From 67fb2f2291331785be548dec66dc46f02e71f698 Mon Sep 17 00:00:00 2001 From: Klaus Date: Mon, 1 Apr 2024 19:55:40 +1300 Subject: [PATCH 001/160] Adding slang --- package-lock.json | 179 ++++++++++++++++++++++++++++++++++++++++++---- package.json | 25 +++---- 2 files changed, 180 insertions(+), 24 deletions(-) diff --git a/package-lock.json b/package-lock.json index df7354da7..675e5b515 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,29 +9,30 @@ "version": "1.3.1", "license": "MIT", "dependencies": { + "@nomicfoundation/slang": "^0.14.2", "@solidity-parser/parser": "^0.18.0", - "semver": "^7.5.4" + "semver": "^7.6.2" }, "devDependencies": { - "@babel/code-frame": "^7.22.10", - "c8": "^9.0.0", + "@babel/code-frame": "^7.24.2", + "c8": "^9.1.0", "cross-env": "^7.0.3", - "eslint": "^8.47.0", + "eslint": "^8.57.0", "eslint-config-airbnb-base": "^15.0.0", - "eslint-config-prettier": "^9.0.0", - "eslint-plugin-import": "^2.28.1", - "esm-utils": "^4.1.2", - "esmock": "^2.3.8", - "jest": "^29.6.3", + "eslint-config-prettier": "^9.1.0", + "eslint-plugin-import": "^2.29.1", + "esm-utils": "^4.3.0", + "esmock": "^2.6.5", + "jest": "^29.7.0", "jest-light-runner": "^0.6.0", "jest-snapshot-serializer-ansi": "^2.1.0", "jest-snapshot-serializer-raw": "^2.0.0", "jest-watch-typeahead": "^2.2.2", - "lines-and-columns": "^2.0.3", - "prettier": "^3.1.1", + "lines-and-columns": "^2.0.4", + "prettier": "^3.2.5", "proxyquire": "^2.1.3", "solc": "^0.8.25", - "webpack": "^5.88.2", + "webpack": "^5.91.0", "webpack-cli": "^5.1.4" }, "engines": { @@ -1245,6 +1246,160 @@ "node": ">= 8" } }, + "node_modules/@nomicfoundation/slang": { + "version": "0.14.2", + "resolved": "https://registry.npmjs.org/@nomicfoundation/slang/-/slang-0.14.2.tgz", + "integrity": "sha512-3CiiJHuqGo5G9oDhRUDexFMlkguwSQMDcapZtJi+vz8x53HOwH4/ZwzwaNi1ZwKGnwT3fp9dxSzxrLYImFcZhA==", + "engines": { + "node": ">= 10" + }, + "optionalDependencies": { + "@nomicfoundation/slang-darwin-arm64": "0.14.2", + "@nomicfoundation/slang-darwin-x64": "0.14.2", + "@nomicfoundation/slang-linux-arm64-gnu": "0.14.2", + "@nomicfoundation/slang-linux-arm64-musl": "0.14.2", + "@nomicfoundation/slang-linux-x64-gnu": "0.14.2", + "@nomicfoundation/slang-linux-x64-musl": "0.14.2", + "@nomicfoundation/slang-win32-arm64-msvc": "0.14.2", + "@nomicfoundation/slang-win32-ia32-msvc": "0.14.2", + "@nomicfoundation/slang-win32-x64-msvc": "0.14.2" + } + }, + "node_modules/@nomicfoundation/slang-darwin-arm64": { + "version": "0.14.2", + "resolved": "https://registry.npmjs.org/@nomicfoundation/slang-darwin-arm64/-/slang-darwin-arm64-0.14.2.tgz", + "integrity": "sha512-ElMGNZHSywlfkP3X9pyym0vaNANSp33Ty/VrYXKABubj2w7+clrzPYQKSjnWv1D7qpJuZwe7SOiHCNCkTEyrVw==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@nomicfoundation/slang-darwin-x64": { + "version": "0.14.2", + "resolved": "https://registry.npmjs.org/@nomicfoundation/slang-darwin-x64/-/slang-darwin-x64-0.14.2.tgz", + "integrity": "sha512-k1LjajxhsU3T0jYmTYIs8S1QAERyOz3YYNL/zhOiah2x8X/jgjHY7dAgkWABzkViQBHUKmc7x8+iUV37h6SuFA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@nomicfoundation/slang-linux-arm64-gnu": { + "version": "0.14.2", + "resolved": "https://registry.npmjs.org/@nomicfoundation/slang-linux-arm64-gnu/-/slang-linux-arm64-gnu-0.14.2.tgz", + "integrity": "sha512-G5ccD82NlF3ijFS1tqlidL2nlfXoFRG2tFPMFTk7etnPElwi4Tq8O0ajZkel2TYiO4LcKxPlfwpVuVR4AbT58Q==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@nomicfoundation/slang-linux-arm64-musl": { + "version": "0.14.2", + "resolved": "https://registry.npmjs.org/@nomicfoundation/slang-linux-arm64-musl/-/slang-linux-arm64-musl-0.14.2.tgz", + "integrity": "sha512-fNeIshoExmikHokUDVbqfV9gDZxtGlJ5cFs3TdwxwWgqEp56V1ByWJ4wGPDQBTwv2p2fil/97LyxnOenHXeOkQ==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@nomicfoundation/slang-linux-x64-gnu": { + "version": "0.14.2", + "resolved": "https://registry.npmjs.org/@nomicfoundation/slang-linux-x64-gnu/-/slang-linux-x64-gnu-0.14.2.tgz", + "integrity": "sha512-kixwVCuvq1TVemPp7Cm6VbpJKmbIcPxhHK4CatOn/Nxm2p35iSBPn/E5OiqwPTjHk+nD684WnuOsZGEvf9NKlg==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@nomicfoundation/slang-linux-x64-musl": { + "version": "0.14.2", + "resolved": "https://registry.npmjs.org/@nomicfoundation/slang-linux-x64-musl/-/slang-linux-x64-musl-0.14.2.tgz", + "integrity": "sha512-oX9ihC3nYyZjG19GxfFthiZJTZkOhYAqyI7YhbPh0BWfAqf3/FxADQkv+4cXv3sb+SsXo4yOVhgVuOq75qWxUw==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@nomicfoundation/slang-win32-arm64-msvc": { + "version": "0.14.2", + "resolved": "https://registry.npmjs.org/@nomicfoundation/slang-win32-arm64-msvc/-/slang-win32-arm64-msvc-0.14.2.tgz", + "integrity": "sha512-VMH2xc0q+iZQ9oGA2NhecYh6GhJAf+M2a+h0IKU+OTbmREUL1nH12huc5wmFzWSdgKyJAyVidCQvcLhgYSoSkw==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@nomicfoundation/slang-win32-ia32-msvc": { + "version": "0.14.2", + "resolved": "https://registry.npmjs.org/@nomicfoundation/slang-win32-ia32-msvc/-/slang-win32-ia32-msvc-0.14.2.tgz", + "integrity": "sha512-z99gbFnAGyA8D/yZoos8S7/VgP0SHrKMt8RcAHluC1UIQ0EnNYJrGwhVVTWPv6PPphoz11nF/UyUZ2cVsBcy0Q==", + "cpu": [ + "ia32" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@nomicfoundation/slang-win32-x64-msvc": { + "version": "0.14.2", + "resolved": "https://registry.npmjs.org/@nomicfoundation/slang-win32-x64-msvc/-/slang-win32-x64-msvc-0.14.2.tgz", + "integrity": "sha512-Av9WnISDikCW+tFf8E8+CE5bGM3K1FRC4yXnZnpPlQmQRIk4RkYQYzFMrAtDdO5NUmgSgVoCDlld5DkQ6vCQxg==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, "node_modules/@pkgr/utils": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/@pkgr/utils/-/utils-2.4.2.tgz", diff --git a/package.json b/package.json index 20a4fe27e..8df12a436 100644 --- a/package.json +++ b/package.json @@ -87,30 +87,31 @@ "node": ">=16" }, "devDependencies": { - "@babel/code-frame": "^7.22.10", - "c8": "^9.0.0", + "@babel/code-frame": "^7.24.2", + "c8": "^9.1.0", "cross-env": "^7.0.3", - "eslint": "^8.47.0", + "eslint": "^8.57.0", "eslint-config-airbnb-base": "^15.0.0", - "eslint-config-prettier": "^9.0.0", - "eslint-plugin-import": "^2.28.1", - "esm-utils": "^4.1.2", - "esmock": "^2.3.8", - "jest": "^29.6.3", + "eslint-config-prettier": "^9.1.0", + "eslint-plugin-import": "^2.29.1", + "esm-utils": "^4.3.0", + "esmock": "^2.6.5", + "jest": "^29.7.0", "jest-light-runner": "^0.6.0", "jest-snapshot-serializer-ansi": "^2.1.0", "jest-snapshot-serializer-raw": "^2.0.0", "jest-watch-typeahead": "^2.2.2", - "lines-and-columns": "^2.0.3", - "prettier": "^3.1.1", + "lines-and-columns": "^2.0.4", + "prettier": "^3.2.5", "proxyquire": "^2.1.3", "solc": "^0.8.25", - "webpack": "^5.88.2", + "webpack": "^5.91.0", "webpack-cli": "^5.1.4" }, "dependencies": { + "@nomicfoundation/slang": "^0.14.2", "@solidity-parser/parser": "^0.18.0", - "semver": "^7.5.4" + "semver": "^7.6.2" }, "peerDependencies": { "prettier": ">=2.3.0" From f2dcfed59ffb688dc4ce18d29abb62a3ce28ee95 Mon Sep 17 00:00:00 2001 From: Klaus Date: Sat, 18 May 2024 14:48:18 +1200 Subject: [PATCH 002/160] WIP: reading the new parsed object and basic structure of the printers --- src/index.js | 24 +- src/slang-nodes/ABICoderPragma.js | 9 + src/slang-nodes/AdditiveExpression.js | 10 + src/slang-nodes/AddressType.js | 9 + src/slang-nodes/AndExpression.js | 10 + src/slang-nodes/ArgumentsDeclaration.js | 8 + src/slang-nodes/ArrayExpression.js | 10 + src/slang-nodes/ArrayTypeName.js | 11 + src/slang-nodes/ArrayValues.js | 9 + src/slang-nodes/AssemblyFlags.js | 9 + src/slang-nodes/AssemblyFlagsDeclaration.js | 10 + src/slang-nodes/AssemblyStatement.js | 11 + src/slang-nodes/AssignmentExpression.js | 10 + src/slang-nodes/BitwiseAndExpression.js | 10 + src/slang-nodes/BitwiseOrExpression.js | 10 + src/slang-nodes/BitwiseXorExpression.js | 10 + src/slang-nodes/Block.js | 10 + src/slang-nodes/BreakStatement.js | 9 + src/slang-nodes/CallOptions.js | 9 + src/slang-nodes/CallOptionsExpression.js | 11 + src/slang-nodes/CatchClause.js | 10 + src/slang-nodes/CatchClauseError.js | 9 + src/slang-nodes/CatchClauses.js | 8 + src/slang-nodes/ComparisonExpression.js | 10 + src/slang-nodes/ConditionalExpression.js | 12 + src/slang-nodes/ConstantDefinition.js | 13 ++ src/slang-nodes/ConstructorAttribute.js | 13 ++ src/slang-nodes/ConstructorAttributes.js | 8 + src/slang-nodes/ConstructorDefinition.js | 11 + src/slang-nodes/ContinueStatement.js | 9 + src/slang-nodes/ContractDefinition.js | 16 ++ src/slang-nodes/ContractMember.js | 7 + src/slang-nodes/ContractMembers.js | 8 + src/slang-nodes/DecimalNumberExpression.js | 9 + src/slang-nodes/DoWhileStatement.js | 14 ++ src/slang-nodes/ElementaryType.js | 13 ++ src/slang-nodes/ElseBranch.js | 9 + src/slang-nodes/EmitStatement.js | 11 + src/slang-nodes/EnumDefinition.js | 12 + src/slang-nodes/EnumMembers.js | 9 + src/slang-nodes/EqualityExpression.js | 10 + src/slang-nodes/ErrorDefinition.js | 11 + src/slang-nodes/ErrorParameter.js | 9 + src/slang-nodes/ErrorParameters.js | 9 + src/slang-nodes/ErrorParametersDeclaration.js | 10 + src/slang-nodes/EventDefinition.js | 12 + src/slang-nodes/EventParameter.js | 10 + src/slang-nodes/EventParameters.js | 9 + src/slang-nodes/EventParametersDeclaration.js | 10 + src/slang-nodes/ExperimentalPragma.js | 9 + src/slang-nodes/ExponentiationExpression.js | 10 + src/slang-nodes/Expression.js | 13 ++ src/slang-nodes/ExpressionStatement.js | 9 + src/slang-nodes/FallbackFunctionAttribute.js | 13 ++ src/slang-nodes/FallbackFunctionAttributes.js | 8 + src/slang-nodes/FallbackFunctionDefinition.js | 12 + src/slang-nodes/ForStatement.js | 14 ++ src/slang-nodes/ForStatementCondition.js | 13 ++ src/slang-nodes/ForStatementInitialization.js | 13 ++ src/slang-nodes/FunctionAttribute.js | 13 ++ src/slang-nodes/FunctionAttributes.js | 8 + src/slang-nodes/FunctionBody.js | 14 ++ src/slang-nodes/FunctionCallExpression.js | 9 + src/slang-nodes/FunctionDefinition.js | 13 ++ src/slang-nodes/FunctionName.js | 7 + src/slang-nodes/FunctionType.js | 11 + src/slang-nodes/FunctionTypeAttribute.js | 7 + src/slang-nodes/FunctionTypeAttributes.js | 8 + src/slang-nodes/HexNumberExpression.js | 9 + src/slang-nodes/HexStringLiteral.js | 7 + src/slang-nodes/HexStringLiterals.js | 8 + src/slang-nodes/IdentifierPath.js | 9 + src/slang-nodes/IfStatement.js | 15 ++ src/slang-nodes/ImportAlias.js | 9 + src/slang-nodes/ImportClause.js | 7 + src/slang-nodes/ImportDeconstruction.js | 12 + src/slang-nodes/ImportDeconstructionSymbol.js | 9 + .../ImportDeconstructionSymbols.js | 9 + src/slang-nodes/ImportDirective.js | 10 + src/slang-nodes/IndexAccessEnd.js | 9 + src/slang-nodes/IndexAccessExpression.js | 12 + src/slang-nodes/InheritanceSpecifier.js | 9 + src/slang-nodes/InheritanceType.js | 9 + src/slang-nodes/InheritanceTypes.js | 9 + src/slang-nodes/InterfaceDefinition.js | 15 ++ src/slang-nodes/InterfaceMembers.js | 9 + src/slang-nodes/LibraryDefinition.js | 12 + src/slang-nodes/LibraryMembers.js | 8 + src/slang-nodes/MappingKey.js | 9 + src/slang-nodes/MappingKeyType.js | 7 + src/slang-nodes/MappingType.js | 13 ++ src/slang-nodes/MappingValue.js | 9 + src/slang-nodes/MemberAccess.js | 7 + src/slang-nodes/MemberAccessExpression.js | 10 + src/slang-nodes/ModifierInvocation.js | 9 + src/slang-nodes/MultiplicativeExpression.js | 10 + src/slang-nodes/NamedArgument.js | 10 + src/slang-nodes/NamedArgumentGroup.js | 10 + src/slang-nodes/NamedArguments.js | 9 + src/slang-nodes/NamedArgumentsDeclaration.js | 10 + src/slang-nodes/NamedImport.js | 11 + src/slang-nodes/NewExpression.js | 9 + src/slang-nodes/NumberUnit.js | 7 + src/slang-nodes/OrExpression.js | 10 + src/slang-nodes/OverridePaths.js | 9 + src/slang-nodes/OverridePathsDeclaration.js | 10 + src/slang-nodes/OverrideSpecifier.js | 11 + src/slang-nodes/Parameter.js | 12 + src/slang-nodes/Parameters.js | 9 + src/slang-nodes/ParametersDeclaration.js | 10 + src/slang-nodes/PathImport.js | 9 + src/slang-nodes/PositionalArguments.js | 9 + .../PositionalArgumentsDeclaration.js | 10 + src/slang-nodes/PostfixExpression.js | 9 + src/slang-nodes/Pragma.js | 7 + src/slang-nodes/PragmaDirective.js | 14 ++ src/slang-nodes/PrefixExpression.js | 9 + src/slang-nodes/ReceiveFunctionAttribute.js | 13 ++ src/slang-nodes/ReceiveFunctionAttributes.js | 8 + src/slang-nodes/ReceiveFunctionDefinition.js | 11 + src/slang-nodes/ReturnStatement.js | 12 + src/slang-nodes/ReturnsDeclaration.js | 9 + src/slang-nodes/RevertStatement.js | 11 + src/slang-nodes/ShiftExpression.js | 10 + src/slang-nodes/SourceUnit.js | 14 ++ src/slang-nodes/SourceUnitMember.js | 7 + src/slang-nodes/SourceUnitMembers.js | 10 + src/slang-nodes/StateVariableAttribute.js | 13 ++ src/slang-nodes/StateVariableAttributes.js | 8 + src/slang-nodes/StateVariableDefinition.js | 12 + .../StateVariableDefinitionValue.js | 9 + src/slang-nodes/Statement.js | 7 + src/slang-nodes/Statements.js | 8 + src/slang-nodes/StorageLocation.js | 7 + src/slang-nodes/StringExpression.js | 7 + src/slang-nodes/StringLiteral.js | 7 + src/slang-nodes/StringLiterals.js | 8 + src/slang-nodes/StructDefinition.js | 12 + src/slang-nodes/StructMember.js | 10 + src/slang-nodes/StructMembers.js | 8 + src/slang-nodes/ThrowStatement.js | 9 + src/slang-nodes/TryStatement.js | 12 + src/slang-nodes/TupleDeconstructionElement.js | 8 + .../TupleDeconstructionElements.js | 9 + .../TupleDeconstructionStatement.js | 14 ++ src/slang-nodes/TupleExpression.js | 10 + src/slang-nodes/TupleMember.js | 7 + src/slang-nodes/TupleValue.js | 10 + src/slang-nodes/TupleValues.js | 9 + src/slang-nodes/TypeExpression.js | 11 + src/slang-nodes/TypeName.js | 7 + src/slang-nodes/TypedTupleMember.js | 12 + src/slang-nodes/UncheckedBlock.js | 9 + src/slang-nodes/UnicodeStringLiteral.js | 7 + src/slang-nodes/UnicodeStringLiterals.js | 8 + src/slang-nodes/UnnamedFunctionAttribute.js | 13 ++ src/slang-nodes/UnnamedFunctionAttributes.js | 8 + src/slang-nodes/UnnamedFunctionDefinition.js | 11 + src/slang-nodes/UntypedTupleMember.js | 11 + .../UserDefinedValueTypeDefinition.js | 12 + src/slang-nodes/UsingAlias.js | 9 + src/slang-nodes/UsingClause.js | 7 + src/slang-nodes/UsingDeconstruction.js | 10 + src/slang-nodes/UsingDeconstructionSymbol.js | 9 + src/slang-nodes/UsingDeconstructionSymbols.js | 9 + src/slang-nodes/UsingDirective.js | 13 ++ src/slang-nodes/UsingOperator.js | 7 + src/slang-nodes/UsingTarget.js | 13 ++ .../VariableDeclarationStatement.js | 14 ++ src/slang-nodes/VariableDeclarationType.js | 13 ++ src/slang-nodes/VariableDeclarationValue.js | 9 + src/slang-nodes/VersionComparator.js | 8 + src/slang-nodes/VersionExpression.js | 13 ++ src/slang-nodes/VersionExpressionSet.js | 7 + src/slang-nodes/VersionExpressionSets.js | 13 ++ src/slang-nodes/VersionPragma.js | 12 + src/slang-nodes/VersionRange.js | 10 + src/slang-nodes/VersionSpecifiers.js | 11 + src/slang-nodes/WhileStatement.js | 12 + src/slang-nodes/YulArguments.js | 9 + src/slang-nodes/YulAssignmentOperator.js | 13 ++ src/slang-nodes/YulAssignmentStatement.js | 10 + src/slang-nodes/YulBlock.js | 10 + src/slang-nodes/YulBreakStatement.js | 8 + src/slang-nodes/YulBuiltInFunction.js | 7 + src/slang-nodes/YulColonAndEqual.js | 9 + src/slang-nodes/YulContinueStatement.js | 8 + src/slang-nodes/YulDefaultCase.js | 9 + src/slang-nodes/YulExpression.js | 7 + src/slang-nodes/YulForStatement.js | 12 + src/slang-nodes/YulFunctionCallExpression.js | 11 + src/slang-nodes/YulFunctionDefinition.js | 12 + src/slang-nodes/YulIfStatement.js | 10 + src/slang-nodes/YulLabel.js | 9 + src/slang-nodes/YulLeaveStatement.js | 8 + src/slang-nodes/YulLiteral.js | 13 ++ src/slang-nodes/YulParameters.js | 9 + src/slang-nodes/YulParametersDeclaration.js | 10 + src/slang-nodes/YulPath.js | 9 + src/slang-nodes/YulPathComponent.js | 7 + src/slang-nodes/YulPaths.js | 9 + src/slang-nodes/YulReturnVariables.js | 9 + src/slang-nodes/YulReturnsDeclaration.js | 9 + src/slang-nodes/YulStatement.js | 7 + src/slang-nodes/YulStatements.js | 8 + src/slang-nodes/YulSwitchCase.js | 7 + src/slang-nodes/YulSwitchCases.js | 8 + src/slang-nodes/YulSwitchStatement.js | 10 + src/slang-nodes/YulValueCase.js | 10 + .../YulVariableDeclarationStatement.js | 10 + .../YulVariableDeclarationValue.js | 9 + src/slang-nodes/index.js | 210 ++++++++++++++++++ src/slangParser.js | 22 ++ src/slangPrinter.js | 45 ++++ .../__snapshots__/jsfmt.spec.js.snap | 24 ++ tests/format/AddressPayable/jsfmt.spec.js | 1 + 216 files changed, 2401 insertions(+), 2 deletions(-) create mode 100644 src/slang-nodes/ABICoderPragma.js create mode 100644 src/slang-nodes/AdditiveExpression.js create mode 100644 src/slang-nodes/AddressType.js create mode 100644 src/slang-nodes/AndExpression.js create mode 100644 src/slang-nodes/ArgumentsDeclaration.js create mode 100644 src/slang-nodes/ArrayExpression.js create mode 100644 src/slang-nodes/ArrayTypeName.js create mode 100644 src/slang-nodes/ArrayValues.js create mode 100644 src/slang-nodes/AssemblyFlags.js create mode 100644 src/slang-nodes/AssemblyFlagsDeclaration.js create mode 100644 src/slang-nodes/AssemblyStatement.js create mode 100644 src/slang-nodes/AssignmentExpression.js create mode 100644 src/slang-nodes/BitwiseAndExpression.js create mode 100644 src/slang-nodes/BitwiseOrExpression.js create mode 100644 src/slang-nodes/BitwiseXorExpression.js create mode 100644 src/slang-nodes/Block.js create mode 100644 src/slang-nodes/BreakStatement.js create mode 100644 src/slang-nodes/CallOptions.js create mode 100644 src/slang-nodes/CallOptionsExpression.js create mode 100644 src/slang-nodes/CatchClause.js create mode 100644 src/slang-nodes/CatchClauseError.js create mode 100644 src/slang-nodes/CatchClauses.js create mode 100644 src/slang-nodes/ComparisonExpression.js create mode 100644 src/slang-nodes/ConditionalExpression.js create mode 100644 src/slang-nodes/ConstantDefinition.js create mode 100644 src/slang-nodes/ConstructorAttribute.js create mode 100644 src/slang-nodes/ConstructorAttributes.js create mode 100644 src/slang-nodes/ConstructorDefinition.js create mode 100644 src/slang-nodes/ContinueStatement.js create mode 100644 src/slang-nodes/ContractDefinition.js create mode 100644 src/slang-nodes/ContractMember.js create mode 100644 src/slang-nodes/ContractMembers.js create mode 100644 src/slang-nodes/DecimalNumberExpression.js create mode 100644 src/slang-nodes/DoWhileStatement.js create mode 100644 src/slang-nodes/ElementaryType.js create mode 100644 src/slang-nodes/ElseBranch.js create mode 100644 src/slang-nodes/EmitStatement.js create mode 100644 src/slang-nodes/EnumDefinition.js create mode 100644 src/slang-nodes/EnumMembers.js create mode 100644 src/slang-nodes/EqualityExpression.js create mode 100644 src/slang-nodes/ErrorDefinition.js create mode 100644 src/slang-nodes/ErrorParameter.js create mode 100644 src/slang-nodes/ErrorParameters.js create mode 100644 src/slang-nodes/ErrorParametersDeclaration.js create mode 100644 src/slang-nodes/EventDefinition.js create mode 100644 src/slang-nodes/EventParameter.js create mode 100644 src/slang-nodes/EventParameters.js create mode 100644 src/slang-nodes/EventParametersDeclaration.js create mode 100644 src/slang-nodes/ExperimentalPragma.js create mode 100644 src/slang-nodes/ExponentiationExpression.js create mode 100644 src/slang-nodes/Expression.js create mode 100644 src/slang-nodes/ExpressionStatement.js create mode 100644 src/slang-nodes/FallbackFunctionAttribute.js create mode 100644 src/slang-nodes/FallbackFunctionAttributes.js create mode 100644 src/slang-nodes/FallbackFunctionDefinition.js create mode 100644 src/slang-nodes/ForStatement.js create mode 100644 src/slang-nodes/ForStatementCondition.js create mode 100644 src/slang-nodes/ForStatementInitialization.js create mode 100644 src/slang-nodes/FunctionAttribute.js create mode 100644 src/slang-nodes/FunctionAttributes.js create mode 100644 src/slang-nodes/FunctionBody.js create mode 100644 src/slang-nodes/FunctionCallExpression.js create mode 100644 src/slang-nodes/FunctionDefinition.js create mode 100644 src/slang-nodes/FunctionName.js create mode 100644 src/slang-nodes/FunctionType.js create mode 100644 src/slang-nodes/FunctionTypeAttribute.js create mode 100644 src/slang-nodes/FunctionTypeAttributes.js create mode 100644 src/slang-nodes/HexNumberExpression.js create mode 100644 src/slang-nodes/HexStringLiteral.js create mode 100644 src/slang-nodes/HexStringLiterals.js create mode 100644 src/slang-nodes/IdentifierPath.js create mode 100644 src/slang-nodes/IfStatement.js create mode 100644 src/slang-nodes/ImportAlias.js create mode 100644 src/slang-nodes/ImportClause.js create mode 100644 src/slang-nodes/ImportDeconstruction.js create mode 100644 src/slang-nodes/ImportDeconstructionSymbol.js create mode 100644 src/slang-nodes/ImportDeconstructionSymbols.js create mode 100644 src/slang-nodes/ImportDirective.js create mode 100644 src/slang-nodes/IndexAccessEnd.js create mode 100644 src/slang-nodes/IndexAccessExpression.js create mode 100644 src/slang-nodes/InheritanceSpecifier.js create mode 100644 src/slang-nodes/InheritanceType.js create mode 100644 src/slang-nodes/InheritanceTypes.js create mode 100644 src/slang-nodes/InterfaceDefinition.js create mode 100644 src/slang-nodes/InterfaceMembers.js create mode 100644 src/slang-nodes/LibraryDefinition.js create mode 100644 src/slang-nodes/LibraryMembers.js create mode 100644 src/slang-nodes/MappingKey.js create mode 100644 src/slang-nodes/MappingKeyType.js create mode 100644 src/slang-nodes/MappingType.js create mode 100644 src/slang-nodes/MappingValue.js create mode 100644 src/slang-nodes/MemberAccess.js create mode 100644 src/slang-nodes/MemberAccessExpression.js create mode 100644 src/slang-nodes/ModifierInvocation.js create mode 100644 src/slang-nodes/MultiplicativeExpression.js create mode 100644 src/slang-nodes/NamedArgument.js create mode 100644 src/slang-nodes/NamedArgumentGroup.js create mode 100644 src/slang-nodes/NamedArguments.js create mode 100644 src/slang-nodes/NamedArgumentsDeclaration.js create mode 100644 src/slang-nodes/NamedImport.js create mode 100644 src/slang-nodes/NewExpression.js create mode 100644 src/slang-nodes/NumberUnit.js create mode 100644 src/slang-nodes/OrExpression.js create mode 100644 src/slang-nodes/OverridePaths.js create mode 100644 src/slang-nodes/OverridePathsDeclaration.js create mode 100644 src/slang-nodes/OverrideSpecifier.js create mode 100644 src/slang-nodes/Parameter.js create mode 100644 src/slang-nodes/Parameters.js create mode 100644 src/slang-nodes/ParametersDeclaration.js create mode 100644 src/slang-nodes/PathImport.js create mode 100644 src/slang-nodes/PositionalArguments.js create mode 100644 src/slang-nodes/PositionalArgumentsDeclaration.js create mode 100644 src/slang-nodes/PostfixExpression.js create mode 100644 src/slang-nodes/Pragma.js create mode 100644 src/slang-nodes/PragmaDirective.js create mode 100644 src/slang-nodes/PrefixExpression.js create mode 100644 src/slang-nodes/ReceiveFunctionAttribute.js create mode 100644 src/slang-nodes/ReceiveFunctionAttributes.js create mode 100644 src/slang-nodes/ReceiveFunctionDefinition.js create mode 100644 src/slang-nodes/ReturnStatement.js create mode 100644 src/slang-nodes/ReturnsDeclaration.js create mode 100644 src/slang-nodes/RevertStatement.js create mode 100644 src/slang-nodes/ShiftExpression.js create mode 100644 src/slang-nodes/SourceUnit.js create mode 100644 src/slang-nodes/SourceUnitMember.js create mode 100644 src/slang-nodes/SourceUnitMembers.js create mode 100644 src/slang-nodes/StateVariableAttribute.js create mode 100644 src/slang-nodes/StateVariableAttributes.js create mode 100644 src/slang-nodes/StateVariableDefinition.js create mode 100644 src/slang-nodes/StateVariableDefinitionValue.js create mode 100644 src/slang-nodes/Statement.js create mode 100644 src/slang-nodes/Statements.js create mode 100644 src/slang-nodes/StorageLocation.js create mode 100644 src/slang-nodes/StringExpression.js create mode 100644 src/slang-nodes/StringLiteral.js create mode 100644 src/slang-nodes/StringLiterals.js create mode 100644 src/slang-nodes/StructDefinition.js create mode 100644 src/slang-nodes/StructMember.js create mode 100644 src/slang-nodes/StructMembers.js create mode 100644 src/slang-nodes/ThrowStatement.js create mode 100644 src/slang-nodes/TryStatement.js create mode 100644 src/slang-nodes/TupleDeconstructionElement.js create mode 100644 src/slang-nodes/TupleDeconstructionElements.js create mode 100644 src/slang-nodes/TupleDeconstructionStatement.js create mode 100644 src/slang-nodes/TupleExpression.js create mode 100644 src/slang-nodes/TupleMember.js create mode 100644 src/slang-nodes/TupleValue.js create mode 100644 src/slang-nodes/TupleValues.js create mode 100644 src/slang-nodes/TypeExpression.js create mode 100644 src/slang-nodes/TypeName.js create mode 100644 src/slang-nodes/TypedTupleMember.js create mode 100644 src/slang-nodes/UncheckedBlock.js create mode 100644 src/slang-nodes/UnicodeStringLiteral.js create mode 100644 src/slang-nodes/UnicodeStringLiterals.js create mode 100644 src/slang-nodes/UnnamedFunctionAttribute.js create mode 100644 src/slang-nodes/UnnamedFunctionAttributes.js create mode 100644 src/slang-nodes/UnnamedFunctionDefinition.js create mode 100644 src/slang-nodes/UntypedTupleMember.js create mode 100644 src/slang-nodes/UserDefinedValueTypeDefinition.js create mode 100644 src/slang-nodes/UsingAlias.js create mode 100644 src/slang-nodes/UsingClause.js create mode 100644 src/slang-nodes/UsingDeconstruction.js create mode 100644 src/slang-nodes/UsingDeconstructionSymbol.js create mode 100644 src/slang-nodes/UsingDeconstructionSymbols.js create mode 100644 src/slang-nodes/UsingDirective.js create mode 100644 src/slang-nodes/UsingOperator.js create mode 100644 src/slang-nodes/UsingTarget.js create mode 100644 src/slang-nodes/VariableDeclarationStatement.js create mode 100644 src/slang-nodes/VariableDeclarationType.js create mode 100644 src/slang-nodes/VariableDeclarationValue.js create mode 100644 src/slang-nodes/VersionComparator.js create mode 100644 src/slang-nodes/VersionExpression.js create mode 100644 src/slang-nodes/VersionExpressionSet.js create mode 100644 src/slang-nodes/VersionExpressionSets.js create mode 100644 src/slang-nodes/VersionPragma.js create mode 100644 src/slang-nodes/VersionRange.js create mode 100644 src/slang-nodes/VersionSpecifiers.js create mode 100644 src/slang-nodes/WhileStatement.js create mode 100644 src/slang-nodes/YulArguments.js create mode 100644 src/slang-nodes/YulAssignmentOperator.js create mode 100644 src/slang-nodes/YulAssignmentStatement.js create mode 100644 src/slang-nodes/YulBlock.js create mode 100644 src/slang-nodes/YulBreakStatement.js create mode 100644 src/slang-nodes/YulBuiltInFunction.js create mode 100644 src/slang-nodes/YulColonAndEqual.js create mode 100644 src/slang-nodes/YulContinueStatement.js create mode 100644 src/slang-nodes/YulDefaultCase.js create mode 100644 src/slang-nodes/YulExpression.js create mode 100644 src/slang-nodes/YulForStatement.js create mode 100644 src/slang-nodes/YulFunctionCallExpression.js create mode 100644 src/slang-nodes/YulFunctionDefinition.js create mode 100644 src/slang-nodes/YulIfStatement.js create mode 100644 src/slang-nodes/YulLabel.js create mode 100644 src/slang-nodes/YulLeaveStatement.js create mode 100644 src/slang-nodes/YulLiteral.js create mode 100644 src/slang-nodes/YulParameters.js create mode 100644 src/slang-nodes/YulParametersDeclaration.js create mode 100644 src/slang-nodes/YulPath.js create mode 100644 src/slang-nodes/YulPathComponent.js create mode 100644 src/slang-nodes/YulPaths.js create mode 100644 src/slang-nodes/YulReturnVariables.js create mode 100644 src/slang-nodes/YulReturnsDeclaration.js create mode 100644 src/slang-nodes/YulStatement.js create mode 100644 src/slang-nodes/YulStatements.js create mode 100644 src/slang-nodes/YulSwitchCase.js create mode 100644 src/slang-nodes/YulSwitchCases.js create mode 100644 src/slang-nodes/YulSwitchStatement.js create mode 100644 src/slang-nodes/YulValueCase.js create mode 100644 src/slang-nodes/YulVariableDeclarationStatement.js create mode 100644 src/slang-nodes/YulVariableDeclarationValue.js create mode 100644 src/slang-nodes/index.js create mode 100644 src/slangParser.js create mode 100644 src/slangPrinter.js diff --git a/src/index.js b/src/index.js index 9d3bfe3cf..60171ef84 100644 --- a/src/index.js +++ b/src/index.js @@ -4,6 +4,8 @@ import loc from './loc.js'; import options from './options.js'; import parse from './parser.js'; import print from './printer.js'; +import slangParse from './slangParser.js'; +import slangPrint from './slangPrinter.js'; // https://prettier.io/docs/en/plugins.html#languages // https://github.com/ikatyang/linguist-languages/blob/master/data/Solidity.json @@ -16,15 +18,21 @@ const languages = [ aceMode: 'text', tmScope: 'source.solidity', extensions: ['.sol'], - parsers: ['solidity-parse'], + parsers: ['solidity-parse', 'solidity-slang-parser'], vscodeLanguageIds: ['solidity'] } ]; // https://prettier.io/docs/en/plugins.html#parsers const parser = { astFormat: 'solidity-ast', parse, ...loc }; +const slangParser = { + astFormat: 'solidity-slang-ast', + parse: slangParse, + ...loc +}; const parsers = { - 'solidity-parse': parser + 'solidity-parse': parser, + 'solidity-slang-parse': slangParser }; const canAttachComment = (node) => @@ -43,6 +51,18 @@ const printers = { massageAstNode, print, printComment: comments.printComment + }, + 'solidity-slang-ast': { + canAttachComment, + handleComments: { + ownLine: comments.solidityHandleOwnLineComment, + endOfLine: comments.solidityHandleEndOfLineComment, + remaining: comments.solidityHandleRemainingComment + }, + isBlockComment: comments.isBlockComment, + massageAstNode, + print: slangPrint, + printComment: comments.printComment } }; diff --git a/src/slang-nodes/ABICoderPragma.js b/src/slang-nodes/ABICoderPragma.js new file mode 100644 index 000000000..b10162ae9 --- /dev/null +++ b/src/slang-nodes/ABICoderPragma.js @@ -0,0 +1,9 @@ +export const ABICoderPragma = { + parse: ({ ast }) => ({ + kind: ast.cst.kind, + abicoderKeyword: ast.abicoderKeyword.text, + version: ast.version.text + }), + // TODO: implement print + print: () => ['ABICoderPragma'] +}; diff --git a/src/slang-nodes/AdditiveExpression.js b/src/slang-nodes/AdditiveExpression.js new file mode 100644 index 000000000..2d9157026 --- /dev/null +++ b/src/slang-nodes/AdditiveExpression.js @@ -0,0 +1,10 @@ +export const AdditiveExpression = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + leftOperand: parse(ast.leftOperand, options, parse), + operator: ast.operator.text, + rightOperand: parse(ast.rightOperand, options, parse) + }), + // TODO: implement print + print: () => ['AdditiveExpression'] +}; diff --git a/src/slang-nodes/AddressType.js b/src/slang-nodes/AddressType.js new file mode 100644 index 000000000..0693d4f70 --- /dev/null +++ b/src/slang-nodes/AddressType.js @@ -0,0 +1,9 @@ +export const AddressType = { + parse: ({ ast }) => ({ + kind: ast.cst.kind, + addressKeyword: ast.addressKeyword.text, + payableKeyword: ast.payableKeyword?.text + }), + // TODO: implement print + print: () => ['AddressType'] +}; diff --git a/src/slang-nodes/AndExpression.js b/src/slang-nodes/AndExpression.js new file mode 100644 index 000000000..c42f41103 --- /dev/null +++ b/src/slang-nodes/AndExpression.js @@ -0,0 +1,10 @@ +export const AndExpression = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + leftOperand: parse(ast.leftOperand, options, parse), + operator: ast.operator.text, + rightOperand: parse(ast.rightOperand, options, parse) + }), + // TODO: implement print + print: () => ['AndExpression'] +}; diff --git a/src/slang-nodes/ArgumentsDeclaration.js b/src/slang-nodes/ArgumentsDeclaration.js new file mode 100644 index 000000000..86cd19db2 --- /dev/null +++ b/src/slang-nodes/ArgumentsDeclaration.js @@ -0,0 +1,8 @@ +export const ArgumentsDeclaration = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + variant: parse(ast.variant, options, parse) + }), + // TODO: implement print + print: ({ path, print }) => path.call(print, 'variant') +}; diff --git a/src/slang-nodes/ArrayExpression.js b/src/slang-nodes/ArrayExpression.js new file mode 100644 index 000000000..3bb605e7e --- /dev/null +++ b/src/slang-nodes/ArrayExpression.js @@ -0,0 +1,10 @@ +export const ArrayExpression = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + openBracket: ast.openBracket.text, + items: parse(ast.items, options, parse), + closeBracket: ast.closeBracket.text + }), + // TODO: implement print + print: () => ['ArrayExpression'] +}; diff --git a/src/slang-nodes/ArrayTypeName.js b/src/slang-nodes/ArrayTypeName.js new file mode 100644 index 000000000..23a25e27b --- /dev/null +++ b/src/slang-nodes/ArrayTypeName.js @@ -0,0 +1,11 @@ +export const ArrayTypeName = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + operand: parse(ast.operand, options, parse), + openBracket: ast.openBracket.text, + index: ast.index ? parse(ast.index, options, parse) : undefined, + closeBracket: ast.closeBracket.text + }), + // TODO: implement print + print: () => ['ArrayTypeName'] +}; diff --git a/src/slang-nodes/ArrayValues.js b/src/slang-nodes/ArrayValues.js new file mode 100644 index 000000000..de79904a6 --- /dev/null +++ b/src/slang-nodes/ArrayValues.js @@ -0,0 +1,9 @@ +export const ArrayValues = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item, options, parse)), + separators: ast.separators.map((separator) => separator.text) + }), + // TODO: implement print + print: () => ['ArrayValues'] +}; diff --git a/src/slang-nodes/AssemblyFlags.js b/src/slang-nodes/AssemblyFlags.js new file mode 100644 index 000000000..f63c35ab3 --- /dev/null +++ b/src/slang-nodes/AssemblyFlags.js @@ -0,0 +1,9 @@ +export const AssemblyFlags = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.maps((item) => parse(item, options, parse)), + separators: ast.separators.maps((separator) => separator.text) + }), + // TODO: implement print + print: () => ['AssemblyFlags'] +}; diff --git a/src/slang-nodes/AssemblyFlagsDeclaration.js b/src/slang-nodes/AssemblyFlagsDeclaration.js new file mode 100644 index 000000000..b2401e015 --- /dev/null +++ b/src/slang-nodes/AssemblyFlagsDeclaration.js @@ -0,0 +1,10 @@ +export const AssemblyFlagsDeclaration = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + openParen: ast.openParen.text, + flags: parse(ast.flags, options, parse), + closeParen: ast.closeParen.text + }), + // TODO: implement print + print: () => ['AssemblyFlagsDeclaration'] +}; diff --git a/src/slang-nodes/AssemblyStatement.js b/src/slang-nodes/AssemblyStatement.js new file mode 100644 index 000000000..553c4fc17 --- /dev/null +++ b/src/slang-nodes/AssemblyStatement.js @@ -0,0 +1,11 @@ +export const AssemblyStatement = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + assemblyKeyword: ast.assemblyKeyword.text, + label: ast.label ? parse(ast.label, options, parse) : undefined, + flags: ast.flags ? parse(ast.flags, options, parse) : undefined, + body: parse(ast.body, options, parse) + }), + // TODO: implement print + print: () => ['AssemblyStatement'] +}; diff --git a/src/slang-nodes/AssignmentExpression.js b/src/slang-nodes/AssignmentExpression.js new file mode 100644 index 000000000..6ee3d9d74 --- /dev/null +++ b/src/slang-nodes/AssignmentExpression.js @@ -0,0 +1,10 @@ +export const AssignmentExpression = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + leftOperand: parse(ast.leftOperand, options, parse), + operator: ast.operator.text, + rightOperand: parse(ast.rightOperand, options, parse) + }), + // TODO: implement print + print: () => ['AssignmentExpression'] +}; diff --git a/src/slang-nodes/BitwiseAndExpression.js b/src/slang-nodes/BitwiseAndExpression.js new file mode 100644 index 000000000..026d91cd1 --- /dev/null +++ b/src/slang-nodes/BitwiseAndExpression.js @@ -0,0 +1,10 @@ +export const BitwiseAndExpression = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + leftOperand: parse(ast.leftOperand, options, parse), + operator: ast.operator.text, + rightOperand: parse(ast.rightOperand, options, parse) + }), + // TODO: implement print + print: () => ['BitwiseAndExpression'] +}; diff --git a/src/slang-nodes/BitwiseOrExpression.js b/src/slang-nodes/BitwiseOrExpression.js new file mode 100644 index 000000000..8b54fd1a8 --- /dev/null +++ b/src/slang-nodes/BitwiseOrExpression.js @@ -0,0 +1,10 @@ +export const BitwiseOrExpression = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + leftOperand: parse(ast.leftOperand, options, parse), + operator: ast.operator.text, + rightOperand: parse(ast.rightOperand, options, parse) + }), + // TODO: implement print + print: () => ['BitwiseOrExpression'] +}; diff --git a/src/slang-nodes/BitwiseXorExpression.js b/src/slang-nodes/BitwiseXorExpression.js new file mode 100644 index 000000000..4170af3ed --- /dev/null +++ b/src/slang-nodes/BitwiseXorExpression.js @@ -0,0 +1,10 @@ +export const BitwiseXorExpression = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + leftOperand: parse(ast.leftOperand, options, parse), + operator: ast.operator.text, + rightOperand: parse(ast.rightOperand, options, parse) + }), + // TODO: implement print + print: () => ['BitwiseXorExpression'] +}; diff --git a/src/slang-nodes/Block.js b/src/slang-nodes/Block.js new file mode 100644 index 000000000..304c3ca57 --- /dev/null +++ b/src/slang-nodes/Block.js @@ -0,0 +1,10 @@ +export const Block = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + openBrace: ast.openBrace.text, + statements: parse(ast.statements, options, parse), + closeBrace: ast.closeBrace.text + }), + // TODO: implement print + print: () => ['Block'] +}; diff --git a/src/slang-nodes/BreakStatement.js b/src/slang-nodes/BreakStatement.js new file mode 100644 index 000000000..38d85a656 --- /dev/null +++ b/src/slang-nodes/BreakStatement.js @@ -0,0 +1,9 @@ +export const BreakStatement = { + parse: ({ ast }) => ({ + kind: ast.cst.kind, + breakKeyword: ast.breakKeyword.text, + semicolon: ast.semicolon.text + }), + // TODO: implement print + print: () => ['BreakStatement'] +}; diff --git a/src/slang-nodes/CallOptions.js b/src/slang-nodes/CallOptions.js new file mode 100644 index 000000000..ee4e8e0cb --- /dev/null +++ b/src/slang-nodes/CallOptions.js @@ -0,0 +1,9 @@ +export const CallOptions = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item, options, parse)), + separators: ast.separators.map((separator) => separator.text) + }), + // TODO: implement print + print: () => ['CallOptions'] +}; diff --git a/src/slang-nodes/CallOptionsExpression.js b/src/slang-nodes/CallOptionsExpression.js new file mode 100644 index 000000000..a83142b4d --- /dev/null +++ b/src/slang-nodes/CallOptionsExpression.js @@ -0,0 +1,11 @@ +export const CallOptionsExpression = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + operand: parse(ast.operand, options, parse), + openBrace: ast.openBrace.text, + options: parse(ast.options, options, parse), + closeBrace: ast.closeBrace.text + }), + // TODO: implement print + print: () => ['CallOptionsExpression'] +}; diff --git a/src/slang-nodes/CatchClause.js b/src/slang-nodes/CatchClause.js new file mode 100644 index 000000000..2c6b5ca9c --- /dev/null +++ b/src/slang-nodes/CatchClause.js @@ -0,0 +1,10 @@ +export const CatchClause = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + catchKeyword: ast.catchKeyword.text, + error: ast.error ? parse(ast.error, options, parse) : undefined, + body: parse(ast.body, options, parse) + }), + // TODO: implement print + print: () => ['CatchClause'] +}; diff --git a/src/slang-nodes/CatchClauseError.js b/src/slang-nodes/CatchClauseError.js new file mode 100644 index 000000000..4f0873264 --- /dev/null +++ b/src/slang-nodes/CatchClauseError.js @@ -0,0 +1,9 @@ +export const CatchClauseError = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + name: ast.name?.text, + parameters: parse(ast.parameters, options, parse) + }), + // TODO: implement print + print: () => ['CatchClauseError'] +}; diff --git a/src/slang-nodes/CatchClauses.js b/src/slang-nodes/CatchClauses.js new file mode 100644 index 000000000..26ed993ed --- /dev/null +++ b/src/slang-nodes/CatchClauses.js @@ -0,0 +1,8 @@ +export const CatchClauses = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item, options, parse)) + }), + // TODO: implement print + print: () => ['CatchClauses'] +}; diff --git a/src/slang-nodes/ComparisonExpression.js b/src/slang-nodes/ComparisonExpression.js new file mode 100644 index 000000000..93bad524f --- /dev/null +++ b/src/slang-nodes/ComparisonExpression.js @@ -0,0 +1,10 @@ +export const ComparisonExpression = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + leftOperand: parse(ast.leftOperand, options, parse), + operator: ast.operator.text, + rightOperand: parse(ast.rightOperand, options, parse) + }), + // TODO: implement print + print: () => ['ComparisonExpression'] +}; diff --git a/src/slang-nodes/ConditionalExpression.js b/src/slang-nodes/ConditionalExpression.js new file mode 100644 index 000000000..9428ce36d --- /dev/null +++ b/src/slang-nodes/ConditionalExpression.js @@ -0,0 +1,12 @@ +export const ConditionalExpression = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + operand: parse(ast.operand, options, parse), + questionMark: ast.questionMark.text, + trueExpression: parse(ast.trueExpression, options, parse), + colon: ast.colon.text, + falseExpression: parse(ast.falseExpression, options, parse) + }), + // TODO: implement print + print: () => ['ConditionalExpression'] +}; diff --git a/src/slang-nodes/ConstantDefinition.js b/src/slang-nodes/ConstantDefinition.js new file mode 100644 index 000000000..dc9d747ae --- /dev/null +++ b/src/slang-nodes/ConstantDefinition.js @@ -0,0 +1,13 @@ +export const ConstantDefinition = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + typeName: parse(ast.typeName, options, parse), + constantKeyword: ast.constantKeyword.text, + name: ast.name.text, + equal: ast.equal.text, + value: parse(ast.value, options, parse), + semicolon: ast.semicolon.text + }), + // TODO: implement print + print: () => ['ConstantDefinition'] +}; diff --git a/src/slang-nodes/ConstructorAttribute.js b/src/slang-nodes/ConstructorAttribute.js new file mode 100644 index 000000000..31d1c2825 --- /dev/null +++ b/src/slang-nodes/ConstructorAttribute.js @@ -0,0 +1,13 @@ +export const ConstructorAttribute = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + variant: + ast.variant.type === 'Token' + ? ast.variant.text + : parse(ast.variant, options, parse) + }), + print: ({ node, path, print }) => + typeof node.variant === 'string' + ? node.variant + : path.call(print, 'variant') +}; diff --git a/src/slang-nodes/ConstructorAttributes.js b/src/slang-nodes/ConstructorAttributes.js new file mode 100644 index 000000000..2087d5a15 --- /dev/null +++ b/src/slang-nodes/ConstructorAttributes.js @@ -0,0 +1,8 @@ +export const ConstructorAttributes = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item, options, parse)) + }), + // TODO: implement print + print: () => ['ConstructorAttributes'] +}; diff --git a/src/slang-nodes/ConstructorDefinition.js b/src/slang-nodes/ConstructorDefinition.js new file mode 100644 index 000000000..ca3cd791b --- /dev/null +++ b/src/slang-nodes/ConstructorDefinition.js @@ -0,0 +1,11 @@ +export const ConstructorDefinition = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + constructorKeyword: ast.constructorKeyword.text, + parameters: parse(ast.parameters, options, parse), + attributes: parse(ast.attributes, options, parse), + body: parse(ast.body, options, parse) + }), + // TODO: implement print + print: () => ['ConstructorDefinition'] +}; diff --git a/src/slang-nodes/ContinueStatement.js b/src/slang-nodes/ContinueStatement.js new file mode 100644 index 000000000..f8ed774e1 --- /dev/null +++ b/src/slang-nodes/ContinueStatement.js @@ -0,0 +1,9 @@ +export const ContinueStatement = { + parse: ({ ast }) => ({ + kind: ast.cst.kind, + continueKeyword: ast.continueKeyword.text, + semicolon: ast.semicolon.text + }), + // TODO: implement print + print: () => ['ContinueStatement'] +}; diff --git a/src/slang-nodes/ContractDefinition.js b/src/slang-nodes/ContractDefinition.js new file mode 100644 index 000000000..d73a22f9d --- /dev/null +++ b/src/slang-nodes/ContractDefinition.js @@ -0,0 +1,16 @@ +export const ContractDefinition = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + abstractKeyword: ast.abstractKeyword?.text, + contractKeyword: ast.contractKeyword.text, + name: ast.name.text, + inheritence: ast.inheritence + ? parse(ast.inheritence, options, parse) + : undefined, + openBrace: ast.openBrace.text, + members: parse(ast.members, options, parse), + closeBrace: ast.closeBrace.text + }), + // TODO: implement print + print: () => ['ContractDefinition'] +}; diff --git a/src/slang-nodes/ContractMember.js b/src/slang-nodes/ContractMember.js new file mode 100644 index 000000000..ce7d1da5b --- /dev/null +++ b/src/slang-nodes/ContractMember.js @@ -0,0 +1,7 @@ +export const ContractMember = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + variant: parse(ast.variant, options, parse) + }), + print: ({ path, print }) => path.call(print, 'variant') +}; diff --git a/src/slang-nodes/ContractMembers.js b/src/slang-nodes/ContractMembers.js new file mode 100644 index 000000000..ab036d867 --- /dev/null +++ b/src/slang-nodes/ContractMembers.js @@ -0,0 +1,8 @@ +export const ContractMembers = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item, options, parse)) + }), + // TODO: implement print + print: () => ['ContractMembers'] +}; diff --git a/src/slang-nodes/DecimalNumberExpression.js b/src/slang-nodes/DecimalNumberExpression.js new file mode 100644 index 000000000..9a2660d44 --- /dev/null +++ b/src/slang-nodes/DecimalNumberExpression.js @@ -0,0 +1,9 @@ +export const DecimalNumberExpression = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + literal: ast.literal.text, + unit: ast.unit ? parse(ast.unit, options, parse) : undefined + }), + // TODO: implement print + print: () => ['DecimalNumberExpression'] +}; diff --git a/src/slang-nodes/DoWhileStatement.js b/src/slang-nodes/DoWhileStatement.js new file mode 100644 index 000000000..8fb4dae5b --- /dev/null +++ b/src/slang-nodes/DoWhileStatement.js @@ -0,0 +1,14 @@ +export const DoWhileStatement = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + doKeyword: ast.doKeyword.text, + body: parse(ast.body, options, parse), + whileKeyword: ast.whileKeyword.text, + openParen: ast.openParen.text, + condition: parse(ast.condition, options, parse), + closeParen: ast.closeParen.text, + semicolon: ast.semicolon.text + }), + // TODO: implement print + print: () => ['DoWhileStatement'] +}; diff --git a/src/slang-nodes/ElementaryType.js b/src/slang-nodes/ElementaryType.js new file mode 100644 index 000000000..48d9abea7 --- /dev/null +++ b/src/slang-nodes/ElementaryType.js @@ -0,0 +1,13 @@ +export const ElementaryType = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + variant: + ast.variant.type === 'Token' + ? ast.variant.text + : parse(ast.variant, options, parse) + }), + print: ({ node, path, print }) => + typeof node.variant === 'string' + ? node.variant + : path.call(print, 'variant') +}; diff --git a/src/slang-nodes/ElseBranch.js b/src/slang-nodes/ElseBranch.js new file mode 100644 index 000000000..9e97a8a13 --- /dev/null +++ b/src/slang-nodes/ElseBranch.js @@ -0,0 +1,9 @@ +export const ElseBranch = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + elseKeyword: ast.elseKeyword.text, + body: parse(ast.body, options, parse) + }), + // TODO: implement print + print: () => ['ElseBranch'] +}; diff --git a/src/slang-nodes/EmitStatement.js b/src/slang-nodes/EmitStatement.js new file mode 100644 index 000000000..3618750c6 --- /dev/null +++ b/src/slang-nodes/EmitStatement.js @@ -0,0 +1,11 @@ +export const EmitStatement = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + emitKeyword: ast.emitKeyword.text, + event: parse(ast.event, options, parse), + arguments: parse(ast.arguments, options, parse), + semicolon: ast.semicolon.text + }), + // TODO: implement print + print: () => ['EmitStatement'] +}; diff --git a/src/slang-nodes/EnumDefinition.js b/src/slang-nodes/EnumDefinition.js new file mode 100644 index 000000000..ef31d87eb --- /dev/null +++ b/src/slang-nodes/EnumDefinition.js @@ -0,0 +1,12 @@ +export const EnumDefinition = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + enumKeyword: ast.enumKeyword.text, + name: ast.name.text, + openBrace: ast.openBrace.text, + members: parse(ast.members, options, parse), + closeBrace: ast.closeBrace.text + }), + // TODO: implement print + print: () => ['EmitStatement'] +}; diff --git a/src/slang-nodes/EnumMembers.js b/src/slang-nodes/EnumMembers.js new file mode 100644 index 000000000..04d68001e --- /dev/null +++ b/src/slang-nodes/EnumMembers.js @@ -0,0 +1,9 @@ +export const EnumMembers = { + parse: ({ ast }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => item.text), + separators: ast.separators.map((separator) => separator.text) + }), + // TODO: implement print + print: () => ['EnumMembers'] +}; diff --git a/src/slang-nodes/EqualityExpression.js b/src/slang-nodes/EqualityExpression.js new file mode 100644 index 000000000..8ed7135af --- /dev/null +++ b/src/slang-nodes/EqualityExpression.js @@ -0,0 +1,10 @@ +export const EqualityExpression = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + leftOperand: parse(ast.leftOperand, options, parse), + operator: ast.operator.text, + rightOperand: parse(ast.rightOperand, options, parse) + }), + // TODO: implement print + print: () => ['EqualityExpression'] +}; diff --git a/src/slang-nodes/ErrorDefinition.js b/src/slang-nodes/ErrorDefinition.js new file mode 100644 index 000000000..6b1768e63 --- /dev/null +++ b/src/slang-nodes/ErrorDefinition.js @@ -0,0 +1,11 @@ +export const ErrorDefinition = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + errorKeyword: ast.errorKeyword.text, + name: ast.name.text, + members: parse(ast.members, options, parse), + semicolon: ast.semicolon.text + }), + // TODO: implement print + print: () => ['ErrorDefinition'] +}; diff --git a/src/slang-nodes/ErrorParameter.js b/src/slang-nodes/ErrorParameter.js new file mode 100644 index 000000000..b426def0e --- /dev/null +++ b/src/slang-nodes/ErrorParameter.js @@ -0,0 +1,9 @@ +export const ErrorParameter = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + typeName: parse(ast.typeName, options, parse), + name: ast.name?.text + }), + // TODO: implement print + print: () => ['ErrorParameter'] +}; diff --git a/src/slang-nodes/ErrorParameters.js b/src/slang-nodes/ErrorParameters.js new file mode 100644 index 000000000..54173c7a9 --- /dev/null +++ b/src/slang-nodes/ErrorParameters.js @@ -0,0 +1,9 @@ +export const ErrorParameters = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item.text, options, parse)), + separators: ast.separators.map((separator) => separator.text) + }), + // TODO: implement print + print: () => ['ErrorParameters'] +}; diff --git a/src/slang-nodes/ErrorParametersDeclaration.js b/src/slang-nodes/ErrorParametersDeclaration.js new file mode 100644 index 000000000..8b4328a14 --- /dev/null +++ b/src/slang-nodes/ErrorParametersDeclaration.js @@ -0,0 +1,10 @@ +export const ErrorParametersDeclaration = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + openParen: ast.openParen.text, + parameters: parse(ast.parameters, options, parse), + closeParen: ast.closeParen.text + }), + // TODO: implement print + print: () => ['ErrorParametersDeclaration'] +}; diff --git a/src/slang-nodes/EventDefinition.js b/src/slang-nodes/EventDefinition.js new file mode 100644 index 000000000..91dd2856e --- /dev/null +++ b/src/slang-nodes/EventDefinition.js @@ -0,0 +1,12 @@ +export const EventDefinition = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + eventKeyword: ast.eventKeyword.text, + name: ast.name.text, + parameters: parse(ast.parameters, options, parse), + anonymousKeyword: ast.anonymousKeyword?.text, + semicolon: ast.semicolon.text + }), + // TODO: implement print + print: () => ['EventDefinition'] +}; diff --git a/src/slang-nodes/EventParameter.js b/src/slang-nodes/EventParameter.js new file mode 100644 index 000000000..dcbb6c048 --- /dev/null +++ b/src/slang-nodes/EventParameter.js @@ -0,0 +1,10 @@ +export const EventParameter = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + typeName: parse(ast.typeName, options, parse), + indexedKeyword: ast.indexedKeyword?.text, + name: ast.name?.text + }), + // TODO: implement print + print: () => ['EventParameter'] +}; diff --git a/src/slang-nodes/EventParameters.js b/src/slang-nodes/EventParameters.js new file mode 100644 index 000000000..8a60296ec --- /dev/null +++ b/src/slang-nodes/EventParameters.js @@ -0,0 +1,9 @@ +export const EventParameters = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item.text, options, parse)), + separators: ast.separators.map((separator) => separator.text) + }), + // TODO: implement print + print: () => ['EventParameters'] +}; diff --git a/src/slang-nodes/EventParametersDeclaration.js b/src/slang-nodes/EventParametersDeclaration.js new file mode 100644 index 000000000..d8fbc90c9 --- /dev/null +++ b/src/slang-nodes/EventParametersDeclaration.js @@ -0,0 +1,10 @@ +export const EventParametersDeclaration = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + openParen: ast.openParen.text, + parameters: parse(ast.parameters, options, parse), + closeParen: ast.closeParen.text + }), + // TODO: implement print + print: () => ['EventParametersDeclaration'] +}; diff --git a/src/slang-nodes/ExperimentalPragma.js b/src/slang-nodes/ExperimentalPragma.js new file mode 100644 index 000000000..f7d9c4f48 --- /dev/null +++ b/src/slang-nodes/ExperimentalPragma.js @@ -0,0 +1,9 @@ +export const ExperimentalPragma = { + parse: ({ ast }) => ({ + kind: ast.cst.kind, + experimentalKeyword: ast.experimentalKeyword.text, + feature: ast.feature + }), + // TODO: implement print + print: () => ['ExperimentalPragma'] +}; diff --git a/src/slang-nodes/ExponentiationExpression.js b/src/slang-nodes/ExponentiationExpression.js new file mode 100644 index 000000000..d76f4d479 --- /dev/null +++ b/src/slang-nodes/ExponentiationExpression.js @@ -0,0 +1,10 @@ +export const ExponentiationExpression = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + leftOperand: parse(ast.leftOperand, options, parse), + operator: ast.operator.text, + rightOperand: parse(ast.rightOperand, options, parse) + }), + // TODO: implement print + print: () => ['ExponentiationExpression'] +}; diff --git a/src/slang-nodes/Expression.js b/src/slang-nodes/Expression.js new file mode 100644 index 000000000..36e7f6d38 --- /dev/null +++ b/src/slang-nodes/Expression.js @@ -0,0 +1,13 @@ +export const Expression = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + variant: + ast.variant.type === 'Token' + ? ast.variant.text + : parse(ast.variant, options, parse) + }), + print: ({ node, path, print }) => + typeof node.variant === 'string' + ? node.variant + : path.call(print, 'variant') +}; diff --git a/src/slang-nodes/ExpressionStatement.js b/src/slang-nodes/ExpressionStatement.js new file mode 100644 index 000000000..e0e627a87 --- /dev/null +++ b/src/slang-nodes/ExpressionStatement.js @@ -0,0 +1,9 @@ +export const ExpressionStatement = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + expression: parse(ast.expression, options, parse), + semicolon: ast.semicolon.text + }), + // TODO: implement print + print: () => ['ExpressionStatement'] +}; diff --git a/src/slang-nodes/FallbackFunctionAttribute.js b/src/slang-nodes/FallbackFunctionAttribute.js new file mode 100644 index 000000000..c7a1dfcad --- /dev/null +++ b/src/slang-nodes/FallbackFunctionAttribute.js @@ -0,0 +1,13 @@ +export const FallbackFunctionAttribute = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + variant: + ast.variant.type === 'Token' + ? ast.variant.text + : parse(ast.variant, options, parse) + }), + print: ({ node, path, print }) => + typeof node.variant === 'string' + ? node.variant + : path.call(print, 'variant') +}; diff --git a/src/slang-nodes/FallbackFunctionAttributes.js b/src/slang-nodes/FallbackFunctionAttributes.js new file mode 100644 index 000000000..caff8fb6d --- /dev/null +++ b/src/slang-nodes/FallbackFunctionAttributes.js @@ -0,0 +1,8 @@ +export const FallbackFunctionAttributes = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item, options, parse)) + }), + // TODO: implement print + print: () => ['FallbackFunctionAttributes'] +}; diff --git a/src/slang-nodes/FallbackFunctionDefinition.js b/src/slang-nodes/FallbackFunctionDefinition.js new file mode 100644 index 000000000..79fa159e1 --- /dev/null +++ b/src/slang-nodes/FallbackFunctionDefinition.js @@ -0,0 +1,12 @@ +export const FallbackFunctionDefinition = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + fallbackKeyword: ast.fallbackKeyword.text, + parameters: parse(ast.parameters, options, parse), + attributes: parse(ast.attributes, options, parse), + returns: ast.returns ? parse(ast.returns, options, parse) : undefined, + body: parse(ast.body, options, parse) + }), + // TODO: implement print + print: () => ['FallbackFunctionDefinition'] +}; diff --git a/src/slang-nodes/ForStatement.js b/src/slang-nodes/ForStatement.js new file mode 100644 index 000000000..f483dc42d --- /dev/null +++ b/src/slang-nodes/ForStatement.js @@ -0,0 +1,14 @@ +export const ForStatement = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + forKeyword: ast.forKeyword.text, + openParen: ast.openParen.text, + initialization: parse(ast.initialization, options, parse), + condition: parse(ast.condition, options, parse), + iterator: ast.iterator ? parse(ast.iterator, options, parse) : undefined, + closeParen: ast.closeParen.text, + body: parse(ast.body, options, parse) + }), + // TODO: implement print + print: () => ['ForStatement'] +}; diff --git a/src/slang-nodes/ForStatementCondition.js b/src/slang-nodes/ForStatementCondition.js new file mode 100644 index 000000000..da1cb8a1f --- /dev/null +++ b/src/slang-nodes/ForStatementCondition.js @@ -0,0 +1,13 @@ +export const ForStatementCondition = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + variant: + ast.variant.type === 'Token' + ? ast.variant.text + : parse(ast.variant, options, parse) + }), + print: ({ node, path, print }) => + typeof node.variant === 'string' + ? node.variant + : path.call(print, 'variant') +}; diff --git a/src/slang-nodes/ForStatementInitialization.js b/src/slang-nodes/ForStatementInitialization.js new file mode 100644 index 000000000..e44f69153 --- /dev/null +++ b/src/slang-nodes/ForStatementInitialization.js @@ -0,0 +1,13 @@ +export const ForStatementInitialization = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + variant: + ast.variant.type === 'Token' + ? ast.variant.text + : parse(ast.variant, options, parse) + }), + print: ({ node, path, print }) => + typeof node.variant === 'string' + ? node.variant + : path.call(print, 'variant') +}; diff --git a/src/slang-nodes/FunctionAttribute.js b/src/slang-nodes/FunctionAttribute.js new file mode 100644 index 000000000..8a14b9e1e --- /dev/null +++ b/src/slang-nodes/FunctionAttribute.js @@ -0,0 +1,13 @@ +export const FunctionAttribute = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + variant: + ast.variant.type === 'Token' + ? ast.variant.text + : parse(ast.variant, options, parse) + }), + print: ({ node, path, print }) => + typeof node.variant === 'string' + ? node.variant + : path.call(print, 'variant') +}; diff --git a/src/slang-nodes/FunctionAttributes.js b/src/slang-nodes/FunctionAttributes.js new file mode 100644 index 000000000..dc764df58 --- /dev/null +++ b/src/slang-nodes/FunctionAttributes.js @@ -0,0 +1,8 @@ +export const FunctionAttributes = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item, options, parse)) + }), + // TODO: implement print + print: () => ['FunctionAttributes'] +}; diff --git a/src/slang-nodes/FunctionBody.js b/src/slang-nodes/FunctionBody.js new file mode 100644 index 000000000..85fc94969 --- /dev/null +++ b/src/slang-nodes/FunctionBody.js @@ -0,0 +1,14 @@ +export const FunctionBody = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + + variant: + ast.variant.type === 'Token' + ? ast.variant.text + : parse(ast.variant, options, parse) + }), + print: ({ node, path, print }) => + typeof node.variant === 'string' + ? node.variant + : path.call(print, 'variant') +}; diff --git a/src/slang-nodes/FunctionCallExpression.js b/src/slang-nodes/FunctionCallExpression.js new file mode 100644 index 000000000..2348c1df5 --- /dev/null +++ b/src/slang-nodes/FunctionCallExpression.js @@ -0,0 +1,9 @@ +export const FunctionCallExpression = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + operand: parse(ast.operand, options, parse), + arguments: parse(ast.arguments, options, parse) + }), + // TODO: implement print + print: () => ['FunctionCallExpression'] +}; diff --git a/src/slang-nodes/FunctionDefinition.js b/src/slang-nodes/FunctionDefinition.js new file mode 100644 index 000000000..c7f053728 --- /dev/null +++ b/src/slang-nodes/FunctionDefinition.js @@ -0,0 +1,13 @@ +export const FunctionDefinition = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + functionKeyword: ast.functionKeyword.text, + name: parse(ast.name, options, parse), + parameters: parse(ast.parameters, options, parse), + attributes: parse(ast.attributes, options, parse), + returns: ast.returns ? parse(ast.returns, options, parse) : undefined, + body: parse(ast.body, options, parse) + }), + // TODO: implement print + print: () => ['FunctionDefinition'] +}; diff --git a/src/slang-nodes/FunctionName.js b/src/slang-nodes/FunctionName.js new file mode 100644 index 000000000..e68c57929 --- /dev/null +++ b/src/slang-nodes/FunctionName.js @@ -0,0 +1,7 @@ +export const FunctionName = { + parse: ({ ast }) => ({ + kind: ast.cst.kind, + variant: ast.variant.text + }), + print: ({ node }) => node.variant +}; diff --git a/src/slang-nodes/FunctionType.js b/src/slang-nodes/FunctionType.js new file mode 100644 index 000000000..dbfcdc31c --- /dev/null +++ b/src/slang-nodes/FunctionType.js @@ -0,0 +1,11 @@ +export const FunctionType = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + functionKeyword: ast.functionKeyword.text, + parameters: parse(ast.parameters, options, parse), + attributes: parse(ast.attributes, options, parse), + returns: ast.returns ? parse(ast.returns, options, parse) : undefined + }), + // TODO: implement print + print: () => ['FunctionType'] +}; diff --git a/src/slang-nodes/FunctionTypeAttribute.js b/src/slang-nodes/FunctionTypeAttribute.js new file mode 100644 index 000000000..162bfb050 --- /dev/null +++ b/src/slang-nodes/FunctionTypeAttribute.js @@ -0,0 +1,7 @@ +export const FunctionTypeAttribute = { + parse: ({ ast }) => ({ + kind: ast.cst.kind, + variant: ast.variant.text + }), + print: ({ node }) => node.variant +}; diff --git a/src/slang-nodes/FunctionTypeAttributes.js b/src/slang-nodes/FunctionTypeAttributes.js new file mode 100644 index 000000000..176694ff9 --- /dev/null +++ b/src/slang-nodes/FunctionTypeAttributes.js @@ -0,0 +1,8 @@ +export const FunctionTypeAttributes = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item, options, parse)) + }), + // TODO: implement print + print: () => ['FunctionTypeAttributes'] +}; diff --git a/src/slang-nodes/HexNumberExpression.js b/src/slang-nodes/HexNumberExpression.js new file mode 100644 index 000000000..02812f72b --- /dev/null +++ b/src/slang-nodes/HexNumberExpression.js @@ -0,0 +1,9 @@ +export const HexNumberExpression = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + literal: ast.literal.text, + unit: ast.unit ? parse(ast.unit, options, parse) : undefined + }), + // TODO: implement print + print: () => ['HexNumberExpression'] +}; diff --git a/src/slang-nodes/HexStringLiteral.js b/src/slang-nodes/HexStringLiteral.js new file mode 100644 index 000000000..933ea6fd0 --- /dev/null +++ b/src/slang-nodes/HexStringLiteral.js @@ -0,0 +1,7 @@ +export const HexStringLiteral = { + parse: ({ ast }) => ({ + kind: ast.cst.kind, + variant: ast.variant.text + }), + print: ({ node }) => node.variant +}; diff --git a/src/slang-nodes/HexStringLiterals.js b/src/slang-nodes/HexStringLiterals.js new file mode 100644 index 000000000..e674c4d94 --- /dev/null +++ b/src/slang-nodes/HexStringLiterals.js @@ -0,0 +1,8 @@ +export const HexStringLiterals = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item, options, parse)) + }), + // TODO: implement print + print: () => ['HexStringLiterals'] +}; diff --git a/src/slang-nodes/IdentifierPath.js b/src/slang-nodes/IdentifierPath.js new file mode 100644 index 000000000..cd5774b5f --- /dev/null +++ b/src/slang-nodes/IdentifierPath.js @@ -0,0 +1,9 @@ +export const IdentifierPath = { + parse: ({ ast }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => item.text), + separators: ast.separators.map((separator) => separator.text) + }), + // TODO: implement print + print: () => ['IdentifierPath'] +}; diff --git a/src/slang-nodes/IfStatement.js b/src/slang-nodes/IfStatement.js new file mode 100644 index 000000000..14ee0e0f0 --- /dev/null +++ b/src/slang-nodes/IfStatement.js @@ -0,0 +1,15 @@ +export const IfStatement = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + ifKeyword: ast.ifKeyword.text, + openParen: ast.openParen.text, + condition: parse(ast.condition, options, parse), + closeParen: ast.closeParen.text, + body: parse(ast.body, options, parse), + elseBranch: ast.elseBranch + ? parse(ast.elseBranch, options, parse) + : undefined + }), + // TODO: implement print + print: () => ['IfStatement'] +}; diff --git a/src/slang-nodes/ImportAlias.js b/src/slang-nodes/ImportAlias.js new file mode 100644 index 000000000..b438e899a --- /dev/null +++ b/src/slang-nodes/ImportAlias.js @@ -0,0 +1,9 @@ +export const ImportAlias = { + parse: ({ ast }) => ({ + kind: ast.cst.kind, + asKeyword: ast.asKeyword.text, + identifier: ast.identifier.text + }), + // TODO: implement print + print: () => ['ImportAlias'] +}; diff --git a/src/slang-nodes/ImportClause.js b/src/slang-nodes/ImportClause.js new file mode 100644 index 000000000..0819567c1 --- /dev/null +++ b/src/slang-nodes/ImportClause.js @@ -0,0 +1,7 @@ +export const ImportClause = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + variant: parse(ast.variant, options, parse) + }), + print: ({ path, print }) => path.call(print, 'variant') +}; diff --git a/src/slang-nodes/ImportDeconstruction.js b/src/slang-nodes/ImportDeconstruction.js new file mode 100644 index 000000000..e55789b07 --- /dev/null +++ b/src/slang-nodes/ImportDeconstruction.js @@ -0,0 +1,12 @@ +export const ImportDeconstruction = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + openBrace: ast.openBrace.text, + symbols: parse(ast.symbols, options, parse), + closeBrace: ast.closeBrace.text, + fromKeyword: ast.fromKeyword.text, + path: parse(ast.path, options, parse) + }), + // TODO: implement print + print: () => ['ImportDeconstruction'] +}; diff --git a/src/slang-nodes/ImportDeconstructionSymbol.js b/src/slang-nodes/ImportDeconstructionSymbol.js new file mode 100644 index 000000000..0ddcfe435 --- /dev/null +++ b/src/slang-nodes/ImportDeconstructionSymbol.js @@ -0,0 +1,9 @@ +export const ImportDeconstructionSymbol = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + name: ast.name.text, + alias: ast.alias ? parse(ast.alias, options, parse) : undefined + }), + // TODO: implement print + print: () => ['ImportDeconstructionSymbol'] +}; diff --git a/src/slang-nodes/ImportDeconstructionSymbols.js b/src/slang-nodes/ImportDeconstructionSymbols.js new file mode 100644 index 000000000..c4bea2f5b --- /dev/null +++ b/src/slang-nodes/ImportDeconstructionSymbols.js @@ -0,0 +1,9 @@ +export const ImportDeconstructionSymbols = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item, options, parse)), + separators: ast.separators.map((separator) => separator.text) + }), + // TODO: implement print + print: () => ['ImportDeconstructionSymbols'] +}; diff --git a/src/slang-nodes/ImportDirective.js b/src/slang-nodes/ImportDirective.js new file mode 100644 index 000000000..0de38d8ec --- /dev/null +++ b/src/slang-nodes/ImportDirective.js @@ -0,0 +1,10 @@ +export const ImportDirective = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + importKeyword: ast.importKeyword.text, + clause: parse(ast.clause, options, parse), + semicolon: ast.semicolon.text + }), + // TODO: implement print + print: () => ['ImportDirective'] +}; diff --git a/src/slang-nodes/IndexAccessEnd.js b/src/slang-nodes/IndexAccessEnd.js new file mode 100644 index 000000000..c5c7c6111 --- /dev/null +++ b/src/slang-nodes/IndexAccessEnd.js @@ -0,0 +1,9 @@ +export const IndexAccessEnd = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + colon: ast.colon.text, + end: ast.end ? parse(ast.end, options, parse) : undefined + }), + // TODO: implement print + print: () => ['IndexAccessEnd'] +}; diff --git a/src/slang-nodes/IndexAccessExpression.js b/src/slang-nodes/IndexAccessExpression.js new file mode 100644 index 000000000..f8331349b --- /dev/null +++ b/src/slang-nodes/IndexAccessExpression.js @@ -0,0 +1,12 @@ +export const IndexAccessExpression = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + operand: parse(ast.operand, options, parse), + openBracket: ast.openBracket.text, + start: ast.start ? parse(ast.start, options, parse) : undefined, + end: ast.end ? parse(ast.end, options, parse) : undefined, + closeBracket: ast.closeBracket.text + }), + // TODO: implement print + print: () => ['IndexAccessExpression'] +}; diff --git a/src/slang-nodes/InheritanceSpecifier.js b/src/slang-nodes/InheritanceSpecifier.js new file mode 100644 index 000000000..884d21e8e --- /dev/null +++ b/src/slang-nodes/InheritanceSpecifier.js @@ -0,0 +1,9 @@ +export const InheritanceSpecifier = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + isKeyword: ast.isKeyword.text, + types: parse(ast.types, options, parse) + }), + // TODO: implement print + print: () => ['InheritanceSpecifier'] +}; diff --git a/src/slang-nodes/InheritanceType.js b/src/slang-nodes/InheritanceType.js new file mode 100644 index 000000000..1ef3489cc --- /dev/null +++ b/src/slang-nodes/InheritanceType.js @@ -0,0 +1,9 @@ +export const InheritanceType = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + typeName: parse(ast.typeName, options, parse), + arguments: ast.arguments ? parse(ast.arguments, options, parse) : undefined + }), + // TODO: implement print + print: () => ['InheritanceType'] +}; diff --git a/src/slang-nodes/InheritanceTypes.js b/src/slang-nodes/InheritanceTypes.js new file mode 100644 index 000000000..24d1ec8d0 --- /dev/null +++ b/src/slang-nodes/InheritanceTypes.js @@ -0,0 +1,9 @@ +export const InheritanceTypes = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item.text, options, parse)), + separators: ast.separators.map((separator) => separator.text) + }), + // TODO: implement print + print: () => ['InheritanceTypes'] +}; diff --git a/src/slang-nodes/InterfaceDefinition.js b/src/slang-nodes/InterfaceDefinition.js new file mode 100644 index 000000000..7496618f2 --- /dev/null +++ b/src/slang-nodes/InterfaceDefinition.js @@ -0,0 +1,15 @@ +export const InterfaceDefinition = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + interfaceKeyword: ast.interfaceKeyword.text, + name: ast.name.text, + inheritence: ast.inheritence + ? parse(ast.inheritence, options, parse) + : undefined, + openBrace: ast.openBrace.text, + members: parse(ast.members, options, parse), + closeBrace: ast.closeBrace.text + }), + // TODO: implement print + print: () => ['InterfaceDefinition'] +}; diff --git a/src/slang-nodes/InterfaceMembers.js b/src/slang-nodes/InterfaceMembers.js new file mode 100644 index 000000000..ff9694e95 --- /dev/null +++ b/src/slang-nodes/InterfaceMembers.js @@ -0,0 +1,9 @@ +export const InterfaceMembers = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + isKeyword: ast.isKeyword.text, + types: parse(ast.types, options, parse) + }), + // TODO: implement print + print: () => ['InterfaceMembers'] +}; diff --git a/src/slang-nodes/LibraryDefinition.js b/src/slang-nodes/LibraryDefinition.js new file mode 100644 index 000000000..5a65113a5 --- /dev/null +++ b/src/slang-nodes/LibraryDefinition.js @@ -0,0 +1,12 @@ +export const LibraryDefinition = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + libraryKeyword: ast.libraryKeyword.text, + name: ast.name.text, + openBrace: ast.openBrace.text, + members: parse(ast.members, options, parse), + closeBrace: ast.closeBrace.text + }), + // TODO: implement print + print: () => ['LibraryDefinition'] +}; diff --git a/src/slang-nodes/LibraryMembers.js b/src/slang-nodes/LibraryMembers.js new file mode 100644 index 000000000..6087b69b3 --- /dev/null +++ b/src/slang-nodes/LibraryMembers.js @@ -0,0 +1,8 @@ +export const LibraryMembers = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item, options, parse)) + }), + // TODO: implement print + print: () => ['LibraryMembers'] +}; diff --git a/src/slang-nodes/MappingKey.js b/src/slang-nodes/MappingKey.js new file mode 100644 index 000000000..4a3cb1054 --- /dev/null +++ b/src/slang-nodes/MappingKey.js @@ -0,0 +1,9 @@ +export const MappingKey = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + keyType: parse(ast.keyType, options, parse), + name: ast.name?.text + }), + // TODO: implement print + print: () => ['MappingKey'] +}; diff --git a/src/slang-nodes/MappingKeyType.js b/src/slang-nodes/MappingKeyType.js new file mode 100644 index 000000000..be8b4b960 --- /dev/null +++ b/src/slang-nodes/MappingKeyType.js @@ -0,0 +1,7 @@ +export const MappingKeyType = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + variant: parse(ast.variant, options, parse) + }), + print: ({ path, print }) => path.call(print, 'variant') +}; diff --git a/src/slang-nodes/MappingType.js b/src/slang-nodes/MappingType.js new file mode 100644 index 000000000..2b1f524f8 --- /dev/null +++ b/src/slang-nodes/MappingType.js @@ -0,0 +1,13 @@ +export const MappingType = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + mappingKeyword: ast.mappingKeyword.text, + openParen: ast.openParen.text, + keyType: parse(ast.keyType, options, parse), + equalGreaterThan: ast.equalGreaterThan.text, + valueType: parse(ast.valueType, options, parse), + closeParen: ast.closeParen.text + }), + // TODO: implement print + print: () => ['MappingType'] +}; diff --git a/src/slang-nodes/MappingValue.js b/src/slang-nodes/MappingValue.js new file mode 100644 index 000000000..304617c9e --- /dev/null +++ b/src/slang-nodes/MappingValue.js @@ -0,0 +1,9 @@ +export const MappingValue = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + typeName: parse(ast.typeName, options, parse), + name: ast.name?.text + }), + // TODO: implement print + print: () => ['MappingValue'] +}; diff --git a/src/slang-nodes/MemberAccess.js b/src/slang-nodes/MemberAccess.js new file mode 100644 index 000000000..d13f0e3a5 --- /dev/null +++ b/src/slang-nodes/MemberAccess.js @@ -0,0 +1,7 @@ +export const MemberAccess = { + parse: ({ ast }) => ({ + kind: ast.cst.kind, + variant: ast.variant.text + }), + print: ({ node }) => node.variant +}; diff --git a/src/slang-nodes/MemberAccessExpression.js b/src/slang-nodes/MemberAccessExpression.js new file mode 100644 index 000000000..e1f025ed4 --- /dev/null +++ b/src/slang-nodes/MemberAccessExpression.js @@ -0,0 +1,10 @@ +export const MemberAccessExpression = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + operand: parse(ast.operand, options, parse), + period: ast.period.text, + member: parse(ast.member, options, parse) + }), + // TODO: implement print + print: () => ['MemberAccessExpression'] +}; diff --git a/src/slang-nodes/ModifierInvocation.js b/src/slang-nodes/ModifierInvocation.js new file mode 100644 index 000000000..2c44e52c3 --- /dev/null +++ b/src/slang-nodes/ModifierInvocation.js @@ -0,0 +1,9 @@ +export const ModifierInvocation = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + name: parse(ast.name, options, parse), + arguments: ast.arguments ? parse(ast.arguments, options, parse) : undefined + }), + // TODO: implement print + print: () => ['ModifierInvocation'] +}; diff --git a/src/slang-nodes/MultiplicativeExpression.js b/src/slang-nodes/MultiplicativeExpression.js new file mode 100644 index 000000000..582d3706b --- /dev/null +++ b/src/slang-nodes/MultiplicativeExpression.js @@ -0,0 +1,10 @@ +export const MultiplicativeExpression = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + leftOperand: parse(ast.leftOperand, options, parse), + operator: ast.operator.text, + rightOperand: parse(ast.rightOperand, options, parse) + }), + // TODO: implement print + print: () => ['MultiplicativeExpression'] +}; diff --git a/src/slang-nodes/NamedArgument.js b/src/slang-nodes/NamedArgument.js new file mode 100644 index 000000000..4d1e9652a --- /dev/null +++ b/src/slang-nodes/NamedArgument.js @@ -0,0 +1,10 @@ +export const NamedArgument = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + name: ast.name.text, + colon: ast.colon.text, + value: parse(ast.value, options, parse) + }), + // TODO: implement print + print: () => ['NamedArgument'] +}; diff --git a/src/slang-nodes/NamedArgumentGroup.js b/src/slang-nodes/NamedArgumentGroup.js new file mode 100644 index 000000000..9efe19240 --- /dev/null +++ b/src/slang-nodes/NamedArgumentGroup.js @@ -0,0 +1,10 @@ +export const NamedArgumentGroup = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + openBrace: ast.openBrace.text, + arguments: parse(ast.arguments, options, parse), + closeBrace: ast.closeBrace.text + }), + // TODO: implement print + print: () => ['NamedArgumentGroup'] +}; diff --git a/src/slang-nodes/NamedArguments.js b/src/slang-nodes/NamedArguments.js new file mode 100644 index 000000000..3fac2f04a --- /dev/null +++ b/src/slang-nodes/NamedArguments.js @@ -0,0 +1,9 @@ +export const NamedArguments = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item, options, parse)), + separators: ast.separators.map((separator) => separator.text) + }), + // TODO: implement print + print: () => ['NamedArguments'] +}; diff --git a/src/slang-nodes/NamedArgumentsDeclaration.js b/src/slang-nodes/NamedArgumentsDeclaration.js new file mode 100644 index 000000000..9fbc632f8 --- /dev/null +++ b/src/slang-nodes/NamedArgumentsDeclaration.js @@ -0,0 +1,10 @@ +export const NamedArgumentsDeclaration = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + openParen: ast.openParen.text, + arguments: ast.arguments ? parse(ast.arguments, options, parse) : undefined, + closeParen: ast.closeParen.text + }), + // TODO: implement print + print: () => ['NamedArgumentsDeclaration'] +}; diff --git a/src/slang-nodes/NamedImport.js b/src/slang-nodes/NamedImport.js new file mode 100644 index 000000000..251bee917 --- /dev/null +++ b/src/slang-nodes/NamedImport.js @@ -0,0 +1,11 @@ +export const NamedImport = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + asterisk: ast.asterisk.text, + alias: parse(ast.alias, options, parse), + fromKeyword: ast.fromKeyword.text, + path: parse(ast.path, options, parse) + }), + // TODO: implement print + print: () => ['NamedImport'] +}; diff --git a/src/slang-nodes/NewExpression.js b/src/slang-nodes/NewExpression.js new file mode 100644 index 000000000..c19d3c6ea --- /dev/null +++ b/src/slang-nodes/NewExpression.js @@ -0,0 +1,9 @@ +export const NewExpression = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + newKeyword: ast.newKeyword.text, + typeName: parse(ast.typeName, options, parse) + }), + // TODO: implement print + print: () => ['NewExpression'] +}; diff --git a/src/slang-nodes/NumberUnit.js b/src/slang-nodes/NumberUnit.js new file mode 100644 index 000000000..69c9c909a --- /dev/null +++ b/src/slang-nodes/NumberUnit.js @@ -0,0 +1,7 @@ +export const NumberUnit = { + parse: ({ ast }) => ({ + kind: ast.cst.kind, + variant: ast.variant.text + }), + print: ({ node }) => node.variant +}; diff --git a/src/slang-nodes/OrExpression.js b/src/slang-nodes/OrExpression.js new file mode 100644 index 000000000..8c9184440 --- /dev/null +++ b/src/slang-nodes/OrExpression.js @@ -0,0 +1,10 @@ +export const OrExpression = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + leftOperand: parse(ast.leftOperand, options, parse), + operator: ast.operator.text, + rightOperand: parse(ast.rightOperand, options, parse) + }), + // TODO: implement print + print: () => ['OrExpression'] +}; diff --git a/src/slang-nodes/OverridePaths.js b/src/slang-nodes/OverridePaths.js new file mode 100644 index 000000000..e14c80cf2 --- /dev/null +++ b/src/slang-nodes/OverridePaths.js @@ -0,0 +1,9 @@ +export const OverridePaths = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item, options, parse)), + separators: ast.separators.map((separator) => separator) + }), + // TODO: implement print + print: () => ['OverridePaths'] +}; diff --git a/src/slang-nodes/OverridePathsDeclaration.js b/src/slang-nodes/OverridePathsDeclaration.js new file mode 100644 index 000000000..159268c69 --- /dev/null +++ b/src/slang-nodes/OverridePathsDeclaration.js @@ -0,0 +1,10 @@ +export const OverridePathsDeclaration = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + openParen: ast.openParen.text, + paths: parse(ast.paths, options, parse), + closeParen: ast.closeParen.text + }), + // TODO: implement print + print: () => ['OverridePathsDeclaration'] +}; diff --git a/src/slang-nodes/OverrideSpecifier.js b/src/slang-nodes/OverrideSpecifier.js new file mode 100644 index 000000000..c304fe2a0 --- /dev/null +++ b/src/slang-nodes/OverrideSpecifier.js @@ -0,0 +1,11 @@ +export const OverrideSpecifier = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + overrideKeyword: ast.overrideKeyword.text, + overridden: ast.overridden + ? parse(ast.overridden, options, parse) + : undefined + }), + // TODO: implement print + print: () => ['OverrideSpecifier'] +}; diff --git a/src/slang-nodes/Parameter.js b/src/slang-nodes/Parameter.js new file mode 100644 index 000000000..9c3fa18a8 --- /dev/null +++ b/src/slang-nodes/Parameter.js @@ -0,0 +1,12 @@ +export const Parameter = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + typeName: parse(ast.typeName, options, parse), + storageLocation: ast.storageLocation + ? parse(ast.storageLocation, options, parse) + : undefined, + name: ast.name?.text + }), + // TODO: implement print + print: () => ['Parameter'] +}; diff --git a/src/slang-nodes/Parameters.js b/src/slang-nodes/Parameters.js new file mode 100644 index 000000000..3cdaa5e57 --- /dev/null +++ b/src/slang-nodes/Parameters.js @@ -0,0 +1,9 @@ +export const Parameters = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item, options, parse)), + separators: ast.separators.map((separator) => separator.text) + }), + // TODO: implement print + print: () => ['Parameters'] +}; diff --git a/src/slang-nodes/ParametersDeclaration.js b/src/slang-nodes/ParametersDeclaration.js new file mode 100644 index 000000000..9b938e067 --- /dev/null +++ b/src/slang-nodes/ParametersDeclaration.js @@ -0,0 +1,10 @@ +export const ParametersDeclaration = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + openParen: ast.openParen.text, + parameters: parse(ast.parameters, options, parse), + closeParen: ast.closeParen.text + }), + // TODO: implement print + print: () => ['ParametersDeclaration'] +}; diff --git a/src/slang-nodes/PathImport.js b/src/slang-nodes/PathImport.js new file mode 100644 index 000000000..98b29651a --- /dev/null +++ b/src/slang-nodes/PathImport.js @@ -0,0 +1,9 @@ +export const PathImport = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + path: parse(ast.path, options, parse), + alias: ast.alias ? parse(ast.alias, options, parse) : undefined + }), + // TODO: implement print + print: () => ['PathImport'] +}; diff --git a/src/slang-nodes/PositionalArguments.js b/src/slang-nodes/PositionalArguments.js new file mode 100644 index 000000000..dbf13a984 --- /dev/null +++ b/src/slang-nodes/PositionalArguments.js @@ -0,0 +1,9 @@ +export const PositionalArguments = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item, options, parse)), + separators: ast.separators.map((separator) => separator.text) + }), + // TODO: implement print + print: () => ['PositionalArguments'] +}; diff --git a/src/slang-nodes/PositionalArgumentsDeclaration.js b/src/slang-nodes/PositionalArgumentsDeclaration.js new file mode 100644 index 000000000..50f2c631f --- /dev/null +++ b/src/slang-nodes/PositionalArgumentsDeclaration.js @@ -0,0 +1,10 @@ +export const PositionalArgumentsDeclaration = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + openParen: ast.openParen.TokenNode, + arguments: parse(ast.arguments, options, parse), + closeParen: ast.closeParen.TokenNode + }), + // TODO: implement print + print: () => ['PositionalArgumentsDeclaration'] +}; diff --git a/src/slang-nodes/PostfixExpression.js b/src/slang-nodes/PostfixExpression.js new file mode 100644 index 000000000..36065d69a --- /dev/null +++ b/src/slang-nodes/PostfixExpression.js @@ -0,0 +1,9 @@ +export const PostfixExpression = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + operand: parse(ast.operand, options, parse), + operator: ast.operator.text + }), + // TODO: implement print + print: () => ['PostfixExpression'] +}; diff --git a/src/slang-nodes/Pragma.js b/src/slang-nodes/Pragma.js new file mode 100644 index 000000000..821bfa207 --- /dev/null +++ b/src/slang-nodes/Pragma.js @@ -0,0 +1,7 @@ +export const Pragma = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + variant: parse(ast.variant, options, parse) + }), + print: ({ path, print }) => path.call(print, 'variant') +}; diff --git a/src/slang-nodes/PragmaDirective.js b/src/slang-nodes/PragmaDirective.js new file mode 100644 index 000000000..c0ecf362f --- /dev/null +++ b/src/slang-nodes/PragmaDirective.js @@ -0,0 +1,14 @@ +export const PragmaDirective = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + pragmaKeyword: ast.pragmaKeyword.text, + pragma: parse(ast.pragma, options, parse), + semicolon: ast.semicolon.text + }), + print: ({ node, path, print }) => [ + node.pragmaKeyword, + ' ', + path.call(print, 'pragma'), + node.semicolon + ] +}; diff --git a/src/slang-nodes/PrefixExpression.js b/src/slang-nodes/PrefixExpression.js new file mode 100644 index 000000000..1f88469c5 --- /dev/null +++ b/src/slang-nodes/PrefixExpression.js @@ -0,0 +1,9 @@ +export const PrefixExpression = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + operator: ast.operator.text, + operand: parse(ast.operand, options, parse) + }), + // TODO: implement print + print: () => ['PrefixExpression'] +}; diff --git a/src/slang-nodes/ReceiveFunctionAttribute.js b/src/slang-nodes/ReceiveFunctionAttribute.js new file mode 100644 index 000000000..81355f8b7 --- /dev/null +++ b/src/slang-nodes/ReceiveFunctionAttribute.js @@ -0,0 +1,13 @@ +export const ReceiveFunctionAttribute = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + variant: + ast.variant.type === 'Token' + ? ast.variant.text + : parse(ast.variant, options, parse) + }), + print: ({ node, path, print }) => + typeof node.variant === 'string' + ? node.variant + : path.call(print, 'variant') +}; diff --git a/src/slang-nodes/ReceiveFunctionAttributes.js b/src/slang-nodes/ReceiveFunctionAttributes.js new file mode 100644 index 000000000..64bc062a2 --- /dev/null +++ b/src/slang-nodes/ReceiveFunctionAttributes.js @@ -0,0 +1,8 @@ +export const ReceiveFunctionAttributes = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item, options, parse)) + }), + // TODO: implement print + print: () => ['ReceiveFunctionAttributes'] +}; diff --git a/src/slang-nodes/ReceiveFunctionDefinition.js b/src/slang-nodes/ReceiveFunctionDefinition.js new file mode 100644 index 000000000..ea5addb0e --- /dev/null +++ b/src/slang-nodes/ReceiveFunctionDefinition.js @@ -0,0 +1,11 @@ +export const ReceiveFunctionDefinition = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + receiveKeyword: ast.receiveKeyword.text, + parameters: parse(ast.parameters, options, parse), + attributes: parse(ast.attributes, options, parse), + body: parse(ast.body, options, parse) + }), + // TODO: implement print + print: () => ['ReceiveFunctionDefinition'] +}; diff --git a/src/slang-nodes/ReturnStatement.js b/src/slang-nodes/ReturnStatement.js new file mode 100644 index 000000000..34e276936 --- /dev/null +++ b/src/slang-nodes/ReturnStatement.js @@ -0,0 +1,12 @@ +export const ReturnStatement = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + returnKeyword: ast.returnKeyword.text, + expression: ast.expression + ? parse(ast.expression, options, parse) + : undefined, + semicolon: ast.semicolon.text + }), + // TODO: implement print + print: () => ['ReturnStatement'] +}; diff --git a/src/slang-nodes/ReturnsDeclaration.js b/src/slang-nodes/ReturnsDeclaration.js new file mode 100644 index 000000000..46f74b7ad --- /dev/null +++ b/src/slang-nodes/ReturnsDeclaration.js @@ -0,0 +1,9 @@ +export const ReturnsDeclaration = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + returnsKeyword: ast.returnsKeyword, + variables: parse(ast.variables, options, parse) + }), + // TODO: implement print + print: () => ['ReturnsDeclaration'] +}; diff --git a/src/slang-nodes/RevertStatement.js b/src/slang-nodes/RevertStatement.js new file mode 100644 index 000000000..91b3b165c --- /dev/null +++ b/src/slang-nodes/RevertStatement.js @@ -0,0 +1,11 @@ +export const RevertStatement = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + revertKeyword: ast.revertKeyword.text, + error: ast.error ? parse(ast.error, options, parse) : undefined, + arguments: parse(ast.arguments, options, parse), + semicolon: ast.semicolon.text + }), + // TODO: implement print + print: () => ['RevertStatement'] +}; diff --git a/src/slang-nodes/ShiftExpression.js b/src/slang-nodes/ShiftExpression.js new file mode 100644 index 000000000..0481fb86f --- /dev/null +++ b/src/slang-nodes/ShiftExpression.js @@ -0,0 +1,10 @@ +export const ShiftExpression = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + leftOperand: parse(ast.leftOperand, options, parse), + operator: ast.operator.text, + rightOperand: parse(ast.rightOperand, options, parse) + }), + // TODO: implement print + print: () => ['ShiftExpression'] +}; diff --git a/src/slang-nodes/SourceUnit.js b/src/slang-nodes/SourceUnit.js new file mode 100644 index 000000000..29acacd2e --- /dev/null +++ b/src/slang-nodes/SourceUnit.js @@ -0,0 +1,14 @@ +import { doc } from 'prettier'; + +const { line } = doc.builders; + +export const SourceUnit = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + members: parse(ast.members, options, parse) + }), + print: ({ options, path, print }) => [ + path.call(print, 'members'), + options.parentParser ? '' : line + ] +}; diff --git a/src/slang-nodes/SourceUnitMember.js b/src/slang-nodes/SourceUnitMember.js new file mode 100644 index 000000000..760cbd80d --- /dev/null +++ b/src/slang-nodes/SourceUnitMember.js @@ -0,0 +1,7 @@ +export const SourceUnitMember = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + variant: parse(ast.variant, options, parse) + }), + print: ({ path, print }) => path.call(print, 'variant') +}; diff --git a/src/slang-nodes/SourceUnitMembers.js b/src/slang-nodes/SourceUnitMembers.js new file mode 100644 index 000000000..1bf8f406f --- /dev/null +++ b/src/slang-nodes/SourceUnitMembers.js @@ -0,0 +1,10 @@ +import { printPreservingEmptyLines } from '../common/printer-helpers.js'; + +export const SourceUnitMembers = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item, options, parse)) + }), + print: ({ path, options, print }) => + printPreservingEmptyLines(path, 'items', options, print) +}; diff --git a/src/slang-nodes/StateVariableAttribute.js b/src/slang-nodes/StateVariableAttribute.js new file mode 100644 index 000000000..8002e595c --- /dev/null +++ b/src/slang-nodes/StateVariableAttribute.js @@ -0,0 +1,13 @@ +export const StateVariableAttribute = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + variant: + ast.variant.type === 'Token' + ? ast.variant.text + : parse(ast.variant, options, parse) + }), + print: ({ node, path, print }) => + typeof node.variant === 'string' + ? node.variant + : path.call(print, 'variant') +}; diff --git a/src/slang-nodes/StateVariableAttributes.js b/src/slang-nodes/StateVariableAttributes.js new file mode 100644 index 000000000..3e36c392c --- /dev/null +++ b/src/slang-nodes/StateVariableAttributes.js @@ -0,0 +1,8 @@ +export const StateVariableAttributes = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item, options, parse)) + }), + // TODO: implement print + print: () => ['StateVariableAttributes'] +}; diff --git a/src/slang-nodes/StateVariableDefinition.js b/src/slang-nodes/StateVariableDefinition.js new file mode 100644 index 000000000..8a96d991f --- /dev/null +++ b/src/slang-nodes/StateVariableDefinition.js @@ -0,0 +1,12 @@ +export const StateVariableDefinition = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + typeName: parse(ast.typeName, options, parse), + attributes: parse(ast.attributes, options, parse), + name: ast.name.text, + value: ast.value ? parse(ast.value, options, parse) : undefined, + semicolon: ast.semicolon.text + }), + // TODO: implement print + print: () => ['StateVariableDefinition'] +}; diff --git a/src/slang-nodes/StateVariableDefinitionValue.js b/src/slang-nodes/StateVariableDefinitionValue.js new file mode 100644 index 000000000..d6c081fbb --- /dev/null +++ b/src/slang-nodes/StateVariableDefinitionValue.js @@ -0,0 +1,9 @@ +export const StateVariableDefinitionValue = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + equal: ast.equal.text, + value: parse(ast.value, options, parse) + }), + // TODO: implement print + print: () => ['StateVariableDefinitionValue'] +}; diff --git a/src/slang-nodes/Statement.js b/src/slang-nodes/Statement.js new file mode 100644 index 000000000..80bc079d8 --- /dev/null +++ b/src/slang-nodes/Statement.js @@ -0,0 +1,7 @@ +export const Statement = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + variant: parse(ast.variant, options, parse) + }), + print: ({ path, print }) => path.call(print, 'variant') +}; diff --git a/src/slang-nodes/Statements.js b/src/slang-nodes/Statements.js new file mode 100644 index 000000000..ab41a6d24 --- /dev/null +++ b/src/slang-nodes/Statements.js @@ -0,0 +1,8 @@ +export const Statements = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item, options, parse)) + }), + // TODO: implement print + print: () => ['Statements'] +}; diff --git a/src/slang-nodes/StorageLocation.js b/src/slang-nodes/StorageLocation.js new file mode 100644 index 000000000..fe9a825ad --- /dev/null +++ b/src/slang-nodes/StorageLocation.js @@ -0,0 +1,7 @@ +export const StorageLocation = { + parse: ({ ast }) => ({ + kind: ast.cst.kind, + variant: ast.variant.text + }), + print: ({ node }) => node.variant +}; diff --git a/src/slang-nodes/StringExpression.js b/src/slang-nodes/StringExpression.js new file mode 100644 index 000000000..884eefba7 --- /dev/null +++ b/src/slang-nodes/StringExpression.js @@ -0,0 +1,7 @@ +export const StringExpression = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + variant: parse(ast.variant, options, parse) + }), + print: ({ path, print }) => path.call(print, 'variant') +}; diff --git a/src/slang-nodes/StringLiteral.js b/src/slang-nodes/StringLiteral.js new file mode 100644 index 000000000..2080b847f --- /dev/null +++ b/src/slang-nodes/StringLiteral.js @@ -0,0 +1,7 @@ +export const StringLiteral = { + parse: ({ ast }) => ({ + kind: ast.cst.kind, + variant: ast.variant.text + }), + print: ({ node }) => node.variant +}; diff --git a/src/slang-nodes/StringLiterals.js b/src/slang-nodes/StringLiterals.js new file mode 100644 index 000000000..1b6be2ed9 --- /dev/null +++ b/src/slang-nodes/StringLiterals.js @@ -0,0 +1,8 @@ +export const StringLiterals = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item, options, parse)) + }), + // TODO: implement print + print: () => ['StringLiterals'] +}; diff --git a/src/slang-nodes/StructDefinition.js b/src/slang-nodes/StructDefinition.js new file mode 100644 index 000000000..85cc79050 --- /dev/null +++ b/src/slang-nodes/StructDefinition.js @@ -0,0 +1,12 @@ +export const StructDefinition = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + structKeyword: ast.structKeyword.text, + name: ast.name.text, + openBrace: ast.openBrace.text, + members: parse(ast.members, options, parse), + closeBrace: ast.closeBrace.text + }), + // TODO: implement print + print: () => ['StructDefinition'] +}; diff --git a/src/slang-nodes/StructMember.js b/src/slang-nodes/StructMember.js new file mode 100644 index 000000000..b8b95c03a --- /dev/null +++ b/src/slang-nodes/StructMember.js @@ -0,0 +1,10 @@ +export const StructMember = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + typeName: parse(ast.typeName, options, parse), + name: ast.name.text, + semicolon: ast.semicolon.text + }), + // TODO: implement print + print: () => ['StructMember'] +}; diff --git a/src/slang-nodes/StructMembers.js b/src/slang-nodes/StructMembers.js new file mode 100644 index 000000000..f3baf9d74 --- /dev/null +++ b/src/slang-nodes/StructMembers.js @@ -0,0 +1,8 @@ +export const StructMembers = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item, options, parse)) + }), + // TODO: implement print + print: () => ['StructMembers'] +}; diff --git a/src/slang-nodes/ThrowStatement.js b/src/slang-nodes/ThrowStatement.js new file mode 100644 index 000000000..dedc7c00f --- /dev/null +++ b/src/slang-nodes/ThrowStatement.js @@ -0,0 +1,9 @@ +export const ThrowStatement = { + parse: ({ ast }) => ({ + kind: ast.cst.kind, + throwKeyword: ast.throwKeyword.text, + semicolon: ast.semicolon.text + }), + // TODO: implement print + print: () => ['ThrowStatement'] +}; diff --git a/src/slang-nodes/TryStatement.js b/src/slang-nodes/TryStatement.js new file mode 100644 index 000000000..89bde2649 --- /dev/null +++ b/src/slang-nodes/TryStatement.js @@ -0,0 +1,12 @@ +export const TryStatement = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + tryKeyword: ast.tryKeyword.text, + expression: parse(ast.expression, options, parse), + returns: ast.returns ? parse(ast.returns, options, parse) : undefined, + body: parse(ast.body, options, parse), + catchClauses: parse(ast.catchClauses, options, parse) + }), + // TODO: implement print + print: () => ['TryStatement'] +}; diff --git a/src/slang-nodes/TupleDeconstructionElement.js b/src/slang-nodes/TupleDeconstructionElement.js new file mode 100644 index 000000000..65e85ae08 --- /dev/null +++ b/src/slang-nodes/TupleDeconstructionElement.js @@ -0,0 +1,8 @@ +export const TupleDeconstructionElement = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + member: ast.member ? parse(ast.member, options, parse) : undefined + }), + // TODO: implement print + print: () => ['TupleDeconstructionElement'] +}; diff --git a/src/slang-nodes/TupleDeconstructionElements.js b/src/slang-nodes/TupleDeconstructionElements.js new file mode 100644 index 000000000..5f453b6a6 --- /dev/null +++ b/src/slang-nodes/TupleDeconstructionElements.js @@ -0,0 +1,9 @@ +export const TupleDeconstructionElements = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item, options, parse)), + separators: ast.separators.map((separator) => separator.text) + }), + // TODO: implement print + print: () => ['TupleDeconstructionElements'] +}; diff --git a/src/slang-nodes/TupleDeconstructionStatement.js b/src/slang-nodes/TupleDeconstructionStatement.js new file mode 100644 index 000000000..675e0796e --- /dev/null +++ b/src/slang-nodes/TupleDeconstructionStatement.js @@ -0,0 +1,14 @@ +export const TupleDeconstructionStatement = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + varKeyword: ast.varKeyword?.text, + openParen: ast.openParen.text, + elements: parse(ast.elements, options, parse), + closeParen: ast.closeParen.text, + equal: ast.equal.text, + expression: parse(ast.expression, options, parse), + semicolon: ast.semicolon.text + }), + // TODO: implement print + print: () => ['TupleDeconstructionStatement'] +}; diff --git a/src/slang-nodes/TupleExpression.js b/src/slang-nodes/TupleExpression.js new file mode 100644 index 000000000..8f8a68618 --- /dev/null +++ b/src/slang-nodes/TupleExpression.js @@ -0,0 +1,10 @@ +export const TupleExpression = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + openParen: ast.openParen.text, + items: parse(ast.items, options, parse), + closeParen: ast.closeParen.text + }), + // TODO: implement print + print: () => ['TupleExpression'] +}; diff --git a/src/slang-nodes/TupleMember.js b/src/slang-nodes/TupleMember.js new file mode 100644 index 000000000..33dadbf32 --- /dev/null +++ b/src/slang-nodes/TupleMember.js @@ -0,0 +1,7 @@ +export const TupleMember = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + variant: parse(ast.variant, options, parse) + }), + print: ({ path, print }) => path.call(print, 'variant') +}; diff --git a/src/slang-nodes/TupleValue.js b/src/slang-nodes/TupleValue.js new file mode 100644 index 000000000..5a7d88aa9 --- /dev/null +++ b/src/slang-nodes/TupleValue.js @@ -0,0 +1,10 @@ +export const TupleValue = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + expression: ast.expression + ? parse(ast.expression, options, parse) + : undefined + }), + // TODO: implement print + print: () => ['TupleValue'] +}; diff --git a/src/slang-nodes/TupleValues.js b/src/slang-nodes/TupleValues.js new file mode 100644 index 000000000..e417af5ef --- /dev/null +++ b/src/slang-nodes/TupleValues.js @@ -0,0 +1,9 @@ +export const TupleValues = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item, options, parse)), + separators: ast.separators.map((separator) => separator.text) + }), + // TODO: implement print + print: () => ['TupleValues'] +}; diff --git a/src/slang-nodes/TypeExpression.js b/src/slang-nodes/TypeExpression.js new file mode 100644 index 000000000..ba99e4252 --- /dev/null +++ b/src/slang-nodes/TypeExpression.js @@ -0,0 +1,11 @@ +export const TypeExpression = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + typeKeyword: ast.typeKeyword.text, + openParen: ast.openParen.text, + typeName: parse(ast.typeName, options, parse), + closeParen: ast.closeParen.text + }), + // TODO: implement print + print: () => ['TypeExpression'] +}; diff --git a/src/slang-nodes/TypeName.js b/src/slang-nodes/TypeName.js new file mode 100644 index 000000000..f87dfbfd0 --- /dev/null +++ b/src/slang-nodes/TypeName.js @@ -0,0 +1,7 @@ +export const TypeName = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + variant: parse(ast.variant, options, parse) + }), + print: ({ path, print }) => path.call(print, 'variant') +}; diff --git a/src/slang-nodes/TypedTupleMember.js b/src/slang-nodes/TypedTupleMember.js new file mode 100644 index 000000000..c29423a80 --- /dev/null +++ b/src/slang-nodes/TypedTupleMember.js @@ -0,0 +1,12 @@ +export const TypedTupleMember = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + typeName: parse(ast.typeName, options, parse), + storageLocation: ast.storageLocation + ? parse(ast.storageLocation, options, parse) + : undefined, + name: ast.name.text + }), + // TODO: implement print + print: () => ['TypedTupleMember'] +}; diff --git a/src/slang-nodes/UncheckedBlock.js b/src/slang-nodes/UncheckedBlock.js new file mode 100644 index 000000000..e5d5e66b5 --- /dev/null +++ b/src/slang-nodes/UncheckedBlock.js @@ -0,0 +1,9 @@ +export const UncheckedBlock = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + uncheckedKeyword: ast.uncheckedKeyword.text, + block: parse(ast.block, options, parse) + }), + // TODO: implement print + print: () => ['UncheckedBlock'] +}; diff --git a/src/slang-nodes/UnicodeStringLiteral.js b/src/slang-nodes/UnicodeStringLiteral.js new file mode 100644 index 000000000..32e1fc458 --- /dev/null +++ b/src/slang-nodes/UnicodeStringLiteral.js @@ -0,0 +1,7 @@ +export const UnicodeStringLiteral = { + parse: ({ ast }) => ({ + kind: ast.cst.kind, + variant: ast.variant.text + }), + print: ({ node }) => node.variant +}; diff --git a/src/slang-nodes/UnicodeStringLiterals.js b/src/slang-nodes/UnicodeStringLiterals.js new file mode 100644 index 000000000..a3f4b0924 --- /dev/null +++ b/src/slang-nodes/UnicodeStringLiterals.js @@ -0,0 +1,8 @@ +export const UnicodeStringLiterals = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item, options, parse)) + }), + // TODO: implement print + print: () => ['UnicodeStringLiterals'] +}; diff --git a/src/slang-nodes/UnnamedFunctionAttribute.js b/src/slang-nodes/UnnamedFunctionAttribute.js new file mode 100644 index 000000000..537161b10 --- /dev/null +++ b/src/slang-nodes/UnnamedFunctionAttribute.js @@ -0,0 +1,13 @@ +export const UnnamedFunctionAttribute = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + variant: + ast.variant.type === 'Token' + ? ast.variant.text + : parse(ast.variant, options, parse) + }), + print: ({ node, path, print }) => + typeof node.variant === 'string' + ? node.variant + : path.call(print, 'variant') +}; diff --git a/src/slang-nodes/UnnamedFunctionAttributes.js b/src/slang-nodes/UnnamedFunctionAttributes.js new file mode 100644 index 000000000..2e62c5104 --- /dev/null +++ b/src/slang-nodes/UnnamedFunctionAttributes.js @@ -0,0 +1,8 @@ +export const UnnamedFunctionAttributes = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item, options, parse)) + }), + // TODO: implement print + print: () => ['UnnamedFunctionAttributes'] +}; diff --git a/src/slang-nodes/UnnamedFunctionDefinition.js b/src/slang-nodes/UnnamedFunctionDefinition.js new file mode 100644 index 000000000..cefe7e0af --- /dev/null +++ b/src/slang-nodes/UnnamedFunctionDefinition.js @@ -0,0 +1,11 @@ +export const UnnamedFunctionDefinition = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + functionKeyword: ast.functionKeyword.text, + parameters: parse(ast.parameters, options, parse), + attributes: parse(ast.attributes, options, parse), + body: parse(ast.body, options, parse) + }), + // TODO: implement print + print: () => ['UnnamedFunctionDefinition'] +}; diff --git a/src/slang-nodes/UntypedTupleMember.js b/src/slang-nodes/UntypedTupleMember.js new file mode 100644 index 000000000..9b1bb5335 --- /dev/null +++ b/src/slang-nodes/UntypedTupleMember.js @@ -0,0 +1,11 @@ +export const UntypedTupleMember = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + storageLocation: ast.storageLocation + ? parse(ast.storageLocation, options, parse) + : undefined, + name: ast.name.text + }), + // TODO: implement print + print: () => ['UntypedTupleMemberUntypedTupleMember'] +}; diff --git a/src/slang-nodes/UserDefinedValueTypeDefinition.js b/src/slang-nodes/UserDefinedValueTypeDefinition.js new file mode 100644 index 000000000..c184c8bb5 --- /dev/null +++ b/src/slang-nodes/UserDefinedValueTypeDefinition.js @@ -0,0 +1,12 @@ +export const UserDefinedValueTypeDefinition = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + typeKeyword: ast.typeKeyword.text, + name: ast.name.text, + isKeyword: ast.isKeyword.text, + valueType: parse(ast.valueType, options, parse), + semicolon: ast.semicolon.text + }), + // TODO: implement print + print: () => ['UserDefinedValueTypeDefinition'] +}; diff --git a/src/slang-nodes/UsingAlias.js b/src/slang-nodes/UsingAlias.js new file mode 100644 index 000000000..4ffed8329 --- /dev/null +++ b/src/slang-nodes/UsingAlias.js @@ -0,0 +1,9 @@ +export const UsingAlias = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + asKeyword: ast.asKeyword.text, + operator: parse(ast.operator, options, parse) + }), + // TODO: implement print + print: () => ['UsingAlias'] +}; diff --git a/src/slang-nodes/UsingClause.js b/src/slang-nodes/UsingClause.js new file mode 100644 index 000000000..98f1647a9 --- /dev/null +++ b/src/slang-nodes/UsingClause.js @@ -0,0 +1,7 @@ +export const UsingClause = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + variant: parse(ast.variant, options, parse) + }), + print: ({ path, print }) => path.call(print, 'variant') +}; diff --git a/src/slang-nodes/UsingDeconstruction.js b/src/slang-nodes/UsingDeconstruction.js new file mode 100644 index 000000000..5622d4def --- /dev/null +++ b/src/slang-nodes/UsingDeconstruction.js @@ -0,0 +1,10 @@ +export const UsingDeconstruction = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + openBrace: ast.openBrace.text, + symbols: parse(ast.symbols, options, parse), + closeBrace: ast.closeBrace.text + }), + // TODO: implement print + print: () => ['UsingDeconstruction'] +}; diff --git a/src/slang-nodes/UsingDeconstructionSymbol.js b/src/slang-nodes/UsingDeconstructionSymbol.js new file mode 100644 index 000000000..e897ef60d --- /dev/null +++ b/src/slang-nodes/UsingDeconstructionSymbol.js @@ -0,0 +1,9 @@ +export const UsingDeconstructionSymbol = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + name: parse(ast.name, options, parse), + alias: ast.alias ? parse(ast.alias, options, parse) : undefined + }), + // TODO: implement print + print: () => ['UsingDeconstructionSymbol'] +}; diff --git a/src/slang-nodes/UsingDeconstructionSymbols.js b/src/slang-nodes/UsingDeconstructionSymbols.js new file mode 100644 index 000000000..bf568d552 --- /dev/null +++ b/src/slang-nodes/UsingDeconstructionSymbols.js @@ -0,0 +1,9 @@ +export const UsingDeconstructionSymbols = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item, options, parse)), + separators: ast.separators.map((separator) => separator.text) + }), + // TODO: implement print + print: () => ['UsingDeconstructionSymbols'] +}; diff --git a/src/slang-nodes/UsingDirective.js b/src/slang-nodes/UsingDirective.js new file mode 100644 index 000000000..c4dc4aa9e --- /dev/null +++ b/src/slang-nodes/UsingDirective.js @@ -0,0 +1,13 @@ +export const UsingDirective = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + usingKeyword: ast.usingKeyword.text, + clause: parse(ast.clause, options, parse), + forKeyword: ast.forKeyword.text, + target: parse(ast.target, options, parse), + globalKeyword: ast.globalKeyword?.text, + semicolon: ast.semicolon.text + }), + // TODO: implement print + print: () => ['UsingDirective'] +}; diff --git a/src/slang-nodes/UsingOperator.js b/src/slang-nodes/UsingOperator.js new file mode 100644 index 000000000..48336ac14 --- /dev/null +++ b/src/slang-nodes/UsingOperator.js @@ -0,0 +1,7 @@ +export const UsingOperator = { + parse: ({ ast }) => ({ + kind: ast.cst.kind, + variant: ast.variant.text + }), + print: ({ node }) => node.variant +}; diff --git a/src/slang-nodes/UsingTarget.js b/src/slang-nodes/UsingTarget.js new file mode 100644 index 000000000..a1beac643 --- /dev/null +++ b/src/slang-nodes/UsingTarget.js @@ -0,0 +1,13 @@ +export const UsingTarget = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + variant: + ast.variant.type === 'Token' + ? ast.variant.text + : parse(ast.variant, options, parse) + }), + print: ({ node, path, print }) => + typeof node.variant === 'string' + ? node.variant + : path.call(print, 'variant') +}; diff --git a/src/slang-nodes/VariableDeclarationStatement.js b/src/slang-nodes/VariableDeclarationStatement.js new file mode 100644 index 000000000..6f86d6ccd --- /dev/null +++ b/src/slang-nodes/VariableDeclarationStatement.js @@ -0,0 +1,14 @@ +export const VariableDeclarationStatement = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + variableType: parse(ast.variableType, options, parse), + storageLocation: ast.storageLocation + ? parse(ast.storageLocation, options, parse) + : undefined, + name: ast.name.text, + value: ast.value ? parse(ast.value, options, parse) : undefined, + semicolon: ast.semicolon.text + }), + // TODO: implement print + print: () => ['TypedTupleMember'] +}; diff --git a/src/slang-nodes/VariableDeclarationType.js b/src/slang-nodes/VariableDeclarationType.js new file mode 100644 index 000000000..57333db53 --- /dev/null +++ b/src/slang-nodes/VariableDeclarationType.js @@ -0,0 +1,13 @@ +export const VariableDeclarationType = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + variant: + ast.variant.type === 'Token' + ? ast.variant.text + : parse(ast.variant, options, parse) + }), + print: ({ node, path, print }) => + typeof node.variant === 'string' + ? node.variant + : path.call(print, 'variant') +}; diff --git a/src/slang-nodes/VariableDeclarationValue.js b/src/slang-nodes/VariableDeclarationValue.js new file mode 100644 index 000000000..4a00a924b --- /dev/null +++ b/src/slang-nodes/VariableDeclarationValue.js @@ -0,0 +1,9 @@ +export const VariableDeclarationValue = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + equal: ast.equal.text, + expression: parse(ast.expression, options, parse) + }), + // TODO: implement print + print: () => ['VariableDeclarationValue'] +}; diff --git a/src/slang-nodes/VersionComparator.js b/src/slang-nodes/VersionComparator.js new file mode 100644 index 000000000..329a45bbd --- /dev/null +++ b/src/slang-nodes/VersionComparator.js @@ -0,0 +1,8 @@ +export const VersionComparator = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + operator: ast.operator.text, + operand: parse(ast.operand, options, parse) + }), + print: ({ node, path, print }) => [node.operator, path.call(print, 'operand')] +}; diff --git a/src/slang-nodes/VersionExpression.js b/src/slang-nodes/VersionExpression.js new file mode 100644 index 000000000..61675bfbd --- /dev/null +++ b/src/slang-nodes/VersionExpression.js @@ -0,0 +1,13 @@ +export const VersionExpression = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + variant: + ast.variant.type === 'Token' + ? ast.variant.text + : parse(ast.variant, options, parse) + }), + print: ({ node, path, print }) => + typeof node.variant === 'string' + ? node.variant + : path.call(print, 'variant') +}; diff --git a/src/slang-nodes/VersionExpressionSet.js b/src/slang-nodes/VersionExpressionSet.js new file mode 100644 index 000000000..423829c0e --- /dev/null +++ b/src/slang-nodes/VersionExpressionSet.js @@ -0,0 +1,7 @@ +export const VersionExpressionSet = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item, options, parse)) + }), + print: ({ path, print }) => path.map(print, 'items') +}; diff --git a/src/slang-nodes/VersionExpressionSets.js b/src/slang-nodes/VersionExpressionSets.js new file mode 100644 index 000000000..655deca77 --- /dev/null +++ b/src/slang-nodes/VersionExpressionSets.js @@ -0,0 +1,13 @@ +export const VersionExpressionSets = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item, options, parse)), + separators: ast.separators.map((separator) => separator.text) + }), + print: ({ node, path, print }) => + path + .map(print, 'items') + .map((item, index) => + index === 0 ? item : [node.separators[index - 1], item] + ) +}; diff --git a/src/slang-nodes/VersionPragma.js b/src/slang-nodes/VersionPragma.js new file mode 100644 index 000000000..b39508c98 --- /dev/null +++ b/src/slang-nodes/VersionPragma.js @@ -0,0 +1,12 @@ +export const VersionPragma = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + solidityKeyword: ast.solidityKeyword.text, + sets: parse(ast.sets, options, parse) + }), + print: ({ node, path, print }) => [ + node.solidityKeyword, + ' ', + path.call(print, 'sets') + ] +}; diff --git a/src/slang-nodes/VersionRange.js b/src/slang-nodes/VersionRange.js new file mode 100644 index 000000000..63e812052 --- /dev/null +++ b/src/slang-nodes/VersionRange.js @@ -0,0 +1,10 @@ +export const VersionRange = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + leftOperand: parse(ast.leftOperand, options, parse), + operator: ast.operator.text, + rightOperand: parse(ast.rightOperand, options, parse) + }), + // TODO: implement print + print: () => ['VersionRange'] +}; diff --git a/src/slang-nodes/VersionSpecifiers.js b/src/slang-nodes/VersionSpecifiers.js new file mode 100644 index 000000000..2e93bf885 --- /dev/null +++ b/src/slang-nodes/VersionSpecifiers.js @@ -0,0 +1,11 @@ +export const VersionSpecifiers = { + parse: ({ ast }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => item.text), + separators: ast.separators.map((separator) => separator.text) + }), + print: ({ node }) => + node.items.map((item, index) => + index === 0 ? item : [node.separators[index - 1], item] + ) +}; diff --git a/src/slang-nodes/WhileStatement.js b/src/slang-nodes/WhileStatement.js new file mode 100644 index 000000000..35ac5c528 --- /dev/null +++ b/src/slang-nodes/WhileStatement.js @@ -0,0 +1,12 @@ +export const WhileStatement = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + whileKeyword: ast.whileKeyword.text, + openParen: ast.openParen.text, + condition: parse(ast.condition, options, parse), + closeParen: ast.closeParen.text, + body: parse(ast.body, options, parse) + }), + // TODO: implement print + print: () => ['WhileStatement'] +}; diff --git a/src/slang-nodes/YulArguments.js b/src/slang-nodes/YulArguments.js new file mode 100644 index 000000000..dcfeb48be --- /dev/null +++ b/src/slang-nodes/YulArguments.js @@ -0,0 +1,9 @@ +export const YulArguments = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item, options, parse)), + separators: ast.separators.map((separator) => separator.text) + }), + // TODO: implement print + print: () => ['YulArguments'] +}; diff --git a/src/slang-nodes/YulAssignmentOperator.js b/src/slang-nodes/YulAssignmentOperator.js new file mode 100644 index 000000000..e3c840c7c --- /dev/null +++ b/src/slang-nodes/YulAssignmentOperator.js @@ -0,0 +1,13 @@ +export const YulAssignmentOperator = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + variant: + ast.variant.type === 'Token' + ? ast.variant.text + : parse(ast.variant, options, parse) + }), + print: ({ node, path, print }) => + typeof node.variant === 'string' + ? node.variant + : path.call(print, 'variant') +}; diff --git a/src/slang-nodes/YulAssignmentStatement.js b/src/slang-nodes/YulAssignmentStatement.js new file mode 100644 index 000000000..e011c3f34 --- /dev/null +++ b/src/slang-nodes/YulAssignmentStatement.js @@ -0,0 +1,10 @@ +export const YulAssignmentStatement = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + names: parse(ast.names, options, parse), + assignment: parse(ast.assignment, options, parse), + expression: parse(ast.expression, options, parse) + }), + // TODO: implement print + print: () => ['YulAssignmentStatement'] +}; diff --git a/src/slang-nodes/YulBlock.js b/src/slang-nodes/YulBlock.js new file mode 100644 index 000000000..704f57595 --- /dev/null +++ b/src/slang-nodes/YulBlock.js @@ -0,0 +1,10 @@ +export const YulBlock = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + openBrace: ast.openBrace.text, + statements: parse(ast.statements, options, parse), + closeBrace: ast.closeBrace.text + }), + // TODO: implement print + print: () => ['YulBlock'] +}; diff --git a/src/slang-nodes/YulBreakStatement.js b/src/slang-nodes/YulBreakStatement.js new file mode 100644 index 000000000..40fb90e7c --- /dev/null +++ b/src/slang-nodes/YulBreakStatement.js @@ -0,0 +1,8 @@ +export const YulBreakStatement = { + parse: ({ ast }) => ({ + kind: ast.cst.kind, + breakKeyword: ast.breakKeyword.text + }), + // TODO: implement print + print: () => ['YulBreakStatement'] +}; diff --git a/src/slang-nodes/YulBuiltInFunction.js b/src/slang-nodes/YulBuiltInFunction.js new file mode 100644 index 000000000..72b6d6fd7 --- /dev/null +++ b/src/slang-nodes/YulBuiltInFunction.js @@ -0,0 +1,7 @@ +export const YulBuiltInFunction = { + parse: ({ ast }) => ({ + kind: ast.cst.kind, + variant: ast.variant.text + }), + print: ({ node }) => node.variant +}; diff --git a/src/slang-nodes/YulColonAndEqual.js b/src/slang-nodes/YulColonAndEqual.js new file mode 100644 index 000000000..699529054 --- /dev/null +++ b/src/slang-nodes/YulColonAndEqual.js @@ -0,0 +1,9 @@ +export const YulColonAndEqual = { + parse: ({ ast }) => ({ + kind: ast.cst.kind, + colon: ast.colon.text, + equal: ast.equal.text + }), + // TODO: implement print + print: () => ['YulColonAndEqual'] +}; diff --git a/src/slang-nodes/YulContinueStatement.js b/src/slang-nodes/YulContinueStatement.js new file mode 100644 index 000000000..48e001947 --- /dev/null +++ b/src/slang-nodes/YulContinueStatement.js @@ -0,0 +1,8 @@ +export const YulContinueStatement = { + parse: ({ ast }) => ({ + kind: ast.cst.kind, + continueKeyword: ast.continueKeyword.text + }), + // TODO: implement print + print: () => ['YulContinueStatement'] +}; diff --git a/src/slang-nodes/YulDefaultCase.js b/src/slang-nodes/YulDefaultCase.js new file mode 100644 index 000000000..8081a58b0 --- /dev/null +++ b/src/slang-nodes/YulDefaultCase.js @@ -0,0 +1,9 @@ +export const YulDefaultCase = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + defaultKeyword: ast.defaultKeyword.text, + body: parse(ast.body, options, parse) + }), + // TODO: implement print + print: () => ['YulDefaultCase'] +}; diff --git a/src/slang-nodes/YulExpression.js b/src/slang-nodes/YulExpression.js new file mode 100644 index 000000000..1b315aa6d --- /dev/null +++ b/src/slang-nodes/YulExpression.js @@ -0,0 +1,7 @@ +export const YulExpression = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + variant: parse(ast.variant, options, parse) + }), + print: ({ path, print }) => path.call(print, 'variant') +}; diff --git a/src/slang-nodes/YulForStatement.js b/src/slang-nodes/YulForStatement.js new file mode 100644 index 000000000..0e3ad1d2e --- /dev/null +++ b/src/slang-nodes/YulForStatement.js @@ -0,0 +1,12 @@ +export const YulForStatement = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + forKeyword: ast.forKeyword.text, + initialization: parse(ast.initialization, options, parse), + condition: parse(ast.condition, options, parse), + iterator: parse(ast.iterator, options, parse), + body: parse(ast.body, options, parse) + }), + // TODO: implement print + print: () => ['YulForStatement'] +}; diff --git a/src/slang-nodes/YulFunctionCallExpression.js b/src/slang-nodes/YulFunctionCallExpression.js new file mode 100644 index 000000000..707a65b4b --- /dev/null +++ b/src/slang-nodes/YulFunctionCallExpression.js @@ -0,0 +1,11 @@ +export const YulFunctionCallExpression = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + operand: parse(ast.operand, options, parse), + openParen: ast.openParen.text, + arguments: parse(ast.arguments, options, parse), + closeParen: ast.closeParen.text + }), + // TODO: implement print + print: () => ['YulFunctionCallExpression'] +}; diff --git a/src/slang-nodes/YulFunctionDefinition.js b/src/slang-nodes/YulFunctionDefinition.js new file mode 100644 index 000000000..2b57a294a --- /dev/null +++ b/src/slang-nodes/YulFunctionDefinition.js @@ -0,0 +1,12 @@ +export const YulFunctionDefinition = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + functionKeyword: ast.functionKeyword.text, + name: ast.name.text, + parameters: parse(ast.parameters, options, parse), + returns: ast.returns ? parse(ast.returns, options, parse) : undefined, + body: parse(ast.body, options, parse) + }), + // TODO: implement print + print: () => ['YulFunctionDefinition'] +}; diff --git a/src/slang-nodes/YulIfStatement.js b/src/slang-nodes/YulIfStatement.js new file mode 100644 index 000000000..0c3fc1a3a --- /dev/null +++ b/src/slang-nodes/YulIfStatement.js @@ -0,0 +1,10 @@ +export const YulIfStatement = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + ifKeyword: ast.ifKeyword.text, + condition: parse(ast.condition, options, parse), + body: parse(ast.body, options, parse) + }), + // TODO: implement print + print: () => ['YulIfStatement'] +}; diff --git a/src/slang-nodes/YulLabel.js b/src/slang-nodes/YulLabel.js new file mode 100644 index 000000000..92ccdb7d8 --- /dev/null +++ b/src/slang-nodes/YulLabel.js @@ -0,0 +1,9 @@ +export const YulLabel = { + parse: ({ ast }) => ({ + kind: ast.cst.kind, + label: ast.label.text, + colon: ast.colon.text + }), + // TODO: implement print + print: () => ['YulLabel'] +}; diff --git a/src/slang-nodes/YulLeaveStatement.js b/src/slang-nodes/YulLeaveStatement.js new file mode 100644 index 000000000..5932887af --- /dev/null +++ b/src/slang-nodes/YulLeaveStatement.js @@ -0,0 +1,8 @@ +export const YulLeaveStatement = { + parse: ({ ast }) => ({ + kind: ast.cst.kind, + leaveKeyword: ast.leaveKeyword.text + }), + // TODO: implement print + print: () => ['YulLeaveStatement'] +}; diff --git a/src/slang-nodes/YulLiteral.js b/src/slang-nodes/YulLiteral.js new file mode 100644 index 000000000..8b0959e3e --- /dev/null +++ b/src/slang-nodes/YulLiteral.js @@ -0,0 +1,13 @@ +export const YulLiteral = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + variant: + ast.variant.type === 'Token' + ? ast.variant.text + : parse(ast.variant, options, parse) + }), + print: ({ node, path, print }) => + typeof node.variant === 'string' + ? node.variant + : path.call(print, 'variant') +}; diff --git a/src/slang-nodes/YulParameters.js b/src/slang-nodes/YulParameters.js new file mode 100644 index 000000000..07e07940a --- /dev/null +++ b/src/slang-nodes/YulParameters.js @@ -0,0 +1,9 @@ +export const YulParameters = { + parse: ({ ast }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => item.text), + separators: ast.separators.map((separator) => separator.text) + }), + // TODO: implement print + print: () => ['YulParameters'] +}; diff --git a/src/slang-nodes/YulParametersDeclaration.js b/src/slang-nodes/YulParametersDeclaration.js new file mode 100644 index 000000000..82b8eff51 --- /dev/null +++ b/src/slang-nodes/YulParametersDeclaration.js @@ -0,0 +1,10 @@ +export const YulParametersDeclaration = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + openParen: ast.openParen.text, + parameters: parse(ast.parameters, options, parse), + closeParen: ast.closeParen.text + }), + // TODO: implement print + print: () => ['YulParametersDeclaration'] +}; diff --git a/src/slang-nodes/YulPath.js b/src/slang-nodes/YulPath.js new file mode 100644 index 000000000..a2d5804c3 --- /dev/null +++ b/src/slang-nodes/YulPath.js @@ -0,0 +1,9 @@ +export const YulPath = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item, options, parse)), + separators: ast.separators.map((separator) => separator.text) + }), + // TODO: implement print + print: () => ['YulPath'] +}; diff --git a/src/slang-nodes/YulPathComponent.js b/src/slang-nodes/YulPathComponent.js new file mode 100644 index 000000000..b4b10be21 --- /dev/null +++ b/src/slang-nodes/YulPathComponent.js @@ -0,0 +1,7 @@ +export const YulPathComponent = { + parse: ({ ast }) => ({ + kind: ast.cst.kind, + variant: ast.variant.text + }), + print: ({ node }) => node.variant +}; diff --git a/src/slang-nodes/YulPaths.js b/src/slang-nodes/YulPaths.js new file mode 100644 index 000000000..b3497a792 --- /dev/null +++ b/src/slang-nodes/YulPaths.js @@ -0,0 +1,9 @@ +export const YulPaths = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item, options, parse)), + separators: ast.separators.map((separator) => separator.text) + }), + // TODO: implement print + print: () => ['YulPaths'] +}; diff --git a/src/slang-nodes/YulReturnVariables.js b/src/slang-nodes/YulReturnVariables.js new file mode 100644 index 000000000..3632c2bb7 --- /dev/null +++ b/src/slang-nodes/YulReturnVariables.js @@ -0,0 +1,9 @@ +export const YulReturnVariables = { + parse: ({ ast }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => item.text), + separators: ast.separators.map((separator) => separator.text) + }), + // TODO: implement print + print: () => ['YulReturnVariables'] +}; diff --git a/src/slang-nodes/YulReturnsDeclaration.js b/src/slang-nodes/YulReturnsDeclaration.js new file mode 100644 index 000000000..168413ea0 --- /dev/null +++ b/src/slang-nodes/YulReturnsDeclaration.js @@ -0,0 +1,9 @@ +export const YulReturnsDeclaration = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + minusGreaterThan: ast.minusGreaterThan.text, + variables: parse(ast.variables, options, parse) + }), + // TODO: implement print + print: () => ['YulReturnsDeclaration'] +}; diff --git a/src/slang-nodes/YulStatement.js b/src/slang-nodes/YulStatement.js new file mode 100644 index 000000000..076bb7cf0 --- /dev/null +++ b/src/slang-nodes/YulStatement.js @@ -0,0 +1,7 @@ +export const YulStatement = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + variant: parse(ast.variant, options, parse) + }), + print: ({ path, print }) => path.call(print, 'variant') +}; diff --git a/src/slang-nodes/YulStatements.js b/src/slang-nodes/YulStatements.js new file mode 100644 index 000000000..b0931b2bc --- /dev/null +++ b/src/slang-nodes/YulStatements.js @@ -0,0 +1,8 @@ +export const YulStatements = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item, options, parse)) + }), + // TODO: implement print + print: () => ['YulStatements'] +}; diff --git a/src/slang-nodes/YulSwitchCase.js b/src/slang-nodes/YulSwitchCase.js new file mode 100644 index 000000000..b2e7a9af6 --- /dev/null +++ b/src/slang-nodes/YulSwitchCase.js @@ -0,0 +1,7 @@ +export const YulSwitchCase = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + variant: parse(ast.variant, options, parse) + }), + print: ({ path, print }) => path.call(print, 'variant') +}; diff --git a/src/slang-nodes/YulSwitchCases.js b/src/slang-nodes/YulSwitchCases.js new file mode 100644 index 000000000..76fb5e379 --- /dev/null +++ b/src/slang-nodes/YulSwitchCases.js @@ -0,0 +1,8 @@ +export const YulSwitchCases = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item, options, parse)) + }), + // TODO: implement print + print: () => ['YulSwitchCases'] +}; diff --git a/src/slang-nodes/YulSwitchStatement.js b/src/slang-nodes/YulSwitchStatement.js new file mode 100644 index 000000000..5351d6cbe --- /dev/null +++ b/src/slang-nodes/YulSwitchStatement.js @@ -0,0 +1,10 @@ +export const YulSwitchStatement = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + switchKeyword: ast.switchKeyword.text, + expression: parse(ast.expression, options, parse), + cases: parse(ast.cases, options, parse) + }), + // TODO: implement print + print: () => ['YulSwitchStatement'] +}; diff --git a/src/slang-nodes/YulValueCase.js b/src/slang-nodes/YulValueCase.js new file mode 100644 index 000000000..a0f44a1ed --- /dev/null +++ b/src/slang-nodes/YulValueCase.js @@ -0,0 +1,10 @@ +export const YulValueCase = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + caseKeyword: ast.caseKeyword.text, + value: parse(ast.value, options, parse), + body: parse(ast.body, options, parse) + }), + // TODO: implement print + print: () => ['YulValueCase'] +}; diff --git a/src/slang-nodes/YulVariableDeclarationStatement.js b/src/slang-nodes/YulVariableDeclarationStatement.js new file mode 100644 index 000000000..abca62d63 --- /dev/null +++ b/src/slang-nodes/YulVariableDeclarationStatement.js @@ -0,0 +1,10 @@ +export const YulVariableDeclarationStatement = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + letKeyword: ast.letKeyword.text, + names: ast.names.text, + value: ast.value ? parse(ast.value, options, parse) : undefined + }), + // TODO: implement print + print: () => ['YulVariableDeclarationStatement'] +}; diff --git a/src/slang-nodes/YulVariableDeclarationValue.js b/src/slang-nodes/YulVariableDeclarationValue.js new file mode 100644 index 000000000..f9da75efe --- /dev/null +++ b/src/slang-nodes/YulVariableDeclarationValue.js @@ -0,0 +1,9 @@ +export const YulVariableDeclarationValue = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + assignment: parse(ast.assignment, options, parse), + expression: parse(ast.expression, options, parse) + }), + // TODO: implement print + print: () => ['YulVariableDeclarationValue'] +}; diff --git a/src/slang-nodes/index.js b/src/slang-nodes/index.js new file mode 100644 index 000000000..88d633569 --- /dev/null +++ b/src/slang-nodes/index.js @@ -0,0 +1,210 @@ +export * from './ABICoderPragma.js'; +export * from './AdditiveExpression.js'; +export * from './AddressType.js'; +export * from './AndExpression.js'; +export * from './ArgumentsDeclaration.js'; +export * from './ArrayExpression.js'; +export * from './ArrayTypeName.js'; +export * from './ArrayValues.js'; +export * from './AssemblyFlags.js'; +export * from './AssemblyFlagsDeclaration.js'; +export * from './AssemblyStatement.js'; +export * from './AssignmentExpression.js'; +export * from './BitwiseAndExpression.js'; +export * from './BitwiseOrExpression.js'; +export * from './BitwiseXorExpression.js'; +export * from './Block.js'; +export * from './BreakStatement.js'; +export * from './CallOptions.js'; +export * from './CallOptionsExpression.js'; +export * from './CatchClause.js'; +export * from './CatchClauseError.js'; +export * from './CatchClauses.js'; +export * from './ComparisonExpression.js'; +export * from './ConditionalExpression.js'; +export * from './ConstantDefinition.js'; +export * from './ConstructorAttribute.js'; +export * from './ConstructorAttributes.js'; +export * from './ConstructorDefinition.js'; +export * from './ContinueStatement.js'; +export * from './ContractDefinition.js'; +export * from './ContractMember.js'; +export * from './ContractMembers.js'; +export * from './DecimalNumberExpression.js'; +export * from './DoWhileStatement.js'; +export * from './ElementaryType.js'; +export * from './ElseBranch.js'; +export * from './EmitStatement.js'; +export * from './EnumDefinition.js'; +export * from './EnumMembers.js'; +export * from './EqualityExpression.js'; +export * from './ErrorDefinition.js'; +export * from './ErrorParameter.js'; +export * from './ErrorParameters.js'; +export * from './ErrorParametersDeclaration.js'; +export * from './EventDefinition.js'; +export * from './EventParameter.js'; +export * from './EventParameters.js'; +export * from './EventParametersDeclaration.js'; +export * from './ExperimentalPragma.js'; +export * from './ExponentiationExpression.js'; +export * from './Expression.js'; +export * from './ExpressionStatement.js'; +export * from './FallbackFunctionAttribute.js'; +export * from './FallbackFunctionAttributes.js'; +export * from './FallbackFunctionDefinition.js'; +export * from './ForStatement.js'; +export * from './ForStatementCondition.js'; +export * from './ForStatementInitialization.js'; +export * from './FunctionAttribute.js'; +export * from './FunctionAttributes.js'; +export * from './FunctionBody.js'; +export * from './FunctionCallExpression.js'; +export * from './FunctionDefinition.js'; +export * from './FunctionName.js'; +export * from './FunctionType.js'; +export * from './FunctionTypeAttribute.js'; +export * from './FunctionTypeAttributes.js'; +export * from './HexNumberExpression.js'; +export * from './HexStringLiteral.js'; +export * from './HexStringLiterals.js'; +export * from './IdentifierPath.js'; +export * from './IfStatement.js'; +export * from './ImportAlias.js'; +export * from './ImportClause.js'; +export * from './ImportDeconstruction.js'; +export * from './ImportDeconstructionSymbol.js'; +export * from './ImportDeconstructionSymbols.js'; +export * from './ImportDirective.js'; +export * from './IndexAccessEnd.js'; +export * from './IndexAccessExpression.js'; +export * from './InheritanceSpecifier.js'; +export * from './InheritanceType.js'; +export * from './InheritanceTypes.js'; +export * from './InterfaceDefinition.js'; +export * from './InterfaceMembers.js'; +export * from './LibraryDefinition.js'; +export * from './LibraryMembers.js'; +export * from './MappingKey.js'; +export * from './MappingKeyType.js'; +export * from './MappingType.js'; +export * from './MappingValue.js'; +export * from './MemberAccess.js'; +export * from './MemberAccessExpression.js'; +export * from './ModifierInvocation.js'; +export * from './MultiplicativeExpression.js'; +export * from './NamedArgument.js'; +export * from './NamedArgumentGroup.js'; +export * from './NamedArguments.js'; +export * from './NamedArgumentsDeclaration.js'; +export * from './NamedImport.js'; +export * from './NewExpression.js'; +export * from './NumberUnit.js'; +export * from './OrExpression.js'; +export * from './OverridePaths.js'; +export * from './OverridePathsDeclaration.js'; +export * from './OverrideSpecifier.js'; +export * from './Parameter.js'; +export * from './Parameters.js'; +export * from './ParametersDeclaration.js'; +export * from './PathImport.js'; +export * from './PositionalArguments.js'; +export * from './PositionalArgumentsDeclaration.js'; +export * from './PostfixExpression.js'; +export * from './Pragma.js'; +export * from './PragmaDirective.js'; +export * from './PrefixExpression.js'; +export * from './ReceiveFunctionAttribute.js'; +export * from './ReceiveFunctionAttributes.js'; +export * from './ReceiveFunctionDefinition.js'; +export * from './ReturnsDeclaration.js'; +export * from './ReturnStatement.js'; +export * from './RevertStatement.js'; +export * from './ShiftExpression.js'; +export * from './SourceUnit.js'; +export * from './SourceUnitMember.js'; +export * from './SourceUnitMembers.js'; +export * from './Statement.js'; +export * from './Statements.js'; +export * from './StateVariableAttribute.js'; +export * from './StateVariableAttributes.js'; +export * from './StateVariableDefinition.js'; +export * from './StateVariableDefinitionValue.js'; +export * from './StorageLocation.js'; +export * from './StringExpression.js'; +export * from './StringLiteral.js'; +export * from './StringLiterals.js'; +export * from './StructDefinition.js'; +export * from './StructMember.js'; +export * from './StructMembers.js'; +export * from './ThrowStatement.js'; +export * from './TryStatement.js'; +export * from './TupleDeconstructionElement.js'; +export * from './TupleDeconstructionElements.js'; +export * from './TupleDeconstructionStatement.js'; +export * from './TupleExpression.js'; +export * from './TupleMember.js'; +export * from './TupleValue.js'; +export * from './TupleValues.js'; +export * from './TypedTupleMember.js'; +export * from './TypeExpression.js'; +export * from './TypeName.js'; +export * from './UncheckedBlock.js'; +export * from './UnicodeStringLiteral.js'; +export * from './UnicodeStringLiterals.js'; +export * from './UnnamedFunctionAttribute.js'; +export * from './UnnamedFunctionAttributes.js'; +export * from './UnnamedFunctionDefinition.js'; +export * from './UntypedTupleMember.js'; +export * from './UserDefinedValueTypeDefinition.js'; +export * from './UsingAlias.js'; +export * from './UsingClause.js'; +export * from './UsingDeconstruction.js'; +export * from './UsingDeconstructionSymbol.js'; +export * from './UsingDeconstructionSymbols.js'; +export * from './UsingDirective.js'; +export * from './UsingOperator.js'; +export * from './UsingTarget.js'; +export * from './VariableDeclarationStatement.js'; +export * from './VariableDeclarationType.js'; +export * from './VariableDeclarationValue.js'; +export * from './VersionComparator.js'; +export * from './VersionExpression.js'; +export * from './VersionExpressionSet.js'; +export * from './VersionExpressionSets.js'; +export * from './VersionPragma.js'; +export * from './VersionRange.js'; +export * from './VersionSpecifiers.js'; +export * from './WhileStatement.js'; +export * from './YulArguments.js'; +export * from './YulAssignmentOperator.js'; +export * from './YulAssignmentStatement.js'; +export * from './YulBlock.js'; +export * from './YulBreakStatement.js'; +export * from './YulBuiltInFunction.js'; +export * from './YulColonAndEqual.js'; +export * from './YulContinueStatement.js'; +export * from './YulDefaultCase.js'; +export * from './YulExpression.js'; +export * from './YulForStatement.js'; +export * from './YulFunctionCallExpression.js'; +export * from './YulFunctionDefinition.js'; +export * from './YulIfStatement.js'; +export * from './YulLabel.js'; +export * from './YulLeaveStatement.js'; +export * from './YulLiteral.js'; +export * from './YulParameters.js'; +export * from './YulParametersDeclaration.js'; +export * from './YulPath.js'; +export * from './YulPathComponent.js'; +export * from './YulPaths.js'; +export * from './YulReturnsDeclaration.js'; +export * from './YulReturnVariables.js'; +export * from './YulStatement.js'; +export * from './YulStatements.js'; +export * from './YulSwitchCase.js'; +export * from './YulSwitchCases.js'; +export * from './YulSwitchStatement.js'; +export * from './YulValueCase.js'; +export * from './YulVariableDeclarationStatement.js'; +export * from './YulVariableDeclarationValue.js'; diff --git a/src/slangParser.js b/src/slangParser.js new file mode 100644 index 000000000..2bf0f13e0 --- /dev/null +++ b/src/slangParser.js @@ -0,0 +1,22 @@ +// https://prettier.io/docs/en/plugins.html#parsers +// import parser from '@solidity-parser/parser'; +import { Language } from '@nomicfoundation/slang/language/index.js'; +import { RuleKind } from '@nomicfoundation/slang/kinds/index.js'; +import { SourceUnit } from '@nomicfoundation/slang/ast/index.js'; +import * as parsers from './slang-nodes/index.js'; + +function genericParse(ast, options, parseFunction) { + return parsers[ast.cst.kind].parse({ ast, options, parse: parseFunction }); +} + +function parse(text, _parsers, options = _parsers) { + // const compiler = coerce(options.compiler); + const language = new Language('0.8.0'); + const parsed = new SourceUnit( + language.parse(RuleKind.SourceUnit, text).tree() + ); + + return genericParse(parsed, options, genericParse); +} + +export default parse; diff --git a/src/slangPrinter.js b/src/slangPrinter.js new file mode 100644 index 000000000..cb9a727e6 --- /dev/null +++ b/src/slangPrinter.js @@ -0,0 +1,45 @@ +import * as nodes from './slang/index.js'; +import { + hasNodeIgnoreComment, + prettierVersionSatisfies +} from './common/util.js'; +import ignoreComments from './comments/ignore.js'; + +let checked = false; + +function prettierVersionCheck() { + if (checked) return; + if (!prettierVersionSatisfies('>=2.3.0')) { + throw new Error( + 'The version of prettier in your node-modules does not satisfy the required ">=2.3.0" constraint. Please update the version of Prettier.' + ); + } + checked = true; +} + +function genericPrint(path, options, print) { + prettierVersionCheck(); + + const node = path.getValue(); + const nodeType = node.kind; + if (node === null) { + return ''; + } + + if (!(nodeType in nodes)) { + throw new Error(`Unknown type: ${JSON.stringify(nodeType)}`); + } + + if (hasNodeIgnoreComment(node)) { + ignoreComments(path); + + return options.originalText.slice( + options.locStart(node), + options.locEnd(node) + 1 + ); + } + + return nodes[nodeType].print({ node, options, path, print }); +} + +export default genericPrint; diff --git a/tests/format/AddressPayable/__snapshots__/jsfmt.spec.js.snap b/tests/format/AddressPayable/__snapshots__/jsfmt.spec.js.snap index df021991a..1152abc21 100644 --- a/tests/format/AddressPayable/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/AddressPayable/__snapshots__/jsfmt.spec.js.snap @@ -34,3 +34,27 @@ contract AddressPayable { ================================================================================ `; + +exports[`AddressPayable.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity ^0.5.2; + +contract AddressPayable { + using Address for address payable; + address payable[] hello; + function sendSomeEth(address payable to, address payable[] memory world) public payable { + address payable target = to; + target.transfer(msg.value); + } +} + +=====================================output===================================== +pragma solidity ^0.5.2; +ContractDefinition + +================================================================================ +`; diff --git a/tests/format/AddressPayable/jsfmt.spec.js b/tests/format/AddressPayable/jsfmt.spec.js index 765dd60a6..fd56c17bc 100644 --- a/tests/format/AddressPayable/jsfmt.spec.js +++ b/tests/format/AddressPayable/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse']); From d54e8f5b9e362790b8800e3bb4e6b6f0849d0cfb Mon Sep 17 00:00:00 2001 From: Klaus Date: Mon, 20 May 2024 18:37:20 +1200 Subject: [PATCH 003/160] Adding a printed 'TODO' to unimplemented printers so they can be seen in testing --- src/slang-nodes/ABICoderPragma.js | 2 +- src/slang-nodes/AdditiveExpression.js | 2 +- src/slang-nodes/AddressType.js | 2 +- src/slang-nodes/AndExpression.js | 2 +- src/slang-nodes/ArrayExpression.js | 2 +- src/slang-nodes/ArrayTypeName.js | 2 +- src/slang-nodes/ArrayValues.js | 2 +- src/slang-nodes/AssemblyFlags.js | 2 +- src/slang-nodes/AssemblyFlagsDeclaration.js | 2 +- src/slang-nodes/AssemblyStatement.js | 2 +- src/slang-nodes/AssignmentExpression.js | 2 +- src/slang-nodes/BitwiseAndExpression.js | 2 +- src/slang-nodes/BitwiseOrExpression.js | 2 +- src/slang-nodes/BitwiseXorExpression.js | 2 +- src/slang-nodes/Block.js | 2 +- src/slang-nodes/BreakStatement.js | 2 +- src/slang-nodes/CallOptions.js | 2 +- src/slang-nodes/CallOptionsExpression.js | 2 +- src/slang-nodes/CatchClause.js | 2 +- src/slang-nodes/CatchClauseError.js | 2 +- src/slang-nodes/CatchClauses.js | 2 +- src/slang-nodes/ComparisonExpression.js | 2 +- src/slang-nodes/ConditionalExpression.js | 2 +- src/slang-nodes/ConstantDefinition.js | 2 +- src/slang-nodes/ConstructorAttributes.js | 2 +- src/slang-nodes/ConstructorDefinition.js | 2 +- src/slang-nodes/ContinueStatement.js | 2 +- src/slang-nodes/ContractDefinition.js | 20 ++++++++++++++++--- src/slang-nodes/ContractMembers.js | 17 ++++++++++++++-- src/slang-nodes/DecimalNumberExpression.js | 2 +- src/slang-nodes/DoWhileStatement.js | 2 +- src/slang-nodes/ElseBranch.js | 2 +- src/slang-nodes/EmitStatement.js | 2 +- src/slang-nodes/EnumDefinition.js | 2 +- src/slang-nodes/EnumMembers.js | 2 +- src/slang-nodes/EqualityExpression.js | 2 +- src/slang-nodes/ErrorDefinition.js | 2 +- src/slang-nodes/ErrorParameter.js | 2 +- src/slang-nodes/ErrorParameters.js | 2 +- src/slang-nodes/ErrorParametersDeclaration.js | 2 +- src/slang-nodes/EventDefinition.js | 2 +- src/slang-nodes/EventParameter.js | 2 +- src/slang-nodes/EventParameters.js | 2 +- src/slang-nodes/EventParametersDeclaration.js | 2 +- src/slang-nodes/ExperimentalPragma.js | 2 +- src/slang-nodes/ExponentiationExpression.js | 2 +- src/slang-nodes/ExpressionStatement.js | 2 +- src/slang-nodes/FallbackFunctionAttributes.js | 2 +- src/slang-nodes/FallbackFunctionDefinition.js | 2 +- src/slang-nodes/ForStatement.js | 2 +- src/slang-nodes/FunctionAttributes.js | 2 +- src/slang-nodes/FunctionCallExpression.js | 2 +- src/slang-nodes/FunctionDefinition.js | 2 +- src/slang-nodes/FunctionType.js | 2 +- src/slang-nodes/FunctionTypeAttributes.js | 2 +- src/slang-nodes/HexNumberExpression.js | 2 +- src/slang-nodes/HexStringLiterals.js | 2 +- src/slang-nodes/IdentifierPath.js | 2 +- src/slang-nodes/IfStatement.js | 2 +- src/slang-nodes/ImportAlias.js | 2 +- src/slang-nodes/ImportDeconstruction.js | 2 +- src/slang-nodes/ImportDeconstructionSymbol.js | 2 +- .../ImportDeconstructionSymbols.js | 2 +- src/slang-nodes/ImportDirective.js | 2 +- src/slang-nodes/IndexAccessEnd.js | 2 +- src/slang-nodes/IndexAccessExpression.js | 2 +- src/slang-nodes/InheritanceSpecifier.js | 2 +- src/slang-nodes/InheritanceType.js | 2 +- src/slang-nodes/InheritanceTypes.js | 2 +- src/slang-nodes/InterfaceDefinition.js | 2 +- src/slang-nodes/InterfaceMembers.js | 2 +- src/slang-nodes/LibraryDefinition.js | 2 +- src/slang-nodes/LibraryMembers.js | 2 +- src/slang-nodes/MappingKey.js | 2 +- src/slang-nodes/MappingType.js | 2 +- src/slang-nodes/MappingValue.js | 2 +- src/slang-nodes/MemberAccessExpression.js | 2 +- src/slang-nodes/ModifierInvocation.js | 2 +- src/slang-nodes/MultiplicativeExpression.js | 2 +- src/slang-nodes/NamedArgument.js | 2 +- src/slang-nodes/NamedArgumentGroup.js | 2 +- src/slang-nodes/NamedArguments.js | 2 +- src/slang-nodes/NamedArgumentsDeclaration.js | 2 +- src/slang-nodes/NamedImport.js | 2 +- src/slang-nodes/NewExpression.js | 2 +- src/slang-nodes/OrExpression.js | 2 +- src/slang-nodes/OverridePaths.js | 2 +- src/slang-nodes/OverridePathsDeclaration.js | 2 +- src/slang-nodes/OverrideSpecifier.js | 2 +- src/slang-nodes/Parameter.js | 2 +- src/slang-nodes/Parameters.js | 2 +- src/slang-nodes/ParametersDeclaration.js | 2 +- src/slang-nodes/PathImport.js | 2 +- src/slang-nodes/PositionalArguments.js | 2 +- .../PositionalArgumentsDeclaration.js | 2 +- src/slang-nodes/PostfixExpression.js | 2 +- src/slang-nodes/PrefixExpression.js | 2 +- src/slang-nodes/ReceiveFunctionAttributes.js | 2 +- src/slang-nodes/ReceiveFunctionDefinition.js | 2 +- src/slang-nodes/ReturnStatement.js | 2 +- src/slang-nodes/ReturnsDeclaration.js | 2 +- src/slang-nodes/RevertStatement.js | 2 +- src/slang-nodes/ShiftExpression.js | 2 +- src/slang-nodes/StateVariableAttributes.js | 2 +- src/slang-nodes/StateVariableDefinition.js | 2 +- .../StateVariableDefinitionValue.js | 2 +- src/slang-nodes/Statements.js | 2 +- src/slang-nodes/StringLiterals.js | 2 +- src/slang-nodes/StructDefinition.js | 2 +- src/slang-nodes/StructMember.js | 2 +- src/slang-nodes/StructMembers.js | 2 +- src/slang-nodes/ThrowStatement.js | 2 +- src/slang-nodes/TryStatement.js | 2 +- src/slang-nodes/TupleDeconstructionElement.js | 2 +- .../TupleDeconstructionElements.js | 2 +- .../TupleDeconstructionStatement.js | 2 +- src/slang-nodes/TupleExpression.js | 2 +- src/slang-nodes/TupleValue.js | 2 +- src/slang-nodes/TupleValues.js | 2 +- src/slang-nodes/TypeExpression.js | 2 +- src/slang-nodes/TypedTupleMember.js | 2 +- src/slang-nodes/UncheckedBlock.js | 2 +- src/slang-nodes/UnicodeStringLiterals.js | 2 +- src/slang-nodes/UnnamedFunctionAttributes.js | 2 +- src/slang-nodes/UnnamedFunctionDefinition.js | 2 +- src/slang-nodes/UntypedTupleMember.js | 2 +- .../UserDefinedValueTypeDefinition.js | 2 +- src/slang-nodes/UsingAlias.js | 2 +- src/slang-nodes/UsingDeconstruction.js | 2 +- src/slang-nodes/UsingDeconstructionSymbol.js | 2 +- src/slang-nodes/UsingDeconstructionSymbols.js | 2 +- src/slang-nodes/UsingDirective.js | 2 +- .../VariableDeclarationStatement.js | 2 +- src/slang-nodes/VariableDeclarationValue.js | 2 +- src/slang-nodes/VersionRange.js | 2 +- src/slang-nodes/WhileStatement.js | 2 +- src/slang-nodes/YulArguments.js | 2 +- src/slang-nodes/YulAssignmentStatement.js | 2 +- src/slang-nodes/YulBlock.js | 2 +- src/slang-nodes/YulBreakStatement.js | 2 +- src/slang-nodes/YulColonAndEqual.js | 2 +- src/slang-nodes/YulContinueStatement.js | 2 +- src/slang-nodes/YulDefaultCase.js | 2 +- src/slang-nodes/YulForStatement.js | 2 +- src/slang-nodes/YulFunctionCallExpression.js | 2 +- src/slang-nodes/YulFunctionDefinition.js | 2 +- src/slang-nodes/YulIfStatement.js | 2 +- src/slang-nodes/YulLabel.js | 2 +- src/slang-nodes/YulLeaveStatement.js | 2 +- src/slang-nodes/YulParameters.js | 2 +- src/slang-nodes/YulParametersDeclaration.js | 2 +- src/slang-nodes/YulPath.js | 2 +- src/slang-nodes/YulPaths.js | 2 +- src/slang-nodes/YulReturnVariables.js | 2 +- src/slang-nodes/YulReturnsDeclaration.js | 2 +- src/slang-nodes/YulStatements.js | 2 +- src/slang-nodes/YulSwitchCases.js | 2 +- src/slang-nodes/YulSwitchStatement.js | 2 +- src/slang-nodes/YulValueCase.js | 2 +- .../YulVariableDeclarationStatement.js | 2 +- .../YulVariableDeclarationValue.js | 2 +- src/slangPrinter.js | 2 +- 162 files changed, 192 insertions(+), 165 deletions(-) diff --git a/src/slang-nodes/ABICoderPragma.js b/src/slang-nodes/ABICoderPragma.js index b10162ae9..a731a7c37 100644 --- a/src/slang-nodes/ABICoderPragma.js +++ b/src/slang-nodes/ABICoderPragma.js @@ -5,5 +5,5 @@ export const ABICoderPragma = { version: ast.version.text }), // TODO: implement print - print: () => ['ABICoderPragma'] + print: () => ['TODO: ABICoderPragma'] }; diff --git a/src/slang-nodes/AdditiveExpression.js b/src/slang-nodes/AdditiveExpression.js index 2d9157026..d4290c953 100644 --- a/src/slang-nodes/AdditiveExpression.js +++ b/src/slang-nodes/AdditiveExpression.js @@ -6,5 +6,5 @@ export const AdditiveExpression = { rightOperand: parse(ast.rightOperand, options, parse) }), // TODO: implement print - print: () => ['AdditiveExpression'] + print: () => ['TODO: AdditiveExpression'] }; diff --git a/src/slang-nodes/AddressType.js b/src/slang-nodes/AddressType.js index 0693d4f70..f2027918c 100644 --- a/src/slang-nodes/AddressType.js +++ b/src/slang-nodes/AddressType.js @@ -5,5 +5,5 @@ export const AddressType = { payableKeyword: ast.payableKeyword?.text }), // TODO: implement print - print: () => ['AddressType'] + print: () => ['TODO: AddressType'] }; diff --git a/src/slang-nodes/AndExpression.js b/src/slang-nodes/AndExpression.js index c42f41103..c0459f650 100644 --- a/src/slang-nodes/AndExpression.js +++ b/src/slang-nodes/AndExpression.js @@ -6,5 +6,5 @@ export const AndExpression = { rightOperand: parse(ast.rightOperand, options, parse) }), // TODO: implement print - print: () => ['AndExpression'] + print: () => ['TODO: AndExpression'] }; diff --git a/src/slang-nodes/ArrayExpression.js b/src/slang-nodes/ArrayExpression.js index 3bb605e7e..f92a70315 100644 --- a/src/slang-nodes/ArrayExpression.js +++ b/src/slang-nodes/ArrayExpression.js @@ -6,5 +6,5 @@ export const ArrayExpression = { closeBracket: ast.closeBracket.text }), // TODO: implement print - print: () => ['ArrayExpression'] + print: () => ['TODO: ArrayExpression'] }; diff --git a/src/slang-nodes/ArrayTypeName.js b/src/slang-nodes/ArrayTypeName.js index 23a25e27b..b8ae0ba0f 100644 --- a/src/slang-nodes/ArrayTypeName.js +++ b/src/slang-nodes/ArrayTypeName.js @@ -7,5 +7,5 @@ export const ArrayTypeName = { closeBracket: ast.closeBracket.text }), // TODO: implement print - print: () => ['ArrayTypeName'] + print: () => ['TODO: ArrayTypeName'] }; diff --git a/src/slang-nodes/ArrayValues.js b/src/slang-nodes/ArrayValues.js index de79904a6..a4e3619af 100644 --- a/src/slang-nodes/ArrayValues.js +++ b/src/slang-nodes/ArrayValues.js @@ -5,5 +5,5 @@ export const ArrayValues = { separators: ast.separators.map((separator) => separator.text) }), // TODO: implement print - print: () => ['ArrayValues'] + print: () => ['TODO: ArrayValues'] }; diff --git a/src/slang-nodes/AssemblyFlags.js b/src/slang-nodes/AssemblyFlags.js index f63c35ab3..259ffd704 100644 --- a/src/slang-nodes/AssemblyFlags.js +++ b/src/slang-nodes/AssemblyFlags.js @@ -5,5 +5,5 @@ export const AssemblyFlags = { separators: ast.separators.maps((separator) => separator.text) }), // TODO: implement print - print: () => ['AssemblyFlags'] + print: () => ['TODO: AssemblyFlags'] }; diff --git a/src/slang-nodes/AssemblyFlagsDeclaration.js b/src/slang-nodes/AssemblyFlagsDeclaration.js index b2401e015..978eb85f0 100644 --- a/src/slang-nodes/AssemblyFlagsDeclaration.js +++ b/src/slang-nodes/AssemblyFlagsDeclaration.js @@ -6,5 +6,5 @@ export const AssemblyFlagsDeclaration = { closeParen: ast.closeParen.text }), // TODO: implement print - print: () => ['AssemblyFlagsDeclaration'] + print: () => ['TODO: AssemblyFlagsDeclaration'] }; diff --git a/src/slang-nodes/AssemblyStatement.js b/src/slang-nodes/AssemblyStatement.js index 553c4fc17..1a8986e9e 100644 --- a/src/slang-nodes/AssemblyStatement.js +++ b/src/slang-nodes/AssemblyStatement.js @@ -7,5 +7,5 @@ export const AssemblyStatement = { body: parse(ast.body, options, parse) }), // TODO: implement print - print: () => ['AssemblyStatement'] + print: () => ['TODO: AssemblyStatement'] }; diff --git a/src/slang-nodes/AssignmentExpression.js b/src/slang-nodes/AssignmentExpression.js index 6ee3d9d74..a1d7cc822 100644 --- a/src/slang-nodes/AssignmentExpression.js +++ b/src/slang-nodes/AssignmentExpression.js @@ -6,5 +6,5 @@ export const AssignmentExpression = { rightOperand: parse(ast.rightOperand, options, parse) }), // TODO: implement print - print: () => ['AssignmentExpression'] + print: () => ['TODO: AssignmentExpression'] }; diff --git a/src/slang-nodes/BitwiseAndExpression.js b/src/slang-nodes/BitwiseAndExpression.js index 026d91cd1..451f3c999 100644 --- a/src/slang-nodes/BitwiseAndExpression.js +++ b/src/slang-nodes/BitwiseAndExpression.js @@ -6,5 +6,5 @@ export const BitwiseAndExpression = { rightOperand: parse(ast.rightOperand, options, parse) }), // TODO: implement print - print: () => ['BitwiseAndExpression'] + print: () => ['TODO: BitwiseAndExpression'] }; diff --git a/src/slang-nodes/BitwiseOrExpression.js b/src/slang-nodes/BitwiseOrExpression.js index 8b54fd1a8..046572ac5 100644 --- a/src/slang-nodes/BitwiseOrExpression.js +++ b/src/slang-nodes/BitwiseOrExpression.js @@ -6,5 +6,5 @@ export const BitwiseOrExpression = { rightOperand: parse(ast.rightOperand, options, parse) }), // TODO: implement print - print: () => ['BitwiseOrExpression'] + print: () => ['TODO: BitwiseOrExpression'] }; diff --git a/src/slang-nodes/BitwiseXorExpression.js b/src/slang-nodes/BitwiseXorExpression.js index 4170af3ed..f616a431e 100644 --- a/src/slang-nodes/BitwiseXorExpression.js +++ b/src/slang-nodes/BitwiseXorExpression.js @@ -6,5 +6,5 @@ export const BitwiseXorExpression = { rightOperand: parse(ast.rightOperand, options, parse) }), // TODO: implement print - print: () => ['BitwiseXorExpression'] + print: () => ['TODO: BitwiseXorExpression'] }; diff --git a/src/slang-nodes/Block.js b/src/slang-nodes/Block.js index 304c3ca57..9d032cbdf 100644 --- a/src/slang-nodes/Block.js +++ b/src/slang-nodes/Block.js @@ -6,5 +6,5 @@ export const Block = { closeBrace: ast.closeBrace.text }), // TODO: implement print - print: () => ['Block'] + print: () => ['TODO: Block'] }; diff --git a/src/slang-nodes/BreakStatement.js b/src/slang-nodes/BreakStatement.js index 38d85a656..538005016 100644 --- a/src/slang-nodes/BreakStatement.js +++ b/src/slang-nodes/BreakStatement.js @@ -5,5 +5,5 @@ export const BreakStatement = { semicolon: ast.semicolon.text }), // TODO: implement print - print: () => ['BreakStatement'] + print: () => ['TODO: BreakStatement'] }; diff --git a/src/slang-nodes/CallOptions.js b/src/slang-nodes/CallOptions.js index ee4e8e0cb..81e5f32a1 100644 --- a/src/slang-nodes/CallOptions.js +++ b/src/slang-nodes/CallOptions.js @@ -5,5 +5,5 @@ export const CallOptions = { separators: ast.separators.map((separator) => separator.text) }), // TODO: implement print - print: () => ['CallOptions'] + print: () => ['TODO: CallOptions'] }; diff --git a/src/slang-nodes/CallOptionsExpression.js b/src/slang-nodes/CallOptionsExpression.js index a83142b4d..b0445c095 100644 --- a/src/slang-nodes/CallOptionsExpression.js +++ b/src/slang-nodes/CallOptionsExpression.js @@ -7,5 +7,5 @@ export const CallOptionsExpression = { closeBrace: ast.closeBrace.text }), // TODO: implement print - print: () => ['CallOptionsExpression'] + print: () => ['TODO: CallOptionsExpression'] }; diff --git a/src/slang-nodes/CatchClause.js b/src/slang-nodes/CatchClause.js index 2c6b5ca9c..3fbb6660f 100644 --- a/src/slang-nodes/CatchClause.js +++ b/src/slang-nodes/CatchClause.js @@ -6,5 +6,5 @@ export const CatchClause = { body: parse(ast.body, options, parse) }), // TODO: implement print - print: () => ['CatchClause'] + print: () => ['TODO: CatchClause'] }; diff --git a/src/slang-nodes/CatchClauseError.js b/src/slang-nodes/CatchClauseError.js index 4f0873264..ef0309880 100644 --- a/src/slang-nodes/CatchClauseError.js +++ b/src/slang-nodes/CatchClauseError.js @@ -5,5 +5,5 @@ export const CatchClauseError = { parameters: parse(ast.parameters, options, parse) }), // TODO: implement print - print: () => ['CatchClauseError'] + print: () => ['TODO: CatchClauseError'] }; diff --git a/src/slang-nodes/CatchClauses.js b/src/slang-nodes/CatchClauses.js index 26ed993ed..512ec0dda 100644 --- a/src/slang-nodes/CatchClauses.js +++ b/src/slang-nodes/CatchClauses.js @@ -4,5 +4,5 @@ export const CatchClauses = { items: ast.items.map((item) => parse(item, options, parse)) }), // TODO: implement print - print: () => ['CatchClauses'] + print: () => ['TODO: CatchClauses'] }; diff --git a/src/slang-nodes/ComparisonExpression.js b/src/slang-nodes/ComparisonExpression.js index 93bad524f..04efbf969 100644 --- a/src/slang-nodes/ComparisonExpression.js +++ b/src/slang-nodes/ComparisonExpression.js @@ -6,5 +6,5 @@ export const ComparisonExpression = { rightOperand: parse(ast.rightOperand, options, parse) }), // TODO: implement print - print: () => ['ComparisonExpression'] + print: () => ['TODO: ComparisonExpression'] }; diff --git a/src/slang-nodes/ConditionalExpression.js b/src/slang-nodes/ConditionalExpression.js index 9428ce36d..f3131df89 100644 --- a/src/slang-nodes/ConditionalExpression.js +++ b/src/slang-nodes/ConditionalExpression.js @@ -8,5 +8,5 @@ export const ConditionalExpression = { falseExpression: parse(ast.falseExpression, options, parse) }), // TODO: implement print - print: () => ['ConditionalExpression'] + print: () => ['TODO: ConditionalExpression'] }; diff --git a/src/slang-nodes/ConstantDefinition.js b/src/slang-nodes/ConstantDefinition.js index dc9d747ae..7ba05df17 100644 --- a/src/slang-nodes/ConstantDefinition.js +++ b/src/slang-nodes/ConstantDefinition.js @@ -9,5 +9,5 @@ export const ConstantDefinition = { semicolon: ast.semicolon.text }), // TODO: implement print - print: () => ['ConstantDefinition'] + print: () => ['TODO: ConstantDefinition'] }; diff --git a/src/slang-nodes/ConstructorAttributes.js b/src/slang-nodes/ConstructorAttributes.js index 2087d5a15..b314f8f01 100644 --- a/src/slang-nodes/ConstructorAttributes.js +++ b/src/slang-nodes/ConstructorAttributes.js @@ -4,5 +4,5 @@ export const ConstructorAttributes = { items: ast.items.map((item) => parse(item, options, parse)) }), // TODO: implement print - print: () => ['ConstructorAttributes'] + print: () => ['TODO: ConstructorAttributes'] }; diff --git a/src/slang-nodes/ConstructorDefinition.js b/src/slang-nodes/ConstructorDefinition.js index ca3cd791b..372eaef46 100644 --- a/src/slang-nodes/ConstructorDefinition.js +++ b/src/slang-nodes/ConstructorDefinition.js @@ -7,5 +7,5 @@ export const ConstructorDefinition = { body: parse(ast.body, options, parse) }), // TODO: implement print - print: () => ['ConstructorDefinition'] + print: () => ['TODO: ConstructorDefinition'] }; diff --git a/src/slang-nodes/ContinueStatement.js b/src/slang-nodes/ContinueStatement.js index f8ed774e1..58aff03d9 100644 --- a/src/slang-nodes/ContinueStatement.js +++ b/src/slang-nodes/ContinueStatement.js @@ -5,5 +5,5 @@ export const ContinueStatement = { semicolon: ast.semicolon.text }), // TODO: implement print - print: () => ['ContinueStatement'] + print: () => ['TODO: ContinueStatement'] }; diff --git a/src/slang-nodes/ContractDefinition.js b/src/slang-nodes/ContractDefinition.js index d73a22f9d..9cf8f14d3 100644 --- a/src/slang-nodes/ContractDefinition.js +++ b/src/slang-nodes/ContractDefinition.js @@ -1,16 +1,30 @@ +import { doc } from 'prettier'; + +const { group, line } = doc.builders; + export const ContractDefinition = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, abstractKeyword: ast.abstractKeyword?.text, contractKeyword: ast.contractKeyword.text, name: ast.name.text, - inheritence: ast.inheritence + inheritance: ast.inheritence ? parse(ast.inheritence, options, parse) : undefined, openBrace: ast.openBrace.text, members: parse(ast.members, options, parse), closeBrace: ast.closeBrace.text }), - // TODO: implement print - print: () => ['ContractDefinition'] + print: ({ node, path, print }) => [ + group([ + node.abstractKeyword ? `${node.abstractKeyword} ` : '', + node.contractKeyword, + ' ', + node.name, + node.inheritance ? path.call(print, 'inheritance') : line, + node.openBrace + ]), + path.call(print, 'members'), + node.closeBrace + ] }; diff --git a/src/slang-nodes/ContractMembers.js b/src/slang-nodes/ContractMembers.js index ab036d867..effc0ee10 100644 --- a/src/slang-nodes/ContractMembers.js +++ b/src/slang-nodes/ContractMembers.js @@ -1,8 +1,21 @@ +import { doc } from 'prettier'; +import { + printPreservingEmptyLines, + printSeparatedItem +} from '../common/printer-helpers.js'; + +const { hardline } = doc.builders; + export const ContractMembers = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), - // TODO: implement print - print: () => ['ContractMembers'] + print: ({ node, options, path, print }) => + node.items.length > 0 + ? printSeparatedItem( + printPreservingEmptyLines(path, 'items', options, print), + { firstSeparator: hardline, grouped: false } + ) + : '' }; diff --git a/src/slang-nodes/DecimalNumberExpression.js b/src/slang-nodes/DecimalNumberExpression.js index 9a2660d44..477fdf232 100644 --- a/src/slang-nodes/DecimalNumberExpression.js +++ b/src/slang-nodes/DecimalNumberExpression.js @@ -5,5 +5,5 @@ export const DecimalNumberExpression = { unit: ast.unit ? parse(ast.unit, options, parse) : undefined }), // TODO: implement print - print: () => ['DecimalNumberExpression'] + print: () => ['TODO: DecimalNumberExpression'] }; diff --git a/src/slang-nodes/DoWhileStatement.js b/src/slang-nodes/DoWhileStatement.js index 8fb4dae5b..96f29304c 100644 --- a/src/slang-nodes/DoWhileStatement.js +++ b/src/slang-nodes/DoWhileStatement.js @@ -10,5 +10,5 @@ export const DoWhileStatement = { semicolon: ast.semicolon.text }), // TODO: implement print - print: () => ['DoWhileStatement'] + print: () => ['TODO: DoWhileStatement'] }; diff --git a/src/slang-nodes/ElseBranch.js b/src/slang-nodes/ElseBranch.js index 9e97a8a13..c98a2b0ab 100644 --- a/src/slang-nodes/ElseBranch.js +++ b/src/slang-nodes/ElseBranch.js @@ -5,5 +5,5 @@ export const ElseBranch = { body: parse(ast.body, options, parse) }), // TODO: implement print - print: () => ['ElseBranch'] + print: () => ['TODO: ElseBranch'] }; diff --git a/src/slang-nodes/EmitStatement.js b/src/slang-nodes/EmitStatement.js index 3618750c6..66143b240 100644 --- a/src/slang-nodes/EmitStatement.js +++ b/src/slang-nodes/EmitStatement.js @@ -7,5 +7,5 @@ export const EmitStatement = { semicolon: ast.semicolon.text }), // TODO: implement print - print: () => ['EmitStatement'] + print: () => ['TODO: EmitStatement'] }; diff --git a/src/slang-nodes/EnumDefinition.js b/src/slang-nodes/EnumDefinition.js index ef31d87eb..336efde2c 100644 --- a/src/slang-nodes/EnumDefinition.js +++ b/src/slang-nodes/EnumDefinition.js @@ -8,5 +8,5 @@ export const EnumDefinition = { closeBrace: ast.closeBrace.text }), // TODO: implement print - print: () => ['EmitStatement'] + print: () => ['TODO: EmitStatement'] }; diff --git a/src/slang-nodes/EnumMembers.js b/src/slang-nodes/EnumMembers.js index 04d68001e..484a625f9 100644 --- a/src/slang-nodes/EnumMembers.js +++ b/src/slang-nodes/EnumMembers.js @@ -5,5 +5,5 @@ export const EnumMembers = { separators: ast.separators.map((separator) => separator.text) }), // TODO: implement print - print: () => ['EnumMembers'] + print: () => ['TODO: EnumMembers'] }; diff --git a/src/slang-nodes/EqualityExpression.js b/src/slang-nodes/EqualityExpression.js index 8ed7135af..3a3ad092b 100644 --- a/src/slang-nodes/EqualityExpression.js +++ b/src/slang-nodes/EqualityExpression.js @@ -6,5 +6,5 @@ export const EqualityExpression = { rightOperand: parse(ast.rightOperand, options, parse) }), // TODO: implement print - print: () => ['EqualityExpression'] + print: () => ['TODO: EqualityExpression'] }; diff --git a/src/slang-nodes/ErrorDefinition.js b/src/slang-nodes/ErrorDefinition.js index 6b1768e63..9e11e744e 100644 --- a/src/slang-nodes/ErrorDefinition.js +++ b/src/slang-nodes/ErrorDefinition.js @@ -7,5 +7,5 @@ export const ErrorDefinition = { semicolon: ast.semicolon.text }), // TODO: implement print - print: () => ['ErrorDefinition'] + print: () => ['TODO: ErrorDefinition'] }; diff --git a/src/slang-nodes/ErrorParameter.js b/src/slang-nodes/ErrorParameter.js index b426def0e..8f6b3dcec 100644 --- a/src/slang-nodes/ErrorParameter.js +++ b/src/slang-nodes/ErrorParameter.js @@ -5,5 +5,5 @@ export const ErrorParameter = { name: ast.name?.text }), // TODO: implement print - print: () => ['ErrorParameter'] + print: () => ['TODO: ErrorParameter'] }; diff --git a/src/slang-nodes/ErrorParameters.js b/src/slang-nodes/ErrorParameters.js index 54173c7a9..7847e4ef6 100644 --- a/src/slang-nodes/ErrorParameters.js +++ b/src/slang-nodes/ErrorParameters.js @@ -5,5 +5,5 @@ export const ErrorParameters = { separators: ast.separators.map((separator) => separator.text) }), // TODO: implement print - print: () => ['ErrorParameters'] + print: () => ['TODO: ErrorParameters'] }; diff --git a/src/slang-nodes/ErrorParametersDeclaration.js b/src/slang-nodes/ErrorParametersDeclaration.js index 8b4328a14..d697e1b4c 100644 --- a/src/slang-nodes/ErrorParametersDeclaration.js +++ b/src/slang-nodes/ErrorParametersDeclaration.js @@ -6,5 +6,5 @@ export const ErrorParametersDeclaration = { closeParen: ast.closeParen.text }), // TODO: implement print - print: () => ['ErrorParametersDeclaration'] + print: () => ['TODO: ErrorParametersDeclaration'] }; diff --git a/src/slang-nodes/EventDefinition.js b/src/slang-nodes/EventDefinition.js index 91dd2856e..f756a2cee 100644 --- a/src/slang-nodes/EventDefinition.js +++ b/src/slang-nodes/EventDefinition.js @@ -8,5 +8,5 @@ export const EventDefinition = { semicolon: ast.semicolon.text }), // TODO: implement print - print: () => ['EventDefinition'] + print: () => ['TODO: EventDefinition'] }; diff --git a/src/slang-nodes/EventParameter.js b/src/slang-nodes/EventParameter.js index dcbb6c048..eb81474e0 100644 --- a/src/slang-nodes/EventParameter.js +++ b/src/slang-nodes/EventParameter.js @@ -6,5 +6,5 @@ export const EventParameter = { name: ast.name?.text }), // TODO: implement print - print: () => ['EventParameter'] + print: () => ['TODO: EventParameter'] }; diff --git a/src/slang-nodes/EventParameters.js b/src/slang-nodes/EventParameters.js index 8a60296ec..aea0439ba 100644 --- a/src/slang-nodes/EventParameters.js +++ b/src/slang-nodes/EventParameters.js @@ -5,5 +5,5 @@ export const EventParameters = { separators: ast.separators.map((separator) => separator.text) }), // TODO: implement print - print: () => ['EventParameters'] + print: () => ['TODO: EventParameters'] }; diff --git a/src/slang-nodes/EventParametersDeclaration.js b/src/slang-nodes/EventParametersDeclaration.js index d8fbc90c9..a307765f9 100644 --- a/src/slang-nodes/EventParametersDeclaration.js +++ b/src/slang-nodes/EventParametersDeclaration.js @@ -6,5 +6,5 @@ export const EventParametersDeclaration = { closeParen: ast.closeParen.text }), // TODO: implement print - print: () => ['EventParametersDeclaration'] + print: () => ['TODO: EventParametersDeclaration'] }; diff --git a/src/slang-nodes/ExperimentalPragma.js b/src/slang-nodes/ExperimentalPragma.js index f7d9c4f48..6f1db6f5d 100644 --- a/src/slang-nodes/ExperimentalPragma.js +++ b/src/slang-nodes/ExperimentalPragma.js @@ -5,5 +5,5 @@ export const ExperimentalPragma = { feature: ast.feature }), // TODO: implement print - print: () => ['ExperimentalPragma'] + print: () => ['TODO: ExperimentalPragma'] }; diff --git a/src/slang-nodes/ExponentiationExpression.js b/src/slang-nodes/ExponentiationExpression.js index d76f4d479..903b17c1a 100644 --- a/src/slang-nodes/ExponentiationExpression.js +++ b/src/slang-nodes/ExponentiationExpression.js @@ -6,5 +6,5 @@ export const ExponentiationExpression = { rightOperand: parse(ast.rightOperand, options, parse) }), // TODO: implement print - print: () => ['ExponentiationExpression'] + print: () => ['TODO: ExponentiationExpression'] }; diff --git a/src/slang-nodes/ExpressionStatement.js b/src/slang-nodes/ExpressionStatement.js index e0e627a87..29fbaefb6 100644 --- a/src/slang-nodes/ExpressionStatement.js +++ b/src/slang-nodes/ExpressionStatement.js @@ -5,5 +5,5 @@ export const ExpressionStatement = { semicolon: ast.semicolon.text }), // TODO: implement print - print: () => ['ExpressionStatement'] + print: () => ['TODO: ExpressionStatement'] }; diff --git a/src/slang-nodes/FallbackFunctionAttributes.js b/src/slang-nodes/FallbackFunctionAttributes.js index caff8fb6d..e8575f40d 100644 --- a/src/slang-nodes/FallbackFunctionAttributes.js +++ b/src/slang-nodes/FallbackFunctionAttributes.js @@ -4,5 +4,5 @@ export const FallbackFunctionAttributes = { items: ast.items.map((item) => parse(item, options, parse)) }), // TODO: implement print - print: () => ['FallbackFunctionAttributes'] + print: () => ['TODO: FallbackFunctionAttributes'] }; diff --git a/src/slang-nodes/FallbackFunctionDefinition.js b/src/slang-nodes/FallbackFunctionDefinition.js index 79fa159e1..5cbc60fe6 100644 --- a/src/slang-nodes/FallbackFunctionDefinition.js +++ b/src/slang-nodes/FallbackFunctionDefinition.js @@ -8,5 +8,5 @@ export const FallbackFunctionDefinition = { body: parse(ast.body, options, parse) }), // TODO: implement print - print: () => ['FallbackFunctionDefinition'] + print: () => ['TODO: FallbackFunctionDefinition'] }; diff --git a/src/slang-nodes/ForStatement.js b/src/slang-nodes/ForStatement.js index f483dc42d..498dfe0b0 100644 --- a/src/slang-nodes/ForStatement.js +++ b/src/slang-nodes/ForStatement.js @@ -10,5 +10,5 @@ export const ForStatement = { body: parse(ast.body, options, parse) }), // TODO: implement print - print: () => ['ForStatement'] + print: () => ['TODO: ForStatement'] }; diff --git a/src/slang-nodes/FunctionAttributes.js b/src/slang-nodes/FunctionAttributes.js index dc764df58..9306d51da 100644 --- a/src/slang-nodes/FunctionAttributes.js +++ b/src/slang-nodes/FunctionAttributes.js @@ -4,5 +4,5 @@ export const FunctionAttributes = { items: ast.items.map((item) => parse(item, options, parse)) }), // TODO: implement print - print: () => ['FunctionAttributes'] + print: () => ['TODO: FunctionAttributes'] }; diff --git a/src/slang-nodes/FunctionCallExpression.js b/src/slang-nodes/FunctionCallExpression.js index 2348c1df5..fac896ad6 100644 --- a/src/slang-nodes/FunctionCallExpression.js +++ b/src/slang-nodes/FunctionCallExpression.js @@ -5,5 +5,5 @@ export const FunctionCallExpression = { arguments: parse(ast.arguments, options, parse) }), // TODO: implement print - print: () => ['FunctionCallExpression'] + print: () => ['TODO: FunctionCallExpression'] }; diff --git a/src/slang-nodes/FunctionDefinition.js b/src/slang-nodes/FunctionDefinition.js index c7f053728..903085d86 100644 --- a/src/slang-nodes/FunctionDefinition.js +++ b/src/slang-nodes/FunctionDefinition.js @@ -9,5 +9,5 @@ export const FunctionDefinition = { body: parse(ast.body, options, parse) }), // TODO: implement print - print: () => ['FunctionDefinition'] + print: () => ['TODO: FunctionDefinition'] }; diff --git a/src/slang-nodes/FunctionType.js b/src/slang-nodes/FunctionType.js index dbfcdc31c..14fd0e212 100644 --- a/src/slang-nodes/FunctionType.js +++ b/src/slang-nodes/FunctionType.js @@ -7,5 +7,5 @@ export const FunctionType = { returns: ast.returns ? parse(ast.returns, options, parse) : undefined }), // TODO: implement print - print: () => ['FunctionType'] + print: () => ['TODO: FunctionType'] }; diff --git a/src/slang-nodes/FunctionTypeAttributes.js b/src/slang-nodes/FunctionTypeAttributes.js index 176694ff9..ffa807f08 100644 --- a/src/slang-nodes/FunctionTypeAttributes.js +++ b/src/slang-nodes/FunctionTypeAttributes.js @@ -4,5 +4,5 @@ export const FunctionTypeAttributes = { items: ast.items.map((item) => parse(item, options, parse)) }), // TODO: implement print - print: () => ['FunctionTypeAttributes'] + print: () => ['TODO: FunctionTypeAttributes'] }; diff --git a/src/slang-nodes/HexNumberExpression.js b/src/slang-nodes/HexNumberExpression.js index 02812f72b..c009dc879 100644 --- a/src/slang-nodes/HexNumberExpression.js +++ b/src/slang-nodes/HexNumberExpression.js @@ -5,5 +5,5 @@ export const HexNumberExpression = { unit: ast.unit ? parse(ast.unit, options, parse) : undefined }), // TODO: implement print - print: () => ['HexNumberExpression'] + print: () => ['TODO: HexNumberExpression'] }; diff --git a/src/slang-nodes/HexStringLiterals.js b/src/slang-nodes/HexStringLiterals.js index e674c4d94..8f9a40028 100644 --- a/src/slang-nodes/HexStringLiterals.js +++ b/src/slang-nodes/HexStringLiterals.js @@ -4,5 +4,5 @@ export const HexStringLiterals = { items: ast.items.map((item) => parse(item, options, parse)) }), // TODO: implement print - print: () => ['HexStringLiterals'] + print: () => ['TODO: HexStringLiterals'] }; diff --git a/src/slang-nodes/IdentifierPath.js b/src/slang-nodes/IdentifierPath.js index cd5774b5f..5bc447940 100644 --- a/src/slang-nodes/IdentifierPath.js +++ b/src/slang-nodes/IdentifierPath.js @@ -5,5 +5,5 @@ export const IdentifierPath = { separators: ast.separators.map((separator) => separator.text) }), // TODO: implement print - print: () => ['IdentifierPath'] + print: () => ['TODO: IdentifierPath'] }; diff --git a/src/slang-nodes/IfStatement.js b/src/slang-nodes/IfStatement.js index 14ee0e0f0..8bab155f9 100644 --- a/src/slang-nodes/IfStatement.js +++ b/src/slang-nodes/IfStatement.js @@ -11,5 +11,5 @@ export const IfStatement = { : undefined }), // TODO: implement print - print: () => ['IfStatement'] + print: () => ['TODO: IfStatement'] }; diff --git a/src/slang-nodes/ImportAlias.js b/src/slang-nodes/ImportAlias.js index b438e899a..b1100b25a 100644 --- a/src/slang-nodes/ImportAlias.js +++ b/src/slang-nodes/ImportAlias.js @@ -5,5 +5,5 @@ export const ImportAlias = { identifier: ast.identifier.text }), // TODO: implement print - print: () => ['ImportAlias'] + print: () => ['TODO: ImportAlias'] }; diff --git a/src/slang-nodes/ImportDeconstruction.js b/src/slang-nodes/ImportDeconstruction.js index e55789b07..d654179df 100644 --- a/src/slang-nodes/ImportDeconstruction.js +++ b/src/slang-nodes/ImportDeconstruction.js @@ -8,5 +8,5 @@ export const ImportDeconstruction = { path: parse(ast.path, options, parse) }), // TODO: implement print - print: () => ['ImportDeconstruction'] + print: () => ['TODO: ImportDeconstruction'] }; diff --git a/src/slang-nodes/ImportDeconstructionSymbol.js b/src/slang-nodes/ImportDeconstructionSymbol.js index 0ddcfe435..1ccbf43d6 100644 --- a/src/slang-nodes/ImportDeconstructionSymbol.js +++ b/src/slang-nodes/ImportDeconstructionSymbol.js @@ -5,5 +5,5 @@ export const ImportDeconstructionSymbol = { alias: ast.alias ? parse(ast.alias, options, parse) : undefined }), // TODO: implement print - print: () => ['ImportDeconstructionSymbol'] + print: () => ['TODO: ImportDeconstructionSymbol'] }; diff --git a/src/slang-nodes/ImportDeconstructionSymbols.js b/src/slang-nodes/ImportDeconstructionSymbols.js index c4bea2f5b..06b9665e7 100644 --- a/src/slang-nodes/ImportDeconstructionSymbols.js +++ b/src/slang-nodes/ImportDeconstructionSymbols.js @@ -5,5 +5,5 @@ export const ImportDeconstructionSymbols = { separators: ast.separators.map((separator) => separator.text) }), // TODO: implement print - print: () => ['ImportDeconstructionSymbols'] + print: () => ['TODO: ImportDeconstructionSymbols'] }; diff --git a/src/slang-nodes/ImportDirective.js b/src/slang-nodes/ImportDirective.js index 0de38d8ec..725494eed 100644 --- a/src/slang-nodes/ImportDirective.js +++ b/src/slang-nodes/ImportDirective.js @@ -6,5 +6,5 @@ export const ImportDirective = { semicolon: ast.semicolon.text }), // TODO: implement print - print: () => ['ImportDirective'] + print: () => ['TODO: ImportDirective'] }; diff --git a/src/slang-nodes/IndexAccessEnd.js b/src/slang-nodes/IndexAccessEnd.js index c5c7c6111..3e0b910a5 100644 --- a/src/slang-nodes/IndexAccessEnd.js +++ b/src/slang-nodes/IndexAccessEnd.js @@ -5,5 +5,5 @@ export const IndexAccessEnd = { end: ast.end ? parse(ast.end, options, parse) : undefined }), // TODO: implement print - print: () => ['IndexAccessEnd'] + print: () => ['TODO: IndexAccessEnd'] }; diff --git a/src/slang-nodes/IndexAccessExpression.js b/src/slang-nodes/IndexAccessExpression.js index f8331349b..7d690a95f 100644 --- a/src/slang-nodes/IndexAccessExpression.js +++ b/src/slang-nodes/IndexAccessExpression.js @@ -8,5 +8,5 @@ export const IndexAccessExpression = { closeBracket: ast.closeBracket.text }), // TODO: implement print - print: () => ['IndexAccessExpression'] + print: () => ['TODO: IndexAccessExpression'] }; diff --git a/src/slang-nodes/InheritanceSpecifier.js b/src/slang-nodes/InheritanceSpecifier.js index 884d21e8e..eea85fc5c 100644 --- a/src/slang-nodes/InheritanceSpecifier.js +++ b/src/slang-nodes/InheritanceSpecifier.js @@ -5,5 +5,5 @@ export const InheritanceSpecifier = { types: parse(ast.types, options, parse) }), // TODO: implement print - print: () => ['InheritanceSpecifier'] + print: () => ['TODO: InheritanceSpecifier'] }; diff --git a/src/slang-nodes/InheritanceType.js b/src/slang-nodes/InheritanceType.js index 1ef3489cc..cbc3f0e96 100644 --- a/src/slang-nodes/InheritanceType.js +++ b/src/slang-nodes/InheritanceType.js @@ -5,5 +5,5 @@ export const InheritanceType = { arguments: ast.arguments ? parse(ast.arguments, options, parse) : undefined }), // TODO: implement print - print: () => ['InheritanceType'] + print: () => ['TODO: InheritanceType'] }; diff --git a/src/slang-nodes/InheritanceTypes.js b/src/slang-nodes/InheritanceTypes.js index 24d1ec8d0..11d381622 100644 --- a/src/slang-nodes/InheritanceTypes.js +++ b/src/slang-nodes/InheritanceTypes.js @@ -5,5 +5,5 @@ export const InheritanceTypes = { separators: ast.separators.map((separator) => separator.text) }), // TODO: implement print - print: () => ['InheritanceTypes'] + print: () => ['TODO: InheritanceTypes'] }; diff --git a/src/slang-nodes/InterfaceDefinition.js b/src/slang-nodes/InterfaceDefinition.js index 7496618f2..a3940f900 100644 --- a/src/slang-nodes/InterfaceDefinition.js +++ b/src/slang-nodes/InterfaceDefinition.js @@ -11,5 +11,5 @@ export const InterfaceDefinition = { closeBrace: ast.closeBrace.text }), // TODO: implement print - print: () => ['InterfaceDefinition'] + print: () => ['TODO: InterfaceDefinition'] }; diff --git a/src/slang-nodes/InterfaceMembers.js b/src/slang-nodes/InterfaceMembers.js index ff9694e95..741d55d87 100644 --- a/src/slang-nodes/InterfaceMembers.js +++ b/src/slang-nodes/InterfaceMembers.js @@ -5,5 +5,5 @@ export const InterfaceMembers = { types: parse(ast.types, options, parse) }), // TODO: implement print - print: () => ['InterfaceMembers'] + print: () => ['TODO: InterfaceMembers'] }; diff --git a/src/slang-nodes/LibraryDefinition.js b/src/slang-nodes/LibraryDefinition.js index 5a65113a5..d5479d8d4 100644 --- a/src/slang-nodes/LibraryDefinition.js +++ b/src/slang-nodes/LibraryDefinition.js @@ -8,5 +8,5 @@ export const LibraryDefinition = { closeBrace: ast.closeBrace.text }), // TODO: implement print - print: () => ['LibraryDefinition'] + print: () => ['TODO: LibraryDefinition'] }; diff --git a/src/slang-nodes/LibraryMembers.js b/src/slang-nodes/LibraryMembers.js index 6087b69b3..50cf0f082 100644 --- a/src/slang-nodes/LibraryMembers.js +++ b/src/slang-nodes/LibraryMembers.js @@ -4,5 +4,5 @@ export const LibraryMembers = { items: ast.items.map((item) => parse(item, options, parse)) }), // TODO: implement print - print: () => ['LibraryMembers'] + print: () => ['TODO: LibraryMembers'] }; diff --git a/src/slang-nodes/MappingKey.js b/src/slang-nodes/MappingKey.js index 4a3cb1054..e88a51eaa 100644 --- a/src/slang-nodes/MappingKey.js +++ b/src/slang-nodes/MappingKey.js @@ -5,5 +5,5 @@ export const MappingKey = { name: ast.name?.text }), // TODO: implement print - print: () => ['MappingKey'] + print: () => ['TODO: MappingKey'] }; diff --git a/src/slang-nodes/MappingType.js b/src/slang-nodes/MappingType.js index 2b1f524f8..641935c56 100644 --- a/src/slang-nodes/MappingType.js +++ b/src/slang-nodes/MappingType.js @@ -9,5 +9,5 @@ export const MappingType = { closeParen: ast.closeParen.text }), // TODO: implement print - print: () => ['MappingType'] + print: () => ['TODO: MappingType'] }; diff --git a/src/slang-nodes/MappingValue.js b/src/slang-nodes/MappingValue.js index 304617c9e..014fbcb24 100644 --- a/src/slang-nodes/MappingValue.js +++ b/src/slang-nodes/MappingValue.js @@ -5,5 +5,5 @@ export const MappingValue = { name: ast.name?.text }), // TODO: implement print - print: () => ['MappingValue'] + print: () => ['TODO: MappingValue'] }; diff --git a/src/slang-nodes/MemberAccessExpression.js b/src/slang-nodes/MemberAccessExpression.js index e1f025ed4..2d1d5e457 100644 --- a/src/slang-nodes/MemberAccessExpression.js +++ b/src/slang-nodes/MemberAccessExpression.js @@ -6,5 +6,5 @@ export const MemberAccessExpression = { member: parse(ast.member, options, parse) }), // TODO: implement print - print: () => ['MemberAccessExpression'] + print: () => ['TODO: MemberAccessExpression'] }; diff --git a/src/slang-nodes/ModifierInvocation.js b/src/slang-nodes/ModifierInvocation.js index 2c44e52c3..b8d62495d 100644 --- a/src/slang-nodes/ModifierInvocation.js +++ b/src/slang-nodes/ModifierInvocation.js @@ -5,5 +5,5 @@ export const ModifierInvocation = { arguments: ast.arguments ? parse(ast.arguments, options, parse) : undefined }), // TODO: implement print - print: () => ['ModifierInvocation'] + print: () => ['TODO: ModifierInvocation'] }; diff --git a/src/slang-nodes/MultiplicativeExpression.js b/src/slang-nodes/MultiplicativeExpression.js index 582d3706b..c5f356ac8 100644 --- a/src/slang-nodes/MultiplicativeExpression.js +++ b/src/slang-nodes/MultiplicativeExpression.js @@ -6,5 +6,5 @@ export const MultiplicativeExpression = { rightOperand: parse(ast.rightOperand, options, parse) }), // TODO: implement print - print: () => ['MultiplicativeExpression'] + print: () => ['TODO: MultiplicativeExpression'] }; diff --git a/src/slang-nodes/NamedArgument.js b/src/slang-nodes/NamedArgument.js index 4d1e9652a..f753552a3 100644 --- a/src/slang-nodes/NamedArgument.js +++ b/src/slang-nodes/NamedArgument.js @@ -6,5 +6,5 @@ export const NamedArgument = { value: parse(ast.value, options, parse) }), // TODO: implement print - print: () => ['NamedArgument'] + print: () => ['TODO: NamedArgument'] }; diff --git a/src/slang-nodes/NamedArgumentGroup.js b/src/slang-nodes/NamedArgumentGroup.js index 9efe19240..1a5434410 100644 --- a/src/slang-nodes/NamedArgumentGroup.js +++ b/src/slang-nodes/NamedArgumentGroup.js @@ -6,5 +6,5 @@ export const NamedArgumentGroup = { closeBrace: ast.closeBrace.text }), // TODO: implement print - print: () => ['NamedArgumentGroup'] + print: () => ['TODO: NamedArgumentGroup'] }; diff --git a/src/slang-nodes/NamedArguments.js b/src/slang-nodes/NamedArguments.js index 3fac2f04a..f227e9ac3 100644 --- a/src/slang-nodes/NamedArguments.js +++ b/src/slang-nodes/NamedArguments.js @@ -5,5 +5,5 @@ export const NamedArguments = { separators: ast.separators.map((separator) => separator.text) }), // TODO: implement print - print: () => ['NamedArguments'] + print: () => ['TODO: NamedArguments'] }; diff --git a/src/slang-nodes/NamedArgumentsDeclaration.js b/src/slang-nodes/NamedArgumentsDeclaration.js index 9fbc632f8..767f1277b 100644 --- a/src/slang-nodes/NamedArgumentsDeclaration.js +++ b/src/slang-nodes/NamedArgumentsDeclaration.js @@ -6,5 +6,5 @@ export const NamedArgumentsDeclaration = { closeParen: ast.closeParen.text }), // TODO: implement print - print: () => ['NamedArgumentsDeclaration'] + print: () => ['TODO: NamedArgumentsDeclaration'] }; diff --git a/src/slang-nodes/NamedImport.js b/src/slang-nodes/NamedImport.js index 251bee917..25c971893 100644 --- a/src/slang-nodes/NamedImport.js +++ b/src/slang-nodes/NamedImport.js @@ -7,5 +7,5 @@ export const NamedImport = { path: parse(ast.path, options, parse) }), // TODO: implement print - print: () => ['NamedImport'] + print: () => ['TODO: NamedImport'] }; diff --git a/src/slang-nodes/NewExpression.js b/src/slang-nodes/NewExpression.js index c19d3c6ea..1ebf8c370 100644 --- a/src/slang-nodes/NewExpression.js +++ b/src/slang-nodes/NewExpression.js @@ -5,5 +5,5 @@ export const NewExpression = { typeName: parse(ast.typeName, options, parse) }), // TODO: implement print - print: () => ['NewExpression'] + print: () => ['TODO: NewExpression'] }; diff --git a/src/slang-nodes/OrExpression.js b/src/slang-nodes/OrExpression.js index 8c9184440..dcc957596 100644 --- a/src/slang-nodes/OrExpression.js +++ b/src/slang-nodes/OrExpression.js @@ -6,5 +6,5 @@ export const OrExpression = { rightOperand: parse(ast.rightOperand, options, parse) }), // TODO: implement print - print: () => ['OrExpression'] + print: () => ['TODO: OrExpression'] }; diff --git a/src/slang-nodes/OverridePaths.js b/src/slang-nodes/OverridePaths.js index e14c80cf2..f70297e26 100644 --- a/src/slang-nodes/OverridePaths.js +++ b/src/slang-nodes/OverridePaths.js @@ -5,5 +5,5 @@ export const OverridePaths = { separators: ast.separators.map((separator) => separator) }), // TODO: implement print - print: () => ['OverridePaths'] + print: () => ['TODO: OverridePaths'] }; diff --git a/src/slang-nodes/OverridePathsDeclaration.js b/src/slang-nodes/OverridePathsDeclaration.js index 159268c69..c954a2d1b 100644 --- a/src/slang-nodes/OverridePathsDeclaration.js +++ b/src/slang-nodes/OverridePathsDeclaration.js @@ -6,5 +6,5 @@ export const OverridePathsDeclaration = { closeParen: ast.closeParen.text }), // TODO: implement print - print: () => ['OverridePathsDeclaration'] + print: () => ['TODO: OverridePathsDeclaration'] }; diff --git a/src/slang-nodes/OverrideSpecifier.js b/src/slang-nodes/OverrideSpecifier.js index c304fe2a0..639a15a0e 100644 --- a/src/slang-nodes/OverrideSpecifier.js +++ b/src/slang-nodes/OverrideSpecifier.js @@ -7,5 +7,5 @@ export const OverrideSpecifier = { : undefined }), // TODO: implement print - print: () => ['OverrideSpecifier'] + print: () => ['TODO: OverrideSpecifier'] }; diff --git a/src/slang-nodes/Parameter.js b/src/slang-nodes/Parameter.js index 9c3fa18a8..687c27fb8 100644 --- a/src/slang-nodes/Parameter.js +++ b/src/slang-nodes/Parameter.js @@ -8,5 +8,5 @@ export const Parameter = { name: ast.name?.text }), // TODO: implement print - print: () => ['Parameter'] + print: () => ['TODO: Parameter'] }; diff --git a/src/slang-nodes/Parameters.js b/src/slang-nodes/Parameters.js index 3cdaa5e57..a72422fd3 100644 --- a/src/slang-nodes/Parameters.js +++ b/src/slang-nodes/Parameters.js @@ -5,5 +5,5 @@ export const Parameters = { separators: ast.separators.map((separator) => separator.text) }), // TODO: implement print - print: () => ['Parameters'] + print: () => ['TODO: Parameters'] }; diff --git a/src/slang-nodes/ParametersDeclaration.js b/src/slang-nodes/ParametersDeclaration.js index 9b938e067..a1c44654a 100644 --- a/src/slang-nodes/ParametersDeclaration.js +++ b/src/slang-nodes/ParametersDeclaration.js @@ -6,5 +6,5 @@ export const ParametersDeclaration = { closeParen: ast.closeParen.text }), // TODO: implement print - print: () => ['ParametersDeclaration'] + print: () => ['TODO: ParametersDeclaration'] }; diff --git a/src/slang-nodes/PathImport.js b/src/slang-nodes/PathImport.js index 98b29651a..c9cad5e1c 100644 --- a/src/slang-nodes/PathImport.js +++ b/src/slang-nodes/PathImport.js @@ -5,5 +5,5 @@ export const PathImport = { alias: ast.alias ? parse(ast.alias, options, parse) : undefined }), // TODO: implement print - print: () => ['PathImport'] + print: () => ['TODO: PathImport'] }; diff --git a/src/slang-nodes/PositionalArguments.js b/src/slang-nodes/PositionalArguments.js index dbf13a984..6a1963851 100644 --- a/src/slang-nodes/PositionalArguments.js +++ b/src/slang-nodes/PositionalArguments.js @@ -5,5 +5,5 @@ export const PositionalArguments = { separators: ast.separators.map((separator) => separator.text) }), // TODO: implement print - print: () => ['PositionalArguments'] + print: () => ['TODO: PositionalArguments'] }; diff --git a/src/slang-nodes/PositionalArgumentsDeclaration.js b/src/slang-nodes/PositionalArgumentsDeclaration.js index 50f2c631f..2863deb39 100644 --- a/src/slang-nodes/PositionalArgumentsDeclaration.js +++ b/src/slang-nodes/PositionalArgumentsDeclaration.js @@ -6,5 +6,5 @@ export const PositionalArgumentsDeclaration = { closeParen: ast.closeParen.TokenNode }), // TODO: implement print - print: () => ['PositionalArgumentsDeclaration'] + print: () => ['TODO: PositionalArgumentsDeclaration'] }; diff --git a/src/slang-nodes/PostfixExpression.js b/src/slang-nodes/PostfixExpression.js index 36065d69a..609946cac 100644 --- a/src/slang-nodes/PostfixExpression.js +++ b/src/slang-nodes/PostfixExpression.js @@ -5,5 +5,5 @@ export const PostfixExpression = { operator: ast.operator.text }), // TODO: implement print - print: () => ['PostfixExpression'] + print: () => ['TODO: PostfixExpression'] }; diff --git a/src/slang-nodes/PrefixExpression.js b/src/slang-nodes/PrefixExpression.js index 1f88469c5..712a441d8 100644 --- a/src/slang-nodes/PrefixExpression.js +++ b/src/slang-nodes/PrefixExpression.js @@ -5,5 +5,5 @@ export const PrefixExpression = { operand: parse(ast.operand, options, parse) }), // TODO: implement print - print: () => ['PrefixExpression'] + print: () => ['TODO: PrefixExpression'] }; diff --git a/src/slang-nodes/ReceiveFunctionAttributes.js b/src/slang-nodes/ReceiveFunctionAttributes.js index 64bc062a2..e40b10481 100644 --- a/src/slang-nodes/ReceiveFunctionAttributes.js +++ b/src/slang-nodes/ReceiveFunctionAttributes.js @@ -4,5 +4,5 @@ export const ReceiveFunctionAttributes = { items: ast.items.map((item) => parse(item, options, parse)) }), // TODO: implement print - print: () => ['ReceiveFunctionAttributes'] + print: () => ['TODO: ReceiveFunctionAttributes'] }; diff --git a/src/slang-nodes/ReceiveFunctionDefinition.js b/src/slang-nodes/ReceiveFunctionDefinition.js index ea5addb0e..97a44de32 100644 --- a/src/slang-nodes/ReceiveFunctionDefinition.js +++ b/src/slang-nodes/ReceiveFunctionDefinition.js @@ -7,5 +7,5 @@ export const ReceiveFunctionDefinition = { body: parse(ast.body, options, parse) }), // TODO: implement print - print: () => ['ReceiveFunctionDefinition'] + print: () => ['TODO: ReceiveFunctionDefinition'] }; diff --git a/src/slang-nodes/ReturnStatement.js b/src/slang-nodes/ReturnStatement.js index 34e276936..df7b94bf6 100644 --- a/src/slang-nodes/ReturnStatement.js +++ b/src/slang-nodes/ReturnStatement.js @@ -8,5 +8,5 @@ export const ReturnStatement = { semicolon: ast.semicolon.text }), // TODO: implement print - print: () => ['ReturnStatement'] + print: () => ['TODO: ReturnStatement'] }; diff --git a/src/slang-nodes/ReturnsDeclaration.js b/src/slang-nodes/ReturnsDeclaration.js index 46f74b7ad..5f6dfb9e0 100644 --- a/src/slang-nodes/ReturnsDeclaration.js +++ b/src/slang-nodes/ReturnsDeclaration.js @@ -5,5 +5,5 @@ export const ReturnsDeclaration = { variables: parse(ast.variables, options, parse) }), // TODO: implement print - print: () => ['ReturnsDeclaration'] + print: () => ['TODO: ReturnsDeclaration'] }; diff --git a/src/slang-nodes/RevertStatement.js b/src/slang-nodes/RevertStatement.js index 91b3b165c..0338bc34e 100644 --- a/src/slang-nodes/RevertStatement.js +++ b/src/slang-nodes/RevertStatement.js @@ -7,5 +7,5 @@ export const RevertStatement = { semicolon: ast.semicolon.text }), // TODO: implement print - print: () => ['RevertStatement'] + print: () => ['TODO: RevertStatement'] }; diff --git a/src/slang-nodes/ShiftExpression.js b/src/slang-nodes/ShiftExpression.js index 0481fb86f..f48796516 100644 --- a/src/slang-nodes/ShiftExpression.js +++ b/src/slang-nodes/ShiftExpression.js @@ -6,5 +6,5 @@ export const ShiftExpression = { rightOperand: parse(ast.rightOperand, options, parse) }), // TODO: implement print - print: () => ['ShiftExpression'] + print: () => ['TODO: ShiftExpression'] }; diff --git a/src/slang-nodes/StateVariableAttributes.js b/src/slang-nodes/StateVariableAttributes.js index 3e36c392c..52d9214ef 100644 --- a/src/slang-nodes/StateVariableAttributes.js +++ b/src/slang-nodes/StateVariableAttributes.js @@ -4,5 +4,5 @@ export const StateVariableAttributes = { items: ast.items.map((item) => parse(item, options, parse)) }), // TODO: implement print - print: () => ['StateVariableAttributes'] + print: () => ['TODO: StateVariableAttributes'] }; diff --git a/src/slang-nodes/StateVariableDefinition.js b/src/slang-nodes/StateVariableDefinition.js index 8a96d991f..d00166106 100644 --- a/src/slang-nodes/StateVariableDefinition.js +++ b/src/slang-nodes/StateVariableDefinition.js @@ -8,5 +8,5 @@ export const StateVariableDefinition = { semicolon: ast.semicolon.text }), // TODO: implement print - print: () => ['StateVariableDefinition'] + print: () => ['TODO: StateVariableDefinition'] }; diff --git a/src/slang-nodes/StateVariableDefinitionValue.js b/src/slang-nodes/StateVariableDefinitionValue.js index d6c081fbb..3516e5de2 100644 --- a/src/slang-nodes/StateVariableDefinitionValue.js +++ b/src/slang-nodes/StateVariableDefinitionValue.js @@ -5,5 +5,5 @@ export const StateVariableDefinitionValue = { value: parse(ast.value, options, parse) }), // TODO: implement print - print: () => ['StateVariableDefinitionValue'] + print: () => ['TODO: StateVariableDefinitionValue'] }; diff --git a/src/slang-nodes/Statements.js b/src/slang-nodes/Statements.js index ab41a6d24..8abb2c105 100644 --- a/src/slang-nodes/Statements.js +++ b/src/slang-nodes/Statements.js @@ -4,5 +4,5 @@ export const Statements = { items: ast.items.map((item) => parse(item, options, parse)) }), // TODO: implement print - print: () => ['Statements'] + print: () => ['TODO: Statements'] }; diff --git a/src/slang-nodes/StringLiterals.js b/src/slang-nodes/StringLiterals.js index 1b6be2ed9..e66d9b2ef 100644 --- a/src/slang-nodes/StringLiterals.js +++ b/src/slang-nodes/StringLiterals.js @@ -4,5 +4,5 @@ export const StringLiterals = { items: ast.items.map((item) => parse(item, options, parse)) }), // TODO: implement print - print: () => ['StringLiterals'] + print: () => ['TODO: StringLiterals'] }; diff --git a/src/slang-nodes/StructDefinition.js b/src/slang-nodes/StructDefinition.js index 85cc79050..c074b2eec 100644 --- a/src/slang-nodes/StructDefinition.js +++ b/src/slang-nodes/StructDefinition.js @@ -8,5 +8,5 @@ export const StructDefinition = { closeBrace: ast.closeBrace.text }), // TODO: implement print - print: () => ['StructDefinition'] + print: () => ['TODO: StructDefinition'] }; diff --git a/src/slang-nodes/StructMember.js b/src/slang-nodes/StructMember.js index b8b95c03a..265bf7101 100644 --- a/src/slang-nodes/StructMember.js +++ b/src/slang-nodes/StructMember.js @@ -6,5 +6,5 @@ export const StructMember = { semicolon: ast.semicolon.text }), // TODO: implement print - print: () => ['StructMember'] + print: () => ['TODO: StructMember'] }; diff --git a/src/slang-nodes/StructMembers.js b/src/slang-nodes/StructMembers.js index f3baf9d74..0d71f3d1b 100644 --- a/src/slang-nodes/StructMembers.js +++ b/src/slang-nodes/StructMembers.js @@ -4,5 +4,5 @@ export const StructMembers = { items: ast.items.map((item) => parse(item, options, parse)) }), // TODO: implement print - print: () => ['StructMembers'] + print: () => ['TODO: StructMembers'] }; diff --git a/src/slang-nodes/ThrowStatement.js b/src/slang-nodes/ThrowStatement.js index dedc7c00f..9f56e1687 100644 --- a/src/slang-nodes/ThrowStatement.js +++ b/src/slang-nodes/ThrowStatement.js @@ -5,5 +5,5 @@ export const ThrowStatement = { semicolon: ast.semicolon.text }), // TODO: implement print - print: () => ['ThrowStatement'] + print: () => ['TODO: ThrowStatement'] }; diff --git a/src/slang-nodes/TryStatement.js b/src/slang-nodes/TryStatement.js index 89bde2649..38e6e6497 100644 --- a/src/slang-nodes/TryStatement.js +++ b/src/slang-nodes/TryStatement.js @@ -8,5 +8,5 @@ export const TryStatement = { catchClauses: parse(ast.catchClauses, options, parse) }), // TODO: implement print - print: () => ['TryStatement'] + print: () => ['TODO: TryStatement'] }; diff --git a/src/slang-nodes/TupleDeconstructionElement.js b/src/slang-nodes/TupleDeconstructionElement.js index 65e85ae08..72070dd1f 100644 --- a/src/slang-nodes/TupleDeconstructionElement.js +++ b/src/slang-nodes/TupleDeconstructionElement.js @@ -4,5 +4,5 @@ export const TupleDeconstructionElement = { member: ast.member ? parse(ast.member, options, parse) : undefined }), // TODO: implement print - print: () => ['TupleDeconstructionElement'] + print: () => ['TODO: TupleDeconstructionElement'] }; diff --git a/src/slang-nodes/TupleDeconstructionElements.js b/src/slang-nodes/TupleDeconstructionElements.js index 5f453b6a6..a25540d02 100644 --- a/src/slang-nodes/TupleDeconstructionElements.js +++ b/src/slang-nodes/TupleDeconstructionElements.js @@ -5,5 +5,5 @@ export const TupleDeconstructionElements = { separators: ast.separators.map((separator) => separator.text) }), // TODO: implement print - print: () => ['TupleDeconstructionElements'] + print: () => ['TODO: TupleDeconstructionElements'] }; diff --git a/src/slang-nodes/TupleDeconstructionStatement.js b/src/slang-nodes/TupleDeconstructionStatement.js index 675e0796e..2d41d2058 100644 --- a/src/slang-nodes/TupleDeconstructionStatement.js +++ b/src/slang-nodes/TupleDeconstructionStatement.js @@ -10,5 +10,5 @@ export const TupleDeconstructionStatement = { semicolon: ast.semicolon.text }), // TODO: implement print - print: () => ['TupleDeconstructionStatement'] + print: () => ['TODO: TupleDeconstructionStatement'] }; diff --git a/src/slang-nodes/TupleExpression.js b/src/slang-nodes/TupleExpression.js index 8f8a68618..eb9fe1181 100644 --- a/src/slang-nodes/TupleExpression.js +++ b/src/slang-nodes/TupleExpression.js @@ -6,5 +6,5 @@ export const TupleExpression = { closeParen: ast.closeParen.text }), // TODO: implement print - print: () => ['TupleExpression'] + print: () => ['TODO: TupleExpression'] }; diff --git a/src/slang-nodes/TupleValue.js b/src/slang-nodes/TupleValue.js index 5a7d88aa9..7456d6318 100644 --- a/src/slang-nodes/TupleValue.js +++ b/src/slang-nodes/TupleValue.js @@ -6,5 +6,5 @@ export const TupleValue = { : undefined }), // TODO: implement print - print: () => ['TupleValue'] + print: () => ['TODO: TupleValue'] }; diff --git a/src/slang-nodes/TupleValues.js b/src/slang-nodes/TupleValues.js index e417af5ef..3414eadf2 100644 --- a/src/slang-nodes/TupleValues.js +++ b/src/slang-nodes/TupleValues.js @@ -5,5 +5,5 @@ export const TupleValues = { separators: ast.separators.map((separator) => separator.text) }), // TODO: implement print - print: () => ['TupleValues'] + print: () => ['TODO: TupleValues'] }; diff --git a/src/slang-nodes/TypeExpression.js b/src/slang-nodes/TypeExpression.js index ba99e4252..61788c3cf 100644 --- a/src/slang-nodes/TypeExpression.js +++ b/src/slang-nodes/TypeExpression.js @@ -7,5 +7,5 @@ export const TypeExpression = { closeParen: ast.closeParen.text }), // TODO: implement print - print: () => ['TypeExpression'] + print: () => ['TODO: TypeExpression'] }; diff --git a/src/slang-nodes/TypedTupleMember.js b/src/slang-nodes/TypedTupleMember.js index c29423a80..5b6d323a9 100644 --- a/src/slang-nodes/TypedTupleMember.js +++ b/src/slang-nodes/TypedTupleMember.js @@ -8,5 +8,5 @@ export const TypedTupleMember = { name: ast.name.text }), // TODO: implement print - print: () => ['TypedTupleMember'] + print: () => ['TODO: TypedTupleMember'] }; diff --git a/src/slang-nodes/UncheckedBlock.js b/src/slang-nodes/UncheckedBlock.js index e5d5e66b5..997da0aaa 100644 --- a/src/slang-nodes/UncheckedBlock.js +++ b/src/slang-nodes/UncheckedBlock.js @@ -5,5 +5,5 @@ export const UncheckedBlock = { block: parse(ast.block, options, parse) }), // TODO: implement print - print: () => ['UncheckedBlock'] + print: () => ['TODO: UncheckedBlock'] }; diff --git a/src/slang-nodes/UnicodeStringLiterals.js b/src/slang-nodes/UnicodeStringLiterals.js index a3f4b0924..8dde9dd0a 100644 --- a/src/slang-nodes/UnicodeStringLiterals.js +++ b/src/slang-nodes/UnicodeStringLiterals.js @@ -4,5 +4,5 @@ export const UnicodeStringLiterals = { items: ast.items.map((item) => parse(item, options, parse)) }), // TODO: implement print - print: () => ['UnicodeStringLiterals'] + print: () => ['TODO: UnicodeStringLiterals'] }; diff --git a/src/slang-nodes/UnnamedFunctionAttributes.js b/src/slang-nodes/UnnamedFunctionAttributes.js index 2e62c5104..820757cc5 100644 --- a/src/slang-nodes/UnnamedFunctionAttributes.js +++ b/src/slang-nodes/UnnamedFunctionAttributes.js @@ -4,5 +4,5 @@ export const UnnamedFunctionAttributes = { items: ast.items.map((item) => parse(item, options, parse)) }), // TODO: implement print - print: () => ['UnnamedFunctionAttributes'] + print: () => ['TODO: UnnamedFunctionAttributes'] }; diff --git a/src/slang-nodes/UnnamedFunctionDefinition.js b/src/slang-nodes/UnnamedFunctionDefinition.js index cefe7e0af..0d75e66f2 100644 --- a/src/slang-nodes/UnnamedFunctionDefinition.js +++ b/src/slang-nodes/UnnamedFunctionDefinition.js @@ -7,5 +7,5 @@ export const UnnamedFunctionDefinition = { body: parse(ast.body, options, parse) }), // TODO: implement print - print: () => ['UnnamedFunctionDefinition'] + print: () => ['TODO: UnnamedFunctionDefinition'] }; diff --git a/src/slang-nodes/UntypedTupleMember.js b/src/slang-nodes/UntypedTupleMember.js index 9b1bb5335..fec374c64 100644 --- a/src/slang-nodes/UntypedTupleMember.js +++ b/src/slang-nodes/UntypedTupleMember.js @@ -7,5 +7,5 @@ export const UntypedTupleMember = { name: ast.name.text }), // TODO: implement print - print: () => ['UntypedTupleMemberUntypedTupleMember'] + print: () => ['TODO: UntypedTupleMemberUntypedTupleMember'] }; diff --git a/src/slang-nodes/UserDefinedValueTypeDefinition.js b/src/slang-nodes/UserDefinedValueTypeDefinition.js index c184c8bb5..81c1bc827 100644 --- a/src/slang-nodes/UserDefinedValueTypeDefinition.js +++ b/src/slang-nodes/UserDefinedValueTypeDefinition.js @@ -8,5 +8,5 @@ export const UserDefinedValueTypeDefinition = { semicolon: ast.semicolon.text }), // TODO: implement print - print: () => ['UserDefinedValueTypeDefinition'] + print: () => ['TODO: UserDefinedValueTypeDefinition'] }; diff --git a/src/slang-nodes/UsingAlias.js b/src/slang-nodes/UsingAlias.js index 4ffed8329..48f90a636 100644 --- a/src/slang-nodes/UsingAlias.js +++ b/src/slang-nodes/UsingAlias.js @@ -5,5 +5,5 @@ export const UsingAlias = { operator: parse(ast.operator, options, parse) }), // TODO: implement print - print: () => ['UsingAlias'] + print: () => ['TODO: UsingAlias'] }; diff --git a/src/slang-nodes/UsingDeconstruction.js b/src/slang-nodes/UsingDeconstruction.js index 5622d4def..74d7e2d15 100644 --- a/src/slang-nodes/UsingDeconstruction.js +++ b/src/slang-nodes/UsingDeconstruction.js @@ -6,5 +6,5 @@ export const UsingDeconstruction = { closeBrace: ast.closeBrace.text }), // TODO: implement print - print: () => ['UsingDeconstruction'] + print: () => ['TODO: UsingDeconstruction'] }; diff --git a/src/slang-nodes/UsingDeconstructionSymbol.js b/src/slang-nodes/UsingDeconstructionSymbol.js index e897ef60d..3bfebd1f6 100644 --- a/src/slang-nodes/UsingDeconstructionSymbol.js +++ b/src/slang-nodes/UsingDeconstructionSymbol.js @@ -5,5 +5,5 @@ export const UsingDeconstructionSymbol = { alias: ast.alias ? parse(ast.alias, options, parse) : undefined }), // TODO: implement print - print: () => ['UsingDeconstructionSymbol'] + print: () => ['TODO: UsingDeconstructionSymbol'] }; diff --git a/src/slang-nodes/UsingDeconstructionSymbols.js b/src/slang-nodes/UsingDeconstructionSymbols.js index bf568d552..01b9c7ce1 100644 --- a/src/slang-nodes/UsingDeconstructionSymbols.js +++ b/src/slang-nodes/UsingDeconstructionSymbols.js @@ -5,5 +5,5 @@ export const UsingDeconstructionSymbols = { separators: ast.separators.map((separator) => separator.text) }), // TODO: implement print - print: () => ['UsingDeconstructionSymbols'] + print: () => ['TODO: UsingDeconstructionSymbols'] }; diff --git a/src/slang-nodes/UsingDirective.js b/src/slang-nodes/UsingDirective.js index c4dc4aa9e..58a445479 100644 --- a/src/slang-nodes/UsingDirective.js +++ b/src/slang-nodes/UsingDirective.js @@ -9,5 +9,5 @@ export const UsingDirective = { semicolon: ast.semicolon.text }), // TODO: implement print - print: () => ['UsingDirective'] + print: () => ['TODO: UsingDirective'] }; diff --git a/src/slang-nodes/VariableDeclarationStatement.js b/src/slang-nodes/VariableDeclarationStatement.js index 6f86d6ccd..af375e1b2 100644 --- a/src/slang-nodes/VariableDeclarationStatement.js +++ b/src/slang-nodes/VariableDeclarationStatement.js @@ -10,5 +10,5 @@ export const VariableDeclarationStatement = { semicolon: ast.semicolon.text }), // TODO: implement print - print: () => ['TypedTupleMember'] + print: () => ['TODO: TypedTupleMember'] }; diff --git a/src/slang-nodes/VariableDeclarationValue.js b/src/slang-nodes/VariableDeclarationValue.js index 4a00a924b..d34a5b3c7 100644 --- a/src/slang-nodes/VariableDeclarationValue.js +++ b/src/slang-nodes/VariableDeclarationValue.js @@ -5,5 +5,5 @@ export const VariableDeclarationValue = { expression: parse(ast.expression, options, parse) }), // TODO: implement print - print: () => ['VariableDeclarationValue'] + print: () => ['TODO: VariableDeclarationValue'] }; diff --git a/src/slang-nodes/VersionRange.js b/src/slang-nodes/VersionRange.js index 63e812052..596b92e4d 100644 --- a/src/slang-nodes/VersionRange.js +++ b/src/slang-nodes/VersionRange.js @@ -6,5 +6,5 @@ export const VersionRange = { rightOperand: parse(ast.rightOperand, options, parse) }), // TODO: implement print - print: () => ['VersionRange'] + print: () => ['TODO: VersionRange'] }; diff --git a/src/slang-nodes/WhileStatement.js b/src/slang-nodes/WhileStatement.js index 35ac5c528..c154155a7 100644 --- a/src/slang-nodes/WhileStatement.js +++ b/src/slang-nodes/WhileStatement.js @@ -8,5 +8,5 @@ export const WhileStatement = { body: parse(ast.body, options, parse) }), // TODO: implement print - print: () => ['WhileStatement'] + print: () => ['TODO: WhileStatement'] }; diff --git a/src/slang-nodes/YulArguments.js b/src/slang-nodes/YulArguments.js index dcfeb48be..2a7dc11d4 100644 --- a/src/slang-nodes/YulArguments.js +++ b/src/slang-nodes/YulArguments.js @@ -5,5 +5,5 @@ export const YulArguments = { separators: ast.separators.map((separator) => separator.text) }), // TODO: implement print - print: () => ['YulArguments'] + print: () => ['TODO: YulArguments'] }; diff --git a/src/slang-nodes/YulAssignmentStatement.js b/src/slang-nodes/YulAssignmentStatement.js index e011c3f34..78ca945e9 100644 --- a/src/slang-nodes/YulAssignmentStatement.js +++ b/src/slang-nodes/YulAssignmentStatement.js @@ -6,5 +6,5 @@ export const YulAssignmentStatement = { expression: parse(ast.expression, options, parse) }), // TODO: implement print - print: () => ['YulAssignmentStatement'] + print: () => ['TODO: YulAssignmentStatement'] }; diff --git a/src/slang-nodes/YulBlock.js b/src/slang-nodes/YulBlock.js index 704f57595..f88107ab8 100644 --- a/src/slang-nodes/YulBlock.js +++ b/src/slang-nodes/YulBlock.js @@ -6,5 +6,5 @@ export const YulBlock = { closeBrace: ast.closeBrace.text }), // TODO: implement print - print: () => ['YulBlock'] + print: () => ['TODO: YulBlock'] }; diff --git a/src/slang-nodes/YulBreakStatement.js b/src/slang-nodes/YulBreakStatement.js index 40fb90e7c..07b5e4125 100644 --- a/src/slang-nodes/YulBreakStatement.js +++ b/src/slang-nodes/YulBreakStatement.js @@ -4,5 +4,5 @@ export const YulBreakStatement = { breakKeyword: ast.breakKeyword.text }), // TODO: implement print - print: () => ['YulBreakStatement'] + print: () => ['TODO: YulBreakStatement'] }; diff --git a/src/slang-nodes/YulColonAndEqual.js b/src/slang-nodes/YulColonAndEqual.js index 699529054..d71929aa6 100644 --- a/src/slang-nodes/YulColonAndEqual.js +++ b/src/slang-nodes/YulColonAndEqual.js @@ -5,5 +5,5 @@ export const YulColonAndEqual = { equal: ast.equal.text }), // TODO: implement print - print: () => ['YulColonAndEqual'] + print: () => ['TODO: YulColonAndEqual'] }; diff --git a/src/slang-nodes/YulContinueStatement.js b/src/slang-nodes/YulContinueStatement.js index 48e001947..09c8629f1 100644 --- a/src/slang-nodes/YulContinueStatement.js +++ b/src/slang-nodes/YulContinueStatement.js @@ -4,5 +4,5 @@ export const YulContinueStatement = { continueKeyword: ast.continueKeyword.text }), // TODO: implement print - print: () => ['YulContinueStatement'] + print: () => ['TODO: YulContinueStatement'] }; diff --git a/src/slang-nodes/YulDefaultCase.js b/src/slang-nodes/YulDefaultCase.js index 8081a58b0..a45da0193 100644 --- a/src/slang-nodes/YulDefaultCase.js +++ b/src/slang-nodes/YulDefaultCase.js @@ -5,5 +5,5 @@ export const YulDefaultCase = { body: parse(ast.body, options, parse) }), // TODO: implement print - print: () => ['YulDefaultCase'] + print: () => ['TODO: YulDefaultCase'] }; diff --git a/src/slang-nodes/YulForStatement.js b/src/slang-nodes/YulForStatement.js index 0e3ad1d2e..a02f65b41 100644 --- a/src/slang-nodes/YulForStatement.js +++ b/src/slang-nodes/YulForStatement.js @@ -8,5 +8,5 @@ export const YulForStatement = { body: parse(ast.body, options, parse) }), // TODO: implement print - print: () => ['YulForStatement'] + print: () => ['TODO: YulForStatement'] }; diff --git a/src/slang-nodes/YulFunctionCallExpression.js b/src/slang-nodes/YulFunctionCallExpression.js index 707a65b4b..f60c68aaf 100644 --- a/src/slang-nodes/YulFunctionCallExpression.js +++ b/src/slang-nodes/YulFunctionCallExpression.js @@ -7,5 +7,5 @@ export const YulFunctionCallExpression = { closeParen: ast.closeParen.text }), // TODO: implement print - print: () => ['YulFunctionCallExpression'] + print: () => ['TODO: YulFunctionCallExpression'] }; diff --git a/src/slang-nodes/YulFunctionDefinition.js b/src/slang-nodes/YulFunctionDefinition.js index 2b57a294a..4758ab69a 100644 --- a/src/slang-nodes/YulFunctionDefinition.js +++ b/src/slang-nodes/YulFunctionDefinition.js @@ -8,5 +8,5 @@ export const YulFunctionDefinition = { body: parse(ast.body, options, parse) }), // TODO: implement print - print: () => ['YulFunctionDefinition'] + print: () => ['TODO: YulFunctionDefinition'] }; diff --git a/src/slang-nodes/YulIfStatement.js b/src/slang-nodes/YulIfStatement.js index 0c3fc1a3a..2337dd4c1 100644 --- a/src/slang-nodes/YulIfStatement.js +++ b/src/slang-nodes/YulIfStatement.js @@ -6,5 +6,5 @@ export const YulIfStatement = { body: parse(ast.body, options, parse) }), // TODO: implement print - print: () => ['YulIfStatement'] + print: () => ['TODO: YulIfStatement'] }; diff --git a/src/slang-nodes/YulLabel.js b/src/slang-nodes/YulLabel.js index 92ccdb7d8..122d022e6 100644 --- a/src/slang-nodes/YulLabel.js +++ b/src/slang-nodes/YulLabel.js @@ -5,5 +5,5 @@ export const YulLabel = { colon: ast.colon.text }), // TODO: implement print - print: () => ['YulLabel'] + print: () => ['TODO: YulLabel'] }; diff --git a/src/slang-nodes/YulLeaveStatement.js b/src/slang-nodes/YulLeaveStatement.js index 5932887af..bf6939c28 100644 --- a/src/slang-nodes/YulLeaveStatement.js +++ b/src/slang-nodes/YulLeaveStatement.js @@ -4,5 +4,5 @@ export const YulLeaveStatement = { leaveKeyword: ast.leaveKeyword.text }), // TODO: implement print - print: () => ['YulLeaveStatement'] + print: () => ['TODO: YulLeaveStatement'] }; diff --git a/src/slang-nodes/YulParameters.js b/src/slang-nodes/YulParameters.js index 07e07940a..df04ae157 100644 --- a/src/slang-nodes/YulParameters.js +++ b/src/slang-nodes/YulParameters.js @@ -5,5 +5,5 @@ export const YulParameters = { separators: ast.separators.map((separator) => separator.text) }), // TODO: implement print - print: () => ['YulParameters'] + print: () => ['TODO: YulParameters'] }; diff --git a/src/slang-nodes/YulParametersDeclaration.js b/src/slang-nodes/YulParametersDeclaration.js index 82b8eff51..8843a1b1e 100644 --- a/src/slang-nodes/YulParametersDeclaration.js +++ b/src/slang-nodes/YulParametersDeclaration.js @@ -6,5 +6,5 @@ export const YulParametersDeclaration = { closeParen: ast.closeParen.text }), // TODO: implement print - print: () => ['YulParametersDeclaration'] + print: () => ['TODO: YulParametersDeclaration'] }; diff --git a/src/slang-nodes/YulPath.js b/src/slang-nodes/YulPath.js index a2d5804c3..864017787 100644 --- a/src/slang-nodes/YulPath.js +++ b/src/slang-nodes/YulPath.js @@ -5,5 +5,5 @@ export const YulPath = { separators: ast.separators.map((separator) => separator.text) }), // TODO: implement print - print: () => ['YulPath'] + print: () => ['TODO: YulPath'] }; diff --git a/src/slang-nodes/YulPaths.js b/src/slang-nodes/YulPaths.js index b3497a792..b4da07c57 100644 --- a/src/slang-nodes/YulPaths.js +++ b/src/slang-nodes/YulPaths.js @@ -5,5 +5,5 @@ export const YulPaths = { separators: ast.separators.map((separator) => separator.text) }), // TODO: implement print - print: () => ['YulPaths'] + print: () => ['TODO: YulPaths'] }; diff --git a/src/slang-nodes/YulReturnVariables.js b/src/slang-nodes/YulReturnVariables.js index 3632c2bb7..7bd26b260 100644 --- a/src/slang-nodes/YulReturnVariables.js +++ b/src/slang-nodes/YulReturnVariables.js @@ -5,5 +5,5 @@ export const YulReturnVariables = { separators: ast.separators.map((separator) => separator.text) }), // TODO: implement print - print: () => ['YulReturnVariables'] + print: () => ['TODO: YulReturnVariables'] }; diff --git a/src/slang-nodes/YulReturnsDeclaration.js b/src/slang-nodes/YulReturnsDeclaration.js index 168413ea0..aef370b42 100644 --- a/src/slang-nodes/YulReturnsDeclaration.js +++ b/src/slang-nodes/YulReturnsDeclaration.js @@ -5,5 +5,5 @@ export const YulReturnsDeclaration = { variables: parse(ast.variables, options, parse) }), // TODO: implement print - print: () => ['YulReturnsDeclaration'] + print: () => ['TODO: YulReturnsDeclaration'] }; diff --git a/src/slang-nodes/YulStatements.js b/src/slang-nodes/YulStatements.js index b0931b2bc..8355c2a76 100644 --- a/src/slang-nodes/YulStatements.js +++ b/src/slang-nodes/YulStatements.js @@ -4,5 +4,5 @@ export const YulStatements = { items: ast.items.map((item) => parse(item, options, parse)) }), // TODO: implement print - print: () => ['YulStatements'] + print: () => ['TODO: YulStatements'] }; diff --git a/src/slang-nodes/YulSwitchCases.js b/src/slang-nodes/YulSwitchCases.js index 76fb5e379..bf14ca705 100644 --- a/src/slang-nodes/YulSwitchCases.js +++ b/src/slang-nodes/YulSwitchCases.js @@ -4,5 +4,5 @@ export const YulSwitchCases = { items: ast.items.map((item) => parse(item, options, parse)) }), // TODO: implement print - print: () => ['YulSwitchCases'] + print: () => ['TODO: YulSwitchCases'] }; diff --git a/src/slang-nodes/YulSwitchStatement.js b/src/slang-nodes/YulSwitchStatement.js index 5351d6cbe..14fbd6593 100644 --- a/src/slang-nodes/YulSwitchStatement.js +++ b/src/slang-nodes/YulSwitchStatement.js @@ -6,5 +6,5 @@ export const YulSwitchStatement = { cases: parse(ast.cases, options, parse) }), // TODO: implement print - print: () => ['YulSwitchStatement'] + print: () => ['TODO: YulSwitchStatement'] }; diff --git a/src/slang-nodes/YulValueCase.js b/src/slang-nodes/YulValueCase.js index a0f44a1ed..a44511a59 100644 --- a/src/slang-nodes/YulValueCase.js +++ b/src/slang-nodes/YulValueCase.js @@ -6,5 +6,5 @@ export const YulValueCase = { body: parse(ast.body, options, parse) }), // TODO: implement print - print: () => ['YulValueCase'] + print: () => ['TODO: YulValueCase'] }; diff --git a/src/slang-nodes/YulVariableDeclarationStatement.js b/src/slang-nodes/YulVariableDeclarationStatement.js index abca62d63..477f829bc 100644 --- a/src/slang-nodes/YulVariableDeclarationStatement.js +++ b/src/slang-nodes/YulVariableDeclarationStatement.js @@ -6,5 +6,5 @@ export const YulVariableDeclarationStatement = { value: ast.value ? parse(ast.value, options, parse) : undefined }), // TODO: implement print - print: () => ['YulVariableDeclarationStatement'] + print: () => ['TODO: YulVariableDeclarationStatement'] }; diff --git a/src/slang-nodes/YulVariableDeclarationValue.js b/src/slang-nodes/YulVariableDeclarationValue.js index f9da75efe..4c709a1fd 100644 --- a/src/slang-nodes/YulVariableDeclarationValue.js +++ b/src/slang-nodes/YulVariableDeclarationValue.js @@ -5,5 +5,5 @@ export const YulVariableDeclarationValue = { expression: parse(ast.expression, options, parse) }), // TODO: implement print - print: () => ['YulVariableDeclarationValue'] + print: () => ['TODO: YulVariableDeclarationValue'] }; diff --git a/src/slangPrinter.js b/src/slangPrinter.js index cb9a727e6..62fe90d26 100644 --- a/src/slangPrinter.js +++ b/src/slangPrinter.js @@ -1,4 +1,4 @@ -import * as nodes from './slang/index.js'; +import * as nodes from './slang-nodes/index.js'; import { hasNodeIgnoreComment, prettierVersionSatisfies From f05707a353101d4a4678dc3ece7ce109dbf9aef5 Mon Sep 17 00:00:00 2001 From: Klaus Date: Mon, 20 May 2024 22:56:23 +1200 Subject: [PATCH 004/160] WIP: more printers implemented --- src/slang-nodes/AddressType.js | 6 +++-- src/slang-nodes/ArgumentsDeclaration.js | 1 - src/slang-nodes/ArrayTypeName.js | 8 +++++-- src/slang-nodes/Block.js | 12 ++++++++-- src/slang-nodes/ExpressionStatement.js | 6 +++-- src/slang-nodes/FunctionAttributes.js | 8 +++++-- src/slang-nodes/FunctionCallExpression.js | 6 +++-- src/slang-nodes/FunctionDefinition.js | 22 +++++++++++++++++-- src/slang-nodes/IdentifierPath.js | 6 +++-- src/slang-nodes/MemberAccessExpression.js | 7 ++++-- src/slang-nodes/Parameter.js | 7 ++++-- src/slang-nodes/Parameters.js | 6 +++-- src/slang-nodes/ParametersDeclaration.js | 7 ++++-- src/slang-nodes/PositionalArguments.js | 3 +-- .../PositionalArgumentsDeclaration.js | 11 ++++++---- src/slang-nodes/StateVariableAttributes.js | 4 ++-- src/slang-nodes/StateVariableDefinition.js | 10 +++++++-- src/slang-nodes/Statements.js | 6 +++-- src/slang-nodes/TypedTupleMember.js | 7 ++++-- src/slang-nodes/UsingDirective.js | 13 +++++++++-- .../VariableDeclarationStatement.js | 9 ++++++-- src/slang-nodes/VariableDeclarationValue.js | 6 +++-- .../__snapshots__/jsfmt.spec.js.snap | 12 +++++++++- 23 files changed, 137 insertions(+), 46 deletions(-) diff --git a/src/slang-nodes/AddressType.js b/src/slang-nodes/AddressType.js index f2027918c..651fd7c90 100644 --- a/src/slang-nodes/AddressType.js +++ b/src/slang-nodes/AddressType.js @@ -4,6 +4,8 @@ export const AddressType = { addressKeyword: ast.addressKeyword.text, payableKeyword: ast.payableKeyword?.text }), - // TODO: implement print - print: () => ['TODO: AddressType'] + print: ({ node }) => [ + node.addressKeyword, + node.payableKeyword ? ` ${node.payableKeyword}` : '' + ] }; diff --git a/src/slang-nodes/ArgumentsDeclaration.js b/src/slang-nodes/ArgumentsDeclaration.js index 86cd19db2..d7730854f 100644 --- a/src/slang-nodes/ArgumentsDeclaration.js +++ b/src/slang-nodes/ArgumentsDeclaration.js @@ -3,6 +3,5 @@ export const ArgumentsDeclaration = { kind: ast.cst.kind, variant: parse(ast.variant, options, parse) }), - // TODO: implement print print: ({ path, print }) => path.call(print, 'variant') }; diff --git a/src/slang-nodes/ArrayTypeName.js b/src/slang-nodes/ArrayTypeName.js index b8ae0ba0f..81b03540f 100644 --- a/src/slang-nodes/ArrayTypeName.js +++ b/src/slang-nodes/ArrayTypeName.js @@ -6,6 +6,10 @@ export const ArrayTypeName = { index: ast.index ? parse(ast.index, options, parse) : undefined, closeBracket: ast.closeBracket.text }), - // TODO: implement print - print: () => ['TODO: ArrayTypeName'] + print: ({ node, path, print }) => [ + path.call(print, 'operand'), + node.openBracket, + node.index ? path.call(print, 'index') : '', + node.closeBracket + ] }; diff --git a/src/slang-nodes/Block.js b/src/slang-nodes/Block.js index 9d032cbdf..910ce6cab 100644 --- a/src/slang-nodes/Block.js +++ b/src/slang-nodes/Block.js @@ -1,3 +1,7 @@ +import { doc } from 'prettier'; + +const { hardline, indent } = doc.builders; + export const Block = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, @@ -5,6 +9,10 @@ export const Block = { statements: parse(ast.statements, options, parse), closeBrace: ast.closeBrace.text }), - // TODO: implement print - print: () => ['TODO: Block'] + print: ({ node, path, print }) => [ + node.openBrace, + indent([hardline, path.call(print, 'statements')]), + hardline, + node.closeBrace + ] }; diff --git a/src/slang-nodes/ExpressionStatement.js b/src/slang-nodes/ExpressionStatement.js index 29fbaefb6..2f60ec749 100644 --- a/src/slang-nodes/ExpressionStatement.js +++ b/src/slang-nodes/ExpressionStatement.js @@ -4,6 +4,8 @@ export const ExpressionStatement = { expression: parse(ast.expression, options, parse), semicolon: ast.semicolon.text }), - // TODO: implement print - print: () => ['TODO: ExpressionStatement'] + print: ({ node, path, print }) => [ + path.call(print, 'expression'), + node.semicolon + ] }; diff --git a/src/slang-nodes/FunctionAttributes.js b/src/slang-nodes/FunctionAttributes.js index 9306d51da..5a2d289db 100644 --- a/src/slang-nodes/FunctionAttributes.js +++ b/src/slang-nodes/FunctionAttributes.js @@ -1,8 +1,12 @@ +import { doc } from 'prettier'; + +const { line } = doc.builders; + export const FunctionAttributes = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), - // TODO: implement print - print: () => ['TODO: FunctionAttributes'] + print: ({ path, print }) => + path.map(print, 'items').map((item) => [line, item]) }; diff --git a/src/slang-nodes/FunctionCallExpression.js b/src/slang-nodes/FunctionCallExpression.js index fac896ad6..3e4b372b9 100644 --- a/src/slang-nodes/FunctionCallExpression.js +++ b/src/slang-nodes/FunctionCallExpression.js @@ -4,6 +4,8 @@ export const FunctionCallExpression = { operand: parse(ast.operand, options, parse), arguments: parse(ast.arguments, options, parse) }), - // TODO: implement print - print: () => ['TODO: FunctionCallExpression'] + print: ({ path, print }) => [ + path.call(print, 'operand'), + path.call(print, 'arguments') + ] }; diff --git a/src/slang-nodes/FunctionDefinition.js b/src/slang-nodes/FunctionDefinition.js index 903085d86..e793caa47 100644 --- a/src/slang-nodes/FunctionDefinition.js +++ b/src/slang-nodes/FunctionDefinition.js @@ -1,3 +1,7 @@ +import { doc } from 'prettier'; + +const { dedent, group, indent, line } = doc.builders; + export const FunctionDefinition = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, @@ -8,6 +12,20 @@ export const FunctionDefinition = { returns: ast.returns ? parse(ast.returns, options, parse) : undefined, body: parse(ast.body, options, parse) }), - // TODO: implement print - print: () => ['TODO: FunctionDefinition'] + print: ({ node, path, print }) => [ + group([ + node.functionKeyword, + ' ', + path.call(print, 'name'), + path.call(print, 'parameters'), + indent( + group([ + path.call(print, 'attributes'), + node.returns ? path.call(print, 'returns') : '', + dedent(line) + ]) + ) + ]), + path.call(print, 'body') + ] }; diff --git a/src/slang-nodes/IdentifierPath.js b/src/slang-nodes/IdentifierPath.js index 5bc447940..6dd35933f 100644 --- a/src/slang-nodes/IdentifierPath.js +++ b/src/slang-nodes/IdentifierPath.js @@ -4,6 +4,8 @@ export const IdentifierPath = { items: ast.items.map((item) => item.text), separators: ast.separators.map((separator) => separator.text) }), - // TODO: implement print - print: () => ['TODO: IdentifierPath'] + print: ({ node }) => + node.items.map((item, index) => + index === 0 ? item : [node.separator[index - 1], item] + ) }; diff --git a/src/slang-nodes/MemberAccessExpression.js b/src/slang-nodes/MemberAccessExpression.js index 2d1d5e457..b0b6c2b76 100644 --- a/src/slang-nodes/MemberAccessExpression.js +++ b/src/slang-nodes/MemberAccessExpression.js @@ -5,6 +5,9 @@ export const MemberAccessExpression = { period: ast.period.text, member: parse(ast.member, options, parse) }), - // TODO: implement print - print: () => ['TODO: MemberAccessExpression'] + print: ({ node, path, print }) => [ + path.call(print, 'operand'), + node.period, + path.call(print, 'member') + ] }; diff --git a/src/slang-nodes/Parameter.js b/src/slang-nodes/Parameter.js index 687c27fb8..1369f5f40 100644 --- a/src/slang-nodes/Parameter.js +++ b/src/slang-nodes/Parameter.js @@ -7,6 +7,9 @@ export const Parameter = { : undefined, name: ast.name?.text }), - // TODO: implement print - print: () => ['TODO: Parameter'] + print: ({ node, path, print }) => [ + path.call(print, 'typeName'), + node.storageLocation ? ` ${path.call(print, 'storageLocation')} ` : ' ', + node.name + ] }; diff --git a/src/slang-nodes/Parameters.js b/src/slang-nodes/Parameters.js index a72422fd3..8a5834766 100644 --- a/src/slang-nodes/Parameters.js +++ b/src/slang-nodes/Parameters.js @@ -1,9 +1,11 @@ +import { printSeparatedList } from '../common/printer-helpers.js'; + export const Parameters = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), - // TODO: implement print - print: () => ['TODO: Parameters'] + print: ({ path, print }) => + printSeparatedList(path.map(print, 'items'), { grouped: false }) }; diff --git a/src/slang-nodes/ParametersDeclaration.js b/src/slang-nodes/ParametersDeclaration.js index a1c44654a..deb1642f7 100644 --- a/src/slang-nodes/ParametersDeclaration.js +++ b/src/slang-nodes/ParametersDeclaration.js @@ -5,6 +5,9 @@ export const ParametersDeclaration = { parameters: parse(ast.parameters, options, parse), closeParen: ast.closeParen.text }), - // TODO: implement print - print: () => ['TODO: ParametersDeclaration'] + print: ({ node, path, print }) => [ + node.openParen, + path.call(print, 'parameters'), + node.closeParen + ] }; diff --git a/src/slang-nodes/PositionalArguments.js b/src/slang-nodes/PositionalArguments.js index 6a1963851..ef698aebe 100644 --- a/src/slang-nodes/PositionalArguments.js +++ b/src/slang-nodes/PositionalArguments.js @@ -4,6 +4,5 @@ export const PositionalArguments = { items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), - // TODO: implement print - print: () => ['TODO: PositionalArguments'] + print: ({ path, print }) => path.map(print, 'items') }; diff --git a/src/slang-nodes/PositionalArgumentsDeclaration.js b/src/slang-nodes/PositionalArgumentsDeclaration.js index 2863deb39..d59df6c01 100644 --- a/src/slang-nodes/PositionalArgumentsDeclaration.js +++ b/src/slang-nodes/PositionalArgumentsDeclaration.js @@ -1,10 +1,13 @@ export const PositionalArgumentsDeclaration = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, - openParen: ast.openParen.TokenNode, + openParen: ast.openParen.text, arguments: parse(ast.arguments, options, parse), - closeParen: ast.closeParen.TokenNode + closeParen: ast.closeParen.text }), - // TODO: implement print - print: () => ['TODO: PositionalArgumentsDeclaration'] + print: ({ node, path, print }) => [ + node.openParen, + path.call(print, 'arguments'), + node.closeParen + ] }; diff --git a/src/slang-nodes/StateVariableAttributes.js b/src/slang-nodes/StateVariableAttributes.js index 52d9214ef..923f3aeaa 100644 --- a/src/slang-nodes/StateVariableAttributes.js +++ b/src/slang-nodes/StateVariableAttributes.js @@ -3,6 +3,6 @@ export const StateVariableAttributes = { kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), - // TODO: implement print - print: () => ['TODO: StateVariableAttributes'] + print: ({ node, path, print }) => + node.items.length ? path.call(print, 'items') : '' }; diff --git a/src/slang-nodes/StateVariableDefinition.js b/src/slang-nodes/StateVariableDefinition.js index d00166106..3d54f4b5a 100644 --- a/src/slang-nodes/StateVariableDefinition.js +++ b/src/slang-nodes/StateVariableDefinition.js @@ -7,6 +7,12 @@ export const StateVariableDefinition = { value: ast.value ? parse(ast.value, options, parse) : undefined, semicolon: ast.semicolon.text }), - // TODO: implement print - print: () => ['TODO: StateVariableDefinition'] + print: ({ node, path, print }) => [ + path.call(print, 'typeName'), + path.call(print, 'attributes'), + ' ', + node.name, + node.value ? path.call(print, 'value') : '', + node.semicolon + ] }; diff --git a/src/slang-nodes/Statements.js b/src/slang-nodes/Statements.js index 8abb2c105..543cbef52 100644 --- a/src/slang-nodes/Statements.js +++ b/src/slang-nodes/Statements.js @@ -1,8 +1,10 @@ +import { printPreservingEmptyLines } from '../common/printer-helpers.js'; + export const Statements = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), - // TODO: implement print - print: () => ['TODO: Statements'] + print: ({ path, options, print }) => + printPreservingEmptyLines(path, 'items', options, print) }; diff --git a/src/slang-nodes/TypedTupleMember.js b/src/slang-nodes/TypedTupleMember.js index 5b6d323a9..c468cd0a4 100644 --- a/src/slang-nodes/TypedTupleMember.js +++ b/src/slang-nodes/TypedTupleMember.js @@ -7,6 +7,9 @@ export const TypedTupleMember = { : undefined, name: ast.name.text }), - // TODO: implement print - print: () => ['TODO: TypedTupleMember'] + print: ({ node, path, print }) => [ + path.call(print, 'typeName'), + node.storageLocation ? path.call(print, 'storageLocation') : '', + node.name + ] }; diff --git a/src/slang-nodes/UsingDirective.js b/src/slang-nodes/UsingDirective.js index 58a445479..f09b022bb 100644 --- a/src/slang-nodes/UsingDirective.js +++ b/src/slang-nodes/UsingDirective.js @@ -8,6 +8,15 @@ export const UsingDirective = { globalKeyword: ast.globalKeyword?.text, semicolon: ast.semicolon.text }), - // TODO: implement print - print: () => ['TODO: UsingDirective'] + print: ({ node, path, print }) => [ + node.usingKeyword, + ' ', + path.call(print, 'clause'), + ' ', + node.forKeyword, + ' ', + path.call(print, 'target'), + node.globalKeyword ? node.globalKeyword : '', + node.semicolon + ] }; diff --git a/src/slang-nodes/VariableDeclarationStatement.js b/src/slang-nodes/VariableDeclarationStatement.js index af375e1b2..8baccc377 100644 --- a/src/slang-nodes/VariableDeclarationStatement.js +++ b/src/slang-nodes/VariableDeclarationStatement.js @@ -9,6 +9,11 @@ export const VariableDeclarationStatement = { value: ast.value ? parse(ast.value, options, parse) : undefined, semicolon: ast.semicolon.text }), - // TODO: implement print - print: () => ['TODO: TypedTupleMember'] + print: ({ node, path, print }) => [ + path.call(print, 'variableType'), + node.storageLocation ? ` ${path.call(print, 'storageLocation')} ` : ' ', + node.name, + node.value ? path.call(print, 'value') : '', + node.semicolon + ] }; diff --git a/src/slang-nodes/VariableDeclarationValue.js b/src/slang-nodes/VariableDeclarationValue.js index d34a5b3c7..af0b1ebe7 100644 --- a/src/slang-nodes/VariableDeclarationValue.js +++ b/src/slang-nodes/VariableDeclarationValue.js @@ -4,6 +4,8 @@ export const VariableDeclarationValue = { equal: ast.equal.text, expression: parse(ast.expression, options, parse) }), - // TODO: implement print - print: () => ['TODO: VariableDeclarationValue'] + print: ({ node, path, print }) => [ + ` ${node.equal} `, + path.call(print, 'expression') + ] }; diff --git a/tests/format/AddressPayable/__snapshots__/jsfmt.spec.js.snap b/tests/format/AddressPayable/__snapshots__/jsfmt.spec.js.snap index 1152abc21..a79eb8a39 100644 --- a/tests/format/AddressPayable/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/AddressPayable/__snapshots__/jsfmt.spec.js.snap @@ -54,7 +54,17 @@ contract AddressPayable { =====================================output===================================== pragma solidity ^0.5.2; -ContractDefinition +contract AddressPayable { + using Address for address payable; + address payable[] hello; + function sendSomeEth( + address payable to, + address payable[] memory world + ) public payable { + address payable target = to; + target.transfer(msg.value); + } +} ================================================================================ `; From 9728d2b1a6c40e9389428f8aafd4593d77784a37 Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 22 May 2024 11:47:54 +1200 Subject: [PATCH 005/160] WIP: 82/210 printers --- src/slang-nodes/ArrayExpression.js | 8 ++- src/slang-nodes/ArrayValues.js | 5 +- src/slang-nodes/DecimalNumberExpression.js | 6 +- src/slang-nodes/IdentifierPath.js | 2 +- src/slang-nodes/IndexAccessEnd.js | 6 +- src/slang-nodes/IndexAccessExpression.js | 9 ++- src/slang-nodes/StateVariableAttributes.js | 2 +- src/slang-nodes/StateVariableDefinition.js | 1 + .../StateVariableDefinitionValue.js | 8 ++- src/slang-nodes/StringLiterals.js | 7 ++- src/slang-nodes/TupleExpression.js | 7 ++- src/slang-nodes/TupleValue.js | 4 +- src/slang-nodes/TupleValues.js | 8 ++- .../Arrays/__snapshots__/jsfmt.spec.js.snap | 56 +++++++++++++++++++ tests/format/Arrays/jsfmt.spec.js | 1 + 15 files changed, 108 insertions(+), 22 deletions(-) diff --git a/src/slang-nodes/ArrayExpression.js b/src/slang-nodes/ArrayExpression.js index f92a70315..f56cdfcd6 100644 --- a/src/slang-nodes/ArrayExpression.js +++ b/src/slang-nodes/ArrayExpression.js @@ -1,3 +1,7 @@ +import { doc } from 'prettier'; + +const { group } = doc.builders; + export const ArrayExpression = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, @@ -5,6 +9,6 @@ export const ArrayExpression = { items: parse(ast.items, options, parse), closeBracket: ast.closeBracket.text }), - // TODO: implement print - print: () => ['TODO: ArrayExpression'] + print: ({ node, path, print }) => + group([node.openBracket, path.call(print, 'items'), node.closeBracket]) }; diff --git a/src/slang-nodes/ArrayValues.js b/src/slang-nodes/ArrayValues.js index a4e3619af..daabcc2b9 100644 --- a/src/slang-nodes/ArrayValues.js +++ b/src/slang-nodes/ArrayValues.js @@ -1,9 +1,10 @@ +import { printSeparatedList } from '../common/printer-helpers.js'; + export const ArrayValues = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), - // TODO: implement print - print: () => ['TODO: ArrayValues'] + print: ({ path, print }) => printSeparatedList(path.map(print, 'items')) }; diff --git a/src/slang-nodes/DecimalNumberExpression.js b/src/slang-nodes/DecimalNumberExpression.js index 477fdf232..f97d43134 100644 --- a/src/slang-nodes/DecimalNumberExpression.js +++ b/src/slang-nodes/DecimalNumberExpression.js @@ -4,6 +4,8 @@ export const DecimalNumberExpression = { literal: ast.literal.text, unit: ast.unit ? parse(ast.unit, options, parse) : undefined }), - // TODO: implement print - print: () => ['TODO: DecimalNumberExpression'] + print: ({ node, path, print }) => [ + node.literal, + node.unit ? path.call(print, 'unit') : '' + ] }; diff --git a/src/slang-nodes/IdentifierPath.js b/src/slang-nodes/IdentifierPath.js index 6dd35933f..5be2c3cad 100644 --- a/src/slang-nodes/IdentifierPath.js +++ b/src/slang-nodes/IdentifierPath.js @@ -6,6 +6,6 @@ export const IdentifierPath = { }), print: ({ node }) => node.items.map((item, index) => - index === 0 ? item : [node.separator[index - 1], item] + index === 0 ? item : [node.separators[index - 1], item] ) }; diff --git a/src/slang-nodes/IndexAccessEnd.js b/src/slang-nodes/IndexAccessEnd.js index 3e0b910a5..56af7be30 100644 --- a/src/slang-nodes/IndexAccessEnd.js +++ b/src/slang-nodes/IndexAccessEnd.js @@ -4,6 +4,8 @@ export const IndexAccessEnd = { colon: ast.colon.text, end: ast.end ? parse(ast.end, options, parse) : undefined }), - // TODO: implement print - print: () => ['TODO: IndexAccessEnd'] + print: ({ node, path, print }) => [ + node.colon, + node.end ? path.call(print, 'end') : '' + ] }; diff --git a/src/slang-nodes/IndexAccessExpression.js b/src/slang-nodes/IndexAccessExpression.js index 7d690a95f..56cb7427c 100644 --- a/src/slang-nodes/IndexAccessExpression.js +++ b/src/slang-nodes/IndexAccessExpression.js @@ -7,6 +7,11 @@ export const IndexAccessExpression = { end: ast.end ? parse(ast.end, options, parse) : undefined, closeBracket: ast.closeBracket.text }), - // TODO: implement print - print: () => ['TODO: IndexAccessExpression'] + print: ({ node, path, print }) => [ + path.call(print, 'operand'), + node.openBracket, + node.start ? path.call(print, 'start') : '', + node.end ? path.call(print, 'end') : '', + node.closeBracket + ] }; diff --git a/src/slang-nodes/StateVariableAttributes.js b/src/slang-nodes/StateVariableAttributes.js index 923f3aeaa..6b6bc6c25 100644 --- a/src/slang-nodes/StateVariableAttributes.js +++ b/src/slang-nodes/StateVariableAttributes.js @@ -4,5 +4,5 @@ export const StateVariableAttributes = { items: ast.items.map((item) => parse(item, options, parse)) }), print: ({ node, path, print }) => - node.items.length ? path.call(print, 'items') : '' + node.items.length ? path.map(print, 'items') : '' }; diff --git a/src/slang-nodes/StateVariableDefinition.js b/src/slang-nodes/StateVariableDefinition.js index 3d54f4b5a..f819e6ee7 100644 --- a/src/slang-nodes/StateVariableDefinition.js +++ b/src/slang-nodes/StateVariableDefinition.js @@ -9,6 +9,7 @@ export const StateVariableDefinition = { }), print: ({ node, path, print }) => [ path.call(print, 'typeName'), + ' ', path.call(print, 'attributes'), ' ', node.name, diff --git a/src/slang-nodes/StateVariableDefinitionValue.js b/src/slang-nodes/StateVariableDefinitionValue.js index 3516e5de2..e3fde26d3 100644 --- a/src/slang-nodes/StateVariableDefinitionValue.js +++ b/src/slang-nodes/StateVariableDefinitionValue.js @@ -4,6 +4,10 @@ export const StateVariableDefinitionValue = { equal: ast.equal.text, value: parse(ast.value, options, parse) }), - // TODO: implement print - print: () => ['TODO: StateVariableDefinitionValue'] + print: ({ node, path, print }) => [ + ' ', + node.equal, + ' ', + path.call(print, 'value') + ] }; diff --git a/src/slang-nodes/StringLiterals.js b/src/slang-nodes/StringLiterals.js index e66d9b2ef..4d163726d 100644 --- a/src/slang-nodes/StringLiterals.js +++ b/src/slang-nodes/StringLiterals.js @@ -1,8 +1,11 @@ +import { doc } from 'prettier'; + +const { join, hardline } = doc.builders; + export const StringLiterals = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), - // TODO: implement print - print: () => ['TODO: StringLiterals'] + print: ({ path, print }) => join(hardline, path.map(print, 'items')) }; diff --git a/src/slang-nodes/TupleExpression.js b/src/slang-nodes/TupleExpression.js index eb9fe1181..d26ddb8bc 100644 --- a/src/slang-nodes/TupleExpression.js +++ b/src/slang-nodes/TupleExpression.js @@ -5,6 +5,9 @@ export const TupleExpression = { items: parse(ast.items, options, parse), closeParen: ast.closeParen.text }), - // TODO: implement print - print: () => ['TODO: TupleExpression'] + print: ({ node, path, print }) => [ + node.openParen, + path.call(print, 'items'), + node.closeParen + ] }; diff --git a/src/slang-nodes/TupleValue.js b/src/slang-nodes/TupleValue.js index 7456d6318..027cb17c1 100644 --- a/src/slang-nodes/TupleValue.js +++ b/src/slang-nodes/TupleValue.js @@ -5,6 +5,6 @@ export const TupleValue = { ? parse(ast.expression, options, parse) : undefined }), - // TODO: implement print - print: () => ['TODO: TupleValue'] + print: ({ node, path, print }) => + node.expression ? path.call(print, 'expression') : '' }; diff --git a/src/slang-nodes/TupleValues.js b/src/slang-nodes/TupleValues.js index 3414eadf2..8ace8acb7 100644 --- a/src/slang-nodes/TupleValues.js +++ b/src/slang-nodes/TupleValues.js @@ -4,6 +4,10 @@ export const TupleValues = { items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), - // TODO: implement print - print: () => ['TODO: TupleValues'] + print: ({ node, path, print }) => + path + .map(print, 'items') + .map((item, index) => + index === 0 ? item : [node.separators[index - 1], item] + ) }; diff --git a/tests/format/Arrays/__snapshots__/jsfmt.spec.js.snap b/tests/format/Arrays/__snapshots__/jsfmt.spec.js.snap index 8eb3ca39b..84dd53f60 100644 --- a/tests/format/Arrays/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Arrays/__snapshots__/jsfmt.spec.js.snap @@ -61,3 +61,59 @@ contract ArraySlices { ================================================================================ `; + +exports[`Arrays.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity ^0.5.2; + +contract Arrays { + bytes32[] public permissions = [bytes32("addPartner"), bytes32("removePartner"), bytes32("addGroup"), bytes32("removeGroup"), bytes32("addUserToGroup"), bytes32("removeUserFromGroup"), bytes32("addSolution"), bytes32("removeSolution"), bytes32("addLibrary"), bytes32("removeLibrary"), bytes32("addPermissionToGroup"), bytes32("removePermissionFromGroup")]; + + function a() { + Outcome.OutcomeItem[] memory outcomeFrom = abi.decode(fromPart.outcome, (Outcome.OutcomeItem[])); +} +} + +contract ArraySlices { + function f(bytes calldata x) public { + bytes memory a1 = abi.decode(x[:], (bytes)); + bytes4 a2 = abi.decode(x[:4], (bytes4)); + address a3 = abi.decode(x[4:], (address)); + } +} + +=====================================output===================================== +pragma solidity ^0.5.2; +contract Arrays { + bytes32[] public permissions = [ + bytes32("addPartner"), + bytes32("removePartner"), + bytes32("addGroup"), + bytes32("removeGroup"), + bytes32("addUserToGroup"), + bytes32("removeUserFromGroup"), + bytes32("addSolution"), + bytes32("removeSolution"), + bytes32("addLibrary"), + bytes32("removeLibrary"), + bytes32("addPermissionToGroup"), + bytes32("removePermissionFromGroup") + ]; + function a() { + Outcome.OutcomeItem[] memory outcomeFrom = abi.decode(fromPart.outcome(Outcome.OutcomeItem[])); + } +} +contract ArraySlices { + function f(bytes calldata x) public { + bytes memory a1 = abi.decode(x[:](bytes)); + bytes4 a2 = abi.decode(x[:4](bytes4)); + address a3 = abi.decode(x[4:](address)); + } +} + +================================================================================ +`; diff --git a/tests/format/Arrays/jsfmt.spec.js b/tests/format/Arrays/jsfmt.spec.js index 765dd60a6..fd56c17bc 100644 --- a/tests/format/Arrays/jsfmt.spec.js +++ b/tests/format/Arrays/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse']); From 837387dd1c0daf565c4d4dc3915fe3704e5cb5ec Mon Sep 17 00:00:00 2001 From: Klaus Date: Thu, 23 May 2024 11:26:03 +1200 Subject: [PATCH 006/160] WIP: 91/210 printers implemented --- src/slang-nodes/AdditiveExpression.js | 7 +++++-- src/slang-nodes/AssignmentExpression.js | 7 +++++-- src/slang-nodes/ComparisonExpression.js | 7 +++++-- src/slang-nodes/EqualityExpression.js | 7 +++++-- src/slang-nodes/IfStatement.js | 10 ++++++++-- src/slang-nodes/Parameter.js | 2 +- src/slang-nodes/PostfixExpression.js | 3 +-- src/slang-nodes/ReturnStatement.js | 7 +++++-- src/slang-nodes/ReturnsDeclaration.js | 8 +++++--- src/slang-nodes/WhileStatement.js | 9 +++++++-- 10 files changed, 47 insertions(+), 20 deletions(-) diff --git a/src/slang-nodes/AdditiveExpression.js b/src/slang-nodes/AdditiveExpression.js index d4290c953..dc5a23e17 100644 --- a/src/slang-nodes/AdditiveExpression.js +++ b/src/slang-nodes/AdditiveExpression.js @@ -5,6 +5,9 @@ export const AdditiveExpression = { operator: ast.operator.text, rightOperand: parse(ast.rightOperand, options, parse) }), - // TODO: implement print - print: () => ['TODO: AdditiveExpression'] + print: ({ node, path, print }) => [ + path.call(print, 'leftOperand'), + ` ${node.operator} `, + path.call(print, 'rightOperand') + ] }; diff --git a/src/slang-nodes/AssignmentExpression.js b/src/slang-nodes/AssignmentExpression.js index a1d7cc822..1eb021f9e 100644 --- a/src/slang-nodes/AssignmentExpression.js +++ b/src/slang-nodes/AssignmentExpression.js @@ -5,6 +5,9 @@ export const AssignmentExpression = { operator: ast.operator.text, rightOperand: parse(ast.rightOperand, options, parse) }), - // TODO: implement print - print: () => ['TODO: AssignmentExpression'] + print: ({ node, path, print }) => [ + path.call(print, 'leftOperand'), + ` ${node.operator} `, + path.call(print, 'rightOperand') + ] }; diff --git a/src/slang-nodes/ComparisonExpression.js b/src/slang-nodes/ComparisonExpression.js index 04efbf969..dcdd352b5 100644 --- a/src/slang-nodes/ComparisonExpression.js +++ b/src/slang-nodes/ComparisonExpression.js @@ -5,6 +5,9 @@ export const ComparisonExpression = { operator: ast.operator.text, rightOperand: parse(ast.rightOperand, options, parse) }), - // TODO: implement print - print: () => ['TODO: ComparisonExpression'] + print: ({ node, path, print }) => [ + path.call(print, 'leftOperand'), + ` ${node.operator} `, + path.call(print, 'rightOperand') + ] }; diff --git a/src/slang-nodes/EqualityExpression.js b/src/slang-nodes/EqualityExpression.js index 3a3ad092b..b486a8aa9 100644 --- a/src/slang-nodes/EqualityExpression.js +++ b/src/slang-nodes/EqualityExpression.js @@ -5,6 +5,9 @@ export const EqualityExpression = { operator: ast.operator.text, rightOperand: parse(ast.rightOperand, options, parse) }), - // TODO: implement print - print: () => ['TODO: EqualityExpression'] + print: ({ node, path, print }) => [ + path.call(print, 'leftOperand'), + ` ${node.operator} `, + path.call(print, 'rightOperand') + ] }; diff --git a/src/slang-nodes/IfStatement.js b/src/slang-nodes/IfStatement.js index 8bab155f9..b41851033 100644 --- a/src/slang-nodes/IfStatement.js +++ b/src/slang-nodes/IfStatement.js @@ -10,6 +10,12 @@ export const IfStatement = { ? parse(ast.elseBranch, options, parse) : undefined }), - // TODO: implement print - print: () => ['TODO: IfStatement'] + print: ({ node, path, print }) => [ + node.ifKeyword, + node.openParen, + path.call(print, 'condition'), + node.closeParen, + path.call(print, 'body'), + node.elseBranch ? path.call(print, 'elseBranch') : '' + ] }; diff --git a/src/slang-nodes/Parameter.js b/src/slang-nodes/Parameter.js index 1369f5f40..2e53e6a0f 100644 --- a/src/slang-nodes/Parameter.js +++ b/src/slang-nodes/Parameter.js @@ -10,6 +10,6 @@ export const Parameter = { print: ({ node, path, print }) => [ path.call(print, 'typeName'), node.storageLocation ? ` ${path.call(print, 'storageLocation')} ` : ' ', - node.name + node.name ? node.name : '' ] }; diff --git a/src/slang-nodes/PostfixExpression.js b/src/slang-nodes/PostfixExpression.js index 609946cac..3a44339f0 100644 --- a/src/slang-nodes/PostfixExpression.js +++ b/src/slang-nodes/PostfixExpression.js @@ -4,6 +4,5 @@ export const PostfixExpression = { operand: parse(ast.operand, options, parse), operator: ast.operator.text }), - // TODO: implement print - print: () => ['TODO: PostfixExpression'] + print: ({ node, path, print }) => [path.call(print, 'operand'), node.operator] }; diff --git a/src/slang-nodes/ReturnStatement.js b/src/slang-nodes/ReturnStatement.js index df7b94bf6..9643c85a3 100644 --- a/src/slang-nodes/ReturnStatement.js +++ b/src/slang-nodes/ReturnStatement.js @@ -7,6 +7,9 @@ export const ReturnStatement = { : undefined, semicolon: ast.semicolon.text }), - // TODO: implement print - print: () => ['TODO: ReturnStatement'] + print: ({ node, path, print }) => [ + node.returnKeyword, + node.expression ? ` ${path.call(print, 'expression')}` : '', + node.semicolon + ] }; diff --git a/src/slang-nodes/ReturnsDeclaration.js b/src/slang-nodes/ReturnsDeclaration.js index 5f6dfb9e0..fa42aa92f 100644 --- a/src/slang-nodes/ReturnsDeclaration.js +++ b/src/slang-nodes/ReturnsDeclaration.js @@ -1,9 +1,11 @@ export const ReturnsDeclaration = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, - returnsKeyword: ast.returnsKeyword, + returnsKeyword: ast.returnsKeyword.text, variables: parse(ast.variables, options, parse) }), - // TODO: implement print - print: () => ['TODO: ReturnsDeclaration'] + print: ({ node, path, print }) => [ + node.returnsKeyword, + path.call(print, 'variables') + ] }; diff --git a/src/slang-nodes/WhileStatement.js b/src/slang-nodes/WhileStatement.js index c154155a7..141b69dbb 100644 --- a/src/slang-nodes/WhileStatement.js +++ b/src/slang-nodes/WhileStatement.js @@ -7,6 +7,11 @@ export const WhileStatement = { closeParen: ast.closeParen.text, body: parse(ast.body, options, parse) }), - // TODO: implement print - print: () => ['TODO: WhileStatement'] + print: ({ node, path, print }) => [ + node.whileKeyword, + node.openParen, + path.call(print, 'condition'), + node.closeParen, + path.call(print, 'body') + ] }; From 88242a179ea9f792ad48924121e3dfac773a07dc Mon Sep 17 00:00:00 2001 From: Klaus Date: Fri, 24 May 2024 18:52:05 +1200 Subject: [PATCH 007/160] WIP: 102/210 printers implemented --- src/common/printer-helpers.js | 5 +- src/slang-nodes/AssemblyFlags.js | 4 +- src/slang-nodes/AssemblyStatement.js | 9 +- src/slang-nodes/YulArguments.js | 8 +- src/slang-nodes/YulAssignmentStatement.js | 9 +- src/slang-nodes/YulBlock.js | 15 +- src/slang-nodes/YulFunctionCallExpression.js | 8 +- src/slang-nodes/YulLabel.js | 7 +- src/slang-nodes/YulPath.js | 8 +- src/slang-nodes/YulPaths.js | 8 +- src/slang-nodes/YulStatements.js | 6 +- .../YulVariableDeclarationStatement.js | 9 +- .../YulVariableDeclarationValue.js | 7 +- src/slangParser.js | 6 +- tests/format/AssemblyV0.4.26/Assembly.sol | 36 ++++ .../__snapshots__/jsfmt.spec.js.snap | 168 ++++++++++++++++++ tests/format/AssemblyV0.4.26/jsfmt.spec.js | 2 + 17 files changed, 287 insertions(+), 28 deletions(-) create mode 100644 tests/format/AssemblyV0.4.26/Assembly.sol create mode 100644 tests/format/AssemblyV0.4.26/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/format/AssemblyV0.4.26/jsfmt.spec.js diff --git a/src/common/printer-helpers.js b/src/common/printer-helpers.js index 1401e1aac..d7005bf47 100644 --- a/src/common/printer-helpers.js +++ b/src/common/printer-helpers.js @@ -40,14 +40,15 @@ export function printPreservingEmptyLines(path, key, options, print) { const parts = []; path.each((childPath, index) => { const node = childPath.getValue(); - const nodeType = node.type; + const nodeType = node.type || node.kind; if ( // Avoid adding a hardline at the beginning of the document. parts.length !== 0 && // LabelDefinition adds a dedented line so we don't have to prepend a // hardline. - nodeType !== 'LabelDefinition' + nodeType !== 'LabelDefinition' && + (nodeType !== 'YulStatement' || node.variant.kind !== 'YulLabel') ) { parts.push(hardline); } diff --git a/src/slang-nodes/AssemblyFlags.js b/src/slang-nodes/AssemblyFlags.js index 259ffd704..59073796b 100644 --- a/src/slang-nodes/AssemblyFlags.js +++ b/src/slang-nodes/AssemblyFlags.js @@ -1,8 +1,8 @@ export const AssemblyFlags = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, - items: ast.items.maps((item) => parse(item, options, parse)), - separators: ast.separators.maps((separator) => separator.text) + items: ast.items.map((item) => parse(item, options, parse)), + separators: ast.separators.map((separator) => separator.text) }), // TODO: implement print print: () => ['TODO: AssemblyFlags'] diff --git a/src/slang-nodes/AssemblyStatement.js b/src/slang-nodes/AssemblyStatement.js index 1a8986e9e..bbf95af36 100644 --- a/src/slang-nodes/AssemblyStatement.js +++ b/src/slang-nodes/AssemblyStatement.js @@ -6,6 +6,11 @@ export const AssemblyStatement = { flags: ast.flags ? parse(ast.flags, options, parse) : undefined, body: parse(ast.body, options, parse) }), - // TODO: implement print - print: () => ['TODO: AssemblyStatement'] + print: ({ node, path, print }) => [ + node.assemblyKeyword, + ' ', + node.label ? path.call(print, 'label') : '', + node.flags ? path.call(print, 'flags') : '', + path.call(print, 'body') + ] }; diff --git a/src/slang-nodes/YulArguments.js b/src/slang-nodes/YulArguments.js index 2a7dc11d4..7f7f74218 100644 --- a/src/slang-nodes/YulArguments.js +++ b/src/slang-nodes/YulArguments.js @@ -4,6 +4,10 @@ export const YulArguments = { items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), - // TODO: implement print - print: () => ['TODO: YulArguments'] + print: ({ node, path, print }) => + path + .map(print, 'items') + .map((item, index) => + index === 0 ? item : [node.separators[index - 1], item] + ) }; diff --git a/src/slang-nodes/YulAssignmentStatement.js b/src/slang-nodes/YulAssignmentStatement.js index 78ca945e9..4f3f48d2e 100644 --- a/src/slang-nodes/YulAssignmentStatement.js +++ b/src/slang-nodes/YulAssignmentStatement.js @@ -5,6 +5,11 @@ export const YulAssignmentStatement = { assignment: parse(ast.assignment, options, parse), expression: parse(ast.expression, options, parse) }), - // TODO: implement print - print: () => ['TODO: YulAssignmentStatement'] + print: ({ path, print }) => [ + path.call(print, 'names'), + ' ', + path.call(print, 'assignment'), + ' ', + path.call(print, 'expression') + ] }; diff --git a/src/slang-nodes/YulBlock.js b/src/slang-nodes/YulBlock.js index f88107ab8..4a5e5fc11 100644 --- a/src/slang-nodes/YulBlock.js +++ b/src/slang-nodes/YulBlock.js @@ -1,3 +1,8 @@ +import { doc } from 'prettier'; +import { printSeparatedItem } from '../common/printer-helpers.js'; + +const { hardline } = doc.builders; + export const YulBlock = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, @@ -5,6 +10,12 @@ export const YulBlock = { statements: parse(ast.statements, options, parse), closeBrace: ast.closeBrace.text }), - // TODO: implement print - print: () => ['TODO: YulBlock'] + print: ({ node, path, print, options }) => [ + node.openBrace, + printSeparatedItem(print.call(print, 'statements'), { + firstSeparator: hardline, + grouped: false + }), + node.closeBrace + ] }; diff --git a/src/slang-nodes/YulFunctionCallExpression.js b/src/slang-nodes/YulFunctionCallExpression.js index f60c68aaf..5c3481b09 100644 --- a/src/slang-nodes/YulFunctionCallExpression.js +++ b/src/slang-nodes/YulFunctionCallExpression.js @@ -6,6 +6,10 @@ export const YulFunctionCallExpression = { arguments: parse(ast.arguments, options, parse), closeParen: ast.closeParen.text }), - // TODO: implement print - print: () => ['TODO: YulFunctionCallExpression'] + print: ({ node, path, print }) => [ + path.call(print, 'operand'), + node.openParen, + path.call(print, 'arguments'), + node.closeParen + ] }; diff --git a/src/slang-nodes/YulLabel.js b/src/slang-nodes/YulLabel.js index 122d022e6..a0cf07d42 100644 --- a/src/slang-nodes/YulLabel.js +++ b/src/slang-nodes/YulLabel.js @@ -1,9 +1,12 @@ +import { doc } from 'prettier'; + +const { dedent, line } = doc.builders; + export const YulLabel = { parse: ({ ast }) => ({ kind: ast.cst.kind, label: ast.label.text, colon: ast.colon.text }), - // TODO: implement print - print: () => ['TODO: YulLabel'] + print: ({ node }) => [dedent(line), node.label, node.colon] }; diff --git a/src/slang-nodes/YulPath.js b/src/slang-nodes/YulPath.js index 864017787..35f8d6efd 100644 --- a/src/slang-nodes/YulPath.js +++ b/src/slang-nodes/YulPath.js @@ -4,6 +4,10 @@ export const YulPath = { items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), - // TODO: implement print - print: () => ['TODO: YulPath'] + print: ({ node, path, print }) => + path + .map(print, 'items') + .map((item, index) => + index === 0 ? item : [node.separators[index - 1], item] + ) }; diff --git a/src/slang-nodes/YulPaths.js b/src/slang-nodes/YulPaths.js index b4da07c57..a7441d6e6 100644 --- a/src/slang-nodes/YulPaths.js +++ b/src/slang-nodes/YulPaths.js @@ -4,6 +4,10 @@ export const YulPaths = { items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), - // TODO: implement print - print: () => ['TODO: YulPaths'] + print: ({ node, path, print }) => + path + .map(print, 'items') + .map((item, index) => + index === 0 ? item : [node.separators[index - 1], item] + ) }; diff --git a/src/slang-nodes/YulStatements.js b/src/slang-nodes/YulStatements.js index 8355c2a76..bcbb7ea7a 100644 --- a/src/slang-nodes/YulStatements.js +++ b/src/slang-nodes/YulStatements.js @@ -1,8 +1,10 @@ +import { printPreservingEmptyLines } from '../common/printer-helpers.js'; + export const YulStatements = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), - // TODO: implement print - print: () => ['TODO: YulStatements'] + print: ({ path, print, options }) => + printPreservingEmptyLines(path, 'items', options, print) }; diff --git a/src/slang-nodes/YulVariableDeclarationStatement.js b/src/slang-nodes/YulVariableDeclarationStatement.js index 477f829bc..e3ff630b7 100644 --- a/src/slang-nodes/YulVariableDeclarationStatement.js +++ b/src/slang-nodes/YulVariableDeclarationStatement.js @@ -5,6 +5,11 @@ export const YulVariableDeclarationStatement = { names: ast.names.text, value: ast.value ? parse(ast.value, options, parse) : undefined }), - // TODO: implement print - print: () => ['TODO: YulVariableDeclarationStatement'] + print: ({ node, path, print }) => [ + node.letKeyword, + ' ', + node.names, + ' ', + node.value ? path.call(print, 'value') : '' + ] }; diff --git a/src/slang-nodes/YulVariableDeclarationValue.js b/src/slang-nodes/YulVariableDeclarationValue.js index 4c709a1fd..6ec94e862 100644 --- a/src/slang-nodes/YulVariableDeclarationValue.js +++ b/src/slang-nodes/YulVariableDeclarationValue.js @@ -4,6 +4,9 @@ export const YulVariableDeclarationValue = { assignment: parse(ast.assignment, options, parse), expression: parse(ast.expression, options, parse) }), - // TODO: implement print - print: () => ['TODO: YulVariableDeclarationValue'] + print: ({ path, print }) => [ + path.call(print, 'assignment'), + ' ', + path.call(print, 'expression') + ] }; diff --git a/src/slangParser.js b/src/slangParser.js index 2bf0f13e0..7ab59742f 100644 --- a/src/slangParser.js +++ b/src/slangParser.js @@ -3,6 +3,7 @@ import { Language } from '@nomicfoundation/slang/language/index.js'; import { RuleKind } from '@nomicfoundation/slang/kinds/index.js'; import { SourceUnit } from '@nomicfoundation/slang/ast/index.js'; +import coerce from 'semver/functions/coerce.js'; import * as parsers from './slang-nodes/index.js'; function genericParse(ast, options, parseFunction) { @@ -10,8 +11,9 @@ function genericParse(ast, options, parseFunction) { } function parse(text, _parsers, options = _parsers) { - // const compiler = coerce(options.compiler); - const language = new Language('0.8.0'); + const compiler = coerce(options.compiler); + + const language = new Language( compiler?.version || '0.8.0'); const parsed = new SourceUnit( language.parse(RuleKind.SourceUnit, text).tree() ); diff --git a/tests/format/AssemblyV0.4.26/Assembly.sol b/tests/format/AssemblyV0.4.26/Assembly.sol new file mode 100644 index 000000000..536bcb652 --- /dev/null +++ b/tests/format/AssemblyV0.4.26/Assembly.sol @@ -0,0 +1,36 @@ +pragma solidity ^0.4.26; + +contract Assembly { + function assemblyLabels() { + assembly { + let n := calldataload(4) + let a := 1 + let b := a +loop: + jumpi(loopend, eq(n, 0)) + a add swap1 + n := sub(n, 1) + jump(loop) + +loopend: + mstore(0, a) + return(0, 0x20) +} + +assembly{ + let x := 8 + jump(two) + one: + // Here the stack height is 2 (because we pushed x and 7), + // but the assembler thinks it is 1 because it reads + // from top to bottom. + // Accessing the stack variable x here will lead to errors. + x := 9 + jump(three) + two: + 7 // push something onto the stack + jump(one) + three: +} +} +} diff --git a/tests/format/AssemblyV0.4.26/__snapshots__/jsfmt.spec.js.snap b/tests/format/AssemblyV0.4.26/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000..247bc7d3c --- /dev/null +++ b/tests/format/AssemblyV0.4.26/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,168 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Assembly.sol - {"compiler":"0.4.26"} format 1`] = ` +====================================options===================================== +compiler: "0.4.26" +parsers: ["solidity-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity ^0.4.26; + +contract Assembly { + function assemblyLabels() { + assembly { + let n := calldataload(4) + let a := 1 + let b := a +loop: + jumpi(loopend, eq(n, 0)) + a add swap1 + n := sub(n, 1) + jump(loop) + +loopend: + mstore(0, a) + return(0, 0x20) +} + +assembly{ + let x := 8 + jump(two) + one: + // Here the stack height is 2 (because we pushed x and 7), + // but the assembler thinks it is 1 because it reads + // from top to bottom. + // Accessing the stack variable x here will lead to errors. + x := 9 + jump(three) + two: + 7 // push something onto the stack + jump(one) + three: +} +} +} + +=====================================output===================================== +pragma solidity ^0.4.26; + +contract Assembly { + function assemblyLabels() { + assembly { + let n := calldataload(4) + let a := 1 + let b := a + loop: + jumpi(loopend, eq(n, 0)) + a + add + swap1 + n := sub(n, 1) + jump(loop) + + loopend: + mstore(0, a) + return(0, 0x20) + } + + assembly { + let x := 8 + jump(two) + one: + // Here the stack height is 2 (because we pushed x and 7), + // but the assembler thinks it is 1 because it reads + // from top to bottom. + // Accessing the stack variable x here will lead to errors. + x := 9 + jump(three) + two: + 7 // push something onto the stack + jump(one) + three: + } + } +} + +================================================================================ +`; + +exports[`Assembly.sol - {"compiler":"0.4.26"} format 2`] = ` +====================================options===================================== +compiler: "0.4.26" +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity ^0.4.26; + +contract Assembly { + function assemblyLabels() { + assembly { + let n := calldataload(4) + let a := 1 + let b := a +loop: + jumpi(loopend, eq(n, 0)) + a add swap1 + n := sub(n, 1) + jump(loop) + +loopend: + mstore(0, a) + return(0, 0x20) +} + +assembly{ + let x := 8 + jump(two) + one: + // Here the stack height is 2 (because we pushed x and 7), + // but the assembler thinks it is 1 because it reads + // from top to bottom. + // Accessing the stack variable x here will lead to errors. + x := 9 + jump(three) + two: + 7 // push something onto the stack + jump(one) + three: +} +} +} + +=====================================output===================================== +pragma solidity ^0.4.26; +contract Assembly { + function assemblyLabels() { + assembly { + let n := calldataload(4) + let a := 1 + let b := a + loop: + jumpi(loopend,eq(n,0)) + a + add + swap1 + n := sub(n,1) + jump(loop) + loopend: + mstore(0,a) + return(0,0x20) + } + assembly { + let x := 8 + jump(two) + one: + x := 9 + jump(three) + two: + 7 + jump(one) + three: + } + } +} + +================================================================================ +`; diff --git a/tests/format/AssemblyV0.4.26/jsfmt.spec.js b/tests/format/AssemblyV0.4.26/jsfmt.spec.js new file mode 100644 index 000000000..a73b08dfc --- /dev/null +++ b/tests/format/AssemblyV0.4.26/jsfmt.spec.js @@ -0,0 +1,2 @@ +run_spec(import.meta, ['solidity-parse'], { compiler: '0.4.26' }); +run_spec(import.meta, ['solidity-slang-parse'], { compiler: '0.4.26' }); From b6a349bd57b0859ccaf34f796a10c19c45ea5710 Mon Sep 17 00:00:00 2001 From: Klaus Date: Sat, 25 May 2024 10:18:25 +1200 Subject: [PATCH 008/160] WIP: 116/210 printers implemented --- src/slang-nodes/AssemblyFlags.js | 5 +++-- src/slang-nodes/AssemblyFlagsDeclaration.js | 7 +++++-- src/slang-nodes/AssemblyStatement.js | 5 ++--- src/slang-nodes/YulBlock.js | 2 +- src/slang-nodes/YulBreakStatement.js | 3 +-- src/slang-nodes/YulContinueStatement.js | 3 +-- src/slang-nodes/YulForStatement.js | 13 +++++++++++-- src/slang-nodes/YulFunctionDefinition.js | 10 ++++++++-- src/slang-nodes/YulIfStatement.js | 9 +++++++-- src/slang-nodes/YulParameters.js | 5 +++-- src/slang-nodes/YulParametersDeclaration.js | 7 +++++-- src/slang-nodes/YulReturnVariables.js | 12 ++++++++++-- src/slang-nodes/YulReturnsDeclaration.js | 11 +++++++++-- src/slang-nodes/YulSwitchCases.js | 7 +++++-- src/slang-nodes/YulSwitchStatement.js | 13 +++++++++++-- src/slang-nodes/YulValueCase.js | 9 +++++++-- 16 files changed, 89 insertions(+), 32 deletions(-) diff --git a/src/slang-nodes/AssemblyFlags.js b/src/slang-nodes/AssemblyFlags.js index 59073796b..ab3671819 100644 --- a/src/slang-nodes/AssemblyFlags.js +++ b/src/slang-nodes/AssemblyFlags.js @@ -1,9 +1,10 @@ +import { printSeparatedList } from '../common/printer-helpers.js'; + export const AssemblyFlags = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), - // TODO: implement print - print: () => ['TODO: AssemblyFlags'] + print: ({ path, print }) => printSeparatedList(path.map(print, 'items')) }; diff --git a/src/slang-nodes/AssemblyFlagsDeclaration.js b/src/slang-nodes/AssemblyFlagsDeclaration.js index 978eb85f0..53dcbb43f 100644 --- a/src/slang-nodes/AssemblyFlagsDeclaration.js +++ b/src/slang-nodes/AssemblyFlagsDeclaration.js @@ -5,6 +5,9 @@ export const AssemblyFlagsDeclaration = { flags: parse(ast.flags, options, parse), closeParen: ast.closeParen.text }), - // TODO: implement print - print: () => ['TODO: AssemblyFlagsDeclaration'] + print: ({ node, path, print }) => [ + node.openParen, + path.call(print, 'flags'), + node.closeParen + ] }; diff --git a/src/slang-nodes/AssemblyStatement.js b/src/slang-nodes/AssemblyStatement.js index bbf95af36..b5ed0ea6f 100644 --- a/src/slang-nodes/AssemblyStatement.js +++ b/src/slang-nodes/AssemblyStatement.js @@ -8,9 +8,8 @@ export const AssemblyStatement = { }), print: ({ node, path, print }) => [ node.assemblyKeyword, - ' ', - node.label ? path.call(print, 'label') : '', - node.flags ? path.call(print, 'flags') : '', + node.label ? [' ', path.call(print, 'label')] : '', + node.flags ? [' ', path.call(print, 'flags'), ' '] : ' ', path.call(print, 'body') ] }; diff --git a/src/slang-nodes/YulBlock.js b/src/slang-nodes/YulBlock.js index 4a5e5fc11..1f3c71db6 100644 --- a/src/slang-nodes/YulBlock.js +++ b/src/slang-nodes/YulBlock.js @@ -10,7 +10,7 @@ export const YulBlock = { statements: parse(ast.statements, options, parse), closeBrace: ast.closeBrace.text }), - print: ({ node, path, print, options }) => [ + print: ({ node, print }) => [ node.openBrace, printSeparatedItem(print.call(print, 'statements'), { firstSeparator: hardline, diff --git a/src/slang-nodes/YulBreakStatement.js b/src/slang-nodes/YulBreakStatement.js index 07b5e4125..50dd95ed4 100644 --- a/src/slang-nodes/YulBreakStatement.js +++ b/src/slang-nodes/YulBreakStatement.js @@ -3,6 +3,5 @@ export const YulBreakStatement = { kind: ast.cst.kind, breakKeyword: ast.breakKeyword.text }), - // TODO: implement print - print: () => ['TODO: YulBreakStatement'] + print: ({node}) => node.breakKeyword }; diff --git a/src/slang-nodes/YulContinueStatement.js b/src/slang-nodes/YulContinueStatement.js index 09c8629f1..f9c0fd0b6 100644 --- a/src/slang-nodes/YulContinueStatement.js +++ b/src/slang-nodes/YulContinueStatement.js @@ -3,6 +3,5 @@ export const YulContinueStatement = { kind: ast.cst.kind, continueKeyword: ast.continueKeyword.text }), - // TODO: implement print - print: () => ['TODO: YulContinueStatement'] + print: ({node}) => node.continueKeyword }; diff --git a/src/slang-nodes/YulForStatement.js b/src/slang-nodes/YulForStatement.js index a02f65b41..ac2b30ebd 100644 --- a/src/slang-nodes/YulForStatement.js +++ b/src/slang-nodes/YulForStatement.js @@ -7,6 +7,15 @@ export const YulForStatement = { iterator: parse(ast.iterator, options, parse), body: parse(ast.body, options, parse) }), - // TODO: implement print - print: () => ['TODO: YulForStatement'] + print: ({ node, path, print }) => [ + node.forKeyword, + ' ', + path.call(print, 'initialization'), + ' ', + path.call(print, 'condition'), + ' ', + path.call(print, 'iterator'), + ' ', + path.call(print, 'body') + ] }; diff --git a/src/slang-nodes/YulFunctionDefinition.js b/src/slang-nodes/YulFunctionDefinition.js index 4758ab69a..81fdedd72 100644 --- a/src/slang-nodes/YulFunctionDefinition.js +++ b/src/slang-nodes/YulFunctionDefinition.js @@ -7,6 +7,12 @@ export const YulFunctionDefinition = { returns: ast.returns ? parse(ast.returns, options, parse) : undefined, body: parse(ast.body, options, parse) }), - // TODO: implement print - print: () => ['TODO: YulFunctionDefinition'] + print: ({ node, path, print }) => [ + node.functionKeyword, + ' ', + node.name, + path.call(print, 'parameters'), + node.returns ? path.call(print, 'returns') : ' ', + path.call(print, 'body') + ] }; diff --git a/src/slang-nodes/YulIfStatement.js b/src/slang-nodes/YulIfStatement.js index 2337dd4c1..acd091955 100644 --- a/src/slang-nodes/YulIfStatement.js +++ b/src/slang-nodes/YulIfStatement.js @@ -5,6 +5,11 @@ export const YulIfStatement = { condition: parse(ast.condition, options, parse), body: parse(ast.body, options, parse) }), - // TODO: implement print - print: () => ['TODO: YulIfStatement'] + print: ({ node, path, print }) => [ + node.ifKeyword, + ' ', + path.call(print, 'condition'), + ' ', + path.call(print, 'body') + ] }; diff --git a/src/slang-nodes/YulParameters.js b/src/slang-nodes/YulParameters.js index df04ae157..fd98c6cf5 100644 --- a/src/slang-nodes/YulParameters.js +++ b/src/slang-nodes/YulParameters.js @@ -1,9 +1,10 @@ +import { printSeparatedList } from '../common/printer-helpers.js'; + export const YulParameters = { parse: ({ ast }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => item.text), separators: ast.separators.map((separator) => separator.text) }), - // TODO: implement print - print: () => ['TODO: YulParameters'] + print: ({ node }) => printSeparatedList(node.items) }; diff --git a/src/slang-nodes/YulParametersDeclaration.js b/src/slang-nodes/YulParametersDeclaration.js index 8843a1b1e..9005fce3d 100644 --- a/src/slang-nodes/YulParametersDeclaration.js +++ b/src/slang-nodes/YulParametersDeclaration.js @@ -5,6 +5,9 @@ export const YulParametersDeclaration = { parameters: parse(ast.parameters, options, parse), closeParen: ast.closeParen.text }), - // TODO: implement print - print: () => ['TODO: YulParametersDeclaration'] + print: ({ node, path, print }) => [ + node.openParen, + path.call(print, 'parameters'), + node.closeParen + ] }; diff --git a/src/slang-nodes/YulReturnVariables.js b/src/slang-nodes/YulReturnVariables.js index 7bd26b260..d18a339c6 100644 --- a/src/slang-nodes/YulReturnVariables.js +++ b/src/slang-nodes/YulReturnVariables.js @@ -1,9 +1,17 @@ +import { doc } from 'prettier'; +import { printSeparatedList } from '../common/printer-helpers.js'; + +const { line } = doc.builders; + export const YulReturnVariables = { parse: ({ ast }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => item.text), separators: ast.separators.map((separator) => separator.text) }), - // TODO: implement print - print: () => ['TODO: YulReturnVariables'] + print: ({ node }) => + printSeparatedList(node.items, { + firstSeparator: line, + lastSeparator: '' + }) }; diff --git a/src/slang-nodes/YulReturnsDeclaration.js b/src/slang-nodes/YulReturnsDeclaration.js index aef370b42..22b6614ff 100644 --- a/src/slang-nodes/YulReturnsDeclaration.js +++ b/src/slang-nodes/YulReturnsDeclaration.js @@ -1,9 +1,16 @@ +import { doc } from 'prettier'; +import { printSeparatedItem } from '../common/printer-helpers.js'; + +const { line } = doc.builders; + export const YulReturnsDeclaration = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, minusGreaterThan: ast.minusGreaterThan.text, variables: parse(ast.variables, options, parse) }), - // TODO: implement print - print: () => ['TODO: YulReturnsDeclaration'] + print: ({ node, path, print }) => + printSeparatedItem([node.minusGreaterThan, path.call(print, 'variables')], { + firstSeparator: line + }) }; diff --git a/src/slang-nodes/YulSwitchCases.js b/src/slang-nodes/YulSwitchCases.js index bf14ca705..72006eaf7 100644 --- a/src/slang-nodes/YulSwitchCases.js +++ b/src/slang-nodes/YulSwitchCases.js @@ -1,8 +1,11 @@ +import { doc } from 'prettier'; + +const { hardline, join } = doc.builders; + export const YulSwitchCases = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), - // TODO: implement print - print: () => ['TODO: YulSwitchCases'] + print: ({ path, print }) => join(hardline, path.map(print, 'items')) }; diff --git a/src/slang-nodes/YulSwitchStatement.js b/src/slang-nodes/YulSwitchStatement.js index 14fbd6593..f54ee32b2 100644 --- a/src/slang-nodes/YulSwitchStatement.js +++ b/src/slang-nodes/YulSwitchStatement.js @@ -1,3 +1,7 @@ +import { doc } from 'prettier'; + +const { hardline } = doc.builders; + export const YulSwitchStatement = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, @@ -5,6 +9,11 @@ export const YulSwitchStatement = { expression: parse(ast.expression, options, parse), cases: parse(ast.cases, options, parse) }), - // TODO: implement print - print: () => ['TODO: YulSwitchStatement'] + print: ({ node, path, print }) => [ + node.switchKeyword, + ' ', + path.call(print, 'expression'), + hardline, + path.call(print, 'cases') + ] }; diff --git a/src/slang-nodes/YulValueCase.js b/src/slang-nodes/YulValueCase.js index a44511a59..70de6965b 100644 --- a/src/slang-nodes/YulValueCase.js +++ b/src/slang-nodes/YulValueCase.js @@ -5,6 +5,11 @@ export const YulValueCase = { value: parse(ast.value, options, parse), body: parse(ast.body, options, parse) }), - // TODO: implement print - print: () => ['TODO: YulValueCase'] + print: ({ node, path, print }) => [ + node.caseKeyword, + ' ', + path.call(print, 'value'), + ' ', + path.call(print, 'body') + ] }; From 9248284f84a13d5ab5885d1cf295e3274b838206 Mon Sep 17 00:00:00 2001 From: Klaus Date: Sun, 26 May 2024 22:33:41 +1200 Subject: [PATCH 009/160] small details in format --- src/slang-nodes/FunctionDefinition.js | 1 + src/slang-nodes/Parameter.js | 4 +- src/slang-nodes/ReturnsDeclaration.js | 2 +- src/slang-nodes/YulDefaultCase.js | 6 +- src/slang-nodes/YulValueCase.js | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 83 +++++++++++++++++++ tests/format/BasicIterator/jsfmt.spec.js | 1 + 7 files changed, 93 insertions(+), 7 deletions(-) diff --git a/src/slang-nodes/FunctionDefinition.js b/src/slang-nodes/FunctionDefinition.js index e793caa47..22df03780 100644 --- a/src/slang-nodes/FunctionDefinition.js +++ b/src/slang-nodes/FunctionDefinition.js @@ -21,6 +21,7 @@ export const FunctionDefinition = { indent( group([ path.call(print, 'attributes'), + line, node.returns ? path.call(print, 'returns') : '', dedent(line) ]) diff --git a/src/slang-nodes/Parameter.js b/src/slang-nodes/Parameter.js index 2e53e6a0f..9950eeaf3 100644 --- a/src/slang-nodes/Parameter.js +++ b/src/slang-nodes/Parameter.js @@ -9,7 +9,7 @@ export const Parameter = { }), print: ({ node, path, print }) => [ path.call(print, 'typeName'), - node.storageLocation ? ` ${path.call(print, 'storageLocation')} ` : ' ', - node.name ? node.name : '' + node.storageLocation ? ` ${path.call(print, 'storageLocation')}` : '', + node.name ? ` ${node.name}` : '' ] }; diff --git a/src/slang-nodes/ReturnsDeclaration.js b/src/slang-nodes/ReturnsDeclaration.js index fa42aa92f..786e12554 100644 --- a/src/slang-nodes/ReturnsDeclaration.js +++ b/src/slang-nodes/ReturnsDeclaration.js @@ -5,7 +5,7 @@ export const ReturnsDeclaration = { variables: parse(ast.variables, options, parse) }), print: ({ node, path, print }) => [ - node.returnsKeyword, + `${node.returnsKeyword} `, path.call(print, 'variables') ] }; diff --git a/src/slang-nodes/YulDefaultCase.js b/src/slang-nodes/YulDefaultCase.js index a45da0193..8a34c0c9b 100644 --- a/src/slang-nodes/YulDefaultCase.js +++ b/src/slang-nodes/YulDefaultCase.js @@ -4,6 +4,8 @@ export const YulDefaultCase = { defaultKeyword: ast.defaultKeyword.text, body: parse(ast.body, options, parse) }), - // TODO: implement print - print: () => ['TODO: YulDefaultCase'] + print: ({ node, path, print }) => [ + `${node.defaultKeyword} `, + path.call(print, 'body') + ] }; diff --git a/src/slang-nodes/YulValueCase.js b/src/slang-nodes/YulValueCase.js index 70de6965b..ed876b5da 100644 --- a/src/slang-nodes/YulValueCase.js +++ b/src/slang-nodes/YulValueCase.js @@ -6,8 +6,7 @@ export const YulValueCase = { body: parse(ast.body, options, parse) }), print: ({ node, path, print }) => [ - node.caseKeyword, - ' ', + `${node.caseKeyword} `, path.call(print, 'value'), ' ', path.call(print, 'body') diff --git a/tests/format/BasicIterator/__snapshots__/jsfmt.spec.js.snap b/tests/format/BasicIterator/__snapshots__/jsfmt.spec.js.snap index 8b650d09a..d6d8db622 100644 --- a/tests/format/BasicIterator/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/BasicIterator/__snapshots__/jsfmt.spec.js.snap @@ -1,5 +1,88 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`BasicIterator.sol - {"compiler":"0.4.11"} format 1`] = ` +====================================options===================================== +compiler: "0.4.11" +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +/* + This is a very simple demonstration of a while loops. Same as JS/c. +*/ + +contract BasicIterator { + + address creator; // reserve one "address"-type spot + uint8[10] integers; // reserve a chunk of storage for 10 8-bit unsigned integers in an array + + function BasicIterator() + { + creator = msg.sender; // set the creator address + uint8 x = 0; // initialize an 8-bit, unsigned integer to zero + while(x < integers.length) // the variable integers was initialized to length 10 + { + integers[x] = x; // set integers to [0,1,2,3,4,5,6,7,8,9] over ten iterations + x++; + } + } + + function getSum() constant returns (uint) // "constant" just means this function returns something to the caller + { // which is immediately followed by what type gets returned, in this case a full uint256 + uint8 sum = 0; + uint8 x = 0; + while(x < integers.length) + { + sum = sum + integers[x]; + x++; + } + return sum; + } + + /********** + Standard kill() function to recover funds + **********/ + + function kill() + { + if (msg.sender == creator) + { + suicide(creator); // kills this contract and sends remaining funds back to creator + } + } +} + +=====================================output===================================== +contract BasicIterator { + address creator; + uint8[10] integers; + function BasicIterator() { + creator = msg.sender; + uint8 x = 0; + while(x < integers.length){ + integers[x] = x; + x++; + } + } + function getSum() constant returns (uint) { + uint8 sum = 0; + uint8 x = 0; + while(x < integers.length){ + sum = sum + integers[x]; + x++; + } + return sum; + } + function kill() { + if(msg.sender == creator){ + suicide(creator); + } + } +} + +================================================================================ +`; + exports[`BasicIterator.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] diff --git a/tests/format/BasicIterator/jsfmt.spec.js b/tests/format/BasicIterator/jsfmt.spec.js index 765dd60a6..57f8f2948 100644 --- a/tests/format/BasicIterator/jsfmt.spec.js +++ b/tests/format/BasicIterator/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse'], { compiler: '0.4.11' }); From acde00137e082dcb6f07fb19855dd1617c759780 Mon Sep 17 00:00:00 2001 From: Klaus Date: Mon, 27 May 2024 10:10:54 +1200 Subject: [PATCH 010/160] WIP: 122/210 printers implemented --- src/slang-nodes/FunctionDefinition.js | 3 +- src/slang-nodes/ImportAlias.js | 3 +- src/slang-nodes/ImportDeconstruction.js | 8 +- src/slang-nodes/ImportDeconstructionSymbol.js | 6 +- .../ImportDeconstructionSymbols.js | 30 +++- src/slang-nodes/ImportDirective.js | 7 +- .../__snapshots__/jsfmt.spec.js.snap | 8 +- tests/format/BasicIterator/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 155 ++++++++++++++++++ .../BreakingChangesV0.7.4/jsfmt.spec.js | 14 ++ 10 files changed, 219 insertions(+), 17 deletions(-) diff --git a/src/slang-nodes/FunctionDefinition.js b/src/slang-nodes/FunctionDefinition.js index 22df03780..63057de15 100644 --- a/src/slang-nodes/FunctionDefinition.js +++ b/src/slang-nodes/FunctionDefinition.js @@ -21,8 +21,7 @@ export const FunctionDefinition = { indent( group([ path.call(print, 'attributes'), - line, - node.returns ? path.call(print, 'returns') : '', + node.returns ? [line, path.call(print, 'returns')] : '', dedent(line) ]) ) diff --git a/src/slang-nodes/ImportAlias.js b/src/slang-nodes/ImportAlias.js index b1100b25a..747928c48 100644 --- a/src/slang-nodes/ImportAlias.js +++ b/src/slang-nodes/ImportAlias.js @@ -4,6 +4,5 @@ export const ImportAlias = { asKeyword: ast.asKeyword.text, identifier: ast.identifier.text }), - // TODO: implement print - print: () => ['TODO: ImportAlias'] + print: ({ node }) => ` ${node.asKeyword} ${node.identifier}` }; diff --git a/src/slang-nodes/ImportDeconstruction.js b/src/slang-nodes/ImportDeconstruction.js index d654179df..7112065da 100644 --- a/src/slang-nodes/ImportDeconstruction.js +++ b/src/slang-nodes/ImportDeconstruction.js @@ -7,6 +7,10 @@ export const ImportDeconstruction = { fromKeyword: ast.fromKeyword.text, path: parse(ast.path, options, parse) }), - // TODO: implement print - print: () => ['TODO: ImportDeconstruction'] + print: ({ node, path, print }) => [ + node.openBrace, + path.call(print, 'symbols'), + `${node.closeBrace} ${node.fromKeyword} `, + path.call(print, 'path') + ] }; diff --git a/src/slang-nodes/ImportDeconstructionSymbol.js b/src/slang-nodes/ImportDeconstructionSymbol.js index 1ccbf43d6..c826b4ceb 100644 --- a/src/slang-nodes/ImportDeconstructionSymbol.js +++ b/src/slang-nodes/ImportDeconstructionSymbol.js @@ -4,6 +4,8 @@ export const ImportDeconstructionSymbol = { name: ast.name.text, alias: ast.alias ? parse(ast.alias, options, parse) : undefined }), - // TODO: implement print - print: () => ['TODO: ImportDeconstructionSymbol'] + print: ({ node, path, print }) => [ + node.name, + node.alias ? path.call(print, 'alias') : '' + ] }; diff --git a/src/slang-nodes/ImportDeconstructionSymbols.js b/src/slang-nodes/ImportDeconstructionSymbols.js index 06b9665e7..406060581 100644 --- a/src/slang-nodes/ImportDeconstructionSymbols.js +++ b/src/slang-nodes/ImportDeconstructionSymbols.js @@ -1,9 +1,35 @@ +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'; + +const { line, softline } = doc.builders; + export const ImportDeconstructionSymbols = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), - // TODO: implement print - print: () => ['TODO: ImportDeconstructionSymbols'] + print: ({ path, print, options }) => { + const compiler = coerce(options.compiler); + let firstSeparator; + let separator; + + if (compiler && satisfies(compiler, '>=0.7.4')) { + // if the compiler exists and is greater than or equal to 0.7.4 we will + // split the ImportDirective. + firstSeparator = options.bracketSpacing ? line : softline; + separator = [',', line]; + } else { + // if the compiler is not given or is lower than 0.7.4 we will not + // split the ImportDirective. + firstSeparator = options.bracketSpacing ? ' ' : ''; + separator = ', '; + } + return printSeparatedList(path.map(print, 'items'), { + firstSeparator, + separator + }); + } }; diff --git a/src/slang-nodes/ImportDirective.js b/src/slang-nodes/ImportDirective.js index 725494eed..19fcb6af5 100644 --- a/src/slang-nodes/ImportDirective.js +++ b/src/slang-nodes/ImportDirective.js @@ -5,6 +5,9 @@ export const ImportDirective = { clause: parse(ast.clause, options, parse), semicolon: ast.semicolon.text }), - // TODO: implement print - print: () => ['TODO: ImportDirective'] + print: ({ node, path, print }) => [ + `${node.importKeyword} `, + path.call(print, 'clause'), + node.semicolon + ] }; diff --git a/tests/format/BasicIterator/__snapshots__/jsfmt.spec.js.snap b/tests/format/BasicIterator/__snapshots__/jsfmt.spec.js.snap index d6d8db622..afaaaf11e 100644 --- a/tests/format/BasicIterator/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/BasicIterator/__snapshots__/jsfmt.spec.js.snap @@ -1,8 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`BasicIterator.sol - {"compiler":"0.4.11"} format 1`] = ` +exports[`BasicIterator.sol - {"compiler":"0.4.26"} format 1`] = ` ====================================options===================================== -compiler: "0.4.11" +compiler: "0.4.26" parsers: ["solidity-slang-parse"] printWidth: 80 | printWidth @@ -56,7 +56,7 @@ contract BasicIterator { contract BasicIterator { address creator; uint8[10] integers; - function BasicIterator() { + function BasicIterator() { creator = msg.sender; uint8 x = 0; while(x < integers.length){ @@ -73,7 +73,7 @@ contract BasicIterator { } return sum; } - function kill() { + function kill() { if(msg.sender == creator){ suicide(creator); } diff --git a/tests/format/BasicIterator/jsfmt.spec.js b/tests/format/BasicIterator/jsfmt.spec.js index 57f8f2948..18602c4e5 100644 --- a/tests/format/BasicIterator/jsfmt.spec.js +++ b/tests/format/BasicIterator/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse'], { compiler: '0.4.11' }); +run_spec(import.meta, ['solidity-slang-parse'], { compiler: '0.4.26' }); diff --git a/tests/format/BreakingChangesV0.7.4/__snapshots__/jsfmt.spec.js.snap b/tests/format/BreakingChangesV0.7.4/__snapshots__/jsfmt.spec.js.snap index bf7c7307e..b4f8f1a4d 100644 --- a/tests/format/BreakingChangesV0.7.4/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/BreakingChangesV0.7.4/__snapshots__/jsfmt.spec.js.snap @@ -31,6 +31,30 @@ import { symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4 } from ================================================================================ `; +exports[`BreakingChangesV0.7.4.sol - {"bracketSpacing":true} format 2`] = ` +====================================options===================================== +bracketSpacing: true +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity ^0.7.0; + +/** + * - if options.compiler is undefined we won't break the ImportDirective. + * - if options.compiler is lower than 0.7.4 we won't break the ImportDirective. + * - if options.compiler is greater than or equal to 0.7.4 we will break the + * ImportDirective if the line length exceeds the printWidth. + */ +import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol"; + +=====================================output===================================== +pragma solidity ^0.7.0; +import { symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4 } from "File2.sol"; + +================================================================================ +`; + exports[`BreakingChangesV0.7.4.sol - {"compiler":"0.7.3","bracketSpacing":true} format 1`] = ` ====================================options===================================== bracketSpacing: true @@ -63,6 +87,31 @@ import { symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4 } from ================================================================================ `; +exports[`BreakingChangesV0.7.4.sol - {"compiler":"0.7.3","bracketSpacing":true} format 2`] = ` +====================================options===================================== +bracketSpacing: true +compiler: "0.7.3" +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity ^0.7.0; + +/** + * - if options.compiler is undefined we won't break the ImportDirective. + * - if options.compiler is lower than 0.7.4 we won't break the ImportDirective. + * - if options.compiler is greater than or equal to 0.7.4 we will break the + * ImportDirective if the line length exceeds the printWidth. + */ +import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol"; + +=====================================output===================================== +pragma solidity ^0.7.0; +import { symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4 } from "File2.sol"; + +================================================================================ +`; + exports[`BreakingChangesV0.7.4.sol - {"compiler":"0.7.3"} format 1`] = ` ====================================options===================================== compiler: "0.7.3" @@ -94,6 +143,30 @@ import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from " ================================================================================ `; +exports[`BreakingChangesV0.7.4.sol - {"compiler":"0.7.3"} format 2`] = ` +====================================options===================================== +compiler: "0.7.3" +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity ^0.7.0; + +/** + * - if options.compiler is undefined we won't break the ImportDirective. + * - if options.compiler is lower than 0.7.4 we won't break the ImportDirective. + * - if options.compiler is greater than or equal to 0.7.4 we will break the + * ImportDirective if the line length exceeds the printWidth. + */ +import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol"; + +=====================================output===================================== +pragma solidity ^0.7.0; +import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol"; + +================================================================================ +`; + exports[`BreakingChangesV0.7.4.sol - {"compiler":"0.7.4","bracketSpacing":true} format 1`] = ` ====================================options===================================== bracketSpacing: true @@ -131,6 +204,36 @@ import { ================================================================================ `; +exports[`BreakingChangesV0.7.4.sol - {"compiler":"0.7.4","bracketSpacing":true} format 2`] = ` +====================================options===================================== +bracketSpacing: true +compiler: "0.7.4" +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity ^0.7.0; + +/** + * - if options.compiler is undefined we won't break the ImportDirective. + * - if options.compiler is lower than 0.7.4 we won't break the ImportDirective. + * - if options.compiler is greater than or equal to 0.7.4 we will break the + * ImportDirective if the line length exceeds the printWidth. + */ +import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol"; + +=====================================output===================================== +pragma solidity ^0.7.0; +import { + symbol1 as alias1, + symbol2 as alias2, + symbol3 as alias3, + symbol4 +} from "File2.sol"; + +================================================================================ +`; + exports[`BreakingChangesV0.7.4.sol - {"compiler":"0.7.4"} format 1`] = ` ====================================options===================================== compiler: "0.7.4" @@ -167,6 +270,35 @@ import { ================================================================================ `; +exports[`BreakingChangesV0.7.4.sol - {"compiler":"0.7.4"} format 2`] = ` +====================================options===================================== +compiler: "0.7.4" +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity ^0.7.0; + +/** + * - if options.compiler is undefined we won't break the ImportDirective. + * - if options.compiler is lower than 0.7.4 we won't break the ImportDirective. + * - if options.compiler is greater than or equal to 0.7.4 we will break the + * ImportDirective if the line length exceeds the printWidth. + */ +import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol"; + +=====================================output===================================== +pragma solidity ^0.7.0; +import { + symbol1 as alias1, + symbol2 as alias2, + symbol3 as alias3, + symbol4 +} from "File2.sol"; + +================================================================================ +`; + exports[`BreakingChangesV0.7.4.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] @@ -196,3 +328,26 @@ import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from " ================================================================================ `; + +exports[`BreakingChangesV0.7.4.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity ^0.7.0; + +/** + * - if options.compiler is undefined we won't break the ImportDirective. + * - if options.compiler is lower than 0.7.4 we won't break the ImportDirective. + * - if options.compiler is greater than or equal to 0.7.4 we will break the + * ImportDirective if the line length exceeds the printWidth. + */ +import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol"; + +=====================================output===================================== +pragma solidity ^0.7.0; +import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol"; + +================================================================================ +`; diff --git a/tests/format/BreakingChangesV0.7.4/jsfmt.spec.js b/tests/format/BreakingChangesV0.7.4/jsfmt.spec.js index b64637462..859b8b539 100644 --- a/tests/format/BreakingChangesV0.7.4/jsfmt.spec.js +++ b/tests/format/BreakingChangesV0.7.4/jsfmt.spec.js @@ -12,3 +12,17 @@ run_spec(import.meta, ['solidity-parse']); run_spec(import.meta, ['solidity-parse'], { bracketSpacing: true }); +run_spec(import.meta, ['solidity-slang-parse'], { compiler: '0.7.4' }); +run_spec(import.meta, ['solidity-slang-parse'], { + compiler: '0.7.4', + bracketSpacing: true +}); +run_spec(import.meta, ['solidity-slang-parse'], { compiler: '0.7.3' }); +run_spec(import.meta, ['solidity-slang-parse'], { + compiler: '0.7.3', + bracketSpacing: true +}); +run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['solidity-slang-parse'], { + bracketSpacing: true +}); From b48c8a2588b1e70897f305832b310bd0c4b81a76 Mon Sep 17 00:00:00 2001 From: Klaus Date: Mon, 27 May 2024 17:40:48 +1200 Subject: [PATCH 011/160] WIP: 131/210 printers implemented --- src/slang-nodes/EmitStatement.js | 8 +- src/slang-nodes/EventDefinition.js | 8 +- src/slang-nodes/EventParameter.js | 7 +- src/slang-nodes/EventParameters.js | 8 +- src/slang-nodes/EventParametersDeclaration.js | 7 +- src/slang-nodes/ExponentiationExpression.js | 7 +- src/slang-nodes/PositionalArguments.js | 4 +- src/slang-nodes/ReturnStatement.js | 2 +- src/slang-nodes/StateVariableAttributes.js | 2 +- src/slang-nodes/StateVariableDefinition.js | 4 +- src/slang-nodes/StructDefinition.js | 7 +- src/slang-nodes/StructMember.js | 6 +- src/slang-nodes/StructMembers.js | 14 ++- src/slang-nodes/TupleValues.js | 9 +- .../Arrays/__snapshots__/jsfmt.spec.js.snap | 11 ++- .../__snapshots__/jsfmt.spec.js.snap | 4 +- .../BreakingChangesV0.8.0.sol | 4 +- .../__snapshots__/jsfmt.spec.js.snap | 95 +++++++++++++++++-- .../BreakingChangesV0.8.0/jsfmt.spec.js | 1 + 19 files changed, 164 insertions(+), 44 deletions(-) diff --git a/src/slang-nodes/EmitStatement.js b/src/slang-nodes/EmitStatement.js index 66143b240..d6495b6c4 100644 --- a/src/slang-nodes/EmitStatement.js +++ b/src/slang-nodes/EmitStatement.js @@ -6,6 +6,10 @@ export const EmitStatement = { arguments: parse(ast.arguments, options, parse), semicolon: ast.semicolon.text }), - // TODO: implement print - print: () => ['TODO: EmitStatement'] + print: ({ node, path, print }) => [ + `${node.emitKeyword} `, + path.call(print, 'event'), + path.call(print, 'arguments'), + node.semicolon + ] }; diff --git a/src/slang-nodes/EventDefinition.js b/src/slang-nodes/EventDefinition.js index f756a2cee..cae5de51e 100644 --- a/src/slang-nodes/EventDefinition.js +++ b/src/slang-nodes/EventDefinition.js @@ -7,6 +7,10 @@ export const EventDefinition = { anonymousKeyword: ast.anonymousKeyword?.text, semicolon: ast.semicolon.text }), - // TODO: implement print - print: () => ['TODO: EventDefinition'] + print: ({ node, path, print }) => [ + `${node.eventKeyword} ${node.name}`, + path.call(print, 'parameters'), + node.anonymousKeyword ? ` ${node.anonymousKeyword}` : '', + node.semicolon + ] }; diff --git a/src/slang-nodes/EventParameter.js b/src/slang-nodes/EventParameter.js index eb81474e0..326514f9a 100644 --- a/src/slang-nodes/EventParameter.js +++ b/src/slang-nodes/EventParameter.js @@ -5,6 +5,9 @@ export const EventParameter = { indexedKeyword: ast.indexedKeyword?.text, name: ast.name?.text }), - // TODO: implement print - print: () => ['TODO: EventParameter'] + print: ({ node, path, print }) => [ + path.call(print, 'typeName'), + node.indexedKeyword ? ` ${node.indexedKeyword}` : '', + node.name ? ` ${node.name}` : '' + ] }; diff --git a/src/slang-nodes/EventParameters.js b/src/slang-nodes/EventParameters.js index aea0439ba..154bd4f37 100644 --- a/src/slang-nodes/EventParameters.js +++ b/src/slang-nodes/EventParameters.js @@ -1,9 +1,11 @@ +import { printSeparatedList } from '../common/printer-helpers.js'; + export const EventParameters = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, - items: ast.items.map((item) => parse(item.text, options, parse)), + items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), - // TODO: implement print - print: () => ['TODO: EventParameters'] + print: ({ node, path, print }) => + node.items?.length > 0 ? printSeparatedList(path.map(print, 'items')) : '' }; diff --git a/src/slang-nodes/EventParametersDeclaration.js b/src/slang-nodes/EventParametersDeclaration.js index a307765f9..d61a026e5 100644 --- a/src/slang-nodes/EventParametersDeclaration.js +++ b/src/slang-nodes/EventParametersDeclaration.js @@ -5,6 +5,9 @@ export const EventParametersDeclaration = { parameters: parse(ast.parameters, options, parse), closeParen: ast.closeParen.text }), - // TODO: implement print - print: () => ['TODO: EventParametersDeclaration'] + print: ({ node, path, print }) => [ + node.openParen, + path.call(print, 'parameters'), + node.closeParen + ] }; diff --git a/src/slang-nodes/ExponentiationExpression.js b/src/slang-nodes/ExponentiationExpression.js index 903b17c1a..6306b06bc 100644 --- a/src/slang-nodes/ExponentiationExpression.js +++ b/src/slang-nodes/ExponentiationExpression.js @@ -5,6 +5,9 @@ export const ExponentiationExpression = { operator: ast.operator.text, rightOperand: parse(ast.rightOperand, options, parse) }), - // TODO: implement print - print: () => ['TODO: ExponentiationExpression'] + print: ({ node, path, print }) => [ + path.call(print, 'leftOperand'), + node.operator, + path.call(print, 'rightOperand') + ] }; diff --git a/src/slang-nodes/PositionalArguments.js b/src/slang-nodes/PositionalArguments.js index ef698aebe..14df6043c 100644 --- a/src/slang-nodes/PositionalArguments.js +++ b/src/slang-nodes/PositionalArguments.js @@ -1,8 +1,10 @@ +import { printSeparatedList } from '../common/printer-helpers.js'; + export const PositionalArguments = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), - print: ({ path, print }) => path.map(print, 'items') + print: ({ path, print }) => printSeparatedList(path.map(print, 'items')) }; diff --git a/src/slang-nodes/ReturnStatement.js b/src/slang-nodes/ReturnStatement.js index 9643c85a3..38c3cf24e 100644 --- a/src/slang-nodes/ReturnStatement.js +++ b/src/slang-nodes/ReturnStatement.js @@ -9,7 +9,7 @@ export const ReturnStatement = { }), print: ({ node, path, print }) => [ node.returnKeyword, - node.expression ? ` ${path.call(print, 'expression')}` : '', + node.expression ? [' ', path.call(print, 'expression')] : '', node.semicolon ] }; diff --git a/src/slang-nodes/StateVariableAttributes.js b/src/slang-nodes/StateVariableAttributes.js index 6b6bc6c25..3816e97f0 100644 --- a/src/slang-nodes/StateVariableAttributes.js +++ b/src/slang-nodes/StateVariableAttributes.js @@ -4,5 +4,5 @@ export const StateVariableAttributes = { items: ast.items.map((item) => parse(item, options, parse)) }), print: ({ node, path, print }) => - node.items.length ? path.map(print, 'items') : '' + node.items.length ? [' ', path.map(print, 'items')] : '' }; diff --git a/src/slang-nodes/StateVariableDefinition.js b/src/slang-nodes/StateVariableDefinition.js index f819e6ee7..83ac00943 100644 --- a/src/slang-nodes/StateVariableDefinition.js +++ b/src/slang-nodes/StateVariableDefinition.js @@ -9,10 +9,8 @@ export const StateVariableDefinition = { }), print: ({ node, path, print }) => [ path.call(print, 'typeName'), - ' ', path.call(print, 'attributes'), - ' ', - node.name, + ` ${node.name}`, node.value ? path.call(print, 'value') : '', node.semicolon ] diff --git a/src/slang-nodes/StructDefinition.js b/src/slang-nodes/StructDefinition.js index c074b2eec..f81342596 100644 --- a/src/slang-nodes/StructDefinition.js +++ b/src/slang-nodes/StructDefinition.js @@ -7,6 +7,9 @@ export const StructDefinition = { members: parse(ast.members, options, parse), closeBrace: ast.closeBrace.text }), - // TODO: implement print - print: () => ['TODO: StructDefinition'] + print: ({ node, path, print }) => [ + `${node.structKeyword} ${node.name} ${node.openBrace}`, + path.call(print, 'members'), + node.closeBrace + ] }; diff --git a/src/slang-nodes/StructMember.js b/src/slang-nodes/StructMember.js index 265bf7101..43aa57cbc 100644 --- a/src/slang-nodes/StructMember.js +++ b/src/slang-nodes/StructMember.js @@ -5,6 +5,8 @@ export const StructMember = { name: ast.name.text, semicolon: ast.semicolon.text }), - // TODO: implement print - print: () => ['TODO: StructMember'] + print: ({ node, path, print }) => [ + path.call(print, 'typeName'), + ` ${node.name}${node.semicolon}` + ] }; diff --git a/src/slang-nodes/StructMembers.js b/src/slang-nodes/StructMembers.js index 0d71f3d1b..4b0d5c6c5 100644 --- a/src/slang-nodes/StructMembers.js +++ b/src/slang-nodes/StructMembers.js @@ -1,8 +1,18 @@ +import { doc } from 'prettier'; +import { printSeparatedList } from '../common/printer-helpers.js'; + +const { hardline } = doc.builders; + export const StructMembers = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), - // TODO: implement print - print: () => ['TODO: StructMembers'] + print: ({ node, path, print }) => + node.items.length > 0 + ? printSeparatedList(path.map(print, 'items'), { + firstSeparator: hardline, + separator: hardline + }) + : '' }; diff --git a/src/slang-nodes/TupleValues.js b/src/slang-nodes/TupleValues.js index 8ace8acb7..f96805818 100644 --- a/src/slang-nodes/TupleValues.js +++ b/src/slang-nodes/TupleValues.js @@ -1,13 +1,10 @@ +import { printSeparatedList } from '../common/printer-helpers.js'; + export const TupleValues = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), - print: ({ node, path, print }) => - path - .map(print, 'items') - .map((item, index) => - index === 0 ? item : [node.separators[index - 1], item] - ) + print: ({ path, print }) => printSeparatedList(path.map(print, 'items')) }; diff --git a/tests/format/Arrays/__snapshots__/jsfmt.spec.js.snap b/tests/format/Arrays/__snapshots__/jsfmt.spec.js.snap index 84dd53f60..266fa4f35 100644 --- a/tests/format/Arrays/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Arrays/__snapshots__/jsfmt.spec.js.snap @@ -104,14 +104,17 @@ contract Arrays { bytes32("removePermissionFromGroup") ]; function a() { - Outcome.OutcomeItem[] memory outcomeFrom = abi.decode(fromPart.outcome(Outcome.OutcomeItem[])); + Outcome.OutcomeItem[] memory outcomeFrom = abi.decode( + fromPart.outcome, + (Outcome.OutcomeItem[]) + ); } } contract ArraySlices { function f(bytes calldata x) public { - bytes memory a1 = abi.decode(x[:](bytes)); - bytes4 a2 = abi.decode(x[:4](bytes4)); - address a3 = abi.decode(x[4:](address)); + bytes memory a1 = abi.decode(x[:], (bytes)); + bytes4 a2 = abi.decode(x[:4], (bytes4)); + address a3 = abi.decode(x[4:], (address)); } } diff --git a/tests/format/BasicIterator/__snapshots__/jsfmt.spec.js.snap b/tests/format/BasicIterator/__snapshots__/jsfmt.spec.js.snap index afaaaf11e..6ea0ee252 100644 --- a/tests/format/BasicIterator/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/BasicIterator/__snapshots__/jsfmt.spec.js.snap @@ -54,8 +54,8 @@ contract BasicIterator { =====================================output===================================== contract BasicIterator { - address creator; - uint8[10] integers; + address creator; + uint8[10] integers; function BasicIterator() { creator = msg.sender; uint8 x = 0; diff --git a/tests/format/BreakingChangesV0.8.0/BreakingChangesV0.8.0.sol b/tests/format/BreakingChangesV0.8.0/BreakingChangesV0.8.0.sol index 951bd447d..e5f6c1fb3 100644 --- a/tests/format/BreakingChangesV0.8.0/BreakingChangesV0.8.0.sol +++ b/tests/format/BreakingChangesV0.8.0/BreakingChangesV0.8.0.sol @@ -1,5 +1,7 @@ // SPDX-License-Identifier: MIT -pragma solidity >=0.7.0 <=0.8.5; +// TODO: uncomment once NomicFoundation addresses Semver notations +// https://github.com/NomicFoundation/slang/issues/986 +// pragma solidity >=0.7.0 <=0.8.5; contract BreakingChangesV080 { /** diff --git a/tests/format/BreakingChangesV0.8.0/__snapshots__/jsfmt.spec.js.snap b/tests/format/BreakingChangesV0.8.0/__snapshots__/jsfmt.spec.js.snap index 20c0d3f21..e44a22f8e 100644 --- a/tests/format/BreakingChangesV0.8.0/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/BreakingChangesV0.8.0/__snapshots__/jsfmt.spec.js.snap @@ -8,7 +8,9 @@ printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -pragma solidity >=0.7.0 <=0.8.5; +// TODO: uncomment once NomicFoundation addresses Semver notations +// https://github.com/NomicFoundation/slang/issues/986 +// pragma solidity >=0.7.0 <=0.8.5; contract BreakingChangesV080 { /** @@ -52,7 +54,9 @@ contract BreakingChangesV080 { =====================================output===================================== // SPDX-License-Identifier: MIT -pragma solidity >=0.7.0 <=0.8.5; +// TODO: uncomment once NomicFoundation addresses Semver notations +// https://github.com/NomicFoundation/slang/issues/986 +// pragma solidity >=0.7.0 <=0.8.5; contract BreakingChangesV080 { /** @@ -88,6 +92,77 @@ contract BreakingChangesV080 { ================================================================================ `; +exports[`BreakingChangesV0.8.0.sol - {"compiler":"0.7.0"} format 2`] = ` +====================================options===================================== +compiler: "0.7.0" +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +// SPDX-License-Identifier: MIT +// TODO: uncomment once NomicFoundation addresses Semver notations +// https://github.com/NomicFoundation/slang/issues/986 +// pragma solidity >=0.7.0 <=0.8.5; + +contract BreakingChangesV080 { + /** + * - if options.compiler is undefined we leave 1**2**3. + * - if options.compiler is lower than 0.8.0 we format as (1**2)**3. + * - if options.compiler is greater than or equal to 0.8.0 we format as + * 1**(2**3). + */ + uint a = 1**2**3; + + /** + * - if options.compiler is undefined or lower than 0.8.0 we enforce the + * use of bytes1. + * - if options.compiler is greater than or equal to 0.8.0 we enforce the + * use of bytes1. + */ + bytes1 public c; + byte public g; + + struct S { + bytes1 c; + byte g; + } + + event Event(bytes1 _c, byte _g); + + function func( + bytes1 _c, + byte _g + ) + public + returns ( + bytes1, + byte + ) + { + emit Event(_c, _g); + return (_c, _g); + } +} + +=====================================output===================================== +contract BreakingChangesV080 { + uint a = 1**2**3; + bytes1 public c; + byte public g; + struct S { + bytes1 c; + byte g; + } + event Event(bytes1 _c, byte _g); + function func(bytes1 _c, byte _g) public returns (bytes1, byte) { + emit Event(_c, _g); + return (_c, _g); + } +} + +================================================================================ +`; + exports[`BreakingChangesV0.8.0.sol - {"compiler":"0.8.0"} format 1`] = ` ====================================options===================================== compiler: "0.8.0" @@ -96,7 +171,9 @@ printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -pragma solidity >=0.7.0 <=0.8.5; +// TODO: uncomment once NomicFoundation addresses Semver notations +// https://github.com/NomicFoundation/slang/issues/986 +// pragma solidity >=0.7.0 <=0.8.5; contract BreakingChangesV080 { /** @@ -140,7 +217,9 @@ contract BreakingChangesV080 { =====================================output===================================== // SPDX-License-Identifier: MIT -pragma solidity >=0.7.0 <=0.8.5; +// TODO: uncomment once NomicFoundation addresses Semver notations +// https://github.com/NomicFoundation/slang/issues/986 +// pragma solidity >=0.7.0 <=0.8.5; contract BreakingChangesV080 { /** @@ -183,7 +262,9 @@ printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -pragma solidity >=0.7.0 <=0.8.5; +// TODO: uncomment once NomicFoundation addresses Semver notations +// https://github.com/NomicFoundation/slang/issues/986 +// pragma solidity >=0.7.0 <=0.8.5; contract BreakingChangesV080 { /** @@ -227,7 +308,9 @@ contract BreakingChangesV080 { =====================================output===================================== // SPDX-License-Identifier: MIT -pragma solidity >=0.7.0 <=0.8.5; +// TODO: uncomment once NomicFoundation addresses Semver notations +// https://github.com/NomicFoundation/slang/issues/986 +// pragma solidity >=0.7.0 <=0.8.5; contract BreakingChangesV080 { /** diff --git a/tests/format/BreakingChangesV0.8.0/jsfmt.spec.js b/tests/format/BreakingChangesV0.8.0/jsfmt.spec.js index 037d673ba..b65e9287f 100644 --- a/tests/format/BreakingChangesV0.8.0/jsfmt.spec.js +++ b/tests/format/BreakingChangesV0.8.0/jsfmt.spec.js @@ -1,3 +1,4 @@ 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' }); +run_spec(import.meta, ['solidity-slang-parse'], { compiler: '0.7.0' }); From 1a6b077600c6411e173cee1c7e9629c066b37f3f Mon Sep 17 00:00:00 2001 From: Klaus Date: Mon, 27 May 2024 20:10:48 +1200 Subject: [PATCH 012/160] WIP: 145/210 printers implemented --- src/slang-nodes/ConditionalExpression.js | 18 ++++- src/slang-nodes/ConstructorAttributes.js | 8 ++- src/slang-nodes/ConstructorDefinition.js | 14 +++- src/slang-nodes/EnumDefinition.js | 7 +- src/slang-nodes/EnumMembers.js | 11 ++- src/slang-nodes/ErrorDefinition.js | 7 +- src/slang-nodes/ErrorParameter.js | 6 +- src/slang-nodes/ErrorParameters.js | 8 ++- src/slang-nodes/ErrorParametersDeclaration.js | 7 +- src/slang-nodes/EventParameters.js | 2 +- src/slang-nodes/InheritanceSpecifier.js | 6 +- src/slang-nodes/InheritanceType.js | 6 +- src/slang-nodes/InheritanceTypes.js | 12 +++- src/slang-nodes/ModifierInvocation.js | 6 +- src/slang-nodes/RevertStatement.js | 8 ++- src/slangParser.js | 4 +- .../__snapshots__/jsfmt.spec.js.snap | 72 +++++++++++++++++++ tests/format/Conditional/jsfmt.spec.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 52 ++++++++++++++ tests/format/Constructors/jsfmt.spec.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 21 ++++++ .../format/ContractDefinitions/jsfmt.spec.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 46 ++++++++++++ tests/format/CustomErrors/jsfmt.spec.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 7 +- tests/format/EnumDefinitions/jsfmt.spec.js | 2 +- 26 files changed, 296 insertions(+), 38 deletions(-) diff --git a/src/slang-nodes/ConditionalExpression.js b/src/slang-nodes/ConditionalExpression.js index f3131df89..291474f30 100644 --- a/src/slang-nodes/ConditionalExpression.js +++ b/src/slang-nodes/ConditionalExpression.js @@ -1,3 +1,7 @@ +import { doc } from 'prettier'; + +const { group, indent, line } = doc.builders; + export const ConditionalExpression = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, @@ -7,6 +11,16 @@ export const ConditionalExpression = { colon: ast.colon.text, falseExpression: parse(ast.falseExpression, options, parse) }), - // TODO: implement print - print: () => ['TODO: ConditionalExpression'] + print: ({ node, path, print }) => + group([ + path.call(print, 'operand'), + indent([ + line, + `${node.questionMark} `, + path.call(print, 'trueExpression'), + line, + `${node.colon} `, + path.call(print, 'falseExpression') + ]) + ]) }; diff --git a/src/slang-nodes/ConstructorAttributes.js b/src/slang-nodes/ConstructorAttributes.js index b314f8f01..bdb470f55 100644 --- a/src/slang-nodes/ConstructorAttributes.js +++ b/src/slang-nodes/ConstructorAttributes.js @@ -1,8 +1,12 @@ +import { doc } from 'prettier'; + +const { line } = doc.builders; + export const ConstructorAttributes = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), - // TODO: implement print - print: () => ['TODO: ConstructorAttributes'] + print: ({ path, print }) => + path.map(print, 'items').map((item) => [line, item]) }; diff --git a/src/slang-nodes/ConstructorDefinition.js b/src/slang-nodes/ConstructorDefinition.js index 372eaef46..4c4a04b52 100644 --- a/src/slang-nodes/ConstructorDefinition.js +++ b/src/slang-nodes/ConstructorDefinition.js @@ -1,3 +1,7 @@ +import { doc } from 'prettier'; + +const { dedent, group, indent, line } = doc.builders; + export const ConstructorDefinition = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, @@ -6,6 +10,12 @@ export const ConstructorDefinition = { attributes: parse(ast.attributes, options, parse), body: parse(ast.body, options, parse) }), - // TODO: implement print - print: () => ['TODO: ConstructorDefinition'] + print: ({ node, path, print }) => [ + group([ + node.constructorKeyword, + path.call(print, 'parameters'), + indent(group([path.call(print, 'attributes'), dedent(line)])) + ]), + path.call(print, 'body') + ] }; diff --git a/src/slang-nodes/EnumDefinition.js b/src/slang-nodes/EnumDefinition.js index 336efde2c..31def03d2 100644 --- a/src/slang-nodes/EnumDefinition.js +++ b/src/slang-nodes/EnumDefinition.js @@ -7,6 +7,9 @@ export const EnumDefinition = { members: parse(ast.members, options, parse), closeBrace: ast.closeBrace.text }), - // TODO: implement print - print: () => ['TODO: EmitStatement'] + print: ({ node, path, print }) => [ + `${node.enumKeyword} ${node.name} ${node.openBrace}`, + path.call(print, 'members'), + node.closeBrace + ] }; diff --git a/src/slang-nodes/EnumMembers.js b/src/slang-nodes/EnumMembers.js index 484a625f9..1f015aff6 100644 --- a/src/slang-nodes/EnumMembers.js +++ b/src/slang-nodes/EnumMembers.js @@ -1,9 +1,16 @@ +import { doc } from 'prettier'; +import { printSeparatedList } from '../common/printer-helpers.js'; + +const { hardline } = doc.builders; + export const EnumMembers = { parse: ({ ast }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => item.text), separators: ast.separators.map((separator) => separator.text) }), - // TODO: implement print - print: () => ['TODO: EnumMembers'] + print: ({ node }) => + printSeparatedList(node.items, { + firstSeparator: hardline + }) }; diff --git a/src/slang-nodes/ErrorDefinition.js b/src/slang-nodes/ErrorDefinition.js index 9e11e744e..29ead464b 100644 --- a/src/slang-nodes/ErrorDefinition.js +++ b/src/slang-nodes/ErrorDefinition.js @@ -6,6 +6,9 @@ export const ErrorDefinition = { members: parse(ast.members, options, parse), semicolon: ast.semicolon.text }), - // TODO: implement print - print: () => ['TODO: ErrorDefinition'] + print: ({ node, path, print }) => [ + `${node.errorKeyword} ${node.name}`, + path.call(print, 'members'), + node.semicolon + ] }; diff --git a/src/slang-nodes/ErrorParameter.js b/src/slang-nodes/ErrorParameter.js index 8f6b3dcec..46ffc308e 100644 --- a/src/slang-nodes/ErrorParameter.js +++ b/src/slang-nodes/ErrorParameter.js @@ -4,6 +4,8 @@ export const ErrorParameter = { typeName: parse(ast.typeName, options, parse), name: ast.name?.text }), - // TODO: implement print - print: () => ['TODO: ErrorParameter'] + print: ({ node, path, print }) => [ + path.call(print, 'typeName'), + node.name ? ` ${node.name}` : '' + ] }; diff --git a/src/slang-nodes/ErrorParameters.js b/src/slang-nodes/ErrorParameters.js index 7847e4ef6..3a6e0be86 100644 --- a/src/slang-nodes/ErrorParameters.js +++ b/src/slang-nodes/ErrorParameters.js @@ -1,9 +1,11 @@ +import { printSeparatedList } from '../common/printer-helpers.js'; + export const ErrorParameters = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, - items: ast.items.map((item) => parse(item.text, options, parse)), + items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), - // TODO: implement print - print: () => ['TODO: ErrorParameters'] + print: ({ node, path, print }) => + node.items.length > 0 ? printSeparatedList(path.map(print, 'items')) : '' }; diff --git a/src/slang-nodes/ErrorParametersDeclaration.js b/src/slang-nodes/ErrorParametersDeclaration.js index d697e1b4c..a7f2d0f98 100644 --- a/src/slang-nodes/ErrorParametersDeclaration.js +++ b/src/slang-nodes/ErrorParametersDeclaration.js @@ -5,6 +5,9 @@ export const ErrorParametersDeclaration = { parameters: parse(ast.parameters, options, parse), closeParen: ast.closeParen.text }), - // TODO: implement print - print: () => ['TODO: ErrorParametersDeclaration'] + print: ({ node, path, print }) => [ + node.openParen, + path.call(print, 'parameters'), + node.closeParen + ] }; diff --git a/src/slang-nodes/EventParameters.js b/src/slang-nodes/EventParameters.js index 154bd4f37..479780999 100644 --- a/src/slang-nodes/EventParameters.js +++ b/src/slang-nodes/EventParameters.js @@ -7,5 +7,5 @@ export const EventParameters = { separators: ast.separators.map((separator) => separator.text) }), print: ({ node, path, print }) => - node.items?.length > 0 ? printSeparatedList(path.map(print, 'items')) : '' + node.items.length > 0 ? printSeparatedList(path.map(print, 'items')) : '' }; diff --git a/src/slang-nodes/InheritanceSpecifier.js b/src/slang-nodes/InheritanceSpecifier.js index eea85fc5c..1e0fccf9d 100644 --- a/src/slang-nodes/InheritanceSpecifier.js +++ b/src/slang-nodes/InheritanceSpecifier.js @@ -4,6 +4,8 @@ export const InheritanceSpecifier = { isKeyword: ast.isKeyword.text, types: parse(ast.types, options, parse) }), - // TODO: implement print - print: () => ['TODO: InheritanceSpecifier'] + print: ({ node, path, print }) => [ + ` ${node.isKeyword}`, + path.call(print, 'types') + ] }; diff --git a/src/slang-nodes/InheritanceType.js b/src/slang-nodes/InheritanceType.js index cbc3f0e96..3e6511222 100644 --- a/src/slang-nodes/InheritanceType.js +++ b/src/slang-nodes/InheritanceType.js @@ -4,6 +4,8 @@ export const InheritanceType = { typeName: parse(ast.typeName, options, parse), arguments: ast.arguments ? parse(ast.arguments, options, parse) : undefined }), - // TODO: implement print - print: () => ['TODO: InheritanceType'] + print: ({ node, path, print }) => [ + path.call(print, 'typeName'), + node.arguments ? path.call(print, 'arguments') : '' + ] }; diff --git a/src/slang-nodes/InheritanceTypes.js b/src/slang-nodes/InheritanceTypes.js index 11d381622..7245f6ad7 100644 --- a/src/slang-nodes/InheritanceTypes.js +++ b/src/slang-nodes/InheritanceTypes.js @@ -1,9 +1,15 @@ +import { doc } from 'prettier'; +import { printSeparatedList } from '../common/printer-helpers.js'; + +const { line } = doc.builders; export const InheritanceTypes = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, - items: ast.items.map((item) => parse(item.text, options, parse)), + items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), - // TODO: implement print - print: () => ['TODO: InheritanceTypes'] + print: ({ path, print }) => + printSeparatedList(path.map(print, 'items'), { + firstSeparator: line + }) }; diff --git a/src/slang-nodes/ModifierInvocation.js b/src/slang-nodes/ModifierInvocation.js index b8d62495d..c0d1ea518 100644 --- a/src/slang-nodes/ModifierInvocation.js +++ b/src/slang-nodes/ModifierInvocation.js @@ -4,6 +4,8 @@ export const ModifierInvocation = { name: parse(ast.name, options, parse), arguments: ast.arguments ? parse(ast.arguments, options, parse) : undefined }), - // TODO: implement print - print: () => ['TODO: ModifierInvocation'] + print: ({ node, path, print }) => [ + path.call(print, 'name'), + node.arguments ? path.call(print, 'arguments') : '' + ] }; diff --git a/src/slang-nodes/RevertStatement.js b/src/slang-nodes/RevertStatement.js index 0338bc34e..b6aa8e407 100644 --- a/src/slang-nodes/RevertStatement.js +++ b/src/slang-nodes/RevertStatement.js @@ -6,6 +6,10 @@ export const RevertStatement = { arguments: parse(ast.arguments, options, parse), semicolon: ast.semicolon.text }), - // TODO: implement print - print: () => ['TODO: RevertStatement'] + print: ({ node, path, print }) => [ + `${node.revertKeyword} `, + node.error ? path.call(print, 'error') : '', + path.call(print, 'arguments'), + node.semicolon + ] }; diff --git a/src/slangParser.js b/src/slangParser.js index 7ab59742f..687f5e252 100644 --- a/src/slangParser.js +++ b/src/slangParser.js @@ -12,8 +12,8 @@ function genericParse(ast, options, parseFunction) { function parse(text, _parsers, options = _parsers) { const compiler = coerce(options.compiler); - - const language = new Language( compiler?.version || '0.8.0'); + + const language = new Language(compiler?.version || '0.8.25'); const parsed = new SourceUnit( language.parse(RuleKind.SourceUnit, text).tree() ); diff --git a/tests/format/Conditional/__snapshots__/jsfmt.spec.js.snap b/tests/format/Conditional/__snapshots__/jsfmt.spec.js.snap index e74eccfaf..5afe671f6 100644 --- a/tests/format/Conditional/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Conditional/__snapshots__/jsfmt.spec.js.snap @@ -78,3 +78,75 @@ contract Conditional { ================================================================================ `; + +exports[`Conditional.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity ^0.4.24; + + +contract Conditional { + function foo() { + address contextAddress = longAddress_ == address(0) ? msg.sender : currentContextAddress_; + asset == ETH + ? require(address(uint160(msg.sender)).send(quantity), "failed to transfer ether") // explicit casting to \`address payable\` + : transferTokensToAccountSecurely(Token(asset), quantity, msg.sender); + asset == ETH + ? true + : transferTokensToAccountSecurely(Token(asset), quantity, msg.sender); + asset == ETH + ? require(address(uint160(msg.sender)).send(quantity), "failed to transfer ether") + : false; + } + + // TODO: work with a break in the condition level. + // function foo() { + // address contextAddress = veryVeryVeryVeryVeryVeryVeryVeryVeryLongAddress_ == address(0) ? msg.sender : currentContextAddress_; + // } + + function bar() { + uint a = true ? 0 : 1; + } +} + +=====================================output===================================== +pragma solidity ^0.4.24; +contract Conditional { + function foo() { + address contextAddress = longAddress_ == address(0) + ? msg.sender + : currentContextAddress_; + asset == ETH + ? require( + address(uint160(msg.sender)).send(quantity), + "failed to transfer ether" + ) + : transferTokensToAccountSecurely( + Token(asset), + quantity, + msg.sender + ); + asset == ETH + ? true + : transferTokensToAccountSecurely( + Token(asset), + quantity, + msg.sender + ); + asset == ETH + ? require( + address(uint160(msg.sender)).send(quantity), + "failed to transfer ether" + ) + : false; + } + function bar() { + uint a = true ? 0 : 1; + } +} + +================================================================================ +`; diff --git a/tests/format/Conditional/jsfmt.spec.js b/tests/format/Conditional/jsfmt.spec.js index 765dd60a6..fd56c17bc 100644 --- a/tests/format/Conditional/jsfmt.spec.js +++ b/tests/format/Conditional/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse']); diff --git a/tests/format/Constructors/__snapshots__/jsfmt.spec.js.snap b/tests/format/Constructors/__snapshots__/jsfmt.spec.js.snap index 08733dfa7..eefe1fafa 100644 --- a/tests/format/Constructors/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Constructors/__snapshots__/jsfmt.spec.js.snap @@ -49,3 +49,55 @@ contract Constructors is Ownable, Changeable { ================================================================================ `; + +exports[`Constructors.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity ^0.5.2; + +contract Constructors is Ownable, Changeable { + function Constructors(variable1) public Changeable(variable1) Ownable() onlyOwner { + } + + constructor(variable1, variable2, variable3, variable4, variable5, variable6, variable7) public Changeable(variable1, variable2, variable3, variable4, variable5, variable6, variable7) Ownable() onlyOwner {} +} + +=====================================output===================================== +pragma solidity ^0.5.2; +contract Constructors is Ownable, Changeable { + function Constructors( + variable1 + ) public Changeable(variable1) Ownable() onlyOwner { + + } + constructor( + variable1, + variable2, + variable3, + variable4, + variable5, + variable6, + variable7 + ) + public + Changeable( + variable1, + variable2, + variable3, + variable4, + variable5, + variable6, + variable7 + ) + Ownable() + onlyOwner + { + + } +} + +================================================================================ +`; diff --git a/tests/format/Constructors/jsfmt.spec.js b/tests/format/Constructors/jsfmt.spec.js index 765dd60a6..fd56c17bc 100644 --- a/tests/format/Constructors/jsfmt.spec.js +++ b/tests/format/Constructors/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse']); diff --git a/tests/format/ContractDefinitions/__snapshots__/jsfmt.spec.js.snap b/tests/format/ContractDefinitions/__snapshots__/jsfmt.spec.js.snap index 1621683a4..28542f7ea 100644 --- a/tests/format/ContractDefinitions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/ContractDefinitions/__snapshots__/jsfmt.spec.js.snap @@ -20,3 +20,24 @@ contract ContractDefinition is ================================================================================ `; + +exports[`ContractDefinitions.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +contract ContractDefinition is Contract1, Contract2, Contract3, Contract4, Contract5 { +} + +=====================================output===================================== +contract ContractDefinition is + Contract1, + Contract2, + Contract3, + Contract4, + Contract5 +{} + +================================================================================ +`; diff --git a/tests/format/ContractDefinitions/jsfmt.spec.js b/tests/format/ContractDefinitions/jsfmt.spec.js index 765dd60a6..fd56c17bc 100644 --- a/tests/format/ContractDefinitions/jsfmt.spec.js +++ b/tests/format/ContractDefinitions/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse']); diff --git a/tests/format/CustomErrors/__snapshots__/jsfmt.spec.js.snap b/tests/format/CustomErrors/__snapshots__/jsfmt.spec.js.snap index 85f94cb7f..870679355 100644 --- a/tests/format/CustomErrors/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/CustomErrors/__snapshots__/jsfmt.spec.js.snap @@ -48,3 +48,49 @@ contract CustomErrors { ================================================================================ `; + +exports[`CustomErrors.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity ^0.8.4; + +error + TopLevelCustomError(); + error TopLevelCustomErrorWithArg(uint x) ; +error TopLevelCustomErrorArgWithoutName (string); + +contract CustomErrors { + error + ContractCustomError(); + error ContractCustomErrorWithArg(uint x) ; + error ContractCustomErrorArgWithoutName (string); + + function throwCustomError() { + revert + FunctionCustomError(); + revert FunctionCustomErrorWithArg( 1 ) ; + revert FunctionCustomErrorArgWithoutName ( "a reason"); + } +} + +=====================================output===================================== +pragma solidity ^0.8.4; +error TopLevelCustomError(); +error TopLevelCustomErrorWithArg(uint x); +error TopLevelCustomErrorArgWithoutName(string); +contract CustomErrors { + error ContractCustomError(); + error ContractCustomErrorWithArg(uint x); + error ContractCustomErrorArgWithoutName(string); + function throwCustomError() { + revert FunctionCustomError(); + revert FunctionCustomErrorWithArg(1); + revert FunctionCustomErrorArgWithoutName("a reason"); + } +} + +================================================================================ +`; diff --git a/tests/format/CustomErrors/jsfmt.spec.js b/tests/format/CustomErrors/jsfmt.spec.js index 765dd60a6..fd56c17bc 100644 --- a/tests/format/CustomErrors/jsfmt.spec.js +++ b/tests/format/CustomErrors/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse']); diff --git a/tests/format/EnumDefinitions/__snapshots__/jsfmt.spec.js.snap b/tests/format/EnumDefinitions/__snapshots__/jsfmt.spec.js.snap index 580eeef8d..1f9043ea3 100644 --- a/tests/format/EnumDefinitions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/EnumDefinitions/__snapshots__/jsfmt.spec.js.snap @@ -1,8 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`EnumDefinitions.sol - {"bracketSpacing":true} format 1`] = ` +exports[`EnumDefinitions.sol format 1`] = ` ====================================options===================================== -bracketSpacing: true parsers: ["solidity-parse"] printWidth: 80 | printWidth @@ -36,9 +35,9 @@ contract EnumDefinitions { ================================================================================ `; -exports[`EnumDefinitions.sol format 1`] = ` +exports[`EnumDefinitions.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["solidity-slang-parse"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/EnumDefinitions/jsfmt.spec.js b/tests/format/EnumDefinitions/jsfmt.spec.js index 993a81764..fd56c17bc 100644 --- a/tests/format/EnumDefinitions/jsfmt.spec.js +++ b/tests/format/EnumDefinitions/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-parse'], { bracketSpacing: true }); +run_spec(import.meta, ['solidity-slang-parse']); From 7d63be00bec5c5d27bf74decda80c21e436775dd Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 29 May 2024 15:59:04 +1200 Subject: [PATCH 013/160] WIP: 159/210 printers implemented --- src/common/slang-helpers.js | 18 + src/slang-nodes/AndExpression.js | 9 +- src/slang-nodes/Block.js | 7 +- src/slang-nodes/ConstructorDefinition.js | 14 +- src/slang-nodes/ContractDefinition.js | 4 +- src/slang-nodes/ElseBranch.js | 15 +- src/slang-nodes/FallbackFunctionAttributes.js | 8 +- src/slang-nodes/FallbackFunctionDefinition.js | 6 +- src/slang-nodes/ForStatement.js | 26 +- src/slang-nodes/FunctionDefinition.js | 28 +- src/slang-nodes/HexStringLiteral.js | 6 +- src/slang-nodes/HexStringLiterals.js | 7 +- src/slang-nodes/IfStatement.js | 38 +- src/slang-nodes/InterfaceDefinition.js | 15 +- src/slang-nodes/InterfaceMembers.js | 20 +- src/slang-nodes/MultiplicativeExpression.js | 7 +- src/slang-nodes/OverrideSpecifier.js | 6 +- src/slang-nodes/ReceiveFunctionAttributes.js | 8 +- src/slang-nodes/ReceiveFunctionDefinition.js | 6 +- src/slang-nodes/Statements.js | 17 +- src/slang-nodes/UnnamedFunctionAttributes.js | 8 +- src/slang-nodes/UnnamedFunctionDefinition.js | 6 +- src/slang-nodes/VersionExpressionSet.js | 6 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 8 +- .../__snapshots__/jsfmt.spec.js.snap | 90 ++++ tests/format/ForStatements/jsfmt.spec.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 52 ++ tests/format/HexLiteral/jsfmt.spec.js | 8 + .../__snapshots__/jsfmt.spec.js.snap | 504 ++++++++++++++++++ tests/format/IfStatements/jsfmt.spec.js | 1 + 31 files changed, 861 insertions(+), 90 deletions(-) create mode 100644 src/common/slang-helpers.js diff --git a/src/common/slang-helpers.js b/src/common/slang-helpers.js new file mode 100644 index 000000000..a7f4220bf --- /dev/null +++ b/src/common/slang-helpers.js @@ -0,0 +1,18 @@ +import { doc } from 'prettier'; + +const { dedent, group, indent, line } = doc.builders; + +export const printFunction = (functionName, node, path, print) => [ + group([ + functionName, + path.call(print, 'parameters'), + indent( + group([ + path.call(print, 'attributes'), + node.returns ? [line, path.call(print, 'returns')] : '', + dedent(line) + ]) + ) + ]), + path.call(print, 'body') +]; diff --git a/src/slang-nodes/AndExpression.js b/src/slang-nodes/AndExpression.js index c0459f650..af2c8bae6 100644 --- a/src/slang-nodes/AndExpression.js +++ b/src/slang-nodes/AndExpression.js @@ -5,6 +5,11 @@ export const AndExpression = { operator: ast.operator.text, rightOperand: parse(ast.rightOperand, options, parse) }), - // TODO: implement print - print: () => ['TODO: AndExpression'] + print: ({ node, path, print }) => [ + path.call(print, 'leftOperand'), + ' ', + node.operator, + ' ', + path.call(print, 'rightOperand') + ] }; diff --git a/src/slang-nodes/Block.js b/src/slang-nodes/Block.js index 910ce6cab..19b247f9a 100644 --- a/src/slang-nodes/Block.js +++ b/src/slang-nodes/Block.js @@ -1,7 +1,3 @@ -import { doc } from 'prettier'; - -const { hardline, indent } = doc.builders; - export const Block = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, @@ -11,8 +7,7 @@ export const Block = { }), print: ({ node, path, print }) => [ node.openBrace, - indent([hardline, path.call(print, 'statements')]), - hardline, + path.call(print, 'statements'), node.closeBrace ] }; diff --git a/src/slang-nodes/ConstructorDefinition.js b/src/slang-nodes/ConstructorDefinition.js index 4c4a04b52..3585a63d1 100644 --- a/src/slang-nodes/ConstructorDefinition.js +++ b/src/slang-nodes/ConstructorDefinition.js @@ -1,6 +1,4 @@ -import { doc } from 'prettier'; - -const { dedent, group, indent, line } = doc.builders; +import { printFunction } from '../common/slang-helpers.js'; export const ConstructorDefinition = { parse: ({ ast, options, parse }) => ({ @@ -10,12 +8,6 @@ export const ConstructorDefinition = { attributes: parse(ast.attributes, options, parse), body: parse(ast.body, options, parse) }), - print: ({ node, path, print }) => [ - group([ - node.constructorKeyword, - path.call(print, 'parameters'), - indent(group([path.call(print, 'attributes'), dedent(line)])) - ]), - path.call(print, 'body') - ] + print: ({ node, path, print }) => + printFunction(node.constructorKeyword, node, path, print) }; diff --git a/src/slang-nodes/ContractDefinition.js b/src/slang-nodes/ContractDefinition.js index 9cf8f14d3..98f512398 100644 --- a/src/slang-nodes/ContractDefinition.js +++ b/src/slang-nodes/ContractDefinition.js @@ -18,9 +18,7 @@ export const ContractDefinition = { print: ({ node, path, print }) => [ group([ node.abstractKeyword ? `${node.abstractKeyword} ` : '', - node.contractKeyword, - ' ', - node.name, + `${node.contractKeyword} ${node.name}`, node.inheritance ? path.call(print, 'inheritance') : line, node.openBrace ]), diff --git a/src/slang-nodes/ElseBranch.js b/src/slang-nodes/ElseBranch.js index c98a2b0ab..c8bf62bb1 100644 --- a/src/slang-nodes/ElseBranch.js +++ b/src/slang-nodes/ElseBranch.js @@ -1,9 +1,20 @@ +import { doc } from 'prettier'; + +const { group, indent, line } = doc.builders; + +const printBody = (bodyVariantKind, path, print) => + bodyVariantKind === 'Block' || bodyVariantKind === 'IfStatement' + ? [' ', path.call(print, 'body')] + : group(indent([line, path.call(print, 'body')])); + export const ElseBranch = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, elseKeyword: ast.elseKeyword.text, body: parse(ast.body, options, parse) }), - // TODO: implement print - print: () => ['TODO: ElseBranch'] + print: ({ node, path, print }) => [ + node.elseKeyword, + printBody(node.body.variant.kind, path, print) + ] }; diff --git a/src/slang-nodes/FallbackFunctionAttributes.js b/src/slang-nodes/FallbackFunctionAttributes.js index e8575f40d..4279b5452 100644 --- a/src/slang-nodes/FallbackFunctionAttributes.js +++ b/src/slang-nodes/FallbackFunctionAttributes.js @@ -1,8 +1,12 @@ +import { doc } from 'prettier'; + +const { line } = doc.builders; + export const FallbackFunctionAttributes = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), - // TODO: implement print - print: () => ['TODO: FallbackFunctionAttributes'] + print: ({ path, print }) => + path.map(print, 'items').map((item) => [line, item]) }; diff --git a/src/slang-nodes/FallbackFunctionDefinition.js b/src/slang-nodes/FallbackFunctionDefinition.js index 5cbc60fe6..676fdee73 100644 --- a/src/slang-nodes/FallbackFunctionDefinition.js +++ b/src/slang-nodes/FallbackFunctionDefinition.js @@ -1,3 +1,5 @@ +import { printFunction } from '../common/slang-helpers.js'; + export const FallbackFunctionDefinition = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, @@ -7,6 +9,6 @@ export const FallbackFunctionDefinition = { returns: ast.returns ? parse(ast.returns, options, parse) : undefined, body: parse(ast.body, options, parse) }), - // TODO: implement print - print: () => ['TODO: FallbackFunctionDefinition'] + print: ({ node, path, print }) => + printFunction(node.fallbackKeyword, node, path, print) }; diff --git a/src/slang-nodes/ForStatement.js b/src/slang-nodes/ForStatement.js index 498dfe0b0..1f9594e9d 100644 --- a/src/slang-nodes/ForStatement.js +++ b/src/slang-nodes/ForStatement.js @@ -1,3 +1,8 @@ +import { doc } from 'prettier'; +import { printSeparatedList } from '../common/printer-helpers.js'; + +const { group, indent, line } = doc.builders; + export const ForStatement = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, @@ -9,6 +14,23 @@ export const ForStatement = { closeParen: ast.closeParen.text, body: parse(ast.body, options, parse) }), - // TODO: implement print - print: () => ['TODO: ForStatement'] + print: ({ node, path, print }) => { + const initialization = path.call(print, 'initialization'); + const condition = path.call(print, 'condition'); + const iterator = node.iterator ? path.call(print, 'iterator') : ''; + + return [ + `${node.forKeyword} ${node.openParen}`, + printSeparatedList([initialization, condition, iterator], { + separator: + initialization !== ';' || condition !== ';' || iterator !== '' + ? line + : '' + }), + node.closeParen, + node.body.variant.kind === 'Block' + ? [' ', path.call(print, 'body')] + : group(indent([line, path.call(print, 'body')])) + ]; + } }; diff --git a/src/slang-nodes/FunctionDefinition.js b/src/slang-nodes/FunctionDefinition.js index 63057de15..0f1b5fe2e 100644 --- a/src/slang-nodes/FunctionDefinition.js +++ b/src/slang-nodes/FunctionDefinition.js @@ -1,6 +1,4 @@ -import { doc } from 'prettier'; - -const { dedent, group, indent, line } = doc.builders; +import { printFunction } from '../common/slang-helpers.js'; export const FunctionDefinition = { parse: ({ ast, options, parse }) => ({ @@ -12,20 +10,12 @@ export const FunctionDefinition = { returns: ast.returns ? parse(ast.returns, options, parse) : undefined, body: parse(ast.body, options, parse) }), - print: ({ node, path, print }) => [ - group([ - node.functionKeyword, - ' ', - path.call(print, 'name'), - path.call(print, 'parameters'), - indent( - group([ - path.call(print, 'attributes'), - node.returns ? [line, path.call(print, 'returns')] : '', - dedent(line) - ]) - ) - ]), - path.call(print, 'body') - ] + + print: ({ node, path, print }) => + printFunction( + [`${node.functionKeyword} `, path.call(print, 'name')], + node, + path, + print + ) }; diff --git a/src/slang-nodes/HexStringLiteral.js b/src/slang-nodes/HexStringLiteral.js index 933ea6fd0..f6fe144d9 100644 --- a/src/slang-nodes/HexStringLiteral.js +++ b/src/slang-nodes/HexStringLiteral.js @@ -1,7 +1,9 @@ export const HexStringLiteral = { - parse: ({ ast }) => ({ + parse: ({ ast, options }) => ({ kind: ast.cst.kind, - variant: ast.variant.text + variant: options.singleQuote + ? `hex'${ast.variant.text.slice(4, -1)}'` + : `hex"${ast.variant.text.slice(4, -1)}"` }), print: ({ node }) => node.variant }; diff --git a/src/slang-nodes/HexStringLiterals.js b/src/slang-nodes/HexStringLiterals.js index 8f9a40028..27b4d5000 100644 --- a/src/slang-nodes/HexStringLiterals.js +++ b/src/slang-nodes/HexStringLiterals.js @@ -1,8 +1,11 @@ +import { doc } from 'prettier'; + +const { join, line } = doc.builders; + export const HexStringLiterals = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), - // TODO: implement print - print: () => ['TODO: HexStringLiterals'] + print: ({ path, print }) => join(line, path.map(print, 'items')) }; diff --git a/src/slang-nodes/IfStatement.js b/src/slang-nodes/IfStatement.js index b41851033..c87ad7000 100644 --- a/src/slang-nodes/IfStatement.js +++ b/src/slang-nodes/IfStatement.js @@ -1,3 +1,15 @@ +import { doc } from 'prettier'; +import { printSeparatedItem } from '../common/printer-helpers.js'; + +const { group, hardline, indent, line } = doc.builders; + +const printBody = (bodyVariantKind, path, print) => + bodyVariantKind === 'Block' + ? [' ', path.call(print, 'body')] + : group(indent([line, path.call(print, 'body')]), { + shouldBreak: bodyVariantKind === 'IfStatement' // `if` within `if` + }); + export const IfStatement = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, @@ -10,12 +22,22 @@ export const IfStatement = { ? parse(ast.elseBranch, options, parse) : undefined }), - print: ({ node, path, print }) => [ - node.ifKeyword, - node.openParen, - path.call(print, 'condition'), - node.closeParen, - path.call(print, 'body'), - node.elseBranch ? path.call(print, 'elseBranch') : '' - ] + print: ({ node, path, print }) => { + const bodyVariantKind = node.body.variant.kind; + + return [ + `${node.ifKeyword} ${node.openParen}`, + printSeparatedItem(path.call(print, 'condition')), + node.closeParen, + printBody(bodyVariantKind, path, print), + node.elseBranch + ? [ + bodyVariantKind !== 'Block' + ? hardline // else on a new line if body is not a block + : ' ', + path.call(print, 'elseBranch') + ] + : '' + ]; + } }; diff --git a/src/slang-nodes/InterfaceDefinition.js b/src/slang-nodes/InterfaceDefinition.js index a3940f900..015afa83f 100644 --- a/src/slang-nodes/InterfaceDefinition.js +++ b/src/slang-nodes/InterfaceDefinition.js @@ -1,3 +1,7 @@ +import { doc } from 'prettier'; + +const { group, line } = doc.builders; + export const InterfaceDefinition = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, @@ -10,6 +14,13 @@ export const InterfaceDefinition = { members: parse(ast.members, options, parse), closeBrace: ast.closeBrace.text }), - // TODO: implement print - print: () => ['TODO: InterfaceDefinition'] + print: ({ node, path, print }) => [ + group([ + `${node.interfaceKeyword} ${node.name}`, + node.inheritance ? path.call(print, 'inheritance') : line, + node.openBrace + ]), + path.call(print, 'members'), + node.closeBrace + ] }; diff --git a/src/slang-nodes/InterfaceMembers.js b/src/slang-nodes/InterfaceMembers.js index 741d55d87..5091a5274 100644 --- a/src/slang-nodes/InterfaceMembers.js +++ b/src/slang-nodes/InterfaceMembers.js @@ -1,9 +1,21 @@ +import { doc } from 'prettier'; +import { + printPreservingEmptyLines, + printSeparatedItem +} from '../common/printer-helpers.js'; + +const { hardline } = doc.builders; + export const InterfaceMembers = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, - isKeyword: ast.isKeyword.text, - types: parse(ast.types, options, parse) + items: ast.items.map((item) => parse(item, options, parse)) }), - // TODO: implement print - print: () => ['TODO: InterfaceMembers'] + print: ({ node, options, path, print }) => + node.items.length > 0 + ? printSeparatedItem( + printPreservingEmptyLines(path, 'items', options, print), + { firstSeparator: hardline, grouped: false } + ) + : '' }; diff --git a/src/slang-nodes/MultiplicativeExpression.js b/src/slang-nodes/MultiplicativeExpression.js index c5f356ac8..374ae5cc4 100644 --- a/src/slang-nodes/MultiplicativeExpression.js +++ b/src/slang-nodes/MultiplicativeExpression.js @@ -5,6 +5,9 @@ export const MultiplicativeExpression = { operator: ast.operator.text, rightOperand: parse(ast.rightOperand, options, parse) }), - // TODO: implement print - print: () => ['TODO: MultiplicativeExpression'] + print: ({ node, path, print }) => [ + path.call(print, 'leftOperand'), + ` ${node.operator} `, + path.call(print, 'rightOperand') + ] }; diff --git a/src/slang-nodes/OverrideSpecifier.js b/src/slang-nodes/OverrideSpecifier.js index 639a15a0e..2e3832546 100644 --- a/src/slang-nodes/OverrideSpecifier.js +++ b/src/slang-nodes/OverrideSpecifier.js @@ -6,6 +6,8 @@ export const OverrideSpecifier = { ? parse(ast.overridden, options, parse) : undefined }), - // TODO: implement print - print: () => ['TODO: OverrideSpecifier'] + print: ({ node, path, print }) => [ + node.overrideKeyword, + node.overridden ? path.call(print, 'overridden') : '' + ] }; diff --git a/src/slang-nodes/ReceiveFunctionAttributes.js b/src/slang-nodes/ReceiveFunctionAttributes.js index e40b10481..ed2b7ae8d 100644 --- a/src/slang-nodes/ReceiveFunctionAttributes.js +++ b/src/slang-nodes/ReceiveFunctionAttributes.js @@ -1,8 +1,12 @@ +import { doc } from 'prettier'; + +const { line } = doc.builders; + export const ReceiveFunctionAttributes = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), - // TODO: implement print - print: () => ['TODO: ReceiveFunctionAttributes'] + print: ({ path, print }) => + path.map(print, 'items').map((item) => [line, item]) }; diff --git a/src/slang-nodes/ReceiveFunctionDefinition.js b/src/slang-nodes/ReceiveFunctionDefinition.js index 97a44de32..972642efb 100644 --- a/src/slang-nodes/ReceiveFunctionDefinition.js +++ b/src/slang-nodes/ReceiveFunctionDefinition.js @@ -1,3 +1,5 @@ +import { printFunction } from '../common/slang-helpers.js'; + export const ReceiveFunctionDefinition = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, @@ -6,6 +8,6 @@ export const ReceiveFunctionDefinition = { attributes: parse(ast.attributes, options, parse), body: parse(ast.body, options, parse) }), - // TODO: implement print - print: () => ['TODO: ReceiveFunctionDefinition'] + print: ({ node, path, print }) => + printFunction(node.receiveKeyword, node, path, print) }; diff --git a/src/slang-nodes/Statements.js b/src/slang-nodes/Statements.js index 543cbef52..d10714575 100644 --- a/src/slang-nodes/Statements.js +++ b/src/slang-nodes/Statements.js @@ -1,10 +1,21 @@ -import { printPreservingEmptyLines } from '../common/printer-helpers.js'; +import { doc } from 'prettier'; +import { + printPreservingEmptyLines, + printSeparatedItem +} from '../common/printer-helpers.js'; + +const { hardline } = doc.builders; export const Statements = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), - print: ({ path, options, print }) => - printPreservingEmptyLines(path, 'items', options, print) + print: ({ node, path, options, print }) => + node.items.length > 0 + ? printSeparatedItem( + printPreservingEmptyLines(path, 'items', options, print), + { firstSeparator: hardline, grouped: false } + ) + : '' }; diff --git a/src/slang-nodes/UnnamedFunctionAttributes.js b/src/slang-nodes/UnnamedFunctionAttributes.js index 820757cc5..e20c683a1 100644 --- a/src/slang-nodes/UnnamedFunctionAttributes.js +++ b/src/slang-nodes/UnnamedFunctionAttributes.js @@ -1,8 +1,12 @@ +import { doc } from 'prettier'; + +const { line } = doc.builders; + export const UnnamedFunctionAttributes = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), - // TODO: implement print - print: () => ['TODO: UnnamedFunctionAttributes'] + print: ({ path, print }) => + path.map(print, 'items').map((item) => [line, item]) }; diff --git a/src/slang-nodes/UnnamedFunctionDefinition.js b/src/slang-nodes/UnnamedFunctionDefinition.js index 0d75e66f2..7c01ba02b 100644 --- a/src/slang-nodes/UnnamedFunctionDefinition.js +++ b/src/slang-nodes/UnnamedFunctionDefinition.js @@ -1,3 +1,5 @@ +import { printFunction } from '../common/slang-helpers.js'; + export const UnnamedFunctionDefinition = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, @@ -6,6 +8,6 @@ export const UnnamedFunctionDefinition = { attributes: parse(ast.attributes, options, parse), body: parse(ast.body, options, parse) }), - // TODO: implement print - print: () => ['TODO: UnnamedFunctionDefinition'] + print: ({ node, path, print }) => + printFunction(node.functionKeyword, node, path, print) }; diff --git a/src/slang-nodes/VersionExpressionSet.js b/src/slang-nodes/VersionExpressionSet.js index 423829c0e..b458413c8 100644 --- a/src/slang-nodes/VersionExpressionSet.js +++ b/src/slang-nodes/VersionExpressionSet.js @@ -1,7 +1,11 @@ +import { doc } from 'prettier'; + +const { join } = doc.builders; + export const VersionExpressionSet = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), - print: ({ path, print }) => path.map(print, 'items') + print: ({ path, print }) => join(' ', path.map(print, 'items')) }; diff --git a/tests/format/BasicIterator/__snapshots__/jsfmt.spec.js.snap b/tests/format/BasicIterator/__snapshots__/jsfmt.spec.js.snap index 6ea0ee252..97e8c58c3 100644 --- a/tests/format/BasicIterator/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/BasicIterator/__snapshots__/jsfmt.spec.js.snap @@ -74,7 +74,7 @@ contract BasicIterator { return sum; } function kill() { - if(msg.sender == creator){ + if (msg.sender == creator) { suicide(creator); } } diff --git a/tests/format/Constructors/__snapshots__/jsfmt.spec.js.snap b/tests/format/Constructors/__snapshots__/jsfmt.spec.js.snap index eefe1fafa..c7ec34220 100644 --- a/tests/format/Constructors/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Constructors/__snapshots__/jsfmt.spec.js.snap @@ -70,9 +70,7 @@ pragma solidity ^0.5.2; contract Constructors is Ownable, Changeable { function Constructors( variable1 - ) public Changeable(variable1) Ownable() onlyOwner { - - } + ) public Changeable(variable1) Ownable() onlyOwner {} constructor( variable1, variable2, @@ -94,9 +92,7 @@ contract Constructors is Ownable, Changeable { ) Ownable() onlyOwner - { - - } + {} } ================================================================================ diff --git a/tests/format/ForStatements/__snapshots__/jsfmt.spec.js.snap b/tests/format/ForStatements/__snapshots__/jsfmt.spec.js.snap index fa6d0e014..9cb8ad225 100644 --- a/tests/format/ForStatements/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/ForStatements/__snapshots__/jsfmt.spec.js.snap @@ -106,3 +106,93 @@ contract ForStatements { ================================================================================ `; + +exports[`ForStatements.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +contract ForStatements { + uint constant LONG_VARIABLE = 1; + + function hi() public { + uint a; + + for (uint i; i < 100; i++) a++; + + for (i = 0; i < 100; i++) a = a.add(LONG_VARIABLE).add(LONG_VARIABLE).add(LONG_VARIABLE); + + for (i = 0; i < 100; i++) { a++; } + + for (i = 0; i < 100; i++) { a = a.add(LONG_VARIABLE).add(LONG_VARIABLE).add(LONG_VARIABLE); } + + for (uint veryLongVariableName; veryLongVariableName < 100; veryLongVariableName++) a++; + + for (veryLongVariableName = 0; veryLongVariableName < 100; veryLongVariableName++) { a++; } + + for (; ; ) { // #178 + } + + for (i = 0; ;) { + } + + for (i = 0; i < 100; ) { + } + + for (i = 0; ; i++) { + } + + for (i = 0; i < 100; i++) { + } + + for (; i < 100; i++) { + } + + for (; i < 100; ) { + } + + for (; ; i++) { + } + } +} + +=====================================output===================================== +contract ForStatements { + uint constant LONG_VARIABLE = 1; + function hi() public { + uint a; + for (uint i; i < 100; i++) a++; + for (i = 0; i < 100; i++) + a = a.add(LONG_VARIABLE).add(LONG_VARIABLE).add(LONG_VARIABLE); + for (i = 0; i < 100; i++) { + a++; + } + for (i = 0; i < 100; i++) { + a = a.add(LONG_VARIABLE).add(LONG_VARIABLE).add(LONG_VARIABLE); + } + for ( + uint veryLongVariableName; + veryLongVariableName < 100; + veryLongVariableName++ + ) a++; + for ( + veryLongVariableName = 0; + veryLongVariableName < 100; + veryLongVariableName++ + ) { + a++; + } + for (;;) {} + for (i = 0; ; ) {} + for (i = 0; i < 100; ) {} + for (i = 0; ; i++) {} + for (i = 0; i < 100; i++) {} + for (; i < 100; i++) {} + for (; i < 100; ) {} + for (; ; i++) {} + } +} + +================================================================================ +`; diff --git a/tests/format/ForStatements/jsfmt.spec.js b/tests/format/ForStatements/jsfmt.spec.js index 765dd60a6..fd56c17bc 100644 --- a/tests/format/ForStatements/jsfmt.spec.js +++ b/tests/format/ForStatements/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse']); diff --git a/tests/format/HexLiteral/__snapshots__/jsfmt.spec.js.snap b/tests/format/HexLiteral/__snapshots__/jsfmt.spec.js.snap index 1af28dcbc..a140eafcf 100644 --- a/tests/format/HexLiteral/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/HexLiteral/__snapshots__/jsfmt.spec.js.snap @@ -55,3 +55,55 @@ contract HexLiteral { ================================================================================ `; + +exports[`HexLiteral.sol - {"compiler":"0.8.25","singleQuote":false} format 1`] = ` +====================================options===================================== +compiler: "0.8.25" +parsers: ["solidity-slang-parse"] +printWidth: 80 +singleQuote: false + | printWidth +=====================================input====================================== +// SPDX-License-Identifier: MIT +pragma solidity 0.8.25; + +contract HexLiteral { + bytes8 hex1 = hex'DeadBeef'; + bytes8 hex2 = hex"DeadBeef"; +} + +=====================================output===================================== +pragma solidity 0.8.25; +contract HexLiteral { + bytes8 hex1 = hex"DeadBeef"; + bytes8 hex2 = hex"DeadBeef"; +} + +================================================================================ +`; + +exports[`HexLiteral.sol - {"compiler":"0.8.25","singleQuote":true} format 1`] = ` +====================================options===================================== +compiler: "0.8.25" +parsers: ["solidity-slang-parse"] +printWidth: 80 +singleQuote: true + | printWidth +=====================================input====================================== +// SPDX-License-Identifier: MIT +pragma solidity 0.8.25; + +contract HexLiteral { + bytes8 hex1 = hex'DeadBeef'; + bytes8 hex2 = hex"DeadBeef"; +} + +=====================================output===================================== +pragma solidity 0.8.25; +contract HexLiteral { + bytes8 hex1 = hex'DeadBeef'; + bytes8 hex2 = hex'DeadBeef'; +} + +================================================================================ +`; diff --git a/tests/format/HexLiteral/jsfmt.spec.js b/tests/format/HexLiteral/jsfmt.spec.js index ac4400e7d..0913ecc8e 100644 --- a/tests/format/HexLiteral/jsfmt.spec.js +++ b/tests/format/HexLiteral/jsfmt.spec.js @@ -6,3 +6,11 @@ run_spec(import.meta, ['solidity-parse'], { compiler: '0.8.6', singleQuote: false }); +run_spec(import.meta, ['solidity-slang-parse'], { + compiler: '0.8.25', + singleQuote: true +}); +run_spec(import.meta, ['solidity-slang-parse'], { + compiler: '0.8.25', + singleQuote: false +}); diff --git a/tests/format/IfStatements/__snapshots__/jsfmt.spec.js.snap b/tests/format/IfStatements/__snapshots__/jsfmt.spec.js.snap index 7ef36a99a..17e140fb4 100644 --- a/tests/format/IfStatements/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/IfStatements/__snapshots__/jsfmt.spec.js.snap @@ -532,3 +532,507 @@ contract IfStatements { ================================================================================ `; + +exports[`IfStatements.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +contract IfStatements { + function hi() public { + if (simpleIf) return true; + + if (simpleIf) return (true,true,true,true,true,true,true,true,true,true,true); + + if (simpleIf) return true; + else return false; + + if (simpleIf) return (true,true,true,true,true,true,true,true,true,true,true); + else return false; + + if (simpleIf) return true; + else return (false,false,false,false,false,false,false,false,false,false,false); + + if (simpleIf) return (true,true,true,true,true,true,true,true,true,true,true); + else return (false,false,false,false,false,false,false,false,false,false,false); + + if (simpleIf) return true; + else if (simpleElseIf) return (true,false); + else return false; + + if (simpleIf) return (true,true,true,true,true,true,true,true,true,true,true); + else if (simpleElseIf) return (true,false); + else return false; + + if (simpleIf) return true; + else if (simpleElseIf) return (true,false); + else return (false,false,false,false,false,false,false,false,false,false,false); + + if (simpleIf) return (true,true,true,true,true,true,true,true,true,true,true); + else if (simpleElseIf) return (true,false); + else return (false,false,false,false,false,false,false,false,false,false,false); + + if (simpleIf) return true; + else if (simpleElseIf) return (true,false,true,false,true,false,true,false,true,false); + else return false; + + if (simpleIf) return (true,true,true,true,true,true,true,true,true,true,true); + else if (simpleElseIf) return (true,false,true,false,true,false,true,false,true,false); + else return false; + + if (simpleIf) return true; + else if (simpleElseIf) return (true,false,true,false,true,false,true,false,true,false); + else return (false,false,false,false,false,false,false,false,false,false,false); + + if (simpleIf) return (true,true,true,true,true,true,true,true,true,true,true); + else if (simpleElseIf) return (true,false,true,false,true,false,true,false,true,false); + else return (false,false,false,false,false,false,false,false,false,false,false); + + if (simpleIf) { return true; } + + if (simpleIf) { return true; } + else return false; + + if (simpleIf) return true; + else { return false; } + + if (simpleIf) { return true; } + else { return false; } + + if (simpleIf) { return true; } + else if (simpleElseIf) return (true,false); + else return false; + + if (simpleIf) return true; + else if (simpleElseIf) return (true,false); + else { return false; } + + if (simpleIf) { return true; } + else if (simpleElseIf) return (true,false); + else { return false; } + + if (simpleIf) { return true; } + else if (simpleElseIf) { return (true,false); } + else return false; + + if (simpleIf) return true; + else if (simpleElseIf) { return (true,false); } + else { return false; } + + if (veryComplicatedComputation(variable1, variable2) == (400 + 500) * 1000) { return true; } + + if (simpleIf) { return true; } + else if (veryComplicatedComputation(variable3, variable4) == (400 + 500) * 1000) { return (true,false); } + else return false; + + if (veryComplicatedComputation(variable1, variable2) == (400 + 500) * 1000) { return true; } + else if (simpleElseIf) { return (true,false); } + else return false; + + if (veryComplicatedComputation(variable1, variable2) == (400 + 500) * 1000) { return true; } + else if (veryComplicatedComputation(variable3, variable4) == (400 + 500) * 1000) { return (true,false); } + else return false; + + if (simpleIf) if (simpleIfWithinIf) return true; else return false; + + if (simpleIf) if (simpleIfWithinIf) {return true;} else {return false;} + + if (simpleIf) {if (simpleIfWithinIf) {return true;} else {return false;}} + + if (simpleIf) {if (simpleIfWithinIf) return true;} else return false; + + if (simpleIf) {if (simpleIfWithinIf) {return true;}} else {return false;} + + if (simpleIf) if (simpleIfWithinIf) return true; else return false; else return false; + + if (simpleIf) if (simpleIfWithinIf) {return true;} else {return false;} else {return false;} + + if (simpleIf) {if (simpleIfWithinIf) {return true;} else {return false;}} else return false; + } +} + +=====================================output===================================== +contract IfStatements { + function hi() public { + if (simpleIf) return true; + if (simpleIf) + return ( + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true + ); + if (simpleIf) return true; + else return false; + if (simpleIf) + return ( + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true + ); + else return false; + if (simpleIf) return true; + else + return ( + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false + ); + if (simpleIf) + return ( + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true + ); + else + return ( + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false + ); + if (simpleIf) return true; + else if (simpleElseIf) return (true, false); + else return false; + if (simpleIf) + return ( + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true + ); + else if (simpleElseIf) return (true, false); + else return false; + if (simpleIf) return true; + else if (simpleElseIf) return (true, false); + else + return ( + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false + ); + if (simpleIf) + return ( + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true + ); + else if (simpleElseIf) return (true, false); + else + return ( + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false + ); + if (simpleIf) return true; + else if (simpleElseIf) + return ( + true, + false, + true, + false, + true, + false, + true, + false, + true, + false + ); + else return false; + if (simpleIf) + return ( + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true + ); + else if (simpleElseIf) + return ( + true, + false, + true, + false, + true, + false, + true, + false, + true, + false + ); + else return false; + if (simpleIf) return true; + else if (simpleElseIf) + return ( + true, + false, + true, + false, + true, + false, + true, + false, + true, + false + ); + else + return ( + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false + ); + if (simpleIf) + return ( + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true + ); + else if (simpleElseIf) + return ( + true, + false, + true, + false, + true, + false, + true, + false, + true, + false + ); + else + return ( + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false + ); + if (simpleIf) { + return true; + } + if (simpleIf) { + return true; + } else return false; + if (simpleIf) return true; + else { + return false; + } + if (simpleIf) { + return true; + } else { + return false; + } + if (simpleIf) { + return true; + } else if (simpleElseIf) return (true, false); + else return false; + if (simpleIf) return true; + else if (simpleElseIf) return (true, false); + else { + return false; + } + if (simpleIf) { + return true; + } else if (simpleElseIf) return (true, false); + else { + return false; + } + if (simpleIf) { + return true; + } else if (simpleElseIf) { + return (true, false); + } else return false; + if (simpleIf) return true; + else if (simpleElseIf) { + return (true, false); + } else { + return false; + } + if ( + veryComplicatedComputation(variable1, variable2) == ( + 400 + 500 + ) * 1000 + ) { + return true; + } + if (simpleIf) { + return true; + } else if ( + veryComplicatedComputation(variable3, variable4) == ( + 400 + 500 + ) * 1000 + ) { + return (true, false); + } else return false; + if ( + veryComplicatedComputation(variable1, variable2) == ( + 400 + 500 + ) * 1000 + ) { + return true; + } else if (simpleElseIf) { + return (true, false); + } else return false; + if ( + veryComplicatedComputation(variable1, variable2) == ( + 400 + 500 + ) * 1000 + ) { + return true; + } else if ( + veryComplicatedComputation(variable3, variable4) == ( + 400 + 500 + ) * 1000 + ) { + return (true, false); + } else return false; + if (simpleIf) + if (simpleIfWithinIf) return true; + else return false; + if (simpleIf) + if (simpleIfWithinIf) { + return true; + } else { + return false; + } + if (simpleIf) { + if (simpleIfWithinIf) { + return true; + } else { + return false; + } + } + if (simpleIf) { + if (simpleIfWithinIf) return true; + } else return false; + if (simpleIf) { + if (simpleIfWithinIf) { + return true; + } + } else { + return false; + } + if (simpleIf) + if (simpleIfWithinIf) return true; + else return false; + else return false; + if (simpleIf) + if (simpleIfWithinIf) { + return true; + } else { + return false; + } + else { + return false; + } + if (simpleIf) { + if (simpleIfWithinIf) { + return true; + } else { + return false; + } + } else return false; + } +} + +================================================================================ +`; diff --git a/tests/format/IfStatements/jsfmt.spec.js b/tests/format/IfStatements/jsfmt.spec.js index 765dd60a6..fd56c17bc 100644 --- a/tests/format/IfStatements/jsfmt.spec.js +++ b/tests/format/IfStatements/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse']); From 9ffcc08fe1d06ab28dae9641a706fd5bda5986c8 Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 29 May 2024 16:33:54 +1200 Subject: [PATCH 014/160] WIP: 165/210 printers implemented --- src/slang-nodes/HexNumberExpression.js | 6 +- src/slang-nodes/NamedImport.js | 8 +- src/slang-nodes/PathImport.js | 6 +- src/slang-nodes/UsingDeconstruction.js | 7 +- src/slang-nodes/UsingDeconstructionSymbol.js | 6 +- src/slang-nodes/UsingDeconstructionSymbols.js | 11 ++- src/slang-nodes/UsingDirective.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 47 ++++++++++ tests/format/ImportDirective/jsfmt.spec.js | 5 ++ .../__snapshots__/jsfmt.spec.js.snap | 28 ++++++ tests/format/IndexRangeAccess/jsfmt.spec.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 22 +++++ .../format/InheritanceSpecifier/jsfmt.spec.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 90 +++++++++++++++++++ tests/format/Libraries/jsfmt.spec.js | 2 + 15 files changed, 229 insertions(+), 13 deletions(-) diff --git a/src/slang-nodes/HexNumberExpression.js b/src/slang-nodes/HexNumberExpression.js index c009dc879..7d5ea7fa3 100644 --- a/src/slang-nodes/HexNumberExpression.js +++ b/src/slang-nodes/HexNumberExpression.js @@ -4,6 +4,8 @@ export const HexNumberExpression = { literal: ast.literal.text, unit: ast.unit ? parse(ast.unit, options, parse) : undefined }), - // TODO: implement print - print: () => ['TODO: HexNumberExpression'] + print: ({ node, path, print }) => [ + node.literal, + node.unit ? path.call(print, 'unit') : '' + ] }; diff --git a/src/slang-nodes/NamedImport.js b/src/slang-nodes/NamedImport.js index 25c971893..0961839f5 100644 --- a/src/slang-nodes/NamedImport.js +++ b/src/slang-nodes/NamedImport.js @@ -6,6 +6,10 @@ export const NamedImport = { fromKeyword: ast.fromKeyword.text, path: parse(ast.path, options, parse) }), - // TODO: implement print - print: () => ['TODO: NamedImport'] + print: ({ node, path, print }) => [ + node.asterisk, + path.call(print, 'alias'), + ` ${node.fromKeyword} `, + path.call(print, 'path') + ] }; diff --git a/src/slang-nodes/PathImport.js b/src/slang-nodes/PathImport.js index c9cad5e1c..80ad96e69 100644 --- a/src/slang-nodes/PathImport.js +++ b/src/slang-nodes/PathImport.js @@ -4,6 +4,8 @@ export const PathImport = { path: parse(ast.path, options, parse), alias: ast.alias ? parse(ast.alias, options, parse) : undefined }), - // TODO: implement print - print: () => ['TODO: PathImport'] + print: ({ node, path, print }) => [ + path.call(print, 'path'), + node.alias ? path.call(print, 'alias') : '' + ] }; diff --git a/src/slang-nodes/UsingDeconstruction.js b/src/slang-nodes/UsingDeconstruction.js index 74d7e2d15..ef2602945 100644 --- a/src/slang-nodes/UsingDeconstruction.js +++ b/src/slang-nodes/UsingDeconstruction.js @@ -5,6 +5,9 @@ export const UsingDeconstruction = { symbols: parse(ast.symbols, options, parse), closeBrace: ast.closeBrace.text }), - // TODO: implement print - print: () => ['TODO: UsingDeconstruction'] + print: ({ node, path, print }) => [ + node.openBrace, + path.call(print, 'symbols'), + node.closeBrace + ] }; diff --git a/src/slang-nodes/UsingDeconstructionSymbol.js b/src/slang-nodes/UsingDeconstructionSymbol.js index 3bfebd1f6..65282c81c 100644 --- a/src/slang-nodes/UsingDeconstructionSymbol.js +++ b/src/slang-nodes/UsingDeconstructionSymbol.js @@ -4,6 +4,8 @@ export const UsingDeconstructionSymbol = { name: parse(ast.name, options, parse), alias: ast.alias ? parse(ast.alias, options, parse) : undefined }), - // TODO: implement print - print: () => ['TODO: UsingDeconstructionSymbol'] + print: ({ node, path, print }) => [ + path.call(print, 'name'), + node.alias ? path.call(print, 'alias') : '' + ] }; diff --git a/src/slang-nodes/UsingDeconstructionSymbols.js b/src/slang-nodes/UsingDeconstructionSymbols.js index 01b9c7ce1..d5376c4b9 100644 --- a/src/slang-nodes/UsingDeconstructionSymbols.js +++ b/src/slang-nodes/UsingDeconstructionSymbols.js @@ -1,9 +1,16 @@ +import { doc } from 'prettier'; +import { printSeparatedList } from '../common/printer-helpers.js'; + +const { line, softline } = doc.builders; + export const UsingDeconstructionSymbols = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), - // TODO: implement print - print: () => ['TODO: UsingDeconstructionSymbols'] + print: ({ path, print, options }) => + printSeparatedList(path.map(print, 'items'), { + firstSeparator: options.bracketSpacing ? line : softline + }) }; diff --git a/src/slang-nodes/UsingDirective.js b/src/slang-nodes/UsingDirective.js index f09b022bb..580444bbd 100644 --- a/src/slang-nodes/UsingDirective.js +++ b/src/slang-nodes/UsingDirective.js @@ -16,7 +16,7 @@ export const UsingDirective = { node.forKeyword, ' ', path.call(print, 'target'), - node.globalKeyword ? node.globalKeyword : '', + node.globalKeyword ? ` ${node.globalKeyword}` : '', node.semicolon ] }; diff --git a/tests/format/ImportDirective/__snapshots__/jsfmt.spec.js.snap b/tests/format/ImportDirective/__snapshots__/jsfmt.spec.js.snap index 3ec86c724..6a21a91dc 100644 --- a/tests/format/ImportDirective/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/ImportDirective/__snapshots__/jsfmt.spec.js.snap @@ -1,5 +1,29 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`ImportDirectives.sol - {"bracketSpacing":true,"compiler":"0.4.26"} format 1`] = ` +====================================options===================================== +bracketSpacing: true +compiler: "0.4.26" +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +import "SomeFile.sol"; +import "SomeFile.sol" as SomeOtherFile; +import * as SomeSymbol from "AnotherFile.sol"; +import {symbol1 as alias, symbol2} from "File.sol"; +import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol"; + +=====================================output===================================== +import "SomeFile.sol"; +import "SomeFile.sol" as SomeOtherFile; +import * as SomeSymbol from "AnotherFile.sol"; +import { symbol1 as alias, symbol2 } from "File.sol"; +import { symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4 } from "File2.sol"; + +================================================================================ +`; + exports[`ImportDirectives.sol - {"bracketSpacing":true} format 1`] = ` ====================================options===================================== bracketSpacing: true @@ -23,6 +47,29 @@ import { symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4 } from ================================================================================ `; +exports[`ImportDirectives.sol - {"compiler":"0.4.26"} format 1`] = ` +====================================options===================================== +compiler: "0.4.26" +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +import "SomeFile.sol"; +import "SomeFile.sol" as SomeOtherFile; +import * as SomeSymbol from "AnotherFile.sol"; +import {symbol1 as alias, symbol2} from "File.sol"; +import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol"; + +=====================================output===================================== +import "SomeFile.sol"; +import "SomeFile.sol" as SomeOtherFile; +import * as SomeSymbol from "AnotherFile.sol"; +import {symbol1 as alias, symbol2} from "File.sol"; +import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol"; + +================================================================================ +`; + exports[`ImportDirectives.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] diff --git a/tests/format/ImportDirective/jsfmt.spec.js b/tests/format/ImportDirective/jsfmt.spec.js index 993a81764..3db6b6040 100644 --- a/tests/format/ImportDirective/jsfmt.spec.js +++ b/tests/format/ImportDirective/jsfmt.spec.js @@ -1,2 +1,7 @@ run_spec(import.meta, ['solidity-parse']); run_spec(import.meta, ['solidity-parse'], { bracketSpacing: true }); +run_spec(import.meta, ['solidity-slang-parse'], { compiler: '0.4.26' }); +run_spec(import.meta, ['solidity-slang-parse'], { + bracketSpacing: true, + compiler: '0.4.26' +}); diff --git a/tests/format/IndexRangeAccess/__snapshots__/jsfmt.spec.js.snap b/tests/format/IndexRangeAccess/__snapshots__/jsfmt.spec.js.snap index acc351b87..5e920b3bd 100644 --- a/tests/format/IndexRangeAccess/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/IndexRangeAccess/__snapshots__/jsfmt.spec.js.snap @@ -29,3 +29,31 @@ contract Demo { ================================================================================ `; + +exports[`IndexRangeAccess.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity ^0.6.4; + +contract Demo { + event Log(bytes value); + + function log(bytes calldata value) external { + emit Log(bytes(value[0:10])); + } +} + +=====================================output===================================== +pragma solidity ^0.6.4; +contract Demo { + event Log(bytes value); + function log(bytes calldata value) external { + emit Log(bytes(value[0:10])); + } +} + +================================================================================ +`; diff --git a/tests/format/IndexRangeAccess/jsfmt.spec.js b/tests/format/IndexRangeAccess/jsfmt.spec.js index 765dd60a6..fd56c17bc 100644 --- a/tests/format/IndexRangeAccess/jsfmt.spec.js +++ b/tests/format/IndexRangeAccess/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse']); diff --git a/tests/format/InheritanceSpecifier/__snapshots__/jsfmt.spec.js.snap b/tests/format/InheritanceSpecifier/__snapshots__/jsfmt.spec.js.snap index c95f10839..20c4a5086 100644 --- a/tests/format/InheritanceSpecifier/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/InheritanceSpecifier/__snapshots__/jsfmt.spec.js.snap @@ -21,3 +21,25 @@ contract LongInheritanceSpecifier is ================================================================================ `; + +exports[`InheritanceSpecifier.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +contract InheritanceSpecifier is SomeOtherContract(1234,false) {} +contract LongInheritanceSpecifier is SomeOtherContract(123467890,false,0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c) {} + +=====================================output===================================== +contract InheritanceSpecifier is SomeOtherContract(1234, false) {} +contract LongInheritanceSpecifier is + SomeOtherContract( + 123467890, + false, + 0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c + ) +{} + +================================================================================ +`; diff --git a/tests/format/InheritanceSpecifier/jsfmt.spec.js b/tests/format/InheritanceSpecifier/jsfmt.spec.js index 765dd60a6..fd56c17bc 100644 --- a/tests/format/InheritanceSpecifier/jsfmt.spec.js +++ b/tests/format/InheritanceSpecifier/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse']); diff --git a/tests/format/Libraries/__snapshots__/jsfmt.spec.js.snap b/tests/format/Libraries/__snapshots__/jsfmt.spec.js.snap index dd90bbbd3..926b4647f 100644 --- a/tests/format/Libraries/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Libraries/__snapshots__/jsfmt.spec.js.snap @@ -51,6 +51,57 @@ using { ================================================================================ `; +exports[`Libraries.sol - {"bracketSpacing":true} format 2`] = ` +====================================options===================================== +bracketSpacing: true +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== + using Lib for uint; +using Lib for + uint global; +using { f} for uint; +using {f } for uint global; +using { a, very, long, and, complex, Function, list, with, long, names } for + uint; +using { a, very, + long, and, complex, Function, + list, with, long, names } for uint global; + +=====================================output===================================== +using Lib for uint; +using Lib for uint global; +using { f } for uint; +using { f } for uint global; +using { + a, + very, + long, + and, + complex, + Function, + list, + with, + long, + names +} for uint; +using { + a, + very, + long, + and, + complex, + Function, + list, + with, + long, + names +} for uint global; + +================================================================================ +`; + exports[`Libraries.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] @@ -89,3 +140,42 @@ using { ================================================================================ `; + +exports[`Libraries.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== + using Lib for uint; +using Lib for + uint global; +using { f} for uint; +using {f } for uint global; +using { a, very, long, and, complex, Function, list, with, long, names } for + uint; +using { a, very, + long, and, complex, Function, + list, with, long, names } for uint global; + +=====================================output===================================== +using Lib for uint; +using Lib for uint global; +using {f} for uint; +using {f} for uint global; +using {a, very, long, and, complex, Function, list, with, long, names} for uint; +using { + a, + very, + long, + and, + complex, + Function, + list, + with, + long, + names +} for uint global; + +================================================================================ +`; diff --git a/tests/format/Libraries/jsfmt.spec.js b/tests/format/Libraries/jsfmt.spec.js index 993a81764..f9974c4c0 100644 --- a/tests/format/Libraries/jsfmt.spec.js +++ b/tests/format/Libraries/jsfmt.spec.js @@ -1,2 +1,4 @@ run_spec(import.meta, ['solidity-parse']); run_spec(import.meta, ['solidity-parse'], { bracketSpacing: true }); +run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['solidity-slang-parse'], { bracketSpacing: true }); From 4cdb43ce8d21560b0bf6d45dddf1a1da10fc8c35 Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 29 May 2024 22:34:26 +1200 Subject: [PATCH 015/160] WIP: 168/213 printers implemented --- src/common/slang-helpers.js | 2 +- src/slang-nodes/ModifierAttribute.js | 13 ++++++ src/slang-nodes/ModifierAttributes.js | 12 ++++++ src/slang-nodes/ModifierDefinition.js | 16 +++++++ src/slang-nodes/index.js | 3 ++ .../__snapshots__/jsfmt.spec.js.snap | 28 +++++++++++++ .../format/ModifierDefinitions/jsfmt.spec.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 42 +++++++++++++++++++ .../format/ModifierInvocations/jsfmt.spec.js | 1 + 9 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 src/slang-nodes/ModifierAttribute.js create mode 100644 src/slang-nodes/ModifierAttributes.js create mode 100644 src/slang-nodes/ModifierDefinition.js diff --git a/src/common/slang-helpers.js b/src/common/slang-helpers.js index a7f4220bf..4a318a9dd 100644 --- a/src/common/slang-helpers.js +++ b/src/common/slang-helpers.js @@ -10,7 +10,7 @@ export const printFunction = (functionName, node, path, print) => [ group([ path.call(print, 'attributes'), node.returns ? [line, path.call(print, 'returns')] : '', - dedent(line) + node.body.variant !== ';' ? dedent(line) : '' ]) ) ]), diff --git a/src/slang-nodes/ModifierAttribute.js b/src/slang-nodes/ModifierAttribute.js new file mode 100644 index 000000000..490f18c7f --- /dev/null +++ b/src/slang-nodes/ModifierAttribute.js @@ -0,0 +1,13 @@ +export const ModifierAttribute = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + variant: + ast.variant.type === 'Token' + ? ast.variant.text + : parse(ast.variant, options, parse) + }), + print: ({ node, path, print }) => + typeof node.variant === 'string' + ? node.variant + : path.call(print, 'variant') +}; diff --git a/src/slang-nodes/ModifierAttributes.js b/src/slang-nodes/ModifierAttributes.js new file mode 100644 index 000000000..a79104fd4 --- /dev/null +++ b/src/slang-nodes/ModifierAttributes.js @@ -0,0 +1,12 @@ +import { doc } from 'prettier'; + +const { line } = doc.builders; + +export const ModifierAttributes = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + items: ast.items.map((item) => parse(item, options, parse)) + }), + print: ({ path, print }) => + path.map(print, 'items').map((item) => [line, item]) +}; diff --git a/src/slang-nodes/ModifierDefinition.js b/src/slang-nodes/ModifierDefinition.js new file mode 100644 index 000000000..fc968c82d --- /dev/null +++ b/src/slang-nodes/ModifierDefinition.js @@ -0,0 +1,16 @@ +import { printFunction } from '../common/slang-helpers.js'; + +export const ModifierDefinition = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + modifierKeyword: ast.modifierKeyword.text, + name: ast.name.text, + parameters: ast.parameters + ? parse(ast.parameters, options, parse) + : undefined, + attributes: parse(ast.attributes, options, parse), + body: parse(ast.body, options, parse) + }), + print: ({ node, path, print }) => + printFunction(`${node.modifierKeyword} ${node.name}`, node, path, print) +}; diff --git a/src/slang-nodes/index.js b/src/slang-nodes/index.js index 88d633569..08281f0b0 100644 --- a/src/slang-nodes/index.js +++ b/src/slang-nodes/index.js @@ -91,6 +91,9 @@ export * from './MappingType.js'; export * from './MappingValue.js'; export * from './MemberAccess.js'; export * from './MemberAccessExpression.js'; +export * from './ModifierAttribute.js'; +export * from './ModifierAttributes.js'; +export * from './ModifierDefinition.js'; export * from './ModifierInvocation.js'; export * from './MultiplicativeExpression.js'; export * from './NamedArgument.js'; diff --git a/tests/format/ModifierDefinitions/__snapshots__/jsfmt.spec.js.snap b/tests/format/ModifierDefinitions/__snapshots__/jsfmt.spec.js.snap index ffe001f38..6878d668f 100644 --- a/tests/format/ModifierDefinitions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/ModifierDefinitions/__snapshots__/jsfmt.spec.js.snap @@ -31,3 +31,31 @@ contract ModifierDefinitions { ================================================================================ `; + +exports[`ModifierDefinitions.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +contract ModifierDefinitions { + modifier noParams() {} + modifier oneParam(uint a) {} + modifier twoParams(uint a,uint b) {} + modifier threeParams(uint a,uint b ,uint c) {} + modifier test() virtual; + modifier test() virtual {} +} + +=====================================output===================================== +contract ModifierDefinitions { + modifier noParams() {} + modifier oneParam(uint a) {} + modifier twoParams(uint a, uint b) {} + modifier threeParams(uint a, uint b, uint c) {} + modifier test() virtual; + modifier test() virtual {} +} + +================================================================================ +`; diff --git a/tests/format/ModifierDefinitions/jsfmt.spec.js b/tests/format/ModifierDefinitions/jsfmt.spec.js index 765dd60a6..fd56c17bc 100644 --- a/tests/format/ModifierDefinitions/jsfmt.spec.js +++ b/tests/format/ModifierDefinitions/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse']); diff --git a/tests/format/ModifierInvocations/__snapshots__/jsfmt.spec.js.snap b/tests/format/ModifierInvocations/__snapshots__/jsfmt.spec.js.snap index dcfdfd2d2..df076fb83 100644 --- a/tests/format/ModifierInvocations/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/ModifierInvocations/__snapshots__/jsfmt.spec.js.snap @@ -49,3 +49,45 @@ contract ModifierInvocations is ModifierDefinitions { ================================================================================ `; + +exports[`ModifierInvocations.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +// SPDX-License-Identifier: MIT +pragma solidity 0.8.25; + +contract ModifierDefinitions { + // We enforce the use of parentheses in modifiers without parameters. + modifier emptyParams {_;} + modifier noParams() {_;} +} + +contract ModifierInvocations is ModifierDefinitions { + // We can't differentiate between constructor calls or modifiers, so we keep + // parentheses untouched in constructors. + constructor () emptyParams noParams() ModifierDefinitions() {} + + // We remove parentheses in modifiers without arguments. + function test() public emptyParams noParams() {} +} + +=====================================output===================================== +pragma solidity 0.8.25; +contract ModifierDefinitions { + modifier emptyParams { + _; + } + modifier noParams() { + _; + } +} +contract ModifierInvocations is ModifierDefinitions { + constructor() emptyParams noParams() ModifierDefinitions() {} + function test() public emptyParams noParams() {} +} + +================================================================================ +`; diff --git a/tests/format/ModifierInvocations/jsfmt.spec.js b/tests/format/ModifierInvocations/jsfmt.spec.js index 765dd60a6..fd56c17bc 100644 --- a/tests/format/ModifierInvocations/jsfmt.spec.js +++ b/tests/format/ModifierInvocations/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse']); From cfcbe87c2e3bb08f7289df48bc7c3c70c689756a Mon Sep 17 00:00:00 2001 From: Klaus Date: Thu, 30 May 2024 00:06:20 +1200 Subject: [PATCH 016/160] WIP: 172/213 printers implemented --- src/slang-nodes/ABICoderPragma.js | 2 +- src/slang-nodes/BitwiseAndExpression.js | 2 +- src/slang-nodes/BitwiseOrExpression.js | 2 +- src/slang-nodes/BitwiseXorExpression.js | 2 +- src/slang-nodes/BreakStatement.js | 2 +- src/slang-nodes/CallOptions.js | 5 +-- src/slang-nodes/CallOptionsExpression.js | 8 +++-- src/slang-nodes/CatchClause.js | 2 +- src/slang-nodes/CatchClauseError.js | 2 +- src/slang-nodes/CatchClauses.js | 2 +- src/slang-nodes/ConstantDefinition.js | 2 +- src/slang-nodes/ContinueStatement.js | 2 +- src/slang-nodes/DecimalNumberExpression.js | 2 +- src/slang-nodes/DoWhileStatement.js | 2 +- src/slang-nodes/ExperimentalPragma.js | 2 +- src/slang-nodes/FunctionType.js | 2 +- src/slang-nodes/FunctionTypeAttributes.js | 2 +- src/slang-nodes/HexNumberExpression.js | 2 +- src/slang-nodes/HexStringLiterals.js | 4 +-- src/slang-nodes/LibraryDefinition.js | 2 +- src/slang-nodes/LibraryMembers.js | 2 +- src/slang-nodes/MappingKey.js | 2 +- src/slang-nodes/MappingType.js | 2 +- src/slang-nodes/MappingValue.js | 2 +- src/slang-nodes/NamedArgument.js | 6 ++-- src/slang-nodes/NamedArgumentGroup.js | 2 +- src/slang-nodes/NamedArguments.js | 2 +- src/slang-nodes/NamedArgumentsDeclaration.js | 2 +- src/slang-nodes/NewExpression.js | 6 ++-- src/slang-nodes/OrExpression.js | 2 +- src/slang-nodes/OverridePaths.js | 2 +- src/slang-nodes/OverridePathsDeclaration.js | 2 +- src/slang-nodes/PrefixExpression.js | 2 +- src/slang-nodes/ShiftExpression.js | 2 +- src/slang-nodes/StringLiterals.js | 4 +-- src/slang-nodes/ThrowStatement.js | 2 +- src/slang-nodes/TryStatement.js | 2 +- src/slang-nodes/TupleDeconstructionElement.js | 4 ++- .../TupleDeconstructionElements.js | 4 ++- .../TupleDeconstructionStatement.js | 4 ++- src/slang-nodes/TypeExpression.js | 2 +- src/slang-nodes/UncheckedBlock.js | 2 +- src/slang-nodes/UnicodeStringLiterals.js | 2 +- src/slang-nodes/UntypedTupleMember.js | 4 ++- .../UserDefinedValueTypeDefinition.js | 4 ++- src/slang-nodes/UsingAlias.js | 2 +- src/slang-nodes/VersionRange.js | 2 +- src/slang-nodes/YulColonAndEqual.js | 2 +- src/slang-nodes/YulLeaveStatement.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 33 +++++++++++++++++ tests/format/MultipartStrings/jsfmt.spec.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 36 +++++++++++++++++++ tests/format/NumberLiteral/jsfmt.spec.js | 1 + 53 files changed, 145 insertions(+), 55 deletions(-) diff --git a/src/slang-nodes/ABICoderPragma.js b/src/slang-nodes/ABICoderPragma.js index a731a7c37..4129f8255 100644 --- a/src/slang-nodes/ABICoderPragma.js +++ b/src/slang-nodes/ABICoderPragma.js @@ -5,5 +5,5 @@ export const ABICoderPragma = { version: ast.version.text }), // TODO: implement print - print: () => ['TODO: ABICoderPragma'] + print: ({ node, path, print, options }) => ['TODO: ABICoderPragma'] }; diff --git a/src/slang-nodes/BitwiseAndExpression.js b/src/slang-nodes/BitwiseAndExpression.js index 451f3c999..b74b1277e 100644 --- a/src/slang-nodes/BitwiseAndExpression.js +++ b/src/slang-nodes/BitwiseAndExpression.js @@ -6,5 +6,5 @@ export const BitwiseAndExpression = { rightOperand: parse(ast.rightOperand, options, parse) }), // TODO: implement print - print: () => ['TODO: BitwiseAndExpression'] + print: ({ node, path, print, options }) => ['TODO: BitwiseAndExpression'] }; diff --git a/src/slang-nodes/BitwiseOrExpression.js b/src/slang-nodes/BitwiseOrExpression.js index 046572ac5..640a1285d 100644 --- a/src/slang-nodes/BitwiseOrExpression.js +++ b/src/slang-nodes/BitwiseOrExpression.js @@ -6,5 +6,5 @@ export const BitwiseOrExpression = { rightOperand: parse(ast.rightOperand, options, parse) }), // TODO: implement print - print: () => ['TODO: BitwiseOrExpression'] + print: ({ node, path, print, options }) => ['TODO: BitwiseOrExpression'] }; diff --git a/src/slang-nodes/BitwiseXorExpression.js b/src/slang-nodes/BitwiseXorExpression.js index f616a431e..64b436e2a 100644 --- a/src/slang-nodes/BitwiseXorExpression.js +++ b/src/slang-nodes/BitwiseXorExpression.js @@ -6,5 +6,5 @@ export const BitwiseXorExpression = { rightOperand: parse(ast.rightOperand, options, parse) }), // TODO: implement print - print: () => ['TODO: BitwiseXorExpression'] + print: ({ node, path, print, options }) => ['TODO: BitwiseXorExpression'] }; diff --git a/src/slang-nodes/BreakStatement.js b/src/slang-nodes/BreakStatement.js index 538005016..fea103926 100644 --- a/src/slang-nodes/BreakStatement.js +++ b/src/slang-nodes/BreakStatement.js @@ -5,5 +5,5 @@ export const BreakStatement = { semicolon: ast.semicolon.text }), // TODO: implement print - print: () => ['TODO: BreakStatement'] + print: ({ node, path, print, options }) => ['TODO: BreakStatement'] }; diff --git a/src/slang-nodes/CallOptions.js b/src/slang-nodes/CallOptions.js index 81e5f32a1..c40b06232 100644 --- a/src/slang-nodes/CallOptions.js +++ b/src/slang-nodes/CallOptions.js @@ -1,9 +1,10 @@ +import { printSeparatedList } from '../common/printer-helpers.js'; + export const CallOptions = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), - // TODO: implement print - print: () => ['TODO: CallOptions'] + print: ({ path, print }) => printSeparatedList(path.map(print, 'items')) }; diff --git a/src/slang-nodes/CallOptionsExpression.js b/src/slang-nodes/CallOptionsExpression.js index b0445c095..5cb8a37f5 100644 --- a/src/slang-nodes/CallOptionsExpression.js +++ b/src/slang-nodes/CallOptionsExpression.js @@ -6,6 +6,10 @@ export const CallOptionsExpression = { options: parse(ast.options, options, parse), closeBrace: ast.closeBrace.text }), - // TODO: implement print - print: () => ['TODO: CallOptionsExpression'] + print: ({ node, path, print }) => [ + path.call(print, 'operand'), + node.openBrace, + path.call(print, 'options'), + node.closeBrace + ] }; diff --git a/src/slang-nodes/CatchClause.js b/src/slang-nodes/CatchClause.js index 3fbb6660f..f399b86a7 100644 --- a/src/slang-nodes/CatchClause.js +++ b/src/slang-nodes/CatchClause.js @@ -6,5 +6,5 @@ export const CatchClause = { body: parse(ast.body, options, parse) }), // TODO: implement print - print: () => ['TODO: CatchClause'] + print: ({ node, path, print, options }) => ['TODO: CatchClause'] }; diff --git a/src/slang-nodes/CatchClauseError.js b/src/slang-nodes/CatchClauseError.js index ef0309880..1c6d56174 100644 --- a/src/slang-nodes/CatchClauseError.js +++ b/src/slang-nodes/CatchClauseError.js @@ -5,5 +5,5 @@ export const CatchClauseError = { parameters: parse(ast.parameters, options, parse) }), // TODO: implement print - print: () => ['TODO: CatchClauseError'] + print: ({ node, path, print, options }) => ['TODO: CatchClauseError'] }; diff --git a/src/slang-nodes/CatchClauses.js b/src/slang-nodes/CatchClauses.js index 512ec0dda..aeadb2b77 100644 --- a/src/slang-nodes/CatchClauses.js +++ b/src/slang-nodes/CatchClauses.js @@ -4,5 +4,5 @@ export const CatchClauses = { items: ast.items.map((item) => parse(item, options, parse)) }), // TODO: implement print - print: () => ['TODO: CatchClauses'] + print: ({ node, path, print, options }) => ['TODO: CatchClauses'] }; diff --git a/src/slang-nodes/ConstantDefinition.js b/src/slang-nodes/ConstantDefinition.js index 7ba05df17..f358f8200 100644 --- a/src/slang-nodes/ConstantDefinition.js +++ b/src/slang-nodes/ConstantDefinition.js @@ -9,5 +9,5 @@ export const ConstantDefinition = { semicolon: ast.semicolon.text }), // TODO: implement print - print: () => ['TODO: ConstantDefinition'] + print: ({ node, path, print, options }) => ['TODO: ConstantDefinition'] }; diff --git a/src/slang-nodes/ContinueStatement.js b/src/slang-nodes/ContinueStatement.js index 58aff03d9..9033b1171 100644 --- a/src/slang-nodes/ContinueStatement.js +++ b/src/slang-nodes/ContinueStatement.js @@ -5,5 +5,5 @@ export const ContinueStatement = { semicolon: ast.semicolon.text }), // TODO: implement print - print: () => ['TODO: ContinueStatement'] + print: ({ node, path, print, options }) => ['TODO: ContinueStatement'] }; diff --git a/src/slang-nodes/DecimalNumberExpression.js b/src/slang-nodes/DecimalNumberExpression.js index f97d43134..6fb87dd7f 100644 --- a/src/slang-nodes/DecimalNumberExpression.js +++ b/src/slang-nodes/DecimalNumberExpression.js @@ -6,6 +6,6 @@ export const DecimalNumberExpression = { }), print: ({ node, path, print }) => [ node.literal, - node.unit ? path.call(print, 'unit') : '' + node.unit ? [' ', path.call(print, 'unit')] : '' ] }; diff --git a/src/slang-nodes/DoWhileStatement.js b/src/slang-nodes/DoWhileStatement.js index 96f29304c..0d53c2b47 100644 --- a/src/slang-nodes/DoWhileStatement.js +++ b/src/slang-nodes/DoWhileStatement.js @@ -10,5 +10,5 @@ export const DoWhileStatement = { semicolon: ast.semicolon.text }), // TODO: implement print - print: () => ['TODO: DoWhileStatement'] + print: ({ node, path, print, options }) => ['TODO: DoWhileStatement'] }; diff --git a/src/slang-nodes/ExperimentalPragma.js b/src/slang-nodes/ExperimentalPragma.js index 6f1db6f5d..e67553bdf 100644 --- a/src/slang-nodes/ExperimentalPragma.js +++ b/src/slang-nodes/ExperimentalPragma.js @@ -5,5 +5,5 @@ export const ExperimentalPragma = { feature: ast.feature }), // TODO: implement print - print: () => ['TODO: ExperimentalPragma'] + print: ({ node, path, print, options }) => ['TODO: ExperimentalPragma'] }; diff --git a/src/slang-nodes/FunctionType.js b/src/slang-nodes/FunctionType.js index 14fd0e212..6c650ba94 100644 --- a/src/slang-nodes/FunctionType.js +++ b/src/slang-nodes/FunctionType.js @@ -7,5 +7,5 @@ export const FunctionType = { returns: ast.returns ? parse(ast.returns, options, parse) : undefined }), // TODO: implement print - print: () => ['TODO: FunctionType'] + print: ({ node, path, print, options }) => ['TODO: FunctionType'] }; diff --git a/src/slang-nodes/FunctionTypeAttributes.js b/src/slang-nodes/FunctionTypeAttributes.js index ffa807f08..769fba83b 100644 --- a/src/slang-nodes/FunctionTypeAttributes.js +++ b/src/slang-nodes/FunctionTypeAttributes.js @@ -4,5 +4,5 @@ export const FunctionTypeAttributes = { items: ast.items.map((item) => parse(item, options, parse)) }), // TODO: implement print - print: () => ['TODO: FunctionTypeAttributes'] + print: ({ node, path, print, options }) => ['TODO: FunctionTypeAttributes'] }; diff --git a/src/slang-nodes/HexNumberExpression.js b/src/slang-nodes/HexNumberExpression.js index 7d5ea7fa3..00fbbd3fd 100644 --- a/src/slang-nodes/HexNumberExpression.js +++ b/src/slang-nodes/HexNumberExpression.js @@ -6,6 +6,6 @@ export const HexNumberExpression = { }), print: ({ node, path, print }) => [ node.literal, - node.unit ? path.call(print, 'unit') : '' + node.unit ? [' ', path.call(print, 'unit')] : '' ] }; diff --git a/src/slang-nodes/HexStringLiterals.js b/src/slang-nodes/HexStringLiterals.js index 27b4d5000..ebddc2ca0 100644 --- a/src/slang-nodes/HexStringLiterals.js +++ b/src/slang-nodes/HexStringLiterals.js @@ -1,11 +1,11 @@ import { doc } from 'prettier'; -const { join, line } = doc.builders; +const { group, join, line } = doc.builders; export const HexStringLiterals = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), - print: ({ path, print }) => join(line, path.map(print, 'items')) + print: ({ path, print }) => group(join(line, path.map(print, 'items'))) }; diff --git a/src/slang-nodes/LibraryDefinition.js b/src/slang-nodes/LibraryDefinition.js index d5479d8d4..caf580b90 100644 --- a/src/slang-nodes/LibraryDefinition.js +++ b/src/slang-nodes/LibraryDefinition.js @@ -8,5 +8,5 @@ export const LibraryDefinition = { closeBrace: ast.closeBrace.text }), // TODO: implement print - print: () => ['TODO: LibraryDefinition'] + print: ({ node, path, print, options }) => ['TODO: LibraryDefinition'] }; diff --git a/src/slang-nodes/LibraryMembers.js b/src/slang-nodes/LibraryMembers.js index 50cf0f082..291df3910 100644 --- a/src/slang-nodes/LibraryMembers.js +++ b/src/slang-nodes/LibraryMembers.js @@ -4,5 +4,5 @@ export const LibraryMembers = { items: ast.items.map((item) => parse(item, options, parse)) }), // TODO: implement print - print: () => ['TODO: LibraryMembers'] + print: ({ node, path, print, options }) => ['TODO: LibraryMembers'] }; diff --git a/src/slang-nodes/MappingKey.js b/src/slang-nodes/MappingKey.js index e88a51eaa..943e5c56c 100644 --- a/src/slang-nodes/MappingKey.js +++ b/src/slang-nodes/MappingKey.js @@ -5,5 +5,5 @@ export const MappingKey = { name: ast.name?.text }), // TODO: implement print - print: () => ['TODO: MappingKey'] + print: ({ node, path, print, options }) => ['TODO: MappingKey'] }; diff --git a/src/slang-nodes/MappingType.js b/src/slang-nodes/MappingType.js index 641935c56..8a2bae0dc 100644 --- a/src/slang-nodes/MappingType.js +++ b/src/slang-nodes/MappingType.js @@ -9,5 +9,5 @@ export const MappingType = { closeParen: ast.closeParen.text }), // TODO: implement print - print: () => ['TODO: MappingType'] + print: ({ node, path, print, options }) => ['TODO: MappingType'] }; diff --git a/src/slang-nodes/MappingValue.js b/src/slang-nodes/MappingValue.js index 014fbcb24..fee2bc772 100644 --- a/src/slang-nodes/MappingValue.js +++ b/src/slang-nodes/MappingValue.js @@ -5,5 +5,5 @@ export const MappingValue = { name: ast.name?.text }), // TODO: implement print - print: () => ['TODO: MappingValue'] + print: ({ node, path, print, options }) => ['TODO: MappingValue'] }; diff --git a/src/slang-nodes/NamedArgument.js b/src/slang-nodes/NamedArgument.js index f753552a3..14cad0616 100644 --- a/src/slang-nodes/NamedArgument.js +++ b/src/slang-nodes/NamedArgument.js @@ -5,6 +5,8 @@ export const NamedArgument = { colon: ast.colon.text, value: parse(ast.value, options, parse) }), - // TODO: implement print - print: () => ['TODO: NamedArgument'] + print: ({ node, path, print }) => [ + `${node.name}${node.colon} `, + path.call(print, 'value') + ] }; diff --git a/src/slang-nodes/NamedArgumentGroup.js b/src/slang-nodes/NamedArgumentGroup.js index 1a5434410..e9fb180b3 100644 --- a/src/slang-nodes/NamedArgumentGroup.js +++ b/src/slang-nodes/NamedArgumentGroup.js @@ -6,5 +6,5 @@ export const NamedArgumentGroup = { closeBrace: ast.closeBrace.text }), // TODO: implement print - print: () => ['TODO: NamedArgumentGroup'] + print: ({ node, path, print, options }) => ['TODO: NamedArgumentGroup'] }; diff --git a/src/slang-nodes/NamedArguments.js b/src/slang-nodes/NamedArguments.js index f227e9ac3..61041871f 100644 --- a/src/slang-nodes/NamedArguments.js +++ b/src/slang-nodes/NamedArguments.js @@ -5,5 +5,5 @@ export const NamedArguments = { separators: ast.separators.map((separator) => separator.text) }), // TODO: implement print - print: () => ['TODO: NamedArguments'] + print: ({ node, path, print, options }) => ['TODO: NamedArguments'] }; diff --git a/src/slang-nodes/NamedArgumentsDeclaration.js b/src/slang-nodes/NamedArgumentsDeclaration.js index 767f1277b..7112c0ee5 100644 --- a/src/slang-nodes/NamedArgumentsDeclaration.js +++ b/src/slang-nodes/NamedArgumentsDeclaration.js @@ -6,5 +6,5 @@ export const NamedArgumentsDeclaration = { closeParen: ast.closeParen.text }), // TODO: implement print - print: () => ['TODO: NamedArgumentsDeclaration'] + print: ({ node, path, print, options }) => ['TODO: NamedArgumentsDeclaration'] }; diff --git a/src/slang-nodes/NewExpression.js b/src/slang-nodes/NewExpression.js index 1ebf8c370..81a90683d 100644 --- a/src/slang-nodes/NewExpression.js +++ b/src/slang-nodes/NewExpression.js @@ -4,6 +4,8 @@ export const NewExpression = { newKeyword: ast.newKeyword.text, typeName: parse(ast.typeName, options, parse) }), - // TODO: implement print - print: () => ['TODO: NewExpression'] + print: ({ node, path, print }) => [ + `${node.newKeyword} `, + path.call(print, 'typeName') + ] }; diff --git a/src/slang-nodes/OrExpression.js b/src/slang-nodes/OrExpression.js index dcc957596..378c82744 100644 --- a/src/slang-nodes/OrExpression.js +++ b/src/slang-nodes/OrExpression.js @@ -6,5 +6,5 @@ export const OrExpression = { rightOperand: parse(ast.rightOperand, options, parse) }), // TODO: implement print - print: () => ['TODO: OrExpression'] + print: ({ node, path, print, options }) => ['TODO: OrExpression'] }; diff --git a/src/slang-nodes/OverridePaths.js b/src/slang-nodes/OverridePaths.js index f70297e26..cee4ef0ef 100644 --- a/src/slang-nodes/OverridePaths.js +++ b/src/slang-nodes/OverridePaths.js @@ -5,5 +5,5 @@ export const OverridePaths = { separators: ast.separators.map((separator) => separator) }), // TODO: implement print - print: () => ['TODO: OverridePaths'] + print: ({ node, path, print, options }) => ['TODO: OverridePaths'] }; diff --git a/src/slang-nodes/OverridePathsDeclaration.js b/src/slang-nodes/OverridePathsDeclaration.js index c954a2d1b..78aaad756 100644 --- a/src/slang-nodes/OverridePathsDeclaration.js +++ b/src/slang-nodes/OverridePathsDeclaration.js @@ -6,5 +6,5 @@ export const OverridePathsDeclaration = { closeParen: ast.closeParen.text }), // TODO: implement print - print: () => ['TODO: OverridePathsDeclaration'] + print: ({ node, path, print, options }) => ['TODO: OverridePathsDeclaration'] }; diff --git a/src/slang-nodes/PrefixExpression.js b/src/slang-nodes/PrefixExpression.js index 712a441d8..2b75c24dc 100644 --- a/src/slang-nodes/PrefixExpression.js +++ b/src/slang-nodes/PrefixExpression.js @@ -5,5 +5,5 @@ export const PrefixExpression = { operand: parse(ast.operand, options, parse) }), // TODO: implement print - print: () => ['TODO: PrefixExpression'] + print: ({ node, path, print, options }) => ['TODO: PrefixExpression'] }; diff --git a/src/slang-nodes/ShiftExpression.js b/src/slang-nodes/ShiftExpression.js index f48796516..0c634563c 100644 --- a/src/slang-nodes/ShiftExpression.js +++ b/src/slang-nodes/ShiftExpression.js @@ -6,5 +6,5 @@ export const ShiftExpression = { rightOperand: parse(ast.rightOperand, options, parse) }), // TODO: implement print - print: () => ['TODO: ShiftExpression'] + print: ({ node, path, print, options }) => ['TODO: ShiftExpression'] }; diff --git a/src/slang-nodes/StringLiterals.js b/src/slang-nodes/StringLiterals.js index 4d163726d..69bc408a6 100644 --- a/src/slang-nodes/StringLiterals.js +++ b/src/slang-nodes/StringLiterals.js @@ -1,11 +1,11 @@ import { doc } from 'prettier'; -const { join, hardline } = doc.builders; +const { group, join, line } = doc.builders; export const StringLiterals = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), - print: ({ path, print }) => join(hardline, path.map(print, 'items')) + print: ({ path, print }) => group(join(line, path.map(print, 'items'))) }; diff --git a/src/slang-nodes/ThrowStatement.js b/src/slang-nodes/ThrowStatement.js index 9f56e1687..2b8690054 100644 --- a/src/slang-nodes/ThrowStatement.js +++ b/src/slang-nodes/ThrowStatement.js @@ -5,5 +5,5 @@ export const ThrowStatement = { semicolon: ast.semicolon.text }), // TODO: implement print - print: () => ['TODO: ThrowStatement'] + print: ({ node, path, print, options }) => ['TODO: ThrowStatement'] }; diff --git a/src/slang-nodes/TryStatement.js b/src/slang-nodes/TryStatement.js index 38e6e6497..b3a415350 100644 --- a/src/slang-nodes/TryStatement.js +++ b/src/slang-nodes/TryStatement.js @@ -8,5 +8,5 @@ export const TryStatement = { catchClauses: parse(ast.catchClauses, options, parse) }), // TODO: implement print - print: () => ['TODO: TryStatement'] + print: ({ node, path, print, options }) => ['TODO: TryStatement'] }; diff --git a/src/slang-nodes/TupleDeconstructionElement.js b/src/slang-nodes/TupleDeconstructionElement.js index 72070dd1f..6fac5f760 100644 --- a/src/slang-nodes/TupleDeconstructionElement.js +++ b/src/slang-nodes/TupleDeconstructionElement.js @@ -4,5 +4,7 @@ export const TupleDeconstructionElement = { member: ast.member ? parse(ast.member, options, parse) : undefined }), // TODO: implement print - print: () => ['TODO: TupleDeconstructionElement'] + print: ({ node, path, print, options }) => [ + 'TODO: TupleDeconstructionElement' + ] }; diff --git a/src/slang-nodes/TupleDeconstructionElements.js b/src/slang-nodes/TupleDeconstructionElements.js index a25540d02..4dd5ad6a6 100644 --- a/src/slang-nodes/TupleDeconstructionElements.js +++ b/src/slang-nodes/TupleDeconstructionElements.js @@ -5,5 +5,7 @@ export const TupleDeconstructionElements = { separators: ast.separators.map((separator) => separator.text) }), // TODO: implement print - print: () => ['TODO: TupleDeconstructionElements'] + print: ({ node, path, print, options }) => [ + 'TODO: TupleDeconstructionElements' + ] }; diff --git a/src/slang-nodes/TupleDeconstructionStatement.js b/src/slang-nodes/TupleDeconstructionStatement.js index 2d41d2058..a6c861996 100644 --- a/src/slang-nodes/TupleDeconstructionStatement.js +++ b/src/slang-nodes/TupleDeconstructionStatement.js @@ -10,5 +10,7 @@ export const TupleDeconstructionStatement = { semicolon: ast.semicolon.text }), // TODO: implement print - print: () => ['TODO: TupleDeconstructionStatement'] + print: ({ node, path, print, options }) => [ + 'TODO: TupleDeconstructionStatement' + ] }; diff --git a/src/slang-nodes/TypeExpression.js b/src/slang-nodes/TypeExpression.js index 61788c3cf..31e579741 100644 --- a/src/slang-nodes/TypeExpression.js +++ b/src/slang-nodes/TypeExpression.js @@ -7,5 +7,5 @@ export const TypeExpression = { closeParen: ast.closeParen.text }), // TODO: implement print - print: () => ['TODO: TypeExpression'] + print: ({ node, path, print, options }) => ['TODO: TypeExpression'] }; diff --git a/src/slang-nodes/UncheckedBlock.js b/src/slang-nodes/UncheckedBlock.js index 997da0aaa..e304b440a 100644 --- a/src/slang-nodes/UncheckedBlock.js +++ b/src/slang-nodes/UncheckedBlock.js @@ -5,5 +5,5 @@ export const UncheckedBlock = { block: parse(ast.block, options, parse) }), // TODO: implement print - print: () => ['TODO: UncheckedBlock'] + print: ({ node, path, print, options }) => ['TODO: UncheckedBlock'] }; diff --git a/src/slang-nodes/UnicodeStringLiterals.js b/src/slang-nodes/UnicodeStringLiterals.js index 8dde9dd0a..b9154b4f8 100644 --- a/src/slang-nodes/UnicodeStringLiterals.js +++ b/src/slang-nodes/UnicodeStringLiterals.js @@ -4,5 +4,5 @@ export const UnicodeStringLiterals = { items: ast.items.map((item) => parse(item, options, parse)) }), // TODO: implement print - print: () => ['TODO: UnicodeStringLiterals'] + print: ({ node, path, print, options }) => ['TODO: UnicodeStringLiterals'] }; diff --git a/src/slang-nodes/UntypedTupleMember.js b/src/slang-nodes/UntypedTupleMember.js index fec374c64..b8707386d 100644 --- a/src/slang-nodes/UntypedTupleMember.js +++ b/src/slang-nodes/UntypedTupleMember.js @@ -7,5 +7,7 @@ export const UntypedTupleMember = { name: ast.name.text }), // TODO: implement print - print: () => ['TODO: UntypedTupleMemberUntypedTupleMember'] + print: ({ node, path, print, options }) => [ + 'TODO: UntypedTupleMemberUntypedTupleMember' + ] }; diff --git a/src/slang-nodes/UserDefinedValueTypeDefinition.js b/src/slang-nodes/UserDefinedValueTypeDefinition.js index 81c1bc827..4dd58a5ba 100644 --- a/src/slang-nodes/UserDefinedValueTypeDefinition.js +++ b/src/slang-nodes/UserDefinedValueTypeDefinition.js @@ -8,5 +8,7 @@ export const UserDefinedValueTypeDefinition = { semicolon: ast.semicolon.text }), // TODO: implement print - print: () => ['TODO: UserDefinedValueTypeDefinition'] + print: ({ node, path, print, options }) => [ + 'TODO: UserDefinedValueTypeDefinition' + ] }; diff --git a/src/slang-nodes/UsingAlias.js b/src/slang-nodes/UsingAlias.js index 48f90a636..6bf584658 100644 --- a/src/slang-nodes/UsingAlias.js +++ b/src/slang-nodes/UsingAlias.js @@ -5,5 +5,5 @@ export const UsingAlias = { operator: parse(ast.operator, options, parse) }), // TODO: implement print - print: () => ['TODO: UsingAlias'] + print: ({ node, path, print, options }) => ['TODO: UsingAlias'] }; diff --git a/src/slang-nodes/VersionRange.js b/src/slang-nodes/VersionRange.js index 596b92e4d..81d8626c8 100644 --- a/src/slang-nodes/VersionRange.js +++ b/src/slang-nodes/VersionRange.js @@ -6,5 +6,5 @@ export const VersionRange = { rightOperand: parse(ast.rightOperand, options, parse) }), // TODO: implement print - print: () => ['TODO: VersionRange'] + print: ({ node, path, print, options }) => ['TODO: VersionRange'] }; diff --git a/src/slang-nodes/YulColonAndEqual.js b/src/slang-nodes/YulColonAndEqual.js index d71929aa6..193ec82b2 100644 --- a/src/slang-nodes/YulColonAndEqual.js +++ b/src/slang-nodes/YulColonAndEqual.js @@ -5,5 +5,5 @@ export const YulColonAndEqual = { equal: ast.equal.text }), // TODO: implement print - print: () => ['TODO: YulColonAndEqual'] + print: ({ node, path, print, options }) => ['TODO: YulColonAndEqual'] }; diff --git a/src/slang-nodes/YulLeaveStatement.js b/src/slang-nodes/YulLeaveStatement.js index bf6939c28..f8d140db1 100644 --- a/src/slang-nodes/YulLeaveStatement.js +++ b/src/slang-nodes/YulLeaveStatement.js @@ -4,5 +4,5 @@ export const YulLeaveStatement = { leaveKeyword: ast.leaveKeyword.text }), // TODO: implement print - print: () => ['TODO: YulLeaveStatement'] + print: ({ node, path, print, options }) => ['TODO: YulLeaveStatement'] }; diff --git a/tests/format/MultipartStrings/__snapshots__/jsfmt.spec.js.snap b/tests/format/MultipartStrings/__snapshots__/jsfmt.spec.js.snap index 72f515f66..d17d7e113 100644 --- a/tests/format/MultipartStrings/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/MultipartStrings/__snapshots__/jsfmt.spec.js.snap @@ -37,3 +37,36 @@ contract MultipartStrings { ================================================================================ `; + +exports[`MultipartStrings.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +contract MultipartStrings { + bytes b1 = hex'beef'; + bytes b2 = hex"beef"; + bytes b3 = hex"beef" hex"c0ffee"; + bytes b4 = hex"beeeeeeeeeeeeeeeeeeeeeef" hex"c0000000000ffeeeeeeeeeeeeeeeeeee"; + + string s1 = "foo"; + string s2 = "foo" "bar"; + string s3 = "foofoofoofooofoofoofofoooofofoo" "barbarbrabrbarbarbabrabrbabr"; +} + +=====================================output===================================== +contract MultipartStrings { + bytes b1 = hex"beef"; + bytes b2 = hex"beef"; + bytes b3 = hex"beef" hex"c0ffee"; + bytes b4 = hex"beeeeeeeeeeeeeeeeeeeeeef" + hex"c0000000000ffeeeeeeeeeeeeeeeeeee"; + string s1 = "foo"; + string s2 = "foo" "bar"; + string s3 = "foofoofoofooofoofoofofoooofofoo" + "barbarbrabrbarbarbabrabrbabr"; +} + +================================================================================ +`; diff --git a/tests/format/MultipartStrings/jsfmt.spec.js b/tests/format/MultipartStrings/jsfmt.spec.js index 765dd60a6..fd56c17bc 100644 --- a/tests/format/MultipartStrings/jsfmt.spec.js +++ b/tests/format/MultipartStrings/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse']); diff --git a/tests/format/NumberLiteral/__snapshots__/jsfmt.spec.js.snap b/tests/format/NumberLiteral/__snapshots__/jsfmt.spec.js.snap index be4698f25..e40fbabd7 100644 --- a/tests/format/NumberLiteral/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/NumberLiteral/__snapshots__/jsfmt.spec.js.snap @@ -37,3 +37,39 @@ contract NumberLiteral { ================================================================================ `; + +exports[`NumberLiteral.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +// SPDX-License-Identifier: MIT +pragma solidity 0.8.25; + +contract NumberLiteral { + function numbers()public { + 2 ether; + 5 days; + 2.3e5; + 1000000e-2; + .1; + 1_000_000; + } +} + +=====================================output===================================== +pragma solidity 0.8.25; +contract NumberLiteral { + function numbers() public { + 2 ether; + 5 days; + 2.3e5; + 1000000e-2; + .1; + 1_000_000; + } +} + +================================================================================ +`; diff --git a/tests/format/NumberLiteral/jsfmt.spec.js b/tests/format/NumberLiteral/jsfmt.spec.js index 765dd60a6..fd56c17bc 100644 --- a/tests/format/NumberLiteral/jsfmt.spec.js +++ b/tests/format/NumberLiteral/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse']); From d24ea6b2d56077a1d99111edc09a3679acd07279 Mon Sep 17 00:00:00 2001 From: Klaus Date: Thu, 30 May 2024 01:12:34 +1200 Subject: [PATCH 017/160] WIP: 183/213 printers implemented --- src/slang-nodes/CatchClause.js | 7 +- src/slang-nodes/CatchClauseError.js | 7 +- src/slang-nodes/CatchClauses.js | 7 +- src/slang-nodes/MappingKey.js | 6 +- src/slang-nodes/MappingType.js | 9 +- src/slang-nodes/MappingValue.js | 6 +- src/slang-nodes/NamedArgumentGroup.js | 7 +- src/slang-nodes/NamedArguments.js | 5 +- src/slang-nodes/NamedArgumentsDeclaration.js | 7 +- src/slang-nodes/TryStatement.js | 17 +- src/slang-nodes/UnicodeStringLiteral.js | 6 +- src/slang-nodes/UnicodeStringLiterals.js | 7 +- .../Proxy/__snapshots__/jsfmt.spec.js.snap | 89 ++++++++ tests/format/Proxy/jsfmt.spec.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 37 ++++ tests/format/SimpleStorage/jsfmt.spec.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 18 ++ .../StateVariableDeclarations/jsfmt.spec.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 34 +++ tests/format/StringLiteral/jsfmt.spec.js | 1 + .../TryCatch/__snapshots__/jsfmt.spec.js.snap | 204 ++++++++++++++++++ tests/format/TryCatch/jsfmt.spec.js | 1 + 22 files changed, 454 insertions(+), 24 deletions(-) diff --git a/src/slang-nodes/CatchClause.js b/src/slang-nodes/CatchClause.js index f399b86a7..8aa86510d 100644 --- a/src/slang-nodes/CatchClause.js +++ b/src/slang-nodes/CatchClause.js @@ -5,6 +5,9 @@ export const CatchClause = { error: ast.error ? parse(ast.error, options, parse) : undefined, body: parse(ast.body, options, parse) }), - // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: CatchClause'] + print: ({ node, path, print }) => [ + node.catchKeyword, + node.error ? [' ', path.call(print, 'error')] : '', + path.call(print, 'body') + ] }; diff --git a/src/slang-nodes/CatchClauseError.js b/src/slang-nodes/CatchClauseError.js index 1c6d56174..87a482f28 100644 --- a/src/slang-nodes/CatchClauseError.js +++ b/src/slang-nodes/CatchClauseError.js @@ -4,6 +4,9 @@ export const CatchClauseError = { name: ast.name?.text, parameters: parse(ast.parameters, options, parse) }), - // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: CatchClauseError'] + print: ({ node, path, print }) => [ + node.name ? node.name : '', + path.call(print, 'parameters'), + ' ' + ] }; diff --git a/src/slang-nodes/CatchClauses.js b/src/slang-nodes/CatchClauses.js index aeadb2b77..2a8050f66 100644 --- a/src/slang-nodes/CatchClauses.js +++ b/src/slang-nodes/CatchClauses.js @@ -1,8 +1,11 @@ +import { doc } from 'prettier'; + +const { join } = doc.builders; + export const CatchClauses = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), - // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: CatchClauses'] + print: ({ path, print }) => join(' ', path.map(print, 'items')) }; diff --git a/src/slang-nodes/MappingKey.js b/src/slang-nodes/MappingKey.js index 943e5c56c..e06e0d517 100644 --- a/src/slang-nodes/MappingKey.js +++ b/src/slang-nodes/MappingKey.js @@ -4,6 +4,8 @@ export const MappingKey = { keyType: parse(ast.keyType, options, parse), name: ast.name?.text }), - // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: MappingKey'] + print: ({ node, path, print }) => [ + path.call(print, 'keyType'), + node.name ? ` ${node.name}` : '' + ] }; diff --git a/src/slang-nodes/MappingType.js b/src/slang-nodes/MappingType.js index 8a2bae0dc..556bfa156 100644 --- a/src/slang-nodes/MappingType.js +++ b/src/slang-nodes/MappingType.js @@ -8,6 +8,11 @@ export const MappingType = { valueType: parse(ast.valueType, options, parse), closeParen: ast.closeParen.text }), - // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: MappingType'] + print: ({ node, path, print }) => [ + `${node.mappingKeyword}${node.openParen}`, + path.call(print, 'keyType'), + ` ${node.equalGreaterThan} `, + path.call(print, 'valueType'), + node.closeParen + ] }; diff --git a/src/slang-nodes/MappingValue.js b/src/slang-nodes/MappingValue.js index fee2bc772..87c0ea02c 100644 --- a/src/slang-nodes/MappingValue.js +++ b/src/slang-nodes/MappingValue.js @@ -4,6 +4,8 @@ export const MappingValue = { typeName: parse(ast.typeName, options, parse), name: ast.name?.text }), - // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: MappingValue'] + print: ({ node, path, print }) => [ + path.call(print, 'typeName'), + node.name ? ` ${node.name}` : '' + ] }; diff --git a/src/slang-nodes/NamedArgumentGroup.js b/src/slang-nodes/NamedArgumentGroup.js index e9fb180b3..901cb8a87 100644 --- a/src/slang-nodes/NamedArgumentGroup.js +++ b/src/slang-nodes/NamedArgumentGroup.js @@ -5,6 +5,9 @@ export const NamedArgumentGroup = { arguments: parse(ast.arguments, options, parse), closeBrace: ast.closeBrace.text }), - // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: NamedArgumentGroup'] + print: ({ node, path, print }) => [ + node.openBrace, + path.call(print, 'arguments'), + node.closeBrace + ] }; diff --git a/src/slang-nodes/NamedArguments.js b/src/slang-nodes/NamedArguments.js index 61041871f..d38781d50 100644 --- a/src/slang-nodes/NamedArguments.js +++ b/src/slang-nodes/NamedArguments.js @@ -1,9 +1,10 @@ +import { printSeparatedList } from '../common/printer-helpers.js'; + export const NamedArguments = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), - // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: NamedArguments'] + print: ({ path, print }) => printSeparatedList(path.map(print, 'items')) }; diff --git a/src/slang-nodes/NamedArgumentsDeclaration.js b/src/slang-nodes/NamedArgumentsDeclaration.js index 7112c0ee5..68d7d25ea 100644 --- a/src/slang-nodes/NamedArgumentsDeclaration.js +++ b/src/slang-nodes/NamedArgumentsDeclaration.js @@ -5,6 +5,9 @@ export const NamedArgumentsDeclaration = { arguments: ast.arguments ? parse(ast.arguments, options, parse) : undefined, closeParen: ast.closeParen.text }), - // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: NamedArgumentsDeclaration'] + print: ({ node, path, print }) => [ + node.openParen, + node.arguments ? path.call(print, 'arguments') : '', + node.closeParen + ] }; diff --git a/src/slang-nodes/TryStatement.js b/src/slang-nodes/TryStatement.js index b3a415350..0d2056fb7 100644 --- a/src/slang-nodes/TryStatement.js +++ b/src/slang-nodes/TryStatement.js @@ -1,3 +1,8 @@ +import { doc } from 'prettier'; +import { printSeparatedItem } from '../common/printer-helpers.js'; + +const { line } = doc.builders; + export const TryStatement = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, @@ -7,6 +12,14 @@ export const TryStatement = { body: parse(ast.body, options, parse), catchClauses: parse(ast.catchClauses, options, parse) }), - // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: TryStatement'] + print: ({ node, path, print }) => [ + node.tryKeyword, + printSeparatedItem(path.call(print, 'expression'), { + firstSeparator: line + }), + node.returns ? path.call(print, 'returns') : '', + path.call(print, 'body'), + ' ', + path.call(print, 'catchClauses') + ] }; diff --git a/src/slang-nodes/UnicodeStringLiteral.js b/src/slang-nodes/UnicodeStringLiteral.js index 32e1fc458..865bbeb8e 100644 --- a/src/slang-nodes/UnicodeStringLiteral.js +++ b/src/slang-nodes/UnicodeStringLiteral.js @@ -1,7 +1,9 @@ export const UnicodeStringLiteral = { - parse: ({ ast }) => ({ + parse: ({ ast, options }) => ({ kind: ast.cst.kind, - variant: ast.variant.text + variant: options.singleQuote + ? `unicode'${ast.variant.text.slice(8, -1)}'` + : `unicode"${ast.variant.text.slice(8, -1)}"` }), print: ({ node }) => node.variant }; diff --git a/src/slang-nodes/UnicodeStringLiterals.js b/src/slang-nodes/UnicodeStringLiterals.js index b9154b4f8..70dbb7364 100644 --- a/src/slang-nodes/UnicodeStringLiterals.js +++ b/src/slang-nodes/UnicodeStringLiterals.js @@ -1,8 +1,11 @@ +import { doc } from 'prettier'; + +const { group, join, line } = doc.builders; + export const UnicodeStringLiterals = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), - // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: UnicodeStringLiterals'] + print: ({ path, print }) => group(join(line, path.map(print, 'items'))) }; diff --git a/tests/format/Proxy/__snapshots__/jsfmt.spec.js.snap b/tests/format/Proxy/__snapshots__/jsfmt.spec.js.snap index 41521a072..3788c8b30 100644 --- a/tests/format/Proxy/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Proxy/__snapshots__/jsfmt.spec.js.snap @@ -1,5 +1,94 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Proxy.sol - {"compiler":"0.4.26"} format 1`] = ` +====================================options===================================== +compiler: "0.4.26" +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity ^0.4.24; + +/** + * @title Proxy + * @dev Gives the possibility to delegate any call to a foreign implementation. + */ +contract Proxy { + + /** + * @dev Tells the address of the implementation where every call will be delegated. + * @return address of the implementation to which it will be delegated + */ + function _implementation() internal view returns (address); + + /** + * @dev Fallback function. + * Implemented entirely in \`_fallback\`. + */ + function _fallback() internal { + _delegate(_implementation()); + } + + /** + * @dev Fallback function allowing to perform a delegatecall to the given implementation. + * This function will return whatever the implementation call returns + */ + function _delegate(address implementation) internal { + /*solium-disable-next-line security/no-inline-assembly*/ + assembly { + // Copy msg.data. We take full control of memory in this inline assembly + // block because it will not return to Solidity code. We overwrite the + // Solidity scratch pad at memory position 0. + calldatacopy(0, 0, calldatasize) + + // Call the implementation. + // out and outsize are 0 because we don't know the size yet. + let result := delegatecall(gas, implementation, 0, calldatasize, 0, 0) + + // Copy the returned data. + returndatacopy(0, 0, returndatasize) + + switch result + // delegatecall returns 0 on error. + case 0 { revert(0, returndatasize) } + default { return(0, returndatasize) } + } + } + + function () public payable { + _fallback(); + } +} + +=====================================output===================================== +pragma solidity ^0.4.24; +contract Proxy { + function _implementation() internal view returns (address); + function _fallback() internal { + _delegate(_implementation()); + } + function _delegate(address implementation) internal { + assembly { + calldatacopy(0,0,calldatasize) + let result := delegatecall(gas,implementation,0,calldatasize,0,0) + returndatacopy(0,0,returndatasize) + switch result + case 0 { + revert(0,returndatasize) + } + default { + return(0,returndatasize) + } + } + } + function() public payable { + _fallback(); + } +} + +================================================================================ +`; + exports[`Proxy.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] diff --git a/tests/format/Proxy/jsfmt.spec.js b/tests/format/Proxy/jsfmt.spec.js index 765dd60a6..18602c4e5 100644 --- a/tests/format/Proxy/jsfmt.spec.js +++ b/tests/format/Proxy/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse'], { compiler: '0.4.26' }); diff --git a/tests/format/SimpleStorage/__snapshots__/jsfmt.spec.js.snap b/tests/format/SimpleStorage/__snapshots__/jsfmt.spec.js.snap index ab685ce2d..0d0ede279 100644 --- a/tests/format/SimpleStorage/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/SimpleStorage/__snapshots__/jsfmt.spec.js.snap @@ -39,3 +39,40 @@ contract SimpleStorage { ================================================================================ `; + +exports[`SimpleStorage.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity ^0.4.0; + +contract SimpleStorage { + string public name = "SimpleStorage"; + uint storedData; + + function set(uint x) public { + storedData = x; + } + + function get() public view returns (uint) { + return storedData; + } +} + +=====================================output===================================== +pragma solidity ^0.4.0; +contract SimpleStorage { + string public name = "SimpleStorage"; + uint storedData; + function set(uint x) public { + storedData = x; + } + function get() public view returns (uint) { + return storedData; + } +} + +================================================================================ +`; diff --git a/tests/format/SimpleStorage/jsfmt.spec.js b/tests/format/SimpleStorage/jsfmt.spec.js index 765dd60a6..fd56c17bc 100644 --- a/tests/format/SimpleStorage/jsfmt.spec.js +++ b/tests/format/SimpleStorage/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse']); diff --git a/tests/format/StateVariableDeclarations/__snapshots__/jsfmt.spec.js.snap b/tests/format/StateVariableDeclarations/__snapshots__/jsfmt.spec.js.snap index 9f48a411d..2b25015ea 100644 --- a/tests/format/StateVariableDeclarations/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/StateVariableDeclarations/__snapshots__/jsfmt.spec.js.snap @@ -18,3 +18,21 @@ contract Contract { ================================================================================ `; + +exports[`StateVariableDeclarations.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +contract Contract { + bytes32 private constant DOMAIN_SEPARATOR_TYPEHASH = 0x035aff83d86937d35b32e04f0ddc6ff469290eef2f1b692d8a815c89404d4749; +} + +=====================================output===================================== +contract Contract { + bytes32 privateconstant DOMAIN_SEPARATOR_TYPEHASH = 0x035aff83d86937d35b32e04f0ddc6ff469290eef2f1b692d8a815c89404d4749; +} + +================================================================================ +`; diff --git a/tests/format/StateVariableDeclarations/jsfmt.spec.js b/tests/format/StateVariableDeclarations/jsfmt.spec.js index 765dd60a6..fd56c17bc 100644 --- a/tests/format/StateVariableDeclarations/jsfmt.spec.js +++ b/tests/format/StateVariableDeclarations/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse']); diff --git a/tests/format/StringLiteral/__snapshots__/jsfmt.spec.js.snap b/tests/format/StringLiteral/__snapshots__/jsfmt.spec.js.snap index 704ec50db..838c79901 100644 --- a/tests/format/StringLiteral/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/StringLiteral/__snapshots__/jsfmt.spec.js.snap @@ -34,3 +34,37 @@ contract StringLiteral { ================================================================================ `; + +exports[`StringLiteral.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +contract StringLiteral { + bytes32 public constant PERMIT_TYPEHASH = keccak256( + "Permit(" + "address owner," + "address spender," + "uint256 value," + "uint256 nonce," + "uint256 deadline" + ")" + ); +} + +=====================================output===================================== +contract StringLiteral { + bytes32 publicconstant PERMIT_TYPEHASH = keccak256( + "Permit(" + "address owner," + "address spender," + "uint256 value," + "uint256 nonce," + "uint256 deadline" + ")" + ); +} + +================================================================================ +`; diff --git a/tests/format/StringLiteral/jsfmt.spec.js b/tests/format/StringLiteral/jsfmt.spec.js index 765dd60a6..fd56c17bc 100644 --- a/tests/format/StringLiteral/jsfmt.spec.js +++ b/tests/format/StringLiteral/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse']); diff --git a/tests/format/TryCatch/__snapshots__/jsfmt.spec.js.snap b/tests/format/TryCatch/__snapshots__/jsfmt.spec.js.snap index 72355b966..a39f33f38 100644 --- a/tests/format/TryCatch/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/TryCatch/__snapshots__/jsfmt.spec.js.snap @@ -222,3 +222,207 @@ contract FeedConsumer { ================================================================================ `; + +exports[`TryCatch.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity ^0.6.0; + +interface DataFeed { function getData(address token) external returns (uint value); } + +contract FeedConsumer { + DataFeed feed; + uint errorCount; + function rate(address token) public returns (uint value, bool success) { + // Permanently disable the mechanism if there are + // more than 10 errors. + require(errorCount < 10); + try feed.getData(token) + returns (uint v) { + return (v, true); + } catch + Error(string memory /*reason*/) + { + // This is executed in case + // revert was called inside getData + // and a reason string was provided. + errorCount++; + return (0, false); + } catch (bytes memory /*lowLevelData*/ + ) { + // This is executed in case revert() was used + // or there was a failing assertion, division + // by zero, etc. inside getData. + errorCount++; + return (0, false); + } } + + function rate2(address token) public returns (uint value, bool success) { + // Permanently disable the mechanism if there are + // more than 10 errors. + require(errorCount < 10); + try feed.getData(token) + returns (uint v, uint v1,uint v2,uint v3,uint v4,uint v5,uint v6,uint v7,uint v8) { + return (v, true); + } catch + Error(string memory /*reason*/) + { + // This is executed in case + // revert was called inside getData + // and a reason string was provided. + errorCount++; + return (0, false); + } catch (bytes memory /*lowLevelData*/ + ) { + // This is executed in case revert() was used + // or there was a failing assertion, division + // by zero, etc. inside getData. + errorCount++; + return (0, false); + } } + + function rate3(address token) public returns (uint value, bool success) { + // Permanently disable the mechanism if there are + // more than 10 errors. + require(errorCount < 10); + try feed.getData(token) { + return (v, true); + } catch + Error(string memory /*reason*/) + { + // This is executed in case + // revert was called inside getData + // and a reason string was provided. + errorCount++; + return (0, false); + } catch { + // This is executed in case revert() was used + // or there was a failing assertion, division + // by zero, etc. inside getData. + errorCount++; + return (0, false); + } } + + function rate4(address token) public returns (uint value, bool success) { + // Permanently disable the mechanism if there are + // more than 10 errors. + require(errorCount < 10); + try feed.getData(token) returns (uint v) { + return (v, true); + } catch Error(string memory /*reason*/) { + // This is executed in case + // revert was called inside getData + // and a reason string was provided. + errorCount++; + return (0, false); + } catch Panic(uint /*errorCode*/) { + // This is executed in case of a panic, + // i.e. a serious error like division by zero + // or overflow. The error code can be used + // to determine the kind of error. + errorCount++; + return (0, false); + } catch (bytes memory /*lowLevelData*/) { + // This is executed in case revert() was used. + errorCount++; + return (0, false); + } + } +} + +=====================================output===================================== +pragma solidity ^0.6.0; +interface DataFeed { + function getData(address token) external returns (uint value); +} +contract FeedConsumer { + DataFeed feed; + uint errorCount; + function rate(address token) public returns (uint value, bool success) { + require(errorCount < 10); + try feed.getData(token) returns ( + uint v + ){ + return (v, true); + } catch Error( + string memory + ) { + errorCount++; + return (0, false); + } catch ( + bytes memory + ) { + errorCount++; + return (0, false); + } + } + function rate2(address token) public returns (uint value, bool success) { + require(errorCount < 10); + try feed.getData(token) returns ( + uint v, + uint v1, + uint v2, + uint v3, + uint v4, + uint v5, + uint v6, + uint v7, + uint v8 + ){ + return (v, true); + } catch Error( + string memory + ) { + errorCount++; + return (0, false); + } catch ( + bytes memory + ) { + errorCount++; + return (0, false); + } + } + function rate3(address token) public returns (uint value, bool success) { + require(errorCount < 10); + try feed.getData(token) { + return (v, true); + } catch Error( + string memory + ) { + errorCount++; + return (0, false); + } catch{ + errorCount++; + return (0, false); + } + } + function rate4(address token) public returns (uint value, bool success) { + require(errorCount < 10); + try feed.getData(token) returns ( + uint v + ){ + return (v, true); + } catch Error( + string memory + ) { + errorCount++; + return (0, false); + } catch Panic( + uint + ) { + errorCount++; + return (0, false); + } catch ( + bytes memory + ) { + errorCount++; + return (0, false); + } + } +} + +================================================================================ +`; diff --git a/tests/format/TryCatch/jsfmt.spec.js b/tests/format/TryCatch/jsfmt.spec.js index 765dd60a6..fd56c17bc 100644 --- a/tests/format/TryCatch/jsfmt.spec.js +++ b/tests/format/TryCatch/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse']); From a239f8aae5403d75c950c8e6c965ad4a4d1e7a86 Mon Sep 17 00:00:00 2001 From: Klaus Date: Thu, 30 May 2024 01:41:31 +1200 Subject: [PATCH 018/160] WIP: 188/213 printers implemented --- src/slang-nodes/DoWhileStatement.js | 19 +++- src/slang-nodes/TupleDeconstructionElement.js | 6 +- .../TupleDeconstructionElements.js | 7 +- .../TupleDeconstructionStatement.js | 10 +- src/slang-nodes/TypedTupleMember.js | 4 +- .../UserDefinedValueTypeDefinition.js | 7 +- .../Tupples/__snapshots__/jsfmt.spec.js.snap | 61 ++++++++++++ tests/format/Tupples/jsfmt.spec.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 33 +++++++ tests/format/TypeDefinition/jsfmt.spec.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 96 +++++++++++++++++++ tests/format/WhileStatements/jsfmt.spec.js | 1 + 12 files changed, 228 insertions(+), 18 deletions(-) diff --git a/src/slang-nodes/DoWhileStatement.js b/src/slang-nodes/DoWhileStatement.js index 0d53c2b47..674709c80 100644 --- a/src/slang-nodes/DoWhileStatement.js +++ b/src/slang-nodes/DoWhileStatement.js @@ -1,3 +1,13 @@ +import { doc } from 'prettier'; +import { printSeparatedItem } from '../common/printer-helpers.js'; + +const { group, indent, line } = doc.builders; + +const printBody = (node, path, print) => + node.body.variant.kind === 'Block' + ? [' ', path.call(print, 'body'), ' '] + : group([indent([line, path.call(print, 'body')]), line]); + export const DoWhileStatement = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, @@ -9,6 +19,11 @@ export const DoWhileStatement = { closeParen: ast.closeParen.text, semicolon: ast.semicolon.text }), - // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: DoWhileStatement'] + print: ({ node, path, print }) => [ + node.doKeyword, + printBody(node, path, print), + `${node.whileKeyword} ${node.openParen}`, + printSeparatedItem(path.call(print, 'condition')), + `${node.closeParen}${node.semicolon}` + ] }; diff --git a/src/slang-nodes/TupleDeconstructionElement.js b/src/slang-nodes/TupleDeconstructionElement.js index 6fac5f760..d59b86766 100644 --- a/src/slang-nodes/TupleDeconstructionElement.js +++ b/src/slang-nodes/TupleDeconstructionElement.js @@ -3,8 +3,6 @@ export const TupleDeconstructionElement = { kind: ast.cst.kind, member: ast.member ? parse(ast.member, options, parse) : undefined }), - // TODO: implement print - print: ({ node, path, print, options }) => [ - 'TODO: TupleDeconstructionElement' - ] + print: ({ node, path, print }) => + node.member ? path.call(print, 'member') : '' }; diff --git a/src/slang-nodes/TupleDeconstructionElements.js b/src/slang-nodes/TupleDeconstructionElements.js index 4dd5ad6a6..726a5ad05 100644 --- a/src/slang-nodes/TupleDeconstructionElements.js +++ b/src/slang-nodes/TupleDeconstructionElements.js @@ -1,11 +1,10 @@ +import { printSeparatedList } from '../common/printer-helpers.js'; + export const TupleDeconstructionElements = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), - // TODO: implement print - print: ({ node, path, print, options }) => [ - 'TODO: TupleDeconstructionElements' - ] + print: ({ path, print }) => printSeparatedList(path.map(print, 'items')) }; diff --git a/src/slang-nodes/TupleDeconstructionStatement.js b/src/slang-nodes/TupleDeconstructionStatement.js index a6c861996..d6552523f 100644 --- a/src/slang-nodes/TupleDeconstructionStatement.js +++ b/src/slang-nodes/TupleDeconstructionStatement.js @@ -9,8 +9,12 @@ export const TupleDeconstructionStatement = { expression: parse(ast.expression, options, parse), semicolon: ast.semicolon.text }), - // TODO: implement print - print: ({ node, path, print, options }) => [ - 'TODO: TupleDeconstructionStatement' + print: ({ node, path, print }) => [ + node.varKeyword ? node.varKeyword : '', + node.openParen, + path.call(print, 'elements'), + `${node.closeParen} ${node.equal} `, + path.call(print, 'expression'), + node.semicolon ] }; diff --git a/src/slang-nodes/TypedTupleMember.js b/src/slang-nodes/TypedTupleMember.js index c468cd0a4..aa7c5ce20 100644 --- a/src/slang-nodes/TypedTupleMember.js +++ b/src/slang-nodes/TypedTupleMember.js @@ -9,7 +9,7 @@ export const TypedTupleMember = { }), print: ({ node, path, print }) => [ path.call(print, 'typeName'), - node.storageLocation ? path.call(print, 'storageLocation') : '', - node.name + node.storageLocation ? [' ', path.call(print, 'storageLocation')] : '', + ` ${node.name}` ] }; diff --git a/src/slang-nodes/UserDefinedValueTypeDefinition.js b/src/slang-nodes/UserDefinedValueTypeDefinition.js index 4dd58a5ba..bd584a387 100644 --- a/src/slang-nodes/UserDefinedValueTypeDefinition.js +++ b/src/slang-nodes/UserDefinedValueTypeDefinition.js @@ -7,8 +7,9 @@ export const UserDefinedValueTypeDefinition = { valueType: parse(ast.valueType, options, parse), semicolon: ast.semicolon.text }), - // TODO: implement print - print: ({ node, path, print, options }) => [ - 'TODO: UserDefinedValueTypeDefinition' + print: ({ node, path, print }) => [ + `${node.typeKeyword} ${node.name} ${node.isKeyword} `, + path.call(print, 'valueType'), + node.semicolon ] }; diff --git a/tests/format/Tupples/__snapshots__/jsfmt.spec.js.snap b/tests/format/Tupples/__snapshots__/jsfmt.spec.js.snap index 4ddda35fc..c8cbbce4f 100644 --- a/tests/format/Tupples/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Tupples/__snapshots__/jsfmt.spec.js.snap @@ -62,3 +62,64 @@ contract Tupples { ================================================================================ `; + +exports[`Tupples.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity ^0.5.0; + +contract demo { + function hello() public view returns(bool,bool) {} + function hello2() public view returns(bool) {} + function hello3() public view returns(bool,bool,bool) {} + +} + +contract Tupples { + function world(address payable _yo) public view { + bool yo; + yo = demo(_yo).hello2(); + (yo, ) = demo(_yo).hello(); + (, yo) = demo(_yo).hello(); + (yo, , yo) = demo(_yo).hello3(); + (yo, yo) = demo(_yo).hello(); + (string memory holderId, +string memory containerId, +string memory parentContainerId, +bytes32 volumeId, +bytes32 subUnitId, +bytes32 requestId) = getParamsById(paramsId); + } +} + +=====================================output===================================== +pragma solidity ^0.5.0; +contract demo { + function hello() public view returns (bool, bool) {} + function hello2() public view returns (bool) {} + function hello3() public view returns (bool, bool, bool) {} +} +contract Tupples { + function world(address payable _yo) public view { + bool yo; + yo = demo(_yo).hello2(); + (yo, ) = demo(_yo).hello(); + (, yo) = demo(_yo).hello(); + (yo, , yo) = demo(_yo).hello3(); + (yo, yo) = demo(_yo).hello(); + ( + string memory holderId, + string memory containerId, + string memory parentContainerId, + bytes32 volumeId, + bytes32 subUnitId, + bytes32 requestId + ) = getParamsById(paramsId); + } +} + +================================================================================ +`; diff --git a/tests/format/Tupples/jsfmt.spec.js b/tests/format/Tupples/jsfmt.spec.js index 765dd60a6..fd56c17bc 100644 --- a/tests/format/Tupples/jsfmt.spec.js +++ b/tests/format/Tupples/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse']); diff --git a/tests/format/TypeDefinition/__snapshots__/jsfmt.spec.js.snap b/tests/format/TypeDefinition/__snapshots__/jsfmt.spec.js.snap index 04e77a23d..400475d96 100644 --- a/tests/format/TypeDefinition/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/TypeDefinition/__snapshots__/jsfmt.spec.js.snap @@ -35,3 +35,36 @@ contract TypeDefinition { ================================================================================ `; + +exports[`TypeDefinition.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity ^0.8.8; + + type Hello is uint; + +contract TypeDefinition { + event Moon(Hello world); + + function demo(Hello world) public { + world = Hello.wrap(Hello.unwrap(world) + 1337); + emit Moon(world); + } +} + +=====================================output===================================== +pragma solidity ^0.8.8; +type Hello is uint; +contract TypeDefinition { + event Moon(Hello world); + function demo(Hello world) public { + world = Hello.wrap(Hello.unwrap(world) + 1337); + emit Moon(world); + } +} + +================================================================================ +`; diff --git a/tests/format/TypeDefinition/jsfmt.spec.js b/tests/format/TypeDefinition/jsfmt.spec.js index 765dd60a6..fd56c17bc 100644 --- a/tests/format/TypeDefinition/jsfmt.spec.js +++ b/tests/format/TypeDefinition/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse']); diff --git a/tests/format/WhileStatements/__snapshots__/jsfmt.spec.js.snap b/tests/format/WhileStatements/__snapshots__/jsfmt.spec.js.snap index e13595552..29831e2a2 100644 --- a/tests/format/WhileStatements/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/WhileStatements/__snapshots__/jsfmt.spec.js.snap @@ -108,3 +108,99 @@ contract WhileStatements { ================================================================================ `; + +exports[`WhileStatements.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +contract WhileStatements { + uint constant LONG_VARIABLE = 1; + + function whileStatements() public { + uint a; + uint veryLongVariableName; + + while (a < 100) a++; + + while (a < 200) a = a.add(LONG_VARIABLE).add(LONG_VARIABLE).add(LONG_VARIABLE); + + while (a < 300) { a++; } + + while (a < 400) { a = a.add(LONG_VARIABLE).add(LONG_VARIABLE).add(LONG_VARIABLE); } + + while (a < veryLongVariableName.add(LONG_VARIABLE).add(LONG_VARIABLE) * 500) a++; + + while (a < veryLongVariableName.add(LONG_VARIABLE).add(LONG_VARIABLE) * 600) { a++; } + } + + function doWhileStatements() public { + uint a; + uint veryLongVariableName; + + do a++; while (a < 100); + + do a = a.add(LONG_VARIABLE).add(LONG_VARIABLE).add(LONG_VARIABLE); while (a < 200); + + do { a++; }while (a < 300); + + do { a = a.add(LONG_VARIABLE).add(LONG_VARIABLE).add(LONG_VARIABLE); }while (a < 400); + + do a++;while (a < veryLongVariableName.add(LONG_VARIABLE).add(LONG_VARIABLE) * 500); + + do { a++; }while (a < veryLongVariableName.add(LONG_VARIABLE).add(LONG_VARIABLE) * 600); + } +} + +=====================================output===================================== +contract WhileStatements { + uint constant LONG_VARIABLE = 1; + function whileStatements() public { + uint a; + uint veryLongVariableName; + while(a < 100)a++; + while(a < 200)a = a.add(LONG_VARIABLE).add(LONG_VARIABLE).add( + LONG_VARIABLE + ); + while(a < 300){ + a++; + } + while(a < 400){ + a = a.add(LONG_VARIABLE).add(LONG_VARIABLE).add(LONG_VARIABLE); + } + while(a < veryLongVariableName.add(LONG_VARIABLE).add( + LONG_VARIABLE + ) * 500)a++; + while(a < veryLongVariableName.add(LONG_VARIABLE).add( + LONG_VARIABLE + ) * 600){ + a++; + } + } + function doWhileStatements() public { + uint a; + uint veryLongVariableName; + do a++; while (a < 100); + do + a = a.add(LONG_VARIABLE).add(LONG_VARIABLE).add(LONG_VARIABLE); + while (a < 200); + do { + a++; + } while (a < 300); + do { + a = a.add(LONG_VARIABLE).add(LONG_VARIABLE).add(LONG_VARIABLE); + } while (a < 400); + do a++; while ( + a < veryLongVariableName.add(LONG_VARIABLE).add(LONG_VARIABLE) * 500 + ); + do { + a++; + } while ( + a < veryLongVariableName.add(LONG_VARIABLE).add(LONG_VARIABLE) * 600 + ); + } +} + +================================================================================ +`; diff --git a/tests/format/WhileStatements/jsfmt.spec.js b/tests/format/WhileStatements/jsfmt.spec.js index 765dd60a6..fd56c17bc 100644 --- a/tests/format/WhileStatements/jsfmt.spec.js +++ b/tests/format/WhileStatements/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse']); From 1862de7ab8a324d68cf476d89b487090cfd5455d Mon Sep 17 00:00:00 2001 From: Klaus Date: Thu, 30 May 2024 23:55:32 +1200 Subject: [PATCH 019/160] respecting preferred quotes in string literals --- src/slang-nodes/AssemblyStatement.js | 3 +- src/slang-nodes/HexStringLiteral.js | 6 +- src/slang-nodes/HexStringLiterals.js | 4 +- src/slang-nodes/StringLiteral.js | 6 +- src/slang-nodes/StringLiterals.js | 4 +- src/slang-nodes/UncheckedBlock.js | 6 +- src/slang-nodes/UnicodeStringLiteral.js | 6 +- src/slang-nodes/UnicodeStringLiterals.js | 4 +- .../__snapshots__/jsfmt.spec.js.snap | 6 +- tests/format/quotes/Quotes.sol | 4 +- .../quotes/__snapshots__/jsfmt.spec.js.snap | 138 +++++++++++++++--- tests/format/quotes/jsfmt.spec.js | 2 + 12 files changed, 147 insertions(+), 42 deletions(-) diff --git a/src/slang-nodes/AssemblyStatement.js b/src/slang-nodes/AssemblyStatement.js index b5ed0ea6f..aa5ae2b04 100644 --- a/src/slang-nodes/AssemblyStatement.js +++ b/src/slang-nodes/AssemblyStatement.js @@ -9,7 +9,8 @@ export const AssemblyStatement = { print: ({ node, path, print }) => [ node.assemblyKeyword, node.label ? [' ', path.call(print, 'label')] : '', - node.flags ? [' ', path.call(print, 'flags'), ' '] : ' ', + node.flags ? [' ', path.call(print, 'flags')] : '', + ' ', path.call(print, 'body') ] }; diff --git a/src/slang-nodes/HexStringLiteral.js b/src/slang-nodes/HexStringLiteral.js index f6fe144d9..3bff2fa11 100644 --- a/src/slang-nodes/HexStringLiteral.js +++ b/src/slang-nodes/HexStringLiteral.js @@ -1,9 +1,9 @@ +import { printString } from '../common/util.js'; + export const HexStringLiteral = { parse: ({ ast, options }) => ({ kind: ast.cst.kind, - variant: options.singleQuote - ? `hex'${ast.variant.text.slice(4, -1)}'` - : `hex"${ast.variant.text.slice(4, -1)}"` + variant: `hex${printString(ast.variant.text.slice(4, -1), options)}` }), print: ({ node }) => node.variant }; diff --git a/src/slang-nodes/HexStringLiterals.js b/src/slang-nodes/HexStringLiterals.js index ebddc2ca0..78a983ebd 100644 --- a/src/slang-nodes/HexStringLiterals.js +++ b/src/slang-nodes/HexStringLiterals.js @@ -1,11 +1,11 @@ import { doc } from 'prettier'; -const { group, join, line } = doc.builders; +const { join, hardline } = doc.builders; export const HexStringLiterals = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), - print: ({ path, print }) => group(join(line, path.map(print, 'items'))) + print: ({ path, print }) => join(hardline, path.map(print, 'items')) }; diff --git a/src/slang-nodes/StringLiteral.js b/src/slang-nodes/StringLiteral.js index 2080b847f..a593d2aae 100644 --- a/src/slang-nodes/StringLiteral.js +++ b/src/slang-nodes/StringLiteral.js @@ -1,7 +1,9 @@ +import { printString } from '../common/util.js'; + export const StringLiteral = { - parse: ({ ast }) => ({ + parse: ({ ast, options }) => ({ kind: ast.cst.kind, - variant: ast.variant.text + variant: printString(ast.variant.text.slice(1, -1), options) }), print: ({ node }) => node.variant }; diff --git a/src/slang-nodes/StringLiterals.js b/src/slang-nodes/StringLiterals.js index 69bc408a6..4d163726d 100644 --- a/src/slang-nodes/StringLiterals.js +++ b/src/slang-nodes/StringLiterals.js @@ -1,11 +1,11 @@ import { doc } from 'prettier'; -const { group, join, line } = doc.builders; +const { join, hardline } = doc.builders; export const StringLiterals = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), - print: ({ path, print }) => group(join(line, path.map(print, 'items'))) + print: ({ path, print }) => join(hardline, path.map(print, 'items')) }; diff --git a/src/slang-nodes/UncheckedBlock.js b/src/slang-nodes/UncheckedBlock.js index e304b440a..d17c419e6 100644 --- a/src/slang-nodes/UncheckedBlock.js +++ b/src/slang-nodes/UncheckedBlock.js @@ -4,6 +4,8 @@ export const UncheckedBlock = { uncheckedKeyword: ast.uncheckedKeyword.text, block: parse(ast.block, options, parse) }), - // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: UncheckedBlock'] + print: ({ node, path, print }) => [ + `${node.uncheckedKeyword} `, + path.call(print, 'block') + ] }; diff --git a/src/slang-nodes/UnicodeStringLiteral.js b/src/slang-nodes/UnicodeStringLiteral.js index 865bbeb8e..71f74e8e2 100644 --- a/src/slang-nodes/UnicodeStringLiteral.js +++ b/src/slang-nodes/UnicodeStringLiteral.js @@ -1,9 +1,9 @@ +import { printString } from '../common/util.js'; + export const UnicodeStringLiteral = { parse: ({ ast, options }) => ({ kind: ast.cst.kind, - variant: options.singleQuote - ? `unicode'${ast.variant.text.slice(8, -1)}'` - : `unicode"${ast.variant.text.slice(8, -1)}"` + variant: `unicode${printString(ast.variant.text.slice(8, -1), options)}` }), print: ({ node }) => node.variant }; diff --git a/src/slang-nodes/UnicodeStringLiterals.js b/src/slang-nodes/UnicodeStringLiterals.js index 70dbb7364..e7509c118 100644 --- a/src/slang-nodes/UnicodeStringLiterals.js +++ b/src/slang-nodes/UnicodeStringLiterals.js @@ -1,11 +1,11 @@ import { doc } from 'prettier'; -const { group, join, line } = doc.builders; +const { join, hardline } = doc.builders; export const UnicodeStringLiterals = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), - print: ({ path, print }) => group(join(line, path.map(print, 'items'))) + print: ({ path, print }) => join(hardline, path.map(print, 'items')) }; diff --git a/tests/format/MultipartStrings/__snapshots__/jsfmt.spec.js.snap b/tests/format/MultipartStrings/__snapshots__/jsfmt.spec.js.snap index d17d7e113..c4968313b 100644 --- a/tests/format/MultipartStrings/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/MultipartStrings/__snapshots__/jsfmt.spec.js.snap @@ -59,11 +59,13 @@ contract MultipartStrings { contract MultipartStrings { bytes b1 = hex"beef"; bytes b2 = hex"beef"; - bytes b3 = hex"beef" hex"c0ffee"; + bytes b3 = hex"beef" + hex"c0ffee"; bytes b4 = hex"beeeeeeeeeeeeeeeeeeeeeef" hex"c0000000000ffeeeeeeeeeeeeeeeeeee"; string s1 = "foo"; - string s2 = "foo" "bar"; + string s2 = "foo" + "bar"; string s3 = "foofoofoofooofoofoofofoooofofoo" "barbarbrabrbarbarbabrabrbabr"; } diff --git a/tests/format/quotes/Quotes.sol b/tests/format/quotes/Quotes.sol index 417a0f6b2..c9a133f97 100644 --- a/tests/format/quotes/Quotes.sol +++ b/tests/format/quotes/Quotes.sol @@ -18,7 +18,5 @@ contract Foo { bytes8 hex2 = hex"DeadBeef"; string withUnicode1 = unicode'hello 🦄 world'; string withUnicode2 = unicode"hello 🦄 world"; - string multiPartAndUnicode1 = unicode'hello 🦄' ' world'; - string multiPartAndUnicode2 = 'hello ' unicode' 🦄world'; - string multiPartAndUnicode3 = unicode'hello 🦄' unicode' world 🦄'; + string multiPartAndUnicode = unicode'hello 🦄' unicode' world 🦄'; } diff --git a/tests/format/quotes/__snapshots__/jsfmt.spec.js.snap b/tests/format/quotes/__snapshots__/jsfmt.spec.js.snap index b999ae311..0c86b3e30 100644 --- a/tests/format/quotes/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/quotes/__snapshots__/jsfmt.spec.js.snap @@ -27,9 +27,7 @@ contract Foo { bytes8 hex2 = hex"DeadBeef"; string withUnicode1 = unicode'hello 🦄 world'; string withUnicode2 = unicode"hello 🦄 world"; - string multiPartAndUnicode1 = unicode'hello 🦄' ' world'; - string multiPartAndUnicode2 = 'hello ' unicode' 🦄world'; - string multiPartAndUnicode3 = unicode'hello 🦄' unicode' world 🦄'; + string multiPartAndUnicode = unicode'hello 🦄' unicode' world 🦄'; } =====================================output===================================== @@ -53,13 +51,7 @@ contract Foo { bytes8 hex2 = hex"DeadBeef"; string withUnicode1 = unicode"hello 🦄 world"; string withUnicode2 = unicode"hello 🦄 world"; - string multiPartAndUnicode1 = - unicode"hello 🦄" - " world"; - string multiPartAndUnicode2 = - "hello " - unicode" 🦄world"; - string multiPartAndUnicode3 = + string multiPartAndUnicode = unicode"hello 🦄" unicode" world 🦄"; } @@ -67,6 +59,63 @@ contract Foo { ================================================================================ `; +exports[`Quotes.sol - {"singleQuote":false} format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 +singleQuote: false + | printWidth +=====================================input====================================== +import 'someContract.sol'; +import "someOtherContract.sol"; + +contract Foo { + string foo1 = 'foo'; + string foo2 = "foo"; + string spaces1 = 'the quick brown fox'; + string spaces2 = "the quick brown fox"; + string singleQuote = "don't do that"; + string escapedSingleQuote = 'don\\'t do that'; + string doubleQuote = 'Use " for quoting'; + string escapedDoubleQuote = "Use \\" for quoting"; + string singleQuotes = "don't do that, don't"; + string escapedSingleQuotes = 'don\\'t do that, don\\'t'; + string doubleQuotes = 'The "quick" brown fox'; + string escapeDoubleQuotes = "The \\"quick\\" brown fox"; + bytes8 hex1 = hex'DeadBeef'; + bytes8 hex2 = hex"DeadBeef"; + string withUnicode1 = unicode'hello 🦄 world'; + string withUnicode2 = unicode"hello 🦄 world"; + string multiPartAndUnicode = unicode'hello 🦄' unicode' world 🦄'; +} + +=====================================output===================================== +import "someContract.sol"; +import "someOtherContract.sol"; +contract Foo { + string foo1 = "foo"; + string foo2 = "foo"; + string spaces1 = "the quick brown fox"; + string spaces2 = "the quick brown fox"; + string singleQuote = "don't do that"; + string escapedSingleQuote = "don't do that"; + string doubleQuote = 'Use " for quoting'; + string escapedDoubleQuote = 'Use " for quoting'; + string singleQuotes = "don't do that, don't"; + string escapedSingleQuotes = "don't do that, don't"; + string doubleQuotes = 'The "quick" brown fox'; + string escapeDoubleQuotes = 'The "quick" brown fox'; + bytes8 hex1 = hex"DeadBeef"; + bytes8 hex2 = hex"DeadBeef"; + string withUnicode1 = unicode"hello 🦄 world"; + string withUnicode2 = unicode"hello 🦄 world"; + string multiPartAndUnicode = unicode"hello 🦄" + unicode" world 🦄"; +} + +================================================================================ +`; + exports[`Quotes.sol - {"singleQuote":true} format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] @@ -94,9 +143,7 @@ contract Foo { bytes8 hex2 = hex"DeadBeef"; string withUnicode1 = unicode'hello 🦄 world'; string withUnicode2 = unicode"hello 🦄 world"; - string multiPartAndUnicode1 = unicode'hello 🦄' ' world'; - string multiPartAndUnicode2 = 'hello ' unicode' 🦄world'; - string multiPartAndUnicode3 = unicode'hello 🦄' unicode' world 🦄'; + string multiPartAndUnicode = unicode'hello 🦄' unicode' world 🦄'; } =====================================output===================================== @@ -120,16 +167,67 @@ contract Foo { bytes8 hex2 = hex'DeadBeef'; string withUnicode1 = unicode'hello 🦄 world'; string withUnicode2 = unicode'hello 🦄 world'; - string multiPartAndUnicode1 = - unicode'hello 🦄' - ' world'; - string multiPartAndUnicode2 = - 'hello ' - unicode' 🦄world'; - string multiPartAndUnicode3 = + string multiPartAndUnicode = unicode'hello 🦄' unicode' world 🦄'; } ================================================================================ `; + +exports[`Quotes.sol - {"singleQuote":true} format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 +singleQuote: true + | printWidth +=====================================input====================================== +import 'someContract.sol'; +import "someOtherContract.sol"; + +contract Foo { + string foo1 = 'foo'; + string foo2 = "foo"; + string spaces1 = 'the quick brown fox'; + string spaces2 = "the quick brown fox"; + string singleQuote = "don't do that"; + string escapedSingleQuote = 'don\\'t do that'; + string doubleQuote = 'Use " for quoting'; + string escapedDoubleQuote = "Use \\" for quoting"; + string singleQuotes = "don't do that, don't"; + string escapedSingleQuotes = 'don\\'t do that, don\\'t'; + string doubleQuotes = 'The "quick" brown fox'; + string escapeDoubleQuotes = "The \\"quick\\" brown fox"; + bytes8 hex1 = hex'DeadBeef'; + bytes8 hex2 = hex"DeadBeef"; + string withUnicode1 = unicode'hello 🦄 world'; + string withUnicode2 = unicode"hello 🦄 world"; + string multiPartAndUnicode = unicode'hello 🦄' unicode' world 🦄'; +} + +=====================================output===================================== +import 'someContract.sol'; +import 'someOtherContract.sol'; +contract Foo { + string foo1 = 'foo'; + string foo2 = 'foo'; + string spaces1 = 'the quick brown fox'; + string spaces2 = 'the quick brown fox'; + string singleQuote = "don't do that"; + string escapedSingleQuote = "don't do that"; + string doubleQuote = 'Use " for quoting'; + string escapedDoubleQuote = 'Use " for quoting'; + string singleQuotes = "don't do that, don't"; + string escapedSingleQuotes = "don't do that, don't"; + string doubleQuotes = 'The "quick" brown fox'; + string escapeDoubleQuotes = 'The "quick" brown fox'; + bytes8 hex1 = hex'DeadBeef'; + bytes8 hex2 = hex'DeadBeef'; + string withUnicode1 = unicode'hello 🦄 world'; + string withUnicode2 = unicode'hello 🦄 world'; + string multiPartAndUnicode = unicode'hello 🦄' + unicode' world 🦄'; +} + +================================================================================ +`; diff --git a/tests/format/quotes/jsfmt.spec.js b/tests/format/quotes/jsfmt.spec.js index 3272026cc..a56d23665 100644 --- a/tests/format/quotes/jsfmt.spec.js +++ b/tests/format/quotes/jsfmt.spec.js @@ -1,2 +1,4 @@ run_spec(import.meta, ['solidity-parse'], { singleQuote: true }); run_spec(import.meta, ['solidity-parse'], { singleQuote: false }); +run_spec(import.meta, ['solidity-slang-parse'], { singleQuote: true }); +run_spec(import.meta, ['solidity-slang-parse'], { singleQuote: false }); From 4c846a1642a3af11307c6ceb486301675ca1964d Mon Sep 17 00:00:00 2001 From: Klaus Date: Fri, 31 May 2024 22:46:10 +1200 Subject: [PATCH 020/160] indentation after equal sign --- .../StateVariableDefinitionValue.js | 14 +++++++------ .../TupleDeconstructionStatement.js | 13 +++++++++--- src/slang-nodes/VariableDeclarationValue.js | 15 ++++++++++---- .../Arrays/__snapshots__/jsfmt.spec.js.snap | 6 ++---- .../__snapshots__/jsfmt.spec.js.snap | 5 ++--- .../__snapshots__/jsfmt.spec.js.snap | 20 +++++++++++-------- .../__snapshots__/jsfmt.spec.js.snap | 3 ++- .../__snapshots__/jsfmt.spec.js.snap | 19 +++++++++--------- .../quotes/__snapshots__/jsfmt.spec.js.snap | 10 ++++++---- 9 files changed, 63 insertions(+), 42 deletions(-) diff --git a/src/slang-nodes/StateVariableDefinitionValue.js b/src/slang-nodes/StateVariableDefinitionValue.js index e3fde26d3..35ea9ce9c 100644 --- a/src/slang-nodes/StateVariableDefinitionValue.js +++ b/src/slang-nodes/StateVariableDefinitionValue.js @@ -1,13 +1,15 @@ +import { doc } from 'prettier'; + +const { group, indent, line } = doc.builders; + export const StateVariableDefinitionValue = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, equal: ast.equal.text, value: parse(ast.value, options, parse) }), - print: ({ node, path, print }) => [ - ' ', - node.equal, - ' ', - path.call(print, 'value') - ] + print: ({ node, path, print }) => + node.value.variant.kind === 'ArrayExpression' + ? [` ${node.equal} `, path.call(print, 'value')] + : group([` ${node.equal}`, indent([line, path.call(print, 'value')])]) }; diff --git a/src/slang-nodes/TupleDeconstructionStatement.js b/src/slang-nodes/TupleDeconstructionStatement.js index d6552523f..875bcaf8e 100644 --- a/src/slang-nodes/TupleDeconstructionStatement.js +++ b/src/slang-nodes/TupleDeconstructionStatement.js @@ -1,3 +1,7 @@ +import { doc } from 'prettier'; + +const { group, indent, line } = doc.builders; + export const TupleDeconstructionStatement = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, @@ -13,8 +17,11 @@ export const TupleDeconstructionStatement = { node.varKeyword ? node.varKeyword : '', node.openParen, path.call(print, 'elements'), - `${node.closeParen} ${node.equal} `, - path.call(print, 'expression'), - node.semicolon + node.expression.variant.kind === 'TupleExpression' + ? [`${node.closeParen} ${node.equal} `, path.call(print, 'expression')] + : group([ + `${node.closeParen} ${node.equal}`, + indent([line, path.call(print, 'expression'), node.semicolon]) + ]) ] }; diff --git a/src/slang-nodes/VariableDeclarationValue.js b/src/slang-nodes/VariableDeclarationValue.js index af0b1ebe7..22d8b8619 100644 --- a/src/slang-nodes/VariableDeclarationValue.js +++ b/src/slang-nodes/VariableDeclarationValue.js @@ -1,11 +1,18 @@ +import { doc } from 'prettier'; + +const { group, indent, line } = doc.builders; + export const VariableDeclarationValue = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, equal: ast.equal.text, expression: parse(ast.expression, options, parse) }), - print: ({ node, path, print }) => [ - ` ${node.equal} `, - path.call(print, 'expression') - ] + print: ({ node, path, print }) => + node.expression.variant.kind === 'ArrayExpression' + ? [` ${node.equal} `, path.call(print, 'expression')] + : group([ + ` ${node.equal}`, + indent([line, path.call(print, 'expression')]) + ]) }; diff --git a/tests/format/Arrays/__snapshots__/jsfmt.spec.js.snap b/tests/format/Arrays/__snapshots__/jsfmt.spec.js.snap index 266fa4f35..a43a3fca8 100644 --- a/tests/format/Arrays/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Arrays/__snapshots__/jsfmt.spec.js.snap @@ -104,10 +104,8 @@ contract Arrays { bytes32("removePermissionFromGroup") ]; function a() { - Outcome.OutcomeItem[] memory outcomeFrom = abi.decode( - fromPart.outcome, - (Outcome.OutcomeItem[]) - ); + Outcome.OutcomeItem[] memory outcomeFrom = + abi.decode(fromPart.outcome, (Outcome.OutcomeItem[])); } } contract ArraySlices { diff --git a/tests/format/Conditional/__snapshots__/jsfmt.spec.js.snap b/tests/format/Conditional/__snapshots__/jsfmt.spec.js.snap index 5afe671f6..67a5e4bf9 100644 --- a/tests/format/Conditional/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Conditional/__snapshots__/jsfmt.spec.js.snap @@ -116,9 +116,8 @@ contract Conditional { pragma solidity ^0.4.24; contract Conditional { function foo() { - address contextAddress = longAddress_ == address(0) - ? msg.sender - : currentContextAddress_; + address contextAddress = + longAddress_ == address(0) ? msg.sender : currentContextAddress_; asset == ETH ? require( address(uint160(msg.sender)).send(quantity), diff --git a/tests/format/MultipartStrings/__snapshots__/jsfmt.spec.js.snap b/tests/format/MultipartStrings/__snapshots__/jsfmt.spec.js.snap index c4968313b..96ffead77 100644 --- a/tests/format/MultipartStrings/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/MultipartStrings/__snapshots__/jsfmt.spec.js.snap @@ -59,15 +59,19 @@ contract MultipartStrings { contract MultipartStrings { bytes b1 = hex"beef"; bytes b2 = hex"beef"; - bytes b3 = hex"beef" - hex"c0ffee"; - bytes b4 = hex"beeeeeeeeeeeeeeeeeeeeeef" - hex"c0000000000ffeeeeeeeeeeeeeeeeeee"; + bytes b3 = + hex"beef" + hex"c0ffee"; + bytes b4 = + hex"beeeeeeeeeeeeeeeeeeeeeef" + hex"c0000000000ffeeeeeeeeeeeeeeeeeee"; string s1 = "foo"; - string s2 = "foo" - "bar"; - string s3 = "foofoofoofooofoofoofofoooofofoo" - "barbarbrabrbarbarbabrabrbabr"; + string s2 = + "foo" + "bar"; + string s3 = + "foofoofoofooofoofoofofoooofofoo" + "barbarbrabrbarbarbabrabrbabr"; } ================================================================================ diff --git a/tests/format/StateVariableDeclarations/__snapshots__/jsfmt.spec.js.snap b/tests/format/StateVariableDeclarations/__snapshots__/jsfmt.spec.js.snap index 2b25015ea..06d251534 100644 --- a/tests/format/StateVariableDeclarations/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/StateVariableDeclarations/__snapshots__/jsfmt.spec.js.snap @@ -31,7 +31,8 @@ contract Contract { =====================================output===================================== contract Contract { - bytes32 privateconstant DOMAIN_SEPARATOR_TYPEHASH = 0x035aff83d86937d35b32e04f0ddc6ff469290eef2f1b692d8a815c89404d4749; + bytes32 privateconstant DOMAIN_SEPARATOR_TYPEHASH = + 0x035aff83d86937d35b32e04f0ddc6ff469290eef2f1b692d8a815c89404d4749; } ================================================================================ diff --git a/tests/format/StringLiteral/__snapshots__/jsfmt.spec.js.snap b/tests/format/StringLiteral/__snapshots__/jsfmt.spec.js.snap index 838c79901..8a418a2a2 100644 --- a/tests/format/StringLiteral/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/StringLiteral/__snapshots__/jsfmt.spec.js.snap @@ -55,15 +55,16 @@ contract StringLiteral { =====================================output===================================== contract StringLiteral { - bytes32 publicconstant PERMIT_TYPEHASH = keccak256( - "Permit(" - "address owner," - "address spender," - "uint256 value," - "uint256 nonce," - "uint256 deadline" - ")" - ); + bytes32 publicconstant PERMIT_TYPEHASH = + keccak256( + "Permit(" + "address owner," + "address spender," + "uint256 value," + "uint256 nonce," + "uint256 deadline" + ")" + ); } ================================================================================ diff --git a/tests/format/quotes/__snapshots__/jsfmt.spec.js.snap b/tests/format/quotes/__snapshots__/jsfmt.spec.js.snap index 0c86b3e30..9ac2c3b70 100644 --- a/tests/format/quotes/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/quotes/__snapshots__/jsfmt.spec.js.snap @@ -109,8 +109,9 @@ contract Foo { bytes8 hex2 = hex"DeadBeef"; string withUnicode1 = unicode"hello 🦄 world"; string withUnicode2 = unicode"hello 🦄 world"; - string multiPartAndUnicode = unicode"hello 🦄" - unicode" world 🦄"; + string multiPartAndUnicode = + unicode"hello 🦄" + unicode" world 🦄"; } ================================================================================ @@ -225,8 +226,9 @@ contract Foo { bytes8 hex2 = hex'DeadBeef'; string withUnicode1 = unicode'hello 🦄 world'; string withUnicode2 = unicode'hello 🦄 world'; - string multiPartAndUnicode = unicode'hello 🦄' - unicode' world 🦄'; + string multiPartAndUnicode = + unicode'hello 🦄' + unicode' world 🦄'; } ================================================================================ From ea0f5ab03e3f3ec145d61eef146805dfb3aec6ff Mon Sep 17 00:00:00 2001 From: Klaus Date: Sun, 2 Jun 2024 11:01:09 +1200 Subject: [PATCH 021/160] Experimental Ternaries --- src/slang-nodes/ConditionalExpression.js | 102 ++++++++++++++++++++--- src/slang-nodes/PositionalArguments.js | 3 +- 2 files changed, 91 insertions(+), 14 deletions(-) diff --git a/src/slang-nodes/ConditionalExpression.js b/src/slang-nodes/ConditionalExpression.js index 291474f30..4d3bb811a 100644 --- a/src/slang-nodes/ConditionalExpression.js +++ b/src/slang-nodes/ConditionalExpression.js @@ -1,6 +1,90 @@ +/* eslint-disable no-nested-ternary */ import { doc } from 'prettier'; +import { printSeparatedItem } from '../common/printer-helpers.js'; -const { group, indent, line } = doc.builders; +const { group, hardline, ifBreak, indent, line } = doc.builders; + +let groupIndex = 0; +const experimentalTernaries = (node, path, print, options) => { + const grandparent = path.getNode(2); + const isNested = grandparent.kind === 'ConditionalExpression'; + const isNestedAsTrueExpression = + isNested && grandparent.trueExpression.variant === node; + const falseExpressionIsTuple = + node.falseExpression.variant.kind === 'TupleExpression'; + const falseExpressionInSameLine = + falseExpressionIsTuple || + node.falseExpression.variant.kind === 'ConditionalExpression'; + + // If the `condition` breaks into multiple lines, we add parentheses, + // unless it already is a `TupleExpression`. + const operand = path.call(print, 'operand'); + const operandDoc = group([ + node.operand.variant.kind === 'TupleExpression' + ? operand + : ifBreak(['(', printSeparatedItem(operand), ')'], operand), + ` ${node.questionMark}` + ]); + + // To switch between "case-style" and "curious" ternaries we force a new line + // before a nested `trueExpression` if the current `Conditional` is also a + // `trueExpression`. + const trueExpressionDoc = indent([ + isNestedAsTrueExpression ? hardline : line, + path.call(print, 'trueExpression') + ]); + + const conditionAndTrueExpressionGroup = group( + [operandDoc, trueExpressionDoc], + { id: `Conditional.trueExpressionDoc-${groupIndex}` } + ); + + groupIndex += 1; + + // For the odd case of `tabWidth` of 1 or 0 we initiate `fillTab` as a single + // space. + let fillTab = ' '; + if ( + !falseExpressionInSameLine && // avoid processing if it's not needed + (options.tabWidth > 2 || options.useTabs) + ) { + fillTab = options.useTabs ? '\t' : ' '.repeat(options.tabWidth - 1); + } + + const falseExpression = path.call(print, 'falseExpression'); + return group([ + conditionAndTrueExpressionGroup, + [ + falseExpressionIsTuple + ? ifBreak(line, ' ', { groupId: conditionAndTrueExpressionGroup.id }) + : isNested + ? hardline + : line, + node.colon, + falseExpressionInSameLine + ? [' ', falseExpression] + : ifBreak([fillTab, indent(falseExpression)], [' ', falseExpression], { + // We only add `fillTab` if we are sure the trueExpression is indented + groupId: conditionAndTrueExpressionGroup.id + }) + ] + ]); +}; + +const traditionalTernaries = (node, path, print) => + group([ + path.call(print, 'operand'), + indent([ + // Nested trueExpression and falseExpression are always printed in a new + // line + path.getNode(2).kind === 'ConditionalExpression' ? hardline : line, + `${node.questionMark} `, + path.call(print, 'trueExpression'), + line, + `${node.colon} `, + path.call(print, 'falseExpression') + ]) + ]); export const ConditionalExpression = { parse: ({ ast, options, parse }) => ({ @@ -11,16 +95,8 @@ export const ConditionalExpression = { colon: ast.colon.text, falseExpression: parse(ast.falseExpression, options, parse) }), - print: ({ node, path, print }) => - group([ - path.call(print, 'operand'), - indent([ - line, - `${node.questionMark} `, - path.call(print, 'trueExpression'), - line, - `${node.colon} `, - path.call(print, 'falseExpression') - ]) - ]) + print: ({ node, path, print, options }) => + options.experimentalTernaries + ? experimentalTernaries(node, path, print, options) + : traditionalTernaries(node, path, print) }; diff --git a/src/slang-nodes/PositionalArguments.js b/src/slang-nodes/PositionalArguments.js index 14df6043c..cfddd63ec 100644 --- a/src/slang-nodes/PositionalArguments.js +++ b/src/slang-nodes/PositionalArguments.js @@ -6,5 +6,6 @@ export const PositionalArguments = { items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), - print: ({ path, print }) => printSeparatedList(path.map(print, 'items')) + print: ({ node, path, print }) => + node.items.length > 0 ? printSeparatedList(path.map(print, 'items')) : '' }; From c84ad19b7856ad44aba5403a428bb26722e2eb92 Mon Sep 17 00:00:00 2001 From: Klaus Date: Tue, 4 Jun 2024 13:36:36 +1200 Subject: [PATCH 022/160] Member Access Chains --- src/common/util.js | 4 + src/slang-nodes/ConditionalExpression.js | 2 +- src/slang-nodes/FunctionCallExpression.js | 33 ++++- src/slang-nodes/IndexAccessExpression.js | 45 +++++- src/slang-nodes/MemberAccessExpression.js | 128 +++++++++++++++++- src/slang-nodes/VariableDeclarationValue.js | 15 +- .../Arrays/__snapshots__/jsfmt.spec.js.snap | 6 +- .../__snapshots__/jsfmt.spec.js.snap | 5 +- 8 files changed, 206 insertions(+), 32 deletions(-) diff --git a/src/common/util.js b/src/common/util.js index 608d72272..bb564c987 100644 --- a/src/common/util.js +++ b/src/common/util.js @@ -44,3 +44,7 @@ export function hasNodeIgnoreComment(node) { node.comments.some((comment) => comment.value.trim() === 'prettier-ignore') ); } + +export function isLabel(doc) { + return doc.type === 'label'; +} diff --git a/src/slang-nodes/ConditionalExpression.js b/src/slang-nodes/ConditionalExpression.js index 4d3bb811a..8d93b2894 100644 --- a/src/slang-nodes/ConditionalExpression.js +++ b/src/slang-nodes/ConditionalExpression.js @@ -36,7 +36,7 @@ const experimentalTernaries = (node, path, print, options) => { const conditionAndTrueExpressionGroup = group( [operandDoc, trueExpressionDoc], - { id: `Conditional.trueExpressionDoc-${groupIndex}` } + { id: Symbol(`Slang.ConditionalExpression.trueExpression-${groupIndex}`) } ); groupIndex += 1; diff --git a/src/slang-nodes/FunctionCallExpression.js b/src/slang-nodes/FunctionCallExpression.js index 3e4b372b9..ff625ca5f 100644 --- a/src/slang-nodes/FunctionCallExpression.js +++ b/src/slang-nodes/FunctionCallExpression.js @@ -1,11 +1,36 @@ +import { doc } from 'prettier'; +import { isLabel } from '../common/util.js'; + +const { group, indentIfBreak, label } = doc.builders; + +let groupIndex = 0; export const FunctionCallExpression = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, operand: parse(ast.operand, options, parse), arguments: parse(ast.arguments, options, parse) }), - print: ({ path, print }) => [ - path.call(print, 'operand'), - path.call(print, 'arguments') - ] + print: ({ path, print }) => { + let operandDoc = path.call(print, 'operand'); + let argumentsDoc = path.call(print, 'arguments'); + + // If we are at the end of a MemberAccessChain we should indent the + // arguments accordingly. + if (isLabel(operandDoc) && operandDoc.label === 'MemberAccessChain') { + operandDoc = group(operandDoc.contents, { + id: `FunctionCall.expression-${groupIndex}` + }); + + groupIndex += 1; + + argumentsDoc = indentIfBreak(argumentsDoc, { + groupId: operandDoc.id + }); + // We wrap the expression in a label in case there is an IndexAccess or + // a FunctionCall following this IndexAccess. + return label('MemberAccessChain', [operandDoc, argumentsDoc]); + } + + return [operandDoc, argumentsDoc]; + } }; diff --git a/src/slang-nodes/IndexAccessExpression.js b/src/slang-nodes/IndexAccessExpression.js index 56cb7427c..ccb202d9c 100644 --- a/src/slang-nodes/IndexAccessExpression.js +++ b/src/slang-nodes/IndexAccessExpression.js @@ -1,3 +1,9 @@ +import { doc } from 'prettier'; +import { isLabel } from '../common/util.js'; + +const { group, indent, indentIfBreak, label, softline } = doc.builders; + +let groupIndex = 0; export const IndexAccessExpression = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, @@ -7,11 +13,36 @@ export const IndexAccessExpression = { end: ast.end ? parse(ast.end, options, parse) : undefined, closeBracket: ast.closeBracket.text }), - print: ({ node, path, print }) => [ - path.call(print, 'operand'), - node.openBracket, - node.start ? path.call(print, 'start') : '', - node.end ? path.call(print, 'end') : '', - node.closeBracket - ] + print: ({ node, path, print }) => { + let operandDoc = path.call(print, 'operand'); + let indexDoc = group([ + node.openBracket, + indent([ + softline, + node.start ? path.call(print, 'start') : '', + node.end ? path.call(print, 'end') : '' + ]), + softline, + node.closeBracket + ]); + + // If we are at the end of a MemberAccessChain we should indent the + // arguments accordingly. + if (isLabel(operandDoc) && operandDoc.label === 'MemberAccessChain') { + operandDoc = group(operandDoc.contents, { + id: `IndexAccess.base-${groupIndex}` + }); + + groupIndex += 1; + + indexDoc = indentIfBreak(indexDoc, { + groupId: operandDoc.id + }); + // We wrap the expression in a label in case there is an IndexAccess or + // a FunctionCall following this IndexAccess. + return label('MemberAccessChain', [operandDoc, indexDoc]); + } + + return [operandDoc, indexDoc]; + } }; diff --git a/src/slang-nodes/MemberAccessExpression.js b/src/slang-nodes/MemberAccessExpression.js index b0b6c2b76..22d604667 100644 --- a/src/slang-nodes/MemberAccessExpression.js +++ b/src/slang-nodes/MemberAccessExpression.js @@ -1,3 +1,112 @@ +import { doc } from 'prettier'; +import { isLabel } from '../common/util.js'; + +const { group, indent, label, softline } = doc.builders; + +const isEndOfChain = (node, path) => { + let i = 0; + let currentNode = node; + let parentNode = path.getParentNode(i); + while ( + parentNode && + [ + 'Expression', + 'FunctionCallExpression', + 'IndexAccessExpression', + 'MemberAccessExpression' + ].includes(parentNode.kind) + ) { + switch (parentNode.kind) { + case 'MemberAccessExpression': + // If direct ParentNode is a MemberAccess we are not at the end of the + // chain. + return false; + + case 'IndexAccessExpression': + // If direct ParentNode is an IndexAccess and currentNode is not the + // operand then it must be the start or the end in which case it is the + // end of the chain. + if (currentNode !== parentNode.operand) return true; + break; + + case 'FunctionCallExpression': + // If direct ParentNode is a FunctionCall and currentNode is not the + // operand then it must be and argument in which case it is the end + // of the chain. + if (currentNode !== parentNode.operand) return true; + break; + + default: + break; + } + + i += 1; + currentNode = parentNode; + parentNode = path.getParentNode(i); + } + return true; +}; + +/** + * processChain expects the doc[] of the full chain of MemberAccess. + * + * It uses the separator label to split the chain into 2 arrays. + * The first array is the doc[] corresponding to the first element before the + * first separator. + * The second array contains the rest of the chain. + * + * The second array is grouped and indented, while the first element's + * formatting logic remains separated. + * + * That way the first element can safely split into multiple lines and the rest + * of the chain will continue its formatting rules as normal. + * + * i.e. + * ``` + * functionCall(arg1, arg2).rest.of.chain + * + * functionCall(arg1, arg2) + * .long + * .rest + * .of + * .chain + * + * functionCall( + * arg1, + * arg2 + * ).rest.of.chain + * + * functionCall( + * arg1, + * arg2 + * ) + * .long + * .rest + * .of + * .chain + * ``` + * + * NOTE: As described in the examples above, the rest of the chain will be grouped + * and try to stay in the same line as the end of the first element. + * + * @param {doc[]} chain is the full chain of MemberAccess + * @returns a processed doc[] with the proper grouping and indentation ready to + * be printed. + */ +const processChain = (chain) => { + const firstSeparatorIndex = chain.findIndex( + (element) => isLabel(element) && element.label === 'separator' + ); + // The doc[] before the first separator + const firstExpression = chain.slice(0, firstSeparatorIndex); + // The doc[] containing the rest of the chain + const restOfChain = group(indent(chain.slice(firstSeparatorIndex))); + + // We wrap the expression in a label in case there is an IndexAccess or + // a FunctionCall following this MemberAccess. + return label('MemberAccessChain', group([firstExpression, restOfChain])); +}; + export const MemberAccessExpression = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, @@ -5,9 +114,18 @@ export const MemberAccessExpression = { period: ast.period.text, member: parse(ast.member, options, parse) }), - print: ({ node, path, print }) => [ - path.call(print, 'operand'), - node.period, - path.call(print, 'member') - ] + print: ({ node, path, print }) => { + let operandDoc = path.call(print, 'operand'); + if (Array.isArray(operandDoc)) { + operandDoc = operandDoc.flat(); + } + + const document = [ + operandDoc, + label('separator', [softline, node.period]), + path.call(print, 'member') + ].flat(); + + return isEndOfChain(node, path) ? processChain(document) : document; + } }; diff --git a/src/slang-nodes/VariableDeclarationValue.js b/src/slang-nodes/VariableDeclarationValue.js index 22d8b8619..af0b1ebe7 100644 --- a/src/slang-nodes/VariableDeclarationValue.js +++ b/src/slang-nodes/VariableDeclarationValue.js @@ -1,18 +1,11 @@ -import { doc } from 'prettier'; - -const { group, indent, line } = doc.builders; - export const VariableDeclarationValue = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, equal: ast.equal.text, expression: parse(ast.expression, options, parse) }), - print: ({ node, path, print }) => - node.expression.variant.kind === 'ArrayExpression' - ? [` ${node.equal} `, path.call(print, 'expression')] - : group([ - ` ${node.equal}`, - indent([line, path.call(print, 'expression')]) - ]) + print: ({ node, path, print }) => [ + ` ${node.equal} `, + path.call(print, 'expression') + ] }; diff --git a/tests/format/Arrays/__snapshots__/jsfmt.spec.js.snap b/tests/format/Arrays/__snapshots__/jsfmt.spec.js.snap index a43a3fca8..266fa4f35 100644 --- a/tests/format/Arrays/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Arrays/__snapshots__/jsfmt.spec.js.snap @@ -104,8 +104,10 @@ contract Arrays { bytes32("removePermissionFromGroup") ]; function a() { - Outcome.OutcomeItem[] memory outcomeFrom = - abi.decode(fromPart.outcome, (Outcome.OutcomeItem[])); + Outcome.OutcomeItem[] memory outcomeFrom = abi.decode( + fromPart.outcome, + (Outcome.OutcomeItem[]) + ); } } contract ArraySlices { diff --git a/tests/format/Conditional/__snapshots__/jsfmt.spec.js.snap b/tests/format/Conditional/__snapshots__/jsfmt.spec.js.snap index 67a5e4bf9..5afe671f6 100644 --- a/tests/format/Conditional/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Conditional/__snapshots__/jsfmt.spec.js.snap @@ -116,8 +116,9 @@ contract Conditional { pragma solidity ^0.4.24; contract Conditional { function foo() { - address contextAddress = - longAddress_ == address(0) ? msg.sender : currentContextAddress_; + address contextAddress = longAddress_ == address(0) + ? msg.sender + : currentContextAddress_; asset == ETH ? require( address(uint160(msg.sender)).send(quantity), From 589f422f0b7155febb6bdf8b00b0e409dc1f5963 Mon Sep 17 00:00:00 2001 From: Klaus Date: Tue, 4 Jun 2024 20:34:41 +1200 Subject: [PATCH 023/160] Additional edge cases --- src/nodes/FunctionCall.js | 2 +- src/nodes/IndexAccess.js | 2 +- src/slang-nodes/FunctionCallExpression.js | 4 +-- src/slang-nodes/IndexAccessExpression.js | 4 +-- src/slang-nodes/MemberAccessExpression.js | 32 +++++++++-------------- 5 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src/nodes/FunctionCall.js b/src/nodes/FunctionCall.js index f33d98b43..865966805 100644 --- a/src/nodes/FunctionCall.js +++ b/src/nodes/FunctionCall.js @@ -55,6 +55,6 @@ export const FunctionCall = { return label('MemberAccessChain', [expressionDoc, '(', argumentsDoc]); } - return [expressionDoc, '(', argumentsDoc]; + return [expressionDoc, '(', argumentsDoc].flat(); } }; diff --git a/src/nodes/IndexAccess.js b/src/nodes/IndexAccess.js index 6838775e7..bb38d3857 100644 --- a/src/nodes/IndexAccess.js +++ b/src/nodes/IndexAccess.js @@ -29,6 +29,6 @@ export const IndexAccess = { return label('MemberAccessChain', [baseDoc, '[', indexDoc]); } - return [baseDoc, '[', indexDoc]; + return [baseDoc, '[', indexDoc].flat(); } }; diff --git a/src/slang-nodes/FunctionCallExpression.js b/src/slang-nodes/FunctionCallExpression.js index ff625ca5f..e8df5b80c 100644 --- a/src/slang-nodes/FunctionCallExpression.js +++ b/src/slang-nodes/FunctionCallExpression.js @@ -18,7 +18,7 @@ export const FunctionCallExpression = { // arguments accordingly. if (isLabel(operandDoc) && operandDoc.label === 'MemberAccessChain') { operandDoc = group(operandDoc.contents, { - id: `FunctionCall.expression-${groupIndex}` + id: `FunctionCallExpression.operand-${groupIndex}` }); groupIndex += 1; @@ -31,6 +31,6 @@ export const FunctionCallExpression = { return label('MemberAccessChain', [operandDoc, argumentsDoc]); } - return [operandDoc, argumentsDoc]; + return [operandDoc, argumentsDoc].flat(); } }; diff --git a/src/slang-nodes/IndexAccessExpression.js b/src/slang-nodes/IndexAccessExpression.js index ccb202d9c..192d0a8ca 100644 --- a/src/slang-nodes/IndexAccessExpression.js +++ b/src/slang-nodes/IndexAccessExpression.js @@ -30,7 +30,7 @@ export const IndexAccessExpression = { // arguments accordingly. if (isLabel(operandDoc) && operandDoc.label === 'MemberAccessChain') { operandDoc = group(operandDoc.contents, { - id: `IndexAccess.base-${groupIndex}` + id: `IndexAccessExpression.operand-${groupIndex}` }); groupIndex += 1; @@ -43,6 +43,6 @@ export const IndexAccessExpression = { return label('MemberAccessChain', [operandDoc, indexDoc]); } - return [operandDoc, indexDoc]; + return [operandDoc, indexDoc].flat(); } }; diff --git a/src/slang-nodes/MemberAccessExpression.js b/src/slang-nodes/MemberAccessExpression.js index 22d604667..c10c7adac 100644 --- a/src/slang-nodes/MemberAccessExpression.js +++ b/src/slang-nodes/MemberAccessExpression.js @@ -4,19 +4,16 @@ import { isLabel } from '../common/util.js'; const { group, indent, label, softline } = doc.builders; const isEndOfChain = (node, path) => { - let i = 0; - let currentNode = node; - let parentNode = path.getParentNode(i); - while ( - parentNode && + for ( + let i = 0, currentNode = node, grandparentNode = path.getNode(i + 2); [ - 'Expression', 'FunctionCallExpression', 'IndexAccessExpression', 'MemberAccessExpression' - ].includes(parentNode.kind) + ].includes(grandparentNode.kind); + i += 2, currentNode = grandparentNode, grandparentNode = path.getNode(i + 2) ) { - switch (parentNode.kind) { + switch (grandparentNode.kind) { case 'MemberAccessExpression': // If direct ParentNode is a MemberAccess we are not at the end of the // chain. @@ -26,23 +23,19 @@ const isEndOfChain = (node, path) => { // If direct ParentNode is an IndexAccess and currentNode is not the // operand then it must be the start or the end in which case it is the // end of the chain. - if (currentNode !== parentNode.operand) return true; + if (currentNode !== grandparentNode.operand.variant) return true; break; case 'FunctionCallExpression': // If direct ParentNode is a FunctionCall and currentNode is not the // operand then it must be and argument in which case it is the end // of the chain. - if (currentNode !== parentNode.operand) return true; + if (currentNode !== grandparentNode.operand.variant) return true; break; default: break; } - - i += 1; - currentNode = parentNode; - parentNode = path.getParentNode(i); } return true; }; @@ -97,14 +90,15 @@ const processChain = (chain) => { const firstSeparatorIndex = chain.findIndex( (element) => isLabel(element) && element.label === 'separator' ); - // The doc[] before the first separator - const firstExpression = chain.slice(0, firstSeparatorIndex); - // The doc[] containing the rest of the chain - const restOfChain = group(indent(chain.slice(firstSeparatorIndex))); // We wrap the expression in a label in case there is an IndexAccess or // a FunctionCall following this MemberAccess. - return label('MemberAccessChain', group([firstExpression, restOfChain])); + return label('MemberAccessChain', [ + // The doc[] before the first separator + chain.slice(0, firstSeparatorIndex), + // The doc[] containing the rest of the chain + group(indent(chain.slice(firstSeparatorIndex))) + ]); }; export const MemberAccessExpression = { From 13af26e54c2029322076d4f7eeca4fe9da5a0b3e Mon Sep 17 00:00:00 2001 From: Klaus Date: Tue, 11 Jun 2024 16:07:03 +1200 Subject: [PATCH 024/160] Binary Operations --- src/common/slang-helpers.js | 133 ++++++++++++++++++++ src/slang-nodes/AdditiveExpression.js | 8 +- src/slang-nodes/AndExpression.js | 10 +- src/slang-nodes/AssignmentExpression.js | 11 +- src/slang-nodes/BitwiseAndExpression.js | 5 +- src/slang-nodes/BitwiseOrExpression.js | 5 +- src/slang-nodes/BitwiseXorExpression.js | 5 +- src/slang-nodes/ComparisonExpression.js | 8 +- src/slang-nodes/EqualityExpression.js | 8 +- src/slang-nodes/ExponentiationExpression.js | 16 ++- src/slang-nodes/MultiplicativeExpression.js | 8 +- src/slang-nodes/OrExpression.js | 5 +- src/slang-nodes/ShiftExpression.js | 5 +- 13 files changed, 183 insertions(+), 44 deletions(-) diff --git a/src/common/slang-helpers.js b/src/common/slang-helpers.js index 4a318a9dd..cb1cbe32b 100644 --- a/src/common/slang-helpers.js +++ b/src/common/slang-helpers.js @@ -16,3 +16,136 @@ export const printFunction = (functionName, node, path, print) => [ ]), path.call(print, 'body') ]; + +export const binaryOperationKinds = [ + 'AdditiveExpression', + 'MultiplicativeExpression', + 'ExponentiationExpression', + 'AssignmentExpression', + 'BitwiseAndExpression', + 'BitwiseOrExpression', + 'BitwiseXorExpression', + 'ComparisonExpression', + 'EqualityExpression', + 'AndExpression', + 'OrExpression', + 'ShiftExpression' +]; + +const binaryOperationKindsWithoutComparison = binaryOperationKinds.filter( + (kind) => kind !== 'ComparisonExpression' +); + +const binaryGroupRulesBuilder = (path) => (document) => { + const grandparentNode = path.getNode(2); + if (binaryOperationKindsWithoutComparison.includes(grandparentNode.kind)) { + return document; + } + return group(document); +}; + +const binaryIndentRulesBuilder = (path) => (document) => { + let node = path.getNode(); + for (let i = 2; ; i += 2) { + const grandparentNode = path.getNode(i); + if (grandparentNode.kind === 'ReturnStatement') return document; + if (!binaryOperationKindsWithoutComparison.includes(grandparentNode.kind)) { + return indent(document); + } + if (node === grandparentNode.rightOperand.variant) return document; + node = grandparentNode; + } +}; + +const comparisonGroupRulesBuilder = () => (document) => group(document); + +const comparisonStatementsWithoutIndentationKinds = [ + 'ReturnStatement', + 'IfStatement', + 'ForStatement', + 'WhileStatement' +]; + +const comparisonIndentRulesBuilder = (path) => (document) => { + let node = path.getNode(); + for (let i = 2; ; i += 2) { + const grandparentNode = path.getNode(i); + if ( + comparisonStatementsWithoutIndentationKinds.includes(grandparentNode.kind) + ) + return document; + if (!binaryOperationKinds.includes(grandparentNode.kind)) + return indent(document); + if (node === grandparentNode.rightOperand.variant) return document; + node = grandparentNode; + } +}; + +const logicalGroupRulesBuilder = (path) => (document) => + binaryOperationKinds.includes(path.getNode(2).kind) + ? document + : group(document); + +const logicalStatementsWithoutIndentationKinds = + comparisonStatementsWithoutIndentationKinds.filter( + (kind) => kind !== 'ForStatement' + ); + +const logicalIndentRulesBuilder = (path, options) => (document) => { + let node = path.getNode(); + for (let i = 2; ; i += 2) { + const parentNode = path.getNode(i); + if (logicalStatementsWithoutIndentationKinds.includes(parentNode.kind)) + return document; + if ( + options.experimentalTernaries && + parentNode.type === 'ConditionalExpression' && + parentNode.operand.variant === node + ) + return document; + if (!binaryOperationKinds.includes(parentNode.kind)) + return indent(document); + if (node === parentNode.rightOperand.variant) return document; + node = parentNode; + } +}; + +export const rightOperandPrint = (node, path, print) => { + const rightOperand = [line, path.call(print, 'rightOperand')]; + + // If it's a single binary operation, avoid having a small right + // operand like - 1 on its own line + const shouldGroup = + !binaryOperationKinds.includes(node.leftOperand.variant.kind) && + !binaryOperationKinds.includes(path.getNode(2).kind); + + return shouldGroup ? group(rightOperand) : rightOperand; +}; + +const binaryOperationPrintBuilder = + (groupRulesBuilder, indentRulesBuilder) => + ({ node, path, print, options }) => { + const groupRules = groupRulesBuilder(path); + const indentRules = indentRulesBuilder(path, options); + + return groupRules([ + path.call(print, 'leftOperand'), + ` ${node.operator}`, + indentRules(rightOperandPrint(node, path, print)) + ]); + }; + +export const binaryOperationPrint = binaryOperationPrintBuilder( + binaryGroupRulesBuilder, + binaryIndentRulesBuilder +); + +export const comparisonOperationPrint = binaryOperationPrintBuilder( + comparisonGroupRulesBuilder, + comparisonIndentRulesBuilder +); + +export const logicalOperationPrint = binaryOperationPrintBuilder( + logicalGroupRulesBuilder, + logicalIndentRulesBuilder +); diff --git a/src/slang-nodes/AdditiveExpression.js b/src/slang-nodes/AdditiveExpression.js index dc5a23e17..78fb4704a 100644 --- a/src/slang-nodes/AdditiveExpression.js +++ b/src/slang-nodes/AdditiveExpression.js @@ -1,3 +1,5 @@ +import { binaryOperationPrint } from '../common/slang-helpers.js'; + export const AdditiveExpression = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, @@ -5,9 +7,5 @@ export const AdditiveExpression = { operator: ast.operator.text, rightOperand: parse(ast.rightOperand, options, parse) }), - print: ({ node, path, print }) => [ - path.call(print, 'leftOperand'), - ` ${node.operator} `, - path.call(print, 'rightOperand') - ] + print: binaryOperationPrint }; diff --git a/src/slang-nodes/AndExpression.js b/src/slang-nodes/AndExpression.js index af2c8bae6..50a4a8a1e 100644 --- a/src/slang-nodes/AndExpression.js +++ b/src/slang-nodes/AndExpression.js @@ -1,3 +1,5 @@ +import { logicalOperationPrint } from '../common/slang-helpers.js'; + export const AndExpression = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, @@ -5,11 +7,5 @@ export const AndExpression = { operator: ast.operator.text, rightOperand: parse(ast.rightOperand, options, parse) }), - print: ({ node, path, print }) => [ - path.call(print, 'leftOperand'), - ' ', - node.operator, - ' ', - path.call(print, 'rightOperand') - ] + print: logicalOperationPrint }; diff --git a/src/slang-nodes/AssignmentExpression.js b/src/slang-nodes/AssignmentExpression.js index 1eb021f9e..665783cb0 100644 --- a/src/slang-nodes/AssignmentExpression.js +++ b/src/slang-nodes/AssignmentExpression.js @@ -1,3 +1,8 @@ +import { doc } from 'prettier'; +import { binaryOperationKinds } from '../common/slang-helpers.js'; + +const { group, indent, line } = doc.builders; + export const AssignmentExpression = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, @@ -7,7 +12,9 @@ export const AssignmentExpression = { }), print: ({ node, path, print }) => [ path.call(print, 'leftOperand'), - ` ${node.operator} `, - path.call(print, 'rightOperand') + ` ${node.operator}`, + binaryOperationKinds.includes(node.rightOperand.variant.kind) + ? group(indent([line, path.call(print, 'rightOperand')])) + : [' ', path.call(print, 'rightOperand')] ] }; diff --git a/src/slang-nodes/BitwiseAndExpression.js b/src/slang-nodes/BitwiseAndExpression.js index b74b1277e..8c726795a 100644 --- a/src/slang-nodes/BitwiseAndExpression.js +++ b/src/slang-nodes/BitwiseAndExpression.js @@ -1,3 +1,5 @@ +import { binaryOperationPrint } from '../common/slang-helpers.js'; + export const BitwiseAndExpression = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, @@ -5,6 +7,5 @@ export const BitwiseAndExpression = { operator: ast.operator.text, rightOperand: parse(ast.rightOperand, options, parse) }), - // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: BitwiseAndExpression'] + print: binaryOperationPrint }; diff --git a/src/slang-nodes/BitwiseOrExpression.js b/src/slang-nodes/BitwiseOrExpression.js index 640a1285d..c4a808da5 100644 --- a/src/slang-nodes/BitwiseOrExpression.js +++ b/src/slang-nodes/BitwiseOrExpression.js @@ -1,3 +1,5 @@ +import { binaryOperationPrint } from '../common/slang-helpers.js'; + export const BitwiseOrExpression = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, @@ -5,6 +7,5 @@ export const BitwiseOrExpression = { operator: ast.operator.text, rightOperand: parse(ast.rightOperand, options, parse) }), - // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: BitwiseOrExpression'] + print: binaryOperationPrint }; diff --git a/src/slang-nodes/BitwiseXorExpression.js b/src/slang-nodes/BitwiseXorExpression.js index 64b436e2a..56e2b16e6 100644 --- a/src/slang-nodes/BitwiseXorExpression.js +++ b/src/slang-nodes/BitwiseXorExpression.js @@ -1,3 +1,5 @@ +import { binaryOperationPrint } from '../common/slang-helpers.js'; + export const BitwiseXorExpression = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, @@ -5,6 +7,5 @@ export const BitwiseXorExpression = { operator: ast.operator.text, rightOperand: parse(ast.rightOperand, options, parse) }), - // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: BitwiseXorExpression'] + print: binaryOperationPrint }; diff --git a/src/slang-nodes/ComparisonExpression.js b/src/slang-nodes/ComparisonExpression.js index dcdd352b5..e3c2cdb18 100644 --- a/src/slang-nodes/ComparisonExpression.js +++ b/src/slang-nodes/ComparisonExpression.js @@ -1,3 +1,5 @@ +import { comparisonOperationPrint } from '../common/slang-helpers.js'; + export const ComparisonExpression = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, @@ -5,9 +7,5 @@ export const ComparisonExpression = { operator: ast.operator.text, rightOperand: parse(ast.rightOperand, options, parse) }), - print: ({ node, path, print }) => [ - path.call(print, 'leftOperand'), - ` ${node.operator} `, - path.call(print, 'rightOperand') - ] + print: comparisonOperationPrint }; diff --git a/src/slang-nodes/EqualityExpression.js b/src/slang-nodes/EqualityExpression.js index b486a8aa9..22e4bb5b2 100644 --- a/src/slang-nodes/EqualityExpression.js +++ b/src/slang-nodes/EqualityExpression.js @@ -1,3 +1,5 @@ +import { comparisonOperationPrint } from '../common/slang-helpers.js'; + export const EqualityExpression = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, @@ -5,9 +7,5 @@ export const EqualityExpression = { operator: ast.operator.text, rightOperand: parse(ast.rightOperand, options, parse) }), - print: ({ node, path, print }) => [ - path.call(print, 'leftOperand'), - ` ${node.operator} `, - path.call(print, 'rightOperand') - ] + print: comparisonOperationPrint }; diff --git a/src/slang-nodes/ExponentiationExpression.js b/src/slang-nodes/ExponentiationExpression.js index 6306b06bc..fca0f47e6 100644 --- a/src/slang-nodes/ExponentiationExpression.js +++ b/src/slang-nodes/ExponentiationExpression.js @@ -1,3 +1,8 @@ +import { doc } from 'prettier'; +import { rightOperandPrint } from '../common/slang-helpers.js'; + +const { group, indent } = doc.builders; + export const ExponentiationExpression = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, @@ -5,9 +10,10 @@ export const ExponentiationExpression = { operator: ast.operator.text, rightOperand: parse(ast.rightOperand, options, parse) }), - print: ({ node, path, print }) => [ - path.call(print, 'leftOperand'), - node.operator, - path.call(print, 'rightOperand') - ] + print: ({ node, path, print }) => + group([ + path.call(print, 'leftOperand'), + ` ${node.operator}`, + indent(rightOperandPrint(node, path, print)) + ]) }; diff --git a/src/slang-nodes/MultiplicativeExpression.js b/src/slang-nodes/MultiplicativeExpression.js index 374ae5cc4..d4e63036a 100644 --- a/src/slang-nodes/MultiplicativeExpression.js +++ b/src/slang-nodes/MultiplicativeExpression.js @@ -1,3 +1,5 @@ +import { binaryOperationPrint } from '../common/slang-helpers.js'; + export const MultiplicativeExpression = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, @@ -5,9 +7,5 @@ export const MultiplicativeExpression = { operator: ast.operator.text, rightOperand: parse(ast.rightOperand, options, parse) }), - print: ({ node, path, print }) => [ - path.call(print, 'leftOperand'), - ` ${node.operator} `, - path.call(print, 'rightOperand') - ] + print: binaryOperationPrint }; diff --git a/src/slang-nodes/OrExpression.js b/src/slang-nodes/OrExpression.js index 378c82744..eac334b78 100644 --- a/src/slang-nodes/OrExpression.js +++ b/src/slang-nodes/OrExpression.js @@ -1,3 +1,5 @@ +import { logicalOperationPrint } from '../common/slang-helpers.js'; + export const OrExpression = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, @@ -5,6 +7,5 @@ export const OrExpression = { operator: ast.operator.text, rightOperand: parse(ast.rightOperand, options, parse) }), - // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: OrExpression'] + print: logicalOperationPrint }; diff --git a/src/slang-nodes/ShiftExpression.js b/src/slang-nodes/ShiftExpression.js index 0c634563c..732ca023f 100644 --- a/src/slang-nodes/ShiftExpression.js +++ b/src/slang-nodes/ShiftExpression.js @@ -1,3 +1,5 @@ +import { binaryOperationPrint } from '../common/slang-helpers.js'; + export const ShiftExpression = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, @@ -5,6 +7,5 @@ export const ShiftExpression = { operator: ast.operator.text, rightOperand: parse(ast.rightOperand, options, parse) }), - // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: ShiftExpression'] + print: binaryOperationPrint }; From cc892d70b0e4628ec23ce2fdcfcc7d9fed96809c Mon Sep 17 00:00:00 2001 From: Klaus Date: Thu, 13 Jun 2024 14:00:12 +1200 Subject: [PATCH 025/160] slang v0.15.0 --- package-lock.json | 176 ++++++------------ package.json | 14 +- src/slang-nodes/ConstructorAttribute.js | 2 +- src/slang-nodes/ContractDefinition.js | 4 +- src/slang-nodes/ElementaryType.js | 2 +- src/slang-nodes/Expression.js | 2 +- src/slang-nodes/FallbackFunctionAttribute.js | 2 +- src/slang-nodes/ForStatementCondition.js | 2 +- src/slang-nodes/ForStatementInitialization.js | 2 +- src/slang-nodes/FunctionAttribute.js | 2 +- src/slang-nodes/FunctionBody.js | 2 +- src/slang-nodes/ModifierAttribute.js | 2 +- src/slang-nodes/ReceiveFunctionAttribute.js | 2 +- src/slang-nodes/StateVariableAttribute.js | 2 +- src/slang-nodes/UnnamedFunctionAttribute.js | 2 +- src/slang-nodes/UsingTarget.js | 2 +- src/slang-nodes/VariableDeclarationType.js | 2 +- src/slang-nodes/VersionExpression.js | 2 +- src/slang-nodes/YulAssignmentOperator.js | 2 +- src/slang-nodes/YulLiteral.js | 2 +- .../YulVariableAssignmentStatement.js | 15 ++ src/slang-nodes/index.js | 1 + src/slangParser.js | 4 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 30 +-- .../__snapshots__/jsfmt.spec.js.snap | 10 +- 26 files changed, 126 insertions(+), 164 deletions(-) create mode 100644 src/slang-nodes/YulVariableAssignmentStatement.js diff --git a/package-lock.json b/package-lock.json index 675e5b515..510f0bda2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,12 +9,12 @@ "version": "1.3.1", "license": "MIT", "dependencies": { - "@nomicfoundation/slang": "^0.14.2", + "@nomicfoundation/slang": "^0.16.0", "@solidity-parser/parser": "^0.18.0", - "semver": "^7.6.2" + "semver": "^7.6.3" }, "devDependencies": { - "@babel/code-frame": "^7.24.2", + "@babel/code-frame": "^7.24.7", "c8": "^9.1.0", "cross-env": "^7.0.3", "eslint": "^8.57.0", @@ -22,17 +22,17 @@ "eslint-config-prettier": "^9.1.0", "eslint-plugin-import": "^2.29.1", "esm-utils": "^4.3.0", - "esmock": "^2.6.5", + "esmock": "^2.6.7", "jest": "^29.7.0", "jest-light-runner": "^0.6.0", "jest-snapshot-serializer-ansi": "^2.1.0", "jest-snapshot-serializer-raw": "^2.0.0", "jest-watch-typeahead": "^2.2.2", "lines-and-columns": "^2.0.4", - "prettier": "^3.2.5", + "prettier": "^3.3.3", "proxyquire": "^2.1.3", - "solc": "^0.8.25", - "webpack": "^5.91.0", + "solc": "^0.8.26", + "webpack": "^5.93.0", "webpack-cli": "^5.1.4" }, "engines": { @@ -1247,155 +1247,102 @@ } }, "node_modules/@nomicfoundation/slang": { - "version": "0.14.2", - "resolved": "https://registry.npmjs.org/@nomicfoundation/slang/-/slang-0.14.2.tgz", - "integrity": "sha512-3CiiJHuqGo5G9oDhRUDexFMlkguwSQMDcapZtJi+vz8x53HOwH4/ZwzwaNi1ZwKGnwT3fp9dxSzxrLYImFcZhA==", + "version": "0.16.0", + "resolved": "https://registry.npmjs.org/@nomicfoundation/slang/-/slang-0.16.0.tgz", + "integrity": "sha512-JBI+X+6/1WnaVNvnWp7o9PRbIFpgxKDmEKzYnMUfrBGFmm7rT2PsvFvVBoZPeM09B0AFYK+XJt9tqnbJvzhlLw==", + "license": "MIT", + "dependencies": { + "@nomicfoundation/slang-darwin-arm64": "0.16.0", + "@nomicfoundation/slang-darwin-x64": "0.16.0", + "@nomicfoundation/slang-linux-arm64-gnu": "0.16.0", + "@nomicfoundation/slang-linux-arm64-musl": "0.16.0", + "@nomicfoundation/slang-linux-x64-gnu": "0.16.0", + "@nomicfoundation/slang-linux-x64-musl": "0.16.0", + "@nomicfoundation/slang-win32-arm64-msvc": "0.16.0", + "@nomicfoundation/slang-win32-ia32-msvc": "0.16.0", + "@nomicfoundation/slang-win32-x64-msvc": "0.16.0" + }, "engines": { "node": ">= 10" - }, - "optionalDependencies": { - "@nomicfoundation/slang-darwin-arm64": "0.14.2", - "@nomicfoundation/slang-darwin-x64": "0.14.2", - "@nomicfoundation/slang-linux-arm64-gnu": "0.14.2", - "@nomicfoundation/slang-linux-arm64-musl": "0.14.2", - "@nomicfoundation/slang-linux-x64-gnu": "0.14.2", - "@nomicfoundation/slang-linux-x64-musl": "0.14.2", - "@nomicfoundation/slang-win32-arm64-msvc": "0.14.2", - "@nomicfoundation/slang-win32-ia32-msvc": "0.14.2", - "@nomicfoundation/slang-win32-x64-msvc": "0.14.2" } }, "node_modules/@nomicfoundation/slang-darwin-arm64": { - "version": "0.14.2", - "resolved": "https://registry.npmjs.org/@nomicfoundation/slang-darwin-arm64/-/slang-darwin-arm64-0.14.2.tgz", - "integrity": "sha512-ElMGNZHSywlfkP3X9pyym0vaNANSp33Ty/VrYXKABubj2w7+clrzPYQKSjnWv1D7qpJuZwe7SOiHCNCkTEyrVw==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "darwin" - ], + "version": "0.16.0", + "resolved": "https://registry.npmjs.org/@nomicfoundation/slang-darwin-arm64/-/slang-darwin-arm64-0.16.0.tgz", + "integrity": "sha512-tdrpV2/sEy9pWevl6pg2qdG8chV5R2lO80D0vgwP3FTd27vwLRgAdSMSUlhtVSb8NWKx6E1dagjjNfabUzmZpQ==", + "license": "MIT", "engines": { "node": ">= 10" } }, "node_modules/@nomicfoundation/slang-darwin-x64": { - "version": "0.14.2", - "resolved": "https://registry.npmjs.org/@nomicfoundation/slang-darwin-x64/-/slang-darwin-x64-0.14.2.tgz", - "integrity": "sha512-k1LjajxhsU3T0jYmTYIs8S1QAERyOz3YYNL/zhOiah2x8X/jgjHY7dAgkWABzkViQBHUKmc7x8+iUV37h6SuFA==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "darwin" - ], + "version": "0.16.0", + "resolved": "https://registry.npmjs.org/@nomicfoundation/slang-darwin-x64/-/slang-darwin-x64-0.16.0.tgz", + "integrity": "sha512-a4OsidbwzaKOR7693ImYUSRKnmOs1xvTJviln0bc9nr6fngSkzXF7ijlHL/9/FrBhCIR+jY2ozmncWNOmqrvjQ==", + "license": "MIT", "engines": { "node": ">= 10" } }, "node_modules/@nomicfoundation/slang-linux-arm64-gnu": { - "version": "0.14.2", - "resolved": "https://registry.npmjs.org/@nomicfoundation/slang-linux-arm64-gnu/-/slang-linux-arm64-gnu-0.14.2.tgz", - "integrity": "sha512-G5ccD82NlF3ijFS1tqlidL2nlfXoFRG2tFPMFTk7etnPElwi4Tq8O0ajZkel2TYiO4LcKxPlfwpVuVR4AbT58Q==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "linux" - ], + "version": "0.16.0", + "resolved": "https://registry.npmjs.org/@nomicfoundation/slang-linux-arm64-gnu/-/slang-linux-arm64-gnu-0.16.0.tgz", + "integrity": "sha512-4kHqeVbJ6HvmhSIP3p/vS4SjiaC8/TRbeh+6jT77mr6fb6fVxUcVdNwCTVPocn7GRx1rYAsuYqjYZkeS72ubzg==", + "license": "MIT", "engines": { "node": ">= 10" } }, "node_modules/@nomicfoundation/slang-linux-arm64-musl": { - "version": "0.14.2", - "resolved": "https://registry.npmjs.org/@nomicfoundation/slang-linux-arm64-musl/-/slang-linux-arm64-musl-0.14.2.tgz", - "integrity": "sha512-fNeIshoExmikHokUDVbqfV9gDZxtGlJ5cFs3TdwxwWgqEp56V1ByWJ4wGPDQBTwv2p2fil/97LyxnOenHXeOkQ==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "linux" - ], + "version": "0.16.0", + "resolved": "https://registry.npmjs.org/@nomicfoundation/slang-linux-arm64-musl/-/slang-linux-arm64-musl-0.16.0.tgz", + "integrity": "sha512-seuEaQSEGa3yqBI6Y/HH4X10+f7BNkX5OzOTNjWejqSIFAVBj0mWNBNWetT2YWDHRqiOSm5khD3+8LaSvShDRQ==", + "license": "MIT", "engines": { "node": ">= 10" } }, "node_modules/@nomicfoundation/slang-linux-x64-gnu": { - "version": "0.14.2", - "resolved": "https://registry.npmjs.org/@nomicfoundation/slang-linux-x64-gnu/-/slang-linux-x64-gnu-0.14.2.tgz", - "integrity": "sha512-kixwVCuvq1TVemPp7Cm6VbpJKmbIcPxhHK4CatOn/Nxm2p35iSBPn/E5OiqwPTjHk+nD684WnuOsZGEvf9NKlg==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "linux" - ], + "version": "0.16.0", + "resolved": "https://registry.npmjs.org/@nomicfoundation/slang-linux-x64-gnu/-/slang-linux-x64-gnu-0.16.0.tgz", + "integrity": "sha512-DI8sIWhz1EsuAE2L4vlBM48WaSaWpRgUixG1ZHIlxpTwzn6s+DxmfAxmOcBeLpNdtfba9eSpqF+2539zllktPQ==", + "license": "MIT", "engines": { "node": ">= 10" } }, "node_modules/@nomicfoundation/slang-linux-x64-musl": { - "version": "0.14.2", - "resolved": "https://registry.npmjs.org/@nomicfoundation/slang-linux-x64-musl/-/slang-linux-x64-musl-0.14.2.tgz", - "integrity": "sha512-oX9ihC3nYyZjG19GxfFthiZJTZkOhYAqyI7YhbPh0BWfAqf3/FxADQkv+4cXv3sb+SsXo4yOVhgVuOq75qWxUw==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "linux" - ], + "version": "0.16.0", + "resolved": "https://registry.npmjs.org/@nomicfoundation/slang-linux-x64-musl/-/slang-linux-x64-musl-0.16.0.tgz", + "integrity": "sha512-80obGwJ336r5wxQ/dLzEDp1nlAYtMWdnP5G5T2JmCnIkxxEVnyQIH62VcK6mc7RMSVeAlL1RGGx2LdNbk9V4QA==", + "license": "MIT", "engines": { "node": ">= 10" } }, "node_modules/@nomicfoundation/slang-win32-arm64-msvc": { - "version": "0.14.2", - "resolved": "https://registry.npmjs.org/@nomicfoundation/slang-win32-arm64-msvc/-/slang-win32-arm64-msvc-0.14.2.tgz", - "integrity": "sha512-VMH2xc0q+iZQ9oGA2NhecYh6GhJAf+M2a+h0IKU+OTbmREUL1nH12huc5wmFzWSdgKyJAyVidCQvcLhgYSoSkw==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "win32" - ], + "version": "0.16.0", + "resolved": "https://registry.npmjs.org/@nomicfoundation/slang-win32-arm64-msvc/-/slang-win32-arm64-msvc-0.16.0.tgz", + "integrity": "sha512-hcmsfXjRaCuy5/eUhrdDOnE5uqfJ0vVXvon5mTHaWzf6UE4REIx3vJwf/t4QQu1Q4mKKO5ZxzauBdzRtbhOKsw==", + "license": "MIT", "engines": { "node": ">= 10" } }, "node_modules/@nomicfoundation/slang-win32-ia32-msvc": { - "version": "0.14.2", - "resolved": "https://registry.npmjs.org/@nomicfoundation/slang-win32-ia32-msvc/-/slang-win32-ia32-msvc-0.14.2.tgz", - "integrity": "sha512-z99gbFnAGyA8D/yZoos8S7/VgP0SHrKMt8RcAHluC1UIQ0EnNYJrGwhVVTWPv6PPphoz11nF/UyUZ2cVsBcy0Q==", - "cpu": [ - "ia32" - ], - "optional": true, - "os": [ - "win32" - ], + "version": "0.16.0", + "resolved": "https://registry.npmjs.org/@nomicfoundation/slang-win32-ia32-msvc/-/slang-win32-ia32-msvc-0.16.0.tgz", + "integrity": "sha512-W9959+Tdq71kkE5EGxoQWBxhpe9bjxpY7ozDoPjz2lBzaGi8X24z4toS6us3W83URIf6Cve0VizAX4fz5MWjFw==", + "license": "MIT", "engines": { "node": ">= 10" } }, "node_modules/@nomicfoundation/slang-win32-x64-msvc": { - "version": "0.14.2", - "resolved": "https://registry.npmjs.org/@nomicfoundation/slang-win32-x64-msvc/-/slang-win32-x64-msvc-0.14.2.tgz", - "integrity": "sha512-Av9WnISDikCW+tFf8E8+CE5bGM3K1FRC4yXnZnpPlQmQRIk4RkYQYzFMrAtDdO5NUmgSgVoCDlld5DkQ6vCQxg==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "win32" - ], + "version": "0.16.0", + "resolved": "https://registry.npmjs.org/@nomicfoundation/slang-win32-x64-msvc/-/slang-win32-x64-msvc-0.16.0.tgz", + "integrity": "sha512-sOKuMtm3g62ugdhgpWqjF+o3clIR4eAIiAbx6oRPGB/9fPukgZnI5untsgTYJyVldAzby7jlIQ4R7df18aNraw==", + "license": "MIT", "engines": { "node": ">= 10" } @@ -6955,10 +6902,11 @@ } }, "node_modules/solc": { - "version": "0.8.25", - "resolved": "https://registry.npmjs.org/solc/-/solc-0.8.25.tgz", - "integrity": "sha512-7P0TF8gPeudl1Ko3RGkyY6XVCxe2SdD/qQhtns1vl3yAbK/PDifKDLHGtx1t7mX3LgR7ojV7Fg/Kc6Q9D2T8UQ==", + "version": "0.8.26", + "resolved": "https://registry.npmjs.org/solc/-/solc-0.8.26.tgz", + "integrity": "sha512-yiPQNVf5rBFHwN6SIf3TUUvVAFKcQqmSUFeq+fb6pNRCo0ZCgpYOZDi3BVoezCPIAcKrVYd/qXlBLUP9wVrZ9g==", "dev": true, + "license": "MIT", "dependencies": { "command-exists": "^1.2.8", "commander": "^8.1.0", diff --git a/package.json b/package.json index 8df12a436..28b75a3c6 100644 --- a/package.json +++ b/package.json @@ -87,7 +87,7 @@ "node": ">=16" }, "devDependencies": { - "@babel/code-frame": "^7.24.2", + "@babel/code-frame": "^7.24.7", "c8": "^9.1.0", "cross-env": "^7.0.3", "eslint": "^8.57.0", @@ -95,23 +95,23 @@ "eslint-config-prettier": "^9.1.0", "eslint-plugin-import": "^2.29.1", "esm-utils": "^4.3.0", - "esmock": "^2.6.5", + "esmock": "^2.6.7", "jest": "^29.7.0", "jest-light-runner": "^0.6.0", "jest-snapshot-serializer-ansi": "^2.1.0", "jest-snapshot-serializer-raw": "^2.0.0", "jest-watch-typeahead": "^2.2.2", "lines-and-columns": "^2.0.4", - "prettier": "^3.2.5", + "prettier": "^3.3.3", "proxyquire": "^2.1.3", - "solc": "^0.8.25", - "webpack": "^5.91.0", + "solc": "^0.8.26", + "webpack": "^5.93.0", "webpack-cli": "^5.1.4" }, "dependencies": { - "@nomicfoundation/slang": "^0.14.2", + "@nomicfoundation/slang": "^0.16.0", "@solidity-parser/parser": "^0.18.0", - "semver": "^7.6.2" + "semver": "^7.6.3" }, "peerDependencies": { "prettier": ">=2.3.0" diff --git a/src/slang-nodes/ConstructorAttribute.js b/src/slang-nodes/ConstructorAttribute.js index 31d1c2825..21c4e416f 100644 --- a/src/slang-nodes/ConstructorAttribute.js +++ b/src/slang-nodes/ConstructorAttribute.js @@ -2,7 +2,7 @@ export const ConstructorAttribute = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, variant: - ast.variant.type === 'Token' + ast.variant.type === 'Terminal' ? ast.variant.text : parse(ast.variant, options, parse) }), diff --git a/src/slang-nodes/ContractDefinition.js b/src/slang-nodes/ContractDefinition.js index 98f512398..7c060c6e9 100644 --- a/src/slang-nodes/ContractDefinition.js +++ b/src/slang-nodes/ContractDefinition.js @@ -8,8 +8,8 @@ export const ContractDefinition = { abstractKeyword: ast.abstractKeyword?.text, contractKeyword: ast.contractKeyword.text, name: ast.name.text, - inheritance: ast.inheritence - ? parse(ast.inheritence, options, parse) + inheritance: ast.inheritance + ? parse(ast.inheritance, options, parse) : undefined, openBrace: ast.openBrace.text, members: parse(ast.members, options, parse), diff --git a/src/slang-nodes/ElementaryType.js b/src/slang-nodes/ElementaryType.js index 48d9abea7..3fa2350fa 100644 --- a/src/slang-nodes/ElementaryType.js +++ b/src/slang-nodes/ElementaryType.js @@ -2,7 +2,7 @@ export const ElementaryType = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, variant: - ast.variant.type === 'Token' + ast.variant.type === 'Terminal' ? ast.variant.text : parse(ast.variant, options, parse) }), diff --git a/src/slang-nodes/Expression.js b/src/slang-nodes/Expression.js index 36e7f6d38..23ee1af7f 100644 --- a/src/slang-nodes/Expression.js +++ b/src/slang-nodes/Expression.js @@ -2,7 +2,7 @@ export const Expression = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, variant: - ast.variant.type === 'Token' + ast.variant.type === 'Terminal' ? ast.variant.text : parse(ast.variant, options, parse) }), diff --git a/src/slang-nodes/FallbackFunctionAttribute.js b/src/slang-nodes/FallbackFunctionAttribute.js index c7a1dfcad..0380aea4e 100644 --- a/src/slang-nodes/FallbackFunctionAttribute.js +++ b/src/slang-nodes/FallbackFunctionAttribute.js @@ -2,7 +2,7 @@ export const FallbackFunctionAttribute = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, variant: - ast.variant.type === 'Token' + ast.variant.type === 'Terminal' ? ast.variant.text : parse(ast.variant, options, parse) }), diff --git a/src/slang-nodes/ForStatementCondition.js b/src/slang-nodes/ForStatementCondition.js index da1cb8a1f..a81e588d2 100644 --- a/src/slang-nodes/ForStatementCondition.js +++ b/src/slang-nodes/ForStatementCondition.js @@ -2,7 +2,7 @@ export const ForStatementCondition = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, variant: - ast.variant.type === 'Token' + ast.variant.type === 'Terminal' ? ast.variant.text : parse(ast.variant, options, parse) }), diff --git a/src/slang-nodes/ForStatementInitialization.js b/src/slang-nodes/ForStatementInitialization.js index e44f69153..041651d48 100644 --- a/src/slang-nodes/ForStatementInitialization.js +++ b/src/slang-nodes/ForStatementInitialization.js @@ -2,7 +2,7 @@ export const ForStatementInitialization = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, variant: - ast.variant.type === 'Token' + ast.variant.type === 'Terminal' ? ast.variant.text : parse(ast.variant, options, parse) }), diff --git a/src/slang-nodes/FunctionAttribute.js b/src/slang-nodes/FunctionAttribute.js index 8a14b9e1e..7a213202d 100644 --- a/src/slang-nodes/FunctionAttribute.js +++ b/src/slang-nodes/FunctionAttribute.js @@ -2,7 +2,7 @@ export const FunctionAttribute = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, variant: - ast.variant.type === 'Token' + ast.variant.type === 'Terminal' ? ast.variant.text : parse(ast.variant, options, parse) }), diff --git a/src/slang-nodes/FunctionBody.js b/src/slang-nodes/FunctionBody.js index 85fc94969..9d24097a1 100644 --- a/src/slang-nodes/FunctionBody.js +++ b/src/slang-nodes/FunctionBody.js @@ -3,7 +3,7 @@ export const FunctionBody = { kind: ast.cst.kind, variant: - ast.variant.type === 'Token' + ast.variant.type === 'Terminal' ? ast.variant.text : parse(ast.variant, options, parse) }), diff --git a/src/slang-nodes/ModifierAttribute.js b/src/slang-nodes/ModifierAttribute.js index 490f18c7f..c4d3b92a5 100644 --- a/src/slang-nodes/ModifierAttribute.js +++ b/src/slang-nodes/ModifierAttribute.js @@ -2,7 +2,7 @@ export const ModifierAttribute = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, variant: - ast.variant.type === 'Token' + ast.variant.type === 'Terminal' ? ast.variant.text : parse(ast.variant, options, parse) }), diff --git a/src/slang-nodes/ReceiveFunctionAttribute.js b/src/slang-nodes/ReceiveFunctionAttribute.js index 81355f8b7..643ae3ce8 100644 --- a/src/slang-nodes/ReceiveFunctionAttribute.js +++ b/src/slang-nodes/ReceiveFunctionAttribute.js @@ -2,7 +2,7 @@ export const ReceiveFunctionAttribute = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, variant: - ast.variant.type === 'Token' + ast.variant.type === 'Terminal' ? ast.variant.text : parse(ast.variant, options, parse) }), diff --git a/src/slang-nodes/StateVariableAttribute.js b/src/slang-nodes/StateVariableAttribute.js index 8002e595c..87fec344b 100644 --- a/src/slang-nodes/StateVariableAttribute.js +++ b/src/slang-nodes/StateVariableAttribute.js @@ -2,7 +2,7 @@ export const StateVariableAttribute = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, variant: - ast.variant.type === 'Token' + ast.variant.type === 'Terminal' ? ast.variant.text : parse(ast.variant, options, parse) }), diff --git a/src/slang-nodes/UnnamedFunctionAttribute.js b/src/slang-nodes/UnnamedFunctionAttribute.js index 537161b10..38d90f3dd 100644 --- a/src/slang-nodes/UnnamedFunctionAttribute.js +++ b/src/slang-nodes/UnnamedFunctionAttribute.js @@ -2,7 +2,7 @@ export const UnnamedFunctionAttribute = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, variant: - ast.variant.type === 'Token' + ast.variant.type === 'Terminal' ? ast.variant.text : parse(ast.variant, options, parse) }), diff --git a/src/slang-nodes/UsingTarget.js b/src/slang-nodes/UsingTarget.js index a1beac643..777b38dec 100644 --- a/src/slang-nodes/UsingTarget.js +++ b/src/slang-nodes/UsingTarget.js @@ -2,7 +2,7 @@ export const UsingTarget = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, variant: - ast.variant.type === 'Token' + ast.variant.type === 'Terminal' ? ast.variant.text : parse(ast.variant, options, parse) }), diff --git a/src/slang-nodes/VariableDeclarationType.js b/src/slang-nodes/VariableDeclarationType.js index 57333db53..385761950 100644 --- a/src/slang-nodes/VariableDeclarationType.js +++ b/src/slang-nodes/VariableDeclarationType.js @@ -2,7 +2,7 @@ export const VariableDeclarationType = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, variant: - ast.variant.type === 'Token' + ast.variant.type === 'Terminal' ? ast.variant.text : parse(ast.variant, options, parse) }), diff --git a/src/slang-nodes/VersionExpression.js b/src/slang-nodes/VersionExpression.js index 61675bfbd..534aa89b6 100644 --- a/src/slang-nodes/VersionExpression.js +++ b/src/slang-nodes/VersionExpression.js @@ -2,7 +2,7 @@ export const VersionExpression = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, variant: - ast.variant.type === 'Token' + ast.variant.type === 'Terminal' ? ast.variant.text : parse(ast.variant, options, parse) }), diff --git a/src/slang-nodes/YulAssignmentOperator.js b/src/slang-nodes/YulAssignmentOperator.js index e3c840c7c..c2377681b 100644 --- a/src/slang-nodes/YulAssignmentOperator.js +++ b/src/slang-nodes/YulAssignmentOperator.js @@ -2,7 +2,7 @@ export const YulAssignmentOperator = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, variant: - ast.variant.type === 'Token' + ast.variant.type === 'Terminal' ? ast.variant.text : parse(ast.variant, options, parse) }), diff --git a/src/slang-nodes/YulLiteral.js b/src/slang-nodes/YulLiteral.js index 8b0959e3e..854b26455 100644 --- a/src/slang-nodes/YulLiteral.js +++ b/src/slang-nodes/YulLiteral.js @@ -2,7 +2,7 @@ export const YulLiteral = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, variant: - ast.variant.type === 'Token' + ast.variant.type === 'Terminal' ? ast.variant.text : parse(ast.variant, options, parse) }), diff --git a/src/slang-nodes/YulVariableAssignmentStatement.js b/src/slang-nodes/YulVariableAssignmentStatement.js new file mode 100644 index 000000000..532b5fd19 --- /dev/null +++ b/src/slang-nodes/YulVariableAssignmentStatement.js @@ -0,0 +1,15 @@ +export const YulVariableAssignmentStatement = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + names: parse(ast.names, options, parse), + assignment: parse(ast.assignment, options, parse), + expression: parse(ast.expression, options, parse) + }), + print: ({ path, print }) => [ + path.call(print, 'names'), + ' ', + path.call(print, 'assignment'), + ' ', + path.call(print, 'expression') + ] +}; diff --git a/src/slang-nodes/index.js b/src/slang-nodes/index.js index 08281f0b0..707b49cd4 100644 --- a/src/slang-nodes/index.js +++ b/src/slang-nodes/index.js @@ -209,5 +209,6 @@ export * from './YulSwitchCase.js'; export * from './YulSwitchCases.js'; export * from './YulSwitchStatement.js'; export * from './YulValueCase.js'; +export * from './YulVariableAssignmentStatement.js'; export * from './YulVariableDeclarationStatement.js'; export * from './YulVariableDeclarationValue.js'; diff --git a/src/slangParser.js b/src/slangParser.js index 687f5e252..846fa13d8 100644 --- a/src/slangParser.js +++ b/src/slangParser.js @@ -1,7 +1,7 @@ // https://prettier.io/docs/en/plugins.html#parsers // import parser from '@solidity-parser/parser'; import { Language } from '@nomicfoundation/slang/language/index.js'; -import { RuleKind } from '@nomicfoundation/slang/kinds/index.js'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SourceUnit } from '@nomicfoundation/slang/ast/index.js'; import coerce from 'semver/functions/coerce.js'; import * as parsers from './slang-nodes/index.js'; @@ -15,7 +15,7 @@ function parse(text, _parsers, options = _parsers) { const language = new Language(compiler?.version || '0.8.25'); const parsed = new SourceUnit( - language.parse(RuleKind.SourceUnit, text).tree() + language.parse(NonterminalKind.SourceUnit, text).tree() ); return genericParse(parsed, options, genericParse); diff --git a/tests/format/BreakingChangesV0.8.0/__snapshots__/jsfmt.spec.js.snap b/tests/format/BreakingChangesV0.8.0/__snapshots__/jsfmt.spec.js.snap index e44a22f8e..6e12b0321 100644 --- a/tests/format/BreakingChangesV0.8.0/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/BreakingChangesV0.8.0/__snapshots__/jsfmt.spec.js.snap @@ -146,7 +146,7 @@ contract BreakingChangesV080 { =====================================output===================================== contract BreakingChangesV080 { - uint a = 1**2**3; + uint a = 1 ** 2 ** 3; bytes1 public c; byte public g; struct S { diff --git a/tests/format/IfStatements/__snapshots__/jsfmt.spec.js.snap b/tests/format/IfStatements/__snapshots__/jsfmt.spec.js.snap index 17e140fb4..edc8386fd 100644 --- a/tests/format/IfStatements/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/IfStatements/__snapshots__/jsfmt.spec.js.snap @@ -948,40 +948,40 @@ contract IfStatements { return false; } if ( - veryComplicatedComputation(variable1, variable2) == ( - 400 + 500 - ) * 1000 + veryComplicatedComputation(variable1, variable2) == + (400 + 500) * + 1000 ) { return true; } if (simpleIf) { return true; } else if ( - veryComplicatedComputation(variable3, variable4) == ( - 400 + 500 - ) * 1000 + veryComplicatedComputation(variable3, variable4) == + (400 + 500) * + 1000 ) { return (true, false); } else return false; if ( - veryComplicatedComputation(variable1, variable2) == ( - 400 + 500 - ) * 1000 + veryComplicatedComputation(variable1, variable2) == + (400 + 500) * + 1000 ) { return true; } else if (simpleElseIf) { return (true, false); } else return false; if ( - veryComplicatedComputation(variable1, variable2) == ( - 400 + 500 - ) * 1000 + veryComplicatedComputation(variable1, variable2) == + (400 + 500) * + 1000 ) { return true; } else if ( - veryComplicatedComputation(variable3, variable4) == ( - 400 + 500 - ) * 1000 + veryComplicatedComputation(variable3, variable4) == + (400 + 500) * + 1000 ) { return (true, false); } else return false; diff --git a/tests/format/WhileStatements/__snapshots__/jsfmt.spec.js.snap b/tests/format/WhileStatements/__snapshots__/jsfmt.spec.js.snap index 29831e2a2..aab46f171 100644 --- a/tests/format/WhileStatements/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/WhileStatements/__snapshots__/jsfmt.spec.js.snap @@ -169,12 +169,10 @@ contract WhileStatements { while(a < 400){ a = a.add(LONG_VARIABLE).add(LONG_VARIABLE).add(LONG_VARIABLE); } - while(a < veryLongVariableName.add(LONG_VARIABLE).add( - LONG_VARIABLE - ) * 500)a++; - while(a < veryLongVariableName.add(LONG_VARIABLE).add( - LONG_VARIABLE - ) * 600){ + while(a < + veryLongVariableName.add(LONG_VARIABLE).add(LONG_VARIABLE) * 500)a++; + while(a < + veryLongVariableName.add(LONG_VARIABLE).add(LONG_VARIABLE) * 600){ a++; } } From b1b5be8a4de32e3d5fc2778828fb6ed3d4b09dd8 Mon Sep 17 00:00:00 2001 From: Klaus Date: Fri, 14 Jun 2024 13:19:47 +1200 Subject: [PATCH 026/160] WIP: 201/215 printers implemented --- src/common/slang-helpers.js | 4 +- src/slang-nodes/ABICoderPragma.js | 3 +- src/slang-nodes/ExperimentalFeature.js | 13 + src/slang-nodes/ExperimentalPragma.js | 10 +- src/slang-nodes/FunctionType.js | 6 +- src/slang-nodes/FunctionTypeAttributes.js | 8 +- src/slang-nodes/Parameters.js | 6 +- src/slang-nodes/PrefixExpression.js | 3 +- src/slang-nodes/index.js | 1 + .../Assembly/__snapshots__/jsfmt.spec.js.snap | 464 +++ tests/format/Assembly/jsfmt.spec.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 1127 +++++- tests/format/BinaryOperators/jsfmt.spec.js | 1 + .../Etc/__snapshots__/jsfmt.spec.js.snap | 127 + tests/format/Etc/jsfmt.spec.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 2855 ++++++++++++--- .../ExperimentalTernaries/jsfmt.spec.js | 13 + .../FunctionDefinitions.sol | 12 +- .../__snapshots__/jsfmt.spec.js.snap | 806 ++++- .../format/FunctionDefinitions/jsfmt.spec.js | 1 + .../DefaultFunctionDefinitions.sol | 4 + .../__snapshots__/jsfmt.spec.js.snap | 42 + .../FunctionDefinitionsv0.5.0/jsfmt.spec.js | 2 + .../__snapshots__/jsfmt.spec.js.snap | 30 +- tests/format/HexLiteral/jsfmt.spec.js | 10 +- .../__snapshots__/jsfmt.spec.js.snap | 48 + tests/format/Immutable/jsfmt.spec.js | 1 + .../Inbox/__snapshots__/jsfmt.spec.js.snap | 57 + tests/format/Inbox/jsfmt.spec.js | 1 + .../IndexOf/__snapshots__/jsfmt.spec.js.snap | 115 + tests/format/IndexOf/jsfmt.spec.js | 1 + .../Issues/__snapshots__/jsfmt.spec.js.snap | 202 ++ tests/format/Issues/jsfmt.spec.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 232 ++ tests/format/MemberAccess/jsfmt.spec.js | 1 + .../Ownable/__snapshots__/jsfmt.spec.js.snap | 121 + tests/format/Ownable/jsfmt.spec.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 3147 ++++++++++++++--- tests/format/Parentheses/jsfmt.spec.js | 1 + tests/format/Pragma/Pragma.sol | 2 + .../Pragma/__snapshots__/jsfmt.spec.js.snap | 36 + tests/format/Pragma/jsfmt.spec.js | 1 + 42 files changed, 8329 insertions(+), 1189 deletions(-) create mode 100644 src/slang-nodes/ExperimentalFeature.js create mode 100644 tests/format/FunctionDefinitionsv0.5.0/DefaultFunctionDefinitions.sol create mode 100644 tests/format/FunctionDefinitionsv0.5.0/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/format/FunctionDefinitionsv0.5.0/jsfmt.spec.js diff --git a/src/common/slang-helpers.js b/src/common/slang-helpers.js index cb1cbe32b..a33c69cbb 100644 --- a/src/common/slang-helpers.js +++ b/src/common/slang-helpers.js @@ -10,11 +10,11 @@ export const printFunction = (functionName, node, path, print) => [ group([ path.call(print, 'attributes'), node.returns ? [line, path.call(print, 'returns')] : '', - node.body.variant !== ';' ? dedent(line) : '' + node.body?.variant !== ';' ? dedent(line) : '' ]) ) ]), - path.call(print, 'body') + node.body ? path.call(print, 'body') : '' ]; export const binaryOperationKinds = [ diff --git a/src/slang-nodes/ABICoderPragma.js b/src/slang-nodes/ABICoderPragma.js index 4129f8255..24bad49f1 100644 --- a/src/slang-nodes/ABICoderPragma.js +++ b/src/slang-nodes/ABICoderPragma.js @@ -4,6 +4,5 @@ export const ABICoderPragma = { abicoderKeyword: ast.abicoderKeyword.text, version: ast.version.text }), - // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: ABICoderPragma'] + print: ({ node }) => `${node.abicoderKeyword} ${node.version}` }; diff --git a/src/slang-nodes/ExperimentalFeature.js b/src/slang-nodes/ExperimentalFeature.js new file mode 100644 index 000000000..6f2845222 --- /dev/null +++ b/src/slang-nodes/ExperimentalFeature.js @@ -0,0 +1,13 @@ +export const ExperimentalFeature = { + parse: ({ ast, options, parse }) => ({ + kind: ast.cst.kind, + variant: + ast.variant.type === 'Terminal' + ? ast.variant.text + : parse(ast.variant, options, parse) + }), + print: ({ node, path, print }) => + typeof node.variant === 'string' + ? node.variant + : path.call(print, 'variant') +}; diff --git a/src/slang-nodes/ExperimentalPragma.js b/src/slang-nodes/ExperimentalPragma.js index e67553bdf..1d0c21072 100644 --- a/src/slang-nodes/ExperimentalPragma.js +++ b/src/slang-nodes/ExperimentalPragma.js @@ -1,9 +1,11 @@ export const ExperimentalPragma = { - parse: ({ ast }) => ({ + parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, experimentalKeyword: ast.experimentalKeyword.text, - feature: ast.feature + feature: parse(ast.feature, options, parse) }), - // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: ExperimentalPragma'] + print: ({ node, path, print }) => [ + `${node.experimentalKeyword} `, + path.call(print, 'feature') + ] }; diff --git a/src/slang-nodes/FunctionType.js b/src/slang-nodes/FunctionType.js index 6c650ba94..f548c7fc8 100644 --- a/src/slang-nodes/FunctionType.js +++ b/src/slang-nodes/FunctionType.js @@ -1,3 +1,5 @@ +import { printFunction } from '../common/slang-helpers.js'; + export const FunctionType = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, @@ -6,6 +8,6 @@ export const FunctionType = { attributes: parse(ast.attributes, options, parse), returns: ast.returns ? parse(ast.returns, options, parse) : undefined }), - // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: FunctionType'] + print: ({ node, path, print }) => + printFunction(`${node.functionKeyword} `, node, path, print) }; diff --git a/src/slang-nodes/FunctionTypeAttributes.js b/src/slang-nodes/FunctionTypeAttributes.js index 769fba83b..10713231d 100644 --- a/src/slang-nodes/FunctionTypeAttributes.js +++ b/src/slang-nodes/FunctionTypeAttributes.js @@ -1,8 +1,12 @@ +import { doc } from 'prettier'; + +const { line } = doc.builders; + export const FunctionTypeAttributes = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), - // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: FunctionTypeAttributes'] + print: ({ path, print }) => + path.map(print, 'items').map((item) => [line, item]) }; diff --git a/src/slang-nodes/Parameters.js b/src/slang-nodes/Parameters.js index 8a5834766..6de87a169 100644 --- a/src/slang-nodes/Parameters.js +++ b/src/slang-nodes/Parameters.js @@ -6,6 +6,8 @@ export const Parameters = { items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), - print: ({ path, print }) => - printSeparatedList(path.map(print, 'items'), { grouped: false }) + print: ({ node, path, print }) => + node.items.length > 0 + ? printSeparatedList(path.map(print, 'items'), { grouped: false }) + : '' }; diff --git a/src/slang-nodes/PrefixExpression.js b/src/slang-nodes/PrefixExpression.js index 2b75c24dc..a3d66ea00 100644 --- a/src/slang-nodes/PrefixExpression.js +++ b/src/slang-nodes/PrefixExpression.js @@ -4,6 +4,5 @@ export const PrefixExpression = { operator: ast.operator.text, operand: parse(ast.operand, options, parse) }), - // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: PrefixExpression'] + print: ({ node, path, print }) => [node.operator, path.call(print, 'operand')] }; diff --git a/src/slang-nodes/index.js b/src/slang-nodes/index.js index 707b49cd4..d5d9083ae 100644 --- a/src/slang-nodes/index.js +++ b/src/slang-nodes/index.js @@ -46,6 +46,7 @@ export * from './EventDefinition.js'; export * from './EventParameter.js'; export * from './EventParameters.js'; export * from './EventParametersDeclaration.js'; +export * from './ExperimentalFeature.js'; export * from './ExperimentalPragma.js'; export * from './ExponentiationExpression.js'; export * from './Expression.js'; diff --git a/tests/format/Assembly/__snapshots__/jsfmt.spec.js.snap b/tests/format/Assembly/__snapshots__/jsfmt.spec.js.snap index ed490afe9..c3340b15c 100644 --- a/tests/format/Assembly/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Assembly/__snapshots__/jsfmt.spec.js.snap @@ -518,3 +518,467 @@ contract AssemblyStackAssignment { ================================================================================ `; + +exports[`Assembly.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +contract Assembly { + function ifAssembly() { + assembly { + if + returndatasize { + success := 0 + } + } + } + + function caseAssembly() { + assembly { + switch value + case 0 { + mstore(0, 0x0000000000000000000000000000000000000000000000000000000000000000) + } + case 1 { + mstore(0, 0x1111111111111111111111111111111111111111111111111111111111111111) + } + } + } + + function forAssembly() { + assembly { +for { let i := 0 } lt(i, x) { i := add(i, 1) } { y := mul(2, y) } + } + } + + function callWithComments() { + assembly { + f( + 1, // one + 2, // two + 3 // three + ) + } + } + + function assemblyFunctionNoParameters() { + assembly { + function getAnswer () + -> answer { + answer:= 42 + } + } + } + + function assemblyFunctionOneParameter() { + assembly { + function inc (x) + -> result { + result := add(x, + 1) + } + } + } + + function assemblyFunctionThreeParameters() { + assembly { + function sum (a, b, c) + -> result { + result := add(a, + add(b, c)) + } + } + } + + function assemblyFunctionLongParameters() { + assembly { + function sum (thisIs, aFunctionWithVery, veryLongParameterNames, andItAlsoHasALotOfParameters, soItShouldBeSplitInMultipleLines) + -> result { + result := 0 + } + } + } + + function assemblyFunctionLongReturnParameters() { + assembly { + function sum (a, b, c, d, e) + -> thisIs, aFunctionWithVery, veryLongParameterNames, andItAlsoHasALotOfParameters, soItShouldBeSplitInMultipleLines { + thisIs := 0 + aFunctionWithVery := 0 + veryLongParameterNames := 0 + andItAlsoHasALotOfParameters := 0 + soItShouldBeSplitInMultipleLines := 0 + } + } + } + + + function assemblyFunctionLongParametersAndReturnParameters() { + assembly { + function sum (a,veryLong, listof, parameters, thatShould,splitForSure) + -> thisIs, aFunctionWithVery, veryLongParameterNames, andItAlsoHasALotOfParameters, soItShouldBeSplitInMultipleLines { + thisIs := 0 + aFunctionWithVery := 0 + veryLongParameterNames := 0 + andItAlsoHasALotOfParameters := 0 + soItShouldBeSplitInMultipleLines := 0 + } + } + } + + function assemblyNoParameterCalls() { + assembly { + call(gas(), to, value, inputData, inputDataSize, 0, 0) + } + } + + function assemblyLabels() { + assembly { + let n := calldataload(4) + let a := 1 + let b := a +loop: + jumpi(loopend, eq(n, 0)) + a add swap1 + n := sub(n, 1) + jump(loop) + +loopend: + mstore(0, a) + return(0, 0x20) +} + +assembly{ + let x := 8 + jump(two) + one: + // Here the stack height is 2 (because we pushed x and 7), + // but the assembler thinks it is 1 because it reads + // from top to bottom. + // Accessing the stack variable x here will lead to errors. + x := 9 + jump(three) + two: + 7 // push something onto the stack + jump(one) + three: +} +} + + function assemblyFunctionNoReturn () { + + assembly { + +function $somefn(somearg) { +} + } + } + + function letWithoutValue ( ) { + + assembly { let result } + } + + function memberAccess ( ) { + + assembly { + ds.slot := position + offset := x.offset + } + } + + function commentsInAssemblyBlock () { + + assembly { + /* foo bar baz */ + /* foobbbbbb */ + } + } + + function withBreak() { + assembly { + for {} 1 {} { + break + } + } + } + + function memorySafe() { + assembly ("memory-safe") { + } + assembly "evmasm" ("memory-safe") { + } + } + +function continueAndBreak(uint256 x) public pure returns (uint a, uint b){ +assembly { +for { let i := 0 } lt(i, x) { i := add(i, 1) } { + if lt(i, 10) { + a := add(a, i) + continue + } + if eq(i, 15) { + break + } + + b := i + } +} +} +} + +contract BooleanLiteralsInAssembly { + function f() { + uint a; + assembly { + a := true + a := false + } + } +} + +contract MultipleAssemblyAssignement { + function foo() public pure { + assembly { + function bar() -> a, b { + a := 1 + b := 2 + } + + let i, j := bar() + } + } +} + +contract AssemblyStackAssignment { + function f() public { + assembly { + 4 =: y + } + } +} + +=====================================output===================================== +contract Assembly { + function ifAssembly() { + assembly { + if returndatasize { + success := 0 + } + } + } + function caseAssembly() { + assembly { + switch value + case 0 { + mstore(0,0x0000000000000000000000000000000000000000000000000000000000000000) + } + case 1 { + mstore(0,0x1111111111111111111111111111111111111111111111111111111111111111) + } + } + } + function forAssembly() { + assembly { + for { + let i := 0 + } lt(i,x) { + i := add(i,1) + } { + y := mul(2,y) + } + } + } + function callWithComments() { + assembly { + f(1,2,3) + } + } + function assemblyFunctionNoParameters() { + assembly { + function getAnswer() -> answer { + answer := 42 + } + } + } + function assemblyFunctionOneParameter() { + assembly { + function inc(x) -> result { + result := add(x,1) + } + } + } + function assemblyFunctionThreeParameters() { + assembly { + function sum(a, b, c) -> result { + result := add(a,add(b,c)) + } + } + } + function assemblyFunctionLongParameters() { + assembly { + function sum( + thisIs, + aFunctionWithVery, + veryLongParameterNames, + andItAlsoHasALotOfParameters, + soItShouldBeSplitInMultipleLines + ) -> result { + result := 0 + } + } + } + function assemblyFunctionLongReturnParameters() { + assembly { + function sum(a, b, c, d, e) + -> + thisIs, + aFunctionWithVery, + veryLongParameterNames, + andItAlsoHasALotOfParameters, + soItShouldBeSplitInMultipleLines + { + thisIs := 0 + aFunctionWithVery := 0 + veryLongParameterNames := 0 + andItAlsoHasALotOfParameters := 0 + soItShouldBeSplitInMultipleLines := 0 + } + } + } + function assemblyFunctionLongParametersAndReturnParameters() { + assembly { + function sum( + a, + veryLong, + listof, + parameters, + thatShould, + splitForSure + ) + -> + thisIs, + aFunctionWithVery, + veryLongParameterNames, + andItAlsoHasALotOfParameters, + soItShouldBeSplitInMultipleLines + { + thisIs := 0 + aFunctionWithVery := 0 + veryLongParameterNames := 0 + andItAlsoHasALotOfParameters := 0 + soItShouldBeSplitInMultipleLines := 0 + } + } + } + function assemblyNoParameterCalls() { + assembly { + call(gas(),to,value,inputData,inputDataSize,0,0) + } + } + function assemblyLabels() { + assembly { + let n := calldataload(4) + let a := 1 + let b := a + loop + } + assembly { + let x := 8 + jump(two) + one + } + } + function assemblyFunctionNoReturn() { + assembly { + function $somefn(somearg) { + + } + } + } + function letWithoutValue() { + assembly { + let result + } + } + function memberAccess() { + assembly { + ds.slot := position + offset := x.offset + } + } + function commentsInAssemblyBlock() { + assembly { + + } + } + function withBreak() { + assembly { + for { + + } 1 { + + } { + break + } + } + } + function memorySafe() { + assembly ("memory-safe") { + + } + assembly "evmasm" ("memory-safe") { + + } + } + function continueAndBreak(uint256 x) public pure returns (uint a, uint b) { + assembly { + for { + let i := 0 + } lt(i,x) { + i := add(i,1) + } { + if lt(i,10) { + a := add(a,i) + continue + } + if eq(i,15) { + break + } + b := i + } + } + } +} +contract BooleanLiteralsInAssembly { + function f() { + uint a; + assembly { + a := true + a := false + } + } +} +contract MultipleAssemblyAssignement { + function foo() public pure { + assembly { + function bar() -> a, b { + a := 1 + b := 2 + } + let i + } + } +} +contract AssemblyStackAssignment { + function f() public { + assembly { + 4 + } + } +} + +================================================================================ +`; diff --git a/tests/format/Assembly/jsfmt.spec.js b/tests/format/Assembly/jsfmt.spec.js index 765dd60a6..fd56c17bc 100644 --- a/tests/format/Assembly/jsfmt.spec.js +++ b/tests/format/Assembly/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse']); diff --git a/tests/format/BinaryOperators/__snapshots__/jsfmt.spec.js.snap b/tests/format/BinaryOperators/__snapshots__/jsfmt.spec.js.snap index fd5d8bb50..4cdbf3902 100644 --- a/tests/format/BinaryOperators/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/BinaryOperators/__snapshots__/jsfmt.spec.js.snap @@ -1,8 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`BinaryOperators.sol format 1`] = ` +exports[`BinaryOperators.sol - {"compiler":"0.5.8"} format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +compiler: "0.5.8" +parsers: ["solidity-slang-parse"] printWidth: 80 | printWidth =====================================input====================================== @@ -195,7 +196,6 @@ contract LogicalOperators { =====================================output===================================== contract ArithmeticOperators { - // ['+', '-', '*', '/', '%'] function someFunction() { a + b; a - b; @@ -203,7 +203,7 @@ contract ArithmeticOperators { a / b; a % b; a ** b; - (a % b) + c - (d * e) / f ** g; + a % b + c - d * e / f ** g; veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB; veryVeryVeryVeryVeryLongVariableCalledA - @@ -218,7 +218,10 @@ contract ArithmeticOperators { veryVeryVeryVeryVeryLongVariableCalledB; veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB - - (((c * d) / e) % f ** g); + c * + d / + e % + f ** g; a = veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB; @@ -230,15 +233,15 @@ contract ArithmeticOperators { if ( a() == veryVeryVeryVeryVeryLongVariableCalledA + - veryVeryVeryVeryVeryLongVariableCalledB + veryVeryVeryVeryVeryLongVariableCalledB ) {} for ( a = veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB; a <= - veryVeryVeryVeryVeryLongVariableCalledA + - veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA + + veryVeryVeryVeryVeryLongVariableCalledB; a += veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB @@ -247,9 +250,8 @@ contract ArithmeticOperators { veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB ); - return - veryVeryVeryVeryVeryLongVariableCalledA + - veryVeryVeryVeryVeryLongVariableCalledB; + return veryVeryVeryVeryVeryLongVariableCalledA + + veryVeryVeryVeryVeryLongVariableCalledB; veryVeryVeryVeryVeryLongFunctionCalledA( veryVeryVeryVeryVeryLongVariableCalledB ) + c; @@ -276,15 +278,12 @@ contract ArithmeticOperators { veryVeryVeryVeryVeryLongVariableCalledB ) + c ); - return - veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - ) + c; + return veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) + c; } } - contract ArithmeticOperators { - // ['**'] function someFunction() { a ** b; a ** c * d ** e; @@ -326,8 +325,8 @@ contract ArithmeticOperators { veryVeryVeryVeryVeryLongVariableCalledA ** veryVeryVeryVeryVeryLongVariableCalledB; a <= - veryVeryVeryVeryVeryLongVariableCalledA ** - veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA ** + veryVeryVeryVeryVeryLongVariableCalledB; a += veryVeryVeryVeryVeryLongVariableCalledA ** veryVeryVeryVeryVeryLongVariableCalledB @@ -336,9 +335,8 @@ contract ArithmeticOperators { veryVeryVeryVeryVeryLongVariableCalledA ** veryVeryVeryVeryVeryLongVariableCalledB ); - return - veryVeryVeryVeryVeryLongVariableCalledA ** - veryVeryVeryVeryVeryLongVariableCalledB; + return veryVeryVeryVeryVeryLongVariableCalledA ** + veryVeryVeryVeryVeryLongVariableCalledB; veryVeryVeryVeryVeryLongFunctionCalledA( veryVeryVeryVeryVeryLongVariableCalledB ) ** c; @@ -365,15 +363,12 @@ contract ArithmeticOperators { veryVeryVeryVeryVeryLongVariableCalledB ) ** c ); - return - veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - ) ** c; + return veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) ** c; } } - contract ShiftOperators { - // ['<<', '>>'] function someFunction() { a << b; a >> b; @@ -392,20 +387,17 @@ contract ShiftOperators { if ( a() == veryVeryVeryVeryVeryLongVariableCalledA << - veryVeryVeryVeryVeryLongVariableCalledB + veryVeryVeryVeryVeryLongVariableCalledB ) {} a( veryVeryVeryVeryVeryLongVariableCalledA << veryVeryVeryVeryVeryLongVariableCalledB ); - return - veryVeryVeryVeryVeryLongVariableCalledA << - veryVeryVeryVeryVeryLongVariableCalledB; + return veryVeryVeryVeryVeryLongVariableCalledA << + veryVeryVeryVeryVeryLongVariableCalledB; } } - contract BitOperators { - // ['&', '|', '^'] function someFunction() { a & b; a | b; @@ -427,20 +419,17 @@ contract BitOperators { if ( a() == veryVeryVeryVeryVeryLongVariableCalledA & - veryVeryVeryVeryVeryLongVariableCalledB + veryVeryVeryVeryVeryLongVariableCalledB ) {} a( veryVeryVeryVeryVeryLongVariableCalledA & veryVeryVeryVeryVeryLongVariableCalledB ); - return - veryVeryVeryVeryVeryLongVariableCalledA & - veryVeryVeryVeryVeryLongVariableCalledB; + return veryVeryVeryVeryVeryLongVariableCalledA & + veryVeryVeryVeryVeryLongVariableCalledB; } } - contract ComparisonOperators { - // ['<', '>', '<=', '>=', '==', '!='] function someFunction() { a < b; a > b; @@ -471,18 +460,14 @@ contract ComparisonOperators { veryVeryVeryVeryVeryLongFunctionB() <= veryVeryVeryVeryVeryLongVariableCalledA ) {} - while ( - veryVeryVeryVeryVeryLongVariableCalledA != - veryVeryVeryVeryVeryLongFunctionB() - ) {} - while ( - veryVeryVeryVeryVeryLongFunctionB() == - veryVeryVeryVeryVeryLongVariableCalledA - ) {} + while(veryVeryVeryVeryVeryLongVariableCalledA != + veryVeryVeryVeryVeryLongFunctionB()){} + while(veryVeryVeryVeryVeryLongFunctionB() == + veryVeryVeryVeryVeryLongVariableCalledA){} for ( a = veryVeryVeryVeryVeryLongVariableCalledA; veryVeryVeryVeryVeryLongVariableCalledB >= - veryVeryVeryVeryVeryLongVariableCalledA; + veryVeryVeryVeryVeryLongVariableCalledA; a += veryVeryVeryVeryVeryLongVariableCalledA || veryVeryVeryVeryVeryLongVariableCalledB ? 1 @@ -492,9 +477,8 @@ contract ComparisonOperators { veryVeryVeryVeryVeryLongVariableCalledA == veryVeryVeryVeryVeryLongVariableCalledB ); - return - veryVeryVeryVeryVeryLongVariableCalledA == - veryVeryVeryVeryVeryLongVariableCalledB; + return veryVeryVeryVeryVeryLongVariableCalledA == + veryVeryVeryVeryVeryLongVariableCalledB; veryVeryVeryVeryVeryLongFunctionCalledA( veryVeryVeryVeryVeryLongVariableCalledB ) == c; @@ -521,15 +505,12 @@ contract ComparisonOperators { veryVeryVeryVeryVeryLongVariableCalledB ) == c ); - return - veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - ) == c; + return veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) == c; } } - contract AssignmentOperators { - // ['=', '|=', '^=', '&=', '<<=', '>>=', '+=', '-=', '*=', '/=', '%='] function someFunction() { a = veryVeryVeryVeryVeryLongVariableCalledA; a |= veryVeryVeryVeryVeryLongVariableCalledA; @@ -577,20 +558,20 @@ contract AssignmentOperators { veryVeryVeryVeryVeryLongFunctionCalledB(c); } } - contract LogicalOperators { - // ['&&', '||'] function someFunction() { a && b; a || b; - a || (b && c) || (d && e); + a || b && c || d && e; veryVeryVeryVeryVeryLongVariableCalledA && veryVeryVeryVeryVeryLongVariableCalledB; veryVeryVeryVeryVeryLongVariableCalledA || veryVeryVeryVeryVeryLongVariableCalledB; veryVeryVeryVeryVeryLongVariableCalledA || - (veryVeryVeryVeryVeryLongVariableCalledB && c) || - (d && e); + veryVeryVeryVeryVeryLongVariableCalledB && + c || + d && + e; a = veryVeryVeryVeryVeryLongVariableCalledA && veryVeryVeryVeryVeryLongVariableCalledB; @@ -607,33 +588,27 @@ contract LogicalOperators { veryVeryVeryVeryVeryLongVariableCalledB ) {} if ( - (veryVeryVeryVeryVeryLongVariableCalledA && - veryVeryVeryVeryVeryLongVariableCalledB) || c - ) {} - if ( - veryVeryVeryVeryVeryLongVariableCalledA || - (veryVeryVeryVeryVeryLongVariableCalledB && c) - ) {} - while ( - veryVeryVeryVeryVeryLongVariableCalledA && - veryVeryVeryVeryVeryLongVariableCalledB == a() - ) {} - while ( - a() == veryVeryVeryVeryVeryLongVariableCalledA && - veryVeryVeryVeryVeryLongVariableCalledB - ) {} - while ( veryVeryVeryVeryVeryLongVariableCalledA && - veryVeryVeryVeryVeryLongVariableCalledB + veryVeryVeryVeryVeryLongVariableCalledB || + c ) {} - while ( - (veryVeryVeryVeryVeryLongVariableCalledA && - veryVeryVeryVeryVeryLongVariableCalledB) || c - ) {} - while ( + if ( veryVeryVeryVeryVeryLongVariableCalledA || - (veryVeryVeryVeryVeryLongVariableCalledB && c) + veryVeryVeryVeryVeryLongVariableCalledB && + c ) {} + while(veryVeryVeryVeryVeryLongVariableCalledA && + veryVeryVeryVeryVeryLongVariableCalledB == a()){} + while(a() == veryVeryVeryVeryVeryLongVariableCalledA && + veryVeryVeryVeryVeryLongVariableCalledB){} + while(veryVeryVeryVeryVeryLongVariableCalledA && + veryVeryVeryVeryVeryLongVariableCalledB){} + while(veryVeryVeryVeryVeryLongVariableCalledA && + veryVeryVeryVeryVeryLongVariableCalledB || + c){} + while(veryVeryVeryVeryVeryLongVariableCalledA || + veryVeryVeryVeryVeryLongVariableCalledB && + c){} for ( a = veryVeryVeryVeryVeryLongVariableCalledA; a <= veryVeryVeryVeryVeryLongVariableCalledA; @@ -646,19 +621,18 @@ contract LogicalOperators { veryVeryVeryVeryVeryLongVariableCalledA || veryVeryVeryVeryVeryLongVariableCalledB ); - return - veryVeryVeryVeryVeryLongVariableCalledA || - veryVeryVeryVeryVeryLongVariableCalledB; + return veryVeryVeryVeryVeryLongVariableCalledA || + veryVeryVeryVeryVeryLongVariableCalledB; veryVeryVeryVeryVeryLongFunctionCalledA( veryVeryVeryVeryVeryLongVariableCalledB ) || c; veryVeryVeryVeryVeryLongFunctionCalledA( veryVeryVeryVeryVeryLongVariableCalledB ) || - (c && - veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - )) || + c && + veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) || d; a = veryVeryVeryVeryVeryLongFunctionCalledA( @@ -675,10 +649,969 @@ contract LogicalOperators { veryVeryVeryVeryVeryLongVariableCalledB ) || c ); - return - veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - ) || c; + return veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) || c; + } +} + +================================================================================ +`; + +exports[`BinaryOperators.sol format 1`] = ` +====================================options===================================== +parsers: ["solidity-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +contract ArithmeticOperators { + // ['+', '-', '*', '/', '%'] + function someFunction() { + a + b; + a - b; + a * b; + a / b; + a % b; + a ** b; + a % b + c - d * e / f ** g; + veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA - veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA * veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA / veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA % veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA ** veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB - c * d / e % f ** g; + a = veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB; + if (veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB == a()) {} + if (a() == veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB) {} + for (a = veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB; a <= veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB; a += veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB) {} + a(veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB); + return veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) + c; + veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) + c * veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) - d; + a = veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) + c; + if (veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) + c) {} + a(veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) + c); + return veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) + c; + } +} + + +contract ArithmeticOperators { + // ['**'] + function someFunction() { + a ** b; + a ** c * d ** e; + a ** c * d ** e * a ** c * d ** e * a ** c * d ** e * a ** c * d ** e * a ** c * d ** e; + veryVeryVeryVeryVeryLongVariableCalledA ** veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA * veryVeryVeryVeryVeryLongVariableCalledB ** c; + c ** veryVeryVeryVeryVeryLongVariableCalledA * veryVeryVeryVeryVeryLongVariableCalledB; + a = veryVeryVeryVeryVeryLongVariableCalledA ** veryVeryVeryVeryVeryLongVariableCalledB; + a = veryVeryVeryVeryVeryLongVariableCalledA ** veryVeryVeryVeryVeryLongVariableCalledB * c; + if (veryVeryVeryVeryVeryLongVariableCalledA ** veryVeryVeryVeryVeryLongVariableCalledB == a()) {} + if (a() == veryVeryVeryVeryVeryLongVariableCalledA ** veryVeryVeryVeryVeryLongVariableCalledB) {} + for (a = veryVeryVeryVeryVeryLongVariableCalledA ** veryVeryVeryVeryVeryLongVariableCalledB; a <= veryVeryVeryVeryVeryLongVariableCalledA ** veryVeryVeryVeryVeryLongVariableCalledB; a += veryVeryVeryVeryVeryLongVariableCalledA ** veryVeryVeryVeryVeryLongVariableCalledB) {} + a(veryVeryVeryVeryVeryLongVariableCalledA ** veryVeryVeryVeryVeryLongVariableCalledB); + return veryVeryVeryVeryVeryLongVariableCalledA ** veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) ** c; + veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) ** c * veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) ** d; + a = veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) ** c; + if (veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) ** c) {} + a(veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) ** c); + return veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) ** c; + } +} + + +contract ShiftOperators { + // ['<<', '>>'] + function someFunction() { + a << b; + a >> b; + veryVeryVeryVeryVeryLongVariableCalledA << veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA >> veryVeryVeryVeryVeryLongVariableCalledB; + a = veryVeryVeryVeryVeryLongVariableCalledA << veryVeryVeryVeryVeryLongVariableCalledB; + if (veryVeryVeryVeryVeryLongVariableCalledA << veryVeryVeryVeryVeryLongVariableCalledB == a()) {} + if (a() == veryVeryVeryVeryVeryLongVariableCalledA << veryVeryVeryVeryVeryLongVariableCalledB) {} + a(veryVeryVeryVeryVeryLongVariableCalledA << veryVeryVeryVeryVeryLongVariableCalledB); + return veryVeryVeryVeryVeryLongVariableCalledA << veryVeryVeryVeryVeryLongVariableCalledB; + } +} + + +contract BitOperators { + // ['&', '|', '^'] + function someFunction() { + a & b; + a | b; + a ^ b; + veryVeryVeryVeryVeryLongVariableCalledA & veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA | veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA ^ veryVeryVeryVeryVeryLongVariableCalledB; + a = veryVeryVeryVeryVeryLongVariableCalledA & veryVeryVeryVeryVeryLongVariableCalledB; + if (veryVeryVeryVeryVeryLongVariableCalledA & veryVeryVeryVeryVeryLongVariableCalledB == a()) {} + if (a() == veryVeryVeryVeryVeryLongVariableCalledA & veryVeryVeryVeryVeryLongVariableCalledB) {} + a(veryVeryVeryVeryVeryLongVariableCalledA & veryVeryVeryVeryVeryLongVariableCalledB); + return veryVeryVeryVeryVeryLongVariableCalledA & veryVeryVeryVeryVeryLongVariableCalledB; + } +} + + +contract ComparisonOperators { + // ['<', '>', '<=', '>=', '==', '!='] + function someFunction() { + a < b; + a > b; + a <= b; + a >= b; + a == b; + a != b; + veryVeryVeryVeryVeryLongVariableCalledA < veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA > veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA <= veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA >= veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA == veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA != veryVeryVeryVeryVeryLongVariableCalledB; + a = veryVeryVeryVeryVeryLongVariableCalledA < veryVeryVeryVeryVeryLongVariableCalledB; + if (veryVeryVeryVeryVeryLongVariableCalledA > veryVeryVeryVeryVeryLongFunctionB()) {} + if (veryVeryVeryVeryVeryLongFunctionB() <= veryVeryVeryVeryVeryLongVariableCalledA) {} + while (veryVeryVeryVeryVeryLongVariableCalledA != veryVeryVeryVeryVeryLongFunctionB()) {} + while (veryVeryVeryVeryVeryLongFunctionB() == veryVeryVeryVeryVeryLongVariableCalledA) {} + for (a = veryVeryVeryVeryVeryLongVariableCalledA; veryVeryVeryVeryVeryLongVariableCalledB >= veryVeryVeryVeryVeryLongVariableCalledA; a += veryVeryVeryVeryVeryLongVariableCalledA || veryVeryVeryVeryVeryLongVariableCalledB ? 1:2) {} + a(veryVeryVeryVeryVeryLongVariableCalledA == veryVeryVeryVeryVeryLongVariableCalledB); + return veryVeryVeryVeryVeryLongVariableCalledA == veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) == c; + veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) < c || veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) > d; + a = veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) == c; + if (veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) == c) {} + a(veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) == c); + return veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) == c; + } +} + + +contract AssignmentOperators { + // ['=', '|=', '^=', '&=', '<<=', '>>=', '+=', '-=', '*=', '/=', '%='] + function someFunction() { + a = veryVeryVeryVeryVeryLongVariableCalledA; + a |= veryVeryVeryVeryVeryLongVariableCalledA; + a ^= veryVeryVeryVeryVeryLongVariableCalledA; + a &= veryVeryVeryVeryVeryLongVariableCalledA; + a <<= veryVeryVeryVeryVeryLongVariableCalledA; + a >>= veryVeryVeryVeryVeryLongVariableCalledA; + a += veryVeryVeryVeryVeryLongVariableCalledA; + a -= veryVeryVeryVeryVeryLongVariableCalledA; + a *= veryVeryVeryVeryVeryLongVariableCalledA; + a /= veryVeryVeryVeryVeryLongVariableCalledA; + a %= veryVeryVeryVeryVeryLongVariableCalledA; + a = veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongFunctionCalledB(c); + a |= veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongFunctionCalledB(c); + a ^= veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongFunctionCalledB(c); + a &= veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongFunctionCalledB(c); + a <<= veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongFunctionCalledB(c); + a >>= veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongFunctionCalledB(c); + a += veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongFunctionCalledB(c); + a -= veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongFunctionCalledB(c); + a *= veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongFunctionCalledB(c); + a /= veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongFunctionCalledB(c); + a %= veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongFunctionCalledB(c); + } +} + + +contract LogicalOperators { + // ['&&', '||'] + function someFunction() { + a && b; + a || b; + a || b && c || d && e; + veryVeryVeryVeryVeryLongVariableCalledA && veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA || veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA || veryVeryVeryVeryVeryLongVariableCalledB && c || d && e; + a = veryVeryVeryVeryVeryLongVariableCalledA && veryVeryVeryVeryVeryLongVariableCalledB; + if (veryVeryVeryVeryVeryLongVariableCalledA && veryVeryVeryVeryVeryLongVariableCalledB == a()) {} + if (a() == veryVeryVeryVeryVeryLongVariableCalledA && veryVeryVeryVeryVeryLongVariableCalledB) {} + if (veryVeryVeryVeryVeryLongVariableCalledA && veryVeryVeryVeryVeryLongVariableCalledB) {} + if (veryVeryVeryVeryVeryLongVariableCalledA && veryVeryVeryVeryVeryLongVariableCalledB || c) {} + if (veryVeryVeryVeryVeryLongVariableCalledA || veryVeryVeryVeryVeryLongVariableCalledB && c) {} + while (veryVeryVeryVeryVeryLongVariableCalledA && veryVeryVeryVeryVeryLongVariableCalledB == a()) {} + while (a() == veryVeryVeryVeryVeryLongVariableCalledA && veryVeryVeryVeryVeryLongVariableCalledB) {} + while (veryVeryVeryVeryVeryLongVariableCalledA && veryVeryVeryVeryVeryLongVariableCalledB) {} + while (veryVeryVeryVeryVeryLongVariableCalledA && veryVeryVeryVeryVeryLongVariableCalledB || c) {} + while (veryVeryVeryVeryVeryLongVariableCalledA || veryVeryVeryVeryVeryLongVariableCalledB && c) {} + for (a = veryVeryVeryVeryVeryLongVariableCalledA; a <= veryVeryVeryVeryVeryLongVariableCalledA; a += veryVeryVeryVeryVeryLongVariableCalledA || veryVeryVeryVeryVeryLongVariableCalledB ? 1:2) {} + a(veryVeryVeryVeryVeryLongVariableCalledA || veryVeryVeryVeryVeryLongVariableCalledB); + return veryVeryVeryVeryVeryLongVariableCalledA || veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) || c; + veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) || c && veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) || d; + a = veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) || c; + if (veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) || c) {} + a(veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) || c); + return veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) || c; + } +} + +=====================================output===================================== +contract ArithmeticOperators { + // ['+', '-', '*', '/', '%'] + function someFunction() { + a + b; + a - b; + a * b; + a / b; + a % b; + a ** b; + (a % b) + c - (d * e) / f ** g; + veryVeryVeryVeryVeryLongVariableCalledA + + veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA - + veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA * + veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA / + veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA % + veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA ** + veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA + + veryVeryVeryVeryVeryLongVariableCalledB - + (((c * d) / e) % f ** g); + a = + veryVeryVeryVeryVeryLongVariableCalledA + + veryVeryVeryVeryVeryLongVariableCalledB; + if ( + veryVeryVeryVeryVeryLongVariableCalledA + + veryVeryVeryVeryVeryLongVariableCalledB == + a() + ) {} + if ( + a() == + veryVeryVeryVeryVeryLongVariableCalledA + + veryVeryVeryVeryVeryLongVariableCalledB + ) {} + for ( + a = + veryVeryVeryVeryVeryLongVariableCalledA + + veryVeryVeryVeryVeryLongVariableCalledB; + a <= + veryVeryVeryVeryVeryLongVariableCalledA + + veryVeryVeryVeryVeryLongVariableCalledB; + a += + veryVeryVeryVeryVeryLongVariableCalledA + + veryVeryVeryVeryVeryLongVariableCalledB + ) {} + a( + veryVeryVeryVeryVeryLongVariableCalledA + + veryVeryVeryVeryVeryLongVariableCalledB + ); + return + veryVeryVeryVeryVeryLongVariableCalledA + + veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) + c; + veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) + + c * + veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) - + d; + a = + veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) + + c; + if ( + veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) + c + ) {} + a( + veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) + c + ); + return + veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) + c; + } +} + +contract ArithmeticOperators { + // ['**'] + function someFunction() { + a ** b; + a ** c * d ** e; + a ** c * + d ** e * + a ** c * + d ** e * + a ** c * + d ** e * + a ** c * + d ** e * + a ** c * + d ** e; + veryVeryVeryVeryVeryLongVariableCalledA ** + veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA * + veryVeryVeryVeryVeryLongVariableCalledB ** c; + c ** veryVeryVeryVeryVeryLongVariableCalledA * + veryVeryVeryVeryVeryLongVariableCalledB; + a = + veryVeryVeryVeryVeryLongVariableCalledA ** + veryVeryVeryVeryVeryLongVariableCalledB; + a = + veryVeryVeryVeryVeryLongVariableCalledA ** + veryVeryVeryVeryVeryLongVariableCalledB * + c; + if ( + veryVeryVeryVeryVeryLongVariableCalledA ** + veryVeryVeryVeryVeryLongVariableCalledB == + a() + ) {} + if ( + a() == + veryVeryVeryVeryVeryLongVariableCalledA ** + veryVeryVeryVeryVeryLongVariableCalledB + ) {} + for ( + a = + veryVeryVeryVeryVeryLongVariableCalledA ** + veryVeryVeryVeryVeryLongVariableCalledB; + a <= + veryVeryVeryVeryVeryLongVariableCalledA ** + veryVeryVeryVeryVeryLongVariableCalledB; + a += + veryVeryVeryVeryVeryLongVariableCalledA ** + veryVeryVeryVeryVeryLongVariableCalledB + ) {} + a( + veryVeryVeryVeryVeryLongVariableCalledA ** + veryVeryVeryVeryVeryLongVariableCalledB + ); + return + veryVeryVeryVeryVeryLongVariableCalledA ** + veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) ** c; + veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) ** + c * + veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) ** + d; + a = + veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) ** + c; + if ( + veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) ** c + ) {} + a( + veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) ** c + ); + return + veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) ** c; + } +} + +contract ShiftOperators { + // ['<<', '>>'] + function someFunction() { + a << b; + a >> b; + veryVeryVeryVeryVeryLongVariableCalledA << + veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA >> + veryVeryVeryVeryVeryLongVariableCalledB; + a = + veryVeryVeryVeryVeryLongVariableCalledA << + veryVeryVeryVeryVeryLongVariableCalledB; + if ( + veryVeryVeryVeryVeryLongVariableCalledA << + veryVeryVeryVeryVeryLongVariableCalledB == + a() + ) {} + if ( + a() == + veryVeryVeryVeryVeryLongVariableCalledA << + veryVeryVeryVeryVeryLongVariableCalledB + ) {} + a( + veryVeryVeryVeryVeryLongVariableCalledA << + veryVeryVeryVeryVeryLongVariableCalledB + ); + return + veryVeryVeryVeryVeryLongVariableCalledA << + veryVeryVeryVeryVeryLongVariableCalledB; + } +} + +contract BitOperators { + // ['&', '|', '^'] + function someFunction() { + a & b; + a | b; + a ^ b; + veryVeryVeryVeryVeryLongVariableCalledA & + veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA | + veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA ^ + veryVeryVeryVeryVeryLongVariableCalledB; + a = + veryVeryVeryVeryVeryLongVariableCalledA & + veryVeryVeryVeryVeryLongVariableCalledB; + if ( + veryVeryVeryVeryVeryLongVariableCalledA & + veryVeryVeryVeryVeryLongVariableCalledB == + a() + ) {} + if ( + a() == + veryVeryVeryVeryVeryLongVariableCalledA & + veryVeryVeryVeryVeryLongVariableCalledB + ) {} + a( + veryVeryVeryVeryVeryLongVariableCalledA & + veryVeryVeryVeryVeryLongVariableCalledB + ); + return + veryVeryVeryVeryVeryLongVariableCalledA & + veryVeryVeryVeryVeryLongVariableCalledB; + } +} + +contract ComparisonOperators { + // ['<', '>', '<=', '>=', '==', '!='] + function someFunction() { + a < b; + a > b; + a <= b; + a >= b; + a == b; + a != b; + veryVeryVeryVeryVeryLongVariableCalledA < + veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA > + veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA <= + veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA >= + veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA == + veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA != + veryVeryVeryVeryVeryLongVariableCalledB; + a = + veryVeryVeryVeryVeryLongVariableCalledA < + veryVeryVeryVeryVeryLongVariableCalledB; + if ( + veryVeryVeryVeryVeryLongVariableCalledA > + veryVeryVeryVeryVeryLongFunctionB() + ) {} + if ( + veryVeryVeryVeryVeryLongFunctionB() <= + veryVeryVeryVeryVeryLongVariableCalledA + ) {} + while ( + veryVeryVeryVeryVeryLongVariableCalledA != + veryVeryVeryVeryVeryLongFunctionB() + ) {} + while ( + veryVeryVeryVeryVeryLongFunctionB() == + veryVeryVeryVeryVeryLongVariableCalledA + ) {} + for ( + a = veryVeryVeryVeryVeryLongVariableCalledA; + veryVeryVeryVeryVeryLongVariableCalledB >= + veryVeryVeryVeryVeryLongVariableCalledA; + a += veryVeryVeryVeryVeryLongVariableCalledA || + veryVeryVeryVeryVeryLongVariableCalledB + ? 1 + : 2 + ) {} + a( + veryVeryVeryVeryVeryLongVariableCalledA == + veryVeryVeryVeryVeryLongVariableCalledB + ); + return + veryVeryVeryVeryVeryLongVariableCalledA == + veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) == c; + veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) < + c || + veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) > + d; + a = + veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) == + c; + if ( + veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) == c + ) {} + a( + veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) == c + ); + return + veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) == c; + } +} + +contract AssignmentOperators { + // ['=', '|=', '^=', '&=', '<<=', '>>=', '+=', '-=', '*=', '/=', '%='] + function someFunction() { + a = veryVeryVeryVeryVeryLongVariableCalledA; + a |= veryVeryVeryVeryVeryLongVariableCalledA; + a ^= veryVeryVeryVeryVeryLongVariableCalledA; + a &= veryVeryVeryVeryVeryLongVariableCalledA; + a <<= veryVeryVeryVeryVeryLongVariableCalledA; + a >>= veryVeryVeryVeryVeryLongVariableCalledA; + a += veryVeryVeryVeryVeryLongVariableCalledA; + a -= veryVeryVeryVeryVeryLongVariableCalledA; + a *= veryVeryVeryVeryVeryLongVariableCalledA; + a /= veryVeryVeryVeryVeryLongVariableCalledA; + a %= veryVeryVeryVeryVeryLongVariableCalledA; + a = + veryVeryVeryVeryVeryLongVariableCalledA + + veryVeryVeryVeryVeryLongFunctionCalledB(c); + a |= + veryVeryVeryVeryVeryLongVariableCalledA + + veryVeryVeryVeryVeryLongFunctionCalledB(c); + a ^= + veryVeryVeryVeryVeryLongVariableCalledA + + veryVeryVeryVeryVeryLongFunctionCalledB(c); + a &= + veryVeryVeryVeryVeryLongVariableCalledA + + veryVeryVeryVeryVeryLongFunctionCalledB(c); + a <<= + veryVeryVeryVeryVeryLongVariableCalledA + + veryVeryVeryVeryVeryLongFunctionCalledB(c); + a >>= + veryVeryVeryVeryVeryLongVariableCalledA + + veryVeryVeryVeryVeryLongFunctionCalledB(c); + a += + veryVeryVeryVeryVeryLongVariableCalledA + + veryVeryVeryVeryVeryLongFunctionCalledB(c); + a -= + veryVeryVeryVeryVeryLongVariableCalledA + + veryVeryVeryVeryVeryLongFunctionCalledB(c); + a *= + veryVeryVeryVeryVeryLongVariableCalledA + + veryVeryVeryVeryVeryLongFunctionCalledB(c); + a /= + veryVeryVeryVeryVeryLongVariableCalledA + + veryVeryVeryVeryVeryLongFunctionCalledB(c); + a %= + veryVeryVeryVeryVeryLongVariableCalledA + + veryVeryVeryVeryVeryLongFunctionCalledB(c); + } +} + +contract LogicalOperators { + // ['&&', '||'] + function someFunction() { + a && b; + a || b; + a || (b && c) || (d && e); + veryVeryVeryVeryVeryLongVariableCalledA && + veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA || + veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA || + (veryVeryVeryVeryVeryLongVariableCalledB && c) || + (d && e); + a = + veryVeryVeryVeryVeryLongVariableCalledA && + veryVeryVeryVeryVeryLongVariableCalledB; + if ( + veryVeryVeryVeryVeryLongVariableCalledA && + veryVeryVeryVeryVeryLongVariableCalledB == a() + ) {} + if ( + a() == veryVeryVeryVeryVeryLongVariableCalledA && + veryVeryVeryVeryVeryLongVariableCalledB + ) {} + if ( + veryVeryVeryVeryVeryLongVariableCalledA && + veryVeryVeryVeryVeryLongVariableCalledB + ) {} + if ( + (veryVeryVeryVeryVeryLongVariableCalledA && + veryVeryVeryVeryVeryLongVariableCalledB) || c + ) {} + if ( + veryVeryVeryVeryVeryLongVariableCalledA || + (veryVeryVeryVeryVeryLongVariableCalledB && c) + ) {} + while ( + veryVeryVeryVeryVeryLongVariableCalledA && + veryVeryVeryVeryVeryLongVariableCalledB == a() + ) {} + while ( + a() == veryVeryVeryVeryVeryLongVariableCalledA && + veryVeryVeryVeryVeryLongVariableCalledB + ) {} + while ( + veryVeryVeryVeryVeryLongVariableCalledA && + veryVeryVeryVeryVeryLongVariableCalledB + ) {} + while ( + (veryVeryVeryVeryVeryLongVariableCalledA && + veryVeryVeryVeryVeryLongVariableCalledB) || c + ) {} + while ( + veryVeryVeryVeryVeryLongVariableCalledA || + (veryVeryVeryVeryVeryLongVariableCalledB && c) + ) {} + for ( + a = veryVeryVeryVeryVeryLongVariableCalledA; + a <= veryVeryVeryVeryVeryLongVariableCalledA; + a += veryVeryVeryVeryVeryLongVariableCalledA || + veryVeryVeryVeryVeryLongVariableCalledB + ? 1 + : 2 + ) {} + a( + veryVeryVeryVeryVeryLongVariableCalledA || + veryVeryVeryVeryVeryLongVariableCalledB + ); + return + veryVeryVeryVeryVeryLongVariableCalledA || + veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) || c; + veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) || + (c && + veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + )) || + d; + a = + veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) || + c; + if ( + veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) || c + ) {} + a( + veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) || c + ); + return + veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) || c; + } +} + +================================================================================ +`; + +exports[`Parentheses.sol - {"compiler":"0.5.8"} format 1`] = ` +====================================options===================================== +compiler: "0.5.8" +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity 0.5.8; + + +contract Parentheses { + function() { + a + b + c; + a + b - c; + a + b * c; + a + b / c; + a + b % c; + a + b ** c; + a + b << c; + a + b >> c; + a + b & c; + a + b | c; + a + b ^ c; + a - b + c; + a - b - c; + a - b * c; + a - b / c; + a - b % c; + a - b ** c; + a - b << c; + a - b >> c; + a - b & c; + a - b | c; + a - b ^ c; + a * b + c; + a * b - c; + a * b * c; + a * b / c; + a * b % c; + a * b ** c; + a * b << c; + a * b >> c; + a * b & c; + a * b | c; + a * b ^ c; + a / b + c; + a / b - c; + a / b * c; + a / b / c; + a / b % c; + a / b ** c; + a / b << c; + a / b >> c; + a / b & c; + a / b | c; + a / b ^ c; + a % b + c; + a % b - c; + a % b * c; + a % b / c; + a % b % c; + a % b ** c; + a % b << c; + a % b >> c; + a % b & c; + a % b | c; + a % b ^ c; + a ** b + c; + a ** b - c; + a ** b * c; + a ** b / c; + a ** b % c; + a ** b ** c; + a ** b << c; + a ** b >> c; + a ** b & c; + a ** b | c; + a ** b ^ c; + a << b + c; + a << b - c; + a << b * c; + a << b / c; + a << b % c; + a << b ** c; + a << b << c; + a << b >> c; + a << b & c; + a << b | c; + a << b ^ c; + a >> b + c; + a >> b - c; + a >> b * c; + a >> b / c; + a >> b % c; + a >> b ** c; + a >> b << c; + a >> b >> c; + a >> b & c; + a >> b | c; + a >> b ^ c; + a & b + c; + a & b - c; + a & b * c; + a & b / c; + a & b % c; + a & b ** c; + a & b << c; + a & b >> c; + a & b & c; + a & b | c; + a & b ^ c; + a | b + c; + a | b - c; + a | b * c; + a | b / c; + a | b % c; + a | b ** c; + a | b << c; + a | b >> c; + a | b & c; + a | b | c; + a | b ^ c; + a ^ b + c; + a ^ b - c; + a ^ b * c; + a ^ b / c; + a ^ b % c; + a ^ b ** c; + a ^ b << c; + a ^ b >> c; + a ^ b & c; + a ^ b | c; + a ^ b ^ c; + a || b || c; + a || b && c; + a && b || c; + a && b && c; + } +} + +=====================================output===================================== +pragma solidity 0.5.8; +contract Parentheses { + function() { + a + b + c; + a + b - c; + a + b * c; + a + b / c; + a + b % c; + a + b ** c; + a + b << c; + a + b >> c; + a + b & c; + a + b | c; + a + b ^ c; + a - b + c; + a - b - c; + a - b * c; + a - b / c; + a - b % c; + a - b ** c; + a - b << c; + a - b >> c; + a - b & c; + a - b | c; + a - b ^ c; + a * b + c; + a * b - c; + a * b * c; + a * b / c; + a * b % c; + a * b ** c; + a * b << c; + a * b >> c; + a * b & c; + a * b | c; + a * b ^ c; + a / b + c; + a / b - c; + a / b * c; + a / b / c; + a / b % c; + a / b ** c; + a / b << c; + a / b >> c; + a / b & c; + a / b | c; + a / b ^ c; + a % b + c; + a % b - c; + a % b * c; + a % b / c; + a % b % c; + a % b ** c; + a % b << c; + a % b >> c; + a % b & c; + a % b | c; + a % b ^ c; + a ** b + c; + a ** b - c; + a ** b * c; + a ** b / c; + a ** b % c; + a ** b ** c; + a ** b << c; + a ** b >> c; + a ** b & c; + a ** b | c; + a ** b ^ c; + a << b + c; + a << b - c; + a << b * c; + a << b / c; + a << b % c; + a << b ** c; + a << b << c; + a << b >> c; + a << b & c; + a << b | c; + a << b ^ c; + a >> b + c; + a >> b - c; + a >> b * c; + a >> b / c; + a >> b % c; + a >> b ** c; + a >> b << c; + a >> b >> c; + a >> b & c; + a >> b | c; + a >> b ^ c; + a & b + c; + a & b - c; + a & b * c; + a & b / c; + a & b % c; + a & b ** c; + a & b << c; + a & b >> c; + a & b & c; + a & b | c; + a & b ^ c; + a | b + c; + a | b - c; + a | b * c; + a | b / c; + a | b % c; + a | b ** c; + a | b << c; + a | b >> c; + a | b & c; + a | b | c; + a | b ^ c; + a ^ b + c; + a ^ b - c; + a ^ b * c; + a ^ b / c; + a ^ b % c; + a ^ b ** c; + a ^ b << c; + a ^ b >> c; + a ^ b & c; + a ^ b | c; + a ^ b ^ c; + a || b || c; + a || b && c; + a && b || c; + a && b && c; } } diff --git a/tests/format/BinaryOperators/jsfmt.spec.js b/tests/format/BinaryOperators/jsfmt.spec.js index 765dd60a6..427a1e619 100644 --- a/tests/format/BinaryOperators/jsfmt.spec.js +++ b/tests/format/BinaryOperators/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse'], { compiler: '0.5.8' }); diff --git a/tests/format/Etc/__snapshots__/jsfmt.spec.js.snap b/tests/format/Etc/__snapshots__/jsfmt.spec.js.snap index 6662b381e..483a36f3b 100644 --- a/tests/format/Etc/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Etc/__snapshots__/jsfmt.spec.js.snap @@ -132,3 +132,130 @@ contract Contract { ================================================================================ `; + +exports[`Etc.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity ^0.4.24; + +// line comment + +/* + Block comment +*/ + +contract Contract { + struct StructWithFunctionTypes { + function (uint, uint) returns(bool)a; + function (uint, uint) returns(bool,bytes32, bytes32, bytes32, bytes32, bytes32, bytes32, bytes32)a; + function(bytes32, bytes32) internal view[] b; + function (bytes32, bytes32)internal[] c; + function(bytes32, bytes32, bytes32, bytes32, bytes32, bytes32) internal view[] d; + function(bytes32, bytes32, bytes32, bytes32, bytes32, bytes32, bytes32, bytes32, bytes32) internal view[] e; + } + + event SomeEvent(); + + modifier modifierWithoutParams() { + require(msg.sender != address(0)); + _; + } + + modifier modifierWithParams(address x) { + require(msg.sender != x); + _; + } + + function ifBlockInOneLine(uint a) returns (uint b) { + if (a < 0) b = 0x67; else if (a == 0) b = 0x12; else b = 0x78; + } + + function forWithoutBlock() { + uint i; + uint sum; + for ( i = 0; i < 10; i++ ) sum += i; + } + + function fun(uint256 a) returns (uint) { + if (something) foo(); + // comment + else if (somethingElse) bar(); + else whatever(); + return; + } +} + +=====================================output===================================== +pragma solidity ^0.4.24; +contract Contract { + struct StructWithFunctionTypes { + function (uint, uint) returns (bool) a; + function ( + uint, + uint + ) + returns ( + bool, + bytes32, + bytes32, + bytes32, + bytes32, + bytes32, + bytes32, + bytes32 + ) + a; + function (bytes32, bytes32) internal view [] b; + function (bytes32, bytes32) internal [] c; + function ( + bytes32, + bytes32, + bytes32, + bytes32, + bytes32, + bytes32 + ) internal view [] d; + function ( + bytes32, + bytes32, + bytes32, + bytes32, + bytes32, + bytes32, + bytes32, + bytes32, + bytes32 + ) internal view [] e; + } + event SomeEvent(); + modifier modifierWithoutParams() { + require(msg.sender != address(0)); + _; + } + modifier modifierWithParams(address x) { + require(msg.sender != x); + _; + } + function ifBlockInOneLine(uint a) returns (uint b) { + if (a < 0) b = 0x67; + else if (a == 0) b = 0x12; + else b = 0x78; + } + function forWithoutBlock() { + uint i; + uint sum; + for (i = 0; i < 10; i++) sum += i; + } + function fun(uint256 a) returns (uint) { + if (something) foo(); + else if (somethingElse) bar(); + else whatever(); + return; + } +} + +================================================================================ +`; diff --git a/tests/format/Etc/jsfmt.spec.js b/tests/format/Etc/jsfmt.spec.js index 765dd60a6..fd56c17bc 100644 --- a/tests/format/Etc/jsfmt.spec.js +++ b/tests/format/Etc/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse']); diff --git a/tests/format/ExperimentalTernaries/__snapshots__/jsfmt.spec.js.snap b/tests/format/ExperimentalTernaries/__snapshots__/jsfmt.spec.js.snap index a290e72ad..ea38f9fe5 100644 --- a/tests/format/ExperimentalTernaries/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/ExperimentalTernaries/__snapshots__/jsfmt.spec.js.snap @@ -510,12 +510,12 @@ contract Conditional { ================================================================================ `; -exports[`ExperimentalTernaries.sol - {"experimentalTernaries":true,"useTabs":true} format 1`] = ` +exports[`ExperimentalTernaries.sol - {"experimentalTernaries":true,"tabWidth":1} format 2`] = ` ====================================options===================================== experimentalTernaries: true -parsers: ["solidity-parse"] +parsers: ["solidity-slang-parse"] printWidth: 80 -useTabs: true +tabWidth: 1 | printWidth =====================================input====================================== pragma solidity ^0.4.24; @@ -770,263 +770,2136 @@ string storage typeofExampleFlipped = =====================================output===================================== pragma solidity ^0.4.24; - contract Conditional { - function blogPostExample() { - // "curious" ternaries - string storage animalName = - pet.canBark() ? - pet.isScary() ? - "wolf" - : "dog" - : pet.canMeow() ? "cat" - : "probably a bunny"; + function blogPostExample() { + string storage animalName = pet.canBark() ? + pet.isScary() ? + "wolf" + : "dog" + : pet.canMeow() ? "cat" + : "probably a bunny"; + string storage animalName = pet.isScary() ? "wolf" + : pet.canBark() ? "dog" + : pet.canMeow() ? "cat" + : "probably a bunny"; + string storage animalName = pet.canSqueak() ? "mouse" + : pet.canBark() ? + pet.isScary() ? + "wolf" + : "dog" + : pet.canMeow() ? "cat" + : pet.canSqueak() ? "mouse" + : "probably a bunny"; + } + function examples1() { + string storage short = isLoud() ? makeNoise() : silent(); + string storage lessShort = isLoudReallyLoud() ? + makeNoiseReallyLoudly.omgSoLoud() + : silent(); + string storage andIndented = isLoudReallyReallyReallyReallyLoud() ? + makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() + : silent(); + string storage indentationInFalseExpression = ( + isLoudReallyReallyReallyReallyLoud() + ) ? + makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); + string storage shortSoCase = isLoudReallyReallyReallyReallyLoud() ? + silent() + : (makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud()); + string storage chainedShort = isCat() ? meow() + : isDog() ? bark() + : silent(); + string storage chainedWithLongConsequent = isCat() ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : isDog() ? bark() + : silent(); + string storage chainedWithTernaryConsequent = isCat() ? + aNestedCondition ? + theResult() + : theAlternate() + : isDog() ? bark() + : silent(); + string storage consequentAndTerminalAlternateBreak = isCat() ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : isDog() ? bark() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); + string storage multilineConditionsConsequentsAndAlternates = ( + isAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : ( + isNotAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + bark() + : shortCondition() ? shortConsequent() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); + assignment = ( + isAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : ( + isNotAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + bark() + : shortCondition() ? shortConsequent() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); + string storage mostlyShort = x == 1 ? "one" + : x == 2 ? "two" + : x == 3 ? "three" + : ( + x == 5 && + y == 7 && + someOtherThing.thatIsSoLong.thatItBreaksTheTestCondition() + ) ? + "four" + : x == 6 ? "six" + : "idk"; + string storage longConditional = ( + bifornCringerMoshedPerplexSawder == 2 / askTrovenaBeenaDependsRowans && + glimseGlyphsHazardNoopsTieTie >= + averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() + ) ? + "foo" + : "bar"; + string storage longConditionalChained = ( + bifornCringerMoshedPerplexSawder == 2 / askTrovenaBeenaDependsRowans && + glimseGlyphsHazardNoopsTieTie >= + averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() + ) ? + "foo" + : anotherCondition ? "bar" + : "baz"; + definition.encode( + row[field] != "undefined" ? row[field] + : definition.defaults != "undefined" ? definition.defaults + : "null", + row[field] == "undefined" ? + definition.defaults == "undefined" ? + "null" + : definition.defaults + : row[field] + ); + (((foo ? 1 : bar))) ? 3 : 4; + ( + isCat() ? meow() + : isDog() ? bark() + : silent() + ) ? + 1 + : 2; + if (short) { + return foo ? 1 : 2; + } + return row[aVeryLongFieldName] != "undefined" ? row[aVeryLongFieldName] + : "null"; + } + function examples2() { + string storage message = i % 3 == 0 && i % 5 == 0 ? "fizzbuzz" + : i % 3 == 0 ? "fizz" + : i % 5 == 0 ? "buzz" + : String(i); + string storage paymentMessageShort = state == "success" ? + "Payment completed successfully" + : state == "processing" ? "Payment processing" + : state == "invalid_cvc" ? "There was an issue with your CVC number" + : state == "invalid_expiry" ? "Expiry must be sometime in the past." + : "There was an issue with the payment. Please contact support."; + string storage paymentMessageWithABreak = state == "success" ? + "Payment completed successfully" + : state == "processing" ? "Payment processing" + : state == "invalid_cvc" ? + "There was an issue with your CVC number, and you need to take a prompt action on it." + : state == "invalid_expiry" ? "Expiry must be sometime in the past." + : "There was an issue with the payment. Please contact support."; + string storage typeofExample = definition.encode ? + definition.encode( + row[field] != "undefined" ? row[field] + : definition.defaults != "undefined" ? definition.defaults + : "null" + ) + : row[field] != "undefined" ? row[field] + : definition.defaults != "undefined" ? definition.defaults + : "null"; + string storage typeofExampleFlipped = definition.encode ? + definition.encode( + row[field] == "undefined" ? + definition.defaults == "undefined" ? + "null" + : definition.defaults + : row[field] + ) + : row[field] == "undefined" ? + definition.defaults == "undefined" ? + "null" + : definition.defaults + : row[field]; + } +} - // "case-style" ternaries - string storage animalName = - pet.isScary() ? "wolf" - : pet.canBark() ? "dog" - : pet.canMeow() ? "cat" - : "probably a bunny"; +================================================================================ +`; - // fluidity between "case-style" and "curious" ternaries - string storage animalName = - pet.canSqueak() ? "mouse" - : pet.canBark() ? - pet.isScary() ? - "wolf" - : "dog" - : pet.canMeow() ? "cat" - : pet.canSqueak() ? "mouse" - : "probably a bunny"; - } +exports[`ExperimentalTernaries.sol - {"experimentalTernaries":true,"useTabs":true} format 1`] = ` +====================================options===================================== +experimentalTernaries: true +parsers: ["solidity-parse"] +printWidth: 80 +useTabs: true + | printWidth +=====================================input====================================== +pragma solidity ^0.4.24; - function examples1() { - // remain on one line if possible: - string storage short = isLoud() ? makeNoise() : silent(); - // next, put everything after the = - string storage lessShort = - isLoudReallyLoud() ? makeNoiseReallyLoudly.omgSoLoud() : silent(); +contract Conditional { + function blogPostExample() { + // "curious" ternaries + string storage animalName = + pet.canBark() ? + pet.isScary() ? + 'wolf' + : 'dog' + : pet.canMeow() ? + 'cat' + : 'probably a bunny'; - // next, indent the consequent: - string storage andIndented = - isLoudReallyReallyReallyReallyLoud() ? - makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() - : silent(); + // "case-style" ternaries + string storage animalName = + pet.isScary() ? 'wolf' + : pet.canBark() ? 'dog' + : pet.canMeow() ? 'cat' + : 'probably a bunny'; + + // fluidity between "case-style" and "curious" ternaries + string storage animalName = + pet.canSqueak() ? 'mouse' + : pet.canBark() ? + pet.isScary() ? + 'wolf' + : 'dog' + : pet.canMeow() ? 'cat' + : pet.canSqueak() ? 'mouse' + : 'probably a bunny'; + } - // if we need to add spaces to the falseExpression to fill a tab, we indent it as well: - string storage indentationInFalseExpression = - isLoudReallyReallyReallyReallyLoud() ? - makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); + function examples1() { + // remain on one line if possible: + string storage short = isLoud() ? makeNoise() : silent(); - // unless the consequent is short (less than ten characters long): - string storage shortSoCase = - isLoudReallyReallyReallyReallyLoud() ? silent() - : (makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud()); + // next, put everything after the = + string storage lessShort = + isLoudReallyLoud() ? makeNoiseReallyLoudly.omgSoLoud() : silent(); - // if chained, always break and put after the = - string storage chainedShort = - isCat() ? meow() - : isDog() ? bark() - : silent(); + // next, indent the consequent: + string storage andIndented = + isLoudReallyReallyReallyReallyLoud() ? + makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() + : silent(); - // when a consequent breaks in a chain: - string storage chainedWithLongConsequent = - isCat() ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : isDog() ? bark() - : silent(); + // if we need to add spaces to the falseExpression to fill a tab, we indent it as well: + string storage indentationInFalseExpression = + isLoudReallyReallyReallyReallyLoud() ? + makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); - // nested ternary in consequent always breaks: - string storage chainedWithTernaryConsequent = - isCat() ? - aNestedCondition ? - theResult() - : theAlternate() - : isDog() ? bark() - : silent(); + // unless the consequent is short (less than ten characters long): + string storage shortSoCase = + isLoudReallyReallyReallyReallyLoud() ? silent() : ( + makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() + ); - // consequent and terminal alternate break: - string storage consequentAndTerminalAlternateBreak = - isCat() ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : isDog() ? bark() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); + // if chained, always break and put after the = + string storage chainedShort = + isCat() ? meow() + : isDog() ? bark() + : silent(); - // multiline conditions and consequents/alternates: - string storage multilineConditionsConsequentsAndAlternates = - ( - isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : ( - isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - bark() - : shortCondition() ? shortConsequent() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); + // when a consequent breaks in a chain: + string storage chainedWithLongConsequent = + isCat() ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : isDog() ? bark() + : silent(); - // Assignment also groups and indents as Variable Declaration: - assignment = ( - isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : ( - isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - bark() - : shortCondition() ? shortConsequent() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); + // nested ternary in consequent always breaks: + string storage chainedWithTernaryConsequent = + isCat() ? + aNestedCondition ? theResult() + : theAlternate() + : isDog() ? bark() + : silent(); - // illustrating case of mostly short conditionals - string storage mostlyShort = - x == 1 ? "one" - : x == 2 ? "two" - : x == 3 ? "three" - : ( - x == 5 && - y == 7 && - someOtherThing.thatIsSoLong.thatItBreaksTheTestCondition() - ) ? - "four" - : x == 6 ? "six" - : "idk"; + // consequent and terminal alternate break: + string storage consequentAndTerminalAlternateBreak = + isCat() ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : isDog() ? bark() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); - // long conditional, short consequent/alternate, not chained - do indent after ? - string storage longConditional = - ( - bifornCringerMoshedPerplexSawder == - 2 / askTrovenaBeenaDependsRowans && - glimseGlyphsHazardNoopsTieTie >= - averredBathersBoxroomBuggyNurl() - .anodyneCondosMalateOverateRetinol() - ) ? - "foo" - : "bar"; + // multiline conditions and consequents/alternates: + string storage multilineConditionsConsequentsAndAlternates = + ( + isAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : ( + isNotAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + bark() + : shortCondition() ? shortConsequent() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); - // long conditional, short consequent/alternate, chained - // (break on short consequents iff in chained ternary and its conditional broke) - string storage longConditionalChained = - ( - bifornCringerMoshedPerplexSawder == - 2 / askTrovenaBeenaDependsRowans && - glimseGlyphsHazardNoopsTieTie >= - averredBathersBoxroomBuggyNurl() - .anodyneCondosMalateOverateRetinol() - ) ? - "foo" - : anotherCondition ? "bar" - : "baz"; + // Assignment also groups and indents as Variable Declaration: + assignment = + ( + isAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : ( + isNotAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + bark() + : shortCondition() ? shortConsequent() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); - // As a function parameter, don't add an extra indent: - definition.encode( - row[field] != "undefined" ? row[field] - : definition.defaults != "undefined" ? definition.defaults - : "null", - row[field] == "undefined" ? - definition.defaults == "undefined" ? - "null" - : definition.defaults - : row[field] - ); + // illustrating case of mostly short conditionals + string storage mostlyShort = + x == 1 ? "one" + : x == 2 ? "two" + : x == 3 ? "three" + : ( + x == 5 && + y == 7 && + someOtherThing.thatIsSoLong.thatItBreaksTheTestCondition() + ) ? + "four" + : x == 6 ? "six" + : "idk"; - // Conditional as a condition - (foo ? 1 : bar) ? 3 : 4; - ( - isCat() ? meow() - : isDog() ? bark() - : silent() - ) ? - 1 - : 2; + // long conditional, short consequent/alternate, not chained - do indent after ? + string storage longConditional = + ( + bifornCringerMoshedPerplexSawder == 2 / askTrovenaBeenaDependsRowans && + glimseGlyphsHazardNoopsTieTie >= + averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() + ) ? + "foo" + : "bar"; - // In a return, break and over-indent: - if (short) { - return foo ? 1 : 2; - } - return row[aVeryLongFieldName] != "undefined" ? row[aVeryLongFieldName] - : "null"; - } + // long conditional, short consequent/alternate, chained + // (break on short consequents iff in chained ternary and its conditional broke) + string storage longConditionalChained = + ( + bifornCringerMoshedPerplexSawder == 2 / askTrovenaBeenaDependsRowans && + glimseGlyphsHazardNoopsTieTie >= + averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() + ) ? + "foo" + : anotherCondition ? "bar" + : "baz"; - function examples2() { - string storage message = - i % 3 == 0 && i % 5 == 0 ? "fizzbuzz" - : i % 3 == 0 ? "fizz" - : i % 5 == 0 ? "buzz" - : String(i); + // As a function parameter, don't add an extra indent: + definition.encode( + row[field] != "undefined" ? row[field] + : definition.defaults != "undefined" ? definition.defaults + : "null", + row[field] == "undefined" ? + definition.defaults == "undefined" ? + "null" + : definition.defaults + : row[field] + ); - string storage paymentMessageShort = - state == "success" ? "Payment completed successfully" - : state == "processing" ? "Payment processing" - : state == "invalid_cvc" ? "There was an issue with your CVC number" - : state == "invalid_expiry" ? "Expiry must be sometime in the past." - : "There was an issue with the payment. Please contact support."; + // Conditional as a condition + (((foo ? 1 : bar))) ? 3 : 4; + (isCat() ? meow() + : isDog() ? bark() + : silent()) ? 1: 2; - string storage paymentMessageWithABreak = - state == "success" ? "Payment completed successfully" - : state == "processing" ? "Payment processing" - : state == "invalid_cvc" ? - "There was an issue with your CVC number, and you need to take a prompt action on it." - : state == "invalid_expiry" ? "Expiry must be sometime in the past." - : "There was an issue with the payment. Please contact support."; + // In a return, break and over-indent: + if (short) { + return foo ? 1 : 2; + } + return row[aVeryLongFieldName] != "undefined" ? + row[aVeryLongFieldName] + : "null"; + } - string storage typeofExample = - definition.encode ? - definition.encode( - row[field] != "undefined" ? row[field] - : definition.defaults != "undefined" ? definition.defaults - : "null" - ) - : row[field] != "undefined" ? row[field] - : definition.defaults != "undefined" ? definition.defaults - : "null"; - // (the following is semantically equivalent to the above, but written in a more-confusing style – it'd be hard to grok no matter the formatting) - string storage typeofExampleFlipped = - definition.encode ? - definition.encode( - row[field] == "undefined" ? - definition.defaults == "undefined" ? - "null" - : definition.defaults - : row[field] - ) - : row[field] == "undefined" ? - definition.defaults == "undefined" ? - "null" + function examples2() {string storage message = + i % 3 == 0 && i % 5 == 0 ? "fizzbuzz" + : i % 3 == 0 ? "fizz" + : i % 5 == 0 ? "buzz" + : String(i); + +string storage paymentMessageShort = + state == "success" ? "Payment completed successfully" + : state == "processing" ? "Payment processing" + : state == "invalid_cvc" ? "There was an issue with your CVC number" + : state == "invalid_expiry" ? "Expiry must be sometime in the past." + : "There was an issue with the payment. Please contact support."; + +string storage paymentMessageWithABreak = + state == "success" ? "Payment completed successfully" + : state == "processing" ? "Payment processing" + : state == "invalid_cvc" ? + "There was an issue with your CVC number, and you need to take a prompt action on it." + : state == "invalid_expiry" ? "Expiry must be sometime in the past." + : "There was an issue with the payment. Please contact support."; + +string storage typeofExample = + definition.encode ? + definition.encode( + row[field] != "undefined" ? row[field] + : definition.defaults != "undefined" ? definition.defaults + : "null" + ) + : row[field] != "undefined" ? row[field] + : definition.defaults != "undefined" ? definition.defaults + : "null"; + +// (the following is semantically equivalent to the above, but written in a more-confusing style – it'd be hard to grok no matter the formatting) +string storage typeofExampleFlipped = + definition.encode ? + definition.encode( + row[field] == "undefined" ? + definition.defaults == "undefined" ? + "null" + : definition.defaults + : row[field] + ) + : row[field] == "undefined" ? + definition.defaults == "undefined" ? + "null" + : definition.defaults + : row[field]; + } +} + + + +=====================================output===================================== +pragma solidity ^0.4.24; + +contract Conditional { + function blogPostExample() { + // "curious" ternaries + string storage animalName = + pet.canBark() ? + pet.isScary() ? + "wolf" + : "dog" + : pet.canMeow() ? "cat" + : "probably a bunny"; + + // "case-style" ternaries + string storage animalName = + pet.isScary() ? "wolf" + : pet.canBark() ? "dog" + : pet.canMeow() ? "cat" + : "probably a bunny"; + + // fluidity between "case-style" and "curious" ternaries + string storage animalName = + pet.canSqueak() ? "mouse" + : pet.canBark() ? + pet.isScary() ? + "wolf" + : "dog" + : pet.canMeow() ? "cat" + : pet.canSqueak() ? "mouse" + : "probably a bunny"; + } + + function examples1() { + // remain on one line if possible: + string storage short = isLoud() ? makeNoise() : silent(); + + // next, put everything after the = + string storage lessShort = + isLoudReallyLoud() ? makeNoiseReallyLoudly.omgSoLoud() : silent(); + + // next, indent the consequent: + string storage andIndented = + isLoudReallyReallyReallyReallyLoud() ? + makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() + : silent(); + + // if we need to add spaces to the falseExpression to fill a tab, we indent it as well: + string storage indentationInFalseExpression = + isLoudReallyReallyReallyReallyLoud() ? + makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); + + // unless the consequent is short (less than ten characters long): + string storage shortSoCase = + isLoudReallyReallyReallyReallyLoud() ? silent() + : (makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud()); + + // if chained, always break and put after the = + string storage chainedShort = + isCat() ? meow() + : isDog() ? bark() + : silent(); + + // when a consequent breaks in a chain: + string storage chainedWithLongConsequent = + isCat() ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : isDog() ? bark() + : silent(); + + // nested ternary in consequent always breaks: + string storage chainedWithTernaryConsequent = + isCat() ? + aNestedCondition ? + theResult() + : theAlternate() + : isDog() ? bark() + : silent(); + + // consequent and terminal alternate break: + string storage consequentAndTerminalAlternateBreak = + isCat() ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : isDog() ? bark() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); + + // multiline conditions and consequents/alternates: + string storage multilineConditionsConsequentsAndAlternates = + ( + isAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : ( + isNotAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + bark() + : shortCondition() ? shortConsequent() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); + + // Assignment also groups and indents as Variable Declaration: + assignment = ( + isAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : ( + isNotAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + bark() + : shortCondition() ? shortConsequent() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); + + // illustrating case of mostly short conditionals + string storage mostlyShort = + x == 1 ? "one" + : x == 2 ? "two" + : x == 3 ? "three" + : ( + x == 5 && + y == 7 && + someOtherThing.thatIsSoLong.thatItBreaksTheTestCondition() + ) ? + "four" + : x == 6 ? "six" + : "idk"; + + // long conditional, short consequent/alternate, not chained - do indent after ? + string storage longConditional = + ( + bifornCringerMoshedPerplexSawder == + 2 / askTrovenaBeenaDependsRowans && + glimseGlyphsHazardNoopsTieTie >= + averredBathersBoxroomBuggyNurl() + .anodyneCondosMalateOverateRetinol() + ) ? + "foo" + : "bar"; + + // long conditional, short consequent/alternate, chained + // (break on short consequents iff in chained ternary and its conditional broke) + string storage longConditionalChained = + ( + bifornCringerMoshedPerplexSawder == + 2 / askTrovenaBeenaDependsRowans && + glimseGlyphsHazardNoopsTieTie >= + averredBathersBoxroomBuggyNurl() + .anodyneCondosMalateOverateRetinol() + ) ? + "foo" + : anotherCondition ? "bar" + : "baz"; + + // As a function parameter, don't add an extra indent: + definition.encode( + row[field] != "undefined" ? row[field] + : definition.defaults != "undefined" ? definition.defaults + : "null", + row[field] == "undefined" ? + definition.defaults == "undefined" ? + "null" : definition.defaults - : row[field]; + : row[field] + ); + + // Conditional as a condition + (foo ? 1 : bar) ? 3 : 4; + ( + isCat() ? meow() + : isDog() ? bark() + : silent() + ) ? + 1 + : 2; + + // In a return, break and over-indent: + if (short) { + return foo ? 1 : 2; + } + return row[aVeryLongFieldName] != "undefined" ? row[aVeryLongFieldName] + : "null"; } + + function examples2() { + string storage message = + i % 3 == 0 && i % 5 == 0 ? "fizzbuzz" + : i % 3 == 0 ? "fizz" + : i % 5 == 0 ? "buzz" + : String(i); + + string storage paymentMessageShort = + state == "success" ? "Payment completed successfully" + : state == "processing" ? "Payment processing" + : state == "invalid_cvc" ? "There was an issue with your CVC number" + : state == "invalid_expiry" ? "Expiry must be sometime in the past." + : "There was an issue with the payment. Please contact support."; + + string storage paymentMessageWithABreak = + state == "success" ? "Payment completed successfully" + : state == "processing" ? "Payment processing" + : state == "invalid_cvc" ? + "There was an issue with your CVC number, and you need to take a prompt action on it." + : state == "invalid_expiry" ? "Expiry must be sometime in the past." + : "There was an issue with the payment. Please contact support."; + + string storage typeofExample = + definition.encode ? + definition.encode( + row[field] != "undefined" ? row[field] + : definition.defaults != "undefined" ? definition.defaults + : "null" + ) + : row[field] != "undefined" ? row[field] + : definition.defaults != "undefined" ? definition.defaults + : "null"; + + // (the following is semantically equivalent to the above, but written in a more-confusing style – it'd be hard to grok no matter the formatting) + string storage typeofExampleFlipped = + definition.encode ? + definition.encode( + row[field] == "undefined" ? + definition.defaults == "undefined" ? + "null" + : definition.defaults + : row[field] + ) + : row[field] == "undefined" ? + definition.defaults == "undefined" ? + "null" + : definition.defaults + : row[field]; + } +} + +================================================================================ +`; + +exports[`ExperimentalTernaries.sol - {"experimentalTernaries":true,"useTabs":true} format 2`] = ` +====================================options===================================== +experimentalTernaries: true +parsers: ["solidity-slang-parse"] +printWidth: 80 +useTabs: true + | printWidth +=====================================input====================================== +pragma solidity ^0.4.24; + + +contract Conditional { + function blogPostExample() { + // "curious" ternaries + string storage animalName = + pet.canBark() ? + pet.isScary() ? + 'wolf' + : 'dog' + : pet.canMeow() ? + 'cat' + : 'probably a bunny'; + + // "case-style" ternaries + string storage animalName = + pet.isScary() ? 'wolf' + : pet.canBark() ? 'dog' + : pet.canMeow() ? 'cat' + : 'probably a bunny'; + + // fluidity between "case-style" and "curious" ternaries + string storage animalName = + pet.canSqueak() ? 'mouse' + : pet.canBark() ? + pet.isScary() ? + 'wolf' + : 'dog' + : pet.canMeow() ? 'cat' + : pet.canSqueak() ? 'mouse' + : 'probably a bunny'; + } + + function examples1() { + // remain on one line if possible: + string storage short = isLoud() ? makeNoise() : silent(); + + // next, put everything after the = + string storage lessShort = + isLoudReallyLoud() ? makeNoiseReallyLoudly.omgSoLoud() : silent(); + + // next, indent the consequent: + string storage andIndented = + isLoudReallyReallyReallyReallyLoud() ? + makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() + : silent(); + + // if we need to add spaces to the falseExpression to fill a tab, we indent it as well: + string storage indentationInFalseExpression = + isLoudReallyReallyReallyReallyLoud() ? + makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); + + // unless the consequent is short (less than ten characters long): + string storage shortSoCase = + isLoudReallyReallyReallyReallyLoud() ? silent() : ( + makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() + ); + + // if chained, always break and put after the = + string storage chainedShort = + isCat() ? meow() + : isDog() ? bark() + : silent(); + + // when a consequent breaks in a chain: + string storage chainedWithLongConsequent = + isCat() ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : isDog() ? bark() + : silent(); + + // nested ternary in consequent always breaks: + string storage chainedWithTernaryConsequent = + isCat() ? + aNestedCondition ? theResult() + : theAlternate() + : isDog() ? bark() + : silent(); + + // consequent and terminal alternate break: + string storage consequentAndTerminalAlternateBreak = + isCat() ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : isDog() ? bark() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); + + // multiline conditions and consequents/alternates: + string storage multilineConditionsConsequentsAndAlternates = + ( + isAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : ( + isNotAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + bark() + : shortCondition() ? shortConsequent() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); + + // Assignment also groups and indents as Variable Declaration: + assignment = + ( + isAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : ( + isNotAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + bark() + : shortCondition() ? shortConsequent() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); + + // illustrating case of mostly short conditionals + string storage mostlyShort = + x == 1 ? "one" + : x == 2 ? "two" + : x == 3 ? "three" + : ( + x == 5 && + y == 7 && + someOtherThing.thatIsSoLong.thatItBreaksTheTestCondition() + ) ? + "four" + : x == 6 ? "six" + : "idk"; + + // long conditional, short consequent/alternate, not chained - do indent after ? + string storage longConditional = + ( + bifornCringerMoshedPerplexSawder == 2 / askTrovenaBeenaDependsRowans && + glimseGlyphsHazardNoopsTieTie >= + averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() + ) ? + "foo" + : "bar"; + + // long conditional, short consequent/alternate, chained + // (break on short consequents iff in chained ternary and its conditional broke) + string storage longConditionalChained = + ( + bifornCringerMoshedPerplexSawder == 2 / askTrovenaBeenaDependsRowans && + glimseGlyphsHazardNoopsTieTie >= + averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() + ) ? + "foo" + : anotherCondition ? "bar" + : "baz"; + + // As a function parameter, don't add an extra indent: + definition.encode( + row[field] != "undefined" ? row[field] + : definition.defaults != "undefined" ? definition.defaults + : "null", + row[field] == "undefined" ? + definition.defaults == "undefined" ? + "null" + : definition.defaults + : row[field] + ); + + // Conditional as a condition + (((foo ? 1 : bar))) ? 3 : 4; + (isCat() ? meow() + : isDog() ? bark() + : silent()) ? 1: 2; + + // In a return, break and over-indent: + if (short) { + return foo ? 1 : 2; + } + return row[aVeryLongFieldName] != "undefined" ? + row[aVeryLongFieldName] + : "null"; + } + + + function examples2() {string storage message = + i % 3 == 0 && i % 5 == 0 ? "fizzbuzz" + : i % 3 == 0 ? "fizz" + : i % 5 == 0 ? "buzz" + : String(i); + +string storage paymentMessageShort = + state == "success" ? "Payment completed successfully" + : state == "processing" ? "Payment processing" + : state == "invalid_cvc" ? "There was an issue with your CVC number" + : state == "invalid_expiry" ? "Expiry must be sometime in the past." + : "There was an issue with the payment. Please contact support."; + +string storage paymentMessageWithABreak = + state == "success" ? "Payment completed successfully" + : state == "processing" ? "Payment processing" + : state == "invalid_cvc" ? + "There was an issue with your CVC number, and you need to take a prompt action on it." + : state == "invalid_expiry" ? "Expiry must be sometime in the past." + : "There was an issue with the payment. Please contact support."; + +string storage typeofExample = + definition.encode ? + definition.encode( + row[field] != "undefined" ? row[field] + : definition.defaults != "undefined" ? definition.defaults + : "null" + ) + : row[field] != "undefined" ? row[field] + : definition.defaults != "undefined" ? definition.defaults + : "null"; + +// (the following is semantically equivalent to the above, but written in a more-confusing style – it'd be hard to grok no matter the formatting) +string storage typeofExampleFlipped = + definition.encode ? + definition.encode( + row[field] == "undefined" ? + definition.defaults == "undefined" ? + "null" + : definition.defaults + : row[field] + ) + : row[field] == "undefined" ? + definition.defaults == "undefined" ? + "null" + : definition.defaults + : row[field]; + } +} + + + +=====================================output===================================== +pragma solidity ^0.4.24; +contract Conditional { + function blogPostExample() { + string storage animalName = pet.canBark() ? + pet.isScary() ? + "wolf" + : "dog" + : pet.canMeow() ? "cat" + : "probably a bunny"; + string storage animalName = pet.isScary() ? "wolf" + : pet.canBark() ? "dog" + : pet.canMeow() ? "cat" + : "probably a bunny"; + string storage animalName = pet.canSqueak() ? "mouse" + : pet.canBark() ? + pet.isScary() ? + "wolf" + : "dog" + : pet.canMeow() ? "cat" + : pet.canSqueak() ? "mouse" + : "probably a bunny"; + } + function examples1() { + string storage short = isLoud() ? makeNoise() : silent(); + string storage lessShort = isLoudReallyLoud() ? + makeNoiseReallyLoudly.omgSoLoud() + : silent(); + string storage andIndented = isLoudReallyReallyReallyReallyLoud() ? + makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() + : silent(); + string storage indentationInFalseExpression = ( + isLoudReallyReallyReallyReallyLoud() + ) ? + makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); + string storage shortSoCase = isLoudReallyReallyReallyReallyLoud() ? + silent() + : (makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud()); + string storage chainedShort = isCat() ? meow() + : isDog() ? bark() + : silent(); + string storage chainedWithLongConsequent = isCat() ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : isDog() ? bark() + : silent(); + string storage chainedWithTernaryConsequent = isCat() ? + aNestedCondition ? + theResult() + : theAlternate() + : isDog() ? bark() + : silent(); + string storage consequentAndTerminalAlternateBreak = isCat() ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : isDog() ? bark() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); + string storage multilineConditionsConsequentsAndAlternates = ( + isAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : ( + isNotAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + bark() + : shortCondition() ? shortConsequent() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); + assignment = ( + isAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : ( + isNotAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + bark() + : shortCondition() ? shortConsequent() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); + string storage mostlyShort = x == 1 ? "one" + : x == 2 ? "two" + : x == 3 ? "three" + : ( + x == 5 && + y == 7 && + someOtherThing.thatIsSoLong.thatItBreaksTheTestCondition() + ) ? + "four" + : x == 6 ? "six" + : "idk"; + string storage longConditional = ( + bifornCringerMoshedPerplexSawder == + 2 / + askTrovenaBeenaDependsRowans && + glimseGlyphsHazardNoopsTieTie >= + averredBathersBoxroomBuggyNurl() + .anodyneCondosMalateOverateRetinol() + ) ? + "foo" + : "bar"; + string storage longConditionalChained = ( + bifornCringerMoshedPerplexSawder == + 2 / + askTrovenaBeenaDependsRowans && + glimseGlyphsHazardNoopsTieTie >= + averredBathersBoxroomBuggyNurl() + .anodyneCondosMalateOverateRetinol() + ) ? + "foo" + : anotherCondition ? "bar" + : "baz"; + definition.encode( + row[field] != "undefined" ? row[field] + : definition.defaults != "undefined" ? definition.defaults + : "null", + row[field] == "undefined" ? + definition.defaults == "undefined" ? + "null" + : definition.defaults + : row[field] + ); + (((foo ? 1 : bar))) ? 3 : 4; + ( + isCat() ? meow() + : isDog() ? bark() + : silent() + ) ? + 1 + : 2; + if (short) { + return foo ? 1 : 2; + } + return row[aVeryLongFieldName] != "undefined" ? row[aVeryLongFieldName] + : "null"; + } + function examples2() { + string storage message = i % 3 == 0 && i % 5 == 0 ? "fizzbuzz" + : i % 3 == 0 ? "fizz" + : i % 5 == 0 ? "buzz" + : String(i); + string storage paymentMessageShort = state == "success" ? + "Payment completed successfully" + : state == "processing" ? "Payment processing" + : state == "invalid_cvc" ? "There was an issue with your CVC number" + : state == "invalid_expiry" ? "Expiry must be sometime in the past." + : "There was an issue with the payment. Please contact support."; + string storage paymentMessageWithABreak = state == "success" ? + "Payment completed successfully" + : state == "processing" ? "Payment processing" + : state == "invalid_cvc" ? + "There was an issue with your CVC number, and you need to take a prompt action on it." + : state == "invalid_expiry" ? "Expiry must be sometime in the past." + : "There was an issue with the payment. Please contact support."; + string storage typeofExample = definition.encode ? + definition.encode( + row[field] != "undefined" ? row[field] + : definition.defaults != "undefined" ? definition.defaults + : "null" + ) + : row[field] != "undefined" ? row[field] + : definition.defaults != "undefined" ? definition.defaults + : "null"; + string storage typeofExampleFlipped = definition.encode ? + definition.encode( + row[field] == "undefined" ? + definition.defaults == "undefined" ? + "null" + : definition.defaults + : row[field] + ) + : row[field] == "undefined" ? + definition.defaults == "undefined" ? + "null" + : definition.defaults + : row[field]; + } +} + +================================================================================ +`; + +exports[`ExperimentalTernaries.sol - {"experimentalTernaries":true} format 1`] = ` +====================================options===================================== +experimentalTernaries: true +parsers: ["solidity-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity ^0.4.24; + + +contract Conditional { + function blogPostExample() { + // "curious" ternaries + string storage animalName = + pet.canBark() ? + pet.isScary() ? + 'wolf' + : 'dog' + : pet.canMeow() ? + 'cat' + : 'probably a bunny'; + + // "case-style" ternaries + string storage animalName = + pet.isScary() ? 'wolf' + : pet.canBark() ? 'dog' + : pet.canMeow() ? 'cat' + : 'probably a bunny'; + + // fluidity between "case-style" and "curious" ternaries + string storage animalName = + pet.canSqueak() ? 'mouse' + : pet.canBark() ? + pet.isScary() ? + 'wolf' + : 'dog' + : pet.canMeow() ? 'cat' + : pet.canSqueak() ? 'mouse' + : 'probably a bunny'; + } + + function examples1() { + // remain on one line if possible: + string storage short = isLoud() ? makeNoise() : silent(); + + // next, put everything after the = + string storage lessShort = + isLoudReallyLoud() ? makeNoiseReallyLoudly.omgSoLoud() : silent(); + + // next, indent the consequent: + string storage andIndented = + isLoudReallyReallyReallyReallyLoud() ? + makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() + : silent(); + + // if we need to add spaces to the falseExpression to fill a tab, we indent it as well: + string storage indentationInFalseExpression = + isLoudReallyReallyReallyReallyLoud() ? + makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); + + // unless the consequent is short (less than ten characters long): + string storage shortSoCase = + isLoudReallyReallyReallyReallyLoud() ? silent() : ( + makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() + ); + + // if chained, always break and put after the = + string storage chainedShort = + isCat() ? meow() + : isDog() ? bark() + : silent(); + + // when a consequent breaks in a chain: + string storage chainedWithLongConsequent = + isCat() ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : isDog() ? bark() + : silent(); + + // nested ternary in consequent always breaks: + string storage chainedWithTernaryConsequent = + isCat() ? + aNestedCondition ? theResult() + : theAlternate() + : isDog() ? bark() + : silent(); + + // consequent and terminal alternate break: + string storage consequentAndTerminalAlternateBreak = + isCat() ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : isDog() ? bark() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); + + // multiline conditions and consequents/alternates: + string storage multilineConditionsConsequentsAndAlternates = + ( + isAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : ( + isNotAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + bark() + : shortCondition() ? shortConsequent() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); + + // Assignment also groups and indents as Variable Declaration: + assignment = + ( + isAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : ( + isNotAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + bark() + : shortCondition() ? shortConsequent() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); + + // illustrating case of mostly short conditionals + string storage mostlyShort = + x == 1 ? "one" + : x == 2 ? "two" + : x == 3 ? "three" + : ( + x == 5 && + y == 7 && + someOtherThing.thatIsSoLong.thatItBreaksTheTestCondition() + ) ? + "four" + : x == 6 ? "six" + : "idk"; + + // long conditional, short consequent/alternate, not chained - do indent after ? + string storage longConditional = + ( + bifornCringerMoshedPerplexSawder == 2 / askTrovenaBeenaDependsRowans && + glimseGlyphsHazardNoopsTieTie >= + averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() + ) ? + "foo" + : "bar"; + + // long conditional, short consequent/alternate, chained + // (break on short consequents iff in chained ternary and its conditional broke) + string storage longConditionalChained = + ( + bifornCringerMoshedPerplexSawder == 2 / askTrovenaBeenaDependsRowans && + glimseGlyphsHazardNoopsTieTie >= + averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() + ) ? + "foo" + : anotherCondition ? "bar" + : "baz"; + + // As a function parameter, don't add an extra indent: + definition.encode( + row[field] != "undefined" ? row[field] + : definition.defaults != "undefined" ? definition.defaults + : "null", + row[field] == "undefined" ? + definition.defaults == "undefined" ? + "null" + : definition.defaults + : row[field] + ); + + // Conditional as a condition + (((foo ? 1 : bar))) ? 3 : 4; + (isCat() ? meow() + : isDog() ? bark() + : silent()) ? 1: 2; + + // In a return, break and over-indent: + if (short) { + return foo ? 1 : 2; + } + return row[aVeryLongFieldName] != "undefined" ? + row[aVeryLongFieldName] + : "null"; + } + + + function examples2() {string storage message = + i % 3 == 0 && i % 5 == 0 ? "fizzbuzz" + : i % 3 == 0 ? "fizz" + : i % 5 == 0 ? "buzz" + : String(i); + +string storage paymentMessageShort = + state == "success" ? "Payment completed successfully" + : state == "processing" ? "Payment processing" + : state == "invalid_cvc" ? "There was an issue with your CVC number" + : state == "invalid_expiry" ? "Expiry must be sometime in the past." + : "There was an issue with the payment. Please contact support."; + +string storage paymentMessageWithABreak = + state == "success" ? "Payment completed successfully" + : state == "processing" ? "Payment processing" + : state == "invalid_cvc" ? + "There was an issue with your CVC number, and you need to take a prompt action on it." + : state == "invalid_expiry" ? "Expiry must be sometime in the past." + : "There was an issue with the payment. Please contact support."; + +string storage typeofExample = + definition.encode ? + definition.encode( + row[field] != "undefined" ? row[field] + : definition.defaults != "undefined" ? definition.defaults + : "null" + ) + : row[field] != "undefined" ? row[field] + : definition.defaults != "undefined" ? definition.defaults + : "null"; + +// (the following is semantically equivalent to the above, but written in a more-confusing style – it'd be hard to grok no matter the formatting) +string storage typeofExampleFlipped = + definition.encode ? + definition.encode( + row[field] == "undefined" ? + definition.defaults == "undefined" ? + "null" + : definition.defaults + : row[field] + ) + : row[field] == "undefined" ? + definition.defaults == "undefined" ? + "null" + : definition.defaults + : row[field]; + } +} + + + +=====================================output===================================== +pragma solidity ^0.4.24; + +contract Conditional { + function blogPostExample() { + // "curious" ternaries + string storage animalName = + pet.canBark() ? + pet.isScary() ? + "wolf" + : "dog" + : pet.canMeow() ? "cat" + : "probably a bunny"; + + // "case-style" ternaries + string storage animalName = + pet.isScary() ? "wolf" + : pet.canBark() ? "dog" + : pet.canMeow() ? "cat" + : "probably a bunny"; + + // fluidity between "case-style" and "curious" ternaries + string storage animalName = + pet.canSqueak() ? "mouse" + : pet.canBark() ? + pet.isScary() ? + "wolf" + : "dog" + : pet.canMeow() ? "cat" + : pet.canSqueak() ? "mouse" + : "probably a bunny"; + } + + function examples1() { + // remain on one line if possible: + string storage short = isLoud() ? makeNoise() : silent(); + + // next, put everything after the = + string storage lessShort = + isLoudReallyLoud() ? makeNoiseReallyLoudly.omgSoLoud() : silent(); + + // next, indent the consequent: + string storage andIndented = + isLoudReallyReallyReallyReallyLoud() ? + makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() + : silent(); + + // if we need to add spaces to the falseExpression to fill a tab, we indent it as well: + string storage indentationInFalseExpression = + isLoudReallyReallyReallyReallyLoud() ? + makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); + + // unless the consequent is short (less than ten characters long): + string storage shortSoCase = + isLoudReallyReallyReallyReallyLoud() ? silent() + : (makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud()); + + // if chained, always break and put after the = + string storage chainedShort = + isCat() ? meow() + : isDog() ? bark() + : silent(); + + // when a consequent breaks in a chain: + string storage chainedWithLongConsequent = + isCat() ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : isDog() ? bark() + : silent(); + + // nested ternary in consequent always breaks: + string storage chainedWithTernaryConsequent = + isCat() ? + aNestedCondition ? + theResult() + : theAlternate() + : isDog() ? bark() + : silent(); + + // consequent and terminal alternate break: + string storage consequentAndTerminalAlternateBreak = + isCat() ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : isDog() ? bark() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); + + // multiline conditions and consequents/alternates: + string storage multilineConditionsConsequentsAndAlternates = + ( + isAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : ( + isNotAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + bark() + : shortCondition() ? shortConsequent() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); + + // Assignment also groups and indents as Variable Declaration: + assignment = ( + isAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : ( + isNotAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + bark() + : shortCondition() ? shortConsequent() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); + + // illustrating case of mostly short conditionals + string storage mostlyShort = + x == 1 ? "one" + : x == 2 ? "two" + : x == 3 ? "three" + : ( + x == 5 && + y == 7 && + someOtherThing.thatIsSoLong.thatItBreaksTheTestCondition() + ) ? + "four" + : x == 6 ? "six" + : "idk"; + + // long conditional, short consequent/alternate, not chained - do indent after ? + string storage longConditional = + ( + bifornCringerMoshedPerplexSawder == + 2 / askTrovenaBeenaDependsRowans && + glimseGlyphsHazardNoopsTieTie >= + averredBathersBoxroomBuggyNurl() + .anodyneCondosMalateOverateRetinol() + ) ? + "foo" + : "bar"; + + // long conditional, short consequent/alternate, chained + // (break on short consequents iff in chained ternary and its conditional broke) + string storage longConditionalChained = + ( + bifornCringerMoshedPerplexSawder == + 2 / askTrovenaBeenaDependsRowans && + glimseGlyphsHazardNoopsTieTie >= + averredBathersBoxroomBuggyNurl() + .anodyneCondosMalateOverateRetinol() + ) ? + "foo" + : anotherCondition ? "bar" + : "baz"; + + // As a function parameter, don't add an extra indent: + definition.encode( + row[field] != "undefined" ? row[field] + : definition.defaults != "undefined" ? definition.defaults + : "null", + row[field] == "undefined" ? + definition.defaults == "undefined" ? + "null" + : definition.defaults + : row[field] + ); + + // Conditional as a condition + (foo ? 1 : bar) ? 3 : 4; + ( + isCat() ? meow() + : isDog() ? bark() + : silent() + ) ? + 1 + : 2; + + // In a return, break and over-indent: + if (short) { + return foo ? 1 : 2; + } + return row[aVeryLongFieldName] != "undefined" ? row[aVeryLongFieldName] + : "null"; + } + + function examples2() { + string storage message = + i % 3 == 0 && i % 5 == 0 ? "fizzbuzz" + : i % 3 == 0 ? "fizz" + : i % 5 == 0 ? "buzz" + : String(i); + + string storage paymentMessageShort = + state == "success" ? "Payment completed successfully" + : state == "processing" ? "Payment processing" + : state == "invalid_cvc" ? "There was an issue with your CVC number" + : state == "invalid_expiry" ? "Expiry must be sometime in the past." + : "There was an issue with the payment. Please contact support."; + + string storage paymentMessageWithABreak = + state == "success" ? "Payment completed successfully" + : state == "processing" ? "Payment processing" + : state == "invalid_cvc" ? + "There was an issue with your CVC number, and you need to take a prompt action on it." + : state == "invalid_expiry" ? "Expiry must be sometime in the past." + : "There was an issue with the payment. Please contact support."; + + string storage typeofExample = + definition.encode ? + definition.encode( + row[field] != "undefined" ? row[field] + : definition.defaults != "undefined" ? definition.defaults + : "null" + ) + : row[field] != "undefined" ? row[field] + : definition.defaults != "undefined" ? definition.defaults + : "null"; + + // (the following is semantically equivalent to the above, but written in a more-confusing style – it'd be hard to grok no matter the formatting) + string storage typeofExampleFlipped = + definition.encode ? + definition.encode( + row[field] == "undefined" ? + definition.defaults == "undefined" ? + "null" + : definition.defaults + : row[field] + ) + : row[field] == "undefined" ? + definition.defaults == "undefined" ? + "null" + : definition.defaults + : row[field]; + } +} + +================================================================================ +`; + +exports[`ExperimentalTernaries.sol - {"experimentalTernaries":true} format 2`] = ` +====================================options===================================== +experimentalTernaries: true +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity ^0.4.24; + + +contract Conditional { + function blogPostExample() { + // "curious" ternaries + string storage animalName = + pet.canBark() ? + pet.isScary() ? + 'wolf' + : 'dog' + : pet.canMeow() ? + 'cat' + : 'probably a bunny'; + + // "case-style" ternaries + string storage animalName = + pet.isScary() ? 'wolf' + : pet.canBark() ? 'dog' + : pet.canMeow() ? 'cat' + : 'probably a bunny'; + + // fluidity between "case-style" and "curious" ternaries + string storage animalName = + pet.canSqueak() ? 'mouse' + : pet.canBark() ? + pet.isScary() ? + 'wolf' + : 'dog' + : pet.canMeow() ? 'cat' + : pet.canSqueak() ? 'mouse' + : 'probably a bunny'; + } + + function examples1() { + // remain on one line if possible: + string storage short = isLoud() ? makeNoise() : silent(); + + // next, put everything after the = + string storage lessShort = + isLoudReallyLoud() ? makeNoiseReallyLoudly.omgSoLoud() : silent(); + + // next, indent the consequent: + string storage andIndented = + isLoudReallyReallyReallyReallyLoud() ? + makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() + : silent(); + + // if we need to add spaces to the falseExpression to fill a tab, we indent it as well: + string storage indentationInFalseExpression = + isLoudReallyReallyReallyReallyLoud() ? + makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); + + // unless the consequent is short (less than ten characters long): + string storage shortSoCase = + isLoudReallyReallyReallyReallyLoud() ? silent() : ( + makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() + ); + + // if chained, always break and put after the = + string storage chainedShort = + isCat() ? meow() + : isDog() ? bark() + : silent(); + + // when a consequent breaks in a chain: + string storage chainedWithLongConsequent = + isCat() ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : isDog() ? bark() + : silent(); + + // nested ternary in consequent always breaks: + string storage chainedWithTernaryConsequent = + isCat() ? + aNestedCondition ? theResult() + : theAlternate() + : isDog() ? bark() + : silent(); + + // consequent and terminal alternate break: + string storage consequentAndTerminalAlternateBreak = + isCat() ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : isDog() ? bark() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); + + // multiline conditions and consequents/alternates: + string storage multilineConditionsConsequentsAndAlternates = + ( + isAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : ( + isNotAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + bark() + : shortCondition() ? shortConsequent() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); + + // Assignment also groups and indents as Variable Declaration: + assignment = + ( + isAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : ( + isNotAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + bark() + : shortCondition() ? shortConsequent() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); + + // illustrating case of mostly short conditionals + string storage mostlyShort = + x == 1 ? "one" + : x == 2 ? "two" + : x == 3 ? "three" + : ( + x == 5 && + y == 7 && + someOtherThing.thatIsSoLong.thatItBreaksTheTestCondition() + ) ? + "four" + : x == 6 ? "six" + : "idk"; + + // long conditional, short consequent/alternate, not chained - do indent after ? + string storage longConditional = + ( + bifornCringerMoshedPerplexSawder == 2 / askTrovenaBeenaDependsRowans && + glimseGlyphsHazardNoopsTieTie >= + averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() + ) ? + "foo" + : "bar"; + + // long conditional, short consequent/alternate, chained + // (break on short consequents iff in chained ternary and its conditional broke) + string storage longConditionalChained = + ( + bifornCringerMoshedPerplexSawder == 2 / askTrovenaBeenaDependsRowans && + glimseGlyphsHazardNoopsTieTie >= + averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() + ) ? + "foo" + : anotherCondition ? "bar" + : "baz"; + + // As a function parameter, don't add an extra indent: + definition.encode( + row[field] != "undefined" ? row[field] + : definition.defaults != "undefined" ? definition.defaults + : "null", + row[field] == "undefined" ? + definition.defaults == "undefined" ? + "null" + : definition.defaults + : row[field] + ); + + // Conditional as a condition + (((foo ? 1 : bar))) ? 3 : 4; + (isCat() ? meow() + : isDog() ? bark() + : silent()) ? 1: 2; + + // In a return, break and over-indent: + if (short) { + return foo ? 1 : 2; + } + return row[aVeryLongFieldName] != "undefined" ? + row[aVeryLongFieldName] + : "null"; + } + + + function examples2() {string storage message = + i % 3 == 0 && i % 5 == 0 ? "fizzbuzz" + : i % 3 == 0 ? "fizz" + : i % 5 == 0 ? "buzz" + : String(i); + +string storage paymentMessageShort = + state == "success" ? "Payment completed successfully" + : state == "processing" ? "Payment processing" + : state == "invalid_cvc" ? "There was an issue with your CVC number" + : state == "invalid_expiry" ? "Expiry must be sometime in the past." + : "There was an issue with the payment. Please contact support."; + +string storage paymentMessageWithABreak = + state == "success" ? "Payment completed successfully" + : state == "processing" ? "Payment processing" + : state == "invalid_cvc" ? + "There was an issue with your CVC number, and you need to take a prompt action on it." + : state == "invalid_expiry" ? "Expiry must be sometime in the past." + : "There was an issue with the payment. Please contact support."; + +string storage typeofExample = + definition.encode ? + definition.encode( + row[field] != "undefined" ? row[field] + : definition.defaults != "undefined" ? definition.defaults + : "null" + ) + : row[field] != "undefined" ? row[field] + : definition.defaults != "undefined" ? definition.defaults + : "null"; + +// (the following is semantically equivalent to the above, but written in a more-confusing style – it'd be hard to grok no matter the formatting) +string storage typeofExampleFlipped = + definition.encode ? + definition.encode( + row[field] == "undefined" ? + definition.defaults == "undefined" ? + "null" + : definition.defaults + : row[field] + ) + : row[field] == "undefined" ? + definition.defaults == "undefined" ? + "null" + : definition.defaults + : row[field]; + } +} + + + +=====================================output===================================== +pragma solidity ^0.4.24; +contract Conditional { + function blogPostExample() { + string storage animalName = pet.canBark() ? + pet.isScary() ? + "wolf" + : "dog" + : pet.canMeow() ? "cat" + : "probably a bunny"; + string storage animalName = pet.isScary() ? "wolf" + : pet.canBark() ? "dog" + : pet.canMeow() ? "cat" + : "probably a bunny"; + string storage animalName = pet.canSqueak() ? "mouse" + : pet.canBark() ? + pet.isScary() ? + "wolf" + : "dog" + : pet.canMeow() ? "cat" + : pet.canSqueak() ? "mouse" + : "probably a bunny"; + } + function examples1() { + string storage short = isLoud() ? makeNoise() : silent(); + string storage lessShort = isLoudReallyLoud() ? + makeNoiseReallyLoudly.omgSoLoud() + : silent(); + string storage andIndented = isLoudReallyReallyReallyReallyLoud() ? + makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() + : silent(); + string storage indentationInFalseExpression = ( + isLoudReallyReallyReallyReallyLoud() + ) ? + makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); + string storage shortSoCase = isLoudReallyReallyReallyReallyLoud() ? + silent() + : (makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud()); + string storage chainedShort = isCat() ? meow() + : isDog() ? bark() + : silent(); + string storage chainedWithLongConsequent = isCat() ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : isDog() ? bark() + : silent(); + string storage chainedWithTernaryConsequent = isCat() ? + aNestedCondition ? + theResult() + : theAlternate() + : isDog() ? bark() + : silent(); + string storage consequentAndTerminalAlternateBreak = isCat() ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : isDog() ? bark() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); + string storage multilineConditionsConsequentsAndAlternates = ( + isAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : ( + isNotAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + bark() + : shortCondition() ? shortConsequent() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); + assignment = ( + isAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : ( + isNotAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + bark() + : shortCondition() ? shortConsequent() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); + string storage mostlyShort = x == 1 ? "one" + : x == 2 ? "two" + : x == 3 ? "three" + : ( + x == 5 && + y == 7 && + someOtherThing.thatIsSoLong.thatItBreaksTheTestCondition() + ) ? + "four" + : x == 6 ? "six" + : "idk"; + string storage longConditional = ( + bifornCringerMoshedPerplexSawder == + 2 / + askTrovenaBeenaDependsRowans && + glimseGlyphsHazardNoopsTieTie >= + averredBathersBoxroomBuggyNurl() + .anodyneCondosMalateOverateRetinol() + ) ? + "foo" + : "bar"; + string storage longConditionalChained = ( + bifornCringerMoshedPerplexSawder == + 2 / + askTrovenaBeenaDependsRowans && + glimseGlyphsHazardNoopsTieTie >= + averredBathersBoxroomBuggyNurl() + .anodyneCondosMalateOverateRetinol() + ) ? + "foo" + : anotherCondition ? "bar" + : "baz"; + definition.encode( + row[field] != "undefined" ? row[field] + : definition.defaults != "undefined" ? definition.defaults + : "null", + row[field] == "undefined" ? + definition.defaults == "undefined" ? + "null" + : definition.defaults + : row[field] + ); + (((foo ? 1 : bar))) ? 3 : 4; + ( + isCat() ? meow() + : isDog() ? bark() + : silent() + ) ? + 1 + : 2; + if (short) { + return foo ? 1 : 2; + } + return row[aVeryLongFieldName] != "undefined" ? row[aVeryLongFieldName] + : "null"; + } + function examples2() { + string storage message = i % 3 == 0 && i % 5 == 0 ? "fizzbuzz" + : i % 3 == 0 ? "fizz" + : i % 5 == 0 ? "buzz" + : String(i); + string storage paymentMessageShort = state == "success" ? + "Payment completed successfully" + : state == "processing" ? "Payment processing" + : state == "invalid_cvc" ? "There was an issue with your CVC number" + : state == "invalid_expiry" ? "Expiry must be sometime in the past." + : "There was an issue with the payment. Please contact support."; + string storage paymentMessageWithABreak = state == "success" ? + "Payment completed successfully" + : state == "processing" ? "Payment processing" + : state == "invalid_cvc" ? + "There was an issue with your CVC number, and you need to take a prompt action on it." + : state == "invalid_expiry" ? "Expiry must be sometime in the past." + : "There was an issue with the payment. Please contact support."; + string storage typeofExample = definition.encode ? + definition.encode( + row[field] != "undefined" ? row[field] + : definition.defaults != "undefined" ? definition.defaults + : "null" + ) + : row[field] != "undefined" ? row[field] + : definition.defaults != "undefined" ? definition.defaults + : "null"; + string storage typeofExampleFlipped = definition.encode ? + definition.encode( + row[field] == "undefined" ? + definition.defaults == "undefined" ? + "null" + : definition.defaults + : row[field] + ) + : row[field] == "undefined" ? + definition.defaults == "undefined" ? + "null" + : definition.defaults + : row[field]; + } } ================================================================================ `; -exports[`ExperimentalTernaries.sol - {"experimentalTernaries":true} format 1`] = ` +exports[`ExperimentalTernaries.sol format 1`] = ` ====================================options===================================== -experimentalTernaries: true parsers: ["solidity-parse"] printWidth: 80 | printWidth @@ -1287,31 +3160,35 @@ pragma solidity ^0.4.24; contract Conditional { function blogPostExample() { // "curious" ternaries - string storage animalName = - pet.canBark() ? - pet.isScary() ? - "wolf" - : "dog" - : pet.canMeow() ? "cat" - : "probably a bunny"; + string storage animalName = pet.canBark() + ? pet.isScary() + ? "wolf" + : "dog" + : pet.canMeow() + ? "cat" + : "probably a bunny"; // "case-style" ternaries - string storage animalName = - pet.isScary() ? "wolf" - : pet.canBark() ? "dog" - : pet.canMeow() ? "cat" - : "probably a bunny"; + string storage animalName = pet.isScary() + ? "wolf" + : pet.canBark() + ? "dog" + : pet.canMeow() + ? "cat" + : "probably a bunny"; // fluidity between "case-style" and "curious" ternaries - string storage animalName = - pet.canSqueak() ? "mouse" - : pet.canBark() ? - pet.isScary() ? - "wolf" - : "dog" - : pet.canMeow() ? "cat" - : pet.canSqueak() ? "mouse" - : "probably a bunny"; + string storage animalName = pet.canSqueak() + ? "mouse" + : pet.canBark() + ? pet.isScary() + ? "wolf" + : "dog" + : pet.canMeow() + ? "cat" + : pet.canSqueak() + ? "mouse" + : "probably a bunny"; } function examples1() { @@ -1319,227 +3196,236 @@ contract Conditional { string storage short = isLoud() ? makeNoise() : silent(); // next, put everything after the = - string storage lessShort = - isLoudReallyLoud() ? makeNoiseReallyLoudly.omgSoLoud() : silent(); + string storage lessShort = isLoudReallyLoud() + ? makeNoiseReallyLoudly.omgSoLoud() + : silent(); // next, indent the consequent: - string storage andIndented = - isLoudReallyReallyReallyReallyLoud() ? - makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() - : silent(); + string storage andIndented = isLoudReallyReallyReallyReallyLoud() + ? makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() + : silent(); // if we need to add spaces to the falseExpression to fill a tab, we indent it as well: - string storage indentationInFalseExpression = - isLoudReallyReallyReallyReallyLoud() ? - makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() - : someReallyLargeExpression + string + storage indentationInFalseExpression = isLoudReallyReallyReallyReallyLoud() + ? makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() + : someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens(); // unless the consequent is short (less than ten characters long): - string storage shortSoCase = - isLoudReallyReallyReallyReallyLoud() ? silent() + string storage shortSoCase = isLoudReallyReallyReallyReallyLoud() + ? silent() : (makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud()); // if chained, always break and put after the = - string storage chainedShort = - isCat() ? meow() - : isDog() ? bark() - : silent(); + string storage chainedShort = isCat() + ? meow() + : isDog() + ? bark() + : silent(); // when a consequent breaks in a chain: - string storage chainedWithLongConsequent = - isCat() ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : isDog() ? bark() - : silent(); + string storage chainedWithLongConsequent = isCat() + ? someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : isDog() + ? bark() + : silent(); // nested ternary in consequent always breaks: - string storage chainedWithTernaryConsequent = - isCat() ? - aNestedCondition ? - theResult() - : theAlternate() - : isDog() ? bark() - : silent(); + string storage chainedWithTernaryConsequent = isCat() + ? aNestedCondition + ? theResult() + : theAlternate() + : isDog() + ? bark() + : silent(); // consequent and terminal alternate break: - string storage consequentAndTerminalAlternateBreak = - isCat() ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : isDog() ? bark() - : someReallyLargeExpression + string storage consequentAndTerminalAlternateBreak = isCat() + ? someReallyLargeExpression .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); + .willCauseAnIndentButNotParens() + : isDog() + ? bark() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); // multiline conditions and consequents/alternates: - string storage multilineConditionsConsequentsAndAlternates = - ( - isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - someReallyLargeExpression + string + storage multilineConditionsConsequentsAndAlternates = (isAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition)) + ? someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens() - : ( - isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - bark() - : shortCondition() ? shortConsequent() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); + : (isNotAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition)) + ? bark() + : shortCondition() + ? shortConsequent() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); // Assignment also groups and indents as Variable Declaration: - assignment = ( - isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - someReallyLargeExpression + assignment = (isAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition)) + ? someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens() - : ( - isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - bark() - : shortCondition() ? shortConsequent() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); + : (isNotAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition)) + ? bark() + : shortCondition() + ? shortConsequent() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); // illustrating case of mostly short conditionals - string storage mostlyShort = - x == 1 ? "one" - : x == 2 ? "two" - : x == 3 ? "three" - : ( - x == 5 && - y == 7 && - someOtherThing.thatIsSoLong.thatItBreaksTheTestCondition() - ) ? - "four" - : x == 6 ? "six" - : "idk"; + string storage mostlyShort = x == 1 + ? "one" + : x == 2 + ? "two" + : x == 3 + ? "three" + : (x == 5 && + y == 7 && + someOtherThing + .thatIsSoLong + .thatItBreaksTheTestCondition()) + ? "four" + : x == 6 + ? "six" + : "idk"; // long conditional, short consequent/alternate, not chained - do indent after ? - string storage longConditional = - ( - bifornCringerMoshedPerplexSawder == - 2 / askTrovenaBeenaDependsRowans && - glimseGlyphsHazardNoopsTieTie >= - averredBathersBoxroomBuggyNurl() - .anodyneCondosMalateOverateRetinol() - ) ? - "foo" - : "bar"; + string storage longConditional = (bifornCringerMoshedPerplexSawder == + 2 / askTrovenaBeenaDependsRowans && + glimseGlyphsHazardNoopsTieTie >= + averredBathersBoxroomBuggyNurl() + .anodyneCondosMalateOverateRetinol()) + ? "foo" + : "bar"; // long conditional, short consequent/alternate, chained // (break on short consequents iff in chained ternary and its conditional broke) - string storage longConditionalChained = - ( - bifornCringerMoshedPerplexSawder == - 2 / askTrovenaBeenaDependsRowans && + string + storage longConditionalChained = (bifornCringerMoshedPerplexSawder == + 2 / askTrovenaBeenaDependsRowans && glimseGlyphsHazardNoopsTieTie >= averredBathersBoxroomBuggyNurl() - .anodyneCondosMalateOverateRetinol() - ) ? - "foo" - : anotherCondition ? "bar" - : "baz"; + .anodyneCondosMalateOverateRetinol()) + ? "foo" + : anotherCondition + ? "bar" + : "baz"; - // As a function parameter, don't add an extra indent: - definition.encode( - row[field] != "undefined" ? row[field] - : definition.defaults != "undefined" ? definition.defaults - : "null", - row[field] == "undefined" ? - definition.defaults == "undefined" ? - "null" - : definition.defaults - : row[field] + // As a function parameter, don't add an extra indent: + definition.encode( + row[field] != "undefined" + ? row[field] + : definition.defaults != "undefined" + ? definition.defaults + : "null", + row[field] == "undefined" + ? definition.defaults == "undefined" + ? "null" + : definition.defaults + : row[field] ); // Conditional as a condition - (foo ? 1 : bar) ? 3 : 4; + (((foo ? 1 : bar))) ? 3 : 4; ( - isCat() ? meow() - : isDog() ? bark() - : silent() - ) ? - 1 - : 2; + isCat() + ? meow() + : isDog() + ? bark() + : silent() + ) + ? 1 + : 2; // In a return, break and over-indent: if (short) { return foo ? 1 : 2; } - return row[aVeryLongFieldName] != "undefined" ? row[aVeryLongFieldName] - : "null"; + return + row[aVeryLongFieldName] != "undefined" + ? row[aVeryLongFieldName] + : "null"; } function examples2() { - string storage message = - i % 3 == 0 && i % 5 == 0 ? "fizzbuzz" - : i % 3 == 0 ? "fizz" - : i % 5 == 0 ? "buzz" - : String(i); + string storage message = i % 3 == 0 && i % 5 == 0 + ? "fizzbuzz" + : i % 3 == 0 + ? "fizz" + : i % 5 == 0 + ? "buzz" + : String(i); - string storage paymentMessageShort = - state == "success" ? "Payment completed successfully" - : state == "processing" ? "Payment processing" - : state == "invalid_cvc" ? "There was an issue with your CVC number" - : state == "invalid_expiry" ? "Expiry must be sometime in the past." - : "There was an issue with the payment. Please contact support."; + string storage paymentMessageShort = state == "success" + ? "Payment completed successfully" + : state == "processing" + ? "Payment processing" + : state == "invalid_cvc" + ? "There was an issue with your CVC number" + : state == "invalid_expiry" + ? "Expiry must be sometime in the past." + : "There was an issue with the payment. Please contact support."; - string storage paymentMessageWithABreak = - state == "success" ? "Payment completed successfully" - : state == "processing" ? "Payment processing" - : state == "invalid_cvc" ? - "There was an issue with your CVC number, and you need to take a prompt action on it." - : state == "invalid_expiry" ? "Expiry must be sometime in the past." - : "There was an issue with the payment. Please contact support."; + string storage paymentMessageWithABreak = state == "success" + ? "Payment completed successfully" + : state == "processing" + ? "Payment processing" + : state == "invalid_cvc" + ? "There was an issue with your CVC number, and you need to take a prompt action on it." + : state == "invalid_expiry" + ? "Expiry must be sometime in the past." + : "There was an issue with the payment. Please contact support."; - string storage typeofExample = - definition.encode ? - definition.encode( - row[field] != "undefined" ? row[field] - : definition.defaults != "undefined" ? definition.defaults - : "null" - ) - : row[field] != "undefined" ? row[field] - : definition.defaults != "undefined" ? definition.defaults - : "null"; + string storage typeofExample = definition.encode + ? definition.encode( + row[field] != "undefined" + ? row[field] + : definition.defaults != "undefined" + ? definition.defaults + : "null" + ) + : row[field] != "undefined" + ? row[field] + : definition.defaults != "undefined" + ? definition.defaults + : "null"; // (the following is semantically equivalent to the above, but written in a more-confusing style – it'd be hard to grok no matter the formatting) - string storage typeofExampleFlipped = - definition.encode ? - definition.encode( - row[field] == "undefined" ? - definition.defaults == "undefined" ? - "null" - : definition.defaults - : row[field] - ) - : row[field] == "undefined" ? - definition.defaults == "undefined" ? - "null" - : definition.defaults - : row[field]; + string storage typeofExampleFlipped = definition.encode + ? definition.encode( + row[field] == "undefined" + ? definition.defaults == "undefined" + ? "null" + : definition.defaults + : row[field] + ) + : row[field] == "undefined" + ? definition.defaults == "undefined" + ? "null" + : definition.defaults + : row[field]; } } ================================================================================ `; -exports[`ExperimentalTernaries.sol format 1`] = ` +exports[`ExperimentalTernaries.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["solidity-slang-parse"] printWidth: 80 | printWidth =====================================input====================================== @@ -1795,10 +3681,8 @@ string storage typeofExampleFlipped = =====================================output===================================== pragma solidity ^0.4.24; - contract Conditional { function blogPostExample() { - // "curious" ternaries string storage animalName = pet.canBark() ? pet.isScary() ? "wolf" @@ -1806,8 +3690,6 @@ contract Conditional { : pet.canMeow() ? "cat" : "probably a bunny"; - - // "case-style" ternaries string storage animalName = pet.isScary() ? "wolf" : pet.canBark() @@ -1815,8 +3697,6 @@ contract Conditional { : pet.canMeow() ? "cat" : "probably a bunny"; - - // fluidity between "case-style" and "curious" ternaries string storage animalName = pet.canSqueak() ? "mouse" : pet.canBark() @@ -1829,42 +3709,27 @@ contract Conditional { ? "mouse" : "probably a bunny"; } - function examples1() { - // remain on one line if possible: string storage short = isLoud() ? makeNoise() : silent(); - - // next, put everything after the = string storage lessShort = isLoudReallyLoud() ? makeNoiseReallyLoudly.omgSoLoud() : silent(); - - // next, indent the consequent: string storage andIndented = isLoudReallyReallyReallyReallyLoud() ? makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() : silent(); - - // if we need to add spaces to the falseExpression to fill a tab, we indent it as well: - string - storage indentationInFalseExpression = isLoudReallyReallyReallyReallyLoud() - ? makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); - - // unless the consequent is short (less than ten characters long): + string storage indentationInFalseExpression = isLoudReallyReallyReallyReallyLoud() + ? makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); string storage shortSoCase = isLoudReallyReallyReallyReallyLoud() ? silent() : (makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud()); - - // if chained, always break and put after the = string storage chainedShort = isCat() ? meow() : isDog() ? bark() : silent(); - - // when a consequent breaks in a chain: string storage chainedWithLongConsequent = isCat() ? someReallyLargeExpression .thatWouldCauseALineBreak() @@ -1872,8 +3737,6 @@ contract Conditional { : isDog() ? bark() : silent(); - - // nested ternary in consequent always breaks: string storage chainedWithTernaryConsequent = isCat() ? aNestedCondition ? theResult() @@ -1881,8 +3744,6 @@ contract Conditional { : isDog() ? bark() : silent(); - - // consequent and terminal alternate break: string storage consequentAndTerminalAlternateBreak = isCat() ? someReallyLargeExpression .thatWouldCauseALineBreak() @@ -1892,78 +3753,79 @@ contract Conditional { : someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens(); - - // multiline conditions and consequents/alternates: - string - storage multilineConditionsConsequentsAndAlternates = (isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition)) - ? someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : (isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition)) - ? bark() - : shortCondition() - ? shortConsequent() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); - - // Assignment also groups and indents as Variable Declaration: - assignment = (isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition)) + string storage multilineConditionsConsequentsAndAlternates = ( + isAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens() - : (isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition)) + : ( + isNotAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) + ? bark() + : shortCondition() + ? shortConsequent() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); + assignment = ( + isAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) + ? someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : ( + isNotAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? bark() : shortCondition() ? shortConsequent() : someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens(); - - // illustrating case of mostly short conditionals string storage mostlyShort = x == 1 ? "one" : x == 2 ? "two" : x == 3 ? "three" - : (x == 5 && - y == 7 && - someOtherThing - .thatIsSoLong - .thatItBreaksTheTestCondition()) + : ( + x == 5 && + y == 7 && + someOtherThing + .thatIsSoLong + .thatItBreaksTheTestCondition() + ) ? "four" : x == 6 ? "six" : "idk"; - - // long conditional, short consequent/alternate, not chained - do indent after ? - string storage longConditional = (bifornCringerMoshedPerplexSawder == - 2 / askTrovenaBeenaDependsRowans && - glimseGlyphsHazardNoopsTieTie >= - averredBathersBoxroomBuggyNurl() - .anodyneCondosMalateOverateRetinol()) + string storage longConditional = ( + bifornCringerMoshedPerplexSawder == + 2 / + askTrovenaBeenaDependsRowans && + glimseGlyphsHazardNoopsTieTie >= + averredBathersBoxroomBuggyNurl() + .anodyneCondosMalateOverateRetinol() + ) ? "foo" : "bar"; - - // long conditional, short consequent/alternate, chained - // (break on short consequents iff in chained ternary and its conditional broke) - string - storage longConditionalChained = (bifornCringerMoshedPerplexSawder == - 2 / askTrovenaBeenaDependsRowans && + string storage longConditionalChained = ( + bifornCringerMoshedPerplexSawder == + 2 / + askTrovenaBeenaDependsRowans && glimseGlyphsHazardNoopsTieTie >= averredBathersBoxroomBuggyNurl() - .anodyneCondosMalateOverateRetinol()) - ? "foo" - : anotherCondition - ? "bar" - : "baz"; - - // As a function parameter, don't add an extra indent: + .anodyneCondosMalateOverateRetinol() + ) + ? "foo" + : anotherCondition + ? "bar" + : "baz"; definition.encode( row[field] != "undefined" ? row[field] @@ -1976,8 +3838,6 @@ contract Conditional { : definition.defaults : row[field] ); - - // Conditional as a condition (((foo ? 1 : bar))) ? 3 : 4; ( isCat() @@ -1988,17 +3848,13 @@ contract Conditional { ) ? 1 : 2; - - // In a return, break and over-indent: if (short) { return foo ? 1 : 2; } - return - row[aVeryLongFieldName] != "undefined" - ? row[aVeryLongFieldName] - : "null"; + return row[aVeryLongFieldName] != "undefined" + ? row[aVeryLongFieldName] + : "null"; } - function examples2() { string storage message = i % 3 == 0 && i % 5 == 0 ? "fizzbuzz" @@ -2007,7 +3863,6 @@ contract Conditional { : i % 5 == 0 ? "buzz" : String(i); - string storage paymentMessageShort = state == "success" ? "Payment completed successfully" : state == "processing" @@ -2017,7 +3872,6 @@ contract Conditional { : state == "invalid_expiry" ? "Expiry must be sometime in the past." : "There was an issue with the payment. Please contact support."; - string storage paymentMessageWithABreak = state == "success" ? "Payment completed successfully" : state == "processing" @@ -2027,7 +3881,6 @@ contract Conditional { : state == "invalid_expiry" ? "Expiry must be sometime in the past." : "There was an issue with the payment. Please contact support."; - string storage typeofExample = definition.encode ? definition.encode( row[field] != "undefined" @@ -2041,8 +3894,6 @@ contract Conditional { : definition.defaults != "undefined" ? definition.defaults : "null"; - - // (the following is semantically equivalent to the above, but written in a more-confusing style – it'd be hard to grok no matter the formatting) string storage typeofExampleFlipped = definition.encode ? definition.encode( row[field] == "undefined" diff --git a/tests/format/ExperimentalTernaries/jsfmt.spec.js b/tests/format/ExperimentalTernaries/jsfmt.spec.js index c79991703..bd91f1554 100644 --- a/tests/format/ExperimentalTernaries/jsfmt.spec.js +++ b/tests/format/ExperimentalTernaries/jsfmt.spec.js @@ -8,3 +8,16 @@ run_spec(import.meta, ['solidity-parse'], { experimentalTernaries: true, useTabs: true }); + +run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['solidity-slang-parse'], { + experimentalTernaries: true +}); +run_spec(import.meta, ['solidity-slang-parse'], { + experimentalTernaries: true, + tabWidth: 1 +}); +run_spec(import.meta, ['solidity-slang-parse'], { + experimentalTernaries: true, + useTabs: true +}); diff --git a/tests/format/FunctionDefinitions/FunctionDefinitions.sol b/tests/format/FunctionDefinitions/FunctionDefinitions.sol index 55a2bf294..ecb37758d 100644 --- a/tests/format/FunctionDefinitions/FunctionDefinitions.sol +++ b/tests/format/FunctionDefinitions/FunctionDefinitions.sol @@ -27,7 +27,7 @@ interface FunctionInterfaces { function modifierOrderIncorrect04() override modifier1 payable external modifier2 returns(uint); } -interface FunctionInterfaces { +abstract contract FunctionInterfaces { function functionDefinition0(); function functionDefinition1(); function functionDefinition2(); @@ -42,11 +42,14 @@ interface FunctionInterfaces { } contract FunctionDefinitions { - function () external {} fallback () external {} - function () external payable {} fallback () external payable {} + fallback() external payable virtual {} + fallback(bytes calldata _input) external {} + receive () external payable {} + receive() external payable virtual {} + function noParamsNoModifiersNoReturns() { a = 1; } @@ -125,7 +128,4 @@ contract FunctionDefinitions { function modifierOrderIncorrect04() override modifier1 payable external modifier2 returns(uint) { a = 1; } - fallback() external payable virtual {} - fallback(bytes calldata _input) external {} - receive() external payable virtual {} } diff --git a/tests/format/FunctionDefinitions/__snapshots__/jsfmt.spec.js.snap b/tests/format/FunctionDefinitions/__snapshots__/jsfmt.spec.js.snap index 7dcdd2002..52849795e 100644 --- a/tests/format/FunctionDefinitions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/FunctionDefinitions/__snapshots__/jsfmt.spec.js.snap @@ -35,7 +35,7 @@ interface FunctionInterfaces { function modifierOrderIncorrect04() override modifier1 payable external modifier2 returns(uint); } -interface FunctionInterfaces { +abstract contract FunctionInterfaces { function functionDefinition0(); function functionDefinition1(); function functionDefinition2(); @@ -50,11 +50,14 @@ interface FunctionInterfaces { } contract FunctionDefinitions { - function () external {} fallback () external {} - function () external payable {} fallback () external payable {} + fallback() external payable virtual {} + fallback(bytes calldata _input) external {} + receive () external payable {} + receive() external payable virtual {} + function noParamsNoModifiersNoReturns() { a = 1; } @@ -133,9 +136,6 @@ contract FunctionDefinitions { function modifierOrderIncorrect04() override modifier1 payable external modifier2 returns(uint) { a = 1; } - fallback() external payable virtual {} - fallback(bytes calldata _input) external {} - receive() external payable virtual {} } =====================================output===================================== @@ -396,7 +396,7 @@ interface FunctionInterfaces { returns (uint); } -interface FunctionInterfaces { +abstract contract FunctionInterfaces { function functionDefinition0(); function functionDefinition1(); function functionDefinition2(); @@ -411,11 +411,14 @@ interface FunctionInterfaces { } contract FunctionDefinitions { - function() external {} fallback() external {} - function() external payable {} fallback() external payable {} + fallback() external payable virtual {} + fallback(bytes calldata _input) external {} + receive() external payable {} + receive() external payable virtual {} + function noParamsNoModifiersNoReturns() { a = 1; } @@ -739,9 +742,788 @@ contract FunctionDefinitions { { a = 1; } - fallback() external payable virtual {} - fallback(bytes calldata _input) external {} - receive() external payable virtual {} +} + +================================================================================ +`; + +exports[`FunctionDefinitions.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +interface FunctionInterfaces { + function noParamsNoModifiersNoReturns(); + function oneParam(uint x); + function oneModifier() modifier1; + function oneReturn() returns(uint y1); + function manyParams(uint x1, uint x2, uint x3, uint x4, uint x5, uint x6, uint x7, uint x8, uint x9, uint x10); + function manyModifiers() modifier1() modifier2() modifier3 modifier4 modifier5 modifier6 modifier7 modifier8 modifier9 modifier10; + function manyReturns() returns(uint y1, uint y2, uint y3, uint y4, uint y5, uint y6, uint y7, uint y8, uint y9, uint y10); + function someParamsSomeModifiers(uint x1, uint x2, uint x3) modifier1() modifier2 modifier3; + function someParamsSomeReturns(uint x1, uint x2, uint x3) returns(uint y1, uint y2, uint y3); + function someModifiersSomeReturns() modifier1 modifier2 modifier3 returns(uint y1, uint y2, uint y3); + function someParamSomeModifiersSomeReturns(uint x1, uint x2, uint x3) modifier1 modifier2 modifier3 returns(uint y1, uint y2, uint y3); + function someParamsManyModifiers(uint x1, uint x2, uint x3) modifier1 modifier2 modifier3 modifier4 modifier5 modifier6 modifier7 modifier8 modifier9 modifier10; + function someParamsManyReturns(uint x1, uint x2, uint x3) returns(uint y1, uint y2, uint y3, uint y4, uint y5, uint y6, uint y7, uint y8, uint y9, uint y10); + function manyParamsSomeModifiers(uint x1, uint x2, uint x3, uint x4, uint x5, uint x6, uint x7, uint x8, uint x9, uint x10) modifier1 modifier2 modifier3; + function manyParamsSomeReturns(uint x1, uint x2, uint x3, uint x4, uint x5, uint x6, uint x7, uint x8, uint x9, uint x10) returns(uint y1, uint y2, uint y3); + function manyParamsManyModifiers(uint x1, uint x2, uint x3, uint x4, uint x5, uint x6, uint x7, uint x8, uint x9, uint x10) modifier1 modifier2 modifier3 modifier4 modifier5 modifier6 modifier7 modifier8 modifier9 modifier10; + function manyParamsManyReturns(uint x1, uint x2, uint x3, uint x4, uint x5, uint x6, uint x7, uint x8, uint x9, uint x10) returns(uint y1, uint y2, uint y3, uint y4, uint y5, uint y6, uint y7, uint y8, uint y9, uint y10); + function manyParamsManyModifiersManyReturns(uint x1, uint x2, uint x3, uint x4, uint x5, uint x6, uint x7, uint x8, uint x9, uint x10) modifier1 modifier2 modifier3 modifier4 modifier5 modifier6 modifier7 modifier8 modifier9 modifier10 returns(uint y1, uint y2, uint y3, uint y4, uint y5, uint y6, uint y7, uint y8, uint y9, uint y10); + function modifierOrderCorrect01() public view virtual override modifier1 modifier2 returns(uint); + function modifierOrderCorrect02() private pure virtual modifier1 modifier2 returns(string); + function modifierOrderCorrect03() external payable override modifier1 modifier2 returns(address); + function modifierOrderCorrect04() internal virtual override modifier1 modifier2 returns(uint); + function modifierOrderIncorrect01() public modifier1 modifier2 override virtual view returns(uint); + function modifierOrderIncorrect02() virtual modifier1 external modifier2 override returns(uint); + function modifierOrderIncorrect03() modifier1 pure internal virtual modifier2 returns(uint); + function modifierOrderIncorrect04() override modifier1 payable external modifier2 returns(uint); +} + +abstract contract FunctionInterfaces { + function functionDefinition0(); + function functionDefinition1(); + function functionDefinition2(); + // Leading Comment + function functionDefinition3(); + function functionDefinition4(); + function functionDefinition5() public {} + function functionDefinition6(); + function functionDefinition7(); // Tailing Comment + function functionDefinition8(); + function functionDefinition9(); +} + +contract FunctionDefinitions { + fallback () external {} + fallback () external payable {} + fallback() external payable virtual {} + fallback(bytes calldata _input) external {} + + receive () external payable {} + receive() external payable virtual {} + + function noParamsNoModifiersNoReturns() { + a = 1; + } + function oneParam(uint x) { + a = 1; + } + function oneModifier() modifier1 { + a = 1; + } + function oneReturn() returns(uint y1) { + a = 1; + } + function manyParams(uint x1, uint x2, uint x3, uint x4, uint x5, uint x6, uint x7, uint x8, uint x9, uint x10) { + a = 1; + } + function manyModifiers() modifier1 modifier2 modifier3 modifier4 modifier5 modifier6 modifier7 modifier8 modifier9 modifier10 { + a = 1; + } + function manyReturns() returns(uint y1, uint y2, uint y3, uint y4, uint y5, uint y6, uint y7, uint y8, uint y9, uint y10) { + a = 1; + } + function someParamsSomeModifiers(uint x1, uint x2, uint x3) modifier1 modifier2 modifier3 { + a = 1; + } + function someParamsSomeReturns(uint x1, uint x2, uint x3) returns(uint y1, uint y2, uint y3) { + a = 1; + } + function someModifiersSomeReturns() modifier1 modifier2 modifier3 returns(uint y1, uint y2, uint y3) { + a = 1; + } + function someParamSomeModifiersSomeReturns(uint x1, uint x2, uint x3) modifier1 modifier2 modifier3 returns(uint y1, uint y2, uint y3) { + a = 1; + } + function someParamsManyModifiers(uint x1, uint x2, uint x3) modifier1 modifier2 modifier3 modifier4 modifier5 modifier6 modifier7 modifier8 modifier9 modifier10 { + a = 1; + } + function someParamsManyReturns(uint x1, uint x2, uint x3) returns(uint y1, uint y2, uint y3, uint y4, uint y5, uint y6, uint y7, uint y8, uint y9, uint y10) { + a = 1; + } + function manyParamsSomeModifiers(uint x1, uint x2, uint x3, uint x4, uint x5, uint x6, uint x7, uint x8, uint x9, uint x10) modifier1 modifier2 modifier3 { + a = 1; + } + function manyParamsSomeReturns(uint x1, uint x2, uint x3, uint x4, uint x5, uint x6, uint x7, uint x8, uint x9, uint x10) returns(uint y1, uint y2, uint y3) { + a = 1; + } + function manyParamsManyModifiers(uint x1, uint x2, uint x3, uint x4, uint x5, uint x6, uint x7, uint x8, uint x9, uint x10) modifier1 modifier2 modifier3 modifier4 modifier5 modifier6 modifier7 modifier8 modifier9 modifier10 public { + a = 1; + } + function manyParamsManyReturns(uint x1, uint x2, uint x3, uint x4, uint x5, uint x6, uint x7, uint x8, uint x9, uint x10) returns(uint y1, uint y2, uint y3, uint y4, uint y5, uint y6, uint y7, uint y8, uint y9, uint y10) { + a = 1; + } + function manyParamsManyModifiersManyReturns(uint x1, uint x2, uint x3, uint x4, uint x5, uint x6, uint x7, uint x8, uint x9, uint x10) modifier1 modifier2 modifier3 modifier4 modifier5 modifier6 modifier7 modifier8 modifier9 modifier10 returns(uint y1, uint y2, uint y3, uint y4, uint y5, uint y6, uint y7, uint y8, uint y9, uint y10) { + a = 1; + } + function modifierOrderCorrect01() public view virtual override modifier1 modifier2 returns(uint) { + a = 1; + } + function modifierOrderCorrect02() private pure virtual modifier1 modifier2 returns(string) { + a = 1; + } + function modifierOrderCorrect03() external payable override modifier1 modifier2 returns(address) { + a = 1; + } + function modifierOrderCorrect04() internal virtual override modifier1 modifier2 returns(uint) { + a = 1; + } + function modifierOrderIncorrect01() public modifier1 modifier2 override virtual view returns(uint) { + a = 1; + } + function modifierOrderIncorrect02() virtual modifier1 external modifier2 override returns(uint) { + a = 1; + } + function modifierOrderIncorrect03() modifier1 pure internal virtual modifier2 returns(uint) { + a = 1; + } + function modifierOrderIncorrect04() override modifier1 payable external modifier2 returns(uint) { + a = 1; + } +} + +=====================================output===================================== +interface FunctionInterfaces { + function noParamsNoModifiersNoReturns(); + function oneParam(uint x); + function oneModifier() modifier1; + function oneReturn() returns (uint y1); + function manyParams( + uint x1, + uint x2, + uint x3, + uint x4, + uint x5, + uint x6, + uint x7, + uint x8, + uint x9, + uint x10 + ); + function manyModifiers() + modifier1() + modifier2() + modifier3 + modifier4 + modifier5 + modifier6 + modifier7 + modifier8 + modifier9 + modifier10; + function manyReturns() + returns ( + uint y1, + uint y2, + uint y3, + uint y4, + uint y5, + uint y6, + uint y7, + uint y8, + uint y9, + uint y10 + ); + function someParamsSomeModifiers( + uint x1, + uint x2, + uint x3 + ) modifier1() modifier2 modifier3; + function someParamsSomeReturns( + uint x1, + uint x2, + uint x3 + ) returns (uint y1, uint y2, uint y3); + function someModifiersSomeReturns() + modifier1 + modifier2 + modifier3 + returns ( + uint y1, + uint y2, + uint y3 + ); + function someParamSomeModifiersSomeReturns( + uint x1, + uint x2, + uint x3 + ) modifier1 modifier2 modifier3 returns (uint y1, uint y2, uint y3); + function someParamsManyModifiers( + uint x1, + uint x2, + uint x3 + ) + modifier1 + modifier2 + modifier3 + modifier4 + modifier5 + modifier6 + modifier7 + modifier8 + modifier9 + modifier10; + function someParamsManyReturns( + uint x1, + uint x2, + uint x3 + ) + returns ( + uint y1, + uint y2, + uint y3, + uint y4, + uint y5, + uint y6, + uint y7, + uint y8, + uint y9, + uint y10 + ); + function manyParamsSomeModifiers( + uint x1, + uint x2, + uint x3, + uint x4, + uint x5, + uint x6, + uint x7, + uint x8, + uint x9, + uint x10 + ) modifier1 modifier2 modifier3; + function manyParamsSomeReturns( + uint x1, + uint x2, + uint x3, + uint x4, + uint x5, + uint x6, + uint x7, + uint x8, + uint x9, + uint x10 + ) returns (uint y1, uint y2, uint y3); + function manyParamsManyModifiers( + uint x1, + uint x2, + uint x3, + uint x4, + uint x5, + uint x6, + uint x7, + uint x8, + uint x9, + uint x10 + ) + modifier1 + modifier2 + modifier3 + modifier4 + modifier5 + modifier6 + modifier7 + modifier8 + modifier9 + modifier10; + function manyParamsManyReturns( + uint x1, + uint x2, + uint x3, + uint x4, + uint x5, + uint x6, + uint x7, + uint x8, + uint x9, + uint x10 + ) + returns ( + uint y1, + uint y2, + uint y3, + uint y4, + uint y5, + uint y6, + uint y7, + uint y8, + uint y9, + uint y10 + ); + function manyParamsManyModifiersManyReturns( + uint x1, + uint x2, + uint x3, + uint x4, + uint x5, + uint x6, + uint x7, + uint x8, + uint x9, + uint x10 + ) + modifier1 + modifier2 + modifier3 + modifier4 + modifier5 + modifier6 + modifier7 + modifier8 + modifier9 + modifier10 + returns ( + uint y1, + uint y2, + uint y3, + uint y4, + uint y5, + uint y6, + uint y7, + uint y8, + uint y9, + uint y10 + ); + function modifierOrderCorrect01() + public + view + virtual + override + modifier1 + modifier2 + returns ( + uint + ); + function modifierOrderCorrect02() + private + pure + virtual + modifier1 + modifier2 + returns ( + string + ); + function modifierOrderCorrect03() + external + payable + override + modifier1 + modifier2 + returns ( + address + ); + function modifierOrderCorrect04() + internal + virtual + override + modifier1 + modifier2 + returns ( + uint + ); + function modifierOrderIncorrect01() + public + modifier1 + modifier2 + override + virtual + view + returns ( + uint + ); + function modifierOrderIncorrect02() + virtual + modifier1 + external + modifier2 + override + returns ( + uint + ); + function modifierOrderIncorrect03() + modifier1 + pure + internal + virtual + modifier2 + returns ( + uint + ); + function modifierOrderIncorrect04() + override + modifier1 + payable + external + modifier2 + returns ( + uint + ); +} +abstract contract FunctionInterfaces { + function functionDefinition0(); + function functionDefinition1(); + function functionDefinition2(); + function functionDefinition3(); + function functionDefinition4(); + function functionDefinition5() public {} + function functionDefinition6(); + function functionDefinition7(); + function functionDefinition8(); + function functionDefinition9(); +} +contract FunctionDefinitions { + fallback() external {} + fallback() external payable {} + fallback() external payable virtual {} + fallback(bytes calldata _input) external {} + receive() external payable {} + receive() external payable virtual {} + function noParamsNoModifiersNoReturns() { + a = 1; + } + function oneParam(uint x) { + a = 1; + } + function oneModifier() modifier1 { + a = 1; + } + function oneReturn() returns (uint y1) { + a = 1; + } + function manyParams( + uint x1, + uint x2, + uint x3, + uint x4, + uint x5, + uint x6, + uint x7, + uint x8, + uint x9, + uint x10 + ) { + a = 1; + } + function manyModifiers() + modifier1 + modifier2 + modifier3 + modifier4 + modifier5 + modifier6 + modifier7 + modifier8 + modifier9 + modifier10 + { + a = 1; + } + function manyReturns() + returns ( + uint y1, + uint y2, + uint y3, + uint y4, + uint y5, + uint y6, + uint y7, + uint y8, + uint y9, + uint y10 + ) + { + a = 1; + } + function someParamsSomeModifiers( + uint x1, + uint x2, + uint x3 + ) modifier1 modifier2 modifier3 { + a = 1; + } + function someParamsSomeReturns( + uint x1, + uint x2, + uint x3 + ) returns (uint y1, uint y2, uint y3) { + a = 1; + } + function someModifiersSomeReturns() + modifier1 + modifier2 + modifier3 + returns ( + uint y1, + uint y2, + uint y3 + ) + { + a = 1; + } + function someParamSomeModifiersSomeReturns( + uint x1, + uint x2, + uint x3 + ) modifier1 modifier2 modifier3 returns (uint y1, uint y2, uint y3) { + a = 1; + } + function someParamsManyModifiers( + uint x1, + uint x2, + uint x3 + ) + modifier1 + modifier2 + modifier3 + modifier4 + modifier5 + modifier6 + modifier7 + modifier8 + modifier9 + modifier10 + { + a = 1; + } + function someParamsManyReturns( + uint x1, + uint x2, + uint x3 + ) + returns ( + uint y1, + uint y2, + uint y3, + uint y4, + uint y5, + uint y6, + uint y7, + uint y8, + uint y9, + uint y10 + ) + { + a = 1; + } + function manyParamsSomeModifiers( + uint x1, + uint x2, + uint x3, + uint x4, + uint x5, + uint x6, + uint x7, + uint x8, + uint x9, + uint x10 + ) modifier1 modifier2 modifier3 { + a = 1; + } + function manyParamsSomeReturns( + uint x1, + uint x2, + uint x3, + uint x4, + uint x5, + uint x6, + uint x7, + uint x8, + uint x9, + uint x10 + ) returns (uint y1, uint y2, uint y3) { + a = 1; + } + function manyParamsManyModifiers( + uint x1, + uint x2, + uint x3, + uint x4, + uint x5, + uint x6, + uint x7, + uint x8, + uint x9, + uint x10 + ) + modifier1 + modifier2 + modifier3 + modifier4 + modifier5 + modifier6 + modifier7 + modifier8 + modifier9 + modifier10 + public + { + a = 1; + } + function manyParamsManyReturns( + uint x1, + uint x2, + uint x3, + uint x4, + uint x5, + uint x6, + uint x7, + uint x8, + uint x9, + uint x10 + ) + returns ( + uint y1, + uint y2, + uint y3, + uint y4, + uint y5, + uint y6, + uint y7, + uint y8, + uint y9, + uint y10 + ) + { + a = 1; + } + function manyParamsManyModifiersManyReturns( + uint x1, + uint x2, + uint x3, + uint x4, + uint x5, + uint x6, + uint x7, + uint x8, + uint x9, + uint x10 + ) + modifier1 + modifier2 + modifier3 + modifier4 + modifier5 + modifier6 + modifier7 + modifier8 + modifier9 + modifier10 + returns ( + uint y1, + uint y2, + uint y3, + uint y4, + uint y5, + uint y6, + uint y7, + uint y8, + uint y9, + uint y10 + ) + { + a = 1; + } + function modifierOrderCorrect01() + public + view + virtual + override + modifier1 + modifier2 + returns ( + uint + ) + { + a = 1; + } + function modifierOrderCorrect02() + private + pure + virtual + modifier1 + modifier2 + returns ( + string + ) + { + a = 1; + } + function modifierOrderCorrect03() + external + payable + override + modifier1 + modifier2 + returns ( + address + ) + { + a = 1; + } + function modifierOrderCorrect04() + internal + virtual + override + modifier1 + modifier2 + returns ( + uint + ) + { + a = 1; + } + function modifierOrderIncorrect01() + public + modifier1 + modifier2 + override + virtual + view + returns ( + uint + ) + { + a = 1; + } + function modifierOrderIncorrect02() + virtual + modifier1 + external + modifier2 + override + returns ( + uint + ) + { + a = 1; + } + function modifierOrderIncorrect03() + modifier1 + pure + internal + virtual + modifier2 + returns ( + uint + ) + { + a = 1; + } + function modifierOrderIncorrect04() + override + modifier1 + payable + external + modifier2 + returns ( + uint + ) + { + a = 1; + } } ================================================================================ diff --git a/tests/format/FunctionDefinitions/jsfmt.spec.js b/tests/format/FunctionDefinitions/jsfmt.spec.js index 765dd60a6..fd56c17bc 100644 --- a/tests/format/FunctionDefinitions/jsfmt.spec.js +++ b/tests/format/FunctionDefinitions/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse']); diff --git a/tests/format/FunctionDefinitionsv0.5.0/DefaultFunctionDefinitions.sol b/tests/format/FunctionDefinitionsv0.5.0/DefaultFunctionDefinitions.sol new file mode 100644 index 000000000..d2d34a07e --- /dev/null +++ b/tests/format/FunctionDefinitionsv0.5.0/DefaultFunctionDefinitions.sol @@ -0,0 +1,4 @@ +contract FunctionDefinitions { + function () external {} + function () external payable {} +} diff --git a/tests/format/FunctionDefinitionsv0.5.0/__snapshots__/jsfmt.spec.js.snap b/tests/format/FunctionDefinitionsv0.5.0/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000..d430c10b2 --- /dev/null +++ b/tests/format/FunctionDefinitionsv0.5.0/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,42 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`DefaultFunctionDefinitions.sol - {"compiler":"0.5.0"} format 1`] = ` +====================================options===================================== +compiler: "0.5.0" +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +contract FunctionDefinitions { + function () external {} + function () external payable {} +} + +=====================================output===================================== +contract FunctionDefinitions { + function() external {} + function() external payable {} +} + +================================================================================ +`; + +exports[`DefaultFunctionDefinitions.sol format 1`] = ` +====================================options===================================== +parsers: ["solidity-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +contract FunctionDefinitions { + function () external {} + function () external payable {} +} + +=====================================output===================================== +contract FunctionDefinitions { + function() external {} + function() external payable {} +} + +================================================================================ +`; diff --git a/tests/format/FunctionDefinitionsv0.5.0/jsfmt.spec.js b/tests/format/FunctionDefinitionsv0.5.0/jsfmt.spec.js new file mode 100644 index 000000000..4205ec3cb --- /dev/null +++ b/tests/format/FunctionDefinitionsv0.5.0/jsfmt.spec.js @@ -0,0 +1,2 @@ +run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse'], {compiler: '0.5.0'}); diff --git a/tests/format/HexLiteral/__snapshots__/jsfmt.spec.js.snap b/tests/format/HexLiteral/__snapshots__/jsfmt.spec.js.snap index a140eafcf..527cd97d7 100644 --- a/tests/format/HexLiteral/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/HexLiteral/__snapshots__/jsfmt.spec.js.snap @@ -1,9 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`HexLiteral.sol - {"compiler":"0.8.6","singleQuote":false} format 1`] = ` +exports[`HexLiteral.sol - {"compiler":"0.8.25","singleQuote":false} format 1`] = ` ====================================options===================================== -compiler: "0.8.6" -parsers: ["solidity-parse"] +compiler: "0.8.25" +parsers: ["solidity-slang-parse"] printWidth: 80 singleQuote: false | printWidth @@ -17,9 +17,7 @@ contract HexLiteral { } =====================================output===================================== -// SPDX-License-Identifier: MIT pragma solidity 0.8.25; - contract HexLiteral { bytes8 hex1 = hex"DeadBeef"; bytes8 hex2 = hex"DeadBeef"; @@ -28,10 +26,10 @@ contract HexLiteral { ================================================================================ `; -exports[`HexLiteral.sol - {"compiler":"0.8.6","singleQuote":true} format 1`] = ` +exports[`HexLiteral.sol - {"compiler":"0.8.25","singleQuote":true} format 1`] = ` ====================================options===================================== -compiler: "0.8.6" -parsers: ["solidity-parse"] +compiler: "0.8.25" +parsers: ["solidity-slang-parse"] printWidth: 80 singleQuote: true | printWidth @@ -45,9 +43,7 @@ contract HexLiteral { } =====================================output===================================== -// SPDX-License-Identifier: MIT pragma solidity 0.8.25; - contract HexLiteral { bytes8 hex1 = hex'DeadBeef'; bytes8 hex2 = hex'DeadBeef'; @@ -56,10 +52,9 @@ contract HexLiteral { ================================================================================ `; -exports[`HexLiteral.sol - {"compiler":"0.8.25","singleQuote":false} format 1`] = ` +exports[`HexLiteral.sol - {"singleQuote":false} format 1`] = ` ====================================options===================================== -compiler: "0.8.25" -parsers: ["solidity-slang-parse"] +parsers: ["solidity-parse"] printWidth: 80 singleQuote: false | printWidth @@ -73,7 +68,9 @@ contract HexLiteral { } =====================================output===================================== +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; + contract HexLiteral { bytes8 hex1 = hex"DeadBeef"; bytes8 hex2 = hex"DeadBeef"; @@ -82,10 +79,9 @@ contract HexLiteral { ================================================================================ `; -exports[`HexLiteral.sol - {"compiler":"0.8.25","singleQuote":true} format 1`] = ` +exports[`HexLiteral.sol - {"singleQuote":true} format 1`] = ` ====================================options===================================== -compiler: "0.8.25" -parsers: ["solidity-slang-parse"] +parsers: ["solidity-parse"] printWidth: 80 singleQuote: true | printWidth @@ -99,7 +95,9 @@ contract HexLiteral { } =====================================output===================================== +// SPDX-License-Identifier: MIT pragma solidity 0.8.25; + contract HexLiteral { bytes8 hex1 = hex'DeadBeef'; bytes8 hex2 = hex'DeadBeef'; diff --git a/tests/format/HexLiteral/jsfmt.spec.js b/tests/format/HexLiteral/jsfmt.spec.js index 0913ecc8e..f2923e7bc 100644 --- a/tests/format/HexLiteral/jsfmt.spec.js +++ b/tests/format/HexLiteral/jsfmt.spec.js @@ -1,11 +1,5 @@ -run_spec(import.meta, ['solidity-parse'], { - compiler: '0.8.6', - singleQuote: true -}); -run_spec(import.meta, ['solidity-parse'], { - compiler: '0.8.6', - singleQuote: false -}); +run_spec(import.meta, ['solidity-parse'], { singleQuote: true }); +run_spec(import.meta, ['solidity-parse'], { singleQuote: false }); run_spec(import.meta, ['solidity-slang-parse'], { compiler: '0.8.25', singleQuote: true diff --git a/tests/format/Immutable/__snapshots__/jsfmt.spec.js.snap b/tests/format/Immutable/__snapshots__/jsfmt.spec.js.snap index 373e42afc..62f0e411a 100644 --- a/tests/format/Immutable/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Immutable/__snapshots__/jsfmt.spec.js.snap @@ -51,3 +51,51 @@ contract Immutable { ================================================================================ `; + +exports[`Immutable.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity >0.6.4 <0.7.0; + +contract Immutable { + uint constant X = 32**22 + 8; + string constant TEXT = "abc"; + bytes32 constant MY_HASH = keccak256("abc"); + uint immutable decimals; + uint immutable maxBalance; + address immutable owner = msg.sender; + + constructor(uint _decimals, address _reference) public { + decimals = _decimals; + // Assignments to immutables can even access the environment. + maxBalance = _reference.balance; + } + + function isBalanceTooHigh(address _other) public view returns (bool) { + return _other.balance > maxBalance; + } +} + +=====================================output===================================== +pragma solidity >0.6.4 <0.7.0; +contract Immutable { + uint constant X = 32 ** 22 + 8; + string constant TEXT = "abc"; + bytes32 constant MY_HASH = keccak256("abc"); + uint immutable decimals; + uint immutable maxBalance; + address immutable owner = msg.sender; + constructor(uint _decimals, address _reference) public { + decimals = _decimals; + maxBalance = _reference.balance; + } + function isBalanceTooHigh(address _other) public view returns (bool) { + return _other.balance > maxBalance; + } +} + +================================================================================ +`; diff --git a/tests/format/Immutable/jsfmt.spec.js b/tests/format/Immutable/jsfmt.spec.js index 765dd60a6..fd56c17bc 100644 --- a/tests/format/Immutable/jsfmt.spec.js +++ b/tests/format/Immutable/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse']); diff --git a/tests/format/Inbox/__snapshots__/jsfmt.spec.js.snap b/tests/format/Inbox/__snapshots__/jsfmt.spec.js.snap index 7ecbcae24..bd05e066a 100644 --- a/tests/format/Inbox/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Inbox/__snapshots__/jsfmt.spec.js.snap @@ -76,3 +76,60 @@ contract Inbox { ================================================================================ `; + +exports[`Inbox.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +// This comment spans one line + +/* +This +comment +spans +multiple +lines. +*/ + +pragma solidity ^0.4.23; +contract Inbox { + string public message; + + constructor(string initialMessage) public { + message = initialMessage; + } + + function setMessage(string newMessage) public { + message = newMessage; + } + + function nothingHere() public { + // to be defined + } + + function nothingHereMultipleComments() public { + // to be defined + // to be defined 2 + /* to be defined 3 */ + } +} + + +=====================================output===================================== +pragma solidity ^0.4.23; +contract Inbox { + string public message; + constructor(string initialMessage) public { + message = initialMessage; + } + function setMessage(string newMessage) public { + message = newMessage; + } + function nothingHere() public {} + function nothingHereMultipleComments() public {} +} + +================================================================================ +`; diff --git a/tests/format/Inbox/jsfmt.spec.js b/tests/format/Inbox/jsfmt.spec.js index 765dd60a6..fd56c17bc 100644 --- a/tests/format/Inbox/jsfmt.spec.js +++ b/tests/format/Inbox/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse']); diff --git a/tests/format/IndexOf/__snapshots__/jsfmt.spec.js.snap b/tests/format/IndexOf/__snapshots__/jsfmt.spec.js.snap index ed75f25aa..9b4db8f8e 100644 --- a/tests/format/IndexOf/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/IndexOf/__snapshots__/jsfmt.spec.js.snap @@ -145,3 +145,118 @@ contract IndexOf { ================================================================================ `; + +exports[`IndexOf.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +contract IndexOf { + + address creator; + + function IndexOf() + { + creator = msg.sender; + } + + int whatwastheval = -10; // -2 = not yet tested, as separate from -1, tested but error + + function indexOf(string _a, string _b) returns (int) // _a = string to search, _b = string we want to find + { + bytes memory a = bytes(_a); + bytes memory b = bytes(_b); + + if(a.length < 1 || b.length < 1 || (b.length > a.length)) + { + whatwastheval = -1; + return -1; + } + else if(a.length > (2**128 -1)) // since we have to be able to return -1 (if the char isn't found or input error), this function must return an "int" type with a max length of (2^128 - 1) + { + whatwastheval = -1; + return -1; + } + else + { + uint subindex = 0; + for (uint i = 0; i < a.length; i ++) + { + if (a[i] == b[0]) // found the first char of b + { + subindex = 1; + while(subindex < b.length && (i + subindex) < a.length && a[i + subindex] == b[subindex]) // search until the chars don't match or until we reach the end of a or b + { + subindex++; + } + if(subindex == b.length) + { + whatwastheval = int(i); + return int(i); + } + } + } + whatwastheval = -1; + return -1; + } + } + + function whatWasTheVal() constant returns (int) + { + return whatwastheval; + } + + /********** + Standard kill() function to recover funds + **********/ + + function kill() + { + if (msg.sender == creator) + { + suicide(creator); // kills this contract and sends remaining funds back to creator + } + } +} + +=====================================output===================================== +contract IndexOf { + address creator; + function IndexOf() { + creator = msg.sender; + } + int whatwastheval = -10; + function indexOf(string _a, string _b) returns (int) { + bytes memory a = bytes(_a); + bytes memory b = bytes(_b); + if (a.length < 1 || b.length < 1 || (b.length > a.length)) { + whatwastheval = -1; + return -1; + } else if (a.length > (2 ** 128 - 1)) { + whatwastheval = -1; + return -1; + } else { + uint subindex = 0; + for (uint i = 0; i < a.length; i++) { + if (a[i] == b[0]) { + subindex = 1; + while(subindex < b.length && + (i + subindex) < a.length && + a[i + subindex] == b[subindex]){ + subindex++; + } + if (subindex == b.length) { + whatwastheval = int(i); + return int(i); + } + } + } + whatwastheval = -1; + return -1; + } + } +} + +================================================================================ +`; diff --git a/tests/format/IndexOf/jsfmt.spec.js b/tests/format/IndexOf/jsfmt.spec.js index 765dd60a6..fd56c17bc 100644 --- a/tests/format/IndexOf/jsfmt.spec.js +++ b/tests/format/IndexOf/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse']); diff --git a/tests/format/Issues/__snapshots__/jsfmt.spec.js.snap b/tests/format/Issues/__snapshots__/jsfmt.spec.js.snap index 145090c30..1aebdc0d0 100644 --- a/tests/format/Issues/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Issues/__snapshots__/jsfmt.spec.js.snap @@ -38,6 +38,42 @@ contract Example { ================================================================================ `; +exports[`Issue205.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +contract Example { + using SafeMath for uint256; + + struct BalanceState { + uint256 balance; + } + + mapping(address => mapping(address => BalanceState)) private balanceStates; + function example(address token, uint amount) public { + balanceStates[msg.sender][token].balance = balanceStates[msg.sender][token].balance.sub(amount); + } +} + +=====================================output===================================== +contract Example { + using SafeMath for uint256; + struct BalanceState { + uint256 balance; + } + mapping(address => mapping(address => BalanceState)) private balanceStates; + function example(address token, uint amount) public { + balanceStates[msg.sender][token].balance = balanceStates[msg.sender][ + token + ].balance.sub(amount); + } +} + +================================================================================ +`; + exports[`Issue289.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] @@ -63,6 +99,31 @@ contract Issue289 { ================================================================================ `; +exports[`Issue289.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +contract Issue289 { + function f() { + address[] storage proposalValidators + = ethProposals[_blockNumber][_proposalId].proposalValidators; + } +} + +=====================================output===================================== +contract Issue289 { + function f() { + address[] storage proposalValidators = ethProposals[_blockNumber][ + _proposalId + ].proposalValidators; + } +} + +================================================================================ +`; + exports[`Issue355.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] @@ -99,6 +160,36 @@ contract Bug { ================================================================================ `; +exports[`Issue355.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity 0.6.12; + +contract Bug { + // This is a comment + uint public hello; + + // Another comment + uint public bigNum = 100_000; + + // This will disappear + uint public magic; +} + +=====================================output===================================== +pragma solidity 0.6.12; +contract Bug { + uint public hello; + uint public bigNum = 100_000; + uint public magic; +} + +================================================================================ +`; + exports[`Issue385.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] @@ -137,6 +228,46 @@ contract Issue385 { ================================================================================ `; +exports[`Issue385.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +contract Issue385 { + function emptyTryCatch() { + try + IService(_THIS_SERVICE).server().assign{value: msg.value}( + taskReceipt + ) + {} catch Error(string memory error) { + error.revertWithInfo("BService.delegatecall.assign:"); + } catch { + revert("BService.delegatecall.assign:undefined"); + } + } +} + +=====================================output===================================== +contract Issue385 { + function emptyTryCatch() { + try + IService(_THIS_SERVICE).server().assign{value: msg.value}( + taskReceipt + ) + {} catch Error( + string memory error + ) { + error.revertWithInfo("BService.delegatecall.assign:"); + } catch{ + revert("BService.delegatecall.assign:undefined"); + } + } +} + +================================================================================ +`; + exports[`Issue564.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] @@ -170,6 +301,38 @@ contract Issue564 { ================================================================================ `; +exports[`Issue564.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +contract Issue564 { + function isAuthorized( + bytes32 serviceId, + address client + ) external view override returns (bool) { + WhitelistStatus storage whitelistStatus = serviceIdToClientToWhitelistStatus[serviceId][client]; + return true; + } +} + +=====================================output===================================== +contract Issue564 { + function isAuthorized( + bytes32 serviceId, + address client + ) external view override returns (bool) { + WhitelistStatus storage whitelistStatus = serviceIdToClientToWhitelistStatus[ + serviceId + ][client]; + return true; + } +} + +================================================================================ +`; + exports[`Issue799.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] @@ -184,6 +347,20 @@ struct EmptyStruct {} ================================================================================ `; +exports[`Issue799.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +struct EmptyStruct {} + +=====================================output===================================== +struct EmptyStruct {} + +================================================================================ +`; + exports[`Issue843.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] @@ -211,3 +388,28 @@ contract ContractWithoutComments {} ================================================================================ `; + +exports[`Issue843.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity ^0.8.0; + +//about the contract +contract ContractWithLeadingComment { + +} + +contract ContractWithoutComments { + +} + +=====================================output===================================== +pragma solidity ^0.8.0; +contract ContractWithLeadingComment {} +contract ContractWithoutComments {} + +================================================================================ +`; diff --git a/tests/format/Issues/jsfmt.spec.js b/tests/format/Issues/jsfmt.spec.js index 765dd60a6..fd56c17bc 100644 --- a/tests/format/Issues/jsfmt.spec.js +++ b/tests/format/Issues/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse']); diff --git a/tests/format/MemberAccess/__snapshots__/jsfmt.spec.js.snap b/tests/format/MemberAccess/__snapshots__/jsfmt.spec.js.snap index ed290e0df..9be3f299d 100644 --- a/tests/format/MemberAccess/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/MemberAccess/__snapshots__/jsfmt.spec.js.snap @@ -1,5 +1,237 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`MemberAccess.sol - {"compiler":"0.5.0"} format 1`] = ` +====================================options===================================== +compiler: "0.5.0" +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity ^0.5.0; + +contract MemberAccess { + function() { + int256 amount = SafeCast.toInt256(10**(18 - underlyingAssetDecimals)).neg(); + longNameAmount = SafeCast.toInt256(10**(18 - underlyingAssetDecimals)).neg(); + a.b.c.d; + a.b().c.d; + a.b.c.d(); + a.b().c().d(); + veryLongVariable.veryLongMember.veryLongMember.veryLongMember.veryLongMember.veryLongMember; + veryLongVariable.veryLongCall(veryLongAttribute).veryLongMember.veryLongMember.veryLongMember; + veryLongVariable.veryLongMember.veryLongCall(veryLongAttribute).veryLongMember.veryLongMember; + veryLongVariable.veryLongMember.veryLongMember.veryLongMember.veryLongCall(veryLongAttribute); + veryLongVariable.veryLongCall(veryLongAttribute).veryLongCall(veryLongAttribute).veryLongCall(veryLongAttribute); + uint256[] memory amounts = IUniswapV2Router(routerAddress) + .swapExactTokensForTokens( + sourceAmount, + minDestination, + path, + address(this, aoeu, aoeueu, aoeu) + )[IUniswapV2Router(routerAddress) + .swapExactTokensForTokens( + sourceAmount, + minDestination, + path, + address(this, aoeu, aoeueu, aoeu) + )]; + uint256[] memory amounts = IUniswapV2Router(routerAddress) + .swapExactTokensForTokens( + sourceAmount, + minDestination, + path, + address(this, aoeu, aoeueu, aoeu) + )[IUniswapV2Router(routerAddress) + .swapExactTokensForTokens( + sourceAmount, + minDestination, + path, + address(this, aoeu, aoeueu, aoeu) + )][IUniswapV2Router(routerAddress) + .swapExactTokensForTokens( + sourceAmount, + minDestination, + path, + address(this, aoeu, aoeueu, aoeu) + )]; + uint256[] memory amounts = IUniswapV2Router(routerAddress) + .swapExactTokensForTokens( + sourceAmount, + minDestination, + path, + address(this, aoeu, aoeueu, aoeu) + )( + sourceAmount, + minDestination, + path, + address(this, aoeu, aoeueu, aoeu) + ); + vm.mockCall( + f.address, + abi.encodeWithSelector(f.selector), + abi.encode(returned1) + ); + } +} + +contract MemberAccessIsEndOfChainCases { + // break if is an ReturnStatement + uint a = b.c; + + function() modifierCase(b.c) { + // break if is an argument of a FunctionCall + a(b.c); + // break if is an index of an IndexAccess + a[b.c]; + // break if is a part of a BinaryOperation + a = b.c; + // break if is a part of a UnaryOperation + !b.c; + // break if is a condition of a IfStatement + if (b.c) {} + // break if is a condition of a WhileStatement + while (b.c) {} + // break if is a part of a ForStatement + // for (b.c;;) {} + for (;b.c;) {} + // for (;;b.c) {} + // break if is a part of a VariableDeclarationStatement + uint a = b.c; + // break if is an ExpressionStatement + b.c; + // break if is an TupleExpression + [a, b.c]; + (b.c); + // break if is an Conditional + a.b ? c : d; + a ? b.c : d; + a ? b : c.d; + // break if is an NameValueList + a.b{value: c.d}(); + // break if is an TryStatement + try a.b() {} catch {} + // break if is an ReturnStatement + return b.c; + } +} + +=====================================output===================================== +pragma solidity ^0.5.0; +contract MemberAccess { + function() { + int256 amount = SafeCast + .toInt256(10 ** (18 - underlyingAssetDecimals)) + .neg(); + longNameAmount = SafeCast + .toInt256(10 ** (18 - underlyingAssetDecimals)) + .neg(); + a.b.c.d; + a.b().c.d; + a.b.c.d(); + a.b().c().d(); + veryLongVariable + .veryLongMember + .veryLongMember + .veryLongMember + .veryLongMember + .veryLongMember; + veryLongVariable + .veryLongCall(veryLongAttribute) + .veryLongMember + .veryLongMember + .veryLongMember; + veryLongVariable + .veryLongMember + .veryLongCall(veryLongAttribute) + .veryLongMember + .veryLongMember; + veryLongVariable + .veryLongMember + .veryLongMember + .veryLongMember + .veryLongCall(veryLongAttribute); + veryLongVariable + .veryLongCall(veryLongAttribute) + .veryLongCall(veryLongAttribute) + .veryLongCall(veryLongAttribute); + uint256[] memory amounts = IUniswapV2Router(routerAddress) + .swapExactTokensForTokens( + sourceAmount, + minDestination, + path, + address(this, aoeu, aoeueu, aoeu) + )[ + IUniswapV2Router(routerAddress).swapExactTokensForTokens( + sourceAmount, + minDestination, + path, + address(this, aoeu, aoeueu, aoeu) + ) + ]; + uint256[] memory amounts = IUniswapV2Router(routerAddress) + .swapExactTokensForTokens( + sourceAmount, + minDestination, + path, + address(this, aoeu, aoeueu, aoeu) + )[ + IUniswapV2Router(routerAddress).swapExactTokensForTokens( + sourceAmount, + minDestination, + path, + address(this, aoeu, aoeueu, aoeu) + ) + ][ + IUniswapV2Router(routerAddress).swapExactTokensForTokens( + sourceAmount, + minDestination, + path, + address(this, aoeu, aoeueu, aoeu) + ) + ]; + uint256[] memory amounts = IUniswapV2Router(routerAddress) + .swapExactTokensForTokens( + sourceAmount, + minDestination, + path, + address(this, aoeu, aoeueu, aoeu) + )( + sourceAmount, + minDestination, + path, + address(this, aoeu, aoeueu, aoeu) + ); + vm.mockCall( + f.address, + abi.encodeWithSelector(f.selector), + abi.encode(returned1) + ); + } +} +contract MemberAccessIsEndOfChainCases { + uint a = b.c; + function() modifierCase(b.c) { + a(b.c); + a[b.c]; + a = b.c; + !b.c; + if (b.c) {} + while(b.c){} + for (; b.c; ) {} + uint a = b.c; + b.c; + [a, b.c]; + (b.c); + a.b ? c : d; + a ? b.c : d; + a ? b : c.d; + a.b; + } +} + +================================================================================ +`; + exports[`MemberAccess.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] diff --git a/tests/format/MemberAccess/jsfmt.spec.js b/tests/format/MemberAccess/jsfmt.spec.js index 765dd60a6..a6a1e4d2b 100644 --- a/tests/format/MemberAccess/jsfmt.spec.js +++ b/tests/format/MemberAccess/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse'], { compiler: '0.5.0' }); diff --git a/tests/format/Ownable/__snapshots__/jsfmt.spec.js.snap b/tests/format/Ownable/__snapshots__/jsfmt.spec.js.snap index a6a2b3930..7584533b5 100644 --- a/tests/format/Ownable/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Ownable/__snapshots__/jsfmt.spec.js.snap @@ -161,3 +161,124 @@ contract Ownable { ================================================================================ `; + +exports[`Ownable.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity ^0.4.24; + +/** + * @title Ownable + * @dev The Ownable contract has an owner address, and provides basic authorization control + * functions, this simplifies the implementation of "user permissions". + */ +contract Ownable { + address private _owner; + + event OwnershipRenounced(address indexed previousOwner); + event OwnershipTransferred( + address indexed previousOwner, + address indexed newOwner + ); + + /** + * @dev The Ownable constructor sets the original \`owner\` of the contract to the sender + * account. + */ + constructor() public { + _owner = msg.sender; + } + + /** + * @return the address of the owner. + */ + function owner() public view returns(address) { + return _owner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(isOwner()); + _; + } + + /** + * @return true if \`msg.sender\` is the owner of the contract. + */ + function isOwner() public view returns(bool) { + return msg.sender == _owner; + } + + /** + * @dev Allows the current owner to relinquish control of the contract. + * @notice Renouncing to ownership will leave the contract without an owner. + * It will not be possible to call the functions with the \`onlyOwner\` + * modifier anymore. + */ + function renounceOwnership() public onlyOwner { + emit OwnershipRenounced(_owner); + _owner = address(0); + } + + /** + * @dev Allows the current owner to transfer control of the contract to a newOwner. + * @param newOwner The address to transfer ownership to. + */ + function transferOwnership(address newOwner) public onlyOwner { + _transferOwnership(newOwner); + } + + /** + * @dev Transfers control of the contract to a newOwner. + * @param newOwner The address to transfer ownership to. + */ + function _transferOwnership(address newOwner) internal { + require(newOwner != address(0)); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } +} + +=====================================output===================================== +pragma solidity ^0.4.24; +contract Ownable { + address private _owner; + event OwnershipRenounced(address indexed previousOwner); + event OwnershipTransferred( + address indexed previousOwner, + address indexed newOwner + ); + constructor() public { + _owner = msg.sender; + } + function owner() public view returns (address) { + return _owner; + } + modifier onlyOwner() { + require(isOwner()); + _; + } + function isOwner() public view returns (bool) { + return msg.sender == _owner; + } + function renounceOwnership() public onlyOwner { + emit OwnershipRenounced(_owner); + _owner = address(0); + } + function transferOwnership(address newOwner) public onlyOwner { + _transferOwnership(newOwner); + } + function _transferOwnership(address newOwner) internal { + require(newOwner != address(0)); + emit OwnershipTransferred(_owner, newOwner); + _owner = newOwner; + } +} + +================================================================================ +`; diff --git a/tests/format/Ownable/jsfmt.spec.js b/tests/format/Ownable/jsfmt.spec.js index 765dd60a6..fd56c17bc 100644 --- a/tests/format/Ownable/jsfmt.spec.js +++ b/tests/format/Ownable/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse']); diff --git a/tests/format/Parentheses/__snapshots__/jsfmt.spec.js.snap b/tests/format/Parentheses/__snapshots__/jsfmt.spec.js.snap index 6cab7e274..9bde97ec7 100644 --- a/tests/format/Parentheses/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Parentheses/__snapshots__/jsfmt.spec.js.snap @@ -197,204 +197,192 @@ contract AddNoParentheses { ================================================================================ `; -exports[`BitAndNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` +exports[`AddNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["solidity-parse"] +parsers: ["solidity-slang-parse"] printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT pragma solidity 0.8.25; -contract BitAndNoParentheses { - function bitAndAdd(uint256 a, uint256 b, uint256 c) +contract AddNoParentheses { + function addAdd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a & b + c; + return a + b + c; } - function bitAndSub(uint256 a, uint256 b, uint256 c) + function addSub(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a & b - c; + return a + b - c; } - function bitAndMul(uint256 a, uint256 b, uint256 c) + function addMul(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a & b * c; + return a + b * c; } - function bitAndDiv(uint256 a, uint256 b, uint256 c) + function addDiv(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a & b / c; + return a + b / c; } - function bitAndMod(uint256 a, uint256 b, uint256 c) + function addMod(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a & b % c; + return a + b % c; } - function bitAndExp(uint256 a, uint256 b, uint256 c) + function addExp(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a & b ** c; + return a + b ** c; } - function bitAndShiftL(uint256 a, uint256 b, uint256 c) + function addShiftL(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a & b << c; + return a + b << c; } - function bitAndShiftR(uint256 a, uint256 b, uint256 c) + function addShiftR(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a & b >> c; + return a + b >> c; } - function bitAndBitAnd(uint256 a, uint256 b, uint256 c) + function addBitAnd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a & b & c; + return a + b & c; } - function bitAndBitOr(uint256 a, uint256 b, uint256 c) + function addBitOr(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a & b | c; + return a + b | c; } - function bitAndBitXor(uint256 a, uint256 b, uint256 c) + function addBitXor(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a & b ^ c; + return a + b ^ c; } } =====================================output===================================== -// SPDX-License-Identifier: MIT pragma solidity 0.8.25; - -contract BitAndNoParentheses { - function bitAndAdd( +contract AddNoParentheses { + function addAdd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a & (b + c); + return a + b + c; } - - function bitAndSub( + function addSub( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a & (b - c); + return a + b - c; } - - function bitAndMul( + function addMul( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a & (b * c); + return a + b * c; } - - function bitAndDiv( + function addDiv( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a & (b / c); + return a + b / c; } - - function bitAndMod( + function addMod( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a & b % c; + return a + b % c; } - - function bitAndExp( + function addExp( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a & (b ** c); + return a + b ** c; } - - function bitAndShiftL( + function addShiftL( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a & (b << c); + return a + b << c; } - - function bitAndShiftR( + function addShiftR( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a & (b >> c); + return a + b >> c; } - - function bitAndBitAnd( + function addBitAnd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a & b & c; + return a + b & c; } - - function bitAndBitOr( + function addBitOr( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a & b) | c; + return a + b | c; } - - function bitAndBitXor( + function addBitXor( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a & b) ^ c; + return a + b ^ c; } } ================================================================================ `; -exports[`BitOrNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` +exports[`BitAndNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` ====================================options===================================== compiler: "0.8.6" parsers: ["solidity-parse"] @@ -404,93 +392,93 @@ printWidth: 80 // SPDX-License-Identifier: MIT pragma solidity 0.8.25; -contract BitOrNoParentheses { - function bitOrAdd(uint256 a, uint256 b, uint256 c) +contract BitAndNoParentheses { + function bitAndAdd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a | b + c; + return a & b + c; } - function bitOrSub(uint256 a, uint256 b, uint256 c) + function bitAndSub(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a | b - c; + return a & b - c; } - function bitOrMul(uint256 a, uint256 b, uint256 c) + function bitAndMul(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a | b * c; + return a & b * c; } - function bitOrDiv(uint256 a, uint256 b, uint256 c) + function bitAndDiv(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a | b / c; + return a & b / c; } - function bitOrMod(uint256 a, uint256 b, uint256 c) + function bitAndMod(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a | b % c; + return a & b % c; } - function bitOrExp(uint256 a, uint256 b, uint256 c) + function bitAndExp(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a | b ** c; + return a & b ** c; } - function bitOrShiftL(uint256 a, uint256 b, uint256 c) + function bitAndShiftL(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a | b << c; + return a & b << c; } - function bitOrShiftR(uint256 a, uint256 b, uint256 c) + function bitAndShiftR(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a | b >> c; + return a & b >> c; } - function bitOrBitAnd(uint256 a, uint256 b, uint256 c) + function bitAndBitAnd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a | b & c; + return a & b & c; } - function bitOrBitOr(uint256 a, uint256 b, uint256 c) + function bitAndBitOr(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a | b | c; + return a & b | c; } - function bitOrBitXor(uint256 a, uint256 b, uint256 c) + function bitAndBitXor(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a | b ^ c; + return a & b ^ c; } } @@ -498,297 +486,285 @@ contract BitOrNoParentheses { // SPDX-License-Identifier: MIT pragma solidity 0.8.25; -contract BitOrNoParentheses { - function bitOrAdd( +contract BitAndNoParentheses { + function bitAndAdd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | (b + c); + return a & (b + c); } - function bitOrSub( + function bitAndSub( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | (b - c); + return a & (b - c); } - function bitOrMul( + function bitAndMul( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | (b * c); + return a & (b * c); } - function bitOrDiv( + function bitAndDiv( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | (b / c); + return a & (b / c); } - function bitOrMod( + function bitAndMod( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | b % c; + return a & b % c; } - function bitOrExp( + function bitAndExp( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | (b ** c); + return a & (b ** c); } - function bitOrShiftL( + function bitAndShiftL( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | (b << c); + return a & (b << c); } - function bitOrShiftR( + function bitAndShiftR( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | (b >> c); + return a & (b >> c); } - function bitOrBitAnd( + function bitAndBitAnd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | (b & c); + return a & b & c; } - function bitOrBitOr( + function bitAndBitOr( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | b | c; + return (a & b) | c; } - function bitOrBitXor( + function bitAndBitXor( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | (b ^ c); + return (a & b) ^ c; } } ================================================================================ `; -exports[`BitXorNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` +exports[`BitAndNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["solidity-parse"] +parsers: ["solidity-slang-parse"] printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT pragma solidity 0.8.25; -contract BitXorNoParentheses { - function bitXorAdd(uint256 a, uint256 b, uint256 c) +contract BitAndNoParentheses { + function bitAndAdd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a ^ b + c; + return a & b + c; } - function bitXorSub(uint256 a, uint256 b, uint256 c) + function bitAndSub(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a ^ b - c; + return a & b - c; } - function bitXorMul(uint256 a, uint256 b, uint256 c) + function bitAndMul(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a ^ b * c; + return a & b * c; } - function bitXorDiv(uint256 a, uint256 b, uint256 c) + function bitAndDiv(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a ^ b / c; + return a & b / c; } - function bitXorMod(uint256 a, uint256 b, uint256 c) + function bitAndMod(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a ^ b % c; + return a & b % c; } - function bitXorExp(uint256 a, uint256 b, uint256 c) + function bitAndExp(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a ^ b ** c; + return a & b ** c; } - function bitXorShiftL(uint256 a, uint256 b, uint256 c) + function bitAndShiftL(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a ^ b << c; + return a & b << c; } - function bitXorShiftR(uint256 a, uint256 b, uint256 c) + function bitAndShiftR(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a ^ b >> c; + return a & b >> c; } - function bitXorBitAnd(uint256 a, uint256 b, uint256 c) + function bitAndBitAnd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a ^ b & c; + return a & b & c; } - function bitXorBitOr(uint256 a, uint256 b, uint256 c) + function bitAndBitOr(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a ^ b | c; + return a & b | c; } - function bitXorBitXor(uint256 a, uint256 b, uint256 c) + function bitAndBitXor(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a ^ b ^ c; + return a & b ^ c; } } =====================================output===================================== -// SPDX-License-Identifier: MIT pragma solidity 0.8.25; - -contract BitXorNoParentheses { - function bitXorAdd( +contract BitAndNoParentheses { + function bitAndAdd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a ^ (b + c); + return a & b + c; } - - function bitXorSub( + function bitAndSub( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a ^ (b - c); + return a & b - c; } - - function bitXorMul( + function bitAndMul( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a ^ (b * c); + return a & b * c; } - - function bitXorDiv( + function bitAndDiv( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a ^ (b / c); + return a & b / c; } - - function bitXorMod( + function bitAndMod( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a ^ b % c; + return a & b % c; } - - function bitXorExp( + function bitAndExp( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a ^ (b ** c); + return a & b ** c; } - - function bitXorShiftL( + function bitAndShiftL( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a ^ (b << c); + return a & b << c; } - - function bitXorShiftR( + function bitAndShiftR( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a ^ (b >> c); + return a & b >> c; } - - function bitXorBitAnd( + function bitAndBitAnd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a ^ (b & c); + return a & b & c; } - - function bitXorBitOr( + function bitAndBitOr( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a ^ b) | c; + return a & b | c; } - - function bitXorBitXor( + function bitAndBitXor( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a ^ b ^ c; + return a & b ^ c; } } ================================================================================ `; -exports[`DivNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` +exports[`BitOrNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` ====================================options===================================== compiler: "0.8.6" parsers: ["solidity-parse"] @@ -798,93 +774,93 @@ printWidth: 80 // SPDX-License-Identifier: MIT pragma solidity 0.8.25; -contract DivNoParentheses { - function divAdd(uint256 a, uint256 b, uint256 c) +contract BitOrNoParentheses { + function bitOrAdd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a / b + c; + return a | b + c; } - function divSub(uint256 a, uint256 b, uint256 c) + function bitOrSub(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a / b - c; + return a | b - c; } - function divMul(uint256 a, uint256 b, uint256 c) + function bitOrMul(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a / b * c; + return a | b * c; } - function divDiv(uint256 a, uint256 b, uint256 c) + function bitOrDiv(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a / b / c; + return a | b / c; } - function divMod(uint256 a, uint256 b, uint256 c) + function bitOrMod(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a / b % c; + return a | b % c; } - function divExp(uint256 a, uint256 b, uint256 c) + function bitOrExp(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a / b ** c; + return a | b ** c; } - function divShiftL(uint256 a, uint256 b, uint256 c) + function bitOrShiftL(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a / b << c; + return a | b << c; } - function divShiftR(uint256 a, uint256 b, uint256 c) + function bitOrShiftR(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a / b >> c; + return a | b >> c; } - function divBitAnd(uint256 a, uint256 b, uint256 c) + function bitOrBitAnd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a / b & c; + return a | b & c; } - function divBitOr(uint256 a, uint256 b, uint256 c) + function bitOrBitOr(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a / b | c; + return a | b | c; } - function divBitXor(uint256 a, uint256 b, uint256 c) + function bitOrBitXor(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a / b ^ c; + return a | b ^ c; } } @@ -892,297 +868,285 @@ contract DivNoParentheses { // SPDX-License-Identifier: MIT pragma solidity 0.8.25; -contract DivNoParentheses { - function divAdd( +contract BitOrNoParentheses { + function bitOrAdd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a / b + c; + return a | (b + c); } - function divSub( + function bitOrSub( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a / b - c; + return a | (b - c); } - function divMul( + function bitOrMul( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a / b) * c; + return a | (b * c); } - function divDiv( + function bitOrDiv( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a / b / c; + return a | (b / c); } - function divMod( + function bitOrMod( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a / b) % c; + return a | b % c; } - function divExp( + function bitOrExp( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a / b ** c; + return a | (b ** c); } - function divShiftL( + function bitOrShiftL( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a / b) << c; + return a | (b << c); } - function divShiftR( + function bitOrShiftR( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a / b) >> c; + return a | (b >> c); } - function divBitAnd( + function bitOrBitAnd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a / b) & c; + return a | (b & c); } - function divBitOr( + function bitOrBitOr( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a / b) | c; + return a | b | c; } - function divBitXor( + function bitOrBitXor( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a / b) ^ c; + return a | (b ^ c); } } ================================================================================ `; -exports[`ExpNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` +exports[`BitOrNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["solidity-parse"] +parsers: ["solidity-slang-parse"] printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT pragma solidity 0.8.25; -contract ExpNoParentheses { - function expAdd(uint256 a, uint256 b, uint256 c) +contract BitOrNoParentheses { + function bitOrAdd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a ** b + c; + return a | b + c; } - function expSub(uint256 a, uint256 b, uint256 c) + function bitOrSub(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a ** b - c; + return a | b - c; } - function expMul(uint256 a, uint256 b, uint256 c) + function bitOrMul(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a ** b * c; + return a | b * c; } - function expDiv(uint256 a, uint256 b, uint256 c) + function bitOrDiv(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a ** b / c; + return a | b / c; } - function expMod(uint256 a, uint256 b, uint256 c) + function bitOrMod(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a ** b % c; + return a | b % c; } - function expExp(uint256 a, uint256 b, uint256 c) + function bitOrExp(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a ** b ** c; + return a | b ** c; } - function expShiftL(uint256 a, uint256 b, uint256 c) + function bitOrShiftL(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a ** b << c; + return a | b << c; } - function expShiftR(uint256 a, uint256 b, uint256 c) + function bitOrShiftR(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a ** b >> c; + return a | b >> c; } - function expBitAnd(uint256 a, uint256 b, uint256 c) + function bitOrBitAnd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a ** b & c; + return a | b & c; } - function expBitOr(uint256 a, uint256 b, uint256 c) + function bitOrBitOr(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a ** b | c; + return a | b | c; } - function expBitXor(uint256 a, uint256 b, uint256 c) + function bitOrBitXor(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a ** b ^ c; + return a | b ^ c; } } =====================================output===================================== -// SPDX-License-Identifier: MIT pragma solidity 0.8.25; - -contract ExpNoParentheses { - function expAdd( +contract BitOrNoParentheses { + function bitOrAdd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a ** b + c; + return a | b + c; } - - function expSub( + function bitOrSub( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a ** b - c; + return a | b - c; } - - function expMul( + function bitOrMul( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a ** b * c; + return a | b * c; } - - function expDiv( + function bitOrDiv( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a ** b / c; + return a | b / c; } - - function expMod( + function bitOrMod( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a ** b % c; + return a | b % c; } - - function expExp( + function bitOrExp( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a ** (b ** c); + return a | b ** c; } - - function expShiftL( + function bitOrShiftL( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a ** b) << c; + return a | b << c; } - - function expShiftR( + function bitOrShiftR( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a ** b) >> c; + return a | b >> c; } - - function expBitAnd( + function bitOrBitAnd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a ** b) & c; + return a | b & c; } - - function expBitOr( + function bitOrBitOr( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a ** b) | c; + return a | b | c; } - - function expBitXor( + function bitOrBitXor( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a ** b) ^ c; + return a | b ^ c; } } ================================================================================ `; -exports[`LogicNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` +exports[`BitXorNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` ====================================options===================================== compiler: "0.8.6" parsers: ["solidity-parse"] @@ -1192,247 +1156,2390 @@ printWidth: 80 // SPDX-License-Identifier: MIT pragma solidity 0.8.25; -contract LogicNoParentheses { - function orOr(bool a, bool b, bool c) public pure returns (bool) { - return a || b || c; - } +contract BitXorNoParentheses { + function bitXorAdd(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ^ b + c; + } + + function bitXorSub(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ^ b - c; + } + + function bitXorMul(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ^ b * c; + } + + function bitXorDiv(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ^ b / c; + } + + function bitXorMod(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ^ b % c; + } + + function bitXorExp(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ^ b ** c; + } + + function bitXorShiftL(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ^ b << c; + } + + function bitXorShiftR(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ^ b >> c; + } + + function bitXorBitAnd(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ^ b & c; + } + + function bitXorBitOr(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ^ b | c; + } + + function bitXorBitXor(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ^ b ^ c; + } +} + +=====================================output===================================== +// SPDX-License-Identifier: MIT +pragma solidity 0.8.25; + +contract BitXorNoParentheses { + function bitXorAdd( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ^ (b + c); + } + + function bitXorSub( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ^ (b - c); + } + + function bitXorMul( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ^ (b * c); + } + + function bitXorDiv( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ^ (b / c); + } + + function bitXorMod( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ^ b % c; + } + + function bitXorExp( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ^ (b ** c); + } + + function bitXorShiftL( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ^ (b << c); + } + + function bitXorShiftR( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ^ (b >> c); + } + + function bitXorBitAnd( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ^ (b & c); + } + + function bitXorBitOr( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return (a ^ b) | c; + } + + function bitXorBitXor( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ^ b ^ c; + } +} + +================================================================================ +`; + +exports[`BitXorNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` +====================================options===================================== +compiler: "0.8.6" +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +// SPDX-License-Identifier: MIT +pragma solidity 0.8.25; + +contract BitXorNoParentheses { + function bitXorAdd(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ^ b + c; + } + + function bitXorSub(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ^ b - c; + } + + function bitXorMul(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ^ b * c; + } + + function bitXorDiv(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ^ b / c; + } + + function bitXorMod(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ^ b % c; + } + + function bitXorExp(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ^ b ** c; + } + + function bitXorShiftL(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ^ b << c; + } + + function bitXorShiftR(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ^ b >> c; + } + + function bitXorBitAnd(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ^ b & c; + } + + function bitXorBitOr(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ^ b | c; + } + + function bitXorBitXor(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ^ b ^ c; + } +} + +=====================================output===================================== +pragma solidity 0.8.25; +contract BitXorNoParentheses { + function bitXorAdd( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ^ b + c; + } + function bitXorSub( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ^ b - c; + } + function bitXorMul( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ^ b * c; + } + function bitXorDiv( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ^ b / c; + } + function bitXorMod( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ^ b % c; + } + function bitXorExp( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ^ b ** c; + } + function bitXorShiftL( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ^ b << c; + } + function bitXorShiftR( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ^ b >> c; + } + function bitXorBitAnd( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ^ b & c; + } + function bitXorBitOr( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ^ b | c; + } + function bitXorBitXor( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ^ b ^ c; + } +} + +================================================================================ +`; + +exports[`DivNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` +====================================options===================================== +compiler: "0.8.6" +parsers: ["solidity-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +// SPDX-License-Identifier: MIT +pragma solidity 0.8.25; + +contract DivNoParentheses { + function divAdd(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a / b + c; + } + + function divSub(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a / b - c; + } + + function divMul(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a / b * c; + } + + function divDiv(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a / b / c; + } + + function divMod(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a / b % c; + } + + function divExp(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a / b ** c; + } + + function divShiftL(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a / b << c; + } + + function divShiftR(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a / b >> c; + } + + function divBitAnd(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a / b & c; + } + + function divBitOr(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a / b | c; + } + + function divBitXor(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a / b ^ c; + } +} + +=====================================output===================================== +// SPDX-License-Identifier: MIT +pragma solidity 0.8.25; + +contract DivNoParentheses { + function divAdd( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a / b + c; + } + + function divSub( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a / b - c; + } + + function divMul( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return (a / b) * c; + } + + function divDiv( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a / b / c; + } + + function divMod( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return (a / b) % c; + } + + function divExp( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a / b ** c; + } + + function divShiftL( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return (a / b) << c; + } + + function divShiftR( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return (a / b) >> c; + } + + function divBitAnd( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return (a / b) & c; + } + + function divBitOr( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return (a / b) | c; + } + + function divBitXor( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return (a / b) ^ c; + } +} + +================================================================================ +`; + +exports[`DivNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` +====================================options===================================== +compiler: "0.8.6" +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +// SPDX-License-Identifier: MIT +pragma solidity 0.8.25; + +contract DivNoParentheses { + function divAdd(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a / b + c; + } + + function divSub(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a / b - c; + } + + function divMul(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a / b * c; + } + + function divDiv(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a / b / c; + } + + function divMod(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a / b % c; + } + + function divExp(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a / b ** c; + } + + function divShiftL(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a / b << c; + } + + function divShiftR(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a / b >> c; + } + + function divBitAnd(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a / b & c; + } + + function divBitOr(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a / b | c; + } + + function divBitXor(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a / b ^ c; + } +} + +=====================================output===================================== +pragma solidity 0.8.25; +contract DivNoParentheses { + function divAdd( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a / b + c; + } + function divSub( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a / b - c; + } + function divMul( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a / b * c; + } + function divDiv( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a / b / c; + } + function divMod( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a / b % c; + } + function divExp( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a / b ** c; + } + function divShiftL( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a / b << c; + } + function divShiftR( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a / b >> c; + } + function divBitAnd( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a / b & c; + } + function divBitOr( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a / b | c; + } + function divBitXor( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a / b ^ c; + } +} + +================================================================================ +`; + +exports[`ExpNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` +====================================options===================================== +compiler: "0.8.6" +parsers: ["solidity-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +// SPDX-License-Identifier: MIT +pragma solidity 0.8.25; + +contract ExpNoParentheses { + function expAdd(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ** b + c; + } + + function expSub(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ** b - c; + } + + function expMul(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ** b * c; + } + + function expDiv(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ** b / c; + } + + function expMod(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ** b % c; + } + + function expExp(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ** b ** c; + } + + function expShiftL(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ** b << c; + } + + function expShiftR(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ** b >> c; + } + + function expBitAnd(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ** b & c; + } + + function expBitOr(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ** b | c; + } + + function expBitXor(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ** b ^ c; + } +} + +=====================================output===================================== +// SPDX-License-Identifier: MIT +pragma solidity 0.8.25; + +contract ExpNoParentheses { + function expAdd( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ** b + c; + } + + function expSub( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ** b - c; + } + + function expMul( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ** b * c; + } + + function expDiv( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ** b / c; + } + + function expMod( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ** b % c; + } + + function expExp( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ** (b ** c); + } + + function expShiftL( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return (a ** b) << c; + } + + function expShiftR( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return (a ** b) >> c; + } + + function expBitAnd( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return (a ** b) & c; + } + + function expBitOr( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return (a ** b) | c; + } + + function expBitXor( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return (a ** b) ^ c; + } +} + +================================================================================ +`; + +exports[`ExpNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` +====================================options===================================== +compiler: "0.8.6" +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +// SPDX-License-Identifier: MIT +pragma solidity 0.8.25; + +contract ExpNoParentheses { + function expAdd(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ** b + c; + } + + function expSub(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ** b - c; + } + + function expMul(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ** b * c; + } + + function expDiv(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ** b / c; + } + + function expMod(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ** b % c; + } + + function expExp(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ** b ** c; + } + + function expShiftL(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ** b << c; + } + + function expShiftR(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ** b >> c; + } + + function expBitAnd(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ** b & c; + } + + function expBitOr(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ** b | c; + } + + function expBitXor(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a ** b ^ c; + } +} + +=====================================output===================================== +pragma solidity 0.8.25; +contract ExpNoParentheses { + function expAdd( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ** b + c; + } + function expSub( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ** b - c; + } + function expMul( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ** b * c; + } + function expDiv( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ** b / c; + } + function expMod( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ** b % c; + } + function expExp( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ** b ** c; + } + function expShiftL( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ** b << c; + } + function expShiftR( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ** b >> c; + } + function expBitAnd( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ** b & c; + } + function expBitOr( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ** b | c; + } + function expBitXor( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a ** b ^ c; + } +} + +================================================================================ +`; + +exports[`LogicNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` +====================================options===================================== +compiler: "0.8.6" +parsers: ["solidity-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +// SPDX-License-Identifier: MIT +pragma solidity 0.8.25; + +contract LogicNoParentheses { + function orOr(bool a, bool b, bool c) public pure returns (bool) { + return a || b || c; + } + + function orAnd(bool a, bool b, bool c) public pure returns (bool) { + return a || b && c; + } + + function andOr(bool a, bool b, bool c) public pure returns (bool) { + return a && b || c; + } + + function andAnd(bool a, bool b, bool c) public pure returns (bool) { + return a && b && c; + } +} + +=====================================output===================================== +// SPDX-License-Identifier: MIT +pragma solidity 0.8.25; + +contract LogicNoParentheses { + function orOr(bool a, bool b, bool c) public pure returns (bool) { + return a || b || c; + } + + function orAnd(bool a, bool b, bool c) public pure returns (bool) { + return a || (b && c); + } + + function andOr(bool a, bool b, bool c) public pure returns (bool) { + return (a && b) || c; + } + + function andAnd(bool a, bool b, bool c) public pure returns (bool) { + return a && b && c; + } +} + +================================================================================ +`; + +exports[`LogicNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` +====================================options===================================== +compiler: "0.8.6" +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +// SPDX-License-Identifier: MIT +pragma solidity 0.8.25; + +contract LogicNoParentheses { + function orOr(bool a, bool b, bool c) public pure returns (bool) { + return a || b || c; + } + + function orAnd(bool a, bool b, bool c) public pure returns (bool) { + return a || b && c; + } + + function andOr(bool a, bool b, bool c) public pure returns (bool) { + return a && b || c; + } + + function andAnd(bool a, bool b, bool c) public pure returns (bool) { + return a && b && c; + } +} + +=====================================output===================================== +pragma solidity 0.8.25; +contract LogicNoParentheses { + function orOr(bool a, bool b, bool c) public pure returns (bool) { + return a || b || c; + } + function orAnd(bool a, bool b, bool c) public pure returns (bool) { + return a || b && c; + } + function andOr(bool a, bool b, bool c) public pure returns (bool) { + return a && b || c; + } + function andAnd(bool a, bool b, bool c) public pure returns (bool) { + return a && b && c; + } +} + +================================================================================ +`; + +exports[`ModNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` +====================================options===================================== +compiler: "0.8.6" +parsers: ["solidity-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +// SPDX-License-Identifier: MIT +pragma solidity 0.8.25; + +contract ModNoParentheses { + function modAdd(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a % b + c; + } + + function modSub(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a % b - c; + } + + function modMul(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a % b * c; + } + + function modDiv(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a % b / c; + } + + function modMod(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a % b % c; + } + + function modExp(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a % b ** c; + } + + function modShiftL(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a % b << c; + } + + function modShiftR(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a % b >> c; + } + + function modBitAnd(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a % b & c; + } + + function modBitOr(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a % b | c; + } + + function modBitXor(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a % b ^ c; + } +} + +=====================================output===================================== +// SPDX-License-Identifier: MIT +pragma solidity 0.8.25; + +contract ModNoParentheses { + function modAdd( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return (a % b) + c; + } + + function modSub( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return (a % b) - c; + } + + function modMul( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return (a % b) * c; + } + + function modDiv( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return (a % b) / c; + } + + function modMod( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return (a % b) % c; + } + + function modExp( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a % b ** c; + } + + function modShiftL( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a % b << c; + } + + function modShiftR( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a % b >> c; + } + + function modBitAnd( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a % b & c; + } + + function modBitOr( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a % b | c; + } + + function modBitXor( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a % b ^ c; + } +} + +================================================================================ +`; + +exports[`ModNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` +====================================options===================================== +compiler: "0.8.6" +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +// SPDX-License-Identifier: MIT +pragma solidity 0.8.25; + +contract ModNoParentheses { + function modAdd(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a % b + c; + } + + function modSub(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a % b - c; + } + + function modMul(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a % b * c; + } + + function modDiv(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a % b / c; + } + + function modMod(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a % b % c; + } + + function modExp(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a % b ** c; + } + + function modShiftL(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a % b << c; + } + + function modShiftR(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a % b >> c; + } + + function modBitAnd(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a % b & c; + } + + function modBitOr(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a % b | c; + } + + function modBitXor(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a % b ^ c; + } +} + +=====================================output===================================== +pragma solidity 0.8.25; +contract ModNoParentheses { + function modAdd( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a % b + c; + } + function modSub( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a % b - c; + } + function modMul( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a % b * c; + } + function modDiv( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a % b / c; + } + function modMod( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a % b % c; + } + function modExp( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a % b ** c; + } + function modShiftL( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a % b << c; + } + function modShiftR( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a % b >> c; + } + function modBitAnd( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a % b & c; + } + function modBitOr( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a % b | c; + } + function modBitXor( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a % b ^ c; + } +} + +================================================================================ +`; + +exports[`MulNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` +====================================options===================================== +compiler: "0.8.6" +parsers: ["solidity-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +// SPDX-License-Identifier: MIT +pragma solidity 0.8.25; + +contract MulNoParentheses { + function mulAdd(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a * b + c; + } + + function mulSub(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a * b - c; + } + + function mulMul(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a * b * c; + } + + function mulDiv(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a * b / c; + } + + function mulMod(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a * b % c; + } + + function mulExp(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a * b ** c; + } + + function mulShiftL(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a * b << c; + } + + function mulShiftR(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a * b >> c; + } + + function mulBitAnd(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a * b & c; + } + + function mulBitOr(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a * b | c; + } + + function mulBitXor(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a * b ^ c; + } +} + +=====================================output===================================== +// SPDX-License-Identifier: MIT +pragma solidity 0.8.25; + +contract MulNoParentheses { + function mulAdd( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a * b + c; + } + + function mulSub( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a * b - c; + } + + function mulMul( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a * b * c; + } + + function mulDiv( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return (a * b) / c; + } + + function mulMod( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return (a * b) % c; + } + + function mulExp( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a * b ** c; + } + + function mulShiftL( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return (a * b) << c; + } + + function mulShiftR( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return (a * b) >> c; + } + + function mulBitAnd( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return (a * b) & c; + } + + function mulBitOr( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return (a * b) | c; + } + + function mulBitXor( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return (a * b) ^ c; + } +} + +================================================================================ +`; + +exports[`MulNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` +====================================options===================================== +compiler: "0.8.6" +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +// SPDX-License-Identifier: MIT +pragma solidity 0.8.25; + +contract MulNoParentheses { + function mulAdd(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a * b + c; + } + + function mulSub(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a * b - c; + } + + function mulMul(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a * b * c; + } + + function mulDiv(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a * b / c; + } + + function mulMod(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a * b % c; + } + + function mulExp(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a * b ** c; + } + + function mulShiftL(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a * b << c; + } + + function mulShiftR(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a * b >> c; + } + + function mulBitAnd(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a * b & c; + } + + function mulBitOr(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a * b | c; + } + + function mulBitXor(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a * b ^ c; + } +} + +=====================================output===================================== +pragma solidity 0.8.25; +contract MulNoParentheses { + function mulAdd( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a * b + c; + } + function mulSub( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a * b - c; + } + function mulMul( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a * b * c; + } + function mulDiv( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a * b / c; + } + function mulMod( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a * b % c; + } + function mulExp( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a * b ** c; + } + function mulShiftL( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a * b << c; + } + function mulShiftR( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a * b >> c; + } + function mulBitAnd( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a * b & c; + } + function mulBitOr( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a * b | c; + } + function mulBitXor( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a * b ^ c; + } +} + +================================================================================ +`; + +exports[`ShiftLNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` +====================================options===================================== +compiler: "0.8.6" +parsers: ["solidity-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +// SPDX-License-Identifier: MIT +pragma solidity 0.8.25; + +contract ShiftLNoParentheses { + function shiftLAdd(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a << b + c; + } + + function shiftLSub(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a << b - c; + } + + function shiftLMul(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a << b * c; + } + + function shiftLDiv(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a << b / c; + } + + function shiftLMod(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a << b % c; + } + + function shiftLExp(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a << b ** c; + } + + function shiftLShiftL(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a << b << c; + } + + function shiftLShiftR(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a << b >> c; + } + + function shiftLBitAnd(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a << b & c; + } + + function shiftLBitOr(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a << b | c; + } + + function shiftLBitXor(uint256 a, uint256 b, uint256 c) + public + pure + returns (uint256) + { + return a << b ^ c; + } +} + +=====================================output===================================== +// SPDX-License-Identifier: MIT +pragma solidity 0.8.25; + +contract ShiftLNoParentheses { + function shiftLAdd( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a << (b + c); + } - function orAnd(bool a, bool b, bool c) public pure returns (bool) { - return a || b && c; + function shiftLSub( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a << (b - c); } - function andOr(bool a, bool b, bool c) public pure returns (bool) { - return a && b || c; + function shiftLMul( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a << (b * c); } - function andAnd(bool a, bool b, bool c) public pure returns (bool) { - return a && b && c; + function shiftLDiv( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a << (b / c); } -} -=====================================output===================================== -// SPDX-License-Identifier: MIT -pragma solidity 0.8.25; + function shiftLMod( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a << b % c; + } -contract LogicNoParentheses { - function orOr(bool a, bool b, bool c) public pure returns (bool) { - return a || b || c; + function shiftLExp( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return a << (b ** c); } - function orAnd(bool a, bool b, bool c) public pure returns (bool) { - return a || (b && c); + function shiftLShiftL( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return (a << b) << c; } - function andOr(bool a, bool b, bool c) public pure returns (bool) { - return (a && b) || c; + function shiftLShiftR( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return (a << b) >> c; } - function andAnd(bool a, bool b, bool c) public pure returns (bool) { - return a && b && c; + function shiftLBitAnd( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return (a << b) & c; + } + + function shiftLBitOr( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return (a << b) | c; + } + + function shiftLBitXor( + uint256 a, + uint256 b, + uint256 c + ) public pure returns (uint256) { + return (a << b) ^ c; } } ================================================================================ `; -exports[`ModNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` +exports[`ShiftLNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["solidity-parse"] +parsers: ["solidity-slang-parse"] printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT pragma solidity 0.8.25; -contract ModNoParentheses { - function modAdd(uint256 a, uint256 b, uint256 c) +contract ShiftLNoParentheses { + function shiftLAdd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a % b + c; + return a << b + c; } - function modSub(uint256 a, uint256 b, uint256 c) + function shiftLSub(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a % b - c; + return a << b - c; } - function modMul(uint256 a, uint256 b, uint256 c) + function shiftLMul(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a % b * c; + return a << b * c; } - function modDiv(uint256 a, uint256 b, uint256 c) + function shiftLDiv(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a % b / c; + return a << b / c; } - function modMod(uint256 a, uint256 b, uint256 c) + function shiftLMod(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a % b % c; + return a << b % c; } - function modExp(uint256 a, uint256 b, uint256 c) + function shiftLExp(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a % b ** c; + return a << b ** c; } - function modShiftL(uint256 a, uint256 b, uint256 c) + function shiftLShiftL(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a % b << c; + return a << b << c; } - function modShiftR(uint256 a, uint256 b, uint256 c) + function shiftLShiftR(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a % b >> c; + return a << b >> c; } - function modBitAnd(uint256 a, uint256 b, uint256 c) + function shiftLBitAnd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a % b & c; + return a << b & c; } - function modBitOr(uint256 a, uint256 b, uint256 c) + function shiftLBitOr(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a % b | c; + return a << b | c; } - function modBitXor(uint256 a, uint256 b, uint256 c) + function shiftLBitXor(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a % b ^ c; + return a << b ^ c; } } =====================================output===================================== -// SPDX-License-Identifier: MIT pragma solidity 0.8.25; - -contract ModNoParentheses { - function modAdd( +contract ShiftLNoParentheses { + function shiftLAdd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a % b) + c; + return a << b + c; } - - function modSub( + function shiftLSub( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a % b) - c; + return a << b - c; } - - function modMul( + function shiftLMul( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a % b) * c; + return a << b * c; } - - function modDiv( + function shiftLDiv( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a % b) / c; + return a << b / c; } - - function modMod( + function shiftLMod( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a % b) % c; + return a << b % c; } - - function modExp( + function shiftLExp( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a % b ** c; + return a << b ** c; } - - function modShiftL( + function shiftLShiftL( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a % b << c; + return a << b << c; } - - function modShiftR( + function shiftLShiftR( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a % b >> c; + return a << b >> c; } - - function modBitAnd( + function shiftLBitAnd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a % b & c; + return a << b & c; } - - function modBitOr( + function shiftLBitOr( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a % b | c; + return a << b | c; } - - function modBitXor( + function shiftLBitXor( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a % b ^ c; + return a << b ^ c; } } ================================================================================ `; -exports[`MulNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` +exports[`ShiftRNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` ====================================options===================================== compiler: "0.8.6" parsers: ["solidity-parse"] @@ -1442,93 +3549,93 @@ printWidth: 80 // SPDX-License-Identifier: MIT pragma solidity 0.8.25; -contract MulNoParentheses { - function mulAdd(uint256 a, uint256 b, uint256 c) +contract ShiftRNoParentheses { + function shiftRAdd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a * b + c; + return a >> b + c; } - function mulSub(uint256 a, uint256 b, uint256 c) + function shiftRSub(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a * b - c; + return a >> b - c; } - function mulMul(uint256 a, uint256 b, uint256 c) + function shiftRMul(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a * b * c; + return a >> b * c; } - function mulDiv(uint256 a, uint256 b, uint256 c) + function shiftRDiv(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a * b / c; + return a >> b / c; } - function mulMod(uint256 a, uint256 b, uint256 c) + function shiftRMod(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a * b % c; + return a >> b % c; } - function mulExp(uint256 a, uint256 b, uint256 c) + function shiftRExp(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a * b ** c; + return a >> b ** c; } - function mulShiftL(uint256 a, uint256 b, uint256 c) + function shiftRShiftL(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a * b << c; + return a >> b << c; } - function mulShiftR(uint256 a, uint256 b, uint256 c) + function shiftRShiftR(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a * b >> c; + return a >> b >> c; } - function mulBitAnd(uint256 a, uint256 b, uint256 c) + function shiftRBitAnd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a * b & c; + return a >> b & c; } - function mulBitOr(uint256 a, uint256 b, uint256 c) + function shiftRBitOr(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a * b | c; + return a >> b | c; } - function mulBitXor(uint256 a, uint256 b, uint256 c) + function shiftRBitXor(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a * b ^ c; + return a >> b ^ c; } } @@ -1536,297 +3643,285 @@ contract MulNoParentheses { // SPDX-License-Identifier: MIT pragma solidity 0.8.25; -contract MulNoParentheses { - function mulAdd( +contract ShiftRNoParentheses { + function shiftRAdd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a * b + c; + return a >> (b + c); } - function mulSub( + function shiftRSub( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a * b - c; + return a >> (b - c); } - function mulMul( + function shiftRMul( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a * b * c; + return a >> (b * c); } - function mulDiv( + function shiftRDiv( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a * b) / c; + return a >> (b / c); } - function mulMod( + function shiftRMod( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a * b) % c; + return a >> b % c; } - function mulExp( + function shiftRExp( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a * b ** c; + return a >> (b ** c); } - function mulShiftL( + function shiftRShiftL( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a * b) << c; + return (a >> b) << c; } - function mulShiftR( + function shiftRShiftR( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a * b) >> c; + return (a >> b) >> c; } - function mulBitAnd( + function shiftRBitAnd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a * b) & c; + return (a >> b) & c; } - function mulBitOr( + function shiftRBitOr( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a * b) | c; + return (a >> b) | c; } - function mulBitXor( + function shiftRBitXor( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a * b) ^ c; + return (a >> b) ^ c; } } ================================================================================ `; -exports[`ShiftLNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` +exports[`ShiftRNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["solidity-parse"] +parsers: ["solidity-slang-parse"] printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT pragma solidity 0.8.25; -contract ShiftLNoParentheses { - function shiftLAdd(uint256 a, uint256 b, uint256 c) +contract ShiftRNoParentheses { + function shiftRAdd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a << b + c; + return a >> b + c; } - function shiftLSub(uint256 a, uint256 b, uint256 c) + function shiftRSub(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a << b - c; + return a >> b - c; } - function shiftLMul(uint256 a, uint256 b, uint256 c) + function shiftRMul(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a << b * c; + return a >> b * c; } - function shiftLDiv(uint256 a, uint256 b, uint256 c) + function shiftRDiv(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a << b / c; + return a >> b / c; } - function shiftLMod(uint256 a, uint256 b, uint256 c) + function shiftRMod(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a << b % c; + return a >> b % c; } - function shiftLExp(uint256 a, uint256 b, uint256 c) + function shiftRExp(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a << b ** c; + return a >> b ** c; } - function shiftLShiftL(uint256 a, uint256 b, uint256 c) + function shiftRShiftL(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a << b << c; + return a >> b << c; } - function shiftLShiftR(uint256 a, uint256 b, uint256 c) + function shiftRShiftR(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a << b >> c; + return a >> b >> c; } - function shiftLBitAnd(uint256 a, uint256 b, uint256 c) + function shiftRBitAnd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a << b & c; + return a >> b & c; } - function shiftLBitOr(uint256 a, uint256 b, uint256 c) + function shiftRBitOr(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a << b | c; + return a >> b | c; } - function shiftLBitXor(uint256 a, uint256 b, uint256 c) + function shiftRBitXor(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a << b ^ c; + return a >> b ^ c; } } =====================================output===================================== -// SPDX-License-Identifier: MIT pragma solidity 0.8.25; - -contract ShiftLNoParentheses { - function shiftLAdd( +contract ShiftRNoParentheses { + function shiftRAdd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a << (b + c); + return a >> b + c; } - - function shiftLSub( + function shiftRSub( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a << (b - c); + return a >> b - c; } - - function shiftLMul( + function shiftRMul( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a << (b * c); + return a >> b * c; } - - function shiftLDiv( + function shiftRDiv( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a << (b / c); + return a >> b / c; } - - function shiftLMod( + function shiftRMod( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a << b % c; + return a >> b % c; } - - function shiftLExp( + function shiftRExp( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a << (b ** c); + return a >> b ** c; } - - function shiftLShiftL( + function shiftRShiftL( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a << b) << c; + return a >> b << c; } - - function shiftLShiftR( + function shiftRShiftR( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a << b) >> c; + return a >> b >> c; } - - function shiftLBitAnd( + function shiftRBitAnd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a << b) & c; + return a >> b & c; } - - function shiftLBitOr( + function shiftRBitOr( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a << b) | c; + return a >> b | c; } - - function shiftLBitXor( + function shiftRBitXor( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a << b) ^ c; + return a >> b ^ c; } } ================================================================================ `; -exports[`ShiftRNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` +exports[`SubNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` ====================================options===================================== compiler: "0.8.6" parsers: ["solidity-parse"] @@ -1836,93 +3931,93 @@ printWidth: 80 // SPDX-License-Identifier: MIT pragma solidity 0.8.25; -contract ShiftRNoParentheses { - function shiftRAdd(uint256 a, uint256 b, uint256 c) +contract SubNoParentheses { + function subAdd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a >> b + c; + return a - b + c; } - function shiftRSub(uint256 a, uint256 b, uint256 c) + function subSub(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a >> b - c; + return a - b - c; } - function shiftRMul(uint256 a, uint256 b, uint256 c) + function subMul(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a >> b * c; + return a - b * c; } - function shiftRDiv(uint256 a, uint256 b, uint256 c) + function subDiv(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a >> b / c; + return a - b / c; } - function shiftRMod(uint256 a, uint256 b, uint256 c) + function subMod(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a >> b % c; + return a - b % c; } - function shiftRExp(uint256 a, uint256 b, uint256 c) + function subExp(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a >> b ** c; + return a - b ** c; } - function shiftRShiftL(uint256 a, uint256 b, uint256 c) + function subShiftL(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a >> b << c; + return a - b << c; } - function shiftRShiftR(uint256 a, uint256 b, uint256 c) + function subShiftR(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a >> b >> c; + return a - b >> c; } - function shiftRBitAnd(uint256 a, uint256 b, uint256 c) + function subBitAnd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a >> b & c; + return a - b & c; } - function shiftRBitOr(uint256 a, uint256 b, uint256 c) + function subBitOr(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a >> b | c; + return a - b | c; } - function shiftRBitXor(uint256 a, uint256 b, uint256 c) + function subBitXor(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a >> b ^ c; + return a - b ^ c; } } @@ -1930,103 +4025,103 @@ contract ShiftRNoParentheses { // SPDX-License-Identifier: MIT pragma solidity 0.8.25; -contract ShiftRNoParentheses { - function shiftRAdd( +contract SubNoParentheses { + function subAdd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a >> (b + c); + return a - b + c; } - function shiftRSub( + function subSub( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a >> (b - c); + return a - b - c; } - function shiftRMul( + function subMul( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a >> (b * c); + return a - b * c; } - function shiftRDiv( + function subDiv( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a >> (b / c); + return a - b / c; } - function shiftRMod( + function subMod( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a >> b % c; + return a - (b % c); } - function shiftRExp( + function subExp( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a >> (b ** c); + return a - b ** c; } - function shiftRShiftL( + function subShiftL( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a >> b) << c; + return (a - b) << c; } - function shiftRShiftR( + function subShiftR( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a >> b) >> c; + return (a - b) >> c; } - function shiftRBitAnd( + function subBitAnd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a >> b) & c; + return (a - b) & c; } - function shiftRBitOr( + function subBitOr( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a >> b) | c; + return (a - b) | c; } - function shiftRBitXor( + function subBitXor( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a >> b) ^ c; + return (a - b) ^ c; } } ================================================================================ `; -exports[`SubNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` +exports[`SubNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["solidity-parse"] +parsers: ["solidity-slang-parse"] printWidth: 80 | printWidth =====================================input====================================== @@ -2124,9 +4219,7 @@ contract SubNoParentheses { } =====================================output===================================== -// SPDX-License-Identifier: MIT pragma solidity 0.8.25; - contract SubNoParentheses { function subAdd( uint256 a, @@ -2135,7 +4228,6 @@ contract SubNoParentheses { ) public pure returns (uint256) { return a - b + c; } - function subSub( uint256 a, uint256 b, @@ -2143,7 +4235,6 @@ contract SubNoParentheses { ) public pure returns (uint256) { return a - b - c; } - function subMul( uint256 a, uint256 b, @@ -2151,7 +4242,6 @@ contract SubNoParentheses { ) public pure returns (uint256) { return a - b * c; } - function subDiv( uint256 a, uint256 b, @@ -2159,15 +4249,13 @@ contract SubNoParentheses { ) public pure returns (uint256) { return a - b / c; } - function subMod( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a - (b % c); + return a - b % c; } - function subExp( uint256 a, uint256 b, @@ -2175,45 +4263,40 @@ contract SubNoParentheses { ) public pure returns (uint256) { return a - b ** c; } - function subShiftL( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a - b) << c; + return a - b << c; } - function subShiftR( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a - b) >> c; + return a - b >> c; } - function subBitAnd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a - b) & c; + return a - b & c; } - function subBitOr( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a - b) | c; + return a - b | c; } - function subBitXor( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a - b) ^ c; + return a - b ^ c; } } diff --git a/tests/format/Parentheses/jsfmt.spec.js b/tests/format/Parentheses/jsfmt.spec.js index 8c772cba0..8012ac6cd 100644 --- a/tests/format/Parentheses/jsfmt.spec.js +++ b/tests/format/Parentheses/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse'], { compiler: '0.8.6' }); +run_spec(import.meta, ['solidity-slang-parse'], { compiler: '0.8.6' }); diff --git a/tests/format/Pragma/Pragma.sol b/tests/format/Pragma/Pragma.sol index fd7f026f1..9ba96701f 100644 --- a/tests/format/Pragma/Pragma.sol +++ b/tests/format/Pragma/Pragma.sol @@ -6,3 +6,5 @@ pragma solidity >=0.4.21<0.6.0; pragma solidity ^ 0.4.21 ; pragma solidity ~ 0.4.21 ; pragma solidity ^0.5.0 || ^0.6.0 || ^0.7.0 ; +pragma experimental ABIEncoderV2; +pragma abicoder v2; diff --git a/tests/format/Pragma/__snapshots__/jsfmt.spec.js.snap b/tests/format/Pragma/__snapshots__/jsfmt.spec.js.snap index c613c56b7..08d535336 100644 --- a/tests/format/Pragma/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Pragma/__snapshots__/jsfmt.spec.js.snap @@ -14,6 +14,8 @@ pragma solidity >=0.4.21<0.6.0; pragma solidity ^ 0.4.21 ; pragma solidity ~ 0.4.21 ; pragma solidity ^0.5.0 || ^0.6.0 || ^0.7.0 ; +pragma experimental ABIEncoderV2; +pragma abicoder v2; =====================================output===================================== pragma solidity >=0.4.21 <0.6.0; @@ -24,6 +26,40 @@ pragma solidity >=0.4.21 <0.6.0; pragma solidity ^0.4.21; pragma solidity ~0.4.21; pragma solidity ^0.5.0 || ^0.6.0 || ^0.7.0; +pragma experimental ABIEncoderV2; +pragma abicoder v2; + +================================================================================ +`; + +exports[`Pragma.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity >=0.4.21 <0.6.0; +pragma solidity >=0.4.21 <=0.6.0 ; +pragma solidity >0.4.21 <0.6.0; +pragma solidity >0.4.21 <=0.6.0; +pragma solidity >=0.4.21<0.6.0; +pragma solidity ^ 0.4.21 ; +pragma solidity ~ 0.4.21 ; +pragma solidity ^0.5.0 || ^0.6.0 || ^0.7.0 ; +pragma experimental ABIEncoderV2; +pragma abicoder v2; + +=====================================output===================================== +pragma solidity >=0.4.21 <0.6.0; +pragma solidity >=0.4.21 <=0.6.0; +pragma solidity >0.4.21 <0.6.0; +pragma solidity >0.4.21 <=0.6.0; +pragma solidity >=0.4.21 <0.6.0; +pragma solidity ^0.4.21; +pragma solidity ~0.4.21; +pragma solidity ^0.5.0||^0.6.0||^0.7.0; +pragma experimental ABIEncoderV2; +pragma abicoder v2; ================================================================================ `; diff --git a/tests/format/Pragma/jsfmt.spec.js b/tests/format/Pragma/jsfmt.spec.js index 765dd60a6..fd56c17bc 100644 --- a/tests/format/Pragma/jsfmt.spec.js +++ b/tests/format/Pragma/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse']); From 4920d6d19d12c32b258467a46ac82f154b856d03 Mon Sep 17 00:00:00 2001 From: Klaus Date: Sat, 15 Jun 2024 11:29:15 +1200 Subject: [PATCH 027/160] WIP: 204/215 printers implemented Tests passing without altering the AST --- src/slang-nodes/BreakStatement.js | 3 +- src/slang-nodes/ConditionalExpression.js | 29 +- src/slang-nodes/InterfaceDefinition.js | 4 +- src/slang-nodes/LibraryDefinition.js | 11 +- src/slang-nodes/LibraryMembers.js | 17 +- src/slang-nodes/StateVariableAttributes.js | 2 +- tests/config/format-test.js | 1 + .../AllSolidityFeatures.sol | 1 - .../__snapshots__/jsfmt.spec.js.snap | 2 - .../__snapshots__/jsfmt.spec.js.snap | 70 +- ...efinitions.sol => FunctionDefinitions.sol} | 0 .../__snapshots__/jsfmt.spec.js.snap | 4 +- tests/format/HexLiteral/HexLiteral.sol | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 16 +- .../ModifierInvocations.sol | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 8 +- tests/format/NumberLiteral/NumberLiteral.sol | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 8 +- tests/format/Parentheses/AddNoParentheses.sol | 2 +- .../Parentheses/BitAndNoParentheses.sol | 2 +- .../format/Parentheses/BitOrNoParentheses.sol | 2 +- .../Parentheses/BitXorNoParentheses.sol | 2 +- tests/format/Parentheses/DivNoParentheses.sol | 2 +- tests/format/Parentheses/ExpNoParentheses.sol | 2 +- .../format/Parentheses/LogicNoParentheses.sol | 2 +- tests/format/Parentheses/ModNoParentheses.sol | 2 +- tests/format/Parentheses/MulNoParentheses.sol | 2 +- .../Parentheses/ShiftLNoParentheses.sol | 2 +- .../Parentheses/ShiftRNoParentheses.sol | 2 +- tests/format/Parentheses/SubNoParentheses.sol | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 96 +- .../__snapshots__/jsfmt.spec.js.snap | 90 ++ tests/format/SampleCrowdsale/jsfmt.spec.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 178 +++ tests/format/SimpleAuction/jsfmt.spec.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 125 ++ .../format/SplittableCommodity/jsfmt.spec.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 851 ++++++++++-- tests/format/StyleGuide/jsfmt.spec.js | 1 + .../strings/__snapshots__/jsfmt.spec.js.snap | 1237 +++++++++++++++++ tests/format/strings/jsfmt.spec.js | 1 + 43 files changed, 2568 insertions(+), 224 deletions(-) rename tests/format/FunctionDefinitionsv0.5.0/{DefaultFunctionDefinitions.sol => FunctionDefinitions.sol} (100%) diff --git a/src/slang-nodes/BreakStatement.js b/src/slang-nodes/BreakStatement.js index fea103926..3bc49e3f3 100644 --- a/src/slang-nodes/BreakStatement.js +++ b/src/slang-nodes/BreakStatement.js @@ -4,6 +4,5 @@ export const BreakStatement = { breakKeyword: ast.breakKeyword.text, semicolon: ast.semicolon.text }), - // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: BreakStatement'] + print: ({ node }) => `${node.breakKeyword}${node.semicolon}` }; diff --git a/src/slang-nodes/ConditionalExpression.js b/src/slang-nodes/ConditionalExpression.js index 8d93b2894..44d2bfabb 100644 --- a/src/slang-nodes/ConditionalExpression.js +++ b/src/slang-nodes/ConditionalExpression.js @@ -87,14 +87,27 @@ const traditionalTernaries = (node, path, print) => ]); export const ConditionalExpression = { - parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, - operand: parse(ast.operand, options, parse), - questionMark: ast.questionMark.text, - trueExpression: parse(ast.trueExpression, options, parse), - colon: ast.colon.text, - falseExpression: parse(ast.falseExpression, options, parse) - }), + parse: ({ ast, options, parse }) => { + let operand = parse(ast.operand, options, parse); + + while ( + operand.variant.kind === 'TupleExpression' && + operand.variant.items.items.length === 1 && + operand.variant.items.items[0].expression.variant.kind !== + 'ConditionalExpression' + ) { + operand = operand.variant.items.items[0].expression; + } + + return { + kind: ast.cst.kind, + operand, + questionMark: ast.questionMark.text, + trueExpression: parse(ast.trueExpression, options, parse), + colon: ast.colon.text, + falseExpression: parse(ast.falseExpression, options, parse) + }; + }, print: ({ node, path, print, options }) => options.experimentalTernaries ? experimentalTernaries(node, path, print, options) diff --git a/src/slang-nodes/InterfaceDefinition.js b/src/slang-nodes/InterfaceDefinition.js index 015afa83f..7382939a8 100644 --- a/src/slang-nodes/InterfaceDefinition.js +++ b/src/slang-nodes/InterfaceDefinition.js @@ -7,8 +7,8 @@ export const InterfaceDefinition = { kind: ast.cst.kind, interfaceKeyword: ast.interfaceKeyword.text, name: ast.name.text, - inheritence: ast.inheritence - ? parse(ast.inheritence, options, parse) + inheritance: ast.inheritence + ? parse(ast.inheritance, options, parse) : undefined, openBrace: ast.openBrace.text, members: parse(ast.members, options, parse), diff --git a/src/slang-nodes/LibraryDefinition.js b/src/slang-nodes/LibraryDefinition.js index caf580b90..78b5d245b 100644 --- a/src/slang-nodes/LibraryDefinition.js +++ b/src/slang-nodes/LibraryDefinition.js @@ -1,3 +1,7 @@ +import { doc } from 'prettier'; + +const { group, line } = doc.builders; + export const LibraryDefinition = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, @@ -7,6 +11,9 @@ export const LibraryDefinition = { members: parse(ast.members, options, parse), closeBrace: ast.closeBrace.text }), - // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: LibraryDefinition'] + print: ({ node, path, print }) => [ + group([`${node.libraryKeyword} ${node.name}`, line, node.openBrace]), + path.call(print, 'members'), + node.closeBrace + ] }; diff --git a/src/slang-nodes/LibraryMembers.js b/src/slang-nodes/LibraryMembers.js index 291df3910..ac2d1bbc9 100644 --- a/src/slang-nodes/LibraryMembers.js +++ b/src/slang-nodes/LibraryMembers.js @@ -1,8 +1,21 @@ +import { doc } from 'prettier'; +import { + printPreservingEmptyLines, + printSeparatedItem +} from '../common/printer-helpers.js'; + +const { hardline } = doc.builders; + export const LibraryMembers = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), - // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: LibraryMembers'] + print: ({ node, path, print, options }) => + node.items.length > 0 + ? printSeparatedItem( + printPreservingEmptyLines(path, 'items', options, print), + { firstSeparator: hardline, grouped: false } + ) + : '' }; diff --git a/src/slang-nodes/StateVariableAttributes.js b/src/slang-nodes/StateVariableAttributes.js index 3816e97f0..2eb593bba 100644 --- a/src/slang-nodes/StateVariableAttributes.js +++ b/src/slang-nodes/StateVariableAttributes.js @@ -4,5 +4,5 @@ export const StateVariableAttributes = { items: ast.items.map((item) => parse(item, options, parse)) }), print: ({ node, path, print }) => - node.items.length ? [' ', path.map(print, 'items')] : '' + node.items.length ? path.map(print, 'items').map((item) => [' ', item]) : '' }; diff --git a/tests/config/format-test.js b/tests/config/format-test.js index 7c3a3ed74..ec88285bc 100644 --- a/tests/config/format-test.js +++ b/tests/config/format-test.js @@ -83,6 +83,7 @@ const isAstUnstable = (filename, options) => { }; const shouldCompareBytecode = (filename, options) => { + if (options.parser === "solidity-slang-parse") return false; const testFunction = testsWithAstChanges.get(filename); if (!testFunction) { diff --git a/tests/format/AllSolidityFeatures/AllSolidityFeatures.sol b/tests/format/AllSolidityFeatures/AllSolidityFeatures.sol index 58b5ed853..b412eba23 100644 --- a/tests/format/AllSolidityFeatures/AllSolidityFeatures.sol +++ b/tests/format/AllSolidityFeatures/AllSolidityFeatures.sol @@ -8,7 +8,6 @@ pragma experimental ABIEncoderV2; import "SomeFile.sol"; import "SomeFile.sol" as SomeOtherFile; import * as SomeSymbol from "AnotherFile.sol"; -import {symbol1 as alias, symbol2} from "File.sol"; interface i { event ForeignEvent(); diff --git a/tests/format/AllSolidityFeatures/__snapshots__/jsfmt.spec.js.snap b/tests/format/AllSolidityFeatures/__snapshots__/jsfmt.spec.js.snap index 5955de940..092296212 100644 --- a/tests/format/AllSolidityFeatures/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/AllSolidityFeatures/__snapshots__/jsfmt.spec.js.snap @@ -16,7 +16,6 @@ pragma experimental ABIEncoderV2; import "SomeFile.sol"; import "SomeFile.sol" as SomeOtherFile; import * as SomeSymbol from "AnotherFile.sol"; -import {symbol1 as alias, symbol2} from "File.sol"; interface i { event ForeignEvent(); @@ -564,7 +563,6 @@ pragma experimental ABIEncoderV2; import "SomeFile.sol"; import "SomeFile.sol" as SomeOtherFile; import "AnotherFile.sol" as SomeSymbol; -import {symbol1 as alias, symbol2} from "File.sol"; interface i { event ForeignEvent(); diff --git a/tests/format/ExperimentalTernaries/__snapshots__/jsfmt.spec.js.snap b/tests/format/ExperimentalTernaries/__snapshots__/jsfmt.spec.js.snap index ea38f9fe5..6685c733e 100644 --- a/tests/format/ExperimentalTernaries/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/ExperimentalTernaries/__snapshots__/jsfmt.spec.js.snap @@ -900,7 +900,7 @@ contract Conditional { : definition.defaults : row[field] ); - (((foo ? 1 : bar))) ? 3 : 4; + (foo ? 1 : bar) ? 3 : 4; ( isCat() ? meow() : isDog() ? bark() @@ -1870,7 +1870,7 @@ contract Conditional { : definition.defaults : row[field] ); - (((foo ? 1 : bar))) ? 3 : 4; + (foo ? 1 : bar) ? 3 : 4; ( isCat() ? meow() : isDog() ? bark() @@ -2838,7 +2838,7 @@ contract Conditional { : definition.defaults : row[field] ); - (((foo ? 1 : bar))) ? 3 : 4; + (foo ? 1 : bar) ? 3 : 4; ( isCat() ? meow() : isDog() ? bark() @@ -3753,34 +3753,26 @@ contract Conditional { : someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens(); - string storage multilineConditionsConsequentsAndAlternates = ( - isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) + string storage multilineConditionsConsequentsAndAlternates = isAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) ? someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens() - : ( - isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) + : isNotAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) ? bark() : shortCondition() ? shortConsequent() : someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens(); - assignment = ( - isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) + assignment = isAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) ? someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens() - : ( - isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) + : isNotAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) ? bark() : shortCondition() ? shortConsequent() @@ -3793,35 +3785,27 @@ contract Conditional { ? "two" : x == 3 ? "three" - : ( - x == 5 && - y == 7 && - someOtherThing - .thatIsSoLong - .thatItBreaksTheTestCondition() - ) + : x == 5 && + y == 7 && + someOtherThing + .thatIsSoLong + .thatItBreaksTheTestCondition() ? "four" : x == 6 ? "six" : "idk"; - string storage longConditional = ( - bifornCringerMoshedPerplexSawder == - 2 / - askTrovenaBeenaDependsRowans && - glimseGlyphsHazardNoopsTieTie >= - averredBathersBoxroomBuggyNurl() - .anodyneCondosMalateOverateRetinol() - ) + string storage longConditional = bifornCringerMoshedPerplexSawder == + 2 / + askTrovenaBeenaDependsRowans && + glimseGlyphsHazardNoopsTieTie >= + averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() ? "foo" : "bar"; - string storage longConditionalChained = ( - bifornCringerMoshedPerplexSawder == - 2 / - askTrovenaBeenaDependsRowans && - glimseGlyphsHazardNoopsTieTie >= - averredBathersBoxroomBuggyNurl() - .anodyneCondosMalateOverateRetinol() - ) + string storage longConditionalChained = bifornCringerMoshedPerplexSawder == + 2 / + askTrovenaBeenaDependsRowans && + glimseGlyphsHazardNoopsTieTie >= + averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() ? "foo" : anotherCondition ? "bar" @@ -3838,7 +3822,7 @@ contract Conditional { : definition.defaults : row[field] ); - (((foo ? 1 : bar))) ? 3 : 4; + (foo ? 1 : bar) ? 3 : 4; ( isCat() ? meow() diff --git a/tests/format/FunctionDefinitionsv0.5.0/DefaultFunctionDefinitions.sol b/tests/format/FunctionDefinitionsv0.5.0/FunctionDefinitions.sol similarity index 100% rename from tests/format/FunctionDefinitionsv0.5.0/DefaultFunctionDefinitions.sol rename to tests/format/FunctionDefinitionsv0.5.0/FunctionDefinitions.sol diff --git a/tests/format/FunctionDefinitionsv0.5.0/__snapshots__/jsfmt.spec.js.snap b/tests/format/FunctionDefinitionsv0.5.0/__snapshots__/jsfmt.spec.js.snap index d430c10b2..43dd005ee 100644 --- a/tests/format/FunctionDefinitionsv0.5.0/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/FunctionDefinitionsv0.5.0/__snapshots__/jsfmt.spec.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`DefaultFunctionDefinitions.sol - {"compiler":"0.5.0"} format 1`] = ` +exports[`FunctionDefinitions.sol - {"compiler":"0.5.0"} format 1`] = ` ====================================options===================================== compiler: "0.5.0" parsers: ["solidity-slang-parse"] @@ -21,7 +21,7 @@ contract FunctionDefinitions { ================================================================================ `; -exports[`DefaultFunctionDefinitions.sol format 1`] = ` +exports[`FunctionDefinitions.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] printWidth: 80 diff --git a/tests/format/HexLiteral/HexLiteral.sol b/tests/format/HexLiteral/HexLiteral.sol index 55475ced6..801c035c8 100644 --- a/tests/format/HexLiteral/HexLiteral.sol +++ b/tests/format/HexLiteral/HexLiteral.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract HexLiteral { bytes8 hex1 = hex'DeadBeef'; diff --git a/tests/format/HexLiteral/__snapshots__/jsfmt.spec.js.snap b/tests/format/HexLiteral/__snapshots__/jsfmt.spec.js.snap index 527cd97d7..27f5134e5 100644 --- a/tests/format/HexLiteral/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/HexLiteral/__snapshots__/jsfmt.spec.js.snap @@ -9,7 +9,7 @@ singleQuote: false | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract HexLiteral { bytes8 hex1 = hex'DeadBeef'; @@ -17,7 +17,7 @@ contract HexLiteral { } =====================================output===================================== -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract HexLiteral { bytes8 hex1 = hex"DeadBeef"; bytes8 hex2 = hex"DeadBeef"; @@ -35,7 +35,7 @@ singleQuote: true | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract HexLiteral { bytes8 hex1 = hex'DeadBeef'; @@ -43,7 +43,7 @@ contract HexLiteral { } =====================================output===================================== -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract HexLiteral { bytes8 hex1 = hex'DeadBeef'; bytes8 hex2 = hex'DeadBeef'; @@ -60,7 +60,7 @@ singleQuote: false | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract HexLiteral { bytes8 hex1 = hex'DeadBeef'; @@ -69,7 +69,7 @@ contract HexLiteral { =====================================output===================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract HexLiteral { bytes8 hex1 = hex"DeadBeef"; @@ -87,7 +87,7 @@ singleQuote: true | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract HexLiteral { bytes8 hex1 = hex'DeadBeef'; @@ -96,7 +96,7 @@ contract HexLiteral { =====================================output===================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract HexLiteral { bytes8 hex1 = hex'DeadBeef'; diff --git a/tests/format/ModifierInvocations/ModifierInvocations.sol b/tests/format/ModifierInvocations/ModifierInvocations.sol index fa682679d..ca5cc9d14 100644 --- a/tests/format/ModifierInvocations/ModifierInvocations.sol +++ b/tests/format/ModifierInvocations/ModifierInvocations.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract ModifierDefinitions { // We enforce the use of parentheses in modifiers without parameters. diff --git a/tests/format/ModifierInvocations/__snapshots__/jsfmt.spec.js.snap b/tests/format/ModifierInvocations/__snapshots__/jsfmt.spec.js.snap index df076fb83..737687ba3 100644 --- a/tests/format/ModifierInvocations/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/ModifierInvocations/__snapshots__/jsfmt.spec.js.snap @@ -7,7 +7,7 @@ printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract ModifierDefinitions { // We enforce the use of parentheses in modifiers without parameters. @@ -26,7 +26,7 @@ contract ModifierInvocations is ModifierDefinitions { =====================================output===================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract ModifierDefinitions { // We enforce the use of parentheses in modifiers without parameters. @@ -57,7 +57,7 @@ printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract ModifierDefinitions { // We enforce the use of parentheses in modifiers without parameters. @@ -75,7 +75,7 @@ contract ModifierInvocations is ModifierDefinitions { } =====================================output===================================== -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract ModifierDefinitions { modifier emptyParams { _; diff --git a/tests/format/NumberLiteral/NumberLiteral.sol b/tests/format/NumberLiteral/NumberLiteral.sol index 1c03f5792..1a5ecf899 100644 --- a/tests/format/NumberLiteral/NumberLiteral.sol +++ b/tests/format/NumberLiteral/NumberLiteral.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract NumberLiteral { function numbers()public { diff --git a/tests/format/NumberLiteral/__snapshots__/jsfmt.spec.js.snap b/tests/format/NumberLiteral/__snapshots__/jsfmt.spec.js.snap index e40fbabd7..6f1a2233a 100644 --- a/tests/format/NumberLiteral/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/NumberLiteral/__snapshots__/jsfmt.spec.js.snap @@ -7,7 +7,7 @@ printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract NumberLiteral { function numbers()public { @@ -22,7 +22,7 @@ contract NumberLiteral { =====================================output===================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract NumberLiteral { function numbers() public { @@ -45,7 +45,7 @@ printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract NumberLiteral { function numbers()public { @@ -59,7 +59,7 @@ contract NumberLiteral { } =====================================output===================================== -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract NumberLiteral { function numbers() public { 2 ether; diff --git a/tests/format/Parentheses/AddNoParentheses.sol b/tests/format/Parentheses/AddNoParentheses.sol index 2f4dc533c..92c74ffd8 100644 --- a/tests/format/Parentheses/AddNoParentheses.sol +++ b/tests/format/Parentheses/AddNoParentheses.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract AddNoParentheses { function addAdd(uint256 a, uint256 b, uint256 c) diff --git a/tests/format/Parentheses/BitAndNoParentheses.sol b/tests/format/Parentheses/BitAndNoParentheses.sol index d592e0ea0..7c0019361 100644 --- a/tests/format/Parentheses/BitAndNoParentheses.sol +++ b/tests/format/Parentheses/BitAndNoParentheses.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract BitAndNoParentheses { function bitAndAdd(uint256 a, uint256 b, uint256 c) diff --git a/tests/format/Parentheses/BitOrNoParentheses.sol b/tests/format/Parentheses/BitOrNoParentheses.sol index bf5b29eb6..b84dc7766 100644 --- a/tests/format/Parentheses/BitOrNoParentheses.sol +++ b/tests/format/Parentheses/BitOrNoParentheses.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract BitOrNoParentheses { function bitOrAdd(uint256 a, uint256 b, uint256 c) diff --git a/tests/format/Parentheses/BitXorNoParentheses.sol b/tests/format/Parentheses/BitXorNoParentheses.sol index 7f30eb2ea..40d7e65a6 100644 --- a/tests/format/Parentheses/BitXorNoParentheses.sol +++ b/tests/format/Parentheses/BitXorNoParentheses.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract BitXorNoParentheses { function bitXorAdd(uint256 a, uint256 b, uint256 c) diff --git a/tests/format/Parentheses/DivNoParentheses.sol b/tests/format/Parentheses/DivNoParentheses.sol index b146d5a20..c1cff9015 100644 --- a/tests/format/Parentheses/DivNoParentheses.sol +++ b/tests/format/Parentheses/DivNoParentheses.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract DivNoParentheses { function divAdd(uint256 a, uint256 b, uint256 c) diff --git a/tests/format/Parentheses/ExpNoParentheses.sol b/tests/format/Parentheses/ExpNoParentheses.sol index 945085bb7..c0da2106e 100644 --- a/tests/format/Parentheses/ExpNoParentheses.sol +++ b/tests/format/Parentheses/ExpNoParentheses.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract ExpNoParentheses { function expAdd(uint256 a, uint256 b, uint256 c) diff --git a/tests/format/Parentheses/LogicNoParentheses.sol b/tests/format/Parentheses/LogicNoParentheses.sol index b4803303e..d2db6ec4a 100644 --- a/tests/format/Parentheses/LogicNoParentheses.sol +++ b/tests/format/Parentheses/LogicNoParentheses.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract LogicNoParentheses { function orOr(bool a, bool b, bool c) public pure returns (bool) { diff --git a/tests/format/Parentheses/ModNoParentheses.sol b/tests/format/Parentheses/ModNoParentheses.sol index b0a63aba3..448edd779 100644 --- a/tests/format/Parentheses/ModNoParentheses.sol +++ b/tests/format/Parentheses/ModNoParentheses.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract ModNoParentheses { function modAdd(uint256 a, uint256 b, uint256 c) diff --git a/tests/format/Parentheses/MulNoParentheses.sol b/tests/format/Parentheses/MulNoParentheses.sol index 88c802dde..941ab6e4d 100644 --- a/tests/format/Parentheses/MulNoParentheses.sol +++ b/tests/format/Parentheses/MulNoParentheses.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract MulNoParentheses { function mulAdd(uint256 a, uint256 b, uint256 c) diff --git a/tests/format/Parentheses/ShiftLNoParentheses.sol b/tests/format/Parentheses/ShiftLNoParentheses.sol index 13d7f1461..1ba14bdae 100644 --- a/tests/format/Parentheses/ShiftLNoParentheses.sol +++ b/tests/format/Parentheses/ShiftLNoParentheses.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract ShiftLNoParentheses { function shiftLAdd(uint256 a, uint256 b, uint256 c) diff --git a/tests/format/Parentheses/ShiftRNoParentheses.sol b/tests/format/Parentheses/ShiftRNoParentheses.sol index ad8034121..a78c4b393 100644 --- a/tests/format/Parentheses/ShiftRNoParentheses.sol +++ b/tests/format/Parentheses/ShiftRNoParentheses.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract ShiftRNoParentheses { function shiftRAdd(uint256 a, uint256 b, uint256 c) diff --git a/tests/format/Parentheses/SubNoParentheses.sol b/tests/format/Parentheses/SubNoParentheses.sol index 04789e1c6..31eacaed8 100644 --- a/tests/format/Parentheses/SubNoParentheses.sol +++ b/tests/format/Parentheses/SubNoParentheses.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract SubNoParentheses { function subAdd(uint256 a, uint256 b, uint256 c) diff --git a/tests/format/Parentheses/__snapshots__/jsfmt.spec.js.snap b/tests/format/Parentheses/__snapshots__/jsfmt.spec.js.snap index 9bde97ec7..0992b9291 100644 --- a/tests/format/Parentheses/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Parentheses/__snapshots__/jsfmt.spec.js.snap @@ -8,7 +8,7 @@ printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract AddNoParentheses { function addAdd(uint256 a, uint256 b, uint256 c) @@ -102,7 +102,7 @@ contract AddNoParentheses { =====================================output===================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract AddNoParentheses { function addAdd( @@ -205,7 +205,7 @@ printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract AddNoParentheses { function addAdd(uint256 a, uint256 b, uint256 c) @@ -298,7 +298,7 @@ contract AddNoParentheses { } =====================================output===================================== -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract AddNoParentheses { function addAdd( uint256 a, @@ -390,7 +390,7 @@ printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract BitAndNoParentheses { function bitAndAdd(uint256 a, uint256 b, uint256 c) @@ -484,7 +484,7 @@ contract BitAndNoParentheses { =====================================output===================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract BitAndNoParentheses { function bitAndAdd( @@ -587,7 +587,7 @@ printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract BitAndNoParentheses { function bitAndAdd(uint256 a, uint256 b, uint256 c) @@ -680,7 +680,7 @@ contract BitAndNoParentheses { } =====================================output===================================== -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract BitAndNoParentheses { function bitAndAdd( uint256 a, @@ -772,7 +772,7 @@ printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract BitOrNoParentheses { function bitOrAdd(uint256 a, uint256 b, uint256 c) @@ -866,7 +866,7 @@ contract BitOrNoParentheses { =====================================output===================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract BitOrNoParentheses { function bitOrAdd( @@ -969,7 +969,7 @@ printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract BitOrNoParentheses { function bitOrAdd(uint256 a, uint256 b, uint256 c) @@ -1062,7 +1062,7 @@ contract BitOrNoParentheses { } =====================================output===================================== -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract BitOrNoParentheses { function bitOrAdd( uint256 a, @@ -1154,7 +1154,7 @@ printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract BitXorNoParentheses { function bitXorAdd(uint256 a, uint256 b, uint256 c) @@ -1248,7 +1248,7 @@ contract BitXorNoParentheses { =====================================output===================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract BitXorNoParentheses { function bitXorAdd( @@ -1351,7 +1351,7 @@ printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract BitXorNoParentheses { function bitXorAdd(uint256 a, uint256 b, uint256 c) @@ -1444,7 +1444,7 @@ contract BitXorNoParentheses { } =====================================output===================================== -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract BitXorNoParentheses { function bitXorAdd( uint256 a, @@ -1536,7 +1536,7 @@ printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract DivNoParentheses { function divAdd(uint256 a, uint256 b, uint256 c) @@ -1630,7 +1630,7 @@ contract DivNoParentheses { =====================================output===================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract DivNoParentheses { function divAdd( @@ -1733,7 +1733,7 @@ printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract DivNoParentheses { function divAdd(uint256 a, uint256 b, uint256 c) @@ -1826,7 +1826,7 @@ contract DivNoParentheses { } =====================================output===================================== -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract DivNoParentheses { function divAdd( uint256 a, @@ -1918,7 +1918,7 @@ printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract ExpNoParentheses { function expAdd(uint256 a, uint256 b, uint256 c) @@ -2012,7 +2012,7 @@ contract ExpNoParentheses { =====================================output===================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract ExpNoParentheses { function expAdd( @@ -2115,7 +2115,7 @@ printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract ExpNoParentheses { function expAdd(uint256 a, uint256 b, uint256 c) @@ -2208,7 +2208,7 @@ contract ExpNoParentheses { } =====================================output===================================== -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract ExpNoParentheses { function expAdd( uint256 a, @@ -2300,7 +2300,7 @@ printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract LogicNoParentheses { function orOr(bool a, bool b, bool c) public pure returns (bool) { @@ -2322,7 +2322,7 @@ contract LogicNoParentheses { =====================================output===================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract LogicNoParentheses { function orOr(bool a, bool b, bool c) public pure returns (bool) { @@ -2353,7 +2353,7 @@ printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract LogicNoParentheses { function orOr(bool a, bool b, bool c) public pure returns (bool) { @@ -2374,7 +2374,7 @@ contract LogicNoParentheses { } =====================================output===================================== -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract LogicNoParentheses { function orOr(bool a, bool b, bool c) public pure returns (bool) { return a || b || c; @@ -2401,7 +2401,7 @@ printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract ModNoParentheses { function modAdd(uint256 a, uint256 b, uint256 c) @@ -2495,7 +2495,7 @@ contract ModNoParentheses { =====================================output===================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract ModNoParentheses { function modAdd( @@ -2598,7 +2598,7 @@ printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract ModNoParentheses { function modAdd(uint256 a, uint256 b, uint256 c) @@ -2691,7 +2691,7 @@ contract ModNoParentheses { } =====================================output===================================== -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract ModNoParentheses { function modAdd( uint256 a, @@ -2783,7 +2783,7 @@ printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract MulNoParentheses { function mulAdd(uint256 a, uint256 b, uint256 c) @@ -2877,7 +2877,7 @@ contract MulNoParentheses { =====================================output===================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract MulNoParentheses { function mulAdd( @@ -2980,7 +2980,7 @@ printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract MulNoParentheses { function mulAdd(uint256 a, uint256 b, uint256 c) @@ -3073,7 +3073,7 @@ contract MulNoParentheses { } =====================================output===================================== -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract MulNoParentheses { function mulAdd( uint256 a, @@ -3165,7 +3165,7 @@ printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract ShiftLNoParentheses { function shiftLAdd(uint256 a, uint256 b, uint256 c) @@ -3259,7 +3259,7 @@ contract ShiftLNoParentheses { =====================================output===================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract ShiftLNoParentheses { function shiftLAdd( @@ -3362,7 +3362,7 @@ printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract ShiftLNoParentheses { function shiftLAdd(uint256 a, uint256 b, uint256 c) @@ -3455,7 +3455,7 @@ contract ShiftLNoParentheses { } =====================================output===================================== -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract ShiftLNoParentheses { function shiftLAdd( uint256 a, @@ -3547,7 +3547,7 @@ printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract ShiftRNoParentheses { function shiftRAdd(uint256 a, uint256 b, uint256 c) @@ -3641,7 +3641,7 @@ contract ShiftRNoParentheses { =====================================output===================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract ShiftRNoParentheses { function shiftRAdd( @@ -3744,7 +3744,7 @@ printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract ShiftRNoParentheses { function shiftRAdd(uint256 a, uint256 b, uint256 c) @@ -3837,7 +3837,7 @@ contract ShiftRNoParentheses { } =====================================output===================================== -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract ShiftRNoParentheses { function shiftRAdd( uint256 a, @@ -3929,7 +3929,7 @@ printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract SubNoParentheses { function subAdd(uint256 a, uint256 b, uint256 c) @@ -4023,7 +4023,7 @@ contract SubNoParentheses { =====================================output===================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract SubNoParentheses { function subAdd( @@ -4126,7 +4126,7 @@ printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract SubNoParentheses { function subAdd(uint256 a, uint256 b, uint256 c) @@ -4219,7 +4219,7 @@ contract SubNoParentheses { } =====================================output===================================== -pragma solidity 0.8.25; +pragma solidity 0.8.26; contract SubNoParentheses { function subAdd( uint256 a, diff --git a/tests/format/SampleCrowdsale/__snapshots__/jsfmt.spec.js.snap b/tests/format/SampleCrowdsale/__snapshots__/jsfmt.spec.js.snap index 733a7d384..330af86f1 100644 --- a/tests/format/SampleCrowdsale/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/SampleCrowdsale/__snapshots__/jsfmt.spec.js.snap @@ -111,3 +111,93 @@ contract SampleCrowdsale is CappedCrowdsale, RefundableCrowdsale { ================================================================================ `; + +exports[`SampleCrowdsale.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity ^0.4.18; + +import "../crowdsale/CappedCrowdsale.sol"; +import "../crowdsale/RefundableCrowdsale.sol"; +import "../token/MintableToken.sol"; + +/** + * @title SampleCrowdsaleToken + * @dev Very simple ERC20 Token that can be minted. + * It is meant to be used in a crowdsale contract. + */ +contract SampleCrowdsaleToken is MintableToken { + + string public constant name = "Sample Crowdsale Token"; + string public constant symbol = "SCT"; + uint8 public constant decimals = 18; + +} + +/** + * @title SampleCrowdsale + * @dev This is an example of a fully fledged crowdsale. + * The way to add new features to a base crowdsale is by multiple inheritance. + * In this example we are providing following extensions: + * CappedCrowdsale - sets a max boundary for raised funds + * RefundableCrowdsale - set a min goal to be reached and returns funds if it's not met + * + * After adding multiple features it's good practice to run integration tests + * to ensure that subcontracts works together as intended. + */ +contract SampleCrowdsale is CappedCrowdsale, RefundableCrowdsale { + + function SampleCrowdsale(uint256 _startTime, uint256 _endTime, uint256 _rate, uint256 _goal, uint256 _cap, address _wallet) public + CappedCrowdsale(_cap) + FinalizableCrowdsale() + RefundableCrowdsale(_goal) + Crowdsale(_startTime, _endTime, _rate, _wallet) + { + //As goal needs to be met for a successful crowdsale + //the value needs to less or equal than a cap which is limit for accepted funds + require(_goal <= _cap); + } + + function createTokenContract() internal returns (MintableToken) { + return new SampleCrowdsaleToken(); + } + +} + +=====================================output===================================== +pragma solidity ^0.4.18; +import "../crowdsale/CappedCrowdsale.sol"; +import "../crowdsale/RefundableCrowdsale.sol"; +import "../token/MintableToken.sol"; +contract SampleCrowdsaleToken is MintableToken { + string public constant name = "Sample Crowdsale Token"; + string public constant symbol = "SCT"; + uint8 public constant decimals = 18; +} +contract SampleCrowdsale is CappedCrowdsale, RefundableCrowdsale { + function SampleCrowdsale( + uint256 _startTime, + uint256 _endTime, + uint256 _rate, + uint256 _goal, + uint256 _cap, + address _wallet + ) + public + CappedCrowdsale(_cap) + FinalizableCrowdsale() + RefundableCrowdsale(_goal) + Crowdsale(_startTime, _endTime, _rate, _wallet) + { + require(_goal <= _cap); + } + function createTokenContract() internal returns (MintableToken) { + return new SampleCrowdsaleToken(); + } +} + +================================================================================ +`; diff --git a/tests/format/SampleCrowdsale/jsfmt.spec.js b/tests/format/SampleCrowdsale/jsfmt.spec.js index 765dd60a6..fd56c17bc 100644 --- a/tests/format/SampleCrowdsale/jsfmt.spec.js +++ b/tests/format/SampleCrowdsale/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse']); diff --git a/tests/format/SimpleAuction/__snapshots__/jsfmt.spec.js.snap b/tests/format/SimpleAuction/__snapshots__/jsfmt.spec.js.snap index d980d9c1a..3b53b30dc 100644 --- a/tests/format/SimpleAuction/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/SimpleAuction/__snapshots__/jsfmt.spec.js.snap @@ -248,3 +248,181 @@ contract SimpleAuction { ================================================================================ `; + +exports[`SimpleAuction.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity ^0.4.22; + +contract SimpleAuction { + // Parameters of the auction. Times are either + // absolute unix timestamps (seconds since 1970-01-01) + // or time periods in seconds. + address public beneficiary; + uint public auctionEnd; + + // Current state of the auction. + address public highestBidder; + uint public highestBid; + + // Allowed withdrawals of previous bids + mapping(address => uint) pendingReturns; + + // Set to true at the end, disallows any change + bool ended; + + // Events that will be fired on changes. + event HighestBidIncreased(address bidder, uint amount); + event AuctionEnded(address winner, uint amount); + + // The following is a so-called natspec comment, + // recognizable by the three slashes. + // It will be shown when the user is asked to + // confirm a transaction. + + /// Create a simple auction with \`_biddingTime\` + /// seconds bidding time on behalf of the + /// beneficiary address \`_beneficiary\`. + constructor( + uint _biddingTime, + address _beneficiary + ) public { + beneficiary = _beneficiary; + auctionEnd = now + _biddingTime; + } + + /// Bid on the auction with the value sent + /// together with this transaction. + /// The value will only be refunded if the + /// auction is not won. + function bid() public payable { + // No arguments are necessary, all + // information is already part of + // the transaction. The keyword payable + // is required for the function to + // be able to receive Ether. + + // Revert the call if the bidding + // period is over. + require( + now <= auctionEnd, + "Auction already ended." + ); + + // If the bid is not higher, send the + // money back. + require( + msg.value > highestBid, + "There already is a higher bid." + ); + + if (highestBid != 0) { + // Sending back the money by simply using + // highestBidder.send(highestBid) is a security risk + // because it could execute an untrusted contract. + // It is always safer to let the recipients + // withdraw their money themselves. + pendingReturns[highestBidder] += highestBid; + } + highestBidder = msg.sender; + highestBid = msg.value; + emit HighestBidIncreased(msg.sender, msg.value); + } + + /// Withdraw a bid that was overbid. + function withdraw() public returns (bool) { + uint amount = pendingReturns[msg.sender]; + if (amount > 0) { + // It is important to set this to zero because the recipient + // can call this function again as part of the receiving call + // before \`send\` returns. + pendingReturns[msg.sender] = 0; + + if (!msg.sender.send(amount)) { + // No need to call throw here, just reset the amount owing + pendingReturns[msg.sender] = amount; + return false; + } + } + return true; + } + + /// End the auction and send the highest bid + /// to the beneficiary. + function auctionEnd() public { + // It is a good guideline to structure functions that interact + // with other contracts (i.e. they call functions or send Ether) + // into three phases: + // 1. checking conditions + // 2. performing actions (potentially changing conditions) + // 3. interacting with other contracts + // If these phases are mixed up, the other contract could call + // back into the current contract and modify the state or cause + // effects (ether payout) to be performed multiple times. + // If functions called internally include interaction with external + // contracts, they also have to be considered interaction with + // external contracts. + + // 1. Conditions + require(now >= auctionEnd, "Auction not yet ended."); + require(!ended, "auctionEnd has already been called."); + + // 2. Effects + ended = true; + emit AuctionEnded(highestBidder, highestBid); + + // 3. Interaction + beneficiary.transfer(highestBid); + } +} + +=====================================output===================================== +pragma solidity ^0.4.22; +contract SimpleAuction { + address public beneficiary; + uint public auctionEnd; + address public highestBidder; + uint public highestBid; + mapping(address => uint) pendingReturns; + bool ended; + event HighestBidIncreased(address bidder, uint amount); + event AuctionEnded(address winner, uint amount); + constructor(uint _biddingTime, address _beneficiary) public { + beneficiary = _beneficiary; + auctionEnd = now + _biddingTime; + } + function bid() public payable { + require(now <= auctionEnd, "Auction already ended."); + require(msg.value > highestBid, "There already is a higher bid."); + if (highestBid != 0) { + pendingReturns[highestBidder] += highestBid; + } + highestBidder = msg.sender; + highestBid = msg.value; + emit HighestBidIncreased(msg.sender, msg.value); + } + function withdraw() public returns (bool) { + uint amount = pendingReturns[msg.sender]; + if (amount > 0) { + pendingReturns[msg.sender] = 0; + if (!msg.sender.send(amount)) { + pendingReturns[msg.sender] = amount; + return false; + } + } + return true; + } + function auctionEnd() public { + require(now >= auctionEnd, "Auction not yet ended."); + require(!ended, "auctionEnd has already been called."); + ended = true; + emit AuctionEnded(highestBidder, highestBid); + beneficiary.transfer(highestBid); + } +} + +================================================================================ +`; diff --git a/tests/format/SimpleAuction/jsfmt.spec.js b/tests/format/SimpleAuction/jsfmt.spec.js index 765dd60a6..fd56c17bc 100644 --- a/tests/format/SimpleAuction/jsfmt.spec.js +++ b/tests/format/SimpleAuction/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse']); diff --git a/tests/format/SplittableCommodity/__snapshots__/jsfmt.spec.js.snap b/tests/format/SplittableCommodity/__snapshots__/jsfmt.spec.js.snap index 988eba232..c662b79f0 100644 --- a/tests/format/SplittableCommodity/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/SplittableCommodity/__snapshots__/jsfmt.spec.js.snap @@ -133,3 +133,128 @@ contract SplittableCommodity is MintableCommodity { ================================================================================ `; + +exports[`SplittableCommodity.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity ^0.4.24; + +import "./MintableCommodity.sol"; +import "../participant/ISupplier.sol"; +import "../../node_modules/zeppelin-solidity/contracts//math/SafeMath.sol"; + +contract SplittableCommodity is MintableCommodity { + using SafeMath for uint256; + + event Split(address indexed to, uint256 amount, uint64 parentId, address indexed operator, bytes operatorData); + + function split(uint _tokenId, address _to, uint256 _amount) public whenNotPaused { + address supplierProxy = IContractRegistry(contractRegistry).getLatestProxyAddr("Supplier"); + require( + msg.sender == IContractRegistry(contractRegistry).getLatestProxyAddr("FifoCrcMarket") || + ISupplier(supplierProxy).isAllowed(this, "IMintableCommodity"), + "Splitting can only be done when both the ISplittableCommodity interface is enabled and is called by a supplier or the FifoCrcMarket is used." + ); + + commodities[_tokenId].value = commodities[_tokenId].value.sub(_amount); + + CommodityLib.Commodity memory _commodity = CommodityLib.Commodity({ + category: uint64(1), + timeRegistered: uint64(now), // solium-disable-line + parentId: _tokenId, + value: _amount, + locked: false, + misc: commodities[_tokenId].misc + }); + uint newCRCId = commodities.push(_commodity).sub(1); + require(newCRCId <= 18446744073709551616, "You can only split a commodity if it is within a valid index range"); + + if(msg.sender == IContractRegistry(contractRegistry).getLatestProxyAddr("FifoCrcMarket")) { + _transfer(ownerOf(_tokenId), _to, newCRCId); + } else { + _transfer(msg.sender, _to, newCRCId); + } + + callRecipient( + msg.sender, + 0x0, + _to, + newCRCId, + "", + "", + false + ); + + emit Split( + _to, + _amount, + uint64(newCRCId), + msg.sender, + "" + ); + } +} + +=====================================output===================================== +pragma solidity ^0.4.24; +import "./MintableCommodity.sol"; +import "../participant/ISupplier.sol"; +import "../../node_modules/zeppelin-solidity/contracts//math/SafeMath.sol"; +contract SplittableCommodity is MintableCommodity { + using SafeMath for uint256; + event Split( + address indexed to, + uint256 amount, + uint64 parentId, + address indexed operator, + bytes operatorData + ); + function split( + uint _tokenId, + address _to, + uint256 _amount + ) public whenNotPaused { + address supplierProxy = IContractRegistry(contractRegistry) + .getLatestProxyAddr("Supplier"); + require( + msg.sender == + IContractRegistry(contractRegistry).getLatestProxyAddr( + "FifoCrcMarket" + ) || + ISupplier(supplierProxy).isAllowed(this, "IMintableCommodity"), + "Splitting can only be done when both the ISplittableCommodity interface is enabled and is called by a supplier or the FifoCrcMarket is used." + ); + commodities[_tokenId].value = commodities[_tokenId].value.sub(_amount); + CommodityLib.Commodity memory _commodity = CommodityLib.Commodity({ + category: uint64(1), + timeRegistered: uint64(now), + parentId: _tokenId, + value: _amount, + locked: false, + misc: commodities[_tokenId].misc + }); + uint newCRCId = commodities.push(_commodity).sub(1); + require( + newCRCId <= 18446744073709551616, + "You can only split a commodity if it is within a valid index range" + ); + if ( + msg.sender == + IContractRegistry(contractRegistry).getLatestProxyAddr( + "FifoCrcMarket" + ) + ) { + _transfer(ownerOf(_tokenId), _to, newCRCId); + } else { + _transfer(msg.sender, _to, newCRCId); + } + callRecipient(msg.sender, 0x0, _to, newCRCId, "", "", false); + emit Split(_to, _amount, uint64(newCRCId), msg.sender, ""); + } +} + +================================================================================ +`; diff --git a/tests/format/SplittableCommodity/jsfmt.spec.js b/tests/format/SplittableCommodity/jsfmt.spec.js index 765dd60a6..fd56c17bc 100644 --- a/tests/format/SplittableCommodity/jsfmt.spec.js +++ b/tests/format/SplittableCommodity/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse']); diff --git a/tests/format/StateVariableDeclarations/__snapshots__/jsfmt.spec.js.snap b/tests/format/StateVariableDeclarations/__snapshots__/jsfmt.spec.js.snap index 06d251534..77c68c298 100644 --- a/tests/format/StateVariableDeclarations/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/StateVariableDeclarations/__snapshots__/jsfmt.spec.js.snap @@ -31,7 +31,7 @@ contract Contract { =====================================output===================================== contract Contract { - bytes32 privateconstant DOMAIN_SEPARATOR_TYPEHASH = + bytes32 private constant DOMAIN_SEPARATOR_TYPEHASH = 0x035aff83d86937d35b32e04f0ddc6ff469290eef2f1b692d8a815c89404d4749; } diff --git a/tests/format/StringLiteral/__snapshots__/jsfmt.spec.js.snap b/tests/format/StringLiteral/__snapshots__/jsfmt.spec.js.snap index 8a418a2a2..7d83cc3e9 100644 --- a/tests/format/StringLiteral/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/StringLiteral/__snapshots__/jsfmt.spec.js.snap @@ -55,7 +55,7 @@ contract StringLiteral { =====================================output===================================== contract StringLiteral { - bytes32 publicconstant PERMIT_TYPEHASH = + bytes32 public constant PERMIT_TYPEHASH = keccak256( "Permit(" "address owner," diff --git a/tests/format/StyleGuide/__snapshots__/jsfmt.spec.js.snap b/tests/format/StyleGuide/__snapshots__/jsfmt.spec.js.snap index b84c1da48..f12d9da11 100644 --- a/tests/format/StyleGuide/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/StyleGuide/__snapshots__/jsfmt.spec.js.snap @@ -1,5 +1,45 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`BlankLines.sol - {"compiler":"0.5.0"} format 1`] = ` +====================================options===================================== +compiler: "0.5.0" +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity >=0.4.0 <0.7.0; + + +contract A { +} +contract B { +} + +contract C { +} + +contract A { + function spam() public pure { + // ... + } + function ham() public pure { + // ... + } +} + +=====================================output===================================== +pragma solidity >=0.4.0 <0.7.0; +contract A {} +contract B {} +contract C {} +contract A { + function spam() public pure {} + function ham() public pure {} +} + +================================================================================ +`; + exports[`BlankLines.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] @@ -46,6 +86,101 @@ contract A { ================================================================================ `; +exports[`ControlStructures.sol - {"compiler":"0.5.0"} format 1`] = ` +====================================options===================================== +compiler: "0.5.0" +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity >=0.4.0 <0.7.0; + + +contract ControlStructures +{ + struct Bank + { + address owner; + uint balance; + } + + function () { + if (true) + { + doSomething(); + } + + while(true){ + break; + } + + for (uint a; a < 10; a++) { + doSomethingElse();} + + /* TODO: singleline trueBody should be printed and indented in a new + line + if (x < 10) + x += 1; + */ + + /* TODO: force braquets if statement is too complex + if (x < 10) + someArray.push(Coin({ + name: 'spam', + value: 42 + })); + */ + + if (x < 3) { + x += 1; + } else + if (x > 7) { + x -= 1; + } + else { + x = 5; + } + + /* TODO: singleline trueBody and falseBody should be printed and + indented in a new line + if (x < 3) + x += 1; + else + x -= 1; + */ + } +} + +=====================================output===================================== +pragma solidity >=0.4.0 <0.7.0; +contract ControlStructures { + struct Bank { + address owner; + uint balance; + } + function() { + if (true) { + doSomething(); + } + while(true){ + break; + } + for (uint a; a < 10; a++) { + doSomethingElse(); + } + if (x < 3) { + x += 1; + } else if (x > 7) { + x -= 1; + } else { + x = 5; + } + } +} + +================================================================================ +`; + exports[`ControlStructures.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] @@ -167,9 +302,10 @@ contract ControlStructures { ================================================================================ `; -exports[`FunctionDeclaration.sol format 1`] = ` +exports[`FunctionDeclaration.sol - {"compiler":"0.5.0"} format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +compiler: "0.5.0" +parsers: ["solidity-slang-parse"] printWidth: 80 | printWidth =====================================input====================================== @@ -311,29 +447,22 @@ contract X is B, C, D { =====================================output===================================== pragma solidity >=0.4.0 <0.7.0; - contract FunctionDeclaration { function increment(uint x) public pure returns (uint) { return x + 1; } - function increment(uint x) public pure returns (uint) { return x + 1; } - function increment(uint x) public pure returns (uint) { return x + 1; } - function increment(uint x) public pure returns (uint) { return x + 1; } - - function kill() public onlyowner { + function kill() onlyowner public { selfdestruct(owner); } - - /* TODO: modifiers should always split if arguments split */ function thisFunctionHasLotsOfArguments( address a, address b, @@ -344,7 +473,6 @@ contract FunctionDeclaration { ) public { doSomething(); } - function thisFunctionHasLotsOfArguments( address a, address b, @@ -355,7 +483,6 @@ contract FunctionDeclaration { ) public { doSomething(); } - function thisFunctionHasLotsOfArguments( address a, address b, @@ -366,7 +493,6 @@ contract FunctionDeclaration { ) public { doSomething(); } - function thisFunctionNameIsReallyLong( address x, address y, @@ -374,7 +500,6 @@ contract FunctionDeclaration { ) public onlyowner priced returns (address) { doSomething(); } - function thisFunctionNameIsReallyLong( address x, address y, @@ -382,7 +507,6 @@ contract FunctionDeclaration { ) public onlyowner priced returns (address) { doSomething(); } - function thisFunctionNameIsReallyLong( address x, address y, @@ -390,7 +514,6 @@ contract FunctionDeclaration { ) public onlyowner priced returns (address) { doSomething(); } - function thisFunctionNameIsReallyLong( address a, address b, @@ -404,7 +527,6 @@ contract FunctionDeclaration { ) { doSomething(); - return ( veryVeryLongReturnArg1, veryVeryLongReturnArg1, @@ -412,38 +534,29 @@ contract FunctionDeclaration { ); } } - -// Base contracts just to make this compile contract B { constructor(uint) public {} } - contract C { constructor(uint, uint) public {} } - contract D { constructor(uint) public {} } - -/* TODO: constructors calls have priority over visibility */ contract A is B, C, D { uint x; - constructor( uint param1, uint param2, uint param3, uint param4, uint param5 - ) public B(param1) C(param2, param3) D(param4) { + ) B(param1) C(param2, param3) D(param4) public { x = param5; } } - contract X is B, C, D { uint x; - constructor( uint param1, uint param2, @@ -458,7 +571,7 @@ contract X is B, C, D { ================================================================================ `; -exports[`Mappings.sol format 1`] = ` +exports[`FunctionDeclaration.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] printWidth: 80 @@ -467,67 +580,535 @@ printWidth: 80 pragma solidity >=0.4.0 <0.7.0; -contract Mappings { - mapping (uint => uint) map; - mapping( address => bool ) registeredAddresses; - mapping (uint => mapping (bool => Data[])) public data; - mapping(uint => mapping (uint => s)) data; -} - -=====================================output===================================== -pragma solidity >=0.4.0 <0.7.0; - -contract Mappings { - mapping(uint => uint) map; - mapping(address => bool) registeredAddresses; - mapping(uint => mapping(bool => Data[])) public data; - mapping(uint => mapping(uint => s)) data; -} +contract FunctionDeclaration { + function increment(uint x) public pure returns (uint) + { + return x + 1; + } -================================================================================ -`; + function increment(uint x) public pure returns (uint){ + return x + 1; + } -exports[`MaximumLineLength.sol format 1`] = ` -====================================options===================================== -parsers: ["solidity-parse"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity >=0.4.0 <0.7.0; + function increment(uint x) public pure returns (uint) { + return x + 1; + } + function increment(uint x) public pure returns (uint) { + return x + 1;} -contract FunctionCalls { - function() { - thisFunctionCallIsReallyLong(longArgument1, - longArgument2, - longArgument3 - ); + function kill() onlyowner public { + selfdestruct(owner); + } - thisFunctionCallIsReallyLong(longArgument1, - longArgument2, - longArgument3 - ); + /* TODO: modifiers should always split if arguments split */ + function thisFunctionHasLotsOfArguments(address a, address b, address c, + address d, address e, address f) public { + doSomething(); + } - thisFunctionCallIsReallyLong( - longArgument1, longArgument2, - longArgument3 - ); + function thisFunctionHasLotsOfArguments(address a, + address b, + address c, + address d, + address e, + address f) public { + doSomething(); + } - thisFunctionCallIsReallyLong( - longArgument1, - longArgument2, - longArgument3 - ); + function thisFunctionHasLotsOfArguments( + address a, + address b, + address c, + address d, + address e, + address f) public { + doSomething(); + } - thisFunctionCallIsReallyLong( - longArgument1, - longArgument2, - longArgument3); + function thisFunctionNameIsReallyLong(address x, address y, address z) + public + onlyowner + priced + returns (address) { + doSomething(); } -} + function thisFunctionNameIsReallyLong(address x, address y, address z) + public onlyowner priced returns (address) + { + doSomething(); + } -contract AssignmentStatements { + function thisFunctionNameIsReallyLong(address x, address y, address z) + public + onlyowner + priced + returns (address) { + doSomething(); + } + + function thisFunctionNameIsReallyLong( + address a, + address b, + address c + ) + public + returns (address someAddressName, + uint256 LongArgument, + uint256 Argument) + { + doSomething(); + + return (veryVeryLongReturnArg1, + veryVeryLongReturnArg1, + veryVeryLongReturnArg1); + } +} + + +// Base contracts just to make this compile +contract B { + constructor(uint) public { + } +} + + +contract C { + constructor(uint, uint) public { + } +} + + +contract D { + constructor(uint) public { + } +} + + +/* TODO: constructors calls have priority over visibility */ +contract A is B, C, D { + uint x; + + constructor(uint param1, uint param2, uint param3, uint param4, uint param5) + B(param1) + C(param2, param3) + D(param4) + public + { + x = param5; + } +} + + +contract X is B, C, D { + uint x; + + constructor(uint param1, uint param2, uint param3, uint param4, uint param5) + public + B(param1) + C(param2, param3) + D(param4) { + x = param5; + } +} + +=====================================output===================================== +pragma solidity >=0.4.0 <0.7.0; + +contract FunctionDeclaration { + function increment(uint x) public pure returns (uint) { + return x + 1; + } + + function increment(uint x) public pure returns (uint) { + return x + 1; + } + + function increment(uint x) public pure returns (uint) { + return x + 1; + } + + function increment(uint x) public pure returns (uint) { + return x + 1; + } + + function kill() public onlyowner { + selfdestruct(owner); + } + + /* TODO: modifiers should always split if arguments split */ + function thisFunctionHasLotsOfArguments( + address a, + address b, + address c, + address d, + address e, + address f + ) public { + doSomething(); + } + + function thisFunctionHasLotsOfArguments( + address a, + address b, + address c, + address d, + address e, + address f + ) public { + doSomething(); + } + + function thisFunctionHasLotsOfArguments( + address a, + address b, + address c, + address d, + address e, + address f + ) public { + doSomething(); + } + + function thisFunctionNameIsReallyLong( + address x, + address y, + address z + ) public onlyowner priced returns (address) { + doSomething(); + } + + function thisFunctionNameIsReallyLong( + address x, + address y, + address z + ) public onlyowner priced returns (address) { + doSomething(); + } + + function thisFunctionNameIsReallyLong( + address x, + address y, + address z + ) public onlyowner priced returns (address) { + doSomething(); + } + + function thisFunctionNameIsReallyLong( + address a, + address b, + address c + ) + public + returns ( + address someAddressName, + uint256 LongArgument, + uint256 Argument + ) + { + doSomething(); + + return ( + veryVeryLongReturnArg1, + veryVeryLongReturnArg1, + veryVeryLongReturnArg1 + ); + } +} + +// Base contracts just to make this compile +contract B { + constructor(uint) public {} +} + +contract C { + constructor(uint, uint) public {} +} + +contract D { + constructor(uint) public {} +} + +/* TODO: constructors calls have priority over visibility */ +contract A is B, C, D { + uint x; + + constructor( + uint param1, + uint param2, + uint param3, + uint param4, + uint param5 + ) public B(param1) C(param2, param3) D(param4) { + x = param5; + } +} + +contract X is B, C, D { + uint x; + + constructor( + uint param1, + uint param2, + uint param3, + uint param4, + uint param5 + ) public B(param1) C(param2, param3) D(param4) { + x = param5; + } +} + +================================================================================ +`; + +exports[`Mappings.sol - {"compiler":"0.5.0"} format 1`] = ` +====================================options===================================== +compiler: "0.5.0" +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity >=0.4.0 <0.7.0; + + +contract Mappings { + mapping (uint => uint) map; + mapping( address => bool ) registeredAddresses; + mapping (uint => mapping (bool => Data[])) public data; + mapping(uint => mapping (uint => s)) data; +} + +=====================================output===================================== +pragma solidity >=0.4.0 <0.7.0; +contract Mappings { + mapping(uint => uint) map; + mapping(address => bool) registeredAddresses; + mapping(uint => mapping(bool => Data[])) public data; + mapping(uint => mapping(uint => s)) data; +} + +================================================================================ +`; + +exports[`Mappings.sol format 1`] = ` +====================================options===================================== +parsers: ["solidity-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity >=0.4.0 <0.7.0; + + +contract Mappings { + mapping (uint => uint) map; + mapping( address => bool ) registeredAddresses; + mapping (uint => mapping (bool => Data[])) public data; + mapping(uint => mapping (uint => s)) data; +} + +=====================================output===================================== +pragma solidity >=0.4.0 <0.7.0; + +contract Mappings { + mapping(uint => uint) map; + mapping(address => bool) registeredAddresses; + mapping(uint => mapping(bool => Data[])) public data; + mapping(uint => mapping(uint => s)) data; +} + +================================================================================ +`; + +exports[`MaximumLineLength.sol - {"compiler":"0.5.0"} format 1`] = ` +====================================options===================================== +compiler: "0.5.0" +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity >=0.4.0 <0.7.0; + + +contract FunctionCalls { + function() { + thisFunctionCallIsReallyLong(longArgument1, + longArgument2, + longArgument3 + ); + + thisFunctionCallIsReallyLong(longArgument1, + longArgument2, + longArgument3 + ); + + thisFunctionCallIsReallyLong( + longArgument1, longArgument2, + longArgument3 + ); + + thisFunctionCallIsReallyLong( + longArgument1, + longArgument2, + longArgument3 + ); + + thisFunctionCallIsReallyLong( + longArgument1, + longArgument2, + longArgument3); + } +} + + +contract AssignmentStatements { + function() { + thisIsALongNestedMapping[being][set][to_some_value] = someFunction(argument1, + argument2, + argument3, + argument4); + } +} + + +contract EventDefinitionsAndEventEmitters { + event LongAndLotsOfArgs(address sender, + address recipient, + uint256 publicKey, + uint256 amount, + bytes32[] options, + bytes32 longAttribute); + + function() { + LongAndLotsOfArgs(sender, + recipient, + publicKey, + amount, + options, + longAttribute); + emit LongAndLotsOfArgs(sender, + recipient, + publicKey, + amount, + options, + longAttribute); + } +} + +=====================================output===================================== +pragma solidity >=0.4.0 <0.7.0; +contract FunctionCalls { + function() { + thisFunctionCallIsReallyLong( + longArgument1, + longArgument2, + longArgument3 + ); + thisFunctionCallIsReallyLong( + longArgument1, + longArgument2, + longArgument3 + ); + thisFunctionCallIsReallyLong( + longArgument1, + longArgument2, + longArgument3 + ); + thisFunctionCallIsReallyLong( + longArgument1, + longArgument2, + longArgument3 + ); + thisFunctionCallIsReallyLong( + longArgument1, + longArgument2, + longArgument3 + ); + } +} +contract AssignmentStatements { + function() { + thisIsALongNestedMapping[being][set][to_some_value] = someFunction( + argument1, + argument2, + argument3, + argument4 + ); + } +} +contract EventDefinitionsAndEventEmitters { + event LongAndLotsOfArgs( + address sender, + address recipient, + uint256 publicKey, + uint256 amount, + bytes32[] options, + bytes32 longAttribute + ); + function() { + LongAndLotsOfArgs( + sender, + recipient, + publicKey, + amount, + options, + longAttribute + ); + emit LongAndLotsOfArgs( + sender, + recipient, + publicKey, + amount, + options, + longAttribute + ); + } +} + +================================================================================ +`; + +exports[`MaximumLineLength.sol format 1`] = ` +====================================options===================================== +parsers: ["solidity-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity >=0.4.0 <0.7.0; + + +contract FunctionCalls { + function() { + thisFunctionCallIsReallyLong(longArgument1, + longArgument2, + longArgument3 + ); + + thisFunctionCallIsReallyLong(longArgument1, + longArgument2, + longArgument3 + ); + + thisFunctionCallIsReallyLong( + longArgument1, longArgument2, + longArgument3 + ); + + thisFunctionCallIsReallyLong( + longArgument1, + longArgument2, + longArgument3 + ); + + thisFunctionCallIsReallyLong( + longArgument1, + longArgument2, + longArgument3); + } +} + + +contract AssignmentStatements { function() { thisIsALongNestedMapping[being][set][to_some_value] = someFunction(argument1, argument2, @@ -642,6 +1223,61 @@ contract EventDefinitionsAndEventEmitters { ================================================================================ `; +exports[`OtherRecommendations.sol - {"compiler":"0.5.0"} format 1`] = ` +====================================options===================================== +compiler: "0.5.0" +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity >=0.4.0 <0.7.0; + + +contract OtherRecommendations { + function () { + str = 'bar'; + /* TODO: escape quotes in Strings when enforcing a new quote + str = '"Be yourself; everyone else is already taken." -Oscar Wilde'; + */ + + x=3; + x = 100/10; + x += 3+4; + x |= y&&z; + + + /* TODO: whitespace around and operator can be different than 1 space if + it is the same length before and after + x = 2**3 + 5; + x = 2*y + 3*z; + x = (a+b) * (a-b); + */ + + + x = 2** 3 + 5; + x = y+z; + x +=1; + } +} + +=====================================output===================================== +pragma solidity >=0.4.0 <0.7.0; +contract OtherRecommendations { + function() { + str = "bar"; + x = 3; + x = 100 / 10; + x += 3 + 4; + x |= y && z; + x = 2 ** 3 + 5; + x = y + z; + x += 1; + } +} + +================================================================================ +`; + exports[`OtherRecommendations.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] @@ -709,6 +1345,29 @@ contract OtherRecommendations { ================================================================================ `; +exports[`VariableDeclarations.sol - {"compiler":"0.5.0"} format 1`] = ` +====================================options===================================== +compiler: "0.5.0" +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity >=0.4.0 <0.7.0; + + +contract VariableDeclarations { + uint [] x; +} + +=====================================output===================================== +pragma solidity >=0.4.0 <0.7.0; +contract VariableDeclarations { + uint[] x; +} + +================================================================================ +`; + exports[`VariableDeclarations.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] @@ -732,6 +1391,42 @@ contract VariableDeclarations { ================================================================================ `; +exports[`WhitespaceInExpressions.sol - {"compiler":"0.5.0"} format 1`] = ` +====================================options===================================== +compiler: "0.5.0" +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity >=0.4.0 <0.7.0; + + +contract WhitespaceInExpressions { + function () { + spam( ham[ 1 ], Coin( { name: "ham" } ) ); + x = 1; + y = 2; + long_variable = 3; + } + + function spam(uint i , Coin coin) public ; +} + +=====================================output===================================== +pragma solidity >=0.4.0 <0.7.0; +contract WhitespaceInExpressions { + function() { + spam(ham[1], Coin({name: "ham"})); + x = 1; + y = 2; + long_variable = 3; + } + function spam(uint i, Coin coin) public; +} + +================================================================================ +`; + exports[`WhitespaceInExpressions.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] diff --git a/tests/format/StyleGuide/jsfmt.spec.js b/tests/format/StyleGuide/jsfmt.spec.js index 765dd60a6..a6a1e4d2b 100644 --- a/tests/format/StyleGuide/jsfmt.spec.js +++ b/tests/format/StyleGuide/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse'], { compiler: '0.5.0' }); diff --git a/tests/format/strings/__snapshots__/jsfmt.spec.js.snap b/tests/format/strings/__snapshots__/jsfmt.spec.js.snap index 2ec8073d9..7f6a5588c 100644 --- a/tests/format/strings/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/strings/__snapshots__/jsfmt.spec.js.snap @@ -1556,3 +1556,1240 @@ library strings { ================================================================================ `; + +exports[`strings.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +/* + * @title String & slice utility library for Solidity contracts. + * @author Nick Johnson + * + * @dev Functionality in this library is largely implemented using an + * abstraction called a 'slice'. A slice represents a part of a string - + * anything from the entire string to a single character, or even no + * characters at all (a 0-length slice). Since a slice only has to specify + * an offset and a length, copying and manipulating slices is a lot less + * expensive than copying and manipulating the strings they reference. + * + * To further reduce gas costs, most functions on slice that need to return + * a slice modify the original one instead of allocating a new one; for + * instance, \`s.split(".")\` will return the text up to the first '.', + * modifying s to only contain the remainder of the string after the '.'. + * In situations where you do not want to modify the original slice, you + * can make a copy first with \`.copy()\`, for example: + * \`s.copy().split(".")\`. Try and avoid using this idiom in loops; since + * Solidity has no memory management, it will result in allocating many + * short-lived slices that are later discarded. + * + * Functions that return two slices come in two versions: a non-allocating + * version that takes the second slice as an argument, modifying it in + * place, and an allocating version that allocates and returns the second + * slice; see \`nextRune\` for example. + * + * Functions that have to copy string data will return strings rather than + * slices; these can be cast back to slices for further processing if + * required. + * + * For convenience, some functions are provided with non-modifying + * variants that create a new slice and return both; for instance, + * \`s.splitNew('.')\` leaves s unmodified, and returns two values + * corresponding to the left and right parts of the string. + */ + +pragma solidity ^0.4.14; + +library strings { + struct slice { + uint _len; + uint _ptr; + } + + function memcpy(uint dest, uint src, uint len) private pure { + // Copy word-length chunks while possible + for(; len >= 32; len -= 32) { + assembly { + mstore(dest, mload(src)) + } + dest += 32; + src += 32; + } + + // Copy remaining bytes + uint mask = 256 ** (32 - len) - 1; + assembly { + let srcpart := and(mload(src), not(mask)) + let destpart := and(mload(dest), mask) + mstore(dest, or(destpart, srcpart)) + } + } + + /* + * @dev Returns a slice containing the entire string. + * @param self The string to make a slice from. + * @return A newly allocated slice containing the entire string. + */ + function toSlice(string memory self) internal pure returns (slice memory) { + uint ptr; + assembly { + ptr := add(self, 0x20) + } + return slice(bytes(self).length, ptr); + } + + /* + * @dev Returns the length of a null-terminated bytes32 string. + * @param self The value to find the length of. + * @return The length of the string, from 0 to 32. + */ + function len(bytes32 self) internal pure returns (uint) { + uint ret; + if (self == 0) + return 0; + if (self & 0xffffffffffffffffffffffffffffffff == 0) { + ret += 16; + self = bytes32(uint(self) / 0x100000000000000000000000000000000); + } + if (self & 0xffffffffffffffff == 0) { + ret += 8; + self = bytes32(uint(self) / 0x10000000000000000); + } + if (self & 0xffffffff == 0) { + ret += 4; + self = bytes32(uint(self) / 0x100000000); + } + if (self & 0xffff == 0) { + ret += 2; + self = bytes32(uint(self) / 0x10000); + } + if (self & 0xff == 0) { + ret += 1; + } + return 32 - ret; + } + + /* + * @dev Returns a slice containing the entire bytes32, interpreted as a + * null-terminated utf-8 string. + * @param self The bytes32 value to convert to a slice. + * @return A new slice containing the value of the input argument up to the + * first null. + */ + function toSliceB32(bytes32 self) internal pure returns (slice memory ret) { + // Allocate space for \`self\` in memory, copy it there, and point ret at it + assembly { + let ptr := mload(0x40) + mstore(0x40, add(ptr, 0x20)) + mstore(ptr, self) + mstore(add(ret, 0x20), ptr) + } + ret._len = len(self); + } + + /* + * @dev Returns a new slice containing the same data as the current slice. + * @param self The slice to copy. + * @return A new slice containing the same data as \`self\`. + */ + function copy(slice memory self) internal pure returns (slice memory) { + return slice(self._len, self._ptr); + } + + /* + * @dev Copies a slice to a new string. + * @param self The slice to copy. + * @return A newly allocated string containing the slice's text. + */ + function toString(slice memory self) internal pure returns (string memory) { + string memory ret = new string(self._len); + uint retptr; + assembly { retptr := add(ret, 32) } + + memcpy(retptr, self._ptr, self._len); + return ret; + } + + /* + * @dev Returns the length in runes of the slice. Note that this operation + * takes time proportional to the length of the slice; avoid using it + * in loops, and call \`slice.empty()\` if you only need to know whether + * the slice is empty or not. + * @param self The slice to operate on. + * @return The length of the slice in runes. + */ + function len(slice memory self) internal pure returns (uint l) { + // Starting at ptr-31 means the LSB will be the byte we care about + uint ptr = self._ptr - 31; + uint end = ptr + self._len; + for (l = 0; ptr < end; l++) { + uint8 b; + assembly { b := and(mload(ptr), 0xFF) } + if (b < 0x80) { + ptr += 1; + } else if(b < 0xE0) { + ptr += 2; + } else if(b < 0xF0) { + ptr += 3; + } else if(b < 0xF8) { + ptr += 4; + } else if(b < 0xFC) { + ptr += 5; + } else { + ptr += 6; + } + } + } + + /* + * @dev Returns true if the slice is empty (has a length of 0). + * @param self The slice to operate on. + * @return True if the slice is empty, False otherwise. + */ + function empty(slice memory self) internal pure returns (bool) { + return self._len == 0; + } + + /* + * @dev Returns a positive number if \`other\` comes lexicographically after + * \`self\`, a negative number if it comes before, or zero if the + * contents of the two slices are equal. Comparison is done per-rune, + * on unicode codepoints. + * @param self The first slice to compare. + * @param other The second slice to compare. + * @return The result of the comparison. + */ + function compare(slice memory self, slice memory other) internal pure returns (int) { + uint shortest = self._len; + if (other._len < self._len) + shortest = other._len; + + uint selfptr = self._ptr; + uint otherptr = other._ptr; + for (uint idx = 0; idx < shortest; idx += 32) { + uint a; + uint b; + assembly { + a := mload(selfptr) + b := mload(otherptr) + } + if (a != b) { + // Mask out irrelevant bytes and check again + uint256 mask = uint256(-1); // 0xffff... + if(shortest < 32) { + mask = ~(2 ** (8 * (32 - shortest + idx)) - 1); + } + uint256 diff = (a & mask) - (b & mask); + if (diff != 0) + return int(diff); + } + selfptr += 32; + otherptr += 32; + } + return int(self._len) - int(other._len); + } + + /* + * @dev Returns true if the two slices contain the same text. + * @param self The first slice to compare. + * @param self The second slice to compare. + * @return True if the slices are equal, false otherwise. + */ + function equals(slice memory self, slice memory other) internal pure returns (bool) { + return compare(self, other) == 0; + } + + /* + * @dev Extracts the first rune in the slice into \`rune\`, advancing the + * slice to point to the next rune and returning \`self\`. + * @param self The slice to operate on. + * @param rune The slice that will contain the first rune. + * @return \`rune\`. + */ + function nextRune(slice memory self, slice memory rune) internal pure returns (slice memory) { + rune._ptr = self._ptr; + + if (self._len == 0) { + rune._len = 0; + return rune; + } + + uint l; + uint b; + // Load the first byte of the rune into the LSBs of b + assembly { b := and(mload(sub(mload(add(self, 32)), 31)), 0xFF) } + if (b < 0x80) { + l = 1; + } else if(b < 0xE0) { + l = 2; + } else if(b < 0xF0) { + l = 3; + } else { + l = 4; + } + + // Check for truncated codepoints + if (l > self._len) { + rune._len = self._len; + self._ptr += self._len; + self._len = 0; + return rune; + } + + self._ptr += l; + self._len -= l; + rune._len = l; + return rune; + } + + /* + * @dev Returns the first rune in the slice, advancing the slice to point + * to the next rune. + * @param self The slice to operate on. + * @return A slice containing only the first rune from \`self\`. + */ + function nextRune(slice memory self) internal pure returns (slice memory ret) { + nextRune(self, ret); + } + + /* + * @dev Returns the number of the first codepoint in the slice. + * @param self The slice to operate on. + * @return The number of the first codepoint in the slice. + */ + function ord(slice memory self) internal pure returns (uint ret) { + if (self._len == 0) { + return 0; + } + + uint word; + uint length; + uint divisor = 2 ** 248; + + // Load the rune into the MSBs of b + assembly { word:= mload(mload(add(self, 32))) } + uint b = word / divisor; + if (b < 0x80) { + ret = b; + length = 1; + } else if(b < 0xE0) { + ret = b & 0x1F; + length = 2; + } else if(b < 0xF0) { + ret = b & 0x0F; + length = 3; + } else { + ret = b & 0x07; + length = 4; + } + + // Check for truncated codepoints + if (length > self._len) { + return 0; + } + + for (uint i = 1; i < length; i++) { + divisor = divisor / 256; + b = (word / divisor) & 0xFF; + if (b & 0xC0 != 0x80) { + // Invalid UTF-8 sequence + return 0; + } + ret = (ret * 64) | (b & 0x3F); + } + + return ret; + } + + /* + * @dev Returns the keccak-256 hash of the slice. + * @param self The slice to hash. + * @return The hash of the slice. + */ + function keccak(slice memory self) internal pure returns (bytes32 ret) { + assembly { + ret := keccak256(mload(add(self, 32)), mload(self)) + } + } + + /* + * @dev Returns true if \`self\` starts with \`needle\`. + * @param self The slice to operate on. + * @param needle The slice to search for. + * @return True if the slice starts with the provided text, false otherwise. + */ + function startsWith(slice memory self, slice memory needle) internal pure returns (bool) { + if (self._len < needle._len) { + return false; + } + + if (self._ptr == needle._ptr) { + return true; + } + + bool equal; + assembly { + let length := mload(needle) + let selfptr := mload(add(self, 0x20)) + let needleptr := mload(add(needle, 0x20)) + equal := eq(keccak256(selfptr, length), keccak256(needleptr, length)) + } + return equal; + } + + /* + * @dev If \`self\` starts with \`needle\`, \`needle\` is removed from the + * beginning of \`self\`. Otherwise, \`self\` is unmodified. + * @param self The slice to operate on. + * @param needle The slice to search for. + * @return \`self\` + */ + function beyond(slice memory self, slice memory needle) internal pure returns (slice memory) { + if (self._len < needle._len) { + return self; + } + + bool equal = true; + if (self._ptr != needle._ptr) { + assembly { + let length := mload(needle) + let selfptr := mload(add(self, 0x20)) + let needleptr := mload(add(needle, 0x20)) + equal := eq(keccak256(selfptr, length), keccak256(needleptr, length)) + } + } + + if (equal) { + self._len -= needle._len; + self._ptr += needle._len; + } + + return self; + } + + /* + * @dev Returns true if the slice ends with \`needle\`. + * @param self The slice to operate on. + * @param needle The slice to search for. + * @return True if the slice starts with the provided text, false otherwise. + */ + function endsWith(slice memory self, slice memory needle) internal pure returns (bool) { + if (self._len < needle._len) { + return false; + } + + uint selfptr = self._ptr + self._len - needle._len; + + if (selfptr == needle._ptr) { + return true; + } + + bool equal; + assembly { + let length := mload(needle) + let needleptr := mload(add(needle, 0x20)) + equal := eq(keccak256(selfptr, length), keccak256(needleptr, length)) + } + + return equal; + } + + /* + * @dev If \`self\` ends with \`needle\`, \`needle\` is removed from the + * end of \`self\`. Otherwise, \`self\` is unmodified. + * @param self The slice to operate on. + * @param needle The slice to search for. + * @return \`self\` + */ + function until(slice memory self, slice memory needle) internal pure returns (slice memory) { + if (self._len < needle._len) { + return self; + } + + uint selfptr = self._ptr + self._len - needle._len; + bool equal = true; + if (selfptr != needle._ptr) { + assembly { + let length := mload(needle) + let needleptr := mload(add(needle, 0x20)) + equal := eq(keccak256(selfptr, length), keccak256(needleptr, length)) + } + } + + if (equal) { + self._len -= needle._len; + } + + return self; + } + + // Returns the memory address of the first byte of the first occurrence of + // \`needle\` in \`self\`, or the first byte after \`self\` if not found. + function findPtr(uint selflen, uint selfptr, uint needlelen, uint needleptr) private pure returns (uint) { + uint ptr = selfptr; + uint idx; + + if (needlelen <= selflen) { + if (needlelen <= 32) { + bytes32 mask = bytes32(~(2 ** (8 * (32 - needlelen)) - 1)); + + bytes32 needledata; + assembly { needledata := and(mload(needleptr), mask) } + + uint end = selfptr + selflen - needlelen; + bytes32 ptrdata; + assembly { ptrdata := and(mload(ptr), mask) } + + while (ptrdata != needledata) { + if (ptr >= end) + return selfptr + selflen; + ptr++; + assembly { ptrdata := and(mload(ptr), mask) } + } + return ptr; + } else { + // For long needles, use hashing + bytes32 hash; + assembly { hash := keccak256(needleptr, needlelen) } + + for (idx = 0; idx <= selflen - needlelen; idx++) { + bytes32 testHash; + assembly { testHash := keccak256(ptr, needlelen) } + if (hash == testHash) + return ptr; + ptr += 1; + } + } + } + return selfptr + selflen; + } + + // Returns the memory address of the first byte after the last occurrence of + // \`needle\` in \`self\`, or the address of \`self\` if not found. + function rfindPtr(uint selflen, uint selfptr, uint needlelen, uint needleptr) private pure returns (uint) { + uint ptr; + + if (needlelen <= selflen) { + if (needlelen <= 32) { + bytes32 mask = bytes32(~(2 ** (8 * (32 - needlelen)) - 1)); + + bytes32 needledata; + assembly { needledata := and(mload(needleptr), mask) } + + ptr = selfptr + selflen - needlelen; + bytes32 ptrdata; + assembly { ptrdata := and(mload(ptr), mask) } + + while (ptrdata != needledata) { + if (ptr <= selfptr) + return selfptr; + ptr--; + assembly { ptrdata := and(mload(ptr), mask) } + } + return ptr + needlelen; + } else { + // For long needles, use hashing + bytes32 hash; + assembly { hash := keccak256(needleptr, needlelen) } + ptr = selfptr + (selflen - needlelen); + while (ptr >= selfptr) { + bytes32 testHash; + assembly { testHash := keccak256(ptr, needlelen) } + if (hash == testHash) + return ptr + needlelen; + ptr -= 1; + } + } + } + return selfptr; + } + + /* + * @dev Modifies \`self\` to contain everything from the first occurrence of + * \`needle\` to the end of the slice. \`self\` is set to the empty slice + * if \`needle\` is not found. + * @param self The slice to search and modify. + * @param needle The text to search for. + * @return \`self\`. + */ + function find(slice memory self, slice memory needle) internal pure returns (slice memory) { + uint ptr = findPtr(self._len, self._ptr, needle._len, needle._ptr); + self._len -= ptr - self._ptr; + self._ptr = ptr; + return self; + } + + /* + * @dev Modifies \`self\` to contain the part of the string from the start of + * \`self\` to the end of the first occurrence of \`needle\`. If \`needle\` + * is not found, \`self\` is set to the empty slice. + * @param self The slice to search and modify. + * @param needle The text to search for. + * @return \`self\`. + */ + function rfind(slice memory self, slice memory needle) internal pure returns (slice memory) { + uint ptr = rfindPtr(self._len, self._ptr, needle._len, needle._ptr); + self._len = ptr - self._ptr; + return self; + } + + /* + * @dev Splits the slice, setting \`self\` to everything after the first + * occurrence of \`needle\`, and \`token\` to everything before it. If + * \`needle\` does not occur in \`self\`, \`self\` is set to the empty slice, + * and \`token\` is set to the entirety of \`self\`. + * @param self The slice to split. + * @param needle The text to search for in \`self\`. + * @param token An output parameter to which the first token is written. + * @return \`token\`. + */ + function split(slice memory self, slice memory needle, slice memory token) internal pure returns (slice memory) { + uint ptr = findPtr(self._len, self._ptr, needle._len, needle._ptr); + token._ptr = self._ptr; + token._len = ptr - self._ptr; + if (ptr == self._ptr + self._len) { + // Not found + self._len = 0; + } else { + self._len -= token._len + needle._len; + self._ptr = ptr + needle._len; + } + return token; + } + + /* + * @dev Splits the slice, setting \`self\` to everything after the first + * occurrence of \`needle\`, and returning everything before it. If + * \`needle\` does not occur in \`self\`, \`self\` is set to the empty slice, + * and the entirety of \`self\` is returned. + * @param self The slice to split. + * @param needle The text to search for in \`self\`. + * @return The part of \`self\` up to the first occurrence of \`delim\`. + */ + function split(slice memory self, slice memory needle) internal pure returns (slice memory token) { + split(self, needle, token); + } + + /* + * @dev Splits the slice, setting \`self\` to everything before the last + * occurrence of \`needle\`, and \`token\` to everything after it. If + * \`needle\` does not occur in \`self\`, \`self\` is set to the empty slice, + * and \`token\` is set to the entirety of \`self\`. + * @param self The slice to split. + * @param needle The text to search for in \`self\`. + * @param token An output parameter to which the first token is written. + * @return \`token\`. + */ + function rsplit(slice memory self, slice memory needle, slice memory token) internal pure returns (slice memory) { + uint ptr = rfindPtr(self._len, self._ptr, needle._len, needle._ptr); + token._ptr = ptr; + token._len = self._len - (ptr - self._ptr); + if (ptr == self._ptr) { + // Not found + self._len = 0; + } else { + self._len -= token._len + needle._len; + } + return token; + } + + /* + * @dev Splits the slice, setting \`self\` to everything before the last + * occurrence of \`needle\`, and returning everything after it. If + * \`needle\` does not occur in \`self\`, \`self\` is set to the empty slice, + * and the entirety of \`self\` is returned. + * @param self The slice to split. + * @param needle The text to search for in \`self\`. + * @return The part of \`self\` after the last occurrence of \`delim\`. + */ + function rsplit(slice memory self, slice memory needle) internal pure returns (slice memory token) { + rsplit(self, needle, token); + } + + /* + * @dev Counts the number of nonoverlapping occurrences of \`needle\` in \`self\`. + * @param self The slice to search. + * @param needle The text to search for in \`self\`. + * @return The number of occurrences of \`needle\` found in \`self\`. + */ + function count(slice memory self, slice memory needle) internal pure returns (uint cnt) { + uint ptr = findPtr(self._len, self._ptr, needle._len, needle._ptr) + needle._len; + while (ptr <= self._ptr + self._len) { + cnt++; + ptr = findPtr(self._len - (ptr - self._ptr), ptr, needle._len, needle._ptr) + needle._len; + } + } + + /* + * @dev Returns True if \`self\` contains \`needle\`. + * @param self The slice to search. + * @param needle The text to search for in \`self\`. + * @return True if \`needle\` is found in \`self\`, false otherwise. + */ + function contains(slice memory self, slice memory needle) internal pure returns (bool) { + return rfindPtr(self._len, self._ptr, needle._len, needle._ptr) != self._ptr; + } + + /* + * @dev Returns a newly allocated string containing the concatenation of + * \`self\` and \`other\`. + * @param self The first slice to concatenate. + * @param other The second slice to concatenate. + * @return The concatenation of the two strings. + */ + function concat(slice memory self, slice memory other) internal pure returns (string memory) { + string memory ret = new string(self._len + other._len); + uint retptr; + assembly { retptr := add(ret, 32) } + memcpy(retptr, self._ptr, self._len); + memcpy(retptr + self._len, other._ptr, other._len); + return ret; + } + + /* + * @dev Joins an array of slices, using \`self\` as a delimiter, returning a + * newly allocated string. + * @param self The delimiter to use. + * @param parts A list of slices to join. + * @return A newly allocated string containing all the slices in \`parts\`, + * joined with \`self\`. + */ + function join(slice memory self, slice[] memory parts) internal pure returns (string memory) { + if (parts.length == 0) + return ""; + + uint length = self._len * (parts.length - 1); + for(uint i = 0; i < parts.length; i++) { + length += parts[i]._len; + } + + string memory ret = new string(length); + uint retptr; + assembly { retptr := add(ret, 32) } + + for(i = 0; i < parts.length; i++) { + memcpy(retptr, parts[i]._ptr, parts[i]._len); + retptr += parts[i]._len; + if (i < parts.length - 1) { + memcpy(retptr, self._ptr, self._len); + retptr += self._len; + } + } + + return ret; + } +} + +=====================================output===================================== +pragma solidity ^0.4.14; +library strings { + struct slice { + uint _len; + uint _ptr; + } + function memcpy(uint dest, uint src, uint len) private pure { + for (; len >= 32; len -= 32) { + assembly { + mstore(dest,mload(src)) + } + dest += 32; + src += 32; + } + uint mask = 256 ** (32 - len) - 1; + assembly { + let srcpart := and(mload(src),not(mask)) + let destpart := and(mload(dest),mask) + mstore(dest,or(destpart,srcpart)) + } + } + function toSlice(string memory self) internal pure returns (slice memory) { + uint ptr; + assembly { + ptr := add(self,0x20) + } + return slice(bytes(self).length, ptr); + } + function len(bytes32 self) internal pure returns (uint) { + uint ret; + if (self == 0) return 0; + if (self & 0xffffffffffffffffffffffffffffffff == 0) { + ret += 16; + self = bytes32(uint(self) / 0x100000000000000000000000000000000); + } + if (self & 0xffffffffffffffff == 0) { + ret += 8; + self = bytes32(uint(self) / 0x10000000000000000); + } + if (self & 0xffffffff == 0) { + ret += 4; + self = bytes32(uint(self) / 0x100000000); + } + if (self & 0xffff == 0) { + ret += 2; + self = bytes32(uint(self) / 0x10000); + } + if (self & 0xff == 0) { + ret += 1; + } + return 32 - ret; + } + function toSliceB32(bytes32 self) internal pure returns (slice memory ret) { + assembly { + let ptr := mload(0x40) + mstore(0x40,add(ptr,0x20)) + mstore(ptr,self) + mstore(add(ret,0x20),ptr) + } + ret._len = len(self); + } + function copy(slice memory self) internal pure returns (slice memory) { + return slice(self._len, self._ptr); + } + function toString(slice memory self) internal pure returns (string memory) { + string memory ret = new string(self._len); + uint retptr; + assembly { + retptr := add(ret,32) + } + memcpy(retptr, self._ptr, self._len); + return ret; + } + function len(slice memory self) internal pure returns (uint l) { + uint ptr = self._ptr - 31; + uint end = ptr + self._len; + for (l = 0; ptr < end; l++) { + uint8 b; + assembly { + b := and(mload(ptr),0xFF) + } + if (b < 0x80) { + ptr += 1; + } else if (b < 0xE0) { + ptr += 2; + } else if (b < 0xF0) { + ptr += 3; + } else if (b < 0xF8) { + ptr += 4; + } else if (b < 0xFC) { + ptr += 5; + } else { + ptr += 6; + } + } + } + function empty(slice memory self) internal pure returns (bool) { + return self._len == 0; + } + function compare( + slice memory self, + slice memory other + ) internal pure returns (int) { + uint shortest = self._len; + if (other._len < self._len) shortest = other._len; + uint selfptr = self._ptr; + uint otherptr = other._ptr; + for (uint idx = 0; idx < shortest; idx += 32) { + uint a; + uint b; + assembly { + a := mload(selfptr) + b := mload(otherptr) + } + if (a != b) { + uint256 mask = uint256(-1); + if (shortest < 32) { + mask = ~(2 ** (8 * (32 - shortest + idx)) - 1); + } + uint256 diff = (a & mask) - (b & mask); + if (diff != 0) return int(diff); + } + selfptr += 32; + otherptr += 32; + } + return int(self._len) - int(other._len); + } + function equals( + slice memory self, + slice memory other + ) internal pure returns (bool) { + return compare(self, other) == 0; + } + function nextRune( + slice memory self, + slice memory rune + ) internal pure returns (slice memory) { + rune._ptr = self._ptr; + if (self._len == 0) { + rune._len = 0; + return rune; + } + uint l; + uint b; + assembly { + b := and(mload(sub(mload(add(self,32)),31)),0xFF) + } + if (b < 0x80) { + l = 1; + } else if (b < 0xE0) { + l = 2; + } else if (b < 0xF0) { + l = 3; + } else { + l = 4; + } + if (l > self._len) { + rune._len = self._len; + self._ptr += self._len; + self._len = 0; + return rune; + } + self._ptr += l; + self._len -= l; + rune._len = l; + return rune; + } + function nextRune( + slice memory self + ) internal pure returns (slice memory ret) { + nextRune(self, ret); + } + function ord(slice memory self) internal pure returns (uint ret) { + if (self._len == 0) { + return 0; + } + uint word; + uint length; + uint divisor = 2 ** 248; + assembly { + word := mload(mload(add(self,32))) + } + uint b = word / divisor; + if (b < 0x80) { + ret = b; + length = 1; + } else if (b < 0xE0) { + ret = b & 0x1F; + length = 2; + } else if (b < 0xF0) { + ret = b & 0x0F; + length = 3; + } else { + ret = b & 0x07; + length = 4; + } + if (length > self._len) { + return 0; + } + for (uint i = 1; i < length; i++) { + divisor = divisor / 256; + b = (word / divisor) & 0xFF; + if (b & 0xC0 != 0x80) { + return 0; + } + ret = (ret * 64) | (b & 0x3F); + } + return ret; + } + function keccak(slice memory self) internal pure returns (bytes32 ret) { + assembly { + ret := keccak256(mload(add(self,32)),mload(self)) + } + } + function startsWith( + slice memory self, + slice memory needle + ) internal pure returns (bool) { + if (self._len < needle._len) { + return false; + } + if (self._ptr == needle._ptr) { + return true; + } + bool equal; + assembly { + let length := mload(needle) + let selfptr := mload(add(self,0x20)) + let needleptr := mload(add(needle,0x20)) + equal := eq(keccak256(selfptr,length),keccak256(needleptr,length)) + } + return equal; + } + function beyond( + slice memory self, + slice memory needle + ) internal pure returns (slice memory) { + if (self._len < needle._len) { + return self; + } + bool equal = true; + if (self._ptr != needle._ptr) { + assembly { + let length := mload(needle) + let selfptr := mload(add(self,0x20)) + let needleptr := mload(add(needle,0x20)) + equal := eq(keccak256(selfptr,length),keccak256(needleptr,length)) + } + } + if (equal) { + self._len -= needle._len; + self._ptr += needle._len; + } + return self; + } + function endsWith( + slice memory self, + slice memory needle + ) internal pure returns (bool) { + if (self._len < needle._len) { + return false; + } + uint selfptr = self._ptr + self._len - needle._len; + if (selfptr == needle._ptr) { + return true; + } + bool equal; + assembly { + let length := mload(needle) + let needleptr := mload(add(needle,0x20)) + equal := eq(keccak256(selfptr,length),keccak256(needleptr,length)) + } + return equal; + } + function until( + slice memory self, + slice memory needle + ) internal pure returns (slice memory) { + if (self._len < needle._len) { + return self; + } + uint selfptr = self._ptr + self._len - needle._len; + bool equal = true; + if (selfptr != needle._ptr) { + assembly { + let length := mload(needle) + let needleptr := mload(add(needle,0x20)) + equal := eq(keccak256(selfptr,length),keccak256(needleptr,length)) + } + } + if (equal) { + self._len -= needle._len; + } + return self; + } + function findPtr( + uint selflen, + uint selfptr, + uint needlelen, + uint needleptr + ) private pure returns (uint) { + uint ptr = selfptr; + uint idx; + if (needlelen <= selflen) { + if (needlelen <= 32) { + bytes32 mask = bytes32(~(2 ** (8 * (32 - needlelen)) - 1)); + bytes32 needledata; + assembly { + needledata := and(mload(needleptr),mask) + } + uint end = selfptr + selflen - needlelen; + bytes32 ptrdata; + assembly { + ptrdata := and(mload(ptr),mask) + } + while(ptrdata != needledata){ + if (ptr >= end) return selfptr + selflen; + ptr++; + assembly { + ptrdata := and(mload(ptr),mask) + } + } + return ptr; + } else { + bytes32 hash; + assembly { + hash := keccak256(needleptr,needlelen) + } + for (idx = 0; idx <= selflen - needlelen; idx++) { + bytes32 testHash; + assembly { + testHash := keccak256(ptr,needlelen) + } + if (hash == testHash) return ptr; + ptr += 1; + } + } + } + return selfptr + selflen; + } + function rfindPtr( + uint selflen, + uint selfptr, + uint needlelen, + uint needleptr + ) private pure returns (uint) { + uint ptr; + if (needlelen <= selflen) { + if (needlelen <= 32) { + bytes32 mask = bytes32(~(2 ** (8 * (32 - needlelen)) - 1)); + bytes32 needledata; + assembly { + needledata := and(mload(needleptr),mask) + } + ptr = selfptr + selflen - needlelen; + bytes32 ptrdata; + assembly { + ptrdata := and(mload(ptr),mask) + } + while(ptrdata != needledata){ + if (ptr <= selfptr) return selfptr; + ptr--; + assembly { + ptrdata := and(mload(ptr),mask) + } + } + return ptr + needlelen; + } else { + bytes32 hash; + assembly { + hash := keccak256(needleptr,needlelen) + } + ptr = selfptr + (selflen - needlelen); + while(ptr >= selfptr){ + bytes32 testHash; + assembly { + testHash := keccak256(ptr,needlelen) + } + if (hash == testHash) return ptr + needlelen; + ptr -= 1; + } + } + } + return selfptr; + } + function find( + slice memory self, + slice memory needle + ) internal pure returns (slice memory) { + uint ptr = findPtr(self._len, self._ptr, needle._len, needle._ptr); + self._len -= ptr - self._ptr; + self._ptr = ptr; + return self; + } + function rfind( + slice memory self, + slice memory needle + ) internal pure returns (slice memory) { + uint ptr = rfindPtr(self._len, self._ptr, needle._len, needle._ptr); + self._len = ptr - self._ptr; + return self; + } + function split( + slice memory self, + slice memory needle, + slice memory token + ) internal pure returns (slice memory) { + uint ptr = findPtr(self._len, self._ptr, needle._len, needle._ptr); + token._ptr = self._ptr; + token._len = ptr - self._ptr; + if (ptr == self._ptr + self._len) { + self._len = 0; + } else { + self._len -= token._len + needle._len; + self._ptr = ptr + needle._len; + } + return token; + } + function split( + slice memory self, + slice memory needle + ) internal pure returns (slice memory token) { + split(self, needle, token); + } + function rsplit( + slice memory self, + slice memory needle, + slice memory token + ) internal pure returns (slice memory) { + uint ptr = rfindPtr(self._len, self._ptr, needle._len, needle._ptr); + token._ptr = ptr; + token._len = self._len - (ptr - self._ptr); + if (ptr == self._ptr) { + self._len = 0; + } else { + self._len -= token._len + needle._len; + } + return token; + } + function rsplit( + slice memory self, + slice memory needle + ) internal pure returns (slice memory token) { + rsplit(self, needle, token); + } + function count( + slice memory self, + slice memory needle + ) internal pure returns (uint cnt) { + uint ptr = findPtr(self._len, self._ptr, needle._len, needle._ptr) + + needle._len; + while(ptr <= self._ptr + self._len){ + cnt++; + ptr = + findPtr( + self._len - (ptr - self._ptr), + ptr, + needle._len, + needle._ptr + ) + + needle._len; + } + } + function contains( + slice memory self, + slice memory needle + ) internal pure returns (bool) { + return rfindPtr(self._len, self._ptr, needle._len, needle._ptr) != + self._ptr; + } + function concat( + slice memory self, + slice memory other + ) internal pure returns (string memory) { + string memory ret = new string(self._len + other._len); + uint retptr; + assembly { + retptr := add(ret,32) + } + memcpy(retptr, self._ptr, self._len); + memcpy(retptr + self._len, other._ptr, other._len); + return ret; + } + function join( + slice memory self, + slice[] memory parts + ) internal pure returns (string memory) { + if (parts.length == 0) return ""; + uint length = self._len * (parts.length - 1); + for (uint i = 0; i < parts.length; i++) { + length += parts[i]._len; + } + string memory ret = new string(length); + uint retptr; + assembly { + retptr := add(ret,32) + } + for (i = 0; i < parts.length; i++) { + memcpy(retptr, parts[i]._ptr, parts[i]._len); + retptr += parts[i]._len; + if (i < parts.length - 1) { + memcpy(retptr, self._ptr, self._len); + retptr += self._len; + } + } + return ret; + } +} + +================================================================================ +`; diff --git a/tests/format/strings/jsfmt.spec.js b/tests/format/strings/jsfmt.spec.js index 765dd60a6..fd56c17bc 100644 --- a/tests/format/strings/jsfmt.spec.js +++ b/tests/format/strings/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse']); From f8c3f867ed6a51b05aba66f2e2134aff02dc85e2 Mon Sep 17 00:00:00 2001 From: Klaus Date: Sat, 15 Jun 2024 22:26:00 +1200 Subject: [PATCH 028/160] adding parentheses in binary operations --- src/common/slang-helpers.js | 21 + src/slang-nodes/AdditiveExpression.js | 6 +- src/slang-nodes/BitwiseAndExpression.js | 22 +- src/slang-nodes/BitwiseOrExpression.js | 26 +- src/slang-nodes/BitwiseXorExpression.js | 24 +- src/slang-nodes/ConditionalExpression.js | 20 +- src/slang-nodes/ExponentiationExpression.js | 29 +- src/slang-nodes/MultiplicativeExpression.js | 33 +- src/slang-nodes/OrExpression.js | 6 +- src/slang-nodes/ShiftExpression.js | 20 +- .../__snapshots__/jsfmt.spec.js.snap | 215 ++++++----- .../Comments/__snapshots__/jsfmt.spec.js.snap | 262 +++++++++++++ tests/format/Comments/jsfmt.spec.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 64 ++-- tests/format/FunctionCalls/FunctionCalls.sol | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 303 ++++++++++++++- tests/format/FunctionCalls/jsfmt.spec.js | 2 + .../__snapshots__/jsfmt.spec.js.snap | 63 +++ .../format/NameValueExpression/jsfmt.spec.js | 2 + .../__snapshots__/jsfmt.spec.js.snap | 360 +++++++++++++----- .../format/PrettierIgnore/PrettierIgnore.sol | 4 +- .../__snapshots__/jsfmt.spec.js.snap | 73 +++- tests/format/PrettierIgnore/jsfmt.spec.js | 1 + 23 files changed, 1292 insertions(+), 267 deletions(-) diff --git a/src/common/slang-helpers.js b/src/common/slang-helpers.js index a33c69cbb..1e7d6703d 100644 --- a/src/common/slang-helpers.js +++ b/src/common/slang-helpers.js @@ -149,3 +149,24 @@ export const logicalOperationPrint = binaryOperationPrintBuilder( logicalGroupRulesBuilder, logicalIndentRulesBuilder ); + +export const tryHug = (node, operators) => { + if ( + binaryOperationKinds.includes(node.variant.kind) && + operators.includes(node.variant.operator) + ) + return { + kind: 'Expression', + variant: { + kind: 'TupleExpression', + openParen: '(', + items: { + kind: 'TupleValues', + items: [node], + separators: [] + }, + closeParen: ')' + } + }; + return node; +}; diff --git a/src/slang-nodes/AdditiveExpression.js b/src/slang-nodes/AdditiveExpression.js index 78fb4704a..2404d71a2 100644 --- a/src/slang-nodes/AdditiveExpression.js +++ b/src/slang-nodes/AdditiveExpression.js @@ -1,11 +1,11 @@ -import { binaryOperationPrint } from '../common/slang-helpers.js'; +import { binaryOperationPrint, tryHug } from '../common/slang-helpers.js'; export const AdditiveExpression = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, - leftOperand: parse(ast.leftOperand, options, parse), + leftOperand: tryHug(parse(ast.leftOperand, options, parse), ['%']), operator: ast.operator.text, - rightOperand: parse(ast.rightOperand, options, parse) + rightOperand: tryHug(parse(ast.rightOperand, options, parse), ['%']) }), print: binaryOperationPrint }; diff --git a/src/slang-nodes/BitwiseAndExpression.js b/src/slang-nodes/BitwiseAndExpression.js index 8c726795a..58584976b 100644 --- a/src/slang-nodes/BitwiseAndExpression.js +++ b/src/slang-nodes/BitwiseAndExpression.js @@ -1,11 +1,27 @@ -import { binaryOperationPrint } from '../common/slang-helpers.js'; +import { binaryOperationPrint, tryHug } from '../common/slang-helpers.js'; export const BitwiseAndExpression = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, - leftOperand: parse(ast.leftOperand, options, parse), + leftOperand: tryHug(parse(ast.leftOperand, options, parse), [ + '+', + '-', + '*', + '/', + '**', + '<<', + '>>' + ]), operator: ast.operator.text, - rightOperand: parse(ast.rightOperand, options, parse) + rightOperand: tryHug(parse(ast.rightOperand, options, parse), [ + '+', + '-', + '*', + '/', + '**', + '<<', + '>>' + ]) }), print: binaryOperationPrint }; diff --git a/src/slang-nodes/BitwiseOrExpression.js b/src/slang-nodes/BitwiseOrExpression.js index c4a808da5..a5d5bb31e 100644 --- a/src/slang-nodes/BitwiseOrExpression.js +++ b/src/slang-nodes/BitwiseOrExpression.js @@ -1,11 +1,31 @@ -import { binaryOperationPrint } from '../common/slang-helpers.js'; +import { binaryOperationPrint, tryHug } from '../common/slang-helpers.js'; export const BitwiseOrExpression = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, - leftOperand: parse(ast.leftOperand, options, parse), + leftOperand: tryHug(parse(ast.leftOperand, options, parse), [ + '+', + '-', + '*', + '/', + '**', + '<<', + '>>', + '&', + '^' + ]), operator: ast.operator.text, - rightOperand: parse(ast.rightOperand, options, parse) + rightOperand: tryHug(parse(ast.rightOperand, options, parse), [ + '+', + '-', + '*', + '/', + '**', + '<<', + '>>', + '&', + '^' + ]) }), print: binaryOperationPrint }; diff --git a/src/slang-nodes/BitwiseXorExpression.js b/src/slang-nodes/BitwiseXorExpression.js index 56e2b16e6..44fef0716 100644 --- a/src/slang-nodes/BitwiseXorExpression.js +++ b/src/slang-nodes/BitwiseXorExpression.js @@ -1,11 +1,29 @@ -import { binaryOperationPrint } from '../common/slang-helpers.js'; +import { binaryOperationPrint, tryHug } from '../common/slang-helpers.js'; export const BitwiseXorExpression = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, - leftOperand: parse(ast.leftOperand, options, parse), + leftOperand: tryHug(parse(ast.leftOperand, options, parse), [ + '+', + '-', + '*', + '/', + '**', + '<<', + '>>', + '&' + ]), operator: ast.operator.text, - rightOperand: parse(ast.rightOperand, options, parse) + rightOperand: tryHug(parse(ast.rightOperand, options, parse), [ + '+', + '-', + '*', + '/', + '**', + '<<', + '>>', + '&' + ]) }), print: binaryOperationPrint }; diff --git a/src/slang-nodes/ConditionalExpression.js b/src/slang-nodes/ConditionalExpression.js index 44d2bfabb..d53541219 100644 --- a/src/slang-nodes/ConditionalExpression.js +++ b/src/slang-nodes/ConditionalExpression.js @@ -90,13 +90,19 @@ export const ConditionalExpression = { parse: ({ ast, options, parse }) => { let operand = parse(ast.operand, options, parse); - while ( - operand.variant.kind === 'TupleExpression' && - operand.variant.items.items.length === 1 && - operand.variant.items.items[0].expression.variant.kind !== - 'ConditionalExpression' - ) { - operand = operand.variant.items.items[0].expression; + // TODO: while the behaviour is not stable, it should be behind the + // experimentalTernaries flag. + if (options.experimentalTernaries) { + // We can remove parentheses only because we are sure that the + // `condition` must be a single `bool` value. + while ( + operand.variant.kind === 'TupleExpression' && + operand.variant.items.items.length === 1 && + operand.variant.items.items[0].expression.variant.kind !== + 'ConditionalExpression' + ) { + operand = operand.variant.items.items[0].expression; + } } return { diff --git a/src/slang-nodes/ExponentiationExpression.js b/src/slang-nodes/ExponentiationExpression.js index fca0f47e6..a1b52577f 100644 --- a/src/slang-nodes/ExponentiationExpression.js +++ b/src/slang-nodes/ExponentiationExpression.js @@ -1,15 +1,30 @@ import { doc } from 'prettier'; -import { rightOperandPrint } from '../common/slang-helpers.js'; +import coerce from 'semver/functions/coerce.js'; +import satisfies from 'semver/functions/satisfies.js'; +import { rightOperandPrint, tryHug } from '../common/slang-helpers.js'; const { group, indent } = doc.builders; export const ExponentiationExpression = { - parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, - leftOperand: parse(ast.leftOperand, options, parse), - operator: ast.operator.text, - rightOperand: parse(ast.rightOperand, options, parse) - }), + parse: ({ ast, options, parse }) => { + const compiler = coerce(options.compiler); + let leftOperand = parse(ast.leftOperand, options, parse); + let rightOperand = parse(ast.rightOperand, options, parse); + + if (compiler) { + if (satisfies(compiler, '>=0.8.0')) { + rightOperand = tryHug(rightOperand, ['**']); + } else { + leftOperand = tryHug(leftOperand, ['**']); + } + } + return { + kind: ast.cst.kind, + leftOperand, + operator: ast.operator.text, + rightOperand + }; + }, print: ({ node, path, print }) => group([ path.call(print, 'leftOperand'), diff --git a/src/slang-nodes/MultiplicativeExpression.js b/src/slang-nodes/MultiplicativeExpression.js index d4e63036a..d1672cb42 100644 --- a/src/slang-nodes/MultiplicativeExpression.js +++ b/src/slang-nodes/MultiplicativeExpression.js @@ -1,11 +1,30 @@ -import { binaryOperationPrint } from '../common/slang-helpers.js'; +import { binaryOperationPrint, tryHug } from '../common/slang-helpers.js'; export const MultiplicativeExpression = { - parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, - leftOperand: parse(ast.leftOperand, options, parse), - operator: ast.operator.text, - rightOperand: parse(ast.rightOperand, options, parse) - }), + parse: ({ ast, options, parse }) => { + let leftOperand = parse(ast.leftOperand, options, parse); + const operator = ast.operator.text; + + switch (operator) { + case '*': + leftOperand = tryHug(leftOperand, ['/', '%']); + break; + case '/': + leftOperand = tryHug(leftOperand, ['*', '%']); + break; + case '%': + leftOperand = tryHug(leftOperand, ['*', '/', '%']); + break; + default: + break; + } + + return { + kind: ast.cst.kind, + leftOperand, + operator, + rightOperand: parse(ast.rightOperand, options, parse) + }; + }, print: binaryOperationPrint }; diff --git a/src/slang-nodes/OrExpression.js b/src/slang-nodes/OrExpression.js index eac334b78..250f180b3 100644 --- a/src/slang-nodes/OrExpression.js +++ b/src/slang-nodes/OrExpression.js @@ -1,11 +1,11 @@ -import { logicalOperationPrint } from '../common/slang-helpers.js'; +import { logicalOperationPrint, tryHug } from '../common/slang-helpers.js'; export const OrExpression = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, - leftOperand: parse(ast.leftOperand, options, parse), + leftOperand: tryHug(parse(ast.leftOperand, options, parse), ['&&']), operator: ast.operator.text, - rightOperand: parse(ast.rightOperand, options, parse) + rightOperand: tryHug(parse(ast.rightOperand, options, parse), ['&&']) }), print: logicalOperationPrint }; diff --git a/src/slang-nodes/ShiftExpression.js b/src/slang-nodes/ShiftExpression.js index 732ca023f..88c017814 100644 --- a/src/slang-nodes/ShiftExpression.js +++ b/src/slang-nodes/ShiftExpression.js @@ -1,11 +1,25 @@ -import { binaryOperationPrint } from '../common/slang-helpers.js'; +import { binaryOperationPrint, tryHug } from '../common/slang-helpers.js'; export const ShiftExpression = { parse: ({ ast, options, parse }) => ({ kind: ast.cst.kind, - leftOperand: parse(ast.leftOperand, options, parse), + leftOperand: tryHug(parse(ast.leftOperand, options, parse), [ + '+', + '-', + '*', + '/', + '**', + '<<', + '>>' + ]), operator: ast.operator.text, - rightOperand: parse(ast.rightOperand, options, parse) + rightOperand: tryHug(parse(ast.rightOperand, options, parse), [ + '+', + '-', + '*', + '/', + '**' + ]) }), print: binaryOperationPrint }; diff --git a/tests/format/BinaryOperators/__snapshots__/jsfmt.spec.js.snap b/tests/format/BinaryOperators/__snapshots__/jsfmt.spec.js.snap index 4cdbf3902..a9c06dcac 100644 --- a/tests/format/BinaryOperators/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/BinaryOperators/__snapshots__/jsfmt.spec.js.snap @@ -203,7 +203,7 @@ contract ArithmeticOperators { a / b; a % b; a ** b; - a % b + c - d * e / f ** g; + (a % b) + c - (d * e) / f ** g; veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB; veryVeryVeryVeryVeryLongVariableCalledA - @@ -218,10 +218,7 @@ contract ArithmeticOperators { veryVeryVeryVeryVeryLongVariableCalledB; veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB - - c * - d / - e % - f ** g; + (((c * d) / e) % f ** g); a = veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB; @@ -562,16 +559,14 @@ contract LogicalOperators { function someFunction() { a && b; a || b; - a || b && c || d && e; + a || (b && c) || (d && e); veryVeryVeryVeryVeryLongVariableCalledA && veryVeryVeryVeryVeryLongVariableCalledB; veryVeryVeryVeryVeryLongVariableCalledA || veryVeryVeryVeryVeryLongVariableCalledB; veryVeryVeryVeryVeryLongVariableCalledA || - veryVeryVeryVeryVeryLongVariableCalledB && - c || - d && - e; + (veryVeryVeryVeryVeryLongVariableCalledB && c) || + (d && e); a = veryVeryVeryVeryVeryLongVariableCalledA && veryVeryVeryVeryVeryLongVariableCalledB; @@ -588,14 +583,14 @@ contract LogicalOperators { veryVeryVeryVeryVeryLongVariableCalledB ) {} if ( - veryVeryVeryVeryVeryLongVariableCalledA && - veryVeryVeryVeryVeryLongVariableCalledB || - c + ( + veryVeryVeryVeryVeryLongVariableCalledA && + veryVeryVeryVeryVeryLongVariableCalledB + ) || c ) {} if ( veryVeryVeryVeryVeryLongVariableCalledA || - veryVeryVeryVeryVeryLongVariableCalledB && - c + (veryVeryVeryVeryVeryLongVariableCalledB && c) ) {} while(veryVeryVeryVeryVeryLongVariableCalledA && veryVeryVeryVeryVeryLongVariableCalledB == a()){} @@ -603,12 +598,12 @@ contract LogicalOperators { veryVeryVeryVeryVeryLongVariableCalledB){} while(veryVeryVeryVeryVeryLongVariableCalledA && veryVeryVeryVeryVeryLongVariableCalledB){} - while(veryVeryVeryVeryVeryLongVariableCalledA && - veryVeryVeryVeryVeryLongVariableCalledB || - c){} + while(( + veryVeryVeryVeryVeryLongVariableCalledA && + veryVeryVeryVeryVeryLongVariableCalledB + ) || c){} while(veryVeryVeryVeryVeryLongVariableCalledA || - veryVeryVeryVeryVeryLongVariableCalledB && - c){} + (veryVeryVeryVeryVeryLongVariableCalledB && c)){} for ( a = veryVeryVeryVeryVeryLongVariableCalledA; a <= veryVeryVeryVeryVeryLongVariableCalledA; @@ -629,9 +624,11 @@ contract LogicalOperators { veryVeryVeryVeryVeryLongFunctionCalledA( veryVeryVeryVeryVeryLongVariableCalledB ) || - c && - veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB + ( + c && + veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) ) || d; a = @@ -1491,51 +1488,51 @@ contract Parentheses { a + b - c; a + b * c; a + b / c; - a + b % c; + a + (b % c); a + b ** c; - a + b << c; - a + b >> c; - a + b & c; - a + b | c; - a + b ^ c; + (a + b) << c; + (a + b) >> c; + (a + b) & c; + (a + b) | c; + (a + b) ^ c; a - b + c; a - b - c; a - b * c; a - b / c; - a - b % c; + a - (b % c); a - b ** c; - a - b << c; - a - b >> c; - a - b & c; - a - b | c; - a - b ^ c; + (a - b) << c; + (a - b) >> c; + (a - b) & c; + (a - b) | c; + (a - b) ^ c; a * b + c; a * b - c; a * b * c; - a * b / c; - a * b % c; + (a * b) / c; + (a * b) % c; a * b ** c; - a * b << c; - a * b >> c; - a * b & c; - a * b | c; - a * b ^ c; + (a * b) << c; + (a * b) >> c; + (a * b) & c; + (a * b) | c; + (a * b) ^ c; a / b + c; a / b - c; - a / b * c; + (a / b) * c; a / b / c; - a / b % c; + (a / b) % c; a / b ** c; - a / b << c; - a / b >> c; - a / b & c; - a / b | c; - a / b ^ c; - a % b + c; - a % b - c; - a % b * c; - a % b / c; - a % b % c; + (a / b) << c; + (a / b) >> c; + (a / b) & c; + (a / b) | c; + (a / b) ^ c; + (a % b) + c; + (a % b) - c; + (a % b) * c; + (a % b) / c; + (a % b) % c; a % b ** c; a % b << c; a % b >> c; @@ -1547,70 +1544,70 @@ contract Parentheses { a ** b * c; a ** b / c; a ** b % c; - a ** b ** c; - a ** b << c; - a ** b >> c; - a ** b & c; - a ** b | c; - a ** b ^ c; - a << b + c; - a << b - c; - a << b * c; - a << b / c; + (a ** b) ** c; + (a ** b) << c; + (a ** b) >> c; + (a ** b) & c; + (a ** b) | c; + (a ** b) ^ c; + a << (b + c); + a << (b - c); + a << (b * c); + a << (b / c); a << b % c; - a << b ** c; - a << b << c; - a << b >> c; - a << b & c; - a << b | c; - a << b ^ c; - a >> b + c; - a >> b - c; - a >> b * c; - a >> b / c; + a << (b ** c); + (a << b) << c; + (a << b) >> c; + (a << b) & c; + (a << b) | c; + (a << b) ^ c; + a >> (b + c); + a >> (b - c); + a >> (b * c); + a >> (b / c); a >> b % c; - a >> b ** c; - a >> b << c; - a >> b >> c; - a >> b & c; - a >> b | c; - a >> b ^ c; - a & b + c; - a & b - c; - a & b * c; - a & b / c; + a >> (b ** c); + (a >> b) << c; + (a >> b) >> c; + (a >> b) & c; + (a >> b) | c; + (a >> b) ^ c; + a & (b + c); + a & (b - c); + a & (b * c); + a & (b / c); a & b % c; - a & b ** c; - a & b << c; - a & b >> c; + a & (b ** c); + a & (b << c); + a & (b >> c); a & b & c; - a & b | c; - a & b ^ c; - a | b + c; - a | b - c; - a | b * c; - a | b / c; + (a & b) | c; + (a & b) ^ c; + a | (b + c); + a | (b - c); + a | (b * c); + a | (b / c); a | b % c; - a | b ** c; - a | b << c; - a | b >> c; - a | b & c; + a | (b ** c); + a | (b << c); + a | (b >> c); + a | (b & c); a | b | c; - a | b ^ c; - a ^ b + c; - a ^ b - c; - a ^ b * c; - a ^ b / c; + a | (b ^ c); + a ^ (b + c); + a ^ (b - c); + a ^ (b * c); + a ^ (b / c); a ^ b % c; - a ^ b ** c; - a ^ b << c; - a ^ b >> c; - a ^ b & c; - a ^ b | c; + a ^ (b ** c); + a ^ (b << c); + a ^ (b >> c); + a ^ (b & c); + (a ^ b) | c; a ^ b ^ c; a || b || c; - a || b && c; - a && b || c; + a || (b && c); + (a && b) || c; a && b && c; } } diff --git a/tests/format/Comments/__snapshots__/jsfmt.spec.js.snap b/tests/format/Comments/__snapshots__/jsfmt.spec.js.snap index 8592e9fbb..985b3e2b0 100644 --- a/tests/format/Comments/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Comments/__snapshots__/jsfmt.spec.js.snap @@ -1,5 +1,267 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Comments.sol - {"compiler":"0.5.0"} format 1`] = ` +====================================options===================================== +compiler: "0.5.0" +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity ^0.4.24; + + +contract Comments1 { + /* solhint-disable var-name-mixedcase */ +IEIP712DomainSeparator private EIP712domainSeparator; +bytes32 private _CACHED_DOMAIN_SEPARATOR; + + +/* solhint-enable var-name-mixedcase */ + + + function() { + // solhint-disable-previous-line no-empty-blocks + } + + function hello() public modifier1 modifier2 modifier3 modifier4 modifier5 modifier6 { + // solhint-disable-previous-line no-empty-blocks + } +} + + +contract Comments2 { + // solhint-disable-previous-line no-empty-blocks +} + + +contract Comments3 is Interface1, Interface2, Interface3, Interface4, Interface5, Interface6 { + // solhint-disable-previous-line no-empty-blocks + + function someFunction() { + + }/*1*//*2 + */ +} + +contract Comments4 is Interface1, Interface2, Interface3, Interface4, Interface5, Interface6 { + // solhint-disable-previous-line no-empty-blocks +} + +contract Comments5 /*nice name*/ { + // solhint-disable-previous-line no-empty-blocks +} + +contract Comments6 /*why the name \`Comments6\`*/ is Interface1/*why we used Interface1*/, Interface2/*why we used Interface2*/, Interface3, Interface4, Interface5, Interface6 { + // solhint-disable-previous-line no-empty-blocks +} + +contract Comments7 { + + + // 1 comment before first function + + + + // 2 comment before first function + + + + // 3 comment before first function + + function someFunction( + uint a, // the first value + uint b, // the second value + uint c // the lats value + ) { + someFunction( + a, // the first value + b, // the second value + c // the lats value + ); + } +} + +contract Comments8 { + function someFunction() { + if (something) { + } + // comment + else { + } + } +} + + +contract Comments8 { + function someFunction() { + if (something) { + } + /* comment + * comment */ + else { + } + } +} + +contract Comments9 { + function someFunction() { + if (something) + // a comment + f(); + else { + } + } +} + +interface Comments10 { + function someFunction( + // the first value + // the second value + // the lats value + ) /* comment outside the parameters */ external; + + function someOtherFunction(/* checking for Block comment */) external; +} + +contract Comments11 { + string a = "\\\\"; + string b = '\\\\'; + + function f() public { + // this should not be removed + } +} + +contract Comments12 { + function f() public { + purchaseData[0] = DomainPurchaseData({ + /* test */prices: _rootPrices, + // test2 + subdomainMintingEnabled: /* test3 */_rootPrices.short > 0, + allowSubdomainsToMint: true, // test4 + wasAllowedToSubdomainMintOnCreation: true + }); + } +} + +contract Comments13 { + function commentInModifierInvocation() + external + // comment 1 + modifier1 // comment 2 + ( + // comment 3 + ) // comment 4 + // comment 5 + modifier2 // comment 6 + ( + /* comment 7 */ + ) // comment 8 + modifier3 // comment 9 + ( + // comment 10 + param1 // comment 11 + // comment 12 + ) // comment 13 + { + } +} +=====================================output===================================== +pragma solidity ^0.4.24; +contract Comments1 { + IEIP712DomainSeparator private EIP712domainSeparator; + bytes32 private _CACHED_DOMAIN_SEPARATOR; + function() {} + function hello() + public + modifier1 + modifier2 + modifier3 + modifier4 + modifier5 + modifier6 + {} +} +contract Comments2 {} +contract Comments3 is + Interface1, + Interface2, + Interface3, + Interface4, + Interface5, + Interface6 +{ + function someFunction() {} +} +contract Comments4 is + Interface1, + Interface2, + Interface3, + Interface4, + Interface5, + Interface6 +{} +contract Comments5 {} +contract Comments6 is + Interface1, + Interface2, + Interface3, + Interface4, + Interface5, + Interface6 +{} +contract Comments7 { + function someFunction(uint a, uint b, uint c) { + someFunction(a, b, c); + } +} +contract Comments8 { + function someFunction() { + if (something) {} else {} + } +} +contract Comments8 { + function someFunction() { + if (something) {} else {} + } +} +contract Comments9 { + function someFunction() { + if (something) f(); + else {} + } +} +interface Comments10 { + function someFunction() external; + function someOtherFunction() external; +} +contract Comments11 { + string a = "\\\\"; + string b = "\\\\"; + function f() public {} +} +contract Comments12 { + function f() public { + purchaseData[0] = DomainPurchaseData({ + prices: _rootPrices, + subdomainMintingEnabled: _rootPrices.short > 0, + allowSubdomainsToMint: true, + wasAllowedToSubdomainMintOnCreation: true + }); + } +} +contract Comments13 { + function commentInModifierInvocation() + external + modifier1() + modifier2() + modifier3(param1) + {} +} + +================================================================================ +`; + exports[`Comments.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] diff --git a/tests/format/Comments/jsfmt.spec.js b/tests/format/Comments/jsfmt.spec.js index 765dd60a6..a6a1e4d2b 100644 --- a/tests/format/Comments/jsfmt.spec.js +++ b/tests/format/Comments/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse'], { compiler: '0.5.0' }); diff --git a/tests/format/ExperimentalTernaries/__snapshots__/jsfmt.spec.js.snap b/tests/format/ExperimentalTernaries/__snapshots__/jsfmt.spec.js.snap index 6685c733e..ee88f37ab 100644 --- a/tests/format/ExperimentalTernaries/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/ExperimentalTernaries/__snapshots__/jsfmt.spec.js.snap @@ -3753,26 +3753,34 @@ contract Conditional { : someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens(); - string storage multilineConditionsConsequentsAndAlternates = isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) + string storage multilineConditionsConsequentsAndAlternates = ( + isAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens() - : isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) + : ( + isNotAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? bark() : shortCondition() ? shortConsequent() : someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens(); - assignment = isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) + assignment = ( + isAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens() - : isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) + : ( + isNotAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? bark() : shortCondition() ? shortConsequent() @@ -3785,27 +3793,35 @@ contract Conditional { ? "two" : x == 3 ? "three" - : x == 5 && - y == 7 && - someOtherThing - .thatIsSoLong - .thatItBreaksTheTestCondition() + : ( + x == 5 && + y == 7 && + someOtherThing + .thatIsSoLong + .thatItBreaksTheTestCondition() + ) ? "four" : x == 6 ? "six" : "idk"; - string storage longConditional = bifornCringerMoshedPerplexSawder == - 2 / - askTrovenaBeenaDependsRowans && - glimseGlyphsHazardNoopsTieTie >= - averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() + string storage longConditional = ( + bifornCringerMoshedPerplexSawder == + 2 / + askTrovenaBeenaDependsRowans && + glimseGlyphsHazardNoopsTieTie >= + averredBathersBoxroomBuggyNurl() + .anodyneCondosMalateOverateRetinol() + ) ? "foo" : "bar"; - string storage longConditionalChained = bifornCringerMoshedPerplexSawder == - 2 / - askTrovenaBeenaDependsRowans && - glimseGlyphsHazardNoopsTieTie >= - averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() + string storage longConditionalChained = ( + bifornCringerMoshedPerplexSawder == + 2 / + askTrovenaBeenaDependsRowans && + glimseGlyphsHazardNoopsTieTie >= + averredBathersBoxroomBuggyNurl() + .anodyneCondosMalateOverateRetinol() + ) ? "foo" : anotherCondition ? "bar" @@ -3822,7 +3838,7 @@ contract Conditional { : definition.defaults : row[field] ); - (foo ? 1 : bar) ? 3 : 4; + (((foo ? 1 : bar))) ? 3 : 4; ( isCat() ? meow() diff --git a/tests/format/FunctionCalls/FunctionCalls.sol b/tests/format/FunctionCalls/FunctionCalls.sol index e432e1a4a..8d5450227 100644 --- a/tests/format/FunctionCalls/FunctionCalls.sol +++ b/tests/format/FunctionCalls/FunctionCalls.sol @@ -13,7 +13,7 @@ contract FunctionCalls { Voter airbnb = Voter({ weight: 2, - voted: true, + voted: true }); } function verify(ForwardRequest calldata req, bytes calldata signature) public view returns (bool) { diff --git a/tests/format/FunctionCalls/__snapshots__/jsfmt.spec.js.snap b/tests/format/FunctionCalls/__snapshots__/jsfmt.spec.js.snap index 3a1ad79d8..75be4dcb8 100644 --- a/tests/format/FunctionCalls/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/FunctionCalls/__snapshots__/jsfmt.spec.js.snap @@ -22,7 +22,7 @@ contract FunctionCalls { Voter airbnb = Voter({ weight: 2, - voted: true, + voted: true }); } function verify(ForwardRequest calldata req, bytes calldata signature) public view returns (bool) { @@ -153,6 +153,156 @@ contract FunctionCalls { ================================================================================ `; +exports[`FunctionCalls.sol - {"bracketSpacing":true} format 2`] = ` +====================================options===================================== +bracketSpacing: true +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +contract FunctionCalls { + function foo() { + address veryLongValidatorAddress = veryVeryVeryLongSignature.popLast20Bytes(); + } + + function foo() { + Voter you = Voter(1, true); + + Voter me = Voter({ + weight: 2, + voted: abstain() + }); + + Voter airbnb = Voter({ + weight: 2, + voted: true + }); + } + function verify(ForwardRequest calldata req, bytes calldata signature) public view returns (bool) { + address signer = + _hashTypedDataV1( + keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data))) + ) + ._hashTypedDataV2( + keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data))) + )._hashTypedDataV3( + keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data))) + ) .recover(signature); + signer = + _hashTypedDataV1( + keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data))) + ) + ._hashTypedDataV2( + keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data))) + )._hashTypedDataV3( + keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data))) + ) .recover(signature); + return _nonces[req.from] == req.nonce && signer == req.from; +} +} + +=====================================output===================================== +contract FunctionCalls { + function foo() { + address veryLongValidatorAddress = veryVeryVeryLongSignature + .popLast20Bytes(); + } + function foo() { + Voter you = Voter(1, true); + Voter me = Voter({weight: 2, voted: abstain()}); + Voter airbnb = Voter({weight: 2, voted: true}); + } + function verify( + ForwardRequest calldata req, + bytes calldata signature + ) public view returns (bool) { + address signer = _hashTypedDataV1( + keccak256( + abi.encode( + TYPEHASH, + req.from, + req.to, + req.value, + req.gas, + req.nonce, + keccak256(req.data) + ) + ) + ) + ._hashTypedDataV2( + keccak256( + abi.encode( + TYPEHASH, + req.from, + req.to, + req.value, + req.gas, + req.nonce, + keccak256(req.data) + ) + ) + ) + ._hashTypedDataV3( + keccak256( + abi.encode( + TYPEHASH, + req.from, + req.to, + req.value, + req.gas, + req.nonce, + keccak256(req.data) + ) + ) + ) + .recover(signature); + signer = _hashTypedDataV1( + keccak256( + abi.encode( + TYPEHASH, + req.from, + req.to, + req.value, + req.gas, + req.nonce, + keccak256(req.data) + ) + ) + ) + ._hashTypedDataV2( + keccak256( + abi.encode( + TYPEHASH, + req.from, + req.to, + req.value, + req.gas, + req.nonce, + keccak256(req.data) + ) + ) + ) + ._hashTypedDataV3( + keccak256( + abi.encode( + TYPEHASH, + req.from, + req.to, + req.value, + req.gas, + req.nonce, + keccak256(req.data) + ) + ) + ) + .recover(signature); + return _nonces[req.from] == req.nonce && signer == req.from; + } +} + +================================================================================ +`; + exports[`FunctionCalls.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] @@ -174,7 +324,7 @@ contract FunctionCalls { Voter airbnb = Voter({ weight: 2, - voted: true, + voted: true }); } function verify(ForwardRequest calldata req, bytes calldata signature) public view returns (bool) { @@ -304,3 +454,152 @@ contract FunctionCalls { ================================================================================ `; + +exports[`FunctionCalls.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +contract FunctionCalls { + function foo() { + address veryLongValidatorAddress = veryVeryVeryLongSignature.popLast20Bytes(); + } + + function foo() { + Voter you = Voter(1, true); + + Voter me = Voter({ + weight: 2, + voted: abstain() + }); + + Voter airbnb = Voter({ + weight: 2, + voted: true + }); + } + function verify(ForwardRequest calldata req, bytes calldata signature) public view returns (bool) { + address signer = + _hashTypedDataV1( + keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data))) + ) + ._hashTypedDataV2( + keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data))) + )._hashTypedDataV3( + keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data))) + ) .recover(signature); + signer = + _hashTypedDataV1( + keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data))) + ) + ._hashTypedDataV2( + keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data))) + )._hashTypedDataV3( + keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data))) + ) .recover(signature); + return _nonces[req.from] == req.nonce && signer == req.from; +} +} + +=====================================output===================================== +contract FunctionCalls { + function foo() { + address veryLongValidatorAddress = veryVeryVeryLongSignature + .popLast20Bytes(); + } + function foo() { + Voter you = Voter(1, true); + Voter me = Voter({weight: 2, voted: abstain()}); + Voter airbnb = Voter({weight: 2, voted: true}); + } + function verify( + ForwardRequest calldata req, + bytes calldata signature + ) public view returns (bool) { + address signer = _hashTypedDataV1( + keccak256( + abi.encode( + TYPEHASH, + req.from, + req.to, + req.value, + req.gas, + req.nonce, + keccak256(req.data) + ) + ) + ) + ._hashTypedDataV2( + keccak256( + abi.encode( + TYPEHASH, + req.from, + req.to, + req.value, + req.gas, + req.nonce, + keccak256(req.data) + ) + ) + ) + ._hashTypedDataV3( + keccak256( + abi.encode( + TYPEHASH, + req.from, + req.to, + req.value, + req.gas, + req.nonce, + keccak256(req.data) + ) + ) + ) + .recover(signature); + signer = _hashTypedDataV1( + keccak256( + abi.encode( + TYPEHASH, + req.from, + req.to, + req.value, + req.gas, + req.nonce, + keccak256(req.data) + ) + ) + ) + ._hashTypedDataV2( + keccak256( + abi.encode( + TYPEHASH, + req.from, + req.to, + req.value, + req.gas, + req.nonce, + keccak256(req.data) + ) + ) + ) + ._hashTypedDataV3( + keccak256( + abi.encode( + TYPEHASH, + req.from, + req.to, + req.value, + req.gas, + req.nonce, + keccak256(req.data) + ) + ) + ) + .recover(signature); + return _nonces[req.from] == req.nonce && signer == req.from; + } +} + +================================================================================ +`; diff --git a/tests/format/FunctionCalls/jsfmt.spec.js b/tests/format/FunctionCalls/jsfmt.spec.js index 993a81764..f9974c4c0 100644 --- a/tests/format/FunctionCalls/jsfmt.spec.js +++ b/tests/format/FunctionCalls/jsfmt.spec.js @@ -1,2 +1,4 @@ run_spec(import.meta, ['solidity-parse']); run_spec(import.meta, ['solidity-parse'], { bracketSpacing: true }); +run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['solidity-slang-parse'], { bracketSpacing: true }); diff --git a/tests/format/NameValueExpression/__snapshots__/jsfmt.spec.js.snap b/tests/format/NameValueExpression/__snapshots__/jsfmt.spec.js.snap index 7bb12c9a8..6839f7f0f 100644 --- a/tests/format/NameValueExpression/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/NameValueExpression/__snapshots__/jsfmt.spec.js.snap @@ -33,6 +33,38 @@ contract NameValueExpression { ================================================================================ `; +exports[`NameValueExpression.sol - {"bracketSpacing":true} format 2`] = ` +====================================options===================================== +bracketSpacing: true +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity >=0.6.2 <0.7.0; + +contract NameValueExpression { + function callFeed() public { feed.info{value: 10, gas: 800, test: true, many: variables(), to: check[0], forSplits: true}(); } + D newD = new D{value: amount}(arg); +} +=====================================output===================================== +pragma solidity >=0.6.2 <0.7.0; +contract NameValueExpression { + function callFeed() public { + feed.info{ + value: 10, + gas: 800, + test: true, + many: variables(), + to: check[0], + forSplits: true + }(); + } + D newD = new D{value: amount}(arg); +} + +================================================================================ +`; + exports[`NameValueExpression.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] @@ -64,3 +96,34 @@ contract NameValueExpression { ================================================================================ `; + +exports[`NameValueExpression.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity >=0.6.2 <0.7.0; + +contract NameValueExpression { + function callFeed() public { feed.info{value: 10, gas: 800, test: true, many: variables(), to: check[0], forSplits: true}(); } + D newD = new D{value: amount}(arg); +} +=====================================output===================================== +pragma solidity >=0.6.2 <0.7.0; +contract NameValueExpression { + function callFeed() public { + feed.info{ + value: 10, + gas: 800, + test: true, + many: variables(), + to: check[0], + forSplits: true + }(); + } + D newD = new D{value: amount}(arg); +} + +================================================================================ +`; diff --git a/tests/format/NameValueExpression/jsfmt.spec.js b/tests/format/NameValueExpression/jsfmt.spec.js index 993a81764..f9974c4c0 100644 --- a/tests/format/NameValueExpression/jsfmt.spec.js +++ b/tests/format/NameValueExpression/jsfmt.spec.js @@ -1,2 +1,4 @@ run_spec(import.meta, ['solidity-parse']); run_spec(import.meta, ['solidity-parse'], { bracketSpacing: true }); +run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['solidity-slang-parse'], { bracketSpacing: true }); diff --git a/tests/format/Parentheses/__snapshots__/jsfmt.spec.js.snap b/tests/format/Parentheses/__snapshots__/jsfmt.spec.js.snap index 0992b9291..49dc22e97 100644 --- a/tests/format/Parentheses/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Parentheses/__snapshots__/jsfmt.spec.js.snap @@ -333,7 +333,7 @@ contract AddNoParentheses { uint256 b, uint256 c ) public pure returns (uint256) { - return a + b % c; + return a + (b % c); } function addExp( uint256 a, @@ -347,35 +347,35 @@ contract AddNoParentheses { uint256 b, uint256 c ) public pure returns (uint256) { - return a + b << c; + return (a + b) << c; } function addShiftR( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a + b >> c; + return (a + b) >> c; } function addBitAnd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a + b & c; + return (a + b) & c; } function addBitOr( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a + b | c; + return (a + b) | c; } function addBitXor( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a + b ^ c; + return (a + b) ^ c; } } @@ -687,28 +687,28 @@ contract BitAndNoParentheses { uint256 b, uint256 c ) public pure returns (uint256) { - return a & b + c; + return a & (b + c); } function bitAndSub( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a & b - c; + return a & (b - c); } function bitAndMul( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a & b * c; + return a & (b * c); } function bitAndDiv( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a & b / c; + return a & (b / c); } function bitAndMod( uint256 a, @@ -722,21 +722,21 @@ contract BitAndNoParentheses { uint256 b, uint256 c ) public pure returns (uint256) { - return a & b ** c; + return a & (b ** c); } function bitAndShiftL( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a & b << c; + return a & (b << c); } function bitAndShiftR( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a & b >> c; + return a & (b >> c); } function bitAndBitAnd( uint256 a, @@ -750,14 +750,14 @@ contract BitAndNoParentheses { uint256 b, uint256 c ) public pure returns (uint256) { - return a & b | c; + return (a & b) | c; } function bitAndBitXor( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a & b ^ c; + return (a & b) ^ c; } } @@ -1069,28 +1069,28 @@ contract BitOrNoParentheses { uint256 b, uint256 c ) public pure returns (uint256) { - return a | b + c; + return a | (b + c); } function bitOrSub( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | b - c; + return a | (b - c); } function bitOrMul( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | b * c; + return a | (b * c); } function bitOrDiv( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | b / c; + return a | (b / c); } function bitOrMod( uint256 a, @@ -1104,28 +1104,28 @@ contract BitOrNoParentheses { uint256 b, uint256 c ) public pure returns (uint256) { - return a | b ** c; + return a | (b ** c); } function bitOrShiftL( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | b << c; + return a | (b << c); } function bitOrShiftR( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | b >> c; + return a | (b >> c); } function bitOrBitAnd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | b & c; + return a | (b & c); } function bitOrBitOr( uint256 a, @@ -1139,7 +1139,7 @@ contract BitOrNoParentheses { uint256 b, uint256 c ) public pure returns (uint256) { - return a | b ^ c; + return a | (b ^ c); } } @@ -1451,28 +1451,28 @@ contract BitXorNoParentheses { uint256 b, uint256 c ) public pure returns (uint256) { - return a ^ b + c; + return a ^ (b + c); } function bitXorSub( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a ^ b - c; + return a ^ (b - c); } function bitXorMul( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a ^ b * c; + return a ^ (b * c); } function bitXorDiv( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a ^ b / c; + return a ^ (b / c); } function bitXorMod( uint256 a, @@ -1486,35 +1486,35 @@ contract BitXorNoParentheses { uint256 b, uint256 c ) public pure returns (uint256) { - return a ^ b ** c; + return a ^ (b ** c); } function bitXorShiftL( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a ^ b << c; + return a ^ (b << c); } function bitXorShiftR( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a ^ b >> c; + return a ^ (b >> c); } function bitXorBitAnd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a ^ b & c; + return a ^ (b & c); } function bitXorBitOr( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a ^ b | c; + return (a ^ b) | c; } function bitXorBitXor( uint256 a, @@ -1847,7 +1847,7 @@ contract DivNoParentheses { uint256 b, uint256 c ) public pure returns (uint256) { - return a / b * c; + return (a / b) * c; } function divDiv( uint256 a, @@ -1861,7 +1861,7 @@ contract DivNoParentheses { uint256 b, uint256 c ) public pure returns (uint256) { - return a / b % c; + return (a / b) % c; } function divExp( uint256 a, @@ -1875,35 +1875,35 @@ contract DivNoParentheses { uint256 b, uint256 c ) public pure returns (uint256) { - return a / b << c; + return (a / b) << c; } function divShiftR( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a / b >> c; + return (a / b) >> c; } function divBitAnd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a / b & c; + return (a / b) & c; } function divBitOr( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a / b | c; + return (a / b) | c; } function divBitXor( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a / b ^ c; + return (a / b) ^ c; } } @@ -2250,42 +2250,42 @@ contract ExpNoParentheses { uint256 b, uint256 c ) public pure returns (uint256) { - return a ** b ** c; + return a ** (b ** c); } function expShiftL( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a ** b << c; + return (a ** b) << c; } function expShiftR( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a ** b >> c; + return (a ** b) >> c; } function expBitAnd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a ** b & c; + return (a ** b) & c; } function expBitOr( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a ** b | c; + return (a ** b) | c; } function expBitXor( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a ** b ^ c; + return (a ** b) ^ c; } } @@ -2380,10 +2380,10 @@ contract LogicNoParentheses { return a || b || c; } function orAnd(bool a, bool b, bool c) public pure returns (bool) { - return a || b && c; + return a || (b && c); } function andOr(bool a, bool b, bool c) public pure returns (bool) { - return a && b || c; + return (a && b) || c; } function andAnd(bool a, bool b, bool c) public pure returns (bool) { return a && b && c; @@ -2698,35 +2698,35 @@ contract ModNoParentheses { uint256 b, uint256 c ) public pure returns (uint256) { - return a % b + c; + return (a % b) + c; } function modSub( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a % b - c; + return (a % b) - c; } function modMul( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a % b * c; + return (a % b) * c; } function modDiv( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a % b / c; + return (a % b) / c; } function modMod( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a % b % c; + return (a % b) % c; } function modExp( uint256 a, @@ -3101,14 +3101,14 @@ contract MulNoParentheses { uint256 b, uint256 c ) public pure returns (uint256) { - return a * b / c; + return (a * b) / c; } function mulMod( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a * b % c; + return (a * b) % c; } function mulExp( uint256 a, @@ -3122,35 +3122,35 @@ contract MulNoParentheses { uint256 b, uint256 c ) public pure returns (uint256) { - return a * b << c; + return (a * b) << c; } function mulShiftR( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a * b >> c; + return (a * b) >> c; } function mulBitAnd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a * b & c; + return (a * b) & c; } function mulBitOr( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a * b | c; + return (a * b) | c; } function mulBitXor( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a * b ^ c; + return (a * b) ^ c; } } @@ -3462,28 +3462,28 @@ contract ShiftLNoParentheses { uint256 b, uint256 c ) public pure returns (uint256) { - return a << b + c; + return a << (b + c); } function shiftLSub( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a << b - c; + return a << (b - c); } function shiftLMul( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a << b * c; + return a << (b * c); } function shiftLDiv( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a << b / c; + return a << (b / c); } function shiftLMod( uint256 a, @@ -3497,42 +3497,42 @@ contract ShiftLNoParentheses { uint256 b, uint256 c ) public pure returns (uint256) { - return a << b ** c; + return a << (b ** c); } function shiftLShiftL( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a << b << c; + return (a << b) << c; } function shiftLShiftR( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a << b >> c; + return (a << b) >> c; } function shiftLBitAnd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a << b & c; + return (a << b) & c; } function shiftLBitOr( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a << b | c; + return (a << b) | c; } function shiftLBitXor( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a << b ^ c; + return (a << b) ^ c; } } @@ -3844,28 +3844,28 @@ contract ShiftRNoParentheses { uint256 b, uint256 c ) public pure returns (uint256) { - return a >> b + c; + return a >> (b + c); } function shiftRSub( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a >> b - c; + return a >> (b - c); } function shiftRMul( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a >> b * c; + return a >> (b * c); } function shiftRDiv( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a >> b / c; + return a >> (b / c); } function shiftRMod( uint256 a, @@ -3879,42 +3879,42 @@ contract ShiftRNoParentheses { uint256 b, uint256 c ) public pure returns (uint256) { - return a >> b ** c; + return a >> (b ** c); } function shiftRShiftL( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a >> b << c; + return (a >> b) << c; } function shiftRShiftR( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a >> b >> c; + return (a >> b) >> c; } function shiftRBitAnd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a >> b & c; + return (a >> b) & c; } function shiftRBitOr( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a >> b | c; + return (a >> b) | c; } function shiftRBitXor( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a >> b ^ c; + return (a >> b) ^ c; } } @@ -4254,7 +4254,7 @@ contract SubNoParentheses { uint256 b, uint256 c ) public pure returns (uint256) { - return a - b % c; + return a - (b % c); } function subExp( uint256 a, @@ -4268,37 +4268,225 @@ contract SubNoParentheses { uint256 b, uint256 c ) public pure returns (uint256) { - return a - b << c; + return (a - b) << c; } function subShiftR( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a - b >> c; + return (a - b) >> c; } function subBitAnd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a - b & c; + return (a - b) & c; } function subBitOr( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a - b | c; + return (a - b) | c; } function subBitXor( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a - b ^ c; + return (a - b) ^ c; } } ================================================================================ `; + +exports[`a.js - {"compiler":"0.8.6"} format 1`] = ` +====================================options===================================== +compiler: "0.8.6" +parsers: ["solidity-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +function addAdd(a, b, c) { + return a + b + c; +} + +function addSub(a, b, c) { + return a + b - c; +} + +function addMul(a, b, c) { + return a + b * c; +} + +function addDiv(a, b, c) { + return a + b / c; +} + +function addMod(a, b, c) { + return a + (b % c); +} + +function addExp(a, b, c) { + return a + b ** c; +} + +function addShiftL(a, b, c) { + return (a + b) << c; +} + +function addShiftR(a, b, c) { + return (a + b) >> c; +} + +function addBitAnd(a, b, c) { + return (a + b) & c; +} + +function addBitOr(a, b, c) { + return (a + b) | c; +} + +function addBitXor(a, b, c) { + return (a + b) ^ c; +} + +=====================================output===================================== +function addAdd(a, b, c) { + return a + b + c; +} + +function addSub(a, b, c) { + return a + b - c; +} + +function addMul(a, b, c) { + return a + b * c; +} + +function addDiv(a, b, c) { + return a + b / c; +} + +function addMod(a, b, c) { + return a + (b % c); +} + +function addExp(a, b, c) { + return a + b ** c; +} + +function addShiftL(a, b, c) { + return (a + b) << c; +} + +function addShiftR(a, b, c) { + return (a + b) >> c; +} + +function addBitAnd(a, b, c) { + return (a + b) & c; +} + +function addBitOr(a, b, c) { + return (a + b) | c; +} + +function addBitXor(a, b, c) { + return (a + b) ^ c; +} + +================================================================================ +`; + +exports[`a.js - {"compiler":"0.8.6"} format 2`] = ` +====================================options===================================== +compiler: "0.8.6" +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +function addAdd(a, b, c) { + return a + b + c; +} + +function addSub(a, b, c) { + return a + b - c; +} + +function addMul(a, b, c) { + return a + b * c; +} + +function addDiv(a, b, c) { + return a + b / c; +} + +function addMod(a, b, c) { + return a + (b % c); +} + +function addExp(a, b, c) { + return a + b ** c; +} + +function addShiftL(a, b, c) { + return (a + b) << c; +} + +function addShiftR(a, b, c) { + return (a + b) >> c; +} + +function addBitAnd(a, b, c) { + return (a + b) & c; +} + +function addBitOr(a, b, c) { + return (a + b) | c; +} + +function addBitXor(a, b, c) { + return (a + b) ^ c; +} + +=====================================output===================================== +function addAdd(a, b, c) { + return a + b + c; +} +function addSub(a, b, c) { + return a + b - c; +} +function addMul(a, b, c) { + return a + b * c; +} +function addDiv(a, b, c) { + return a + b / c; +} +function addMod(a, b, c) { + return a + (b % c); +} +function addExp(a, b, c) { + return a + b ** c; +} +function addShiftL(a, b, c) { + return (a + b) << c; +} +function addShiftR(a, b, c) { + return (a + b) >> c; +} +function addBitAnd(a, b, c) { + return (a + b) & c; +} +function addBitOr(a, b, c) { + return (a + b) | c; +} +function addBitXor(a, b, c) { + return (a + b) ^ c; +} + +================================================================================ +`; diff --git a/tests/format/PrettierIgnore/PrettierIgnore.sol b/tests/format/PrettierIgnore/PrettierIgnore.sol index a58b95d94..b2e54f789 100644 --- a/tests/format/PrettierIgnore/PrettierIgnore.sol +++ b/tests/format/PrettierIgnore/PrettierIgnore.sol @@ -1,7 +1,7 @@ pragma solidity ^0.5.2; contract PrettierIgnore { - function() public payable { + fallback() external payable { matrix( 1, 0, 0, 0, 1, 0, @@ -20,7 +20,7 @@ contract PrettierIgnore { // prettier-ignore contract Example { // Test comment - function() public payable { + fallback() external payable { // This should be marked as printed // Everything inside is also ignored matrix( diff --git a/tests/format/PrettierIgnore/__snapshots__/jsfmt.spec.js.snap b/tests/format/PrettierIgnore/__snapshots__/jsfmt.spec.js.snap index ee5f28cc3..a323840c3 100644 --- a/tests/format/PrettierIgnore/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/PrettierIgnore/__snapshots__/jsfmt.spec.js.snap @@ -9,7 +9,7 @@ printWidth: 80 pragma solidity ^0.5.2; contract PrettierIgnore { - function() public payable { + fallback() external payable { matrix( 1, 0, 0, 0, 1, 0, @@ -28,7 +28,7 @@ contract PrettierIgnore { // prettier-ignore contract Example { // Test comment - function() public payable { + fallback() external payable { // This should be marked as printed // Everything inside is also ignored matrix( @@ -50,7 +50,7 @@ contract Example { pragma solidity ^0.5.2; contract PrettierIgnore { - function() public payable { + fallback() external payable { matrix(1, 0, 0, 0, 1, 0, 0, 0, 1); // prettier-ignore @@ -65,7 +65,7 @@ contract PrettierIgnore { // prettier-ignore contract Example { // Test comment - function() public payable { + fallback() external payable { // This should be marked as printed // Everything inside is also ignored matrix( @@ -85,3 +85,68 @@ contract Example { ================================================================================ `; + +exports[`PrettierIgnore.sol format 2`] = ` +====================================options===================================== +parsers: ["solidity-slang-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity ^0.5.2; + +contract PrettierIgnore { + fallback() external payable { + matrix( + 1, 0, 0, + 0, 1, 0, + 0, 0, 1 + ); + + // prettier-ignore + matrix( + 1, 0, 0, + 0, 1, 0, + 0, 0, 1 + ); + } +} + +// prettier-ignore +contract Example { +// Test comment + fallback() external payable { + // This should be marked as printed + // Everything inside is also ignored + matrix( + 1, 0, 0, + 0, 1, 0, + 0, 0, 1 + ); + // Comments for members of an Array are marked as printed + if (true) + // Comments of single child Objects are marked as printed + return; + else + // Comments of children should be marked as printed + return; + } +} + +=====================================output===================================== +pragma solidity ^0.5.2; +contract PrettierIgnore { + fallback() external payable { + matrix(1, 0, 0, 0, 1, 0, 0, 0, 1); + matrix(1, 0, 0, 0, 1, 0, 0, 0, 1); + } +} +contract Example { + fallback() external payable { + matrix(1, 0, 0, 0, 1, 0, 0, 0, 1); + if (true) return; + else return; + } +} + +================================================================================ +`; diff --git a/tests/format/PrettierIgnore/jsfmt.spec.js b/tests/format/PrettierIgnore/jsfmt.spec.js index 765dd60a6..fd56c17bc 100644 --- a/tests/format/PrettierIgnore/jsfmt.spec.js +++ b/tests/format/PrettierIgnore/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-slang-parse']); From 9b5e403f3be5ffc533d7da3c7ca36fc405c14537 Mon Sep 17 00:00:00 2001 From: Klaus Date: Sun, 16 Jun 2024 13:01:59 +1200 Subject: [PATCH 029/160] WIP: 206/215 printers implemented --- src/common/slang-helpers.js | 2 +- src/slang-nodes/ContinueStatement.js | 3 +-- src/slang-nodes/UsingAlias.js | 6 ++++-- src/slang-nodes/YulBreakStatement.js | 2 +- src/slang-nodes/YulContinueStatement.js | 2 +- tests/format/Libraries/Libraries.sol | 1 + tests/format/Libraries/__snapshots__/jsfmt.spec.js.snap | 8 ++++++++ 7 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/common/slang-helpers.js b/src/common/slang-helpers.js index 1e7d6703d..c3d374a6b 100644 --- a/src/common/slang-helpers.js +++ b/src/common/slang-helpers.js @@ -162,7 +162,7 @@ export const tryHug = (node, operators) => { openParen: '(', items: { kind: 'TupleValues', - items: [node], + items: [{ kind: 'TupleValue', expression: node }], separators: [] }, closeParen: ')' diff --git a/src/slang-nodes/ContinueStatement.js b/src/slang-nodes/ContinueStatement.js index 9033b1171..e65e1cfdc 100644 --- a/src/slang-nodes/ContinueStatement.js +++ b/src/slang-nodes/ContinueStatement.js @@ -4,6 +4,5 @@ export const ContinueStatement = { continueKeyword: ast.continueKeyword.text, semicolon: ast.semicolon.text }), - // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: ContinueStatement'] + print: ({ node }) => `${node.continueKeyword}${node.semicolon}` }; diff --git a/src/slang-nodes/UsingAlias.js b/src/slang-nodes/UsingAlias.js index 6bf584658..6d1cffb61 100644 --- a/src/slang-nodes/UsingAlias.js +++ b/src/slang-nodes/UsingAlias.js @@ -4,6 +4,8 @@ export const UsingAlias = { asKeyword: ast.asKeyword.text, operator: parse(ast.operator, options, parse) }), - // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: UsingAlias'] + print: ({ node, path, print }) => [ + ` ${node.asKeyword} `, + path.call(print, 'operator') + ] }; diff --git a/src/slang-nodes/YulBreakStatement.js b/src/slang-nodes/YulBreakStatement.js index 50dd95ed4..6b5f55781 100644 --- a/src/slang-nodes/YulBreakStatement.js +++ b/src/slang-nodes/YulBreakStatement.js @@ -3,5 +3,5 @@ export const YulBreakStatement = { kind: ast.cst.kind, breakKeyword: ast.breakKeyword.text }), - print: ({node}) => node.breakKeyword + print: ({ node }) => node.breakKeyword }; diff --git a/src/slang-nodes/YulContinueStatement.js b/src/slang-nodes/YulContinueStatement.js index f9c0fd0b6..8e1f4fb6d 100644 --- a/src/slang-nodes/YulContinueStatement.js +++ b/src/slang-nodes/YulContinueStatement.js @@ -3,5 +3,5 @@ export const YulContinueStatement = { kind: ast.cst.kind, continueKeyword: ast.continueKeyword.text }), - print: ({node}) => node.continueKeyword + print: ({ node }) => node.continueKeyword }; diff --git a/tests/format/Libraries/Libraries.sol b/tests/format/Libraries/Libraries.sol index 09dfa2f2d..aa023147f 100644 --- a/tests/format/Libraries/Libraries.sol +++ b/tests/format/Libraries/Libraries.sol @@ -3,6 +3,7 @@ using Lib for uint global; using { f} for uint; using {f } for uint global; +using {f as +} for uint global; using { a, very, long, and, complex, Function, list, with, long, names } for uint; using { a, very, diff --git a/tests/format/Libraries/__snapshots__/jsfmt.spec.js.snap b/tests/format/Libraries/__snapshots__/jsfmt.spec.js.snap index 926b4647f..03420de41 100644 --- a/tests/format/Libraries/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Libraries/__snapshots__/jsfmt.spec.js.snap @@ -12,6 +12,7 @@ using Lib for uint global; using { f} for uint; using {f } for uint global; +using {f as +} for uint global; using { a, very, long, and, complex, Function, list, with, long, names } for uint; using { a, very, @@ -23,6 +24,7 @@ using Lib for uint; using Lib for uint global; using { f } for uint; using { f } for uint global; +using { f as + } for uint global; using { a, very, @@ -63,6 +65,7 @@ using Lib for uint global; using { f} for uint; using {f } for uint global; +using {f as +} for uint global; using { a, very, long, and, complex, Function, list, with, long, names } for uint; using { a, very, @@ -74,6 +77,7 @@ using Lib for uint; using Lib for uint global; using { f } for uint; using { f } for uint global; +using { f as + } for uint global; using { a, very, @@ -113,6 +117,7 @@ using Lib for uint global; using { f} for uint; using {f } for uint global; +using {f as +} for uint global; using { a, very, long, and, complex, Function, list, with, long, names } for uint; using { a, very, @@ -124,6 +129,7 @@ using Lib for uint; using Lib for uint global; using {f} for uint; using {f} for uint global; +using {f as +} for uint global; using {a, very, long, and, complex, Function, list, with, long, names} for uint; using { a, @@ -152,6 +158,7 @@ using Lib for uint global; using { f} for uint; using {f } for uint global; +using {f as +} for uint global; using { a, very, long, and, complex, Function, list, with, long, names } for uint; using { a, very, @@ -163,6 +170,7 @@ using Lib for uint; using Lib for uint global; using {f} for uint; using {f} for uint global; +using {f as +} for uint global; using {a, very, long, and, complex, Function, list, with, long, names} for uint; using { a, From f9ed6f89b105ccb270b628006f4b4e0e3eb0acf4 Mon Sep 17 00:00:00 2001 From: Klaus Date: Sun, 16 Jun 2024 15:46:05 +1200 Subject: [PATCH 030/160] recolect cst Metadata at the general parser level --- src/slang-nodes/ABICoderPragma.js | 1 - src/slang-nodes/AdditiveExpression.js | 1 - src/slang-nodes/AddressType.js | 1 - src/slang-nodes/AndExpression.js | 1 - src/slang-nodes/ArgumentsDeclaration.js | 1 - src/slang-nodes/ArrayExpression.js | 1 - src/slang-nodes/ArrayTypeName.js | 1 - src/slang-nodes/ArrayValues.js | 1 - src/slang-nodes/AssemblyFlags.js | 1 - src/slang-nodes/AssemblyFlagsDeclaration.js | 1 - src/slang-nodes/AssemblyStatement.js | 1 - src/slang-nodes/AssignmentExpression.js | 1 - src/slang-nodes/BitwiseAndExpression.js | 1 - src/slang-nodes/BitwiseOrExpression.js | 1 - src/slang-nodes/BitwiseXorExpression.js | 1 - src/slang-nodes/Block.js | 1 - src/slang-nodes/BreakStatement.js | 1 - src/slang-nodes/CallOptions.js | 1 - src/slang-nodes/CallOptionsExpression.js | 1 - src/slang-nodes/CatchClause.js | 1 - src/slang-nodes/CatchClauseError.js | 1 - src/slang-nodes/CatchClauses.js | 1 - src/slang-nodes/ComparisonExpression.js | 1 - src/slang-nodes/ConditionalExpression.js | 1 - src/slang-nodes/ConstantDefinition.js | 1 - src/slang-nodes/ConstructorAttribute.js | 1 - src/slang-nodes/ConstructorAttributes.js | 1 - src/slang-nodes/ConstructorDefinition.js | 1 - src/slang-nodes/ContinueStatement.js | 1 - src/slang-nodes/ContractDefinition.js | 1 - src/slang-nodes/ContractMember.js | 1 - src/slang-nodes/ContractMembers.js | 1 - src/slang-nodes/DecimalNumberExpression.js | 1 - src/slang-nodes/DoWhileStatement.js | 1 - src/slang-nodes/ElementaryType.js | 1 - src/slang-nodes/ElseBranch.js | 1 - src/slang-nodes/EmitStatement.js | 1 - src/slang-nodes/EnumDefinition.js | 1 - src/slang-nodes/EnumMembers.js | 1 - src/slang-nodes/EqualityExpression.js | 1 - src/slang-nodes/ErrorDefinition.js | 1 - src/slang-nodes/ErrorParameter.js | 1 - src/slang-nodes/ErrorParameters.js | 1 - src/slang-nodes/ErrorParametersDeclaration.js | 1 - src/slang-nodes/EventDefinition.js | 1 - src/slang-nodes/EventParameter.js | 1 - src/slang-nodes/EventParameters.js | 1 - src/slang-nodes/EventParametersDeclaration.js | 1 - src/slang-nodes/ExperimentalFeature.js | 1 - src/slang-nodes/ExperimentalPragma.js | 1 - src/slang-nodes/ExponentiationExpression.js | 1 - src/slang-nodes/Expression.js | 1 - src/slang-nodes/ExpressionStatement.js | 1 - src/slang-nodes/FallbackFunctionAttribute.js | 1 - src/slang-nodes/FallbackFunctionAttributes.js | 1 - src/slang-nodes/FallbackFunctionDefinition.js | 1 - src/slang-nodes/ForStatement.js | 1 - src/slang-nodes/ForStatementCondition.js | 1 - src/slang-nodes/ForStatementInitialization.js | 1 - src/slang-nodes/FunctionAttribute.js | 1 - src/slang-nodes/FunctionAttributes.js | 1 - src/slang-nodes/FunctionBody.js | 2 -- src/slang-nodes/FunctionCallExpression.js | 1 - src/slang-nodes/FunctionDefinition.js | 1 - src/slang-nodes/FunctionName.js | 1 - src/slang-nodes/FunctionType.js | 1 - src/slang-nodes/FunctionTypeAttribute.js | 1 - src/slang-nodes/FunctionTypeAttributes.js | 1 - src/slang-nodes/HexNumberExpression.js | 1 - src/slang-nodes/HexStringLiteral.js | 1 - src/slang-nodes/HexStringLiterals.js | 1 - src/slang-nodes/IdentifierPath.js | 1 - src/slang-nodes/IfStatement.js | 1 - src/slang-nodes/ImportAlias.js | 1 - src/slang-nodes/ImportClause.js | 1 - src/slang-nodes/ImportDeconstruction.js | 1 - src/slang-nodes/ImportDeconstructionSymbol.js | 1 - src/slang-nodes/ImportDeconstructionSymbols.js | 1 - src/slang-nodes/ImportDirective.js | 1 - src/slang-nodes/IndexAccessEnd.js | 1 - src/slang-nodes/IndexAccessExpression.js | 1 - src/slang-nodes/InheritanceSpecifier.js | 1 - src/slang-nodes/InheritanceType.js | 1 - src/slang-nodes/InheritanceTypes.js | 1 - src/slang-nodes/InterfaceDefinition.js | 1 - src/slang-nodes/InterfaceMembers.js | 1 - src/slang-nodes/LibraryDefinition.js | 1 - src/slang-nodes/LibraryMembers.js | 1 - src/slang-nodes/MappingKey.js | 1 - src/slang-nodes/MappingKeyType.js | 1 - src/slang-nodes/MappingType.js | 1 - src/slang-nodes/MappingValue.js | 1 - src/slang-nodes/MemberAccess.js | 1 - src/slang-nodes/MemberAccessExpression.js | 1 - src/slang-nodes/ModifierAttribute.js | 1 - src/slang-nodes/ModifierAttributes.js | 1 - src/slang-nodes/ModifierDefinition.js | 1 - src/slang-nodes/ModifierInvocation.js | 1 - src/slang-nodes/MultiplicativeExpression.js | 1 - src/slang-nodes/NamedArgument.js | 1 - src/slang-nodes/NamedArgumentGroup.js | 1 - src/slang-nodes/NamedArguments.js | 1 - src/slang-nodes/NamedArgumentsDeclaration.js | 1 - src/slang-nodes/NamedImport.js | 1 - src/slang-nodes/NewExpression.js | 1 - src/slang-nodes/NumberUnit.js | 1 - src/slang-nodes/OrExpression.js | 1 - src/slang-nodes/OverridePaths.js | 1 - src/slang-nodes/OverridePathsDeclaration.js | 1 - src/slang-nodes/OverrideSpecifier.js | 1 - src/slang-nodes/Parameter.js | 1 - src/slang-nodes/Parameters.js | 1 - src/slang-nodes/ParametersDeclaration.js | 1 - src/slang-nodes/PathImport.js | 1 - src/slang-nodes/PositionalArguments.js | 1 - src/slang-nodes/PositionalArgumentsDeclaration.js | 1 - src/slang-nodes/PostfixExpression.js | 1 - src/slang-nodes/Pragma.js | 1 - src/slang-nodes/PragmaDirective.js | 1 - src/slang-nodes/PrefixExpression.js | 1 - src/slang-nodes/ReceiveFunctionAttribute.js | 1 - src/slang-nodes/ReceiveFunctionAttributes.js | 1 - src/slang-nodes/ReceiveFunctionDefinition.js | 1 - src/slang-nodes/ReturnStatement.js | 1 - src/slang-nodes/ReturnsDeclaration.js | 1 - src/slang-nodes/RevertStatement.js | 1 - src/slang-nodes/ShiftExpression.js | 1 - src/slang-nodes/SourceUnit.js | 1 - src/slang-nodes/SourceUnitMember.js | 1 - src/slang-nodes/SourceUnitMembers.js | 1 - src/slang-nodes/StateVariableAttribute.js | 1 - src/slang-nodes/StateVariableAttributes.js | 1 - src/slang-nodes/StateVariableDefinition.js | 1 - src/slang-nodes/StateVariableDefinitionValue.js | 1 - src/slang-nodes/Statement.js | 1 - src/slang-nodes/Statements.js | 1 - src/slang-nodes/StorageLocation.js | 1 - src/slang-nodes/StringExpression.js | 1 - src/slang-nodes/StringLiteral.js | 1 - src/slang-nodes/StringLiterals.js | 1 - src/slang-nodes/StructDefinition.js | 1 - src/slang-nodes/StructMember.js | 1 - src/slang-nodes/StructMembers.js | 1 - src/slang-nodes/ThrowStatement.js | 1 - src/slang-nodes/TryStatement.js | 1 - src/slang-nodes/TupleDeconstructionElement.js | 1 - src/slang-nodes/TupleDeconstructionElements.js | 1 - src/slang-nodes/TupleDeconstructionStatement.js | 1 - src/slang-nodes/TupleExpression.js | 1 - src/slang-nodes/TupleMember.js | 1 - src/slang-nodes/TupleValue.js | 1 - src/slang-nodes/TupleValues.js | 1 - src/slang-nodes/TypeExpression.js | 1 - src/slang-nodes/TypeName.js | 1 - src/slang-nodes/TypedTupleMember.js | 1 - src/slang-nodes/UncheckedBlock.js | 1 - src/slang-nodes/UnicodeStringLiteral.js | 1 - src/slang-nodes/UnicodeStringLiterals.js | 1 - src/slang-nodes/UnnamedFunctionAttribute.js | 1 - src/slang-nodes/UnnamedFunctionAttributes.js | 1 - src/slang-nodes/UnnamedFunctionDefinition.js | 1 - src/slang-nodes/UntypedTupleMember.js | 1 - src/slang-nodes/UserDefinedValueTypeDefinition.js | 1 - src/slang-nodes/UsingAlias.js | 1 - src/slang-nodes/UsingClause.js | 1 - src/slang-nodes/UsingDeconstruction.js | 1 - src/slang-nodes/UsingDeconstructionSymbol.js | 1 - src/slang-nodes/UsingDeconstructionSymbols.js | 1 - src/slang-nodes/UsingDirective.js | 1 - src/slang-nodes/UsingOperator.js | 1 - src/slang-nodes/UsingTarget.js | 1 - src/slang-nodes/VariableDeclarationStatement.js | 1 - src/slang-nodes/VariableDeclarationType.js | 1 - src/slang-nodes/VariableDeclarationValue.js | 1 - src/slang-nodes/VersionComparator.js | 1 - src/slang-nodes/VersionExpression.js | 1 - src/slang-nodes/VersionExpressionSet.js | 1 - src/slang-nodes/VersionExpressionSets.js | 1 - src/slang-nodes/VersionPragma.js | 1 - src/slang-nodes/VersionRange.js | 1 - src/slang-nodes/VersionSpecifiers.js | 1 - src/slang-nodes/WhileStatement.js | 1 - src/slang-nodes/YulArguments.js | 1 - src/slang-nodes/YulAssignmentOperator.js | 1 - src/slang-nodes/YulAssignmentStatement.js | 1 - src/slang-nodes/YulBlock.js | 1 - src/slang-nodes/YulBreakStatement.js | 1 - src/slang-nodes/YulBuiltInFunction.js | 1 - src/slang-nodes/YulColonAndEqual.js | 1 - src/slang-nodes/YulContinueStatement.js | 1 - src/slang-nodes/YulDefaultCase.js | 1 - src/slang-nodes/YulExpression.js | 1 - src/slang-nodes/YulForStatement.js | 1 - src/slang-nodes/YulFunctionCallExpression.js | 1 - src/slang-nodes/YulFunctionDefinition.js | 1 - src/slang-nodes/YulIfStatement.js | 1 - src/slang-nodes/YulLabel.js | 1 - src/slang-nodes/YulLeaveStatement.js | 1 - src/slang-nodes/YulLiteral.js | 1 - src/slang-nodes/YulParameters.js | 1 - src/slang-nodes/YulParametersDeclaration.js | 1 - src/slang-nodes/YulPath.js | 1 - src/slang-nodes/YulPathComponent.js | 1 - src/slang-nodes/YulPaths.js | 1 - src/slang-nodes/YulReturnVariables.js | 1 - src/slang-nodes/YulReturnsDeclaration.js | 1 - src/slang-nodes/YulStatement.js | 1 - src/slang-nodes/YulStatements.js | 1 - src/slang-nodes/YulSwitchCase.js | 1 - src/slang-nodes/YulSwitchCases.js | 1 - src/slang-nodes/YulSwitchStatement.js | 1 - src/slang-nodes/YulValueCase.js | 1 - src/slang-nodes/YulVariableAssignmentStatement.js | 1 - src/slang-nodes/YulVariableDeclarationStatement.js | 1 - src/slang-nodes/YulVariableDeclarationValue.js | 1 - src/slangParser.js | 10 +++++++++- 216 files changed, 9 insertions(+), 217 deletions(-) diff --git a/src/slang-nodes/ABICoderPragma.js b/src/slang-nodes/ABICoderPragma.js index 24bad49f1..5de917342 100644 --- a/src/slang-nodes/ABICoderPragma.js +++ b/src/slang-nodes/ABICoderPragma.js @@ -1,6 +1,5 @@ export const ABICoderPragma = { parse: ({ ast }) => ({ - kind: ast.cst.kind, abicoderKeyword: ast.abicoderKeyword.text, version: ast.version.text }), diff --git a/src/slang-nodes/AdditiveExpression.js b/src/slang-nodes/AdditiveExpression.js index 2404d71a2..f4afb7260 100644 --- a/src/slang-nodes/AdditiveExpression.js +++ b/src/slang-nodes/AdditiveExpression.js @@ -2,7 +2,6 @@ import { binaryOperationPrint, tryHug } from '../common/slang-helpers.js'; export const AdditiveExpression = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, leftOperand: tryHug(parse(ast.leftOperand, options, parse), ['%']), operator: ast.operator.text, rightOperand: tryHug(parse(ast.rightOperand, options, parse), ['%']) diff --git a/src/slang-nodes/AddressType.js b/src/slang-nodes/AddressType.js index 651fd7c90..75c8d2c8e 100644 --- a/src/slang-nodes/AddressType.js +++ b/src/slang-nodes/AddressType.js @@ -1,6 +1,5 @@ export const AddressType = { parse: ({ ast }) => ({ - kind: ast.cst.kind, addressKeyword: ast.addressKeyword.text, payableKeyword: ast.payableKeyword?.text }), diff --git a/src/slang-nodes/AndExpression.js b/src/slang-nodes/AndExpression.js index 50a4a8a1e..1978c8b8f 100644 --- a/src/slang-nodes/AndExpression.js +++ b/src/slang-nodes/AndExpression.js @@ -2,7 +2,6 @@ import { logicalOperationPrint } from '../common/slang-helpers.js'; export const AndExpression = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, leftOperand: parse(ast.leftOperand, options, parse), operator: ast.operator.text, rightOperand: parse(ast.rightOperand, options, parse) diff --git a/src/slang-nodes/ArgumentsDeclaration.js b/src/slang-nodes/ArgumentsDeclaration.js index d7730854f..b81548d51 100644 --- a/src/slang-nodes/ArgumentsDeclaration.js +++ b/src/slang-nodes/ArgumentsDeclaration.js @@ -1,6 +1,5 @@ export const ArgumentsDeclaration = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, variant: parse(ast.variant, options, parse) }), print: ({ path, print }) => path.call(print, 'variant') diff --git a/src/slang-nodes/ArrayExpression.js b/src/slang-nodes/ArrayExpression.js index f56cdfcd6..afc98c477 100644 --- a/src/slang-nodes/ArrayExpression.js +++ b/src/slang-nodes/ArrayExpression.js @@ -4,7 +4,6 @@ const { group } = doc.builders; export const ArrayExpression = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, openBracket: ast.openBracket.text, items: parse(ast.items, options, parse), closeBracket: ast.closeBracket.text diff --git a/src/slang-nodes/ArrayTypeName.js b/src/slang-nodes/ArrayTypeName.js index 81b03540f..fd2033483 100644 --- a/src/slang-nodes/ArrayTypeName.js +++ b/src/slang-nodes/ArrayTypeName.js @@ -1,6 +1,5 @@ export const ArrayTypeName = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, operand: parse(ast.operand, options, parse), openBracket: ast.openBracket.text, index: ast.index ? parse(ast.index, options, parse) : undefined, diff --git a/src/slang-nodes/ArrayValues.js b/src/slang-nodes/ArrayValues.js index daabcc2b9..0cb242986 100644 --- a/src/slang-nodes/ArrayValues.js +++ b/src/slang-nodes/ArrayValues.js @@ -2,7 +2,6 @@ import { printSeparatedList } from '../common/printer-helpers.js'; export const ArrayValues = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/AssemblyFlags.js b/src/slang-nodes/AssemblyFlags.js index ab3671819..5c950f912 100644 --- a/src/slang-nodes/AssemblyFlags.js +++ b/src/slang-nodes/AssemblyFlags.js @@ -2,7 +2,6 @@ import { printSeparatedList } from '../common/printer-helpers.js'; export const AssemblyFlags = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/AssemblyFlagsDeclaration.js b/src/slang-nodes/AssemblyFlagsDeclaration.js index 53dcbb43f..8abbbb25e 100644 --- a/src/slang-nodes/AssemblyFlagsDeclaration.js +++ b/src/slang-nodes/AssemblyFlagsDeclaration.js @@ -1,6 +1,5 @@ export const AssemblyFlagsDeclaration = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, openParen: ast.openParen.text, flags: parse(ast.flags, options, parse), closeParen: ast.closeParen.text diff --git a/src/slang-nodes/AssemblyStatement.js b/src/slang-nodes/AssemblyStatement.js index aa5ae2b04..a60ebff9e 100644 --- a/src/slang-nodes/AssemblyStatement.js +++ b/src/slang-nodes/AssemblyStatement.js @@ -1,6 +1,5 @@ export const AssemblyStatement = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, assemblyKeyword: ast.assemblyKeyword.text, label: ast.label ? parse(ast.label, options, parse) : undefined, flags: ast.flags ? parse(ast.flags, options, parse) : undefined, diff --git a/src/slang-nodes/AssignmentExpression.js b/src/slang-nodes/AssignmentExpression.js index 665783cb0..d183ab4e0 100644 --- a/src/slang-nodes/AssignmentExpression.js +++ b/src/slang-nodes/AssignmentExpression.js @@ -5,7 +5,6 @@ const { group, indent, line } = doc.builders; export const AssignmentExpression = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, leftOperand: parse(ast.leftOperand, options, parse), operator: ast.operator.text, rightOperand: parse(ast.rightOperand, options, parse) diff --git a/src/slang-nodes/BitwiseAndExpression.js b/src/slang-nodes/BitwiseAndExpression.js index 58584976b..e9bac0ac9 100644 --- a/src/slang-nodes/BitwiseAndExpression.js +++ b/src/slang-nodes/BitwiseAndExpression.js @@ -2,7 +2,6 @@ import { binaryOperationPrint, tryHug } from '../common/slang-helpers.js'; export const BitwiseAndExpression = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, leftOperand: tryHug(parse(ast.leftOperand, options, parse), [ '+', '-', diff --git a/src/slang-nodes/BitwiseOrExpression.js b/src/slang-nodes/BitwiseOrExpression.js index a5d5bb31e..5b3f18a81 100644 --- a/src/slang-nodes/BitwiseOrExpression.js +++ b/src/slang-nodes/BitwiseOrExpression.js @@ -2,7 +2,6 @@ import { binaryOperationPrint, tryHug } from '../common/slang-helpers.js'; export const BitwiseOrExpression = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, leftOperand: tryHug(parse(ast.leftOperand, options, parse), [ '+', '-', diff --git a/src/slang-nodes/BitwiseXorExpression.js b/src/slang-nodes/BitwiseXorExpression.js index 44fef0716..1e867ea87 100644 --- a/src/slang-nodes/BitwiseXorExpression.js +++ b/src/slang-nodes/BitwiseXorExpression.js @@ -2,7 +2,6 @@ import { binaryOperationPrint, tryHug } from '../common/slang-helpers.js'; export const BitwiseXorExpression = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, leftOperand: tryHug(parse(ast.leftOperand, options, parse), [ '+', '-', diff --git a/src/slang-nodes/Block.js b/src/slang-nodes/Block.js index 19b247f9a..31c2be88d 100644 --- a/src/slang-nodes/Block.js +++ b/src/slang-nodes/Block.js @@ -1,6 +1,5 @@ export const Block = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, openBrace: ast.openBrace.text, statements: parse(ast.statements, options, parse), closeBrace: ast.closeBrace.text diff --git a/src/slang-nodes/BreakStatement.js b/src/slang-nodes/BreakStatement.js index 3bc49e3f3..4326e8a1a 100644 --- a/src/slang-nodes/BreakStatement.js +++ b/src/slang-nodes/BreakStatement.js @@ -1,6 +1,5 @@ export const BreakStatement = { parse: ({ ast }) => ({ - kind: ast.cst.kind, breakKeyword: ast.breakKeyword.text, semicolon: ast.semicolon.text }), diff --git a/src/slang-nodes/CallOptions.js b/src/slang-nodes/CallOptions.js index c40b06232..e62679417 100644 --- a/src/slang-nodes/CallOptions.js +++ b/src/slang-nodes/CallOptions.js @@ -2,7 +2,6 @@ import { printSeparatedList } from '../common/printer-helpers.js'; export const CallOptions = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/CallOptionsExpression.js b/src/slang-nodes/CallOptionsExpression.js index 5cb8a37f5..f8cf1c9fb 100644 --- a/src/slang-nodes/CallOptionsExpression.js +++ b/src/slang-nodes/CallOptionsExpression.js @@ -1,6 +1,5 @@ export const CallOptionsExpression = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, operand: parse(ast.operand, options, parse), openBrace: ast.openBrace.text, options: parse(ast.options, options, parse), diff --git a/src/slang-nodes/CatchClause.js b/src/slang-nodes/CatchClause.js index 8aa86510d..a9583b159 100644 --- a/src/slang-nodes/CatchClause.js +++ b/src/slang-nodes/CatchClause.js @@ -1,6 +1,5 @@ export const CatchClause = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, catchKeyword: ast.catchKeyword.text, error: ast.error ? parse(ast.error, options, parse) : undefined, body: parse(ast.body, options, parse) diff --git a/src/slang-nodes/CatchClauseError.js b/src/slang-nodes/CatchClauseError.js index 87a482f28..3e4f9f57a 100644 --- a/src/slang-nodes/CatchClauseError.js +++ b/src/slang-nodes/CatchClauseError.js @@ -1,6 +1,5 @@ export const CatchClauseError = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, name: ast.name?.text, parameters: parse(ast.parameters, options, parse) }), diff --git a/src/slang-nodes/CatchClauses.js b/src/slang-nodes/CatchClauses.js index 2a8050f66..9d34c16a5 100644 --- a/src/slang-nodes/CatchClauses.js +++ b/src/slang-nodes/CatchClauses.js @@ -4,7 +4,6 @@ const { join } = doc.builders; export const CatchClauses = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), print: ({ path, print }) => join(' ', path.map(print, 'items')) diff --git a/src/slang-nodes/ComparisonExpression.js b/src/slang-nodes/ComparisonExpression.js index e3c2cdb18..fae8601b3 100644 --- a/src/slang-nodes/ComparisonExpression.js +++ b/src/slang-nodes/ComparisonExpression.js @@ -2,7 +2,6 @@ import { comparisonOperationPrint } from '../common/slang-helpers.js'; export const ComparisonExpression = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, leftOperand: parse(ast.leftOperand, options, parse), operator: ast.operator.text, rightOperand: parse(ast.rightOperand, options, parse) diff --git a/src/slang-nodes/ConditionalExpression.js b/src/slang-nodes/ConditionalExpression.js index d53541219..63ba28de2 100644 --- a/src/slang-nodes/ConditionalExpression.js +++ b/src/slang-nodes/ConditionalExpression.js @@ -106,7 +106,6 @@ export const ConditionalExpression = { } return { - kind: ast.cst.kind, operand, questionMark: ast.questionMark.text, trueExpression: parse(ast.trueExpression, options, parse), diff --git a/src/slang-nodes/ConstantDefinition.js b/src/slang-nodes/ConstantDefinition.js index f358f8200..b2b523945 100644 --- a/src/slang-nodes/ConstantDefinition.js +++ b/src/slang-nodes/ConstantDefinition.js @@ -1,6 +1,5 @@ export const ConstantDefinition = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, typeName: parse(ast.typeName, options, parse), constantKeyword: ast.constantKeyword.text, name: ast.name.text, diff --git a/src/slang-nodes/ConstructorAttribute.js b/src/slang-nodes/ConstructorAttribute.js index 21c4e416f..6a5a4482d 100644 --- a/src/slang-nodes/ConstructorAttribute.js +++ b/src/slang-nodes/ConstructorAttribute.js @@ -1,6 +1,5 @@ export const ConstructorAttribute = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/ConstructorAttributes.js b/src/slang-nodes/ConstructorAttributes.js index bdb470f55..b27d72996 100644 --- a/src/slang-nodes/ConstructorAttributes.js +++ b/src/slang-nodes/ConstructorAttributes.js @@ -4,7 +4,6 @@ const { line } = doc.builders; export const ConstructorAttributes = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), print: ({ path, print }) => diff --git a/src/slang-nodes/ConstructorDefinition.js b/src/slang-nodes/ConstructorDefinition.js index 3585a63d1..0d2543e20 100644 --- a/src/slang-nodes/ConstructorDefinition.js +++ b/src/slang-nodes/ConstructorDefinition.js @@ -2,7 +2,6 @@ import { printFunction } from '../common/slang-helpers.js'; export const ConstructorDefinition = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, constructorKeyword: ast.constructorKeyword.text, parameters: parse(ast.parameters, options, parse), attributes: parse(ast.attributes, options, parse), diff --git a/src/slang-nodes/ContinueStatement.js b/src/slang-nodes/ContinueStatement.js index e65e1cfdc..760347a99 100644 --- a/src/slang-nodes/ContinueStatement.js +++ b/src/slang-nodes/ContinueStatement.js @@ -1,6 +1,5 @@ export const ContinueStatement = { parse: ({ ast }) => ({ - kind: ast.cst.kind, continueKeyword: ast.continueKeyword.text, semicolon: ast.semicolon.text }), diff --git a/src/slang-nodes/ContractDefinition.js b/src/slang-nodes/ContractDefinition.js index 7c060c6e9..7d957d560 100644 --- a/src/slang-nodes/ContractDefinition.js +++ b/src/slang-nodes/ContractDefinition.js @@ -4,7 +4,6 @@ const { group, line } = doc.builders; export const ContractDefinition = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, abstractKeyword: ast.abstractKeyword?.text, contractKeyword: ast.contractKeyword.text, name: ast.name.text, diff --git a/src/slang-nodes/ContractMember.js b/src/slang-nodes/ContractMember.js index ce7d1da5b..8180d3f15 100644 --- a/src/slang-nodes/ContractMember.js +++ b/src/slang-nodes/ContractMember.js @@ -1,6 +1,5 @@ export const ContractMember = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, variant: parse(ast.variant, options, parse) }), print: ({ path, print }) => path.call(print, 'variant') diff --git a/src/slang-nodes/ContractMembers.js b/src/slang-nodes/ContractMembers.js index effc0ee10..dc881958a 100644 --- a/src/slang-nodes/ContractMembers.js +++ b/src/slang-nodes/ContractMembers.js @@ -8,7 +8,6 @@ const { hardline } = doc.builders; export const ContractMembers = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), print: ({ node, options, path, print }) => diff --git a/src/slang-nodes/DecimalNumberExpression.js b/src/slang-nodes/DecimalNumberExpression.js index 6fb87dd7f..d7fdf947f 100644 --- a/src/slang-nodes/DecimalNumberExpression.js +++ b/src/slang-nodes/DecimalNumberExpression.js @@ -1,6 +1,5 @@ export const DecimalNumberExpression = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, literal: ast.literal.text, unit: ast.unit ? parse(ast.unit, options, parse) : undefined }), diff --git a/src/slang-nodes/DoWhileStatement.js b/src/slang-nodes/DoWhileStatement.js index 674709c80..2558b746c 100644 --- a/src/slang-nodes/DoWhileStatement.js +++ b/src/slang-nodes/DoWhileStatement.js @@ -10,7 +10,6 @@ const printBody = (node, path, print) => export const DoWhileStatement = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, doKeyword: ast.doKeyword.text, body: parse(ast.body, options, parse), whileKeyword: ast.whileKeyword.text, diff --git a/src/slang-nodes/ElementaryType.js b/src/slang-nodes/ElementaryType.js index 3fa2350fa..dd35918a4 100644 --- a/src/slang-nodes/ElementaryType.js +++ b/src/slang-nodes/ElementaryType.js @@ -1,6 +1,5 @@ export const ElementaryType = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/ElseBranch.js b/src/slang-nodes/ElseBranch.js index c8bf62bb1..7b9451f2f 100644 --- a/src/slang-nodes/ElseBranch.js +++ b/src/slang-nodes/ElseBranch.js @@ -9,7 +9,6 @@ const printBody = (bodyVariantKind, path, print) => export const ElseBranch = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, elseKeyword: ast.elseKeyword.text, body: parse(ast.body, options, parse) }), diff --git a/src/slang-nodes/EmitStatement.js b/src/slang-nodes/EmitStatement.js index d6495b6c4..195176aed 100644 --- a/src/slang-nodes/EmitStatement.js +++ b/src/slang-nodes/EmitStatement.js @@ -1,6 +1,5 @@ export const EmitStatement = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, emitKeyword: ast.emitKeyword.text, event: parse(ast.event, options, parse), arguments: parse(ast.arguments, options, parse), diff --git a/src/slang-nodes/EnumDefinition.js b/src/slang-nodes/EnumDefinition.js index 31def03d2..6b0563156 100644 --- a/src/slang-nodes/EnumDefinition.js +++ b/src/slang-nodes/EnumDefinition.js @@ -1,6 +1,5 @@ export const EnumDefinition = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, enumKeyword: ast.enumKeyword.text, name: ast.name.text, openBrace: ast.openBrace.text, diff --git a/src/slang-nodes/EnumMembers.js b/src/slang-nodes/EnumMembers.js index 1f015aff6..a741876bb 100644 --- a/src/slang-nodes/EnumMembers.js +++ b/src/slang-nodes/EnumMembers.js @@ -5,7 +5,6 @@ const { hardline } = doc.builders; export const EnumMembers = { parse: ({ ast }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => item.text), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/EqualityExpression.js b/src/slang-nodes/EqualityExpression.js index 22e4bb5b2..ac47ea857 100644 --- a/src/slang-nodes/EqualityExpression.js +++ b/src/slang-nodes/EqualityExpression.js @@ -2,7 +2,6 @@ import { comparisonOperationPrint } from '../common/slang-helpers.js'; export const EqualityExpression = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, leftOperand: parse(ast.leftOperand, options, parse), operator: ast.operator.text, rightOperand: parse(ast.rightOperand, options, parse) diff --git a/src/slang-nodes/ErrorDefinition.js b/src/slang-nodes/ErrorDefinition.js index 29ead464b..ac8487cc5 100644 --- a/src/slang-nodes/ErrorDefinition.js +++ b/src/slang-nodes/ErrorDefinition.js @@ -1,6 +1,5 @@ export const ErrorDefinition = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, errorKeyword: ast.errorKeyword.text, name: ast.name.text, members: parse(ast.members, options, parse), diff --git a/src/slang-nodes/ErrorParameter.js b/src/slang-nodes/ErrorParameter.js index 46ffc308e..8ca417e94 100644 --- a/src/slang-nodes/ErrorParameter.js +++ b/src/slang-nodes/ErrorParameter.js @@ -1,6 +1,5 @@ export const ErrorParameter = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, typeName: parse(ast.typeName, options, parse), name: ast.name?.text }), diff --git a/src/slang-nodes/ErrorParameters.js b/src/slang-nodes/ErrorParameters.js index 3a6e0be86..c8316ea31 100644 --- a/src/slang-nodes/ErrorParameters.js +++ b/src/slang-nodes/ErrorParameters.js @@ -2,7 +2,6 @@ import { printSeparatedList } from '../common/printer-helpers.js'; export const ErrorParameters = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/ErrorParametersDeclaration.js b/src/slang-nodes/ErrorParametersDeclaration.js index a7f2d0f98..f76755a55 100644 --- a/src/slang-nodes/ErrorParametersDeclaration.js +++ b/src/slang-nodes/ErrorParametersDeclaration.js @@ -1,6 +1,5 @@ export const ErrorParametersDeclaration = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, openParen: ast.openParen.text, parameters: parse(ast.parameters, options, parse), closeParen: ast.closeParen.text diff --git a/src/slang-nodes/EventDefinition.js b/src/slang-nodes/EventDefinition.js index cae5de51e..c381d587d 100644 --- a/src/slang-nodes/EventDefinition.js +++ b/src/slang-nodes/EventDefinition.js @@ -1,6 +1,5 @@ export const EventDefinition = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, eventKeyword: ast.eventKeyword.text, name: ast.name.text, parameters: parse(ast.parameters, options, parse), diff --git a/src/slang-nodes/EventParameter.js b/src/slang-nodes/EventParameter.js index 326514f9a..7cea70fe3 100644 --- a/src/slang-nodes/EventParameter.js +++ b/src/slang-nodes/EventParameter.js @@ -1,6 +1,5 @@ export const EventParameter = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, typeName: parse(ast.typeName, options, parse), indexedKeyword: ast.indexedKeyword?.text, name: ast.name?.text diff --git a/src/slang-nodes/EventParameters.js b/src/slang-nodes/EventParameters.js index 479780999..0222138bf 100644 --- a/src/slang-nodes/EventParameters.js +++ b/src/slang-nodes/EventParameters.js @@ -2,7 +2,6 @@ import { printSeparatedList } from '../common/printer-helpers.js'; export const EventParameters = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/EventParametersDeclaration.js b/src/slang-nodes/EventParametersDeclaration.js index d61a026e5..1c47a0434 100644 --- a/src/slang-nodes/EventParametersDeclaration.js +++ b/src/slang-nodes/EventParametersDeclaration.js @@ -1,6 +1,5 @@ export const EventParametersDeclaration = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, openParen: ast.openParen.text, parameters: parse(ast.parameters, options, parse), closeParen: ast.closeParen.text diff --git a/src/slang-nodes/ExperimentalFeature.js b/src/slang-nodes/ExperimentalFeature.js index 6f2845222..f1b61b6ec 100644 --- a/src/slang-nodes/ExperimentalFeature.js +++ b/src/slang-nodes/ExperimentalFeature.js @@ -1,6 +1,5 @@ export const ExperimentalFeature = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/ExperimentalPragma.js b/src/slang-nodes/ExperimentalPragma.js index 1d0c21072..f2e9a7af4 100644 --- a/src/slang-nodes/ExperimentalPragma.js +++ b/src/slang-nodes/ExperimentalPragma.js @@ -1,6 +1,5 @@ export const ExperimentalPragma = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, experimentalKeyword: ast.experimentalKeyword.text, feature: parse(ast.feature, options, parse) }), diff --git a/src/slang-nodes/ExponentiationExpression.js b/src/slang-nodes/ExponentiationExpression.js index a1b52577f..da1347177 100644 --- a/src/slang-nodes/ExponentiationExpression.js +++ b/src/slang-nodes/ExponentiationExpression.js @@ -19,7 +19,6 @@ export const ExponentiationExpression = { } } return { - kind: ast.cst.kind, leftOperand, operator: ast.operator.text, rightOperand diff --git a/src/slang-nodes/Expression.js b/src/slang-nodes/Expression.js index 23ee1af7f..7174f98e2 100644 --- a/src/slang-nodes/Expression.js +++ b/src/slang-nodes/Expression.js @@ -1,6 +1,5 @@ export const Expression = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/ExpressionStatement.js b/src/slang-nodes/ExpressionStatement.js index 2f60ec749..10db79262 100644 --- a/src/slang-nodes/ExpressionStatement.js +++ b/src/slang-nodes/ExpressionStatement.js @@ -1,6 +1,5 @@ export const ExpressionStatement = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, expression: parse(ast.expression, options, parse), semicolon: ast.semicolon.text }), diff --git a/src/slang-nodes/FallbackFunctionAttribute.js b/src/slang-nodes/FallbackFunctionAttribute.js index 0380aea4e..9154f3bb1 100644 --- a/src/slang-nodes/FallbackFunctionAttribute.js +++ b/src/slang-nodes/FallbackFunctionAttribute.js @@ -1,6 +1,5 @@ export const FallbackFunctionAttribute = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/FallbackFunctionAttributes.js b/src/slang-nodes/FallbackFunctionAttributes.js index 4279b5452..a347b46ad 100644 --- a/src/slang-nodes/FallbackFunctionAttributes.js +++ b/src/slang-nodes/FallbackFunctionAttributes.js @@ -4,7 +4,6 @@ const { line } = doc.builders; export const FallbackFunctionAttributes = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), print: ({ path, print }) => diff --git a/src/slang-nodes/FallbackFunctionDefinition.js b/src/slang-nodes/FallbackFunctionDefinition.js index 676fdee73..043fabc34 100644 --- a/src/slang-nodes/FallbackFunctionDefinition.js +++ b/src/slang-nodes/FallbackFunctionDefinition.js @@ -2,7 +2,6 @@ import { printFunction } from '../common/slang-helpers.js'; export const FallbackFunctionDefinition = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, fallbackKeyword: ast.fallbackKeyword.text, parameters: parse(ast.parameters, options, parse), attributes: parse(ast.attributes, options, parse), diff --git a/src/slang-nodes/ForStatement.js b/src/slang-nodes/ForStatement.js index 1f9594e9d..6dc9b9877 100644 --- a/src/slang-nodes/ForStatement.js +++ b/src/slang-nodes/ForStatement.js @@ -5,7 +5,6 @@ const { group, indent, line } = doc.builders; export const ForStatement = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, forKeyword: ast.forKeyword.text, openParen: ast.openParen.text, initialization: parse(ast.initialization, options, parse), diff --git a/src/slang-nodes/ForStatementCondition.js b/src/slang-nodes/ForStatementCondition.js index a81e588d2..4520890fe 100644 --- a/src/slang-nodes/ForStatementCondition.js +++ b/src/slang-nodes/ForStatementCondition.js @@ -1,6 +1,5 @@ export const ForStatementCondition = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/ForStatementInitialization.js b/src/slang-nodes/ForStatementInitialization.js index 041651d48..35eab7491 100644 --- a/src/slang-nodes/ForStatementInitialization.js +++ b/src/slang-nodes/ForStatementInitialization.js @@ -1,6 +1,5 @@ export const ForStatementInitialization = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/FunctionAttribute.js b/src/slang-nodes/FunctionAttribute.js index 7a213202d..dcdcfa885 100644 --- a/src/slang-nodes/FunctionAttribute.js +++ b/src/slang-nodes/FunctionAttribute.js @@ -1,6 +1,5 @@ export const FunctionAttribute = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/FunctionAttributes.js b/src/slang-nodes/FunctionAttributes.js index 5a2d289db..b1a2a1015 100644 --- a/src/slang-nodes/FunctionAttributes.js +++ b/src/slang-nodes/FunctionAttributes.js @@ -4,7 +4,6 @@ const { line } = doc.builders; export const FunctionAttributes = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), print: ({ path, print }) => diff --git a/src/slang-nodes/FunctionBody.js b/src/slang-nodes/FunctionBody.js index 9d24097a1..cb9f8f8ed 100644 --- a/src/slang-nodes/FunctionBody.js +++ b/src/slang-nodes/FunctionBody.js @@ -1,7 +1,5 @@ export const FunctionBody = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, - variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/FunctionCallExpression.js b/src/slang-nodes/FunctionCallExpression.js index e8df5b80c..a84f17266 100644 --- a/src/slang-nodes/FunctionCallExpression.js +++ b/src/slang-nodes/FunctionCallExpression.js @@ -6,7 +6,6 @@ const { group, indentIfBreak, label } = doc.builders; let groupIndex = 0; export const FunctionCallExpression = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, operand: parse(ast.operand, options, parse), arguments: parse(ast.arguments, options, parse) }), diff --git a/src/slang-nodes/FunctionDefinition.js b/src/slang-nodes/FunctionDefinition.js index 0f1b5fe2e..5dd54725f 100644 --- a/src/slang-nodes/FunctionDefinition.js +++ b/src/slang-nodes/FunctionDefinition.js @@ -2,7 +2,6 @@ import { printFunction } from '../common/slang-helpers.js'; export const FunctionDefinition = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, functionKeyword: ast.functionKeyword.text, name: parse(ast.name, options, parse), parameters: parse(ast.parameters, options, parse), diff --git a/src/slang-nodes/FunctionName.js b/src/slang-nodes/FunctionName.js index e68c57929..5cb2e0579 100644 --- a/src/slang-nodes/FunctionName.js +++ b/src/slang-nodes/FunctionName.js @@ -1,6 +1,5 @@ export const FunctionName = { parse: ({ ast }) => ({ - kind: ast.cst.kind, variant: ast.variant.text }), print: ({ node }) => node.variant diff --git a/src/slang-nodes/FunctionType.js b/src/slang-nodes/FunctionType.js index f548c7fc8..e6af8fdca 100644 --- a/src/slang-nodes/FunctionType.js +++ b/src/slang-nodes/FunctionType.js @@ -2,7 +2,6 @@ import { printFunction } from '../common/slang-helpers.js'; export const FunctionType = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, functionKeyword: ast.functionKeyword.text, parameters: parse(ast.parameters, options, parse), attributes: parse(ast.attributes, options, parse), diff --git a/src/slang-nodes/FunctionTypeAttribute.js b/src/slang-nodes/FunctionTypeAttribute.js index 162bfb050..5cda4b957 100644 --- a/src/slang-nodes/FunctionTypeAttribute.js +++ b/src/slang-nodes/FunctionTypeAttribute.js @@ -1,6 +1,5 @@ export const FunctionTypeAttribute = { parse: ({ ast }) => ({ - kind: ast.cst.kind, variant: ast.variant.text }), print: ({ node }) => node.variant diff --git a/src/slang-nodes/FunctionTypeAttributes.js b/src/slang-nodes/FunctionTypeAttributes.js index 10713231d..a15184ae1 100644 --- a/src/slang-nodes/FunctionTypeAttributes.js +++ b/src/slang-nodes/FunctionTypeAttributes.js @@ -4,7 +4,6 @@ const { line } = doc.builders; export const FunctionTypeAttributes = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), print: ({ path, print }) => diff --git a/src/slang-nodes/HexNumberExpression.js b/src/slang-nodes/HexNumberExpression.js index 00fbbd3fd..b3e10a550 100644 --- a/src/slang-nodes/HexNumberExpression.js +++ b/src/slang-nodes/HexNumberExpression.js @@ -1,6 +1,5 @@ export const HexNumberExpression = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, literal: ast.literal.text, unit: ast.unit ? parse(ast.unit, options, parse) : undefined }), diff --git a/src/slang-nodes/HexStringLiteral.js b/src/slang-nodes/HexStringLiteral.js index 3bff2fa11..b16f31f2b 100644 --- a/src/slang-nodes/HexStringLiteral.js +++ b/src/slang-nodes/HexStringLiteral.js @@ -2,7 +2,6 @@ import { printString } from '../common/util.js'; export const HexStringLiteral = { parse: ({ ast, options }) => ({ - kind: ast.cst.kind, variant: `hex${printString(ast.variant.text.slice(4, -1), options)}` }), print: ({ node }) => node.variant diff --git a/src/slang-nodes/HexStringLiterals.js b/src/slang-nodes/HexStringLiterals.js index 78a983ebd..5edf0f83d 100644 --- a/src/slang-nodes/HexStringLiterals.js +++ b/src/slang-nodes/HexStringLiterals.js @@ -4,7 +4,6 @@ const { join, hardline } = doc.builders; export const HexStringLiterals = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), print: ({ path, print }) => join(hardline, path.map(print, 'items')) diff --git a/src/slang-nodes/IdentifierPath.js b/src/slang-nodes/IdentifierPath.js index 5be2c3cad..4b8dfb60d 100644 --- a/src/slang-nodes/IdentifierPath.js +++ b/src/slang-nodes/IdentifierPath.js @@ -1,6 +1,5 @@ export const IdentifierPath = { parse: ({ ast }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => item.text), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/IfStatement.js b/src/slang-nodes/IfStatement.js index c87ad7000..25bbbc3c5 100644 --- a/src/slang-nodes/IfStatement.js +++ b/src/slang-nodes/IfStatement.js @@ -12,7 +12,6 @@ const printBody = (bodyVariantKind, path, print) => export const IfStatement = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, ifKeyword: ast.ifKeyword.text, openParen: ast.openParen.text, condition: parse(ast.condition, options, parse), diff --git a/src/slang-nodes/ImportAlias.js b/src/slang-nodes/ImportAlias.js index 747928c48..088d8cec9 100644 --- a/src/slang-nodes/ImportAlias.js +++ b/src/slang-nodes/ImportAlias.js @@ -1,6 +1,5 @@ export const ImportAlias = { parse: ({ ast }) => ({ - kind: ast.cst.kind, asKeyword: ast.asKeyword.text, identifier: ast.identifier.text }), diff --git a/src/slang-nodes/ImportClause.js b/src/slang-nodes/ImportClause.js index 0819567c1..8e652223d 100644 --- a/src/slang-nodes/ImportClause.js +++ b/src/slang-nodes/ImportClause.js @@ -1,6 +1,5 @@ export const ImportClause = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, variant: parse(ast.variant, options, parse) }), print: ({ path, print }) => path.call(print, 'variant') diff --git a/src/slang-nodes/ImportDeconstruction.js b/src/slang-nodes/ImportDeconstruction.js index 7112065da..c38eee3e3 100644 --- a/src/slang-nodes/ImportDeconstruction.js +++ b/src/slang-nodes/ImportDeconstruction.js @@ -1,6 +1,5 @@ export const ImportDeconstruction = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, openBrace: ast.openBrace.text, symbols: parse(ast.symbols, options, parse), closeBrace: ast.closeBrace.text, diff --git a/src/slang-nodes/ImportDeconstructionSymbol.js b/src/slang-nodes/ImportDeconstructionSymbol.js index c826b4ceb..3eb05baa4 100644 --- a/src/slang-nodes/ImportDeconstructionSymbol.js +++ b/src/slang-nodes/ImportDeconstructionSymbol.js @@ -1,6 +1,5 @@ export const ImportDeconstructionSymbol = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, name: ast.name.text, alias: ast.alias ? parse(ast.alias, options, parse) : undefined }), diff --git a/src/slang-nodes/ImportDeconstructionSymbols.js b/src/slang-nodes/ImportDeconstructionSymbols.js index 406060581..c33c0d39d 100644 --- a/src/slang-nodes/ImportDeconstructionSymbols.js +++ b/src/slang-nodes/ImportDeconstructionSymbols.js @@ -7,7 +7,6 @@ const { line, softline } = doc.builders; export const ImportDeconstructionSymbols = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/ImportDirective.js b/src/slang-nodes/ImportDirective.js index 19fcb6af5..b859ceab1 100644 --- a/src/slang-nodes/ImportDirective.js +++ b/src/slang-nodes/ImportDirective.js @@ -1,6 +1,5 @@ export const ImportDirective = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, importKeyword: ast.importKeyword.text, clause: parse(ast.clause, options, parse), semicolon: ast.semicolon.text diff --git a/src/slang-nodes/IndexAccessEnd.js b/src/slang-nodes/IndexAccessEnd.js index 56af7be30..6e1472f06 100644 --- a/src/slang-nodes/IndexAccessEnd.js +++ b/src/slang-nodes/IndexAccessEnd.js @@ -1,6 +1,5 @@ export const IndexAccessEnd = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, colon: ast.colon.text, end: ast.end ? parse(ast.end, options, parse) : undefined }), diff --git a/src/slang-nodes/IndexAccessExpression.js b/src/slang-nodes/IndexAccessExpression.js index 192d0a8ca..a2d0f00f9 100644 --- a/src/slang-nodes/IndexAccessExpression.js +++ b/src/slang-nodes/IndexAccessExpression.js @@ -6,7 +6,6 @@ const { group, indent, indentIfBreak, label, softline } = doc.builders; let groupIndex = 0; export const IndexAccessExpression = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, operand: parse(ast.operand, options, parse), openBracket: ast.openBracket.text, start: ast.start ? parse(ast.start, options, parse) : undefined, diff --git a/src/slang-nodes/InheritanceSpecifier.js b/src/slang-nodes/InheritanceSpecifier.js index 1e0fccf9d..5afe3f709 100644 --- a/src/slang-nodes/InheritanceSpecifier.js +++ b/src/slang-nodes/InheritanceSpecifier.js @@ -1,6 +1,5 @@ export const InheritanceSpecifier = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, isKeyword: ast.isKeyword.text, types: parse(ast.types, options, parse) }), diff --git a/src/slang-nodes/InheritanceType.js b/src/slang-nodes/InheritanceType.js index 3e6511222..d0442ee07 100644 --- a/src/slang-nodes/InheritanceType.js +++ b/src/slang-nodes/InheritanceType.js @@ -1,6 +1,5 @@ export const InheritanceType = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, typeName: parse(ast.typeName, options, parse), arguments: ast.arguments ? parse(ast.arguments, options, parse) : undefined }), diff --git a/src/slang-nodes/InheritanceTypes.js b/src/slang-nodes/InheritanceTypes.js index 7245f6ad7..53ed26e4e 100644 --- a/src/slang-nodes/InheritanceTypes.js +++ b/src/slang-nodes/InheritanceTypes.js @@ -4,7 +4,6 @@ import { printSeparatedList } from '../common/printer-helpers.js'; const { line } = doc.builders; export const InheritanceTypes = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/InterfaceDefinition.js b/src/slang-nodes/InterfaceDefinition.js index 7382939a8..5dacfbf03 100644 --- a/src/slang-nodes/InterfaceDefinition.js +++ b/src/slang-nodes/InterfaceDefinition.js @@ -4,7 +4,6 @@ const { group, line } = doc.builders; export const InterfaceDefinition = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, interfaceKeyword: ast.interfaceKeyword.text, name: ast.name.text, inheritance: ast.inheritence diff --git a/src/slang-nodes/InterfaceMembers.js b/src/slang-nodes/InterfaceMembers.js index 5091a5274..0bf940858 100644 --- a/src/slang-nodes/InterfaceMembers.js +++ b/src/slang-nodes/InterfaceMembers.js @@ -8,7 +8,6 @@ const { hardline } = doc.builders; export const InterfaceMembers = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), print: ({ node, options, path, print }) => diff --git a/src/slang-nodes/LibraryDefinition.js b/src/slang-nodes/LibraryDefinition.js index 78b5d245b..15aef8447 100644 --- a/src/slang-nodes/LibraryDefinition.js +++ b/src/slang-nodes/LibraryDefinition.js @@ -4,7 +4,6 @@ const { group, line } = doc.builders; export const LibraryDefinition = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, libraryKeyword: ast.libraryKeyword.text, name: ast.name.text, openBrace: ast.openBrace.text, diff --git a/src/slang-nodes/LibraryMembers.js b/src/slang-nodes/LibraryMembers.js index ac2d1bbc9..2080cf903 100644 --- a/src/slang-nodes/LibraryMembers.js +++ b/src/slang-nodes/LibraryMembers.js @@ -8,7 +8,6 @@ const { hardline } = doc.builders; export const LibraryMembers = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), print: ({ node, path, print, options }) => diff --git a/src/slang-nodes/MappingKey.js b/src/slang-nodes/MappingKey.js index e06e0d517..72882f0d9 100644 --- a/src/slang-nodes/MappingKey.js +++ b/src/slang-nodes/MappingKey.js @@ -1,6 +1,5 @@ export const MappingKey = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, keyType: parse(ast.keyType, options, parse), name: ast.name?.text }), diff --git a/src/slang-nodes/MappingKeyType.js b/src/slang-nodes/MappingKeyType.js index be8b4b960..774bdb2de 100644 --- a/src/slang-nodes/MappingKeyType.js +++ b/src/slang-nodes/MappingKeyType.js @@ -1,6 +1,5 @@ export const MappingKeyType = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, variant: parse(ast.variant, options, parse) }), print: ({ path, print }) => path.call(print, 'variant') diff --git a/src/slang-nodes/MappingType.js b/src/slang-nodes/MappingType.js index 556bfa156..6d6ad951b 100644 --- a/src/slang-nodes/MappingType.js +++ b/src/slang-nodes/MappingType.js @@ -1,6 +1,5 @@ export const MappingType = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, mappingKeyword: ast.mappingKeyword.text, openParen: ast.openParen.text, keyType: parse(ast.keyType, options, parse), diff --git a/src/slang-nodes/MappingValue.js b/src/slang-nodes/MappingValue.js index 87c0ea02c..e8009cad8 100644 --- a/src/slang-nodes/MappingValue.js +++ b/src/slang-nodes/MappingValue.js @@ -1,6 +1,5 @@ export const MappingValue = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, typeName: parse(ast.typeName, options, parse), name: ast.name?.text }), diff --git a/src/slang-nodes/MemberAccess.js b/src/slang-nodes/MemberAccess.js index d13f0e3a5..780257c4a 100644 --- a/src/slang-nodes/MemberAccess.js +++ b/src/slang-nodes/MemberAccess.js @@ -1,6 +1,5 @@ export const MemberAccess = { parse: ({ ast }) => ({ - kind: ast.cst.kind, variant: ast.variant.text }), print: ({ node }) => node.variant diff --git a/src/slang-nodes/MemberAccessExpression.js b/src/slang-nodes/MemberAccessExpression.js index c10c7adac..2d16662ec 100644 --- a/src/slang-nodes/MemberAccessExpression.js +++ b/src/slang-nodes/MemberAccessExpression.js @@ -103,7 +103,6 @@ const processChain = (chain) => { export const MemberAccessExpression = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, operand: parse(ast.operand, options, parse), period: ast.period.text, member: parse(ast.member, options, parse) diff --git a/src/slang-nodes/ModifierAttribute.js b/src/slang-nodes/ModifierAttribute.js index c4d3b92a5..e57458c7b 100644 --- a/src/slang-nodes/ModifierAttribute.js +++ b/src/slang-nodes/ModifierAttribute.js @@ -1,6 +1,5 @@ export const ModifierAttribute = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/ModifierAttributes.js b/src/slang-nodes/ModifierAttributes.js index a79104fd4..1ea9c141b 100644 --- a/src/slang-nodes/ModifierAttributes.js +++ b/src/slang-nodes/ModifierAttributes.js @@ -4,7 +4,6 @@ const { line } = doc.builders; export const ModifierAttributes = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), print: ({ path, print }) => diff --git a/src/slang-nodes/ModifierDefinition.js b/src/slang-nodes/ModifierDefinition.js index fc968c82d..2964bb69c 100644 --- a/src/slang-nodes/ModifierDefinition.js +++ b/src/slang-nodes/ModifierDefinition.js @@ -2,7 +2,6 @@ import { printFunction } from '../common/slang-helpers.js'; export const ModifierDefinition = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, modifierKeyword: ast.modifierKeyword.text, name: ast.name.text, parameters: ast.parameters diff --git a/src/slang-nodes/ModifierInvocation.js b/src/slang-nodes/ModifierInvocation.js index c0d1ea518..8cbc3d0b0 100644 --- a/src/slang-nodes/ModifierInvocation.js +++ b/src/slang-nodes/ModifierInvocation.js @@ -1,6 +1,5 @@ export const ModifierInvocation = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, name: parse(ast.name, options, parse), arguments: ast.arguments ? parse(ast.arguments, options, parse) : undefined }), diff --git a/src/slang-nodes/MultiplicativeExpression.js b/src/slang-nodes/MultiplicativeExpression.js index d1672cb42..cf270f82a 100644 --- a/src/slang-nodes/MultiplicativeExpression.js +++ b/src/slang-nodes/MultiplicativeExpression.js @@ -20,7 +20,6 @@ export const MultiplicativeExpression = { } return { - kind: ast.cst.kind, leftOperand, operator, rightOperand: parse(ast.rightOperand, options, parse) diff --git a/src/slang-nodes/NamedArgument.js b/src/slang-nodes/NamedArgument.js index 14cad0616..fbbb0f105 100644 --- a/src/slang-nodes/NamedArgument.js +++ b/src/slang-nodes/NamedArgument.js @@ -1,6 +1,5 @@ export const NamedArgument = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, name: ast.name.text, colon: ast.colon.text, value: parse(ast.value, options, parse) diff --git a/src/slang-nodes/NamedArgumentGroup.js b/src/slang-nodes/NamedArgumentGroup.js index 901cb8a87..a04ab8dc8 100644 --- a/src/slang-nodes/NamedArgumentGroup.js +++ b/src/slang-nodes/NamedArgumentGroup.js @@ -1,6 +1,5 @@ export const NamedArgumentGroup = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, openBrace: ast.openBrace.text, arguments: parse(ast.arguments, options, parse), closeBrace: ast.closeBrace.text diff --git a/src/slang-nodes/NamedArguments.js b/src/slang-nodes/NamedArguments.js index d38781d50..58292d81a 100644 --- a/src/slang-nodes/NamedArguments.js +++ b/src/slang-nodes/NamedArguments.js @@ -2,7 +2,6 @@ import { printSeparatedList } from '../common/printer-helpers.js'; export const NamedArguments = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/NamedArgumentsDeclaration.js b/src/slang-nodes/NamedArgumentsDeclaration.js index 68d7d25ea..c8819ba07 100644 --- a/src/slang-nodes/NamedArgumentsDeclaration.js +++ b/src/slang-nodes/NamedArgumentsDeclaration.js @@ -1,6 +1,5 @@ export const NamedArgumentsDeclaration = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, openParen: ast.openParen.text, arguments: ast.arguments ? parse(ast.arguments, options, parse) : undefined, closeParen: ast.closeParen.text diff --git a/src/slang-nodes/NamedImport.js b/src/slang-nodes/NamedImport.js index 0961839f5..8905a40c8 100644 --- a/src/slang-nodes/NamedImport.js +++ b/src/slang-nodes/NamedImport.js @@ -1,6 +1,5 @@ export const NamedImport = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, asterisk: ast.asterisk.text, alias: parse(ast.alias, options, parse), fromKeyword: ast.fromKeyword.text, diff --git a/src/slang-nodes/NewExpression.js b/src/slang-nodes/NewExpression.js index 81a90683d..a8f355bbc 100644 --- a/src/slang-nodes/NewExpression.js +++ b/src/slang-nodes/NewExpression.js @@ -1,6 +1,5 @@ export const NewExpression = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, newKeyword: ast.newKeyword.text, typeName: parse(ast.typeName, options, parse) }), diff --git a/src/slang-nodes/NumberUnit.js b/src/slang-nodes/NumberUnit.js index 69c9c909a..7b57c2db0 100644 --- a/src/slang-nodes/NumberUnit.js +++ b/src/slang-nodes/NumberUnit.js @@ -1,6 +1,5 @@ export const NumberUnit = { parse: ({ ast }) => ({ - kind: ast.cst.kind, variant: ast.variant.text }), print: ({ node }) => node.variant diff --git a/src/slang-nodes/OrExpression.js b/src/slang-nodes/OrExpression.js index 250f180b3..dc5118ec6 100644 --- a/src/slang-nodes/OrExpression.js +++ b/src/slang-nodes/OrExpression.js @@ -2,7 +2,6 @@ import { logicalOperationPrint, tryHug } from '../common/slang-helpers.js'; export const OrExpression = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, leftOperand: tryHug(parse(ast.leftOperand, options, parse), ['&&']), operator: ast.operator.text, rightOperand: tryHug(parse(ast.rightOperand, options, parse), ['&&']) diff --git a/src/slang-nodes/OverridePaths.js b/src/slang-nodes/OverridePaths.js index cee4ef0ef..0b042a83d 100644 --- a/src/slang-nodes/OverridePaths.js +++ b/src/slang-nodes/OverridePaths.js @@ -1,6 +1,5 @@ export const OverridePaths = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator) }), diff --git a/src/slang-nodes/OverridePathsDeclaration.js b/src/slang-nodes/OverridePathsDeclaration.js index 78aaad756..868da87c1 100644 --- a/src/slang-nodes/OverridePathsDeclaration.js +++ b/src/slang-nodes/OverridePathsDeclaration.js @@ -1,6 +1,5 @@ export const OverridePathsDeclaration = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, openParen: ast.openParen.text, paths: parse(ast.paths, options, parse), closeParen: ast.closeParen.text diff --git a/src/slang-nodes/OverrideSpecifier.js b/src/slang-nodes/OverrideSpecifier.js index 2e3832546..5ac0f3002 100644 --- a/src/slang-nodes/OverrideSpecifier.js +++ b/src/slang-nodes/OverrideSpecifier.js @@ -1,6 +1,5 @@ export const OverrideSpecifier = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, overrideKeyword: ast.overrideKeyword.text, overridden: ast.overridden ? parse(ast.overridden, options, parse) diff --git a/src/slang-nodes/Parameter.js b/src/slang-nodes/Parameter.js index 9950eeaf3..010b1a6e1 100644 --- a/src/slang-nodes/Parameter.js +++ b/src/slang-nodes/Parameter.js @@ -1,6 +1,5 @@ export const Parameter = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, typeName: parse(ast.typeName, options, parse), storageLocation: ast.storageLocation ? parse(ast.storageLocation, options, parse) diff --git a/src/slang-nodes/Parameters.js b/src/slang-nodes/Parameters.js index 6de87a169..9fe5e2154 100644 --- a/src/slang-nodes/Parameters.js +++ b/src/slang-nodes/Parameters.js @@ -2,7 +2,6 @@ import { printSeparatedList } from '../common/printer-helpers.js'; export const Parameters = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/ParametersDeclaration.js b/src/slang-nodes/ParametersDeclaration.js index deb1642f7..6042bc4f6 100644 --- a/src/slang-nodes/ParametersDeclaration.js +++ b/src/slang-nodes/ParametersDeclaration.js @@ -1,6 +1,5 @@ export const ParametersDeclaration = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, openParen: ast.openParen.text, parameters: parse(ast.parameters, options, parse), closeParen: ast.closeParen.text diff --git a/src/slang-nodes/PathImport.js b/src/slang-nodes/PathImport.js index 80ad96e69..d33adbf31 100644 --- a/src/slang-nodes/PathImport.js +++ b/src/slang-nodes/PathImport.js @@ -1,6 +1,5 @@ export const PathImport = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, path: parse(ast.path, options, parse), alias: ast.alias ? parse(ast.alias, options, parse) : undefined }), diff --git a/src/slang-nodes/PositionalArguments.js b/src/slang-nodes/PositionalArguments.js index cfddd63ec..67c80bce5 100644 --- a/src/slang-nodes/PositionalArguments.js +++ b/src/slang-nodes/PositionalArguments.js @@ -2,7 +2,6 @@ import { printSeparatedList } from '../common/printer-helpers.js'; export const PositionalArguments = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/PositionalArgumentsDeclaration.js b/src/slang-nodes/PositionalArgumentsDeclaration.js index d59df6c01..1c3454801 100644 --- a/src/slang-nodes/PositionalArgumentsDeclaration.js +++ b/src/slang-nodes/PositionalArgumentsDeclaration.js @@ -1,6 +1,5 @@ export const PositionalArgumentsDeclaration = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, openParen: ast.openParen.text, arguments: parse(ast.arguments, options, parse), closeParen: ast.closeParen.text diff --git a/src/slang-nodes/PostfixExpression.js b/src/slang-nodes/PostfixExpression.js index 3a44339f0..af5f2bdb9 100644 --- a/src/slang-nodes/PostfixExpression.js +++ b/src/slang-nodes/PostfixExpression.js @@ -1,6 +1,5 @@ export const PostfixExpression = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, operand: parse(ast.operand, options, parse), operator: ast.operator.text }), diff --git a/src/slang-nodes/Pragma.js b/src/slang-nodes/Pragma.js index 821bfa207..7b9815094 100644 --- a/src/slang-nodes/Pragma.js +++ b/src/slang-nodes/Pragma.js @@ -1,6 +1,5 @@ export const Pragma = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, variant: parse(ast.variant, options, parse) }), print: ({ path, print }) => path.call(print, 'variant') diff --git a/src/slang-nodes/PragmaDirective.js b/src/slang-nodes/PragmaDirective.js index c0ecf362f..3ce605679 100644 --- a/src/slang-nodes/PragmaDirective.js +++ b/src/slang-nodes/PragmaDirective.js @@ -1,6 +1,5 @@ export const PragmaDirective = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, pragmaKeyword: ast.pragmaKeyword.text, pragma: parse(ast.pragma, options, parse), semicolon: ast.semicolon.text diff --git a/src/slang-nodes/PrefixExpression.js b/src/slang-nodes/PrefixExpression.js index a3d66ea00..7cdd67f1d 100644 --- a/src/slang-nodes/PrefixExpression.js +++ b/src/slang-nodes/PrefixExpression.js @@ -1,6 +1,5 @@ export const PrefixExpression = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, operator: ast.operator.text, operand: parse(ast.operand, options, parse) }), diff --git a/src/slang-nodes/ReceiveFunctionAttribute.js b/src/slang-nodes/ReceiveFunctionAttribute.js index 643ae3ce8..39d86856d 100644 --- a/src/slang-nodes/ReceiveFunctionAttribute.js +++ b/src/slang-nodes/ReceiveFunctionAttribute.js @@ -1,6 +1,5 @@ export const ReceiveFunctionAttribute = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/ReceiveFunctionAttributes.js b/src/slang-nodes/ReceiveFunctionAttributes.js index ed2b7ae8d..e0fd2507f 100644 --- a/src/slang-nodes/ReceiveFunctionAttributes.js +++ b/src/slang-nodes/ReceiveFunctionAttributes.js @@ -4,7 +4,6 @@ const { line } = doc.builders; export const ReceiveFunctionAttributes = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), print: ({ path, print }) => diff --git a/src/slang-nodes/ReceiveFunctionDefinition.js b/src/slang-nodes/ReceiveFunctionDefinition.js index 972642efb..ca5699b20 100644 --- a/src/slang-nodes/ReceiveFunctionDefinition.js +++ b/src/slang-nodes/ReceiveFunctionDefinition.js @@ -2,7 +2,6 @@ import { printFunction } from '../common/slang-helpers.js'; export const ReceiveFunctionDefinition = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, receiveKeyword: ast.receiveKeyword.text, parameters: parse(ast.parameters, options, parse), attributes: parse(ast.attributes, options, parse), diff --git a/src/slang-nodes/ReturnStatement.js b/src/slang-nodes/ReturnStatement.js index 38c3cf24e..a12e15528 100644 --- a/src/slang-nodes/ReturnStatement.js +++ b/src/slang-nodes/ReturnStatement.js @@ -1,6 +1,5 @@ export const ReturnStatement = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, returnKeyword: ast.returnKeyword.text, expression: ast.expression ? parse(ast.expression, options, parse) diff --git a/src/slang-nodes/ReturnsDeclaration.js b/src/slang-nodes/ReturnsDeclaration.js index 786e12554..5691550a2 100644 --- a/src/slang-nodes/ReturnsDeclaration.js +++ b/src/slang-nodes/ReturnsDeclaration.js @@ -1,6 +1,5 @@ export const ReturnsDeclaration = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, returnsKeyword: ast.returnsKeyword.text, variables: parse(ast.variables, options, parse) }), diff --git a/src/slang-nodes/RevertStatement.js b/src/slang-nodes/RevertStatement.js index b6aa8e407..4254de926 100644 --- a/src/slang-nodes/RevertStatement.js +++ b/src/slang-nodes/RevertStatement.js @@ -1,6 +1,5 @@ export const RevertStatement = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, revertKeyword: ast.revertKeyword.text, error: ast.error ? parse(ast.error, options, parse) : undefined, arguments: parse(ast.arguments, options, parse), diff --git a/src/slang-nodes/ShiftExpression.js b/src/slang-nodes/ShiftExpression.js index 88c017814..ad6e3e9e4 100644 --- a/src/slang-nodes/ShiftExpression.js +++ b/src/slang-nodes/ShiftExpression.js @@ -2,7 +2,6 @@ import { binaryOperationPrint, tryHug } from '../common/slang-helpers.js'; export const ShiftExpression = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, leftOperand: tryHug(parse(ast.leftOperand, options, parse), [ '+', '-', diff --git a/src/slang-nodes/SourceUnit.js b/src/slang-nodes/SourceUnit.js index 29acacd2e..6f3cb3a2a 100644 --- a/src/slang-nodes/SourceUnit.js +++ b/src/slang-nodes/SourceUnit.js @@ -4,7 +4,6 @@ const { line } = doc.builders; export const SourceUnit = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, members: parse(ast.members, options, parse) }), print: ({ options, path, print }) => [ diff --git a/src/slang-nodes/SourceUnitMember.js b/src/slang-nodes/SourceUnitMember.js index 760cbd80d..bc59be136 100644 --- a/src/slang-nodes/SourceUnitMember.js +++ b/src/slang-nodes/SourceUnitMember.js @@ -1,6 +1,5 @@ export const SourceUnitMember = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, variant: parse(ast.variant, options, parse) }), print: ({ path, print }) => path.call(print, 'variant') diff --git a/src/slang-nodes/SourceUnitMembers.js b/src/slang-nodes/SourceUnitMembers.js index 1bf8f406f..7230bd3c6 100644 --- a/src/slang-nodes/SourceUnitMembers.js +++ b/src/slang-nodes/SourceUnitMembers.js @@ -2,7 +2,6 @@ import { printPreservingEmptyLines } from '../common/printer-helpers.js'; export const SourceUnitMembers = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), print: ({ path, options, print }) => diff --git a/src/slang-nodes/StateVariableAttribute.js b/src/slang-nodes/StateVariableAttribute.js index 87fec344b..eeeeb2eb2 100644 --- a/src/slang-nodes/StateVariableAttribute.js +++ b/src/slang-nodes/StateVariableAttribute.js @@ -1,6 +1,5 @@ export const StateVariableAttribute = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/StateVariableAttributes.js b/src/slang-nodes/StateVariableAttributes.js index 2eb593bba..e4aebc536 100644 --- a/src/slang-nodes/StateVariableAttributes.js +++ b/src/slang-nodes/StateVariableAttributes.js @@ -1,6 +1,5 @@ export const StateVariableAttributes = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), print: ({ node, path, print }) => diff --git a/src/slang-nodes/StateVariableDefinition.js b/src/slang-nodes/StateVariableDefinition.js index 83ac00943..4b29d02bd 100644 --- a/src/slang-nodes/StateVariableDefinition.js +++ b/src/slang-nodes/StateVariableDefinition.js @@ -1,6 +1,5 @@ export const StateVariableDefinition = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, typeName: parse(ast.typeName, options, parse), attributes: parse(ast.attributes, options, parse), name: ast.name.text, diff --git a/src/slang-nodes/StateVariableDefinitionValue.js b/src/slang-nodes/StateVariableDefinitionValue.js index 35ea9ce9c..d28dce996 100644 --- a/src/slang-nodes/StateVariableDefinitionValue.js +++ b/src/slang-nodes/StateVariableDefinitionValue.js @@ -4,7 +4,6 @@ const { group, indent, line } = doc.builders; export const StateVariableDefinitionValue = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, equal: ast.equal.text, value: parse(ast.value, options, parse) }), diff --git a/src/slang-nodes/Statement.js b/src/slang-nodes/Statement.js index 80bc079d8..2932b69be 100644 --- a/src/slang-nodes/Statement.js +++ b/src/slang-nodes/Statement.js @@ -1,6 +1,5 @@ export const Statement = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, variant: parse(ast.variant, options, parse) }), print: ({ path, print }) => path.call(print, 'variant') diff --git a/src/slang-nodes/Statements.js b/src/slang-nodes/Statements.js index d10714575..fabd4c24d 100644 --- a/src/slang-nodes/Statements.js +++ b/src/slang-nodes/Statements.js @@ -8,7 +8,6 @@ const { hardline } = doc.builders; export const Statements = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), print: ({ node, path, options, print }) => diff --git a/src/slang-nodes/StorageLocation.js b/src/slang-nodes/StorageLocation.js index fe9a825ad..1f7e90481 100644 --- a/src/slang-nodes/StorageLocation.js +++ b/src/slang-nodes/StorageLocation.js @@ -1,6 +1,5 @@ export const StorageLocation = { parse: ({ ast }) => ({ - kind: ast.cst.kind, variant: ast.variant.text }), print: ({ node }) => node.variant diff --git a/src/slang-nodes/StringExpression.js b/src/slang-nodes/StringExpression.js index 884eefba7..855648d44 100644 --- a/src/slang-nodes/StringExpression.js +++ b/src/slang-nodes/StringExpression.js @@ -1,6 +1,5 @@ export const StringExpression = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, variant: parse(ast.variant, options, parse) }), print: ({ path, print }) => path.call(print, 'variant') diff --git a/src/slang-nodes/StringLiteral.js b/src/slang-nodes/StringLiteral.js index a593d2aae..ddd8896fd 100644 --- a/src/slang-nodes/StringLiteral.js +++ b/src/slang-nodes/StringLiteral.js @@ -2,7 +2,6 @@ import { printString } from '../common/util.js'; export const StringLiteral = { parse: ({ ast, options }) => ({ - kind: ast.cst.kind, variant: printString(ast.variant.text.slice(1, -1), options) }), print: ({ node }) => node.variant diff --git a/src/slang-nodes/StringLiterals.js b/src/slang-nodes/StringLiterals.js index 4d163726d..229d2abcd 100644 --- a/src/slang-nodes/StringLiterals.js +++ b/src/slang-nodes/StringLiterals.js @@ -4,7 +4,6 @@ const { join, hardline } = doc.builders; export const StringLiterals = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), print: ({ path, print }) => join(hardline, path.map(print, 'items')) diff --git a/src/slang-nodes/StructDefinition.js b/src/slang-nodes/StructDefinition.js index f81342596..eeae988dd 100644 --- a/src/slang-nodes/StructDefinition.js +++ b/src/slang-nodes/StructDefinition.js @@ -1,6 +1,5 @@ export const StructDefinition = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, structKeyword: ast.structKeyword.text, name: ast.name.text, openBrace: ast.openBrace.text, diff --git a/src/slang-nodes/StructMember.js b/src/slang-nodes/StructMember.js index 43aa57cbc..fada97185 100644 --- a/src/slang-nodes/StructMember.js +++ b/src/slang-nodes/StructMember.js @@ -1,6 +1,5 @@ export const StructMember = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, typeName: parse(ast.typeName, options, parse), name: ast.name.text, semicolon: ast.semicolon.text diff --git a/src/slang-nodes/StructMembers.js b/src/slang-nodes/StructMembers.js index 4b0d5c6c5..940a9c531 100644 --- a/src/slang-nodes/StructMembers.js +++ b/src/slang-nodes/StructMembers.js @@ -5,7 +5,6 @@ const { hardline } = doc.builders; export const StructMembers = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), print: ({ node, path, print }) => diff --git a/src/slang-nodes/ThrowStatement.js b/src/slang-nodes/ThrowStatement.js index 2b8690054..e414091fd 100644 --- a/src/slang-nodes/ThrowStatement.js +++ b/src/slang-nodes/ThrowStatement.js @@ -1,6 +1,5 @@ export const ThrowStatement = { parse: ({ ast }) => ({ - kind: ast.cst.kind, throwKeyword: ast.throwKeyword.text, semicolon: ast.semicolon.text }), diff --git a/src/slang-nodes/TryStatement.js b/src/slang-nodes/TryStatement.js index 0d2056fb7..21f8f5919 100644 --- a/src/slang-nodes/TryStatement.js +++ b/src/slang-nodes/TryStatement.js @@ -5,7 +5,6 @@ const { line } = doc.builders; export const TryStatement = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, tryKeyword: ast.tryKeyword.text, expression: parse(ast.expression, options, parse), returns: ast.returns ? parse(ast.returns, options, parse) : undefined, diff --git a/src/slang-nodes/TupleDeconstructionElement.js b/src/slang-nodes/TupleDeconstructionElement.js index d59b86766..7c1b8dd59 100644 --- a/src/slang-nodes/TupleDeconstructionElement.js +++ b/src/slang-nodes/TupleDeconstructionElement.js @@ -1,6 +1,5 @@ export const TupleDeconstructionElement = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, member: ast.member ? parse(ast.member, options, parse) : undefined }), print: ({ node, path, print }) => diff --git a/src/slang-nodes/TupleDeconstructionElements.js b/src/slang-nodes/TupleDeconstructionElements.js index 726a5ad05..add09240f 100644 --- a/src/slang-nodes/TupleDeconstructionElements.js +++ b/src/slang-nodes/TupleDeconstructionElements.js @@ -2,7 +2,6 @@ import { printSeparatedList } from '../common/printer-helpers.js'; export const TupleDeconstructionElements = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/TupleDeconstructionStatement.js b/src/slang-nodes/TupleDeconstructionStatement.js index 875bcaf8e..b208dea4f 100644 --- a/src/slang-nodes/TupleDeconstructionStatement.js +++ b/src/slang-nodes/TupleDeconstructionStatement.js @@ -4,7 +4,6 @@ const { group, indent, line } = doc.builders; export const TupleDeconstructionStatement = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, varKeyword: ast.varKeyword?.text, openParen: ast.openParen.text, elements: parse(ast.elements, options, parse), diff --git a/src/slang-nodes/TupleExpression.js b/src/slang-nodes/TupleExpression.js index d26ddb8bc..7a9376a92 100644 --- a/src/slang-nodes/TupleExpression.js +++ b/src/slang-nodes/TupleExpression.js @@ -1,6 +1,5 @@ export const TupleExpression = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, openParen: ast.openParen.text, items: parse(ast.items, options, parse), closeParen: ast.closeParen.text diff --git a/src/slang-nodes/TupleMember.js b/src/slang-nodes/TupleMember.js index 33dadbf32..4c9b56770 100644 --- a/src/slang-nodes/TupleMember.js +++ b/src/slang-nodes/TupleMember.js @@ -1,6 +1,5 @@ export const TupleMember = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, variant: parse(ast.variant, options, parse) }), print: ({ path, print }) => path.call(print, 'variant') diff --git a/src/slang-nodes/TupleValue.js b/src/slang-nodes/TupleValue.js index 027cb17c1..43201e630 100644 --- a/src/slang-nodes/TupleValue.js +++ b/src/slang-nodes/TupleValue.js @@ -1,6 +1,5 @@ export const TupleValue = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, expression: ast.expression ? parse(ast.expression, options, parse) : undefined diff --git a/src/slang-nodes/TupleValues.js b/src/slang-nodes/TupleValues.js index f96805818..b477f15f0 100644 --- a/src/slang-nodes/TupleValues.js +++ b/src/slang-nodes/TupleValues.js @@ -2,7 +2,6 @@ import { printSeparatedList } from '../common/printer-helpers.js'; export const TupleValues = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/TypeExpression.js b/src/slang-nodes/TypeExpression.js index 31e579741..752dec35a 100644 --- a/src/slang-nodes/TypeExpression.js +++ b/src/slang-nodes/TypeExpression.js @@ -1,6 +1,5 @@ export const TypeExpression = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, typeKeyword: ast.typeKeyword.text, openParen: ast.openParen.text, typeName: parse(ast.typeName, options, parse), diff --git a/src/slang-nodes/TypeName.js b/src/slang-nodes/TypeName.js index f87dfbfd0..75f3bbb2e 100644 --- a/src/slang-nodes/TypeName.js +++ b/src/slang-nodes/TypeName.js @@ -1,6 +1,5 @@ export const TypeName = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, variant: parse(ast.variant, options, parse) }), print: ({ path, print }) => path.call(print, 'variant') diff --git a/src/slang-nodes/TypedTupleMember.js b/src/slang-nodes/TypedTupleMember.js index aa7c5ce20..f2038f5a0 100644 --- a/src/slang-nodes/TypedTupleMember.js +++ b/src/slang-nodes/TypedTupleMember.js @@ -1,6 +1,5 @@ export const TypedTupleMember = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, typeName: parse(ast.typeName, options, parse), storageLocation: ast.storageLocation ? parse(ast.storageLocation, options, parse) diff --git a/src/slang-nodes/UncheckedBlock.js b/src/slang-nodes/UncheckedBlock.js index d17c419e6..f8ff87279 100644 --- a/src/slang-nodes/UncheckedBlock.js +++ b/src/slang-nodes/UncheckedBlock.js @@ -1,6 +1,5 @@ export const UncheckedBlock = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, uncheckedKeyword: ast.uncheckedKeyword.text, block: parse(ast.block, options, parse) }), diff --git a/src/slang-nodes/UnicodeStringLiteral.js b/src/slang-nodes/UnicodeStringLiteral.js index 71f74e8e2..6add29a29 100644 --- a/src/slang-nodes/UnicodeStringLiteral.js +++ b/src/slang-nodes/UnicodeStringLiteral.js @@ -2,7 +2,6 @@ import { printString } from '../common/util.js'; export const UnicodeStringLiteral = { parse: ({ ast, options }) => ({ - kind: ast.cst.kind, variant: `unicode${printString(ast.variant.text.slice(8, -1), options)}` }), print: ({ node }) => node.variant diff --git a/src/slang-nodes/UnicodeStringLiterals.js b/src/slang-nodes/UnicodeStringLiterals.js index e7509c118..c229cc774 100644 --- a/src/slang-nodes/UnicodeStringLiterals.js +++ b/src/slang-nodes/UnicodeStringLiterals.js @@ -4,7 +4,6 @@ const { join, hardline } = doc.builders; export const UnicodeStringLiterals = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), print: ({ path, print }) => join(hardline, path.map(print, 'items')) diff --git a/src/slang-nodes/UnnamedFunctionAttribute.js b/src/slang-nodes/UnnamedFunctionAttribute.js index 38d90f3dd..156f65a43 100644 --- a/src/slang-nodes/UnnamedFunctionAttribute.js +++ b/src/slang-nodes/UnnamedFunctionAttribute.js @@ -1,6 +1,5 @@ export const UnnamedFunctionAttribute = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/UnnamedFunctionAttributes.js b/src/slang-nodes/UnnamedFunctionAttributes.js index e20c683a1..6037c819d 100644 --- a/src/slang-nodes/UnnamedFunctionAttributes.js +++ b/src/slang-nodes/UnnamedFunctionAttributes.js @@ -4,7 +4,6 @@ const { line } = doc.builders; export const UnnamedFunctionAttributes = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), print: ({ path, print }) => diff --git a/src/slang-nodes/UnnamedFunctionDefinition.js b/src/slang-nodes/UnnamedFunctionDefinition.js index 7c01ba02b..b49ea65ce 100644 --- a/src/slang-nodes/UnnamedFunctionDefinition.js +++ b/src/slang-nodes/UnnamedFunctionDefinition.js @@ -2,7 +2,6 @@ import { printFunction } from '../common/slang-helpers.js'; export const UnnamedFunctionDefinition = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, functionKeyword: ast.functionKeyword.text, parameters: parse(ast.parameters, options, parse), attributes: parse(ast.attributes, options, parse), diff --git a/src/slang-nodes/UntypedTupleMember.js b/src/slang-nodes/UntypedTupleMember.js index b8707386d..058bfb4c2 100644 --- a/src/slang-nodes/UntypedTupleMember.js +++ b/src/slang-nodes/UntypedTupleMember.js @@ -1,6 +1,5 @@ export const UntypedTupleMember = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, storageLocation: ast.storageLocation ? parse(ast.storageLocation, options, parse) : undefined, diff --git a/src/slang-nodes/UserDefinedValueTypeDefinition.js b/src/slang-nodes/UserDefinedValueTypeDefinition.js index bd584a387..cc1889490 100644 --- a/src/slang-nodes/UserDefinedValueTypeDefinition.js +++ b/src/slang-nodes/UserDefinedValueTypeDefinition.js @@ -1,6 +1,5 @@ export const UserDefinedValueTypeDefinition = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, typeKeyword: ast.typeKeyword.text, name: ast.name.text, isKeyword: ast.isKeyword.text, diff --git a/src/slang-nodes/UsingAlias.js b/src/slang-nodes/UsingAlias.js index 6d1cffb61..8e0cb2683 100644 --- a/src/slang-nodes/UsingAlias.js +++ b/src/slang-nodes/UsingAlias.js @@ -1,6 +1,5 @@ export const UsingAlias = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, asKeyword: ast.asKeyword.text, operator: parse(ast.operator, options, parse) }), diff --git a/src/slang-nodes/UsingClause.js b/src/slang-nodes/UsingClause.js index 98f1647a9..75cd2b903 100644 --- a/src/slang-nodes/UsingClause.js +++ b/src/slang-nodes/UsingClause.js @@ -1,6 +1,5 @@ export const UsingClause = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, variant: parse(ast.variant, options, parse) }), print: ({ path, print }) => path.call(print, 'variant') diff --git a/src/slang-nodes/UsingDeconstruction.js b/src/slang-nodes/UsingDeconstruction.js index ef2602945..b09e55343 100644 --- a/src/slang-nodes/UsingDeconstruction.js +++ b/src/slang-nodes/UsingDeconstruction.js @@ -1,6 +1,5 @@ export const UsingDeconstruction = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, openBrace: ast.openBrace.text, symbols: parse(ast.symbols, options, parse), closeBrace: ast.closeBrace.text diff --git a/src/slang-nodes/UsingDeconstructionSymbol.js b/src/slang-nodes/UsingDeconstructionSymbol.js index 65282c81c..78845afde 100644 --- a/src/slang-nodes/UsingDeconstructionSymbol.js +++ b/src/slang-nodes/UsingDeconstructionSymbol.js @@ -1,6 +1,5 @@ export const UsingDeconstructionSymbol = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, name: parse(ast.name, options, parse), alias: ast.alias ? parse(ast.alias, options, parse) : undefined }), diff --git a/src/slang-nodes/UsingDeconstructionSymbols.js b/src/slang-nodes/UsingDeconstructionSymbols.js index d5376c4b9..be7378eee 100644 --- a/src/slang-nodes/UsingDeconstructionSymbols.js +++ b/src/slang-nodes/UsingDeconstructionSymbols.js @@ -5,7 +5,6 @@ const { line, softline } = doc.builders; export const UsingDeconstructionSymbols = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/UsingDirective.js b/src/slang-nodes/UsingDirective.js index 580444bbd..8cfa1dfd0 100644 --- a/src/slang-nodes/UsingDirective.js +++ b/src/slang-nodes/UsingDirective.js @@ -1,6 +1,5 @@ export const UsingDirective = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, usingKeyword: ast.usingKeyword.text, clause: parse(ast.clause, options, parse), forKeyword: ast.forKeyword.text, diff --git a/src/slang-nodes/UsingOperator.js b/src/slang-nodes/UsingOperator.js index 48336ac14..3514cd39f 100644 --- a/src/slang-nodes/UsingOperator.js +++ b/src/slang-nodes/UsingOperator.js @@ -1,6 +1,5 @@ export const UsingOperator = { parse: ({ ast }) => ({ - kind: ast.cst.kind, variant: ast.variant.text }), print: ({ node }) => node.variant diff --git a/src/slang-nodes/UsingTarget.js b/src/slang-nodes/UsingTarget.js index 777b38dec..ec9660fd8 100644 --- a/src/slang-nodes/UsingTarget.js +++ b/src/slang-nodes/UsingTarget.js @@ -1,6 +1,5 @@ export const UsingTarget = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/VariableDeclarationStatement.js b/src/slang-nodes/VariableDeclarationStatement.js index 8baccc377..c88422084 100644 --- a/src/slang-nodes/VariableDeclarationStatement.js +++ b/src/slang-nodes/VariableDeclarationStatement.js @@ -1,6 +1,5 @@ export const VariableDeclarationStatement = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, variableType: parse(ast.variableType, options, parse), storageLocation: ast.storageLocation ? parse(ast.storageLocation, options, parse) diff --git a/src/slang-nodes/VariableDeclarationType.js b/src/slang-nodes/VariableDeclarationType.js index 385761950..d4506234a 100644 --- a/src/slang-nodes/VariableDeclarationType.js +++ b/src/slang-nodes/VariableDeclarationType.js @@ -1,6 +1,5 @@ export const VariableDeclarationType = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/VariableDeclarationValue.js b/src/slang-nodes/VariableDeclarationValue.js index af0b1ebe7..42d477152 100644 --- a/src/slang-nodes/VariableDeclarationValue.js +++ b/src/slang-nodes/VariableDeclarationValue.js @@ -1,6 +1,5 @@ export const VariableDeclarationValue = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, equal: ast.equal.text, expression: parse(ast.expression, options, parse) }), diff --git a/src/slang-nodes/VersionComparator.js b/src/slang-nodes/VersionComparator.js index 329a45bbd..bb2f67330 100644 --- a/src/slang-nodes/VersionComparator.js +++ b/src/slang-nodes/VersionComparator.js @@ -1,6 +1,5 @@ export const VersionComparator = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, operator: ast.operator.text, operand: parse(ast.operand, options, parse) }), diff --git a/src/slang-nodes/VersionExpression.js b/src/slang-nodes/VersionExpression.js index 534aa89b6..eb827577c 100644 --- a/src/slang-nodes/VersionExpression.js +++ b/src/slang-nodes/VersionExpression.js @@ -1,6 +1,5 @@ export const VersionExpression = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/VersionExpressionSet.js b/src/slang-nodes/VersionExpressionSet.js index b458413c8..ee32680a1 100644 --- a/src/slang-nodes/VersionExpressionSet.js +++ b/src/slang-nodes/VersionExpressionSet.js @@ -4,7 +4,6 @@ const { join } = doc.builders; export const VersionExpressionSet = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), print: ({ path, print }) => join(' ', path.map(print, 'items')) diff --git a/src/slang-nodes/VersionExpressionSets.js b/src/slang-nodes/VersionExpressionSets.js index 655deca77..addaf361b 100644 --- a/src/slang-nodes/VersionExpressionSets.js +++ b/src/slang-nodes/VersionExpressionSets.js @@ -1,6 +1,5 @@ export const VersionExpressionSets = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/VersionPragma.js b/src/slang-nodes/VersionPragma.js index b39508c98..d18057c05 100644 --- a/src/slang-nodes/VersionPragma.js +++ b/src/slang-nodes/VersionPragma.js @@ -1,6 +1,5 @@ export const VersionPragma = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, solidityKeyword: ast.solidityKeyword.text, sets: parse(ast.sets, options, parse) }), diff --git a/src/slang-nodes/VersionRange.js b/src/slang-nodes/VersionRange.js index 81d8626c8..c59335080 100644 --- a/src/slang-nodes/VersionRange.js +++ b/src/slang-nodes/VersionRange.js @@ -1,6 +1,5 @@ export const VersionRange = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, leftOperand: parse(ast.leftOperand, options, parse), operator: ast.operator.text, rightOperand: parse(ast.rightOperand, options, parse) diff --git a/src/slang-nodes/VersionSpecifiers.js b/src/slang-nodes/VersionSpecifiers.js index 2e93bf885..e08e48a0e 100644 --- a/src/slang-nodes/VersionSpecifiers.js +++ b/src/slang-nodes/VersionSpecifiers.js @@ -1,6 +1,5 @@ export const VersionSpecifiers = { parse: ({ ast }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => item.text), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/WhileStatement.js b/src/slang-nodes/WhileStatement.js index 141b69dbb..9ed1f7a3c 100644 --- a/src/slang-nodes/WhileStatement.js +++ b/src/slang-nodes/WhileStatement.js @@ -1,6 +1,5 @@ export const WhileStatement = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, whileKeyword: ast.whileKeyword.text, openParen: ast.openParen.text, condition: parse(ast.condition, options, parse), diff --git a/src/slang-nodes/YulArguments.js b/src/slang-nodes/YulArguments.js index 7f7f74218..97cfcadaa 100644 --- a/src/slang-nodes/YulArguments.js +++ b/src/slang-nodes/YulArguments.js @@ -1,6 +1,5 @@ export const YulArguments = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/YulAssignmentOperator.js b/src/slang-nodes/YulAssignmentOperator.js index c2377681b..0c1421168 100644 --- a/src/slang-nodes/YulAssignmentOperator.js +++ b/src/slang-nodes/YulAssignmentOperator.js @@ -1,6 +1,5 @@ export const YulAssignmentOperator = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/YulAssignmentStatement.js b/src/slang-nodes/YulAssignmentStatement.js index 4f3f48d2e..d02699d16 100644 --- a/src/slang-nodes/YulAssignmentStatement.js +++ b/src/slang-nodes/YulAssignmentStatement.js @@ -1,6 +1,5 @@ export const YulAssignmentStatement = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, names: parse(ast.names, options, parse), assignment: parse(ast.assignment, options, parse), expression: parse(ast.expression, options, parse) diff --git a/src/slang-nodes/YulBlock.js b/src/slang-nodes/YulBlock.js index 1f3c71db6..d786a209e 100644 --- a/src/slang-nodes/YulBlock.js +++ b/src/slang-nodes/YulBlock.js @@ -5,7 +5,6 @@ const { hardline } = doc.builders; export const YulBlock = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, openBrace: ast.openBrace.text, statements: parse(ast.statements, options, parse), closeBrace: ast.closeBrace.text diff --git a/src/slang-nodes/YulBreakStatement.js b/src/slang-nodes/YulBreakStatement.js index 6b5f55781..4062e1a00 100644 --- a/src/slang-nodes/YulBreakStatement.js +++ b/src/slang-nodes/YulBreakStatement.js @@ -1,6 +1,5 @@ export const YulBreakStatement = { parse: ({ ast }) => ({ - kind: ast.cst.kind, breakKeyword: ast.breakKeyword.text }), print: ({ node }) => node.breakKeyword diff --git a/src/slang-nodes/YulBuiltInFunction.js b/src/slang-nodes/YulBuiltInFunction.js index 72b6d6fd7..ce31570da 100644 --- a/src/slang-nodes/YulBuiltInFunction.js +++ b/src/slang-nodes/YulBuiltInFunction.js @@ -1,6 +1,5 @@ export const YulBuiltInFunction = { parse: ({ ast }) => ({ - kind: ast.cst.kind, variant: ast.variant.text }), print: ({ node }) => node.variant diff --git a/src/slang-nodes/YulColonAndEqual.js b/src/slang-nodes/YulColonAndEqual.js index 193ec82b2..e9a02962a 100644 --- a/src/slang-nodes/YulColonAndEqual.js +++ b/src/slang-nodes/YulColonAndEqual.js @@ -1,6 +1,5 @@ export const YulColonAndEqual = { parse: ({ ast }) => ({ - kind: ast.cst.kind, colon: ast.colon.text, equal: ast.equal.text }), diff --git a/src/slang-nodes/YulContinueStatement.js b/src/slang-nodes/YulContinueStatement.js index 8e1f4fb6d..d70042ed8 100644 --- a/src/slang-nodes/YulContinueStatement.js +++ b/src/slang-nodes/YulContinueStatement.js @@ -1,6 +1,5 @@ export const YulContinueStatement = { parse: ({ ast }) => ({ - kind: ast.cst.kind, continueKeyword: ast.continueKeyword.text }), print: ({ node }) => node.continueKeyword diff --git a/src/slang-nodes/YulDefaultCase.js b/src/slang-nodes/YulDefaultCase.js index 8a34c0c9b..783e32950 100644 --- a/src/slang-nodes/YulDefaultCase.js +++ b/src/slang-nodes/YulDefaultCase.js @@ -1,6 +1,5 @@ export const YulDefaultCase = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, defaultKeyword: ast.defaultKeyword.text, body: parse(ast.body, options, parse) }), diff --git a/src/slang-nodes/YulExpression.js b/src/slang-nodes/YulExpression.js index 1b315aa6d..9d3d65441 100644 --- a/src/slang-nodes/YulExpression.js +++ b/src/slang-nodes/YulExpression.js @@ -1,6 +1,5 @@ export const YulExpression = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, variant: parse(ast.variant, options, parse) }), print: ({ path, print }) => path.call(print, 'variant') diff --git a/src/slang-nodes/YulForStatement.js b/src/slang-nodes/YulForStatement.js index ac2b30ebd..a785388e4 100644 --- a/src/slang-nodes/YulForStatement.js +++ b/src/slang-nodes/YulForStatement.js @@ -1,6 +1,5 @@ export const YulForStatement = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, forKeyword: ast.forKeyword.text, initialization: parse(ast.initialization, options, parse), condition: parse(ast.condition, options, parse), diff --git a/src/slang-nodes/YulFunctionCallExpression.js b/src/slang-nodes/YulFunctionCallExpression.js index 5c3481b09..07673b70b 100644 --- a/src/slang-nodes/YulFunctionCallExpression.js +++ b/src/slang-nodes/YulFunctionCallExpression.js @@ -1,6 +1,5 @@ export const YulFunctionCallExpression = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, operand: parse(ast.operand, options, parse), openParen: ast.openParen.text, arguments: parse(ast.arguments, options, parse), diff --git a/src/slang-nodes/YulFunctionDefinition.js b/src/slang-nodes/YulFunctionDefinition.js index 81fdedd72..105b2ab1d 100644 --- a/src/slang-nodes/YulFunctionDefinition.js +++ b/src/slang-nodes/YulFunctionDefinition.js @@ -1,6 +1,5 @@ export const YulFunctionDefinition = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, functionKeyword: ast.functionKeyword.text, name: ast.name.text, parameters: parse(ast.parameters, options, parse), diff --git a/src/slang-nodes/YulIfStatement.js b/src/slang-nodes/YulIfStatement.js index acd091955..a0ee76d72 100644 --- a/src/slang-nodes/YulIfStatement.js +++ b/src/slang-nodes/YulIfStatement.js @@ -1,6 +1,5 @@ export const YulIfStatement = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, ifKeyword: ast.ifKeyword.text, condition: parse(ast.condition, options, parse), body: parse(ast.body, options, parse) diff --git a/src/slang-nodes/YulLabel.js b/src/slang-nodes/YulLabel.js index a0cf07d42..3a7f4ab0e 100644 --- a/src/slang-nodes/YulLabel.js +++ b/src/slang-nodes/YulLabel.js @@ -4,7 +4,6 @@ const { dedent, line } = doc.builders; export const YulLabel = { parse: ({ ast }) => ({ - kind: ast.cst.kind, label: ast.label.text, colon: ast.colon.text }), diff --git a/src/slang-nodes/YulLeaveStatement.js b/src/slang-nodes/YulLeaveStatement.js index f8d140db1..d014e23fe 100644 --- a/src/slang-nodes/YulLeaveStatement.js +++ b/src/slang-nodes/YulLeaveStatement.js @@ -1,6 +1,5 @@ export const YulLeaveStatement = { parse: ({ ast }) => ({ - kind: ast.cst.kind, leaveKeyword: ast.leaveKeyword.text }), // TODO: implement print diff --git a/src/slang-nodes/YulLiteral.js b/src/slang-nodes/YulLiteral.js index 854b26455..998b403a5 100644 --- a/src/slang-nodes/YulLiteral.js +++ b/src/slang-nodes/YulLiteral.js @@ -1,6 +1,5 @@ export const YulLiteral = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/YulParameters.js b/src/slang-nodes/YulParameters.js index fd98c6cf5..cdc084191 100644 --- a/src/slang-nodes/YulParameters.js +++ b/src/slang-nodes/YulParameters.js @@ -2,7 +2,6 @@ import { printSeparatedList } from '../common/printer-helpers.js'; export const YulParameters = { parse: ({ ast }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => item.text), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/YulParametersDeclaration.js b/src/slang-nodes/YulParametersDeclaration.js index 9005fce3d..bfe77ea3c 100644 --- a/src/slang-nodes/YulParametersDeclaration.js +++ b/src/slang-nodes/YulParametersDeclaration.js @@ -1,6 +1,5 @@ export const YulParametersDeclaration = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, openParen: ast.openParen.text, parameters: parse(ast.parameters, options, parse), closeParen: ast.closeParen.text diff --git a/src/slang-nodes/YulPath.js b/src/slang-nodes/YulPath.js index 35f8d6efd..d2950f258 100644 --- a/src/slang-nodes/YulPath.js +++ b/src/slang-nodes/YulPath.js @@ -1,6 +1,5 @@ export const YulPath = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/YulPathComponent.js b/src/slang-nodes/YulPathComponent.js index b4b10be21..411333dc8 100644 --- a/src/slang-nodes/YulPathComponent.js +++ b/src/slang-nodes/YulPathComponent.js @@ -1,6 +1,5 @@ export const YulPathComponent = { parse: ({ ast }) => ({ - kind: ast.cst.kind, variant: ast.variant.text }), print: ({ node }) => node.variant diff --git a/src/slang-nodes/YulPaths.js b/src/slang-nodes/YulPaths.js index a7441d6e6..05d2cda92 100644 --- a/src/slang-nodes/YulPaths.js +++ b/src/slang-nodes/YulPaths.js @@ -1,6 +1,5 @@ export const YulPaths = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/YulReturnVariables.js b/src/slang-nodes/YulReturnVariables.js index d18a339c6..10093aa1a 100644 --- a/src/slang-nodes/YulReturnVariables.js +++ b/src/slang-nodes/YulReturnVariables.js @@ -5,7 +5,6 @@ const { line } = doc.builders; export const YulReturnVariables = { parse: ({ ast }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => item.text), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/YulReturnsDeclaration.js b/src/slang-nodes/YulReturnsDeclaration.js index 22b6614ff..c14565895 100644 --- a/src/slang-nodes/YulReturnsDeclaration.js +++ b/src/slang-nodes/YulReturnsDeclaration.js @@ -5,7 +5,6 @@ const { line } = doc.builders; export const YulReturnsDeclaration = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, minusGreaterThan: ast.minusGreaterThan.text, variables: parse(ast.variables, options, parse) }), diff --git a/src/slang-nodes/YulStatement.js b/src/slang-nodes/YulStatement.js index 076bb7cf0..246fdb308 100644 --- a/src/slang-nodes/YulStatement.js +++ b/src/slang-nodes/YulStatement.js @@ -1,6 +1,5 @@ export const YulStatement = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, variant: parse(ast.variant, options, parse) }), print: ({ path, print }) => path.call(print, 'variant') diff --git a/src/slang-nodes/YulStatements.js b/src/slang-nodes/YulStatements.js index bcbb7ea7a..66536e972 100644 --- a/src/slang-nodes/YulStatements.js +++ b/src/slang-nodes/YulStatements.js @@ -2,7 +2,6 @@ import { printPreservingEmptyLines } from '../common/printer-helpers.js'; export const YulStatements = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), print: ({ path, print, options }) => diff --git a/src/slang-nodes/YulSwitchCase.js b/src/slang-nodes/YulSwitchCase.js index b2e7a9af6..363e57eb9 100644 --- a/src/slang-nodes/YulSwitchCase.js +++ b/src/slang-nodes/YulSwitchCase.js @@ -1,6 +1,5 @@ export const YulSwitchCase = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, variant: parse(ast.variant, options, parse) }), print: ({ path, print }) => path.call(print, 'variant') diff --git a/src/slang-nodes/YulSwitchCases.js b/src/slang-nodes/YulSwitchCases.js index 72006eaf7..6ea070dd0 100644 --- a/src/slang-nodes/YulSwitchCases.js +++ b/src/slang-nodes/YulSwitchCases.js @@ -4,7 +4,6 @@ const { hardline, join } = doc.builders; export const YulSwitchCases = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, items: ast.items.map((item) => parse(item, options, parse)) }), print: ({ path, print }) => join(hardline, path.map(print, 'items')) diff --git a/src/slang-nodes/YulSwitchStatement.js b/src/slang-nodes/YulSwitchStatement.js index f54ee32b2..f29a2ccb3 100644 --- a/src/slang-nodes/YulSwitchStatement.js +++ b/src/slang-nodes/YulSwitchStatement.js @@ -4,7 +4,6 @@ const { hardline } = doc.builders; export const YulSwitchStatement = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, switchKeyword: ast.switchKeyword.text, expression: parse(ast.expression, options, parse), cases: parse(ast.cases, options, parse) diff --git a/src/slang-nodes/YulValueCase.js b/src/slang-nodes/YulValueCase.js index ed876b5da..09218cbbd 100644 --- a/src/slang-nodes/YulValueCase.js +++ b/src/slang-nodes/YulValueCase.js @@ -1,6 +1,5 @@ export const YulValueCase = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, caseKeyword: ast.caseKeyword.text, value: parse(ast.value, options, parse), body: parse(ast.body, options, parse) diff --git a/src/slang-nodes/YulVariableAssignmentStatement.js b/src/slang-nodes/YulVariableAssignmentStatement.js index 532b5fd19..f3acb32e9 100644 --- a/src/slang-nodes/YulVariableAssignmentStatement.js +++ b/src/slang-nodes/YulVariableAssignmentStatement.js @@ -1,6 +1,5 @@ export const YulVariableAssignmentStatement = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, names: parse(ast.names, options, parse), assignment: parse(ast.assignment, options, parse), expression: parse(ast.expression, options, parse) diff --git a/src/slang-nodes/YulVariableDeclarationStatement.js b/src/slang-nodes/YulVariableDeclarationStatement.js index e3ff630b7..2b426cbe2 100644 --- a/src/slang-nodes/YulVariableDeclarationStatement.js +++ b/src/slang-nodes/YulVariableDeclarationStatement.js @@ -1,6 +1,5 @@ export const YulVariableDeclarationStatement = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, letKeyword: ast.letKeyword.text, names: ast.names.text, value: ast.value ? parse(ast.value, options, parse) : undefined diff --git a/src/slang-nodes/YulVariableDeclarationValue.js b/src/slang-nodes/YulVariableDeclarationValue.js index 6ec94e862..a259478a2 100644 --- a/src/slang-nodes/YulVariableDeclarationValue.js +++ b/src/slang-nodes/YulVariableDeclarationValue.js @@ -1,6 +1,5 @@ export const YulVariableDeclarationValue = { parse: ({ ast, options, parse }) => ({ - kind: ast.cst.kind, assignment: parse(ast.assignment, options, parse), expression: parse(ast.expression, options, parse) }), diff --git a/src/slangParser.js b/src/slangParser.js index 846fa13d8..67ef92285 100644 --- a/src/slangParser.js +++ b/src/slangParser.js @@ -7,7 +7,15 @@ import coerce from 'semver/functions/coerce.js'; import * as parsers from './slang-nodes/index.js'; function genericParse(ast, options, parseFunction) { - return parsers[ast.cst.kind].parse({ ast, options, parse: parseFunction }); + const data = parsers[ast.cst.kind].parse({ + ast, + options, + parse: parseFunction + }); + + data.kind = ast.cst.kind; + + return data; } function parse(text, _parsers, options = _parsers) { From ad0aacc18295945faae0f4aefdec54c62da3ad8c Mon Sep 17 00:00:00 2001 From: Klaus Date: Mon, 17 Jun 2024 23:12:44 +1200 Subject: [PATCH 031/160] locEnd and locStart recreated using cst --- src/common/slang-helpers.js | 28 +- src/index.js | 3 +- src/slang-nodes/ABICoderPragma.js | 3 +- src/slang-nodes/AdditiveExpression.js | 9 +- src/slang-nodes/AddressType.js | 3 +- src/slang-nodes/AndExpression.js | 7 +- src/slang-nodes/ArgumentsDeclaration.js | 5 +- src/slang-nodes/ArrayExpression.js | 5 +- src/slang-nodes/ArrayTypeName.js | 7 +- src/slang-nodes/ArrayValues.js | 5 +- src/slang-nodes/AssemblyFlags.js | 5 +- src/slang-nodes/AssemblyFlagsDeclaration.js | 5 +- src/slang-nodes/AssemblyStatement.js | 9 +- src/slang-nodes/AssignmentExpression.js | 7 +- src/slang-nodes/BitwiseAndExpression.js | 7 +- src/slang-nodes/BitwiseOrExpression.js | 7 +- src/slang-nodes/BitwiseXorExpression.js | 7 +- src/slang-nodes/Block.js | 5 +- src/slang-nodes/BreakStatement.js | 3 +- src/slang-nodes/CallOptions.js | 5 +- src/slang-nodes/CallOptionsExpression.js | 7 +- src/slang-nodes/CatchClause.js | 7 +- src/slang-nodes/CatchClauseError.js | 5 +- src/slang-nodes/CatchClauses.js | 5 +- src/slang-nodes/ComparisonExpression.js | 7 +- src/slang-nodes/ConditionalExpression.js | 9 +- src/slang-nodes/ConstantDefinition.js | 7 +- src/slang-nodes/ConstructorAttribute.js | 5 +- src/slang-nodes/ConstructorAttributes.js | 5 +- src/slang-nodes/ConstructorDefinition.js | 9 +- src/slang-nodes/ContinueStatement.js | 3 +- src/slang-nodes/ContractDefinition.js | 7 +- src/slang-nodes/ContractMember.js | 5 +- src/slang-nodes/ContractMembers.js | 11 +- src/slang-nodes/DecimalNumberExpression.js | 5 +- src/slang-nodes/DoWhileStatement.js | 7 +- src/slang-nodes/ElementaryType.js | 5 +- src/slang-nodes/ElseBranch.js | 5 +- src/slang-nodes/EmitStatement.js | 7 +- src/slang-nodes/EnumDefinition.js | 5 +- src/slang-nodes/EnumMembers.js | 3 +- src/slang-nodes/EqualityExpression.js | 7 +- src/slang-nodes/ErrorDefinition.js | 5 +- src/slang-nodes/ErrorParameter.js | 5 +- src/slang-nodes/ErrorParameters.js | 5 +- src/slang-nodes/ErrorParametersDeclaration.js | 5 +- src/slang-nodes/EventDefinition.js | 5 +- src/slang-nodes/EventParameter.js | 5 +- src/slang-nodes/EventParameters.js | 5 +- src/slang-nodes/EventParametersDeclaration.js | 5 +- src/slang-nodes/ExperimentalFeature.js | 5 +- src/slang-nodes/ExperimentalPragma.js | 5 +- src/slang-nodes/ExponentiationExpression.js | 7 +- src/slang-nodes/Expression.js | 5 +- src/slang-nodes/ExpressionStatement.js | 5 +- src/slang-nodes/FallbackFunctionAttribute.js | 5 +- src/slang-nodes/FallbackFunctionAttributes.js | 5 +- src/slang-nodes/FallbackFunctionDefinition.js | 13 +- src/slang-nodes/ForStatement.js | 13 +- src/slang-nodes/ForStatementCondition.js | 5 +- src/slang-nodes/ForStatementInitialization.js | 5 +- src/slang-nodes/FunctionAttribute.js | 5 +- src/slang-nodes/FunctionAttributes.js | 5 +- src/slang-nodes/FunctionBody.js | 5 +- src/slang-nodes/FunctionCallExpression.js | 8 +- src/slang-nodes/FunctionDefinition.js | 16 +- src/slang-nodes/FunctionName.js | 3 +- src/slang-nodes/FunctionType.js | 11 +- src/slang-nodes/FunctionTypeAttribute.js | 3 +- src/slang-nodes/FunctionTypeAttributes.js | 5 +- src/slang-nodes/HexNumberExpression.js | 5 +- src/slang-nodes/HexStringLiteral.js | 3 +- src/slang-nodes/HexStringLiterals.js | 5 +- src/slang-nodes/IdentifierPath.js | 3 +- src/slang-nodes/IfStatement.js | 9 +- src/slang-nodes/ImportAlias.js | 3 +- src/slang-nodes/ImportClause.js | 5 +- src/slang-nodes/ImportDeconstruction.js | 7 +- src/slang-nodes/ImportDeconstructionSymbol.js | 5 +- .../ImportDeconstructionSymbols.js | 5 +- src/slang-nodes/ImportDirective.js | 5 +- src/slang-nodes/IndexAccessEnd.js | 5 +- src/slang-nodes/IndexAccessExpression.js | 10 +- src/slang-nodes/InheritanceSpecifier.js | 5 +- src/slang-nodes/InheritanceType.js | 9 +- src/slang-nodes/InheritanceTypes.js | 6 +- src/slang-nodes/InterfaceDefinition.js | 7 +- src/slang-nodes/InterfaceMembers.js | 11 +- src/slang-nodes/LibraryDefinition.js | 5 +- src/slang-nodes/LibraryMembers.js | 11 +- src/slang-nodes/MappingKey.js | 5 +- src/slang-nodes/MappingKeyType.js | 5 +- src/slang-nodes/MappingType.js | 7 +- src/slang-nodes/MappingValue.js | 5 +- src/slang-nodes/MemberAccess.js | 3 +- src/slang-nodes/MemberAccessExpression.js | 7 +- src/slang-nodes/ModifierAttribute.js | 5 +- src/slang-nodes/ModifierAttributes.js | 5 +- src/slang-nodes/ModifierDefinition.js | 9 +- src/slang-nodes/ModifierInvocation.js | 9 +- src/slang-nodes/MultiplicativeExpression.js | 7 +- src/slang-nodes/NamedArgument.js | 5 +- src/slang-nodes/NamedArgumentGroup.js | 5 +- src/slang-nodes/NamedArguments.js | 5 +- src/slang-nodes/NamedArgumentsDeclaration.js | 7 +- src/slang-nodes/NamedImport.js | 7 +- src/slang-nodes/NewExpression.js | 5 +- src/slang-nodes/NumberUnit.js | 3 +- src/slang-nodes/OrExpression.js | 11 +- src/slang-nodes/OverridePaths.js | 5 +- src/slang-nodes/OverridePathsDeclaration.js | 5 +- src/slang-nodes/OverrideSpecifier.js | 5 +- src/slang-nodes/Parameter.js | 7 +- src/slang-nodes/Parameters.js | 5 +- src/slang-nodes/ParametersDeclaration.js | 5 +- src/slang-nodes/PathImport.js | 7 +- src/slang-nodes/PositionalArguments.js | 5 +- .../PositionalArgumentsDeclaration.js | 5 +- src/slang-nodes/PostfixExpression.js | 5 +- src/slang-nodes/Pragma.js | 5 +- src/slang-nodes/PragmaDirective.js | 5 +- src/slang-nodes/PrefixExpression.js | 5 +- src/slang-nodes/ReceiveFunctionAttribute.js | 5 +- src/slang-nodes/ReceiveFunctionAttributes.js | 5 +- src/slang-nodes/ReceiveFunctionDefinition.js | 9 +- src/slang-nodes/ReturnStatement.js | 5 +- src/slang-nodes/ReturnsDeclaration.js | 5 +- src/slang-nodes/RevertStatement.js | 7 +- src/slang-nodes/ShiftExpression.js | 7 +- src/slang-nodes/SourceUnit.js | 5 +- src/slang-nodes/SourceUnitMember.js | 5 +- src/slang-nodes/SourceUnitMembers.js | 7 +- src/slang-nodes/StateVariableAttribute.js | 5 +- src/slang-nodes/StateVariableAttributes.js | 5 +- src/slang-nodes/StateVariableDefinition.js | 9 +- .../StateVariableDefinitionValue.js | 5 +- src/slang-nodes/Statement.js | 5 +- src/slang-nodes/Statements.js | 11 +- src/slang-nodes/StorageLocation.js | 3 +- src/slang-nodes/StringExpression.js | 5 +- src/slang-nodes/StringLiteral.js | 3 +- src/slang-nodes/StringLiterals.js | 5 +- src/slang-nodes/StructDefinition.js | 5 +- src/slang-nodes/StructMember.js | 5 +- src/slang-nodes/StructMembers.js | 5 +- src/slang-nodes/ThrowStatement.js | 3 +- src/slang-nodes/TryStatement.js | 13 +- src/slang-nodes/TupleDeconstructionElement.js | 5 +- .../TupleDeconstructionElements.js | 5 +- .../TupleDeconstructionStatement.js | 7 +- src/slang-nodes/TupleExpression.js | 5 +- src/slang-nodes/TupleMember.js | 5 +- src/slang-nodes/TupleValue.js | 5 +- src/slang-nodes/TupleValues.js | 5 +- src/slang-nodes/TypeExpression.js | 5 +- src/slang-nodes/TypeName.js | 5 +- src/slang-nodes/TypedTupleMember.js | 7 +- src/slang-nodes/UncheckedBlock.js | 5 +- src/slang-nodes/UnicodeStringLiteral.js | 3 +- src/slang-nodes/UnicodeStringLiterals.js | 5 +- src/slang-nodes/UnnamedFunctionAttribute.js | 5 +- src/slang-nodes/UnnamedFunctionAttributes.js | 5 +- src/slang-nodes/UnnamedFunctionDefinition.js | 9 +- src/slang-nodes/UntypedTupleMember.js | 5 +- .../UserDefinedValueTypeDefinition.js | 5 +- src/slang-nodes/UsingAlias.js | 5 +- src/slang-nodes/UsingClause.js | 5 +- src/slang-nodes/UsingDeconstruction.js | 5 +- src/slang-nodes/UsingDeconstructionSymbol.js | 7 +- src/slang-nodes/UsingDeconstructionSymbols.js | 5 +- src/slang-nodes/UsingDirective.js | 7 +- src/slang-nodes/UsingOperator.js | 3 +- src/slang-nodes/UsingTarget.js | 5 +- .../VariableDeclarationStatement.js | 9 +- src/slang-nodes/VariableDeclarationType.js | 5 +- src/slang-nodes/VariableDeclarationValue.js | 5 +- src/slang-nodes/VersionComparator.js | 5 +- src/slang-nodes/VersionExpression.js | 5 +- src/slang-nodes/VersionExpressionSet.js | 5 +- src/slang-nodes/VersionExpressionSets.js | 5 +- src/slang-nodes/VersionPragma.js | 5 +- src/slang-nodes/VersionRange.js | 7 +- src/slang-nodes/VersionSpecifiers.js | 3 +- src/slang-nodes/WhileStatement.js | 7 +- src/slang-nodes/YulArguments.js | 5 +- src/slang-nodes/YulAssignmentOperator.js | 5 +- src/slang-nodes/YulAssignmentStatement.js | 9 +- src/slang-nodes/YulBlock.js | 5 +- src/slang-nodes/YulBreakStatement.js | 3 +- src/slang-nodes/YulBuiltInFunction.js | 3 +- src/slang-nodes/YulColonAndEqual.js | 3 +- src/slang-nodes/YulContinueStatement.js | 3 +- src/slang-nodes/YulDefaultCase.js | 5 +- src/slang-nodes/YulExpression.js | 5 +- src/slang-nodes/YulForStatement.js | 11 +- src/slang-nodes/YulFunctionCallExpression.js | 7 +- src/slang-nodes/YulFunctionDefinition.js | 11 +- src/slang-nodes/YulIfStatement.js | 7 +- src/slang-nodes/YulLabel.js | 3 +- src/slang-nodes/YulLeaveStatement.js | 3 +- src/slang-nodes/YulLiteral.js | 5 +- src/slang-nodes/YulParameters.js | 3 +- src/slang-nodes/YulParametersDeclaration.js | 5 +- src/slang-nodes/YulPath.js | 5 +- src/slang-nodes/YulPathComponent.js | 3 +- src/slang-nodes/YulPaths.js | 5 +- src/slang-nodes/YulReturnVariables.js | 3 +- src/slang-nodes/YulReturnsDeclaration.js | 5 +- src/slang-nodes/YulStatement.js | 5 +- src/slang-nodes/YulStatements.js | 7 +- src/slang-nodes/YulSwitchCase.js | 5 +- src/slang-nodes/YulSwitchCases.js | 5 +- src/slang-nodes/YulSwitchStatement.js | 7 +- src/slang-nodes/YulValueCase.js | 7 +- .../YulVariableAssignmentStatement.js | 9 +- .../YulVariableDeclarationStatement.js | 5 +- .../YulVariableDeclarationValue.js | 7 +- src/slangParser.js | 55 ++- .../__snapshots__/jsfmt.spec.js.snap | 1 + .../Arrays/__snapshots__/jsfmt.spec.js.snap | 3 + .../Assembly/__snapshots__/jsfmt.spec.js.snap | 24 ++ .../__snapshots__/jsfmt.spec.js.snap | 3 + .../__snapshots__/jsfmt.spec.js.snap | 3 + .../__snapshots__/jsfmt.spec.js.snap | 7 + .../__snapshots__/jsfmt.spec.js.snap | 6 + .../__snapshots__/jsfmt.spec.js.snap | 4 + .../Comments/__snapshots__/jsfmt.spec.js.snap | 18 + .../__snapshots__/jsfmt.spec.js.snap | 2 + .../__snapshots__/jsfmt.spec.js.snap | 2 + .../__snapshots__/jsfmt.spec.js.snap | 3 + .../Etc/__snapshots__/jsfmt.spec.js.snap | 7 + .../__snapshots__/jsfmt.spec.js.snap | 164 +++++++-- .../__snapshots__/jsfmt.spec.js.snap | 15 + .../__snapshots__/jsfmt.spec.js.snap | 6 + .../__snapshots__/jsfmt.spec.js.snap | 4 + .../__snapshots__/jsfmt.spec.js.snap | 2 + .../__snapshots__/jsfmt.spec.js.snap | 34 ++ .../__snapshots__/jsfmt.spec.js.snap | 3 + .../Inbox/__snapshots__/jsfmt.spec.js.snap | 4 + .../IndexOf/__snapshots__/jsfmt.spec.js.snap | 4 + .../__snapshots__/jsfmt.spec.js.snap | 2 + .../Issues/__snapshots__/jsfmt.spec.js.snap | 7 + .../__snapshots__/jsfmt.spec.js.snap | 3 + .../__snapshots__/jsfmt.spec.js.snap | 3 + .../__snapshots__/jsfmt.spec.js.snap | 1 + .../__snapshots__/jsfmt.spec.js.snap | 2 + .../__snapshots__/jsfmt.spec.js.snap | 1 + .../Ownable/__snapshots__/jsfmt.spec.js.snap | 9 + .../__snapshots__/jsfmt.spec.js.snap | 313 +++++++----------- .../__snapshots__/jsfmt.spec.js.snap | 3 + .../Proxy/__snapshots__/jsfmt.spec.js.snap | 7 + .../__snapshots__/jsfmt.spec.js.snap | 4 + .../__snapshots__/jsfmt.spec.js.snap | 14 + .../__snapshots__/jsfmt.spec.js.snap | 3 + .../__snapshots__/jsfmt.spec.js.snap | 9 + .../__snapshots__/jsfmt.spec.js.snap | 42 +++ .../TryCatch/__snapshots__/jsfmt.spec.js.snap | 5 + .../Tupples/__snapshots__/jsfmt.spec.js.snap | 2 + .../__snapshots__/jsfmt.spec.js.snap | 3 + .../__snapshots__/jsfmt.spec.js.snap | 14 + .../quotes/__snapshots__/jsfmt.spec.js.snap | 2 + .../strings/__snapshots__/jsfmt.spec.js.snap | 68 ++++ 262 files changed, 1432 insertions(+), 737 deletions(-) diff --git a/src/common/slang-helpers.js b/src/common/slang-helpers.js index c3d374a6b..6cae1ed46 100644 --- a/src/common/slang-helpers.js +++ b/src/common/slang-helpers.js @@ -1,6 +1,7 @@ import { doc } from 'prettier'; +import { isLast, isNextLineEmpty } from './backward-compatibility.js'; -const { dedent, group, indent, line } = doc.builders; +const { dedent, group, hardline, indent, line } = doc.builders; export const printFunction = (functionName, node, path, print) => [ group([ @@ -17,6 +18,29 @@ export const printFunction = (functionName, node, path, print) => [ node.body ? path.call(print, 'body') : '' ]; +export function printPreservingEmptyLines(path, key, options, print) { + return path.map((childPath, index) => { + const node = childPath.getNode(); + + return [ + // Only attempt to prepend an empty line if `node` is not the first item + index > 0 && + // YulLabel adds a dedented line so we don't have to prepend a hardline. + node.variant.kind !== 'YulLabel' + ? hardline + : '', + print(childPath), + // Only attempt to append an empty line if `node` is not the last item + !isLast(childPath, key, index) && + // Append an empty line if the original text already had an one after the + // current `node` + isNextLineEmpty(options.originalText, options.locEnd(node)) + ? hardline + : '' + ]; + }, key); +} + export const binaryOperationKinds = [ 'AdditiveExpression', 'MultiplicativeExpression', @@ -99,7 +123,7 @@ const logicalIndentRulesBuilder = (path, options) => (document) => { return document; if ( options.experimentalTernaries && - parentNode.type === 'ConditionalExpression' && + parentNode.kind === 'ConditionalExpression' && parentNode.operand.variant === node ) return document; diff --git a/src/index.js b/src/index.js index 60171ef84..d6cc17c78 100644 --- a/src/index.js +++ b/src/index.js @@ -28,7 +28,8 @@ const parser = { astFormat: 'solidity-ast', parse, ...loc }; const slangParser = { astFormat: 'solidity-slang-ast', parse: slangParse, - ...loc + locStart: (node) => node.loc.start, + locEnd: (node) => node.loc.end }; const parsers = { 'solidity-parse': parser, diff --git a/src/slang-nodes/ABICoderPragma.js b/src/slang-nodes/ABICoderPragma.js index 5de917342..a590793e1 100644 --- a/src/slang-nodes/ABICoderPragma.js +++ b/src/slang-nodes/ABICoderPragma.js @@ -1,5 +1,6 @@ export const ABICoderPragma = { - parse: ({ ast }) => ({ + parse: ({ node, offsets, ast }) => ({ + ...node, abicoderKeyword: ast.abicoderKeyword.text, version: ast.version.text }), diff --git a/src/slang-nodes/AdditiveExpression.js b/src/slang-nodes/AdditiveExpression.js index f4afb7260..70e2f3c69 100644 --- a/src/slang-nodes/AdditiveExpression.js +++ b/src/slang-nodes/AdditiveExpression.js @@ -1,10 +1,13 @@ import { binaryOperationPrint, tryHug } from '../common/slang-helpers.js'; export const AdditiveExpression = { - parse: ({ ast, options, parse }) => ({ - leftOperand: tryHug(parse(ast.leftOperand, options, parse), ['%']), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + leftOperand: tryHug(parse(ast.leftOperand, options, parse, offsets), ['%']), operator: ast.operator.text, - rightOperand: tryHug(parse(ast.rightOperand, options, parse), ['%']) + rightOperand: tryHug(parse(ast.rightOperand, options, parse, offsets), [ + '%' + ]) }), print: binaryOperationPrint }; diff --git a/src/slang-nodes/AddressType.js b/src/slang-nodes/AddressType.js index 75c8d2c8e..43cf29d79 100644 --- a/src/slang-nodes/AddressType.js +++ b/src/slang-nodes/AddressType.js @@ -1,5 +1,6 @@ export const AddressType = { - parse: ({ ast }) => ({ + parse: ({ node, offsets, ast }) => ({ + ...node, addressKeyword: ast.addressKeyword.text, payableKeyword: ast.payableKeyword?.text }), diff --git a/src/slang-nodes/AndExpression.js b/src/slang-nodes/AndExpression.js index 1978c8b8f..4601e3fde 100644 --- a/src/slang-nodes/AndExpression.js +++ b/src/slang-nodes/AndExpression.js @@ -1,10 +1,11 @@ import { logicalOperationPrint } from '../common/slang-helpers.js'; export const AndExpression = { - parse: ({ ast, options, parse }) => ({ - leftOperand: parse(ast.leftOperand, options, parse), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + leftOperand: parse(ast.leftOperand, options, parse, offsets), operator: ast.operator.text, - rightOperand: parse(ast.rightOperand, options, parse) + rightOperand: parse(ast.rightOperand, options, parse, offsets) }), print: logicalOperationPrint }; diff --git a/src/slang-nodes/ArgumentsDeclaration.js b/src/slang-nodes/ArgumentsDeclaration.js index b81548d51..ad2e1a2a0 100644 --- a/src/slang-nodes/ArgumentsDeclaration.js +++ b/src/slang-nodes/ArgumentsDeclaration.js @@ -1,6 +1,7 @@ export const ArgumentsDeclaration = { - parse: ({ ast, options, parse }) => ({ - variant: parse(ast.variant, options, parse) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + variant: parse(ast.variant, options, parse, offsets) }), print: ({ path, print }) => path.call(print, 'variant') }; diff --git a/src/slang-nodes/ArrayExpression.js b/src/slang-nodes/ArrayExpression.js index afc98c477..a143f507d 100644 --- a/src/slang-nodes/ArrayExpression.js +++ b/src/slang-nodes/ArrayExpression.js @@ -3,9 +3,10 @@ import { doc } from 'prettier'; const { group } = doc.builders; export const ArrayExpression = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, openBracket: ast.openBracket.text, - items: parse(ast.items, options, parse), + items: parse(ast.items, options, parse, offsets), closeBracket: ast.closeBracket.text }), print: ({ node, path, print }) => diff --git a/src/slang-nodes/ArrayTypeName.js b/src/slang-nodes/ArrayTypeName.js index fd2033483..a3a75c65f 100644 --- a/src/slang-nodes/ArrayTypeName.js +++ b/src/slang-nodes/ArrayTypeName.js @@ -1,8 +1,9 @@ export const ArrayTypeName = { - parse: ({ ast, options, parse }) => ({ - operand: parse(ast.operand, options, parse), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + operand: parse(ast.operand, options, parse, offsets), openBracket: ast.openBracket.text, - index: ast.index ? parse(ast.index, options, parse) : undefined, + index: ast.index ? parse(ast.index, options, parse, offsets) : undefined, closeBracket: ast.closeBracket.text }), print: ({ node, path, print }) => [ diff --git a/src/slang-nodes/ArrayValues.js b/src/slang-nodes/ArrayValues.js index 0cb242986..61e8c8ce7 100644 --- a/src/slang-nodes/ArrayValues.js +++ b/src/slang-nodes/ArrayValues.js @@ -1,8 +1,9 @@ import { printSeparatedList } from '../common/printer-helpers.js'; export const ArrayValues = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), print: ({ path, print }) => printSeparatedList(path.map(print, 'items')) diff --git a/src/slang-nodes/AssemblyFlags.js b/src/slang-nodes/AssemblyFlags.js index 5c950f912..b62a5568c 100644 --- a/src/slang-nodes/AssemblyFlags.js +++ b/src/slang-nodes/AssemblyFlags.js @@ -1,8 +1,9 @@ import { printSeparatedList } from '../common/printer-helpers.js'; export const AssemblyFlags = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), print: ({ path, print }) => printSeparatedList(path.map(print, 'items')) diff --git a/src/slang-nodes/AssemblyFlagsDeclaration.js b/src/slang-nodes/AssemblyFlagsDeclaration.js index 8abbbb25e..e4bc26559 100644 --- a/src/slang-nodes/AssemblyFlagsDeclaration.js +++ b/src/slang-nodes/AssemblyFlagsDeclaration.js @@ -1,7 +1,8 @@ export const AssemblyFlagsDeclaration = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, openParen: ast.openParen.text, - flags: parse(ast.flags, options, parse), + flags: parse(ast.flags, options, parse, offsets), closeParen: ast.closeParen.text }), print: ({ node, path, print }) => [ diff --git a/src/slang-nodes/AssemblyStatement.js b/src/slang-nodes/AssemblyStatement.js index a60ebff9e..db1d0bee0 100644 --- a/src/slang-nodes/AssemblyStatement.js +++ b/src/slang-nodes/AssemblyStatement.js @@ -1,9 +1,10 @@ export const AssemblyStatement = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, assemblyKeyword: ast.assemblyKeyword.text, - label: ast.label ? parse(ast.label, options, parse) : undefined, - flags: ast.flags ? parse(ast.flags, options, parse) : undefined, - body: parse(ast.body, options, parse) + label: ast.label ? parse(ast.label, options, parse, offsets) : undefined, + flags: ast.flags ? parse(ast.flags, options, parse, offsets) : undefined, + body: parse(ast.body, options, parse, offsets) }), print: ({ node, path, print }) => [ node.assemblyKeyword, diff --git a/src/slang-nodes/AssignmentExpression.js b/src/slang-nodes/AssignmentExpression.js index d183ab4e0..e8b4176d7 100644 --- a/src/slang-nodes/AssignmentExpression.js +++ b/src/slang-nodes/AssignmentExpression.js @@ -4,10 +4,11 @@ import { binaryOperationKinds } from '../common/slang-helpers.js'; const { group, indent, line } = doc.builders; export const AssignmentExpression = { - parse: ({ ast, options, parse }) => ({ - leftOperand: parse(ast.leftOperand, options, parse), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + leftOperand: parse(ast.leftOperand, options, parse, offsets), operator: ast.operator.text, - rightOperand: parse(ast.rightOperand, options, parse) + rightOperand: parse(ast.rightOperand, options, parse, offsets) }), print: ({ node, path, print }) => [ path.call(print, 'leftOperand'), diff --git a/src/slang-nodes/BitwiseAndExpression.js b/src/slang-nodes/BitwiseAndExpression.js index e9bac0ac9..b501d0abe 100644 --- a/src/slang-nodes/BitwiseAndExpression.js +++ b/src/slang-nodes/BitwiseAndExpression.js @@ -1,8 +1,9 @@ import { binaryOperationPrint, tryHug } from '../common/slang-helpers.js'; export const BitwiseAndExpression = { - parse: ({ ast, options, parse }) => ({ - leftOperand: tryHug(parse(ast.leftOperand, options, parse), [ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + leftOperand: tryHug(parse(ast.leftOperand, options, parse, offsets), [ '+', '-', '*', @@ -12,7 +13,7 @@ export const BitwiseAndExpression = { '>>' ]), operator: ast.operator.text, - rightOperand: tryHug(parse(ast.rightOperand, options, parse), [ + rightOperand: tryHug(parse(ast.rightOperand, options, parse, offsets), [ '+', '-', '*', diff --git a/src/slang-nodes/BitwiseOrExpression.js b/src/slang-nodes/BitwiseOrExpression.js index 5b3f18a81..da479affb 100644 --- a/src/slang-nodes/BitwiseOrExpression.js +++ b/src/slang-nodes/BitwiseOrExpression.js @@ -1,8 +1,9 @@ import { binaryOperationPrint, tryHug } from '../common/slang-helpers.js'; export const BitwiseOrExpression = { - parse: ({ ast, options, parse }) => ({ - leftOperand: tryHug(parse(ast.leftOperand, options, parse), [ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + leftOperand: tryHug(parse(ast.leftOperand, options, parse, offsets), [ '+', '-', '*', @@ -14,7 +15,7 @@ export const BitwiseOrExpression = { '^' ]), operator: ast.operator.text, - rightOperand: tryHug(parse(ast.rightOperand, options, parse), [ + rightOperand: tryHug(parse(ast.rightOperand, options, parse, offsets), [ '+', '-', '*', diff --git a/src/slang-nodes/BitwiseXorExpression.js b/src/slang-nodes/BitwiseXorExpression.js index 1e867ea87..cf898083e 100644 --- a/src/slang-nodes/BitwiseXorExpression.js +++ b/src/slang-nodes/BitwiseXorExpression.js @@ -1,8 +1,9 @@ import { binaryOperationPrint, tryHug } from '../common/slang-helpers.js'; export const BitwiseXorExpression = { - parse: ({ ast, options, parse }) => ({ - leftOperand: tryHug(parse(ast.leftOperand, options, parse), [ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + leftOperand: tryHug(parse(ast.leftOperand, options, parse, offsets), [ '+', '-', '*', @@ -13,7 +14,7 @@ export const BitwiseXorExpression = { '&' ]), operator: ast.operator.text, - rightOperand: tryHug(parse(ast.rightOperand, options, parse), [ + rightOperand: tryHug(parse(ast.rightOperand, options, parse, offsets), [ '+', '-', '*', diff --git a/src/slang-nodes/Block.js b/src/slang-nodes/Block.js index 31c2be88d..fe67af530 100644 --- a/src/slang-nodes/Block.js +++ b/src/slang-nodes/Block.js @@ -1,7 +1,8 @@ export const Block = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, openBrace: ast.openBrace.text, - statements: parse(ast.statements, options, parse), + statements: parse(ast.statements, options, parse, offsets), closeBrace: ast.closeBrace.text }), print: ({ node, path, print }) => [ diff --git a/src/slang-nodes/BreakStatement.js b/src/slang-nodes/BreakStatement.js index 4326e8a1a..7dd8b488d 100644 --- a/src/slang-nodes/BreakStatement.js +++ b/src/slang-nodes/BreakStatement.js @@ -1,5 +1,6 @@ export const BreakStatement = { - parse: ({ ast }) => ({ + parse: ({ node, offsets, ast }) => ({ + ...node, breakKeyword: ast.breakKeyword.text, semicolon: ast.semicolon.text }), diff --git a/src/slang-nodes/CallOptions.js b/src/slang-nodes/CallOptions.js index e62679417..1bdeddb04 100644 --- a/src/slang-nodes/CallOptions.js +++ b/src/slang-nodes/CallOptions.js @@ -1,8 +1,9 @@ import { printSeparatedList } from '../common/printer-helpers.js'; export const CallOptions = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), print: ({ path, print }) => printSeparatedList(path.map(print, 'items')) diff --git a/src/slang-nodes/CallOptionsExpression.js b/src/slang-nodes/CallOptionsExpression.js index f8cf1c9fb..5d2a75fe5 100644 --- a/src/slang-nodes/CallOptionsExpression.js +++ b/src/slang-nodes/CallOptionsExpression.js @@ -1,8 +1,9 @@ export const CallOptionsExpression = { - parse: ({ ast, options, parse }) => ({ - operand: parse(ast.operand, options, parse), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + operand: parse(ast.operand, options, parse, offsets), openBrace: ast.openBrace.text, - options: parse(ast.options, options, parse), + options: parse(ast.options, options, parse, offsets), closeBrace: ast.closeBrace.text }), print: ({ node, path, print }) => [ diff --git a/src/slang-nodes/CatchClause.js b/src/slang-nodes/CatchClause.js index a9583b159..0549a123b 100644 --- a/src/slang-nodes/CatchClause.js +++ b/src/slang-nodes/CatchClause.js @@ -1,8 +1,9 @@ export const CatchClause = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, catchKeyword: ast.catchKeyword.text, - error: ast.error ? parse(ast.error, options, parse) : undefined, - body: parse(ast.body, options, parse) + error: ast.error ? parse(ast.error, options, parse, offsets) : undefined, + body: parse(ast.body, options, parse, offsets) }), print: ({ node, path, print }) => [ node.catchKeyword, diff --git a/src/slang-nodes/CatchClauseError.js b/src/slang-nodes/CatchClauseError.js index 3e4f9f57a..3241a0409 100644 --- a/src/slang-nodes/CatchClauseError.js +++ b/src/slang-nodes/CatchClauseError.js @@ -1,7 +1,8 @@ export const CatchClauseError = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, name: ast.name?.text, - parameters: parse(ast.parameters, options, parse) + parameters: parse(ast.parameters, options, parse, offsets) }), print: ({ node, path, print }) => [ node.name ? node.name : '', diff --git a/src/slang-nodes/CatchClauses.js b/src/slang-nodes/CatchClauses.js index 9d34c16a5..1f26f84d7 100644 --- a/src/slang-nodes/CatchClauses.js +++ b/src/slang-nodes/CatchClauses.js @@ -3,8 +3,9 @@ import { doc } from 'prettier'; const { join } = doc.builders; export const CatchClauses = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ path, print }) => join(' ', path.map(print, 'items')) }; diff --git a/src/slang-nodes/ComparisonExpression.js b/src/slang-nodes/ComparisonExpression.js index fae8601b3..bde9559f6 100644 --- a/src/slang-nodes/ComparisonExpression.js +++ b/src/slang-nodes/ComparisonExpression.js @@ -1,10 +1,11 @@ import { comparisonOperationPrint } from '../common/slang-helpers.js'; export const ComparisonExpression = { - parse: ({ ast, options, parse }) => ({ - leftOperand: parse(ast.leftOperand, options, parse), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + leftOperand: parse(ast.leftOperand, options, parse, offsets), operator: ast.operator.text, - rightOperand: parse(ast.rightOperand, options, parse) + rightOperand: parse(ast.rightOperand, options, parse, offsets) }), print: comparisonOperationPrint }; diff --git a/src/slang-nodes/ConditionalExpression.js b/src/slang-nodes/ConditionalExpression.js index 63ba28de2..89299805d 100644 --- a/src/slang-nodes/ConditionalExpression.js +++ b/src/slang-nodes/ConditionalExpression.js @@ -87,8 +87,8 @@ const traditionalTernaries = (node, path, print) => ]); export const ConditionalExpression = { - parse: ({ ast, options, parse }) => { - let operand = parse(ast.operand, options, parse); + parse: ({ node, offsets, ast, options, parse }) => { + let operand = parse(ast.operand, options, parse, offsets); // TODO: while the behaviour is not stable, it should be behind the // experimentalTernaries flag. @@ -106,11 +106,12 @@ export const ConditionalExpression = { } return { + ...node, operand, questionMark: ast.questionMark.text, - trueExpression: parse(ast.trueExpression, options, parse), + trueExpression: parse(ast.trueExpression, options, parse, offsets), colon: ast.colon.text, - falseExpression: parse(ast.falseExpression, options, parse) + falseExpression: parse(ast.falseExpression, options, parse, offsets) }; }, print: ({ node, path, print, options }) => diff --git a/src/slang-nodes/ConstantDefinition.js b/src/slang-nodes/ConstantDefinition.js index b2b523945..1e35f145a 100644 --- a/src/slang-nodes/ConstantDefinition.js +++ b/src/slang-nodes/ConstantDefinition.js @@ -1,10 +1,11 @@ export const ConstantDefinition = { - parse: ({ ast, options, parse }) => ({ - typeName: parse(ast.typeName, options, parse), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + typeName: parse(ast.typeName, options, parse, offsets), constantKeyword: ast.constantKeyword.text, name: ast.name.text, equal: ast.equal.text, - value: parse(ast.value, options, parse), + value: parse(ast.value, options, parse, offsets), semicolon: ast.semicolon.text }), // TODO: implement print diff --git a/src/slang-nodes/ConstructorAttribute.js b/src/slang-nodes/ConstructorAttribute.js index 6a5a4482d..60c3270b0 100644 --- a/src/slang-nodes/ConstructorAttribute.js +++ b/src/slang-nodes/ConstructorAttribute.js @@ -1,9 +1,10 @@ export const ConstructorAttribute = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, variant: ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, options, parse) + : parse(ast.variant, options, parse, offsets) }), print: ({ node, path, print }) => typeof node.variant === 'string' diff --git a/src/slang-nodes/ConstructorAttributes.js b/src/slang-nodes/ConstructorAttributes.js index b27d72996..dd64cc6f9 100644 --- a/src/slang-nodes/ConstructorAttributes.js +++ b/src/slang-nodes/ConstructorAttributes.js @@ -3,8 +3,9 @@ import { doc } from 'prettier'; const { line } = doc.builders; export const ConstructorAttributes = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ path, print }) => path.map(print, 'items').map((item) => [line, item]) diff --git a/src/slang-nodes/ConstructorDefinition.js b/src/slang-nodes/ConstructorDefinition.js index 0d2543e20..b92430ea9 100644 --- a/src/slang-nodes/ConstructorDefinition.js +++ b/src/slang-nodes/ConstructorDefinition.js @@ -1,11 +1,12 @@ import { printFunction } from '../common/slang-helpers.js'; export const ConstructorDefinition = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, constructorKeyword: ast.constructorKeyword.text, - parameters: parse(ast.parameters, options, parse), - attributes: parse(ast.attributes, options, parse), - body: parse(ast.body, options, parse) + parameters: parse(ast.parameters, options, parse, offsets), + attributes: parse(ast.attributes, options, parse, offsets), + body: parse(ast.body, options, parse, offsets) }), print: ({ node, path, print }) => printFunction(node.constructorKeyword, node, path, print) diff --git a/src/slang-nodes/ContinueStatement.js b/src/slang-nodes/ContinueStatement.js index 760347a99..c2c69480a 100644 --- a/src/slang-nodes/ContinueStatement.js +++ b/src/slang-nodes/ContinueStatement.js @@ -1,5 +1,6 @@ export const ContinueStatement = { - parse: ({ ast }) => ({ + parse: ({ node, offsets, ast }) => ({ + ...node, continueKeyword: ast.continueKeyword.text, semicolon: ast.semicolon.text }), diff --git a/src/slang-nodes/ContractDefinition.js b/src/slang-nodes/ContractDefinition.js index 7d957d560..d4f36f26f 100644 --- a/src/slang-nodes/ContractDefinition.js +++ b/src/slang-nodes/ContractDefinition.js @@ -3,15 +3,16 @@ import { doc } from 'prettier'; const { group, line } = doc.builders; export const ContractDefinition = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, abstractKeyword: ast.abstractKeyword?.text, contractKeyword: ast.contractKeyword.text, name: ast.name.text, inheritance: ast.inheritance - ? parse(ast.inheritance, options, parse) + ? parse(ast.inheritance, options, parse, offsets) : undefined, openBrace: ast.openBrace.text, - members: parse(ast.members, options, parse), + members: parse(ast.members, options, parse, offsets), closeBrace: ast.closeBrace.text }), print: ({ node, path, print }) => [ diff --git a/src/slang-nodes/ContractMember.js b/src/slang-nodes/ContractMember.js index 8180d3f15..12950c3b5 100644 --- a/src/slang-nodes/ContractMember.js +++ b/src/slang-nodes/ContractMember.js @@ -1,6 +1,7 @@ export const ContractMember = { - parse: ({ ast, options, parse }) => ({ - variant: parse(ast.variant, options, parse) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + variant: parse(ast.variant, options, parse, offsets) }), print: ({ path, print }) => path.call(print, 'variant') }; diff --git a/src/slang-nodes/ContractMembers.js b/src/slang-nodes/ContractMembers.js index dc881958a..34a89db8e 100644 --- a/src/slang-nodes/ContractMembers.js +++ b/src/slang-nodes/ContractMembers.js @@ -1,14 +1,13 @@ import { doc } from 'prettier'; -import { - printPreservingEmptyLines, - printSeparatedItem -} from '../common/printer-helpers.js'; +import { printSeparatedItem } from '../common/printer-helpers.js'; +import { printPreservingEmptyLines } from '../common/slang-helpers.js'; const { hardline } = doc.builders; export const ContractMembers = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ node, options, path, print }) => node.items.length > 0 diff --git a/src/slang-nodes/DecimalNumberExpression.js b/src/slang-nodes/DecimalNumberExpression.js index d7fdf947f..fb523b9a4 100644 --- a/src/slang-nodes/DecimalNumberExpression.js +++ b/src/slang-nodes/DecimalNumberExpression.js @@ -1,7 +1,8 @@ export const DecimalNumberExpression = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, literal: ast.literal.text, - unit: ast.unit ? parse(ast.unit, options, parse) : undefined + unit: ast.unit ? parse(ast.unit, options, parse, offsets) : undefined }), print: ({ node, path, print }) => [ node.literal, diff --git a/src/slang-nodes/DoWhileStatement.js b/src/slang-nodes/DoWhileStatement.js index 2558b746c..4b765c975 100644 --- a/src/slang-nodes/DoWhileStatement.js +++ b/src/slang-nodes/DoWhileStatement.js @@ -9,12 +9,13 @@ const printBody = (node, path, print) => : group([indent([line, path.call(print, 'body')]), line]); export const DoWhileStatement = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, doKeyword: ast.doKeyword.text, - body: parse(ast.body, options, parse), + body: parse(ast.body, options, parse, offsets), whileKeyword: ast.whileKeyword.text, openParen: ast.openParen.text, - condition: parse(ast.condition, options, parse), + condition: parse(ast.condition, options, parse, offsets), closeParen: ast.closeParen.text, semicolon: ast.semicolon.text }), diff --git a/src/slang-nodes/ElementaryType.js b/src/slang-nodes/ElementaryType.js index dd35918a4..8659967fc 100644 --- a/src/slang-nodes/ElementaryType.js +++ b/src/slang-nodes/ElementaryType.js @@ -1,9 +1,10 @@ export const ElementaryType = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, variant: ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, options, parse) + : parse(ast.variant, options, parse, offsets) }), print: ({ node, path, print }) => typeof node.variant === 'string' diff --git a/src/slang-nodes/ElseBranch.js b/src/slang-nodes/ElseBranch.js index 7b9451f2f..8579adddf 100644 --- a/src/slang-nodes/ElseBranch.js +++ b/src/slang-nodes/ElseBranch.js @@ -8,9 +8,10 @@ const printBody = (bodyVariantKind, path, print) => : group(indent([line, path.call(print, 'body')])); export const ElseBranch = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, elseKeyword: ast.elseKeyword.text, - body: parse(ast.body, options, parse) + body: parse(ast.body, options, parse, offsets) }), print: ({ node, path, print }) => [ node.elseKeyword, diff --git a/src/slang-nodes/EmitStatement.js b/src/slang-nodes/EmitStatement.js index 195176aed..8f2c6d664 100644 --- a/src/slang-nodes/EmitStatement.js +++ b/src/slang-nodes/EmitStatement.js @@ -1,8 +1,9 @@ export const EmitStatement = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, emitKeyword: ast.emitKeyword.text, - event: parse(ast.event, options, parse), - arguments: parse(ast.arguments, options, parse), + event: parse(ast.event, options, parse, offsets), + arguments: parse(ast.arguments, options, parse, offsets), semicolon: ast.semicolon.text }), print: ({ node, path, print }) => [ diff --git a/src/slang-nodes/EnumDefinition.js b/src/slang-nodes/EnumDefinition.js index 6b0563156..fe46abbd6 100644 --- a/src/slang-nodes/EnumDefinition.js +++ b/src/slang-nodes/EnumDefinition.js @@ -1,9 +1,10 @@ export const EnumDefinition = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, enumKeyword: ast.enumKeyword.text, name: ast.name.text, openBrace: ast.openBrace.text, - members: parse(ast.members, options, parse), + members: parse(ast.members, options, parse, offsets), closeBrace: ast.closeBrace.text }), print: ({ node, path, print }) => [ diff --git a/src/slang-nodes/EnumMembers.js b/src/slang-nodes/EnumMembers.js index a741876bb..473a0afec 100644 --- a/src/slang-nodes/EnumMembers.js +++ b/src/slang-nodes/EnumMembers.js @@ -4,7 +4,8 @@ import { printSeparatedList } from '../common/printer-helpers.js'; const { hardline } = doc.builders; export const EnumMembers = { - parse: ({ ast }) => ({ + parse: ({ node, offsets, ast }) => ({ + ...node, items: ast.items.map((item) => item.text), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/EqualityExpression.js b/src/slang-nodes/EqualityExpression.js index ac47ea857..d5b5fbd41 100644 --- a/src/slang-nodes/EqualityExpression.js +++ b/src/slang-nodes/EqualityExpression.js @@ -1,10 +1,11 @@ import { comparisonOperationPrint } from '../common/slang-helpers.js'; export const EqualityExpression = { - parse: ({ ast, options, parse }) => ({ - leftOperand: parse(ast.leftOperand, options, parse), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + leftOperand: parse(ast.leftOperand, options, parse, offsets), operator: ast.operator.text, - rightOperand: parse(ast.rightOperand, options, parse) + rightOperand: parse(ast.rightOperand, options, parse, offsets) }), print: comparisonOperationPrint }; diff --git a/src/slang-nodes/ErrorDefinition.js b/src/slang-nodes/ErrorDefinition.js index ac8487cc5..06a1e8d9c 100644 --- a/src/slang-nodes/ErrorDefinition.js +++ b/src/slang-nodes/ErrorDefinition.js @@ -1,8 +1,9 @@ export const ErrorDefinition = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, errorKeyword: ast.errorKeyword.text, name: ast.name.text, - members: parse(ast.members, options, parse), + members: parse(ast.members, options, parse, offsets), semicolon: ast.semicolon.text }), print: ({ node, path, print }) => [ diff --git a/src/slang-nodes/ErrorParameter.js b/src/slang-nodes/ErrorParameter.js index 8ca417e94..fa3fcb60e 100644 --- a/src/slang-nodes/ErrorParameter.js +++ b/src/slang-nodes/ErrorParameter.js @@ -1,6 +1,7 @@ export const ErrorParameter = { - parse: ({ ast, options, parse }) => ({ - typeName: parse(ast.typeName, options, parse), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + typeName: parse(ast.typeName, options, parse, offsets), name: ast.name?.text }), print: ({ node, path, print }) => [ diff --git a/src/slang-nodes/ErrorParameters.js b/src/slang-nodes/ErrorParameters.js index c8316ea31..a480f4c46 100644 --- a/src/slang-nodes/ErrorParameters.js +++ b/src/slang-nodes/ErrorParameters.js @@ -1,8 +1,9 @@ import { printSeparatedList } from '../common/printer-helpers.js'; export const ErrorParameters = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), print: ({ node, path, print }) => diff --git a/src/slang-nodes/ErrorParametersDeclaration.js b/src/slang-nodes/ErrorParametersDeclaration.js index f76755a55..c3011b9a6 100644 --- a/src/slang-nodes/ErrorParametersDeclaration.js +++ b/src/slang-nodes/ErrorParametersDeclaration.js @@ -1,7 +1,8 @@ export const ErrorParametersDeclaration = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, openParen: ast.openParen.text, - parameters: parse(ast.parameters, options, parse), + parameters: parse(ast.parameters, options, parse, offsets), closeParen: ast.closeParen.text }), print: ({ node, path, print }) => [ diff --git a/src/slang-nodes/EventDefinition.js b/src/slang-nodes/EventDefinition.js index c381d587d..5903ade78 100644 --- a/src/slang-nodes/EventDefinition.js +++ b/src/slang-nodes/EventDefinition.js @@ -1,8 +1,9 @@ export const EventDefinition = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, eventKeyword: ast.eventKeyword.text, name: ast.name.text, - parameters: parse(ast.parameters, options, parse), + parameters: parse(ast.parameters, options, parse, offsets), anonymousKeyword: ast.anonymousKeyword?.text, semicolon: ast.semicolon.text }), diff --git a/src/slang-nodes/EventParameter.js b/src/slang-nodes/EventParameter.js index 7cea70fe3..31516c309 100644 --- a/src/slang-nodes/EventParameter.js +++ b/src/slang-nodes/EventParameter.js @@ -1,6 +1,7 @@ export const EventParameter = { - parse: ({ ast, options, parse }) => ({ - typeName: parse(ast.typeName, options, parse), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + typeName: parse(ast.typeName, options, parse, offsets), indexedKeyword: ast.indexedKeyword?.text, name: ast.name?.text }), diff --git a/src/slang-nodes/EventParameters.js b/src/slang-nodes/EventParameters.js index 0222138bf..0489e2ddb 100644 --- a/src/slang-nodes/EventParameters.js +++ b/src/slang-nodes/EventParameters.js @@ -1,8 +1,9 @@ import { printSeparatedList } from '../common/printer-helpers.js'; export const EventParameters = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), print: ({ node, path, print }) => diff --git a/src/slang-nodes/EventParametersDeclaration.js b/src/slang-nodes/EventParametersDeclaration.js index 1c47a0434..b60ce01b9 100644 --- a/src/slang-nodes/EventParametersDeclaration.js +++ b/src/slang-nodes/EventParametersDeclaration.js @@ -1,7 +1,8 @@ export const EventParametersDeclaration = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, openParen: ast.openParen.text, - parameters: parse(ast.parameters, options, parse), + parameters: parse(ast.parameters, options, parse, offsets), closeParen: ast.closeParen.text }), print: ({ node, path, print }) => [ diff --git a/src/slang-nodes/ExperimentalFeature.js b/src/slang-nodes/ExperimentalFeature.js index f1b61b6ec..330c455a7 100644 --- a/src/slang-nodes/ExperimentalFeature.js +++ b/src/slang-nodes/ExperimentalFeature.js @@ -1,9 +1,10 @@ export const ExperimentalFeature = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, variant: ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, options, parse) + : parse(ast.variant, options, parse, offsets) }), print: ({ node, path, print }) => typeof node.variant === 'string' diff --git a/src/slang-nodes/ExperimentalPragma.js b/src/slang-nodes/ExperimentalPragma.js index f2e9a7af4..3f041b887 100644 --- a/src/slang-nodes/ExperimentalPragma.js +++ b/src/slang-nodes/ExperimentalPragma.js @@ -1,7 +1,8 @@ export const ExperimentalPragma = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, experimentalKeyword: ast.experimentalKeyword.text, - feature: parse(ast.feature, options, parse) + feature: parse(ast.feature, options, parse, offsets) }), print: ({ node, path, print }) => [ `${node.experimentalKeyword} `, diff --git a/src/slang-nodes/ExponentiationExpression.js b/src/slang-nodes/ExponentiationExpression.js index da1347177..0b74b6403 100644 --- a/src/slang-nodes/ExponentiationExpression.js +++ b/src/slang-nodes/ExponentiationExpression.js @@ -6,10 +6,10 @@ import { rightOperandPrint, tryHug } from '../common/slang-helpers.js'; const { group, indent } = doc.builders; export const ExponentiationExpression = { - parse: ({ ast, options, parse }) => { + parse: ({ node, offsets, ast, options, parse }) => { const compiler = coerce(options.compiler); - let leftOperand = parse(ast.leftOperand, options, parse); - let rightOperand = parse(ast.rightOperand, options, parse); + let leftOperand = parse(ast.leftOperand, options, parse, offsets); + let rightOperand = parse(ast.rightOperand, options, parse, offsets); if (compiler) { if (satisfies(compiler, '>=0.8.0')) { @@ -19,6 +19,7 @@ export const ExponentiationExpression = { } } return { + ...node, leftOperand, operator: ast.operator.text, rightOperand diff --git a/src/slang-nodes/Expression.js b/src/slang-nodes/Expression.js index 7174f98e2..fc6f15d42 100644 --- a/src/slang-nodes/Expression.js +++ b/src/slang-nodes/Expression.js @@ -1,9 +1,10 @@ export const Expression = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, variant: ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, options, parse) + : parse(ast.variant, options, parse, offsets) }), print: ({ node, path, print }) => typeof node.variant === 'string' diff --git a/src/slang-nodes/ExpressionStatement.js b/src/slang-nodes/ExpressionStatement.js index 10db79262..843197ca0 100644 --- a/src/slang-nodes/ExpressionStatement.js +++ b/src/slang-nodes/ExpressionStatement.js @@ -1,6 +1,7 @@ export const ExpressionStatement = { - parse: ({ ast, options, parse }) => ({ - expression: parse(ast.expression, options, parse), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + expression: parse(ast.expression, options, parse, offsets), semicolon: ast.semicolon.text }), print: ({ node, path, print }) => [ diff --git a/src/slang-nodes/FallbackFunctionAttribute.js b/src/slang-nodes/FallbackFunctionAttribute.js index 9154f3bb1..b6978ccd0 100644 --- a/src/slang-nodes/FallbackFunctionAttribute.js +++ b/src/slang-nodes/FallbackFunctionAttribute.js @@ -1,9 +1,10 @@ export const FallbackFunctionAttribute = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, variant: ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, options, parse) + : parse(ast.variant, options, parse, offsets) }), print: ({ node, path, print }) => typeof node.variant === 'string' diff --git a/src/slang-nodes/FallbackFunctionAttributes.js b/src/slang-nodes/FallbackFunctionAttributes.js index a347b46ad..142bc757f 100644 --- a/src/slang-nodes/FallbackFunctionAttributes.js +++ b/src/slang-nodes/FallbackFunctionAttributes.js @@ -3,8 +3,9 @@ import { doc } from 'prettier'; const { line } = doc.builders; export const FallbackFunctionAttributes = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ path, print }) => path.map(print, 'items').map((item) => [line, item]) diff --git a/src/slang-nodes/FallbackFunctionDefinition.js b/src/slang-nodes/FallbackFunctionDefinition.js index 043fabc34..9aa6b4108 100644 --- a/src/slang-nodes/FallbackFunctionDefinition.js +++ b/src/slang-nodes/FallbackFunctionDefinition.js @@ -1,12 +1,15 @@ import { printFunction } from '../common/slang-helpers.js'; export const FallbackFunctionDefinition = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, fallbackKeyword: ast.fallbackKeyword.text, - parameters: parse(ast.parameters, options, parse), - attributes: parse(ast.attributes, options, parse), - returns: ast.returns ? parse(ast.returns, options, parse) : undefined, - body: parse(ast.body, options, parse) + parameters: parse(ast.parameters, options, parse, offsets), + attributes: parse(ast.attributes, options, parse, offsets), + returns: ast.returns + ? parse(ast.returns, options, parse, offsets) + : undefined, + body: parse(ast.body, options, parse, offsets) }), print: ({ node, path, print }) => printFunction(node.fallbackKeyword, node, path, print) diff --git a/src/slang-nodes/ForStatement.js b/src/slang-nodes/ForStatement.js index 6dc9b9877..f8c72a648 100644 --- a/src/slang-nodes/ForStatement.js +++ b/src/slang-nodes/ForStatement.js @@ -4,14 +4,17 @@ import { printSeparatedList } from '../common/printer-helpers.js'; const { group, indent, line } = doc.builders; export const ForStatement = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, forKeyword: ast.forKeyword.text, openParen: ast.openParen.text, - initialization: parse(ast.initialization, options, parse), - condition: parse(ast.condition, options, parse), - iterator: ast.iterator ? parse(ast.iterator, options, parse) : undefined, + initialization: parse(ast.initialization, options, parse, offsets), + condition: parse(ast.condition, options, parse, offsets), + iterator: ast.iterator + ? parse(ast.iterator, options, parse, offsets) + : undefined, closeParen: ast.closeParen.text, - body: parse(ast.body, options, parse) + body: parse(ast.body, options, parse, offsets) }), print: ({ node, path, print }) => { const initialization = path.call(print, 'initialization'); diff --git a/src/slang-nodes/ForStatementCondition.js b/src/slang-nodes/ForStatementCondition.js index 4520890fe..98ab18436 100644 --- a/src/slang-nodes/ForStatementCondition.js +++ b/src/slang-nodes/ForStatementCondition.js @@ -1,9 +1,10 @@ export const ForStatementCondition = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, variant: ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, options, parse) + : parse(ast.variant, options, parse, offsets) }), print: ({ node, path, print }) => typeof node.variant === 'string' diff --git a/src/slang-nodes/ForStatementInitialization.js b/src/slang-nodes/ForStatementInitialization.js index 35eab7491..554963166 100644 --- a/src/slang-nodes/ForStatementInitialization.js +++ b/src/slang-nodes/ForStatementInitialization.js @@ -1,9 +1,10 @@ export const ForStatementInitialization = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, variant: ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, options, parse) + : parse(ast.variant, options, parse, offsets) }), print: ({ node, path, print }) => typeof node.variant === 'string' diff --git a/src/slang-nodes/FunctionAttribute.js b/src/slang-nodes/FunctionAttribute.js index dcdcfa885..15c6caadc 100644 --- a/src/slang-nodes/FunctionAttribute.js +++ b/src/slang-nodes/FunctionAttribute.js @@ -1,9 +1,10 @@ export const FunctionAttribute = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, variant: ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, options, parse) + : parse(ast.variant, options, parse, offsets) }), print: ({ node, path, print }) => typeof node.variant === 'string' diff --git a/src/slang-nodes/FunctionAttributes.js b/src/slang-nodes/FunctionAttributes.js index b1a2a1015..56a92c0d4 100644 --- a/src/slang-nodes/FunctionAttributes.js +++ b/src/slang-nodes/FunctionAttributes.js @@ -3,8 +3,9 @@ import { doc } from 'prettier'; const { line } = doc.builders; export const FunctionAttributes = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ path, print }) => path.map(print, 'items').map((item) => [line, item]) diff --git a/src/slang-nodes/FunctionBody.js b/src/slang-nodes/FunctionBody.js index cb9f8f8ed..3eb2b0198 100644 --- a/src/slang-nodes/FunctionBody.js +++ b/src/slang-nodes/FunctionBody.js @@ -1,9 +1,10 @@ export const FunctionBody = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, variant: ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, options, parse) + : parse(ast.variant, options, parse, offsets) }), print: ({ node, path, print }) => typeof node.variant === 'string' diff --git a/src/slang-nodes/FunctionCallExpression.js b/src/slang-nodes/FunctionCallExpression.js index a84f17266..b43208b25 100644 --- a/src/slang-nodes/FunctionCallExpression.js +++ b/src/slang-nodes/FunctionCallExpression.js @@ -4,10 +4,12 @@ import { isLabel } from '../common/util.js'; const { group, indentIfBreak, label } = doc.builders; let groupIndex = 0; + export const FunctionCallExpression = { - parse: ({ ast, options, parse }) => ({ - operand: parse(ast.operand, options, parse), - arguments: parse(ast.arguments, options, parse) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + operand: parse(ast.operand, options, parse, offsets), + arguments: parse(ast.arguments, options, parse, offsets) }), print: ({ path, print }) => { let operandDoc = path.call(print, 'operand'); diff --git a/src/slang-nodes/FunctionDefinition.js b/src/slang-nodes/FunctionDefinition.js index 5dd54725f..a77ff08db 100644 --- a/src/slang-nodes/FunctionDefinition.js +++ b/src/slang-nodes/FunctionDefinition.js @@ -1,15 +1,17 @@ import { printFunction } from '../common/slang-helpers.js'; export const FunctionDefinition = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, functionKeyword: ast.functionKeyword.text, - name: parse(ast.name, options, parse), - parameters: parse(ast.parameters, options, parse), - attributes: parse(ast.attributes, options, parse), - returns: ast.returns ? parse(ast.returns, options, parse) : undefined, - body: parse(ast.body, options, parse) + name: parse(ast.name, options, parse, offsets), + parameters: parse(ast.parameters, options, parse, offsets), + attributes: parse(ast.attributes, options, parse, offsets), + returns: ast.returns + ? parse(ast.returns, options, parse, offsets) + : undefined, + body: parse(ast.body, options, parse, offsets) }), - print: ({ node, path, print }) => printFunction( [`${node.functionKeyword} `, path.call(print, 'name')], diff --git a/src/slang-nodes/FunctionName.js b/src/slang-nodes/FunctionName.js index 5cb2e0579..89442e90e 100644 --- a/src/slang-nodes/FunctionName.js +++ b/src/slang-nodes/FunctionName.js @@ -1,5 +1,6 @@ export const FunctionName = { - parse: ({ ast }) => ({ + parse: ({ node, offsets, ast }) => ({ + ...node, variant: ast.variant.text }), print: ({ node }) => node.variant diff --git a/src/slang-nodes/FunctionType.js b/src/slang-nodes/FunctionType.js index e6af8fdca..9cadcdc38 100644 --- a/src/slang-nodes/FunctionType.js +++ b/src/slang-nodes/FunctionType.js @@ -1,11 +1,14 @@ import { printFunction } from '../common/slang-helpers.js'; export const FunctionType = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, functionKeyword: ast.functionKeyword.text, - parameters: parse(ast.parameters, options, parse), - attributes: parse(ast.attributes, options, parse), - returns: ast.returns ? parse(ast.returns, options, parse) : undefined + parameters: parse(ast.parameters, options, parse, offsets), + attributes: parse(ast.attributes, options, parse, offsets), + returns: ast.returns + ? parse(ast.returns, options, parse, offsets) + : undefined }), print: ({ node, path, print }) => printFunction(`${node.functionKeyword} `, node, path, print) diff --git a/src/slang-nodes/FunctionTypeAttribute.js b/src/slang-nodes/FunctionTypeAttribute.js index 5cda4b957..07e6df457 100644 --- a/src/slang-nodes/FunctionTypeAttribute.js +++ b/src/slang-nodes/FunctionTypeAttribute.js @@ -1,5 +1,6 @@ export const FunctionTypeAttribute = { - parse: ({ ast }) => ({ + parse: ({ node, offsets, ast }) => ({ + ...node, variant: ast.variant.text }), print: ({ node }) => node.variant diff --git a/src/slang-nodes/FunctionTypeAttributes.js b/src/slang-nodes/FunctionTypeAttributes.js index a15184ae1..c06b82701 100644 --- a/src/slang-nodes/FunctionTypeAttributes.js +++ b/src/slang-nodes/FunctionTypeAttributes.js @@ -3,8 +3,9 @@ import { doc } from 'prettier'; const { line } = doc.builders; export const FunctionTypeAttributes = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ path, print }) => path.map(print, 'items').map((item) => [line, item]) diff --git a/src/slang-nodes/HexNumberExpression.js b/src/slang-nodes/HexNumberExpression.js index b3e10a550..09abce561 100644 --- a/src/slang-nodes/HexNumberExpression.js +++ b/src/slang-nodes/HexNumberExpression.js @@ -1,7 +1,8 @@ export const HexNumberExpression = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, literal: ast.literal.text, - unit: ast.unit ? parse(ast.unit, options, parse) : undefined + unit: ast.unit ? parse(ast.unit, options, parse, offsets) : undefined }), print: ({ node, path, print }) => [ node.literal, diff --git a/src/slang-nodes/HexStringLiteral.js b/src/slang-nodes/HexStringLiteral.js index b16f31f2b..d97a82caf 100644 --- a/src/slang-nodes/HexStringLiteral.js +++ b/src/slang-nodes/HexStringLiteral.js @@ -1,7 +1,8 @@ import { printString } from '../common/util.js'; export const HexStringLiteral = { - parse: ({ ast, options }) => ({ + parse: ({ node, offsets, ast, options }) => ({ + ...node, variant: `hex${printString(ast.variant.text.slice(4, -1), options)}` }), print: ({ node }) => node.variant diff --git a/src/slang-nodes/HexStringLiterals.js b/src/slang-nodes/HexStringLiterals.js index 5edf0f83d..fe6e6fd71 100644 --- a/src/slang-nodes/HexStringLiterals.js +++ b/src/slang-nodes/HexStringLiterals.js @@ -3,8 +3,9 @@ import { doc } from 'prettier'; const { join, hardline } = doc.builders; export const HexStringLiterals = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ path, print }) => join(hardline, path.map(print, 'items')) }; diff --git a/src/slang-nodes/IdentifierPath.js b/src/slang-nodes/IdentifierPath.js index 4b8dfb60d..92b16b7f5 100644 --- a/src/slang-nodes/IdentifierPath.js +++ b/src/slang-nodes/IdentifierPath.js @@ -1,5 +1,6 @@ export const IdentifierPath = { - parse: ({ ast }) => ({ + parse: ({ node, offsets, ast }) => ({ + ...node, items: ast.items.map((item) => item.text), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/IfStatement.js b/src/slang-nodes/IfStatement.js index 25bbbc3c5..c276b6828 100644 --- a/src/slang-nodes/IfStatement.js +++ b/src/slang-nodes/IfStatement.js @@ -11,14 +11,15 @@ const printBody = (bodyVariantKind, path, print) => }); export const IfStatement = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, ifKeyword: ast.ifKeyword.text, openParen: ast.openParen.text, - condition: parse(ast.condition, options, parse), + condition: parse(ast.condition, options, parse, offsets), closeParen: ast.closeParen.text, - body: parse(ast.body, options, parse), + body: parse(ast.body, options, parse, offsets), elseBranch: ast.elseBranch - ? parse(ast.elseBranch, options, parse) + ? parse(ast.elseBranch, options, parse, offsets) : undefined }), print: ({ node, path, print }) => { diff --git a/src/slang-nodes/ImportAlias.js b/src/slang-nodes/ImportAlias.js index 088d8cec9..a87fc63e3 100644 --- a/src/slang-nodes/ImportAlias.js +++ b/src/slang-nodes/ImportAlias.js @@ -1,5 +1,6 @@ export const ImportAlias = { - parse: ({ ast }) => ({ + parse: ({ node, offsets, ast }) => ({ + ...node, asKeyword: ast.asKeyword.text, identifier: ast.identifier.text }), diff --git a/src/slang-nodes/ImportClause.js b/src/slang-nodes/ImportClause.js index 8e652223d..5f98954d5 100644 --- a/src/slang-nodes/ImportClause.js +++ b/src/slang-nodes/ImportClause.js @@ -1,6 +1,7 @@ export const ImportClause = { - parse: ({ ast, options, parse }) => ({ - variant: parse(ast.variant, options, parse) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + variant: parse(ast.variant, options, parse, offsets) }), print: ({ path, print }) => path.call(print, 'variant') }; diff --git a/src/slang-nodes/ImportDeconstruction.js b/src/slang-nodes/ImportDeconstruction.js index c38eee3e3..2f3b19da4 100644 --- a/src/slang-nodes/ImportDeconstruction.js +++ b/src/slang-nodes/ImportDeconstruction.js @@ -1,10 +1,11 @@ export const ImportDeconstruction = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, openBrace: ast.openBrace.text, - symbols: parse(ast.symbols, options, parse), + symbols: parse(ast.symbols, options, parse, offsets), closeBrace: ast.closeBrace.text, fromKeyword: ast.fromKeyword.text, - path: parse(ast.path, options, parse) + path: parse(ast.path, options, parse, offsets) }), print: ({ node, path, print }) => [ node.openBrace, diff --git a/src/slang-nodes/ImportDeconstructionSymbol.js b/src/slang-nodes/ImportDeconstructionSymbol.js index 3eb05baa4..a47aed9b2 100644 --- a/src/slang-nodes/ImportDeconstructionSymbol.js +++ b/src/slang-nodes/ImportDeconstructionSymbol.js @@ -1,7 +1,8 @@ export const ImportDeconstructionSymbol = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, name: ast.name.text, - alias: ast.alias ? parse(ast.alias, options, parse) : undefined + alias: ast.alias ? parse(ast.alias, options, parse, offsets) : undefined }), print: ({ node, path, print }) => [ node.name, diff --git a/src/slang-nodes/ImportDeconstructionSymbols.js b/src/slang-nodes/ImportDeconstructionSymbols.js index c33c0d39d..79d3b43ab 100644 --- a/src/slang-nodes/ImportDeconstructionSymbols.js +++ b/src/slang-nodes/ImportDeconstructionSymbols.js @@ -6,8 +6,9 @@ import { printSeparatedList } from '../common/printer-helpers.js'; const { line, softline } = doc.builders; export const ImportDeconstructionSymbols = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), print: ({ path, print, options }) => { diff --git a/src/slang-nodes/ImportDirective.js b/src/slang-nodes/ImportDirective.js index b859ceab1..a17e36282 100644 --- a/src/slang-nodes/ImportDirective.js +++ b/src/slang-nodes/ImportDirective.js @@ -1,7 +1,8 @@ export const ImportDirective = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, importKeyword: ast.importKeyword.text, - clause: parse(ast.clause, options, parse), + clause: parse(ast.clause, options, parse, offsets), semicolon: ast.semicolon.text }), print: ({ node, path, print }) => [ diff --git a/src/slang-nodes/IndexAccessEnd.js b/src/slang-nodes/IndexAccessEnd.js index 6e1472f06..48f8a66ce 100644 --- a/src/slang-nodes/IndexAccessEnd.js +++ b/src/slang-nodes/IndexAccessEnd.js @@ -1,7 +1,8 @@ export const IndexAccessEnd = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, colon: ast.colon.text, - end: ast.end ? parse(ast.end, options, parse) : undefined + end: ast.end ? parse(ast.end, options, parse, offsets) : undefined }), print: ({ node, path, print }) => [ node.colon, diff --git a/src/slang-nodes/IndexAccessExpression.js b/src/slang-nodes/IndexAccessExpression.js index a2d0f00f9..1e6c6aa1b 100644 --- a/src/slang-nodes/IndexAccessExpression.js +++ b/src/slang-nodes/IndexAccessExpression.js @@ -4,12 +4,14 @@ import { isLabel } from '../common/util.js'; const { group, indent, indentIfBreak, label, softline } = doc.builders; let groupIndex = 0; + export const IndexAccessExpression = { - parse: ({ ast, options, parse }) => ({ - operand: parse(ast.operand, options, parse), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + operand: parse(ast.operand, options, parse, offsets), openBracket: ast.openBracket.text, - start: ast.start ? parse(ast.start, options, parse) : undefined, - end: ast.end ? parse(ast.end, options, parse) : undefined, + start: ast.start ? parse(ast.start, options, parse, offsets) : undefined, + end: ast.end ? parse(ast.end, options, parse, offsets) : undefined, closeBracket: ast.closeBracket.text }), print: ({ node, path, print }) => { diff --git a/src/slang-nodes/InheritanceSpecifier.js b/src/slang-nodes/InheritanceSpecifier.js index 5afe3f709..1f8a85384 100644 --- a/src/slang-nodes/InheritanceSpecifier.js +++ b/src/slang-nodes/InheritanceSpecifier.js @@ -1,7 +1,8 @@ export const InheritanceSpecifier = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, isKeyword: ast.isKeyword.text, - types: parse(ast.types, options, parse) + types: parse(ast.types, options, parse, offsets) }), print: ({ node, path, print }) => [ ` ${node.isKeyword}`, diff --git a/src/slang-nodes/InheritanceType.js b/src/slang-nodes/InheritanceType.js index d0442ee07..c8db7bd45 100644 --- a/src/slang-nodes/InheritanceType.js +++ b/src/slang-nodes/InheritanceType.js @@ -1,7 +1,10 @@ export const InheritanceType = { - parse: ({ ast, options, parse }) => ({ - typeName: parse(ast.typeName, options, parse), - arguments: ast.arguments ? parse(ast.arguments, options, parse) : undefined + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + typeName: parse(ast.typeName, options, parse, offsets), + arguments: ast.arguments + ? parse(ast.arguments, options, parse, offsets) + : undefined }), print: ({ node, path, print }) => [ path.call(print, 'typeName'), diff --git a/src/slang-nodes/InheritanceTypes.js b/src/slang-nodes/InheritanceTypes.js index 53ed26e4e..ff35dd632 100644 --- a/src/slang-nodes/InheritanceTypes.js +++ b/src/slang-nodes/InheritanceTypes.js @@ -2,9 +2,11 @@ import { doc } from 'prettier'; import { printSeparatedList } from '../common/printer-helpers.js'; const { line } = doc.builders; + export const InheritanceTypes = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), print: ({ path, print }) => diff --git a/src/slang-nodes/InterfaceDefinition.js b/src/slang-nodes/InterfaceDefinition.js index 5dacfbf03..7988bb49d 100644 --- a/src/slang-nodes/InterfaceDefinition.js +++ b/src/slang-nodes/InterfaceDefinition.js @@ -3,14 +3,15 @@ import { doc } from 'prettier'; const { group, line } = doc.builders; export const InterfaceDefinition = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, interfaceKeyword: ast.interfaceKeyword.text, name: ast.name.text, inheritance: ast.inheritence - ? parse(ast.inheritance, options, parse) + ? parse(ast.inheritance, options, parse, offsets) : undefined, openBrace: ast.openBrace.text, - members: parse(ast.members, options, parse), + members: parse(ast.members, options, parse, offsets), closeBrace: ast.closeBrace.text }), print: ({ node, path, print }) => [ diff --git a/src/slang-nodes/InterfaceMembers.js b/src/slang-nodes/InterfaceMembers.js index 0bf940858..181a34526 100644 --- a/src/slang-nodes/InterfaceMembers.js +++ b/src/slang-nodes/InterfaceMembers.js @@ -1,14 +1,13 @@ import { doc } from 'prettier'; -import { - printPreservingEmptyLines, - printSeparatedItem -} from '../common/printer-helpers.js'; +import { printSeparatedItem } from '../common/printer-helpers.js'; +import { printPreservingEmptyLines } from '../common/slang-helpers.js'; const { hardline } = doc.builders; export const InterfaceMembers = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ node, options, path, print }) => node.items.length > 0 diff --git a/src/slang-nodes/LibraryDefinition.js b/src/slang-nodes/LibraryDefinition.js index 15aef8447..774e041f0 100644 --- a/src/slang-nodes/LibraryDefinition.js +++ b/src/slang-nodes/LibraryDefinition.js @@ -3,11 +3,12 @@ import { doc } from 'prettier'; const { group, line } = doc.builders; export const LibraryDefinition = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, libraryKeyword: ast.libraryKeyword.text, name: ast.name.text, openBrace: ast.openBrace.text, - members: parse(ast.members, options, parse), + members: parse(ast.members, options, parse, offsets), closeBrace: ast.closeBrace.text }), print: ({ node, path, print }) => [ diff --git a/src/slang-nodes/LibraryMembers.js b/src/slang-nodes/LibraryMembers.js index 2080cf903..b72267b5c 100644 --- a/src/slang-nodes/LibraryMembers.js +++ b/src/slang-nodes/LibraryMembers.js @@ -1,14 +1,13 @@ import { doc } from 'prettier'; -import { - printPreservingEmptyLines, - printSeparatedItem -} from '../common/printer-helpers.js'; +import { printSeparatedItem } from '../common/printer-helpers.js'; +import { printPreservingEmptyLines } from '../common/slang-helpers.js'; const { hardline } = doc.builders; export const LibraryMembers = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ node, path, print, options }) => node.items.length > 0 diff --git a/src/slang-nodes/MappingKey.js b/src/slang-nodes/MappingKey.js index 72882f0d9..a56e5f86f 100644 --- a/src/slang-nodes/MappingKey.js +++ b/src/slang-nodes/MappingKey.js @@ -1,6 +1,7 @@ export const MappingKey = { - parse: ({ ast, options, parse }) => ({ - keyType: parse(ast.keyType, options, parse), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + keyType: parse(ast.keyType, options, parse, offsets), name: ast.name?.text }), print: ({ node, path, print }) => [ diff --git a/src/slang-nodes/MappingKeyType.js b/src/slang-nodes/MappingKeyType.js index 774bdb2de..92f154052 100644 --- a/src/slang-nodes/MappingKeyType.js +++ b/src/slang-nodes/MappingKeyType.js @@ -1,6 +1,7 @@ export const MappingKeyType = { - parse: ({ ast, options, parse }) => ({ - variant: parse(ast.variant, options, parse) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + variant: parse(ast.variant, options, parse, offsets) }), print: ({ path, print }) => path.call(print, 'variant') }; diff --git a/src/slang-nodes/MappingType.js b/src/slang-nodes/MappingType.js index 6d6ad951b..b1ce8e252 100644 --- a/src/slang-nodes/MappingType.js +++ b/src/slang-nodes/MappingType.js @@ -1,10 +1,11 @@ export const MappingType = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, mappingKeyword: ast.mappingKeyword.text, openParen: ast.openParen.text, - keyType: parse(ast.keyType, options, parse), + keyType: parse(ast.keyType, options, parse, offsets), equalGreaterThan: ast.equalGreaterThan.text, - valueType: parse(ast.valueType, options, parse), + valueType: parse(ast.valueType, options, parse, offsets), closeParen: ast.closeParen.text }), print: ({ node, path, print }) => [ diff --git a/src/slang-nodes/MappingValue.js b/src/slang-nodes/MappingValue.js index e8009cad8..0cbb7cfd6 100644 --- a/src/slang-nodes/MappingValue.js +++ b/src/slang-nodes/MappingValue.js @@ -1,6 +1,7 @@ export const MappingValue = { - parse: ({ ast, options, parse }) => ({ - typeName: parse(ast.typeName, options, parse), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + typeName: parse(ast.typeName, options, parse, offsets), name: ast.name?.text }), print: ({ node, path, print }) => [ diff --git a/src/slang-nodes/MemberAccess.js b/src/slang-nodes/MemberAccess.js index 780257c4a..bd6be90ac 100644 --- a/src/slang-nodes/MemberAccess.js +++ b/src/slang-nodes/MemberAccess.js @@ -1,5 +1,6 @@ export const MemberAccess = { - parse: ({ ast }) => ({ + parse: ({ node, offsets, ast }) => ({ + ...node, variant: ast.variant.text }), print: ({ node }) => node.variant diff --git a/src/slang-nodes/MemberAccessExpression.js b/src/slang-nodes/MemberAccessExpression.js index 2d16662ec..2698d23df 100644 --- a/src/slang-nodes/MemberAccessExpression.js +++ b/src/slang-nodes/MemberAccessExpression.js @@ -102,10 +102,11 @@ const processChain = (chain) => { }; export const MemberAccessExpression = { - parse: ({ ast, options, parse }) => ({ - operand: parse(ast.operand, options, parse), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + operand: parse(ast.operand, options, parse, offsets), period: ast.period.text, - member: parse(ast.member, options, parse) + member: parse(ast.member, options, parse, offsets) }), print: ({ node, path, print }) => { let operandDoc = path.call(print, 'operand'); diff --git a/src/slang-nodes/ModifierAttribute.js b/src/slang-nodes/ModifierAttribute.js index e57458c7b..ed830d814 100644 --- a/src/slang-nodes/ModifierAttribute.js +++ b/src/slang-nodes/ModifierAttribute.js @@ -1,9 +1,10 @@ export const ModifierAttribute = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, variant: ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, options, parse) + : parse(ast.variant, options, parse, offsets) }), print: ({ node, path, print }) => typeof node.variant === 'string' diff --git a/src/slang-nodes/ModifierAttributes.js b/src/slang-nodes/ModifierAttributes.js index 1ea9c141b..05ec78c70 100644 --- a/src/slang-nodes/ModifierAttributes.js +++ b/src/slang-nodes/ModifierAttributes.js @@ -3,8 +3,9 @@ import { doc } from 'prettier'; const { line } = doc.builders; export const ModifierAttributes = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ path, print }) => path.map(print, 'items').map((item) => [line, item]) diff --git a/src/slang-nodes/ModifierDefinition.js b/src/slang-nodes/ModifierDefinition.js index 2964bb69c..4bccd128d 100644 --- a/src/slang-nodes/ModifierDefinition.js +++ b/src/slang-nodes/ModifierDefinition.js @@ -1,14 +1,15 @@ import { printFunction } from '../common/slang-helpers.js'; export const ModifierDefinition = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, modifierKeyword: ast.modifierKeyword.text, name: ast.name.text, parameters: ast.parameters - ? parse(ast.parameters, options, parse) + ? parse(ast.parameters, options, parse, offsets) : undefined, - attributes: parse(ast.attributes, options, parse), - body: parse(ast.body, options, parse) + attributes: parse(ast.attributes, options, parse, offsets), + body: parse(ast.body, options, parse, offsets) }), print: ({ node, path, print }) => printFunction(`${node.modifierKeyword} ${node.name}`, node, path, print) diff --git a/src/slang-nodes/ModifierInvocation.js b/src/slang-nodes/ModifierInvocation.js index 8cbc3d0b0..67d5f6a2b 100644 --- a/src/slang-nodes/ModifierInvocation.js +++ b/src/slang-nodes/ModifierInvocation.js @@ -1,7 +1,10 @@ export const ModifierInvocation = { - parse: ({ ast, options, parse }) => ({ - name: parse(ast.name, options, parse), - arguments: ast.arguments ? parse(ast.arguments, options, parse) : undefined + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + name: parse(ast.name, options, parse, offsets), + arguments: ast.arguments + ? parse(ast.arguments, options, parse, offsets) + : undefined }), print: ({ node, path, print }) => [ path.call(print, 'name'), diff --git a/src/slang-nodes/MultiplicativeExpression.js b/src/slang-nodes/MultiplicativeExpression.js index cf270f82a..a288deb56 100644 --- a/src/slang-nodes/MultiplicativeExpression.js +++ b/src/slang-nodes/MultiplicativeExpression.js @@ -1,8 +1,8 @@ import { binaryOperationPrint, tryHug } from '../common/slang-helpers.js'; export const MultiplicativeExpression = { - parse: ({ ast, options, parse }) => { - let leftOperand = parse(ast.leftOperand, options, parse); + parse: ({ node, offsets, ast, options, parse }) => { + let leftOperand = parse(ast.leftOperand, options, parse, offsets); const operator = ast.operator.text; switch (operator) { @@ -20,9 +20,10 @@ export const MultiplicativeExpression = { } return { + ...node, leftOperand, operator, - rightOperand: parse(ast.rightOperand, options, parse) + rightOperand: parse(ast.rightOperand, options, parse, offsets) }; }, print: binaryOperationPrint diff --git a/src/slang-nodes/NamedArgument.js b/src/slang-nodes/NamedArgument.js index fbbb0f105..f024ad39d 100644 --- a/src/slang-nodes/NamedArgument.js +++ b/src/slang-nodes/NamedArgument.js @@ -1,8 +1,9 @@ export const NamedArgument = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, name: ast.name.text, colon: ast.colon.text, - value: parse(ast.value, options, parse) + value: parse(ast.value, options, parse, offsets) }), print: ({ node, path, print }) => [ `${node.name}${node.colon} `, diff --git a/src/slang-nodes/NamedArgumentGroup.js b/src/slang-nodes/NamedArgumentGroup.js index a04ab8dc8..2e1112a7c 100644 --- a/src/slang-nodes/NamedArgumentGroup.js +++ b/src/slang-nodes/NamedArgumentGroup.js @@ -1,7 +1,8 @@ export const NamedArgumentGroup = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, openBrace: ast.openBrace.text, - arguments: parse(ast.arguments, options, parse), + arguments: parse(ast.arguments, options, parse, offsets), closeBrace: ast.closeBrace.text }), print: ({ node, path, print }) => [ diff --git a/src/slang-nodes/NamedArguments.js b/src/slang-nodes/NamedArguments.js index 58292d81a..44225db54 100644 --- a/src/slang-nodes/NamedArguments.js +++ b/src/slang-nodes/NamedArguments.js @@ -1,8 +1,9 @@ import { printSeparatedList } from '../common/printer-helpers.js'; export const NamedArguments = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), print: ({ path, print }) => printSeparatedList(path.map(print, 'items')) diff --git a/src/slang-nodes/NamedArgumentsDeclaration.js b/src/slang-nodes/NamedArgumentsDeclaration.js index c8819ba07..016cd126c 100644 --- a/src/slang-nodes/NamedArgumentsDeclaration.js +++ b/src/slang-nodes/NamedArgumentsDeclaration.js @@ -1,7 +1,10 @@ export const NamedArgumentsDeclaration = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, openParen: ast.openParen.text, - arguments: ast.arguments ? parse(ast.arguments, options, parse) : undefined, + arguments: ast.arguments + ? parse(ast.arguments, options, parse, offsets) + : undefined, closeParen: ast.closeParen.text }), print: ({ node, path, print }) => [ diff --git a/src/slang-nodes/NamedImport.js b/src/slang-nodes/NamedImport.js index 8905a40c8..bbc7295fe 100644 --- a/src/slang-nodes/NamedImport.js +++ b/src/slang-nodes/NamedImport.js @@ -1,9 +1,10 @@ export const NamedImport = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, asterisk: ast.asterisk.text, - alias: parse(ast.alias, options, parse), + alias: parse(ast.alias, options, parse, offsets), fromKeyword: ast.fromKeyword.text, - path: parse(ast.path, options, parse) + path: parse(ast.path, options, parse, offsets) }), print: ({ node, path, print }) => [ node.asterisk, diff --git a/src/slang-nodes/NewExpression.js b/src/slang-nodes/NewExpression.js index a8f355bbc..ec1498340 100644 --- a/src/slang-nodes/NewExpression.js +++ b/src/slang-nodes/NewExpression.js @@ -1,7 +1,8 @@ export const NewExpression = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, newKeyword: ast.newKeyword.text, - typeName: parse(ast.typeName, options, parse) + typeName: parse(ast.typeName, options, parse, offsets) }), print: ({ node, path, print }) => [ `${node.newKeyword} `, diff --git a/src/slang-nodes/NumberUnit.js b/src/slang-nodes/NumberUnit.js index 7b57c2db0..e15e434c8 100644 --- a/src/slang-nodes/NumberUnit.js +++ b/src/slang-nodes/NumberUnit.js @@ -1,5 +1,6 @@ export const NumberUnit = { - parse: ({ ast }) => ({ + parse: ({ node, offsets, ast }) => ({ + ...node, variant: ast.variant.text }), print: ({ node }) => node.variant diff --git a/src/slang-nodes/OrExpression.js b/src/slang-nodes/OrExpression.js index dc5118ec6..66f3ca2d2 100644 --- a/src/slang-nodes/OrExpression.js +++ b/src/slang-nodes/OrExpression.js @@ -1,10 +1,15 @@ import { logicalOperationPrint, tryHug } from '../common/slang-helpers.js'; export const OrExpression = { - parse: ({ ast, options, parse }) => ({ - leftOperand: tryHug(parse(ast.leftOperand, options, parse), ['&&']), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + leftOperand: tryHug(parse(ast.leftOperand, options, parse, offsets), [ + '&&' + ]), operator: ast.operator.text, - rightOperand: tryHug(parse(ast.rightOperand, options, parse), ['&&']) + rightOperand: tryHug(parse(ast.rightOperand, options, parse, offsets), [ + '&&' + ]) }), print: logicalOperationPrint }; diff --git a/src/slang-nodes/OverridePaths.js b/src/slang-nodes/OverridePaths.js index 0b042a83d..aafd2d4f9 100644 --- a/src/slang-nodes/OverridePaths.js +++ b/src/slang-nodes/OverridePaths.js @@ -1,6 +1,7 @@ export const OverridePaths = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator) }), // TODO: implement print diff --git a/src/slang-nodes/OverridePathsDeclaration.js b/src/slang-nodes/OverridePathsDeclaration.js index 868da87c1..1b18084b0 100644 --- a/src/slang-nodes/OverridePathsDeclaration.js +++ b/src/slang-nodes/OverridePathsDeclaration.js @@ -1,7 +1,8 @@ export const OverridePathsDeclaration = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, openParen: ast.openParen.text, - paths: parse(ast.paths, options, parse), + paths: parse(ast.paths, options, parse, offsets), closeParen: ast.closeParen.text }), // TODO: implement print diff --git a/src/slang-nodes/OverrideSpecifier.js b/src/slang-nodes/OverrideSpecifier.js index 5ac0f3002..ea4c55a3f 100644 --- a/src/slang-nodes/OverrideSpecifier.js +++ b/src/slang-nodes/OverrideSpecifier.js @@ -1,8 +1,9 @@ export const OverrideSpecifier = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, overrideKeyword: ast.overrideKeyword.text, overridden: ast.overridden - ? parse(ast.overridden, options, parse) + ? parse(ast.overridden, options, parse, offsets) : undefined }), print: ({ node, path, print }) => [ diff --git a/src/slang-nodes/Parameter.js b/src/slang-nodes/Parameter.js index 010b1a6e1..bb04a4763 100644 --- a/src/slang-nodes/Parameter.js +++ b/src/slang-nodes/Parameter.js @@ -1,8 +1,9 @@ export const Parameter = { - parse: ({ ast, options, parse }) => ({ - typeName: parse(ast.typeName, options, parse), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + typeName: parse(ast.typeName, options, parse, offsets), storageLocation: ast.storageLocation - ? parse(ast.storageLocation, options, parse) + ? parse(ast.storageLocation, options, parse, offsets) : undefined, name: ast.name?.text }), diff --git a/src/slang-nodes/Parameters.js b/src/slang-nodes/Parameters.js index 9fe5e2154..51c1e763f 100644 --- a/src/slang-nodes/Parameters.js +++ b/src/slang-nodes/Parameters.js @@ -1,8 +1,9 @@ import { printSeparatedList } from '../common/printer-helpers.js'; export const Parameters = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), print: ({ node, path, print }) => diff --git a/src/slang-nodes/ParametersDeclaration.js b/src/slang-nodes/ParametersDeclaration.js index 6042bc4f6..83c7f8208 100644 --- a/src/slang-nodes/ParametersDeclaration.js +++ b/src/slang-nodes/ParametersDeclaration.js @@ -1,7 +1,8 @@ export const ParametersDeclaration = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, openParen: ast.openParen.text, - parameters: parse(ast.parameters, options, parse), + parameters: parse(ast.parameters, options, parse, offsets), closeParen: ast.closeParen.text }), print: ({ node, path, print }) => [ diff --git a/src/slang-nodes/PathImport.js b/src/slang-nodes/PathImport.js index d33adbf31..dfdebac97 100644 --- a/src/slang-nodes/PathImport.js +++ b/src/slang-nodes/PathImport.js @@ -1,7 +1,8 @@ export const PathImport = { - parse: ({ ast, options, parse }) => ({ - path: parse(ast.path, options, parse), - alias: ast.alias ? parse(ast.alias, options, parse) : undefined + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + path: parse(ast.path, options, parse, offsets), + alias: ast.alias ? parse(ast.alias, options, parse, offsets) : undefined }), print: ({ node, path, print }) => [ path.call(print, 'path'), diff --git a/src/slang-nodes/PositionalArguments.js b/src/slang-nodes/PositionalArguments.js index 67c80bce5..581e1f2fa 100644 --- a/src/slang-nodes/PositionalArguments.js +++ b/src/slang-nodes/PositionalArguments.js @@ -1,8 +1,9 @@ import { printSeparatedList } from '../common/printer-helpers.js'; export const PositionalArguments = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), print: ({ node, path, print }) => diff --git a/src/slang-nodes/PositionalArgumentsDeclaration.js b/src/slang-nodes/PositionalArgumentsDeclaration.js index 1c3454801..7f38b43b5 100644 --- a/src/slang-nodes/PositionalArgumentsDeclaration.js +++ b/src/slang-nodes/PositionalArgumentsDeclaration.js @@ -1,7 +1,8 @@ export const PositionalArgumentsDeclaration = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, openParen: ast.openParen.text, - arguments: parse(ast.arguments, options, parse), + arguments: parse(ast.arguments, options, parse, offsets), closeParen: ast.closeParen.text }), print: ({ node, path, print }) => [ diff --git a/src/slang-nodes/PostfixExpression.js b/src/slang-nodes/PostfixExpression.js index af5f2bdb9..a97fa975a 100644 --- a/src/slang-nodes/PostfixExpression.js +++ b/src/slang-nodes/PostfixExpression.js @@ -1,6 +1,7 @@ export const PostfixExpression = { - parse: ({ ast, options, parse }) => ({ - operand: parse(ast.operand, options, parse), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + operand: parse(ast.operand, options, parse, offsets), operator: ast.operator.text }), print: ({ node, path, print }) => [path.call(print, 'operand'), node.operator] diff --git a/src/slang-nodes/Pragma.js b/src/slang-nodes/Pragma.js index 7b9815094..f27429b5f 100644 --- a/src/slang-nodes/Pragma.js +++ b/src/slang-nodes/Pragma.js @@ -1,6 +1,7 @@ export const Pragma = { - parse: ({ ast, options, parse }) => ({ - variant: parse(ast.variant, options, parse) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + variant: parse(ast.variant, options, parse, offsets) }), print: ({ path, print }) => path.call(print, 'variant') }; diff --git a/src/slang-nodes/PragmaDirective.js b/src/slang-nodes/PragmaDirective.js index 3ce605679..861c18e80 100644 --- a/src/slang-nodes/PragmaDirective.js +++ b/src/slang-nodes/PragmaDirective.js @@ -1,7 +1,8 @@ export const PragmaDirective = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, pragmaKeyword: ast.pragmaKeyword.text, - pragma: parse(ast.pragma, options, parse), + pragma: parse(ast.pragma, options, parse, offsets), semicolon: ast.semicolon.text }), print: ({ node, path, print }) => [ diff --git a/src/slang-nodes/PrefixExpression.js b/src/slang-nodes/PrefixExpression.js index 7cdd67f1d..3404d6adf 100644 --- a/src/slang-nodes/PrefixExpression.js +++ b/src/slang-nodes/PrefixExpression.js @@ -1,7 +1,8 @@ export const PrefixExpression = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, operator: ast.operator.text, - operand: parse(ast.operand, options, parse) + operand: parse(ast.operand, options, parse, offsets) }), print: ({ node, path, print }) => [node.operator, path.call(print, 'operand')] }; diff --git a/src/slang-nodes/ReceiveFunctionAttribute.js b/src/slang-nodes/ReceiveFunctionAttribute.js index 39d86856d..9fe335c25 100644 --- a/src/slang-nodes/ReceiveFunctionAttribute.js +++ b/src/slang-nodes/ReceiveFunctionAttribute.js @@ -1,9 +1,10 @@ export const ReceiveFunctionAttribute = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, variant: ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, options, parse) + : parse(ast.variant, options, parse, offsets) }), print: ({ node, path, print }) => typeof node.variant === 'string' diff --git a/src/slang-nodes/ReceiveFunctionAttributes.js b/src/slang-nodes/ReceiveFunctionAttributes.js index e0fd2507f..6bf94ef76 100644 --- a/src/slang-nodes/ReceiveFunctionAttributes.js +++ b/src/slang-nodes/ReceiveFunctionAttributes.js @@ -3,8 +3,9 @@ import { doc } from 'prettier'; const { line } = doc.builders; export const ReceiveFunctionAttributes = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ path, print }) => path.map(print, 'items').map((item) => [line, item]) diff --git a/src/slang-nodes/ReceiveFunctionDefinition.js b/src/slang-nodes/ReceiveFunctionDefinition.js index ca5699b20..d07aa1477 100644 --- a/src/slang-nodes/ReceiveFunctionDefinition.js +++ b/src/slang-nodes/ReceiveFunctionDefinition.js @@ -1,11 +1,12 @@ import { printFunction } from '../common/slang-helpers.js'; export const ReceiveFunctionDefinition = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, receiveKeyword: ast.receiveKeyword.text, - parameters: parse(ast.parameters, options, parse), - attributes: parse(ast.attributes, options, parse), - body: parse(ast.body, options, parse) + parameters: parse(ast.parameters, options, parse, offsets), + attributes: parse(ast.attributes, options, parse, offsets), + body: parse(ast.body, options, parse, offsets) }), print: ({ node, path, print }) => printFunction(node.receiveKeyword, node, path, print) diff --git a/src/slang-nodes/ReturnStatement.js b/src/slang-nodes/ReturnStatement.js index a12e15528..2e82e105c 100644 --- a/src/slang-nodes/ReturnStatement.js +++ b/src/slang-nodes/ReturnStatement.js @@ -1,8 +1,9 @@ export const ReturnStatement = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, returnKeyword: ast.returnKeyword.text, expression: ast.expression - ? parse(ast.expression, options, parse) + ? parse(ast.expression, options, parse, offsets) : undefined, semicolon: ast.semicolon.text }), diff --git a/src/slang-nodes/ReturnsDeclaration.js b/src/slang-nodes/ReturnsDeclaration.js index 5691550a2..92e876a46 100644 --- a/src/slang-nodes/ReturnsDeclaration.js +++ b/src/slang-nodes/ReturnsDeclaration.js @@ -1,7 +1,8 @@ export const ReturnsDeclaration = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, returnsKeyword: ast.returnsKeyword.text, - variables: parse(ast.variables, options, parse) + variables: parse(ast.variables, options, parse, offsets) }), print: ({ node, path, print }) => [ `${node.returnsKeyword} `, diff --git a/src/slang-nodes/RevertStatement.js b/src/slang-nodes/RevertStatement.js index 4254de926..d74c69bdc 100644 --- a/src/slang-nodes/RevertStatement.js +++ b/src/slang-nodes/RevertStatement.js @@ -1,8 +1,9 @@ export const RevertStatement = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, revertKeyword: ast.revertKeyword.text, - error: ast.error ? parse(ast.error, options, parse) : undefined, - arguments: parse(ast.arguments, options, parse), + error: ast.error ? parse(ast.error, options, parse, offsets) : undefined, + arguments: parse(ast.arguments, options, parse, offsets), semicolon: ast.semicolon.text }), print: ({ node, path, print }) => [ diff --git a/src/slang-nodes/ShiftExpression.js b/src/slang-nodes/ShiftExpression.js index ad6e3e9e4..93f6f10c4 100644 --- a/src/slang-nodes/ShiftExpression.js +++ b/src/slang-nodes/ShiftExpression.js @@ -1,8 +1,9 @@ import { binaryOperationPrint, tryHug } from '../common/slang-helpers.js'; export const ShiftExpression = { - parse: ({ ast, options, parse }) => ({ - leftOperand: tryHug(parse(ast.leftOperand, options, parse), [ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + leftOperand: tryHug(parse(ast.leftOperand, options, parse, offsets), [ '+', '-', '*', @@ -12,7 +13,7 @@ export const ShiftExpression = { '>>' ]), operator: ast.operator.text, - rightOperand: tryHug(parse(ast.rightOperand, options, parse), [ + rightOperand: tryHug(parse(ast.rightOperand, options, parse, offsets), [ '+', '-', '*', diff --git a/src/slang-nodes/SourceUnit.js b/src/slang-nodes/SourceUnit.js index 6f3cb3a2a..188449a2e 100644 --- a/src/slang-nodes/SourceUnit.js +++ b/src/slang-nodes/SourceUnit.js @@ -3,8 +3,9 @@ import { doc } from 'prettier'; const { line } = doc.builders; export const SourceUnit = { - parse: ({ ast, options, parse }) => ({ - members: parse(ast.members, options, parse) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + members: parse(ast.members, options, parse, offsets) }), print: ({ options, path, print }) => [ path.call(print, 'members'), diff --git a/src/slang-nodes/SourceUnitMember.js b/src/slang-nodes/SourceUnitMember.js index bc59be136..ea278d14f 100644 --- a/src/slang-nodes/SourceUnitMember.js +++ b/src/slang-nodes/SourceUnitMember.js @@ -1,6 +1,7 @@ export const SourceUnitMember = { - parse: ({ ast, options, parse }) => ({ - variant: parse(ast.variant, options, parse) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + variant: parse(ast.variant, options, parse, offsets) }), print: ({ path, print }) => path.call(print, 'variant') }; diff --git a/src/slang-nodes/SourceUnitMembers.js b/src/slang-nodes/SourceUnitMembers.js index 7230bd3c6..ceda58978 100644 --- a/src/slang-nodes/SourceUnitMembers.js +++ b/src/slang-nodes/SourceUnitMembers.js @@ -1,8 +1,9 @@ -import { printPreservingEmptyLines } from '../common/printer-helpers.js'; +import { printPreservingEmptyLines } from '../common/slang-helpers.js'; export const SourceUnitMembers = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ path, options, print }) => printPreservingEmptyLines(path, 'items', options, print) diff --git a/src/slang-nodes/StateVariableAttribute.js b/src/slang-nodes/StateVariableAttribute.js index eeeeb2eb2..347a5ddf1 100644 --- a/src/slang-nodes/StateVariableAttribute.js +++ b/src/slang-nodes/StateVariableAttribute.js @@ -1,9 +1,10 @@ export const StateVariableAttribute = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, variant: ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, options, parse) + : parse(ast.variant, options, parse, offsets) }), print: ({ node, path, print }) => typeof node.variant === 'string' diff --git a/src/slang-nodes/StateVariableAttributes.js b/src/slang-nodes/StateVariableAttributes.js index e4aebc536..ed758daab 100644 --- a/src/slang-nodes/StateVariableAttributes.js +++ b/src/slang-nodes/StateVariableAttributes.js @@ -1,6 +1,7 @@ export const StateVariableAttributes = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ node, path, print }) => node.items.length ? path.map(print, 'items').map((item) => [' ', item]) : '' diff --git a/src/slang-nodes/StateVariableDefinition.js b/src/slang-nodes/StateVariableDefinition.js index 4b29d02bd..b6805059e 100644 --- a/src/slang-nodes/StateVariableDefinition.js +++ b/src/slang-nodes/StateVariableDefinition.js @@ -1,9 +1,10 @@ export const StateVariableDefinition = { - parse: ({ ast, options, parse }) => ({ - typeName: parse(ast.typeName, options, parse), - attributes: parse(ast.attributes, options, parse), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + typeName: parse(ast.typeName, options, parse, offsets), + attributes: parse(ast.attributes, options, parse, offsets), name: ast.name.text, - value: ast.value ? parse(ast.value, options, parse) : undefined, + value: ast.value ? parse(ast.value, options, parse, offsets) : undefined, semicolon: ast.semicolon.text }), print: ({ node, path, print }) => [ diff --git a/src/slang-nodes/StateVariableDefinitionValue.js b/src/slang-nodes/StateVariableDefinitionValue.js index d28dce996..5d652af35 100644 --- a/src/slang-nodes/StateVariableDefinitionValue.js +++ b/src/slang-nodes/StateVariableDefinitionValue.js @@ -3,9 +3,10 @@ import { doc } from 'prettier'; const { group, indent, line } = doc.builders; export const StateVariableDefinitionValue = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, equal: ast.equal.text, - value: parse(ast.value, options, parse) + value: parse(ast.value, options, parse, offsets) }), print: ({ node, path, print }) => node.value.variant.kind === 'ArrayExpression' diff --git a/src/slang-nodes/Statement.js b/src/slang-nodes/Statement.js index 2932b69be..de95d1bd7 100644 --- a/src/slang-nodes/Statement.js +++ b/src/slang-nodes/Statement.js @@ -1,6 +1,7 @@ export const Statement = { - parse: ({ ast, options, parse }) => ({ - variant: parse(ast.variant, options, parse) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + variant: parse(ast.variant, options, parse, offsets) }), print: ({ path, print }) => path.call(print, 'variant') }; diff --git a/src/slang-nodes/Statements.js b/src/slang-nodes/Statements.js index fabd4c24d..8c9274841 100644 --- a/src/slang-nodes/Statements.js +++ b/src/slang-nodes/Statements.js @@ -1,14 +1,13 @@ import { doc } from 'prettier'; -import { - printPreservingEmptyLines, - printSeparatedItem -} from '../common/printer-helpers.js'; +import { printSeparatedItem } from '../common/printer-helpers.js'; +import { printPreservingEmptyLines } from '../common/slang-helpers.js'; const { hardline } = doc.builders; export const Statements = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ node, path, options, print }) => node.items.length > 0 diff --git a/src/slang-nodes/StorageLocation.js b/src/slang-nodes/StorageLocation.js index 1f7e90481..d0a3fd1f0 100644 --- a/src/slang-nodes/StorageLocation.js +++ b/src/slang-nodes/StorageLocation.js @@ -1,5 +1,6 @@ export const StorageLocation = { - parse: ({ ast }) => ({ + parse: ({ node, offsets, ast }) => ({ + ...node, variant: ast.variant.text }), print: ({ node }) => node.variant diff --git a/src/slang-nodes/StringExpression.js b/src/slang-nodes/StringExpression.js index 855648d44..2113db25f 100644 --- a/src/slang-nodes/StringExpression.js +++ b/src/slang-nodes/StringExpression.js @@ -1,6 +1,7 @@ export const StringExpression = { - parse: ({ ast, options, parse }) => ({ - variant: parse(ast.variant, options, parse) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + variant: parse(ast.variant, options, parse, offsets) }), print: ({ path, print }) => path.call(print, 'variant') }; diff --git a/src/slang-nodes/StringLiteral.js b/src/slang-nodes/StringLiteral.js index ddd8896fd..2ab12f95c 100644 --- a/src/slang-nodes/StringLiteral.js +++ b/src/slang-nodes/StringLiteral.js @@ -1,7 +1,8 @@ import { printString } from '../common/util.js'; export const StringLiteral = { - parse: ({ ast, options }) => ({ + parse: ({ node, offsets, ast, options }) => ({ + ...node, variant: printString(ast.variant.text.slice(1, -1), options) }), print: ({ node }) => node.variant diff --git a/src/slang-nodes/StringLiterals.js b/src/slang-nodes/StringLiterals.js index 229d2abcd..389e6589a 100644 --- a/src/slang-nodes/StringLiterals.js +++ b/src/slang-nodes/StringLiterals.js @@ -3,8 +3,9 @@ import { doc } from 'prettier'; const { join, hardline } = doc.builders; export const StringLiterals = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ path, print }) => join(hardline, path.map(print, 'items')) }; diff --git a/src/slang-nodes/StructDefinition.js b/src/slang-nodes/StructDefinition.js index eeae988dd..e3aff6dc2 100644 --- a/src/slang-nodes/StructDefinition.js +++ b/src/slang-nodes/StructDefinition.js @@ -1,9 +1,10 @@ export const StructDefinition = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, structKeyword: ast.structKeyword.text, name: ast.name.text, openBrace: ast.openBrace.text, - members: parse(ast.members, options, parse), + members: parse(ast.members, options, parse, offsets), closeBrace: ast.closeBrace.text }), print: ({ node, path, print }) => [ diff --git a/src/slang-nodes/StructMember.js b/src/slang-nodes/StructMember.js index fada97185..bf7563d4e 100644 --- a/src/slang-nodes/StructMember.js +++ b/src/slang-nodes/StructMember.js @@ -1,6 +1,7 @@ export const StructMember = { - parse: ({ ast, options, parse }) => ({ - typeName: parse(ast.typeName, options, parse), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + typeName: parse(ast.typeName, options, parse, offsets), name: ast.name.text, semicolon: ast.semicolon.text }), diff --git a/src/slang-nodes/StructMembers.js b/src/slang-nodes/StructMembers.js index 940a9c531..3da9f18ba 100644 --- a/src/slang-nodes/StructMembers.js +++ b/src/slang-nodes/StructMembers.js @@ -4,8 +4,9 @@ import { printSeparatedList } from '../common/printer-helpers.js'; const { hardline } = doc.builders; export const StructMembers = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ node, path, print }) => node.items.length > 0 diff --git a/src/slang-nodes/ThrowStatement.js b/src/slang-nodes/ThrowStatement.js index e414091fd..56c59ba79 100644 --- a/src/slang-nodes/ThrowStatement.js +++ b/src/slang-nodes/ThrowStatement.js @@ -1,5 +1,6 @@ export const ThrowStatement = { - parse: ({ ast }) => ({ + parse: ({ node, offsets, ast }) => ({ + ...node, throwKeyword: ast.throwKeyword.text, semicolon: ast.semicolon.text }), diff --git a/src/slang-nodes/TryStatement.js b/src/slang-nodes/TryStatement.js index 21f8f5919..4c88fdf25 100644 --- a/src/slang-nodes/TryStatement.js +++ b/src/slang-nodes/TryStatement.js @@ -4,12 +4,15 @@ import { printSeparatedItem } from '../common/printer-helpers.js'; const { line } = doc.builders; export const TryStatement = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, tryKeyword: ast.tryKeyword.text, - expression: parse(ast.expression, options, parse), - returns: ast.returns ? parse(ast.returns, options, parse) : undefined, - body: parse(ast.body, options, parse), - catchClauses: parse(ast.catchClauses, options, parse) + expression: parse(ast.expression, options, parse, offsets), + returns: ast.returns + ? parse(ast.returns, options, parse, offsets) + : undefined, + body: parse(ast.body, options, parse, offsets), + catchClauses: parse(ast.catchClauses, options, parse, offsets) }), print: ({ node, path, print }) => [ node.tryKeyword, diff --git a/src/slang-nodes/TupleDeconstructionElement.js b/src/slang-nodes/TupleDeconstructionElement.js index 7c1b8dd59..408fbfebd 100644 --- a/src/slang-nodes/TupleDeconstructionElement.js +++ b/src/slang-nodes/TupleDeconstructionElement.js @@ -1,6 +1,7 @@ export const TupleDeconstructionElement = { - parse: ({ ast, options, parse }) => ({ - member: ast.member ? parse(ast.member, options, parse) : undefined + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + member: ast.member ? parse(ast.member, options, parse, offsets) : undefined }), print: ({ node, path, print }) => node.member ? path.call(print, 'member') : '' diff --git a/src/slang-nodes/TupleDeconstructionElements.js b/src/slang-nodes/TupleDeconstructionElements.js index add09240f..72f2109bf 100644 --- a/src/slang-nodes/TupleDeconstructionElements.js +++ b/src/slang-nodes/TupleDeconstructionElements.js @@ -1,8 +1,9 @@ import { printSeparatedList } from '../common/printer-helpers.js'; export const TupleDeconstructionElements = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), print: ({ path, print }) => printSeparatedList(path.map(print, 'items')) diff --git a/src/slang-nodes/TupleDeconstructionStatement.js b/src/slang-nodes/TupleDeconstructionStatement.js index b208dea4f..8502a3bc6 100644 --- a/src/slang-nodes/TupleDeconstructionStatement.js +++ b/src/slang-nodes/TupleDeconstructionStatement.js @@ -3,13 +3,14 @@ import { doc } from 'prettier'; const { group, indent, line } = doc.builders; export const TupleDeconstructionStatement = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, varKeyword: ast.varKeyword?.text, openParen: ast.openParen.text, - elements: parse(ast.elements, options, parse), + elements: parse(ast.elements, options, parse, offsets), closeParen: ast.closeParen.text, equal: ast.equal.text, - expression: parse(ast.expression, options, parse), + expression: parse(ast.expression, options, parse, offsets), semicolon: ast.semicolon.text }), print: ({ node, path, print }) => [ diff --git a/src/slang-nodes/TupleExpression.js b/src/slang-nodes/TupleExpression.js index 7a9376a92..fc0b38882 100644 --- a/src/slang-nodes/TupleExpression.js +++ b/src/slang-nodes/TupleExpression.js @@ -1,7 +1,8 @@ export const TupleExpression = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, openParen: ast.openParen.text, - items: parse(ast.items, options, parse), + items: parse(ast.items, options, parse, offsets), closeParen: ast.closeParen.text }), print: ({ node, path, print }) => [ diff --git a/src/slang-nodes/TupleMember.js b/src/slang-nodes/TupleMember.js index 4c9b56770..ec821ba1f 100644 --- a/src/slang-nodes/TupleMember.js +++ b/src/slang-nodes/TupleMember.js @@ -1,6 +1,7 @@ export const TupleMember = { - parse: ({ ast, options, parse }) => ({ - variant: parse(ast.variant, options, parse) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + variant: parse(ast.variant, options, parse, offsets) }), print: ({ path, print }) => path.call(print, 'variant') }; diff --git a/src/slang-nodes/TupleValue.js b/src/slang-nodes/TupleValue.js index 43201e630..d77c04ca0 100644 --- a/src/slang-nodes/TupleValue.js +++ b/src/slang-nodes/TupleValue.js @@ -1,7 +1,8 @@ export const TupleValue = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, expression: ast.expression - ? parse(ast.expression, options, parse) + ? parse(ast.expression, options, parse, offsets) : undefined }), print: ({ node, path, print }) => diff --git a/src/slang-nodes/TupleValues.js b/src/slang-nodes/TupleValues.js index b477f15f0..ff5d7e141 100644 --- a/src/slang-nodes/TupleValues.js +++ b/src/slang-nodes/TupleValues.js @@ -1,8 +1,9 @@ import { printSeparatedList } from '../common/printer-helpers.js'; export const TupleValues = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), print: ({ path, print }) => printSeparatedList(path.map(print, 'items')) diff --git a/src/slang-nodes/TypeExpression.js b/src/slang-nodes/TypeExpression.js index 752dec35a..651f09c73 100644 --- a/src/slang-nodes/TypeExpression.js +++ b/src/slang-nodes/TypeExpression.js @@ -1,8 +1,9 @@ export const TypeExpression = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, typeKeyword: ast.typeKeyword.text, openParen: ast.openParen.text, - typeName: parse(ast.typeName, options, parse), + typeName: parse(ast.typeName, options, parse, offsets), closeParen: ast.closeParen.text }), // TODO: implement print diff --git a/src/slang-nodes/TypeName.js b/src/slang-nodes/TypeName.js index 75f3bbb2e..b2003d610 100644 --- a/src/slang-nodes/TypeName.js +++ b/src/slang-nodes/TypeName.js @@ -1,6 +1,7 @@ export const TypeName = { - parse: ({ ast, options, parse }) => ({ - variant: parse(ast.variant, options, parse) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + variant: parse(ast.variant, options, parse, offsets) }), print: ({ path, print }) => path.call(print, 'variant') }; diff --git a/src/slang-nodes/TypedTupleMember.js b/src/slang-nodes/TypedTupleMember.js index f2038f5a0..0c0fa3222 100644 --- a/src/slang-nodes/TypedTupleMember.js +++ b/src/slang-nodes/TypedTupleMember.js @@ -1,8 +1,9 @@ export const TypedTupleMember = { - parse: ({ ast, options, parse }) => ({ - typeName: parse(ast.typeName, options, parse), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + typeName: parse(ast.typeName, options, parse, offsets), storageLocation: ast.storageLocation - ? parse(ast.storageLocation, options, parse) + ? parse(ast.storageLocation, options, parse, offsets) : undefined, name: ast.name.text }), diff --git a/src/slang-nodes/UncheckedBlock.js b/src/slang-nodes/UncheckedBlock.js index f8ff87279..675a346e6 100644 --- a/src/slang-nodes/UncheckedBlock.js +++ b/src/slang-nodes/UncheckedBlock.js @@ -1,7 +1,8 @@ export const UncheckedBlock = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, uncheckedKeyword: ast.uncheckedKeyword.text, - block: parse(ast.block, options, parse) + block: parse(ast.block, options, parse, offsets) }), print: ({ node, path, print }) => [ `${node.uncheckedKeyword} `, diff --git a/src/slang-nodes/UnicodeStringLiteral.js b/src/slang-nodes/UnicodeStringLiteral.js index 6add29a29..b103b8343 100644 --- a/src/slang-nodes/UnicodeStringLiteral.js +++ b/src/slang-nodes/UnicodeStringLiteral.js @@ -1,7 +1,8 @@ import { printString } from '../common/util.js'; export const UnicodeStringLiteral = { - parse: ({ ast, options }) => ({ + parse: ({ node, offsets, ast, options }) => ({ + ...node, variant: `unicode${printString(ast.variant.text.slice(8, -1), options)}` }), print: ({ node }) => node.variant diff --git a/src/slang-nodes/UnicodeStringLiterals.js b/src/slang-nodes/UnicodeStringLiterals.js index c229cc774..00b628d5e 100644 --- a/src/slang-nodes/UnicodeStringLiterals.js +++ b/src/slang-nodes/UnicodeStringLiterals.js @@ -3,8 +3,9 @@ import { doc } from 'prettier'; const { join, hardline } = doc.builders; export const UnicodeStringLiterals = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ path, print }) => join(hardline, path.map(print, 'items')) }; diff --git a/src/slang-nodes/UnnamedFunctionAttribute.js b/src/slang-nodes/UnnamedFunctionAttribute.js index 156f65a43..3dcb53f35 100644 --- a/src/slang-nodes/UnnamedFunctionAttribute.js +++ b/src/slang-nodes/UnnamedFunctionAttribute.js @@ -1,9 +1,10 @@ export const UnnamedFunctionAttribute = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, variant: ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, options, parse) + : parse(ast.variant, options, parse, offsets) }), print: ({ node, path, print }) => typeof node.variant === 'string' diff --git a/src/slang-nodes/UnnamedFunctionAttributes.js b/src/slang-nodes/UnnamedFunctionAttributes.js index 6037c819d..24d843c75 100644 --- a/src/slang-nodes/UnnamedFunctionAttributes.js +++ b/src/slang-nodes/UnnamedFunctionAttributes.js @@ -3,8 +3,9 @@ import { doc } from 'prettier'; const { line } = doc.builders; export const UnnamedFunctionAttributes = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ path, print }) => path.map(print, 'items').map((item) => [line, item]) diff --git a/src/slang-nodes/UnnamedFunctionDefinition.js b/src/slang-nodes/UnnamedFunctionDefinition.js index b49ea65ce..a15695c4c 100644 --- a/src/slang-nodes/UnnamedFunctionDefinition.js +++ b/src/slang-nodes/UnnamedFunctionDefinition.js @@ -1,11 +1,12 @@ import { printFunction } from '../common/slang-helpers.js'; export const UnnamedFunctionDefinition = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, functionKeyword: ast.functionKeyword.text, - parameters: parse(ast.parameters, options, parse), - attributes: parse(ast.attributes, options, parse), - body: parse(ast.body, options, parse) + parameters: parse(ast.parameters, options, parse, offsets), + attributes: parse(ast.attributes, options, parse, offsets), + body: parse(ast.body, options, parse, offsets) }), print: ({ node, path, print }) => printFunction(node.functionKeyword, node, path, print) diff --git a/src/slang-nodes/UntypedTupleMember.js b/src/slang-nodes/UntypedTupleMember.js index 058bfb4c2..cce88edb8 100644 --- a/src/slang-nodes/UntypedTupleMember.js +++ b/src/slang-nodes/UntypedTupleMember.js @@ -1,7 +1,8 @@ export const UntypedTupleMember = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, storageLocation: ast.storageLocation - ? parse(ast.storageLocation, options, parse) + ? parse(ast.storageLocation, options, parse, offsets) : undefined, name: ast.name.text }), diff --git a/src/slang-nodes/UserDefinedValueTypeDefinition.js b/src/slang-nodes/UserDefinedValueTypeDefinition.js index cc1889490..af9e63fc3 100644 --- a/src/slang-nodes/UserDefinedValueTypeDefinition.js +++ b/src/slang-nodes/UserDefinedValueTypeDefinition.js @@ -1,9 +1,10 @@ export const UserDefinedValueTypeDefinition = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, typeKeyword: ast.typeKeyword.text, name: ast.name.text, isKeyword: ast.isKeyword.text, - valueType: parse(ast.valueType, options, parse), + valueType: parse(ast.valueType, options, parse, offsets), semicolon: ast.semicolon.text }), print: ({ node, path, print }) => [ diff --git a/src/slang-nodes/UsingAlias.js b/src/slang-nodes/UsingAlias.js index 8e0cb2683..cbd0ec10d 100644 --- a/src/slang-nodes/UsingAlias.js +++ b/src/slang-nodes/UsingAlias.js @@ -1,7 +1,8 @@ export const UsingAlias = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, asKeyword: ast.asKeyword.text, - operator: parse(ast.operator, options, parse) + operator: parse(ast.operator, options, parse, offsets) }), print: ({ node, path, print }) => [ ` ${node.asKeyword} `, diff --git a/src/slang-nodes/UsingClause.js b/src/slang-nodes/UsingClause.js index 75cd2b903..0850d716b 100644 --- a/src/slang-nodes/UsingClause.js +++ b/src/slang-nodes/UsingClause.js @@ -1,6 +1,7 @@ export const UsingClause = { - parse: ({ ast, options, parse }) => ({ - variant: parse(ast.variant, options, parse) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + variant: parse(ast.variant, options, parse, offsets) }), print: ({ path, print }) => path.call(print, 'variant') }; diff --git a/src/slang-nodes/UsingDeconstruction.js b/src/slang-nodes/UsingDeconstruction.js index b09e55343..02920ef50 100644 --- a/src/slang-nodes/UsingDeconstruction.js +++ b/src/slang-nodes/UsingDeconstruction.js @@ -1,7 +1,8 @@ export const UsingDeconstruction = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, openBrace: ast.openBrace.text, - symbols: parse(ast.symbols, options, parse), + symbols: parse(ast.symbols, options, parse, offsets), closeBrace: ast.closeBrace.text }), print: ({ node, path, print }) => [ diff --git a/src/slang-nodes/UsingDeconstructionSymbol.js b/src/slang-nodes/UsingDeconstructionSymbol.js index 78845afde..06ba41bed 100644 --- a/src/slang-nodes/UsingDeconstructionSymbol.js +++ b/src/slang-nodes/UsingDeconstructionSymbol.js @@ -1,7 +1,8 @@ export const UsingDeconstructionSymbol = { - parse: ({ ast, options, parse }) => ({ - name: parse(ast.name, options, parse), - alias: ast.alias ? parse(ast.alias, options, parse) : undefined + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + name: parse(ast.name, options, parse, offsets), + alias: ast.alias ? parse(ast.alias, options, parse, offsets) : undefined }), print: ({ node, path, print }) => [ path.call(print, 'name'), diff --git a/src/slang-nodes/UsingDeconstructionSymbols.js b/src/slang-nodes/UsingDeconstructionSymbols.js index be7378eee..62d13b931 100644 --- a/src/slang-nodes/UsingDeconstructionSymbols.js +++ b/src/slang-nodes/UsingDeconstructionSymbols.js @@ -4,8 +4,9 @@ import { printSeparatedList } from '../common/printer-helpers.js'; const { line, softline } = doc.builders; export const UsingDeconstructionSymbols = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), print: ({ path, print, options }) => diff --git a/src/slang-nodes/UsingDirective.js b/src/slang-nodes/UsingDirective.js index 8cfa1dfd0..a2a3859ec 100644 --- a/src/slang-nodes/UsingDirective.js +++ b/src/slang-nodes/UsingDirective.js @@ -1,9 +1,10 @@ export const UsingDirective = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, usingKeyword: ast.usingKeyword.text, - clause: parse(ast.clause, options, parse), + clause: parse(ast.clause, options, parse, offsets), forKeyword: ast.forKeyword.text, - target: parse(ast.target, options, parse), + target: parse(ast.target, options, parse, offsets), globalKeyword: ast.globalKeyword?.text, semicolon: ast.semicolon.text }), diff --git a/src/slang-nodes/UsingOperator.js b/src/slang-nodes/UsingOperator.js index 3514cd39f..9e1b1912d 100644 --- a/src/slang-nodes/UsingOperator.js +++ b/src/slang-nodes/UsingOperator.js @@ -1,5 +1,6 @@ export const UsingOperator = { - parse: ({ ast }) => ({ + parse: ({ node, offsets, ast }) => ({ + ...node, variant: ast.variant.text }), print: ({ node }) => node.variant diff --git a/src/slang-nodes/UsingTarget.js b/src/slang-nodes/UsingTarget.js index ec9660fd8..875cc698d 100644 --- a/src/slang-nodes/UsingTarget.js +++ b/src/slang-nodes/UsingTarget.js @@ -1,9 +1,10 @@ export const UsingTarget = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, variant: ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, options, parse) + : parse(ast.variant, options, parse, offsets) }), print: ({ node, path, print }) => typeof node.variant === 'string' diff --git a/src/slang-nodes/VariableDeclarationStatement.js b/src/slang-nodes/VariableDeclarationStatement.js index c88422084..8cf3a907d 100644 --- a/src/slang-nodes/VariableDeclarationStatement.js +++ b/src/slang-nodes/VariableDeclarationStatement.js @@ -1,11 +1,12 @@ export const VariableDeclarationStatement = { - parse: ({ ast, options, parse }) => ({ - variableType: parse(ast.variableType, options, parse), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + variableType: parse(ast.variableType, options, parse, offsets), storageLocation: ast.storageLocation - ? parse(ast.storageLocation, options, parse) + ? parse(ast.storageLocation, options, parse, offsets) : undefined, name: ast.name.text, - value: ast.value ? parse(ast.value, options, parse) : undefined, + value: ast.value ? parse(ast.value, options, parse, offsets) : undefined, semicolon: ast.semicolon.text }), print: ({ node, path, print }) => [ diff --git a/src/slang-nodes/VariableDeclarationType.js b/src/slang-nodes/VariableDeclarationType.js index d4506234a..3ca084e65 100644 --- a/src/slang-nodes/VariableDeclarationType.js +++ b/src/slang-nodes/VariableDeclarationType.js @@ -1,9 +1,10 @@ export const VariableDeclarationType = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, variant: ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, options, parse) + : parse(ast.variant, options, parse, offsets) }), print: ({ node, path, print }) => typeof node.variant === 'string' diff --git a/src/slang-nodes/VariableDeclarationValue.js b/src/slang-nodes/VariableDeclarationValue.js index 42d477152..4012c4afe 100644 --- a/src/slang-nodes/VariableDeclarationValue.js +++ b/src/slang-nodes/VariableDeclarationValue.js @@ -1,7 +1,8 @@ export const VariableDeclarationValue = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, equal: ast.equal.text, - expression: parse(ast.expression, options, parse) + expression: parse(ast.expression, options, parse, offsets) }), print: ({ node, path, print }) => [ ` ${node.equal} `, diff --git a/src/slang-nodes/VersionComparator.js b/src/slang-nodes/VersionComparator.js index bb2f67330..4504a840f 100644 --- a/src/slang-nodes/VersionComparator.js +++ b/src/slang-nodes/VersionComparator.js @@ -1,7 +1,8 @@ export const VersionComparator = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, operator: ast.operator.text, - operand: parse(ast.operand, options, parse) + operand: parse(ast.operand, options, parse, offsets) }), print: ({ node, path, print }) => [node.operator, path.call(print, 'operand')] }; diff --git a/src/slang-nodes/VersionExpression.js b/src/slang-nodes/VersionExpression.js index eb827577c..6f74a4ab5 100644 --- a/src/slang-nodes/VersionExpression.js +++ b/src/slang-nodes/VersionExpression.js @@ -1,9 +1,10 @@ export const VersionExpression = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, variant: ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, options, parse) + : parse(ast.variant, options, parse, offsets) }), print: ({ node, path, print }) => typeof node.variant === 'string' diff --git a/src/slang-nodes/VersionExpressionSet.js b/src/slang-nodes/VersionExpressionSet.js index ee32680a1..30b66d182 100644 --- a/src/slang-nodes/VersionExpressionSet.js +++ b/src/slang-nodes/VersionExpressionSet.js @@ -3,8 +3,9 @@ import { doc } from 'prettier'; const { join } = doc.builders; export const VersionExpressionSet = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ path, print }) => join(' ', path.map(print, 'items')) }; diff --git a/src/slang-nodes/VersionExpressionSets.js b/src/slang-nodes/VersionExpressionSets.js index addaf361b..542fd6016 100644 --- a/src/slang-nodes/VersionExpressionSets.js +++ b/src/slang-nodes/VersionExpressionSets.js @@ -1,6 +1,7 @@ export const VersionExpressionSets = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), print: ({ node, path, print }) => diff --git a/src/slang-nodes/VersionPragma.js b/src/slang-nodes/VersionPragma.js index d18057c05..a440247fd 100644 --- a/src/slang-nodes/VersionPragma.js +++ b/src/slang-nodes/VersionPragma.js @@ -1,7 +1,8 @@ export const VersionPragma = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, solidityKeyword: ast.solidityKeyword.text, - sets: parse(ast.sets, options, parse) + sets: parse(ast.sets, options, parse, offsets) }), print: ({ node, path, print }) => [ node.solidityKeyword, diff --git a/src/slang-nodes/VersionRange.js b/src/slang-nodes/VersionRange.js index c59335080..50e913465 100644 --- a/src/slang-nodes/VersionRange.js +++ b/src/slang-nodes/VersionRange.js @@ -1,8 +1,9 @@ export const VersionRange = { - parse: ({ ast, options, parse }) => ({ - leftOperand: parse(ast.leftOperand, options, parse), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + leftOperand: parse(ast.leftOperand, options, parse, offsets), operator: ast.operator.text, - rightOperand: parse(ast.rightOperand, options, parse) + rightOperand: parse(ast.rightOperand, options, parse, offsets) }), // TODO: implement print print: ({ node, path, print, options }) => ['TODO: VersionRange'] diff --git a/src/slang-nodes/VersionSpecifiers.js b/src/slang-nodes/VersionSpecifiers.js index e08e48a0e..1ce951af2 100644 --- a/src/slang-nodes/VersionSpecifiers.js +++ b/src/slang-nodes/VersionSpecifiers.js @@ -1,5 +1,6 @@ export const VersionSpecifiers = { - parse: ({ ast }) => ({ + parse: ({ node, offsets, ast }) => ({ + ...node, items: ast.items.map((item) => item.text), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/WhileStatement.js b/src/slang-nodes/WhileStatement.js index 9ed1f7a3c..a213f0ece 100644 --- a/src/slang-nodes/WhileStatement.js +++ b/src/slang-nodes/WhileStatement.js @@ -1,10 +1,11 @@ export const WhileStatement = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, whileKeyword: ast.whileKeyword.text, openParen: ast.openParen.text, - condition: parse(ast.condition, options, parse), + condition: parse(ast.condition, options, parse, offsets), closeParen: ast.closeParen.text, - body: parse(ast.body, options, parse) + body: parse(ast.body, options, parse, offsets) }), print: ({ node, path, print }) => [ node.whileKeyword, diff --git a/src/slang-nodes/YulArguments.js b/src/slang-nodes/YulArguments.js index 97cfcadaa..2315f4850 100644 --- a/src/slang-nodes/YulArguments.js +++ b/src/slang-nodes/YulArguments.js @@ -1,6 +1,7 @@ export const YulArguments = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), print: ({ node, path, print }) => diff --git a/src/slang-nodes/YulAssignmentOperator.js b/src/slang-nodes/YulAssignmentOperator.js index 0c1421168..41384807e 100644 --- a/src/slang-nodes/YulAssignmentOperator.js +++ b/src/slang-nodes/YulAssignmentOperator.js @@ -1,9 +1,10 @@ export const YulAssignmentOperator = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, variant: ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, options, parse) + : parse(ast.variant, options, parse, offsets) }), print: ({ node, path, print }) => typeof node.variant === 'string' diff --git a/src/slang-nodes/YulAssignmentStatement.js b/src/slang-nodes/YulAssignmentStatement.js index d02699d16..394674c65 100644 --- a/src/slang-nodes/YulAssignmentStatement.js +++ b/src/slang-nodes/YulAssignmentStatement.js @@ -1,8 +1,9 @@ export const YulAssignmentStatement = { - parse: ({ ast, options, parse }) => ({ - names: parse(ast.names, options, parse), - assignment: parse(ast.assignment, options, parse), - expression: parse(ast.expression, options, parse) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + names: parse(ast.names, options, parse, offsets), + assignment: parse(ast.assignment, options, parse, offsets), + expression: parse(ast.expression, options, parse, offsets) }), print: ({ path, print }) => [ path.call(print, 'names'), diff --git a/src/slang-nodes/YulBlock.js b/src/slang-nodes/YulBlock.js index d786a209e..9cb844219 100644 --- a/src/slang-nodes/YulBlock.js +++ b/src/slang-nodes/YulBlock.js @@ -4,9 +4,10 @@ import { printSeparatedItem } from '../common/printer-helpers.js'; const { hardline } = doc.builders; export const YulBlock = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, openBrace: ast.openBrace.text, - statements: parse(ast.statements, options, parse), + statements: parse(ast.statements, options, parse, offsets), closeBrace: ast.closeBrace.text }), print: ({ node, print }) => [ diff --git a/src/slang-nodes/YulBreakStatement.js b/src/slang-nodes/YulBreakStatement.js index 4062e1a00..5b955ae22 100644 --- a/src/slang-nodes/YulBreakStatement.js +++ b/src/slang-nodes/YulBreakStatement.js @@ -1,5 +1,6 @@ export const YulBreakStatement = { - parse: ({ ast }) => ({ + parse: ({ node, offsets, ast }) => ({ + ...node, breakKeyword: ast.breakKeyword.text }), print: ({ node }) => node.breakKeyword diff --git a/src/slang-nodes/YulBuiltInFunction.js b/src/slang-nodes/YulBuiltInFunction.js index ce31570da..293de3024 100644 --- a/src/slang-nodes/YulBuiltInFunction.js +++ b/src/slang-nodes/YulBuiltInFunction.js @@ -1,5 +1,6 @@ export const YulBuiltInFunction = { - parse: ({ ast }) => ({ + parse: ({ node, offsets, ast }) => ({ + ...node, variant: ast.variant.text }), print: ({ node }) => node.variant diff --git a/src/slang-nodes/YulColonAndEqual.js b/src/slang-nodes/YulColonAndEqual.js index e9a02962a..b5ea7ee63 100644 --- a/src/slang-nodes/YulColonAndEqual.js +++ b/src/slang-nodes/YulColonAndEqual.js @@ -1,5 +1,6 @@ export const YulColonAndEqual = { - parse: ({ ast }) => ({ + parse: ({ node, offsets, ast }) => ({ + ...node, colon: ast.colon.text, equal: ast.equal.text }), diff --git a/src/slang-nodes/YulContinueStatement.js b/src/slang-nodes/YulContinueStatement.js index d70042ed8..71116e627 100644 --- a/src/slang-nodes/YulContinueStatement.js +++ b/src/slang-nodes/YulContinueStatement.js @@ -1,5 +1,6 @@ export const YulContinueStatement = { - parse: ({ ast }) => ({ + parse: ({ node, offsets, ast }) => ({ + ...node, continueKeyword: ast.continueKeyword.text }), print: ({ node }) => node.continueKeyword diff --git a/src/slang-nodes/YulDefaultCase.js b/src/slang-nodes/YulDefaultCase.js index 783e32950..613bcad07 100644 --- a/src/slang-nodes/YulDefaultCase.js +++ b/src/slang-nodes/YulDefaultCase.js @@ -1,7 +1,8 @@ export const YulDefaultCase = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, defaultKeyword: ast.defaultKeyword.text, - body: parse(ast.body, options, parse) + body: parse(ast.body, options, parse, offsets) }), print: ({ node, path, print }) => [ `${node.defaultKeyword} `, diff --git a/src/slang-nodes/YulExpression.js b/src/slang-nodes/YulExpression.js index 9d3d65441..f65922494 100644 --- a/src/slang-nodes/YulExpression.js +++ b/src/slang-nodes/YulExpression.js @@ -1,6 +1,7 @@ export const YulExpression = { - parse: ({ ast, options, parse }) => ({ - variant: parse(ast.variant, options, parse) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + variant: parse(ast.variant, options, parse, offsets) }), print: ({ path, print }) => path.call(print, 'variant') }; diff --git a/src/slang-nodes/YulForStatement.js b/src/slang-nodes/YulForStatement.js index a785388e4..3b5f1854d 100644 --- a/src/slang-nodes/YulForStatement.js +++ b/src/slang-nodes/YulForStatement.js @@ -1,10 +1,11 @@ export const YulForStatement = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, forKeyword: ast.forKeyword.text, - initialization: parse(ast.initialization, options, parse), - condition: parse(ast.condition, options, parse), - iterator: parse(ast.iterator, options, parse), - body: parse(ast.body, options, parse) + initialization: parse(ast.initialization, options, parse, offsets), + condition: parse(ast.condition, options, parse, offsets), + iterator: parse(ast.iterator, options, parse, offsets), + body: parse(ast.body, options, parse, offsets) }), print: ({ node, path, print }) => [ node.forKeyword, diff --git a/src/slang-nodes/YulFunctionCallExpression.js b/src/slang-nodes/YulFunctionCallExpression.js index 07673b70b..0269d4de0 100644 --- a/src/slang-nodes/YulFunctionCallExpression.js +++ b/src/slang-nodes/YulFunctionCallExpression.js @@ -1,8 +1,9 @@ export const YulFunctionCallExpression = { - parse: ({ ast, options, parse }) => ({ - operand: parse(ast.operand, options, parse), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + operand: parse(ast.operand, options, parse, offsets), openParen: ast.openParen.text, - arguments: parse(ast.arguments, options, parse), + arguments: parse(ast.arguments, options, parse, offsets), closeParen: ast.closeParen.text }), print: ({ node, path, print }) => [ diff --git a/src/slang-nodes/YulFunctionDefinition.js b/src/slang-nodes/YulFunctionDefinition.js index 105b2ab1d..602ff2aa5 100644 --- a/src/slang-nodes/YulFunctionDefinition.js +++ b/src/slang-nodes/YulFunctionDefinition.js @@ -1,10 +1,13 @@ export const YulFunctionDefinition = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, functionKeyword: ast.functionKeyword.text, name: ast.name.text, - parameters: parse(ast.parameters, options, parse), - returns: ast.returns ? parse(ast.returns, options, parse) : undefined, - body: parse(ast.body, options, parse) + parameters: parse(ast.parameters, options, parse, offsets), + returns: ast.returns + ? parse(ast.returns, options, parse, offsets) + : undefined, + body: parse(ast.body, options, parse, offsets) }), print: ({ node, path, print }) => [ node.functionKeyword, diff --git a/src/slang-nodes/YulIfStatement.js b/src/slang-nodes/YulIfStatement.js index a0ee76d72..66a88ad3e 100644 --- a/src/slang-nodes/YulIfStatement.js +++ b/src/slang-nodes/YulIfStatement.js @@ -1,8 +1,9 @@ export const YulIfStatement = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, ifKeyword: ast.ifKeyword.text, - condition: parse(ast.condition, options, parse), - body: parse(ast.body, options, parse) + condition: parse(ast.condition, options, parse, offsets), + body: parse(ast.body, options, parse, offsets) }), print: ({ node, path, print }) => [ node.ifKeyword, diff --git a/src/slang-nodes/YulLabel.js b/src/slang-nodes/YulLabel.js index 3a7f4ab0e..6c227b0b4 100644 --- a/src/slang-nodes/YulLabel.js +++ b/src/slang-nodes/YulLabel.js @@ -3,7 +3,8 @@ import { doc } from 'prettier'; const { dedent, line } = doc.builders; export const YulLabel = { - parse: ({ ast }) => ({ + parse: ({ node, offsets, ast }) => ({ + ...node, label: ast.label.text, colon: ast.colon.text }), diff --git a/src/slang-nodes/YulLeaveStatement.js b/src/slang-nodes/YulLeaveStatement.js index d014e23fe..516cbe5a0 100644 --- a/src/slang-nodes/YulLeaveStatement.js +++ b/src/slang-nodes/YulLeaveStatement.js @@ -1,5 +1,6 @@ export const YulLeaveStatement = { - parse: ({ ast }) => ({ + parse: ({ node, offsets, ast }) => ({ + ...node, leaveKeyword: ast.leaveKeyword.text }), // TODO: implement print diff --git a/src/slang-nodes/YulLiteral.js b/src/slang-nodes/YulLiteral.js index 998b403a5..89aac03ec 100644 --- a/src/slang-nodes/YulLiteral.js +++ b/src/slang-nodes/YulLiteral.js @@ -1,9 +1,10 @@ export const YulLiteral = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, variant: ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, options, parse) + : parse(ast.variant, options, parse, offsets) }), print: ({ node, path, print }) => typeof node.variant === 'string' diff --git a/src/slang-nodes/YulParameters.js b/src/slang-nodes/YulParameters.js index cdc084191..455eb0dd0 100644 --- a/src/slang-nodes/YulParameters.js +++ b/src/slang-nodes/YulParameters.js @@ -1,7 +1,8 @@ import { printSeparatedList } from '../common/printer-helpers.js'; export const YulParameters = { - parse: ({ ast }) => ({ + parse: ({ node, offsets, ast }) => ({ + ...node, items: ast.items.map((item) => item.text), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/YulParametersDeclaration.js b/src/slang-nodes/YulParametersDeclaration.js index bfe77ea3c..edc74ad7a 100644 --- a/src/slang-nodes/YulParametersDeclaration.js +++ b/src/slang-nodes/YulParametersDeclaration.js @@ -1,7 +1,8 @@ export const YulParametersDeclaration = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, openParen: ast.openParen.text, - parameters: parse(ast.parameters, options, parse), + parameters: parse(ast.parameters, options, parse, offsets), closeParen: ast.closeParen.text }), print: ({ node, path, print }) => [ diff --git a/src/slang-nodes/YulPath.js b/src/slang-nodes/YulPath.js index d2950f258..eec4fef55 100644 --- a/src/slang-nodes/YulPath.js +++ b/src/slang-nodes/YulPath.js @@ -1,6 +1,7 @@ export const YulPath = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), print: ({ node, path, print }) => diff --git a/src/slang-nodes/YulPathComponent.js b/src/slang-nodes/YulPathComponent.js index 411333dc8..8e9217645 100644 --- a/src/slang-nodes/YulPathComponent.js +++ b/src/slang-nodes/YulPathComponent.js @@ -1,5 +1,6 @@ export const YulPathComponent = { - parse: ({ ast }) => ({ + parse: ({ node, offsets, ast }) => ({ + ...node, variant: ast.variant.text }), print: ({ node }) => node.variant diff --git a/src/slang-nodes/YulPaths.js b/src/slang-nodes/YulPaths.js index 05d2cda92..7bb7d60a8 100644 --- a/src/slang-nodes/YulPaths.js +++ b/src/slang-nodes/YulPaths.js @@ -1,6 +1,7 @@ export const YulPaths = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)), + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), print: ({ node, path, print }) => diff --git a/src/slang-nodes/YulReturnVariables.js b/src/slang-nodes/YulReturnVariables.js index 10093aa1a..8a3bf6ea0 100644 --- a/src/slang-nodes/YulReturnVariables.js +++ b/src/slang-nodes/YulReturnVariables.js @@ -4,7 +4,8 @@ import { printSeparatedList } from '../common/printer-helpers.js'; const { line } = doc.builders; export const YulReturnVariables = { - parse: ({ ast }) => ({ + parse: ({ node, offsets, ast }) => ({ + ...node, items: ast.items.map((item) => item.text), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/YulReturnsDeclaration.js b/src/slang-nodes/YulReturnsDeclaration.js index c14565895..6e4906bd2 100644 --- a/src/slang-nodes/YulReturnsDeclaration.js +++ b/src/slang-nodes/YulReturnsDeclaration.js @@ -4,9 +4,10 @@ import { printSeparatedItem } from '../common/printer-helpers.js'; const { line } = doc.builders; export const YulReturnsDeclaration = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, minusGreaterThan: ast.minusGreaterThan.text, - variables: parse(ast.variables, options, parse) + variables: parse(ast.variables, options, parse, offsets) }), print: ({ node, path, print }) => printSeparatedItem([node.minusGreaterThan, path.call(print, 'variables')], { diff --git a/src/slang-nodes/YulStatement.js b/src/slang-nodes/YulStatement.js index 246fdb308..ef8163da0 100644 --- a/src/slang-nodes/YulStatement.js +++ b/src/slang-nodes/YulStatement.js @@ -1,6 +1,7 @@ export const YulStatement = { - parse: ({ ast, options, parse }) => ({ - variant: parse(ast.variant, options, parse) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + variant: parse(ast.variant, options, parse, offsets) }), print: ({ path, print }) => path.call(print, 'variant') }; diff --git a/src/slang-nodes/YulStatements.js b/src/slang-nodes/YulStatements.js index 66536e972..cfcf095e8 100644 --- a/src/slang-nodes/YulStatements.js +++ b/src/slang-nodes/YulStatements.js @@ -1,8 +1,9 @@ -import { printPreservingEmptyLines } from '../common/printer-helpers.js'; +import { printPreservingEmptyLines } from '../common/slang-helpers.js'; export const YulStatements = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ path, print, options }) => printPreservingEmptyLines(path, 'items', options, print) diff --git a/src/slang-nodes/YulSwitchCase.js b/src/slang-nodes/YulSwitchCase.js index 363e57eb9..8b9f4b41c 100644 --- a/src/slang-nodes/YulSwitchCase.js +++ b/src/slang-nodes/YulSwitchCase.js @@ -1,6 +1,7 @@ export const YulSwitchCase = { - parse: ({ ast, options, parse }) => ({ - variant: parse(ast.variant, options, parse) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + variant: parse(ast.variant, options, parse, offsets) }), print: ({ path, print }) => path.call(print, 'variant') }; diff --git a/src/slang-nodes/YulSwitchCases.js b/src/slang-nodes/YulSwitchCases.js index 6ea070dd0..4b7ce9eb2 100644 --- a/src/slang-nodes/YulSwitchCases.js +++ b/src/slang-nodes/YulSwitchCases.js @@ -3,8 +3,9 @@ import { doc } from 'prettier'; const { hardline, join } = doc.builders; export const YulSwitchCases = { - parse: ({ ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse)) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ path, print }) => join(hardline, path.map(print, 'items')) }; diff --git a/src/slang-nodes/YulSwitchStatement.js b/src/slang-nodes/YulSwitchStatement.js index f29a2ccb3..8c12440cd 100644 --- a/src/slang-nodes/YulSwitchStatement.js +++ b/src/slang-nodes/YulSwitchStatement.js @@ -3,10 +3,11 @@ import { doc } from 'prettier'; const { hardline } = doc.builders; export const YulSwitchStatement = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, switchKeyword: ast.switchKeyword.text, - expression: parse(ast.expression, options, parse), - cases: parse(ast.cases, options, parse) + expression: parse(ast.expression, options, parse, offsets), + cases: parse(ast.cases, options, parse, offsets) }), print: ({ node, path, print }) => [ node.switchKeyword, diff --git a/src/slang-nodes/YulValueCase.js b/src/slang-nodes/YulValueCase.js index 09218cbbd..cd866a8e5 100644 --- a/src/slang-nodes/YulValueCase.js +++ b/src/slang-nodes/YulValueCase.js @@ -1,8 +1,9 @@ export const YulValueCase = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, caseKeyword: ast.caseKeyword.text, - value: parse(ast.value, options, parse), - body: parse(ast.body, options, parse) + value: parse(ast.value, options, parse, offsets), + body: parse(ast.body, options, parse, offsets) }), print: ({ node, path, print }) => [ `${node.caseKeyword} `, diff --git a/src/slang-nodes/YulVariableAssignmentStatement.js b/src/slang-nodes/YulVariableAssignmentStatement.js index f3acb32e9..7324fe37e 100644 --- a/src/slang-nodes/YulVariableAssignmentStatement.js +++ b/src/slang-nodes/YulVariableAssignmentStatement.js @@ -1,8 +1,9 @@ export const YulVariableAssignmentStatement = { - parse: ({ ast, options, parse }) => ({ - names: parse(ast.names, options, parse), - assignment: parse(ast.assignment, options, parse), - expression: parse(ast.expression, options, parse) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + names: parse(ast.names, options, parse, offsets), + assignment: parse(ast.assignment, options, parse, offsets), + expression: parse(ast.expression, options, parse, offsets) }), print: ({ path, print }) => [ path.call(print, 'names'), diff --git a/src/slang-nodes/YulVariableDeclarationStatement.js b/src/slang-nodes/YulVariableDeclarationStatement.js index 2b426cbe2..51bec30c5 100644 --- a/src/slang-nodes/YulVariableDeclarationStatement.js +++ b/src/slang-nodes/YulVariableDeclarationStatement.js @@ -1,8 +1,9 @@ export const YulVariableDeclarationStatement = { - parse: ({ ast, options, parse }) => ({ + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, letKeyword: ast.letKeyword.text, names: ast.names.text, - value: ast.value ? parse(ast.value, options, parse) : undefined + value: ast.value ? parse(ast.value, options, parse, offsets) : undefined }), print: ({ node, path, print }) => [ node.letKeyword, diff --git a/src/slang-nodes/YulVariableDeclarationValue.js b/src/slang-nodes/YulVariableDeclarationValue.js index a259478a2..c232566f7 100644 --- a/src/slang-nodes/YulVariableDeclarationValue.js +++ b/src/slang-nodes/YulVariableDeclarationValue.js @@ -1,7 +1,8 @@ export const YulVariableDeclarationValue = { - parse: ({ ast, options, parse }) => ({ - assignment: parse(ast.assignment, options, parse), - expression: parse(ast.expression, options, parse) + parse: ({ node, offsets, ast, options, parse }) => ({ + ...node, + assignment: parse(ast.assignment, options, parse, offsets), + expression: parse(ast.expression, options, parse, offsets) }), print: ({ path, print }) => [ path.call(print, 'assignment'), diff --git a/src/slangParser.js b/src/slangParser.js index 67ef92285..20fee589c 100644 --- a/src/slangParser.js +++ b/src/slangParser.js @@ -6,16 +6,61 @@ import { SourceUnit } from '@nomicfoundation/slang/ast/index.js'; import coerce from 'semver/functions/coerce.js'; import * as parsers from './slang-nodes/index.js'; -function genericParse(ast, options, parseFunction) { - const data = parsers[ast.cst.kind].parse({ +const commentKinds = [ + 'MultiLineComment', + 'MultiLineNatSpecComment', + 'SingleLineComment', + 'SingleLineNatSpecComment' +]; + +const getCommentsAndOffsets = (ast, nodeOffset) => { + const children = ast.cst.children(); + let offset = nodeOffset; + return children.reduce( + (commentsAndOffsets, child) => { + if (child.type === 'Nonterminal') { + commentsAndOffsets.offsets.push(offset); + } + if (child.type === 'Terminal' && commentKinds.includes(child.kind)) { + commentsAndOffsets.comments.push({ + value: child.text, + loc: { + start: offset, + end: offset + child.textLength.utf8 - 1 + } + }); + } + offset += child.textLength.utf8; + return commentsAndOffsets; + }, + { comments: [], offsets: [] } + ); +}; + +function genericParse(ast, options, parseFunction, parentOffsets = [0]) { + const offset = parentOffsets.shift(); + const { comments, offsets } = getCommentsAndOffsets(ast, offset); + // console.log(comments); + // console.log(offsets); + + let node = { + kind: ast.cst.kind, + loc: { + start: offset, + end: offset + ast.cst.textLength.utf8 - 1 + } + // comments + }; + + node = parsers[ast.cst.kind].parse({ + node, + offsets, ast, options, parse: parseFunction }); - data.kind = ast.cst.kind; - - return data; + return node; } function parse(text, _parsers, options = _parsers) { diff --git a/tests/format/AddressPayable/__snapshots__/jsfmt.spec.js.snap b/tests/format/AddressPayable/__snapshots__/jsfmt.spec.js.snap index a79eb8a39..02ac3b22f 100644 --- a/tests/format/AddressPayable/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/AddressPayable/__snapshots__/jsfmt.spec.js.snap @@ -54,6 +54,7 @@ contract AddressPayable { =====================================output===================================== pragma solidity ^0.5.2; + contract AddressPayable { using Address for address payable; address payable[] hello; diff --git a/tests/format/Arrays/__snapshots__/jsfmt.spec.js.snap b/tests/format/Arrays/__snapshots__/jsfmt.spec.js.snap index 266fa4f35..b1c2abec6 100644 --- a/tests/format/Arrays/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Arrays/__snapshots__/jsfmt.spec.js.snap @@ -88,6 +88,7 @@ contract ArraySlices { =====================================output===================================== pragma solidity ^0.5.2; + contract Arrays { bytes32[] public permissions = [ bytes32("addPartner"), @@ -103,6 +104,7 @@ contract Arrays { bytes32("addPermissionToGroup"), bytes32("removePermissionFromGroup") ]; + function a() { Outcome.OutcomeItem[] memory outcomeFrom = abi.decode( fromPart.outcome, @@ -110,6 +112,7 @@ contract Arrays { ); } } + contract ArraySlices { function f(bytes calldata x) public { bytes memory a1 = abi.decode(x[:], (bytes)); diff --git a/tests/format/Assembly/__snapshots__/jsfmt.spec.js.snap b/tests/format/Assembly/__snapshots__/jsfmt.spec.js.snap index c3340b15c..f8dbd1811 100644 --- a/tests/format/Assembly/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Assembly/__snapshots__/jsfmt.spec.js.snap @@ -769,6 +769,7 @@ contract Assembly { } } } + function caseAssembly() { assembly { switch value @@ -780,6 +781,7 @@ contract Assembly { } } } + function forAssembly() { assembly { for { @@ -791,11 +793,13 @@ contract Assembly { } } } + function callWithComments() { assembly { f(1,2,3) } } + function assemblyFunctionNoParameters() { assembly { function getAnswer() -> answer { @@ -803,6 +807,7 @@ contract Assembly { } } } + function assemblyFunctionOneParameter() { assembly { function inc(x) -> result { @@ -810,6 +815,7 @@ contract Assembly { } } } + function assemblyFunctionThreeParameters() { assembly { function sum(a, b, c) -> result { @@ -817,6 +823,7 @@ contract Assembly { } } } + function assemblyFunctionLongParameters() { assembly { function sum( @@ -830,6 +837,7 @@ contract Assembly { } } } + function assemblyFunctionLongReturnParameters() { assembly { function sum(a, b, c, d, e) @@ -848,6 +856,7 @@ contract Assembly { } } } + function assemblyFunctionLongParametersAndReturnParameters() { assembly { function sum( @@ -873,11 +882,13 @@ contract Assembly { } } } + function assemblyNoParameterCalls() { assembly { call(gas(),to,value,inputData,inputDataSize,0,0) } } + function assemblyLabels() { assembly { let n := calldataload(4) @@ -885,12 +896,14 @@ contract Assembly { let b := a loop } + assembly { let x := 8 jump(two) one } } + function assemblyFunctionNoReturn() { assembly { function $somefn(somearg) { @@ -898,22 +911,26 @@ contract Assembly { } } } + function letWithoutValue() { assembly { let result } } + function memberAccess() { assembly { ds.slot := position offset := x.offset } } + function commentsInAssemblyBlock() { assembly { } } + function withBreak() { assembly { for { @@ -925,6 +942,7 @@ contract Assembly { } } } + function memorySafe() { assembly ("memory-safe") { @@ -933,6 +951,7 @@ contract Assembly { } } + function continueAndBreak(uint256 x) public pure returns (uint a, uint b) { assembly { for { @@ -947,11 +966,13 @@ contract Assembly { if eq(i,15) { break } + b := i } } } } + contract BooleanLiteralsInAssembly { function f() { uint a; @@ -961,6 +982,7 @@ contract BooleanLiteralsInAssembly { } } } + contract MultipleAssemblyAssignement { function foo() public pure { assembly { @@ -968,10 +990,12 @@ contract MultipleAssemblyAssignement { a := 1 b := 2 } + let i } } } + contract AssemblyStackAssignment { function f() public { assembly { diff --git a/tests/format/AssemblyV0.4.26/__snapshots__/jsfmt.spec.js.snap b/tests/format/AssemblyV0.4.26/__snapshots__/jsfmt.spec.js.snap index 247bc7d3c..a5fb69f04 100644 --- a/tests/format/AssemblyV0.4.26/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/AssemblyV0.4.26/__snapshots__/jsfmt.spec.js.snap @@ -133,6 +133,7 @@ assembly{ =====================================output===================================== pragma solidity ^0.4.26; + contract Assembly { function assemblyLabels() { assembly { @@ -146,10 +147,12 @@ contract Assembly { swap1 n := sub(n,1) jump(loop) + loopend: mstore(0,a) return(0,0x20) } + assembly { let x := 8 jump(two) diff --git a/tests/format/BasicIterator/__snapshots__/jsfmt.spec.js.snap b/tests/format/BasicIterator/__snapshots__/jsfmt.spec.js.snap index 97e8c58c3..1d089b8c3 100644 --- a/tests/format/BasicIterator/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/BasicIterator/__snapshots__/jsfmt.spec.js.snap @@ -56,6 +56,7 @@ contract BasicIterator { contract BasicIterator { address creator; uint8[10] integers; + function BasicIterator() { creator = msg.sender; uint8 x = 0; @@ -64,6 +65,7 @@ contract BasicIterator { x++; } } + function getSum() constant returns (uint) { uint8 sum = 0; uint8 x = 0; @@ -73,6 +75,7 @@ contract BasicIterator { } return sum; } + function kill() { if (msg.sender == creator) { suicide(creator); diff --git a/tests/format/BinaryOperators/__snapshots__/jsfmt.spec.js.snap b/tests/format/BinaryOperators/__snapshots__/jsfmt.spec.js.snap index a9c06dcac..9dae74e33 100644 --- a/tests/format/BinaryOperators/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/BinaryOperators/__snapshots__/jsfmt.spec.js.snap @@ -280,6 +280,7 @@ contract ArithmeticOperators { ) + c; } } + contract ArithmeticOperators { function someFunction() { a ** b; @@ -365,6 +366,7 @@ contract ArithmeticOperators { ) ** c; } } + contract ShiftOperators { function someFunction() { a << b; @@ -394,6 +396,7 @@ contract ShiftOperators { veryVeryVeryVeryVeryLongVariableCalledB; } } + contract BitOperators { function someFunction() { a & b; @@ -426,6 +429,7 @@ contract BitOperators { veryVeryVeryVeryVeryLongVariableCalledB; } } + contract ComparisonOperators { function someFunction() { a < b; @@ -507,6 +511,7 @@ contract ComparisonOperators { ) == c; } } + contract AssignmentOperators { function someFunction() { a = veryVeryVeryVeryVeryLongVariableCalledA; @@ -555,6 +560,7 @@ contract AssignmentOperators { veryVeryVeryVeryVeryLongFunctionCalledB(c); } } + contract LogicalOperators { function someFunction() { a && b; @@ -1482,6 +1488,7 @@ contract Parentheses { =====================================output===================================== pragma solidity 0.5.8; + contract Parentheses { function() { a + b + c; diff --git a/tests/format/BreakingChangesV0.7.4/__snapshots__/jsfmt.spec.js.snap b/tests/format/BreakingChangesV0.7.4/__snapshots__/jsfmt.spec.js.snap index b4f8f1a4d..9ef8f6e99 100644 --- a/tests/format/BreakingChangesV0.7.4/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/BreakingChangesV0.7.4/__snapshots__/jsfmt.spec.js.snap @@ -50,6 +50,7 @@ import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from " =====================================output===================================== pragma solidity ^0.7.0; + import { symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4 } from "File2.sol"; ================================================================================ @@ -107,6 +108,7 @@ import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from " =====================================output===================================== pragma solidity ^0.7.0; + import { symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4 } from "File2.sol"; ================================================================================ @@ -162,6 +164,7 @@ import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from " =====================================output===================================== pragma solidity ^0.7.0; + import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol"; ================================================================================ @@ -224,6 +227,7 @@ import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from " =====================================output===================================== pragma solidity ^0.7.0; + import { symbol1 as alias1, symbol2 as alias2, @@ -289,6 +293,7 @@ import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from " =====================================output===================================== pragma solidity ^0.7.0; + import { symbol1 as alias1, symbol2 as alias2, @@ -347,6 +352,7 @@ import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from " =====================================output===================================== pragma solidity ^0.7.0; + import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol"; ================================================================================ diff --git a/tests/format/BreakingChangesV0.8.0/__snapshots__/jsfmt.spec.js.snap b/tests/format/BreakingChangesV0.8.0/__snapshots__/jsfmt.spec.js.snap index 6e12b0321..b126fe0e6 100644 --- a/tests/format/BreakingChangesV0.8.0/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/BreakingChangesV0.8.0/__snapshots__/jsfmt.spec.js.snap @@ -147,13 +147,17 @@ contract BreakingChangesV080 { =====================================output===================================== contract BreakingChangesV080 { uint a = 1 ** 2 ** 3; + bytes1 public c; byte public g; + struct S { bytes1 c; byte g; } + event Event(bytes1 _c, byte _g); + function func(bytes1 _c, byte _g) public returns (bytes1, byte) { emit Event(_c, _g); return (_c, _g); diff --git a/tests/format/Comments/__snapshots__/jsfmt.spec.js.snap b/tests/format/Comments/__snapshots__/jsfmt.spec.js.snap index 985b3e2b0..cbaff7fe3 100644 --- a/tests/format/Comments/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Comments/__snapshots__/jsfmt.spec.js.snap @@ -168,10 +168,13 @@ contract Comments13 { } =====================================output===================================== pragma solidity ^0.4.24; + contract Comments1 { IEIP712DomainSeparator private EIP712domainSeparator; bytes32 private _CACHED_DOMAIN_SEPARATOR; + function() {} + function hello() public modifier1 @@ -182,7 +185,9 @@ contract Comments1 { modifier6 {} } + contract Comments2 {} + contract Comments3 is Interface1, Interface2, @@ -193,6 +198,7 @@ contract Comments3 is { function someFunction() {} } + contract Comments4 is Interface1, Interface2, @@ -201,7 +207,9 @@ contract Comments4 is Interface5, Interface6 {} + contract Comments5 {} + contract Comments6 is Interface1, Interface2, @@ -210,36 +218,45 @@ contract Comments6 is Interface5, Interface6 {} + contract Comments7 { function someFunction(uint a, uint b, uint c) { someFunction(a, b, c); } } + contract Comments8 { function someFunction() { if (something) {} else {} } } + contract Comments8 { function someFunction() { if (something) {} else {} } } + contract Comments9 { function someFunction() { if (something) f(); else {} } } + interface Comments10 { function someFunction() external; + function someOtherFunction() external; } + contract Comments11 { string a = "\\\\"; string b = "\\\\"; + function f() public {} } + contract Comments12 { function f() public { purchaseData[0] = DomainPurchaseData({ @@ -250,6 +267,7 @@ contract Comments12 { }); } } + contract Comments13 { function commentInModifierInvocation() external diff --git a/tests/format/Conditional/__snapshots__/jsfmt.spec.js.snap b/tests/format/Conditional/__snapshots__/jsfmt.spec.js.snap index 5afe671f6..a978e8959 100644 --- a/tests/format/Conditional/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Conditional/__snapshots__/jsfmt.spec.js.snap @@ -114,6 +114,7 @@ contract Conditional { =====================================output===================================== pragma solidity ^0.4.24; + contract Conditional { function foo() { address contextAddress = longAddress_ == address(0) @@ -143,6 +144,7 @@ contract Conditional { ) : false; } + function bar() { uint a = true ? 0 : 1; } diff --git a/tests/format/Constructors/__snapshots__/jsfmt.spec.js.snap b/tests/format/Constructors/__snapshots__/jsfmt.spec.js.snap index c7ec34220..ee5e0571c 100644 --- a/tests/format/Constructors/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Constructors/__snapshots__/jsfmt.spec.js.snap @@ -67,10 +67,12 @@ contract Constructors is Ownable, Changeable { =====================================output===================================== pragma solidity ^0.5.2; + contract Constructors is Ownable, Changeable { function Constructors( variable1 ) public Changeable(variable1) Ownable() onlyOwner {} + constructor( variable1, variable2, diff --git a/tests/format/CustomErrors/__snapshots__/jsfmt.spec.js.snap b/tests/format/CustomErrors/__snapshots__/jsfmt.spec.js.snap index 870679355..7b2b5ced6 100644 --- a/tests/format/CustomErrors/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/CustomErrors/__snapshots__/jsfmt.spec.js.snap @@ -78,13 +78,16 @@ contract CustomErrors { =====================================output===================================== pragma solidity ^0.8.4; + error TopLevelCustomError(); error TopLevelCustomErrorWithArg(uint x); error TopLevelCustomErrorArgWithoutName(string); + contract CustomErrors { error ContractCustomError(); error ContractCustomErrorWithArg(uint x); error ContractCustomErrorArgWithoutName(string); + function throwCustomError() { revert FunctionCustomError(); revert FunctionCustomErrorWithArg(1); diff --git a/tests/format/Etc/__snapshots__/jsfmt.spec.js.snap b/tests/format/Etc/__snapshots__/jsfmt.spec.js.snap index 483a36f3b..d2da88d19 100644 --- a/tests/format/Etc/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Etc/__snapshots__/jsfmt.spec.js.snap @@ -190,6 +190,7 @@ contract Contract { =====================================output===================================== pragma solidity ^0.4.24; + contract Contract { struct StructWithFunctionTypes { function (uint, uint) returns (bool) a; @@ -230,25 +231,31 @@ contract Contract { bytes32 ) internal view [] e; } + event SomeEvent(); + modifier modifierWithoutParams() { require(msg.sender != address(0)); _; } + modifier modifierWithParams(address x) { require(msg.sender != x); _; } + function ifBlockInOneLine(uint a) returns (uint b) { if (a < 0) b = 0x67; else if (a == 0) b = 0x12; else b = 0x78; } + function forWithoutBlock() { uint i; uint sum; for (i = 0; i < 10; i++) sum += i; } + function fun(uint256 a) returns (uint) { if (something) foo(); else if (somethingElse) bar(); diff --git a/tests/format/ExperimentalTernaries/__snapshots__/jsfmt.spec.js.snap b/tests/format/ExperimentalTernaries/__snapshots__/jsfmt.spec.js.snap index ee88f37ab..7cf940966 100644 --- a/tests/format/ExperimentalTernaries/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/ExperimentalTernaries/__snapshots__/jsfmt.spec.js.snap @@ -770,6 +770,7 @@ string storage typeofExampleFlipped = =====================================output===================================== pragma solidity ^0.4.24; + contract Conditional { function blogPostExample() { string storage animalName = pet.canBark() ? @@ -778,10 +779,12 @@ contract Conditional { : "dog" : pet.canMeow() ? "cat" : "probably a bunny"; + string storage animalName = pet.isScary() ? "wolf" : pet.canBark() ? "dog" : pet.canMeow() ? "cat" : "probably a bunny"; + string storage animalName = pet.canSqueak() ? "mouse" : pet.canBark() ? pet.isScary() ? @@ -791,14 +794,18 @@ contract Conditional { : pet.canSqueak() ? "mouse" : "probably a bunny"; } + function examples1() { string storage short = isLoud() ? makeNoise() : silent(); + string storage lessShort = isLoudReallyLoud() ? makeNoiseReallyLoudly.omgSoLoud() : silent(); + string storage andIndented = isLoudReallyReallyReallyReallyLoud() ? makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() : silent(); + string storage indentationInFalseExpression = ( isLoudReallyReallyReallyReallyLoud() ) ? @@ -806,24 +813,29 @@ contract Conditional { : someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens(); + string storage shortSoCase = isLoudReallyReallyReallyReallyLoud() ? silent() : (makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud()); + string storage chainedShort = isCat() ? meow() : isDog() ? bark() : silent(); + string storage chainedWithLongConsequent = isCat() ? someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens() : isDog() ? bark() : silent(); + string storage chainedWithTernaryConsequent = isCat() ? aNestedCondition ? theResult() : theAlternate() : isDog() ? bark() : silent(); + string storage consequentAndTerminalAlternateBreak = isCat() ? someReallyLargeExpression .thatWouldCauseALineBreak() @@ -832,64 +844,70 @@ contract Conditional { : someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens(); + string storage multilineConditionsConsequentsAndAlternates = ( isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) + (someReallyLongCondition || moreInThisLongCondition) ) ? someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens() : ( isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) + (someReallyLongCondition || moreInThisLongCondition) ) ? bark() : shortCondition() ? shortConsequent() : someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens(); + assignment = ( isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) + (someReallyLongCondition || moreInThisLongCondition) ) ? someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens() : ( isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) + (someReallyLongCondition || moreInThisLongCondition) ) ? bark() : shortCondition() ? shortConsequent() : someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens(); + string storage mostlyShort = x == 1 ? "one" : x == 2 ? "two" : x == 3 ? "three" : ( x == 5 && - y == 7 && - someOtherThing.thatIsSoLong.thatItBreaksTheTestCondition() + y == 7 && + someOtherThing.thatIsSoLong.thatItBreaksTheTestCondition() ) ? "four" : x == 6 ? "six" : "idk"; + string storage longConditional = ( bifornCringerMoshedPerplexSawder == 2 / askTrovenaBeenaDependsRowans && - glimseGlyphsHazardNoopsTieTie >= - averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() + glimseGlyphsHazardNoopsTieTie >= + averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() ) ? "foo" : "bar"; + string storage longConditionalChained = ( bifornCringerMoshedPerplexSawder == 2 / askTrovenaBeenaDependsRowans && - glimseGlyphsHazardNoopsTieTie >= - averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() + glimseGlyphsHazardNoopsTieTie >= + averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() ) ? "foo" : anotherCondition ? "bar" : "baz"; + definition.encode( row[field] != "undefined" ? row[field] : definition.defaults != "undefined" ? definition.defaults @@ -900,6 +918,7 @@ contract Conditional { : definition.defaults : row[field] ); + (foo ? 1 : bar) ? 3 : 4; ( isCat() ? meow() @@ -908,23 +927,27 @@ contract Conditional { ) ? 1 : 2; + if (short) { return foo ? 1 : 2; } return row[aVeryLongFieldName] != "undefined" ? row[aVeryLongFieldName] : "null"; } + function examples2() { string storage message = i % 3 == 0 && i % 5 == 0 ? "fizzbuzz" : i % 3 == 0 ? "fizz" : i % 5 == 0 ? "buzz" : String(i); + string storage paymentMessageShort = state == "success" ? "Payment completed successfully" : state == "processing" ? "Payment processing" : state == "invalid_cvc" ? "There was an issue with your CVC number" : state == "invalid_expiry" ? "Expiry must be sometime in the past." : "There was an issue with the payment. Please contact support."; + string storage paymentMessageWithABreak = state == "success" ? "Payment completed successfully" : state == "processing" ? "Payment processing" @@ -932,6 +955,7 @@ contract Conditional { "There was an issue with your CVC number, and you need to take a prompt action on it." : state == "invalid_expiry" ? "Expiry must be sometime in the past." : "There was an issue with the payment. Please contact support."; + string storage typeofExample = definition.encode ? definition.encode( row[field] != "undefined" ? row[field] @@ -941,6 +965,7 @@ contract Conditional { : row[field] != "undefined" ? row[field] : definition.defaults != "undefined" ? definition.defaults : "null"; + string storage typeofExampleFlipped = definition.encode ? definition.encode( row[field] == "undefined" ? @@ -1734,6 +1759,7 @@ string storage typeofExampleFlipped = =====================================output===================================== pragma solidity ^0.4.24; + contract Conditional { function blogPostExample() { string storage animalName = pet.canBark() ? @@ -1742,10 +1768,12 @@ contract Conditional { : "dog" : pet.canMeow() ? "cat" : "probably a bunny"; + string storage animalName = pet.isScary() ? "wolf" : pet.canBark() ? "dog" : pet.canMeow() ? "cat" : "probably a bunny"; + string storage animalName = pet.canSqueak() ? "mouse" : pet.canBark() ? pet.isScary() ? @@ -1755,14 +1783,18 @@ contract Conditional { : pet.canSqueak() ? "mouse" : "probably a bunny"; } + function examples1() { string storage short = isLoud() ? makeNoise() : silent(); + string storage lessShort = isLoudReallyLoud() ? makeNoiseReallyLoudly.omgSoLoud() : silent(); + string storage andIndented = isLoudReallyReallyReallyReallyLoud() ? makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() : silent(); + string storage indentationInFalseExpression = ( isLoudReallyReallyReallyReallyLoud() ) ? @@ -1770,24 +1802,29 @@ contract Conditional { : someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens(); + string storage shortSoCase = isLoudReallyReallyReallyReallyLoud() ? silent() : (makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud()); + string storage chainedShort = isCat() ? meow() : isDog() ? bark() : silent(); + string storage chainedWithLongConsequent = isCat() ? someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens() : isDog() ? bark() : silent(); + string storage chainedWithTernaryConsequent = isCat() ? aNestedCondition ? theResult() : theAlternate() : isDog() ? bark() : silent(); + string storage consequentAndTerminalAlternateBreak = isCat() ? someReallyLargeExpression .thatWouldCauseALineBreak() @@ -1796,70 +1833,74 @@ contract Conditional { : someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens(); + string storage multilineConditionsConsequentsAndAlternates = ( isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) + (someReallyLongCondition || moreInThisLongCondition) ) ? someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens() : ( isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) + (someReallyLongCondition || moreInThisLongCondition) ) ? bark() : shortCondition() ? shortConsequent() : someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens(); + assignment = ( isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) + (someReallyLongCondition || moreInThisLongCondition) ) ? someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens() : ( isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) + (someReallyLongCondition || moreInThisLongCondition) ) ? bark() : shortCondition() ? shortConsequent() : someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens(); + string storage mostlyShort = x == 1 ? "one" : x == 2 ? "two" : x == 3 ? "three" : ( x == 5 && - y == 7 && - someOtherThing.thatIsSoLong.thatItBreaksTheTestCondition() + y == 7 && + someOtherThing.thatIsSoLong.thatItBreaksTheTestCondition() ) ? "four" : x == 6 ? "six" : "idk"; + string storage longConditional = ( bifornCringerMoshedPerplexSawder == 2 / askTrovenaBeenaDependsRowans && - glimseGlyphsHazardNoopsTieTie >= - averredBathersBoxroomBuggyNurl() - .anodyneCondosMalateOverateRetinol() + glimseGlyphsHazardNoopsTieTie >= + averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() ) ? "foo" : "bar"; + string storage longConditionalChained = ( bifornCringerMoshedPerplexSawder == 2 / askTrovenaBeenaDependsRowans && - glimseGlyphsHazardNoopsTieTie >= - averredBathersBoxroomBuggyNurl() - .anodyneCondosMalateOverateRetinol() + glimseGlyphsHazardNoopsTieTie >= + averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() ) ? "foo" : anotherCondition ? "bar" : "baz"; + definition.encode( row[field] != "undefined" ? row[field] : definition.defaults != "undefined" ? definition.defaults @@ -1870,6 +1911,7 @@ contract Conditional { : definition.defaults : row[field] ); + (foo ? 1 : bar) ? 3 : 4; ( isCat() ? meow() @@ -1878,23 +1920,27 @@ contract Conditional { ) ? 1 : 2; + if (short) { return foo ? 1 : 2; } return row[aVeryLongFieldName] != "undefined" ? row[aVeryLongFieldName] : "null"; } + function examples2() { string storage message = i % 3 == 0 && i % 5 == 0 ? "fizzbuzz" : i % 3 == 0 ? "fizz" : i % 5 == 0 ? "buzz" : String(i); + string storage paymentMessageShort = state == "success" ? "Payment completed successfully" : state == "processing" ? "Payment processing" : state == "invalid_cvc" ? "There was an issue with your CVC number" : state == "invalid_expiry" ? "Expiry must be sometime in the past." : "There was an issue with the payment. Please contact support."; + string storage paymentMessageWithABreak = state == "success" ? "Payment completed successfully" : state == "processing" ? "Payment processing" @@ -1902,6 +1948,7 @@ contract Conditional { "There was an issue with your CVC number, and you need to take a prompt action on it." : state == "invalid_expiry" ? "Expiry must be sometime in the past." : "There was an issue with the payment. Please contact support."; + string storage typeofExample = definition.encode ? definition.encode( row[field] != "undefined" ? row[field] @@ -1911,6 +1958,7 @@ contract Conditional { : row[field] != "undefined" ? row[field] : definition.defaults != "undefined" ? definition.defaults : "null"; + string storage typeofExampleFlipped = definition.encode ? definition.encode( row[field] == "undefined" ? @@ -2702,6 +2750,7 @@ string storage typeofExampleFlipped = =====================================output===================================== pragma solidity ^0.4.24; + contract Conditional { function blogPostExample() { string storage animalName = pet.canBark() ? @@ -2710,10 +2759,12 @@ contract Conditional { : "dog" : pet.canMeow() ? "cat" : "probably a bunny"; + string storage animalName = pet.isScary() ? "wolf" : pet.canBark() ? "dog" : pet.canMeow() ? "cat" : "probably a bunny"; + string storage animalName = pet.canSqueak() ? "mouse" : pet.canBark() ? pet.isScary() ? @@ -2723,14 +2774,18 @@ contract Conditional { : pet.canSqueak() ? "mouse" : "probably a bunny"; } + function examples1() { string storage short = isLoud() ? makeNoise() : silent(); + string storage lessShort = isLoudReallyLoud() ? makeNoiseReallyLoudly.omgSoLoud() : silent(); + string storage andIndented = isLoudReallyReallyReallyReallyLoud() ? makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() : silent(); + string storage indentationInFalseExpression = ( isLoudReallyReallyReallyReallyLoud() ) ? @@ -2738,24 +2793,29 @@ contract Conditional { : someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens(); + string storage shortSoCase = isLoudReallyReallyReallyReallyLoud() ? silent() : (makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud()); + string storage chainedShort = isCat() ? meow() : isDog() ? bark() : silent(); + string storage chainedWithLongConsequent = isCat() ? someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens() : isDog() ? bark() : silent(); + string storage chainedWithTernaryConsequent = isCat() ? aNestedCondition ? theResult() : theAlternate() : isDog() ? bark() : silent(); + string storage consequentAndTerminalAlternateBreak = isCat() ? someReallyLargeExpression .thatWouldCauseALineBreak() @@ -2764,70 +2824,74 @@ contract Conditional { : someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens(); + string storage multilineConditionsConsequentsAndAlternates = ( isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) + (someReallyLongCondition || moreInThisLongCondition) ) ? someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens() : ( isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) + (someReallyLongCondition || moreInThisLongCondition) ) ? bark() : shortCondition() ? shortConsequent() : someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens(); + assignment = ( isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) + (someReallyLongCondition || moreInThisLongCondition) ) ? someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens() : ( isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) + (someReallyLongCondition || moreInThisLongCondition) ) ? bark() : shortCondition() ? shortConsequent() : someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens(); + string storage mostlyShort = x == 1 ? "one" : x == 2 ? "two" : x == 3 ? "three" : ( x == 5 && - y == 7 && - someOtherThing.thatIsSoLong.thatItBreaksTheTestCondition() + y == 7 && + someOtherThing.thatIsSoLong.thatItBreaksTheTestCondition() ) ? "four" : x == 6 ? "six" : "idk"; + string storage longConditional = ( bifornCringerMoshedPerplexSawder == 2 / askTrovenaBeenaDependsRowans && - glimseGlyphsHazardNoopsTieTie >= - averredBathersBoxroomBuggyNurl() - .anodyneCondosMalateOverateRetinol() + glimseGlyphsHazardNoopsTieTie >= + averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() ) ? "foo" : "bar"; + string storage longConditionalChained = ( bifornCringerMoshedPerplexSawder == 2 / askTrovenaBeenaDependsRowans && - glimseGlyphsHazardNoopsTieTie >= - averredBathersBoxroomBuggyNurl() - .anodyneCondosMalateOverateRetinol() + glimseGlyphsHazardNoopsTieTie >= + averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() ) ? "foo" : anotherCondition ? "bar" : "baz"; + definition.encode( row[field] != "undefined" ? row[field] : definition.defaults != "undefined" ? definition.defaults @@ -2838,6 +2902,7 @@ contract Conditional { : definition.defaults : row[field] ); + (foo ? 1 : bar) ? 3 : 4; ( isCat() ? meow() @@ -2846,23 +2911,27 @@ contract Conditional { ) ? 1 : 2; + if (short) { return foo ? 1 : 2; } return row[aVeryLongFieldName] != "undefined" ? row[aVeryLongFieldName] : "null"; } + function examples2() { string storage message = i % 3 == 0 && i % 5 == 0 ? "fizzbuzz" : i % 3 == 0 ? "fizz" : i % 5 == 0 ? "buzz" : String(i); + string storage paymentMessageShort = state == "success" ? "Payment completed successfully" : state == "processing" ? "Payment processing" : state == "invalid_cvc" ? "There was an issue with your CVC number" : state == "invalid_expiry" ? "Expiry must be sometime in the past." : "There was an issue with the payment. Please contact support."; + string storage paymentMessageWithABreak = state == "success" ? "Payment completed successfully" : state == "processing" ? "Payment processing" @@ -2870,6 +2939,7 @@ contract Conditional { "There was an issue with your CVC number, and you need to take a prompt action on it." : state == "invalid_expiry" ? "Expiry must be sometime in the past." : "There was an issue with the payment. Please contact support."; + string storage typeofExample = definition.encode ? definition.encode( row[field] != "undefined" ? row[field] @@ -2879,6 +2949,7 @@ contract Conditional { : row[field] != "undefined" ? row[field] : definition.defaults != "undefined" ? definition.defaults : "null"; + string storage typeofExampleFlipped = definition.encode ? definition.encode( row[field] == "undefined" ? @@ -3681,6 +3752,7 @@ string storage typeofExampleFlipped = =====================================output===================================== pragma solidity ^0.4.24; + contract Conditional { function blogPostExample() { string storage animalName = pet.canBark() @@ -3690,6 +3762,7 @@ contract Conditional { : pet.canMeow() ? "cat" : "probably a bunny"; + string storage animalName = pet.isScary() ? "wolf" : pet.canBark() @@ -3697,6 +3770,7 @@ contract Conditional { : pet.canMeow() ? "cat" : "probably a bunny"; + string storage animalName = pet.canSqueak() ? "mouse" : pet.canBark() @@ -3709,27 +3783,34 @@ contract Conditional { ? "mouse" : "probably a bunny"; } + function examples1() { string storage short = isLoud() ? makeNoise() : silent(); + string storage lessShort = isLoudReallyLoud() ? makeNoiseReallyLoudly.omgSoLoud() : silent(); + string storage andIndented = isLoudReallyReallyReallyReallyLoud() ? makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() : silent(); + string storage indentationInFalseExpression = isLoudReallyReallyReallyReallyLoud() ? makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() : someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens(); + string storage shortSoCase = isLoudReallyReallyReallyReallyLoud() ? silent() : (makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud()); + string storage chainedShort = isCat() ? meow() : isDog() ? bark() : silent(); + string storage chainedWithLongConsequent = isCat() ? someReallyLargeExpression .thatWouldCauseALineBreak() @@ -3737,6 +3818,7 @@ contract Conditional { : isDog() ? bark() : silent(); + string storage chainedWithTernaryConsequent = isCat() ? aNestedCondition ? theResult() @@ -3744,6 +3826,7 @@ contract Conditional { : isDog() ? bark() : silent(); + string storage consequentAndTerminalAlternateBreak = isCat() ? someReallyLargeExpression .thatWouldCauseALineBreak() @@ -3753,6 +3836,7 @@ contract Conditional { : someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens(); + string storage multilineConditionsConsequentsAndAlternates = ( isAnAdorableKittyCat() && (someReallyLongCondition || moreInThisLongCondition) @@ -3770,6 +3854,7 @@ contract Conditional { : someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens(); + assignment = ( isAnAdorableKittyCat() && (someReallyLongCondition || moreInThisLongCondition) @@ -3787,6 +3872,7 @@ contract Conditional { : someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens(); + string storage mostlyShort = x == 1 ? "one" : x == 2 @@ -3804,6 +3890,7 @@ contract Conditional { : x == 6 ? "six" : "idk"; + string storage longConditional = ( bifornCringerMoshedPerplexSawder == 2 / @@ -3814,6 +3901,7 @@ contract Conditional { ) ? "foo" : "bar"; + string storage longConditionalChained = ( bifornCringerMoshedPerplexSawder == 2 / @@ -3826,6 +3914,7 @@ contract Conditional { : anotherCondition ? "bar" : "baz"; + definition.encode( row[field] != "undefined" ? row[field] @@ -3838,6 +3927,7 @@ contract Conditional { : definition.defaults : row[field] ); + (((foo ? 1 : bar))) ? 3 : 4; ( isCat() @@ -3848,6 +3938,7 @@ contract Conditional { ) ? 1 : 2; + if (short) { return foo ? 1 : 2; } @@ -3855,6 +3946,7 @@ contract Conditional { ? row[aVeryLongFieldName] : "null"; } + function examples2() { string storage message = i % 3 == 0 && i % 5 == 0 ? "fizzbuzz" @@ -3863,6 +3955,7 @@ contract Conditional { : i % 5 == 0 ? "buzz" : String(i); + string storage paymentMessageShort = state == "success" ? "Payment completed successfully" : state == "processing" @@ -3872,6 +3965,7 @@ contract Conditional { : state == "invalid_expiry" ? "Expiry must be sometime in the past." : "There was an issue with the payment. Please contact support."; + string storage paymentMessageWithABreak = state == "success" ? "Payment completed successfully" : state == "processing" @@ -3881,6 +3975,7 @@ contract Conditional { : state == "invalid_expiry" ? "Expiry must be sometime in the past." : "There was an issue with the payment. Please contact support."; + string storage typeofExample = definition.encode ? definition.encode( row[field] != "undefined" @@ -3894,6 +3989,7 @@ contract Conditional { : definition.defaults != "undefined" ? definition.defaults : "null"; + string storage typeofExampleFlipped = definition.encode ? definition.encode( row[field] == "undefined" diff --git a/tests/format/ForStatements/__snapshots__/jsfmt.spec.js.snap b/tests/format/ForStatements/__snapshots__/jsfmt.spec.js.snap index 9cb8ad225..855f120e6 100644 --- a/tests/format/ForStatements/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/ForStatements/__snapshots__/jsfmt.spec.js.snap @@ -160,22 +160,29 @@ contract ForStatements { =====================================output===================================== contract ForStatements { uint constant LONG_VARIABLE = 1; + function hi() public { uint a; + for (uint i; i < 100; i++) a++; + for (i = 0; i < 100; i++) a = a.add(LONG_VARIABLE).add(LONG_VARIABLE).add(LONG_VARIABLE); + for (i = 0; i < 100; i++) { a++; } + for (i = 0; i < 100; i++) { a = a.add(LONG_VARIABLE).add(LONG_VARIABLE).add(LONG_VARIABLE); } + for ( uint veryLongVariableName; veryLongVariableName < 100; veryLongVariableName++ ) a++; + for ( veryLongVariableName = 0; veryLongVariableName < 100; @@ -183,13 +190,21 @@ contract ForStatements { ) { a++; } + for (;;) {} + for (i = 0; ; ) {} + for (i = 0; i < 100; ) {} + for (i = 0; ; i++) {} + for (i = 0; i < 100; i++) {} + for (; i < 100; i++) {} + for (; i < 100; ) {} + for (; ; i++) {} } } diff --git a/tests/format/FunctionCalls/__snapshots__/jsfmt.spec.js.snap b/tests/format/FunctionCalls/__snapshots__/jsfmt.spec.js.snap index 75be4dcb8..7c9a727d9 100644 --- a/tests/format/FunctionCalls/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/FunctionCalls/__snapshots__/jsfmt.spec.js.snap @@ -207,9 +207,12 @@ contract FunctionCalls { address veryLongValidatorAddress = veryVeryVeryLongSignature .popLast20Bytes(); } + function foo() { Voter you = Voter(1, true); + Voter me = Voter({weight: 2, voted: abstain()}); + Voter airbnb = Voter({weight: 2, voted: true}); } function verify( @@ -508,9 +511,12 @@ contract FunctionCalls { address veryLongValidatorAddress = veryVeryVeryLongSignature .popLast20Bytes(); } + function foo() { Voter you = Voter(1, true); + Voter me = Voter({weight: 2, voted: abstain()}); + Voter airbnb = Voter({weight: 2, voted: true}); } function verify( diff --git a/tests/format/FunctionDefinitions/__snapshots__/jsfmt.spec.js.snap b/tests/format/FunctionDefinitions/__snapshots__/jsfmt.spec.js.snap index 52849795e..9be97d021 100644 --- a/tests/format/FunctionDefinitions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/FunctionDefinitions/__snapshots__/jsfmt.spec.js.snap @@ -1162,6 +1162,7 @@ interface FunctionInterfaces { uint ); } + abstract contract FunctionInterfaces { function functionDefinition0(); function functionDefinition1(); @@ -1174,13 +1175,16 @@ abstract contract FunctionInterfaces { function functionDefinition8(); function functionDefinition9(); } + contract FunctionDefinitions { fallback() external {} fallback() external payable {} fallback() external payable virtual {} fallback(bytes calldata _input) external {} + receive() external payable {} receive() external payable virtual {} + function noParamsNoModifiersNoReturns() { a = 1; } diff --git a/tests/format/HexLiteral/__snapshots__/jsfmt.spec.js.snap b/tests/format/HexLiteral/__snapshots__/jsfmt.spec.js.snap index 27f5134e5..c5f971459 100644 --- a/tests/format/HexLiteral/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/HexLiteral/__snapshots__/jsfmt.spec.js.snap @@ -18,6 +18,7 @@ contract HexLiteral { =====================================output===================================== pragma solidity 0.8.26; + contract HexLiteral { bytes8 hex1 = hex"DeadBeef"; bytes8 hex2 = hex"DeadBeef"; @@ -44,6 +45,7 @@ contract HexLiteral { =====================================output===================================== pragma solidity 0.8.26; + contract HexLiteral { bytes8 hex1 = hex'DeadBeef'; bytes8 hex2 = hex'DeadBeef'; diff --git a/tests/format/IfStatements/__snapshots__/jsfmt.spec.js.snap b/tests/format/IfStatements/__snapshots__/jsfmt.spec.js.snap index edc8386fd..331d12143 100644 --- a/tests/format/IfStatements/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/IfStatements/__snapshots__/jsfmt.spec.js.snap @@ -656,6 +656,7 @@ contract IfStatements { contract IfStatements { function hi() public { if (simpleIf) return true; + if (simpleIf) return ( true, @@ -670,8 +671,10 @@ contract IfStatements { true, true ); + if (simpleIf) return true; else return false; + if (simpleIf) return ( true, @@ -687,6 +690,7 @@ contract IfStatements { true ); else return false; + if (simpleIf) return true; else return ( @@ -702,6 +706,7 @@ contract IfStatements { false, false ); + if (simpleIf) return ( true, @@ -730,9 +735,11 @@ contract IfStatements { false, false ); + if (simpleIf) return true; else if (simpleElseIf) return (true, false); else return false; + if (simpleIf) return ( true, @@ -749,6 +756,7 @@ contract IfStatements { ); else if (simpleElseIf) return (true, false); else return false; + if (simpleIf) return true; else if (simpleElseIf) return (true, false); else @@ -765,6 +773,7 @@ contract IfStatements { false, false ); + if (simpleIf) return ( true, @@ -794,6 +803,7 @@ contract IfStatements { false, false ); + if (simpleIf) return true; else if (simpleElseIf) return ( @@ -809,6 +819,7 @@ contract IfStatements { false ); else return false; + if (simpleIf) return ( true, @@ -837,6 +848,7 @@ contract IfStatements { false ); else return false; + if (simpleIf) return true; else if (simpleElseIf) return ( @@ -865,6 +877,7 @@ contract IfStatements { false, false ); + if (simpleIf) return ( true, @@ -906,47 +919,57 @@ contract IfStatements { false, false ); + if (simpleIf) { return true; } + if (simpleIf) { return true; } else return false; + if (simpleIf) return true; else { return false; } + if (simpleIf) { return true; } else { return false; } + if (simpleIf) { return true; } else if (simpleElseIf) return (true, false); else return false; + if (simpleIf) return true; else if (simpleElseIf) return (true, false); else { return false; } + if (simpleIf) { return true; } else if (simpleElseIf) return (true, false); else { return false; } + if (simpleIf) { return true; } else if (simpleElseIf) { return (true, false); } else return false; + if (simpleIf) return true; else if (simpleElseIf) { return (true, false); } else { return false; } + if ( veryComplicatedComputation(variable1, variable2) == (400 + 500) * @@ -954,6 +977,7 @@ contract IfStatements { ) { return true; } + if (simpleIf) { return true; } else if ( @@ -963,6 +987,7 @@ contract IfStatements { ) { return (true, false); } else return false; + if ( veryComplicatedComputation(variable1, variable2) == (400 + 500) * @@ -972,6 +997,7 @@ contract IfStatements { } else if (simpleElseIf) { return (true, false); } else return false; + if ( veryComplicatedComputation(variable1, variable2) == (400 + 500) * @@ -985,15 +1011,18 @@ contract IfStatements { ) { return (true, false); } else return false; + if (simpleIf) if (simpleIfWithinIf) return true; else return false; + if (simpleIf) if (simpleIfWithinIf) { return true; } else { return false; } + if (simpleIf) { if (simpleIfWithinIf) { return true; @@ -1001,9 +1030,11 @@ contract IfStatements { return false; } } + if (simpleIf) { if (simpleIfWithinIf) return true; } else return false; + if (simpleIf) { if (simpleIfWithinIf) { return true; @@ -1011,10 +1042,12 @@ contract IfStatements { } else { return false; } + if (simpleIf) if (simpleIfWithinIf) return true; else return false; else return false; + if (simpleIf) if (simpleIfWithinIf) { return true; @@ -1024,6 +1057,7 @@ contract IfStatements { else { return false; } + if (simpleIf) { if (simpleIfWithinIf) { return true; diff --git a/tests/format/Immutable/__snapshots__/jsfmt.spec.js.snap b/tests/format/Immutable/__snapshots__/jsfmt.spec.js.snap index 62f0e411a..de432a14b 100644 --- a/tests/format/Immutable/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Immutable/__snapshots__/jsfmt.spec.js.snap @@ -81,6 +81,7 @@ contract Immutable { =====================================output===================================== pragma solidity >0.6.4 <0.7.0; + contract Immutable { uint constant X = 32 ** 22 + 8; string constant TEXT = "abc"; @@ -88,10 +89,12 @@ contract Immutable { uint immutable decimals; uint immutable maxBalance; address immutable owner = msg.sender; + constructor(uint _decimals, address _reference) public { decimals = _decimals; maxBalance = _reference.balance; } + function isBalanceTooHigh(address _other) public view returns (bool) { return _other.balance > maxBalance; } diff --git a/tests/format/Inbox/__snapshots__/jsfmt.spec.js.snap b/tests/format/Inbox/__snapshots__/jsfmt.spec.js.snap index bd05e066a..376e25afa 100644 --- a/tests/format/Inbox/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Inbox/__snapshots__/jsfmt.spec.js.snap @@ -121,13 +121,17 @@ contract Inbox { pragma solidity ^0.4.23; contract Inbox { string public message; + constructor(string initialMessage) public { message = initialMessage; } + function setMessage(string newMessage) public { message = newMessage; } + function nothingHere() public {} + function nothingHereMultipleComments() public {} } diff --git a/tests/format/IndexOf/__snapshots__/jsfmt.spec.js.snap b/tests/format/IndexOf/__snapshots__/jsfmt.spec.js.snap index 9b4db8f8e..9f0f1d4da 100644 --- a/tests/format/IndexOf/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/IndexOf/__snapshots__/jsfmt.spec.js.snap @@ -223,13 +223,17 @@ contract IndexOf { =====================================output===================================== contract IndexOf { address creator; + function IndexOf() { creator = msg.sender; } + int whatwastheval = -10; + function indexOf(string _a, string _b) returns (int) { bytes memory a = bytes(_a); bytes memory b = bytes(_b); + if (a.length < 1 || b.length < 1 || (b.length > a.length)) { whatwastheval = -1; return -1; diff --git a/tests/format/IndexRangeAccess/__snapshots__/jsfmt.spec.js.snap b/tests/format/IndexRangeAccess/__snapshots__/jsfmt.spec.js.snap index 5e920b3bd..e339ed528 100644 --- a/tests/format/IndexRangeAccess/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/IndexRangeAccess/__snapshots__/jsfmt.spec.js.snap @@ -48,8 +48,10 @@ contract Demo { =====================================output===================================== pragma solidity ^0.6.4; + contract Demo { event Log(bytes value); + function log(bytes calldata value) external { emit Log(bytes(value[0:10])); } diff --git a/tests/format/Issues/__snapshots__/jsfmt.spec.js.snap b/tests/format/Issues/__snapshots__/jsfmt.spec.js.snap index 1aebdc0d0..bec273b20 100644 --- a/tests/format/Issues/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Issues/__snapshots__/jsfmt.spec.js.snap @@ -60,9 +60,11 @@ contract Example { =====================================output===================================== contract Example { using SafeMath for uint256; + struct BalanceState { uint256 balance; } + mapping(address => mapping(address => BalanceState)) private balanceStates; function example(address token, uint amount) public { balanceStates[msg.sender][token].balance = balanceStates[msg.sender][ @@ -181,9 +183,12 @@ contract Bug { =====================================output===================================== pragma solidity 0.6.12; + contract Bug { uint public hello; + uint public bigNum = 100_000; + uint public magic; } @@ -408,7 +413,9 @@ contract ContractWithoutComments { =====================================output===================================== pragma solidity ^0.8.0; + contract ContractWithLeadingComment {} + contract ContractWithoutComments {} ================================================================================ diff --git a/tests/format/MemberAccess/__snapshots__/jsfmt.spec.js.snap b/tests/format/MemberAccess/__snapshots__/jsfmt.spec.js.snap index 9be3f299d..a6a373cb1 100644 --- a/tests/format/MemberAccess/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/MemberAccess/__snapshots__/jsfmt.spec.js.snap @@ -117,6 +117,7 @@ contract MemberAccessIsEndOfChainCases { =====================================output===================================== pragma solidity ^0.5.0; + contract MemberAccess { function() { int256 amount = SafeCast @@ -208,8 +209,10 @@ contract MemberAccess { ); } } + contract MemberAccessIsEndOfChainCases { uint a = b.c; + function() modifierCase(b.c) { a(b.c); a[b.c]; diff --git a/tests/format/ModifierInvocations/__snapshots__/jsfmt.spec.js.snap b/tests/format/ModifierInvocations/__snapshots__/jsfmt.spec.js.snap index 737687ba3..8636ff191 100644 --- a/tests/format/ModifierInvocations/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/ModifierInvocations/__snapshots__/jsfmt.spec.js.snap @@ -76,6 +76,7 @@ contract ModifierInvocations is ModifierDefinitions { =====================================output===================================== pragma solidity 0.8.26; + contract ModifierDefinitions { modifier emptyParams { _; @@ -84,8 +85,10 @@ contract ModifierDefinitions { _; } } + contract ModifierInvocations is ModifierDefinitions { constructor() emptyParams noParams() ModifierDefinitions() {} + function test() public emptyParams noParams() {} } diff --git a/tests/format/MultipartStrings/__snapshots__/jsfmt.spec.js.snap b/tests/format/MultipartStrings/__snapshots__/jsfmt.spec.js.snap index 96ffead77..a2940e65f 100644 --- a/tests/format/MultipartStrings/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/MultipartStrings/__snapshots__/jsfmt.spec.js.snap @@ -65,6 +65,7 @@ contract MultipartStrings { bytes b4 = hex"beeeeeeeeeeeeeeeeeeeeeef" hex"c0000000000ffeeeeeeeeeeeeeeeeeee"; + string s1 = "foo"; string s2 = "foo" diff --git a/tests/format/NameValueExpression/__snapshots__/jsfmt.spec.js.snap b/tests/format/NameValueExpression/__snapshots__/jsfmt.spec.js.snap index 6839f7f0f..0df1fbfdb 100644 --- a/tests/format/NameValueExpression/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/NameValueExpression/__snapshots__/jsfmt.spec.js.snap @@ -48,6 +48,7 @@ contract NameValueExpression { } =====================================output===================================== pragma solidity >=0.6.2 <0.7.0; + contract NameValueExpression { function callFeed() public { feed.info{ @@ -111,6 +112,7 @@ contract NameValueExpression { } =====================================output===================================== pragma solidity >=0.6.2 <0.7.0; + contract NameValueExpression { function callFeed() public { feed.info{ diff --git a/tests/format/NumberLiteral/__snapshots__/jsfmt.spec.js.snap b/tests/format/NumberLiteral/__snapshots__/jsfmt.spec.js.snap index 6f1a2233a..cbbe8f055 100644 --- a/tests/format/NumberLiteral/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/NumberLiteral/__snapshots__/jsfmt.spec.js.snap @@ -60,6 +60,7 @@ contract NumberLiteral { =====================================output===================================== pragma solidity 0.8.26; + contract NumberLiteral { function numbers() public { 2 ether; diff --git a/tests/format/Ownable/__snapshots__/jsfmt.spec.js.snap b/tests/format/Ownable/__snapshots__/jsfmt.spec.js.snap index 7584533b5..dcc47868e 100644 --- a/tests/format/Ownable/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Ownable/__snapshots__/jsfmt.spec.js.snap @@ -246,33 +246,42 @@ contract Ownable { =====================================output===================================== pragma solidity ^0.4.24; + contract Ownable { address private _owner; + event OwnershipRenounced(address indexed previousOwner); event OwnershipTransferred( address indexed previousOwner, address indexed newOwner ); + constructor() public { _owner = msg.sender; } + function owner() public view returns (address) { return _owner; } + modifier onlyOwner() { require(isOwner()); _; } + function isOwner() public view returns (bool) { return msg.sender == _owner; } + function renounceOwnership() public onlyOwner { emit OwnershipRenounced(_owner); _owner = address(0); } + function transferOwnership(address newOwner) public onlyOwner { _transferOwnership(newOwner); } + function _transferOwnership(address newOwner) internal { require(newOwner != address(0)); emit OwnershipTransferred(_owner, newOwner); diff --git a/tests/format/Parentheses/__snapshots__/jsfmt.spec.js.snap b/tests/format/Parentheses/__snapshots__/jsfmt.spec.js.snap index 49dc22e97..7cc01d9a6 100644 --- a/tests/format/Parentheses/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Parentheses/__snapshots__/jsfmt.spec.js.snap @@ -299,6 +299,7 @@ contract AddNoParentheses { =====================================output===================================== pragma solidity 0.8.26; + contract AddNoParentheses { function addAdd( uint256 a, @@ -307,6 +308,7 @@ contract AddNoParentheses { ) public pure returns (uint256) { return a + b + c; } + function addSub( uint256 a, uint256 b, @@ -314,6 +316,7 @@ contract AddNoParentheses { ) public pure returns (uint256) { return a + b - c; } + function addMul( uint256 a, uint256 b, @@ -321,6 +324,7 @@ contract AddNoParentheses { ) public pure returns (uint256) { return a + b * c; } + function addDiv( uint256 a, uint256 b, @@ -328,6 +332,7 @@ contract AddNoParentheses { ) public pure returns (uint256) { return a + b / c; } + function addMod( uint256 a, uint256 b, @@ -335,6 +340,7 @@ contract AddNoParentheses { ) public pure returns (uint256) { return a + (b % c); } + function addExp( uint256 a, uint256 b, @@ -342,6 +348,7 @@ contract AddNoParentheses { ) public pure returns (uint256) { return a + b ** c; } + function addShiftL( uint256 a, uint256 b, @@ -349,6 +356,7 @@ contract AddNoParentheses { ) public pure returns (uint256) { return (a + b) << c; } + function addShiftR( uint256 a, uint256 b, @@ -356,6 +364,7 @@ contract AddNoParentheses { ) public pure returns (uint256) { return (a + b) >> c; } + function addBitAnd( uint256 a, uint256 b, @@ -363,6 +372,7 @@ contract AddNoParentheses { ) public pure returns (uint256) { return (a + b) & c; } + function addBitOr( uint256 a, uint256 b, @@ -370,6 +380,7 @@ contract AddNoParentheses { ) public pure returns (uint256) { return (a + b) | c; } + function addBitXor( uint256 a, uint256 b, @@ -681,6 +692,7 @@ contract BitAndNoParentheses { =====================================output===================================== pragma solidity 0.8.26; + contract BitAndNoParentheses { function bitAndAdd( uint256 a, @@ -689,6 +701,7 @@ contract BitAndNoParentheses { ) public pure returns (uint256) { return a & (b + c); } + function bitAndSub( uint256 a, uint256 b, @@ -696,6 +709,7 @@ contract BitAndNoParentheses { ) public pure returns (uint256) { return a & (b - c); } + function bitAndMul( uint256 a, uint256 b, @@ -703,6 +717,7 @@ contract BitAndNoParentheses { ) public pure returns (uint256) { return a & (b * c); } + function bitAndDiv( uint256 a, uint256 b, @@ -710,6 +725,7 @@ contract BitAndNoParentheses { ) public pure returns (uint256) { return a & (b / c); } + function bitAndMod( uint256 a, uint256 b, @@ -717,6 +733,7 @@ contract BitAndNoParentheses { ) public pure returns (uint256) { return a & b % c; } + function bitAndExp( uint256 a, uint256 b, @@ -724,6 +741,7 @@ contract BitAndNoParentheses { ) public pure returns (uint256) { return a & (b ** c); } + function bitAndShiftL( uint256 a, uint256 b, @@ -731,6 +749,7 @@ contract BitAndNoParentheses { ) public pure returns (uint256) { return a & (b << c); } + function bitAndShiftR( uint256 a, uint256 b, @@ -738,6 +757,7 @@ contract BitAndNoParentheses { ) public pure returns (uint256) { return a & (b >> c); } + function bitAndBitAnd( uint256 a, uint256 b, @@ -745,6 +765,7 @@ contract BitAndNoParentheses { ) public pure returns (uint256) { return a & b & c; } + function bitAndBitOr( uint256 a, uint256 b, @@ -752,6 +773,7 @@ contract BitAndNoParentheses { ) public pure returns (uint256) { return (a & b) | c; } + function bitAndBitXor( uint256 a, uint256 b, @@ -1063,6 +1085,7 @@ contract BitOrNoParentheses { =====================================output===================================== pragma solidity 0.8.26; + contract BitOrNoParentheses { function bitOrAdd( uint256 a, @@ -1071,6 +1094,7 @@ contract BitOrNoParentheses { ) public pure returns (uint256) { return a | (b + c); } + function bitOrSub( uint256 a, uint256 b, @@ -1078,6 +1102,7 @@ contract BitOrNoParentheses { ) public pure returns (uint256) { return a | (b - c); } + function bitOrMul( uint256 a, uint256 b, @@ -1085,6 +1110,7 @@ contract BitOrNoParentheses { ) public pure returns (uint256) { return a | (b * c); } + function bitOrDiv( uint256 a, uint256 b, @@ -1092,6 +1118,7 @@ contract BitOrNoParentheses { ) public pure returns (uint256) { return a | (b / c); } + function bitOrMod( uint256 a, uint256 b, @@ -1099,6 +1126,7 @@ contract BitOrNoParentheses { ) public pure returns (uint256) { return a | b % c; } + function bitOrExp( uint256 a, uint256 b, @@ -1106,6 +1134,7 @@ contract BitOrNoParentheses { ) public pure returns (uint256) { return a | (b ** c); } + function bitOrShiftL( uint256 a, uint256 b, @@ -1113,6 +1142,7 @@ contract BitOrNoParentheses { ) public pure returns (uint256) { return a | (b << c); } + function bitOrShiftR( uint256 a, uint256 b, @@ -1120,6 +1150,7 @@ contract BitOrNoParentheses { ) public pure returns (uint256) { return a | (b >> c); } + function bitOrBitAnd( uint256 a, uint256 b, @@ -1127,6 +1158,7 @@ contract BitOrNoParentheses { ) public pure returns (uint256) { return a | (b & c); } + function bitOrBitOr( uint256 a, uint256 b, @@ -1134,6 +1166,7 @@ contract BitOrNoParentheses { ) public pure returns (uint256) { return a | b | c; } + function bitOrBitXor( uint256 a, uint256 b, @@ -1445,6 +1478,7 @@ contract BitXorNoParentheses { =====================================output===================================== pragma solidity 0.8.26; + contract BitXorNoParentheses { function bitXorAdd( uint256 a, @@ -1453,6 +1487,7 @@ contract BitXorNoParentheses { ) public pure returns (uint256) { return a ^ (b + c); } + function bitXorSub( uint256 a, uint256 b, @@ -1460,6 +1495,7 @@ contract BitXorNoParentheses { ) public pure returns (uint256) { return a ^ (b - c); } + function bitXorMul( uint256 a, uint256 b, @@ -1467,6 +1503,7 @@ contract BitXorNoParentheses { ) public pure returns (uint256) { return a ^ (b * c); } + function bitXorDiv( uint256 a, uint256 b, @@ -1474,6 +1511,7 @@ contract BitXorNoParentheses { ) public pure returns (uint256) { return a ^ (b / c); } + function bitXorMod( uint256 a, uint256 b, @@ -1481,6 +1519,7 @@ contract BitXorNoParentheses { ) public pure returns (uint256) { return a ^ b % c; } + function bitXorExp( uint256 a, uint256 b, @@ -1488,6 +1527,7 @@ contract BitXorNoParentheses { ) public pure returns (uint256) { return a ^ (b ** c); } + function bitXorShiftL( uint256 a, uint256 b, @@ -1495,6 +1535,7 @@ contract BitXorNoParentheses { ) public pure returns (uint256) { return a ^ (b << c); } + function bitXorShiftR( uint256 a, uint256 b, @@ -1502,6 +1543,7 @@ contract BitXorNoParentheses { ) public pure returns (uint256) { return a ^ (b >> c); } + function bitXorBitAnd( uint256 a, uint256 b, @@ -1509,6 +1551,7 @@ contract BitXorNoParentheses { ) public pure returns (uint256) { return a ^ (b & c); } + function bitXorBitOr( uint256 a, uint256 b, @@ -1516,6 +1559,7 @@ contract BitXorNoParentheses { ) public pure returns (uint256) { return (a ^ b) | c; } + function bitXorBitXor( uint256 a, uint256 b, @@ -1827,6 +1871,7 @@ contract DivNoParentheses { =====================================output===================================== pragma solidity 0.8.26; + contract DivNoParentheses { function divAdd( uint256 a, @@ -1835,6 +1880,7 @@ contract DivNoParentheses { ) public pure returns (uint256) { return a / b + c; } + function divSub( uint256 a, uint256 b, @@ -1842,6 +1888,7 @@ contract DivNoParentheses { ) public pure returns (uint256) { return a / b - c; } + function divMul( uint256 a, uint256 b, @@ -1849,6 +1896,7 @@ contract DivNoParentheses { ) public pure returns (uint256) { return (a / b) * c; } + function divDiv( uint256 a, uint256 b, @@ -1856,6 +1904,7 @@ contract DivNoParentheses { ) public pure returns (uint256) { return a / b / c; } + function divMod( uint256 a, uint256 b, @@ -1863,6 +1912,7 @@ contract DivNoParentheses { ) public pure returns (uint256) { return (a / b) % c; } + function divExp( uint256 a, uint256 b, @@ -1870,6 +1920,7 @@ contract DivNoParentheses { ) public pure returns (uint256) { return a / b ** c; } + function divShiftL( uint256 a, uint256 b, @@ -1877,6 +1928,7 @@ contract DivNoParentheses { ) public pure returns (uint256) { return (a / b) << c; } + function divShiftR( uint256 a, uint256 b, @@ -1884,6 +1936,7 @@ contract DivNoParentheses { ) public pure returns (uint256) { return (a / b) >> c; } + function divBitAnd( uint256 a, uint256 b, @@ -1891,6 +1944,7 @@ contract DivNoParentheses { ) public pure returns (uint256) { return (a / b) & c; } + function divBitOr( uint256 a, uint256 b, @@ -1898,6 +1952,7 @@ contract DivNoParentheses { ) public pure returns (uint256) { return (a / b) | c; } + function divBitXor( uint256 a, uint256 b, @@ -2209,6 +2264,7 @@ contract ExpNoParentheses { =====================================output===================================== pragma solidity 0.8.26; + contract ExpNoParentheses { function expAdd( uint256 a, @@ -2217,6 +2273,7 @@ contract ExpNoParentheses { ) public pure returns (uint256) { return a ** b + c; } + function expSub( uint256 a, uint256 b, @@ -2224,6 +2281,7 @@ contract ExpNoParentheses { ) public pure returns (uint256) { return a ** b - c; } + function expMul( uint256 a, uint256 b, @@ -2231,6 +2289,7 @@ contract ExpNoParentheses { ) public pure returns (uint256) { return a ** b * c; } + function expDiv( uint256 a, uint256 b, @@ -2238,6 +2297,7 @@ contract ExpNoParentheses { ) public pure returns (uint256) { return a ** b / c; } + function expMod( uint256 a, uint256 b, @@ -2245,6 +2305,7 @@ contract ExpNoParentheses { ) public pure returns (uint256) { return a ** b % c; } + function expExp( uint256 a, uint256 b, @@ -2252,6 +2313,7 @@ contract ExpNoParentheses { ) public pure returns (uint256) { return a ** (b ** c); } + function expShiftL( uint256 a, uint256 b, @@ -2259,6 +2321,7 @@ contract ExpNoParentheses { ) public pure returns (uint256) { return (a ** b) << c; } + function expShiftR( uint256 a, uint256 b, @@ -2266,6 +2329,7 @@ contract ExpNoParentheses { ) public pure returns (uint256) { return (a ** b) >> c; } + function expBitAnd( uint256 a, uint256 b, @@ -2273,6 +2337,7 @@ contract ExpNoParentheses { ) public pure returns (uint256) { return (a ** b) & c; } + function expBitOr( uint256 a, uint256 b, @@ -2280,6 +2345,7 @@ contract ExpNoParentheses { ) public pure returns (uint256) { return (a ** b) | c; } + function expBitXor( uint256 a, uint256 b, @@ -2375,16 +2441,20 @@ contract LogicNoParentheses { =====================================output===================================== pragma solidity 0.8.26; + contract LogicNoParentheses { function orOr(bool a, bool b, bool c) public pure returns (bool) { return a || b || c; } + function orAnd(bool a, bool b, bool c) public pure returns (bool) { return a || (b && c); } + function andOr(bool a, bool b, bool c) public pure returns (bool) { return (a && b) || c; } + function andAnd(bool a, bool b, bool c) public pure returns (bool) { return a && b && c; } @@ -2692,6 +2762,7 @@ contract ModNoParentheses { =====================================output===================================== pragma solidity 0.8.26; + contract ModNoParentheses { function modAdd( uint256 a, @@ -2700,6 +2771,7 @@ contract ModNoParentheses { ) public pure returns (uint256) { return (a % b) + c; } + function modSub( uint256 a, uint256 b, @@ -2707,6 +2779,7 @@ contract ModNoParentheses { ) public pure returns (uint256) { return (a % b) - c; } + function modMul( uint256 a, uint256 b, @@ -2714,6 +2787,7 @@ contract ModNoParentheses { ) public pure returns (uint256) { return (a % b) * c; } + function modDiv( uint256 a, uint256 b, @@ -2721,6 +2795,7 @@ contract ModNoParentheses { ) public pure returns (uint256) { return (a % b) / c; } + function modMod( uint256 a, uint256 b, @@ -2728,6 +2803,7 @@ contract ModNoParentheses { ) public pure returns (uint256) { return (a % b) % c; } + function modExp( uint256 a, uint256 b, @@ -2735,6 +2811,7 @@ contract ModNoParentheses { ) public pure returns (uint256) { return a % b ** c; } + function modShiftL( uint256 a, uint256 b, @@ -2742,6 +2819,7 @@ contract ModNoParentheses { ) public pure returns (uint256) { return a % b << c; } + function modShiftR( uint256 a, uint256 b, @@ -2749,6 +2827,7 @@ contract ModNoParentheses { ) public pure returns (uint256) { return a % b >> c; } + function modBitAnd( uint256 a, uint256 b, @@ -2756,6 +2835,7 @@ contract ModNoParentheses { ) public pure returns (uint256) { return a % b & c; } + function modBitOr( uint256 a, uint256 b, @@ -2763,6 +2843,7 @@ contract ModNoParentheses { ) public pure returns (uint256) { return a % b | c; } + function modBitXor( uint256 a, uint256 b, @@ -3074,6 +3155,7 @@ contract MulNoParentheses { =====================================output===================================== pragma solidity 0.8.26; + contract MulNoParentheses { function mulAdd( uint256 a, @@ -3082,6 +3164,7 @@ contract MulNoParentheses { ) public pure returns (uint256) { return a * b + c; } + function mulSub( uint256 a, uint256 b, @@ -3089,6 +3172,7 @@ contract MulNoParentheses { ) public pure returns (uint256) { return a * b - c; } + function mulMul( uint256 a, uint256 b, @@ -3096,6 +3180,7 @@ contract MulNoParentheses { ) public pure returns (uint256) { return a * b * c; } + function mulDiv( uint256 a, uint256 b, @@ -3103,6 +3188,7 @@ contract MulNoParentheses { ) public pure returns (uint256) { return (a * b) / c; } + function mulMod( uint256 a, uint256 b, @@ -3110,6 +3196,7 @@ contract MulNoParentheses { ) public pure returns (uint256) { return (a * b) % c; } + function mulExp( uint256 a, uint256 b, @@ -3117,6 +3204,7 @@ contract MulNoParentheses { ) public pure returns (uint256) { return a * b ** c; } + function mulShiftL( uint256 a, uint256 b, @@ -3124,6 +3212,7 @@ contract MulNoParentheses { ) public pure returns (uint256) { return (a * b) << c; } + function mulShiftR( uint256 a, uint256 b, @@ -3131,6 +3220,7 @@ contract MulNoParentheses { ) public pure returns (uint256) { return (a * b) >> c; } + function mulBitAnd( uint256 a, uint256 b, @@ -3138,6 +3228,7 @@ contract MulNoParentheses { ) public pure returns (uint256) { return (a * b) & c; } + function mulBitOr( uint256 a, uint256 b, @@ -3145,6 +3236,7 @@ contract MulNoParentheses { ) public pure returns (uint256) { return (a * b) | c; } + function mulBitXor( uint256 a, uint256 b, @@ -3456,6 +3548,7 @@ contract ShiftLNoParentheses { =====================================output===================================== pragma solidity 0.8.26; + contract ShiftLNoParentheses { function shiftLAdd( uint256 a, @@ -3464,6 +3557,7 @@ contract ShiftLNoParentheses { ) public pure returns (uint256) { return a << (b + c); } + function shiftLSub( uint256 a, uint256 b, @@ -3471,6 +3565,7 @@ contract ShiftLNoParentheses { ) public pure returns (uint256) { return a << (b - c); } + function shiftLMul( uint256 a, uint256 b, @@ -3478,6 +3573,7 @@ contract ShiftLNoParentheses { ) public pure returns (uint256) { return a << (b * c); } + function shiftLDiv( uint256 a, uint256 b, @@ -3485,6 +3581,7 @@ contract ShiftLNoParentheses { ) public pure returns (uint256) { return a << (b / c); } + function shiftLMod( uint256 a, uint256 b, @@ -3492,6 +3589,7 @@ contract ShiftLNoParentheses { ) public pure returns (uint256) { return a << b % c; } + function shiftLExp( uint256 a, uint256 b, @@ -3499,6 +3597,7 @@ contract ShiftLNoParentheses { ) public pure returns (uint256) { return a << (b ** c); } + function shiftLShiftL( uint256 a, uint256 b, @@ -3506,6 +3605,7 @@ contract ShiftLNoParentheses { ) public pure returns (uint256) { return (a << b) << c; } + function shiftLShiftR( uint256 a, uint256 b, @@ -3513,6 +3613,7 @@ contract ShiftLNoParentheses { ) public pure returns (uint256) { return (a << b) >> c; } + function shiftLBitAnd( uint256 a, uint256 b, @@ -3520,6 +3621,7 @@ contract ShiftLNoParentheses { ) public pure returns (uint256) { return (a << b) & c; } + function shiftLBitOr( uint256 a, uint256 b, @@ -3527,6 +3629,7 @@ contract ShiftLNoParentheses { ) public pure returns (uint256) { return (a << b) | c; } + function shiftLBitXor( uint256 a, uint256 b, @@ -3838,6 +3941,7 @@ contract ShiftRNoParentheses { =====================================output===================================== pragma solidity 0.8.26; + contract ShiftRNoParentheses { function shiftRAdd( uint256 a, @@ -3846,6 +3950,7 @@ contract ShiftRNoParentheses { ) public pure returns (uint256) { return a >> (b + c); } + function shiftRSub( uint256 a, uint256 b, @@ -3853,6 +3958,7 @@ contract ShiftRNoParentheses { ) public pure returns (uint256) { return a >> (b - c); } + function shiftRMul( uint256 a, uint256 b, @@ -3860,6 +3966,7 @@ contract ShiftRNoParentheses { ) public pure returns (uint256) { return a >> (b * c); } + function shiftRDiv( uint256 a, uint256 b, @@ -3867,6 +3974,7 @@ contract ShiftRNoParentheses { ) public pure returns (uint256) { return a >> (b / c); } + function shiftRMod( uint256 a, uint256 b, @@ -3874,6 +3982,7 @@ contract ShiftRNoParentheses { ) public pure returns (uint256) { return a >> b % c; } + function shiftRExp( uint256 a, uint256 b, @@ -3881,6 +3990,7 @@ contract ShiftRNoParentheses { ) public pure returns (uint256) { return a >> (b ** c); } + function shiftRShiftL( uint256 a, uint256 b, @@ -3888,6 +3998,7 @@ contract ShiftRNoParentheses { ) public pure returns (uint256) { return (a >> b) << c; } + function shiftRShiftR( uint256 a, uint256 b, @@ -3895,6 +4006,7 @@ contract ShiftRNoParentheses { ) public pure returns (uint256) { return (a >> b) >> c; } + function shiftRBitAnd( uint256 a, uint256 b, @@ -3902,6 +4014,7 @@ contract ShiftRNoParentheses { ) public pure returns (uint256) { return (a >> b) & c; } + function shiftRBitOr( uint256 a, uint256 b, @@ -3909,6 +4022,7 @@ contract ShiftRNoParentheses { ) public pure returns (uint256) { return (a >> b) | c; } + function shiftRBitXor( uint256 a, uint256 b, @@ -4220,6 +4334,7 @@ contract SubNoParentheses { =====================================output===================================== pragma solidity 0.8.26; + contract SubNoParentheses { function subAdd( uint256 a, @@ -4228,6 +4343,7 @@ contract SubNoParentheses { ) public pure returns (uint256) { return a - b + c; } + function subSub( uint256 a, uint256 b, @@ -4235,6 +4351,7 @@ contract SubNoParentheses { ) public pure returns (uint256) { return a - b - c; } + function subMul( uint256 a, uint256 b, @@ -4242,6 +4359,7 @@ contract SubNoParentheses { ) public pure returns (uint256) { return a - b * c; } + function subDiv( uint256 a, uint256 b, @@ -4249,6 +4367,7 @@ contract SubNoParentheses { ) public pure returns (uint256) { return a - b / c; } + function subMod( uint256 a, uint256 b, @@ -4256,6 +4375,7 @@ contract SubNoParentheses { ) public pure returns (uint256) { return a - (b % c); } + function subExp( uint256 a, uint256 b, @@ -4263,6 +4383,7 @@ contract SubNoParentheses { ) public pure returns (uint256) { return a - b ** c; } + function subShiftL( uint256 a, uint256 b, @@ -4270,6 +4391,7 @@ contract SubNoParentheses { ) public pure returns (uint256) { return (a - b) << c; } + function subShiftR( uint256 a, uint256 b, @@ -4277,6 +4399,7 @@ contract SubNoParentheses { ) public pure returns (uint256) { return (a - b) >> c; } + function subBitAnd( uint256 a, uint256 b, @@ -4284,6 +4407,7 @@ contract SubNoParentheses { ) public pure returns (uint256) { return (a - b) & c; } + function subBitOr( uint256 a, uint256 b, @@ -4291,6 +4415,7 @@ contract SubNoParentheses { ) public pure returns (uint256) { return (a - b) | c; } + function subBitXor( uint256 a, uint256 b, @@ -4302,191 +4427,3 @@ contract SubNoParentheses { ================================================================================ `; - -exports[`a.js - {"compiler":"0.8.6"} format 1`] = ` -====================================options===================================== -compiler: "0.8.6" -parsers: ["solidity-parse"] -printWidth: 80 - | printWidth -=====================================input====================================== -function addAdd(a, b, c) { - return a + b + c; -} - -function addSub(a, b, c) { - return a + b - c; -} - -function addMul(a, b, c) { - return a + b * c; -} - -function addDiv(a, b, c) { - return a + b / c; -} - -function addMod(a, b, c) { - return a + (b % c); -} - -function addExp(a, b, c) { - return a + b ** c; -} - -function addShiftL(a, b, c) { - return (a + b) << c; -} - -function addShiftR(a, b, c) { - return (a + b) >> c; -} - -function addBitAnd(a, b, c) { - return (a + b) & c; -} - -function addBitOr(a, b, c) { - return (a + b) | c; -} - -function addBitXor(a, b, c) { - return (a + b) ^ c; -} - -=====================================output===================================== -function addAdd(a, b, c) { - return a + b + c; -} - -function addSub(a, b, c) { - return a + b - c; -} - -function addMul(a, b, c) { - return a + b * c; -} - -function addDiv(a, b, c) { - return a + b / c; -} - -function addMod(a, b, c) { - return a + (b % c); -} - -function addExp(a, b, c) { - return a + b ** c; -} - -function addShiftL(a, b, c) { - return (a + b) << c; -} - -function addShiftR(a, b, c) { - return (a + b) >> c; -} - -function addBitAnd(a, b, c) { - return (a + b) & c; -} - -function addBitOr(a, b, c) { - return (a + b) | c; -} - -function addBitXor(a, b, c) { - return (a + b) ^ c; -} - -================================================================================ -`; - -exports[`a.js - {"compiler":"0.8.6"} format 2`] = ` -====================================options===================================== -compiler: "0.8.6" -parsers: ["solidity-slang-parse"] -printWidth: 80 - | printWidth -=====================================input====================================== -function addAdd(a, b, c) { - return a + b + c; -} - -function addSub(a, b, c) { - return a + b - c; -} - -function addMul(a, b, c) { - return a + b * c; -} - -function addDiv(a, b, c) { - return a + b / c; -} - -function addMod(a, b, c) { - return a + (b % c); -} - -function addExp(a, b, c) { - return a + b ** c; -} - -function addShiftL(a, b, c) { - return (a + b) << c; -} - -function addShiftR(a, b, c) { - return (a + b) >> c; -} - -function addBitAnd(a, b, c) { - return (a + b) & c; -} - -function addBitOr(a, b, c) { - return (a + b) | c; -} - -function addBitXor(a, b, c) { - return (a + b) ^ c; -} - -=====================================output===================================== -function addAdd(a, b, c) { - return a + b + c; -} -function addSub(a, b, c) { - return a + b - c; -} -function addMul(a, b, c) { - return a + b * c; -} -function addDiv(a, b, c) { - return a + b / c; -} -function addMod(a, b, c) { - return a + (b % c); -} -function addExp(a, b, c) { - return a + b ** c; -} -function addShiftL(a, b, c) { - return (a + b) << c; -} -function addShiftR(a, b, c) { - return (a + b) >> c; -} -function addBitAnd(a, b, c) { - return (a + b) & c; -} -function addBitOr(a, b, c) { - return (a + b) | c; -} -function addBitXor(a, b, c) { - return (a + b) ^ c; -} - -================================================================================ -`; diff --git a/tests/format/PrettierIgnore/__snapshots__/jsfmt.spec.js.snap b/tests/format/PrettierIgnore/__snapshots__/jsfmt.spec.js.snap index a323840c3..1e7373011 100644 --- a/tests/format/PrettierIgnore/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/PrettierIgnore/__snapshots__/jsfmt.spec.js.snap @@ -134,12 +134,15 @@ contract Example { =====================================output===================================== pragma solidity ^0.5.2; + contract PrettierIgnore { fallback() external payable { matrix(1, 0, 0, 0, 1, 0, 0, 0, 1); + matrix(1, 0, 0, 0, 1, 0, 0, 0, 1); } } + contract Example { fallback() external payable { matrix(1, 0, 0, 0, 1, 0, 0, 0, 1); diff --git a/tests/format/Proxy/__snapshots__/jsfmt.spec.js.snap b/tests/format/Proxy/__snapshots__/jsfmt.spec.js.snap index 3788c8b30..405a88bac 100644 --- a/tests/format/Proxy/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Proxy/__snapshots__/jsfmt.spec.js.snap @@ -62,16 +62,22 @@ contract Proxy { =====================================output===================================== pragma solidity ^0.4.24; + contract Proxy { function _implementation() internal view returns (address); + function _fallback() internal { _delegate(_implementation()); } + function _delegate(address implementation) internal { assembly { calldatacopy(0,0,calldatasize) + let result := delegatecall(gas,implementation,0,calldatasize,0,0) + returndatacopy(0,0,returndatasize) + switch result case 0 { revert(0,returndatasize) @@ -81,6 +87,7 @@ contract Proxy { } } } + function() public payable { _fallback(); } diff --git a/tests/format/SampleCrowdsale/__snapshots__/jsfmt.spec.js.snap b/tests/format/SampleCrowdsale/__snapshots__/jsfmt.spec.js.snap index 330af86f1..6d02d7cf3 100644 --- a/tests/format/SampleCrowdsale/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/SampleCrowdsale/__snapshots__/jsfmt.spec.js.snap @@ -169,14 +169,17 @@ contract SampleCrowdsale is CappedCrowdsale, RefundableCrowdsale { =====================================output===================================== pragma solidity ^0.4.18; + import "../crowdsale/CappedCrowdsale.sol"; import "../crowdsale/RefundableCrowdsale.sol"; import "../token/MintableToken.sol"; + contract SampleCrowdsaleToken is MintableToken { string public constant name = "Sample Crowdsale Token"; string public constant symbol = "SCT"; uint8 public constant decimals = 18; } + contract SampleCrowdsale is CappedCrowdsale, RefundableCrowdsale { function SampleCrowdsale( uint256 _startTime, @@ -194,6 +197,7 @@ contract SampleCrowdsale is CappedCrowdsale, RefundableCrowdsale { { require(_goal <= _cap); } + function createTokenContract() internal returns (MintableToken) { return new SampleCrowdsaleToken(); } diff --git a/tests/format/SimpleAuction/__snapshots__/jsfmt.spec.js.snap b/tests/format/SimpleAuction/__snapshots__/jsfmt.spec.js.snap index 3b53b30dc..ca88e0ade 100644 --- a/tests/format/SimpleAuction/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/SimpleAuction/__snapshots__/jsfmt.spec.js.snap @@ -381,22 +381,31 @@ contract SimpleAuction { =====================================output===================================== pragma solidity ^0.4.22; + contract SimpleAuction { address public beneficiary; uint public auctionEnd; + address public highestBidder; uint public highestBid; + mapping(address => uint) pendingReturns; + bool ended; + event HighestBidIncreased(address bidder, uint amount); event AuctionEnded(address winner, uint amount); + constructor(uint _biddingTime, address _beneficiary) public { beneficiary = _beneficiary; auctionEnd = now + _biddingTime; } + function bid() public payable { require(now <= auctionEnd, "Auction already ended."); + require(msg.value > highestBid, "There already is a higher bid."); + if (highestBid != 0) { pendingReturns[highestBidder] += highestBid; } @@ -404,10 +413,12 @@ contract SimpleAuction { highestBid = msg.value; emit HighestBidIncreased(msg.sender, msg.value); } + function withdraw() public returns (bool) { uint amount = pendingReturns[msg.sender]; if (amount > 0) { pendingReturns[msg.sender] = 0; + if (!msg.sender.send(amount)) { pendingReturns[msg.sender] = amount; return false; @@ -415,11 +426,14 @@ contract SimpleAuction { } return true; } + function auctionEnd() public { require(now >= auctionEnd, "Auction not yet ended."); require(!ended, "auctionEnd has already been called."); + ended = true; emit AuctionEnded(highestBidder, highestBid); + beneficiary.transfer(highestBid); } } diff --git a/tests/format/SimpleStorage/__snapshots__/jsfmt.spec.js.snap b/tests/format/SimpleStorage/__snapshots__/jsfmt.spec.js.snap index 0d0ede279..5c33bbeb5 100644 --- a/tests/format/SimpleStorage/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/SimpleStorage/__snapshots__/jsfmt.spec.js.snap @@ -63,12 +63,15 @@ contract SimpleStorage { =====================================output===================================== pragma solidity ^0.4.0; + contract SimpleStorage { string public name = "SimpleStorage"; uint storedData; + function set(uint x) public { storedData = x; } + function get() public view returns (uint) { return storedData; } diff --git a/tests/format/SplittableCommodity/__snapshots__/jsfmt.spec.js.snap b/tests/format/SplittableCommodity/__snapshots__/jsfmt.spec.js.snap index c662b79f0..154e214ff 100644 --- a/tests/format/SplittableCommodity/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/SplittableCommodity/__snapshots__/jsfmt.spec.js.snap @@ -200,11 +200,14 @@ contract SplittableCommodity is MintableCommodity { =====================================output===================================== pragma solidity ^0.4.24; + import "./MintableCommodity.sol"; import "../participant/ISupplier.sol"; import "../../node_modules/zeppelin-solidity/contracts//math/SafeMath.sol"; + contract SplittableCommodity is MintableCommodity { using SafeMath for uint256; + event Split( address indexed to, uint256 amount, @@ -212,6 +215,7 @@ contract SplittableCommodity is MintableCommodity { address indexed operator, bytes operatorData ); + function split( uint _tokenId, address _to, @@ -227,7 +231,9 @@ contract SplittableCommodity is MintableCommodity { ISupplier(supplierProxy).isAllowed(this, "IMintableCommodity"), "Splitting can only be done when both the ISplittableCommodity interface is enabled and is called by a supplier or the FifoCrcMarket is used." ); + commodities[_tokenId].value = commodities[_tokenId].value.sub(_amount); + CommodityLib.Commodity memory _commodity = CommodityLib.Commodity({ category: uint64(1), timeRegistered: uint64(now), @@ -241,6 +247,7 @@ contract SplittableCommodity is MintableCommodity { newCRCId <= 18446744073709551616, "You can only split a commodity if it is within a valid index range" ); + if ( msg.sender == IContractRegistry(contractRegistry).getLatestProxyAddr( @@ -251,7 +258,9 @@ contract SplittableCommodity is MintableCommodity { } else { _transfer(msg.sender, _to, newCRCId); } + callRecipient(msg.sender, 0x0, _to, newCRCId, "", "", false); + emit Split(_to, _amount, uint64(newCRCId), msg.sender, ""); } } diff --git a/tests/format/StyleGuide/__snapshots__/jsfmt.spec.js.snap b/tests/format/StyleGuide/__snapshots__/jsfmt.spec.js.snap index f12d9da11..5ec08179b 100644 --- a/tests/format/StyleGuide/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/StyleGuide/__snapshots__/jsfmt.spec.js.snap @@ -29,9 +29,12 @@ contract A { =====================================output===================================== pragma solidity >=0.4.0 <0.7.0; + contract A {} contract B {} + contract C {} + contract A { function spam() public pure {} function ham() public pure {} @@ -153,21 +156,26 @@ contract ControlStructures =====================================output===================================== pragma solidity >=0.4.0 <0.7.0; + contract ControlStructures { struct Bank { address owner; uint balance; } + function() { if (true) { doSomething(); } + while(true){ break; } + for (uint a; a < 10; a++) { doSomethingElse(); } + if (x < 3) { x += 1; } else if (x > 7) { @@ -447,22 +455,28 @@ contract X is B, C, D { =====================================output===================================== pragma solidity >=0.4.0 <0.7.0; + contract FunctionDeclaration { function increment(uint x) public pure returns (uint) { return x + 1; } + function increment(uint x) public pure returns (uint) { return x + 1; } + function increment(uint x) public pure returns (uint) { return x + 1; } + function increment(uint x) public pure returns (uint) { return x + 1; } + function kill() onlyowner public { selfdestruct(owner); } + function thisFunctionHasLotsOfArguments( address a, address b, @@ -473,6 +487,7 @@ contract FunctionDeclaration { ) public { doSomething(); } + function thisFunctionHasLotsOfArguments( address a, address b, @@ -483,6 +498,7 @@ contract FunctionDeclaration { ) public { doSomething(); } + function thisFunctionHasLotsOfArguments( address a, address b, @@ -493,6 +509,7 @@ contract FunctionDeclaration { ) public { doSomething(); } + function thisFunctionNameIsReallyLong( address x, address y, @@ -500,6 +517,7 @@ contract FunctionDeclaration { ) public onlyowner priced returns (address) { doSomething(); } + function thisFunctionNameIsReallyLong( address x, address y, @@ -507,6 +525,7 @@ contract FunctionDeclaration { ) public onlyowner priced returns (address) { doSomething(); } + function thisFunctionNameIsReallyLong( address x, address y, @@ -514,6 +533,7 @@ contract FunctionDeclaration { ) public onlyowner priced returns (address) { doSomething(); } + function thisFunctionNameIsReallyLong( address a, address b, @@ -527,6 +547,7 @@ contract FunctionDeclaration { ) { doSomething(); + return ( veryVeryLongReturnArg1, veryVeryLongReturnArg1, @@ -534,17 +555,22 @@ contract FunctionDeclaration { ); } } + contract B { constructor(uint) public {} } + contract C { constructor(uint, uint) public {} } + contract D { constructor(uint) public {} } + contract A is B, C, D { uint x; + constructor( uint param1, uint param2, @@ -555,8 +581,10 @@ contract A is B, C, D { x = param5; } } + contract X is B, C, D { uint x; + constructor( uint param1, uint param2, @@ -881,6 +909,7 @@ contract Mappings { =====================================output===================================== pragma solidity >=0.4.0 <0.7.0; + contract Mappings { mapping(uint => uint) map; mapping(address => bool) registeredAddresses; @@ -997,6 +1026,7 @@ contract EventDefinitionsAndEventEmitters { =====================================output===================================== pragma solidity >=0.4.0 <0.7.0; + contract FunctionCalls { function() { thisFunctionCallIsReallyLong( @@ -1004,21 +1034,25 @@ contract FunctionCalls { longArgument2, longArgument3 ); + thisFunctionCallIsReallyLong( longArgument1, longArgument2, longArgument3 ); + thisFunctionCallIsReallyLong( longArgument1, longArgument2, longArgument3 ); + thisFunctionCallIsReallyLong( longArgument1, longArgument2, longArgument3 ); + thisFunctionCallIsReallyLong( longArgument1, longArgument2, @@ -1026,6 +1060,7 @@ contract FunctionCalls { ); } } + contract AssignmentStatements { function() { thisIsALongNestedMapping[being][set][to_some_value] = someFunction( @@ -1036,6 +1071,7 @@ contract AssignmentStatements { ); } } + contract EventDefinitionsAndEventEmitters { event LongAndLotsOfArgs( address sender, @@ -1045,6 +1081,7 @@ contract EventDefinitionsAndEventEmitters { bytes32[] options, bytes32 longAttribute ); + function() { LongAndLotsOfArgs( sender, @@ -1262,6 +1299,7 @@ contract OtherRecommendations { =====================================output===================================== pragma solidity >=0.4.0 <0.7.0; + contract OtherRecommendations { function() { str = "bar"; @@ -1269,6 +1307,7 @@ contract OtherRecommendations { x = 100 / 10; x += 3 + 4; x |= y && z; + x = 2 ** 3 + 5; x = y + z; x += 1; @@ -1361,6 +1400,7 @@ contract VariableDeclarations { =====================================output===================================== pragma solidity >=0.4.0 <0.7.0; + contract VariableDeclarations { uint[] x; } @@ -1414,6 +1454,7 @@ contract WhitespaceInExpressions { =====================================output===================================== pragma solidity >=0.4.0 <0.7.0; + contract WhitespaceInExpressions { function() { spam(ham[1], Coin({name: "ham"})); @@ -1421,6 +1462,7 @@ contract WhitespaceInExpressions { y = 2; long_variable = 3; } + function spam(uint i, Coin coin) public; } diff --git a/tests/format/TryCatch/__snapshots__/jsfmt.spec.js.snap b/tests/format/TryCatch/__snapshots__/jsfmt.spec.js.snap index a39f33f38..421a6de1f 100644 --- a/tests/format/TryCatch/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/TryCatch/__snapshots__/jsfmt.spec.js.snap @@ -335,9 +335,11 @@ contract FeedConsumer { =====================================output===================================== pragma solidity ^0.6.0; + interface DataFeed { function getData(address token) external returns (uint value); } + contract FeedConsumer { DataFeed feed; uint errorCount; @@ -359,6 +361,7 @@ contract FeedConsumer { return (0, false); } } + function rate2(address token) public returns (uint value, bool success) { require(errorCount < 10); try feed.getData(token) returns ( @@ -385,6 +388,7 @@ contract FeedConsumer { return (0, false); } } + function rate3(address token) public returns (uint value, bool success) { require(errorCount < 10); try feed.getData(token) { @@ -399,6 +403,7 @@ contract FeedConsumer { return (0, false); } } + function rate4(address token) public returns (uint value, bool success) { require(errorCount < 10); try feed.getData(token) returns ( diff --git a/tests/format/Tupples/__snapshots__/jsfmt.spec.js.snap b/tests/format/Tupples/__snapshots__/jsfmt.spec.js.snap index c8cbbce4f..b6e732ec7 100644 --- a/tests/format/Tupples/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Tupples/__snapshots__/jsfmt.spec.js.snap @@ -97,11 +97,13 @@ bytes32 requestId) = getParamsById(paramsId); =====================================output===================================== pragma solidity ^0.5.0; + contract demo { function hello() public view returns (bool, bool) {} function hello2() public view returns (bool) {} function hello3() public view returns (bool, bool, bool) {} } + contract Tupples { function world(address payable _yo) public view { bool yo; diff --git a/tests/format/TypeDefinition/__snapshots__/jsfmt.spec.js.snap b/tests/format/TypeDefinition/__snapshots__/jsfmt.spec.js.snap index 400475d96..c89783b6c 100644 --- a/tests/format/TypeDefinition/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/TypeDefinition/__snapshots__/jsfmt.spec.js.snap @@ -57,9 +57,12 @@ contract TypeDefinition { =====================================output===================================== pragma solidity ^0.8.8; + type Hello is uint; + contract TypeDefinition { event Moon(Hello world); + function demo(Hello world) public { world = Hello.wrap(Hello.unwrap(world) + 1337); emit Moon(world); diff --git a/tests/format/WhileStatements/__snapshots__/jsfmt.spec.js.snap b/tests/format/WhileStatements/__snapshots__/jsfmt.spec.js.snap index aab46f171..1df776419 100644 --- a/tests/format/WhileStatements/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/WhileStatements/__snapshots__/jsfmt.spec.js.snap @@ -156,42 +156,56 @@ contract WhileStatements { =====================================output===================================== contract WhileStatements { uint constant LONG_VARIABLE = 1; + function whileStatements() public { uint a; uint veryLongVariableName; + while(a < 100)a++; + while(a < 200)a = a.add(LONG_VARIABLE).add(LONG_VARIABLE).add( LONG_VARIABLE ); + while(a < 300){ a++; } + while(a < 400){ a = a.add(LONG_VARIABLE).add(LONG_VARIABLE).add(LONG_VARIABLE); } + while(a < veryLongVariableName.add(LONG_VARIABLE).add(LONG_VARIABLE) * 500)a++; + while(a < veryLongVariableName.add(LONG_VARIABLE).add(LONG_VARIABLE) * 600){ a++; } } + function doWhileStatements() public { uint a; uint veryLongVariableName; + do a++; while (a < 100); + do a = a.add(LONG_VARIABLE).add(LONG_VARIABLE).add(LONG_VARIABLE); while (a < 200); + do { a++; } while (a < 300); + do { a = a.add(LONG_VARIABLE).add(LONG_VARIABLE).add(LONG_VARIABLE); } while (a < 400); + do a++; while ( a < veryLongVariableName.add(LONG_VARIABLE).add(LONG_VARIABLE) * 500 ); + do { a++; } while ( diff --git a/tests/format/quotes/__snapshots__/jsfmt.spec.js.snap b/tests/format/quotes/__snapshots__/jsfmt.spec.js.snap index 9ac2c3b70..f460fb99c 100644 --- a/tests/format/quotes/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/quotes/__snapshots__/jsfmt.spec.js.snap @@ -92,6 +92,7 @@ contract Foo { =====================================output===================================== import "someContract.sol"; import "someOtherContract.sol"; + contract Foo { string foo1 = "foo"; string foo2 = "foo"; @@ -209,6 +210,7 @@ contract Foo { =====================================output===================================== import 'someContract.sol'; import 'someOtherContract.sol'; + contract Foo { string foo1 = 'foo'; string foo2 = 'foo'; diff --git a/tests/format/strings/__snapshots__/jsfmt.spec.js.snap b/tests/format/strings/__snapshots__/jsfmt.spec.js.snap index 7f6a5588c..4b49903ec 100644 --- a/tests/format/strings/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/strings/__snapshots__/jsfmt.spec.js.snap @@ -2283,11 +2283,13 @@ library strings { =====================================output===================================== pragma solidity ^0.4.14; + library strings { struct slice { uint _len; uint _ptr; } + function memcpy(uint dest, uint src, uint len) private pure { for (; len >= 32; len -= 32) { assembly { @@ -2296,6 +2298,7 @@ library strings { dest += 32; src += 32; } + uint mask = 256 ** (32 - len) - 1; assembly { let srcpart := and(mload(src),not(mask)) @@ -2303,6 +2306,7 @@ library strings { mstore(dest,or(destpart,srcpart)) } } + function toSlice(string memory self) internal pure returns (slice memory) { uint ptr; assembly { @@ -2310,6 +2314,7 @@ library strings { } return slice(bytes(self).length, ptr); } + function len(bytes32 self) internal pure returns (uint) { uint ret; if (self == 0) return 0; @@ -2334,6 +2339,7 @@ library strings { } return 32 - ret; } + function toSliceB32(bytes32 self) internal pure returns (slice memory ret) { assembly { let ptr := mload(0x40) @@ -2343,18 +2349,22 @@ library strings { } ret._len = len(self); } + function copy(slice memory self) internal pure returns (slice memory) { return slice(self._len, self._ptr); } + function toString(slice memory self) internal pure returns (string memory) { string memory ret = new string(self._len); uint retptr; assembly { retptr := add(ret,32) } + memcpy(retptr, self._ptr, self._len); return ret; } + function len(slice memory self) internal pure returns (uint l) { uint ptr = self._ptr - 31; uint end = ptr + self._len; @@ -2378,15 +2388,18 @@ library strings { } } } + function empty(slice memory self) internal pure returns (bool) { return self._len == 0; } + function compare( slice memory self, slice memory other ) internal pure returns (int) { uint shortest = self._len; if (other._len < self._len) shortest = other._len; + uint selfptr = self._ptr; uint otherptr = other._ptr; for (uint idx = 0; idx < shortest; idx += 32) { @@ -2409,21 +2422,25 @@ library strings { } return int(self._len) - int(other._len); } + function equals( slice memory self, slice memory other ) internal pure returns (bool) { return compare(self, other) == 0; } + function nextRune( slice memory self, slice memory rune ) internal pure returns (slice memory) { rune._ptr = self._ptr; + if (self._len == 0) { rune._len = 0; return rune; } + uint l; uint b; assembly { @@ -2438,29 +2455,35 @@ library strings { } else { l = 4; } + if (l > self._len) { rune._len = self._len; self._ptr += self._len; self._len = 0; return rune; } + self._ptr += l; self._len -= l; rune._len = l; return rune; } + function nextRune( slice memory self ) internal pure returns (slice memory ret) { nextRune(self, ret); } + function ord(slice memory self) internal pure returns (uint ret) { if (self._len == 0) { return 0; } + uint word; uint length; uint divisor = 2 ** 248; + assembly { word := mload(mload(add(self,32))) } @@ -2478,9 +2501,11 @@ library strings { ret = b & 0x07; length = 4; } + if (length > self._len) { return 0; } + for (uint i = 1; i < length; i++) { divisor = divisor / 256; b = (word / divisor) & 0xFF; @@ -2489,13 +2514,16 @@ library strings { } ret = (ret * 64) | (b & 0x3F); } + return ret; } + function keccak(slice memory self) internal pure returns (bytes32 ret) { assembly { ret := keccak256(mload(add(self,32)),mload(self)) } } + function startsWith( slice memory self, slice memory needle @@ -2503,9 +2531,11 @@ library strings { if (self._len < needle._len) { return false; } + if (self._ptr == needle._ptr) { return true; } + bool equal; assembly { let length := mload(needle) @@ -2515,6 +2545,7 @@ library strings { } return equal; } + function beyond( slice memory self, slice memory needle @@ -2522,6 +2553,7 @@ library strings { if (self._len < needle._len) { return self; } + bool equal = true; if (self._ptr != needle._ptr) { assembly { @@ -2531,12 +2563,15 @@ library strings { equal := eq(keccak256(selfptr,length),keccak256(needleptr,length)) } } + if (equal) { self._len -= needle._len; self._ptr += needle._len; } + return self; } + function endsWith( slice memory self, slice memory needle @@ -2544,18 +2579,23 @@ library strings { if (self._len < needle._len) { return false; } + uint selfptr = self._ptr + self._len - needle._len; + if (selfptr == needle._ptr) { return true; } + bool equal; assembly { let length := mload(needle) let needleptr := mload(add(needle,0x20)) equal := eq(keccak256(selfptr,length),keccak256(needleptr,length)) } + return equal; } + function until( slice memory self, slice memory needle @@ -2563,6 +2603,7 @@ library strings { if (self._len < needle._len) { return self; } + uint selfptr = self._ptr + self._len - needle._len; bool equal = true; if (selfptr != needle._ptr) { @@ -2572,11 +2613,14 @@ library strings { equal := eq(keccak256(selfptr,length),keccak256(needleptr,length)) } } + if (equal) { self._len -= needle._len; } + return self; } + function findPtr( uint selflen, uint selfptr, @@ -2585,18 +2629,22 @@ library strings { ) private pure returns (uint) { uint ptr = selfptr; uint idx; + if (needlelen <= selflen) { if (needlelen <= 32) { bytes32 mask = bytes32(~(2 ** (8 * (32 - needlelen)) - 1)); + bytes32 needledata; assembly { needledata := and(mload(needleptr),mask) } + uint end = selfptr + selflen - needlelen; bytes32 ptrdata; assembly { ptrdata := and(mload(ptr),mask) } + while(ptrdata != needledata){ if (ptr >= end) return selfptr + selflen; ptr++; @@ -2610,6 +2658,7 @@ library strings { assembly { hash := keccak256(needleptr,needlelen) } + for (idx = 0; idx <= selflen - needlelen; idx++) { bytes32 testHash; assembly { @@ -2622,6 +2671,7 @@ library strings { } return selfptr + selflen; } + function rfindPtr( uint selflen, uint selfptr, @@ -2629,18 +2679,22 @@ library strings { uint needleptr ) private pure returns (uint) { uint ptr; + if (needlelen <= selflen) { if (needlelen <= 32) { bytes32 mask = bytes32(~(2 ** (8 * (32 - needlelen)) - 1)); + bytes32 needledata; assembly { needledata := and(mload(needleptr),mask) } + ptr = selfptr + selflen - needlelen; bytes32 ptrdata; assembly { ptrdata := and(mload(ptr),mask) } + while(ptrdata != needledata){ if (ptr <= selfptr) return selfptr; ptr--; @@ -2667,6 +2721,7 @@ library strings { } return selfptr; } + function find( slice memory self, slice memory needle @@ -2676,6 +2731,7 @@ library strings { self._ptr = ptr; return self; } + function rfind( slice memory self, slice memory needle @@ -2684,6 +2740,7 @@ library strings { self._len = ptr - self._ptr; return self; } + function split( slice memory self, slice memory needle, @@ -2700,12 +2757,14 @@ library strings { } return token; } + function split( slice memory self, slice memory needle ) internal pure returns (slice memory token) { split(self, needle, token); } + function rsplit( slice memory self, slice memory needle, @@ -2721,12 +2780,14 @@ library strings { } return token; } + function rsplit( slice memory self, slice memory needle ) internal pure returns (slice memory token) { rsplit(self, needle, token); } + function count( slice memory self, slice memory needle @@ -2745,6 +2806,7 @@ library strings { needle._len; } } + function contains( slice memory self, slice memory needle @@ -2752,6 +2814,7 @@ library strings { return rfindPtr(self._len, self._ptr, needle._len, needle._ptr) != self._ptr; } + function concat( slice memory self, slice memory other @@ -2765,20 +2828,24 @@ library strings { memcpy(retptr + self._len, other._ptr, other._len); return ret; } + function join( slice memory self, slice[] memory parts ) internal pure returns (string memory) { if (parts.length == 0) return ""; + uint length = self._len * (parts.length - 1); for (uint i = 0; i < parts.length; i++) { length += parts[i]._len; } + string memory ret = new string(length); uint retptr; assembly { retptr := add(ret,32) } + for (i = 0; i < parts.length; i++) { memcpy(retptr, parts[i]._ptr, parts[i]._len); retptr += parts[i]._len; @@ -2787,6 +2854,7 @@ library strings { retptr += self._len; } } + return ret; } } From 8126918d8c12acbe8930525a1c50e80d5457c4f2 Mon Sep 17 00:00:00 2001 From: Klaus Date: Tue, 18 Jun 2024 09:02:47 +1200 Subject: [PATCH 032/160] cleanup --- src/common/printer-helpers.js | 5 ++--- src/common/slang-helpers.js | 9 +++++++-- src/slang-nodes/ABICoderPragma.js | 2 +- src/slang-nodes/AddressType.js | 2 +- src/slang-nodes/BreakStatement.js | 2 +- src/slang-nodes/ContinueStatement.js | 2 +- src/slang-nodes/EnumMembers.js | 2 +- src/slang-nodes/FunctionName.js | 2 +- src/slang-nodes/FunctionTypeAttribute.js | 2 +- src/slang-nodes/HexStringLiteral.js | 2 +- src/slang-nodes/IdentifierPath.js | 2 +- src/slang-nodes/ImportAlias.js | 2 +- src/slang-nodes/MemberAccess.js | 2 +- src/slang-nodes/NumberUnit.js | 2 +- src/slang-nodes/StorageLocation.js | 2 +- src/slang-nodes/StringLiteral.js | 2 +- src/slang-nodes/ThrowStatement.js | 2 +- src/slang-nodes/UnicodeStringLiteral.js | 2 +- src/slang-nodes/UsingOperator.js | 2 +- src/slang-nodes/VersionSpecifiers.js | 2 +- src/slang-nodes/YulBreakStatement.js | 2 +- src/slang-nodes/YulBuiltInFunction.js | 2 +- src/slang-nodes/YulColonAndEqual.js | 2 +- src/slang-nodes/YulContinueStatement.js | 2 +- src/slang-nodes/YulLabel.js | 2 +- src/slang-nodes/YulLeaveStatement.js | 2 +- src/slang-nodes/YulParameters.js | 2 +- src/slang-nodes/YulPathComponent.js | 2 +- src/slang-nodes/YulReturnVariables.js | 2 +- 29 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/common/printer-helpers.js b/src/common/printer-helpers.js index d7005bf47..1401e1aac 100644 --- a/src/common/printer-helpers.js +++ b/src/common/printer-helpers.js @@ -40,15 +40,14 @@ export function printPreservingEmptyLines(path, key, options, print) { const parts = []; path.each((childPath, index) => { const node = childPath.getValue(); - const nodeType = node.type || node.kind; + const nodeType = node.type; if ( // Avoid adding a hardline at the beginning of the document. parts.length !== 0 && // LabelDefinition adds a dedented line so we don't have to prepend a // hardline. - nodeType !== 'LabelDefinition' && - (nodeType !== 'YulStatement' || node.variant.kind !== 'YulLabel') + nodeType !== 'LabelDefinition' ) { parts.push(hardline); } diff --git a/src/common/slang-helpers.js b/src/common/slang-helpers.js index 6cae1ed46..82b40fd8f 100644 --- a/src/common/slang-helpers.js +++ b/src/common/slang-helpers.js @@ -26,7 +26,7 @@ export function printPreservingEmptyLines(path, key, options, print) { // Only attempt to prepend an empty line if `node` is not the first item index > 0 && // YulLabel adds a dedented line so we don't have to prepend a hardline. - node.variant.kind !== 'YulLabel' + (node.kind !== 'YulStatement' || node.variant.kind !== 'YulLabel') ? hardline : '', print(childPath), @@ -181,12 +181,17 @@ export const tryHug = (node, operators) => { ) return { kind: 'Expression', + loc: { ...node.loc }, variant: { kind: 'TupleExpression', + loc: { ...node.loc }, openParen: '(', items: { kind: 'TupleValues', - items: [{ kind: 'TupleValue', expression: node }], + loc: { ...node.loc }, + items: [ + { kind: 'TupleValue', loc: { ...node.loc }, expression: node } + ], separators: [] }, closeParen: ')' diff --git a/src/slang-nodes/ABICoderPragma.js b/src/slang-nodes/ABICoderPragma.js index a590793e1..5c590a8dc 100644 --- a/src/slang-nodes/ABICoderPragma.js +++ b/src/slang-nodes/ABICoderPragma.js @@ -1,5 +1,5 @@ export const ABICoderPragma = { - parse: ({ node, offsets, ast }) => ({ + parse: ({ node, ast }) => ({ ...node, abicoderKeyword: ast.abicoderKeyword.text, version: ast.version.text diff --git a/src/slang-nodes/AddressType.js b/src/slang-nodes/AddressType.js index 43cf29d79..43d2ac6af 100644 --- a/src/slang-nodes/AddressType.js +++ b/src/slang-nodes/AddressType.js @@ -1,5 +1,5 @@ export const AddressType = { - parse: ({ node, offsets, ast }) => ({ + parse: ({ node, ast }) => ({ ...node, addressKeyword: ast.addressKeyword.text, payableKeyword: ast.payableKeyword?.text diff --git a/src/slang-nodes/BreakStatement.js b/src/slang-nodes/BreakStatement.js index 7dd8b488d..3fc29b9e1 100644 --- a/src/slang-nodes/BreakStatement.js +++ b/src/slang-nodes/BreakStatement.js @@ -1,5 +1,5 @@ export const BreakStatement = { - parse: ({ node, offsets, ast }) => ({ + parse: ({ node, ast }) => ({ ...node, breakKeyword: ast.breakKeyword.text, semicolon: ast.semicolon.text diff --git a/src/slang-nodes/ContinueStatement.js b/src/slang-nodes/ContinueStatement.js index c2c69480a..c3ba84d88 100644 --- a/src/slang-nodes/ContinueStatement.js +++ b/src/slang-nodes/ContinueStatement.js @@ -1,5 +1,5 @@ export const ContinueStatement = { - parse: ({ node, offsets, ast }) => ({ + parse: ({ node, ast }) => ({ ...node, continueKeyword: ast.continueKeyword.text, semicolon: ast.semicolon.text diff --git a/src/slang-nodes/EnumMembers.js b/src/slang-nodes/EnumMembers.js index 473a0afec..3b782a0b4 100644 --- a/src/slang-nodes/EnumMembers.js +++ b/src/slang-nodes/EnumMembers.js @@ -4,7 +4,7 @@ import { printSeparatedList } from '../common/printer-helpers.js'; const { hardline } = doc.builders; export const EnumMembers = { - parse: ({ node, offsets, ast }) => ({ + parse: ({ node, ast }) => ({ ...node, items: ast.items.map((item) => item.text), separators: ast.separators.map((separator) => separator.text) diff --git a/src/slang-nodes/FunctionName.js b/src/slang-nodes/FunctionName.js index 89442e90e..4d14af1c0 100644 --- a/src/slang-nodes/FunctionName.js +++ b/src/slang-nodes/FunctionName.js @@ -1,5 +1,5 @@ export const FunctionName = { - parse: ({ node, offsets, ast }) => ({ + parse: ({ node, ast }) => ({ ...node, variant: ast.variant.text }), diff --git a/src/slang-nodes/FunctionTypeAttribute.js b/src/slang-nodes/FunctionTypeAttribute.js index 07e6df457..132e30aef 100644 --- a/src/slang-nodes/FunctionTypeAttribute.js +++ b/src/slang-nodes/FunctionTypeAttribute.js @@ -1,5 +1,5 @@ export const FunctionTypeAttribute = { - parse: ({ node, offsets, ast }) => ({ + parse: ({ node, ast }) => ({ ...node, variant: ast.variant.text }), diff --git a/src/slang-nodes/HexStringLiteral.js b/src/slang-nodes/HexStringLiteral.js index d97a82caf..5145d9e39 100644 --- a/src/slang-nodes/HexStringLiteral.js +++ b/src/slang-nodes/HexStringLiteral.js @@ -1,7 +1,7 @@ import { printString } from '../common/util.js'; export const HexStringLiteral = { - parse: ({ node, offsets, ast, options }) => ({ + parse: ({ node, ast, options }) => ({ ...node, variant: `hex${printString(ast.variant.text.slice(4, -1), options)}` }), diff --git a/src/slang-nodes/IdentifierPath.js b/src/slang-nodes/IdentifierPath.js index 92b16b7f5..7cffda01a 100644 --- a/src/slang-nodes/IdentifierPath.js +++ b/src/slang-nodes/IdentifierPath.js @@ -1,5 +1,5 @@ export const IdentifierPath = { - parse: ({ node, offsets, ast }) => ({ + parse: ({ node, ast }) => ({ ...node, items: ast.items.map((item) => item.text), separators: ast.separators.map((separator) => separator.text) diff --git a/src/slang-nodes/ImportAlias.js b/src/slang-nodes/ImportAlias.js index a87fc63e3..d96a6f34e 100644 --- a/src/slang-nodes/ImportAlias.js +++ b/src/slang-nodes/ImportAlias.js @@ -1,5 +1,5 @@ export const ImportAlias = { - parse: ({ node, offsets, ast }) => ({ + parse: ({ node, ast }) => ({ ...node, asKeyword: ast.asKeyword.text, identifier: ast.identifier.text diff --git a/src/slang-nodes/MemberAccess.js b/src/slang-nodes/MemberAccess.js index bd6be90ac..837864f01 100644 --- a/src/slang-nodes/MemberAccess.js +++ b/src/slang-nodes/MemberAccess.js @@ -1,5 +1,5 @@ export const MemberAccess = { - parse: ({ node, offsets, ast }) => ({ + parse: ({ node, ast }) => ({ ...node, variant: ast.variant.text }), diff --git a/src/slang-nodes/NumberUnit.js b/src/slang-nodes/NumberUnit.js index e15e434c8..6cff6561a 100644 --- a/src/slang-nodes/NumberUnit.js +++ b/src/slang-nodes/NumberUnit.js @@ -1,5 +1,5 @@ export const NumberUnit = { - parse: ({ node, offsets, ast }) => ({ + parse: ({ node, ast }) => ({ ...node, variant: ast.variant.text }), diff --git a/src/slang-nodes/StorageLocation.js b/src/slang-nodes/StorageLocation.js index d0a3fd1f0..aa4c8b079 100644 --- a/src/slang-nodes/StorageLocation.js +++ b/src/slang-nodes/StorageLocation.js @@ -1,5 +1,5 @@ export const StorageLocation = { - parse: ({ node, offsets, ast }) => ({ + parse: ({ node, ast }) => ({ ...node, variant: ast.variant.text }), diff --git a/src/slang-nodes/StringLiteral.js b/src/slang-nodes/StringLiteral.js index 2ab12f95c..ef0a08fe3 100644 --- a/src/slang-nodes/StringLiteral.js +++ b/src/slang-nodes/StringLiteral.js @@ -1,7 +1,7 @@ import { printString } from '../common/util.js'; export const StringLiteral = { - parse: ({ node, offsets, ast, options }) => ({ + parse: ({ node, ast, options }) => ({ ...node, variant: printString(ast.variant.text.slice(1, -1), options) }), diff --git a/src/slang-nodes/ThrowStatement.js b/src/slang-nodes/ThrowStatement.js index 56c59ba79..ef06be154 100644 --- a/src/slang-nodes/ThrowStatement.js +++ b/src/slang-nodes/ThrowStatement.js @@ -1,5 +1,5 @@ export const ThrowStatement = { - parse: ({ node, offsets, ast }) => ({ + parse: ({ node, ast }) => ({ ...node, throwKeyword: ast.throwKeyword.text, semicolon: ast.semicolon.text diff --git a/src/slang-nodes/UnicodeStringLiteral.js b/src/slang-nodes/UnicodeStringLiteral.js index b103b8343..35fbb823f 100644 --- a/src/slang-nodes/UnicodeStringLiteral.js +++ b/src/slang-nodes/UnicodeStringLiteral.js @@ -1,7 +1,7 @@ import { printString } from '../common/util.js'; export const UnicodeStringLiteral = { - parse: ({ node, offsets, ast, options }) => ({ + parse: ({ node, ast, options }) => ({ ...node, variant: `unicode${printString(ast.variant.text.slice(8, -1), options)}` }), diff --git a/src/slang-nodes/UsingOperator.js b/src/slang-nodes/UsingOperator.js index 9e1b1912d..8a02bab5c 100644 --- a/src/slang-nodes/UsingOperator.js +++ b/src/slang-nodes/UsingOperator.js @@ -1,5 +1,5 @@ export const UsingOperator = { - parse: ({ node, offsets, ast }) => ({ + parse: ({ node, ast }) => ({ ...node, variant: ast.variant.text }), diff --git a/src/slang-nodes/VersionSpecifiers.js b/src/slang-nodes/VersionSpecifiers.js index 1ce951af2..90053d7e6 100644 --- a/src/slang-nodes/VersionSpecifiers.js +++ b/src/slang-nodes/VersionSpecifiers.js @@ -1,5 +1,5 @@ export const VersionSpecifiers = { - parse: ({ node, offsets, ast }) => ({ + parse: ({ node, ast }) => ({ ...node, items: ast.items.map((item) => item.text), separators: ast.separators.map((separator) => separator.text) diff --git a/src/slang-nodes/YulBreakStatement.js b/src/slang-nodes/YulBreakStatement.js index 5b955ae22..f18e22db3 100644 --- a/src/slang-nodes/YulBreakStatement.js +++ b/src/slang-nodes/YulBreakStatement.js @@ -1,5 +1,5 @@ export const YulBreakStatement = { - parse: ({ node, offsets, ast }) => ({ + parse: ({ node, ast }) => ({ ...node, breakKeyword: ast.breakKeyword.text }), diff --git a/src/slang-nodes/YulBuiltInFunction.js b/src/slang-nodes/YulBuiltInFunction.js index 293de3024..35396756a 100644 --- a/src/slang-nodes/YulBuiltInFunction.js +++ b/src/slang-nodes/YulBuiltInFunction.js @@ -1,5 +1,5 @@ export const YulBuiltInFunction = { - parse: ({ node, offsets, ast }) => ({ + parse: ({ node, ast }) => ({ ...node, variant: ast.variant.text }), diff --git a/src/slang-nodes/YulColonAndEqual.js b/src/slang-nodes/YulColonAndEqual.js index b5ea7ee63..839437b05 100644 --- a/src/slang-nodes/YulColonAndEqual.js +++ b/src/slang-nodes/YulColonAndEqual.js @@ -1,5 +1,5 @@ export const YulColonAndEqual = { - parse: ({ node, offsets, ast }) => ({ + parse: ({ node, ast }) => ({ ...node, colon: ast.colon.text, equal: ast.equal.text diff --git a/src/slang-nodes/YulContinueStatement.js b/src/slang-nodes/YulContinueStatement.js index 71116e627..4249f030b 100644 --- a/src/slang-nodes/YulContinueStatement.js +++ b/src/slang-nodes/YulContinueStatement.js @@ -1,5 +1,5 @@ export const YulContinueStatement = { - parse: ({ node, offsets, ast }) => ({ + parse: ({ node, ast }) => ({ ...node, continueKeyword: ast.continueKeyword.text }), diff --git a/src/slang-nodes/YulLabel.js b/src/slang-nodes/YulLabel.js index 6c227b0b4..60f3cfc8a 100644 --- a/src/slang-nodes/YulLabel.js +++ b/src/slang-nodes/YulLabel.js @@ -3,7 +3,7 @@ import { doc } from 'prettier'; const { dedent, line } = doc.builders; export const YulLabel = { - parse: ({ node, offsets, ast }) => ({ + parse: ({ node, ast }) => ({ ...node, label: ast.label.text, colon: ast.colon.text diff --git a/src/slang-nodes/YulLeaveStatement.js b/src/slang-nodes/YulLeaveStatement.js index 516cbe5a0..6dab0ba6e 100644 --- a/src/slang-nodes/YulLeaveStatement.js +++ b/src/slang-nodes/YulLeaveStatement.js @@ -1,5 +1,5 @@ export const YulLeaveStatement = { - parse: ({ node, offsets, ast }) => ({ + parse: ({ node, ast }) => ({ ...node, leaveKeyword: ast.leaveKeyword.text }), diff --git a/src/slang-nodes/YulParameters.js b/src/slang-nodes/YulParameters.js index 455eb0dd0..24090d0f8 100644 --- a/src/slang-nodes/YulParameters.js +++ b/src/slang-nodes/YulParameters.js @@ -1,7 +1,7 @@ import { printSeparatedList } from '../common/printer-helpers.js'; export const YulParameters = { - parse: ({ node, offsets, ast }) => ({ + parse: ({ node, ast }) => ({ ...node, items: ast.items.map((item) => item.text), separators: ast.separators.map((separator) => separator.text) diff --git a/src/slang-nodes/YulPathComponent.js b/src/slang-nodes/YulPathComponent.js index 8e9217645..05c59e794 100644 --- a/src/slang-nodes/YulPathComponent.js +++ b/src/slang-nodes/YulPathComponent.js @@ -1,5 +1,5 @@ export const YulPathComponent = { - parse: ({ node, offsets, ast }) => ({ + parse: ({ node, ast }) => ({ ...node, variant: ast.variant.text }), diff --git a/src/slang-nodes/YulReturnVariables.js b/src/slang-nodes/YulReturnVariables.js index 8a3bf6ea0..a99e8ff06 100644 --- a/src/slang-nodes/YulReturnVariables.js +++ b/src/slang-nodes/YulReturnVariables.js @@ -4,7 +4,7 @@ import { printSeparatedList } from '../common/printer-helpers.js'; const { line } = doc.builders; export const YulReturnVariables = { - parse: ({ node, offsets, ast }) => ({ + parse: ({ node, ast }) => ({ ...node, items: ast.items.map((item) => item.text), separators: ast.separators.map((separator) => separator.text) From 6829687773e24b1c08469c6c3ef8c7c880cc100c Mon Sep 17 00:00:00 2001 From: Klaus Date: Thu, 20 Jun 2024 16:53:08 +1200 Subject: [PATCH 033/160] refactor type checks --- src/common/printer-helpers.js | 35 +++---- src/common/slang-helpers.js | 126 +++++++++++++----------- src/index.js | 10 +- src/slang-nodes/AssignmentExpression.js | 4 +- src/slangParser.js | 11 +-- 5 files changed, 96 insertions(+), 90 deletions(-) diff --git a/src/common/printer-helpers.js b/src/common/printer-helpers.js index 1401e1aac..15ce5e4de 100644 --- a/src/common/printer-helpers.js +++ b/src/common/printer-helpers.js @@ -37,35 +37,26 @@ export const printComments = (node, path, options, filter = () => true) => { }; export function printPreservingEmptyLines(path, key, options, print) { - const parts = []; - path.each((childPath, index) => { - const node = childPath.getValue(); - const nodeType = node.type; - - if ( + return path.map((childPath, index) => { + const node = childPath.getNode(); + return [ // Avoid adding a hardline at the beginning of the document. - parts.length !== 0 && + index > 0 && // LabelDefinition adds a dedented line so we don't have to prepend a // hardline. - nodeType !== 'LabelDefinition' - ) { - parts.push(hardline); - } - - parts.push(print(childPath)); - - // Only attempt to append an empty line if `node` is not the last item - if ( + node.type !== 'LabelDefinition' + ? hardline + : '', + print(childPath), + // Only attempt to append an empty line if `node` is not the last item !isLast(childPath, key, index) && - isNextLineEmpty(options.originalText, options.locEnd(node) + 1) - ) { // Append an empty line if the original text already had an one after // the current `node` - parts.push(hardline); - } + isNextLineEmpty(options.originalText, options.locEnd(node) + 1) + ? hardline + : '' + ]; }, key); - - return parts; } // This function will add an indentation to the `item` and separate it from the diff --git a/src/common/slang-helpers.js b/src/common/slang-helpers.js index 82b40fd8f..0b98328bd 100644 --- a/src/common/slang-helpers.js +++ b/src/common/slang-helpers.js @@ -3,20 +3,24 @@ import { isLast, isNextLineEmpty } from './backward-compatibility.js'; const { dedent, group, hardline, indent, line } = doc.builders; -export const printFunction = (functionName, node, path, print) => [ - group([ - functionName, - path.call(print, 'parameters'), - indent( - group([ - path.call(print, 'attributes'), - node.returns ? [line, path.call(print, 'returns')] : '', - node.body?.variant !== ';' ? dedent(line) : '' - ]) - ) - ]), - node.body ? path.call(print, 'body') : '' -]; +function createKindCheckFunction(kindsArray) { + const kinds = new Set(kindsArray); + return (node) => kinds.has(node?.kind); +} + +export const isBlockComment = createKindCheckFunction([ + 'MultiLineComment', + 'MultiLineNatSpecComment' +]); + +export const isLineComment = createKindCheckFunction([ + 'SingleLineComment', + 'SingleLineNatSpecComment' +]); + +export function isComment(node) { + return isBlockComment(node) || isLineComment(node); +} export function printPreservingEmptyLines(path, key, options, print) { return path.map((childPath, index) => { @@ -41,7 +45,22 @@ export function printPreservingEmptyLines(path, key, options, print) { }, key); } -export const binaryOperationKinds = [ +export const printFunction = (functionName, node, path, print) => [ + group([ + functionName, + path.call(print, 'parameters'), + indent( + group([ + path.call(print, 'attributes'), + node.returns ? [line, path.call(print, 'returns')] : '', + node.body?.variant !== ';' ? dedent(line) : '' + ]) + ) + ]), + node.body ? path.call(print, 'body') : '' +]; + +export const isBinaryOperation = createKindCheckFunction([ 'AdditiveExpression', 'MultiplicativeExpression', 'ExponentiationExpression', @@ -54,15 +73,14 @@ export const binaryOperationKinds = [ 'AndExpression', 'OrExpression', 'ShiftExpression' -]; - -const binaryOperationKindsWithoutComparison = binaryOperationKinds.filter( - (kind) => kind !== 'ComparisonExpression' -); +]); const binaryGroupRulesBuilder = (path) => (document) => { const grandparentNode = path.getNode(2); - if (binaryOperationKindsWithoutComparison.includes(grandparentNode.kind)) { + if ( + isBinaryOperation(grandparentNode) && + grandparentNode.kind !== 'ComparisonExpression' + ) { return document; } return group(document); @@ -72,66 +90,64 @@ const binaryIndentRulesBuilder = (path) => (document) => { let node = path.getNode(); for (let i = 2; ; i += 2) { const grandparentNode = path.getNode(i); - if (grandparentNode.kind === 'ReturnStatement') return document; - if (!binaryOperationKindsWithoutComparison.includes(grandparentNode.kind)) { + if (grandparentNode.kind === 'ReturnStatement') break; + if ( + !isBinaryOperation(grandparentNode) || + grandparentNode.kind === 'ComparisonExpression' + ) { return indent(document); } - if (node === grandparentNode.rightOperand.variant) return document; + if (node === grandparentNode.rightOperand.variant) break; node = grandparentNode; } + return document; }; const comparisonGroupRulesBuilder = () => (document) => group(document); -const comparisonStatementsWithoutIndentationKinds = [ - 'ReturnStatement', - 'IfStatement', - 'ForStatement', - 'WhileStatement' -]; +const isStatementWithComparisonOperationWithoutIndentation = + createKindCheckFunction([ + 'ReturnStatement', + 'IfStatement', + 'ForStatement', + 'WhileStatement' + ]); const comparisonIndentRulesBuilder = (path) => (document) => { let node = path.getNode(); for (let i = 2; ; i += 2) { const grandparentNode = path.getNode(i); - if ( - comparisonStatementsWithoutIndentationKinds.includes(grandparentNode.kind) - ) - return document; - if (!binaryOperationKinds.includes(grandparentNode.kind)) - return indent(document); - if (node === grandparentNode.rightOperand.variant) return document; + if (isStatementWithComparisonOperationWithoutIndentation(grandparentNode)) + break; + if (!isBinaryOperation(grandparentNode)) return indent(document); + if (node === grandparentNode.rightOperand.variant) break; node = grandparentNode; } + return document; }; const logicalGroupRulesBuilder = (path) => (document) => - binaryOperationKinds.includes(path.getNode(2).kind) - ? document - : group(document); + isBinaryOperation(path.getNode(2)) ? document : group(document); -const logicalStatementsWithoutIndentationKinds = - comparisonStatementsWithoutIndentationKinds.filter( - (kind) => kind !== 'ForStatement' - ); +const isStatementWithLogicalOperationWithoutIndentation = + createKindCheckFunction(['ReturnStatement', 'IfStatement', 'WhileStatement']); const logicalIndentRulesBuilder = (path, options) => (document) => { let node = path.getNode(); for (let i = 2; ; i += 2) { const parentNode = path.getNode(i); - if (logicalStatementsWithoutIndentationKinds.includes(parentNode.kind)) - return document; + if (isStatementWithLogicalOperationWithoutIndentation(parentNode)) break; if ( options.experimentalTernaries && parentNode.kind === 'ConditionalExpression' && parentNode.operand.variant === node ) - return document; - if (!binaryOperationKinds.includes(parentNode.kind)) - return indent(document); - if (node === parentNode.rightOperand.variant) return document; + break; + if (!isBinaryOperation(parentNode)) return indent(document); + if (node === parentNode.rightOperand.variant) break; node = parentNode; } + return document; }; export const rightOperandPrint = (node, path, print) => { @@ -140,8 +156,8 @@ export const rightOperandPrint = (node, path, print) => { // If it's a single binary operation, avoid having a small right // operand like - 1 on its own line const shouldGroup = - !binaryOperationKinds.includes(node.leftOperand.variant.kind) && - !binaryOperationKinds.includes(path.getNode(2).kind); + !isBinaryOperation(node.leftOperand.variant) && + !isBinaryOperation(path.getNode(2)); return shouldGroup ? group(rightOperand) : rightOperand; }; @@ -174,10 +190,10 @@ export const logicalOperationPrint = binaryOperationPrintBuilder( logicalIndentRulesBuilder ); -export const tryHug = (node, operators) => { +export const tryHug = (node, huggableOperators) => { if ( - binaryOperationKinds.includes(node.variant.kind) && - operators.includes(node.variant.operator) + isBinaryOperation(node.variant) && + huggableOperators.has(node.variant.operator) ) return { kind: 'Expression', diff --git a/src/index.js b/src/index.js index d6cc17c78..fbe163c97 100644 --- a/src/index.js +++ b/src/index.js @@ -6,6 +6,8 @@ import parse from './parser.js'; import print from './printer.js'; import slangParse from './slangParser.js'; import slangPrint from './slangPrinter.js'; +import { isComment, isBlockComment } from './common/slang-helpers.js'; +import { printComment } from './slangCommentPrinter.js'; // https://prettier.io/docs/en/plugins.html#languages // https://github.com/ikatyang/linguist-languages/blob/master/data/Solidity.json @@ -39,6 +41,8 @@ const parsers = { const canAttachComment = (node) => node.type && node.type !== 'BlockComment' && node.type !== 'LineComment'; +const slangCanAttachComment = (node) => node.kind && !isComment(node); + // https://prettier.io/docs/en/plugins.html#printers const printers = { 'solidity-ast': { @@ -54,16 +58,16 @@ const printers = { printComment: comments.printComment }, 'solidity-slang-ast': { - canAttachComment, + slangCanAttachComment, handleComments: { ownLine: comments.solidityHandleOwnLineComment, endOfLine: comments.solidityHandleEndOfLineComment, remaining: comments.solidityHandleRemainingComment }, - isBlockComment: comments.isBlockComment, + isBlockComment, massageAstNode, print: slangPrint, - printComment: comments.printComment + printComment } }; diff --git a/src/slang-nodes/AssignmentExpression.js b/src/slang-nodes/AssignmentExpression.js index e8b4176d7..9f8e17b70 100644 --- a/src/slang-nodes/AssignmentExpression.js +++ b/src/slang-nodes/AssignmentExpression.js @@ -1,5 +1,5 @@ import { doc } from 'prettier'; -import { binaryOperationKinds } from '../common/slang-helpers.js'; +import { isBinaryOperation } from '../common/slang-helpers.js'; const { group, indent, line } = doc.builders; @@ -13,7 +13,7 @@ export const AssignmentExpression = { print: ({ node, path, print }) => [ path.call(print, 'leftOperand'), ` ${node.operator}`, - binaryOperationKinds.includes(node.rightOperand.variant.kind) + isBinaryOperation(node.rightOperand.variant) ? group(indent([line, path.call(print, 'rightOperand')])) : [' ', path.call(print, 'rightOperand')] ] diff --git a/src/slangParser.js b/src/slangParser.js index 20fee589c..a2a9d0a36 100644 --- a/src/slangParser.js +++ b/src/slangParser.js @@ -5,13 +5,7 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SourceUnit } from '@nomicfoundation/slang/ast/index.js'; import coerce from 'semver/functions/coerce.js'; import * as parsers from './slang-nodes/index.js'; - -const commentKinds = [ - 'MultiLineComment', - 'MultiLineNatSpecComment', - 'SingleLineComment', - 'SingleLineNatSpecComment' -]; +import { isComment } from './common/slang-helpers.js'; const getCommentsAndOffsets = (ast, nodeOffset) => { const children = ast.cst.children(); @@ -21,8 +15,9 @@ const getCommentsAndOffsets = (ast, nodeOffset) => { if (child.type === 'Nonterminal') { commentsAndOffsets.offsets.push(offset); } - if (child.type === 'Terminal' && commentKinds.includes(child.kind)) { + if (child.type === 'Terminal' && isComment(child)) { commentsAndOffsets.comments.push({ + kind: child.kind, value: child.text, loc: { start: offset, From f1243f3ec9f2e6d43905ce793a0f66694becf239 Mon Sep 17 00:00:00 2001 From: Klaus Date: Thu, 20 Jun 2024 17:04:20 +1200 Subject: [PATCH 034/160] using set#has instead of array#includes --- src/common/slang-helpers.js | 2 +- src/slang-nodes/AdditiveExpression.js | 14 +++++-- src/slang-nodes/BitwiseAndExpression.js | 28 +++++--------- src/slang-nodes/BitwiseOrExpression.js | 42 ++++++++++----------- src/slang-nodes/BitwiseXorExpression.js | 30 +++++---------- src/slang-nodes/ExponentiationExpression.js | 6 ++- src/slang-nodes/MemberAccessExpression.js | 13 ++++--- src/slang-nodes/MultiplicativeExpression.js | 10 +++-- src/slang-nodes/OrExpression.js | 16 +++++--- src/slang-nodes/ShiftExpression.js | 35 +++++++++-------- 10 files changed, 99 insertions(+), 97 deletions(-) diff --git a/src/common/slang-helpers.js b/src/common/slang-helpers.js index 0b98328bd..6cec31388 100644 --- a/src/common/slang-helpers.js +++ b/src/common/slang-helpers.js @@ -3,7 +3,7 @@ import { isLast, isNextLineEmpty } from './backward-compatibility.js'; const { dedent, group, hardline, indent, line } = doc.builders; -function createKindCheckFunction(kindsArray) { +export function createKindCheckFunction(kindsArray) { const kinds = new Set(kindsArray); return (node) => kinds.has(node?.kind); } diff --git a/src/slang-nodes/AdditiveExpression.js b/src/slang-nodes/AdditiveExpression.js index 70e2f3c69..f5a95493a 100644 --- a/src/slang-nodes/AdditiveExpression.js +++ b/src/slang-nodes/AdditiveExpression.js @@ -1,13 +1,19 @@ import { binaryOperationPrint, tryHug } from '../common/slang-helpers.js'; +const huggableOperators = new Set(['%']); + export const AdditiveExpression = { parse: ({ node, offsets, ast, options, parse }) => ({ ...node, - leftOperand: tryHug(parse(ast.leftOperand, options, parse, offsets), ['%']), + leftOperand: tryHug( + parse(ast.leftOperand, options, parse, offsets), + huggableOperators + ), operator: ast.operator.text, - rightOperand: tryHug(parse(ast.rightOperand, options, parse, offsets), [ - '%' - ]) + rightOperand: tryHug( + parse(ast.rightOperand, options, parse, offsets), + huggableOperators + ) }), print: binaryOperationPrint }; diff --git a/src/slang-nodes/BitwiseAndExpression.js b/src/slang-nodes/BitwiseAndExpression.js index b501d0abe..555683d8c 100644 --- a/src/slang-nodes/BitwiseAndExpression.js +++ b/src/slang-nodes/BitwiseAndExpression.js @@ -1,27 +1,19 @@ import { binaryOperationPrint, tryHug } from '../common/slang-helpers.js'; +const huggableOperators = new Set(['+', '-', '*', '/', '**', '<<', '>>']); + export const BitwiseAndExpression = { parse: ({ node, offsets, ast, options, parse }) => ({ ...node, - leftOperand: tryHug(parse(ast.leftOperand, options, parse, offsets), [ - '+', - '-', - '*', - '/', - '**', - '<<', - '>>' - ]), + leftOperand: tryHug( + parse(ast.leftOperand, options, parse, offsets), + huggableOperators + ), operator: ast.operator.text, - rightOperand: tryHug(parse(ast.rightOperand, options, parse, offsets), [ - '+', - '-', - '*', - '/', - '**', - '<<', - '>>' - ]) + rightOperand: tryHug( + parse(ast.rightOperand, options, parse, offsets), + huggableOperators + ) }), print: binaryOperationPrint }; diff --git a/src/slang-nodes/BitwiseOrExpression.js b/src/slang-nodes/BitwiseOrExpression.js index da479affb..4f3ab709f 100644 --- a/src/slang-nodes/BitwiseOrExpression.js +++ b/src/slang-nodes/BitwiseOrExpression.js @@ -1,31 +1,29 @@ import { binaryOperationPrint, tryHug } from '../common/slang-helpers.js'; +const huggableOperators = new Set([ + '+', + '-', + '*', + '/', + '**', + '<<', + '>>', + '&', + '^' +]); + export const BitwiseOrExpression = { parse: ({ node, offsets, ast, options, parse }) => ({ ...node, - leftOperand: tryHug(parse(ast.leftOperand, options, parse, offsets), [ - '+', - '-', - '*', - '/', - '**', - '<<', - '>>', - '&', - '^' - ]), + leftOperand: tryHug( + parse(ast.leftOperand, options, parse, offsets), + huggableOperators + ), operator: ast.operator.text, - rightOperand: tryHug(parse(ast.rightOperand, options, parse, offsets), [ - '+', - '-', - '*', - '/', - '**', - '<<', - '>>', - '&', - '^' - ]) + rightOperand: tryHug( + parse(ast.rightOperand, options, parse, offsets), + huggableOperators + ) }), print: binaryOperationPrint }; diff --git a/src/slang-nodes/BitwiseXorExpression.js b/src/slang-nodes/BitwiseXorExpression.js index cf898083e..08f9a94d6 100644 --- a/src/slang-nodes/BitwiseXorExpression.js +++ b/src/slang-nodes/BitwiseXorExpression.js @@ -1,29 +1,19 @@ import { binaryOperationPrint, tryHug } from '../common/slang-helpers.js'; +const huggableOperators = new Set(['+', '-', '*', '/', '**', '<<', '>>', '&']); + export const BitwiseXorExpression = { parse: ({ node, offsets, ast, options, parse }) => ({ ...node, - leftOperand: tryHug(parse(ast.leftOperand, options, parse, offsets), [ - '+', - '-', - '*', - '/', - '**', - '<<', - '>>', - '&' - ]), + leftOperand: tryHug( + parse(ast.leftOperand, options, parse, offsets), + huggableOperators + ), operator: ast.operator.text, - rightOperand: tryHug(parse(ast.rightOperand, options, parse, offsets), [ - '+', - '-', - '*', - '/', - '**', - '<<', - '>>', - '&' - ]) + rightOperand: tryHug( + parse(ast.rightOperand, options, parse, offsets), + huggableOperators + ) }), print: binaryOperationPrint }; diff --git a/src/slang-nodes/ExponentiationExpression.js b/src/slang-nodes/ExponentiationExpression.js index 0b74b6403..b423fd203 100644 --- a/src/slang-nodes/ExponentiationExpression.js +++ b/src/slang-nodes/ExponentiationExpression.js @@ -5,6 +5,8 @@ import { rightOperandPrint, tryHug } from '../common/slang-helpers.js'; const { group, indent } = doc.builders; +const huggableOperators = new Set(['**']); + export const ExponentiationExpression = { parse: ({ node, offsets, ast, options, parse }) => { const compiler = coerce(options.compiler); @@ -13,9 +15,9 @@ export const ExponentiationExpression = { if (compiler) { if (satisfies(compiler, '>=0.8.0')) { - rightOperand = tryHug(rightOperand, ['**']); + rightOperand = tryHug(rightOperand, huggableOperators); } else { - leftOperand = tryHug(leftOperand, ['**']); + leftOperand = tryHug(leftOperand, huggableOperators); } } return { diff --git a/src/slang-nodes/MemberAccessExpression.js b/src/slang-nodes/MemberAccessExpression.js index 2698d23df..4ff6069f0 100644 --- a/src/slang-nodes/MemberAccessExpression.js +++ b/src/slang-nodes/MemberAccessExpression.js @@ -1,16 +1,19 @@ import { doc } from 'prettier'; import { isLabel } from '../common/util.js'; +import { createKindCheckFunction } from '../common/slang-helpers.js'; const { group, indent, label, softline } = doc.builders; +const isChainableExpression = createKindCheckFunction([ + 'FunctionCallExpression', + 'IndexAccessExpression', + 'MemberAccessExpression' +]); + const isEndOfChain = (node, path) => { for ( let i = 0, currentNode = node, grandparentNode = path.getNode(i + 2); - [ - 'FunctionCallExpression', - 'IndexAccessExpression', - 'MemberAccessExpression' - ].includes(grandparentNode.kind); + isChainableExpression(grandparentNode); i += 2, currentNode = grandparentNode, grandparentNode = path.getNode(i + 2) ) { switch (grandparentNode.kind) { diff --git a/src/slang-nodes/MultiplicativeExpression.js b/src/slang-nodes/MultiplicativeExpression.js index a288deb56..24e239758 100644 --- a/src/slang-nodes/MultiplicativeExpression.js +++ b/src/slang-nodes/MultiplicativeExpression.js @@ -1,5 +1,9 @@ import { binaryOperationPrint, tryHug } from '../common/slang-helpers.js'; +const multiplicationHuggableOperators = new Set(['/', '%']); +const divisionHuggableOperators = new Set(['*', '%']); +const moduloHuggableOperators = new Set(['*', '/', '%']); + export const MultiplicativeExpression = { parse: ({ node, offsets, ast, options, parse }) => { let leftOperand = parse(ast.leftOperand, options, parse, offsets); @@ -7,13 +11,13 @@ export const MultiplicativeExpression = { switch (operator) { case '*': - leftOperand = tryHug(leftOperand, ['/', '%']); + leftOperand = tryHug(leftOperand, multiplicationHuggableOperators); break; case '/': - leftOperand = tryHug(leftOperand, ['*', '%']); + leftOperand = tryHug(leftOperand, divisionHuggableOperators); break; case '%': - leftOperand = tryHug(leftOperand, ['*', '/', '%']); + leftOperand = tryHug(leftOperand, moduloHuggableOperators); break; default: break; diff --git a/src/slang-nodes/OrExpression.js b/src/slang-nodes/OrExpression.js index 66f3ca2d2..7e0703a2f 100644 --- a/src/slang-nodes/OrExpression.js +++ b/src/slang-nodes/OrExpression.js @@ -1,15 +1,19 @@ import { logicalOperationPrint, tryHug } from '../common/slang-helpers.js'; +const huggableOperators = new Set(['&&']); + export const OrExpression = { parse: ({ node, offsets, ast, options, parse }) => ({ ...node, - leftOperand: tryHug(parse(ast.leftOperand, options, parse, offsets), [ - '&&' - ]), + leftOperand: tryHug( + parse(ast.leftOperand, options, parse, offsets), + huggableOperators + ), operator: ast.operator.text, - rightOperand: tryHug(parse(ast.rightOperand, options, parse, offsets), [ - '&&' - ]) + rightOperand: tryHug( + parse(ast.rightOperand, options, parse, offsets), + huggableOperators + ) }), print: logicalOperationPrint }; diff --git a/src/slang-nodes/ShiftExpression.js b/src/slang-nodes/ShiftExpression.js index 93f6f10c4..cb2f34c93 100644 --- a/src/slang-nodes/ShiftExpression.js +++ b/src/slang-nodes/ShiftExpression.js @@ -1,25 +1,28 @@ import { binaryOperationPrint, tryHug } from '../common/slang-helpers.js'; +const leftOperandHuggableOperators = new Set([ + '+', + '-', + '*', + '/', + '**', + '<<', + '>>' +]); +const rightOperandHuggableOperators = new Set(['+', '-', '*', '/', '**']); + export const ShiftExpression = { parse: ({ node, offsets, ast, options, parse }) => ({ ...node, - leftOperand: tryHug(parse(ast.leftOperand, options, parse, offsets), [ - '+', - '-', - '*', - '/', - '**', - '<<', - '>>' - ]), + leftOperand: tryHug( + parse(ast.leftOperand, options, parse, offsets), + leftOperandHuggableOperators + ), operator: ast.operator.text, - rightOperand: tryHug(parse(ast.rightOperand, options, parse, offsets), [ - '+', - '-', - '*', - '/', - '**' - ]) + rightOperand: tryHug( + parse(ast.rightOperand, options, parse, offsets), + rightOperandHuggableOperators + ) }), print: binaryOperationPrint }; From c51855eb47c3353ea26566de30438589ae21f49e Mon Sep 17 00:00:00 2001 From: Klaus Date: Thu, 20 Jun 2024 18:22:02 +1200 Subject: [PATCH 035/160] renaming parser name --- src/index.js | 13 ++++++---- tests/config/format-test.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/AddressPayable/jsfmt.spec.js | 2 +- .../Arrays/__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/Arrays/jsfmt.spec.js | 2 +- .../Assembly/__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/Assembly/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/AssemblyV0.4.26/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/BasicIterator/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 4 ++-- tests/format/BinaryOperators/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 12 +++++----- .../BreakingChangesV0.7.4/jsfmt.spec.js | 12 +++++----- .../__snapshots__/jsfmt.spec.js.snap | 2 +- .../BreakingChangesV0.8.0/jsfmt.spec.js | 2 +- .../Comments/__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/Comments/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/Conditional/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/Constructors/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- .../format/ContractDefinitions/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/CustomErrors/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/EnumDefinitions/jsfmt.spec.js | 2 +- .../Etc/__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/Etc/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 8 +++---- .../ExperimentalTernaries/jsfmt.spec.js | 8 +++---- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/ForStatements/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 4 ++-- tests/format/FunctionCalls/jsfmt.spec.js | 4 ++-- .../__snapshots__/jsfmt.spec.js.snap | 2 +- .../format/FunctionDefinitions/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- .../FunctionDefinitionsv0.5.0/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 4 ++-- tests/format/HexLiteral/jsfmt.spec.js | 4 ++-- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/IfStatements/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/Immutable/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 4 ++-- tests/format/ImportDirective/jsfmt.spec.js | 4 ++-- .../Inbox/__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/Inbox/jsfmt.spec.js | 2 +- .../IndexOf/__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/IndexOf/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/IndexRangeAccess/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- .../format/InheritanceSpecifier/jsfmt.spec.js | 2 +- .../Issues/__snapshots__/jsfmt.spec.js.snap | 14 +++++------ tests/format/Issues/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 4 ++-- tests/format/Libraries/jsfmt.spec.js | 4 ++-- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/MemberAccess/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- .../format/ModifierDefinitions/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- .../format/ModifierInvocations/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/MultipartStrings/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 4 ++-- .../format/NameValueExpression/jsfmt.spec.js | 4 ++-- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/NumberLiteral/jsfmt.spec.js | 2 +- .../Ownable/__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/Ownable/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 24 +++++++++---------- tests/format/Parentheses/jsfmt.spec.js | 2 +- .../Pragma/__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/Pragma/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/PrettierIgnore/jsfmt.spec.js | 2 +- .../Proxy/__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/Proxy/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/SampleCrowdsale/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/SimpleAuction/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/SimpleStorage/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- .../format/SplittableCommodity/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- .../StateVariableDeclarations/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/StringLiteral/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 16 ++++++------- tests/format/StyleGuide/jsfmt.spec.js | 2 +- .../TryCatch/__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/TryCatch/jsfmt.spec.js | 2 +- .../Tupples/__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/Tupples/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/TypeDefinition/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/WhileStatements/jsfmt.spec.js | 2 +- .../quotes/__snapshots__/jsfmt.spec.js.snap | 4 ++-- tests/format/quotes/jsfmt.spec.js | 4 ++-- .../strings/__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/strings/jsfmt.spec.js | 2 +- 110 files changed, 170 insertions(+), 167 deletions(-) diff --git a/src/index.js b/src/index.js index fbe163c97..cc408a008 100644 --- a/src/index.js +++ b/src/index.js @@ -9,6 +9,9 @@ import slangPrint from './slangPrinter.js'; import { isComment, isBlockComment } from './common/slang-helpers.js'; import { printComment } from './slangCommentPrinter.js'; +const parserName = 'slang'; +const astFormat = 'slang-ast'; + // https://prettier.io/docs/en/plugins.html#languages // https://github.com/ikatyang/linguist-languages/blob/master/data/Solidity.json const languages = [ @@ -20,7 +23,7 @@ const languages = [ aceMode: 'text', tmScope: 'source.solidity', extensions: ['.sol'], - parsers: ['solidity-parse', 'solidity-slang-parser'], + parsers: ['solidity-parse', parserName], vscodeLanguageIds: ['solidity'] } ]; @@ -28,14 +31,14 @@ const languages = [ // https://prettier.io/docs/en/plugins.html#parsers const parser = { astFormat: 'solidity-ast', parse, ...loc }; const slangParser = { - astFormat: 'solidity-slang-ast', + astFormat, parse: slangParse, locStart: (node) => node.loc.start, locEnd: (node) => node.loc.end }; const parsers = { 'solidity-parse': parser, - 'solidity-slang-parse': slangParser + [parserName]: slangParser }; const canAttachComment = (node) => @@ -57,8 +60,8 @@ const printers = { print, printComment: comments.printComment }, - 'solidity-slang-ast': { - slangCanAttachComment, + [astFormat]: { + canAttachComment: slangCanAttachComment, handleComments: { ownLine: comments.solidityHandleOwnLineComment, endOfLine: comments.solidityHandleEndOfLineComment, diff --git a/tests/config/format-test.js b/tests/config/format-test.js index ec88285bc..5cd254548 100644 --- a/tests/config/format-test.js +++ b/tests/config/format-test.js @@ -83,7 +83,7 @@ const isAstUnstable = (filename, options) => { }; const shouldCompareBytecode = (filename, options) => { - if (options.parser === "solidity-slang-parse") return false; + if (options.parser === "slang") return false; const testFunction = testsWithAstChanges.get(filename); if (!testFunction) { diff --git a/tests/format/AddressPayable/__snapshots__/jsfmt.spec.js.snap b/tests/format/AddressPayable/__snapshots__/jsfmt.spec.js.snap index 02ac3b22f..827486583 100644 --- a/tests/format/AddressPayable/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/AddressPayable/__snapshots__/jsfmt.spec.js.snap @@ -37,7 +37,7 @@ contract AddressPayable { exports[`AddressPayable.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/AddressPayable/jsfmt.spec.js b/tests/format/AddressPayable/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/AddressPayable/jsfmt.spec.js +++ b/tests/format/AddressPayable/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/Arrays/__snapshots__/jsfmt.spec.js.snap b/tests/format/Arrays/__snapshots__/jsfmt.spec.js.snap index b1c2abec6..bce32895b 100644 --- a/tests/format/Arrays/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Arrays/__snapshots__/jsfmt.spec.js.snap @@ -64,7 +64,7 @@ contract ArraySlices { exports[`Arrays.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/Arrays/jsfmt.spec.js b/tests/format/Arrays/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/Arrays/jsfmt.spec.js +++ b/tests/format/Arrays/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/Assembly/__snapshots__/jsfmt.spec.js.snap b/tests/format/Assembly/__snapshots__/jsfmt.spec.js.snap index f8dbd1811..3452d1c7f 100644 --- a/tests/format/Assembly/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Assembly/__snapshots__/jsfmt.spec.js.snap @@ -521,7 +521,7 @@ contract AssemblyStackAssignment { exports[`Assembly.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/Assembly/jsfmt.spec.js b/tests/format/Assembly/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/Assembly/jsfmt.spec.js +++ b/tests/format/Assembly/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/AssemblyV0.4.26/__snapshots__/jsfmt.spec.js.snap b/tests/format/AssemblyV0.4.26/__snapshots__/jsfmt.spec.js.snap index a5fb69f04..bc94f8545 100644 --- a/tests/format/AssemblyV0.4.26/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/AssemblyV0.4.26/__snapshots__/jsfmt.spec.js.snap @@ -90,7 +90,7 @@ contract Assembly { exports[`Assembly.sol - {"compiler":"0.4.26"} format 2`] = ` ====================================options===================================== compiler: "0.4.26" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/AssemblyV0.4.26/jsfmt.spec.js b/tests/format/AssemblyV0.4.26/jsfmt.spec.js index a73b08dfc..9f2954259 100644 --- a/tests/format/AssemblyV0.4.26/jsfmt.spec.js +++ b/tests/format/AssemblyV0.4.26/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse'], { compiler: '0.4.26' }); -run_spec(import.meta, ['solidity-slang-parse'], { compiler: '0.4.26' }); +run_spec(import.meta, ['slang'], { compiler: '0.4.26' }); diff --git a/tests/format/BasicIterator/__snapshots__/jsfmt.spec.js.snap b/tests/format/BasicIterator/__snapshots__/jsfmt.spec.js.snap index 1d089b8c3..852556c6f 100644 --- a/tests/format/BasicIterator/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/BasicIterator/__snapshots__/jsfmt.spec.js.snap @@ -3,7 +3,7 @@ exports[`BasicIterator.sol - {"compiler":"0.4.26"} format 1`] = ` ====================================options===================================== compiler: "0.4.26" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/BasicIterator/jsfmt.spec.js b/tests/format/BasicIterator/jsfmt.spec.js index 18602c4e5..c8fb0ebbc 100644 --- a/tests/format/BasicIterator/jsfmt.spec.js +++ b/tests/format/BasicIterator/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse'], { compiler: '0.4.26' }); +run_spec(import.meta, ['slang'], { compiler: '0.4.26' }); diff --git a/tests/format/BinaryOperators/__snapshots__/jsfmt.spec.js.snap b/tests/format/BinaryOperators/__snapshots__/jsfmt.spec.js.snap index 9dae74e33..18f73fb47 100644 --- a/tests/format/BinaryOperators/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/BinaryOperators/__snapshots__/jsfmt.spec.js.snap @@ -3,7 +3,7 @@ exports[`BinaryOperators.sol - {"compiler":"0.5.8"} format 1`] = ` ====================================options===================================== compiler: "0.5.8" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -1349,7 +1349,7 @@ contract LogicalOperators { exports[`Parentheses.sol - {"compiler":"0.5.8"} format 1`] = ` ====================================options===================================== compiler: "0.5.8" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/BinaryOperators/jsfmt.spec.js b/tests/format/BinaryOperators/jsfmt.spec.js index 427a1e619..053aef41e 100644 --- a/tests/format/BinaryOperators/jsfmt.spec.js +++ b/tests/format/BinaryOperators/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse'], { compiler: '0.5.8' }); +run_spec(import.meta, ['slang'], { compiler: '0.5.8' }); diff --git a/tests/format/BreakingChangesV0.7.4/__snapshots__/jsfmt.spec.js.snap b/tests/format/BreakingChangesV0.7.4/__snapshots__/jsfmt.spec.js.snap index 9ef8f6e99..5c44e9a4e 100644 --- a/tests/format/BreakingChangesV0.7.4/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/BreakingChangesV0.7.4/__snapshots__/jsfmt.spec.js.snap @@ -34,7 +34,7 @@ import { symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4 } from exports[`BreakingChangesV0.7.4.sol - {"bracketSpacing":true} format 2`] = ` ====================================options===================================== bracketSpacing: true -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -92,7 +92,7 @@ exports[`BreakingChangesV0.7.4.sol - {"compiler":"0.7.3","bracketSpacing":true} ====================================options===================================== bracketSpacing: true compiler: "0.7.3" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -148,7 +148,7 @@ import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from " exports[`BreakingChangesV0.7.4.sol - {"compiler":"0.7.3"} format 2`] = ` ====================================options===================================== compiler: "0.7.3" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -211,7 +211,7 @@ exports[`BreakingChangesV0.7.4.sol - {"compiler":"0.7.4","bracketSpacing":true} ====================================options===================================== bracketSpacing: true compiler: "0.7.4" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -277,7 +277,7 @@ import { exports[`BreakingChangesV0.7.4.sol - {"compiler":"0.7.4"} format 2`] = ` ====================================options===================================== compiler: "0.7.4" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -336,7 +336,7 @@ import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from " exports[`BreakingChangesV0.7.4.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/BreakingChangesV0.7.4/jsfmt.spec.js b/tests/format/BreakingChangesV0.7.4/jsfmt.spec.js index 859b8b539..0d83de79c 100644 --- a/tests/format/BreakingChangesV0.7.4/jsfmt.spec.js +++ b/tests/format/BreakingChangesV0.7.4/jsfmt.spec.js @@ -12,17 +12,17 @@ run_spec(import.meta, ['solidity-parse']); run_spec(import.meta, ['solidity-parse'], { bracketSpacing: true }); -run_spec(import.meta, ['solidity-slang-parse'], { compiler: '0.7.4' }); -run_spec(import.meta, ['solidity-slang-parse'], { +run_spec(import.meta, ['slang'], { compiler: '0.7.4' }); +run_spec(import.meta, ['slang'], { compiler: '0.7.4', bracketSpacing: true }); -run_spec(import.meta, ['solidity-slang-parse'], { compiler: '0.7.3' }); -run_spec(import.meta, ['solidity-slang-parse'], { +run_spec(import.meta, ['slang'], { compiler: '0.7.3' }); +run_spec(import.meta, ['slang'], { compiler: '0.7.3', bracketSpacing: true }); -run_spec(import.meta, ['solidity-slang-parse']); -run_spec(import.meta, ['solidity-slang-parse'], { +run_spec(import.meta, ['slang']); +run_spec(import.meta, ['slang'], { bracketSpacing: true }); diff --git a/tests/format/BreakingChangesV0.8.0/__snapshots__/jsfmt.spec.js.snap b/tests/format/BreakingChangesV0.8.0/__snapshots__/jsfmt.spec.js.snap index b126fe0e6..f60aa1204 100644 --- a/tests/format/BreakingChangesV0.8.0/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/BreakingChangesV0.8.0/__snapshots__/jsfmt.spec.js.snap @@ -95,7 +95,7 @@ contract BreakingChangesV080 { exports[`BreakingChangesV0.8.0.sol - {"compiler":"0.7.0"} format 2`] = ` ====================================options===================================== compiler: "0.7.0" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/BreakingChangesV0.8.0/jsfmt.spec.js b/tests/format/BreakingChangesV0.8.0/jsfmt.spec.js index b65e9287f..05d7dfd79 100644 --- a/tests/format/BreakingChangesV0.8.0/jsfmt.spec.js +++ b/tests/format/BreakingChangesV0.8.0/jsfmt.spec.js @@ -1,4 +1,4 @@ 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' }); -run_spec(import.meta, ['solidity-slang-parse'], { compiler: '0.7.0' }); +run_spec(import.meta, ['slang'], { compiler: '0.7.0' }); diff --git a/tests/format/Comments/__snapshots__/jsfmt.spec.js.snap b/tests/format/Comments/__snapshots__/jsfmt.spec.js.snap index cbaff7fe3..a09391adb 100644 --- a/tests/format/Comments/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Comments/__snapshots__/jsfmt.spec.js.snap @@ -3,7 +3,7 @@ exports[`Comments.sol - {"compiler":"0.5.0"} format 1`] = ` ====================================options===================================== compiler: "0.5.0" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/Comments/jsfmt.spec.js b/tests/format/Comments/jsfmt.spec.js index a6a1e4d2b..feedd0559 100644 --- a/tests/format/Comments/jsfmt.spec.js +++ b/tests/format/Comments/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse'], { compiler: '0.5.0' }); +run_spec(import.meta, ['slang'], { compiler: '0.5.0' }); diff --git a/tests/format/Conditional/__snapshots__/jsfmt.spec.js.snap b/tests/format/Conditional/__snapshots__/jsfmt.spec.js.snap index a978e8959..be88f9435 100644 --- a/tests/format/Conditional/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Conditional/__snapshots__/jsfmt.spec.js.snap @@ -81,7 +81,7 @@ contract Conditional { exports[`Conditional.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/Conditional/jsfmt.spec.js b/tests/format/Conditional/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/Conditional/jsfmt.spec.js +++ b/tests/format/Conditional/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/Constructors/__snapshots__/jsfmt.spec.js.snap b/tests/format/Constructors/__snapshots__/jsfmt.spec.js.snap index ee5e0571c..24d928a6b 100644 --- a/tests/format/Constructors/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Constructors/__snapshots__/jsfmt.spec.js.snap @@ -52,7 +52,7 @@ contract Constructors is Ownable, Changeable { exports[`Constructors.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/Constructors/jsfmt.spec.js b/tests/format/Constructors/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/Constructors/jsfmt.spec.js +++ b/tests/format/Constructors/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/ContractDefinitions/__snapshots__/jsfmt.spec.js.snap b/tests/format/ContractDefinitions/__snapshots__/jsfmt.spec.js.snap index 28542f7ea..d53ac9044 100644 --- a/tests/format/ContractDefinitions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/ContractDefinitions/__snapshots__/jsfmt.spec.js.snap @@ -23,7 +23,7 @@ contract ContractDefinition is exports[`ContractDefinitions.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/ContractDefinitions/jsfmt.spec.js b/tests/format/ContractDefinitions/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/ContractDefinitions/jsfmt.spec.js +++ b/tests/format/ContractDefinitions/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/CustomErrors/__snapshots__/jsfmt.spec.js.snap b/tests/format/CustomErrors/__snapshots__/jsfmt.spec.js.snap index 7b2b5ced6..b5eb560c4 100644 --- a/tests/format/CustomErrors/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/CustomErrors/__snapshots__/jsfmt.spec.js.snap @@ -51,7 +51,7 @@ contract CustomErrors { exports[`CustomErrors.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/CustomErrors/jsfmt.spec.js b/tests/format/CustomErrors/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/CustomErrors/jsfmt.spec.js +++ b/tests/format/CustomErrors/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/EnumDefinitions/__snapshots__/jsfmt.spec.js.snap b/tests/format/EnumDefinitions/__snapshots__/jsfmt.spec.js.snap index 1f9043ea3..7f7dbf256 100644 --- a/tests/format/EnumDefinitions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/EnumDefinitions/__snapshots__/jsfmt.spec.js.snap @@ -37,7 +37,7 @@ contract EnumDefinitions { exports[`EnumDefinitions.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/EnumDefinitions/jsfmt.spec.js b/tests/format/EnumDefinitions/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/EnumDefinitions/jsfmt.spec.js +++ b/tests/format/EnumDefinitions/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/Etc/__snapshots__/jsfmt.spec.js.snap b/tests/format/Etc/__snapshots__/jsfmt.spec.js.snap index d2da88d19..bbaeafde0 100644 --- a/tests/format/Etc/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Etc/__snapshots__/jsfmt.spec.js.snap @@ -135,7 +135,7 @@ contract Contract { exports[`Etc.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/Etc/jsfmt.spec.js b/tests/format/Etc/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/Etc/jsfmt.spec.js +++ b/tests/format/Etc/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/ExperimentalTernaries/__snapshots__/jsfmt.spec.js.snap b/tests/format/ExperimentalTernaries/__snapshots__/jsfmt.spec.js.snap index 7cf940966..b81ab698a 100644 --- a/tests/format/ExperimentalTernaries/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/ExperimentalTernaries/__snapshots__/jsfmt.spec.js.snap @@ -513,7 +513,7 @@ contract Conditional { exports[`ExperimentalTernaries.sol - {"experimentalTernaries":true,"tabWidth":1} format 2`] = ` ====================================options===================================== experimentalTernaries: true -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 tabWidth: 1 | printWidth @@ -1502,7 +1502,7 @@ contract Conditional { exports[`ExperimentalTernaries.sol - {"experimentalTernaries":true,"useTabs":true} format 2`] = ` ====================================options===================================== experimentalTernaries: true -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 useTabs: true | printWidth @@ -2494,7 +2494,7 @@ contract Conditional { exports[`ExperimentalTernaries.sol - {"experimentalTernaries":true} format 2`] = ` ====================================options===================================== experimentalTernaries: true -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -3496,7 +3496,7 @@ contract Conditional { exports[`ExperimentalTernaries.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/ExperimentalTernaries/jsfmt.spec.js b/tests/format/ExperimentalTernaries/jsfmt.spec.js index bd91f1554..0c5c92458 100644 --- a/tests/format/ExperimentalTernaries/jsfmt.spec.js +++ b/tests/format/ExperimentalTernaries/jsfmt.spec.js @@ -9,15 +9,15 @@ run_spec(import.meta, ['solidity-parse'], { useTabs: true }); -run_spec(import.meta, ['solidity-slang-parse']); -run_spec(import.meta, ['solidity-slang-parse'], { +run_spec(import.meta, ['slang']); +run_spec(import.meta, ['slang'], { experimentalTernaries: true }); -run_spec(import.meta, ['solidity-slang-parse'], { +run_spec(import.meta, ['slang'], { experimentalTernaries: true, tabWidth: 1 }); -run_spec(import.meta, ['solidity-slang-parse'], { +run_spec(import.meta, ['slang'], { experimentalTernaries: true, useTabs: true }); diff --git a/tests/format/ForStatements/__snapshots__/jsfmt.spec.js.snap b/tests/format/ForStatements/__snapshots__/jsfmt.spec.js.snap index 855f120e6..34159d1c4 100644 --- a/tests/format/ForStatements/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/ForStatements/__snapshots__/jsfmt.spec.js.snap @@ -109,7 +109,7 @@ contract ForStatements { exports[`ForStatements.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/ForStatements/jsfmt.spec.js b/tests/format/ForStatements/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/ForStatements/jsfmt.spec.js +++ b/tests/format/ForStatements/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/FunctionCalls/__snapshots__/jsfmt.spec.js.snap b/tests/format/FunctionCalls/__snapshots__/jsfmt.spec.js.snap index 7c9a727d9..94a47aa63 100644 --- a/tests/format/FunctionCalls/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/FunctionCalls/__snapshots__/jsfmt.spec.js.snap @@ -156,7 +156,7 @@ contract FunctionCalls { exports[`FunctionCalls.sol - {"bracketSpacing":true} format 2`] = ` ====================================options===================================== bracketSpacing: true -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -460,7 +460,7 @@ contract FunctionCalls { exports[`FunctionCalls.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/FunctionCalls/jsfmt.spec.js b/tests/format/FunctionCalls/jsfmt.spec.js index f9974c4c0..46fbb44d0 100644 --- a/tests/format/FunctionCalls/jsfmt.spec.js +++ b/tests/format/FunctionCalls/jsfmt.spec.js @@ -1,4 +1,4 @@ run_spec(import.meta, ['solidity-parse']); run_spec(import.meta, ['solidity-parse'], { bracketSpacing: true }); -run_spec(import.meta, ['solidity-slang-parse']); -run_spec(import.meta, ['solidity-slang-parse'], { bracketSpacing: true }); +run_spec(import.meta, ['slang']); +run_spec(import.meta, ['slang'], { bracketSpacing: true }); diff --git a/tests/format/FunctionDefinitions/__snapshots__/jsfmt.spec.js.snap b/tests/format/FunctionDefinitions/__snapshots__/jsfmt.spec.js.snap index 9be97d021..9d3da8719 100644 --- a/tests/format/FunctionDefinitions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/FunctionDefinitions/__snapshots__/jsfmt.spec.js.snap @@ -749,7 +749,7 @@ contract FunctionDefinitions { exports[`FunctionDefinitions.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/FunctionDefinitions/jsfmt.spec.js b/tests/format/FunctionDefinitions/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/FunctionDefinitions/jsfmt.spec.js +++ b/tests/format/FunctionDefinitions/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/FunctionDefinitionsv0.5.0/__snapshots__/jsfmt.spec.js.snap b/tests/format/FunctionDefinitionsv0.5.0/__snapshots__/jsfmt.spec.js.snap index 43dd005ee..71ccc4a35 100644 --- a/tests/format/FunctionDefinitionsv0.5.0/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/FunctionDefinitionsv0.5.0/__snapshots__/jsfmt.spec.js.snap @@ -3,7 +3,7 @@ exports[`FunctionDefinitions.sol - {"compiler":"0.5.0"} format 1`] = ` ====================================options===================================== compiler: "0.5.0" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/FunctionDefinitionsv0.5.0/jsfmt.spec.js b/tests/format/FunctionDefinitionsv0.5.0/jsfmt.spec.js index 4205ec3cb..feedd0559 100644 --- a/tests/format/FunctionDefinitionsv0.5.0/jsfmt.spec.js +++ b/tests/format/FunctionDefinitionsv0.5.0/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse'], {compiler: '0.5.0'}); +run_spec(import.meta, ['slang'], { compiler: '0.5.0' }); diff --git a/tests/format/HexLiteral/__snapshots__/jsfmt.spec.js.snap b/tests/format/HexLiteral/__snapshots__/jsfmt.spec.js.snap index c5f971459..fbfc77c3d 100644 --- a/tests/format/HexLiteral/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/HexLiteral/__snapshots__/jsfmt.spec.js.snap @@ -3,7 +3,7 @@ exports[`HexLiteral.sol - {"compiler":"0.8.25","singleQuote":false} format 1`] = ` ====================================options===================================== compiler: "0.8.25" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 singleQuote: false | printWidth @@ -30,7 +30,7 @@ contract HexLiteral { exports[`HexLiteral.sol - {"compiler":"0.8.25","singleQuote":true} format 1`] = ` ====================================options===================================== compiler: "0.8.25" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 singleQuote: true | printWidth diff --git a/tests/format/HexLiteral/jsfmt.spec.js b/tests/format/HexLiteral/jsfmt.spec.js index f2923e7bc..2bf288adf 100644 --- a/tests/format/HexLiteral/jsfmt.spec.js +++ b/tests/format/HexLiteral/jsfmt.spec.js @@ -1,10 +1,10 @@ run_spec(import.meta, ['solidity-parse'], { singleQuote: true }); run_spec(import.meta, ['solidity-parse'], { singleQuote: false }); -run_spec(import.meta, ['solidity-slang-parse'], { +run_spec(import.meta, ['slang'], { compiler: '0.8.25', singleQuote: true }); -run_spec(import.meta, ['solidity-slang-parse'], { +run_spec(import.meta, ['slang'], { compiler: '0.8.25', singleQuote: false }); diff --git a/tests/format/IfStatements/__snapshots__/jsfmt.spec.js.snap b/tests/format/IfStatements/__snapshots__/jsfmt.spec.js.snap index 331d12143..8aaba6eba 100644 --- a/tests/format/IfStatements/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/IfStatements/__snapshots__/jsfmt.spec.js.snap @@ -535,7 +535,7 @@ contract IfStatements { exports[`IfStatements.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/IfStatements/jsfmt.spec.js b/tests/format/IfStatements/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/IfStatements/jsfmt.spec.js +++ b/tests/format/IfStatements/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/Immutable/__snapshots__/jsfmt.spec.js.snap b/tests/format/Immutable/__snapshots__/jsfmt.spec.js.snap index de432a14b..aefc00cd3 100644 --- a/tests/format/Immutable/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Immutable/__snapshots__/jsfmt.spec.js.snap @@ -54,7 +54,7 @@ contract Immutable { exports[`Immutable.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/Immutable/jsfmt.spec.js b/tests/format/Immutable/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/Immutable/jsfmt.spec.js +++ b/tests/format/Immutable/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/ImportDirective/__snapshots__/jsfmt.spec.js.snap b/tests/format/ImportDirective/__snapshots__/jsfmt.spec.js.snap index 6a21a91dc..98264ab55 100644 --- a/tests/format/ImportDirective/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/ImportDirective/__snapshots__/jsfmt.spec.js.snap @@ -4,7 +4,7 @@ exports[`ImportDirectives.sol - {"bracketSpacing":true,"compiler":"0.4.26"} form ====================================options===================================== bracketSpacing: true compiler: "0.4.26" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -50,7 +50,7 @@ import { symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4 } from exports[`ImportDirectives.sol - {"compiler":"0.4.26"} format 1`] = ` ====================================options===================================== compiler: "0.4.26" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/ImportDirective/jsfmt.spec.js b/tests/format/ImportDirective/jsfmt.spec.js index 3db6b6040..9ace2a8b2 100644 --- a/tests/format/ImportDirective/jsfmt.spec.js +++ b/tests/format/ImportDirective/jsfmt.spec.js @@ -1,7 +1,7 @@ run_spec(import.meta, ['solidity-parse']); run_spec(import.meta, ['solidity-parse'], { bracketSpacing: true }); -run_spec(import.meta, ['solidity-slang-parse'], { compiler: '0.4.26' }); -run_spec(import.meta, ['solidity-slang-parse'], { +run_spec(import.meta, ['slang'], { compiler: '0.4.26' }); +run_spec(import.meta, ['slang'], { bracketSpacing: true, compiler: '0.4.26' }); diff --git a/tests/format/Inbox/__snapshots__/jsfmt.spec.js.snap b/tests/format/Inbox/__snapshots__/jsfmt.spec.js.snap index 376e25afa..41b47dd2a 100644 --- a/tests/format/Inbox/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Inbox/__snapshots__/jsfmt.spec.js.snap @@ -79,7 +79,7 @@ contract Inbox { exports[`Inbox.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/Inbox/jsfmt.spec.js b/tests/format/Inbox/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/Inbox/jsfmt.spec.js +++ b/tests/format/Inbox/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/IndexOf/__snapshots__/jsfmt.spec.js.snap b/tests/format/IndexOf/__snapshots__/jsfmt.spec.js.snap index 9f0f1d4da..de13806ae 100644 --- a/tests/format/IndexOf/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/IndexOf/__snapshots__/jsfmt.spec.js.snap @@ -148,7 +148,7 @@ contract IndexOf { exports[`IndexOf.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/IndexOf/jsfmt.spec.js b/tests/format/IndexOf/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/IndexOf/jsfmt.spec.js +++ b/tests/format/IndexOf/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/IndexRangeAccess/__snapshots__/jsfmt.spec.js.snap b/tests/format/IndexRangeAccess/__snapshots__/jsfmt.spec.js.snap index e339ed528..8dc01fd73 100644 --- a/tests/format/IndexRangeAccess/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/IndexRangeAccess/__snapshots__/jsfmt.spec.js.snap @@ -32,7 +32,7 @@ contract Demo { exports[`IndexRangeAccess.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/IndexRangeAccess/jsfmt.spec.js b/tests/format/IndexRangeAccess/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/IndexRangeAccess/jsfmt.spec.js +++ b/tests/format/IndexRangeAccess/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/InheritanceSpecifier/__snapshots__/jsfmt.spec.js.snap b/tests/format/InheritanceSpecifier/__snapshots__/jsfmt.spec.js.snap index 20c4a5086..f7f1986d6 100644 --- a/tests/format/InheritanceSpecifier/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/InheritanceSpecifier/__snapshots__/jsfmt.spec.js.snap @@ -24,7 +24,7 @@ contract LongInheritanceSpecifier is exports[`InheritanceSpecifier.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/InheritanceSpecifier/jsfmt.spec.js b/tests/format/InheritanceSpecifier/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/InheritanceSpecifier/jsfmt.spec.js +++ b/tests/format/InheritanceSpecifier/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/Issues/__snapshots__/jsfmt.spec.js.snap b/tests/format/Issues/__snapshots__/jsfmt.spec.js.snap index bec273b20..fd3ce3cec 100644 --- a/tests/format/Issues/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Issues/__snapshots__/jsfmt.spec.js.snap @@ -40,7 +40,7 @@ contract Example { exports[`Issue205.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -103,7 +103,7 @@ contract Issue289 { exports[`Issue289.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -164,7 +164,7 @@ contract Bug { exports[`Issue355.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -235,7 +235,7 @@ contract Issue385 { exports[`Issue385.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -308,7 +308,7 @@ contract Issue564 { exports[`Issue564.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -354,7 +354,7 @@ struct EmptyStruct {} exports[`Issue799.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -396,7 +396,7 @@ contract ContractWithoutComments {} exports[`Issue843.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/Issues/jsfmt.spec.js b/tests/format/Issues/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/Issues/jsfmt.spec.js +++ b/tests/format/Issues/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/Libraries/__snapshots__/jsfmt.spec.js.snap b/tests/format/Libraries/__snapshots__/jsfmt.spec.js.snap index 03420de41..0c79ba81e 100644 --- a/tests/format/Libraries/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Libraries/__snapshots__/jsfmt.spec.js.snap @@ -56,7 +56,7 @@ using { exports[`Libraries.sol - {"bracketSpacing":true} format 2`] = ` ====================================options===================================== bracketSpacing: true -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -149,7 +149,7 @@ using { exports[`Libraries.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/Libraries/jsfmt.spec.js b/tests/format/Libraries/jsfmt.spec.js index f9974c4c0..46fbb44d0 100644 --- a/tests/format/Libraries/jsfmt.spec.js +++ b/tests/format/Libraries/jsfmt.spec.js @@ -1,4 +1,4 @@ run_spec(import.meta, ['solidity-parse']); run_spec(import.meta, ['solidity-parse'], { bracketSpacing: true }); -run_spec(import.meta, ['solidity-slang-parse']); -run_spec(import.meta, ['solidity-slang-parse'], { bracketSpacing: true }); +run_spec(import.meta, ['slang']); +run_spec(import.meta, ['slang'], { bracketSpacing: true }); diff --git a/tests/format/MemberAccess/__snapshots__/jsfmt.spec.js.snap b/tests/format/MemberAccess/__snapshots__/jsfmt.spec.js.snap index a6a373cb1..a41dcfb96 100644 --- a/tests/format/MemberAccess/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/MemberAccess/__snapshots__/jsfmt.spec.js.snap @@ -3,7 +3,7 @@ exports[`MemberAccess.sol - {"compiler":"0.5.0"} format 1`] = ` ====================================options===================================== compiler: "0.5.0" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/MemberAccess/jsfmt.spec.js b/tests/format/MemberAccess/jsfmt.spec.js index a6a1e4d2b..feedd0559 100644 --- a/tests/format/MemberAccess/jsfmt.spec.js +++ b/tests/format/MemberAccess/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse'], { compiler: '0.5.0' }); +run_spec(import.meta, ['slang'], { compiler: '0.5.0' }); diff --git a/tests/format/ModifierDefinitions/__snapshots__/jsfmt.spec.js.snap b/tests/format/ModifierDefinitions/__snapshots__/jsfmt.spec.js.snap index 6878d668f..750d4d0a2 100644 --- a/tests/format/ModifierDefinitions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/ModifierDefinitions/__snapshots__/jsfmt.spec.js.snap @@ -34,7 +34,7 @@ contract ModifierDefinitions { exports[`ModifierDefinitions.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/ModifierDefinitions/jsfmt.spec.js b/tests/format/ModifierDefinitions/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/ModifierDefinitions/jsfmt.spec.js +++ b/tests/format/ModifierDefinitions/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/ModifierInvocations/__snapshots__/jsfmt.spec.js.snap b/tests/format/ModifierInvocations/__snapshots__/jsfmt.spec.js.snap index 8636ff191..b256f32a3 100644 --- a/tests/format/ModifierInvocations/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/ModifierInvocations/__snapshots__/jsfmt.spec.js.snap @@ -52,7 +52,7 @@ contract ModifierInvocations is ModifierDefinitions { exports[`ModifierInvocations.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/ModifierInvocations/jsfmt.spec.js b/tests/format/ModifierInvocations/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/ModifierInvocations/jsfmt.spec.js +++ b/tests/format/ModifierInvocations/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/MultipartStrings/__snapshots__/jsfmt.spec.js.snap b/tests/format/MultipartStrings/__snapshots__/jsfmt.spec.js.snap index a2940e65f..6f9ab7c57 100644 --- a/tests/format/MultipartStrings/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/MultipartStrings/__snapshots__/jsfmt.spec.js.snap @@ -40,7 +40,7 @@ contract MultipartStrings { exports[`MultipartStrings.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/MultipartStrings/jsfmt.spec.js b/tests/format/MultipartStrings/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/MultipartStrings/jsfmt.spec.js +++ b/tests/format/MultipartStrings/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/NameValueExpression/__snapshots__/jsfmt.spec.js.snap b/tests/format/NameValueExpression/__snapshots__/jsfmt.spec.js.snap index 0df1fbfdb..32ff0937b 100644 --- a/tests/format/NameValueExpression/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/NameValueExpression/__snapshots__/jsfmt.spec.js.snap @@ -36,7 +36,7 @@ contract NameValueExpression { exports[`NameValueExpression.sol - {"bracketSpacing":true} format 2`] = ` ====================================options===================================== bracketSpacing: true -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -100,7 +100,7 @@ contract NameValueExpression { exports[`NameValueExpression.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/NameValueExpression/jsfmt.spec.js b/tests/format/NameValueExpression/jsfmt.spec.js index f9974c4c0..46fbb44d0 100644 --- a/tests/format/NameValueExpression/jsfmt.spec.js +++ b/tests/format/NameValueExpression/jsfmt.spec.js @@ -1,4 +1,4 @@ run_spec(import.meta, ['solidity-parse']); run_spec(import.meta, ['solidity-parse'], { bracketSpacing: true }); -run_spec(import.meta, ['solidity-slang-parse']); -run_spec(import.meta, ['solidity-slang-parse'], { bracketSpacing: true }); +run_spec(import.meta, ['slang']); +run_spec(import.meta, ['slang'], { bracketSpacing: true }); diff --git a/tests/format/NumberLiteral/__snapshots__/jsfmt.spec.js.snap b/tests/format/NumberLiteral/__snapshots__/jsfmt.spec.js.snap index cbbe8f055..fea20c5dd 100644 --- a/tests/format/NumberLiteral/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/NumberLiteral/__snapshots__/jsfmt.spec.js.snap @@ -40,7 +40,7 @@ contract NumberLiteral { exports[`NumberLiteral.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/NumberLiteral/jsfmt.spec.js b/tests/format/NumberLiteral/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/NumberLiteral/jsfmt.spec.js +++ b/tests/format/NumberLiteral/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/Ownable/__snapshots__/jsfmt.spec.js.snap b/tests/format/Ownable/__snapshots__/jsfmt.spec.js.snap index dcc47868e..a36dc587a 100644 --- a/tests/format/Ownable/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Ownable/__snapshots__/jsfmt.spec.js.snap @@ -164,7 +164,7 @@ contract Ownable { exports[`Ownable.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/Ownable/jsfmt.spec.js b/tests/format/Ownable/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/Ownable/jsfmt.spec.js +++ b/tests/format/Ownable/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/Parentheses/__snapshots__/jsfmt.spec.js.snap b/tests/format/Parentheses/__snapshots__/jsfmt.spec.js.snap index 7cc01d9a6..82daedda0 100644 --- a/tests/format/Parentheses/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Parentheses/__snapshots__/jsfmt.spec.js.snap @@ -200,7 +200,7 @@ contract AddNoParentheses { exports[`AddNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -593,7 +593,7 @@ contract BitAndNoParentheses { exports[`BitAndNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -986,7 +986,7 @@ contract BitOrNoParentheses { exports[`BitOrNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -1379,7 +1379,7 @@ contract BitXorNoParentheses { exports[`BitXorNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -1772,7 +1772,7 @@ contract DivNoParentheses { exports[`DivNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -2165,7 +2165,7 @@ contract ExpNoParentheses { exports[`ExpNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -2414,7 +2414,7 @@ contract LogicNoParentheses { exports[`LogicNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -2663,7 +2663,7 @@ contract ModNoParentheses { exports[`ModNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -3056,7 +3056,7 @@ contract MulNoParentheses { exports[`MulNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -3449,7 +3449,7 @@ contract ShiftLNoParentheses { exports[`ShiftLNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -3842,7 +3842,7 @@ contract ShiftRNoParentheses { exports[`ShiftRNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -4235,7 +4235,7 @@ contract SubNoParentheses { exports[`SubNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/Parentheses/jsfmt.spec.js b/tests/format/Parentheses/jsfmt.spec.js index 8012ac6cd..15c5d58fc 100644 --- a/tests/format/Parentheses/jsfmt.spec.js +++ b/tests/format/Parentheses/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse'], { compiler: '0.8.6' }); -run_spec(import.meta, ['solidity-slang-parse'], { compiler: '0.8.6' }); +run_spec(import.meta, ['slang'], { compiler: '0.8.6' }); diff --git a/tests/format/Pragma/__snapshots__/jsfmt.spec.js.snap b/tests/format/Pragma/__snapshots__/jsfmt.spec.js.snap index 08d535336..b3d7e1edc 100644 --- a/tests/format/Pragma/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Pragma/__snapshots__/jsfmt.spec.js.snap @@ -34,7 +34,7 @@ pragma abicoder v2; exports[`Pragma.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/Pragma/jsfmt.spec.js b/tests/format/Pragma/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/Pragma/jsfmt.spec.js +++ b/tests/format/Pragma/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/PrettierIgnore/__snapshots__/jsfmt.spec.js.snap b/tests/format/PrettierIgnore/__snapshots__/jsfmt.spec.js.snap index 1e7373011..0cd0ee1ee 100644 --- a/tests/format/PrettierIgnore/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/PrettierIgnore/__snapshots__/jsfmt.spec.js.snap @@ -88,7 +88,7 @@ contract Example { exports[`PrettierIgnore.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/PrettierIgnore/jsfmt.spec.js b/tests/format/PrettierIgnore/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/PrettierIgnore/jsfmt.spec.js +++ b/tests/format/PrettierIgnore/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/Proxy/__snapshots__/jsfmt.spec.js.snap b/tests/format/Proxy/__snapshots__/jsfmt.spec.js.snap index 405a88bac..bcee98b4a 100644 --- a/tests/format/Proxy/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Proxy/__snapshots__/jsfmt.spec.js.snap @@ -3,7 +3,7 @@ exports[`Proxy.sol - {"compiler":"0.4.26"} format 1`] = ` ====================================options===================================== compiler: "0.4.26" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/Proxy/jsfmt.spec.js b/tests/format/Proxy/jsfmt.spec.js index 18602c4e5..c8fb0ebbc 100644 --- a/tests/format/Proxy/jsfmt.spec.js +++ b/tests/format/Proxy/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse'], { compiler: '0.4.26' }); +run_spec(import.meta, ['slang'], { compiler: '0.4.26' }); diff --git a/tests/format/SampleCrowdsale/__snapshots__/jsfmt.spec.js.snap b/tests/format/SampleCrowdsale/__snapshots__/jsfmt.spec.js.snap index 6d02d7cf3..fda521b17 100644 --- a/tests/format/SampleCrowdsale/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/SampleCrowdsale/__snapshots__/jsfmt.spec.js.snap @@ -114,7 +114,7 @@ contract SampleCrowdsale is CappedCrowdsale, RefundableCrowdsale { exports[`SampleCrowdsale.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/SampleCrowdsale/jsfmt.spec.js b/tests/format/SampleCrowdsale/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/SampleCrowdsale/jsfmt.spec.js +++ b/tests/format/SampleCrowdsale/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/SimpleAuction/__snapshots__/jsfmt.spec.js.snap b/tests/format/SimpleAuction/__snapshots__/jsfmt.spec.js.snap index ca88e0ade..7a149c1cb 100644 --- a/tests/format/SimpleAuction/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/SimpleAuction/__snapshots__/jsfmt.spec.js.snap @@ -251,7 +251,7 @@ contract SimpleAuction { exports[`SimpleAuction.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/SimpleAuction/jsfmt.spec.js b/tests/format/SimpleAuction/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/SimpleAuction/jsfmt.spec.js +++ b/tests/format/SimpleAuction/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/SimpleStorage/__snapshots__/jsfmt.spec.js.snap b/tests/format/SimpleStorage/__snapshots__/jsfmt.spec.js.snap index 5c33bbeb5..b87023117 100644 --- a/tests/format/SimpleStorage/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/SimpleStorage/__snapshots__/jsfmt.spec.js.snap @@ -42,7 +42,7 @@ contract SimpleStorage { exports[`SimpleStorage.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/SimpleStorage/jsfmt.spec.js b/tests/format/SimpleStorage/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/SimpleStorage/jsfmt.spec.js +++ b/tests/format/SimpleStorage/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/SplittableCommodity/__snapshots__/jsfmt.spec.js.snap b/tests/format/SplittableCommodity/__snapshots__/jsfmt.spec.js.snap index 154e214ff..58ddaa12a 100644 --- a/tests/format/SplittableCommodity/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/SplittableCommodity/__snapshots__/jsfmt.spec.js.snap @@ -136,7 +136,7 @@ contract SplittableCommodity is MintableCommodity { exports[`SplittableCommodity.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/SplittableCommodity/jsfmt.spec.js b/tests/format/SplittableCommodity/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/SplittableCommodity/jsfmt.spec.js +++ b/tests/format/SplittableCommodity/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/StateVariableDeclarations/__snapshots__/jsfmt.spec.js.snap b/tests/format/StateVariableDeclarations/__snapshots__/jsfmt.spec.js.snap index 77c68c298..9f4c08040 100644 --- a/tests/format/StateVariableDeclarations/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/StateVariableDeclarations/__snapshots__/jsfmt.spec.js.snap @@ -21,7 +21,7 @@ contract Contract { exports[`StateVariableDeclarations.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/StateVariableDeclarations/jsfmt.spec.js b/tests/format/StateVariableDeclarations/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/StateVariableDeclarations/jsfmt.spec.js +++ b/tests/format/StateVariableDeclarations/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/StringLiteral/__snapshots__/jsfmt.spec.js.snap b/tests/format/StringLiteral/__snapshots__/jsfmt.spec.js.snap index 7d83cc3e9..e813af4a3 100644 --- a/tests/format/StringLiteral/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/StringLiteral/__snapshots__/jsfmt.spec.js.snap @@ -37,7 +37,7 @@ contract StringLiteral { exports[`StringLiteral.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/StringLiteral/jsfmt.spec.js b/tests/format/StringLiteral/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/StringLiteral/jsfmt.spec.js +++ b/tests/format/StringLiteral/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/StyleGuide/__snapshots__/jsfmt.spec.js.snap b/tests/format/StyleGuide/__snapshots__/jsfmt.spec.js.snap index 5ec08179b..c3c94d073 100644 --- a/tests/format/StyleGuide/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/StyleGuide/__snapshots__/jsfmt.spec.js.snap @@ -3,7 +3,7 @@ exports[`BlankLines.sol - {"compiler":"0.5.0"} format 1`] = ` ====================================options===================================== compiler: "0.5.0" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -92,7 +92,7 @@ contract A { exports[`ControlStructures.sol - {"compiler":"0.5.0"} format 1`] = ` ====================================options===================================== compiler: "0.5.0" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -313,7 +313,7 @@ contract ControlStructures { exports[`FunctionDeclaration.sol - {"compiler":"0.5.0"} format 1`] = ` ====================================options===================================== compiler: "0.5.0" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -893,7 +893,7 @@ contract X is B, C, D { exports[`Mappings.sol - {"compiler":"0.5.0"} format 1`] = ` ====================================options===================================== compiler: "0.5.0" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -952,7 +952,7 @@ contract Mappings { exports[`MaximumLineLength.sol - {"compiler":"0.5.0"} format 1`] = ` ====================================options===================================== compiler: "0.5.0" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -1263,7 +1263,7 @@ contract EventDefinitionsAndEventEmitters { exports[`OtherRecommendations.sol - {"compiler":"0.5.0"} format 1`] = ` ====================================options===================================== compiler: "0.5.0" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -1387,7 +1387,7 @@ contract OtherRecommendations { exports[`VariableDeclarations.sol - {"compiler":"0.5.0"} format 1`] = ` ====================================options===================================== compiler: "0.5.0" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -1434,7 +1434,7 @@ contract VariableDeclarations { exports[`WhitespaceInExpressions.sol - {"compiler":"0.5.0"} format 1`] = ` ====================================options===================================== compiler: "0.5.0" -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/StyleGuide/jsfmt.spec.js b/tests/format/StyleGuide/jsfmt.spec.js index a6a1e4d2b..feedd0559 100644 --- a/tests/format/StyleGuide/jsfmt.spec.js +++ b/tests/format/StyleGuide/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse'], { compiler: '0.5.0' }); +run_spec(import.meta, ['slang'], { compiler: '0.5.0' }); diff --git a/tests/format/TryCatch/__snapshots__/jsfmt.spec.js.snap b/tests/format/TryCatch/__snapshots__/jsfmt.spec.js.snap index 421a6de1f..58efea045 100644 --- a/tests/format/TryCatch/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/TryCatch/__snapshots__/jsfmt.spec.js.snap @@ -225,7 +225,7 @@ contract FeedConsumer { exports[`TryCatch.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/TryCatch/jsfmt.spec.js b/tests/format/TryCatch/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/TryCatch/jsfmt.spec.js +++ b/tests/format/TryCatch/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/Tupples/__snapshots__/jsfmt.spec.js.snap b/tests/format/Tupples/__snapshots__/jsfmt.spec.js.snap index b6e732ec7..fc1451502 100644 --- a/tests/format/Tupples/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Tupples/__snapshots__/jsfmt.spec.js.snap @@ -65,7 +65,7 @@ contract Tupples { exports[`Tupples.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/Tupples/jsfmt.spec.js b/tests/format/Tupples/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/Tupples/jsfmt.spec.js +++ b/tests/format/Tupples/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/TypeDefinition/__snapshots__/jsfmt.spec.js.snap b/tests/format/TypeDefinition/__snapshots__/jsfmt.spec.js.snap index c89783b6c..46c6fd3eb 100644 --- a/tests/format/TypeDefinition/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/TypeDefinition/__snapshots__/jsfmt.spec.js.snap @@ -38,7 +38,7 @@ contract TypeDefinition { exports[`TypeDefinition.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/TypeDefinition/jsfmt.spec.js b/tests/format/TypeDefinition/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/TypeDefinition/jsfmt.spec.js +++ b/tests/format/TypeDefinition/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/WhileStatements/__snapshots__/jsfmt.spec.js.snap b/tests/format/WhileStatements/__snapshots__/jsfmt.spec.js.snap index 1df776419..160e74f6e 100644 --- a/tests/format/WhileStatements/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/WhileStatements/__snapshots__/jsfmt.spec.js.snap @@ -111,7 +111,7 @@ contract WhileStatements { exports[`WhileStatements.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/WhileStatements/jsfmt.spec.js b/tests/format/WhileStatements/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/WhileStatements/jsfmt.spec.js +++ b/tests/format/WhileStatements/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/quotes/__snapshots__/jsfmt.spec.js.snap b/tests/format/quotes/__snapshots__/jsfmt.spec.js.snap index f460fb99c..97b7c17b8 100644 --- a/tests/format/quotes/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/quotes/__snapshots__/jsfmt.spec.js.snap @@ -61,7 +61,7 @@ contract Foo { exports[`Quotes.sol - {"singleQuote":false} format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 singleQuote: false | printWidth @@ -179,7 +179,7 @@ contract Foo { exports[`Quotes.sol - {"singleQuote":true} format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 singleQuote: true | printWidth diff --git a/tests/format/quotes/jsfmt.spec.js b/tests/format/quotes/jsfmt.spec.js index a56d23665..6532de66b 100644 --- a/tests/format/quotes/jsfmt.spec.js +++ b/tests/format/quotes/jsfmt.spec.js @@ -1,4 +1,4 @@ run_spec(import.meta, ['solidity-parse'], { singleQuote: true }); run_spec(import.meta, ['solidity-parse'], { singleQuote: false }); -run_spec(import.meta, ['solidity-slang-parse'], { singleQuote: true }); -run_spec(import.meta, ['solidity-slang-parse'], { singleQuote: false }); +run_spec(import.meta, ['slang'], { singleQuote: true }); +run_spec(import.meta, ['slang'], { singleQuote: false }); diff --git a/tests/format/strings/__snapshots__/jsfmt.spec.js.snap b/tests/format/strings/__snapshots__/jsfmt.spec.js.snap index 4b49903ec..9b3efc0b5 100644 --- a/tests/format/strings/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/strings/__snapshots__/jsfmt.spec.js.snap @@ -1559,7 +1559,7 @@ library strings { exports[`strings.sol format 2`] = ` ====================================options===================================== -parsers: ["solidity-slang-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/strings/jsfmt.spec.js b/tests/format/strings/jsfmt.spec.js index fd56c17bc..2bfbc1a00 100644 --- a/tests/format/strings/jsfmt.spec.js +++ b/tests/format/strings/jsfmt.spec.js @@ -1,2 +1,2 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-slang-parse']); +run_spec(import.meta, ['slang']); From 662589b80545468381e651828697ee49c5eb2aa2 Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 26 Jun 2024 21:16:24 +1200 Subject: [PATCH 036/160] gathering comments --- src/common/slang-helpers.js | 52 +++++++------- src/slang-nodes/ABICoderPragma.js | 3 +- src/slang-nodes/AdditiveExpression.js | 20 +++--- src/slang-nodes/AddressType.js | 3 +- src/slang-nodes/AndExpression.js | 3 +- src/slang-nodes/ArgumentsDeclaration.js | 3 +- src/slang-nodes/ArrayExpression.js | 3 +- src/slang-nodes/ArrayTypeName.js | 3 +- src/slang-nodes/ArrayValues.js | 3 +- src/slang-nodes/AssemblyFlags.js | 3 +- src/slang-nodes/AssemblyFlagsDeclaration.js | 3 +- src/slang-nodes/AssemblyStatement.js | 3 +- src/slang-nodes/AssignmentExpression.js | 3 +- src/slang-nodes/BitwiseAndExpression.js | 20 +++--- src/slang-nodes/BitwiseOrExpression.js | 20 +++--- src/slang-nodes/BitwiseXorExpression.js | 20 +++--- src/slang-nodes/Block.js | 3 +- src/slang-nodes/BreakStatement.js | 3 +- src/slang-nodes/CallOptions.js | 3 +- src/slang-nodes/CallOptionsExpression.js | 3 +- src/slang-nodes/CatchClause.js | 3 +- src/slang-nodes/CatchClauseError.js | 3 +- src/slang-nodes/CatchClauses.js | 3 +- src/slang-nodes/ComparisonExpression.js | 3 +- src/slang-nodes/ConditionalExpression.js | 3 +- src/slang-nodes/ConstantDefinition.js | 3 +- src/slang-nodes/ConstructorAttribute.js | 3 +- src/slang-nodes/ConstructorAttributes.js | 3 +- src/slang-nodes/ConstructorDefinition.js | 3 +- src/slang-nodes/ContinueStatement.js | 3 +- src/slang-nodes/ContractDefinition.js | 3 +- src/slang-nodes/ContractMember.js | 3 +- src/slang-nodes/ContractMembers.js | 3 +- src/slang-nodes/DecimalNumberExpression.js | 3 +- src/slang-nodes/DoWhileStatement.js | 3 +- src/slang-nodes/ElementaryType.js | 3 +- src/slang-nodes/ElseBranch.js | 3 +- src/slang-nodes/EmitStatement.js | 3 +- src/slang-nodes/EnumDefinition.js | 3 +- src/slang-nodes/EnumMembers.js | 3 +- src/slang-nodes/EqualityExpression.js | 3 +- src/slang-nodes/ErrorDefinition.js | 3 +- src/slang-nodes/ErrorParameter.js | 3 +- src/slang-nodes/ErrorParameters.js | 3 +- src/slang-nodes/ErrorParametersDeclaration.js | 3 +- src/slang-nodes/EventDefinition.js | 3 +- src/slang-nodes/EventParameter.js | 3 +- src/slang-nodes/EventParameters.js | 3 +- src/slang-nodes/EventParametersDeclaration.js | 3 +- src/slang-nodes/ExperimentalFeature.js | 3 +- src/slang-nodes/ExperimentalPragma.js | 3 +- src/slang-nodes/ExponentiationExpression.js | 24 +++---- src/slang-nodes/Expression.js | 3 +- src/slang-nodes/ExpressionStatement.js | 3 +- src/slang-nodes/FallbackFunctionAttribute.js | 3 +- src/slang-nodes/FallbackFunctionAttributes.js | 3 +- src/slang-nodes/FallbackFunctionDefinition.js | 3 +- src/slang-nodes/ForStatement.js | 3 +- src/slang-nodes/ForStatementCondition.js | 3 +- src/slang-nodes/ForStatementInitialization.js | 3 +- src/slang-nodes/FunctionAttribute.js | 3 +- src/slang-nodes/FunctionAttributes.js | 3 +- src/slang-nodes/FunctionBody.js | 3 +- src/slang-nodes/FunctionCallExpression.js | 3 +- src/slang-nodes/FunctionDefinition.js | 3 +- src/slang-nodes/FunctionName.js | 3 +- src/slang-nodes/FunctionType.js | 3 +- src/slang-nodes/FunctionTypeAttribute.js | 3 +- src/slang-nodes/FunctionTypeAttributes.js | 3 +- src/slang-nodes/HexNumberExpression.js | 3 +- src/slang-nodes/HexStringLiteral.js | 3 +- src/slang-nodes/HexStringLiterals.js | 3 +- src/slang-nodes/IdentifierPath.js | 3 +- src/slang-nodes/IfStatement.js | 3 +- src/slang-nodes/ImportAlias.js | 3 +- src/slang-nodes/ImportClause.js | 3 +- src/slang-nodes/ImportDeconstruction.js | 3 +- src/slang-nodes/ImportDeconstructionSymbol.js | 3 +- .../ImportDeconstructionSymbols.js | 3 +- src/slang-nodes/ImportDirective.js | 3 +- src/slang-nodes/IndexAccessEnd.js | 3 +- src/slang-nodes/IndexAccessExpression.js | 3 +- src/slang-nodes/InheritanceSpecifier.js | 3 +- src/slang-nodes/InheritanceType.js | 3 +- src/slang-nodes/InheritanceTypes.js | 3 +- src/slang-nodes/InterfaceDefinition.js | 3 +- src/slang-nodes/InterfaceMembers.js | 3 +- src/slang-nodes/LibraryDefinition.js | 3 +- src/slang-nodes/LibraryMembers.js | 3 +- src/slang-nodes/MappingKey.js | 3 +- src/slang-nodes/MappingKeyType.js | 3 +- src/slang-nodes/MappingType.js | 3 +- src/slang-nodes/MappingValue.js | 3 +- src/slang-nodes/MemberAccess.js | 3 +- src/slang-nodes/MemberAccessExpression.js | 3 +- src/slang-nodes/ModifierAttribute.js | 3 +- src/slang-nodes/ModifierAttributes.js | 3 +- src/slang-nodes/ModifierDefinition.js | 3 +- src/slang-nodes/ModifierInvocation.js | 3 +- src/slang-nodes/MultiplicativeExpression.js | 20 +++--- src/slang-nodes/NamedArgument.js | 3 +- src/slang-nodes/NamedArgumentGroup.js | 3 +- src/slang-nodes/NamedArguments.js | 3 +- src/slang-nodes/NamedArgumentsDeclaration.js | 3 +- src/slang-nodes/NamedImport.js | 3 +- src/slang-nodes/NewExpression.js | 3 +- src/slang-nodes/NumberUnit.js | 3 +- src/slang-nodes/OrExpression.js | 20 +++--- src/slang-nodes/OverridePaths.js | 3 +- src/slang-nodes/OverridePathsDeclaration.js | 3 +- src/slang-nodes/OverrideSpecifier.js | 3 +- src/slang-nodes/Parameter.js | 3 +- src/slang-nodes/Parameters.js | 3 +- src/slang-nodes/ParametersDeclaration.js | 3 +- src/slang-nodes/PathImport.js | 3 +- src/slang-nodes/PositionalArguments.js | 3 +- .../PositionalArgumentsDeclaration.js | 3 +- src/slang-nodes/PostfixExpression.js | 3 +- src/slang-nodes/Pragma.js | 3 +- src/slang-nodes/PragmaDirective.js | 3 +- src/slang-nodes/PrefixExpression.js | 3 +- src/slang-nodes/ReceiveFunctionAttribute.js | 3 +- src/slang-nodes/ReceiveFunctionAttributes.js | 3 +- src/slang-nodes/ReceiveFunctionDefinition.js | 3 +- src/slang-nodes/ReturnStatement.js | 3 +- src/slang-nodes/ReturnsDeclaration.js | 3 +- src/slang-nodes/RevertStatement.js | 3 +- src/slang-nodes/ShiftExpression.js | 22 +++--- src/slang-nodes/SourceUnit.js | 3 +- src/slang-nodes/SourceUnitMember.js | 3 +- src/slang-nodes/SourceUnitMembers.js | 3 +- src/slang-nodes/StateVariableAttribute.js | 3 +- src/slang-nodes/StateVariableAttributes.js | 3 +- src/slang-nodes/StateVariableDefinition.js | 3 +- .../StateVariableDefinitionValue.js | 3 +- src/slang-nodes/Statement.js | 3 +- src/slang-nodes/Statements.js | 3 +- src/slang-nodes/StorageLocation.js | 3 +- src/slang-nodes/StringExpression.js | 3 +- src/slang-nodes/StringLiteral.js | 3 +- src/slang-nodes/StringLiterals.js | 3 +- src/slang-nodes/StructDefinition.js | 3 +- src/slang-nodes/StructMember.js | 3 +- src/slang-nodes/StructMembers.js | 3 +- src/slang-nodes/ThrowStatement.js | 3 +- src/slang-nodes/TryStatement.js | 3 +- src/slang-nodes/TupleDeconstructionElement.js | 3 +- .../TupleDeconstructionElements.js | 3 +- .../TupleDeconstructionStatement.js | 3 +- src/slang-nodes/TupleExpression.js | 3 +- src/slang-nodes/TupleMember.js | 3 +- src/slang-nodes/TupleValue.js | 3 +- src/slang-nodes/TupleValues.js | 3 +- src/slang-nodes/TypeExpression.js | 3 +- src/slang-nodes/TypeName.js | 3 +- src/slang-nodes/TypedTupleMember.js | 3 +- src/slang-nodes/UncheckedBlock.js | 3 +- src/slang-nodes/UnicodeStringLiteral.js | 3 +- src/slang-nodes/UnicodeStringLiterals.js | 3 +- src/slang-nodes/UnnamedFunctionAttribute.js | 3 +- src/slang-nodes/UnnamedFunctionAttributes.js | 3 +- src/slang-nodes/UnnamedFunctionDefinition.js | 3 +- src/slang-nodes/UntypedTupleMember.js | 3 +- .../UserDefinedValueTypeDefinition.js | 3 +- src/slang-nodes/UsingAlias.js | 3 +- src/slang-nodes/UsingClause.js | 3 +- src/slang-nodes/UsingDeconstruction.js | 3 +- src/slang-nodes/UsingDeconstructionSymbol.js | 3 +- src/slang-nodes/UsingDeconstructionSymbols.js | 3 +- src/slang-nodes/UsingDirective.js | 3 +- src/slang-nodes/UsingOperator.js | 3 +- src/slang-nodes/UsingTarget.js | 3 +- .../VariableDeclarationStatement.js | 3 +- src/slang-nodes/VariableDeclarationType.js | 3 +- src/slang-nodes/VariableDeclarationValue.js | 3 +- src/slang-nodes/VersionComparator.js | 3 +- src/slang-nodes/VersionExpression.js | 3 +- src/slang-nodes/VersionExpressionSet.js | 3 +- src/slang-nodes/VersionExpressionSets.js | 3 +- src/slang-nodes/VersionPragma.js | 3 +- src/slang-nodes/VersionRange.js | 3 +- src/slang-nodes/VersionSpecifiers.js | 3 +- src/slang-nodes/WhileStatement.js | 3 +- src/slang-nodes/YulArguments.js | 3 +- src/slang-nodes/YulAssignmentOperator.js | 3 +- src/slang-nodes/YulAssignmentStatement.js | 3 +- src/slang-nodes/YulBlock.js | 3 +- src/slang-nodes/YulBreakStatement.js | 3 +- src/slang-nodes/YulBuiltInFunction.js | 3 +- src/slang-nodes/YulColonAndEqual.js | 3 +- src/slang-nodes/YulContinueStatement.js | 3 +- src/slang-nodes/YulDefaultCase.js | 3 +- src/slang-nodes/YulExpression.js | 3 +- src/slang-nodes/YulForStatement.js | 3 +- src/slang-nodes/YulFunctionCallExpression.js | 3 +- src/slang-nodes/YulFunctionDefinition.js | 3 +- src/slang-nodes/YulIfStatement.js | 3 +- src/slang-nodes/YulLabel.js | 3 +- src/slang-nodes/YulLeaveStatement.js | 3 +- src/slang-nodes/YulLiteral.js | 3 +- src/slang-nodes/YulParameters.js | 3 +- src/slang-nodes/YulParametersDeclaration.js | 3 +- src/slang-nodes/YulPath.js | 3 +- src/slang-nodes/YulPathComponent.js | 3 +- src/slang-nodes/YulPaths.js | 3 +- src/slang-nodes/YulReturnVariables.js | 3 +- src/slang-nodes/YulReturnsDeclaration.js | 3 +- src/slang-nodes/YulStatement.js | 3 +- src/slang-nodes/YulStatements.js | 3 +- src/slang-nodes/YulSwitchCase.js | 3 +- src/slang-nodes/YulSwitchCases.js | 3 +- src/slang-nodes/YulSwitchStatement.js | 3 +- src/slang-nodes/YulValueCase.js | 3 +- .../YulVariableAssignmentStatement.js | 3 +- .../YulVariableDeclarationStatement.js | 3 +- .../YulVariableDeclarationValue.js | 3 +- src/slangCommentPrinter.js | 57 +++++++++++++++ src/slangParser.js | 69 +++++++++---------- 218 files changed, 396 insertions(+), 569 deletions(-) create mode 100644 src/slangCommentPrinter.js diff --git a/src/common/slang-helpers.js b/src/common/slang-helpers.js index 6cec31388..bf9c07e8b 100644 --- a/src/common/slang-helpers.js +++ b/src/common/slang-helpers.js @@ -103,8 +103,6 @@ const binaryIndentRulesBuilder = (path) => (document) => { return document; }; -const comparisonGroupRulesBuilder = () => (document) => group(document); - const isStatementWithComparisonOperationWithoutIndentation = createKindCheckFunction([ 'ReturnStatement', @@ -162,7 +160,7 @@ export const rightOperandPrint = (node, path, print) => { return shouldGroup ? group(rightOperand) : rightOperand; }; -const binaryOperationPrintBuilder = +export const binaryOperationPrintBuilder = (groupRulesBuilder, indentRulesBuilder) => ({ node, path, print, options }) => { const groupRules = groupRulesBuilder(path); @@ -181,7 +179,7 @@ export const binaryOperationPrint = binaryOperationPrintBuilder( ); export const comparisonOperationPrint = binaryOperationPrintBuilder( - comparisonGroupRulesBuilder, + () => (document) => group(document), // always group comparisonIndentRulesBuilder ); @@ -190,28 +188,28 @@ export const logicalOperationPrint = binaryOperationPrintBuilder( logicalIndentRulesBuilder ); -export const tryHug = (node, huggableOperators) => { - if ( - isBinaryOperation(node.variant) && - huggableOperators.has(node.variant.operator) - ) - return { - kind: 'Expression', - loc: { ...node.loc }, - variant: { - kind: 'TupleExpression', +export function createHugFunction(huggableOperators) { + const operators = new Set(huggableOperators); + return (node) => { + if (isBinaryOperation(node.variant) && operators.has(node.variant.operator)) + return { + kind: 'Expression', loc: { ...node.loc }, - openParen: '(', - items: { - kind: 'TupleValues', + variant: { + kind: 'TupleExpression', loc: { ...node.loc }, - items: [ - { kind: 'TupleValue', loc: { ...node.loc }, expression: node } - ], - separators: [] - }, - closeParen: ')' - } - }; - return node; -}; + openParen: '(', + items: { + kind: 'TupleValues', + loc: { ...node.loc }, + items: [ + { kind: 'TupleValue', loc: { ...node.loc }, expression: node } + ], + separators: [] + }, + closeParen: ')' + } + }; + return node; + }; +} diff --git a/src/slang-nodes/ABICoderPragma.js b/src/slang-nodes/ABICoderPragma.js index 5c590a8dc..5de917342 100644 --- a/src/slang-nodes/ABICoderPragma.js +++ b/src/slang-nodes/ABICoderPragma.js @@ -1,6 +1,5 @@ export const ABICoderPragma = { - parse: ({ node, ast }) => ({ - ...node, + parse: ({ ast }) => ({ abicoderKeyword: ast.abicoderKeyword.text, version: ast.version.text }), diff --git a/src/slang-nodes/AdditiveExpression.js b/src/slang-nodes/AdditiveExpression.js index f5a95493a..3f1344fd8 100644 --- a/src/slang-nodes/AdditiveExpression.js +++ b/src/slang-nodes/AdditiveExpression.js @@ -1,19 +1,15 @@ -import { binaryOperationPrint, tryHug } from '../common/slang-helpers.js'; +import { + binaryOperationPrint, + createHugFunction +} from '../common/slang-helpers.js'; -const huggableOperators = new Set(['%']); +const tryToHug = createHugFunction(['%']); export const AdditiveExpression = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, - leftOperand: tryHug( - parse(ast.leftOperand, options, parse, offsets), - huggableOperators - ), + parse: ({ offsets, ast, options, parse }) => ({ + leftOperand: tryToHug(parse(ast.leftOperand, options, parse, offsets)), operator: ast.operator.text, - rightOperand: tryHug( - parse(ast.rightOperand, options, parse, offsets), - huggableOperators - ) + rightOperand: tryToHug(parse(ast.rightOperand, options, parse, offsets)) }), print: binaryOperationPrint }; diff --git a/src/slang-nodes/AddressType.js b/src/slang-nodes/AddressType.js index 43d2ac6af..75c8d2c8e 100644 --- a/src/slang-nodes/AddressType.js +++ b/src/slang-nodes/AddressType.js @@ -1,6 +1,5 @@ export const AddressType = { - parse: ({ node, ast }) => ({ - ...node, + parse: ({ ast }) => ({ addressKeyword: ast.addressKeyword.text, payableKeyword: ast.payableKeyword?.text }), diff --git a/src/slang-nodes/AndExpression.js b/src/slang-nodes/AndExpression.js index 4601e3fde..9dad3a31f 100644 --- a/src/slang-nodes/AndExpression.js +++ b/src/slang-nodes/AndExpression.js @@ -1,8 +1,7 @@ import { logicalOperationPrint } from '../common/slang-helpers.js'; export const AndExpression = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ leftOperand: parse(ast.leftOperand, options, parse, offsets), operator: ast.operator.text, rightOperand: parse(ast.rightOperand, options, parse, offsets) diff --git a/src/slang-nodes/ArgumentsDeclaration.js b/src/slang-nodes/ArgumentsDeclaration.js index ad2e1a2a0..707e4d0b4 100644 --- a/src/slang-nodes/ArgumentsDeclaration.js +++ b/src/slang-nodes/ArgumentsDeclaration.js @@ -1,6 +1,5 @@ export const ArgumentsDeclaration = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ variant: parse(ast.variant, options, parse, offsets) }), print: ({ path, print }) => path.call(print, 'variant') diff --git a/src/slang-nodes/ArrayExpression.js b/src/slang-nodes/ArrayExpression.js index a143f507d..0c6eda827 100644 --- a/src/slang-nodes/ArrayExpression.js +++ b/src/slang-nodes/ArrayExpression.js @@ -3,8 +3,7 @@ import { doc } from 'prettier'; const { group } = doc.builders; export const ArrayExpression = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ openBracket: ast.openBracket.text, items: parse(ast.items, options, parse, offsets), closeBracket: ast.closeBracket.text diff --git a/src/slang-nodes/ArrayTypeName.js b/src/slang-nodes/ArrayTypeName.js index a3a75c65f..2d2a629cc 100644 --- a/src/slang-nodes/ArrayTypeName.js +++ b/src/slang-nodes/ArrayTypeName.js @@ -1,6 +1,5 @@ export const ArrayTypeName = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ operand: parse(ast.operand, options, parse, offsets), openBracket: ast.openBracket.text, index: ast.index ? parse(ast.index, options, parse, offsets) : undefined, diff --git a/src/slang-nodes/ArrayValues.js b/src/slang-nodes/ArrayValues.js index 61e8c8ce7..984ffc130 100644 --- a/src/slang-nodes/ArrayValues.js +++ b/src/slang-nodes/ArrayValues.js @@ -1,8 +1,7 @@ import { printSeparatedList } from '../common/printer-helpers.js'; export const ArrayValues = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/AssemblyFlags.js b/src/slang-nodes/AssemblyFlags.js index b62a5568c..1f8cc5ccc 100644 --- a/src/slang-nodes/AssemblyFlags.js +++ b/src/slang-nodes/AssemblyFlags.js @@ -1,8 +1,7 @@ import { printSeparatedList } from '../common/printer-helpers.js'; export const AssemblyFlags = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/AssemblyFlagsDeclaration.js b/src/slang-nodes/AssemblyFlagsDeclaration.js index e4bc26559..7595f1c0d 100644 --- a/src/slang-nodes/AssemblyFlagsDeclaration.js +++ b/src/slang-nodes/AssemblyFlagsDeclaration.js @@ -1,6 +1,5 @@ export const AssemblyFlagsDeclaration = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ openParen: ast.openParen.text, flags: parse(ast.flags, options, parse, offsets), closeParen: ast.closeParen.text diff --git a/src/slang-nodes/AssemblyStatement.js b/src/slang-nodes/AssemblyStatement.js index db1d0bee0..45a13a89b 100644 --- a/src/slang-nodes/AssemblyStatement.js +++ b/src/slang-nodes/AssemblyStatement.js @@ -1,6 +1,5 @@ export const AssemblyStatement = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ assemblyKeyword: ast.assemblyKeyword.text, label: ast.label ? parse(ast.label, options, parse, offsets) : undefined, flags: ast.flags ? parse(ast.flags, options, parse, offsets) : undefined, diff --git a/src/slang-nodes/AssignmentExpression.js b/src/slang-nodes/AssignmentExpression.js index 9f8e17b70..33798ca78 100644 --- a/src/slang-nodes/AssignmentExpression.js +++ b/src/slang-nodes/AssignmentExpression.js @@ -4,8 +4,7 @@ import { isBinaryOperation } from '../common/slang-helpers.js'; const { group, indent, line } = doc.builders; export const AssignmentExpression = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ leftOperand: parse(ast.leftOperand, options, parse, offsets), operator: ast.operator.text, rightOperand: parse(ast.rightOperand, options, parse, offsets) diff --git a/src/slang-nodes/BitwiseAndExpression.js b/src/slang-nodes/BitwiseAndExpression.js index 555683d8c..3c23df7d8 100644 --- a/src/slang-nodes/BitwiseAndExpression.js +++ b/src/slang-nodes/BitwiseAndExpression.js @@ -1,19 +1,15 @@ -import { binaryOperationPrint, tryHug } from '../common/slang-helpers.js'; +import { + binaryOperationPrint, + createHugFunction +} from '../common/slang-helpers.js'; -const huggableOperators = new Set(['+', '-', '*', '/', '**', '<<', '>>']); +const tryToHug = createHugFunction(['+', '-', '*', '/', '**', '<<', '>>']); export const BitwiseAndExpression = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, - leftOperand: tryHug( - parse(ast.leftOperand, options, parse, offsets), - huggableOperators - ), + parse: ({ offsets, ast, options, parse }) => ({ + leftOperand: tryToHug(parse(ast.leftOperand, options, parse, offsets)), operator: ast.operator.text, - rightOperand: tryHug( - parse(ast.rightOperand, options, parse, offsets), - huggableOperators - ) + rightOperand: tryToHug(parse(ast.rightOperand, options, parse, offsets)) }), print: binaryOperationPrint }; diff --git a/src/slang-nodes/BitwiseOrExpression.js b/src/slang-nodes/BitwiseOrExpression.js index 4f3ab709f..d8fd7bcea 100644 --- a/src/slang-nodes/BitwiseOrExpression.js +++ b/src/slang-nodes/BitwiseOrExpression.js @@ -1,6 +1,9 @@ -import { binaryOperationPrint, tryHug } from '../common/slang-helpers.js'; +import { + binaryOperationPrint, + createHugFunction +} from '../common/slang-helpers.js'; -const huggableOperators = new Set([ +const tryToHug = createHugFunction([ '+', '-', '*', @@ -13,17 +16,10 @@ const huggableOperators = new Set([ ]); export const BitwiseOrExpression = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, - leftOperand: tryHug( - parse(ast.leftOperand, options, parse, offsets), - huggableOperators - ), + parse: ({ offsets, ast, options, parse }) => ({ + leftOperand: tryToHug(parse(ast.leftOperand, options, parse, offsets)), operator: ast.operator.text, - rightOperand: tryHug( - parse(ast.rightOperand, options, parse, offsets), - huggableOperators - ) + rightOperand: tryToHug(parse(ast.rightOperand, options, parse, offsets)) }), print: binaryOperationPrint }; diff --git a/src/slang-nodes/BitwiseXorExpression.js b/src/slang-nodes/BitwiseXorExpression.js index 08f9a94d6..f64ed12e2 100644 --- a/src/slang-nodes/BitwiseXorExpression.js +++ b/src/slang-nodes/BitwiseXorExpression.js @@ -1,19 +1,15 @@ -import { binaryOperationPrint, tryHug } from '../common/slang-helpers.js'; +import { + binaryOperationPrint, + createHugFunction +} from '../common/slang-helpers.js'; -const huggableOperators = new Set(['+', '-', '*', '/', '**', '<<', '>>', '&']); +const tryToHug = createHugFunction(['+', '-', '*', '/', '**', '<<', '>>', '&']); export const BitwiseXorExpression = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, - leftOperand: tryHug( - parse(ast.leftOperand, options, parse, offsets), - huggableOperators - ), + parse: ({ offsets, ast, options, parse }) => ({ + leftOperand: tryToHug(parse(ast.leftOperand, options, parse, offsets)), operator: ast.operator.text, - rightOperand: tryHug( - parse(ast.rightOperand, options, parse, offsets), - huggableOperators - ) + rightOperand: tryToHug(parse(ast.rightOperand, options, parse, offsets)) }), print: binaryOperationPrint }; diff --git a/src/slang-nodes/Block.js b/src/slang-nodes/Block.js index fe67af530..c42738fc1 100644 --- a/src/slang-nodes/Block.js +++ b/src/slang-nodes/Block.js @@ -1,6 +1,5 @@ export const Block = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ openBrace: ast.openBrace.text, statements: parse(ast.statements, options, parse, offsets), closeBrace: ast.closeBrace.text diff --git a/src/slang-nodes/BreakStatement.js b/src/slang-nodes/BreakStatement.js index 3fc29b9e1..4326e8a1a 100644 --- a/src/slang-nodes/BreakStatement.js +++ b/src/slang-nodes/BreakStatement.js @@ -1,6 +1,5 @@ export const BreakStatement = { - parse: ({ node, ast }) => ({ - ...node, + parse: ({ ast }) => ({ breakKeyword: ast.breakKeyword.text, semicolon: ast.semicolon.text }), diff --git a/src/slang-nodes/CallOptions.js b/src/slang-nodes/CallOptions.js index 1bdeddb04..1eaad1b40 100644 --- a/src/slang-nodes/CallOptions.js +++ b/src/slang-nodes/CallOptions.js @@ -1,8 +1,7 @@ import { printSeparatedList } from '../common/printer-helpers.js'; export const CallOptions = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/CallOptionsExpression.js b/src/slang-nodes/CallOptionsExpression.js index 5d2a75fe5..25c1fab8a 100644 --- a/src/slang-nodes/CallOptionsExpression.js +++ b/src/slang-nodes/CallOptionsExpression.js @@ -1,6 +1,5 @@ export const CallOptionsExpression = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ operand: parse(ast.operand, options, parse, offsets), openBrace: ast.openBrace.text, options: parse(ast.options, options, parse, offsets), diff --git a/src/slang-nodes/CatchClause.js b/src/slang-nodes/CatchClause.js index 0549a123b..7cec9d289 100644 --- a/src/slang-nodes/CatchClause.js +++ b/src/slang-nodes/CatchClause.js @@ -1,6 +1,5 @@ export const CatchClause = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ catchKeyword: ast.catchKeyword.text, error: ast.error ? parse(ast.error, options, parse, offsets) : undefined, body: parse(ast.body, options, parse, offsets) diff --git a/src/slang-nodes/CatchClauseError.js b/src/slang-nodes/CatchClauseError.js index 3241a0409..c6665c3a8 100644 --- a/src/slang-nodes/CatchClauseError.js +++ b/src/slang-nodes/CatchClauseError.js @@ -1,6 +1,5 @@ export const CatchClauseError = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ name: ast.name?.text, parameters: parse(ast.parameters, options, parse, offsets) }), diff --git a/src/slang-nodes/CatchClauses.js b/src/slang-nodes/CatchClauses.js index 1f26f84d7..25de211aa 100644 --- a/src/slang-nodes/CatchClauses.js +++ b/src/slang-nodes/CatchClauses.js @@ -3,8 +3,7 @@ import { doc } from 'prettier'; const { join } = doc.builders; export const CatchClauses = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ path, print }) => join(' ', path.map(print, 'items')) diff --git a/src/slang-nodes/ComparisonExpression.js b/src/slang-nodes/ComparisonExpression.js index bde9559f6..d3aa5d3f6 100644 --- a/src/slang-nodes/ComparisonExpression.js +++ b/src/slang-nodes/ComparisonExpression.js @@ -1,8 +1,7 @@ import { comparisonOperationPrint } from '../common/slang-helpers.js'; export const ComparisonExpression = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ leftOperand: parse(ast.leftOperand, options, parse, offsets), operator: ast.operator.text, rightOperand: parse(ast.rightOperand, options, parse, offsets) diff --git a/src/slang-nodes/ConditionalExpression.js b/src/slang-nodes/ConditionalExpression.js index 89299805d..2324e4698 100644 --- a/src/slang-nodes/ConditionalExpression.js +++ b/src/slang-nodes/ConditionalExpression.js @@ -87,7 +87,7 @@ const traditionalTernaries = (node, path, print) => ]); export const ConditionalExpression = { - parse: ({ node, offsets, ast, options, parse }) => { + parse: ({ offsets, ast, options, parse }) => { let operand = parse(ast.operand, options, parse, offsets); // TODO: while the behaviour is not stable, it should be behind the @@ -106,7 +106,6 @@ export const ConditionalExpression = { } return { - ...node, operand, questionMark: ast.questionMark.text, trueExpression: parse(ast.trueExpression, options, parse, offsets), diff --git a/src/slang-nodes/ConstantDefinition.js b/src/slang-nodes/ConstantDefinition.js index 1e35f145a..a5f6868e0 100644 --- a/src/slang-nodes/ConstantDefinition.js +++ b/src/slang-nodes/ConstantDefinition.js @@ -1,6 +1,5 @@ export const ConstantDefinition = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ typeName: parse(ast.typeName, options, parse, offsets), constantKeyword: ast.constantKeyword.text, name: ast.name.text, diff --git a/src/slang-nodes/ConstructorAttribute.js b/src/slang-nodes/ConstructorAttribute.js index 60c3270b0..3bfb4491c 100644 --- a/src/slang-nodes/ConstructorAttribute.js +++ b/src/slang-nodes/ConstructorAttribute.js @@ -1,6 +1,5 @@ export const ConstructorAttribute = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/ConstructorAttributes.js b/src/slang-nodes/ConstructorAttributes.js index dd64cc6f9..6331077e9 100644 --- a/src/slang-nodes/ConstructorAttributes.js +++ b/src/slang-nodes/ConstructorAttributes.js @@ -3,8 +3,7 @@ import { doc } from 'prettier'; const { line } = doc.builders; export const ConstructorAttributes = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ path, print }) => diff --git a/src/slang-nodes/ConstructorDefinition.js b/src/slang-nodes/ConstructorDefinition.js index b92430ea9..cf478071c 100644 --- a/src/slang-nodes/ConstructorDefinition.js +++ b/src/slang-nodes/ConstructorDefinition.js @@ -1,8 +1,7 @@ import { printFunction } from '../common/slang-helpers.js'; export const ConstructorDefinition = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ constructorKeyword: ast.constructorKeyword.text, parameters: parse(ast.parameters, options, parse, offsets), attributes: parse(ast.attributes, options, parse, offsets), diff --git a/src/slang-nodes/ContinueStatement.js b/src/slang-nodes/ContinueStatement.js index c3ba84d88..760347a99 100644 --- a/src/slang-nodes/ContinueStatement.js +++ b/src/slang-nodes/ContinueStatement.js @@ -1,6 +1,5 @@ export const ContinueStatement = { - parse: ({ node, ast }) => ({ - ...node, + parse: ({ ast }) => ({ continueKeyword: ast.continueKeyword.text, semicolon: ast.semicolon.text }), diff --git a/src/slang-nodes/ContractDefinition.js b/src/slang-nodes/ContractDefinition.js index d4f36f26f..5190c046e 100644 --- a/src/slang-nodes/ContractDefinition.js +++ b/src/slang-nodes/ContractDefinition.js @@ -3,8 +3,7 @@ import { doc } from 'prettier'; const { group, line } = doc.builders; export const ContractDefinition = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ abstractKeyword: ast.abstractKeyword?.text, contractKeyword: ast.contractKeyword.text, name: ast.name.text, diff --git a/src/slang-nodes/ContractMember.js b/src/slang-nodes/ContractMember.js index 12950c3b5..82fe9d048 100644 --- a/src/slang-nodes/ContractMember.js +++ b/src/slang-nodes/ContractMember.js @@ -1,6 +1,5 @@ export const ContractMember = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ variant: parse(ast.variant, options, parse, offsets) }), print: ({ path, print }) => path.call(print, 'variant') diff --git a/src/slang-nodes/ContractMembers.js b/src/slang-nodes/ContractMembers.js index 34a89db8e..2ff014ed8 100644 --- a/src/slang-nodes/ContractMembers.js +++ b/src/slang-nodes/ContractMembers.js @@ -5,8 +5,7 @@ import { printPreservingEmptyLines } from '../common/slang-helpers.js'; const { hardline } = doc.builders; export const ContractMembers = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ node, options, path, print }) => diff --git a/src/slang-nodes/DecimalNumberExpression.js b/src/slang-nodes/DecimalNumberExpression.js index fb523b9a4..2137c61bb 100644 --- a/src/slang-nodes/DecimalNumberExpression.js +++ b/src/slang-nodes/DecimalNumberExpression.js @@ -1,6 +1,5 @@ export const DecimalNumberExpression = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ literal: ast.literal.text, unit: ast.unit ? parse(ast.unit, options, parse, offsets) : undefined }), diff --git a/src/slang-nodes/DoWhileStatement.js b/src/slang-nodes/DoWhileStatement.js index 4b765c975..eedef4e75 100644 --- a/src/slang-nodes/DoWhileStatement.js +++ b/src/slang-nodes/DoWhileStatement.js @@ -9,8 +9,7 @@ const printBody = (node, path, print) => : group([indent([line, path.call(print, 'body')]), line]); export const DoWhileStatement = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ doKeyword: ast.doKeyword.text, body: parse(ast.body, options, parse, offsets), whileKeyword: ast.whileKeyword.text, diff --git a/src/slang-nodes/ElementaryType.js b/src/slang-nodes/ElementaryType.js index 8659967fc..d6f336a2b 100644 --- a/src/slang-nodes/ElementaryType.js +++ b/src/slang-nodes/ElementaryType.js @@ -1,6 +1,5 @@ export const ElementaryType = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/ElseBranch.js b/src/slang-nodes/ElseBranch.js index 8579adddf..1648aa131 100644 --- a/src/slang-nodes/ElseBranch.js +++ b/src/slang-nodes/ElseBranch.js @@ -8,8 +8,7 @@ const printBody = (bodyVariantKind, path, print) => : group(indent([line, path.call(print, 'body')])); export const ElseBranch = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ elseKeyword: ast.elseKeyword.text, body: parse(ast.body, options, parse, offsets) }), diff --git a/src/slang-nodes/EmitStatement.js b/src/slang-nodes/EmitStatement.js index 8f2c6d664..b36e8a34b 100644 --- a/src/slang-nodes/EmitStatement.js +++ b/src/slang-nodes/EmitStatement.js @@ -1,6 +1,5 @@ export const EmitStatement = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ emitKeyword: ast.emitKeyword.text, event: parse(ast.event, options, parse, offsets), arguments: parse(ast.arguments, options, parse, offsets), diff --git a/src/slang-nodes/EnumDefinition.js b/src/slang-nodes/EnumDefinition.js index fe46abbd6..2021e404b 100644 --- a/src/slang-nodes/EnumDefinition.js +++ b/src/slang-nodes/EnumDefinition.js @@ -1,6 +1,5 @@ export const EnumDefinition = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ enumKeyword: ast.enumKeyword.text, name: ast.name.text, openBrace: ast.openBrace.text, diff --git a/src/slang-nodes/EnumMembers.js b/src/slang-nodes/EnumMembers.js index 3b782a0b4..a741876bb 100644 --- a/src/slang-nodes/EnumMembers.js +++ b/src/slang-nodes/EnumMembers.js @@ -4,8 +4,7 @@ import { printSeparatedList } from '../common/printer-helpers.js'; const { hardline } = doc.builders; export const EnumMembers = { - parse: ({ node, ast }) => ({ - ...node, + parse: ({ ast }) => ({ items: ast.items.map((item) => item.text), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/EqualityExpression.js b/src/slang-nodes/EqualityExpression.js index d5b5fbd41..3a2f8fd0d 100644 --- a/src/slang-nodes/EqualityExpression.js +++ b/src/slang-nodes/EqualityExpression.js @@ -1,8 +1,7 @@ import { comparisonOperationPrint } from '../common/slang-helpers.js'; export const EqualityExpression = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ leftOperand: parse(ast.leftOperand, options, parse, offsets), operator: ast.operator.text, rightOperand: parse(ast.rightOperand, options, parse, offsets) diff --git a/src/slang-nodes/ErrorDefinition.js b/src/slang-nodes/ErrorDefinition.js index 06a1e8d9c..b74b9e9a3 100644 --- a/src/slang-nodes/ErrorDefinition.js +++ b/src/slang-nodes/ErrorDefinition.js @@ -1,6 +1,5 @@ export const ErrorDefinition = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ errorKeyword: ast.errorKeyword.text, name: ast.name.text, members: parse(ast.members, options, parse, offsets), diff --git a/src/slang-nodes/ErrorParameter.js b/src/slang-nodes/ErrorParameter.js index fa3fcb60e..68dcbf772 100644 --- a/src/slang-nodes/ErrorParameter.js +++ b/src/slang-nodes/ErrorParameter.js @@ -1,6 +1,5 @@ export const ErrorParameter = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ typeName: parse(ast.typeName, options, parse, offsets), name: ast.name?.text }), diff --git a/src/slang-nodes/ErrorParameters.js b/src/slang-nodes/ErrorParameters.js index a480f4c46..85454e1bf 100644 --- a/src/slang-nodes/ErrorParameters.js +++ b/src/slang-nodes/ErrorParameters.js @@ -1,8 +1,7 @@ import { printSeparatedList } from '../common/printer-helpers.js'; export const ErrorParameters = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/ErrorParametersDeclaration.js b/src/slang-nodes/ErrorParametersDeclaration.js index c3011b9a6..cce0f25b5 100644 --- a/src/slang-nodes/ErrorParametersDeclaration.js +++ b/src/slang-nodes/ErrorParametersDeclaration.js @@ -1,6 +1,5 @@ export const ErrorParametersDeclaration = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ openParen: ast.openParen.text, parameters: parse(ast.parameters, options, parse, offsets), closeParen: ast.closeParen.text diff --git a/src/slang-nodes/EventDefinition.js b/src/slang-nodes/EventDefinition.js index 5903ade78..5b5a7a54a 100644 --- a/src/slang-nodes/EventDefinition.js +++ b/src/slang-nodes/EventDefinition.js @@ -1,6 +1,5 @@ export const EventDefinition = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ eventKeyword: ast.eventKeyword.text, name: ast.name.text, parameters: parse(ast.parameters, options, parse, offsets), diff --git a/src/slang-nodes/EventParameter.js b/src/slang-nodes/EventParameter.js index 31516c309..5ae0ab6b6 100644 --- a/src/slang-nodes/EventParameter.js +++ b/src/slang-nodes/EventParameter.js @@ -1,6 +1,5 @@ export const EventParameter = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ typeName: parse(ast.typeName, options, parse, offsets), indexedKeyword: ast.indexedKeyword?.text, name: ast.name?.text diff --git a/src/slang-nodes/EventParameters.js b/src/slang-nodes/EventParameters.js index 0489e2ddb..88501eb67 100644 --- a/src/slang-nodes/EventParameters.js +++ b/src/slang-nodes/EventParameters.js @@ -1,8 +1,7 @@ import { printSeparatedList } from '../common/printer-helpers.js'; export const EventParameters = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/EventParametersDeclaration.js b/src/slang-nodes/EventParametersDeclaration.js index b60ce01b9..874469597 100644 --- a/src/slang-nodes/EventParametersDeclaration.js +++ b/src/slang-nodes/EventParametersDeclaration.js @@ -1,6 +1,5 @@ export const EventParametersDeclaration = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ openParen: ast.openParen.text, parameters: parse(ast.parameters, options, parse, offsets), closeParen: ast.closeParen.text diff --git a/src/slang-nodes/ExperimentalFeature.js b/src/slang-nodes/ExperimentalFeature.js index 330c455a7..e61b524d2 100644 --- a/src/slang-nodes/ExperimentalFeature.js +++ b/src/slang-nodes/ExperimentalFeature.js @@ -1,6 +1,5 @@ export const ExperimentalFeature = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/ExperimentalPragma.js b/src/slang-nodes/ExperimentalPragma.js index 3f041b887..dac744fed 100644 --- a/src/slang-nodes/ExperimentalPragma.js +++ b/src/slang-nodes/ExperimentalPragma.js @@ -1,6 +1,5 @@ export const ExperimentalPragma = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ experimentalKeyword: ast.experimentalKeyword.text, feature: parse(ast.feature, options, parse, offsets) }), diff --git a/src/slang-nodes/ExponentiationExpression.js b/src/slang-nodes/ExponentiationExpression.js index b423fd203..f461aeec2 100644 --- a/src/slang-nodes/ExponentiationExpression.js +++ b/src/slang-nodes/ExponentiationExpression.js @@ -1,36 +1,36 @@ import { doc } from 'prettier'; import coerce from 'semver/functions/coerce.js'; import satisfies from 'semver/functions/satisfies.js'; -import { rightOperandPrint, tryHug } from '../common/slang-helpers.js'; +import { + binaryOperationPrintBuilder, + createHugFunction +} from '../common/slang-helpers.js'; const { group, indent } = doc.builders; -const huggableOperators = new Set(['**']); +const tryToHug = createHugFunction(['**']); export const ExponentiationExpression = { - parse: ({ node, offsets, ast, options, parse }) => { + parse: ({ offsets, ast, options, parse }) => { const compiler = coerce(options.compiler); let leftOperand = parse(ast.leftOperand, options, parse, offsets); let rightOperand = parse(ast.rightOperand, options, parse, offsets); if (compiler) { if (satisfies(compiler, '>=0.8.0')) { - rightOperand = tryHug(rightOperand, huggableOperators); + rightOperand = tryToHug(rightOperand); } else { - leftOperand = tryHug(leftOperand, huggableOperators); + leftOperand = tryToHug(leftOperand); } } return { - ...node, leftOperand, operator: ast.operator.text, rightOperand }; }, - print: ({ node, path, print }) => - group([ - path.call(print, 'leftOperand'), - ` ${node.operator}`, - indent(rightOperandPrint(node, path, print)) - ]) + print: binaryOperationPrintBuilder( + () => (document) => group(document), // always group + () => (document) => indent(document) // always indent + ) }; diff --git a/src/slang-nodes/Expression.js b/src/slang-nodes/Expression.js index fc6f15d42..955e32ee9 100644 --- a/src/slang-nodes/Expression.js +++ b/src/slang-nodes/Expression.js @@ -1,6 +1,5 @@ export const Expression = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/ExpressionStatement.js b/src/slang-nodes/ExpressionStatement.js index 843197ca0..f954820d8 100644 --- a/src/slang-nodes/ExpressionStatement.js +++ b/src/slang-nodes/ExpressionStatement.js @@ -1,6 +1,5 @@ export const ExpressionStatement = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ expression: parse(ast.expression, options, parse, offsets), semicolon: ast.semicolon.text }), diff --git a/src/slang-nodes/FallbackFunctionAttribute.js b/src/slang-nodes/FallbackFunctionAttribute.js index b6978ccd0..84c9a913b 100644 --- a/src/slang-nodes/FallbackFunctionAttribute.js +++ b/src/slang-nodes/FallbackFunctionAttribute.js @@ -1,6 +1,5 @@ export const FallbackFunctionAttribute = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/FallbackFunctionAttributes.js b/src/slang-nodes/FallbackFunctionAttributes.js index 142bc757f..cbe66818c 100644 --- a/src/slang-nodes/FallbackFunctionAttributes.js +++ b/src/slang-nodes/FallbackFunctionAttributes.js @@ -3,8 +3,7 @@ import { doc } from 'prettier'; const { line } = doc.builders; export const FallbackFunctionAttributes = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ path, print }) => diff --git a/src/slang-nodes/FallbackFunctionDefinition.js b/src/slang-nodes/FallbackFunctionDefinition.js index 9aa6b4108..16834e18d 100644 --- a/src/slang-nodes/FallbackFunctionDefinition.js +++ b/src/slang-nodes/FallbackFunctionDefinition.js @@ -1,8 +1,7 @@ import { printFunction } from '../common/slang-helpers.js'; export const FallbackFunctionDefinition = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ fallbackKeyword: ast.fallbackKeyword.text, parameters: parse(ast.parameters, options, parse, offsets), attributes: parse(ast.attributes, options, parse, offsets), diff --git a/src/slang-nodes/ForStatement.js b/src/slang-nodes/ForStatement.js index f8c72a648..626a100f0 100644 --- a/src/slang-nodes/ForStatement.js +++ b/src/slang-nodes/ForStatement.js @@ -4,8 +4,7 @@ import { printSeparatedList } from '../common/printer-helpers.js'; const { group, indent, line } = doc.builders; export const ForStatement = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ forKeyword: ast.forKeyword.text, openParen: ast.openParen.text, initialization: parse(ast.initialization, options, parse, offsets), diff --git a/src/slang-nodes/ForStatementCondition.js b/src/slang-nodes/ForStatementCondition.js index 98ab18436..5b4ff65d5 100644 --- a/src/slang-nodes/ForStatementCondition.js +++ b/src/slang-nodes/ForStatementCondition.js @@ -1,6 +1,5 @@ export const ForStatementCondition = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/ForStatementInitialization.js b/src/slang-nodes/ForStatementInitialization.js index 554963166..49d0fb98f 100644 --- a/src/slang-nodes/ForStatementInitialization.js +++ b/src/slang-nodes/ForStatementInitialization.js @@ -1,6 +1,5 @@ export const ForStatementInitialization = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/FunctionAttribute.js b/src/slang-nodes/FunctionAttribute.js index 15c6caadc..0518a885f 100644 --- a/src/slang-nodes/FunctionAttribute.js +++ b/src/slang-nodes/FunctionAttribute.js @@ -1,6 +1,5 @@ export const FunctionAttribute = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/FunctionAttributes.js b/src/slang-nodes/FunctionAttributes.js index 56a92c0d4..fec1c5c4f 100644 --- a/src/slang-nodes/FunctionAttributes.js +++ b/src/slang-nodes/FunctionAttributes.js @@ -3,8 +3,7 @@ import { doc } from 'prettier'; const { line } = doc.builders; export const FunctionAttributes = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ path, print }) => diff --git a/src/slang-nodes/FunctionBody.js b/src/slang-nodes/FunctionBody.js index 3eb2b0198..82263ae77 100644 --- a/src/slang-nodes/FunctionBody.js +++ b/src/slang-nodes/FunctionBody.js @@ -1,6 +1,5 @@ export const FunctionBody = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/FunctionCallExpression.js b/src/slang-nodes/FunctionCallExpression.js index b43208b25..222067a56 100644 --- a/src/slang-nodes/FunctionCallExpression.js +++ b/src/slang-nodes/FunctionCallExpression.js @@ -6,8 +6,7 @@ const { group, indentIfBreak, label } = doc.builders; let groupIndex = 0; export const FunctionCallExpression = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ operand: parse(ast.operand, options, parse, offsets), arguments: parse(ast.arguments, options, parse, offsets) }), diff --git a/src/slang-nodes/FunctionDefinition.js b/src/slang-nodes/FunctionDefinition.js index a77ff08db..44ed880d9 100644 --- a/src/slang-nodes/FunctionDefinition.js +++ b/src/slang-nodes/FunctionDefinition.js @@ -1,8 +1,7 @@ import { printFunction } from '../common/slang-helpers.js'; export const FunctionDefinition = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ functionKeyword: ast.functionKeyword.text, name: parse(ast.name, options, parse, offsets), parameters: parse(ast.parameters, options, parse, offsets), diff --git a/src/slang-nodes/FunctionName.js b/src/slang-nodes/FunctionName.js index 4d14af1c0..5cb2e0579 100644 --- a/src/slang-nodes/FunctionName.js +++ b/src/slang-nodes/FunctionName.js @@ -1,6 +1,5 @@ export const FunctionName = { - parse: ({ node, ast }) => ({ - ...node, + parse: ({ ast }) => ({ variant: ast.variant.text }), print: ({ node }) => node.variant diff --git a/src/slang-nodes/FunctionType.js b/src/slang-nodes/FunctionType.js index 9cadcdc38..1c6caca4b 100644 --- a/src/slang-nodes/FunctionType.js +++ b/src/slang-nodes/FunctionType.js @@ -1,8 +1,7 @@ import { printFunction } from '../common/slang-helpers.js'; export const FunctionType = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ functionKeyword: ast.functionKeyword.text, parameters: parse(ast.parameters, options, parse, offsets), attributes: parse(ast.attributes, options, parse, offsets), diff --git a/src/slang-nodes/FunctionTypeAttribute.js b/src/slang-nodes/FunctionTypeAttribute.js index 132e30aef..5cda4b957 100644 --- a/src/slang-nodes/FunctionTypeAttribute.js +++ b/src/slang-nodes/FunctionTypeAttribute.js @@ -1,6 +1,5 @@ export const FunctionTypeAttribute = { - parse: ({ node, ast }) => ({ - ...node, + parse: ({ ast }) => ({ variant: ast.variant.text }), print: ({ node }) => node.variant diff --git a/src/slang-nodes/FunctionTypeAttributes.js b/src/slang-nodes/FunctionTypeAttributes.js index c06b82701..4d9b7feab 100644 --- a/src/slang-nodes/FunctionTypeAttributes.js +++ b/src/slang-nodes/FunctionTypeAttributes.js @@ -3,8 +3,7 @@ import { doc } from 'prettier'; const { line } = doc.builders; export const FunctionTypeAttributes = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ path, print }) => diff --git a/src/slang-nodes/HexNumberExpression.js b/src/slang-nodes/HexNumberExpression.js index 09abce561..98fa1eded 100644 --- a/src/slang-nodes/HexNumberExpression.js +++ b/src/slang-nodes/HexNumberExpression.js @@ -1,6 +1,5 @@ export const HexNumberExpression = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ literal: ast.literal.text, unit: ast.unit ? parse(ast.unit, options, parse, offsets) : undefined }), diff --git a/src/slang-nodes/HexStringLiteral.js b/src/slang-nodes/HexStringLiteral.js index 5145d9e39..b16f31f2b 100644 --- a/src/slang-nodes/HexStringLiteral.js +++ b/src/slang-nodes/HexStringLiteral.js @@ -1,8 +1,7 @@ import { printString } from '../common/util.js'; export const HexStringLiteral = { - parse: ({ node, ast, options }) => ({ - ...node, + parse: ({ ast, options }) => ({ variant: `hex${printString(ast.variant.text.slice(4, -1), options)}` }), print: ({ node }) => node.variant diff --git a/src/slang-nodes/HexStringLiterals.js b/src/slang-nodes/HexStringLiterals.js index fe6e6fd71..eec902d0b 100644 --- a/src/slang-nodes/HexStringLiterals.js +++ b/src/slang-nodes/HexStringLiterals.js @@ -3,8 +3,7 @@ import { doc } from 'prettier'; const { join, hardline } = doc.builders; export const HexStringLiterals = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ path, print }) => join(hardline, path.map(print, 'items')) diff --git a/src/slang-nodes/IdentifierPath.js b/src/slang-nodes/IdentifierPath.js index 7cffda01a..4b8dfb60d 100644 --- a/src/slang-nodes/IdentifierPath.js +++ b/src/slang-nodes/IdentifierPath.js @@ -1,6 +1,5 @@ export const IdentifierPath = { - parse: ({ node, ast }) => ({ - ...node, + parse: ({ ast }) => ({ items: ast.items.map((item) => item.text), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/IfStatement.js b/src/slang-nodes/IfStatement.js index c276b6828..70c8e1513 100644 --- a/src/slang-nodes/IfStatement.js +++ b/src/slang-nodes/IfStatement.js @@ -11,8 +11,7 @@ const printBody = (bodyVariantKind, path, print) => }); export const IfStatement = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ ifKeyword: ast.ifKeyword.text, openParen: ast.openParen.text, condition: parse(ast.condition, options, parse, offsets), diff --git a/src/slang-nodes/ImportAlias.js b/src/slang-nodes/ImportAlias.js index d96a6f34e..088d8cec9 100644 --- a/src/slang-nodes/ImportAlias.js +++ b/src/slang-nodes/ImportAlias.js @@ -1,6 +1,5 @@ export const ImportAlias = { - parse: ({ node, ast }) => ({ - ...node, + parse: ({ ast }) => ({ asKeyword: ast.asKeyword.text, identifier: ast.identifier.text }), diff --git a/src/slang-nodes/ImportClause.js b/src/slang-nodes/ImportClause.js index 5f98954d5..04ec7473e 100644 --- a/src/slang-nodes/ImportClause.js +++ b/src/slang-nodes/ImportClause.js @@ -1,6 +1,5 @@ export const ImportClause = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ variant: parse(ast.variant, options, parse, offsets) }), print: ({ path, print }) => path.call(print, 'variant') diff --git a/src/slang-nodes/ImportDeconstruction.js b/src/slang-nodes/ImportDeconstruction.js index 2f3b19da4..2947be004 100644 --- a/src/slang-nodes/ImportDeconstruction.js +++ b/src/slang-nodes/ImportDeconstruction.js @@ -1,6 +1,5 @@ export const ImportDeconstruction = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ openBrace: ast.openBrace.text, symbols: parse(ast.symbols, options, parse, offsets), closeBrace: ast.closeBrace.text, diff --git a/src/slang-nodes/ImportDeconstructionSymbol.js b/src/slang-nodes/ImportDeconstructionSymbol.js index a47aed9b2..748f49683 100644 --- a/src/slang-nodes/ImportDeconstructionSymbol.js +++ b/src/slang-nodes/ImportDeconstructionSymbol.js @@ -1,6 +1,5 @@ export const ImportDeconstructionSymbol = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ name: ast.name.text, alias: ast.alias ? parse(ast.alias, options, parse, offsets) : undefined }), diff --git a/src/slang-nodes/ImportDeconstructionSymbols.js b/src/slang-nodes/ImportDeconstructionSymbols.js index 79d3b43ab..f15fec283 100644 --- a/src/slang-nodes/ImportDeconstructionSymbols.js +++ b/src/slang-nodes/ImportDeconstructionSymbols.js @@ -6,8 +6,7 @@ import { printSeparatedList } from '../common/printer-helpers.js'; const { line, softline } = doc.builders; export const ImportDeconstructionSymbols = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/ImportDirective.js b/src/slang-nodes/ImportDirective.js index a17e36282..50c8c7889 100644 --- a/src/slang-nodes/ImportDirective.js +++ b/src/slang-nodes/ImportDirective.js @@ -1,6 +1,5 @@ export const ImportDirective = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ importKeyword: ast.importKeyword.text, clause: parse(ast.clause, options, parse, offsets), semicolon: ast.semicolon.text diff --git a/src/slang-nodes/IndexAccessEnd.js b/src/slang-nodes/IndexAccessEnd.js index 48f8a66ce..acdc20242 100644 --- a/src/slang-nodes/IndexAccessEnd.js +++ b/src/slang-nodes/IndexAccessEnd.js @@ -1,6 +1,5 @@ export const IndexAccessEnd = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ colon: ast.colon.text, end: ast.end ? parse(ast.end, options, parse, offsets) : undefined }), diff --git a/src/slang-nodes/IndexAccessExpression.js b/src/slang-nodes/IndexAccessExpression.js index 1e6c6aa1b..332c94f56 100644 --- a/src/slang-nodes/IndexAccessExpression.js +++ b/src/slang-nodes/IndexAccessExpression.js @@ -6,8 +6,7 @@ const { group, indent, indentIfBreak, label, softline } = doc.builders; let groupIndex = 0; export const IndexAccessExpression = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ operand: parse(ast.operand, options, parse, offsets), openBracket: ast.openBracket.text, start: ast.start ? parse(ast.start, options, parse, offsets) : undefined, diff --git a/src/slang-nodes/InheritanceSpecifier.js b/src/slang-nodes/InheritanceSpecifier.js index 1f8a85384..b490fd856 100644 --- a/src/slang-nodes/InheritanceSpecifier.js +++ b/src/slang-nodes/InheritanceSpecifier.js @@ -1,6 +1,5 @@ export const InheritanceSpecifier = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ isKeyword: ast.isKeyword.text, types: parse(ast.types, options, parse, offsets) }), diff --git a/src/slang-nodes/InheritanceType.js b/src/slang-nodes/InheritanceType.js index c8db7bd45..5ba9c95cf 100644 --- a/src/slang-nodes/InheritanceType.js +++ b/src/slang-nodes/InheritanceType.js @@ -1,6 +1,5 @@ export const InheritanceType = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ typeName: parse(ast.typeName, options, parse, offsets), arguments: ast.arguments ? parse(ast.arguments, options, parse, offsets) diff --git a/src/slang-nodes/InheritanceTypes.js b/src/slang-nodes/InheritanceTypes.js index ff35dd632..4471808df 100644 --- a/src/slang-nodes/InheritanceTypes.js +++ b/src/slang-nodes/InheritanceTypes.js @@ -4,8 +4,7 @@ import { printSeparatedList } from '../common/printer-helpers.js'; const { line } = doc.builders; export const InheritanceTypes = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/InterfaceDefinition.js b/src/slang-nodes/InterfaceDefinition.js index 7988bb49d..40e3a4463 100644 --- a/src/slang-nodes/InterfaceDefinition.js +++ b/src/slang-nodes/InterfaceDefinition.js @@ -3,8 +3,7 @@ import { doc } from 'prettier'; const { group, line } = doc.builders; export const InterfaceDefinition = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ interfaceKeyword: ast.interfaceKeyword.text, name: ast.name.text, inheritance: ast.inheritence diff --git a/src/slang-nodes/InterfaceMembers.js b/src/slang-nodes/InterfaceMembers.js index 181a34526..5c63ecd40 100644 --- a/src/slang-nodes/InterfaceMembers.js +++ b/src/slang-nodes/InterfaceMembers.js @@ -5,8 +5,7 @@ import { printPreservingEmptyLines } from '../common/slang-helpers.js'; const { hardline } = doc.builders; export const InterfaceMembers = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ node, options, path, print }) => diff --git a/src/slang-nodes/LibraryDefinition.js b/src/slang-nodes/LibraryDefinition.js index 774e041f0..7df51a1f9 100644 --- a/src/slang-nodes/LibraryDefinition.js +++ b/src/slang-nodes/LibraryDefinition.js @@ -3,8 +3,7 @@ import { doc } from 'prettier'; const { group, line } = doc.builders; export const LibraryDefinition = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ libraryKeyword: ast.libraryKeyword.text, name: ast.name.text, openBrace: ast.openBrace.text, diff --git a/src/slang-nodes/LibraryMembers.js b/src/slang-nodes/LibraryMembers.js index b72267b5c..5d6f78886 100644 --- a/src/slang-nodes/LibraryMembers.js +++ b/src/slang-nodes/LibraryMembers.js @@ -5,8 +5,7 @@ import { printPreservingEmptyLines } from '../common/slang-helpers.js'; const { hardline } = doc.builders; export const LibraryMembers = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ node, path, print, options }) => diff --git a/src/slang-nodes/MappingKey.js b/src/slang-nodes/MappingKey.js index a56e5f86f..13053af70 100644 --- a/src/slang-nodes/MappingKey.js +++ b/src/slang-nodes/MappingKey.js @@ -1,6 +1,5 @@ export const MappingKey = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ keyType: parse(ast.keyType, options, parse, offsets), name: ast.name?.text }), diff --git a/src/slang-nodes/MappingKeyType.js b/src/slang-nodes/MappingKeyType.js index 92f154052..eab4d9d49 100644 --- a/src/slang-nodes/MappingKeyType.js +++ b/src/slang-nodes/MappingKeyType.js @@ -1,6 +1,5 @@ export const MappingKeyType = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ variant: parse(ast.variant, options, parse, offsets) }), print: ({ path, print }) => path.call(print, 'variant') diff --git a/src/slang-nodes/MappingType.js b/src/slang-nodes/MappingType.js index b1ce8e252..5f9708976 100644 --- a/src/slang-nodes/MappingType.js +++ b/src/slang-nodes/MappingType.js @@ -1,6 +1,5 @@ export const MappingType = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ mappingKeyword: ast.mappingKeyword.text, openParen: ast.openParen.text, keyType: parse(ast.keyType, options, parse, offsets), diff --git a/src/slang-nodes/MappingValue.js b/src/slang-nodes/MappingValue.js index 0cbb7cfd6..e37e8a90f 100644 --- a/src/slang-nodes/MappingValue.js +++ b/src/slang-nodes/MappingValue.js @@ -1,6 +1,5 @@ export const MappingValue = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ typeName: parse(ast.typeName, options, parse, offsets), name: ast.name?.text }), diff --git a/src/slang-nodes/MemberAccess.js b/src/slang-nodes/MemberAccess.js index 837864f01..780257c4a 100644 --- a/src/slang-nodes/MemberAccess.js +++ b/src/slang-nodes/MemberAccess.js @@ -1,6 +1,5 @@ export const MemberAccess = { - parse: ({ node, ast }) => ({ - ...node, + parse: ({ ast }) => ({ variant: ast.variant.text }), print: ({ node }) => node.variant diff --git a/src/slang-nodes/MemberAccessExpression.js b/src/slang-nodes/MemberAccessExpression.js index 4ff6069f0..f80cac862 100644 --- a/src/slang-nodes/MemberAccessExpression.js +++ b/src/slang-nodes/MemberAccessExpression.js @@ -105,8 +105,7 @@ const processChain = (chain) => { }; export const MemberAccessExpression = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ operand: parse(ast.operand, options, parse, offsets), period: ast.period.text, member: parse(ast.member, options, parse, offsets) diff --git a/src/slang-nodes/ModifierAttribute.js b/src/slang-nodes/ModifierAttribute.js index ed830d814..7ddd1d2ec 100644 --- a/src/slang-nodes/ModifierAttribute.js +++ b/src/slang-nodes/ModifierAttribute.js @@ -1,6 +1,5 @@ export const ModifierAttribute = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/ModifierAttributes.js b/src/slang-nodes/ModifierAttributes.js index 05ec78c70..26d9bd7e1 100644 --- a/src/slang-nodes/ModifierAttributes.js +++ b/src/slang-nodes/ModifierAttributes.js @@ -3,8 +3,7 @@ import { doc } from 'prettier'; const { line } = doc.builders; export const ModifierAttributes = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ path, print }) => diff --git a/src/slang-nodes/ModifierDefinition.js b/src/slang-nodes/ModifierDefinition.js index 4bccd128d..0debe44c5 100644 --- a/src/slang-nodes/ModifierDefinition.js +++ b/src/slang-nodes/ModifierDefinition.js @@ -1,8 +1,7 @@ import { printFunction } from '../common/slang-helpers.js'; export const ModifierDefinition = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ modifierKeyword: ast.modifierKeyword.text, name: ast.name.text, parameters: ast.parameters diff --git a/src/slang-nodes/ModifierInvocation.js b/src/slang-nodes/ModifierInvocation.js index 67d5f6a2b..2a90291f0 100644 --- a/src/slang-nodes/ModifierInvocation.js +++ b/src/slang-nodes/ModifierInvocation.js @@ -1,6 +1,5 @@ export const ModifierInvocation = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ name: parse(ast.name, options, parse, offsets), arguments: ast.arguments ? parse(ast.arguments, options, parse, offsets) diff --git a/src/slang-nodes/MultiplicativeExpression.js b/src/slang-nodes/MultiplicativeExpression.js index 24e239758..19d67e086 100644 --- a/src/slang-nodes/MultiplicativeExpression.js +++ b/src/slang-nodes/MultiplicativeExpression.js @@ -1,30 +1,32 @@ -import { binaryOperationPrint, tryHug } from '../common/slang-helpers.js'; +import { + binaryOperationPrint, + createHugFunction +} from '../common/slang-helpers.js'; -const multiplicationHuggableOperators = new Set(['/', '%']); -const divisionHuggableOperators = new Set(['*', '%']); -const moduloHuggableOperators = new Set(['*', '/', '%']); +const multiplicationTryToHug = createHugFunction(['/', '%']); +const divisionTryToHug = createHugFunction(['*', '%']); +const moduloTryToHug = createHugFunction(['*', '/', '%']); export const MultiplicativeExpression = { - parse: ({ node, offsets, ast, options, parse }) => { + parse: ({ offsets, ast, options, parse }) => { let leftOperand = parse(ast.leftOperand, options, parse, offsets); const operator = ast.operator.text; switch (operator) { case '*': - leftOperand = tryHug(leftOperand, multiplicationHuggableOperators); + leftOperand = multiplicationTryToHug(leftOperand); break; case '/': - leftOperand = tryHug(leftOperand, divisionHuggableOperators); + leftOperand = divisionTryToHug(leftOperand); break; case '%': - leftOperand = tryHug(leftOperand, moduloHuggableOperators); + leftOperand = moduloTryToHug(leftOperand); break; default: break; } return { - ...node, leftOperand, operator, rightOperand: parse(ast.rightOperand, options, parse, offsets) diff --git a/src/slang-nodes/NamedArgument.js b/src/slang-nodes/NamedArgument.js index f024ad39d..fa9cd6be4 100644 --- a/src/slang-nodes/NamedArgument.js +++ b/src/slang-nodes/NamedArgument.js @@ -1,6 +1,5 @@ export const NamedArgument = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ name: ast.name.text, colon: ast.colon.text, value: parse(ast.value, options, parse, offsets) diff --git a/src/slang-nodes/NamedArgumentGroup.js b/src/slang-nodes/NamedArgumentGroup.js index 2e1112a7c..e1f2770ae 100644 --- a/src/slang-nodes/NamedArgumentGroup.js +++ b/src/slang-nodes/NamedArgumentGroup.js @@ -1,6 +1,5 @@ export const NamedArgumentGroup = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ openBrace: ast.openBrace.text, arguments: parse(ast.arguments, options, parse, offsets), closeBrace: ast.closeBrace.text diff --git a/src/slang-nodes/NamedArguments.js b/src/slang-nodes/NamedArguments.js index 44225db54..ef5e7294a 100644 --- a/src/slang-nodes/NamedArguments.js +++ b/src/slang-nodes/NamedArguments.js @@ -1,8 +1,7 @@ import { printSeparatedList } from '../common/printer-helpers.js'; export const NamedArguments = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/NamedArgumentsDeclaration.js b/src/slang-nodes/NamedArgumentsDeclaration.js index 016cd126c..62bfe9177 100644 --- a/src/slang-nodes/NamedArgumentsDeclaration.js +++ b/src/slang-nodes/NamedArgumentsDeclaration.js @@ -1,6 +1,5 @@ export const NamedArgumentsDeclaration = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ openParen: ast.openParen.text, arguments: ast.arguments ? parse(ast.arguments, options, parse, offsets) diff --git a/src/slang-nodes/NamedImport.js b/src/slang-nodes/NamedImport.js index bbc7295fe..9e27dc34a 100644 --- a/src/slang-nodes/NamedImport.js +++ b/src/slang-nodes/NamedImport.js @@ -1,6 +1,5 @@ export const NamedImport = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ asterisk: ast.asterisk.text, alias: parse(ast.alias, options, parse, offsets), fromKeyword: ast.fromKeyword.text, diff --git a/src/slang-nodes/NewExpression.js b/src/slang-nodes/NewExpression.js index ec1498340..a88dd6473 100644 --- a/src/slang-nodes/NewExpression.js +++ b/src/slang-nodes/NewExpression.js @@ -1,6 +1,5 @@ export const NewExpression = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ newKeyword: ast.newKeyword.text, typeName: parse(ast.typeName, options, parse, offsets) }), diff --git a/src/slang-nodes/NumberUnit.js b/src/slang-nodes/NumberUnit.js index 6cff6561a..7b57c2db0 100644 --- a/src/slang-nodes/NumberUnit.js +++ b/src/slang-nodes/NumberUnit.js @@ -1,6 +1,5 @@ export const NumberUnit = { - parse: ({ node, ast }) => ({ - ...node, + parse: ({ ast }) => ({ variant: ast.variant.text }), print: ({ node }) => node.variant diff --git a/src/slang-nodes/OrExpression.js b/src/slang-nodes/OrExpression.js index 7e0703a2f..a3e7cb317 100644 --- a/src/slang-nodes/OrExpression.js +++ b/src/slang-nodes/OrExpression.js @@ -1,19 +1,15 @@ -import { logicalOperationPrint, tryHug } from '../common/slang-helpers.js'; +import { + logicalOperationPrint, + createHugFunction +} from '../common/slang-helpers.js'; -const huggableOperators = new Set(['&&']); +const tryToHug = createHugFunction(['&&']); export const OrExpression = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, - leftOperand: tryHug( - parse(ast.leftOperand, options, parse, offsets), - huggableOperators - ), + parse: ({ offsets, ast, options, parse }) => ({ + leftOperand: tryToHug(parse(ast.leftOperand, options, parse, offsets)), operator: ast.operator.text, - rightOperand: tryHug( - parse(ast.rightOperand, options, parse, offsets), - huggableOperators - ) + rightOperand: tryToHug(parse(ast.rightOperand, options, parse, offsets)) }), print: logicalOperationPrint }; diff --git a/src/slang-nodes/OverridePaths.js b/src/slang-nodes/OverridePaths.js index aafd2d4f9..e5aa2a4f8 100644 --- a/src/slang-nodes/OverridePaths.js +++ b/src/slang-nodes/OverridePaths.js @@ -1,6 +1,5 @@ export const OverridePaths = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator) }), diff --git a/src/slang-nodes/OverridePathsDeclaration.js b/src/slang-nodes/OverridePathsDeclaration.js index 1b18084b0..d10e018a1 100644 --- a/src/slang-nodes/OverridePathsDeclaration.js +++ b/src/slang-nodes/OverridePathsDeclaration.js @@ -1,6 +1,5 @@ export const OverridePathsDeclaration = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ openParen: ast.openParen.text, paths: parse(ast.paths, options, parse, offsets), closeParen: ast.closeParen.text diff --git a/src/slang-nodes/OverrideSpecifier.js b/src/slang-nodes/OverrideSpecifier.js index ea4c55a3f..8162267e7 100644 --- a/src/slang-nodes/OverrideSpecifier.js +++ b/src/slang-nodes/OverrideSpecifier.js @@ -1,6 +1,5 @@ export const OverrideSpecifier = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ overrideKeyword: ast.overrideKeyword.text, overridden: ast.overridden ? parse(ast.overridden, options, parse, offsets) diff --git a/src/slang-nodes/Parameter.js b/src/slang-nodes/Parameter.js index bb04a4763..1df3111d9 100644 --- a/src/slang-nodes/Parameter.js +++ b/src/slang-nodes/Parameter.js @@ -1,6 +1,5 @@ export const Parameter = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ typeName: parse(ast.typeName, options, parse, offsets), storageLocation: ast.storageLocation ? parse(ast.storageLocation, options, parse, offsets) diff --git a/src/slang-nodes/Parameters.js b/src/slang-nodes/Parameters.js index 51c1e763f..23c23ea8e 100644 --- a/src/slang-nodes/Parameters.js +++ b/src/slang-nodes/Parameters.js @@ -1,8 +1,7 @@ import { printSeparatedList } from '../common/printer-helpers.js'; export const Parameters = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/ParametersDeclaration.js b/src/slang-nodes/ParametersDeclaration.js index 83c7f8208..fa070f72c 100644 --- a/src/slang-nodes/ParametersDeclaration.js +++ b/src/slang-nodes/ParametersDeclaration.js @@ -1,6 +1,5 @@ export const ParametersDeclaration = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ openParen: ast.openParen.text, parameters: parse(ast.parameters, options, parse, offsets), closeParen: ast.closeParen.text diff --git a/src/slang-nodes/PathImport.js b/src/slang-nodes/PathImport.js index dfdebac97..ca781af99 100644 --- a/src/slang-nodes/PathImport.js +++ b/src/slang-nodes/PathImport.js @@ -1,6 +1,5 @@ export const PathImport = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ path: parse(ast.path, options, parse, offsets), alias: ast.alias ? parse(ast.alias, options, parse, offsets) : undefined }), diff --git a/src/slang-nodes/PositionalArguments.js b/src/slang-nodes/PositionalArguments.js index 581e1f2fa..f4ff4b2cd 100644 --- a/src/slang-nodes/PositionalArguments.js +++ b/src/slang-nodes/PositionalArguments.js @@ -1,8 +1,7 @@ import { printSeparatedList } from '../common/printer-helpers.js'; export const PositionalArguments = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/PositionalArgumentsDeclaration.js b/src/slang-nodes/PositionalArgumentsDeclaration.js index 7f38b43b5..24f0cfeb6 100644 --- a/src/slang-nodes/PositionalArgumentsDeclaration.js +++ b/src/slang-nodes/PositionalArgumentsDeclaration.js @@ -1,6 +1,5 @@ export const PositionalArgumentsDeclaration = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ openParen: ast.openParen.text, arguments: parse(ast.arguments, options, parse, offsets), closeParen: ast.closeParen.text diff --git a/src/slang-nodes/PostfixExpression.js b/src/slang-nodes/PostfixExpression.js index a97fa975a..6d4202e2a 100644 --- a/src/slang-nodes/PostfixExpression.js +++ b/src/slang-nodes/PostfixExpression.js @@ -1,6 +1,5 @@ export const PostfixExpression = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ operand: parse(ast.operand, options, parse, offsets), operator: ast.operator.text }), diff --git a/src/slang-nodes/Pragma.js b/src/slang-nodes/Pragma.js index f27429b5f..4dd057d81 100644 --- a/src/slang-nodes/Pragma.js +++ b/src/slang-nodes/Pragma.js @@ -1,6 +1,5 @@ export const Pragma = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ variant: parse(ast.variant, options, parse, offsets) }), print: ({ path, print }) => path.call(print, 'variant') diff --git a/src/slang-nodes/PragmaDirective.js b/src/slang-nodes/PragmaDirective.js index 861c18e80..35e81b3f2 100644 --- a/src/slang-nodes/PragmaDirective.js +++ b/src/slang-nodes/PragmaDirective.js @@ -1,6 +1,5 @@ export const PragmaDirective = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ pragmaKeyword: ast.pragmaKeyword.text, pragma: parse(ast.pragma, options, parse, offsets), semicolon: ast.semicolon.text diff --git a/src/slang-nodes/PrefixExpression.js b/src/slang-nodes/PrefixExpression.js index 3404d6adf..435c78f42 100644 --- a/src/slang-nodes/PrefixExpression.js +++ b/src/slang-nodes/PrefixExpression.js @@ -1,6 +1,5 @@ export const PrefixExpression = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ operator: ast.operator.text, operand: parse(ast.operand, options, parse, offsets) }), diff --git a/src/slang-nodes/ReceiveFunctionAttribute.js b/src/slang-nodes/ReceiveFunctionAttribute.js index 9fe335c25..061fa8bb7 100644 --- a/src/slang-nodes/ReceiveFunctionAttribute.js +++ b/src/slang-nodes/ReceiveFunctionAttribute.js @@ -1,6 +1,5 @@ export const ReceiveFunctionAttribute = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/ReceiveFunctionAttributes.js b/src/slang-nodes/ReceiveFunctionAttributes.js index 6bf94ef76..2264d9f37 100644 --- a/src/slang-nodes/ReceiveFunctionAttributes.js +++ b/src/slang-nodes/ReceiveFunctionAttributes.js @@ -3,8 +3,7 @@ import { doc } from 'prettier'; const { line } = doc.builders; export const ReceiveFunctionAttributes = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ path, print }) => diff --git a/src/slang-nodes/ReceiveFunctionDefinition.js b/src/slang-nodes/ReceiveFunctionDefinition.js index d07aa1477..009f8b137 100644 --- a/src/slang-nodes/ReceiveFunctionDefinition.js +++ b/src/slang-nodes/ReceiveFunctionDefinition.js @@ -1,8 +1,7 @@ import { printFunction } from '../common/slang-helpers.js'; export const ReceiveFunctionDefinition = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ receiveKeyword: ast.receiveKeyword.text, parameters: parse(ast.parameters, options, parse, offsets), attributes: parse(ast.attributes, options, parse, offsets), diff --git a/src/slang-nodes/ReturnStatement.js b/src/slang-nodes/ReturnStatement.js index 2e82e105c..d1d4930dc 100644 --- a/src/slang-nodes/ReturnStatement.js +++ b/src/slang-nodes/ReturnStatement.js @@ -1,6 +1,5 @@ export const ReturnStatement = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ returnKeyword: ast.returnKeyword.text, expression: ast.expression ? parse(ast.expression, options, parse, offsets) diff --git a/src/slang-nodes/ReturnsDeclaration.js b/src/slang-nodes/ReturnsDeclaration.js index 92e876a46..d922d4e51 100644 --- a/src/slang-nodes/ReturnsDeclaration.js +++ b/src/slang-nodes/ReturnsDeclaration.js @@ -1,6 +1,5 @@ export const ReturnsDeclaration = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ returnsKeyword: ast.returnsKeyword.text, variables: parse(ast.variables, options, parse, offsets) }), diff --git a/src/slang-nodes/RevertStatement.js b/src/slang-nodes/RevertStatement.js index d74c69bdc..e8677fe3e 100644 --- a/src/slang-nodes/RevertStatement.js +++ b/src/slang-nodes/RevertStatement.js @@ -1,6 +1,5 @@ export const RevertStatement = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ revertKeyword: ast.revertKeyword.text, error: ast.error ? parse(ast.error, options, parse, offsets) : undefined, arguments: parse(ast.arguments, options, parse, offsets), diff --git a/src/slang-nodes/ShiftExpression.js b/src/slang-nodes/ShiftExpression.js index cb2f34c93..49beb3362 100644 --- a/src/slang-nodes/ShiftExpression.js +++ b/src/slang-nodes/ShiftExpression.js @@ -1,6 +1,9 @@ -import { binaryOperationPrint, tryHug } from '../common/slang-helpers.js'; +import { + binaryOperationPrint, + createHugFunction +} from '../common/slang-helpers.js'; -const leftOperandHuggableOperators = new Set([ +const tryToHugLeftOperand = createHugFunction([ '+', '-', '*', @@ -9,19 +12,16 @@ const leftOperandHuggableOperators = new Set([ '<<', '>>' ]); -const rightOperandHuggableOperators = new Set(['+', '-', '*', '/', '**']); +const tryToHugRightOperand = createHugFunction(['+', '-', '*', '/', '**']); export const ShiftExpression = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, - leftOperand: tryHug( - parse(ast.leftOperand, options, parse, offsets), - leftOperandHuggableOperators + parse: ({ offsets, ast, options, parse }) => ({ + leftOperand: tryToHugLeftOperand( + parse(ast.leftOperand, options, parse, offsets) ), operator: ast.operator.text, - rightOperand: tryHug( - parse(ast.rightOperand, options, parse, offsets), - rightOperandHuggableOperators + rightOperand: tryToHugRightOperand( + parse(ast.rightOperand, options, parse, offsets) ) }), print: binaryOperationPrint diff --git a/src/slang-nodes/SourceUnit.js b/src/slang-nodes/SourceUnit.js index 188449a2e..5564aa668 100644 --- a/src/slang-nodes/SourceUnit.js +++ b/src/slang-nodes/SourceUnit.js @@ -3,8 +3,7 @@ import { doc } from 'prettier'; const { line } = doc.builders; export const SourceUnit = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ members: parse(ast.members, options, parse, offsets) }), print: ({ options, path, print }) => [ diff --git a/src/slang-nodes/SourceUnitMember.js b/src/slang-nodes/SourceUnitMember.js index ea278d14f..6fc6afa65 100644 --- a/src/slang-nodes/SourceUnitMember.js +++ b/src/slang-nodes/SourceUnitMember.js @@ -1,6 +1,5 @@ export const SourceUnitMember = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ variant: parse(ast.variant, options, parse, offsets) }), print: ({ path, print }) => path.call(print, 'variant') diff --git a/src/slang-nodes/SourceUnitMembers.js b/src/slang-nodes/SourceUnitMembers.js index ceda58978..a66df95f7 100644 --- a/src/slang-nodes/SourceUnitMembers.js +++ b/src/slang-nodes/SourceUnitMembers.js @@ -1,8 +1,7 @@ import { printPreservingEmptyLines } from '../common/slang-helpers.js'; export const SourceUnitMembers = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ path, options, print }) => diff --git a/src/slang-nodes/StateVariableAttribute.js b/src/slang-nodes/StateVariableAttribute.js index 347a5ddf1..d09c6e1ac 100644 --- a/src/slang-nodes/StateVariableAttribute.js +++ b/src/slang-nodes/StateVariableAttribute.js @@ -1,6 +1,5 @@ export const StateVariableAttribute = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/StateVariableAttributes.js b/src/slang-nodes/StateVariableAttributes.js index ed758daab..6520f31d5 100644 --- a/src/slang-nodes/StateVariableAttributes.js +++ b/src/slang-nodes/StateVariableAttributes.js @@ -1,6 +1,5 @@ export const StateVariableAttributes = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ node, path, print }) => diff --git a/src/slang-nodes/StateVariableDefinition.js b/src/slang-nodes/StateVariableDefinition.js index b6805059e..2c42598de 100644 --- a/src/slang-nodes/StateVariableDefinition.js +++ b/src/slang-nodes/StateVariableDefinition.js @@ -1,6 +1,5 @@ export const StateVariableDefinition = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ typeName: parse(ast.typeName, options, parse, offsets), attributes: parse(ast.attributes, options, parse, offsets), name: ast.name.text, diff --git a/src/slang-nodes/StateVariableDefinitionValue.js b/src/slang-nodes/StateVariableDefinitionValue.js index 5d652af35..53197daea 100644 --- a/src/slang-nodes/StateVariableDefinitionValue.js +++ b/src/slang-nodes/StateVariableDefinitionValue.js @@ -3,8 +3,7 @@ import { doc } from 'prettier'; const { group, indent, line } = doc.builders; export const StateVariableDefinitionValue = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ equal: ast.equal.text, value: parse(ast.value, options, parse, offsets) }), diff --git a/src/slang-nodes/Statement.js b/src/slang-nodes/Statement.js index de95d1bd7..837527df7 100644 --- a/src/slang-nodes/Statement.js +++ b/src/slang-nodes/Statement.js @@ -1,6 +1,5 @@ export const Statement = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ variant: parse(ast.variant, options, parse, offsets) }), print: ({ path, print }) => path.call(print, 'variant') diff --git a/src/slang-nodes/Statements.js b/src/slang-nodes/Statements.js index 8c9274841..f2ccd8a43 100644 --- a/src/slang-nodes/Statements.js +++ b/src/slang-nodes/Statements.js @@ -5,8 +5,7 @@ import { printPreservingEmptyLines } from '../common/slang-helpers.js'; const { hardline } = doc.builders; export const Statements = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ node, path, options, print }) => diff --git a/src/slang-nodes/StorageLocation.js b/src/slang-nodes/StorageLocation.js index aa4c8b079..1f7e90481 100644 --- a/src/slang-nodes/StorageLocation.js +++ b/src/slang-nodes/StorageLocation.js @@ -1,6 +1,5 @@ export const StorageLocation = { - parse: ({ node, ast }) => ({ - ...node, + parse: ({ ast }) => ({ variant: ast.variant.text }), print: ({ node }) => node.variant diff --git a/src/slang-nodes/StringExpression.js b/src/slang-nodes/StringExpression.js index 2113db25f..73bb4023b 100644 --- a/src/slang-nodes/StringExpression.js +++ b/src/slang-nodes/StringExpression.js @@ -1,6 +1,5 @@ export const StringExpression = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ variant: parse(ast.variant, options, parse, offsets) }), print: ({ path, print }) => path.call(print, 'variant') diff --git a/src/slang-nodes/StringLiteral.js b/src/slang-nodes/StringLiteral.js index ef0a08fe3..ddd8896fd 100644 --- a/src/slang-nodes/StringLiteral.js +++ b/src/slang-nodes/StringLiteral.js @@ -1,8 +1,7 @@ import { printString } from '../common/util.js'; export const StringLiteral = { - parse: ({ node, ast, options }) => ({ - ...node, + parse: ({ ast, options }) => ({ variant: printString(ast.variant.text.slice(1, -1), options) }), print: ({ node }) => node.variant diff --git a/src/slang-nodes/StringLiterals.js b/src/slang-nodes/StringLiterals.js index 389e6589a..df6ec7ea1 100644 --- a/src/slang-nodes/StringLiterals.js +++ b/src/slang-nodes/StringLiterals.js @@ -3,8 +3,7 @@ import { doc } from 'prettier'; const { join, hardline } = doc.builders; export const StringLiterals = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ path, print }) => join(hardline, path.map(print, 'items')) diff --git a/src/slang-nodes/StructDefinition.js b/src/slang-nodes/StructDefinition.js index e3aff6dc2..04a0f5950 100644 --- a/src/slang-nodes/StructDefinition.js +++ b/src/slang-nodes/StructDefinition.js @@ -1,6 +1,5 @@ export const StructDefinition = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ structKeyword: ast.structKeyword.text, name: ast.name.text, openBrace: ast.openBrace.text, diff --git a/src/slang-nodes/StructMember.js b/src/slang-nodes/StructMember.js index bf7563d4e..09c6a576e 100644 --- a/src/slang-nodes/StructMember.js +++ b/src/slang-nodes/StructMember.js @@ -1,6 +1,5 @@ export const StructMember = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ typeName: parse(ast.typeName, options, parse, offsets), name: ast.name.text, semicolon: ast.semicolon.text diff --git a/src/slang-nodes/StructMembers.js b/src/slang-nodes/StructMembers.js index 3da9f18ba..233e1f3f1 100644 --- a/src/slang-nodes/StructMembers.js +++ b/src/slang-nodes/StructMembers.js @@ -4,8 +4,7 @@ import { printSeparatedList } from '../common/printer-helpers.js'; const { hardline } = doc.builders; export const StructMembers = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ node, path, print }) => diff --git a/src/slang-nodes/ThrowStatement.js b/src/slang-nodes/ThrowStatement.js index ef06be154..e414091fd 100644 --- a/src/slang-nodes/ThrowStatement.js +++ b/src/slang-nodes/ThrowStatement.js @@ -1,6 +1,5 @@ export const ThrowStatement = { - parse: ({ node, ast }) => ({ - ...node, + parse: ({ ast }) => ({ throwKeyword: ast.throwKeyword.text, semicolon: ast.semicolon.text }), diff --git a/src/slang-nodes/TryStatement.js b/src/slang-nodes/TryStatement.js index 4c88fdf25..1a7b14c52 100644 --- a/src/slang-nodes/TryStatement.js +++ b/src/slang-nodes/TryStatement.js @@ -4,8 +4,7 @@ import { printSeparatedItem } from '../common/printer-helpers.js'; const { line } = doc.builders; export const TryStatement = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ tryKeyword: ast.tryKeyword.text, expression: parse(ast.expression, options, parse, offsets), returns: ast.returns diff --git a/src/slang-nodes/TupleDeconstructionElement.js b/src/slang-nodes/TupleDeconstructionElement.js index 408fbfebd..8c4d10d3a 100644 --- a/src/slang-nodes/TupleDeconstructionElement.js +++ b/src/slang-nodes/TupleDeconstructionElement.js @@ -1,6 +1,5 @@ export const TupleDeconstructionElement = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ member: ast.member ? parse(ast.member, options, parse, offsets) : undefined }), print: ({ node, path, print }) => diff --git a/src/slang-nodes/TupleDeconstructionElements.js b/src/slang-nodes/TupleDeconstructionElements.js index 72f2109bf..f6e3a2b3c 100644 --- a/src/slang-nodes/TupleDeconstructionElements.js +++ b/src/slang-nodes/TupleDeconstructionElements.js @@ -1,8 +1,7 @@ import { printSeparatedList } from '../common/printer-helpers.js'; export const TupleDeconstructionElements = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/TupleDeconstructionStatement.js b/src/slang-nodes/TupleDeconstructionStatement.js index 8502a3bc6..5f499cd1a 100644 --- a/src/slang-nodes/TupleDeconstructionStatement.js +++ b/src/slang-nodes/TupleDeconstructionStatement.js @@ -3,8 +3,7 @@ import { doc } from 'prettier'; const { group, indent, line } = doc.builders; export const TupleDeconstructionStatement = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ varKeyword: ast.varKeyword?.text, openParen: ast.openParen.text, elements: parse(ast.elements, options, parse, offsets), diff --git a/src/slang-nodes/TupleExpression.js b/src/slang-nodes/TupleExpression.js index fc0b38882..98c506815 100644 --- a/src/slang-nodes/TupleExpression.js +++ b/src/slang-nodes/TupleExpression.js @@ -1,6 +1,5 @@ export const TupleExpression = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ openParen: ast.openParen.text, items: parse(ast.items, options, parse, offsets), closeParen: ast.closeParen.text diff --git a/src/slang-nodes/TupleMember.js b/src/slang-nodes/TupleMember.js index ec821ba1f..2d29904f8 100644 --- a/src/slang-nodes/TupleMember.js +++ b/src/slang-nodes/TupleMember.js @@ -1,6 +1,5 @@ export const TupleMember = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ variant: parse(ast.variant, options, parse, offsets) }), print: ({ path, print }) => path.call(print, 'variant') diff --git a/src/slang-nodes/TupleValue.js b/src/slang-nodes/TupleValue.js index d77c04ca0..b8afab681 100644 --- a/src/slang-nodes/TupleValue.js +++ b/src/slang-nodes/TupleValue.js @@ -1,6 +1,5 @@ export const TupleValue = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ expression: ast.expression ? parse(ast.expression, options, parse, offsets) : undefined diff --git a/src/slang-nodes/TupleValues.js b/src/slang-nodes/TupleValues.js index ff5d7e141..db23d2fbc 100644 --- a/src/slang-nodes/TupleValues.js +++ b/src/slang-nodes/TupleValues.js @@ -1,8 +1,7 @@ import { printSeparatedList } from '../common/printer-helpers.js'; export const TupleValues = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/TypeExpression.js b/src/slang-nodes/TypeExpression.js index 651f09c73..5216d4e5c 100644 --- a/src/slang-nodes/TypeExpression.js +++ b/src/slang-nodes/TypeExpression.js @@ -1,6 +1,5 @@ export const TypeExpression = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ typeKeyword: ast.typeKeyword.text, openParen: ast.openParen.text, typeName: parse(ast.typeName, options, parse, offsets), diff --git a/src/slang-nodes/TypeName.js b/src/slang-nodes/TypeName.js index b2003d610..9d767be73 100644 --- a/src/slang-nodes/TypeName.js +++ b/src/slang-nodes/TypeName.js @@ -1,6 +1,5 @@ export const TypeName = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ variant: parse(ast.variant, options, parse, offsets) }), print: ({ path, print }) => path.call(print, 'variant') diff --git a/src/slang-nodes/TypedTupleMember.js b/src/slang-nodes/TypedTupleMember.js index 0c0fa3222..9edac11e1 100644 --- a/src/slang-nodes/TypedTupleMember.js +++ b/src/slang-nodes/TypedTupleMember.js @@ -1,6 +1,5 @@ export const TypedTupleMember = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ typeName: parse(ast.typeName, options, parse, offsets), storageLocation: ast.storageLocation ? parse(ast.storageLocation, options, parse, offsets) diff --git a/src/slang-nodes/UncheckedBlock.js b/src/slang-nodes/UncheckedBlock.js index 675a346e6..3616d7d5f 100644 --- a/src/slang-nodes/UncheckedBlock.js +++ b/src/slang-nodes/UncheckedBlock.js @@ -1,6 +1,5 @@ export const UncheckedBlock = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ uncheckedKeyword: ast.uncheckedKeyword.text, block: parse(ast.block, options, parse, offsets) }), diff --git a/src/slang-nodes/UnicodeStringLiteral.js b/src/slang-nodes/UnicodeStringLiteral.js index 35fbb823f..6add29a29 100644 --- a/src/slang-nodes/UnicodeStringLiteral.js +++ b/src/slang-nodes/UnicodeStringLiteral.js @@ -1,8 +1,7 @@ import { printString } from '../common/util.js'; export const UnicodeStringLiteral = { - parse: ({ node, ast, options }) => ({ - ...node, + parse: ({ ast, options }) => ({ variant: `unicode${printString(ast.variant.text.slice(8, -1), options)}` }), print: ({ node }) => node.variant diff --git a/src/slang-nodes/UnicodeStringLiterals.js b/src/slang-nodes/UnicodeStringLiterals.js index 00b628d5e..9009d4d1e 100644 --- a/src/slang-nodes/UnicodeStringLiterals.js +++ b/src/slang-nodes/UnicodeStringLiterals.js @@ -3,8 +3,7 @@ import { doc } from 'prettier'; const { join, hardline } = doc.builders; export const UnicodeStringLiterals = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ path, print }) => join(hardline, path.map(print, 'items')) diff --git a/src/slang-nodes/UnnamedFunctionAttribute.js b/src/slang-nodes/UnnamedFunctionAttribute.js index 3dcb53f35..79f355cb7 100644 --- a/src/slang-nodes/UnnamedFunctionAttribute.js +++ b/src/slang-nodes/UnnamedFunctionAttribute.js @@ -1,6 +1,5 @@ export const UnnamedFunctionAttribute = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/UnnamedFunctionAttributes.js b/src/slang-nodes/UnnamedFunctionAttributes.js index 24d843c75..9ab8dc343 100644 --- a/src/slang-nodes/UnnamedFunctionAttributes.js +++ b/src/slang-nodes/UnnamedFunctionAttributes.js @@ -3,8 +3,7 @@ import { doc } from 'prettier'; const { line } = doc.builders; export const UnnamedFunctionAttributes = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ path, print }) => diff --git a/src/slang-nodes/UnnamedFunctionDefinition.js b/src/slang-nodes/UnnamedFunctionDefinition.js index a15695c4c..59d728690 100644 --- a/src/slang-nodes/UnnamedFunctionDefinition.js +++ b/src/slang-nodes/UnnamedFunctionDefinition.js @@ -1,8 +1,7 @@ import { printFunction } from '../common/slang-helpers.js'; export const UnnamedFunctionDefinition = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ functionKeyword: ast.functionKeyword.text, parameters: parse(ast.parameters, options, parse, offsets), attributes: parse(ast.attributes, options, parse, offsets), diff --git a/src/slang-nodes/UntypedTupleMember.js b/src/slang-nodes/UntypedTupleMember.js index cce88edb8..c4824b36a 100644 --- a/src/slang-nodes/UntypedTupleMember.js +++ b/src/slang-nodes/UntypedTupleMember.js @@ -1,6 +1,5 @@ export const UntypedTupleMember = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ storageLocation: ast.storageLocation ? parse(ast.storageLocation, options, parse, offsets) : undefined, diff --git a/src/slang-nodes/UserDefinedValueTypeDefinition.js b/src/slang-nodes/UserDefinedValueTypeDefinition.js index af9e63fc3..6d3d7a238 100644 --- a/src/slang-nodes/UserDefinedValueTypeDefinition.js +++ b/src/slang-nodes/UserDefinedValueTypeDefinition.js @@ -1,6 +1,5 @@ export const UserDefinedValueTypeDefinition = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ typeKeyword: ast.typeKeyword.text, name: ast.name.text, isKeyword: ast.isKeyword.text, diff --git a/src/slang-nodes/UsingAlias.js b/src/slang-nodes/UsingAlias.js index cbd0ec10d..0d7d1b682 100644 --- a/src/slang-nodes/UsingAlias.js +++ b/src/slang-nodes/UsingAlias.js @@ -1,6 +1,5 @@ export const UsingAlias = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ asKeyword: ast.asKeyword.text, operator: parse(ast.operator, options, parse, offsets) }), diff --git a/src/slang-nodes/UsingClause.js b/src/slang-nodes/UsingClause.js index 0850d716b..754b9cb90 100644 --- a/src/slang-nodes/UsingClause.js +++ b/src/slang-nodes/UsingClause.js @@ -1,6 +1,5 @@ export const UsingClause = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ variant: parse(ast.variant, options, parse, offsets) }), print: ({ path, print }) => path.call(print, 'variant') diff --git a/src/slang-nodes/UsingDeconstruction.js b/src/slang-nodes/UsingDeconstruction.js index 02920ef50..6be559b79 100644 --- a/src/slang-nodes/UsingDeconstruction.js +++ b/src/slang-nodes/UsingDeconstruction.js @@ -1,6 +1,5 @@ export const UsingDeconstruction = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ openBrace: ast.openBrace.text, symbols: parse(ast.symbols, options, parse, offsets), closeBrace: ast.closeBrace.text diff --git a/src/slang-nodes/UsingDeconstructionSymbol.js b/src/slang-nodes/UsingDeconstructionSymbol.js index 06ba41bed..7a658fc25 100644 --- a/src/slang-nodes/UsingDeconstructionSymbol.js +++ b/src/slang-nodes/UsingDeconstructionSymbol.js @@ -1,6 +1,5 @@ export const UsingDeconstructionSymbol = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ name: parse(ast.name, options, parse, offsets), alias: ast.alias ? parse(ast.alias, options, parse, offsets) : undefined }), diff --git a/src/slang-nodes/UsingDeconstructionSymbols.js b/src/slang-nodes/UsingDeconstructionSymbols.js index 62d13b931..9754883b9 100644 --- a/src/slang-nodes/UsingDeconstructionSymbols.js +++ b/src/slang-nodes/UsingDeconstructionSymbols.js @@ -4,8 +4,7 @@ import { printSeparatedList } from '../common/printer-helpers.js'; const { line, softline } = doc.builders; export const UsingDeconstructionSymbols = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/UsingDirective.js b/src/slang-nodes/UsingDirective.js index a2a3859ec..d4a591c26 100644 --- a/src/slang-nodes/UsingDirective.js +++ b/src/slang-nodes/UsingDirective.js @@ -1,6 +1,5 @@ export const UsingDirective = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ usingKeyword: ast.usingKeyword.text, clause: parse(ast.clause, options, parse, offsets), forKeyword: ast.forKeyword.text, diff --git a/src/slang-nodes/UsingOperator.js b/src/slang-nodes/UsingOperator.js index 8a02bab5c..3514cd39f 100644 --- a/src/slang-nodes/UsingOperator.js +++ b/src/slang-nodes/UsingOperator.js @@ -1,6 +1,5 @@ export const UsingOperator = { - parse: ({ node, ast }) => ({ - ...node, + parse: ({ ast }) => ({ variant: ast.variant.text }), print: ({ node }) => node.variant diff --git a/src/slang-nodes/UsingTarget.js b/src/slang-nodes/UsingTarget.js index 875cc698d..22eb7691f 100644 --- a/src/slang-nodes/UsingTarget.js +++ b/src/slang-nodes/UsingTarget.js @@ -1,6 +1,5 @@ export const UsingTarget = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/VariableDeclarationStatement.js b/src/slang-nodes/VariableDeclarationStatement.js index 8cf3a907d..6d0160fa2 100644 --- a/src/slang-nodes/VariableDeclarationStatement.js +++ b/src/slang-nodes/VariableDeclarationStatement.js @@ -1,6 +1,5 @@ export const VariableDeclarationStatement = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ variableType: parse(ast.variableType, options, parse, offsets), storageLocation: ast.storageLocation ? parse(ast.storageLocation, options, parse, offsets) diff --git a/src/slang-nodes/VariableDeclarationType.js b/src/slang-nodes/VariableDeclarationType.js index 3ca084e65..b13dfe6b7 100644 --- a/src/slang-nodes/VariableDeclarationType.js +++ b/src/slang-nodes/VariableDeclarationType.js @@ -1,6 +1,5 @@ export const VariableDeclarationType = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/VariableDeclarationValue.js b/src/slang-nodes/VariableDeclarationValue.js index 4012c4afe..f99d44d4b 100644 --- a/src/slang-nodes/VariableDeclarationValue.js +++ b/src/slang-nodes/VariableDeclarationValue.js @@ -1,6 +1,5 @@ export const VariableDeclarationValue = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ equal: ast.equal.text, expression: parse(ast.expression, options, parse, offsets) }), diff --git a/src/slang-nodes/VersionComparator.js b/src/slang-nodes/VersionComparator.js index 4504a840f..1a1b8b599 100644 --- a/src/slang-nodes/VersionComparator.js +++ b/src/slang-nodes/VersionComparator.js @@ -1,6 +1,5 @@ export const VersionComparator = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ operator: ast.operator.text, operand: parse(ast.operand, options, parse, offsets) }), diff --git a/src/slang-nodes/VersionExpression.js b/src/slang-nodes/VersionExpression.js index 6f74a4ab5..bb5fae09e 100644 --- a/src/slang-nodes/VersionExpression.js +++ b/src/slang-nodes/VersionExpression.js @@ -1,6 +1,5 @@ export const VersionExpression = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/VersionExpressionSet.js b/src/slang-nodes/VersionExpressionSet.js index 30b66d182..6c65c0586 100644 --- a/src/slang-nodes/VersionExpressionSet.js +++ b/src/slang-nodes/VersionExpressionSet.js @@ -3,8 +3,7 @@ import { doc } from 'prettier'; const { join } = doc.builders; export const VersionExpressionSet = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ path, print }) => join(' ', path.map(print, 'items')) diff --git a/src/slang-nodes/VersionExpressionSets.js b/src/slang-nodes/VersionExpressionSets.js index 542fd6016..7a75077df 100644 --- a/src/slang-nodes/VersionExpressionSets.js +++ b/src/slang-nodes/VersionExpressionSets.js @@ -1,6 +1,5 @@ export const VersionExpressionSets = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/VersionPragma.js b/src/slang-nodes/VersionPragma.js index a440247fd..daedaf415 100644 --- a/src/slang-nodes/VersionPragma.js +++ b/src/slang-nodes/VersionPragma.js @@ -1,6 +1,5 @@ export const VersionPragma = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ solidityKeyword: ast.solidityKeyword.text, sets: parse(ast.sets, options, parse, offsets) }), diff --git a/src/slang-nodes/VersionRange.js b/src/slang-nodes/VersionRange.js index 50e913465..e846b9e84 100644 --- a/src/slang-nodes/VersionRange.js +++ b/src/slang-nodes/VersionRange.js @@ -1,6 +1,5 @@ export const VersionRange = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ leftOperand: parse(ast.leftOperand, options, parse, offsets), operator: ast.operator.text, rightOperand: parse(ast.rightOperand, options, parse, offsets) diff --git a/src/slang-nodes/VersionSpecifiers.js b/src/slang-nodes/VersionSpecifiers.js index 90053d7e6..e08e48a0e 100644 --- a/src/slang-nodes/VersionSpecifiers.js +++ b/src/slang-nodes/VersionSpecifiers.js @@ -1,6 +1,5 @@ export const VersionSpecifiers = { - parse: ({ node, ast }) => ({ - ...node, + parse: ({ ast }) => ({ items: ast.items.map((item) => item.text), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/WhileStatement.js b/src/slang-nodes/WhileStatement.js index a213f0ece..a1cd49420 100644 --- a/src/slang-nodes/WhileStatement.js +++ b/src/slang-nodes/WhileStatement.js @@ -1,6 +1,5 @@ export const WhileStatement = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ whileKeyword: ast.whileKeyword.text, openParen: ast.openParen.text, condition: parse(ast.condition, options, parse, offsets), diff --git a/src/slang-nodes/YulArguments.js b/src/slang-nodes/YulArguments.js index 2315f4850..8eedba833 100644 --- a/src/slang-nodes/YulArguments.js +++ b/src/slang-nodes/YulArguments.js @@ -1,6 +1,5 @@ export const YulArguments = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/YulAssignmentOperator.js b/src/slang-nodes/YulAssignmentOperator.js index 41384807e..66d0f7e1c 100644 --- a/src/slang-nodes/YulAssignmentOperator.js +++ b/src/slang-nodes/YulAssignmentOperator.js @@ -1,6 +1,5 @@ export const YulAssignmentOperator = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/YulAssignmentStatement.js b/src/slang-nodes/YulAssignmentStatement.js index 394674c65..04dbc7d2d 100644 --- a/src/slang-nodes/YulAssignmentStatement.js +++ b/src/slang-nodes/YulAssignmentStatement.js @@ -1,6 +1,5 @@ export const YulAssignmentStatement = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ names: parse(ast.names, options, parse, offsets), assignment: parse(ast.assignment, options, parse, offsets), expression: parse(ast.expression, options, parse, offsets) diff --git a/src/slang-nodes/YulBlock.js b/src/slang-nodes/YulBlock.js index 9cb844219..8e4aae9a9 100644 --- a/src/slang-nodes/YulBlock.js +++ b/src/slang-nodes/YulBlock.js @@ -4,8 +4,7 @@ import { printSeparatedItem } from '../common/printer-helpers.js'; const { hardline } = doc.builders; export const YulBlock = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ openBrace: ast.openBrace.text, statements: parse(ast.statements, options, parse, offsets), closeBrace: ast.closeBrace.text diff --git a/src/slang-nodes/YulBreakStatement.js b/src/slang-nodes/YulBreakStatement.js index f18e22db3..4062e1a00 100644 --- a/src/slang-nodes/YulBreakStatement.js +++ b/src/slang-nodes/YulBreakStatement.js @@ -1,6 +1,5 @@ export const YulBreakStatement = { - parse: ({ node, ast }) => ({ - ...node, + parse: ({ ast }) => ({ breakKeyword: ast.breakKeyword.text }), print: ({ node }) => node.breakKeyword diff --git a/src/slang-nodes/YulBuiltInFunction.js b/src/slang-nodes/YulBuiltInFunction.js index 35396756a..ce31570da 100644 --- a/src/slang-nodes/YulBuiltInFunction.js +++ b/src/slang-nodes/YulBuiltInFunction.js @@ -1,6 +1,5 @@ export const YulBuiltInFunction = { - parse: ({ node, ast }) => ({ - ...node, + parse: ({ ast }) => ({ variant: ast.variant.text }), print: ({ node }) => node.variant diff --git a/src/slang-nodes/YulColonAndEqual.js b/src/slang-nodes/YulColonAndEqual.js index 839437b05..e9a02962a 100644 --- a/src/slang-nodes/YulColonAndEqual.js +++ b/src/slang-nodes/YulColonAndEqual.js @@ -1,6 +1,5 @@ export const YulColonAndEqual = { - parse: ({ node, ast }) => ({ - ...node, + parse: ({ ast }) => ({ colon: ast.colon.text, equal: ast.equal.text }), diff --git a/src/slang-nodes/YulContinueStatement.js b/src/slang-nodes/YulContinueStatement.js index 4249f030b..d70042ed8 100644 --- a/src/slang-nodes/YulContinueStatement.js +++ b/src/slang-nodes/YulContinueStatement.js @@ -1,6 +1,5 @@ export const YulContinueStatement = { - parse: ({ node, ast }) => ({ - ...node, + parse: ({ ast }) => ({ continueKeyword: ast.continueKeyword.text }), print: ({ node }) => node.continueKeyword diff --git a/src/slang-nodes/YulDefaultCase.js b/src/slang-nodes/YulDefaultCase.js index 613bcad07..28d47cc00 100644 --- a/src/slang-nodes/YulDefaultCase.js +++ b/src/slang-nodes/YulDefaultCase.js @@ -1,6 +1,5 @@ export const YulDefaultCase = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ defaultKeyword: ast.defaultKeyword.text, body: parse(ast.body, options, parse, offsets) }), diff --git a/src/slang-nodes/YulExpression.js b/src/slang-nodes/YulExpression.js index f65922494..a46f2af5f 100644 --- a/src/slang-nodes/YulExpression.js +++ b/src/slang-nodes/YulExpression.js @@ -1,6 +1,5 @@ export const YulExpression = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ variant: parse(ast.variant, options, parse, offsets) }), print: ({ path, print }) => path.call(print, 'variant') diff --git a/src/slang-nodes/YulForStatement.js b/src/slang-nodes/YulForStatement.js index 3b5f1854d..c488a2c51 100644 --- a/src/slang-nodes/YulForStatement.js +++ b/src/slang-nodes/YulForStatement.js @@ -1,6 +1,5 @@ export const YulForStatement = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ forKeyword: ast.forKeyword.text, initialization: parse(ast.initialization, options, parse, offsets), condition: parse(ast.condition, options, parse, offsets), diff --git a/src/slang-nodes/YulFunctionCallExpression.js b/src/slang-nodes/YulFunctionCallExpression.js index 0269d4de0..744d9ac17 100644 --- a/src/slang-nodes/YulFunctionCallExpression.js +++ b/src/slang-nodes/YulFunctionCallExpression.js @@ -1,6 +1,5 @@ export const YulFunctionCallExpression = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ operand: parse(ast.operand, options, parse, offsets), openParen: ast.openParen.text, arguments: parse(ast.arguments, options, parse, offsets), diff --git a/src/slang-nodes/YulFunctionDefinition.js b/src/slang-nodes/YulFunctionDefinition.js index 602ff2aa5..6698d3117 100644 --- a/src/slang-nodes/YulFunctionDefinition.js +++ b/src/slang-nodes/YulFunctionDefinition.js @@ -1,6 +1,5 @@ export const YulFunctionDefinition = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ functionKeyword: ast.functionKeyword.text, name: ast.name.text, parameters: parse(ast.parameters, options, parse, offsets), diff --git a/src/slang-nodes/YulIfStatement.js b/src/slang-nodes/YulIfStatement.js index 66a88ad3e..9263c2b9b 100644 --- a/src/slang-nodes/YulIfStatement.js +++ b/src/slang-nodes/YulIfStatement.js @@ -1,6 +1,5 @@ export const YulIfStatement = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ ifKeyword: ast.ifKeyword.text, condition: parse(ast.condition, options, parse, offsets), body: parse(ast.body, options, parse, offsets) diff --git a/src/slang-nodes/YulLabel.js b/src/slang-nodes/YulLabel.js index 60f3cfc8a..3a7f4ab0e 100644 --- a/src/slang-nodes/YulLabel.js +++ b/src/slang-nodes/YulLabel.js @@ -3,8 +3,7 @@ import { doc } from 'prettier'; const { dedent, line } = doc.builders; export const YulLabel = { - parse: ({ node, ast }) => ({ - ...node, + parse: ({ ast }) => ({ label: ast.label.text, colon: ast.colon.text }), diff --git a/src/slang-nodes/YulLeaveStatement.js b/src/slang-nodes/YulLeaveStatement.js index 6dab0ba6e..d014e23fe 100644 --- a/src/slang-nodes/YulLeaveStatement.js +++ b/src/slang-nodes/YulLeaveStatement.js @@ -1,6 +1,5 @@ export const YulLeaveStatement = { - parse: ({ node, ast }) => ({ - ...node, + parse: ({ ast }) => ({ leaveKeyword: ast.leaveKeyword.text }), // TODO: implement print diff --git a/src/slang-nodes/YulLiteral.js b/src/slang-nodes/YulLiteral.js index 89aac03ec..0a2064a4d 100644 --- a/src/slang-nodes/YulLiteral.js +++ b/src/slang-nodes/YulLiteral.js @@ -1,6 +1,5 @@ export const YulLiteral = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text diff --git a/src/slang-nodes/YulParameters.js b/src/slang-nodes/YulParameters.js index 24090d0f8..cdc084191 100644 --- a/src/slang-nodes/YulParameters.js +++ b/src/slang-nodes/YulParameters.js @@ -1,8 +1,7 @@ import { printSeparatedList } from '../common/printer-helpers.js'; export const YulParameters = { - parse: ({ node, ast }) => ({ - ...node, + parse: ({ ast }) => ({ items: ast.items.map((item) => item.text), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/YulParametersDeclaration.js b/src/slang-nodes/YulParametersDeclaration.js index edc74ad7a..1b2962fc0 100644 --- a/src/slang-nodes/YulParametersDeclaration.js +++ b/src/slang-nodes/YulParametersDeclaration.js @@ -1,6 +1,5 @@ export const YulParametersDeclaration = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ openParen: ast.openParen.text, parameters: parse(ast.parameters, options, parse, offsets), closeParen: ast.closeParen.text diff --git a/src/slang-nodes/YulPath.js b/src/slang-nodes/YulPath.js index eec4fef55..89d1f7239 100644 --- a/src/slang-nodes/YulPath.js +++ b/src/slang-nodes/YulPath.js @@ -1,6 +1,5 @@ export const YulPath = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/YulPathComponent.js b/src/slang-nodes/YulPathComponent.js index 05c59e794..411333dc8 100644 --- a/src/slang-nodes/YulPathComponent.js +++ b/src/slang-nodes/YulPathComponent.js @@ -1,6 +1,5 @@ export const YulPathComponent = { - parse: ({ node, ast }) => ({ - ...node, + parse: ({ ast }) => ({ variant: ast.variant.text }), print: ({ node }) => node.variant diff --git a/src/slang-nodes/YulPaths.js b/src/slang-nodes/YulPaths.js index 7bb7d60a8..7506d60fc 100644 --- a/src/slang-nodes/YulPaths.js +++ b/src/slang-nodes/YulPaths.js @@ -1,6 +1,5 @@ export const YulPaths = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/YulReturnVariables.js b/src/slang-nodes/YulReturnVariables.js index a99e8ff06..10093aa1a 100644 --- a/src/slang-nodes/YulReturnVariables.js +++ b/src/slang-nodes/YulReturnVariables.js @@ -4,8 +4,7 @@ import { printSeparatedList } from '../common/printer-helpers.js'; const { line } = doc.builders; export const YulReturnVariables = { - parse: ({ node, ast }) => ({ - ...node, + parse: ({ ast }) => ({ items: ast.items.map((item) => item.text), separators: ast.separators.map((separator) => separator.text) }), diff --git a/src/slang-nodes/YulReturnsDeclaration.js b/src/slang-nodes/YulReturnsDeclaration.js index 6e4906bd2..d51337b97 100644 --- a/src/slang-nodes/YulReturnsDeclaration.js +++ b/src/slang-nodes/YulReturnsDeclaration.js @@ -4,8 +4,7 @@ import { printSeparatedItem } from '../common/printer-helpers.js'; const { line } = doc.builders; export const YulReturnsDeclaration = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ minusGreaterThan: ast.minusGreaterThan.text, variables: parse(ast.variables, options, parse, offsets) }), diff --git a/src/slang-nodes/YulStatement.js b/src/slang-nodes/YulStatement.js index ef8163da0..294a19308 100644 --- a/src/slang-nodes/YulStatement.js +++ b/src/slang-nodes/YulStatement.js @@ -1,6 +1,5 @@ export const YulStatement = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ variant: parse(ast.variant, options, parse, offsets) }), print: ({ path, print }) => path.call(print, 'variant') diff --git a/src/slang-nodes/YulStatements.js b/src/slang-nodes/YulStatements.js index cfcf095e8..462cbb354 100644 --- a/src/slang-nodes/YulStatements.js +++ b/src/slang-nodes/YulStatements.js @@ -1,8 +1,7 @@ import { printPreservingEmptyLines } from '../common/slang-helpers.js'; export const YulStatements = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ path, print, options }) => diff --git a/src/slang-nodes/YulSwitchCase.js b/src/slang-nodes/YulSwitchCase.js index 8b9f4b41c..f97bd724c 100644 --- a/src/slang-nodes/YulSwitchCase.js +++ b/src/slang-nodes/YulSwitchCase.js @@ -1,6 +1,5 @@ export const YulSwitchCase = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ variant: parse(ast.variant, options, parse, offsets) }), print: ({ path, print }) => path.call(print, 'variant') diff --git a/src/slang-nodes/YulSwitchCases.js b/src/slang-nodes/YulSwitchCases.js index 4b7ce9eb2..af7c0865a 100644 --- a/src/slang-nodes/YulSwitchCases.js +++ b/src/slang-nodes/YulSwitchCases.js @@ -3,8 +3,7 @@ import { doc } from 'prettier'; const { hardline, join } = doc.builders; export const YulSwitchCases = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ path, print }) => join(hardline, path.map(print, 'items')) diff --git a/src/slang-nodes/YulSwitchStatement.js b/src/slang-nodes/YulSwitchStatement.js index 8c12440cd..ff8700a0b 100644 --- a/src/slang-nodes/YulSwitchStatement.js +++ b/src/slang-nodes/YulSwitchStatement.js @@ -3,8 +3,7 @@ import { doc } from 'prettier'; const { hardline } = doc.builders; export const YulSwitchStatement = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ switchKeyword: ast.switchKeyword.text, expression: parse(ast.expression, options, parse, offsets), cases: parse(ast.cases, options, parse, offsets) diff --git a/src/slang-nodes/YulValueCase.js b/src/slang-nodes/YulValueCase.js index cd866a8e5..6b4a27f40 100644 --- a/src/slang-nodes/YulValueCase.js +++ b/src/slang-nodes/YulValueCase.js @@ -1,6 +1,5 @@ export const YulValueCase = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ caseKeyword: ast.caseKeyword.text, value: parse(ast.value, options, parse, offsets), body: parse(ast.body, options, parse, offsets) diff --git a/src/slang-nodes/YulVariableAssignmentStatement.js b/src/slang-nodes/YulVariableAssignmentStatement.js index 7324fe37e..01f0dffc7 100644 --- a/src/slang-nodes/YulVariableAssignmentStatement.js +++ b/src/slang-nodes/YulVariableAssignmentStatement.js @@ -1,6 +1,5 @@ export const YulVariableAssignmentStatement = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ names: parse(ast.names, options, parse, offsets), assignment: parse(ast.assignment, options, parse, offsets), expression: parse(ast.expression, options, parse, offsets) diff --git a/src/slang-nodes/YulVariableDeclarationStatement.js b/src/slang-nodes/YulVariableDeclarationStatement.js index 51bec30c5..9cf5f12bd 100644 --- a/src/slang-nodes/YulVariableDeclarationStatement.js +++ b/src/slang-nodes/YulVariableDeclarationStatement.js @@ -1,6 +1,5 @@ export const YulVariableDeclarationStatement = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ letKeyword: ast.letKeyword.text, names: ast.names.text, value: ast.value ? parse(ast.value, options, parse, offsets) : undefined diff --git a/src/slang-nodes/YulVariableDeclarationValue.js b/src/slang-nodes/YulVariableDeclarationValue.js index c232566f7..b9634dac0 100644 --- a/src/slang-nodes/YulVariableDeclarationValue.js +++ b/src/slang-nodes/YulVariableDeclarationValue.js @@ -1,6 +1,5 @@ export const YulVariableDeclarationValue = { - parse: ({ node, offsets, ast, options, parse }) => ({ - ...node, + parse: ({ offsets, ast, options, parse }) => ({ assignment: parse(ast.assignment, options, parse, offsets), expression: parse(ast.expression, options, parse, offsets) }), diff --git a/src/slangCommentPrinter.js b/src/slangCommentPrinter.js new file mode 100644 index 000000000..8896c9bc7 --- /dev/null +++ b/src/slangCommentPrinter.js @@ -0,0 +1,57 @@ +import { doc } from 'prettier'; +import { isBlockComment, isLineComment } from './common/slang-helpers.js'; + +const { hardline, join, literalline } = doc.builders; + +function isIndentableBlockComment(comment) { + // If the comment has multiple lines and every line starts with a star + // we can fix the indentation of each line. The stars in the `/*` and + // `*/` delimiters are not included in the comment value, so add them + // back first. + const lines = comment.value.slice(1, -1).split('\n'); + return lines.length > 1 && lines.every((line) => line.trimStart()[0] === '*'); +} + +function printIndentableBlockComment(comment) { + const lines = comment.value.split('\n'); + + return join( + hardline, + lines.map((line, index) => + index === 0 + ? line.trimEnd() + : ` ${index < lines.length - 1 ? line.trim() : line.trimStart()}` + ) + ); +} + +export function printComment(commentPath) { + const comment = commentPath.node; + const { comments } = commentPath.getParentNode(); + + // TODO: Prettier creates duplicates, research why this happens + if ( + comments.some( + (c) => + c.printed && + c.loc.start === comment.loc.start && + c.loc.end === comment.loc.end + ) + ) { + return ''; + } + + if (isLineComment(comment)) { + return comment.value.trimEnd(); + } + + if (isBlockComment(comment)) { + if (isIndentableBlockComment(comment)) { + return printIndentableBlockComment(comment); + } + + return join(literalline, comment.value.split('\n')); + } + + throw new Error(`Not a comment: ${JSON.stringify(comment)}`); +} diff --git a/src/slangParser.js b/src/slangParser.js index a2a9d0a36..105b08a15 100644 --- a/src/slangParser.js +++ b/src/slangParser.js @@ -7,54 +7,51 @@ import coerce from 'semver/functions/coerce.js'; import * as parsers from './slang-nodes/index.js'; import { isComment } from './common/slang-helpers.js'; -const getCommentsAndOffsets = (ast, nodeOffset) => { - const children = ast.cst.children(); +const comments = []; +const getOffsets = (ast, nodeOffset) => { let offset = nodeOffset; - return children.reduce( - (commentsAndOffsets, child) => { - if (child.type === 'Nonterminal') { - commentsAndOffsets.offsets.push(offset); - } - if (child.type === 'Terminal' && isComment(child)) { - commentsAndOffsets.comments.push({ - kind: child.kind, - value: child.text, - loc: { - start: offset, - end: offset + child.textLength.utf8 - 1 - } - }); - } - offset += child.textLength.utf8; - return commentsAndOffsets; - }, - { comments: [], offsets: [] } - ); + + return ast.cst.children().reduce((offsetsArray, child) => { + if (child.type === 'Nonterminal') { + offsetsArray.push(offset); + } + if (child.type === 'Terminal' && isComment(child)) { + // TODO: avoid collecting comments as a side effect of the functionality + // for retrieving offsets + comments.push({ + kind: child.kind, + value: child.text, + loc: { + start: offset, + end: offset + child.textLength.utf8 + } + }); + } + + offset += child.textLength.utf8; + return offsetsArray; + }, []); }; function genericParse(ast, options, parseFunction, parentOffsets = [0]) { const offset = parentOffsets.shift(); - const { comments, offsets } = getCommentsAndOffsets(ast, offset); - // console.log(comments); - // console.log(offsets); + const offsets = getOffsets(ast, offset); - let node = { - kind: ast.cst.kind, - loc: { - start: offset, - end: offset + ast.cst.textLength.utf8 - 1 - } - // comments - }; - - node = parsers[ast.cst.kind].parse({ - node, + const node = parsers[ast.cst.kind].parse({ offsets, ast, options, parse: parseFunction }); + node.kind = ast.cst.kind; + node.loc = { + start: offset, + end: offset + ast.cst.textLength.utf8 + }; + + if (node.kind === 'SourceUnit') node.comments = comments; + return node; } From 1226a4a5fda549870bdee651d4a49c3cbca1dc4a Mon Sep 17 00:00:00 2001 From: Klaus Date: Thu, 27 Jun 2024 08:07:53 +1200 Subject: [PATCH 037/160] allocating leading comments before the node instead of at the beginning of it. --- src/slangCommentPrinter.js | 13 -------- src/slangParser.js | 63 +++++++++++++++++++++++++++----------- src/slangPrinter.js | 25 +++++++++++++++ 3 files changed, 70 insertions(+), 31 deletions(-) diff --git a/src/slangCommentPrinter.js b/src/slangCommentPrinter.js index 8896c9bc7..066546af3 100644 --- a/src/slangCommentPrinter.js +++ b/src/slangCommentPrinter.js @@ -27,19 +27,6 @@ function printIndentableBlockComment(comment) { export function printComment(commentPath) { const comment = commentPath.node; - const { comments } = commentPath.getParentNode(); - - // TODO: Prettier creates duplicates, research why this happens - if ( - comments.some( - (c) => - c.printed && - c.loc.start === comment.loc.start && - c.loc.end === comment.loc.end - ) - ) { - return ''; - } if (isLineComment(comment)) { return comment.value.trimEnd(); diff --git a/src/slangParser.js b/src/slangParser.js index 105b08a15..18a245814 100644 --- a/src/slangParser.js +++ b/src/slangParser.js @@ -8,34 +8,58 @@ import * as parsers from './slang-nodes/index.js'; import { isComment } from './common/slang-helpers.js'; const comments = []; -const getOffsets = (ast, nodeOffset) => { - let offset = nodeOffset; +const getOffsets = (ast, initialOffset) => { + let offset = initialOffset; + let isLeadingTrivia = true; + let currentOffset = offset; - return ast.cst.children().reduce((offsetsArray, child) => { + const offsets = ast.cst.children().reduce((offsetsArray, child) => { if (child.type === 'Nonterminal') { + // The node's content starts when we find the first non-terminal, + // non-comment, non-whitespace token. + if (isLeadingTrivia) { + isLeadingTrivia = false; + currentOffset = offset; + } + offsetsArray.push(offset); } - if (child.type === 'Terminal' && isComment(child)) { - // TODO: avoid collecting comments as a side effect of the functionality - // for retrieving offsets - comments.push({ - kind: child.kind, - value: child.text, - loc: { - start: offset, - end: offset + child.textLength.utf8 + if (child.type === 'Terminal') { + if (isComment(child)) { + // TODO: avoid collecting comments as a side effect of the functionality + // for retrieving offsets + comments.push({ + kind: child.kind, + value: child.text, + loc: { + start: offset, + end: offset + child.textLength.utf8 + } + }); + } + if ( + !isComment(child) && + child.kind !== 'EndOfLine' && + child.kind !== 'Whitespace' + ) { + // The content of the node started if we find a non-comment, + // non-whitespace token. + if (isLeadingTrivia) { + isLeadingTrivia = false; + currentOffset = offset; } - }); + } } offset += child.textLength.utf8; return offsetsArray; }, []); + return { currentOffset, offsets }; }; function genericParse(ast, options, parseFunction, parentOffsets = [0]) { - const offset = parentOffsets.shift(); - const offsets = getOffsets(ast, offset); + const initialOffset = parentOffsets.shift(); + const { currentOffset, offsets } = getOffsets(ast, initialOffset); const node = parsers[ast.cst.kind].parse({ offsets, @@ -46,11 +70,14 @@ function genericParse(ast, options, parseFunction, parentOffsets = [0]) { node.kind = ast.cst.kind; node.loc = { - start: offset, - end: offset + ast.cst.textLength.utf8 + // We ignore the leading trivia and assume the node starts after it + start: currentOffset, + end: initialOffset + ast.cst.textLength.utf8 }; - if (node.kind === 'SourceUnit') node.comments = comments; + if (node.kind === 'SourceUnit') { + node.comments = comments; + } return node; } diff --git a/src/slangPrinter.js b/src/slangPrinter.js index 62fe90d26..f85d1b8fc 100644 --- a/src/slangPrinter.js +++ b/src/slangPrinter.js @@ -30,6 +30,31 @@ function genericPrint(path, options, print) { throw new Error(`Unknown type: ${JSON.stringify(nodeType)}`); } + // For some reason, prettier is duplicating comments when attaching them. + // This just removes the duplicated comments + // TODO: research why is this happening and report it to the prettier team + // and remove this once it's fixed. + if (node.comments) { + let i; + for (i = 0; i < node.comments.length; i += 1) { + node.comments[i].printed = true; + } + + node.comments = node.comments.filter( + (comment, index) => + index === + node.comments.findIndex( + (commentCheck) => + commentCheck.loc.start === comment.loc.start && + commentCheck.loc.end === comment.loc.end + ) + ); + + for (i = 0; i < node.comments.length; i += 1) { + node.comments[i].printed = false; + } + } + if (hasNodeIgnoreComment(node)) { ignoreComments(path); From 15af4c5269a5942c0337367f3dfc931dcd4341b1 Mon Sep 17 00:00:00 2001 From: Klaus Date: Thu, 27 Jun 2024 10:39:41 +1200 Subject: [PATCH 038/160] removing slang snapshots --- .../__snapshots__/jsfmt.spec.js.snap | 35 - tests/format/AddressPayable/jsfmt.spec.js | 1 - .../Arrays/__snapshots__/jsfmt.spec.js.snap | 62 - tests/format/Arrays/jsfmt.spec.js | 1 - .../Assembly/__snapshots__/jsfmt.spec.js.snap | 488 --- tests/format/Assembly/jsfmt.spec.js | 1 - .../__snapshots__/jsfmt.spec.js.snap | 83 - tests/format/AssemblyV0.4.26/jsfmt.spec.js | 1 - .../__snapshots__/jsfmt.spec.js.snap | 86 - tests/format/BasicIterator/jsfmt.spec.js | 1 - .../__snapshots__/jsfmt.spec.js.snap | 1099 +----- tests/format/BinaryOperators/jsfmt.spec.js | 1 - .../__snapshots__/jsfmt.spec.js.snap | 161 - .../BreakingChangesV0.7.4/jsfmt.spec.js | 14 - .../__snapshots__/jsfmt.spec.js.snap | 75 - .../BreakingChangesV0.8.0/jsfmt.spec.js | 1 - .../Comments/__snapshots__/jsfmt.spec.js.snap | 280 -- tests/format/Comments/jsfmt.spec.js | 1 - .../__snapshots__/jsfmt.spec.js.snap | 74 - tests/format/Conditional/jsfmt.spec.js | 1 - .../__snapshots__/jsfmt.spec.js.snap | 50 - tests/format/Constructors/jsfmt.spec.js | 1 - .../__snapshots__/jsfmt.spec.js.snap | 21 - .../format/ContractDefinitions/jsfmt.spec.js | 1 - .../__snapshots__/jsfmt.spec.js.snap | 49 - tests/format/CustomErrors/jsfmt.spec.js | 1 - .../__snapshots__/jsfmt.spec.js.snap | 35 - tests/format/EnumDefinitions/jsfmt.spec.js | 1 - .../Etc/__snapshots__/jsfmt.spec.js.snap | 134 - tests/format/Etc/jsfmt.spec.js | 1 - .../__snapshots__/jsfmt.spec.js.snap | 2899 +++------------ .../ExperimentalTernaries/jsfmt.spec.js | 13 - .../__snapshots__/jsfmt.spec.js.snap | 105 - tests/format/ForStatements/jsfmt.spec.js | 1 - .../__snapshots__/jsfmt.spec.js.snap | 305 -- tests/format/FunctionCalls/jsfmt.spec.js | 2 - .../__snapshots__/jsfmt.spec.js.snap | 786 ----- .../format/FunctionDefinitions/jsfmt.spec.js | 1 - .../__snapshots__/jsfmt.spec.js.snap | 21 - .../FunctionDefinitionsv0.5.0/jsfmt.spec.js | 1 - .../__snapshots__/jsfmt.spec.js.snap | 54 - tests/format/HexLiteral/jsfmt.spec.js | 8 - .../__snapshots__/jsfmt.spec.js.snap | 538 --- tests/format/IfStatements/jsfmt.spec.js | 1 - .../__snapshots__/jsfmt.spec.js.snap | 51 - tests/format/Immutable/jsfmt.spec.js | 1 - .../__snapshots__/jsfmt.spec.js.snap | 47 - tests/format/ImportDirective/jsfmt.spec.js | 5 - .../Inbox/__snapshots__/jsfmt.spec.js.snap | 61 - tests/format/Inbox/jsfmt.spec.js | 1 - .../IndexOf/__snapshots__/jsfmt.spec.js.snap | 119 - tests/format/IndexOf/jsfmt.spec.js | 1 - .../__snapshots__/jsfmt.spec.js.snap | 30 - tests/format/IndexRangeAccess/jsfmt.spec.js | 1 - .../__snapshots__/jsfmt.spec.js.snap | 22 - .../format/InheritanceSpecifier/jsfmt.spec.js | 1 - .../Issues/__snapshots__/jsfmt.spec.js.snap | 209 -- tests/format/Issues/jsfmt.spec.js | 1 - .../__snapshots__/jsfmt.spec.js.snap | 94 - tests/format/Libraries/jsfmt.spec.js | 2 - .../__snapshots__/jsfmt.spec.js.snap | 235 -- tests/format/MemberAccess/jsfmt.spec.js | 1 - .../__snapshots__/jsfmt.spec.js.snap | 28 - .../format/ModifierDefinitions/jsfmt.spec.js | 1 - .../__snapshots__/jsfmt.spec.js.snap | 45 - .../format/ModifierInvocations/jsfmt.spec.js | 1 - .../__snapshots__/jsfmt.spec.js.snap | 40 - tests/format/MultipartStrings/jsfmt.spec.js | 1 - .../__snapshots__/jsfmt.spec.js.snap | 65 - .../format/NameValueExpression/jsfmt.spec.js | 2 - .../__snapshots__/jsfmt.spec.js.snap | 37 - tests/format/NumberLiteral/jsfmt.spec.js | 1 - .../Ownable/__snapshots__/jsfmt.spec.js.snap | 130 - tests/format/Ownable/jsfmt.spec.js | 1 - .../__snapshots__/jsfmt.spec.js.snap | 3120 +++-------------- tests/format/Parentheses/jsfmt.spec.js | 1 - .../Pragma/__snapshots__/jsfmt.spec.js.snap | 32 - tests/format/Pragma/jsfmt.spec.js | 1 - .../__snapshots__/jsfmt.spec.js.snap | 68 - tests/format/PrettierIgnore/jsfmt.spec.js | 1 - .../Proxy/__snapshots__/jsfmt.spec.js.snap | 96 - tests/format/Proxy/jsfmt.spec.js | 1 - .../__snapshots__/jsfmt.spec.js.snap | 94 - tests/format/SampleCrowdsale/jsfmt.spec.js | 1 - .../__snapshots__/jsfmt.spec.js.snap | 192 - tests/format/SimpleAuction/jsfmt.spec.js | 1 - .../__snapshots__/jsfmt.spec.js.snap | 40 - tests/format/SimpleStorage/jsfmt.spec.js | 1 - .../__snapshots__/jsfmt.spec.js.snap | 134 - .../format/SplittableCommodity/jsfmt.spec.js | 1 - .../__snapshots__/jsfmt.spec.js.snap | 19 - .../StateVariableDeclarations/jsfmt.spec.js | 1 - .../__snapshots__/jsfmt.spec.js.snap | 35 - tests/format/StringLiteral/jsfmt.spec.js | 1 - .../__snapshots__/jsfmt.spec.js.snap | 865 +---- tests/format/StyleGuide/jsfmt.spec.js | 1 - .../TryCatch/__snapshots__/jsfmt.spec.js.snap | 209 -- tests/format/TryCatch/jsfmt.spec.js | 1 - .../Tupples/__snapshots__/jsfmt.spec.js.snap | 63 - tests/format/Tupples/jsfmt.spec.js | 1 - .../__snapshots__/jsfmt.spec.js.snap | 36 - tests/format/TypeDefinition/jsfmt.spec.js | 1 - .../__snapshots__/jsfmt.spec.js.snap | 108 - tests/format/WhileStatements/jsfmt.spec.js | 1 - .../quotes/__snapshots__/jsfmt.spec.js.snap | 118 - tests/format/quotes/jsfmt.spec.js | 2 - .../strings/__snapshots__/jsfmt.spec.js.snap | 1305 ------- tests/format/strings/jsfmt.spec.js | 1 - 108 files changed, 1077 insertions(+), 14204 deletions(-) diff --git a/tests/format/AddressPayable/__snapshots__/jsfmt.spec.js.snap b/tests/format/AddressPayable/__snapshots__/jsfmt.spec.js.snap index 827486583..df021991a 100644 --- a/tests/format/AddressPayable/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/AddressPayable/__snapshots__/jsfmt.spec.js.snap @@ -34,38 +34,3 @@ contract AddressPayable { ================================================================================ `; - -exports[`AddressPayable.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity ^0.5.2; - -contract AddressPayable { - using Address for address payable; - address payable[] hello; - function sendSomeEth(address payable to, address payable[] memory world) public payable { - address payable target = to; - target.transfer(msg.value); - } -} - -=====================================output===================================== -pragma solidity ^0.5.2; - -contract AddressPayable { - using Address for address payable; - address payable[] hello; - function sendSomeEth( - address payable to, - address payable[] memory world - ) public payable { - address payable target = to; - target.transfer(msg.value); - } -} - -================================================================================ -`; diff --git a/tests/format/AddressPayable/jsfmt.spec.js b/tests/format/AddressPayable/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/AddressPayable/jsfmt.spec.js +++ b/tests/format/AddressPayable/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); diff --git a/tests/format/Arrays/__snapshots__/jsfmt.spec.js.snap b/tests/format/Arrays/__snapshots__/jsfmt.spec.js.snap index bce32895b..8eb3ca39b 100644 --- a/tests/format/Arrays/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Arrays/__snapshots__/jsfmt.spec.js.snap @@ -61,65 +61,3 @@ contract ArraySlices { ================================================================================ `; - -exports[`Arrays.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity ^0.5.2; - -contract Arrays { - bytes32[] public permissions = [bytes32("addPartner"), bytes32("removePartner"), bytes32("addGroup"), bytes32("removeGroup"), bytes32("addUserToGroup"), bytes32("removeUserFromGroup"), bytes32("addSolution"), bytes32("removeSolution"), bytes32("addLibrary"), bytes32("removeLibrary"), bytes32("addPermissionToGroup"), bytes32("removePermissionFromGroup")]; - - function a() { - Outcome.OutcomeItem[] memory outcomeFrom = abi.decode(fromPart.outcome, (Outcome.OutcomeItem[])); -} -} - -contract ArraySlices { - function f(bytes calldata x) public { - bytes memory a1 = abi.decode(x[:], (bytes)); - bytes4 a2 = abi.decode(x[:4], (bytes4)); - address a3 = abi.decode(x[4:], (address)); - } -} - -=====================================output===================================== -pragma solidity ^0.5.2; - -contract Arrays { - bytes32[] public permissions = [ - bytes32("addPartner"), - bytes32("removePartner"), - bytes32("addGroup"), - bytes32("removeGroup"), - bytes32("addUserToGroup"), - bytes32("removeUserFromGroup"), - bytes32("addSolution"), - bytes32("removeSolution"), - bytes32("addLibrary"), - bytes32("removeLibrary"), - bytes32("addPermissionToGroup"), - bytes32("removePermissionFromGroup") - ]; - - function a() { - Outcome.OutcomeItem[] memory outcomeFrom = abi.decode( - fromPart.outcome, - (Outcome.OutcomeItem[]) - ); - } -} - -contract ArraySlices { - function f(bytes calldata x) public { - bytes memory a1 = abi.decode(x[:], (bytes)); - bytes4 a2 = abi.decode(x[:4], (bytes4)); - address a3 = abi.decode(x[4:], (address)); - } -} - -================================================================================ -`; diff --git a/tests/format/Arrays/jsfmt.spec.js b/tests/format/Arrays/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/Arrays/jsfmt.spec.js +++ b/tests/format/Arrays/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); diff --git a/tests/format/Assembly/__snapshots__/jsfmt.spec.js.snap b/tests/format/Assembly/__snapshots__/jsfmt.spec.js.snap index 3452d1c7f..ed490afe9 100644 --- a/tests/format/Assembly/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Assembly/__snapshots__/jsfmt.spec.js.snap @@ -518,491 +518,3 @@ contract AssemblyStackAssignment { ================================================================================ `; - -exports[`Assembly.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -contract Assembly { - function ifAssembly() { - assembly { - if - returndatasize { - success := 0 - } - } - } - - function caseAssembly() { - assembly { - switch value - case 0 { - mstore(0, 0x0000000000000000000000000000000000000000000000000000000000000000) - } - case 1 { - mstore(0, 0x1111111111111111111111111111111111111111111111111111111111111111) - } - } - } - - function forAssembly() { - assembly { -for { let i := 0 } lt(i, x) { i := add(i, 1) } { y := mul(2, y) } - } - } - - function callWithComments() { - assembly { - f( - 1, // one - 2, // two - 3 // three - ) - } - } - - function assemblyFunctionNoParameters() { - assembly { - function getAnswer () - -> answer { - answer:= 42 - } - } - } - - function assemblyFunctionOneParameter() { - assembly { - function inc (x) - -> result { - result := add(x, - 1) - } - } - } - - function assemblyFunctionThreeParameters() { - assembly { - function sum (a, b, c) - -> result { - result := add(a, - add(b, c)) - } - } - } - - function assemblyFunctionLongParameters() { - assembly { - function sum (thisIs, aFunctionWithVery, veryLongParameterNames, andItAlsoHasALotOfParameters, soItShouldBeSplitInMultipleLines) - -> result { - result := 0 - } - } - } - - function assemblyFunctionLongReturnParameters() { - assembly { - function sum (a, b, c, d, e) - -> thisIs, aFunctionWithVery, veryLongParameterNames, andItAlsoHasALotOfParameters, soItShouldBeSplitInMultipleLines { - thisIs := 0 - aFunctionWithVery := 0 - veryLongParameterNames := 0 - andItAlsoHasALotOfParameters := 0 - soItShouldBeSplitInMultipleLines := 0 - } - } - } - - - function assemblyFunctionLongParametersAndReturnParameters() { - assembly { - function sum (a,veryLong, listof, parameters, thatShould,splitForSure) - -> thisIs, aFunctionWithVery, veryLongParameterNames, andItAlsoHasALotOfParameters, soItShouldBeSplitInMultipleLines { - thisIs := 0 - aFunctionWithVery := 0 - veryLongParameterNames := 0 - andItAlsoHasALotOfParameters := 0 - soItShouldBeSplitInMultipleLines := 0 - } - } - } - - function assemblyNoParameterCalls() { - assembly { - call(gas(), to, value, inputData, inputDataSize, 0, 0) - } - } - - function assemblyLabels() { - assembly { - let n := calldataload(4) - let a := 1 - let b := a -loop: - jumpi(loopend, eq(n, 0)) - a add swap1 - n := sub(n, 1) - jump(loop) - -loopend: - mstore(0, a) - return(0, 0x20) -} - -assembly{ - let x := 8 - jump(two) - one: - // Here the stack height is 2 (because we pushed x and 7), - // but the assembler thinks it is 1 because it reads - // from top to bottom. - // Accessing the stack variable x here will lead to errors. - x := 9 - jump(three) - two: - 7 // push something onto the stack - jump(one) - three: -} -} - - function assemblyFunctionNoReturn () { - - assembly { - -function $somefn(somearg) { -} - } - } - - function letWithoutValue ( ) { - - assembly { let result } - } - - function memberAccess ( ) { - - assembly { - ds.slot := position - offset := x.offset - } - } - - function commentsInAssemblyBlock () { - - assembly { - /* foo bar baz */ - /* foobbbbbb */ - } - } - - function withBreak() { - assembly { - for {} 1 {} { - break - } - } - } - - function memorySafe() { - assembly ("memory-safe") { - } - assembly "evmasm" ("memory-safe") { - } - } - -function continueAndBreak(uint256 x) public pure returns (uint a, uint b){ -assembly { -for { let i := 0 } lt(i, x) { i := add(i, 1) } { - if lt(i, 10) { - a := add(a, i) - continue - } - if eq(i, 15) { - break - } - - b := i - } -} -} -} - -contract BooleanLiteralsInAssembly { - function f() { - uint a; - assembly { - a := true - a := false - } - } -} - -contract MultipleAssemblyAssignement { - function foo() public pure { - assembly { - function bar() -> a, b { - a := 1 - b := 2 - } - - let i, j := bar() - } - } -} - -contract AssemblyStackAssignment { - function f() public { - assembly { - 4 =: y - } - } -} - -=====================================output===================================== -contract Assembly { - function ifAssembly() { - assembly { - if returndatasize { - success := 0 - } - } - } - - function caseAssembly() { - assembly { - switch value - case 0 { - mstore(0,0x0000000000000000000000000000000000000000000000000000000000000000) - } - case 1 { - mstore(0,0x1111111111111111111111111111111111111111111111111111111111111111) - } - } - } - - function forAssembly() { - assembly { - for { - let i := 0 - } lt(i,x) { - i := add(i,1) - } { - y := mul(2,y) - } - } - } - - function callWithComments() { - assembly { - f(1,2,3) - } - } - - function assemblyFunctionNoParameters() { - assembly { - function getAnswer() -> answer { - answer := 42 - } - } - } - - function assemblyFunctionOneParameter() { - assembly { - function inc(x) -> result { - result := add(x,1) - } - } - } - - function assemblyFunctionThreeParameters() { - assembly { - function sum(a, b, c) -> result { - result := add(a,add(b,c)) - } - } - } - - function assemblyFunctionLongParameters() { - assembly { - function sum( - thisIs, - aFunctionWithVery, - veryLongParameterNames, - andItAlsoHasALotOfParameters, - soItShouldBeSplitInMultipleLines - ) -> result { - result := 0 - } - } - } - - function assemblyFunctionLongReturnParameters() { - assembly { - function sum(a, b, c, d, e) - -> - thisIs, - aFunctionWithVery, - veryLongParameterNames, - andItAlsoHasALotOfParameters, - soItShouldBeSplitInMultipleLines - { - thisIs := 0 - aFunctionWithVery := 0 - veryLongParameterNames := 0 - andItAlsoHasALotOfParameters := 0 - soItShouldBeSplitInMultipleLines := 0 - } - } - } - - function assemblyFunctionLongParametersAndReturnParameters() { - assembly { - function sum( - a, - veryLong, - listof, - parameters, - thatShould, - splitForSure - ) - -> - thisIs, - aFunctionWithVery, - veryLongParameterNames, - andItAlsoHasALotOfParameters, - soItShouldBeSplitInMultipleLines - { - thisIs := 0 - aFunctionWithVery := 0 - veryLongParameterNames := 0 - andItAlsoHasALotOfParameters := 0 - soItShouldBeSplitInMultipleLines := 0 - } - } - } - - function assemblyNoParameterCalls() { - assembly { - call(gas(),to,value,inputData,inputDataSize,0,0) - } - } - - function assemblyLabels() { - assembly { - let n := calldataload(4) - let a := 1 - let b := a - loop - } - - assembly { - let x := 8 - jump(two) - one - } - } - - function assemblyFunctionNoReturn() { - assembly { - function $somefn(somearg) { - - } - } - } - - function letWithoutValue() { - assembly { - let result - } - } - - function memberAccess() { - assembly { - ds.slot := position - offset := x.offset - } - } - - function commentsInAssemblyBlock() { - assembly { - - } - } - - function withBreak() { - assembly { - for { - - } 1 { - - } { - break - } - } - } - - function memorySafe() { - assembly ("memory-safe") { - - } - assembly "evmasm" ("memory-safe") { - - } - } - - function continueAndBreak(uint256 x) public pure returns (uint a, uint b) { - assembly { - for { - let i := 0 - } lt(i,x) { - i := add(i,1) - } { - if lt(i,10) { - a := add(a,i) - continue - } - if eq(i,15) { - break - } - - b := i - } - } - } -} - -contract BooleanLiteralsInAssembly { - function f() { - uint a; - assembly { - a := true - a := false - } - } -} - -contract MultipleAssemblyAssignement { - function foo() public pure { - assembly { - function bar() -> a, b { - a := 1 - b := 2 - } - - let i - } - } -} - -contract AssemblyStackAssignment { - function f() public { - assembly { - 4 - } - } -} - -================================================================================ -`; diff --git a/tests/format/Assembly/jsfmt.spec.js b/tests/format/Assembly/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/Assembly/jsfmt.spec.js +++ b/tests/format/Assembly/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); diff --git a/tests/format/AssemblyV0.4.26/__snapshots__/jsfmt.spec.js.snap b/tests/format/AssemblyV0.4.26/__snapshots__/jsfmt.spec.js.snap index bc94f8545..43771df49 100644 --- a/tests/format/AssemblyV0.4.26/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/AssemblyV0.4.26/__snapshots__/jsfmt.spec.js.snap @@ -86,86 +86,3 @@ contract Assembly { ================================================================================ `; - -exports[`Assembly.sol - {"compiler":"0.4.26"} format 2`] = ` -====================================options===================================== -compiler: "0.4.26" -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity ^0.4.26; - -contract Assembly { - function assemblyLabels() { - assembly { - let n := calldataload(4) - let a := 1 - let b := a -loop: - jumpi(loopend, eq(n, 0)) - a add swap1 - n := sub(n, 1) - jump(loop) - -loopend: - mstore(0, a) - return(0, 0x20) -} - -assembly{ - let x := 8 - jump(two) - one: - // Here the stack height is 2 (because we pushed x and 7), - // but the assembler thinks it is 1 because it reads - // from top to bottom. - // Accessing the stack variable x here will lead to errors. - x := 9 - jump(three) - two: - 7 // push something onto the stack - jump(one) - three: -} -} -} - -=====================================output===================================== -pragma solidity ^0.4.26; - -contract Assembly { - function assemblyLabels() { - assembly { - let n := calldataload(4) - let a := 1 - let b := a - loop: - jumpi(loopend,eq(n,0)) - a - add - swap1 - n := sub(n,1) - jump(loop) - - loopend: - mstore(0,a) - return(0,0x20) - } - - assembly { - let x := 8 - jump(two) - one: - x := 9 - jump(three) - two: - 7 - jump(one) - three: - } - } -} - -================================================================================ -`; diff --git a/tests/format/AssemblyV0.4.26/jsfmt.spec.js b/tests/format/AssemblyV0.4.26/jsfmt.spec.js index 9f2954259..fb953582e 100644 --- a/tests/format/AssemblyV0.4.26/jsfmt.spec.js +++ b/tests/format/AssemblyV0.4.26/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse'], { compiler: '0.4.26' }); -run_spec(import.meta, ['slang'], { compiler: '0.4.26' }); diff --git a/tests/format/BasicIterator/__snapshots__/jsfmt.spec.js.snap b/tests/format/BasicIterator/__snapshots__/jsfmt.spec.js.snap index 852556c6f..8b650d09a 100644 --- a/tests/format/BasicIterator/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/BasicIterator/__snapshots__/jsfmt.spec.js.snap @@ -1,91 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`BasicIterator.sol - {"compiler":"0.4.26"} format 1`] = ` -====================================options===================================== -compiler: "0.4.26" -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -/* - This is a very simple demonstration of a while loops. Same as JS/c. -*/ - -contract BasicIterator { - - address creator; // reserve one "address"-type spot - uint8[10] integers; // reserve a chunk of storage for 10 8-bit unsigned integers in an array - - function BasicIterator() - { - creator = msg.sender; // set the creator address - uint8 x = 0; // initialize an 8-bit, unsigned integer to zero - while(x < integers.length) // the variable integers was initialized to length 10 - { - integers[x] = x; // set integers to [0,1,2,3,4,5,6,7,8,9] over ten iterations - x++; - } - } - - function getSum() constant returns (uint) // "constant" just means this function returns something to the caller - { // which is immediately followed by what type gets returned, in this case a full uint256 - uint8 sum = 0; - uint8 x = 0; - while(x < integers.length) - { - sum = sum + integers[x]; - x++; - } - return sum; - } - - /********** - Standard kill() function to recover funds - **********/ - - function kill() - { - if (msg.sender == creator) - { - suicide(creator); // kills this contract and sends remaining funds back to creator - } - } -} - -=====================================output===================================== -contract BasicIterator { - address creator; - uint8[10] integers; - - function BasicIterator() { - creator = msg.sender; - uint8 x = 0; - while(x < integers.length){ - integers[x] = x; - x++; - } - } - - function getSum() constant returns (uint) { - uint8 sum = 0; - uint8 x = 0; - while(x < integers.length){ - sum = sum + integers[x]; - x++; - } - return sum; - } - - function kill() { - if (msg.sender == creator) { - suicide(creator); - } - } -} - -================================================================================ -`; - exports[`BasicIterator.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] diff --git a/tests/format/BasicIterator/jsfmt.spec.js b/tests/format/BasicIterator/jsfmt.spec.js index c8fb0ebbc..765dd60a6 100644 --- a/tests/format/BasicIterator/jsfmt.spec.js +++ b/tests/format/BasicIterator/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang'], { compiler: '0.4.26' }); diff --git a/tests/format/BinaryOperators/__snapshots__/jsfmt.spec.js.snap b/tests/format/BinaryOperators/__snapshots__/jsfmt.spec.js.snap index 18f73fb47..fd5d8bb50 100644 --- a/tests/format/BinaryOperators/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/BinaryOperators/__snapshots__/jsfmt.spec.js.snap @@ -1,9 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`BinaryOperators.sol - {"compiler":"0.5.8"} format 1`] = ` +exports[`BinaryOperators.sol format 1`] = ` ====================================options===================================== -compiler: "0.5.8" -parsers: ["slang"] +parsers: ["solidity-parse"] printWidth: 80 | printWidth =====================================input====================================== @@ -196,6 +195,7 @@ contract LogicalOperators { =====================================output===================================== contract ArithmeticOperators { + // ['+', '-', '*', '/', '%'] function someFunction() { a + b; a - b; @@ -230,15 +230,15 @@ contract ArithmeticOperators { if ( a() == veryVeryVeryVeryVeryLongVariableCalledA + - veryVeryVeryVeryVeryLongVariableCalledB + veryVeryVeryVeryVeryLongVariableCalledB ) {} for ( a = veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB; a <= - veryVeryVeryVeryVeryLongVariableCalledA + - veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA + + veryVeryVeryVeryVeryLongVariableCalledB; a += veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB @@ -247,8 +247,9 @@ contract ArithmeticOperators { veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB ); - return veryVeryVeryVeryVeryLongVariableCalledA + - veryVeryVeryVeryVeryLongVariableCalledB; + return + veryVeryVeryVeryVeryLongVariableCalledA + + veryVeryVeryVeryVeryLongVariableCalledB; veryVeryVeryVeryVeryLongFunctionCalledA( veryVeryVeryVeryVeryLongVariableCalledB ) + c; @@ -275,13 +276,15 @@ contract ArithmeticOperators { veryVeryVeryVeryVeryLongVariableCalledB ) + c ); - return veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - ) + c; + return + veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) + c; } } contract ArithmeticOperators { + // ['**'] function someFunction() { a ** b; a ** c * d ** e; @@ -323,8 +326,8 @@ contract ArithmeticOperators { veryVeryVeryVeryVeryLongVariableCalledA ** veryVeryVeryVeryVeryLongVariableCalledB; a <= - veryVeryVeryVeryVeryLongVariableCalledA ** - veryVeryVeryVeryVeryLongVariableCalledB; + veryVeryVeryVeryVeryLongVariableCalledA ** + veryVeryVeryVeryVeryLongVariableCalledB; a += veryVeryVeryVeryVeryLongVariableCalledA ** veryVeryVeryVeryVeryLongVariableCalledB @@ -333,8 +336,9 @@ contract ArithmeticOperators { veryVeryVeryVeryVeryLongVariableCalledA ** veryVeryVeryVeryVeryLongVariableCalledB ); - return veryVeryVeryVeryVeryLongVariableCalledA ** - veryVeryVeryVeryVeryLongVariableCalledB; + return + veryVeryVeryVeryVeryLongVariableCalledA ** + veryVeryVeryVeryVeryLongVariableCalledB; veryVeryVeryVeryVeryLongFunctionCalledA( veryVeryVeryVeryVeryLongVariableCalledB ) ** c; @@ -361,13 +365,15 @@ contract ArithmeticOperators { veryVeryVeryVeryVeryLongVariableCalledB ) ** c ); - return veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - ) ** c; + return + veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) ** c; } } contract ShiftOperators { + // ['<<', '>>'] function someFunction() { a << b; a >> b; @@ -386,18 +392,20 @@ contract ShiftOperators { if ( a() == veryVeryVeryVeryVeryLongVariableCalledA << - veryVeryVeryVeryVeryLongVariableCalledB + veryVeryVeryVeryVeryLongVariableCalledB ) {} a( veryVeryVeryVeryVeryLongVariableCalledA << veryVeryVeryVeryVeryLongVariableCalledB ); - return veryVeryVeryVeryVeryLongVariableCalledA << - veryVeryVeryVeryVeryLongVariableCalledB; + return + veryVeryVeryVeryVeryLongVariableCalledA << + veryVeryVeryVeryVeryLongVariableCalledB; } } contract BitOperators { + // ['&', '|', '^'] function someFunction() { a & b; a | b; @@ -419,18 +427,20 @@ contract BitOperators { if ( a() == veryVeryVeryVeryVeryLongVariableCalledA & - veryVeryVeryVeryVeryLongVariableCalledB + veryVeryVeryVeryVeryLongVariableCalledB ) {} a( veryVeryVeryVeryVeryLongVariableCalledA & veryVeryVeryVeryVeryLongVariableCalledB ); - return veryVeryVeryVeryVeryLongVariableCalledA & - veryVeryVeryVeryVeryLongVariableCalledB; + return + veryVeryVeryVeryVeryLongVariableCalledA & + veryVeryVeryVeryVeryLongVariableCalledB; } } contract ComparisonOperators { + // ['<', '>', '<=', '>=', '==', '!='] function someFunction() { a < b; a > b; @@ -461,14 +471,18 @@ contract ComparisonOperators { veryVeryVeryVeryVeryLongFunctionB() <= veryVeryVeryVeryVeryLongVariableCalledA ) {} - while(veryVeryVeryVeryVeryLongVariableCalledA != - veryVeryVeryVeryVeryLongFunctionB()){} - while(veryVeryVeryVeryVeryLongFunctionB() == - veryVeryVeryVeryVeryLongVariableCalledA){} + while ( + veryVeryVeryVeryVeryLongVariableCalledA != + veryVeryVeryVeryVeryLongFunctionB() + ) {} + while ( + veryVeryVeryVeryVeryLongFunctionB() == + veryVeryVeryVeryVeryLongVariableCalledA + ) {} for ( a = veryVeryVeryVeryVeryLongVariableCalledA; veryVeryVeryVeryVeryLongVariableCalledB >= - veryVeryVeryVeryVeryLongVariableCalledA; + veryVeryVeryVeryVeryLongVariableCalledA; a += veryVeryVeryVeryVeryLongVariableCalledA || veryVeryVeryVeryVeryLongVariableCalledB ? 1 @@ -478,8 +492,9 @@ contract ComparisonOperators { veryVeryVeryVeryVeryLongVariableCalledA == veryVeryVeryVeryVeryLongVariableCalledB ); - return veryVeryVeryVeryVeryLongVariableCalledA == - veryVeryVeryVeryVeryLongVariableCalledB; + return + veryVeryVeryVeryVeryLongVariableCalledA == + veryVeryVeryVeryVeryLongVariableCalledB; veryVeryVeryVeryVeryLongFunctionCalledA( veryVeryVeryVeryVeryLongVariableCalledB ) == c; @@ -506,13 +521,15 @@ contract ComparisonOperators { veryVeryVeryVeryVeryLongVariableCalledB ) == c ); - return veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - ) == c; + return + veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + ) == c; } } contract AssignmentOperators { + // ['=', '|=', '^=', '&=', '<<=', '>>=', '+=', '-=', '*=', '/=', '%='] function someFunction() { a = veryVeryVeryVeryVeryLongVariableCalledA; a |= veryVeryVeryVeryVeryLongVariableCalledA; @@ -562,6 +579,7 @@ contract AssignmentOperators { } contract LogicalOperators { + // ['&&', '||'] function someFunction() { a && b; a || b; @@ -589,27 +607,33 @@ contract LogicalOperators { veryVeryVeryVeryVeryLongVariableCalledB ) {} if ( - ( - veryVeryVeryVeryVeryLongVariableCalledA && - veryVeryVeryVeryVeryLongVariableCalledB - ) || c + (veryVeryVeryVeryVeryLongVariableCalledA && + veryVeryVeryVeryVeryLongVariableCalledB) || c ) {} if ( veryVeryVeryVeryVeryLongVariableCalledA || (veryVeryVeryVeryVeryLongVariableCalledB && c) ) {} - while(veryVeryVeryVeryVeryLongVariableCalledA && - veryVeryVeryVeryVeryLongVariableCalledB == a()){} - while(a() == veryVeryVeryVeryVeryLongVariableCalledA && - veryVeryVeryVeryVeryLongVariableCalledB){} - while(veryVeryVeryVeryVeryLongVariableCalledA && - veryVeryVeryVeryVeryLongVariableCalledB){} - while(( + while ( veryVeryVeryVeryVeryLongVariableCalledA && - veryVeryVeryVeryVeryLongVariableCalledB - ) || c){} - while(veryVeryVeryVeryVeryLongVariableCalledA || - (veryVeryVeryVeryVeryLongVariableCalledB && c)){} + veryVeryVeryVeryVeryLongVariableCalledB == a() + ) {} + while ( + a() == veryVeryVeryVeryVeryLongVariableCalledA && + veryVeryVeryVeryVeryLongVariableCalledB + ) {} + while ( + veryVeryVeryVeryVeryLongVariableCalledA && + veryVeryVeryVeryVeryLongVariableCalledB + ) {} + while ( + (veryVeryVeryVeryVeryLongVariableCalledA && + veryVeryVeryVeryVeryLongVariableCalledB) || c + ) {} + while ( + veryVeryVeryVeryVeryLongVariableCalledA || + (veryVeryVeryVeryVeryLongVariableCalledB && c) + ) {} for ( a = veryVeryVeryVeryVeryLongVariableCalledA; a <= veryVeryVeryVeryVeryLongVariableCalledA; @@ -622,20 +646,19 @@ contract LogicalOperators { veryVeryVeryVeryVeryLongVariableCalledA || veryVeryVeryVeryVeryLongVariableCalledB ); - return veryVeryVeryVeryVeryLongVariableCalledA || - veryVeryVeryVeryVeryLongVariableCalledB; + return + veryVeryVeryVeryVeryLongVariableCalledA || + veryVeryVeryVeryVeryLongVariableCalledB; veryVeryVeryVeryVeryLongFunctionCalledA( veryVeryVeryVeryVeryLongVariableCalledB ) || c; veryVeryVeryVeryVeryLongFunctionCalledA( veryVeryVeryVeryVeryLongVariableCalledB ) || - ( - c && - veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - ) - ) || + (c && + veryVeryVeryVeryVeryLongFunctionCalledA( + veryVeryVeryVeryVeryLongVariableCalledB + )) || d; a = veryVeryVeryVeryVeryLongFunctionCalledA( @@ -652,970 +675,10 @@ contract LogicalOperators { veryVeryVeryVeryVeryLongVariableCalledB ) || c ); - return veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - ) || c; - } -} - -================================================================================ -`; - -exports[`BinaryOperators.sol format 1`] = ` -====================================options===================================== -parsers: ["solidity-parse"] -printWidth: 80 - | printWidth -=====================================input====================================== -contract ArithmeticOperators { - // ['+', '-', '*', '/', '%'] - function someFunction() { - a + b; - a - b; - a * b; - a / b; - a % b; - a ** b; - a % b + c - d * e / f ** g; - veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongVariableCalledA - veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongVariableCalledA * veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongVariableCalledA / veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongVariableCalledA % veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongVariableCalledA ** veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB - c * d / e % f ** g; - a = veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB; - if (veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB == a()) {} - if (a() == veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB) {} - for (a = veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB; a <= veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB; a += veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB) {} - a(veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB); - return veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) + c; - veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) + c * veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) - d; - a = veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) + c; - if (veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) + c) {} - a(veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) + c); - return veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) + c; - } -} - - -contract ArithmeticOperators { - // ['**'] - function someFunction() { - a ** b; - a ** c * d ** e; - a ** c * d ** e * a ** c * d ** e * a ** c * d ** e * a ** c * d ** e * a ** c * d ** e; - veryVeryVeryVeryVeryLongVariableCalledA ** veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongVariableCalledA * veryVeryVeryVeryVeryLongVariableCalledB ** c; - c ** veryVeryVeryVeryVeryLongVariableCalledA * veryVeryVeryVeryVeryLongVariableCalledB; - a = veryVeryVeryVeryVeryLongVariableCalledA ** veryVeryVeryVeryVeryLongVariableCalledB; - a = veryVeryVeryVeryVeryLongVariableCalledA ** veryVeryVeryVeryVeryLongVariableCalledB * c; - if (veryVeryVeryVeryVeryLongVariableCalledA ** veryVeryVeryVeryVeryLongVariableCalledB == a()) {} - if (a() == veryVeryVeryVeryVeryLongVariableCalledA ** veryVeryVeryVeryVeryLongVariableCalledB) {} - for (a = veryVeryVeryVeryVeryLongVariableCalledA ** veryVeryVeryVeryVeryLongVariableCalledB; a <= veryVeryVeryVeryVeryLongVariableCalledA ** veryVeryVeryVeryVeryLongVariableCalledB; a += veryVeryVeryVeryVeryLongVariableCalledA ** veryVeryVeryVeryVeryLongVariableCalledB) {} - a(veryVeryVeryVeryVeryLongVariableCalledA ** veryVeryVeryVeryVeryLongVariableCalledB); - return veryVeryVeryVeryVeryLongVariableCalledA ** veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) ** c; - veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) ** c * veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) ** d; - a = veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) ** c; - if (veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) ** c) {} - a(veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) ** c); - return veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) ** c; - } -} - - -contract ShiftOperators { - // ['<<', '>>'] - function someFunction() { - a << b; - a >> b; - veryVeryVeryVeryVeryLongVariableCalledA << veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongVariableCalledA >> veryVeryVeryVeryVeryLongVariableCalledB; - a = veryVeryVeryVeryVeryLongVariableCalledA << veryVeryVeryVeryVeryLongVariableCalledB; - if (veryVeryVeryVeryVeryLongVariableCalledA << veryVeryVeryVeryVeryLongVariableCalledB == a()) {} - if (a() == veryVeryVeryVeryVeryLongVariableCalledA << veryVeryVeryVeryVeryLongVariableCalledB) {} - a(veryVeryVeryVeryVeryLongVariableCalledA << veryVeryVeryVeryVeryLongVariableCalledB); - return veryVeryVeryVeryVeryLongVariableCalledA << veryVeryVeryVeryVeryLongVariableCalledB; - } -} - - -contract BitOperators { - // ['&', '|', '^'] - function someFunction() { - a & b; - a | b; - a ^ b; - veryVeryVeryVeryVeryLongVariableCalledA & veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongVariableCalledA | veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongVariableCalledA ^ veryVeryVeryVeryVeryLongVariableCalledB; - a = veryVeryVeryVeryVeryLongVariableCalledA & veryVeryVeryVeryVeryLongVariableCalledB; - if (veryVeryVeryVeryVeryLongVariableCalledA & veryVeryVeryVeryVeryLongVariableCalledB == a()) {} - if (a() == veryVeryVeryVeryVeryLongVariableCalledA & veryVeryVeryVeryVeryLongVariableCalledB) {} - a(veryVeryVeryVeryVeryLongVariableCalledA & veryVeryVeryVeryVeryLongVariableCalledB); - return veryVeryVeryVeryVeryLongVariableCalledA & veryVeryVeryVeryVeryLongVariableCalledB; - } -} - - -contract ComparisonOperators { - // ['<', '>', '<=', '>=', '==', '!='] - function someFunction() { - a < b; - a > b; - a <= b; - a >= b; - a == b; - a != b; - veryVeryVeryVeryVeryLongVariableCalledA < veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongVariableCalledA > veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongVariableCalledA <= veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongVariableCalledA >= veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongVariableCalledA == veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongVariableCalledA != veryVeryVeryVeryVeryLongVariableCalledB; - a = veryVeryVeryVeryVeryLongVariableCalledA < veryVeryVeryVeryVeryLongVariableCalledB; - if (veryVeryVeryVeryVeryLongVariableCalledA > veryVeryVeryVeryVeryLongFunctionB()) {} - if (veryVeryVeryVeryVeryLongFunctionB() <= veryVeryVeryVeryVeryLongVariableCalledA) {} - while (veryVeryVeryVeryVeryLongVariableCalledA != veryVeryVeryVeryVeryLongFunctionB()) {} - while (veryVeryVeryVeryVeryLongFunctionB() == veryVeryVeryVeryVeryLongVariableCalledA) {} - for (a = veryVeryVeryVeryVeryLongVariableCalledA; veryVeryVeryVeryVeryLongVariableCalledB >= veryVeryVeryVeryVeryLongVariableCalledA; a += veryVeryVeryVeryVeryLongVariableCalledA || veryVeryVeryVeryVeryLongVariableCalledB ? 1:2) {} - a(veryVeryVeryVeryVeryLongVariableCalledA == veryVeryVeryVeryVeryLongVariableCalledB); - return veryVeryVeryVeryVeryLongVariableCalledA == veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) == c; - veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) < c || veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) > d; - a = veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) == c; - if (veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) == c) {} - a(veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) == c); - return veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) == c; - } -} - - -contract AssignmentOperators { - // ['=', '|=', '^=', '&=', '<<=', '>>=', '+=', '-=', '*=', '/=', '%='] - function someFunction() { - a = veryVeryVeryVeryVeryLongVariableCalledA; - a |= veryVeryVeryVeryVeryLongVariableCalledA; - a ^= veryVeryVeryVeryVeryLongVariableCalledA; - a &= veryVeryVeryVeryVeryLongVariableCalledA; - a <<= veryVeryVeryVeryVeryLongVariableCalledA; - a >>= veryVeryVeryVeryVeryLongVariableCalledA; - a += veryVeryVeryVeryVeryLongVariableCalledA; - a -= veryVeryVeryVeryVeryLongVariableCalledA; - a *= veryVeryVeryVeryVeryLongVariableCalledA; - a /= veryVeryVeryVeryVeryLongVariableCalledA; - a %= veryVeryVeryVeryVeryLongVariableCalledA; - a = veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongFunctionCalledB(c); - a |= veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongFunctionCalledB(c); - a ^= veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongFunctionCalledB(c); - a &= veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongFunctionCalledB(c); - a <<= veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongFunctionCalledB(c); - a >>= veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongFunctionCalledB(c); - a += veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongFunctionCalledB(c); - a -= veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongFunctionCalledB(c); - a *= veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongFunctionCalledB(c); - a /= veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongFunctionCalledB(c); - a %= veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongFunctionCalledB(c); - } -} - - -contract LogicalOperators { - // ['&&', '||'] - function someFunction() { - a && b; - a || b; - a || b && c || d && e; - veryVeryVeryVeryVeryLongVariableCalledA && veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongVariableCalledA || veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongVariableCalledA || veryVeryVeryVeryVeryLongVariableCalledB && c || d && e; - a = veryVeryVeryVeryVeryLongVariableCalledA && veryVeryVeryVeryVeryLongVariableCalledB; - if (veryVeryVeryVeryVeryLongVariableCalledA && veryVeryVeryVeryVeryLongVariableCalledB == a()) {} - if (a() == veryVeryVeryVeryVeryLongVariableCalledA && veryVeryVeryVeryVeryLongVariableCalledB) {} - if (veryVeryVeryVeryVeryLongVariableCalledA && veryVeryVeryVeryVeryLongVariableCalledB) {} - if (veryVeryVeryVeryVeryLongVariableCalledA && veryVeryVeryVeryVeryLongVariableCalledB || c) {} - if (veryVeryVeryVeryVeryLongVariableCalledA || veryVeryVeryVeryVeryLongVariableCalledB && c) {} - while (veryVeryVeryVeryVeryLongVariableCalledA && veryVeryVeryVeryVeryLongVariableCalledB == a()) {} - while (a() == veryVeryVeryVeryVeryLongVariableCalledA && veryVeryVeryVeryVeryLongVariableCalledB) {} - while (veryVeryVeryVeryVeryLongVariableCalledA && veryVeryVeryVeryVeryLongVariableCalledB) {} - while (veryVeryVeryVeryVeryLongVariableCalledA && veryVeryVeryVeryVeryLongVariableCalledB || c) {} - while (veryVeryVeryVeryVeryLongVariableCalledA || veryVeryVeryVeryVeryLongVariableCalledB && c) {} - for (a = veryVeryVeryVeryVeryLongVariableCalledA; a <= veryVeryVeryVeryVeryLongVariableCalledA; a += veryVeryVeryVeryVeryLongVariableCalledA || veryVeryVeryVeryVeryLongVariableCalledB ? 1:2) {} - a(veryVeryVeryVeryVeryLongVariableCalledA || veryVeryVeryVeryVeryLongVariableCalledB); - return veryVeryVeryVeryVeryLongVariableCalledA || veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) || c; - veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) || c && veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) || d; - a = veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) || c; - if (veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) || c) {} - a(veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) || c); - return veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongVariableCalledB) || c; - } -} - -=====================================output===================================== -contract ArithmeticOperators { - // ['+', '-', '*', '/', '%'] - function someFunction() { - a + b; - a - b; - a * b; - a / b; - a % b; - a ** b; - (a % b) + c - (d * e) / f ** g; - veryVeryVeryVeryVeryLongVariableCalledA + - veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongVariableCalledA - - veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongVariableCalledA * - veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongVariableCalledA / - veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongVariableCalledA % - veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongVariableCalledA ** - veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongVariableCalledA + - veryVeryVeryVeryVeryLongVariableCalledB - - (((c * d) / e) % f ** g); - a = - veryVeryVeryVeryVeryLongVariableCalledA + - veryVeryVeryVeryVeryLongVariableCalledB; - if ( - veryVeryVeryVeryVeryLongVariableCalledA + - veryVeryVeryVeryVeryLongVariableCalledB == - a() - ) {} - if ( - a() == - veryVeryVeryVeryVeryLongVariableCalledA + - veryVeryVeryVeryVeryLongVariableCalledB - ) {} - for ( - a = - veryVeryVeryVeryVeryLongVariableCalledA + - veryVeryVeryVeryVeryLongVariableCalledB; - a <= - veryVeryVeryVeryVeryLongVariableCalledA + - veryVeryVeryVeryVeryLongVariableCalledB; - a += - veryVeryVeryVeryVeryLongVariableCalledA + - veryVeryVeryVeryVeryLongVariableCalledB - ) {} - a( - veryVeryVeryVeryVeryLongVariableCalledA + - veryVeryVeryVeryVeryLongVariableCalledB - ); - return - veryVeryVeryVeryVeryLongVariableCalledA + - veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - ) + c; - veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - ) + - c * - veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - ) - - d; - a = - veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - ) + - c; - if ( - veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - ) + c - ) {} - a( - veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - ) + c - ); - return - veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - ) + c; - } -} - -contract ArithmeticOperators { - // ['**'] - function someFunction() { - a ** b; - a ** c * d ** e; - a ** c * - d ** e * - a ** c * - d ** e * - a ** c * - d ** e * - a ** c * - d ** e * - a ** c * - d ** e; - veryVeryVeryVeryVeryLongVariableCalledA ** - veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongVariableCalledA * - veryVeryVeryVeryVeryLongVariableCalledB ** c; - c ** veryVeryVeryVeryVeryLongVariableCalledA * - veryVeryVeryVeryVeryLongVariableCalledB; - a = - veryVeryVeryVeryVeryLongVariableCalledA ** - veryVeryVeryVeryVeryLongVariableCalledB; - a = - veryVeryVeryVeryVeryLongVariableCalledA ** - veryVeryVeryVeryVeryLongVariableCalledB * - c; - if ( - veryVeryVeryVeryVeryLongVariableCalledA ** - veryVeryVeryVeryVeryLongVariableCalledB == - a() - ) {} - if ( - a() == - veryVeryVeryVeryVeryLongVariableCalledA ** - veryVeryVeryVeryVeryLongVariableCalledB - ) {} - for ( - a = - veryVeryVeryVeryVeryLongVariableCalledA ** - veryVeryVeryVeryVeryLongVariableCalledB; - a <= - veryVeryVeryVeryVeryLongVariableCalledA ** - veryVeryVeryVeryVeryLongVariableCalledB; - a += - veryVeryVeryVeryVeryLongVariableCalledA ** - veryVeryVeryVeryVeryLongVariableCalledB - ) {} - a( - veryVeryVeryVeryVeryLongVariableCalledA ** - veryVeryVeryVeryVeryLongVariableCalledB - ); - return - veryVeryVeryVeryVeryLongVariableCalledA ** - veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - ) ** c; - veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - ) ** - c * - veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - ) ** - d; - a = - veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - ) ** - c; - if ( - veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - ) ** c - ) {} - a( - veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - ) ** c - ); return veryVeryVeryVeryVeryLongFunctionCalledA( veryVeryVeryVeryVeryLongVariableCalledB - ) ** c; - } -} - -contract ShiftOperators { - // ['<<', '>>'] - function someFunction() { - a << b; - a >> b; - veryVeryVeryVeryVeryLongVariableCalledA << - veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongVariableCalledA >> - veryVeryVeryVeryVeryLongVariableCalledB; - a = - veryVeryVeryVeryVeryLongVariableCalledA << - veryVeryVeryVeryVeryLongVariableCalledB; - if ( - veryVeryVeryVeryVeryLongVariableCalledA << - veryVeryVeryVeryVeryLongVariableCalledB == - a() - ) {} - if ( - a() == - veryVeryVeryVeryVeryLongVariableCalledA << - veryVeryVeryVeryVeryLongVariableCalledB - ) {} - a( - veryVeryVeryVeryVeryLongVariableCalledA << - veryVeryVeryVeryVeryLongVariableCalledB - ); - return - veryVeryVeryVeryVeryLongVariableCalledA << - veryVeryVeryVeryVeryLongVariableCalledB; - } -} - -contract BitOperators { - // ['&', '|', '^'] - function someFunction() { - a & b; - a | b; - a ^ b; - veryVeryVeryVeryVeryLongVariableCalledA & - veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongVariableCalledA | - veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongVariableCalledA ^ - veryVeryVeryVeryVeryLongVariableCalledB; - a = - veryVeryVeryVeryVeryLongVariableCalledA & - veryVeryVeryVeryVeryLongVariableCalledB; - if ( - veryVeryVeryVeryVeryLongVariableCalledA & - veryVeryVeryVeryVeryLongVariableCalledB == - a() - ) {} - if ( - a() == - veryVeryVeryVeryVeryLongVariableCalledA & - veryVeryVeryVeryVeryLongVariableCalledB - ) {} - a( - veryVeryVeryVeryVeryLongVariableCalledA & - veryVeryVeryVeryVeryLongVariableCalledB - ); - return - veryVeryVeryVeryVeryLongVariableCalledA & - veryVeryVeryVeryVeryLongVariableCalledB; - } -} - -contract ComparisonOperators { - // ['<', '>', '<=', '>=', '==', '!='] - function someFunction() { - a < b; - a > b; - a <= b; - a >= b; - a == b; - a != b; - veryVeryVeryVeryVeryLongVariableCalledA < - veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongVariableCalledA > - veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongVariableCalledA <= - veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongVariableCalledA >= - veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongVariableCalledA == - veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongVariableCalledA != - veryVeryVeryVeryVeryLongVariableCalledB; - a = - veryVeryVeryVeryVeryLongVariableCalledA < - veryVeryVeryVeryVeryLongVariableCalledB; - if ( - veryVeryVeryVeryVeryLongVariableCalledA > - veryVeryVeryVeryVeryLongFunctionB() - ) {} - if ( - veryVeryVeryVeryVeryLongFunctionB() <= - veryVeryVeryVeryVeryLongVariableCalledA - ) {} - while ( - veryVeryVeryVeryVeryLongVariableCalledA != - veryVeryVeryVeryVeryLongFunctionB() - ) {} - while ( - veryVeryVeryVeryVeryLongFunctionB() == - veryVeryVeryVeryVeryLongVariableCalledA - ) {} - for ( - a = veryVeryVeryVeryVeryLongVariableCalledA; - veryVeryVeryVeryVeryLongVariableCalledB >= - veryVeryVeryVeryVeryLongVariableCalledA; - a += veryVeryVeryVeryVeryLongVariableCalledA || - veryVeryVeryVeryVeryLongVariableCalledB - ? 1 - : 2 - ) {} - a( - veryVeryVeryVeryVeryLongVariableCalledA == - veryVeryVeryVeryVeryLongVariableCalledB - ); - return - veryVeryVeryVeryVeryLongVariableCalledA == - veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - ) == c; - veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - ) < - c || - veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - ) > - d; - a = - veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - ) == - c; - if ( - veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - ) == c - ) {} - a( - veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - ) == c - ); - return - veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - ) == c; - } -} - -contract AssignmentOperators { - // ['=', '|=', '^=', '&=', '<<=', '>>=', '+=', '-=', '*=', '/=', '%='] - function someFunction() { - a = veryVeryVeryVeryVeryLongVariableCalledA; - a |= veryVeryVeryVeryVeryLongVariableCalledA; - a ^= veryVeryVeryVeryVeryLongVariableCalledA; - a &= veryVeryVeryVeryVeryLongVariableCalledA; - a <<= veryVeryVeryVeryVeryLongVariableCalledA; - a >>= veryVeryVeryVeryVeryLongVariableCalledA; - a += veryVeryVeryVeryVeryLongVariableCalledA; - a -= veryVeryVeryVeryVeryLongVariableCalledA; - a *= veryVeryVeryVeryVeryLongVariableCalledA; - a /= veryVeryVeryVeryVeryLongVariableCalledA; - a %= veryVeryVeryVeryVeryLongVariableCalledA; - a = - veryVeryVeryVeryVeryLongVariableCalledA + - veryVeryVeryVeryVeryLongFunctionCalledB(c); - a |= - veryVeryVeryVeryVeryLongVariableCalledA + - veryVeryVeryVeryVeryLongFunctionCalledB(c); - a ^= - veryVeryVeryVeryVeryLongVariableCalledA + - veryVeryVeryVeryVeryLongFunctionCalledB(c); - a &= - veryVeryVeryVeryVeryLongVariableCalledA + - veryVeryVeryVeryVeryLongFunctionCalledB(c); - a <<= - veryVeryVeryVeryVeryLongVariableCalledA + - veryVeryVeryVeryVeryLongFunctionCalledB(c); - a >>= - veryVeryVeryVeryVeryLongVariableCalledA + - veryVeryVeryVeryVeryLongFunctionCalledB(c); - a += - veryVeryVeryVeryVeryLongVariableCalledA + - veryVeryVeryVeryVeryLongFunctionCalledB(c); - a -= - veryVeryVeryVeryVeryLongVariableCalledA + - veryVeryVeryVeryVeryLongFunctionCalledB(c); - a *= - veryVeryVeryVeryVeryLongVariableCalledA + - veryVeryVeryVeryVeryLongFunctionCalledB(c); - a /= - veryVeryVeryVeryVeryLongVariableCalledA + - veryVeryVeryVeryVeryLongFunctionCalledB(c); - a %= - veryVeryVeryVeryVeryLongVariableCalledA + - veryVeryVeryVeryVeryLongFunctionCalledB(c); - } -} - -contract LogicalOperators { - // ['&&', '||'] - function someFunction() { - a && b; - a || b; - a || (b && c) || (d && e); - veryVeryVeryVeryVeryLongVariableCalledA && - veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongVariableCalledA || - veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongVariableCalledA || - (veryVeryVeryVeryVeryLongVariableCalledB && c) || - (d && e); - a = - veryVeryVeryVeryVeryLongVariableCalledA && - veryVeryVeryVeryVeryLongVariableCalledB; - if ( - veryVeryVeryVeryVeryLongVariableCalledA && - veryVeryVeryVeryVeryLongVariableCalledB == a() - ) {} - if ( - a() == veryVeryVeryVeryVeryLongVariableCalledA && - veryVeryVeryVeryVeryLongVariableCalledB - ) {} - if ( - veryVeryVeryVeryVeryLongVariableCalledA && - veryVeryVeryVeryVeryLongVariableCalledB - ) {} - if ( - (veryVeryVeryVeryVeryLongVariableCalledA && - veryVeryVeryVeryVeryLongVariableCalledB) || c - ) {} - if ( - veryVeryVeryVeryVeryLongVariableCalledA || - (veryVeryVeryVeryVeryLongVariableCalledB && c) - ) {} - while ( - veryVeryVeryVeryVeryLongVariableCalledA && - veryVeryVeryVeryVeryLongVariableCalledB == a() - ) {} - while ( - a() == veryVeryVeryVeryVeryLongVariableCalledA && - veryVeryVeryVeryVeryLongVariableCalledB - ) {} - while ( - veryVeryVeryVeryVeryLongVariableCalledA && - veryVeryVeryVeryVeryLongVariableCalledB - ) {} - while ( - (veryVeryVeryVeryVeryLongVariableCalledA && - veryVeryVeryVeryVeryLongVariableCalledB) || c - ) {} - while ( - veryVeryVeryVeryVeryLongVariableCalledA || - (veryVeryVeryVeryVeryLongVariableCalledB && c) - ) {} - for ( - a = veryVeryVeryVeryVeryLongVariableCalledA; - a <= veryVeryVeryVeryVeryLongVariableCalledA; - a += veryVeryVeryVeryVeryLongVariableCalledA || - veryVeryVeryVeryVeryLongVariableCalledB - ? 1 - : 2 - ) {} - a( - veryVeryVeryVeryVeryLongVariableCalledA || - veryVeryVeryVeryVeryLongVariableCalledB - ); - return - veryVeryVeryVeryVeryLongVariableCalledA || - veryVeryVeryVeryVeryLongVariableCalledB; - veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - ) || c; - veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - ) || - (c && - veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - )) || - d; - a = - veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - ) || - c; - if ( - veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - ) || c - ) {} - a( - veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - ) || c - ); - return - veryVeryVeryVeryVeryLongFunctionCalledA( - veryVeryVeryVeryVeryLongVariableCalledB - ) || c; - } -} - -================================================================================ -`; - -exports[`Parentheses.sol - {"compiler":"0.5.8"} format 1`] = ` -====================================options===================================== -compiler: "0.5.8" -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity 0.5.8; - - -contract Parentheses { - function() { - a + b + c; - a + b - c; - a + b * c; - a + b / c; - a + b % c; - a + b ** c; - a + b << c; - a + b >> c; - a + b & c; - a + b | c; - a + b ^ c; - a - b + c; - a - b - c; - a - b * c; - a - b / c; - a - b % c; - a - b ** c; - a - b << c; - a - b >> c; - a - b & c; - a - b | c; - a - b ^ c; - a * b + c; - a * b - c; - a * b * c; - a * b / c; - a * b % c; - a * b ** c; - a * b << c; - a * b >> c; - a * b & c; - a * b | c; - a * b ^ c; - a / b + c; - a / b - c; - a / b * c; - a / b / c; - a / b % c; - a / b ** c; - a / b << c; - a / b >> c; - a / b & c; - a / b | c; - a / b ^ c; - a % b + c; - a % b - c; - a % b * c; - a % b / c; - a % b % c; - a % b ** c; - a % b << c; - a % b >> c; - a % b & c; - a % b | c; - a % b ^ c; - a ** b + c; - a ** b - c; - a ** b * c; - a ** b / c; - a ** b % c; - a ** b ** c; - a ** b << c; - a ** b >> c; - a ** b & c; - a ** b | c; - a ** b ^ c; - a << b + c; - a << b - c; - a << b * c; - a << b / c; - a << b % c; - a << b ** c; - a << b << c; - a << b >> c; - a << b & c; - a << b | c; - a << b ^ c; - a >> b + c; - a >> b - c; - a >> b * c; - a >> b / c; - a >> b % c; - a >> b ** c; - a >> b << c; - a >> b >> c; - a >> b & c; - a >> b | c; - a >> b ^ c; - a & b + c; - a & b - c; - a & b * c; - a & b / c; - a & b % c; - a & b ** c; - a & b << c; - a & b >> c; - a & b & c; - a & b | c; - a & b ^ c; - a | b + c; - a | b - c; - a | b * c; - a | b / c; - a | b % c; - a | b ** c; - a | b << c; - a | b >> c; - a | b & c; - a | b | c; - a | b ^ c; - a ^ b + c; - a ^ b - c; - a ^ b * c; - a ^ b / c; - a ^ b % c; - a ^ b ** c; - a ^ b << c; - a ^ b >> c; - a ^ b & c; - a ^ b | c; - a ^ b ^ c; - a || b || c; - a || b && c; - a && b || c; - a && b && c; - } -} - -=====================================output===================================== -pragma solidity 0.5.8; - -contract Parentheses { - function() { - a + b + c; - a + b - c; - a + b * c; - a + b / c; - a + (b % c); - a + b ** c; - (a + b) << c; - (a + b) >> c; - (a + b) & c; - (a + b) | c; - (a + b) ^ c; - a - b + c; - a - b - c; - a - b * c; - a - b / c; - a - (b % c); - a - b ** c; - (a - b) << c; - (a - b) >> c; - (a - b) & c; - (a - b) | c; - (a - b) ^ c; - a * b + c; - a * b - c; - a * b * c; - (a * b) / c; - (a * b) % c; - a * b ** c; - (a * b) << c; - (a * b) >> c; - (a * b) & c; - (a * b) | c; - (a * b) ^ c; - a / b + c; - a / b - c; - (a / b) * c; - a / b / c; - (a / b) % c; - a / b ** c; - (a / b) << c; - (a / b) >> c; - (a / b) & c; - (a / b) | c; - (a / b) ^ c; - (a % b) + c; - (a % b) - c; - (a % b) * c; - (a % b) / c; - (a % b) % c; - a % b ** c; - a % b << c; - a % b >> c; - a % b & c; - a % b | c; - a % b ^ c; - a ** b + c; - a ** b - c; - a ** b * c; - a ** b / c; - a ** b % c; - (a ** b) ** c; - (a ** b) << c; - (a ** b) >> c; - (a ** b) & c; - (a ** b) | c; - (a ** b) ^ c; - a << (b + c); - a << (b - c); - a << (b * c); - a << (b / c); - a << b % c; - a << (b ** c); - (a << b) << c; - (a << b) >> c; - (a << b) & c; - (a << b) | c; - (a << b) ^ c; - a >> (b + c); - a >> (b - c); - a >> (b * c); - a >> (b / c); - a >> b % c; - a >> (b ** c); - (a >> b) << c; - (a >> b) >> c; - (a >> b) & c; - (a >> b) | c; - (a >> b) ^ c; - a & (b + c); - a & (b - c); - a & (b * c); - a & (b / c); - a & b % c; - a & (b ** c); - a & (b << c); - a & (b >> c); - a & b & c; - (a & b) | c; - (a & b) ^ c; - a | (b + c); - a | (b - c); - a | (b * c); - a | (b / c); - a | b % c; - a | (b ** c); - a | (b << c); - a | (b >> c); - a | (b & c); - a | b | c; - a | (b ^ c); - a ^ (b + c); - a ^ (b - c); - a ^ (b * c); - a ^ (b / c); - a ^ b % c; - a ^ (b ** c); - a ^ (b << c); - a ^ (b >> c); - a ^ (b & c); - (a ^ b) | c; - a ^ b ^ c; - a || b || c; - a || (b && c); - (a && b) || c; - a && b && c; + ) || c; } } diff --git a/tests/format/BinaryOperators/jsfmt.spec.js b/tests/format/BinaryOperators/jsfmt.spec.js index 053aef41e..765dd60a6 100644 --- a/tests/format/BinaryOperators/jsfmt.spec.js +++ b/tests/format/BinaryOperators/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang'], { compiler: '0.5.8' }); diff --git a/tests/format/BreakingChangesV0.7.4/__snapshots__/jsfmt.spec.js.snap b/tests/format/BreakingChangesV0.7.4/__snapshots__/jsfmt.spec.js.snap index 5c44e9a4e..bf7c7307e 100644 --- a/tests/format/BreakingChangesV0.7.4/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/BreakingChangesV0.7.4/__snapshots__/jsfmt.spec.js.snap @@ -31,31 +31,6 @@ import { symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4 } from ================================================================================ `; -exports[`BreakingChangesV0.7.4.sol - {"bracketSpacing":true} format 2`] = ` -====================================options===================================== -bracketSpacing: true -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity ^0.7.0; - -/** - * - if options.compiler is undefined we won't break the ImportDirective. - * - if options.compiler is lower than 0.7.4 we won't break the ImportDirective. - * - if options.compiler is greater than or equal to 0.7.4 we will break the - * ImportDirective if the line length exceeds the printWidth. - */ -import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol"; - -=====================================output===================================== -pragma solidity ^0.7.0; - -import { symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4 } from "File2.sol"; - -================================================================================ -`; - exports[`BreakingChangesV0.7.4.sol - {"compiler":"0.7.3","bracketSpacing":true} format 1`] = ` ====================================options===================================== bracketSpacing: true @@ -88,32 +63,6 @@ import { symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4 } from ================================================================================ `; -exports[`BreakingChangesV0.7.4.sol - {"compiler":"0.7.3","bracketSpacing":true} format 2`] = ` -====================================options===================================== -bracketSpacing: true -compiler: "0.7.3" -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity ^0.7.0; - -/** - * - if options.compiler is undefined we won't break the ImportDirective. - * - if options.compiler is lower than 0.7.4 we won't break the ImportDirective. - * - if options.compiler is greater than or equal to 0.7.4 we will break the - * ImportDirective if the line length exceeds the printWidth. - */ -import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol"; - -=====================================output===================================== -pragma solidity ^0.7.0; - -import { symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4 } from "File2.sol"; - -================================================================================ -`; - exports[`BreakingChangesV0.7.4.sol - {"compiler":"0.7.3"} format 1`] = ` ====================================options===================================== compiler: "0.7.3" @@ -145,31 +94,6 @@ import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from " ================================================================================ `; -exports[`BreakingChangesV0.7.4.sol - {"compiler":"0.7.3"} format 2`] = ` -====================================options===================================== -compiler: "0.7.3" -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity ^0.7.0; - -/** - * - if options.compiler is undefined we won't break the ImportDirective. - * - if options.compiler is lower than 0.7.4 we won't break the ImportDirective. - * - if options.compiler is greater than or equal to 0.7.4 we will break the - * ImportDirective if the line length exceeds the printWidth. - */ -import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol"; - -=====================================output===================================== -pragma solidity ^0.7.0; - -import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol"; - -================================================================================ -`; - exports[`BreakingChangesV0.7.4.sol - {"compiler":"0.7.4","bracketSpacing":true} format 1`] = ` ====================================options===================================== bracketSpacing: true @@ -207,37 +131,6 @@ import { ================================================================================ `; -exports[`BreakingChangesV0.7.4.sol - {"compiler":"0.7.4","bracketSpacing":true} format 2`] = ` -====================================options===================================== -bracketSpacing: true -compiler: "0.7.4" -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity ^0.7.0; - -/** - * - if options.compiler is undefined we won't break the ImportDirective. - * - if options.compiler is lower than 0.7.4 we won't break the ImportDirective. - * - if options.compiler is greater than or equal to 0.7.4 we will break the - * ImportDirective if the line length exceeds the printWidth. - */ -import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol"; - -=====================================output===================================== -pragma solidity ^0.7.0; - -import { - symbol1 as alias1, - symbol2 as alias2, - symbol3 as alias3, - symbol4 -} from "File2.sol"; - -================================================================================ -`; - exports[`BreakingChangesV0.7.4.sol - {"compiler":"0.7.4"} format 1`] = ` ====================================options===================================== compiler: "0.7.4" @@ -274,36 +167,6 @@ import { ================================================================================ `; -exports[`BreakingChangesV0.7.4.sol - {"compiler":"0.7.4"} format 2`] = ` -====================================options===================================== -compiler: "0.7.4" -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity ^0.7.0; - -/** - * - if options.compiler is undefined we won't break the ImportDirective. - * - if options.compiler is lower than 0.7.4 we won't break the ImportDirective. - * - if options.compiler is greater than or equal to 0.7.4 we will break the - * ImportDirective if the line length exceeds the printWidth. - */ -import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol"; - -=====================================output===================================== -pragma solidity ^0.7.0; - -import { - symbol1 as alias1, - symbol2 as alias2, - symbol3 as alias3, - symbol4 -} from "File2.sol"; - -================================================================================ -`; - exports[`BreakingChangesV0.7.4.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] @@ -333,27 +196,3 @@ import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from " ================================================================================ `; - -exports[`BreakingChangesV0.7.4.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity ^0.7.0; - -/** - * - if options.compiler is undefined we won't break the ImportDirective. - * - if options.compiler is lower than 0.7.4 we won't break the ImportDirective. - * - if options.compiler is greater than or equal to 0.7.4 we will break the - * ImportDirective if the line length exceeds the printWidth. - */ -import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol"; - -=====================================output===================================== -pragma solidity ^0.7.0; - -import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol"; - -================================================================================ -`; diff --git a/tests/format/BreakingChangesV0.7.4/jsfmt.spec.js b/tests/format/BreakingChangesV0.7.4/jsfmt.spec.js index 0d83de79c..b64637462 100644 --- a/tests/format/BreakingChangesV0.7.4/jsfmt.spec.js +++ b/tests/format/BreakingChangesV0.7.4/jsfmt.spec.js @@ -12,17 +12,3 @@ run_spec(import.meta, ['solidity-parse']); run_spec(import.meta, ['solidity-parse'], { bracketSpacing: true }); -run_spec(import.meta, ['slang'], { compiler: '0.7.4' }); -run_spec(import.meta, ['slang'], { - compiler: '0.7.4', - bracketSpacing: true -}); -run_spec(import.meta, ['slang'], { compiler: '0.7.3' }); -run_spec(import.meta, ['slang'], { - compiler: '0.7.3', - bracketSpacing: true -}); -run_spec(import.meta, ['slang']); -run_spec(import.meta, ['slang'], { - bracketSpacing: true -}); diff --git a/tests/format/BreakingChangesV0.8.0/__snapshots__/jsfmt.spec.js.snap b/tests/format/BreakingChangesV0.8.0/__snapshots__/jsfmt.spec.js.snap index f60aa1204..2ad74c457 100644 --- a/tests/format/BreakingChangesV0.8.0/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/BreakingChangesV0.8.0/__snapshots__/jsfmt.spec.js.snap @@ -92,81 +92,6 @@ contract BreakingChangesV080 { ================================================================================ `; -exports[`BreakingChangesV0.8.0.sol - {"compiler":"0.7.0"} format 2`] = ` -====================================options===================================== -compiler: "0.7.0" -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -// SPDX-License-Identifier: MIT -// TODO: uncomment once NomicFoundation addresses Semver notations -// https://github.com/NomicFoundation/slang/issues/986 -// pragma solidity >=0.7.0 <=0.8.5; - -contract BreakingChangesV080 { - /** - * - if options.compiler is undefined we leave 1**2**3. - * - if options.compiler is lower than 0.8.0 we format as (1**2)**3. - * - if options.compiler is greater than or equal to 0.8.0 we format as - * 1**(2**3). - */ - uint a = 1**2**3; - - /** - * - if options.compiler is undefined or lower than 0.8.0 we enforce the - * use of bytes1. - * - if options.compiler is greater than or equal to 0.8.0 we enforce the - * use of bytes1. - */ - bytes1 public c; - byte public g; - - struct S { - bytes1 c; - byte g; - } - - event Event(bytes1 _c, byte _g); - - function func( - bytes1 _c, - byte _g - ) - public - returns ( - bytes1, - byte - ) - { - emit Event(_c, _g); - return (_c, _g); - } -} - -=====================================output===================================== -contract BreakingChangesV080 { - uint a = 1 ** 2 ** 3; - - bytes1 public c; - byte public g; - - struct S { - bytes1 c; - byte g; - } - - event Event(bytes1 _c, byte _g); - - function func(bytes1 _c, byte _g) public returns (bytes1, byte) { - emit Event(_c, _g); - return (_c, _g); - } -} - -================================================================================ -`; - exports[`BreakingChangesV0.8.0.sol - {"compiler":"0.8.0"} format 1`] = ` ====================================options===================================== compiler: "0.8.0" diff --git a/tests/format/BreakingChangesV0.8.0/jsfmt.spec.js b/tests/format/BreakingChangesV0.8.0/jsfmt.spec.js index 05d7dfd79..037d673ba 100644 --- a/tests/format/BreakingChangesV0.8.0/jsfmt.spec.js +++ b/tests/format/BreakingChangesV0.8.0/jsfmt.spec.js @@ -1,4 +1,3 @@ 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' }); -run_spec(import.meta, ['slang'], { compiler: '0.7.0' }); diff --git a/tests/format/Comments/__snapshots__/jsfmt.spec.js.snap b/tests/format/Comments/__snapshots__/jsfmt.spec.js.snap index a09391adb..8592e9fbb 100644 --- a/tests/format/Comments/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Comments/__snapshots__/jsfmt.spec.js.snap @@ -1,285 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Comments.sol - {"compiler":"0.5.0"} format 1`] = ` -====================================options===================================== -compiler: "0.5.0" -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity ^0.4.24; - - -contract Comments1 { - /* solhint-disable var-name-mixedcase */ -IEIP712DomainSeparator private EIP712domainSeparator; -bytes32 private _CACHED_DOMAIN_SEPARATOR; - - -/* solhint-enable var-name-mixedcase */ - - - function() { - // solhint-disable-previous-line no-empty-blocks - } - - function hello() public modifier1 modifier2 modifier3 modifier4 modifier5 modifier6 { - // solhint-disable-previous-line no-empty-blocks - } -} - - -contract Comments2 { - // solhint-disable-previous-line no-empty-blocks -} - - -contract Comments3 is Interface1, Interface2, Interface3, Interface4, Interface5, Interface6 { - // solhint-disable-previous-line no-empty-blocks - - function someFunction() { - - }/*1*//*2 - */ -} - -contract Comments4 is Interface1, Interface2, Interface3, Interface4, Interface5, Interface6 { - // solhint-disable-previous-line no-empty-blocks -} - -contract Comments5 /*nice name*/ { - // solhint-disable-previous-line no-empty-blocks -} - -contract Comments6 /*why the name \`Comments6\`*/ is Interface1/*why we used Interface1*/, Interface2/*why we used Interface2*/, Interface3, Interface4, Interface5, Interface6 { - // solhint-disable-previous-line no-empty-blocks -} - -contract Comments7 { - - - // 1 comment before first function - - - - // 2 comment before first function - - - - // 3 comment before first function - - function someFunction( - uint a, // the first value - uint b, // the second value - uint c // the lats value - ) { - someFunction( - a, // the first value - b, // the second value - c // the lats value - ); - } -} - -contract Comments8 { - function someFunction() { - if (something) { - } - // comment - else { - } - } -} - - -contract Comments8 { - function someFunction() { - if (something) { - } - /* comment - * comment */ - else { - } - } -} - -contract Comments9 { - function someFunction() { - if (something) - // a comment - f(); - else { - } - } -} - -interface Comments10 { - function someFunction( - // the first value - // the second value - // the lats value - ) /* comment outside the parameters */ external; - - function someOtherFunction(/* checking for Block comment */) external; -} - -contract Comments11 { - string a = "\\\\"; - string b = '\\\\'; - - function f() public { - // this should not be removed - } -} - -contract Comments12 { - function f() public { - purchaseData[0] = DomainPurchaseData({ - /* test */prices: _rootPrices, - // test2 - subdomainMintingEnabled: /* test3 */_rootPrices.short > 0, - allowSubdomainsToMint: true, // test4 - wasAllowedToSubdomainMintOnCreation: true - }); - } -} - -contract Comments13 { - function commentInModifierInvocation() - external - // comment 1 - modifier1 // comment 2 - ( - // comment 3 - ) // comment 4 - // comment 5 - modifier2 // comment 6 - ( - /* comment 7 */ - ) // comment 8 - modifier3 // comment 9 - ( - // comment 10 - param1 // comment 11 - // comment 12 - ) // comment 13 - { - } -} -=====================================output===================================== -pragma solidity ^0.4.24; - -contract Comments1 { - IEIP712DomainSeparator private EIP712domainSeparator; - bytes32 private _CACHED_DOMAIN_SEPARATOR; - - function() {} - - function hello() - public - modifier1 - modifier2 - modifier3 - modifier4 - modifier5 - modifier6 - {} -} - -contract Comments2 {} - -contract Comments3 is - Interface1, - Interface2, - Interface3, - Interface4, - Interface5, - Interface6 -{ - function someFunction() {} -} - -contract Comments4 is - Interface1, - Interface2, - Interface3, - Interface4, - Interface5, - Interface6 -{} - -contract Comments5 {} - -contract Comments6 is - Interface1, - Interface2, - Interface3, - Interface4, - Interface5, - Interface6 -{} - -contract Comments7 { - function someFunction(uint a, uint b, uint c) { - someFunction(a, b, c); - } -} - -contract Comments8 { - function someFunction() { - if (something) {} else {} - } -} - -contract Comments8 { - function someFunction() { - if (something) {} else {} - } -} - -contract Comments9 { - function someFunction() { - if (something) f(); - else {} - } -} - -interface Comments10 { - function someFunction() external; - - function someOtherFunction() external; -} - -contract Comments11 { - string a = "\\\\"; - string b = "\\\\"; - - function f() public {} -} - -contract Comments12 { - function f() public { - purchaseData[0] = DomainPurchaseData({ - prices: _rootPrices, - subdomainMintingEnabled: _rootPrices.short > 0, - allowSubdomainsToMint: true, - wasAllowedToSubdomainMintOnCreation: true - }); - } -} - -contract Comments13 { - function commentInModifierInvocation() - external - modifier1() - modifier2() - modifier3(param1) - {} -} - -================================================================================ -`; - exports[`Comments.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] diff --git a/tests/format/Comments/jsfmt.spec.js b/tests/format/Comments/jsfmt.spec.js index feedd0559..765dd60a6 100644 --- a/tests/format/Comments/jsfmt.spec.js +++ b/tests/format/Comments/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang'], { compiler: '0.5.0' }); diff --git a/tests/format/Conditional/__snapshots__/jsfmt.spec.js.snap b/tests/format/Conditional/__snapshots__/jsfmt.spec.js.snap index be88f9435..e74eccfaf 100644 --- a/tests/format/Conditional/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Conditional/__snapshots__/jsfmt.spec.js.snap @@ -78,77 +78,3 @@ contract Conditional { ================================================================================ `; - -exports[`Conditional.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity ^0.4.24; - - -contract Conditional { - function foo() { - address contextAddress = longAddress_ == address(0) ? msg.sender : currentContextAddress_; - asset == ETH - ? require(address(uint160(msg.sender)).send(quantity), "failed to transfer ether") // explicit casting to \`address payable\` - : transferTokensToAccountSecurely(Token(asset), quantity, msg.sender); - asset == ETH - ? true - : transferTokensToAccountSecurely(Token(asset), quantity, msg.sender); - asset == ETH - ? require(address(uint160(msg.sender)).send(quantity), "failed to transfer ether") - : false; - } - - // TODO: work with a break in the condition level. - // function foo() { - // address contextAddress = veryVeryVeryVeryVeryVeryVeryVeryVeryLongAddress_ == address(0) ? msg.sender : currentContextAddress_; - // } - - function bar() { - uint a = true ? 0 : 1; - } -} - -=====================================output===================================== -pragma solidity ^0.4.24; - -contract Conditional { - function foo() { - address contextAddress = longAddress_ == address(0) - ? msg.sender - : currentContextAddress_; - asset == ETH - ? require( - address(uint160(msg.sender)).send(quantity), - "failed to transfer ether" - ) - : transferTokensToAccountSecurely( - Token(asset), - quantity, - msg.sender - ); - asset == ETH - ? true - : transferTokensToAccountSecurely( - Token(asset), - quantity, - msg.sender - ); - asset == ETH - ? require( - address(uint160(msg.sender)).send(quantity), - "failed to transfer ether" - ) - : false; - } - - function bar() { - uint a = true ? 0 : 1; - } -} - -================================================================================ -`; diff --git a/tests/format/Conditional/jsfmt.spec.js b/tests/format/Conditional/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/Conditional/jsfmt.spec.js +++ b/tests/format/Conditional/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); diff --git a/tests/format/Constructors/__snapshots__/jsfmt.spec.js.snap b/tests/format/Constructors/__snapshots__/jsfmt.spec.js.snap index 24d928a6b..08733dfa7 100644 --- a/tests/format/Constructors/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Constructors/__snapshots__/jsfmt.spec.js.snap @@ -49,53 +49,3 @@ contract Constructors is Ownable, Changeable { ================================================================================ `; - -exports[`Constructors.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity ^0.5.2; - -contract Constructors is Ownable, Changeable { - function Constructors(variable1) public Changeable(variable1) Ownable() onlyOwner { - } - - constructor(variable1, variable2, variable3, variable4, variable5, variable6, variable7) public Changeable(variable1, variable2, variable3, variable4, variable5, variable6, variable7) Ownable() onlyOwner {} -} - -=====================================output===================================== -pragma solidity ^0.5.2; - -contract Constructors is Ownable, Changeable { - function Constructors( - variable1 - ) public Changeable(variable1) Ownable() onlyOwner {} - - constructor( - variable1, - variable2, - variable3, - variable4, - variable5, - variable6, - variable7 - ) - public - Changeable( - variable1, - variable2, - variable3, - variable4, - variable5, - variable6, - variable7 - ) - Ownable() - onlyOwner - {} -} - -================================================================================ -`; diff --git a/tests/format/Constructors/jsfmt.spec.js b/tests/format/Constructors/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/Constructors/jsfmt.spec.js +++ b/tests/format/Constructors/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); diff --git a/tests/format/ContractDefinitions/__snapshots__/jsfmt.spec.js.snap b/tests/format/ContractDefinitions/__snapshots__/jsfmt.spec.js.snap index d53ac9044..1621683a4 100644 --- a/tests/format/ContractDefinitions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/ContractDefinitions/__snapshots__/jsfmt.spec.js.snap @@ -20,24 +20,3 @@ contract ContractDefinition is ================================================================================ `; - -exports[`ContractDefinitions.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -contract ContractDefinition is Contract1, Contract2, Contract3, Contract4, Contract5 { -} - -=====================================output===================================== -contract ContractDefinition is - Contract1, - Contract2, - Contract3, - Contract4, - Contract5 -{} - -================================================================================ -`; diff --git a/tests/format/ContractDefinitions/jsfmt.spec.js b/tests/format/ContractDefinitions/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/ContractDefinitions/jsfmt.spec.js +++ b/tests/format/ContractDefinitions/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); diff --git a/tests/format/CustomErrors/__snapshots__/jsfmt.spec.js.snap b/tests/format/CustomErrors/__snapshots__/jsfmt.spec.js.snap index b5eb560c4..85f94cb7f 100644 --- a/tests/format/CustomErrors/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/CustomErrors/__snapshots__/jsfmt.spec.js.snap @@ -48,52 +48,3 @@ contract CustomErrors { ================================================================================ `; - -exports[`CustomErrors.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity ^0.8.4; - -error - TopLevelCustomError(); - error TopLevelCustomErrorWithArg(uint x) ; -error TopLevelCustomErrorArgWithoutName (string); - -contract CustomErrors { - error - ContractCustomError(); - error ContractCustomErrorWithArg(uint x) ; - error ContractCustomErrorArgWithoutName (string); - - function throwCustomError() { - revert - FunctionCustomError(); - revert FunctionCustomErrorWithArg( 1 ) ; - revert FunctionCustomErrorArgWithoutName ( "a reason"); - } -} - -=====================================output===================================== -pragma solidity ^0.8.4; - -error TopLevelCustomError(); -error TopLevelCustomErrorWithArg(uint x); -error TopLevelCustomErrorArgWithoutName(string); - -contract CustomErrors { - error ContractCustomError(); - error ContractCustomErrorWithArg(uint x); - error ContractCustomErrorArgWithoutName(string); - - function throwCustomError() { - revert FunctionCustomError(); - revert FunctionCustomErrorWithArg(1); - revert FunctionCustomErrorArgWithoutName("a reason"); - } -} - -================================================================================ -`; diff --git a/tests/format/CustomErrors/jsfmt.spec.js b/tests/format/CustomErrors/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/CustomErrors/jsfmt.spec.js +++ b/tests/format/CustomErrors/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); diff --git a/tests/format/EnumDefinitions/__snapshots__/jsfmt.spec.js.snap b/tests/format/EnumDefinitions/__snapshots__/jsfmt.spec.js.snap index 7f7dbf256..64735676e 100644 --- a/tests/format/EnumDefinitions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/EnumDefinitions/__snapshots__/jsfmt.spec.js.snap @@ -34,38 +34,3 @@ contract EnumDefinitions { ================================================================================ `; - -exports[`EnumDefinitions.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -contract EnumDefinitions { - enum ActionChoices { GoLeft, GoRight, GoStraight, SitStill } - enum States { State1, State2, State3, State4, State5, State6, State7, State8, State9 } -} - -=====================================output===================================== -contract EnumDefinitions { - enum ActionChoices { - GoLeft, - GoRight, - GoStraight, - SitStill - } - enum States { - State1, - State2, - State3, - State4, - State5, - State6, - State7, - State8, - State9 - } -} - -================================================================================ -`; diff --git a/tests/format/EnumDefinitions/jsfmt.spec.js b/tests/format/EnumDefinitions/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/EnumDefinitions/jsfmt.spec.js +++ b/tests/format/EnumDefinitions/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); diff --git a/tests/format/Etc/__snapshots__/jsfmt.spec.js.snap b/tests/format/Etc/__snapshots__/jsfmt.spec.js.snap index bbaeafde0..6662b381e 100644 --- a/tests/format/Etc/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Etc/__snapshots__/jsfmt.spec.js.snap @@ -132,137 +132,3 @@ contract Contract { ================================================================================ `; - -exports[`Etc.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity ^0.4.24; - -// line comment - -/* - Block comment -*/ - -contract Contract { - struct StructWithFunctionTypes { - function (uint, uint) returns(bool)a; - function (uint, uint) returns(bool,bytes32, bytes32, bytes32, bytes32, bytes32, bytes32, bytes32)a; - function(bytes32, bytes32) internal view[] b; - function (bytes32, bytes32)internal[] c; - function(bytes32, bytes32, bytes32, bytes32, bytes32, bytes32) internal view[] d; - function(bytes32, bytes32, bytes32, bytes32, bytes32, bytes32, bytes32, bytes32, bytes32) internal view[] e; - } - - event SomeEvent(); - - modifier modifierWithoutParams() { - require(msg.sender != address(0)); - _; - } - - modifier modifierWithParams(address x) { - require(msg.sender != x); - _; - } - - function ifBlockInOneLine(uint a) returns (uint b) { - if (a < 0) b = 0x67; else if (a == 0) b = 0x12; else b = 0x78; - } - - function forWithoutBlock() { - uint i; - uint sum; - for ( i = 0; i < 10; i++ ) sum += i; - } - - function fun(uint256 a) returns (uint) { - if (something) foo(); - // comment - else if (somethingElse) bar(); - else whatever(); - return; - } -} - -=====================================output===================================== -pragma solidity ^0.4.24; - -contract Contract { - struct StructWithFunctionTypes { - function (uint, uint) returns (bool) a; - function ( - uint, - uint - ) - returns ( - bool, - bytes32, - bytes32, - bytes32, - bytes32, - bytes32, - bytes32, - bytes32 - ) - a; - function (bytes32, bytes32) internal view [] b; - function (bytes32, bytes32) internal [] c; - function ( - bytes32, - bytes32, - bytes32, - bytes32, - bytes32, - bytes32 - ) internal view [] d; - function ( - bytes32, - bytes32, - bytes32, - bytes32, - bytes32, - bytes32, - bytes32, - bytes32, - bytes32 - ) internal view [] e; - } - - event SomeEvent(); - - modifier modifierWithoutParams() { - require(msg.sender != address(0)); - _; - } - - modifier modifierWithParams(address x) { - require(msg.sender != x); - _; - } - - function ifBlockInOneLine(uint a) returns (uint b) { - if (a < 0) b = 0x67; - else if (a == 0) b = 0x12; - else b = 0x78; - } - - function forWithoutBlock() { - uint i; - uint sum; - for (i = 0; i < 10; i++) sum += i; - } - - function fun(uint256 a) returns (uint) { - if (something) foo(); - else if (somethingElse) bar(); - else whatever(); - return; - } -} - -================================================================================ -`; diff --git a/tests/format/Etc/jsfmt.spec.js b/tests/format/Etc/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/Etc/jsfmt.spec.js +++ b/tests/format/Etc/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); diff --git a/tests/format/ExperimentalTernaries/__snapshots__/jsfmt.spec.js.snap b/tests/format/ExperimentalTernaries/__snapshots__/jsfmt.spec.js.snap index b81ab698a..a290e72ad 100644 --- a/tests/format/ExperimentalTernaries/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/ExperimentalTernaries/__snapshots__/jsfmt.spec.js.snap @@ -510,12 +510,12 @@ contract Conditional { ================================================================================ `; -exports[`ExperimentalTernaries.sol - {"experimentalTernaries":true,"tabWidth":1} format 2`] = ` +exports[`ExperimentalTernaries.sol - {"experimentalTernaries":true,"useTabs":true} format 1`] = ` ====================================options===================================== experimentalTernaries: true -parsers: ["slang"] +parsers: ["solidity-parse"] printWidth: 80 -tabWidth: 1 +useTabs: true | printWidth =====================================input====================================== pragma solidity ^0.4.24; @@ -772,2205 +772,261 @@ string storage typeofExampleFlipped = pragma solidity ^0.4.24; contract Conditional { - function blogPostExample() { - string storage animalName = pet.canBark() ? - pet.isScary() ? - "wolf" - : "dog" - : pet.canMeow() ? "cat" - : "probably a bunny"; - - string storage animalName = pet.isScary() ? "wolf" - : pet.canBark() ? "dog" - : pet.canMeow() ? "cat" - : "probably a bunny"; - - string storage animalName = pet.canSqueak() ? "mouse" - : pet.canBark() ? - pet.isScary() ? - "wolf" - : "dog" - : pet.canMeow() ? "cat" - : pet.canSqueak() ? "mouse" - : "probably a bunny"; - } - - function examples1() { - string storage short = isLoud() ? makeNoise() : silent(); - - string storage lessShort = isLoudReallyLoud() ? - makeNoiseReallyLoudly.omgSoLoud() - : silent(); + function blogPostExample() { + // "curious" ternaries + string storage animalName = + pet.canBark() ? + pet.isScary() ? + "wolf" + : "dog" + : pet.canMeow() ? "cat" + : "probably a bunny"; - string storage andIndented = isLoudReallyReallyReallyReallyLoud() ? - makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() - : silent(); + // "case-style" ternaries + string storage animalName = + pet.isScary() ? "wolf" + : pet.canBark() ? "dog" + : pet.canMeow() ? "cat" + : "probably a bunny"; - string storage indentationInFalseExpression = ( - isLoudReallyReallyReallyReallyLoud() - ) ? - makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); + // fluidity between "case-style" and "curious" ternaries + string storage animalName = + pet.canSqueak() ? "mouse" + : pet.canBark() ? + pet.isScary() ? + "wolf" + : "dog" + : pet.canMeow() ? "cat" + : pet.canSqueak() ? "mouse" + : "probably a bunny"; + } - string storage shortSoCase = isLoudReallyReallyReallyReallyLoud() ? - silent() - : (makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud()); + function examples1() { + // remain on one line if possible: + string storage short = isLoud() ? makeNoise() : silent(); - string storage chainedShort = isCat() ? meow() - : isDog() ? bark() - : silent(); + // next, put everything after the = + string storage lessShort = + isLoudReallyLoud() ? makeNoiseReallyLoudly.omgSoLoud() : silent(); - string storage chainedWithLongConsequent = isCat() ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : isDog() ? bark() - : silent(); + // next, indent the consequent: + string storage andIndented = + isLoudReallyReallyReallyReallyLoud() ? + makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() + : silent(); - string storage chainedWithTernaryConsequent = isCat() ? - aNestedCondition ? - theResult() - : theAlternate() - : isDog() ? bark() - : silent(); + // if we need to add spaces to the falseExpression to fill a tab, we indent it as well: + string storage indentationInFalseExpression = + isLoudReallyReallyReallyReallyLoud() ? + makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); - string storage consequentAndTerminalAlternateBreak = isCat() ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : isDog() ? bark() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); + // unless the consequent is short (less than ten characters long): + string storage shortSoCase = + isLoudReallyReallyReallyReallyLoud() ? silent() + : (makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud()); - string storage multilineConditionsConsequentsAndAlternates = ( - isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : ( - isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - bark() - : shortCondition() ? shortConsequent() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); + // if chained, always break and put after the = + string storage chainedShort = + isCat() ? meow() + : isDog() ? bark() + : silent(); - assignment = ( - isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : ( - isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - bark() - : shortCondition() ? shortConsequent() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); + // when a consequent breaks in a chain: + string storage chainedWithLongConsequent = + isCat() ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : isDog() ? bark() + : silent(); - string storage mostlyShort = x == 1 ? "one" - : x == 2 ? "two" - : x == 3 ? "three" - : ( - x == 5 && - y == 7 && - someOtherThing.thatIsSoLong.thatItBreaksTheTestCondition() - ) ? - "four" - : x == 6 ? "six" - : "idk"; - - string storage longConditional = ( - bifornCringerMoshedPerplexSawder == 2 / askTrovenaBeenaDependsRowans && - glimseGlyphsHazardNoopsTieTie >= - averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() - ) ? - "foo" - : "bar"; + // nested ternary in consequent always breaks: + string storage chainedWithTernaryConsequent = + isCat() ? + aNestedCondition ? + theResult() + : theAlternate() + : isDog() ? bark() + : silent(); - string storage longConditionalChained = ( - bifornCringerMoshedPerplexSawder == 2 / askTrovenaBeenaDependsRowans && - glimseGlyphsHazardNoopsTieTie >= - averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() - ) ? - "foo" - : anotherCondition ? "bar" - : "baz"; + // consequent and terminal alternate break: + string storage consequentAndTerminalAlternateBreak = + isCat() ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : isDog() ? bark() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); - definition.encode( - row[field] != "undefined" ? row[field] - : definition.defaults != "undefined" ? definition.defaults - : "null", - row[field] == "undefined" ? - definition.defaults == "undefined" ? - "null" - : definition.defaults - : row[field] - ); + // multiline conditions and consequents/alternates: + string storage multilineConditionsConsequentsAndAlternates = + ( + isAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : ( + isNotAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + bark() + : shortCondition() ? shortConsequent() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); - (foo ? 1 : bar) ? 3 : 4; - ( - isCat() ? meow() - : isDog() ? bark() - : silent() - ) ? - 1 - : 2; + // Assignment also groups and indents as Variable Declaration: + assignment = ( + isAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : ( + isNotAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + bark() + : shortCondition() ? shortConsequent() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); - if (short) { - return foo ? 1 : 2; - } - return row[aVeryLongFieldName] != "undefined" ? row[aVeryLongFieldName] - : "null"; - } + // illustrating case of mostly short conditionals + string storage mostlyShort = + x == 1 ? "one" + : x == 2 ? "two" + : x == 3 ? "three" + : ( + x == 5 && + y == 7 && + someOtherThing.thatIsSoLong.thatItBreaksTheTestCondition() + ) ? + "four" + : x == 6 ? "six" + : "idk"; - function examples2() { - string storage message = i % 3 == 0 && i % 5 == 0 ? "fizzbuzz" - : i % 3 == 0 ? "fizz" - : i % 5 == 0 ? "buzz" - : String(i); + // long conditional, short consequent/alternate, not chained - do indent after ? + string storage longConditional = + ( + bifornCringerMoshedPerplexSawder == + 2 / askTrovenaBeenaDependsRowans && + glimseGlyphsHazardNoopsTieTie >= + averredBathersBoxroomBuggyNurl() + .anodyneCondosMalateOverateRetinol() + ) ? + "foo" + : "bar"; - string storage paymentMessageShort = state == "success" ? - "Payment completed successfully" - : state == "processing" ? "Payment processing" - : state == "invalid_cvc" ? "There was an issue with your CVC number" - : state == "invalid_expiry" ? "Expiry must be sometime in the past." - : "There was an issue with the payment. Please contact support."; + // long conditional, short consequent/alternate, chained + // (break on short consequents iff in chained ternary and its conditional broke) + string storage longConditionalChained = + ( + bifornCringerMoshedPerplexSawder == + 2 / askTrovenaBeenaDependsRowans && + glimseGlyphsHazardNoopsTieTie >= + averredBathersBoxroomBuggyNurl() + .anodyneCondosMalateOverateRetinol() + ) ? + "foo" + : anotherCondition ? "bar" + : "baz"; - string storage paymentMessageWithABreak = state == "success" ? - "Payment completed successfully" - : state == "processing" ? "Payment processing" - : state == "invalid_cvc" ? - "There was an issue with your CVC number, and you need to take a prompt action on it." - : state == "invalid_expiry" ? "Expiry must be sometime in the past." - : "There was an issue with the payment. Please contact support."; + // As a function parameter, don't add an extra indent: + definition.encode( + row[field] != "undefined" ? row[field] + : definition.defaults != "undefined" ? definition.defaults + : "null", + row[field] == "undefined" ? + definition.defaults == "undefined" ? + "null" + : definition.defaults + : row[field] + ); - string storage typeofExample = definition.encode ? - definition.encode( - row[field] != "undefined" ? row[field] - : definition.defaults != "undefined" ? definition.defaults - : "null" - ) - : row[field] != "undefined" ? row[field] - : definition.defaults != "undefined" ? definition.defaults - : "null"; - - string storage typeofExampleFlipped = definition.encode ? - definition.encode( - row[field] == "undefined" ? - definition.defaults == "undefined" ? - "null" - : definition.defaults - : row[field] - ) - : row[field] == "undefined" ? - definition.defaults == "undefined" ? - "null" - : definition.defaults - : row[field]; - } -} - -================================================================================ -`; - -exports[`ExperimentalTernaries.sol - {"experimentalTernaries":true,"useTabs":true} format 1`] = ` -====================================options===================================== -experimentalTernaries: true -parsers: ["solidity-parse"] -printWidth: 80 -useTabs: true - | printWidth -=====================================input====================================== -pragma solidity ^0.4.24; - - -contract Conditional { - function blogPostExample() { - // "curious" ternaries - string storage animalName = - pet.canBark() ? - pet.isScary() ? - 'wolf' - : 'dog' - : pet.canMeow() ? - 'cat' - : 'probably a bunny'; - - // "case-style" ternaries - string storage animalName = - pet.isScary() ? 'wolf' - : pet.canBark() ? 'dog' - : pet.canMeow() ? 'cat' - : 'probably a bunny'; - - // fluidity between "case-style" and "curious" ternaries - string storage animalName = - pet.canSqueak() ? 'mouse' - : pet.canBark() ? - pet.isScary() ? - 'wolf' - : 'dog' - : pet.canMeow() ? 'cat' - : pet.canSqueak() ? 'mouse' - : 'probably a bunny'; - } - - function examples1() { - // remain on one line if possible: - string storage short = isLoud() ? makeNoise() : silent(); - - // next, put everything after the = - string storage lessShort = - isLoudReallyLoud() ? makeNoiseReallyLoudly.omgSoLoud() : silent(); - - // next, indent the consequent: - string storage andIndented = - isLoudReallyReallyReallyReallyLoud() ? - makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() - : silent(); - - // if we need to add spaces to the falseExpression to fill a tab, we indent it as well: - string storage indentationInFalseExpression = - isLoudReallyReallyReallyReallyLoud() ? - makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); - - // unless the consequent is short (less than ten characters long): - string storage shortSoCase = - isLoudReallyReallyReallyReallyLoud() ? silent() : ( - makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() - ); - - // if chained, always break and put after the = - string storage chainedShort = - isCat() ? meow() - : isDog() ? bark() - : silent(); - - // when a consequent breaks in a chain: - string storage chainedWithLongConsequent = - isCat() ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : isDog() ? bark() - : silent(); - - // nested ternary in consequent always breaks: - string storage chainedWithTernaryConsequent = - isCat() ? - aNestedCondition ? theResult() - : theAlternate() - : isDog() ? bark() - : silent(); - - // consequent and terminal alternate break: - string storage consequentAndTerminalAlternateBreak = - isCat() ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : isDog() ? bark() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); - - // multiline conditions and consequents/alternates: - string storage multilineConditionsConsequentsAndAlternates = - ( - isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : ( - isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - bark() - : shortCondition() ? shortConsequent() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); - - // Assignment also groups and indents as Variable Declaration: - assignment = - ( - isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : ( - isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - bark() - : shortCondition() ? shortConsequent() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); - - // illustrating case of mostly short conditionals - string storage mostlyShort = - x == 1 ? "one" - : x == 2 ? "two" - : x == 3 ? "three" - : ( - x == 5 && - y == 7 && - someOtherThing.thatIsSoLong.thatItBreaksTheTestCondition() - ) ? - "four" - : x == 6 ? "six" - : "idk"; - - // long conditional, short consequent/alternate, not chained - do indent after ? - string storage longConditional = - ( - bifornCringerMoshedPerplexSawder == 2 / askTrovenaBeenaDependsRowans && - glimseGlyphsHazardNoopsTieTie >= - averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() - ) ? - "foo" - : "bar"; - - // long conditional, short consequent/alternate, chained - // (break on short consequents iff in chained ternary and its conditional broke) - string storage longConditionalChained = - ( - bifornCringerMoshedPerplexSawder == 2 / askTrovenaBeenaDependsRowans && - glimseGlyphsHazardNoopsTieTie >= - averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() - ) ? - "foo" - : anotherCondition ? "bar" - : "baz"; - - // As a function parameter, don't add an extra indent: - definition.encode( - row[field] != "undefined" ? row[field] - : definition.defaults != "undefined" ? definition.defaults - : "null", - row[field] == "undefined" ? - definition.defaults == "undefined" ? - "null" - : definition.defaults - : row[field] - ); - - // Conditional as a condition - (((foo ? 1 : bar))) ? 3 : 4; - (isCat() ? meow() - : isDog() ? bark() - : silent()) ? 1: 2; - - // In a return, break and over-indent: - if (short) { - return foo ? 1 : 2; - } - return row[aVeryLongFieldName] != "undefined" ? - row[aVeryLongFieldName] - : "null"; - } - - - function examples2() {string storage message = - i % 3 == 0 && i % 5 == 0 ? "fizzbuzz" - : i % 3 == 0 ? "fizz" - : i % 5 == 0 ? "buzz" - : String(i); - -string storage paymentMessageShort = - state == "success" ? "Payment completed successfully" - : state == "processing" ? "Payment processing" - : state == "invalid_cvc" ? "There was an issue with your CVC number" - : state == "invalid_expiry" ? "Expiry must be sometime in the past." - : "There was an issue with the payment. Please contact support."; - -string storage paymentMessageWithABreak = - state == "success" ? "Payment completed successfully" - : state == "processing" ? "Payment processing" - : state == "invalid_cvc" ? - "There was an issue with your CVC number, and you need to take a prompt action on it." - : state == "invalid_expiry" ? "Expiry must be sometime in the past." - : "There was an issue with the payment. Please contact support."; - -string storage typeofExample = - definition.encode ? - definition.encode( - row[field] != "undefined" ? row[field] - : definition.defaults != "undefined" ? definition.defaults - : "null" - ) - : row[field] != "undefined" ? row[field] - : definition.defaults != "undefined" ? definition.defaults - : "null"; - -// (the following is semantically equivalent to the above, but written in a more-confusing style – it'd be hard to grok no matter the formatting) -string storage typeofExampleFlipped = - definition.encode ? - definition.encode( - row[field] == "undefined" ? - definition.defaults == "undefined" ? - "null" - : definition.defaults - : row[field] - ) - : row[field] == "undefined" ? - definition.defaults == "undefined" ? - "null" - : definition.defaults - : row[field]; - } -} - - - -=====================================output===================================== -pragma solidity ^0.4.24; - -contract Conditional { - function blogPostExample() { - // "curious" ternaries - string storage animalName = - pet.canBark() ? - pet.isScary() ? - "wolf" - : "dog" - : pet.canMeow() ? "cat" - : "probably a bunny"; - - // "case-style" ternaries - string storage animalName = - pet.isScary() ? "wolf" - : pet.canBark() ? "dog" - : pet.canMeow() ? "cat" - : "probably a bunny"; - - // fluidity between "case-style" and "curious" ternaries - string storage animalName = - pet.canSqueak() ? "mouse" - : pet.canBark() ? - pet.isScary() ? - "wolf" - : "dog" - : pet.canMeow() ? "cat" - : pet.canSqueak() ? "mouse" - : "probably a bunny"; - } - - function examples1() { - // remain on one line if possible: - string storage short = isLoud() ? makeNoise() : silent(); - - // next, put everything after the = - string storage lessShort = - isLoudReallyLoud() ? makeNoiseReallyLoudly.omgSoLoud() : silent(); - - // next, indent the consequent: - string storage andIndented = - isLoudReallyReallyReallyReallyLoud() ? - makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() - : silent(); - - // if we need to add spaces to the falseExpression to fill a tab, we indent it as well: - string storage indentationInFalseExpression = - isLoudReallyReallyReallyReallyLoud() ? - makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); - - // unless the consequent is short (less than ten characters long): - string storage shortSoCase = - isLoudReallyReallyReallyReallyLoud() ? silent() - : (makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud()); - - // if chained, always break and put after the = - string storage chainedShort = - isCat() ? meow() - : isDog() ? bark() - : silent(); - - // when a consequent breaks in a chain: - string storage chainedWithLongConsequent = - isCat() ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : isDog() ? bark() - : silent(); - - // nested ternary in consequent always breaks: - string storage chainedWithTernaryConsequent = - isCat() ? - aNestedCondition ? - theResult() - : theAlternate() - : isDog() ? bark() - : silent(); - - // consequent and terminal alternate break: - string storage consequentAndTerminalAlternateBreak = - isCat() ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : isDog() ? bark() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); - - // multiline conditions and consequents/alternates: - string storage multilineConditionsConsequentsAndAlternates = - ( - isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : ( - isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - bark() - : shortCondition() ? shortConsequent() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); - - // Assignment also groups and indents as Variable Declaration: - assignment = ( - isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : ( - isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - bark() - : shortCondition() ? shortConsequent() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); - - // illustrating case of mostly short conditionals - string storage mostlyShort = - x == 1 ? "one" - : x == 2 ? "two" - : x == 3 ? "three" - : ( - x == 5 && - y == 7 && - someOtherThing.thatIsSoLong.thatItBreaksTheTestCondition() - ) ? - "four" - : x == 6 ? "six" - : "idk"; - - // long conditional, short consequent/alternate, not chained - do indent after ? - string storage longConditional = - ( - bifornCringerMoshedPerplexSawder == - 2 / askTrovenaBeenaDependsRowans && - glimseGlyphsHazardNoopsTieTie >= - averredBathersBoxroomBuggyNurl() - .anodyneCondosMalateOverateRetinol() - ) ? - "foo" - : "bar"; - - // long conditional, short consequent/alternate, chained - // (break on short consequents iff in chained ternary and its conditional broke) - string storage longConditionalChained = - ( - bifornCringerMoshedPerplexSawder == - 2 / askTrovenaBeenaDependsRowans && - glimseGlyphsHazardNoopsTieTie >= - averredBathersBoxroomBuggyNurl() - .anodyneCondosMalateOverateRetinol() - ) ? - "foo" - : anotherCondition ? "bar" - : "baz"; - - // As a function parameter, don't add an extra indent: - definition.encode( - row[field] != "undefined" ? row[field] - : definition.defaults != "undefined" ? definition.defaults - : "null", - row[field] == "undefined" ? - definition.defaults == "undefined" ? - "null" - : definition.defaults - : row[field] - ); - - // Conditional as a condition - (foo ? 1 : bar) ? 3 : 4; - ( - isCat() ? meow() - : isDog() ? bark() - : silent() - ) ? - 1 - : 2; - - // In a return, break and over-indent: - if (short) { - return foo ? 1 : 2; - } - return row[aVeryLongFieldName] != "undefined" ? row[aVeryLongFieldName] - : "null"; - } - - function examples2() { - string storage message = - i % 3 == 0 && i % 5 == 0 ? "fizzbuzz" - : i % 3 == 0 ? "fizz" - : i % 5 == 0 ? "buzz" - : String(i); - - string storage paymentMessageShort = - state == "success" ? "Payment completed successfully" - : state == "processing" ? "Payment processing" - : state == "invalid_cvc" ? "There was an issue with your CVC number" - : state == "invalid_expiry" ? "Expiry must be sometime in the past." - : "There was an issue with the payment. Please contact support."; - - string storage paymentMessageWithABreak = - state == "success" ? "Payment completed successfully" - : state == "processing" ? "Payment processing" - : state == "invalid_cvc" ? - "There was an issue with your CVC number, and you need to take a prompt action on it." - : state == "invalid_expiry" ? "Expiry must be sometime in the past." - : "There was an issue with the payment. Please contact support."; - - string storage typeofExample = - definition.encode ? - definition.encode( - row[field] != "undefined" ? row[field] - : definition.defaults != "undefined" ? definition.defaults - : "null" - ) - : row[field] != "undefined" ? row[field] - : definition.defaults != "undefined" ? definition.defaults - : "null"; - - // (the following is semantically equivalent to the above, but written in a more-confusing style – it'd be hard to grok no matter the formatting) - string storage typeofExampleFlipped = - definition.encode ? - definition.encode( - row[field] == "undefined" ? - definition.defaults == "undefined" ? - "null" - : definition.defaults - : row[field] - ) - : row[field] == "undefined" ? - definition.defaults == "undefined" ? - "null" - : definition.defaults - : row[field]; - } -} - -================================================================================ -`; - -exports[`ExperimentalTernaries.sol - {"experimentalTernaries":true,"useTabs":true} format 2`] = ` -====================================options===================================== -experimentalTernaries: true -parsers: ["slang"] -printWidth: 80 -useTabs: true - | printWidth -=====================================input====================================== -pragma solidity ^0.4.24; - - -contract Conditional { - function blogPostExample() { - // "curious" ternaries - string storage animalName = - pet.canBark() ? - pet.isScary() ? - 'wolf' - : 'dog' - : pet.canMeow() ? - 'cat' - : 'probably a bunny'; - - // "case-style" ternaries - string storage animalName = - pet.isScary() ? 'wolf' - : pet.canBark() ? 'dog' - : pet.canMeow() ? 'cat' - : 'probably a bunny'; - - // fluidity between "case-style" and "curious" ternaries - string storage animalName = - pet.canSqueak() ? 'mouse' - : pet.canBark() ? - pet.isScary() ? - 'wolf' - : 'dog' - : pet.canMeow() ? 'cat' - : pet.canSqueak() ? 'mouse' - : 'probably a bunny'; - } - - function examples1() { - // remain on one line if possible: - string storage short = isLoud() ? makeNoise() : silent(); - - // next, put everything after the = - string storage lessShort = - isLoudReallyLoud() ? makeNoiseReallyLoudly.omgSoLoud() : silent(); - - // next, indent the consequent: - string storage andIndented = - isLoudReallyReallyReallyReallyLoud() ? - makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() - : silent(); - - // if we need to add spaces to the falseExpression to fill a tab, we indent it as well: - string storage indentationInFalseExpression = - isLoudReallyReallyReallyReallyLoud() ? - makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); - - // unless the consequent is short (less than ten characters long): - string storage shortSoCase = - isLoudReallyReallyReallyReallyLoud() ? silent() : ( - makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() - ); - - // if chained, always break and put after the = - string storage chainedShort = - isCat() ? meow() - : isDog() ? bark() - : silent(); - - // when a consequent breaks in a chain: - string storage chainedWithLongConsequent = - isCat() ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : isDog() ? bark() - : silent(); - - // nested ternary in consequent always breaks: - string storage chainedWithTernaryConsequent = - isCat() ? - aNestedCondition ? theResult() - : theAlternate() - : isDog() ? bark() - : silent(); - - // consequent and terminal alternate break: - string storage consequentAndTerminalAlternateBreak = - isCat() ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : isDog() ? bark() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); - - // multiline conditions and consequents/alternates: - string storage multilineConditionsConsequentsAndAlternates = - ( - isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : ( - isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - bark() - : shortCondition() ? shortConsequent() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); - - // Assignment also groups and indents as Variable Declaration: - assignment = - ( - isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : ( - isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - bark() - : shortCondition() ? shortConsequent() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); - - // illustrating case of mostly short conditionals - string storage mostlyShort = - x == 1 ? "one" - : x == 2 ? "two" - : x == 3 ? "three" - : ( - x == 5 && - y == 7 && - someOtherThing.thatIsSoLong.thatItBreaksTheTestCondition() - ) ? - "four" - : x == 6 ? "six" - : "idk"; - - // long conditional, short consequent/alternate, not chained - do indent after ? - string storage longConditional = - ( - bifornCringerMoshedPerplexSawder == 2 / askTrovenaBeenaDependsRowans && - glimseGlyphsHazardNoopsTieTie >= - averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() - ) ? - "foo" - : "bar"; - - // long conditional, short consequent/alternate, chained - // (break on short consequents iff in chained ternary and its conditional broke) - string storage longConditionalChained = - ( - bifornCringerMoshedPerplexSawder == 2 / askTrovenaBeenaDependsRowans && - glimseGlyphsHazardNoopsTieTie >= - averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() - ) ? - "foo" - : anotherCondition ? "bar" - : "baz"; - - // As a function parameter, don't add an extra indent: - definition.encode( - row[field] != "undefined" ? row[field] - : definition.defaults != "undefined" ? definition.defaults - : "null", - row[field] == "undefined" ? - definition.defaults == "undefined" ? - "null" - : definition.defaults - : row[field] - ); - - // Conditional as a condition - (((foo ? 1 : bar))) ? 3 : 4; - (isCat() ? meow() - : isDog() ? bark() - : silent()) ? 1: 2; - - // In a return, break and over-indent: - if (short) { - return foo ? 1 : 2; - } - return row[aVeryLongFieldName] != "undefined" ? - row[aVeryLongFieldName] - : "null"; - } - - - function examples2() {string storage message = - i % 3 == 0 && i % 5 == 0 ? "fizzbuzz" - : i % 3 == 0 ? "fizz" - : i % 5 == 0 ? "buzz" - : String(i); - -string storage paymentMessageShort = - state == "success" ? "Payment completed successfully" - : state == "processing" ? "Payment processing" - : state == "invalid_cvc" ? "There was an issue with your CVC number" - : state == "invalid_expiry" ? "Expiry must be sometime in the past." - : "There was an issue with the payment. Please contact support."; - -string storage paymentMessageWithABreak = - state == "success" ? "Payment completed successfully" - : state == "processing" ? "Payment processing" - : state == "invalid_cvc" ? - "There was an issue with your CVC number, and you need to take a prompt action on it." - : state == "invalid_expiry" ? "Expiry must be sometime in the past." - : "There was an issue with the payment. Please contact support."; - -string storage typeofExample = - definition.encode ? - definition.encode( - row[field] != "undefined" ? row[field] - : definition.defaults != "undefined" ? definition.defaults - : "null" - ) - : row[field] != "undefined" ? row[field] - : definition.defaults != "undefined" ? definition.defaults - : "null"; - -// (the following is semantically equivalent to the above, but written in a more-confusing style – it'd be hard to grok no matter the formatting) -string storage typeofExampleFlipped = - definition.encode ? - definition.encode( - row[field] == "undefined" ? - definition.defaults == "undefined" ? - "null" - : definition.defaults - : row[field] - ) - : row[field] == "undefined" ? - definition.defaults == "undefined" ? - "null" - : definition.defaults - : row[field]; - } -} - - - -=====================================output===================================== -pragma solidity ^0.4.24; - -contract Conditional { - function blogPostExample() { - string storage animalName = pet.canBark() ? - pet.isScary() ? - "wolf" - : "dog" - : pet.canMeow() ? "cat" - : "probably a bunny"; - - string storage animalName = pet.isScary() ? "wolf" - : pet.canBark() ? "dog" - : pet.canMeow() ? "cat" - : "probably a bunny"; - - string storage animalName = pet.canSqueak() ? "mouse" - : pet.canBark() ? - pet.isScary() ? - "wolf" - : "dog" - : pet.canMeow() ? "cat" - : pet.canSqueak() ? "mouse" - : "probably a bunny"; - } - - function examples1() { - string storage short = isLoud() ? makeNoise() : silent(); - - string storage lessShort = isLoudReallyLoud() ? - makeNoiseReallyLoudly.omgSoLoud() - : silent(); - - string storage andIndented = isLoudReallyReallyReallyReallyLoud() ? - makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() - : silent(); - - string storage indentationInFalseExpression = ( - isLoudReallyReallyReallyReallyLoud() - ) ? - makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); - - string storage shortSoCase = isLoudReallyReallyReallyReallyLoud() ? - silent() - : (makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud()); - - string storage chainedShort = isCat() ? meow() - : isDog() ? bark() - : silent(); - - string storage chainedWithLongConsequent = isCat() ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : isDog() ? bark() - : silent(); - - string storage chainedWithTernaryConsequent = isCat() ? - aNestedCondition ? - theResult() - : theAlternate() - : isDog() ? bark() - : silent(); - - string storage consequentAndTerminalAlternateBreak = isCat() ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : isDog() ? bark() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); - - string storage multilineConditionsConsequentsAndAlternates = ( - isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : ( - isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - bark() - : shortCondition() ? shortConsequent() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); - - assignment = ( - isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : ( - isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - bark() - : shortCondition() ? shortConsequent() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); - - string storage mostlyShort = x == 1 ? "one" - : x == 2 ? "two" - : x == 3 ? "three" - : ( - x == 5 && - y == 7 && - someOtherThing.thatIsSoLong.thatItBreaksTheTestCondition() - ) ? - "four" - : x == 6 ? "six" - : "idk"; - - string storage longConditional = ( - bifornCringerMoshedPerplexSawder == - 2 / - askTrovenaBeenaDependsRowans && - glimseGlyphsHazardNoopsTieTie >= - averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() - ) ? - "foo" - : "bar"; - - string storage longConditionalChained = ( - bifornCringerMoshedPerplexSawder == - 2 / - askTrovenaBeenaDependsRowans && - glimseGlyphsHazardNoopsTieTie >= - averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() - ) ? - "foo" - : anotherCondition ? "bar" - : "baz"; - - definition.encode( - row[field] != "undefined" ? row[field] - : definition.defaults != "undefined" ? definition.defaults - : "null", - row[field] == "undefined" ? - definition.defaults == "undefined" ? - "null" - : definition.defaults - : row[field] - ); - - (foo ? 1 : bar) ? 3 : 4; - ( - isCat() ? meow() - : isDog() ? bark() - : silent() - ) ? - 1 - : 2; - - if (short) { - return foo ? 1 : 2; - } - return row[aVeryLongFieldName] != "undefined" ? row[aVeryLongFieldName] - : "null"; - } - - function examples2() { - string storage message = i % 3 == 0 && i % 5 == 0 ? "fizzbuzz" - : i % 3 == 0 ? "fizz" - : i % 5 == 0 ? "buzz" - : String(i); - - string storage paymentMessageShort = state == "success" ? - "Payment completed successfully" - : state == "processing" ? "Payment processing" - : state == "invalid_cvc" ? "There was an issue with your CVC number" - : state == "invalid_expiry" ? "Expiry must be sometime in the past." - : "There was an issue with the payment. Please contact support."; - - string storage paymentMessageWithABreak = state == "success" ? - "Payment completed successfully" - : state == "processing" ? "Payment processing" - : state == "invalid_cvc" ? - "There was an issue with your CVC number, and you need to take a prompt action on it." - : state == "invalid_expiry" ? "Expiry must be sometime in the past." - : "There was an issue with the payment. Please contact support."; - - string storage typeofExample = definition.encode ? - definition.encode( - row[field] != "undefined" ? row[field] - : definition.defaults != "undefined" ? definition.defaults - : "null" - ) - : row[field] != "undefined" ? row[field] - : definition.defaults != "undefined" ? definition.defaults - : "null"; - - string storage typeofExampleFlipped = definition.encode ? - definition.encode( - row[field] == "undefined" ? - definition.defaults == "undefined" ? - "null" - : definition.defaults - : row[field] - ) - : row[field] == "undefined" ? - definition.defaults == "undefined" ? - "null" - : definition.defaults - : row[field]; - } -} - -================================================================================ -`; - -exports[`ExperimentalTernaries.sol - {"experimentalTernaries":true} format 1`] = ` -====================================options===================================== -experimentalTernaries: true -parsers: ["solidity-parse"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity ^0.4.24; - - -contract Conditional { - function blogPostExample() { - // "curious" ternaries - string storage animalName = - pet.canBark() ? - pet.isScary() ? - 'wolf' - : 'dog' - : pet.canMeow() ? - 'cat' - : 'probably a bunny'; - - // "case-style" ternaries - string storage animalName = - pet.isScary() ? 'wolf' - : pet.canBark() ? 'dog' - : pet.canMeow() ? 'cat' - : 'probably a bunny'; - - // fluidity between "case-style" and "curious" ternaries - string storage animalName = - pet.canSqueak() ? 'mouse' - : pet.canBark() ? - pet.isScary() ? - 'wolf' - : 'dog' - : pet.canMeow() ? 'cat' - : pet.canSqueak() ? 'mouse' - : 'probably a bunny'; - } - - function examples1() { - // remain on one line if possible: - string storage short = isLoud() ? makeNoise() : silent(); - - // next, put everything after the = - string storage lessShort = - isLoudReallyLoud() ? makeNoiseReallyLoudly.omgSoLoud() : silent(); - - // next, indent the consequent: - string storage andIndented = - isLoudReallyReallyReallyReallyLoud() ? - makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() - : silent(); - - // if we need to add spaces to the falseExpression to fill a tab, we indent it as well: - string storage indentationInFalseExpression = - isLoudReallyReallyReallyReallyLoud() ? - makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); - - // unless the consequent is short (less than ten characters long): - string storage shortSoCase = - isLoudReallyReallyReallyReallyLoud() ? silent() : ( - makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() - ); - - // if chained, always break and put after the = - string storage chainedShort = - isCat() ? meow() - : isDog() ? bark() - : silent(); - - // when a consequent breaks in a chain: - string storage chainedWithLongConsequent = - isCat() ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : isDog() ? bark() - : silent(); - - // nested ternary in consequent always breaks: - string storage chainedWithTernaryConsequent = - isCat() ? - aNestedCondition ? theResult() - : theAlternate() - : isDog() ? bark() - : silent(); - - // consequent and terminal alternate break: - string storage consequentAndTerminalAlternateBreak = - isCat() ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : isDog() ? bark() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); - - // multiline conditions and consequents/alternates: - string storage multilineConditionsConsequentsAndAlternates = - ( - isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : ( - isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - bark() - : shortCondition() ? shortConsequent() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); - - // Assignment also groups and indents as Variable Declaration: - assignment = - ( - isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : ( - isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - bark() - : shortCondition() ? shortConsequent() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); - - // illustrating case of mostly short conditionals - string storage mostlyShort = - x == 1 ? "one" - : x == 2 ? "two" - : x == 3 ? "three" - : ( - x == 5 && - y == 7 && - someOtherThing.thatIsSoLong.thatItBreaksTheTestCondition() - ) ? - "four" - : x == 6 ? "six" - : "idk"; - - // long conditional, short consequent/alternate, not chained - do indent after ? - string storage longConditional = - ( - bifornCringerMoshedPerplexSawder == 2 / askTrovenaBeenaDependsRowans && - glimseGlyphsHazardNoopsTieTie >= - averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() - ) ? - "foo" - : "bar"; - - // long conditional, short consequent/alternate, chained - // (break on short consequents iff in chained ternary and its conditional broke) - string storage longConditionalChained = - ( - bifornCringerMoshedPerplexSawder == 2 / askTrovenaBeenaDependsRowans && - glimseGlyphsHazardNoopsTieTie >= - averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() - ) ? - "foo" - : anotherCondition ? "bar" - : "baz"; - - // As a function parameter, don't add an extra indent: - definition.encode( - row[field] != "undefined" ? row[field] - : definition.defaults != "undefined" ? definition.defaults - : "null", - row[field] == "undefined" ? - definition.defaults == "undefined" ? - "null" - : definition.defaults - : row[field] - ); - - // Conditional as a condition - (((foo ? 1 : bar))) ? 3 : 4; - (isCat() ? meow() - : isDog() ? bark() - : silent()) ? 1: 2; - - // In a return, break and over-indent: - if (short) { - return foo ? 1 : 2; - } - return row[aVeryLongFieldName] != "undefined" ? - row[aVeryLongFieldName] - : "null"; - } - - - function examples2() {string storage message = - i % 3 == 0 && i % 5 == 0 ? "fizzbuzz" - : i % 3 == 0 ? "fizz" - : i % 5 == 0 ? "buzz" - : String(i); - -string storage paymentMessageShort = - state == "success" ? "Payment completed successfully" - : state == "processing" ? "Payment processing" - : state == "invalid_cvc" ? "There was an issue with your CVC number" - : state == "invalid_expiry" ? "Expiry must be sometime in the past." - : "There was an issue with the payment. Please contact support."; - -string storage paymentMessageWithABreak = - state == "success" ? "Payment completed successfully" - : state == "processing" ? "Payment processing" - : state == "invalid_cvc" ? - "There was an issue with your CVC number, and you need to take a prompt action on it." - : state == "invalid_expiry" ? "Expiry must be sometime in the past." - : "There was an issue with the payment. Please contact support."; - -string storage typeofExample = - definition.encode ? - definition.encode( - row[field] != "undefined" ? row[field] - : definition.defaults != "undefined" ? definition.defaults - : "null" - ) - : row[field] != "undefined" ? row[field] - : definition.defaults != "undefined" ? definition.defaults - : "null"; - -// (the following is semantically equivalent to the above, but written in a more-confusing style – it'd be hard to grok no matter the formatting) -string storage typeofExampleFlipped = - definition.encode ? - definition.encode( - row[field] == "undefined" ? - definition.defaults == "undefined" ? - "null" - : definition.defaults - : row[field] - ) - : row[field] == "undefined" ? - definition.defaults == "undefined" ? - "null" - : definition.defaults - : row[field]; - } -} - - - -=====================================output===================================== -pragma solidity ^0.4.24; - -contract Conditional { - function blogPostExample() { - // "curious" ternaries - string storage animalName = - pet.canBark() ? - pet.isScary() ? - "wolf" - : "dog" - : pet.canMeow() ? "cat" - : "probably a bunny"; - - // "case-style" ternaries - string storage animalName = - pet.isScary() ? "wolf" - : pet.canBark() ? "dog" - : pet.canMeow() ? "cat" - : "probably a bunny"; - - // fluidity between "case-style" and "curious" ternaries - string storage animalName = - pet.canSqueak() ? "mouse" - : pet.canBark() ? - pet.isScary() ? - "wolf" - : "dog" - : pet.canMeow() ? "cat" - : pet.canSqueak() ? "mouse" - : "probably a bunny"; - } - - function examples1() { - // remain on one line if possible: - string storage short = isLoud() ? makeNoise() : silent(); - - // next, put everything after the = - string storage lessShort = - isLoudReallyLoud() ? makeNoiseReallyLoudly.omgSoLoud() : silent(); - - // next, indent the consequent: - string storage andIndented = - isLoudReallyReallyReallyReallyLoud() ? - makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() - : silent(); - - // if we need to add spaces to the falseExpression to fill a tab, we indent it as well: - string storage indentationInFalseExpression = - isLoudReallyReallyReallyReallyLoud() ? - makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); - - // unless the consequent is short (less than ten characters long): - string storage shortSoCase = - isLoudReallyReallyReallyReallyLoud() ? silent() - : (makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud()); - - // if chained, always break and put after the = - string storage chainedShort = - isCat() ? meow() - : isDog() ? bark() - : silent(); - - // when a consequent breaks in a chain: - string storage chainedWithLongConsequent = - isCat() ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : isDog() ? bark() - : silent(); - - // nested ternary in consequent always breaks: - string storage chainedWithTernaryConsequent = - isCat() ? - aNestedCondition ? - theResult() - : theAlternate() - : isDog() ? bark() - : silent(); - - // consequent and terminal alternate break: - string storage consequentAndTerminalAlternateBreak = - isCat() ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : isDog() ? bark() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); - - // multiline conditions and consequents/alternates: - string storage multilineConditionsConsequentsAndAlternates = - ( - isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : ( - isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - bark() - : shortCondition() ? shortConsequent() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); - - // Assignment also groups and indents as Variable Declaration: - assignment = ( - isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : ( - isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - bark() - : shortCondition() ? shortConsequent() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); - - // illustrating case of mostly short conditionals - string storage mostlyShort = - x == 1 ? "one" - : x == 2 ? "two" - : x == 3 ? "three" - : ( - x == 5 && - y == 7 && - someOtherThing.thatIsSoLong.thatItBreaksTheTestCondition() - ) ? - "four" - : x == 6 ? "six" - : "idk"; - - // long conditional, short consequent/alternate, not chained - do indent after ? - string storage longConditional = - ( - bifornCringerMoshedPerplexSawder == - 2 / askTrovenaBeenaDependsRowans && - glimseGlyphsHazardNoopsTieTie >= - averredBathersBoxroomBuggyNurl() - .anodyneCondosMalateOverateRetinol() - ) ? - "foo" - : "bar"; - - // long conditional, short consequent/alternate, chained - // (break on short consequents iff in chained ternary and its conditional broke) - string storage longConditionalChained = - ( - bifornCringerMoshedPerplexSawder == - 2 / askTrovenaBeenaDependsRowans && - glimseGlyphsHazardNoopsTieTie >= - averredBathersBoxroomBuggyNurl() - .anodyneCondosMalateOverateRetinol() - ) ? - "foo" - : anotherCondition ? "bar" - : "baz"; - - // As a function parameter, don't add an extra indent: - definition.encode( - row[field] != "undefined" ? row[field] - : definition.defaults != "undefined" ? definition.defaults - : "null", - row[field] == "undefined" ? - definition.defaults == "undefined" ? - "null" - : definition.defaults - : row[field] - ); - - // Conditional as a condition - (foo ? 1 : bar) ? 3 : 4; - ( - isCat() ? meow() - : isDog() ? bark() - : silent() - ) ? - 1 - : 2; - - // In a return, break and over-indent: - if (short) { - return foo ? 1 : 2; - } - return row[aVeryLongFieldName] != "undefined" ? row[aVeryLongFieldName] - : "null"; - } - - function examples2() { - string storage message = - i % 3 == 0 && i % 5 == 0 ? "fizzbuzz" - : i % 3 == 0 ? "fizz" - : i % 5 == 0 ? "buzz" - : String(i); - - string storage paymentMessageShort = - state == "success" ? "Payment completed successfully" - : state == "processing" ? "Payment processing" - : state == "invalid_cvc" ? "There was an issue with your CVC number" - : state == "invalid_expiry" ? "Expiry must be sometime in the past." - : "There was an issue with the payment. Please contact support."; - - string storage paymentMessageWithABreak = - state == "success" ? "Payment completed successfully" - : state == "processing" ? "Payment processing" - : state == "invalid_cvc" ? - "There was an issue with your CVC number, and you need to take a prompt action on it." - : state == "invalid_expiry" ? "Expiry must be sometime in the past." - : "There was an issue with the payment. Please contact support."; - - string storage typeofExample = - definition.encode ? - definition.encode( - row[field] != "undefined" ? row[field] - : definition.defaults != "undefined" ? definition.defaults - : "null" - ) - : row[field] != "undefined" ? row[field] - : definition.defaults != "undefined" ? definition.defaults - : "null"; - - // (the following is semantically equivalent to the above, but written in a more-confusing style – it'd be hard to grok no matter the formatting) - string storage typeofExampleFlipped = - definition.encode ? - definition.encode( - row[field] == "undefined" ? - definition.defaults == "undefined" ? - "null" - : definition.defaults - : row[field] - ) - : row[field] == "undefined" ? - definition.defaults == "undefined" ? - "null" - : definition.defaults - : row[field]; - } -} - -================================================================================ -`; - -exports[`ExperimentalTernaries.sol - {"experimentalTernaries":true} format 2`] = ` -====================================options===================================== -experimentalTernaries: true -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity ^0.4.24; - - -contract Conditional { - function blogPostExample() { - // "curious" ternaries - string storage animalName = - pet.canBark() ? - pet.isScary() ? - 'wolf' - : 'dog' - : pet.canMeow() ? - 'cat' - : 'probably a bunny'; - - // "case-style" ternaries - string storage animalName = - pet.isScary() ? 'wolf' - : pet.canBark() ? 'dog' - : pet.canMeow() ? 'cat' - : 'probably a bunny'; - - // fluidity between "case-style" and "curious" ternaries - string storage animalName = - pet.canSqueak() ? 'mouse' - : pet.canBark() ? - pet.isScary() ? - 'wolf' - : 'dog' - : pet.canMeow() ? 'cat' - : pet.canSqueak() ? 'mouse' - : 'probably a bunny'; - } - - function examples1() { - // remain on one line if possible: - string storage short = isLoud() ? makeNoise() : silent(); - - // next, put everything after the = - string storage lessShort = - isLoudReallyLoud() ? makeNoiseReallyLoudly.omgSoLoud() : silent(); - - // next, indent the consequent: - string storage andIndented = - isLoudReallyReallyReallyReallyLoud() ? - makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() - : silent(); - - // if we need to add spaces to the falseExpression to fill a tab, we indent it as well: - string storage indentationInFalseExpression = - isLoudReallyReallyReallyReallyLoud() ? - makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); - - // unless the consequent is short (less than ten characters long): - string storage shortSoCase = - isLoudReallyReallyReallyReallyLoud() ? silent() : ( - makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() - ); - - // if chained, always break and put after the = - string storage chainedShort = - isCat() ? meow() - : isDog() ? bark() - : silent(); - - // when a consequent breaks in a chain: - string storage chainedWithLongConsequent = - isCat() ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : isDog() ? bark() - : silent(); - - // nested ternary in consequent always breaks: - string storage chainedWithTernaryConsequent = - isCat() ? - aNestedCondition ? theResult() - : theAlternate() - : isDog() ? bark() - : silent(); - - // consequent and terminal alternate break: - string storage consequentAndTerminalAlternateBreak = - isCat() ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : isDog() ? bark() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); - - // multiline conditions and consequents/alternates: - string storage multilineConditionsConsequentsAndAlternates = - ( - isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : ( - isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - bark() - : shortCondition() ? shortConsequent() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); - - // Assignment also groups and indents as Variable Declaration: - assignment = - ( - isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : ( - isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - bark() - : shortCondition() ? shortConsequent() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); - - // illustrating case of mostly short conditionals - string storage mostlyShort = - x == 1 ? "one" - : x == 2 ? "two" - : x == 3 ? "three" - : ( - x == 5 && - y == 7 && - someOtherThing.thatIsSoLong.thatItBreaksTheTestCondition() - ) ? - "four" - : x == 6 ? "six" - : "idk"; - - // long conditional, short consequent/alternate, not chained - do indent after ? - string storage longConditional = - ( - bifornCringerMoshedPerplexSawder == 2 / askTrovenaBeenaDependsRowans && - glimseGlyphsHazardNoopsTieTie >= - averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() - ) ? - "foo" - : "bar"; - - // long conditional, short consequent/alternate, chained - // (break on short consequents iff in chained ternary and its conditional broke) - string storage longConditionalChained = - ( - bifornCringerMoshedPerplexSawder == 2 / askTrovenaBeenaDependsRowans && - glimseGlyphsHazardNoopsTieTie >= - averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() - ) ? - "foo" - : anotherCondition ? "bar" - : "baz"; - - // As a function parameter, don't add an extra indent: - definition.encode( - row[field] != "undefined" ? row[field] - : definition.defaults != "undefined" ? definition.defaults - : "null", - row[field] == "undefined" ? - definition.defaults == "undefined" ? - "null" - : definition.defaults - : row[field] - ); - - // Conditional as a condition - (((foo ? 1 : bar))) ? 3 : 4; - (isCat() ? meow() - : isDog() ? bark() - : silent()) ? 1: 2; - - // In a return, break and over-indent: - if (short) { - return foo ? 1 : 2; - } - return row[aVeryLongFieldName] != "undefined" ? - row[aVeryLongFieldName] - : "null"; - } - - - function examples2() {string storage message = - i % 3 == 0 && i % 5 == 0 ? "fizzbuzz" - : i % 3 == 0 ? "fizz" - : i % 5 == 0 ? "buzz" - : String(i); - -string storage paymentMessageShort = - state == "success" ? "Payment completed successfully" - : state == "processing" ? "Payment processing" - : state == "invalid_cvc" ? "There was an issue with your CVC number" - : state == "invalid_expiry" ? "Expiry must be sometime in the past." - : "There was an issue with the payment. Please contact support."; - -string storage paymentMessageWithABreak = - state == "success" ? "Payment completed successfully" - : state == "processing" ? "Payment processing" - : state == "invalid_cvc" ? - "There was an issue with your CVC number, and you need to take a prompt action on it." - : state == "invalid_expiry" ? "Expiry must be sometime in the past." - : "There was an issue with the payment. Please contact support."; - -string storage typeofExample = - definition.encode ? - definition.encode( - row[field] != "undefined" ? row[field] - : definition.defaults != "undefined" ? definition.defaults - : "null" - ) - : row[field] != "undefined" ? row[field] - : definition.defaults != "undefined" ? definition.defaults - : "null"; - -// (the following is semantically equivalent to the above, but written in a more-confusing style – it'd be hard to grok no matter the formatting) -string storage typeofExampleFlipped = - definition.encode ? - definition.encode( - row[field] == "undefined" ? - definition.defaults == "undefined" ? - "null" - : definition.defaults - : row[field] - ) - : row[field] == "undefined" ? - definition.defaults == "undefined" ? - "null" - : definition.defaults - : row[field]; - } -} - - - -=====================================output===================================== -pragma solidity ^0.4.24; - -contract Conditional { - function blogPostExample() { - string storage animalName = pet.canBark() ? - pet.isScary() ? - "wolf" - : "dog" - : pet.canMeow() ? "cat" - : "probably a bunny"; - - string storage animalName = pet.isScary() ? "wolf" - : pet.canBark() ? "dog" - : pet.canMeow() ? "cat" - : "probably a bunny"; - - string storage animalName = pet.canSqueak() ? "mouse" - : pet.canBark() ? - pet.isScary() ? - "wolf" - : "dog" - : pet.canMeow() ? "cat" - : pet.canSqueak() ? "mouse" - : "probably a bunny"; - } - - function examples1() { - string storage short = isLoud() ? makeNoise() : silent(); - - string storage lessShort = isLoudReallyLoud() ? - makeNoiseReallyLoudly.omgSoLoud() - : silent(); - - string storage andIndented = isLoudReallyReallyReallyReallyLoud() ? - makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() - : silent(); - - string storage indentationInFalseExpression = ( - isLoudReallyReallyReallyReallyLoud() - ) ? - makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); - - string storage shortSoCase = isLoudReallyReallyReallyReallyLoud() ? - silent() - : (makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud()); - - string storage chainedShort = isCat() ? meow() - : isDog() ? bark() - : silent(); - - string storage chainedWithLongConsequent = isCat() ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : isDog() ? bark() - : silent(); - - string storage chainedWithTernaryConsequent = isCat() ? - aNestedCondition ? - theResult() - : theAlternate() - : isDog() ? bark() - : silent(); - - string storage consequentAndTerminalAlternateBreak = isCat() ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : isDog() ? bark() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); - - string storage multilineConditionsConsequentsAndAlternates = ( - isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : ( - isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - bark() - : shortCondition() ? shortConsequent() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); - - assignment = ( - isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : ( - isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) ? - bark() - : shortCondition() ? shortConsequent() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); - - string storage mostlyShort = x == 1 ? "one" - : x == 2 ? "two" - : x == 3 ? "three" - : ( - x == 5 && - y == 7 && - someOtherThing.thatIsSoLong.thatItBreaksTheTestCondition() - ) ? - "four" - : x == 6 ? "six" - : "idk"; - - string storage longConditional = ( - bifornCringerMoshedPerplexSawder == - 2 / - askTrovenaBeenaDependsRowans && - glimseGlyphsHazardNoopsTieTie >= - averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() - ) ? - "foo" - : "bar"; + // Conditional as a condition + (foo ? 1 : bar) ? 3 : 4; + ( + isCat() ? meow() + : isDog() ? bark() + : silent() + ) ? + 1 + : 2; - string storage longConditionalChained = ( - bifornCringerMoshedPerplexSawder == - 2 / - askTrovenaBeenaDependsRowans && - glimseGlyphsHazardNoopsTieTie >= - averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol() - ) ? - "foo" - : anotherCondition ? "bar" - : "baz"; + // In a return, break and over-indent: + if (short) { + return foo ? 1 : 2; + } + return row[aVeryLongFieldName] != "undefined" ? row[aVeryLongFieldName] + : "null"; + } - definition.encode( - row[field] != "undefined" ? row[field] - : definition.defaults != "undefined" ? definition.defaults - : "null", - row[field] == "undefined" ? - definition.defaults == "undefined" ? - "null" - : definition.defaults - : row[field] - ); + function examples2() { + string storage message = + i % 3 == 0 && i % 5 == 0 ? "fizzbuzz" + : i % 3 == 0 ? "fizz" + : i % 5 == 0 ? "buzz" + : String(i); - (foo ? 1 : bar) ? 3 : 4; - ( - isCat() ? meow() - : isDog() ? bark() - : silent() - ) ? - 1 - : 2; + string storage paymentMessageShort = + state == "success" ? "Payment completed successfully" + : state == "processing" ? "Payment processing" + : state == "invalid_cvc" ? "There was an issue with your CVC number" + : state == "invalid_expiry" ? "Expiry must be sometime in the past." + : "There was an issue with the payment. Please contact support."; - if (short) { - return foo ? 1 : 2; - } - return row[aVeryLongFieldName] != "undefined" ? row[aVeryLongFieldName] - : "null"; - } + string storage paymentMessageWithABreak = + state == "success" ? "Payment completed successfully" + : state == "processing" ? "Payment processing" + : state == "invalid_cvc" ? + "There was an issue with your CVC number, and you need to take a prompt action on it." + : state == "invalid_expiry" ? "Expiry must be sometime in the past." + : "There was an issue with the payment. Please contact support."; - function examples2() { - string storage message = i % 3 == 0 && i % 5 == 0 ? "fizzbuzz" - : i % 3 == 0 ? "fizz" - : i % 5 == 0 ? "buzz" - : String(i); - - string storage paymentMessageShort = state == "success" ? - "Payment completed successfully" - : state == "processing" ? "Payment processing" - : state == "invalid_cvc" ? "There was an issue with your CVC number" - : state == "invalid_expiry" ? "Expiry must be sometime in the past." - : "There was an issue with the payment. Please contact support."; - - string storage paymentMessageWithABreak = state == "success" ? - "Payment completed successfully" - : state == "processing" ? "Payment processing" - : state == "invalid_cvc" ? - "There was an issue with your CVC number, and you need to take a prompt action on it." - : state == "invalid_expiry" ? "Expiry must be sometime in the past." - : "There was an issue with the payment. Please contact support."; - - string storage typeofExample = definition.encode ? - definition.encode( - row[field] != "undefined" ? row[field] - : definition.defaults != "undefined" ? definition.defaults - : "null" - ) - : row[field] != "undefined" ? row[field] - : definition.defaults != "undefined" ? definition.defaults - : "null"; + string storage typeofExample = + definition.encode ? + definition.encode( + row[field] != "undefined" ? row[field] + : definition.defaults != "undefined" ? definition.defaults + : "null" + ) + : row[field] != "undefined" ? row[field] + : definition.defaults != "undefined" ? definition.defaults + : "null"; - string storage typeofExampleFlipped = definition.encode ? - definition.encode( - row[field] == "undefined" ? - definition.defaults == "undefined" ? - "null" - : definition.defaults - : row[field] - ) - : row[field] == "undefined" ? - definition.defaults == "undefined" ? - "null" - : definition.defaults - : row[field]; - } + // (the following is semantically equivalent to the above, but written in a more-confusing style – it'd be hard to grok no matter the formatting) + string storage typeofExampleFlipped = + definition.encode ? + definition.encode( + row[field] == "undefined" ? + definition.defaults == "undefined" ? + "null" + : definition.defaults + : row[field] + ) + : row[field] == "undefined" ? + definition.defaults == "undefined" ? + "null" + : definition.defaults + : row[field]; + } } ================================================================================ `; -exports[`ExperimentalTernaries.sol format 1`] = ` +exports[`ExperimentalTernaries.sol - {"experimentalTernaries":true} format 1`] = ` ====================================options===================================== +experimentalTernaries: true parsers: ["solidity-parse"] printWidth: 80 | printWidth @@ -3231,35 +1287,31 @@ pragma solidity ^0.4.24; contract Conditional { function blogPostExample() { // "curious" ternaries - string storage animalName = pet.canBark() - ? pet.isScary() - ? "wolf" - : "dog" - : pet.canMeow() - ? "cat" - : "probably a bunny"; + string storage animalName = + pet.canBark() ? + pet.isScary() ? + "wolf" + : "dog" + : pet.canMeow() ? "cat" + : "probably a bunny"; // "case-style" ternaries - string storage animalName = pet.isScary() - ? "wolf" - : pet.canBark() - ? "dog" - : pet.canMeow() - ? "cat" - : "probably a bunny"; + string storage animalName = + pet.isScary() ? "wolf" + : pet.canBark() ? "dog" + : pet.canMeow() ? "cat" + : "probably a bunny"; // fluidity between "case-style" and "curious" ternaries - string storage animalName = pet.canSqueak() - ? "mouse" - : pet.canBark() - ? pet.isScary() - ? "wolf" - : "dog" - : pet.canMeow() - ? "cat" - : pet.canSqueak() - ? "mouse" - : "probably a bunny"; + string storage animalName = + pet.canSqueak() ? "mouse" + : pet.canBark() ? + pet.isScary() ? + "wolf" + : "dog" + : pet.canMeow() ? "cat" + : pet.canSqueak() ? "mouse" + : "probably a bunny"; } function examples1() { @@ -3267,236 +1319,227 @@ contract Conditional { string storage short = isLoud() ? makeNoise() : silent(); // next, put everything after the = - string storage lessShort = isLoudReallyLoud() - ? makeNoiseReallyLoudly.omgSoLoud() - : silent(); + string storage lessShort = + isLoudReallyLoud() ? makeNoiseReallyLoudly.omgSoLoud() : silent(); // next, indent the consequent: - string storage andIndented = isLoudReallyReallyReallyReallyLoud() - ? makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() - : silent(); + string storage andIndented = + isLoudReallyReallyReallyReallyLoud() ? + makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() + : silent(); // if we need to add spaces to the falseExpression to fill a tab, we indent it as well: - string - storage indentationInFalseExpression = isLoudReallyReallyReallyReallyLoud() - ? makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() - : someReallyLargeExpression + string storage indentationInFalseExpression = + isLoudReallyReallyReallyReallyLoud() ? + makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() + : someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens(); // unless the consequent is short (less than ten characters long): - string storage shortSoCase = isLoudReallyReallyReallyReallyLoud() - ? silent() + string storage shortSoCase = + isLoudReallyReallyReallyReallyLoud() ? silent() : (makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud()); // if chained, always break and put after the = - string storage chainedShort = isCat() - ? meow() - : isDog() - ? bark() - : silent(); + string storage chainedShort = + isCat() ? meow() + : isDog() ? bark() + : silent(); // when a consequent breaks in a chain: - string storage chainedWithLongConsequent = isCat() - ? someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : isDog() - ? bark() - : silent(); + string storage chainedWithLongConsequent = + isCat() ? + someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : isDog() ? bark() + : silent(); // nested ternary in consequent always breaks: - string storage chainedWithTernaryConsequent = isCat() - ? aNestedCondition - ? theResult() - : theAlternate() - : isDog() - ? bark() - : silent(); + string storage chainedWithTernaryConsequent = + isCat() ? + aNestedCondition ? + theResult() + : theAlternate() + : isDog() ? bark() + : silent(); // consequent and terminal alternate break: - string storage consequentAndTerminalAlternateBreak = isCat() - ? someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : isDog() - ? bark() - : someReallyLargeExpression + string storage consequentAndTerminalAlternateBreak = + isCat() ? + someReallyLargeExpression .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); + .willCauseAnIndentButNotParens() + : isDog() ? bark() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); // multiline conditions and consequents/alternates: - string - storage multilineConditionsConsequentsAndAlternates = (isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition)) - ? someReallyLargeExpression + string storage multilineConditionsConsequentsAndAlternates = + ( + isAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens() - : (isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition)) - ? bark() - : shortCondition() - ? shortConsequent() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); + : ( + isNotAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + bark() + : shortCondition() ? shortConsequent() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); // Assignment also groups and indents as Variable Declaration: - assignment = (isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition)) - ? someReallyLargeExpression + assignment = ( + isAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens() - : (isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition)) - ? bark() - : shortCondition() - ? shortConsequent() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); + : ( + isNotAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition) + ) ? + bark() + : shortCondition() ? shortConsequent() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); // illustrating case of mostly short conditionals - string storage mostlyShort = x == 1 - ? "one" - : x == 2 - ? "two" - : x == 3 - ? "three" - : (x == 5 && - y == 7 && - someOtherThing - .thatIsSoLong - .thatItBreaksTheTestCondition()) - ? "four" - : x == 6 - ? "six" - : "idk"; + string storage mostlyShort = + x == 1 ? "one" + : x == 2 ? "two" + : x == 3 ? "three" + : ( + x == 5 && + y == 7 && + someOtherThing.thatIsSoLong.thatItBreaksTheTestCondition() + ) ? + "four" + : x == 6 ? "six" + : "idk"; // long conditional, short consequent/alternate, not chained - do indent after ? - string storage longConditional = (bifornCringerMoshedPerplexSawder == - 2 / askTrovenaBeenaDependsRowans && - glimseGlyphsHazardNoopsTieTie >= - averredBathersBoxroomBuggyNurl() - .anodyneCondosMalateOverateRetinol()) - ? "foo" - : "bar"; + string storage longConditional = + ( + bifornCringerMoshedPerplexSawder == + 2 / askTrovenaBeenaDependsRowans && + glimseGlyphsHazardNoopsTieTie >= + averredBathersBoxroomBuggyNurl() + .anodyneCondosMalateOverateRetinol() + ) ? + "foo" + : "bar"; // long conditional, short consequent/alternate, chained // (break on short consequents iff in chained ternary and its conditional broke) - string - storage longConditionalChained = (bifornCringerMoshedPerplexSawder == - 2 / askTrovenaBeenaDependsRowans && + string storage longConditionalChained = + ( + bifornCringerMoshedPerplexSawder == + 2 / askTrovenaBeenaDependsRowans && glimseGlyphsHazardNoopsTieTie >= averredBathersBoxroomBuggyNurl() - .anodyneCondosMalateOverateRetinol()) - ? "foo" - : anotherCondition - ? "bar" - : "baz"; + .anodyneCondosMalateOverateRetinol() + ) ? + "foo" + : anotherCondition ? "bar" + : "baz"; // As a function parameter, don't add an extra indent: definition.encode( - row[field] != "undefined" - ? row[field] - : definition.defaults != "undefined" - ? definition.defaults - : "null", - row[field] == "undefined" - ? definition.defaults == "undefined" - ? "null" - : definition.defaults - : row[field] + row[field] != "undefined" ? row[field] + : definition.defaults != "undefined" ? definition.defaults + : "null", + row[field] == "undefined" ? + definition.defaults == "undefined" ? + "null" + : definition.defaults + : row[field] ); // Conditional as a condition - (((foo ? 1 : bar))) ? 3 : 4; + (foo ? 1 : bar) ? 3 : 4; ( - isCat() - ? meow() - : isDog() - ? bark() - : silent() - ) - ? 1 - : 2; + isCat() ? meow() + : isDog() ? bark() + : silent() + ) ? + 1 + : 2; // In a return, break and over-indent: if (short) { return foo ? 1 : 2; } - return - row[aVeryLongFieldName] != "undefined" - ? row[aVeryLongFieldName] - : "null"; + return row[aVeryLongFieldName] != "undefined" ? row[aVeryLongFieldName] + : "null"; } function examples2() { - string storage message = i % 3 == 0 && i % 5 == 0 - ? "fizzbuzz" - : i % 3 == 0 - ? "fizz" - : i % 5 == 0 - ? "buzz" - : String(i); + string storage message = + i % 3 == 0 && i % 5 == 0 ? "fizzbuzz" + : i % 3 == 0 ? "fizz" + : i % 5 == 0 ? "buzz" + : String(i); - string storage paymentMessageShort = state == "success" - ? "Payment completed successfully" - : state == "processing" - ? "Payment processing" - : state == "invalid_cvc" - ? "There was an issue with your CVC number" - : state == "invalid_expiry" - ? "Expiry must be sometime in the past." - : "There was an issue with the payment. Please contact support."; + string storage paymentMessageShort = + state == "success" ? "Payment completed successfully" + : state == "processing" ? "Payment processing" + : state == "invalid_cvc" ? "There was an issue with your CVC number" + : state == "invalid_expiry" ? "Expiry must be sometime in the past." + : "There was an issue with the payment. Please contact support."; - string storage paymentMessageWithABreak = state == "success" - ? "Payment completed successfully" - : state == "processing" - ? "Payment processing" - : state == "invalid_cvc" - ? "There was an issue with your CVC number, and you need to take a prompt action on it." - : state == "invalid_expiry" - ? "Expiry must be sometime in the past." - : "There was an issue with the payment. Please contact support."; + string storage paymentMessageWithABreak = + state == "success" ? "Payment completed successfully" + : state == "processing" ? "Payment processing" + : state == "invalid_cvc" ? + "There was an issue with your CVC number, and you need to take a prompt action on it." + : state == "invalid_expiry" ? "Expiry must be sometime in the past." + : "There was an issue with the payment. Please contact support."; - string storage typeofExample = definition.encode - ? definition.encode( - row[field] != "undefined" - ? row[field] - : definition.defaults != "undefined" - ? definition.defaults - : "null" - ) - : row[field] != "undefined" - ? row[field] - : definition.defaults != "undefined" - ? definition.defaults - : "null"; + string storage typeofExample = + definition.encode ? + definition.encode( + row[field] != "undefined" ? row[field] + : definition.defaults != "undefined" ? definition.defaults + : "null" + ) + : row[field] != "undefined" ? row[field] + : definition.defaults != "undefined" ? definition.defaults + : "null"; // (the following is semantically equivalent to the above, but written in a more-confusing style – it'd be hard to grok no matter the formatting) - string storage typeofExampleFlipped = definition.encode - ? definition.encode( - row[field] == "undefined" - ? definition.defaults == "undefined" - ? "null" - : definition.defaults - : row[field] - ) - : row[field] == "undefined" - ? definition.defaults == "undefined" - ? "null" - : definition.defaults - : row[field]; + string storage typeofExampleFlipped = + definition.encode ? + definition.encode( + row[field] == "undefined" ? + definition.defaults == "undefined" ? + "null" + : definition.defaults + : row[field] + ) + : row[field] == "undefined" ? + definition.defaults == "undefined" ? + "null" + : definition.defaults + : row[field]; } } ================================================================================ `; -exports[`ExperimentalTernaries.sol format 2`] = ` +exports[`ExperimentalTernaries.sol format 1`] = ` ====================================options===================================== -parsers: ["slang"] +parsers: ["solidity-parse"] printWidth: 80 | printWidth =====================================input====================================== @@ -3755,6 +1798,7 @@ pragma solidity ^0.4.24; contract Conditional { function blogPostExample() { + // "curious" ternaries string storage animalName = pet.canBark() ? pet.isScary() ? "wolf" @@ -3763,6 +1807,7 @@ contract Conditional { ? "cat" : "probably a bunny"; + // "case-style" ternaries string storage animalName = pet.isScary() ? "wolf" : pet.canBark() @@ -3771,6 +1816,7 @@ contract Conditional { ? "cat" : "probably a bunny"; + // fluidity between "case-style" and "curious" ternaries string storage animalName = pet.canSqueak() ? "mouse" : pet.canBark() @@ -3785,32 +1831,40 @@ contract Conditional { } function examples1() { + // remain on one line if possible: string storage short = isLoud() ? makeNoise() : silent(); + // next, put everything after the = string storage lessShort = isLoudReallyLoud() ? makeNoiseReallyLoudly.omgSoLoud() : silent(); + // next, indent the consequent: string storage andIndented = isLoudReallyReallyReallyReallyLoud() ? makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() : silent(); - string storage indentationInFalseExpression = isLoudReallyReallyReallyReallyLoud() - ? makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); + // if we need to add spaces to the falseExpression to fill a tab, we indent it as well: + string + storage indentationInFalseExpression = isLoudReallyReallyReallyReallyLoud() + ? makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); + // unless the consequent is short (less than ten characters long): string storage shortSoCase = isLoudReallyReallyReallyReallyLoud() ? silent() : (makeNoiseReallyReallyReallyReallyReallyLoudly.omgSoLoud()); + // if chained, always break and put after the = string storage chainedShort = isCat() ? meow() : isDog() ? bark() : silent(); + // when a consequent breaks in a chain: string storage chainedWithLongConsequent = isCat() ? someReallyLargeExpression .thatWouldCauseALineBreak() @@ -3819,6 +1873,7 @@ contract Conditional { ? bark() : silent(); + // nested ternary in consequent always breaks: string storage chainedWithTernaryConsequent = isCat() ? aNestedCondition ? theResult() @@ -3827,6 +1882,7 @@ contract Conditional { ? bark() : silent(); + // consequent and terminal alternate break: string storage consequentAndTerminalAlternateBreak = isCat() ? someReallyLargeExpression .thatWouldCauseALineBreak() @@ -3837,35 +1893,30 @@ contract Conditional { .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens(); - string storage multilineConditionsConsequentsAndAlternates = ( - isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) - ? someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens() - : ( - isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) - ? bark() - : shortCondition() - ? shortConsequent() - : someReallyLargeExpression - .thatWouldCauseALineBreak() - .willCauseAnIndentButNotParens(); + // multiline conditions and consequents/alternates: + string + storage multilineConditionsConsequentsAndAlternates = (isAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition)) + ? someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens() + : (isNotAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition)) + ? bark() + : shortCondition() + ? shortConsequent() + : someReallyLargeExpression + .thatWouldCauseALineBreak() + .willCauseAnIndentButNotParens(); - assignment = ( - isAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) + // Assignment also groups and indents as Variable Declaration: + assignment = (isAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition)) ? someReallyLargeExpression .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens() - : ( - isNotAnAdorableKittyCat() && - (someReallyLongCondition || moreInThisLongCondition) - ) + : (isNotAnAdorableKittyCat() && + (someReallyLongCondition || moreInThisLongCondition)) ? bark() : shortCondition() ? shortConsequent() @@ -3873,48 +1924,46 @@ contract Conditional { .thatWouldCauseALineBreak() .willCauseAnIndentButNotParens(); + // illustrating case of mostly short conditionals string storage mostlyShort = x == 1 ? "one" : x == 2 ? "two" : x == 3 ? "three" - : ( - x == 5 && - y == 7 && - someOtherThing - .thatIsSoLong - .thatItBreaksTheTestCondition() - ) + : (x == 5 && + y == 7 && + someOtherThing + .thatIsSoLong + .thatItBreaksTheTestCondition()) ? "four" : x == 6 ? "six" : "idk"; - string storage longConditional = ( - bifornCringerMoshedPerplexSawder == - 2 / - askTrovenaBeenaDependsRowans && - glimseGlyphsHazardNoopsTieTie >= - averredBathersBoxroomBuggyNurl() - .anodyneCondosMalateOverateRetinol() - ) + // long conditional, short consequent/alternate, not chained - do indent after ? + string storage longConditional = (bifornCringerMoshedPerplexSawder == + 2 / askTrovenaBeenaDependsRowans && + glimseGlyphsHazardNoopsTieTie >= + averredBathersBoxroomBuggyNurl() + .anodyneCondosMalateOverateRetinol()) ? "foo" : "bar"; - string storage longConditionalChained = ( - bifornCringerMoshedPerplexSawder == - 2 / - askTrovenaBeenaDependsRowans && + // long conditional, short consequent/alternate, chained + // (break on short consequents iff in chained ternary and its conditional broke) + string + storage longConditionalChained = (bifornCringerMoshedPerplexSawder == + 2 / askTrovenaBeenaDependsRowans && glimseGlyphsHazardNoopsTieTie >= averredBathersBoxroomBuggyNurl() - .anodyneCondosMalateOverateRetinol() - ) - ? "foo" - : anotherCondition - ? "bar" - : "baz"; + .anodyneCondosMalateOverateRetinol()) + ? "foo" + : anotherCondition + ? "bar" + : "baz"; + // As a function parameter, don't add an extra indent: definition.encode( row[field] != "undefined" ? row[field] @@ -3928,6 +1977,7 @@ contract Conditional { : row[field] ); + // Conditional as a condition (((foo ? 1 : bar))) ? 3 : 4; ( isCat() @@ -3939,12 +1989,14 @@ contract Conditional { ? 1 : 2; + // In a return, break and over-indent: if (short) { return foo ? 1 : 2; } - return row[aVeryLongFieldName] != "undefined" - ? row[aVeryLongFieldName] - : "null"; + return + row[aVeryLongFieldName] != "undefined" + ? row[aVeryLongFieldName] + : "null"; } function examples2() { @@ -3990,6 +2042,7 @@ contract Conditional { ? definition.defaults : "null"; + // (the following is semantically equivalent to the above, but written in a more-confusing style – it'd be hard to grok no matter the formatting) string storage typeofExampleFlipped = definition.encode ? definition.encode( row[field] == "undefined" diff --git a/tests/format/ExperimentalTernaries/jsfmt.spec.js b/tests/format/ExperimentalTernaries/jsfmt.spec.js index 0c5c92458..c79991703 100644 --- a/tests/format/ExperimentalTernaries/jsfmt.spec.js +++ b/tests/format/ExperimentalTernaries/jsfmt.spec.js @@ -8,16 +8,3 @@ run_spec(import.meta, ['solidity-parse'], { experimentalTernaries: true, useTabs: true }); - -run_spec(import.meta, ['slang']); -run_spec(import.meta, ['slang'], { - experimentalTernaries: true -}); -run_spec(import.meta, ['slang'], { - experimentalTernaries: true, - tabWidth: 1 -}); -run_spec(import.meta, ['slang'], { - experimentalTernaries: true, - useTabs: true -}); diff --git a/tests/format/ForStatements/__snapshots__/jsfmt.spec.js.snap b/tests/format/ForStatements/__snapshots__/jsfmt.spec.js.snap index 34159d1c4..fa6d0e014 100644 --- a/tests/format/ForStatements/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/ForStatements/__snapshots__/jsfmt.spec.js.snap @@ -106,108 +106,3 @@ contract ForStatements { ================================================================================ `; - -exports[`ForStatements.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -contract ForStatements { - uint constant LONG_VARIABLE = 1; - - function hi() public { - uint a; - - for (uint i; i < 100; i++) a++; - - for (i = 0; i < 100; i++) a = a.add(LONG_VARIABLE).add(LONG_VARIABLE).add(LONG_VARIABLE); - - for (i = 0; i < 100; i++) { a++; } - - for (i = 0; i < 100; i++) { a = a.add(LONG_VARIABLE).add(LONG_VARIABLE).add(LONG_VARIABLE); } - - for (uint veryLongVariableName; veryLongVariableName < 100; veryLongVariableName++) a++; - - for (veryLongVariableName = 0; veryLongVariableName < 100; veryLongVariableName++) { a++; } - - for (; ; ) { // #178 - } - - for (i = 0; ;) { - } - - for (i = 0; i < 100; ) { - } - - for (i = 0; ; i++) { - } - - for (i = 0; i < 100; i++) { - } - - for (; i < 100; i++) { - } - - for (; i < 100; ) { - } - - for (; ; i++) { - } - } -} - -=====================================output===================================== -contract ForStatements { - uint constant LONG_VARIABLE = 1; - - function hi() public { - uint a; - - for (uint i; i < 100; i++) a++; - - for (i = 0; i < 100; i++) - a = a.add(LONG_VARIABLE).add(LONG_VARIABLE).add(LONG_VARIABLE); - - for (i = 0; i < 100; i++) { - a++; - } - - for (i = 0; i < 100; i++) { - a = a.add(LONG_VARIABLE).add(LONG_VARIABLE).add(LONG_VARIABLE); - } - - for ( - uint veryLongVariableName; - veryLongVariableName < 100; - veryLongVariableName++ - ) a++; - - for ( - veryLongVariableName = 0; - veryLongVariableName < 100; - veryLongVariableName++ - ) { - a++; - } - - for (;;) {} - - for (i = 0; ; ) {} - - for (i = 0; i < 100; ) {} - - for (i = 0; ; i++) {} - - for (i = 0; i < 100; i++) {} - - for (; i < 100; i++) {} - - for (; i < 100; ) {} - - for (; ; i++) {} - } -} - -================================================================================ -`; diff --git a/tests/format/ForStatements/jsfmt.spec.js b/tests/format/ForStatements/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/ForStatements/jsfmt.spec.js +++ b/tests/format/ForStatements/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); diff --git a/tests/format/FunctionCalls/__snapshots__/jsfmt.spec.js.snap b/tests/format/FunctionCalls/__snapshots__/jsfmt.spec.js.snap index 94a47aa63..5e5db2ab9 100644 --- a/tests/format/FunctionCalls/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/FunctionCalls/__snapshots__/jsfmt.spec.js.snap @@ -153,159 +153,6 @@ contract FunctionCalls { ================================================================================ `; -exports[`FunctionCalls.sol - {"bracketSpacing":true} format 2`] = ` -====================================options===================================== -bracketSpacing: true -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -contract FunctionCalls { - function foo() { - address veryLongValidatorAddress = veryVeryVeryLongSignature.popLast20Bytes(); - } - - function foo() { - Voter you = Voter(1, true); - - Voter me = Voter({ - weight: 2, - voted: abstain() - }); - - Voter airbnb = Voter({ - weight: 2, - voted: true - }); - } - function verify(ForwardRequest calldata req, bytes calldata signature) public view returns (bool) { - address signer = - _hashTypedDataV1( - keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data))) - ) - ._hashTypedDataV2( - keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data))) - )._hashTypedDataV3( - keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data))) - ) .recover(signature); - signer = - _hashTypedDataV1( - keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data))) - ) - ._hashTypedDataV2( - keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data))) - )._hashTypedDataV3( - keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data))) - ) .recover(signature); - return _nonces[req.from] == req.nonce && signer == req.from; -} -} - -=====================================output===================================== -contract FunctionCalls { - function foo() { - address veryLongValidatorAddress = veryVeryVeryLongSignature - .popLast20Bytes(); - } - - function foo() { - Voter you = Voter(1, true); - - Voter me = Voter({weight: 2, voted: abstain()}); - - Voter airbnb = Voter({weight: 2, voted: true}); - } - function verify( - ForwardRequest calldata req, - bytes calldata signature - ) public view returns (bool) { - address signer = _hashTypedDataV1( - keccak256( - abi.encode( - TYPEHASH, - req.from, - req.to, - req.value, - req.gas, - req.nonce, - keccak256(req.data) - ) - ) - ) - ._hashTypedDataV2( - keccak256( - abi.encode( - TYPEHASH, - req.from, - req.to, - req.value, - req.gas, - req.nonce, - keccak256(req.data) - ) - ) - ) - ._hashTypedDataV3( - keccak256( - abi.encode( - TYPEHASH, - req.from, - req.to, - req.value, - req.gas, - req.nonce, - keccak256(req.data) - ) - ) - ) - .recover(signature); - signer = _hashTypedDataV1( - keccak256( - abi.encode( - TYPEHASH, - req.from, - req.to, - req.value, - req.gas, - req.nonce, - keccak256(req.data) - ) - ) - ) - ._hashTypedDataV2( - keccak256( - abi.encode( - TYPEHASH, - req.from, - req.to, - req.value, - req.gas, - req.nonce, - keccak256(req.data) - ) - ) - ) - ._hashTypedDataV3( - keccak256( - abi.encode( - TYPEHASH, - req.from, - req.to, - req.value, - req.gas, - req.nonce, - keccak256(req.data) - ) - ) - ) - .recover(signature); - return _nonces[req.from] == req.nonce && signer == req.from; - } -} - -================================================================================ -`; - exports[`FunctionCalls.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] @@ -457,155 +304,3 @@ contract FunctionCalls { ================================================================================ `; - -exports[`FunctionCalls.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -contract FunctionCalls { - function foo() { - address veryLongValidatorAddress = veryVeryVeryLongSignature.popLast20Bytes(); - } - - function foo() { - Voter you = Voter(1, true); - - Voter me = Voter({ - weight: 2, - voted: abstain() - }); - - Voter airbnb = Voter({ - weight: 2, - voted: true - }); - } - function verify(ForwardRequest calldata req, bytes calldata signature) public view returns (bool) { - address signer = - _hashTypedDataV1( - keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data))) - ) - ._hashTypedDataV2( - keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data))) - )._hashTypedDataV3( - keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data))) - ) .recover(signature); - signer = - _hashTypedDataV1( - keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data))) - ) - ._hashTypedDataV2( - keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data))) - )._hashTypedDataV3( - keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data))) - ) .recover(signature); - return _nonces[req.from] == req.nonce && signer == req.from; -} -} - -=====================================output===================================== -contract FunctionCalls { - function foo() { - address veryLongValidatorAddress = veryVeryVeryLongSignature - .popLast20Bytes(); - } - - function foo() { - Voter you = Voter(1, true); - - Voter me = Voter({weight: 2, voted: abstain()}); - - Voter airbnb = Voter({weight: 2, voted: true}); - } - function verify( - ForwardRequest calldata req, - bytes calldata signature - ) public view returns (bool) { - address signer = _hashTypedDataV1( - keccak256( - abi.encode( - TYPEHASH, - req.from, - req.to, - req.value, - req.gas, - req.nonce, - keccak256(req.data) - ) - ) - ) - ._hashTypedDataV2( - keccak256( - abi.encode( - TYPEHASH, - req.from, - req.to, - req.value, - req.gas, - req.nonce, - keccak256(req.data) - ) - ) - ) - ._hashTypedDataV3( - keccak256( - abi.encode( - TYPEHASH, - req.from, - req.to, - req.value, - req.gas, - req.nonce, - keccak256(req.data) - ) - ) - ) - .recover(signature); - signer = _hashTypedDataV1( - keccak256( - abi.encode( - TYPEHASH, - req.from, - req.to, - req.value, - req.gas, - req.nonce, - keccak256(req.data) - ) - ) - ) - ._hashTypedDataV2( - keccak256( - abi.encode( - TYPEHASH, - req.from, - req.to, - req.value, - req.gas, - req.nonce, - keccak256(req.data) - ) - ) - ) - ._hashTypedDataV3( - keccak256( - abi.encode( - TYPEHASH, - req.from, - req.to, - req.value, - req.gas, - req.nonce, - keccak256(req.data) - ) - ) - ) - .recover(signature); - return _nonces[req.from] == req.nonce && signer == req.from; - } -} - -================================================================================ -`; diff --git a/tests/format/FunctionCalls/jsfmt.spec.js b/tests/format/FunctionCalls/jsfmt.spec.js index 46fbb44d0..993a81764 100644 --- a/tests/format/FunctionCalls/jsfmt.spec.js +++ b/tests/format/FunctionCalls/jsfmt.spec.js @@ -1,4 +1,2 @@ run_spec(import.meta, ['solidity-parse']); run_spec(import.meta, ['solidity-parse'], { bracketSpacing: true }); -run_spec(import.meta, ['slang']); -run_spec(import.meta, ['slang'], { bracketSpacing: true }); diff --git a/tests/format/FunctionDefinitions/__snapshots__/jsfmt.spec.js.snap b/tests/format/FunctionDefinitions/__snapshots__/jsfmt.spec.js.snap index 9d3da8719..df0c891f8 100644 --- a/tests/format/FunctionDefinitions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/FunctionDefinitions/__snapshots__/jsfmt.spec.js.snap @@ -746,789 +746,3 @@ contract FunctionDefinitions { ================================================================================ `; - -exports[`FunctionDefinitions.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -interface FunctionInterfaces { - function noParamsNoModifiersNoReturns(); - function oneParam(uint x); - function oneModifier() modifier1; - function oneReturn() returns(uint y1); - function manyParams(uint x1, uint x2, uint x3, uint x4, uint x5, uint x6, uint x7, uint x8, uint x9, uint x10); - function manyModifiers() modifier1() modifier2() modifier3 modifier4 modifier5 modifier6 modifier7 modifier8 modifier9 modifier10; - function manyReturns() returns(uint y1, uint y2, uint y3, uint y4, uint y5, uint y6, uint y7, uint y8, uint y9, uint y10); - function someParamsSomeModifiers(uint x1, uint x2, uint x3) modifier1() modifier2 modifier3; - function someParamsSomeReturns(uint x1, uint x2, uint x3) returns(uint y1, uint y2, uint y3); - function someModifiersSomeReturns() modifier1 modifier2 modifier3 returns(uint y1, uint y2, uint y3); - function someParamSomeModifiersSomeReturns(uint x1, uint x2, uint x3) modifier1 modifier2 modifier3 returns(uint y1, uint y2, uint y3); - function someParamsManyModifiers(uint x1, uint x2, uint x3) modifier1 modifier2 modifier3 modifier4 modifier5 modifier6 modifier7 modifier8 modifier9 modifier10; - function someParamsManyReturns(uint x1, uint x2, uint x3) returns(uint y1, uint y2, uint y3, uint y4, uint y5, uint y6, uint y7, uint y8, uint y9, uint y10); - function manyParamsSomeModifiers(uint x1, uint x2, uint x3, uint x4, uint x5, uint x6, uint x7, uint x8, uint x9, uint x10) modifier1 modifier2 modifier3; - function manyParamsSomeReturns(uint x1, uint x2, uint x3, uint x4, uint x5, uint x6, uint x7, uint x8, uint x9, uint x10) returns(uint y1, uint y2, uint y3); - function manyParamsManyModifiers(uint x1, uint x2, uint x3, uint x4, uint x5, uint x6, uint x7, uint x8, uint x9, uint x10) modifier1 modifier2 modifier3 modifier4 modifier5 modifier6 modifier7 modifier8 modifier9 modifier10; - function manyParamsManyReturns(uint x1, uint x2, uint x3, uint x4, uint x5, uint x6, uint x7, uint x8, uint x9, uint x10) returns(uint y1, uint y2, uint y3, uint y4, uint y5, uint y6, uint y7, uint y8, uint y9, uint y10); - function manyParamsManyModifiersManyReturns(uint x1, uint x2, uint x3, uint x4, uint x5, uint x6, uint x7, uint x8, uint x9, uint x10) modifier1 modifier2 modifier3 modifier4 modifier5 modifier6 modifier7 modifier8 modifier9 modifier10 returns(uint y1, uint y2, uint y3, uint y4, uint y5, uint y6, uint y7, uint y8, uint y9, uint y10); - function modifierOrderCorrect01() public view virtual override modifier1 modifier2 returns(uint); - function modifierOrderCorrect02() private pure virtual modifier1 modifier2 returns(string); - function modifierOrderCorrect03() external payable override modifier1 modifier2 returns(address); - function modifierOrderCorrect04() internal virtual override modifier1 modifier2 returns(uint); - function modifierOrderIncorrect01() public modifier1 modifier2 override virtual view returns(uint); - function modifierOrderIncorrect02() virtual modifier1 external modifier2 override returns(uint); - function modifierOrderIncorrect03() modifier1 pure internal virtual modifier2 returns(uint); - function modifierOrderIncorrect04() override modifier1 payable external modifier2 returns(uint); -} - -abstract contract FunctionInterfaces { - function functionDefinition0(); - function functionDefinition1(); - function functionDefinition2(); - // Leading Comment - function functionDefinition3(); - function functionDefinition4(); - function functionDefinition5() public {} - function functionDefinition6(); - function functionDefinition7(); // Tailing Comment - function functionDefinition8(); - function functionDefinition9(); -} - -contract FunctionDefinitions { - fallback () external {} - fallback () external payable {} - fallback() external payable virtual {} - fallback(bytes calldata _input) external {} - - receive () external payable {} - receive() external payable virtual {} - - function noParamsNoModifiersNoReturns() { - a = 1; - } - function oneParam(uint x) { - a = 1; - } - function oneModifier() modifier1 { - a = 1; - } - function oneReturn() returns(uint y1) { - a = 1; - } - function manyParams(uint x1, uint x2, uint x3, uint x4, uint x5, uint x6, uint x7, uint x8, uint x9, uint x10) { - a = 1; - } - function manyModifiers() modifier1 modifier2 modifier3 modifier4 modifier5 modifier6 modifier7 modifier8 modifier9 modifier10 { - a = 1; - } - function manyReturns() returns(uint y1, uint y2, uint y3, uint y4, uint y5, uint y6, uint y7, uint y8, uint y9, uint y10) { - a = 1; - } - function someParamsSomeModifiers(uint x1, uint x2, uint x3) modifier1 modifier2 modifier3 { - a = 1; - } - function someParamsSomeReturns(uint x1, uint x2, uint x3) returns(uint y1, uint y2, uint y3) { - a = 1; - } - function someModifiersSomeReturns() modifier1 modifier2 modifier3 returns(uint y1, uint y2, uint y3) { - a = 1; - } - function someParamSomeModifiersSomeReturns(uint x1, uint x2, uint x3) modifier1 modifier2 modifier3 returns(uint y1, uint y2, uint y3) { - a = 1; - } - function someParamsManyModifiers(uint x1, uint x2, uint x3) modifier1 modifier2 modifier3 modifier4 modifier5 modifier6 modifier7 modifier8 modifier9 modifier10 { - a = 1; - } - function someParamsManyReturns(uint x1, uint x2, uint x3) returns(uint y1, uint y2, uint y3, uint y4, uint y5, uint y6, uint y7, uint y8, uint y9, uint y10) { - a = 1; - } - function manyParamsSomeModifiers(uint x1, uint x2, uint x3, uint x4, uint x5, uint x6, uint x7, uint x8, uint x9, uint x10) modifier1 modifier2 modifier3 { - a = 1; - } - function manyParamsSomeReturns(uint x1, uint x2, uint x3, uint x4, uint x5, uint x6, uint x7, uint x8, uint x9, uint x10) returns(uint y1, uint y2, uint y3) { - a = 1; - } - function manyParamsManyModifiers(uint x1, uint x2, uint x3, uint x4, uint x5, uint x6, uint x7, uint x8, uint x9, uint x10) modifier1 modifier2 modifier3 modifier4 modifier5 modifier6 modifier7 modifier8 modifier9 modifier10 public { - a = 1; - } - function manyParamsManyReturns(uint x1, uint x2, uint x3, uint x4, uint x5, uint x6, uint x7, uint x8, uint x9, uint x10) returns(uint y1, uint y2, uint y3, uint y4, uint y5, uint y6, uint y7, uint y8, uint y9, uint y10) { - a = 1; - } - function manyParamsManyModifiersManyReturns(uint x1, uint x2, uint x3, uint x4, uint x5, uint x6, uint x7, uint x8, uint x9, uint x10) modifier1 modifier2 modifier3 modifier4 modifier5 modifier6 modifier7 modifier8 modifier9 modifier10 returns(uint y1, uint y2, uint y3, uint y4, uint y5, uint y6, uint y7, uint y8, uint y9, uint y10) { - a = 1; - } - function modifierOrderCorrect01() public view virtual override modifier1 modifier2 returns(uint) { - a = 1; - } - function modifierOrderCorrect02() private pure virtual modifier1 modifier2 returns(string) { - a = 1; - } - function modifierOrderCorrect03() external payable override modifier1 modifier2 returns(address) { - a = 1; - } - function modifierOrderCorrect04() internal virtual override modifier1 modifier2 returns(uint) { - a = 1; - } - function modifierOrderIncorrect01() public modifier1 modifier2 override virtual view returns(uint) { - a = 1; - } - function modifierOrderIncorrect02() virtual modifier1 external modifier2 override returns(uint) { - a = 1; - } - function modifierOrderIncorrect03() modifier1 pure internal virtual modifier2 returns(uint) { - a = 1; - } - function modifierOrderIncorrect04() override modifier1 payable external modifier2 returns(uint) { - a = 1; - } -} - -=====================================output===================================== -interface FunctionInterfaces { - function noParamsNoModifiersNoReturns(); - function oneParam(uint x); - function oneModifier() modifier1; - function oneReturn() returns (uint y1); - function manyParams( - uint x1, - uint x2, - uint x3, - uint x4, - uint x5, - uint x6, - uint x7, - uint x8, - uint x9, - uint x10 - ); - function manyModifiers() - modifier1() - modifier2() - modifier3 - modifier4 - modifier5 - modifier6 - modifier7 - modifier8 - modifier9 - modifier10; - function manyReturns() - returns ( - uint y1, - uint y2, - uint y3, - uint y4, - uint y5, - uint y6, - uint y7, - uint y8, - uint y9, - uint y10 - ); - function someParamsSomeModifiers( - uint x1, - uint x2, - uint x3 - ) modifier1() modifier2 modifier3; - function someParamsSomeReturns( - uint x1, - uint x2, - uint x3 - ) returns (uint y1, uint y2, uint y3); - function someModifiersSomeReturns() - modifier1 - modifier2 - modifier3 - returns ( - uint y1, - uint y2, - uint y3 - ); - function someParamSomeModifiersSomeReturns( - uint x1, - uint x2, - uint x3 - ) modifier1 modifier2 modifier3 returns (uint y1, uint y2, uint y3); - function someParamsManyModifiers( - uint x1, - uint x2, - uint x3 - ) - modifier1 - modifier2 - modifier3 - modifier4 - modifier5 - modifier6 - modifier7 - modifier8 - modifier9 - modifier10; - function someParamsManyReturns( - uint x1, - uint x2, - uint x3 - ) - returns ( - uint y1, - uint y2, - uint y3, - uint y4, - uint y5, - uint y6, - uint y7, - uint y8, - uint y9, - uint y10 - ); - function manyParamsSomeModifiers( - uint x1, - uint x2, - uint x3, - uint x4, - uint x5, - uint x6, - uint x7, - uint x8, - uint x9, - uint x10 - ) modifier1 modifier2 modifier3; - function manyParamsSomeReturns( - uint x1, - uint x2, - uint x3, - uint x4, - uint x5, - uint x6, - uint x7, - uint x8, - uint x9, - uint x10 - ) returns (uint y1, uint y2, uint y3); - function manyParamsManyModifiers( - uint x1, - uint x2, - uint x3, - uint x4, - uint x5, - uint x6, - uint x7, - uint x8, - uint x9, - uint x10 - ) - modifier1 - modifier2 - modifier3 - modifier4 - modifier5 - modifier6 - modifier7 - modifier8 - modifier9 - modifier10; - function manyParamsManyReturns( - uint x1, - uint x2, - uint x3, - uint x4, - uint x5, - uint x6, - uint x7, - uint x8, - uint x9, - uint x10 - ) - returns ( - uint y1, - uint y2, - uint y3, - uint y4, - uint y5, - uint y6, - uint y7, - uint y8, - uint y9, - uint y10 - ); - function manyParamsManyModifiersManyReturns( - uint x1, - uint x2, - uint x3, - uint x4, - uint x5, - uint x6, - uint x7, - uint x8, - uint x9, - uint x10 - ) - modifier1 - modifier2 - modifier3 - modifier4 - modifier5 - modifier6 - modifier7 - modifier8 - modifier9 - modifier10 - returns ( - uint y1, - uint y2, - uint y3, - uint y4, - uint y5, - uint y6, - uint y7, - uint y8, - uint y9, - uint y10 - ); - function modifierOrderCorrect01() - public - view - virtual - override - modifier1 - modifier2 - returns ( - uint - ); - function modifierOrderCorrect02() - private - pure - virtual - modifier1 - modifier2 - returns ( - string - ); - function modifierOrderCorrect03() - external - payable - override - modifier1 - modifier2 - returns ( - address - ); - function modifierOrderCorrect04() - internal - virtual - override - modifier1 - modifier2 - returns ( - uint - ); - function modifierOrderIncorrect01() - public - modifier1 - modifier2 - override - virtual - view - returns ( - uint - ); - function modifierOrderIncorrect02() - virtual - modifier1 - external - modifier2 - override - returns ( - uint - ); - function modifierOrderIncorrect03() - modifier1 - pure - internal - virtual - modifier2 - returns ( - uint - ); - function modifierOrderIncorrect04() - override - modifier1 - payable - external - modifier2 - returns ( - uint - ); -} - -abstract contract FunctionInterfaces { - function functionDefinition0(); - function functionDefinition1(); - function functionDefinition2(); - function functionDefinition3(); - function functionDefinition4(); - function functionDefinition5() public {} - function functionDefinition6(); - function functionDefinition7(); - function functionDefinition8(); - function functionDefinition9(); -} - -contract FunctionDefinitions { - fallback() external {} - fallback() external payable {} - fallback() external payable virtual {} - fallback(bytes calldata _input) external {} - - receive() external payable {} - receive() external payable virtual {} - - function noParamsNoModifiersNoReturns() { - a = 1; - } - function oneParam(uint x) { - a = 1; - } - function oneModifier() modifier1 { - a = 1; - } - function oneReturn() returns (uint y1) { - a = 1; - } - function manyParams( - uint x1, - uint x2, - uint x3, - uint x4, - uint x5, - uint x6, - uint x7, - uint x8, - uint x9, - uint x10 - ) { - a = 1; - } - function manyModifiers() - modifier1 - modifier2 - modifier3 - modifier4 - modifier5 - modifier6 - modifier7 - modifier8 - modifier9 - modifier10 - { - a = 1; - } - function manyReturns() - returns ( - uint y1, - uint y2, - uint y3, - uint y4, - uint y5, - uint y6, - uint y7, - uint y8, - uint y9, - uint y10 - ) - { - a = 1; - } - function someParamsSomeModifiers( - uint x1, - uint x2, - uint x3 - ) modifier1 modifier2 modifier3 { - a = 1; - } - function someParamsSomeReturns( - uint x1, - uint x2, - uint x3 - ) returns (uint y1, uint y2, uint y3) { - a = 1; - } - function someModifiersSomeReturns() - modifier1 - modifier2 - modifier3 - returns ( - uint y1, - uint y2, - uint y3 - ) - { - a = 1; - } - function someParamSomeModifiersSomeReturns( - uint x1, - uint x2, - uint x3 - ) modifier1 modifier2 modifier3 returns (uint y1, uint y2, uint y3) { - a = 1; - } - function someParamsManyModifiers( - uint x1, - uint x2, - uint x3 - ) - modifier1 - modifier2 - modifier3 - modifier4 - modifier5 - modifier6 - modifier7 - modifier8 - modifier9 - modifier10 - { - a = 1; - } - function someParamsManyReturns( - uint x1, - uint x2, - uint x3 - ) - returns ( - uint y1, - uint y2, - uint y3, - uint y4, - uint y5, - uint y6, - uint y7, - uint y8, - uint y9, - uint y10 - ) - { - a = 1; - } - function manyParamsSomeModifiers( - uint x1, - uint x2, - uint x3, - uint x4, - uint x5, - uint x6, - uint x7, - uint x8, - uint x9, - uint x10 - ) modifier1 modifier2 modifier3 { - a = 1; - } - function manyParamsSomeReturns( - uint x1, - uint x2, - uint x3, - uint x4, - uint x5, - uint x6, - uint x7, - uint x8, - uint x9, - uint x10 - ) returns (uint y1, uint y2, uint y3) { - a = 1; - } - function manyParamsManyModifiers( - uint x1, - uint x2, - uint x3, - uint x4, - uint x5, - uint x6, - uint x7, - uint x8, - uint x9, - uint x10 - ) - modifier1 - modifier2 - modifier3 - modifier4 - modifier5 - modifier6 - modifier7 - modifier8 - modifier9 - modifier10 - public - { - a = 1; - } - function manyParamsManyReturns( - uint x1, - uint x2, - uint x3, - uint x4, - uint x5, - uint x6, - uint x7, - uint x8, - uint x9, - uint x10 - ) - returns ( - uint y1, - uint y2, - uint y3, - uint y4, - uint y5, - uint y6, - uint y7, - uint y8, - uint y9, - uint y10 - ) - { - a = 1; - } - function manyParamsManyModifiersManyReturns( - uint x1, - uint x2, - uint x3, - uint x4, - uint x5, - uint x6, - uint x7, - uint x8, - uint x9, - uint x10 - ) - modifier1 - modifier2 - modifier3 - modifier4 - modifier5 - modifier6 - modifier7 - modifier8 - modifier9 - modifier10 - returns ( - uint y1, - uint y2, - uint y3, - uint y4, - uint y5, - uint y6, - uint y7, - uint y8, - uint y9, - uint y10 - ) - { - a = 1; - } - function modifierOrderCorrect01() - public - view - virtual - override - modifier1 - modifier2 - returns ( - uint - ) - { - a = 1; - } - function modifierOrderCorrect02() - private - pure - virtual - modifier1 - modifier2 - returns ( - string - ) - { - a = 1; - } - function modifierOrderCorrect03() - external - payable - override - modifier1 - modifier2 - returns ( - address - ) - { - a = 1; - } - function modifierOrderCorrect04() - internal - virtual - override - modifier1 - modifier2 - returns ( - uint - ) - { - a = 1; - } - function modifierOrderIncorrect01() - public - modifier1 - modifier2 - override - virtual - view - returns ( - uint - ) - { - a = 1; - } - function modifierOrderIncorrect02() - virtual - modifier1 - external - modifier2 - override - returns ( - uint - ) - { - a = 1; - } - function modifierOrderIncorrect03() - modifier1 - pure - internal - virtual - modifier2 - returns ( - uint - ) - { - a = 1; - } - function modifierOrderIncorrect04() - override - modifier1 - payable - external - modifier2 - returns ( - uint - ) - { - a = 1; - } -} - -================================================================================ -`; diff --git a/tests/format/FunctionDefinitions/jsfmt.spec.js b/tests/format/FunctionDefinitions/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/FunctionDefinitions/jsfmt.spec.js +++ b/tests/format/FunctionDefinitions/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); diff --git a/tests/format/FunctionDefinitionsv0.5.0/__snapshots__/jsfmt.spec.js.snap b/tests/format/FunctionDefinitionsv0.5.0/__snapshots__/jsfmt.spec.js.snap index 71ccc4a35..900ffad07 100644 --- a/tests/format/FunctionDefinitionsv0.5.0/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/FunctionDefinitionsv0.5.0/__snapshots__/jsfmt.spec.js.snap @@ -1,26 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`FunctionDefinitions.sol - {"compiler":"0.5.0"} format 1`] = ` -====================================options===================================== -compiler: "0.5.0" -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -contract FunctionDefinitions { - function () external {} - function () external payable {} -} - -=====================================output===================================== -contract FunctionDefinitions { - function() external {} - function() external payable {} -} - -================================================================================ -`; - exports[`FunctionDefinitions.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] diff --git a/tests/format/FunctionDefinitionsv0.5.0/jsfmt.spec.js b/tests/format/FunctionDefinitionsv0.5.0/jsfmt.spec.js index feedd0559..765dd60a6 100644 --- a/tests/format/FunctionDefinitionsv0.5.0/jsfmt.spec.js +++ b/tests/format/FunctionDefinitionsv0.5.0/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang'], { compiler: '0.5.0' }); diff --git a/tests/format/HexLiteral/__snapshots__/jsfmt.spec.js.snap b/tests/format/HexLiteral/__snapshots__/jsfmt.spec.js.snap index fbfc77c3d..8ae334be2 100644 --- a/tests/format/HexLiteral/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/HexLiteral/__snapshots__/jsfmt.spec.js.snap @@ -1,59 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`HexLiteral.sol - {"compiler":"0.8.25","singleQuote":false} format 1`] = ` -====================================options===================================== -compiler: "0.8.25" -parsers: ["slang"] -printWidth: 80 -singleQuote: false - | printWidth -=====================================input====================================== -// SPDX-License-Identifier: MIT -pragma solidity 0.8.26; - -contract HexLiteral { - bytes8 hex1 = hex'DeadBeef'; - bytes8 hex2 = hex"DeadBeef"; -} - -=====================================output===================================== -pragma solidity 0.8.26; - -contract HexLiteral { - bytes8 hex1 = hex"DeadBeef"; - bytes8 hex2 = hex"DeadBeef"; -} - -================================================================================ -`; - -exports[`HexLiteral.sol - {"compiler":"0.8.25","singleQuote":true} format 1`] = ` -====================================options===================================== -compiler: "0.8.25" -parsers: ["slang"] -printWidth: 80 -singleQuote: true - | printWidth -=====================================input====================================== -// SPDX-License-Identifier: MIT -pragma solidity 0.8.26; - -contract HexLiteral { - bytes8 hex1 = hex'DeadBeef'; - bytes8 hex2 = hex"DeadBeef"; -} - -=====================================output===================================== -pragma solidity 0.8.26; - -contract HexLiteral { - bytes8 hex1 = hex'DeadBeef'; - bytes8 hex2 = hex'DeadBeef'; -} - -================================================================================ -`; - exports[`HexLiteral.sol - {"singleQuote":false} format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] diff --git a/tests/format/HexLiteral/jsfmt.spec.js b/tests/format/HexLiteral/jsfmt.spec.js index 2bf288adf..3272026cc 100644 --- a/tests/format/HexLiteral/jsfmt.spec.js +++ b/tests/format/HexLiteral/jsfmt.spec.js @@ -1,10 +1,2 @@ run_spec(import.meta, ['solidity-parse'], { singleQuote: true }); run_spec(import.meta, ['solidity-parse'], { singleQuote: false }); -run_spec(import.meta, ['slang'], { - compiler: '0.8.25', - singleQuote: true -}); -run_spec(import.meta, ['slang'], { - compiler: '0.8.25', - singleQuote: false -}); diff --git a/tests/format/IfStatements/__snapshots__/jsfmt.spec.js.snap b/tests/format/IfStatements/__snapshots__/jsfmt.spec.js.snap index 8aaba6eba..7ef36a99a 100644 --- a/tests/format/IfStatements/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/IfStatements/__snapshots__/jsfmt.spec.js.snap @@ -532,541 +532,3 @@ contract IfStatements { ================================================================================ `; - -exports[`IfStatements.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -contract IfStatements { - function hi() public { - if (simpleIf) return true; - - if (simpleIf) return (true,true,true,true,true,true,true,true,true,true,true); - - if (simpleIf) return true; - else return false; - - if (simpleIf) return (true,true,true,true,true,true,true,true,true,true,true); - else return false; - - if (simpleIf) return true; - else return (false,false,false,false,false,false,false,false,false,false,false); - - if (simpleIf) return (true,true,true,true,true,true,true,true,true,true,true); - else return (false,false,false,false,false,false,false,false,false,false,false); - - if (simpleIf) return true; - else if (simpleElseIf) return (true,false); - else return false; - - if (simpleIf) return (true,true,true,true,true,true,true,true,true,true,true); - else if (simpleElseIf) return (true,false); - else return false; - - if (simpleIf) return true; - else if (simpleElseIf) return (true,false); - else return (false,false,false,false,false,false,false,false,false,false,false); - - if (simpleIf) return (true,true,true,true,true,true,true,true,true,true,true); - else if (simpleElseIf) return (true,false); - else return (false,false,false,false,false,false,false,false,false,false,false); - - if (simpleIf) return true; - else if (simpleElseIf) return (true,false,true,false,true,false,true,false,true,false); - else return false; - - if (simpleIf) return (true,true,true,true,true,true,true,true,true,true,true); - else if (simpleElseIf) return (true,false,true,false,true,false,true,false,true,false); - else return false; - - if (simpleIf) return true; - else if (simpleElseIf) return (true,false,true,false,true,false,true,false,true,false); - else return (false,false,false,false,false,false,false,false,false,false,false); - - if (simpleIf) return (true,true,true,true,true,true,true,true,true,true,true); - else if (simpleElseIf) return (true,false,true,false,true,false,true,false,true,false); - else return (false,false,false,false,false,false,false,false,false,false,false); - - if (simpleIf) { return true; } - - if (simpleIf) { return true; } - else return false; - - if (simpleIf) return true; - else { return false; } - - if (simpleIf) { return true; } - else { return false; } - - if (simpleIf) { return true; } - else if (simpleElseIf) return (true,false); - else return false; - - if (simpleIf) return true; - else if (simpleElseIf) return (true,false); - else { return false; } - - if (simpleIf) { return true; } - else if (simpleElseIf) return (true,false); - else { return false; } - - if (simpleIf) { return true; } - else if (simpleElseIf) { return (true,false); } - else return false; - - if (simpleIf) return true; - else if (simpleElseIf) { return (true,false); } - else { return false; } - - if (veryComplicatedComputation(variable1, variable2) == (400 + 500) * 1000) { return true; } - - if (simpleIf) { return true; } - else if (veryComplicatedComputation(variable3, variable4) == (400 + 500) * 1000) { return (true,false); } - else return false; - - if (veryComplicatedComputation(variable1, variable2) == (400 + 500) * 1000) { return true; } - else if (simpleElseIf) { return (true,false); } - else return false; - - if (veryComplicatedComputation(variable1, variable2) == (400 + 500) * 1000) { return true; } - else if (veryComplicatedComputation(variable3, variable4) == (400 + 500) * 1000) { return (true,false); } - else return false; - - if (simpleIf) if (simpleIfWithinIf) return true; else return false; - - if (simpleIf) if (simpleIfWithinIf) {return true;} else {return false;} - - if (simpleIf) {if (simpleIfWithinIf) {return true;} else {return false;}} - - if (simpleIf) {if (simpleIfWithinIf) return true;} else return false; - - if (simpleIf) {if (simpleIfWithinIf) {return true;}} else {return false;} - - if (simpleIf) if (simpleIfWithinIf) return true; else return false; else return false; - - if (simpleIf) if (simpleIfWithinIf) {return true;} else {return false;} else {return false;} - - if (simpleIf) {if (simpleIfWithinIf) {return true;} else {return false;}} else return false; - } -} - -=====================================output===================================== -contract IfStatements { - function hi() public { - if (simpleIf) return true; - - if (simpleIf) - return ( - true, - true, - true, - true, - true, - true, - true, - true, - true, - true, - true - ); - - if (simpleIf) return true; - else return false; - - if (simpleIf) - return ( - true, - true, - true, - true, - true, - true, - true, - true, - true, - true, - true - ); - else return false; - - if (simpleIf) return true; - else - return ( - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false - ); - - if (simpleIf) - return ( - true, - true, - true, - true, - true, - true, - true, - true, - true, - true, - true - ); - else - return ( - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false - ); - - if (simpleIf) return true; - else if (simpleElseIf) return (true, false); - else return false; - - if (simpleIf) - return ( - true, - true, - true, - true, - true, - true, - true, - true, - true, - true, - true - ); - else if (simpleElseIf) return (true, false); - else return false; - - if (simpleIf) return true; - else if (simpleElseIf) return (true, false); - else - return ( - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false - ); - - if (simpleIf) - return ( - true, - true, - true, - true, - true, - true, - true, - true, - true, - true, - true - ); - else if (simpleElseIf) return (true, false); - else - return ( - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false - ); - - if (simpleIf) return true; - else if (simpleElseIf) - return ( - true, - false, - true, - false, - true, - false, - true, - false, - true, - false - ); - else return false; - - if (simpleIf) - return ( - true, - true, - true, - true, - true, - true, - true, - true, - true, - true, - true - ); - else if (simpleElseIf) - return ( - true, - false, - true, - false, - true, - false, - true, - false, - true, - false - ); - else return false; - - if (simpleIf) return true; - else if (simpleElseIf) - return ( - true, - false, - true, - false, - true, - false, - true, - false, - true, - false - ); - else - return ( - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false - ); - - if (simpleIf) - return ( - true, - true, - true, - true, - true, - true, - true, - true, - true, - true, - true - ); - else if (simpleElseIf) - return ( - true, - false, - true, - false, - true, - false, - true, - false, - true, - false - ); - else - return ( - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false - ); - - if (simpleIf) { - return true; - } - - if (simpleIf) { - return true; - } else return false; - - if (simpleIf) return true; - else { - return false; - } - - if (simpleIf) { - return true; - } else { - return false; - } - - if (simpleIf) { - return true; - } else if (simpleElseIf) return (true, false); - else return false; - - if (simpleIf) return true; - else if (simpleElseIf) return (true, false); - else { - return false; - } - - if (simpleIf) { - return true; - } else if (simpleElseIf) return (true, false); - else { - return false; - } - - if (simpleIf) { - return true; - } else if (simpleElseIf) { - return (true, false); - } else return false; - - if (simpleIf) return true; - else if (simpleElseIf) { - return (true, false); - } else { - return false; - } - - if ( - veryComplicatedComputation(variable1, variable2) == - (400 + 500) * - 1000 - ) { - return true; - } - - if (simpleIf) { - return true; - } else if ( - veryComplicatedComputation(variable3, variable4) == - (400 + 500) * - 1000 - ) { - return (true, false); - } else return false; - - if ( - veryComplicatedComputation(variable1, variable2) == - (400 + 500) * - 1000 - ) { - return true; - } else if (simpleElseIf) { - return (true, false); - } else return false; - - if ( - veryComplicatedComputation(variable1, variable2) == - (400 + 500) * - 1000 - ) { - return true; - } else if ( - veryComplicatedComputation(variable3, variable4) == - (400 + 500) * - 1000 - ) { - return (true, false); - } else return false; - - if (simpleIf) - if (simpleIfWithinIf) return true; - else return false; - - if (simpleIf) - if (simpleIfWithinIf) { - return true; - } else { - return false; - } - - if (simpleIf) { - if (simpleIfWithinIf) { - return true; - } else { - return false; - } - } - - if (simpleIf) { - if (simpleIfWithinIf) return true; - } else return false; - - if (simpleIf) { - if (simpleIfWithinIf) { - return true; - } - } else { - return false; - } - - if (simpleIf) - if (simpleIfWithinIf) return true; - else return false; - else return false; - - if (simpleIf) - if (simpleIfWithinIf) { - return true; - } else { - return false; - } - else { - return false; - } - - if (simpleIf) { - if (simpleIfWithinIf) { - return true; - } else { - return false; - } - } else return false; - } -} - -================================================================================ -`; diff --git a/tests/format/IfStatements/jsfmt.spec.js b/tests/format/IfStatements/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/IfStatements/jsfmt.spec.js +++ b/tests/format/IfStatements/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); diff --git a/tests/format/Immutable/__snapshots__/jsfmt.spec.js.snap b/tests/format/Immutable/__snapshots__/jsfmt.spec.js.snap index aefc00cd3..373e42afc 100644 --- a/tests/format/Immutable/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Immutable/__snapshots__/jsfmt.spec.js.snap @@ -51,54 +51,3 @@ contract Immutable { ================================================================================ `; - -exports[`Immutable.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity >0.6.4 <0.7.0; - -contract Immutable { - uint constant X = 32**22 + 8; - string constant TEXT = "abc"; - bytes32 constant MY_HASH = keccak256("abc"); - uint immutable decimals; - uint immutable maxBalance; - address immutable owner = msg.sender; - - constructor(uint _decimals, address _reference) public { - decimals = _decimals; - // Assignments to immutables can even access the environment. - maxBalance = _reference.balance; - } - - function isBalanceTooHigh(address _other) public view returns (bool) { - return _other.balance > maxBalance; - } -} - -=====================================output===================================== -pragma solidity >0.6.4 <0.7.0; - -contract Immutable { - uint constant X = 32 ** 22 + 8; - string constant TEXT = "abc"; - bytes32 constant MY_HASH = keccak256("abc"); - uint immutable decimals; - uint immutable maxBalance; - address immutable owner = msg.sender; - - constructor(uint _decimals, address _reference) public { - decimals = _decimals; - maxBalance = _reference.balance; - } - - function isBalanceTooHigh(address _other) public view returns (bool) { - return _other.balance > maxBalance; - } -} - -================================================================================ -`; diff --git a/tests/format/Immutable/jsfmt.spec.js b/tests/format/Immutable/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/Immutable/jsfmt.spec.js +++ b/tests/format/Immutable/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); diff --git a/tests/format/ImportDirective/__snapshots__/jsfmt.spec.js.snap b/tests/format/ImportDirective/__snapshots__/jsfmt.spec.js.snap index 98264ab55..3ec86c724 100644 --- a/tests/format/ImportDirective/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/ImportDirective/__snapshots__/jsfmt.spec.js.snap @@ -1,29 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`ImportDirectives.sol - {"bracketSpacing":true,"compiler":"0.4.26"} format 1`] = ` -====================================options===================================== -bracketSpacing: true -compiler: "0.4.26" -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -import "SomeFile.sol"; -import "SomeFile.sol" as SomeOtherFile; -import * as SomeSymbol from "AnotherFile.sol"; -import {symbol1 as alias, symbol2} from "File.sol"; -import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol"; - -=====================================output===================================== -import "SomeFile.sol"; -import "SomeFile.sol" as SomeOtherFile; -import * as SomeSymbol from "AnotherFile.sol"; -import { symbol1 as alias, symbol2 } from "File.sol"; -import { symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4 } from "File2.sol"; - -================================================================================ -`; - exports[`ImportDirectives.sol - {"bracketSpacing":true} format 1`] = ` ====================================options===================================== bracketSpacing: true @@ -47,29 +23,6 @@ import { symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4 } from ================================================================================ `; -exports[`ImportDirectives.sol - {"compiler":"0.4.26"} format 1`] = ` -====================================options===================================== -compiler: "0.4.26" -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -import "SomeFile.sol"; -import "SomeFile.sol" as SomeOtherFile; -import * as SomeSymbol from "AnotherFile.sol"; -import {symbol1 as alias, symbol2} from "File.sol"; -import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol"; - -=====================================output===================================== -import "SomeFile.sol"; -import "SomeFile.sol" as SomeOtherFile; -import * as SomeSymbol from "AnotherFile.sol"; -import {symbol1 as alias, symbol2} from "File.sol"; -import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol"; - -================================================================================ -`; - exports[`ImportDirectives.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] diff --git a/tests/format/ImportDirective/jsfmt.spec.js b/tests/format/ImportDirective/jsfmt.spec.js index 9ace2a8b2..993a81764 100644 --- a/tests/format/ImportDirective/jsfmt.spec.js +++ b/tests/format/ImportDirective/jsfmt.spec.js @@ -1,7 +1,2 @@ run_spec(import.meta, ['solidity-parse']); run_spec(import.meta, ['solidity-parse'], { bracketSpacing: true }); -run_spec(import.meta, ['slang'], { compiler: '0.4.26' }); -run_spec(import.meta, ['slang'], { - bracketSpacing: true, - compiler: '0.4.26' -}); diff --git a/tests/format/Inbox/__snapshots__/jsfmt.spec.js.snap b/tests/format/Inbox/__snapshots__/jsfmt.spec.js.snap index 41b47dd2a..7ecbcae24 100644 --- a/tests/format/Inbox/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Inbox/__snapshots__/jsfmt.spec.js.snap @@ -76,64 +76,3 @@ contract Inbox { ================================================================================ `; - -exports[`Inbox.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -// This comment spans one line - -/* -This -comment -spans -multiple -lines. -*/ - -pragma solidity ^0.4.23; -contract Inbox { - string public message; - - constructor(string initialMessage) public { - message = initialMessage; - } - - function setMessage(string newMessage) public { - message = newMessage; - } - - function nothingHere() public { - // to be defined - } - - function nothingHereMultipleComments() public { - // to be defined - // to be defined 2 - /* to be defined 3 */ - } -} - - -=====================================output===================================== -pragma solidity ^0.4.23; -contract Inbox { - string public message; - - constructor(string initialMessage) public { - message = initialMessage; - } - - function setMessage(string newMessage) public { - message = newMessage; - } - - function nothingHere() public {} - - function nothingHereMultipleComments() public {} -} - -================================================================================ -`; diff --git a/tests/format/Inbox/jsfmt.spec.js b/tests/format/Inbox/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/Inbox/jsfmt.spec.js +++ b/tests/format/Inbox/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); diff --git a/tests/format/IndexOf/__snapshots__/jsfmt.spec.js.snap b/tests/format/IndexOf/__snapshots__/jsfmt.spec.js.snap index de13806ae..ed75f25aa 100644 --- a/tests/format/IndexOf/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/IndexOf/__snapshots__/jsfmt.spec.js.snap @@ -145,122 +145,3 @@ contract IndexOf { ================================================================================ `; - -exports[`IndexOf.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -contract IndexOf { - - address creator; - - function IndexOf() - { - creator = msg.sender; - } - - int whatwastheval = -10; // -2 = not yet tested, as separate from -1, tested but error - - function indexOf(string _a, string _b) returns (int) // _a = string to search, _b = string we want to find - { - bytes memory a = bytes(_a); - bytes memory b = bytes(_b); - - if(a.length < 1 || b.length < 1 || (b.length > a.length)) - { - whatwastheval = -1; - return -1; - } - else if(a.length > (2**128 -1)) // since we have to be able to return -1 (if the char isn't found or input error), this function must return an "int" type with a max length of (2^128 - 1) - { - whatwastheval = -1; - return -1; - } - else - { - uint subindex = 0; - for (uint i = 0; i < a.length; i ++) - { - if (a[i] == b[0]) // found the first char of b - { - subindex = 1; - while(subindex < b.length && (i + subindex) < a.length && a[i + subindex] == b[subindex]) // search until the chars don't match or until we reach the end of a or b - { - subindex++; - } - if(subindex == b.length) - { - whatwastheval = int(i); - return int(i); - } - } - } - whatwastheval = -1; - return -1; - } - } - - function whatWasTheVal() constant returns (int) - { - return whatwastheval; - } - - /********** - Standard kill() function to recover funds - **********/ - - function kill() - { - if (msg.sender == creator) - { - suicide(creator); // kills this contract and sends remaining funds back to creator - } - } -} - -=====================================output===================================== -contract IndexOf { - address creator; - - function IndexOf() { - creator = msg.sender; - } - - int whatwastheval = -10; - - function indexOf(string _a, string _b) returns (int) { - bytes memory a = bytes(_a); - bytes memory b = bytes(_b); - - if (a.length < 1 || b.length < 1 || (b.length > a.length)) { - whatwastheval = -1; - return -1; - } else if (a.length > (2 ** 128 - 1)) { - whatwastheval = -1; - return -1; - } else { - uint subindex = 0; - for (uint i = 0; i < a.length; i++) { - if (a[i] == b[0]) { - subindex = 1; - while(subindex < b.length && - (i + subindex) < a.length && - a[i + subindex] == b[subindex]){ - subindex++; - } - if (subindex == b.length) { - whatwastheval = int(i); - return int(i); - } - } - } - whatwastheval = -1; - return -1; - } - } -} - -================================================================================ -`; diff --git a/tests/format/IndexOf/jsfmt.spec.js b/tests/format/IndexOf/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/IndexOf/jsfmt.spec.js +++ b/tests/format/IndexOf/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); diff --git a/tests/format/IndexRangeAccess/__snapshots__/jsfmt.spec.js.snap b/tests/format/IndexRangeAccess/__snapshots__/jsfmt.spec.js.snap index 8dc01fd73..acc351b87 100644 --- a/tests/format/IndexRangeAccess/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/IndexRangeAccess/__snapshots__/jsfmt.spec.js.snap @@ -29,33 +29,3 @@ contract Demo { ================================================================================ `; - -exports[`IndexRangeAccess.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity ^0.6.4; - -contract Demo { - event Log(bytes value); - - function log(bytes calldata value) external { - emit Log(bytes(value[0:10])); - } -} - -=====================================output===================================== -pragma solidity ^0.6.4; - -contract Demo { - event Log(bytes value); - - function log(bytes calldata value) external { - emit Log(bytes(value[0:10])); - } -} - -================================================================================ -`; diff --git a/tests/format/IndexRangeAccess/jsfmt.spec.js b/tests/format/IndexRangeAccess/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/IndexRangeAccess/jsfmt.spec.js +++ b/tests/format/IndexRangeAccess/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); diff --git a/tests/format/InheritanceSpecifier/__snapshots__/jsfmt.spec.js.snap b/tests/format/InheritanceSpecifier/__snapshots__/jsfmt.spec.js.snap index f7f1986d6..c95f10839 100644 --- a/tests/format/InheritanceSpecifier/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/InheritanceSpecifier/__snapshots__/jsfmt.spec.js.snap @@ -21,25 +21,3 @@ contract LongInheritanceSpecifier is ================================================================================ `; - -exports[`InheritanceSpecifier.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -contract InheritanceSpecifier is SomeOtherContract(1234,false) {} -contract LongInheritanceSpecifier is SomeOtherContract(123467890,false,0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c) {} - -=====================================output===================================== -contract InheritanceSpecifier is SomeOtherContract(1234, false) {} -contract LongInheritanceSpecifier is - SomeOtherContract( - 123467890, - false, - 0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c - ) -{} - -================================================================================ -`; diff --git a/tests/format/InheritanceSpecifier/jsfmt.spec.js b/tests/format/InheritanceSpecifier/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/InheritanceSpecifier/jsfmt.spec.js +++ b/tests/format/InheritanceSpecifier/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); diff --git a/tests/format/Issues/__snapshots__/jsfmt.spec.js.snap b/tests/format/Issues/__snapshots__/jsfmt.spec.js.snap index fd3ce3cec..145090c30 100644 --- a/tests/format/Issues/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Issues/__snapshots__/jsfmt.spec.js.snap @@ -38,44 +38,6 @@ contract Example { ================================================================================ `; -exports[`Issue205.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -contract Example { - using SafeMath for uint256; - - struct BalanceState { - uint256 balance; - } - - mapping(address => mapping(address => BalanceState)) private balanceStates; - function example(address token, uint amount) public { - balanceStates[msg.sender][token].balance = balanceStates[msg.sender][token].balance.sub(amount); - } -} - -=====================================output===================================== -contract Example { - using SafeMath for uint256; - - struct BalanceState { - uint256 balance; - } - - mapping(address => mapping(address => BalanceState)) private balanceStates; - function example(address token, uint amount) public { - balanceStates[msg.sender][token].balance = balanceStates[msg.sender][ - token - ].balance.sub(amount); - } -} - -================================================================================ -`; - exports[`Issue289.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] @@ -101,31 +63,6 @@ contract Issue289 { ================================================================================ `; -exports[`Issue289.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -contract Issue289 { - function f() { - address[] storage proposalValidators - = ethProposals[_blockNumber][_proposalId].proposalValidators; - } -} - -=====================================output===================================== -contract Issue289 { - function f() { - address[] storage proposalValidators = ethProposals[_blockNumber][ - _proposalId - ].proposalValidators; - } -} - -================================================================================ -`; - exports[`Issue355.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] @@ -162,39 +99,6 @@ contract Bug { ================================================================================ `; -exports[`Issue355.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity 0.6.12; - -contract Bug { - // This is a comment - uint public hello; - - // Another comment - uint public bigNum = 100_000; - - // This will disappear - uint public magic; -} - -=====================================output===================================== -pragma solidity 0.6.12; - -contract Bug { - uint public hello; - - uint public bigNum = 100_000; - - uint public magic; -} - -================================================================================ -`; - exports[`Issue385.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] @@ -233,46 +137,6 @@ contract Issue385 { ================================================================================ `; -exports[`Issue385.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -contract Issue385 { - function emptyTryCatch() { - try - IService(_THIS_SERVICE).server().assign{value: msg.value}( - taskReceipt - ) - {} catch Error(string memory error) { - error.revertWithInfo("BService.delegatecall.assign:"); - } catch { - revert("BService.delegatecall.assign:undefined"); - } - } -} - -=====================================output===================================== -contract Issue385 { - function emptyTryCatch() { - try - IService(_THIS_SERVICE).server().assign{value: msg.value}( - taskReceipt - ) - {} catch Error( - string memory error - ) { - error.revertWithInfo("BService.delegatecall.assign:"); - } catch{ - revert("BService.delegatecall.assign:undefined"); - } - } -} - -================================================================================ -`; - exports[`Issue564.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] @@ -306,38 +170,6 @@ contract Issue564 { ================================================================================ `; -exports[`Issue564.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -contract Issue564 { - function isAuthorized( - bytes32 serviceId, - address client - ) external view override returns (bool) { - WhitelistStatus storage whitelistStatus = serviceIdToClientToWhitelistStatus[serviceId][client]; - return true; - } -} - -=====================================output===================================== -contract Issue564 { - function isAuthorized( - bytes32 serviceId, - address client - ) external view override returns (bool) { - WhitelistStatus storage whitelistStatus = serviceIdToClientToWhitelistStatus[ - serviceId - ][client]; - return true; - } -} - -================================================================================ -`; - exports[`Issue799.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] @@ -352,20 +184,6 @@ struct EmptyStruct {} ================================================================================ `; -exports[`Issue799.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -struct EmptyStruct {} - -=====================================output===================================== -struct EmptyStruct {} - -================================================================================ -`; - exports[`Issue843.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] @@ -393,30 +211,3 @@ contract ContractWithoutComments {} ================================================================================ `; - -exports[`Issue843.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity ^0.8.0; - -//about the contract -contract ContractWithLeadingComment { - -} - -contract ContractWithoutComments { - -} - -=====================================output===================================== -pragma solidity ^0.8.0; - -contract ContractWithLeadingComment {} - -contract ContractWithoutComments {} - -================================================================================ -`; diff --git a/tests/format/Issues/jsfmt.spec.js b/tests/format/Issues/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/Issues/jsfmt.spec.js +++ b/tests/format/Issues/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); diff --git a/tests/format/Libraries/__snapshots__/jsfmt.spec.js.snap b/tests/format/Libraries/__snapshots__/jsfmt.spec.js.snap index 0c79ba81e..35b6b0e6b 100644 --- a/tests/format/Libraries/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Libraries/__snapshots__/jsfmt.spec.js.snap @@ -53,59 +53,6 @@ using { ================================================================================ `; -exports[`Libraries.sol - {"bracketSpacing":true} format 2`] = ` -====================================options===================================== -bracketSpacing: true -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== - using Lib for uint; -using Lib for - uint global; -using { f} for uint; -using {f } for uint global; -using {f as +} for uint global; -using { a, very, long, and, complex, Function, list, with, long, names } for - uint; -using { a, very, - long, and, complex, Function, - list, with, long, names } for uint global; - -=====================================output===================================== -using Lib for uint; -using Lib for uint global; -using { f } for uint; -using { f } for uint global; -using { f as + } for uint global; -using { - a, - very, - long, - and, - complex, - Function, - list, - with, - long, - names -} for uint; -using { - a, - very, - long, - and, - complex, - Function, - list, - with, - long, - names -} for uint global; - -================================================================================ -`; - exports[`Libraries.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] @@ -146,44 +93,3 @@ using { ================================================================================ `; - -exports[`Libraries.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== - using Lib for uint; -using Lib for - uint global; -using { f} for uint; -using {f } for uint global; -using {f as +} for uint global; -using { a, very, long, and, complex, Function, list, with, long, names } for - uint; -using { a, very, - long, and, complex, Function, - list, with, long, names } for uint global; - -=====================================output===================================== -using Lib for uint; -using Lib for uint global; -using {f} for uint; -using {f} for uint global; -using {f as +} for uint global; -using {a, very, long, and, complex, Function, list, with, long, names} for uint; -using { - a, - very, - long, - and, - complex, - Function, - list, - with, - long, - names -} for uint global; - -================================================================================ -`; diff --git a/tests/format/Libraries/jsfmt.spec.js b/tests/format/Libraries/jsfmt.spec.js index 46fbb44d0..993a81764 100644 --- a/tests/format/Libraries/jsfmt.spec.js +++ b/tests/format/Libraries/jsfmt.spec.js @@ -1,4 +1,2 @@ run_spec(import.meta, ['solidity-parse']); run_spec(import.meta, ['solidity-parse'], { bracketSpacing: true }); -run_spec(import.meta, ['slang']); -run_spec(import.meta, ['slang'], { bracketSpacing: true }); diff --git a/tests/format/MemberAccess/__snapshots__/jsfmt.spec.js.snap b/tests/format/MemberAccess/__snapshots__/jsfmt.spec.js.snap index a41dcfb96..ed290e0df 100644 --- a/tests/format/MemberAccess/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/MemberAccess/__snapshots__/jsfmt.spec.js.snap @@ -1,240 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`MemberAccess.sol - {"compiler":"0.5.0"} format 1`] = ` -====================================options===================================== -compiler: "0.5.0" -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity ^0.5.0; - -contract MemberAccess { - function() { - int256 amount = SafeCast.toInt256(10**(18 - underlyingAssetDecimals)).neg(); - longNameAmount = SafeCast.toInt256(10**(18 - underlyingAssetDecimals)).neg(); - a.b.c.d; - a.b().c.d; - a.b.c.d(); - a.b().c().d(); - veryLongVariable.veryLongMember.veryLongMember.veryLongMember.veryLongMember.veryLongMember; - veryLongVariable.veryLongCall(veryLongAttribute).veryLongMember.veryLongMember.veryLongMember; - veryLongVariable.veryLongMember.veryLongCall(veryLongAttribute).veryLongMember.veryLongMember; - veryLongVariable.veryLongMember.veryLongMember.veryLongMember.veryLongCall(veryLongAttribute); - veryLongVariable.veryLongCall(veryLongAttribute).veryLongCall(veryLongAttribute).veryLongCall(veryLongAttribute); - uint256[] memory amounts = IUniswapV2Router(routerAddress) - .swapExactTokensForTokens( - sourceAmount, - minDestination, - path, - address(this, aoeu, aoeueu, aoeu) - )[IUniswapV2Router(routerAddress) - .swapExactTokensForTokens( - sourceAmount, - minDestination, - path, - address(this, aoeu, aoeueu, aoeu) - )]; - uint256[] memory amounts = IUniswapV2Router(routerAddress) - .swapExactTokensForTokens( - sourceAmount, - minDestination, - path, - address(this, aoeu, aoeueu, aoeu) - )[IUniswapV2Router(routerAddress) - .swapExactTokensForTokens( - sourceAmount, - minDestination, - path, - address(this, aoeu, aoeueu, aoeu) - )][IUniswapV2Router(routerAddress) - .swapExactTokensForTokens( - sourceAmount, - minDestination, - path, - address(this, aoeu, aoeueu, aoeu) - )]; - uint256[] memory amounts = IUniswapV2Router(routerAddress) - .swapExactTokensForTokens( - sourceAmount, - minDestination, - path, - address(this, aoeu, aoeueu, aoeu) - )( - sourceAmount, - minDestination, - path, - address(this, aoeu, aoeueu, aoeu) - ); - vm.mockCall( - f.address, - abi.encodeWithSelector(f.selector), - abi.encode(returned1) - ); - } -} - -contract MemberAccessIsEndOfChainCases { - // break if is an ReturnStatement - uint a = b.c; - - function() modifierCase(b.c) { - // break if is an argument of a FunctionCall - a(b.c); - // break if is an index of an IndexAccess - a[b.c]; - // break if is a part of a BinaryOperation - a = b.c; - // break if is a part of a UnaryOperation - !b.c; - // break if is a condition of a IfStatement - if (b.c) {} - // break if is a condition of a WhileStatement - while (b.c) {} - // break if is a part of a ForStatement - // for (b.c;;) {} - for (;b.c;) {} - // for (;;b.c) {} - // break if is a part of a VariableDeclarationStatement - uint a = b.c; - // break if is an ExpressionStatement - b.c; - // break if is an TupleExpression - [a, b.c]; - (b.c); - // break if is an Conditional - a.b ? c : d; - a ? b.c : d; - a ? b : c.d; - // break if is an NameValueList - a.b{value: c.d}(); - // break if is an TryStatement - try a.b() {} catch {} - // break if is an ReturnStatement - return b.c; - } -} - -=====================================output===================================== -pragma solidity ^0.5.0; - -contract MemberAccess { - function() { - int256 amount = SafeCast - .toInt256(10 ** (18 - underlyingAssetDecimals)) - .neg(); - longNameAmount = SafeCast - .toInt256(10 ** (18 - underlyingAssetDecimals)) - .neg(); - a.b.c.d; - a.b().c.d; - a.b.c.d(); - a.b().c().d(); - veryLongVariable - .veryLongMember - .veryLongMember - .veryLongMember - .veryLongMember - .veryLongMember; - veryLongVariable - .veryLongCall(veryLongAttribute) - .veryLongMember - .veryLongMember - .veryLongMember; - veryLongVariable - .veryLongMember - .veryLongCall(veryLongAttribute) - .veryLongMember - .veryLongMember; - veryLongVariable - .veryLongMember - .veryLongMember - .veryLongMember - .veryLongCall(veryLongAttribute); - veryLongVariable - .veryLongCall(veryLongAttribute) - .veryLongCall(veryLongAttribute) - .veryLongCall(veryLongAttribute); - uint256[] memory amounts = IUniswapV2Router(routerAddress) - .swapExactTokensForTokens( - sourceAmount, - minDestination, - path, - address(this, aoeu, aoeueu, aoeu) - )[ - IUniswapV2Router(routerAddress).swapExactTokensForTokens( - sourceAmount, - minDestination, - path, - address(this, aoeu, aoeueu, aoeu) - ) - ]; - uint256[] memory amounts = IUniswapV2Router(routerAddress) - .swapExactTokensForTokens( - sourceAmount, - minDestination, - path, - address(this, aoeu, aoeueu, aoeu) - )[ - IUniswapV2Router(routerAddress).swapExactTokensForTokens( - sourceAmount, - minDestination, - path, - address(this, aoeu, aoeueu, aoeu) - ) - ][ - IUniswapV2Router(routerAddress).swapExactTokensForTokens( - sourceAmount, - minDestination, - path, - address(this, aoeu, aoeueu, aoeu) - ) - ]; - uint256[] memory amounts = IUniswapV2Router(routerAddress) - .swapExactTokensForTokens( - sourceAmount, - minDestination, - path, - address(this, aoeu, aoeueu, aoeu) - )( - sourceAmount, - minDestination, - path, - address(this, aoeu, aoeueu, aoeu) - ); - vm.mockCall( - f.address, - abi.encodeWithSelector(f.selector), - abi.encode(returned1) - ); - } -} - -contract MemberAccessIsEndOfChainCases { - uint a = b.c; - - function() modifierCase(b.c) { - a(b.c); - a[b.c]; - a = b.c; - !b.c; - if (b.c) {} - while(b.c){} - for (; b.c; ) {} - uint a = b.c; - b.c; - [a, b.c]; - (b.c); - a.b ? c : d; - a ? b.c : d; - a ? b : c.d; - a.b; - } -} - -================================================================================ -`; - exports[`MemberAccess.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] diff --git a/tests/format/MemberAccess/jsfmt.spec.js b/tests/format/MemberAccess/jsfmt.spec.js index feedd0559..765dd60a6 100644 --- a/tests/format/MemberAccess/jsfmt.spec.js +++ b/tests/format/MemberAccess/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang'], { compiler: '0.5.0' }); diff --git a/tests/format/ModifierDefinitions/__snapshots__/jsfmt.spec.js.snap b/tests/format/ModifierDefinitions/__snapshots__/jsfmt.spec.js.snap index 750d4d0a2..ffe001f38 100644 --- a/tests/format/ModifierDefinitions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/ModifierDefinitions/__snapshots__/jsfmt.spec.js.snap @@ -31,31 +31,3 @@ contract ModifierDefinitions { ================================================================================ `; - -exports[`ModifierDefinitions.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -contract ModifierDefinitions { - modifier noParams() {} - modifier oneParam(uint a) {} - modifier twoParams(uint a,uint b) {} - modifier threeParams(uint a,uint b ,uint c) {} - modifier test() virtual; - modifier test() virtual {} -} - -=====================================output===================================== -contract ModifierDefinitions { - modifier noParams() {} - modifier oneParam(uint a) {} - modifier twoParams(uint a, uint b) {} - modifier threeParams(uint a, uint b, uint c) {} - modifier test() virtual; - modifier test() virtual {} -} - -================================================================================ -`; diff --git a/tests/format/ModifierDefinitions/jsfmt.spec.js b/tests/format/ModifierDefinitions/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/ModifierDefinitions/jsfmt.spec.js +++ b/tests/format/ModifierDefinitions/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); diff --git a/tests/format/ModifierInvocations/__snapshots__/jsfmt.spec.js.snap b/tests/format/ModifierInvocations/__snapshots__/jsfmt.spec.js.snap index b256f32a3..4e84fd7ab 100644 --- a/tests/format/ModifierInvocations/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/ModifierInvocations/__snapshots__/jsfmt.spec.js.snap @@ -49,48 +49,3 @@ contract ModifierInvocations is ModifierDefinitions { ================================================================================ `; - -exports[`ModifierInvocations.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -// SPDX-License-Identifier: MIT -pragma solidity 0.8.26; - -contract ModifierDefinitions { - // We enforce the use of parentheses in modifiers without parameters. - modifier emptyParams {_;} - modifier noParams() {_;} -} - -contract ModifierInvocations is ModifierDefinitions { - // We can't differentiate between constructor calls or modifiers, so we keep - // parentheses untouched in constructors. - constructor () emptyParams noParams() ModifierDefinitions() {} - - // We remove parentheses in modifiers without arguments. - function test() public emptyParams noParams() {} -} - -=====================================output===================================== -pragma solidity 0.8.26; - -contract ModifierDefinitions { - modifier emptyParams { - _; - } - modifier noParams() { - _; - } -} - -contract ModifierInvocations is ModifierDefinitions { - constructor() emptyParams noParams() ModifierDefinitions() {} - - function test() public emptyParams noParams() {} -} - -================================================================================ -`; diff --git a/tests/format/ModifierInvocations/jsfmt.spec.js b/tests/format/ModifierInvocations/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/ModifierInvocations/jsfmt.spec.js +++ b/tests/format/ModifierInvocations/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); diff --git a/tests/format/MultipartStrings/__snapshots__/jsfmt.spec.js.snap b/tests/format/MultipartStrings/__snapshots__/jsfmt.spec.js.snap index 6f9ab7c57..72f515f66 100644 --- a/tests/format/MultipartStrings/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/MultipartStrings/__snapshots__/jsfmt.spec.js.snap @@ -37,43 +37,3 @@ contract MultipartStrings { ================================================================================ `; - -exports[`MultipartStrings.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -contract MultipartStrings { - bytes b1 = hex'beef'; - bytes b2 = hex"beef"; - bytes b3 = hex"beef" hex"c0ffee"; - bytes b4 = hex"beeeeeeeeeeeeeeeeeeeeeef" hex"c0000000000ffeeeeeeeeeeeeeeeeeee"; - - string s1 = "foo"; - string s2 = "foo" "bar"; - string s3 = "foofoofoofooofoofoofofoooofofoo" "barbarbrabrbarbarbabrabrbabr"; -} - -=====================================output===================================== -contract MultipartStrings { - bytes b1 = hex"beef"; - bytes b2 = hex"beef"; - bytes b3 = - hex"beef" - hex"c0ffee"; - bytes b4 = - hex"beeeeeeeeeeeeeeeeeeeeeef" - hex"c0000000000ffeeeeeeeeeeeeeeeeeee"; - - string s1 = "foo"; - string s2 = - "foo" - "bar"; - string s3 = - "foofoofoofooofoofoofofoooofofoo" - "barbarbrabrbarbarbabrabrbabr"; -} - -================================================================================ -`; diff --git a/tests/format/MultipartStrings/jsfmt.spec.js b/tests/format/MultipartStrings/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/MultipartStrings/jsfmt.spec.js +++ b/tests/format/MultipartStrings/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); diff --git a/tests/format/NameValueExpression/__snapshots__/jsfmt.spec.js.snap b/tests/format/NameValueExpression/__snapshots__/jsfmt.spec.js.snap index 32ff0937b..7bb12c9a8 100644 --- a/tests/format/NameValueExpression/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/NameValueExpression/__snapshots__/jsfmt.spec.js.snap @@ -33,39 +33,6 @@ contract NameValueExpression { ================================================================================ `; -exports[`NameValueExpression.sol - {"bracketSpacing":true} format 2`] = ` -====================================options===================================== -bracketSpacing: true -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity >=0.6.2 <0.7.0; - -contract NameValueExpression { - function callFeed() public { feed.info{value: 10, gas: 800, test: true, many: variables(), to: check[0], forSplits: true}(); } - D newD = new D{value: amount}(arg); -} -=====================================output===================================== -pragma solidity >=0.6.2 <0.7.0; - -contract NameValueExpression { - function callFeed() public { - feed.info{ - value: 10, - gas: 800, - test: true, - many: variables(), - to: check[0], - forSplits: true - }(); - } - D newD = new D{value: amount}(arg); -} - -================================================================================ -`; - exports[`NameValueExpression.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] @@ -97,35 +64,3 @@ contract NameValueExpression { ================================================================================ `; - -exports[`NameValueExpression.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity >=0.6.2 <0.7.0; - -contract NameValueExpression { - function callFeed() public { feed.info{value: 10, gas: 800, test: true, many: variables(), to: check[0], forSplits: true}(); } - D newD = new D{value: amount}(arg); -} -=====================================output===================================== -pragma solidity >=0.6.2 <0.7.0; - -contract NameValueExpression { - function callFeed() public { - feed.info{ - value: 10, - gas: 800, - test: true, - many: variables(), - to: check[0], - forSplits: true - }(); - } - D newD = new D{value: amount}(arg); -} - -================================================================================ -`; diff --git a/tests/format/NameValueExpression/jsfmt.spec.js b/tests/format/NameValueExpression/jsfmt.spec.js index 46fbb44d0..993a81764 100644 --- a/tests/format/NameValueExpression/jsfmt.spec.js +++ b/tests/format/NameValueExpression/jsfmt.spec.js @@ -1,4 +1,2 @@ run_spec(import.meta, ['solidity-parse']); run_spec(import.meta, ['solidity-parse'], { bracketSpacing: true }); -run_spec(import.meta, ['slang']); -run_spec(import.meta, ['slang'], { bracketSpacing: true }); diff --git a/tests/format/NumberLiteral/__snapshots__/jsfmt.spec.js.snap b/tests/format/NumberLiteral/__snapshots__/jsfmt.spec.js.snap index fea20c5dd..3392a346a 100644 --- a/tests/format/NumberLiteral/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/NumberLiteral/__snapshots__/jsfmt.spec.js.snap @@ -37,40 +37,3 @@ contract NumberLiteral { ================================================================================ `; - -exports[`NumberLiteral.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -// SPDX-License-Identifier: MIT -pragma solidity 0.8.26; - -contract NumberLiteral { - function numbers()public { - 2 ether; - 5 days; - 2.3e5; - 1000000e-2; - .1; - 1_000_000; - } -} - -=====================================output===================================== -pragma solidity 0.8.26; - -contract NumberLiteral { - function numbers() public { - 2 ether; - 5 days; - 2.3e5; - 1000000e-2; - .1; - 1_000_000; - } -} - -================================================================================ -`; diff --git a/tests/format/NumberLiteral/jsfmt.spec.js b/tests/format/NumberLiteral/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/NumberLiteral/jsfmt.spec.js +++ b/tests/format/NumberLiteral/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); diff --git a/tests/format/Ownable/__snapshots__/jsfmt.spec.js.snap b/tests/format/Ownable/__snapshots__/jsfmt.spec.js.snap index a36dc587a..a6a2b3930 100644 --- a/tests/format/Ownable/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Ownable/__snapshots__/jsfmt.spec.js.snap @@ -161,133 +161,3 @@ contract Ownable { ================================================================================ `; - -exports[`Ownable.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity ^0.4.24; - -/** - * @title Ownable - * @dev The Ownable contract has an owner address, and provides basic authorization control - * functions, this simplifies the implementation of "user permissions". - */ -contract Ownable { - address private _owner; - - event OwnershipRenounced(address indexed previousOwner); - event OwnershipTransferred( - address indexed previousOwner, - address indexed newOwner - ); - - /** - * @dev The Ownable constructor sets the original \`owner\` of the contract to the sender - * account. - */ - constructor() public { - _owner = msg.sender; - } - - /** - * @return the address of the owner. - */ - function owner() public view returns(address) { - return _owner; - } - - /** - * @dev Throws if called by any account other than the owner. - */ - modifier onlyOwner() { - require(isOwner()); - _; - } - - /** - * @return true if \`msg.sender\` is the owner of the contract. - */ - function isOwner() public view returns(bool) { - return msg.sender == _owner; - } - - /** - * @dev Allows the current owner to relinquish control of the contract. - * @notice Renouncing to ownership will leave the contract without an owner. - * It will not be possible to call the functions with the \`onlyOwner\` - * modifier anymore. - */ - function renounceOwnership() public onlyOwner { - emit OwnershipRenounced(_owner); - _owner = address(0); - } - - /** - * @dev Allows the current owner to transfer control of the contract to a newOwner. - * @param newOwner The address to transfer ownership to. - */ - function transferOwnership(address newOwner) public onlyOwner { - _transferOwnership(newOwner); - } - - /** - * @dev Transfers control of the contract to a newOwner. - * @param newOwner The address to transfer ownership to. - */ - function _transferOwnership(address newOwner) internal { - require(newOwner != address(0)); - emit OwnershipTransferred(_owner, newOwner); - _owner = newOwner; - } -} - -=====================================output===================================== -pragma solidity ^0.4.24; - -contract Ownable { - address private _owner; - - event OwnershipRenounced(address indexed previousOwner); - event OwnershipTransferred( - address indexed previousOwner, - address indexed newOwner - ); - - constructor() public { - _owner = msg.sender; - } - - function owner() public view returns (address) { - return _owner; - } - - modifier onlyOwner() { - require(isOwner()); - _; - } - - function isOwner() public view returns (bool) { - return msg.sender == _owner; - } - - function renounceOwnership() public onlyOwner { - emit OwnershipRenounced(_owner); - _owner = address(0); - } - - function transferOwnership(address newOwner) public onlyOwner { - _transferOwnership(newOwner); - } - - function _transferOwnership(address newOwner) internal { - require(newOwner != address(0)); - emit OwnershipTransferred(_owner, newOwner); - _owner = newOwner; - } -} - -================================================================================ -`; diff --git a/tests/format/Ownable/jsfmt.spec.js b/tests/format/Ownable/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/Ownable/jsfmt.spec.js +++ b/tests/format/Ownable/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); diff --git a/tests/format/Parentheses/__snapshots__/jsfmt.spec.js.snap b/tests/format/Parentheses/__snapshots__/jsfmt.spec.js.snap index 82daedda0..098c17a55 100644 --- a/tests/format/Parentheses/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Parentheses/__snapshots__/jsfmt.spec.js.snap @@ -197,203 +197,204 @@ contract AddNoParentheses { ================================================================================ `; -exports[`AddNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` +exports[`BitAndNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["slang"] +parsers: ["solidity-parse"] printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT pragma solidity 0.8.26; -contract AddNoParentheses { - function addAdd(uint256 a, uint256 b, uint256 c) +contract BitAndNoParentheses { + function bitAndAdd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a + b + c; + return a & b + c; } - function addSub(uint256 a, uint256 b, uint256 c) + function bitAndSub(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a + b - c; + return a & b - c; } - function addMul(uint256 a, uint256 b, uint256 c) + function bitAndMul(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a + b * c; + return a & b * c; } - function addDiv(uint256 a, uint256 b, uint256 c) + function bitAndDiv(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a + b / c; + return a & b / c; } - function addMod(uint256 a, uint256 b, uint256 c) + function bitAndMod(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a + b % c; + return a & b % c; } - function addExp(uint256 a, uint256 b, uint256 c) + function bitAndExp(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a + b ** c; + return a & b ** c; } - function addShiftL(uint256 a, uint256 b, uint256 c) + function bitAndShiftL(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a + b << c; + return a & b << c; } - function addShiftR(uint256 a, uint256 b, uint256 c) + function bitAndShiftR(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a + b >> c; + return a & b >> c; } - function addBitAnd(uint256 a, uint256 b, uint256 c) + function bitAndBitAnd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a + b & c; + return a & b & c; } - function addBitOr(uint256 a, uint256 b, uint256 c) + function bitAndBitOr(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a + b | c; + return a & b | c; } - function addBitXor(uint256 a, uint256 b, uint256 c) + function bitAndBitXor(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a + b ^ c; + return a & b ^ c; } } =====================================output===================================== +// SPDX-License-Identifier: MIT pragma solidity 0.8.26; -contract AddNoParentheses { - function addAdd( +contract BitAndNoParentheses { + function bitAndAdd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a + b + c; + return a & (b + c); } - function addSub( + function bitAndSub( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a + b - c; + return a & (b - c); } - function addMul( + function bitAndMul( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a + b * c; + return a & (b * c); } - function addDiv( + function bitAndDiv( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a + b / c; + return a & (b / c); } - function addMod( + function bitAndMod( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a + (b % c); + return a & b % c; } - function addExp( + function bitAndExp( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a + b ** c; + return a & (b ** c); } - function addShiftL( + function bitAndShiftL( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a + b) << c; + return a & (b << c); } - function addShiftR( + function bitAndShiftR( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a + b) >> c; + return a & (b >> c); } - function addBitAnd( + function bitAndBitAnd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a + b) & c; + return a & b & c; } - function addBitOr( + function bitAndBitOr( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a + b) | c; + return (a & b) | c; } - function addBitXor( + function bitAndBitXor( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a + b) ^ c; + return (a & b) ^ c; } } ================================================================================ `; -exports[`BitAndNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` +exports[`BitOrNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` ====================================options===================================== compiler: "0.8.6" parsers: ["solidity-parse"] @@ -403,93 +404,93 @@ printWidth: 80 // SPDX-License-Identifier: MIT pragma solidity 0.8.26; -contract BitAndNoParentheses { - function bitAndAdd(uint256 a, uint256 b, uint256 c) +contract BitOrNoParentheses { + function bitOrAdd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a & b + c; + return a | b + c; } - function bitAndSub(uint256 a, uint256 b, uint256 c) + function bitOrSub(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a & b - c; + return a | b - c; } - function bitAndMul(uint256 a, uint256 b, uint256 c) + function bitOrMul(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a & b * c; + return a | b * c; } - function bitAndDiv(uint256 a, uint256 b, uint256 c) + function bitOrDiv(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a & b / c; + return a | b / c; } - function bitAndMod(uint256 a, uint256 b, uint256 c) + function bitOrMod(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a & b % c; + return a | b % c; } - function bitAndExp(uint256 a, uint256 b, uint256 c) + function bitOrExp(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a & b ** c; + return a | b ** c; } - function bitAndShiftL(uint256 a, uint256 b, uint256 c) + function bitOrShiftL(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a & b << c; + return a | b << c; } - function bitAndShiftR(uint256 a, uint256 b, uint256 c) + function bitOrShiftR(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a & b >> c; + return a | b >> c; } - function bitAndBitAnd(uint256 a, uint256 b, uint256 c) + function bitOrBitAnd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a & b & c; + return a | b & c; } - function bitAndBitOr(uint256 a, uint256 b, uint256 c) + function bitOrBitOr(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a & b | c; + return a | b | c; } - function bitAndBitXor(uint256 a, uint256 b, uint256 c) + function bitOrBitXor(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a & b ^ c; + return a | b ^ c; } } @@ -497,296 +498,297 @@ contract BitAndNoParentheses { // SPDX-License-Identifier: MIT pragma solidity 0.8.26; -contract BitAndNoParentheses { - function bitAndAdd( +contract BitOrNoParentheses { + function bitOrAdd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a & (b + c); + return a | (b + c); } - function bitAndSub( + function bitOrSub( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a & (b - c); + return a | (b - c); } - function bitAndMul( + function bitOrMul( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a & (b * c); + return a | (b * c); } - function bitAndDiv( + function bitOrDiv( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a & (b / c); + return a | (b / c); } - function bitAndMod( + function bitOrMod( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a & b % c; + return a | b % c; } - function bitAndExp( + function bitOrExp( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a & (b ** c); + return a | (b ** c); } - function bitAndShiftL( + function bitOrShiftL( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a & (b << c); + return a | (b << c); } - function bitAndShiftR( + function bitOrShiftR( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a & (b >> c); + return a | (b >> c); } - function bitAndBitAnd( + function bitOrBitAnd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a & b & c; + return a | (b & c); } - function bitAndBitOr( + function bitOrBitOr( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a & b) | c; + return a | b | c; } - function bitAndBitXor( + function bitOrBitXor( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a & b) ^ c; + return a | (b ^ c); } } ================================================================================ `; -exports[`BitAndNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` +exports[`BitXorNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["slang"] +parsers: ["solidity-parse"] printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT pragma solidity 0.8.26; -contract BitAndNoParentheses { - function bitAndAdd(uint256 a, uint256 b, uint256 c) +contract BitXorNoParentheses { + function bitXorAdd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a & b + c; + return a ^ b + c; } - function bitAndSub(uint256 a, uint256 b, uint256 c) + function bitXorSub(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a & b - c; + return a ^ b - c; } - function bitAndMul(uint256 a, uint256 b, uint256 c) + function bitXorMul(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a & b * c; + return a ^ b * c; } - function bitAndDiv(uint256 a, uint256 b, uint256 c) + function bitXorDiv(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a & b / c; + return a ^ b / c; } - function bitAndMod(uint256 a, uint256 b, uint256 c) + function bitXorMod(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a & b % c; + return a ^ b % c; } - function bitAndExp(uint256 a, uint256 b, uint256 c) + function bitXorExp(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a & b ** c; + return a ^ b ** c; } - function bitAndShiftL(uint256 a, uint256 b, uint256 c) + function bitXorShiftL(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a & b << c; + return a ^ b << c; } - function bitAndShiftR(uint256 a, uint256 b, uint256 c) + function bitXorShiftR(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a & b >> c; + return a ^ b >> c; } - function bitAndBitAnd(uint256 a, uint256 b, uint256 c) + function bitXorBitAnd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a & b & c; + return a ^ b & c; } - function bitAndBitOr(uint256 a, uint256 b, uint256 c) + function bitXorBitOr(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a & b | c; + return a ^ b | c; } - function bitAndBitXor(uint256 a, uint256 b, uint256 c) + function bitXorBitXor(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a & b ^ c; + return a ^ b ^ c; } } =====================================output===================================== +// SPDX-License-Identifier: MIT pragma solidity 0.8.26; -contract BitAndNoParentheses { - function bitAndAdd( +contract BitXorNoParentheses { + function bitXorAdd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a & (b + c); + return a ^ (b + c); } - function bitAndSub( + function bitXorSub( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a & (b - c); + return a ^ (b - c); } - function bitAndMul( + function bitXorMul( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a & (b * c); + return a ^ (b * c); } - function bitAndDiv( + function bitXorDiv( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a & (b / c); + return a ^ (b / c); } - function bitAndMod( + function bitXorMod( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a & b % c; + return a ^ b % c; } - function bitAndExp( + function bitXorExp( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a & (b ** c); + return a ^ (b ** c); } - function bitAndShiftL( + function bitXorShiftL( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a & (b << c); + return a ^ (b << c); } - function bitAndShiftR( + function bitXorShiftR( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a & (b >> c); + return a ^ (b >> c); } - function bitAndBitAnd( + function bitXorBitAnd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a & b & c; + return a ^ (b & c); } - function bitAndBitOr( + function bitXorBitOr( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a & b) | c; + return (a ^ b) | c; } - function bitAndBitXor( + function bitXorBitXor( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a & b) ^ c; + return a ^ b ^ c; } } ================================================================================ `; -exports[`BitOrNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` +exports[`DivNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` ====================================options===================================== compiler: "0.8.6" parsers: ["solidity-parse"] @@ -796,93 +798,93 @@ printWidth: 80 // SPDX-License-Identifier: MIT pragma solidity 0.8.26; -contract BitOrNoParentheses { - function bitOrAdd(uint256 a, uint256 b, uint256 c) +contract DivNoParentheses { + function divAdd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a | b + c; + return a / b + c; } - function bitOrSub(uint256 a, uint256 b, uint256 c) + function divSub(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a | b - c; + return a / b - c; } - function bitOrMul(uint256 a, uint256 b, uint256 c) + function divMul(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a | b * c; + return a / b * c; } - function bitOrDiv(uint256 a, uint256 b, uint256 c) + function divDiv(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a | b / c; + return a / b / c; } - function bitOrMod(uint256 a, uint256 b, uint256 c) + function divMod(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a | b % c; + return a / b % c; } - function bitOrExp(uint256 a, uint256 b, uint256 c) + function divExp(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a | b ** c; + return a / b ** c; } - function bitOrShiftL(uint256 a, uint256 b, uint256 c) + function divShiftL(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a | b << c; + return a / b << c; } - function bitOrShiftR(uint256 a, uint256 b, uint256 c) + function divShiftR(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a | b >> c; + return a / b >> c; } - function bitOrBitAnd(uint256 a, uint256 b, uint256 c) + function divBitAnd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a | b & c; + return a / b & c; } - function bitOrBitOr(uint256 a, uint256 b, uint256 c) + function divBitOr(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a | b | c; + return a / b | c; } - function bitOrBitXor(uint256 a, uint256 b, uint256 c) + function divBitXor(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a | b ^ c; + return a / b ^ c; } } @@ -890,296 +892,297 @@ contract BitOrNoParentheses { // SPDX-License-Identifier: MIT pragma solidity 0.8.26; -contract BitOrNoParentheses { - function bitOrAdd( +contract DivNoParentheses { + function divAdd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | (b + c); + return a / b + c; } - function bitOrSub( + function divSub( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | (b - c); + return a / b - c; } - function bitOrMul( + function divMul( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | (b * c); + return (a / b) * c; } - function bitOrDiv( + function divDiv( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | (b / c); + return a / b / c; } - function bitOrMod( + function divMod( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | b % c; + return (a / b) % c; } - function bitOrExp( + function divExp( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | (b ** c); + return a / b ** c; } - function bitOrShiftL( + function divShiftL( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | (b << c); + return (a / b) << c; } - function bitOrShiftR( + function divShiftR( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | (b >> c); + return (a / b) >> c; } - function bitOrBitAnd( + function divBitAnd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | (b & c); + return (a / b) & c; } - function bitOrBitOr( + function divBitOr( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | b | c; + return (a / b) | c; } - function bitOrBitXor( + function divBitXor( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | (b ^ c); + return (a / b) ^ c; } } ================================================================================ `; -exports[`BitOrNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` +exports[`ExpNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["slang"] +parsers: ["solidity-parse"] printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT pragma solidity 0.8.26; -contract BitOrNoParentheses { - function bitOrAdd(uint256 a, uint256 b, uint256 c) +contract ExpNoParentheses { + function expAdd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a | b + c; + return a ** b + c; } - function bitOrSub(uint256 a, uint256 b, uint256 c) + function expSub(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a | b - c; + return a ** b - c; } - function bitOrMul(uint256 a, uint256 b, uint256 c) + function expMul(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a | b * c; + return a ** b * c; } - function bitOrDiv(uint256 a, uint256 b, uint256 c) + function expDiv(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a | b / c; + return a ** b / c; } - function bitOrMod(uint256 a, uint256 b, uint256 c) + function expMod(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a | b % c; + return a ** b % c; } - function bitOrExp(uint256 a, uint256 b, uint256 c) + function expExp(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a | b ** c; + return a ** b ** c; } - function bitOrShiftL(uint256 a, uint256 b, uint256 c) + function expShiftL(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a | b << c; + return a ** b << c; } - function bitOrShiftR(uint256 a, uint256 b, uint256 c) + function expShiftR(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a | b >> c; + return a ** b >> c; } - function bitOrBitAnd(uint256 a, uint256 b, uint256 c) + function expBitAnd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a | b & c; + return a ** b & c; } - function bitOrBitOr(uint256 a, uint256 b, uint256 c) + function expBitOr(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a | b | c; + return a ** b | c; } - function bitOrBitXor(uint256 a, uint256 b, uint256 c) + function expBitXor(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a | b ^ c; + return a ** b ^ c; } } =====================================output===================================== +// SPDX-License-Identifier: MIT pragma solidity 0.8.26; -contract BitOrNoParentheses { - function bitOrAdd( +contract ExpNoParentheses { + function expAdd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | (b + c); + return a ** b + c; } - function bitOrSub( + function expSub( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | (b - c); + return a ** b - c; } - function bitOrMul( + function expMul( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | (b * c); + return a ** b * c; } - function bitOrDiv( + function expDiv( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | (b / c); + return a ** b / c; } - function bitOrMod( + function expMod( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | b % c; + return a ** b % c; } - function bitOrExp( + function expExp( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | (b ** c); + return a ** (b ** c); } - function bitOrShiftL( + function expShiftL( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | (b << c); + return (a ** b) << c; } - function bitOrShiftR( + function expShiftR( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | (b >> c); + return (a ** b) >> c; } - function bitOrBitAnd( + function expBitAnd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | (b & c); + return (a ** b) & c; } - function bitOrBitOr( + function expBitOr( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | b | c; + return (a ** b) | c; } - function bitOrBitXor( + function expBitXor( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a | (b ^ c); + return (a ** b) ^ c; } } ================================================================================ `; -exports[`BitXorNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` +exports[`LogicNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` ====================================options===================================== compiler: "0.8.6" parsers: ["solidity-parse"] @@ -1189,2460 +1192,247 @@ printWidth: 80 // SPDX-License-Identifier: MIT pragma solidity 0.8.26; -contract BitXorNoParentheses { - function bitXorAdd(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ^ b + c; +contract LogicNoParentheses { + function orOr(bool a, bool b, bool c) public pure returns (bool) { + return a || b || c; } - function bitXorSub(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ^ b - c; + function orAnd(bool a, bool b, bool c) public pure returns (bool) { + return a || b && c; } - function bitXorMul(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ^ b * c; + function andOr(bool a, bool b, bool c) public pure returns (bool) { + return a && b || c; } - function bitXorDiv(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ^ b / c; + function andAnd(bool a, bool b, bool c) public pure returns (bool) { + return a && b && c; } - - function bitXorMod(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ^ b % c; - } - - function bitXorExp(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ^ b ** c; - } - - function bitXorShiftL(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ^ b << c; - } - - function bitXorShiftR(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ^ b >> c; - } - - function bitXorBitAnd(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ^ b & c; - } - - function bitXorBitOr(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ^ b | c; - } - - function bitXorBitXor(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ^ b ^ c; - } -} - -=====================================output===================================== -// SPDX-License-Identifier: MIT -pragma solidity 0.8.26; - -contract BitXorNoParentheses { - function bitXorAdd( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a ^ (b + c); - } - - function bitXorSub( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a ^ (b - c); - } - - function bitXorMul( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a ^ (b * c); - } - - function bitXorDiv( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a ^ (b / c); - } - - function bitXorMod( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a ^ b % c; - } - - function bitXorExp( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a ^ (b ** c); - } - - function bitXorShiftL( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a ^ (b << c); - } - - function bitXorShiftR( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a ^ (b >> c); - } - - function bitXorBitAnd( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a ^ (b & c); - } - - function bitXorBitOr( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a ^ b) | c; - } - - function bitXorBitXor( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a ^ b ^ c; - } -} - -================================================================================ -`; - -exports[`BitXorNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` -====================================options===================================== -compiler: "0.8.6" -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -// SPDX-License-Identifier: MIT -pragma solidity 0.8.26; - -contract BitXorNoParentheses { - function bitXorAdd(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ^ b + c; - } - - function bitXorSub(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ^ b - c; - } - - function bitXorMul(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ^ b * c; - } - - function bitXorDiv(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ^ b / c; - } - - function bitXorMod(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ^ b % c; - } - - function bitXorExp(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ^ b ** c; - } - - function bitXorShiftL(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ^ b << c; - } - - function bitXorShiftR(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ^ b >> c; - } - - function bitXorBitAnd(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ^ b & c; - } - - function bitXorBitOr(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ^ b | c; - } - - function bitXorBitXor(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ^ b ^ c; - } -} - -=====================================output===================================== -pragma solidity 0.8.26; - -contract BitXorNoParentheses { - function bitXorAdd( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a ^ (b + c); - } - - function bitXorSub( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a ^ (b - c); - } - - function bitXorMul( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a ^ (b * c); - } - - function bitXorDiv( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a ^ (b / c); - } - - function bitXorMod( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a ^ b % c; - } - - function bitXorExp( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a ^ (b ** c); - } - - function bitXorShiftL( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a ^ (b << c); - } - - function bitXorShiftR( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a ^ (b >> c); - } - - function bitXorBitAnd( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a ^ (b & c); - } - - function bitXorBitOr( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a ^ b) | c; - } - - function bitXorBitXor( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a ^ b ^ c; - } -} - -================================================================================ -`; - -exports[`DivNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` -====================================options===================================== -compiler: "0.8.6" -parsers: ["solidity-parse"] -printWidth: 80 - | printWidth -=====================================input====================================== -// SPDX-License-Identifier: MIT -pragma solidity 0.8.26; - -contract DivNoParentheses { - function divAdd(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a / b + c; - } - - function divSub(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a / b - c; - } - - function divMul(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a / b * c; - } - - function divDiv(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a / b / c; - } - - function divMod(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a / b % c; - } - - function divExp(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a / b ** c; - } - - function divShiftL(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a / b << c; - } - - function divShiftR(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a / b >> c; - } - - function divBitAnd(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a / b & c; - } - - function divBitOr(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a / b | c; - } - - function divBitXor(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a / b ^ c; - } -} - -=====================================output===================================== -// SPDX-License-Identifier: MIT -pragma solidity 0.8.26; - -contract DivNoParentheses { - function divAdd( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a / b + c; - } - - function divSub( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a / b - c; - } - - function divMul( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a / b) * c; - } - - function divDiv( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a / b / c; - } - - function divMod( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a / b) % c; - } - - function divExp( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a / b ** c; - } - - function divShiftL( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a / b) << c; - } - - function divShiftR( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a / b) >> c; - } - - function divBitAnd( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a / b) & c; - } - - function divBitOr( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a / b) | c; - } - - function divBitXor( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a / b) ^ c; - } -} - -================================================================================ -`; - -exports[`DivNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` -====================================options===================================== -compiler: "0.8.6" -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -// SPDX-License-Identifier: MIT -pragma solidity 0.8.26; - -contract DivNoParentheses { - function divAdd(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a / b + c; - } - - function divSub(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a / b - c; - } - - function divMul(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a / b * c; - } - - function divDiv(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a / b / c; - } - - function divMod(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a / b % c; - } - - function divExp(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a / b ** c; - } - - function divShiftL(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a / b << c; - } - - function divShiftR(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a / b >> c; - } - - function divBitAnd(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a / b & c; - } - - function divBitOr(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a / b | c; - } - - function divBitXor(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a / b ^ c; - } -} - -=====================================output===================================== -pragma solidity 0.8.26; - -contract DivNoParentheses { - function divAdd( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a / b + c; - } - - function divSub( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a / b - c; - } - - function divMul( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a / b) * c; - } - - function divDiv( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a / b / c; - } - - function divMod( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a / b) % c; - } - - function divExp( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a / b ** c; - } - - function divShiftL( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a / b) << c; - } - - function divShiftR( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a / b) >> c; - } - - function divBitAnd( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a / b) & c; - } - - function divBitOr( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a / b) | c; - } - - function divBitXor( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a / b) ^ c; - } -} - -================================================================================ -`; - -exports[`ExpNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` -====================================options===================================== -compiler: "0.8.6" -parsers: ["solidity-parse"] -printWidth: 80 - | printWidth -=====================================input====================================== -// SPDX-License-Identifier: MIT -pragma solidity 0.8.26; - -contract ExpNoParentheses { - function expAdd(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ** b + c; - } - - function expSub(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ** b - c; - } - - function expMul(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ** b * c; - } - - function expDiv(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ** b / c; - } - - function expMod(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ** b % c; - } - - function expExp(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ** b ** c; - } - - function expShiftL(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ** b << c; - } - - function expShiftR(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ** b >> c; - } - - function expBitAnd(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ** b & c; - } - - function expBitOr(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ** b | c; - } - - function expBitXor(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ** b ^ c; - } -} - -=====================================output===================================== -// SPDX-License-Identifier: MIT -pragma solidity 0.8.26; - -contract ExpNoParentheses { - function expAdd( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a ** b + c; - } - - function expSub( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a ** b - c; - } - - function expMul( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a ** b * c; - } - - function expDiv( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a ** b / c; - } - - function expMod( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a ** b % c; - } - - function expExp( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a ** (b ** c); - } - - function expShiftL( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a ** b) << c; - } - - function expShiftR( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a ** b) >> c; - } - - function expBitAnd( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a ** b) & c; - } - - function expBitOr( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a ** b) | c; - } - - function expBitXor( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a ** b) ^ c; - } -} - -================================================================================ -`; - -exports[`ExpNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` -====================================options===================================== -compiler: "0.8.6" -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -// SPDX-License-Identifier: MIT -pragma solidity 0.8.26; - -contract ExpNoParentheses { - function expAdd(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ** b + c; - } - - function expSub(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ** b - c; - } - - function expMul(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ** b * c; - } - - function expDiv(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ** b / c; - } - - function expMod(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ** b % c; - } - - function expExp(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ** b ** c; - } - - function expShiftL(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ** b << c; - } - - function expShiftR(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ** b >> c; - } - - function expBitAnd(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ** b & c; - } - - function expBitOr(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ** b | c; - } - - function expBitXor(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a ** b ^ c; - } -} - -=====================================output===================================== -pragma solidity 0.8.26; - -contract ExpNoParentheses { - function expAdd( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a ** b + c; - } - - function expSub( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a ** b - c; - } - - function expMul( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a ** b * c; - } - - function expDiv( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a ** b / c; - } - - function expMod( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a ** b % c; - } - - function expExp( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a ** (b ** c); - } - - function expShiftL( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a ** b) << c; - } - - function expShiftR( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a ** b) >> c; - } - - function expBitAnd( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a ** b) & c; - } - - function expBitOr( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a ** b) | c; - } - - function expBitXor( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a ** b) ^ c; - } -} - -================================================================================ -`; - -exports[`LogicNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` -====================================options===================================== -compiler: "0.8.6" -parsers: ["solidity-parse"] -printWidth: 80 - | printWidth -=====================================input====================================== -// SPDX-License-Identifier: MIT -pragma solidity 0.8.26; - -contract LogicNoParentheses { - function orOr(bool a, bool b, bool c) public pure returns (bool) { - return a || b || c; - } - - function orAnd(bool a, bool b, bool c) public pure returns (bool) { - return a || b && c; - } - - function andOr(bool a, bool b, bool c) public pure returns (bool) { - return a && b || c; - } - - function andAnd(bool a, bool b, bool c) public pure returns (bool) { - return a && b && c; - } -} - -=====================================output===================================== -// SPDX-License-Identifier: MIT -pragma solidity 0.8.26; - -contract LogicNoParentheses { - function orOr(bool a, bool b, bool c) public pure returns (bool) { - return a || b || c; - } - - function orAnd(bool a, bool b, bool c) public pure returns (bool) { - return a || (b && c); - } - - function andOr(bool a, bool b, bool c) public pure returns (bool) { - return (a && b) || c; - } - - function andAnd(bool a, bool b, bool c) public pure returns (bool) { - return a && b && c; - } -} - -================================================================================ -`; - -exports[`LogicNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` -====================================options===================================== -compiler: "0.8.6" -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -// SPDX-License-Identifier: MIT -pragma solidity 0.8.26; - -contract LogicNoParentheses { - function orOr(bool a, bool b, bool c) public pure returns (bool) { - return a || b || c; - } - - function orAnd(bool a, bool b, bool c) public pure returns (bool) { - return a || b && c; - } - - function andOr(bool a, bool b, bool c) public pure returns (bool) { - return a && b || c; - } - - function andAnd(bool a, bool b, bool c) public pure returns (bool) { - return a && b && c; - } -} - -=====================================output===================================== -pragma solidity 0.8.26; - -contract LogicNoParentheses { - function orOr(bool a, bool b, bool c) public pure returns (bool) { - return a || b || c; - } - - function orAnd(bool a, bool b, bool c) public pure returns (bool) { - return a || (b && c); - } - - function andOr(bool a, bool b, bool c) public pure returns (bool) { - return (a && b) || c; - } - - function andAnd(bool a, bool b, bool c) public pure returns (bool) { - return a && b && c; - } -} - -================================================================================ -`; - -exports[`ModNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` -====================================options===================================== -compiler: "0.8.6" -parsers: ["solidity-parse"] -printWidth: 80 - | printWidth -=====================================input====================================== -// SPDX-License-Identifier: MIT -pragma solidity 0.8.26; - -contract ModNoParentheses { - function modAdd(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a % b + c; - } - - function modSub(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a % b - c; - } - - function modMul(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a % b * c; - } - - function modDiv(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a % b / c; - } - - function modMod(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a % b % c; - } - - function modExp(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a % b ** c; - } - - function modShiftL(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a % b << c; - } - - function modShiftR(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a % b >> c; - } - - function modBitAnd(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a % b & c; - } - - function modBitOr(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a % b | c; - } - - function modBitXor(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a % b ^ c; - } -} - -=====================================output===================================== -// SPDX-License-Identifier: MIT -pragma solidity 0.8.26; - -contract ModNoParentheses { - function modAdd( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a % b) + c; - } - - function modSub( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a % b) - c; - } - - function modMul( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a % b) * c; - } - - function modDiv( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a % b) / c; - } - - function modMod( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a % b) % c; - } - - function modExp( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a % b ** c; - } - - function modShiftL( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a % b << c; - } - - function modShiftR( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a % b >> c; - } - - function modBitAnd( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a % b & c; - } - - function modBitOr( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a % b | c; - } - - function modBitXor( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a % b ^ c; - } -} - -================================================================================ -`; - -exports[`ModNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` -====================================options===================================== -compiler: "0.8.6" -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -// SPDX-License-Identifier: MIT -pragma solidity 0.8.26; - -contract ModNoParentheses { - function modAdd(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a % b + c; - } - - function modSub(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a % b - c; - } - - function modMul(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a % b * c; - } - - function modDiv(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a % b / c; - } - - function modMod(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a % b % c; - } - - function modExp(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a % b ** c; - } - - function modShiftL(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a % b << c; - } - - function modShiftR(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a % b >> c; - } - - function modBitAnd(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a % b & c; - } - - function modBitOr(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a % b | c; - } - - function modBitXor(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a % b ^ c; - } -} - -=====================================output===================================== -pragma solidity 0.8.26; - -contract ModNoParentheses { - function modAdd( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a % b) + c; - } - - function modSub( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a % b) - c; - } - - function modMul( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a % b) * c; - } - - function modDiv( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a % b) / c; - } - - function modMod( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a % b) % c; - } - - function modExp( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a % b ** c; - } - - function modShiftL( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a % b << c; - } - - function modShiftR( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a % b >> c; - } - - function modBitAnd( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a % b & c; - } - - function modBitOr( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a % b | c; - } - - function modBitXor( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a % b ^ c; - } -} - -================================================================================ -`; - -exports[`MulNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` -====================================options===================================== -compiler: "0.8.6" -parsers: ["solidity-parse"] -printWidth: 80 - | printWidth -=====================================input====================================== -// SPDX-License-Identifier: MIT -pragma solidity 0.8.26; - -contract MulNoParentheses { - function mulAdd(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a * b + c; - } - - function mulSub(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a * b - c; - } - - function mulMul(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a * b * c; - } - - function mulDiv(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a * b / c; - } - - function mulMod(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a * b % c; - } - - function mulExp(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a * b ** c; - } - - function mulShiftL(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a * b << c; - } - - function mulShiftR(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a * b >> c; - } - - function mulBitAnd(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a * b & c; - } - - function mulBitOr(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a * b | c; - } - - function mulBitXor(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a * b ^ c; - } -} - -=====================================output===================================== -// SPDX-License-Identifier: MIT -pragma solidity 0.8.26; - -contract MulNoParentheses { - function mulAdd( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a * b + c; - } - - function mulSub( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a * b - c; - } - - function mulMul( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a * b * c; - } - - function mulDiv( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a * b) / c; - } - - function mulMod( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a * b) % c; - } - - function mulExp( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a * b ** c; - } - - function mulShiftL( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a * b) << c; - } - - function mulShiftR( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a * b) >> c; - } - - function mulBitAnd( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a * b) & c; - } - - function mulBitOr( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a * b) | c; - } - - function mulBitXor( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a * b) ^ c; - } -} - -================================================================================ -`; - -exports[`MulNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` -====================================options===================================== -compiler: "0.8.6" -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -// SPDX-License-Identifier: MIT -pragma solidity 0.8.26; - -contract MulNoParentheses { - function mulAdd(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a * b + c; - } - - function mulSub(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a * b - c; - } - - function mulMul(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a * b * c; - } - - function mulDiv(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a * b / c; - } - - function mulMod(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a * b % c; - } - - function mulExp(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a * b ** c; - } - - function mulShiftL(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a * b << c; - } - - function mulShiftR(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a * b >> c; - } - - function mulBitAnd(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a * b & c; - } - - function mulBitOr(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a * b | c; - } - - function mulBitXor(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a * b ^ c; - } -} - -=====================================output===================================== -pragma solidity 0.8.26; - -contract MulNoParentheses { - function mulAdd( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a * b + c; - } - - function mulSub( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a * b - c; - } - - function mulMul( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a * b * c; - } - - function mulDiv( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a * b) / c; - } - - function mulMod( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a * b) % c; - } - - function mulExp( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a * b ** c; - } - - function mulShiftL( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a * b) << c; - } - - function mulShiftR( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a * b) >> c; - } - - function mulBitAnd( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a * b) & c; - } - - function mulBitOr( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a * b) | c; - } - - function mulBitXor( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a * b) ^ c; - } -} - -================================================================================ -`; - -exports[`ShiftLNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` -====================================options===================================== -compiler: "0.8.6" -parsers: ["solidity-parse"] -printWidth: 80 - | printWidth -=====================================input====================================== -// SPDX-License-Identifier: MIT -pragma solidity 0.8.26; - -contract ShiftLNoParentheses { - function shiftLAdd(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a << b + c; - } - - function shiftLSub(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a << b - c; - } - - function shiftLMul(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a << b * c; - } - - function shiftLDiv(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a << b / c; - } - - function shiftLMod(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a << b % c; - } - - function shiftLExp(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a << b ** c; - } - - function shiftLShiftL(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a << b << c; - } - - function shiftLShiftR(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a << b >> c; - } - - function shiftLBitAnd(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a << b & c; - } - - function shiftLBitOr(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a << b | c; - } - - function shiftLBitXor(uint256 a, uint256 b, uint256 c) - public - pure - returns (uint256) - { - return a << b ^ c; - } -} +} =====================================output===================================== // SPDX-License-Identifier: MIT pragma solidity 0.8.26; -contract ShiftLNoParentheses { - function shiftLAdd( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a << (b + c); - } - - function shiftLSub( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a << (b - c); - } - - function shiftLMul( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a << (b * c); - } - - function shiftLDiv( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a << (b / c); - } - - function shiftLMod( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a << b % c; - } - - function shiftLExp( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return a << (b ** c); - } - - function shiftLShiftL( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a << b) << c; - } - - function shiftLShiftR( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a << b) >> c; +contract LogicNoParentheses { + function orOr(bool a, bool b, bool c) public pure returns (bool) { + return a || b || c; } - function shiftLBitAnd( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a << b) & c; + function orAnd(bool a, bool b, bool c) public pure returns (bool) { + return a || (b && c); } - function shiftLBitOr( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a << b) | c; + function andOr(bool a, bool b, bool c) public pure returns (bool) { + return (a && b) || c; } - function shiftLBitXor( - uint256 a, - uint256 b, - uint256 c - ) public pure returns (uint256) { - return (a << b) ^ c; + function andAnd(bool a, bool b, bool c) public pure returns (bool) { + return a && b && c; } } ================================================================================ `; -exports[`ShiftLNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` +exports[`ModNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["slang"] +parsers: ["solidity-parse"] printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT pragma solidity 0.8.26; -contract ShiftLNoParentheses { - function shiftLAdd(uint256 a, uint256 b, uint256 c) +contract ModNoParentheses { + function modAdd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a << b + c; + return a % b + c; } - function shiftLSub(uint256 a, uint256 b, uint256 c) + function modSub(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a << b - c; + return a % b - c; } - function shiftLMul(uint256 a, uint256 b, uint256 c) + function modMul(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a << b * c; + return a % b * c; } - function shiftLDiv(uint256 a, uint256 b, uint256 c) + function modDiv(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a << b / c; + return a % b / c; } - function shiftLMod(uint256 a, uint256 b, uint256 c) + function modMod(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a << b % c; + return a % b % c; } - function shiftLExp(uint256 a, uint256 b, uint256 c) + function modExp(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a << b ** c; + return a % b ** c; } - function shiftLShiftL(uint256 a, uint256 b, uint256 c) + function modShiftL(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a << b << c; + return a % b << c; } - function shiftLShiftR(uint256 a, uint256 b, uint256 c) + function modShiftR(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a << b >> c; + return a % b >> c; } - function shiftLBitAnd(uint256 a, uint256 b, uint256 c) + function modBitAnd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a << b & c; + return a % b & c; } - function shiftLBitOr(uint256 a, uint256 b, uint256 c) + function modBitOr(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a << b | c; + return a % b | c; } - function shiftLBitXor(uint256 a, uint256 b, uint256 c) + function modBitXor(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a << b ^ c; + return a % b ^ c; } } =====================================output===================================== +// SPDX-License-Identifier: MIT pragma solidity 0.8.26; -contract ShiftLNoParentheses { - function shiftLAdd( +contract ModNoParentheses { + function modAdd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a << (b + c); + return (a % b) + c; } - function shiftLSub( + function modSub( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a << (b - c); + return (a % b) - c; } - function shiftLMul( + function modMul( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a << (b * c); + return (a % b) * c; } - function shiftLDiv( + function modDiv( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a << (b / c); + return (a % b) / c; } - function shiftLMod( + function modMod( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a << b % c; + return (a % b) % c; } - function shiftLExp( + function modExp( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a << (b ** c); + return a % b ** c; } - function shiftLShiftL( + function modShiftL( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a << b) << c; + return a % b << c; } - function shiftLShiftR( + function modShiftR( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a << b) >> c; + return a % b >> c; } - function shiftLBitAnd( + function modBitAnd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a << b) & c; + return a % b & c; } - function shiftLBitOr( + function modBitOr( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a << b) | c; + return a % b | c; } - function shiftLBitXor( + function modBitXor( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a << b) ^ c; + return a % b ^ c; } } ================================================================================ `; -exports[`ShiftRNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` +exports[`MulNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` ====================================options===================================== compiler: "0.8.6" parsers: ["solidity-parse"] @@ -3652,93 +1442,93 @@ printWidth: 80 // SPDX-License-Identifier: MIT pragma solidity 0.8.26; -contract ShiftRNoParentheses { - function shiftRAdd(uint256 a, uint256 b, uint256 c) +contract MulNoParentheses { + function mulAdd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a >> b + c; + return a * b + c; } - function shiftRSub(uint256 a, uint256 b, uint256 c) + function mulSub(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a >> b - c; + return a * b - c; } - function shiftRMul(uint256 a, uint256 b, uint256 c) + function mulMul(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a >> b * c; + return a * b * c; } - function shiftRDiv(uint256 a, uint256 b, uint256 c) + function mulDiv(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a >> b / c; + return a * b / c; } - function shiftRMod(uint256 a, uint256 b, uint256 c) + function mulMod(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a >> b % c; + return a * b % c; } - function shiftRExp(uint256 a, uint256 b, uint256 c) + function mulExp(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a >> b ** c; + return a * b ** c; } - function shiftRShiftL(uint256 a, uint256 b, uint256 c) + function mulShiftL(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a >> b << c; + return a * b << c; } - function shiftRShiftR(uint256 a, uint256 b, uint256 c) + function mulShiftR(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a >> b >> c; + return a * b >> c; } - function shiftRBitAnd(uint256 a, uint256 b, uint256 c) + function mulBitAnd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a >> b & c; + return a * b & c; } - function shiftRBitOr(uint256 a, uint256 b, uint256 c) + function mulBitOr(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a >> b | c; + return a * b | c; } - function shiftRBitXor(uint256 a, uint256 b, uint256 c) + function mulBitXor(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a >> b ^ c; + return a * b ^ c; } } @@ -3746,296 +1536,297 @@ contract ShiftRNoParentheses { // SPDX-License-Identifier: MIT pragma solidity 0.8.26; -contract ShiftRNoParentheses { - function shiftRAdd( +contract MulNoParentheses { + function mulAdd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a >> (b + c); + return a * b + c; } - function shiftRSub( + function mulSub( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a >> (b - c); + return a * b - c; } - function shiftRMul( + function mulMul( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a >> (b * c); + return a * b * c; } - function shiftRDiv( + function mulDiv( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a >> (b / c); + return (a * b) / c; } - function shiftRMod( + function mulMod( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a >> b % c; + return (a * b) % c; } - function shiftRExp( + function mulExp( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a >> (b ** c); + return a * b ** c; } - function shiftRShiftL( + function mulShiftL( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a >> b) << c; + return (a * b) << c; } - function shiftRShiftR( + function mulShiftR( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a >> b) >> c; + return (a * b) >> c; } - function shiftRBitAnd( + function mulBitAnd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a >> b) & c; + return (a * b) & c; } - function shiftRBitOr( + function mulBitOr( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a >> b) | c; + return (a * b) | c; } - function shiftRBitXor( + function mulBitXor( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a >> b) ^ c; + return (a * b) ^ c; } } ================================================================================ `; -exports[`ShiftRNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` +exports[`ShiftLNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["slang"] +parsers: ["solidity-parse"] printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT pragma solidity 0.8.26; -contract ShiftRNoParentheses { - function shiftRAdd(uint256 a, uint256 b, uint256 c) +contract ShiftLNoParentheses { + function shiftLAdd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a >> b + c; + return a << b + c; } - function shiftRSub(uint256 a, uint256 b, uint256 c) + function shiftLSub(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a >> b - c; + return a << b - c; } - function shiftRMul(uint256 a, uint256 b, uint256 c) + function shiftLMul(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a >> b * c; + return a << b * c; } - function shiftRDiv(uint256 a, uint256 b, uint256 c) + function shiftLDiv(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a >> b / c; + return a << b / c; } - function shiftRMod(uint256 a, uint256 b, uint256 c) + function shiftLMod(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a >> b % c; + return a << b % c; } - function shiftRExp(uint256 a, uint256 b, uint256 c) + function shiftLExp(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a >> b ** c; + return a << b ** c; } - function shiftRShiftL(uint256 a, uint256 b, uint256 c) + function shiftLShiftL(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a >> b << c; + return a << b << c; } - function shiftRShiftR(uint256 a, uint256 b, uint256 c) + function shiftLShiftR(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a >> b >> c; + return a << b >> c; } - function shiftRBitAnd(uint256 a, uint256 b, uint256 c) + function shiftLBitAnd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a >> b & c; + return a << b & c; } - function shiftRBitOr(uint256 a, uint256 b, uint256 c) + function shiftLBitOr(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a >> b | c; + return a << b | c; } - function shiftRBitXor(uint256 a, uint256 b, uint256 c) + function shiftLBitXor(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a >> b ^ c; + return a << b ^ c; } } =====================================output===================================== +// SPDX-License-Identifier: MIT pragma solidity 0.8.26; -contract ShiftRNoParentheses { - function shiftRAdd( +contract ShiftLNoParentheses { + function shiftLAdd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a >> (b + c); + return a << (b + c); } - function shiftRSub( + function shiftLSub( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a >> (b - c); + return a << (b - c); } - function shiftRMul( + function shiftLMul( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a >> (b * c); + return a << (b * c); } - function shiftRDiv( + function shiftLDiv( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a >> (b / c); + return a << (b / c); } - function shiftRMod( + function shiftLMod( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a >> b % c; + return a << b % c; } - function shiftRExp( + function shiftLExp( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a >> (b ** c); + return a << (b ** c); } - function shiftRShiftL( + function shiftLShiftL( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a >> b) << c; + return (a << b) << c; } - function shiftRShiftR( + function shiftLShiftR( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a >> b) >> c; + return (a << b) >> c; } - function shiftRBitAnd( + function shiftLBitAnd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a >> b) & c; + return (a << b) & c; } - function shiftRBitOr( + function shiftLBitOr( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a >> b) | c; + return (a << b) | c; } - function shiftRBitXor( + function shiftLBitXor( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a >> b) ^ c; + return (a << b) ^ c; } } ================================================================================ `; -exports[`SubNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` +exports[`ShiftRNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` ====================================options===================================== compiler: "0.8.6" parsers: ["solidity-parse"] @@ -4045,93 +1836,93 @@ printWidth: 80 // SPDX-License-Identifier: MIT pragma solidity 0.8.26; -contract SubNoParentheses { - function subAdd(uint256 a, uint256 b, uint256 c) +contract ShiftRNoParentheses { + function shiftRAdd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a - b + c; + return a >> b + c; } - function subSub(uint256 a, uint256 b, uint256 c) + function shiftRSub(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a - b - c; + return a >> b - c; } - function subMul(uint256 a, uint256 b, uint256 c) + function shiftRMul(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a - b * c; + return a >> b * c; } - function subDiv(uint256 a, uint256 b, uint256 c) + function shiftRDiv(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a - b / c; + return a >> b / c; } - function subMod(uint256 a, uint256 b, uint256 c) + function shiftRMod(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a - b % c; + return a >> b % c; } - function subExp(uint256 a, uint256 b, uint256 c) + function shiftRExp(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a - b ** c; + return a >> b ** c; } - function subShiftL(uint256 a, uint256 b, uint256 c) + function shiftRShiftL(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a - b << c; + return a >> b << c; } - function subShiftR(uint256 a, uint256 b, uint256 c) + function shiftRShiftR(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a - b >> c; + return a >> b >> c; } - function subBitAnd(uint256 a, uint256 b, uint256 c) + function shiftRBitAnd(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a - b & c; + return a >> b & c; } - function subBitOr(uint256 a, uint256 b, uint256 c) + function shiftRBitOr(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a - b | c; + return a >> b | c; } - function subBitXor(uint256 a, uint256 b, uint256 c) + function shiftRBitXor(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - return a - b ^ c; + return a >> b ^ c; } } @@ -4139,103 +1930,103 @@ contract SubNoParentheses { // SPDX-License-Identifier: MIT pragma solidity 0.8.26; -contract SubNoParentheses { - function subAdd( +contract ShiftRNoParentheses { + function shiftRAdd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a - b + c; + return a >> (b + c); } - function subSub( + function shiftRSub( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a - b - c; + return a >> (b - c); } - function subMul( + function shiftRMul( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a - b * c; + return a >> (b * c); } - function subDiv( + function shiftRDiv( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a - b / c; + return a >> (b / c); } - function subMod( + function shiftRMod( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a - (b % c); + return a >> b % c; } - function subExp( + function shiftRExp( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return a - b ** c; + return a >> (b ** c); } - function subShiftL( + function shiftRShiftL( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a - b) << c; + return (a >> b) << c; } - function subShiftR( + function shiftRShiftR( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a - b) >> c; + return (a >> b) >> c; } - function subBitAnd( + function shiftRBitAnd( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a - b) & c; + return (a >> b) & c; } - function subBitOr( + function shiftRBitOr( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a - b) | c; + return (a >> b) | c; } - function subBitXor( + function shiftRBitXor( uint256 a, uint256 b, uint256 c ) public pure returns (uint256) { - return (a - b) ^ c; + return (a >> b) ^ c; } } ================================================================================ `; -exports[`SubNoParentheses.sol - {"compiler":"0.8.6"} format 2`] = ` +exports[`SubNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["slang"] +parsers: ["solidity-parse"] printWidth: 80 | printWidth =====================================input====================================== @@ -4333,6 +2124,7 @@ contract SubNoParentheses { } =====================================output===================================== +// SPDX-License-Identifier: MIT pragma solidity 0.8.26; contract SubNoParentheses { diff --git a/tests/format/Parentheses/jsfmt.spec.js b/tests/format/Parentheses/jsfmt.spec.js index 15c5d58fc..8c772cba0 100644 --- a/tests/format/Parentheses/jsfmt.spec.js +++ b/tests/format/Parentheses/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse'], { compiler: '0.8.6' }); -run_spec(import.meta, ['slang'], { compiler: '0.8.6' }); diff --git a/tests/format/Pragma/__snapshots__/jsfmt.spec.js.snap b/tests/format/Pragma/__snapshots__/jsfmt.spec.js.snap index b3d7e1edc..5971506a0 100644 --- a/tests/format/Pragma/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Pragma/__snapshots__/jsfmt.spec.js.snap @@ -31,35 +31,3 @@ pragma abicoder v2; ================================================================================ `; - -exports[`Pragma.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity >=0.4.21 <0.6.0; -pragma solidity >=0.4.21 <=0.6.0 ; -pragma solidity >0.4.21 <0.6.0; -pragma solidity >0.4.21 <=0.6.0; -pragma solidity >=0.4.21<0.6.0; -pragma solidity ^ 0.4.21 ; -pragma solidity ~ 0.4.21 ; -pragma solidity ^0.5.0 || ^0.6.0 || ^0.7.0 ; -pragma experimental ABIEncoderV2; -pragma abicoder v2; - -=====================================output===================================== -pragma solidity >=0.4.21 <0.6.0; -pragma solidity >=0.4.21 <=0.6.0; -pragma solidity >0.4.21 <0.6.0; -pragma solidity >0.4.21 <=0.6.0; -pragma solidity >=0.4.21 <0.6.0; -pragma solidity ^0.4.21; -pragma solidity ~0.4.21; -pragma solidity ^0.5.0||^0.6.0||^0.7.0; -pragma experimental ABIEncoderV2; -pragma abicoder v2; - -================================================================================ -`; diff --git a/tests/format/Pragma/jsfmt.spec.js b/tests/format/Pragma/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/Pragma/jsfmt.spec.js +++ b/tests/format/Pragma/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); diff --git a/tests/format/PrettierIgnore/__snapshots__/jsfmt.spec.js.snap b/tests/format/PrettierIgnore/__snapshots__/jsfmt.spec.js.snap index 0cd0ee1ee..e945dda29 100644 --- a/tests/format/PrettierIgnore/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/PrettierIgnore/__snapshots__/jsfmt.spec.js.snap @@ -85,71 +85,3 @@ contract Example { ================================================================================ `; - -exports[`PrettierIgnore.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity ^0.5.2; - -contract PrettierIgnore { - fallback() external payable { - matrix( - 1, 0, 0, - 0, 1, 0, - 0, 0, 1 - ); - - // prettier-ignore - matrix( - 1, 0, 0, - 0, 1, 0, - 0, 0, 1 - ); - } -} - -// prettier-ignore -contract Example { -// Test comment - fallback() external payable { - // This should be marked as printed - // Everything inside is also ignored - matrix( - 1, 0, 0, - 0, 1, 0, - 0, 0, 1 - ); - // Comments for members of an Array are marked as printed - if (true) - // Comments of single child Objects are marked as printed - return; - else - // Comments of children should be marked as printed - return; - } -} - -=====================================output===================================== -pragma solidity ^0.5.2; - -contract PrettierIgnore { - fallback() external payable { - matrix(1, 0, 0, 0, 1, 0, 0, 0, 1); - - matrix(1, 0, 0, 0, 1, 0, 0, 0, 1); - } -} - -contract Example { - fallback() external payable { - matrix(1, 0, 0, 0, 1, 0, 0, 0, 1); - if (true) return; - else return; - } -} - -================================================================================ -`; diff --git a/tests/format/PrettierIgnore/jsfmt.spec.js b/tests/format/PrettierIgnore/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/PrettierIgnore/jsfmt.spec.js +++ b/tests/format/PrettierIgnore/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); diff --git a/tests/format/Proxy/__snapshots__/jsfmt.spec.js.snap b/tests/format/Proxy/__snapshots__/jsfmt.spec.js.snap index bcee98b4a..41521a072 100644 --- a/tests/format/Proxy/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Proxy/__snapshots__/jsfmt.spec.js.snap @@ -1,101 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Proxy.sol - {"compiler":"0.4.26"} format 1`] = ` -====================================options===================================== -compiler: "0.4.26" -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity ^0.4.24; - -/** - * @title Proxy - * @dev Gives the possibility to delegate any call to a foreign implementation. - */ -contract Proxy { - - /** - * @dev Tells the address of the implementation where every call will be delegated. - * @return address of the implementation to which it will be delegated - */ - function _implementation() internal view returns (address); - - /** - * @dev Fallback function. - * Implemented entirely in \`_fallback\`. - */ - function _fallback() internal { - _delegate(_implementation()); - } - - /** - * @dev Fallback function allowing to perform a delegatecall to the given implementation. - * This function will return whatever the implementation call returns - */ - function _delegate(address implementation) internal { - /*solium-disable-next-line security/no-inline-assembly*/ - assembly { - // Copy msg.data. We take full control of memory in this inline assembly - // block because it will not return to Solidity code. We overwrite the - // Solidity scratch pad at memory position 0. - calldatacopy(0, 0, calldatasize) - - // Call the implementation. - // out and outsize are 0 because we don't know the size yet. - let result := delegatecall(gas, implementation, 0, calldatasize, 0, 0) - - // Copy the returned data. - returndatacopy(0, 0, returndatasize) - - switch result - // delegatecall returns 0 on error. - case 0 { revert(0, returndatasize) } - default { return(0, returndatasize) } - } - } - - function () public payable { - _fallback(); - } -} - -=====================================output===================================== -pragma solidity ^0.4.24; - -contract Proxy { - function _implementation() internal view returns (address); - - function _fallback() internal { - _delegate(_implementation()); - } - - function _delegate(address implementation) internal { - assembly { - calldatacopy(0,0,calldatasize) - - let result := delegatecall(gas,implementation,0,calldatasize,0,0) - - returndatacopy(0,0,returndatasize) - - switch result - case 0 { - revert(0,returndatasize) - } - default { - return(0,returndatasize) - } - } - } - - function() public payable { - _fallback(); - } -} - -================================================================================ -`; - exports[`Proxy.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] diff --git a/tests/format/Proxy/jsfmt.spec.js b/tests/format/Proxy/jsfmt.spec.js index c8fb0ebbc..765dd60a6 100644 --- a/tests/format/Proxy/jsfmt.spec.js +++ b/tests/format/Proxy/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang'], { compiler: '0.4.26' }); diff --git a/tests/format/SampleCrowdsale/__snapshots__/jsfmt.spec.js.snap b/tests/format/SampleCrowdsale/__snapshots__/jsfmt.spec.js.snap index fda521b17..733a7d384 100644 --- a/tests/format/SampleCrowdsale/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/SampleCrowdsale/__snapshots__/jsfmt.spec.js.snap @@ -111,97 +111,3 @@ contract SampleCrowdsale is CappedCrowdsale, RefundableCrowdsale { ================================================================================ `; - -exports[`SampleCrowdsale.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity ^0.4.18; - -import "../crowdsale/CappedCrowdsale.sol"; -import "../crowdsale/RefundableCrowdsale.sol"; -import "../token/MintableToken.sol"; - -/** - * @title SampleCrowdsaleToken - * @dev Very simple ERC20 Token that can be minted. - * It is meant to be used in a crowdsale contract. - */ -contract SampleCrowdsaleToken is MintableToken { - - string public constant name = "Sample Crowdsale Token"; - string public constant symbol = "SCT"; - uint8 public constant decimals = 18; - -} - -/** - * @title SampleCrowdsale - * @dev This is an example of a fully fledged crowdsale. - * The way to add new features to a base crowdsale is by multiple inheritance. - * In this example we are providing following extensions: - * CappedCrowdsale - sets a max boundary for raised funds - * RefundableCrowdsale - set a min goal to be reached and returns funds if it's not met - * - * After adding multiple features it's good practice to run integration tests - * to ensure that subcontracts works together as intended. - */ -contract SampleCrowdsale is CappedCrowdsale, RefundableCrowdsale { - - function SampleCrowdsale(uint256 _startTime, uint256 _endTime, uint256 _rate, uint256 _goal, uint256 _cap, address _wallet) public - CappedCrowdsale(_cap) - FinalizableCrowdsale() - RefundableCrowdsale(_goal) - Crowdsale(_startTime, _endTime, _rate, _wallet) - { - //As goal needs to be met for a successful crowdsale - //the value needs to less or equal than a cap which is limit for accepted funds - require(_goal <= _cap); - } - - function createTokenContract() internal returns (MintableToken) { - return new SampleCrowdsaleToken(); - } - -} - -=====================================output===================================== -pragma solidity ^0.4.18; - -import "../crowdsale/CappedCrowdsale.sol"; -import "../crowdsale/RefundableCrowdsale.sol"; -import "../token/MintableToken.sol"; - -contract SampleCrowdsaleToken is MintableToken { - string public constant name = "Sample Crowdsale Token"; - string public constant symbol = "SCT"; - uint8 public constant decimals = 18; -} - -contract SampleCrowdsale is CappedCrowdsale, RefundableCrowdsale { - function SampleCrowdsale( - uint256 _startTime, - uint256 _endTime, - uint256 _rate, - uint256 _goal, - uint256 _cap, - address _wallet - ) - public - CappedCrowdsale(_cap) - FinalizableCrowdsale() - RefundableCrowdsale(_goal) - Crowdsale(_startTime, _endTime, _rate, _wallet) - { - require(_goal <= _cap); - } - - function createTokenContract() internal returns (MintableToken) { - return new SampleCrowdsaleToken(); - } -} - -================================================================================ -`; diff --git a/tests/format/SampleCrowdsale/jsfmt.spec.js b/tests/format/SampleCrowdsale/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/SampleCrowdsale/jsfmt.spec.js +++ b/tests/format/SampleCrowdsale/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); diff --git a/tests/format/SimpleAuction/__snapshots__/jsfmt.spec.js.snap b/tests/format/SimpleAuction/__snapshots__/jsfmt.spec.js.snap index 7a149c1cb..d980d9c1a 100644 --- a/tests/format/SimpleAuction/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/SimpleAuction/__snapshots__/jsfmt.spec.js.snap @@ -248,195 +248,3 @@ contract SimpleAuction { ================================================================================ `; - -exports[`SimpleAuction.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity ^0.4.22; - -contract SimpleAuction { - // Parameters of the auction. Times are either - // absolute unix timestamps (seconds since 1970-01-01) - // or time periods in seconds. - address public beneficiary; - uint public auctionEnd; - - // Current state of the auction. - address public highestBidder; - uint public highestBid; - - // Allowed withdrawals of previous bids - mapping(address => uint) pendingReturns; - - // Set to true at the end, disallows any change - bool ended; - - // Events that will be fired on changes. - event HighestBidIncreased(address bidder, uint amount); - event AuctionEnded(address winner, uint amount); - - // The following is a so-called natspec comment, - // recognizable by the three slashes. - // It will be shown when the user is asked to - // confirm a transaction. - - /// Create a simple auction with \`_biddingTime\` - /// seconds bidding time on behalf of the - /// beneficiary address \`_beneficiary\`. - constructor( - uint _biddingTime, - address _beneficiary - ) public { - beneficiary = _beneficiary; - auctionEnd = now + _biddingTime; - } - - /// Bid on the auction with the value sent - /// together with this transaction. - /// The value will only be refunded if the - /// auction is not won. - function bid() public payable { - // No arguments are necessary, all - // information is already part of - // the transaction. The keyword payable - // is required for the function to - // be able to receive Ether. - - // Revert the call if the bidding - // period is over. - require( - now <= auctionEnd, - "Auction already ended." - ); - - // If the bid is not higher, send the - // money back. - require( - msg.value > highestBid, - "There already is a higher bid." - ); - - if (highestBid != 0) { - // Sending back the money by simply using - // highestBidder.send(highestBid) is a security risk - // because it could execute an untrusted contract. - // It is always safer to let the recipients - // withdraw their money themselves. - pendingReturns[highestBidder] += highestBid; - } - highestBidder = msg.sender; - highestBid = msg.value; - emit HighestBidIncreased(msg.sender, msg.value); - } - - /// Withdraw a bid that was overbid. - function withdraw() public returns (bool) { - uint amount = pendingReturns[msg.sender]; - if (amount > 0) { - // It is important to set this to zero because the recipient - // can call this function again as part of the receiving call - // before \`send\` returns. - pendingReturns[msg.sender] = 0; - - if (!msg.sender.send(amount)) { - // No need to call throw here, just reset the amount owing - pendingReturns[msg.sender] = amount; - return false; - } - } - return true; - } - - /// End the auction and send the highest bid - /// to the beneficiary. - function auctionEnd() public { - // It is a good guideline to structure functions that interact - // with other contracts (i.e. they call functions or send Ether) - // into three phases: - // 1. checking conditions - // 2. performing actions (potentially changing conditions) - // 3. interacting with other contracts - // If these phases are mixed up, the other contract could call - // back into the current contract and modify the state or cause - // effects (ether payout) to be performed multiple times. - // If functions called internally include interaction with external - // contracts, they also have to be considered interaction with - // external contracts. - - // 1. Conditions - require(now >= auctionEnd, "Auction not yet ended."); - require(!ended, "auctionEnd has already been called."); - - // 2. Effects - ended = true; - emit AuctionEnded(highestBidder, highestBid); - - // 3. Interaction - beneficiary.transfer(highestBid); - } -} - -=====================================output===================================== -pragma solidity ^0.4.22; - -contract SimpleAuction { - address public beneficiary; - uint public auctionEnd; - - address public highestBidder; - uint public highestBid; - - mapping(address => uint) pendingReturns; - - bool ended; - - event HighestBidIncreased(address bidder, uint amount); - event AuctionEnded(address winner, uint amount); - - constructor(uint _biddingTime, address _beneficiary) public { - beneficiary = _beneficiary; - auctionEnd = now + _biddingTime; - } - - function bid() public payable { - require(now <= auctionEnd, "Auction already ended."); - - require(msg.value > highestBid, "There already is a higher bid."); - - if (highestBid != 0) { - pendingReturns[highestBidder] += highestBid; - } - highestBidder = msg.sender; - highestBid = msg.value; - emit HighestBidIncreased(msg.sender, msg.value); - } - - function withdraw() public returns (bool) { - uint amount = pendingReturns[msg.sender]; - if (amount > 0) { - pendingReturns[msg.sender] = 0; - - if (!msg.sender.send(amount)) { - pendingReturns[msg.sender] = amount; - return false; - } - } - return true; - } - - function auctionEnd() public { - require(now >= auctionEnd, "Auction not yet ended."); - require(!ended, "auctionEnd has already been called."); - - ended = true; - emit AuctionEnded(highestBidder, highestBid); - - beneficiary.transfer(highestBid); - } -} - -================================================================================ -`; diff --git a/tests/format/SimpleAuction/jsfmt.spec.js b/tests/format/SimpleAuction/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/SimpleAuction/jsfmt.spec.js +++ b/tests/format/SimpleAuction/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); diff --git a/tests/format/SimpleStorage/__snapshots__/jsfmt.spec.js.snap b/tests/format/SimpleStorage/__snapshots__/jsfmt.spec.js.snap index b87023117..ab685ce2d 100644 --- a/tests/format/SimpleStorage/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/SimpleStorage/__snapshots__/jsfmt.spec.js.snap @@ -39,43 +39,3 @@ contract SimpleStorage { ================================================================================ `; - -exports[`SimpleStorage.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity ^0.4.0; - -contract SimpleStorage { - string public name = "SimpleStorage"; - uint storedData; - - function set(uint x) public { - storedData = x; - } - - function get() public view returns (uint) { - return storedData; - } -} - -=====================================output===================================== -pragma solidity ^0.4.0; - -contract SimpleStorage { - string public name = "SimpleStorage"; - uint storedData; - - function set(uint x) public { - storedData = x; - } - - function get() public view returns (uint) { - return storedData; - } -} - -================================================================================ -`; diff --git a/tests/format/SimpleStorage/jsfmt.spec.js b/tests/format/SimpleStorage/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/SimpleStorage/jsfmt.spec.js +++ b/tests/format/SimpleStorage/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); diff --git a/tests/format/SplittableCommodity/__snapshots__/jsfmt.spec.js.snap b/tests/format/SplittableCommodity/__snapshots__/jsfmt.spec.js.snap index 58ddaa12a..988eba232 100644 --- a/tests/format/SplittableCommodity/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/SplittableCommodity/__snapshots__/jsfmt.spec.js.snap @@ -133,137 +133,3 @@ contract SplittableCommodity is MintableCommodity { ================================================================================ `; - -exports[`SplittableCommodity.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity ^0.4.24; - -import "./MintableCommodity.sol"; -import "../participant/ISupplier.sol"; -import "../../node_modules/zeppelin-solidity/contracts//math/SafeMath.sol"; - -contract SplittableCommodity is MintableCommodity { - using SafeMath for uint256; - - event Split(address indexed to, uint256 amount, uint64 parentId, address indexed operator, bytes operatorData); - - function split(uint _tokenId, address _to, uint256 _amount) public whenNotPaused { - address supplierProxy = IContractRegistry(contractRegistry).getLatestProxyAddr("Supplier"); - require( - msg.sender == IContractRegistry(contractRegistry).getLatestProxyAddr("FifoCrcMarket") || - ISupplier(supplierProxy).isAllowed(this, "IMintableCommodity"), - "Splitting can only be done when both the ISplittableCommodity interface is enabled and is called by a supplier or the FifoCrcMarket is used." - ); - - commodities[_tokenId].value = commodities[_tokenId].value.sub(_amount); - - CommodityLib.Commodity memory _commodity = CommodityLib.Commodity({ - category: uint64(1), - timeRegistered: uint64(now), // solium-disable-line - parentId: _tokenId, - value: _amount, - locked: false, - misc: commodities[_tokenId].misc - }); - uint newCRCId = commodities.push(_commodity).sub(1); - require(newCRCId <= 18446744073709551616, "You can only split a commodity if it is within a valid index range"); - - if(msg.sender == IContractRegistry(contractRegistry).getLatestProxyAddr("FifoCrcMarket")) { - _transfer(ownerOf(_tokenId), _to, newCRCId); - } else { - _transfer(msg.sender, _to, newCRCId); - } - - callRecipient( - msg.sender, - 0x0, - _to, - newCRCId, - "", - "", - false - ); - - emit Split( - _to, - _amount, - uint64(newCRCId), - msg.sender, - "" - ); - } -} - -=====================================output===================================== -pragma solidity ^0.4.24; - -import "./MintableCommodity.sol"; -import "../participant/ISupplier.sol"; -import "../../node_modules/zeppelin-solidity/contracts//math/SafeMath.sol"; - -contract SplittableCommodity is MintableCommodity { - using SafeMath for uint256; - - event Split( - address indexed to, - uint256 amount, - uint64 parentId, - address indexed operator, - bytes operatorData - ); - - function split( - uint _tokenId, - address _to, - uint256 _amount - ) public whenNotPaused { - address supplierProxy = IContractRegistry(contractRegistry) - .getLatestProxyAddr("Supplier"); - require( - msg.sender == - IContractRegistry(contractRegistry).getLatestProxyAddr( - "FifoCrcMarket" - ) || - ISupplier(supplierProxy).isAllowed(this, "IMintableCommodity"), - "Splitting can only be done when both the ISplittableCommodity interface is enabled and is called by a supplier or the FifoCrcMarket is used." - ); - - commodities[_tokenId].value = commodities[_tokenId].value.sub(_amount); - - CommodityLib.Commodity memory _commodity = CommodityLib.Commodity({ - category: uint64(1), - timeRegistered: uint64(now), - parentId: _tokenId, - value: _amount, - locked: false, - misc: commodities[_tokenId].misc - }); - uint newCRCId = commodities.push(_commodity).sub(1); - require( - newCRCId <= 18446744073709551616, - "You can only split a commodity if it is within a valid index range" - ); - - if ( - msg.sender == - IContractRegistry(contractRegistry).getLatestProxyAddr( - "FifoCrcMarket" - ) - ) { - _transfer(ownerOf(_tokenId), _to, newCRCId); - } else { - _transfer(msg.sender, _to, newCRCId); - } - - callRecipient(msg.sender, 0x0, _to, newCRCId, "", "", false); - - emit Split(_to, _amount, uint64(newCRCId), msg.sender, ""); - } -} - -================================================================================ -`; diff --git a/tests/format/SplittableCommodity/jsfmt.spec.js b/tests/format/SplittableCommodity/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/SplittableCommodity/jsfmt.spec.js +++ b/tests/format/SplittableCommodity/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); diff --git a/tests/format/StateVariableDeclarations/__snapshots__/jsfmt.spec.js.snap b/tests/format/StateVariableDeclarations/__snapshots__/jsfmt.spec.js.snap index 9f4c08040..9f48a411d 100644 --- a/tests/format/StateVariableDeclarations/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/StateVariableDeclarations/__snapshots__/jsfmt.spec.js.snap @@ -18,22 +18,3 @@ contract Contract { ================================================================================ `; - -exports[`StateVariableDeclarations.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -contract Contract { - bytes32 private constant DOMAIN_SEPARATOR_TYPEHASH = 0x035aff83d86937d35b32e04f0ddc6ff469290eef2f1b692d8a815c89404d4749; -} - -=====================================output===================================== -contract Contract { - bytes32 private constant DOMAIN_SEPARATOR_TYPEHASH = - 0x035aff83d86937d35b32e04f0ddc6ff469290eef2f1b692d8a815c89404d4749; -} - -================================================================================ -`; diff --git a/tests/format/StateVariableDeclarations/jsfmt.spec.js b/tests/format/StateVariableDeclarations/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/StateVariableDeclarations/jsfmt.spec.js +++ b/tests/format/StateVariableDeclarations/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); diff --git a/tests/format/StringLiteral/__snapshots__/jsfmt.spec.js.snap b/tests/format/StringLiteral/__snapshots__/jsfmt.spec.js.snap index e813af4a3..704ec50db 100644 --- a/tests/format/StringLiteral/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/StringLiteral/__snapshots__/jsfmt.spec.js.snap @@ -34,38 +34,3 @@ contract StringLiteral { ================================================================================ `; - -exports[`StringLiteral.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -contract StringLiteral { - bytes32 public constant PERMIT_TYPEHASH = keccak256( - "Permit(" - "address owner," - "address spender," - "uint256 value," - "uint256 nonce," - "uint256 deadline" - ")" - ); -} - -=====================================output===================================== -contract StringLiteral { - bytes32 public constant PERMIT_TYPEHASH = - keccak256( - "Permit(" - "address owner," - "address spender," - "uint256 value," - "uint256 nonce," - "uint256 deadline" - ")" - ); -} - -================================================================================ -`; diff --git a/tests/format/StringLiteral/jsfmt.spec.js b/tests/format/StringLiteral/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/StringLiteral/jsfmt.spec.js +++ b/tests/format/StringLiteral/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); diff --git a/tests/format/StyleGuide/__snapshots__/jsfmt.spec.js.snap b/tests/format/StyleGuide/__snapshots__/jsfmt.spec.js.snap index c3c94d073..b84c1da48 100644 --- a/tests/format/StyleGuide/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/StyleGuide/__snapshots__/jsfmt.spec.js.snap @@ -1,48 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`BlankLines.sol - {"compiler":"0.5.0"} format 1`] = ` -====================================options===================================== -compiler: "0.5.0" -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity >=0.4.0 <0.7.0; - - -contract A { -} -contract B { -} - -contract C { -} - -contract A { - function spam() public pure { - // ... - } - function ham() public pure { - // ... - } -} - -=====================================output===================================== -pragma solidity >=0.4.0 <0.7.0; - -contract A {} -contract B {} - -contract C {} - -contract A { - function spam() public pure {} - function ham() public pure {} -} - -================================================================================ -`; - exports[`BlankLines.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] @@ -89,106 +46,6 @@ contract A { ================================================================================ `; -exports[`ControlStructures.sol - {"compiler":"0.5.0"} format 1`] = ` -====================================options===================================== -compiler: "0.5.0" -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity >=0.4.0 <0.7.0; - - -contract ControlStructures -{ - struct Bank - { - address owner; - uint balance; - } - - function () { - if (true) - { - doSomething(); - } - - while(true){ - break; - } - - for (uint a; a < 10; a++) { - doSomethingElse();} - - /* TODO: singleline trueBody should be printed and indented in a new - line - if (x < 10) - x += 1; - */ - - /* TODO: force braquets if statement is too complex - if (x < 10) - someArray.push(Coin({ - name: 'spam', - value: 42 - })); - */ - - if (x < 3) { - x += 1; - } else - if (x > 7) { - x -= 1; - } - else { - x = 5; - } - - /* TODO: singleline trueBody and falseBody should be printed and - indented in a new line - if (x < 3) - x += 1; - else - x -= 1; - */ - } -} - -=====================================output===================================== -pragma solidity >=0.4.0 <0.7.0; - -contract ControlStructures { - struct Bank { - address owner; - uint balance; - } - - function() { - if (true) { - doSomething(); - } - - while(true){ - break; - } - - for (uint a; a < 10; a++) { - doSomethingElse(); - } - - if (x < 3) { - x += 1; - } else if (x > 7) { - x -= 1; - } else { - x = 5; - } - } -} - -================================================================================ -`; - exports[`ControlStructures.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] @@ -310,10 +167,9 @@ contract ControlStructures { ================================================================================ `; -exports[`FunctionDeclaration.sol - {"compiler":"0.5.0"} format 1`] = ` +exports[`FunctionDeclaration.sol format 1`] = ` ====================================options===================================== -compiler: "0.5.0" -parsers: ["slang"] +parsers: ["solidity-parse"] printWidth: 80 | printWidth =====================================input====================================== @@ -473,10 +329,11 @@ contract FunctionDeclaration { return x + 1; } - function kill() onlyowner public { + function kill() public onlyowner { selfdestruct(owner); } + /* TODO: modifiers should always split if arguments split */ function thisFunctionHasLotsOfArguments( address a, address b, @@ -556,6 +413,7 @@ contract FunctionDeclaration { } } +// Base contracts just to make this compile contract B { constructor(uint) public {} } @@ -568,6 +426,7 @@ contract D { constructor(uint) public {} } +/* TODO: constructors calls have priority over visibility */ contract A is B, C, D { uint x; @@ -577,7 +436,7 @@ contract A is B, C, D { uint param3, uint param4, uint param5 - ) B(param1) C(param2, param3) D(param4) public { + ) public B(param1) C(param2, param3) D(param4) { x = param5; } } @@ -599,7 +458,7 @@ contract X is B, C, D { ================================================================================ `; -exports[`FunctionDeclaration.sol format 1`] = ` +exports[`Mappings.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] printWidth: 80 @@ -608,551 +467,74 @@ printWidth: 80 pragma solidity >=0.4.0 <0.7.0; -contract FunctionDeclaration { - function increment(uint x) public pure returns (uint) - { - return x + 1; - } +contract Mappings { + mapping (uint => uint) map; + mapping( address => bool ) registeredAddresses; + mapping (uint => mapping (bool => Data[])) public data; + mapping(uint => mapping (uint => s)) data; +} - function increment(uint x) public pure returns (uint){ - return x + 1; - } +=====================================output===================================== +pragma solidity >=0.4.0 <0.7.0; - function increment(uint x) public pure returns (uint) { - return x + 1; - } +contract Mappings { + mapping(uint => uint) map; + mapping(address => bool) registeredAddresses; + mapping(uint => mapping(bool => Data[])) public data; + mapping(uint => mapping(uint => s)) data; +} - function increment(uint x) public pure returns (uint) { - return x + 1;} +================================================================================ +`; - function kill() onlyowner public { - selfdestruct(owner); - } +exports[`MaximumLineLength.sol format 1`] = ` +====================================options===================================== +parsers: ["solidity-parse"] +printWidth: 80 + | printWidth +=====================================input====================================== +pragma solidity >=0.4.0 <0.7.0; - /* TODO: modifiers should always split if arguments split */ - function thisFunctionHasLotsOfArguments(address a, address b, address c, - address d, address e, address f) public { - doSomething(); - } - function thisFunctionHasLotsOfArguments(address a, - address b, - address c, - address d, - address e, - address f) public { - doSomething(); - } +contract FunctionCalls { + function() { + thisFunctionCallIsReallyLong(longArgument1, + longArgument2, + longArgument3 + ); - function thisFunctionHasLotsOfArguments( - address a, - address b, - address c, - address d, - address e, - address f) public { - doSomething(); - } + thisFunctionCallIsReallyLong(longArgument1, + longArgument2, + longArgument3 + ); - function thisFunctionNameIsReallyLong(address x, address y, address z) - public - onlyowner - priced - returns (address) { - doSomething(); - } + thisFunctionCallIsReallyLong( + longArgument1, longArgument2, + longArgument3 + ); - function thisFunctionNameIsReallyLong(address x, address y, address z) - public onlyowner priced returns (address) - { - doSomething(); + thisFunctionCallIsReallyLong( + longArgument1, + longArgument2, + longArgument3 + ); + + thisFunctionCallIsReallyLong( + longArgument1, + longArgument2, + longArgument3); } +} - function thisFunctionNameIsReallyLong(address x, address y, address z) - public - onlyowner - priced - returns (address) { - doSomething(); + +contract AssignmentStatements { + function() { + thisIsALongNestedMapping[being][set][to_some_value] = someFunction(argument1, + argument2, + argument3, + argument4); } - - function thisFunctionNameIsReallyLong( - address a, - address b, - address c - ) - public - returns (address someAddressName, - uint256 LongArgument, - uint256 Argument) - { - doSomething(); - - return (veryVeryLongReturnArg1, - veryVeryLongReturnArg1, - veryVeryLongReturnArg1); - } -} - - -// Base contracts just to make this compile -contract B { - constructor(uint) public { - } -} - - -contract C { - constructor(uint, uint) public { - } -} - - -contract D { - constructor(uint) public { - } -} - - -/* TODO: constructors calls have priority over visibility */ -contract A is B, C, D { - uint x; - - constructor(uint param1, uint param2, uint param3, uint param4, uint param5) - B(param1) - C(param2, param3) - D(param4) - public - { - x = param5; - } -} - - -contract X is B, C, D { - uint x; - - constructor(uint param1, uint param2, uint param3, uint param4, uint param5) - public - B(param1) - C(param2, param3) - D(param4) { - x = param5; - } -} - -=====================================output===================================== -pragma solidity >=0.4.0 <0.7.0; - -contract FunctionDeclaration { - function increment(uint x) public pure returns (uint) { - return x + 1; - } - - function increment(uint x) public pure returns (uint) { - return x + 1; - } - - function increment(uint x) public pure returns (uint) { - return x + 1; - } - - function increment(uint x) public pure returns (uint) { - return x + 1; - } - - function kill() public onlyowner { - selfdestruct(owner); - } - - /* TODO: modifiers should always split if arguments split */ - function thisFunctionHasLotsOfArguments( - address a, - address b, - address c, - address d, - address e, - address f - ) public { - doSomething(); - } - - function thisFunctionHasLotsOfArguments( - address a, - address b, - address c, - address d, - address e, - address f - ) public { - doSomething(); - } - - function thisFunctionHasLotsOfArguments( - address a, - address b, - address c, - address d, - address e, - address f - ) public { - doSomething(); - } - - function thisFunctionNameIsReallyLong( - address x, - address y, - address z - ) public onlyowner priced returns (address) { - doSomething(); - } - - function thisFunctionNameIsReallyLong( - address x, - address y, - address z - ) public onlyowner priced returns (address) { - doSomething(); - } - - function thisFunctionNameIsReallyLong( - address x, - address y, - address z - ) public onlyowner priced returns (address) { - doSomething(); - } - - function thisFunctionNameIsReallyLong( - address a, - address b, - address c - ) - public - returns ( - address someAddressName, - uint256 LongArgument, - uint256 Argument - ) - { - doSomething(); - - return ( - veryVeryLongReturnArg1, - veryVeryLongReturnArg1, - veryVeryLongReturnArg1 - ); - } -} - -// Base contracts just to make this compile -contract B { - constructor(uint) public {} -} - -contract C { - constructor(uint, uint) public {} -} - -contract D { - constructor(uint) public {} -} - -/* TODO: constructors calls have priority over visibility */ -contract A is B, C, D { - uint x; - - constructor( - uint param1, - uint param2, - uint param3, - uint param4, - uint param5 - ) public B(param1) C(param2, param3) D(param4) { - x = param5; - } -} - -contract X is B, C, D { - uint x; - - constructor( - uint param1, - uint param2, - uint param3, - uint param4, - uint param5 - ) public B(param1) C(param2, param3) D(param4) { - x = param5; - } -} - -================================================================================ -`; - -exports[`Mappings.sol - {"compiler":"0.5.0"} format 1`] = ` -====================================options===================================== -compiler: "0.5.0" -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity >=0.4.0 <0.7.0; - - -contract Mappings { - mapping (uint => uint) map; - mapping( address => bool ) registeredAddresses; - mapping (uint => mapping (bool => Data[])) public data; - mapping(uint => mapping (uint => s)) data; -} - -=====================================output===================================== -pragma solidity >=0.4.0 <0.7.0; - -contract Mappings { - mapping(uint => uint) map; - mapping(address => bool) registeredAddresses; - mapping(uint => mapping(bool => Data[])) public data; - mapping(uint => mapping(uint => s)) data; -} - -================================================================================ -`; - -exports[`Mappings.sol format 1`] = ` -====================================options===================================== -parsers: ["solidity-parse"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity >=0.4.0 <0.7.0; - - -contract Mappings { - mapping (uint => uint) map; - mapping( address => bool ) registeredAddresses; - mapping (uint => mapping (bool => Data[])) public data; - mapping(uint => mapping (uint => s)) data; -} - -=====================================output===================================== -pragma solidity >=0.4.0 <0.7.0; - -contract Mappings { - mapping(uint => uint) map; - mapping(address => bool) registeredAddresses; - mapping(uint => mapping(bool => Data[])) public data; - mapping(uint => mapping(uint => s)) data; -} - -================================================================================ -`; - -exports[`MaximumLineLength.sol - {"compiler":"0.5.0"} format 1`] = ` -====================================options===================================== -compiler: "0.5.0" -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity >=0.4.0 <0.7.0; - - -contract FunctionCalls { - function() { - thisFunctionCallIsReallyLong(longArgument1, - longArgument2, - longArgument3 - ); - - thisFunctionCallIsReallyLong(longArgument1, - longArgument2, - longArgument3 - ); - - thisFunctionCallIsReallyLong( - longArgument1, longArgument2, - longArgument3 - ); - - thisFunctionCallIsReallyLong( - longArgument1, - longArgument2, - longArgument3 - ); - - thisFunctionCallIsReallyLong( - longArgument1, - longArgument2, - longArgument3); - } -} - - -contract AssignmentStatements { - function() { - thisIsALongNestedMapping[being][set][to_some_value] = someFunction(argument1, - argument2, - argument3, - argument4); - } -} - - -contract EventDefinitionsAndEventEmitters { - event LongAndLotsOfArgs(address sender, - address recipient, - uint256 publicKey, - uint256 amount, - bytes32[] options, - bytes32 longAttribute); - - function() { - LongAndLotsOfArgs(sender, - recipient, - publicKey, - amount, - options, - longAttribute); - emit LongAndLotsOfArgs(sender, - recipient, - publicKey, - amount, - options, - longAttribute); - } -} - -=====================================output===================================== -pragma solidity >=0.4.0 <0.7.0; - -contract FunctionCalls { - function() { - thisFunctionCallIsReallyLong( - longArgument1, - longArgument2, - longArgument3 - ); - - thisFunctionCallIsReallyLong( - longArgument1, - longArgument2, - longArgument3 - ); - - thisFunctionCallIsReallyLong( - longArgument1, - longArgument2, - longArgument3 - ); - - thisFunctionCallIsReallyLong( - longArgument1, - longArgument2, - longArgument3 - ); - - thisFunctionCallIsReallyLong( - longArgument1, - longArgument2, - longArgument3 - ); - } -} - -contract AssignmentStatements { - function() { - thisIsALongNestedMapping[being][set][to_some_value] = someFunction( - argument1, - argument2, - argument3, - argument4 - ); - } -} - -contract EventDefinitionsAndEventEmitters { - event LongAndLotsOfArgs( - address sender, - address recipient, - uint256 publicKey, - uint256 amount, - bytes32[] options, - bytes32 longAttribute - ); - - function() { - LongAndLotsOfArgs( - sender, - recipient, - publicKey, - amount, - options, - longAttribute - ); - emit LongAndLotsOfArgs( - sender, - recipient, - publicKey, - amount, - options, - longAttribute - ); - } -} - -================================================================================ -`; - -exports[`MaximumLineLength.sol format 1`] = ` -====================================options===================================== -parsers: ["solidity-parse"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity >=0.4.0 <0.7.0; - - -contract FunctionCalls { - function() { - thisFunctionCallIsReallyLong(longArgument1, - longArgument2, - longArgument3 - ); - - thisFunctionCallIsReallyLong(longArgument1, - longArgument2, - longArgument3 - ); - - thisFunctionCallIsReallyLong( - longArgument1, longArgument2, - longArgument3 - ); - - thisFunctionCallIsReallyLong( - longArgument1, - longArgument2, - longArgument3 - ); - - thisFunctionCallIsReallyLong( - longArgument1, - longArgument2, - longArgument3); - } -} - - -contract AssignmentStatements { - function() { - thisIsALongNestedMapping[being][set][to_some_value] = someFunction(argument1, - argument2, - argument3, - argument4); - } -} +} contract EventDefinitionsAndEventEmitters { @@ -1260,63 +642,6 @@ contract EventDefinitionsAndEventEmitters { ================================================================================ `; -exports[`OtherRecommendations.sol - {"compiler":"0.5.0"} format 1`] = ` -====================================options===================================== -compiler: "0.5.0" -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity >=0.4.0 <0.7.0; - - -contract OtherRecommendations { - function () { - str = 'bar'; - /* TODO: escape quotes in Strings when enforcing a new quote - str = '"Be yourself; everyone else is already taken." -Oscar Wilde'; - */ - - x=3; - x = 100/10; - x += 3+4; - x |= y&&z; - - - /* TODO: whitespace around and operator can be different than 1 space if - it is the same length before and after - x = 2**3 + 5; - x = 2*y + 3*z; - x = (a+b) * (a-b); - */ - - - x = 2** 3 + 5; - x = y+z; - x +=1; - } -} - -=====================================output===================================== -pragma solidity >=0.4.0 <0.7.0; - -contract OtherRecommendations { - function() { - str = "bar"; - x = 3; - x = 100 / 10; - x += 3 + 4; - x |= y && z; - - x = 2 ** 3 + 5; - x = y + z; - x += 1; - } -} - -================================================================================ -`; - exports[`OtherRecommendations.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] @@ -1384,30 +709,6 @@ contract OtherRecommendations { ================================================================================ `; -exports[`VariableDeclarations.sol - {"compiler":"0.5.0"} format 1`] = ` -====================================options===================================== -compiler: "0.5.0" -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity >=0.4.0 <0.7.0; - - -contract VariableDeclarations { - uint [] x; -} - -=====================================output===================================== -pragma solidity >=0.4.0 <0.7.0; - -contract VariableDeclarations { - uint[] x; -} - -================================================================================ -`; - exports[`VariableDeclarations.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] @@ -1431,44 +732,6 @@ contract VariableDeclarations { ================================================================================ `; -exports[`WhitespaceInExpressions.sol - {"compiler":"0.5.0"} format 1`] = ` -====================================options===================================== -compiler: "0.5.0" -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity >=0.4.0 <0.7.0; - - -contract WhitespaceInExpressions { - function () { - spam( ham[ 1 ], Coin( { name: "ham" } ) ); - x = 1; - y = 2; - long_variable = 3; - } - - function spam(uint i , Coin coin) public ; -} - -=====================================output===================================== -pragma solidity >=0.4.0 <0.7.0; - -contract WhitespaceInExpressions { - function() { - spam(ham[1], Coin({name: "ham"})); - x = 1; - y = 2; - long_variable = 3; - } - - function spam(uint i, Coin coin) public; -} - -================================================================================ -`; - exports[`WhitespaceInExpressions.sol format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] diff --git a/tests/format/StyleGuide/jsfmt.spec.js b/tests/format/StyleGuide/jsfmt.spec.js index feedd0559..765dd60a6 100644 --- a/tests/format/StyleGuide/jsfmt.spec.js +++ b/tests/format/StyleGuide/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang'], { compiler: '0.5.0' }); diff --git a/tests/format/TryCatch/__snapshots__/jsfmt.spec.js.snap b/tests/format/TryCatch/__snapshots__/jsfmt.spec.js.snap index 58efea045..72355b966 100644 --- a/tests/format/TryCatch/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/TryCatch/__snapshots__/jsfmt.spec.js.snap @@ -222,212 +222,3 @@ contract FeedConsumer { ================================================================================ `; - -exports[`TryCatch.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity ^0.6.0; - -interface DataFeed { function getData(address token) external returns (uint value); } - -contract FeedConsumer { - DataFeed feed; - uint errorCount; - function rate(address token) public returns (uint value, bool success) { - // Permanently disable the mechanism if there are - // more than 10 errors. - require(errorCount < 10); - try feed.getData(token) - returns (uint v) { - return (v, true); - } catch - Error(string memory /*reason*/) - { - // This is executed in case - // revert was called inside getData - // and a reason string was provided. - errorCount++; - return (0, false); - } catch (bytes memory /*lowLevelData*/ - ) { - // This is executed in case revert() was used - // or there was a failing assertion, division - // by zero, etc. inside getData. - errorCount++; - return (0, false); - } } - - function rate2(address token) public returns (uint value, bool success) { - // Permanently disable the mechanism if there are - // more than 10 errors. - require(errorCount < 10); - try feed.getData(token) - returns (uint v, uint v1,uint v2,uint v3,uint v4,uint v5,uint v6,uint v7,uint v8) { - return (v, true); - } catch - Error(string memory /*reason*/) - { - // This is executed in case - // revert was called inside getData - // and a reason string was provided. - errorCount++; - return (0, false); - } catch (bytes memory /*lowLevelData*/ - ) { - // This is executed in case revert() was used - // or there was a failing assertion, division - // by zero, etc. inside getData. - errorCount++; - return (0, false); - } } - - function rate3(address token) public returns (uint value, bool success) { - // Permanently disable the mechanism if there are - // more than 10 errors. - require(errorCount < 10); - try feed.getData(token) { - return (v, true); - } catch - Error(string memory /*reason*/) - { - // This is executed in case - // revert was called inside getData - // and a reason string was provided. - errorCount++; - return (0, false); - } catch { - // This is executed in case revert() was used - // or there was a failing assertion, division - // by zero, etc. inside getData. - errorCount++; - return (0, false); - } } - - function rate4(address token) public returns (uint value, bool success) { - // Permanently disable the mechanism if there are - // more than 10 errors. - require(errorCount < 10); - try feed.getData(token) returns (uint v) { - return (v, true); - } catch Error(string memory /*reason*/) { - // This is executed in case - // revert was called inside getData - // and a reason string was provided. - errorCount++; - return (0, false); - } catch Panic(uint /*errorCode*/) { - // This is executed in case of a panic, - // i.e. a serious error like division by zero - // or overflow. The error code can be used - // to determine the kind of error. - errorCount++; - return (0, false); - } catch (bytes memory /*lowLevelData*/) { - // This is executed in case revert() was used. - errorCount++; - return (0, false); - } - } -} - -=====================================output===================================== -pragma solidity ^0.6.0; - -interface DataFeed { - function getData(address token) external returns (uint value); -} - -contract FeedConsumer { - DataFeed feed; - uint errorCount; - function rate(address token) public returns (uint value, bool success) { - require(errorCount < 10); - try feed.getData(token) returns ( - uint v - ){ - return (v, true); - } catch Error( - string memory - ) { - errorCount++; - return (0, false); - } catch ( - bytes memory - ) { - errorCount++; - return (0, false); - } - } - - function rate2(address token) public returns (uint value, bool success) { - require(errorCount < 10); - try feed.getData(token) returns ( - uint v, - uint v1, - uint v2, - uint v3, - uint v4, - uint v5, - uint v6, - uint v7, - uint v8 - ){ - return (v, true); - } catch Error( - string memory - ) { - errorCount++; - return (0, false); - } catch ( - bytes memory - ) { - errorCount++; - return (0, false); - } - } - - function rate3(address token) public returns (uint value, bool success) { - require(errorCount < 10); - try feed.getData(token) { - return (v, true); - } catch Error( - string memory - ) { - errorCount++; - return (0, false); - } catch{ - errorCount++; - return (0, false); - } - } - - function rate4(address token) public returns (uint value, bool success) { - require(errorCount < 10); - try feed.getData(token) returns ( - uint v - ){ - return (v, true); - } catch Error( - string memory - ) { - errorCount++; - return (0, false); - } catch Panic( - uint - ) { - errorCount++; - return (0, false); - } catch ( - bytes memory - ) { - errorCount++; - return (0, false); - } - } -} - -================================================================================ -`; diff --git a/tests/format/TryCatch/jsfmt.spec.js b/tests/format/TryCatch/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/TryCatch/jsfmt.spec.js +++ b/tests/format/TryCatch/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); diff --git a/tests/format/Tupples/__snapshots__/jsfmt.spec.js.snap b/tests/format/Tupples/__snapshots__/jsfmt.spec.js.snap index fc1451502..4ddda35fc 100644 --- a/tests/format/Tupples/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Tupples/__snapshots__/jsfmt.spec.js.snap @@ -62,66 +62,3 @@ contract Tupples { ================================================================================ `; - -exports[`Tupples.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity ^0.5.0; - -contract demo { - function hello() public view returns(bool,bool) {} - function hello2() public view returns(bool) {} - function hello3() public view returns(bool,bool,bool) {} - -} - -contract Tupples { - function world(address payable _yo) public view { - bool yo; - yo = demo(_yo).hello2(); - (yo, ) = demo(_yo).hello(); - (, yo) = demo(_yo).hello(); - (yo, , yo) = demo(_yo).hello3(); - (yo, yo) = demo(_yo).hello(); - (string memory holderId, -string memory containerId, -string memory parentContainerId, -bytes32 volumeId, -bytes32 subUnitId, -bytes32 requestId) = getParamsById(paramsId); - } -} - -=====================================output===================================== -pragma solidity ^0.5.0; - -contract demo { - function hello() public view returns (bool, bool) {} - function hello2() public view returns (bool) {} - function hello3() public view returns (bool, bool, bool) {} -} - -contract Tupples { - function world(address payable _yo) public view { - bool yo; - yo = demo(_yo).hello2(); - (yo, ) = demo(_yo).hello(); - (, yo) = demo(_yo).hello(); - (yo, , yo) = demo(_yo).hello3(); - (yo, yo) = demo(_yo).hello(); - ( - string memory holderId, - string memory containerId, - string memory parentContainerId, - bytes32 volumeId, - bytes32 subUnitId, - bytes32 requestId - ) = getParamsById(paramsId); - } -} - -================================================================================ -`; diff --git a/tests/format/Tupples/jsfmt.spec.js b/tests/format/Tupples/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/Tupples/jsfmt.spec.js +++ b/tests/format/Tupples/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); diff --git a/tests/format/TypeDefinition/__snapshots__/jsfmt.spec.js.snap b/tests/format/TypeDefinition/__snapshots__/jsfmt.spec.js.snap index 46c6fd3eb..04e77a23d 100644 --- a/tests/format/TypeDefinition/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/TypeDefinition/__snapshots__/jsfmt.spec.js.snap @@ -35,39 +35,3 @@ contract TypeDefinition { ================================================================================ `; - -exports[`TypeDefinition.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -pragma solidity ^0.8.8; - - type Hello is uint; - -contract TypeDefinition { - event Moon(Hello world); - - function demo(Hello world) public { - world = Hello.wrap(Hello.unwrap(world) + 1337); - emit Moon(world); - } -} - -=====================================output===================================== -pragma solidity ^0.8.8; - -type Hello is uint; - -contract TypeDefinition { - event Moon(Hello world); - - function demo(Hello world) public { - world = Hello.wrap(Hello.unwrap(world) + 1337); - emit Moon(world); - } -} - -================================================================================ -`; diff --git a/tests/format/TypeDefinition/jsfmt.spec.js b/tests/format/TypeDefinition/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/TypeDefinition/jsfmt.spec.js +++ b/tests/format/TypeDefinition/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); diff --git a/tests/format/WhileStatements/__snapshots__/jsfmt.spec.js.snap b/tests/format/WhileStatements/__snapshots__/jsfmt.spec.js.snap index 160e74f6e..e13595552 100644 --- a/tests/format/WhileStatements/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/WhileStatements/__snapshots__/jsfmt.spec.js.snap @@ -108,111 +108,3 @@ contract WhileStatements { ================================================================================ `; - -exports[`WhileStatements.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -contract WhileStatements { - uint constant LONG_VARIABLE = 1; - - function whileStatements() public { - uint a; - uint veryLongVariableName; - - while (a < 100) a++; - - while (a < 200) a = a.add(LONG_VARIABLE).add(LONG_VARIABLE).add(LONG_VARIABLE); - - while (a < 300) { a++; } - - while (a < 400) { a = a.add(LONG_VARIABLE).add(LONG_VARIABLE).add(LONG_VARIABLE); } - - while (a < veryLongVariableName.add(LONG_VARIABLE).add(LONG_VARIABLE) * 500) a++; - - while (a < veryLongVariableName.add(LONG_VARIABLE).add(LONG_VARIABLE) * 600) { a++; } - } - - function doWhileStatements() public { - uint a; - uint veryLongVariableName; - - do a++; while (a < 100); - - do a = a.add(LONG_VARIABLE).add(LONG_VARIABLE).add(LONG_VARIABLE); while (a < 200); - - do { a++; }while (a < 300); - - do { a = a.add(LONG_VARIABLE).add(LONG_VARIABLE).add(LONG_VARIABLE); }while (a < 400); - - do a++;while (a < veryLongVariableName.add(LONG_VARIABLE).add(LONG_VARIABLE) * 500); - - do { a++; }while (a < veryLongVariableName.add(LONG_VARIABLE).add(LONG_VARIABLE) * 600); - } -} - -=====================================output===================================== -contract WhileStatements { - uint constant LONG_VARIABLE = 1; - - function whileStatements() public { - uint a; - uint veryLongVariableName; - - while(a < 100)a++; - - while(a < 200)a = a.add(LONG_VARIABLE).add(LONG_VARIABLE).add( - LONG_VARIABLE - ); - - while(a < 300){ - a++; - } - - while(a < 400){ - a = a.add(LONG_VARIABLE).add(LONG_VARIABLE).add(LONG_VARIABLE); - } - - while(a < - veryLongVariableName.add(LONG_VARIABLE).add(LONG_VARIABLE) * 500)a++; - - while(a < - veryLongVariableName.add(LONG_VARIABLE).add(LONG_VARIABLE) * 600){ - a++; - } - } - - function doWhileStatements() public { - uint a; - uint veryLongVariableName; - - do a++; while (a < 100); - - do - a = a.add(LONG_VARIABLE).add(LONG_VARIABLE).add(LONG_VARIABLE); - while (a < 200); - - do { - a++; - } while (a < 300); - - do { - a = a.add(LONG_VARIABLE).add(LONG_VARIABLE).add(LONG_VARIABLE); - } while (a < 400); - - do a++; while ( - a < veryLongVariableName.add(LONG_VARIABLE).add(LONG_VARIABLE) * 500 - ); - - do { - a++; - } while ( - a < veryLongVariableName.add(LONG_VARIABLE).add(LONG_VARIABLE) * 600 - ); - } -} - -================================================================================ -`; diff --git a/tests/format/WhileStatements/jsfmt.spec.js b/tests/format/WhileStatements/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/WhileStatements/jsfmt.spec.js +++ b/tests/format/WhileStatements/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); diff --git a/tests/format/quotes/__snapshots__/jsfmt.spec.js.snap b/tests/format/quotes/__snapshots__/jsfmt.spec.js.snap index 97b7c17b8..ea7f83dd4 100644 --- a/tests/format/quotes/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/quotes/__snapshots__/jsfmt.spec.js.snap @@ -59,65 +59,6 @@ contract Foo { ================================================================================ `; -exports[`Quotes.sol - {"singleQuote":false} format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 -singleQuote: false - | printWidth -=====================================input====================================== -import 'someContract.sol'; -import "someOtherContract.sol"; - -contract Foo { - string foo1 = 'foo'; - string foo2 = "foo"; - string spaces1 = 'the quick brown fox'; - string spaces2 = "the quick brown fox"; - string singleQuote = "don't do that"; - string escapedSingleQuote = 'don\\'t do that'; - string doubleQuote = 'Use " for quoting'; - string escapedDoubleQuote = "Use \\" for quoting"; - string singleQuotes = "don't do that, don't"; - string escapedSingleQuotes = 'don\\'t do that, don\\'t'; - string doubleQuotes = 'The "quick" brown fox'; - string escapeDoubleQuotes = "The \\"quick\\" brown fox"; - bytes8 hex1 = hex'DeadBeef'; - bytes8 hex2 = hex"DeadBeef"; - string withUnicode1 = unicode'hello 🦄 world'; - string withUnicode2 = unicode"hello 🦄 world"; - string multiPartAndUnicode = unicode'hello 🦄' unicode' world 🦄'; -} - -=====================================output===================================== -import "someContract.sol"; -import "someOtherContract.sol"; - -contract Foo { - string foo1 = "foo"; - string foo2 = "foo"; - string spaces1 = "the quick brown fox"; - string spaces2 = "the quick brown fox"; - string singleQuote = "don't do that"; - string escapedSingleQuote = "don't do that"; - string doubleQuote = 'Use " for quoting'; - string escapedDoubleQuote = 'Use " for quoting'; - string singleQuotes = "don't do that, don't"; - string escapedSingleQuotes = "don't do that, don't"; - string doubleQuotes = 'The "quick" brown fox'; - string escapeDoubleQuotes = 'The "quick" brown fox'; - bytes8 hex1 = hex"DeadBeef"; - bytes8 hex2 = hex"DeadBeef"; - string withUnicode1 = unicode"hello 🦄 world"; - string withUnicode2 = unicode"hello 🦄 world"; - string multiPartAndUnicode = - unicode"hello 🦄" - unicode" world 🦄"; -} - -================================================================================ -`; - exports[`Quotes.sol - {"singleQuote":true} format 1`] = ` ====================================options===================================== parsers: ["solidity-parse"] @@ -176,62 +117,3 @@ contract Foo { ================================================================================ `; - -exports[`Quotes.sol - {"singleQuote":true} format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 -singleQuote: true - | printWidth -=====================================input====================================== -import 'someContract.sol'; -import "someOtherContract.sol"; - -contract Foo { - string foo1 = 'foo'; - string foo2 = "foo"; - string spaces1 = 'the quick brown fox'; - string spaces2 = "the quick brown fox"; - string singleQuote = "don't do that"; - string escapedSingleQuote = 'don\\'t do that'; - string doubleQuote = 'Use " for quoting'; - string escapedDoubleQuote = "Use \\" for quoting"; - string singleQuotes = "don't do that, don't"; - string escapedSingleQuotes = 'don\\'t do that, don\\'t'; - string doubleQuotes = 'The "quick" brown fox'; - string escapeDoubleQuotes = "The \\"quick\\" brown fox"; - bytes8 hex1 = hex'DeadBeef'; - bytes8 hex2 = hex"DeadBeef"; - string withUnicode1 = unicode'hello 🦄 world'; - string withUnicode2 = unicode"hello 🦄 world"; - string multiPartAndUnicode = unicode'hello 🦄' unicode' world 🦄'; -} - -=====================================output===================================== -import 'someContract.sol'; -import 'someOtherContract.sol'; - -contract Foo { - string foo1 = 'foo'; - string foo2 = 'foo'; - string spaces1 = 'the quick brown fox'; - string spaces2 = 'the quick brown fox'; - string singleQuote = "don't do that"; - string escapedSingleQuote = "don't do that"; - string doubleQuote = 'Use " for quoting'; - string escapedDoubleQuote = 'Use " for quoting'; - string singleQuotes = "don't do that, don't"; - string escapedSingleQuotes = "don't do that, don't"; - string doubleQuotes = 'The "quick" brown fox'; - string escapeDoubleQuotes = 'The "quick" brown fox'; - bytes8 hex1 = hex'DeadBeef'; - bytes8 hex2 = hex'DeadBeef'; - string withUnicode1 = unicode'hello 🦄 world'; - string withUnicode2 = unicode'hello 🦄 world'; - string multiPartAndUnicode = - unicode'hello 🦄' - unicode' world 🦄'; -} - -================================================================================ -`; diff --git a/tests/format/quotes/jsfmt.spec.js b/tests/format/quotes/jsfmt.spec.js index 6532de66b..3272026cc 100644 --- a/tests/format/quotes/jsfmt.spec.js +++ b/tests/format/quotes/jsfmt.spec.js @@ -1,4 +1,2 @@ run_spec(import.meta, ['solidity-parse'], { singleQuote: true }); run_spec(import.meta, ['solidity-parse'], { singleQuote: false }); -run_spec(import.meta, ['slang'], { singleQuote: true }); -run_spec(import.meta, ['slang'], { singleQuote: false }); diff --git a/tests/format/strings/__snapshots__/jsfmt.spec.js.snap b/tests/format/strings/__snapshots__/jsfmt.spec.js.snap index 9b3efc0b5..2ec8073d9 100644 --- a/tests/format/strings/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/strings/__snapshots__/jsfmt.spec.js.snap @@ -1556,1308 +1556,3 @@ library strings { ================================================================================ `; - -exports[`strings.sol format 2`] = ` -====================================options===================================== -parsers: ["slang"] -printWidth: 80 - | printWidth -=====================================input====================================== -/* - * @title String & slice utility library for Solidity contracts. - * @author Nick Johnson - * - * @dev Functionality in this library is largely implemented using an - * abstraction called a 'slice'. A slice represents a part of a string - - * anything from the entire string to a single character, or even no - * characters at all (a 0-length slice). Since a slice only has to specify - * an offset and a length, copying and manipulating slices is a lot less - * expensive than copying and manipulating the strings they reference. - * - * To further reduce gas costs, most functions on slice that need to return - * a slice modify the original one instead of allocating a new one; for - * instance, \`s.split(".")\` will return the text up to the first '.', - * modifying s to only contain the remainder of the string after the '.'. - * In situations where you do not want to modify the original slice, you - * can make a copy first with \`.copy()\`, for example: - * \`s.copy().split(".")\`. Try and avoid using this idiom in loops; since - * Solidity has no memory management, it will result in allocating many - * short-lived slices that are later discarded. - * - * Functions that return two slices come in two versions: a non-allocating - * version that takes the second slice as an argument, modifying it in - * place, and an allocating version that allocates and returns the second - * slice; see \`nextRune\` for example. - * - * Functions that have to copy string data will return strings rather than - * slices; these can be cast back to slices for further processing if - * required. - * - * For convenience, some functions are provided with non-modifying - * variants that create a new slice and return both; for instance, - * \`s.splitNew('.')\` leaves s unmodified, and returns two values - * corresponding to the left and right parts of the string. - */ - -pragma solidity ^0.4.14; - -library strings { - struct slice { - uint _len; - uint _ptr; - } - - function memcpy(uint dest, uint src, uint len) private pure { - // Copy word-length chunks while possible - for(; len >= 32; len -= 32) { - assembly { - mstore(dest, mload(src)) - } - dest += 32; - src += 32; - } - - // Copy remaining bytes - uint mask = 256 ** (32 - len) - 1; - assembly { - let srcpart := and(mload(src), not(mask)) - let destpart := and(mload(dest), mask) - mstore(dest, or(destpart, srcpart)) - } - } - - /* - * @dev Returns a slice containing the entire string. - * @param self The string to make a slice from. - * @return A newly allocated slice containing the entire string. - */ - function toSlice(string memory self) internal pure returns (slice memory) { - uint ptr; - assembly { - ptr := add(self, 0x20) - } - return slice(bytes(self).length, ptr); - } - - /* - * @dev Returns the length of a null-terminated bytes32 string. - * @param self The value to find the length of. - * @return The length of the string, from 0 to 32. - */ - function len(bytes32 self) internal pure returns (uint) { - uint ret; - if (self == 0) - return 0; - if (self & 0xffffffffffffffffffffffffffffffff == 0) { - ret += 16; - self = bytes32(uint(self) / 0x100000000000000000000000000000000); - } - if (self & 0xffffffffffffffff == 0) { - ret += 8; - self = bytes32(uint(self) / 0x10000000000000000); - } - if (self & 0xffffffff == 0) { - ret += 4; - self = bytes32(uint(self) / 0x100000000); - } - if (self & 0xffff == 0) { - ret += 2; - self = bytes32(uint(self) / 0x10000); - } - if (self & 0xff == 0) { - ret += 1; - } - return 32 - ret; - } - - /* - * @dev Returns a slice containing the entire bytes32, interpreted as a - * null-terminated utf-8 string. - * @param self The bytes32 value to convert to a slice. - * @return A new slice containing the value of the input argument up to the - * first null. - */ - function toSliceB32(bytes32 self) internal pure returns (slice memory ret) { - // Allocate space for \`self\` in memory, copy it there, and point ret at it - assembly { - let ptr := mload(0x40) - mstore(0x40, add(ptr, 0x20)) - mstore(ptr, self) - mstore(add(ret, 0x20), ptr) - } - ret._len = len(self); - } - - /* - * @dev Returns a new slice containing the same data as the current slice. - * @param self The slice to copy. - * @return A new slice containing the same data as \`self\`. - */ - function copy(slice memory self) internal pure returns (slice memory) { - return slice(self._len, self._ptr); - } - - /* - * @dev Copies a slice to a new string. - * @param self The slice to copy. - * @return A newly allocated string containing the slice's text. - */ - function toString(slice memory self) internal pure returns (string memory) { - string memory ret = new string(self._len); - uint retptr; - assembly { retptr := add(ret, 32) } - - memcpy(retptr, self._ptr, self._len); - return ret; - } - - /* - * @dev Returns the length in runes of the slice. Note that this operation - * takes time proportional to the length of the slice; avoid using it - * in loops, and call \`slice.empty()\` if you only need to know whether - * the slice is empty or not. - * @param self The slice to operate on. - * @return The length of the slice in runes. - */ - function len(slice memory self) internal pure returns (uint l) { - // Starting at ptr-31 means the LSB will be the byte we care about - uint ptr = self._ptr - 31; - uint end = ptr + self._len; - for (l = 0; ptr < end; l++) { - uint8 b; - assembly { b := and(mload(ptr), 0xFF) } - if (b < 0x80) { - ptr += 1; - } else if(b < 0xE0) { - ptr += 2; - } else if(b < 0xF0) { - ptr += 3; - } else if(b < 0xF8) { - ptr += 4; - } else if(b < 0xFC) { - ptr += 5; - } else { - ptr += 6; - } - } - } - - /* - * @dev Returns true if the slice is empty (has a length of 0). - * @param self The slice to operate on. - * @return True if the slice is empty, False otherwise. - */ - function empty(slice memory self) internal pure returns (bool) { - return self._len == 0; - } - - /* - * @dev Returns a positive number if \`other\` comes lexicographically after - * \`self\`, a negative number if it comes before, or zero if the - * contents of the two slices are equal. Comparison is done per-rune, - * on unicode codepoints. - * @param self The first slice to compare. - * @param other The second slice to compare. - * @return The result of the comparison. - */ - function compare(slice memory self, slice memory other) internal pure returns (int) { - uint shortest = self._len; - if (other._len < self._len) - shortest = other._len; - - uint selfptr = self._ptr; - uint otherptr = other._ptr; - for (uint idx = 0; idx < shortest; idx += 32) { - uint a; - uint b; - assembly { - a := mload(selfptr) - b := mload(otherptr) - } - if (a != b) { - // Mask out irrelevant bytes and check again - uint256 mask = uint256(-1); // 0xffff... - if(shortest < 32) { - mask = ~(2 ** (8 * (32 - shortest + idx)) - 1); - } - uint256 diff = (a & mask) - (b & mask); - if (diff != 0) - return int(diff); - } - selfptr += 32; - otherptr += 32; - } - return int(self._len) - int(other._len); - } - - /* - * @dev Returns true if the two slices contain the same text. - * @param self The first slice to compare. - * @param self The second slice to compare. - * @return True if the slices are equal, false otherwise. - */ - function equals(slice memory self, slice memory other) internal pure returns (bool) { - return compare(self, other) == 0; - } - - /* - * @dev Extracts the first rune in the slice into \`rune\`, advancing the - * slice to point to the next rune and returning \`self\`. - * @param self The slice to operate on. - * @param rune The slice that will contain the first rune. - * @return \`rune\`. - */ - function nextRune(slice memory self, slice memory rune) internal pure returns (slice memory) { - rune._ptr = self._ptr; - - if (self._len == 0) { - rune._len = 0; - return rune; - } - - uint l; - uint b; - // Load the first byte of the rune into the LSBs of b - assembly { b := and(mload(sub(mload(add(self, 32)), 31)), 0xFF) } - if (b < 0x80) { - l = 1; - } else if(b < 0xE0) { - l = 2; - } else if(b < 0xF0) { - l = 3; - } else { - l = 4; - } - - // Check for truncated codepoints - if (l > self._len) { - rune._len = self._len; - self._ptr += self._len; - self._len = 0; - return rune; - } - - self._ptr += l; - self._len -= l; - rune._len = l; - return rune; - } - - /* - * @dev Returns the first rune in the slice, advancing the slice to point - * to the next rune. - * @param self The slice to operate on. - * @return A slice containing only the first rune from \`self\`. - */ - function nextRune(slice memory self) internal pure returns (slice memory ret) { - nextRune(self, ret); - } - - /* - * @dev Returns the number of the first codepoint in the slice. - * @param self The slice to operate on. - * @return The number of the first codepoint in the slice. - */ - function ord(slice memory self) internal pure returns (uint ret) { - if (self._len == 0) { - return 0; - } - - uint word; - uint length; - uint divisor = 2 ** 248; - - // Load the rune into the MSBs of b - assembly { word:= mload(mload(add(self, 32))) } - uint b = word / divisor; - if (b < 0x80) { - ret = b; - length = 1; - } else if(b < 0xE0) { - ret = b & 0x1F; - length = 2; - } else if(b < 0xF0) { - ret = b & 0x0F; - length = 3; - } else { - ret = b & 0x07; - length = 4; - } - - // Check for truncated codepoints - if (length > self._len) { - return 0; - } - - for (uint i = 1; i < length; i++) { - divisor = divisor / 256; - b = (word / divisor) & 0xFF; - if (b & 0xC0 != 0x80) { - // Invalid UTF-8 sequence - return 0; - } - ret = (ret * 64) | (b & 0x3F); - } - - return ret; - } - - /* - * @dev Returns the keccak-256 hash of the slice. - * @param self The slice to hash. - * @return The hash of the slice. - */ - function keccak(slice memory self) internal pure returns (bytes32 ret) { - assembly { - ret := keccak256(mload(add(self, 32)), mload(self)) - } - } - - /* - * @dev Returns true if \`self\` starts with \`needle\`. - * @param self The slice to operate on. - * @param needle The slice to search for. - * @return True if the slice starts with the provided text, false otherwise. - */ - function startsWith(slice memory self, slice memory needle) internal pure returns (bool) { - if (self._len < needle._len) { - return false; - } - - if (self._ptr == needle._ptr) { - return true; - } - - bool equal; - assembly { - let length := mload(needle) - let selfptr := mload(add(self, 0x20)) - let needleptr := mload(add(needle, 0x20)) - equal := eq(keccak256(selfptr, length), keccak256(needleptr, length)) - } - return equal; - } - - /* - * @dev If \`self\` starts with \`needle\`, \`needle\` is removed from the - * beginning of \`self\`. Otherwise, \`self\` is unmodified. - * @param self The slice to operate on. - * @param needle The slice to search for. - * @return \`self\` - */ - function beyond(slice memory self, slice memory needle) internal pure returns (slice memory) { - if (self._len < needle._len) { - return self; - } - - bool equal = true; - if (self._ptr != needle._ptr) { - assembly { - let length := mload(needle) - let selfptr := mload(add(self, 0x20)) - let needleptr := mload(add(needle, 0x20)) - equal := eq(keccak256(selfptr, length), keccak256(needleptr, length)) - } - } - - if (equal) { - self._len -= needle._len; - self._ptr += needle._len; - } - - return self; - } - - /* - * @dev Returns true if the slice ends with \`needle\`. - * @param self The slice to operate on. - * @param needle The slice to search for. - * @return True if the slice starts with the provided text, false otherwise. - */ - function endsWith(slice memory self, slice memory needle) internal pure returns (bool) { - if (self._len < needle._len) { - return false; - } - - uint selfptr = self._ptr + self._len - needle._len; - - if (selfptr == needle._ptr) { - return true; - } - - bool equal; - assembly { - let length := mload(needle) - let needleptr := mload(add(needle, 0x20)) - equal := eq(keccak256(selfptr, length), keccak256(needleptr, length)) - } - - return equal; - } - - /* - * @dev If \`self\` ends with \`needle\`, \`needle\` is removed from the - * end of \`self\`. Otherwise, \`self\` is unmodified. - * @param self The slice to operate on. - * @param needle The slice to search for. - * @return \`self\` - */ - function until(slice memory self, slice memory needle) internal pure returns (slice memory) { - if (self._len < needle._len) { - return self; - } - - uint selfptr = self._ptr + self._len - needle._len; - bool equal = true; - if (selfptr != needle._ptr) { - assembly { - let length := mload(needle) - let needleptr := mload(add(needle, 0x20)) - equal := eq(keccak256(selfptr, length), keccak256(needleptr, length)) - } - } - - if (equal) { - self._len -= needle._len; - } - - return self; - } - - // Returns the memory address of the first byte of the first occurrence of - // \`needle\` in \`self\`, or the first byte after \`self\` if not found. - function findPtr(uint selflen, uint selfptr, uint needlelen, uint needleptr) private pure returns (uint) { - uint ptr = selfptr; - uint idx; - - if (needlelen <= selflen) { - if (needlelen <= 32) { - bytes32 mask = bytes32(~(2 ** (8 * (32 - needlelen)) - 1)); - - bytes32 needledata; - assembly { needledata := and(mload(needleptr), mask) } - - uint end = selfptr + selflen - needlelen; - bytes32 ptrdata; - assembly { ptrdata := and(mload(ptr), mask) } - - while (ptrdata != needledata) { - if (ptr >= end) - return selfptr + selflen; - ptr++; - assembly { ptrdata := and(mload(ptr), mask) } - } - return ptr; - } else { - // For long needles, use hashing - bytes32 hash; - assembly { hash := keccak256(needleptr, needlelen) } - - for (idx = 0; idx <= selflen - needlelen; idx++) { - bytes32 testHash; - assembly { testHash := keccak256(ptr, needlelen) } - if (hash == testHash) - return ptr; - ptr += 1; - } - } - } - return selfptr + selflen; - } - - // Returns the memory address of the first byte after the last occurrence of - // \`needle\` in \`self\`, or the address of \`self\` if not found. - function rfindPtr(uint selflen, uint selfptr, uint needlelen, uint needleptr) private pure returns (uint) { - uint ptr; - - if (needlelen <= selflen) { - if (needlelen <= 32) { - bytes32 mask = bytes32(~(2 ** (8 * (32 - needlelen)) - 1)); - - bytes32 needledata; - assembly { needledata := and(mload(needleptr), mask) } - - ptr = selfptr + selflen - needlelen; - bytes32 ptrdata; - assembly { ptrdata := and(mload(ptr), mask) } - - while (ptrdata != needledata) { - if (ptr <= selfptr) - return selfptr; - ptr--; - assembly { ptrdata := and(mload(ptr), mask) } - } - return ptr + needlelen; - } else { - // For long needles, use hashing - bytes32 hash; - assembly { hash := keccak256(needleptr, needlelen) } - ptr = selfptr + (selflen - needlelen); - while (ptr >= selfptr) { - bytes32 testHash; - assembly { testHash := keccak256(ptr, needlelen) } - if (hash == testHash) - return ptr + needlelen; - ptr -= 1; - } - } - } - return selfptr; - } - - /* - * @dev Modifies \`self\` to contain everything from the first occurrence of - * \`needle\` to the end of the slice. \`self\` is set to the empty slice - * if \`needle\` is not found. - * @param self The slice to search and modify. - * @param needle The text to search for. - * @return \`self\`. - */ - function find(slice memory self, slice memory needle) internal pure returns (slice memory) { - uint ptr = findPtr(self._len, self._ptr, needle._len, needle._ptr); - self._len -= ptr - self._ptr; - self._ptr = ptr; - return self; - } - - /* - * @dev Modifies \`self\` to contain the part of the string from the start of - * \`self\` to the end of the first occurrence of \`needle\`. If \`needle\` - * is not found, \`self\` is set to the empty slice. - * @param self The slice to search and modify. - * @param needle The text to search for. - * @return \`self\`. - */ - function rfind(slice memory self, slice memory needle) internal pure returns (slice memory) { - uint ptr = rfindPtr(self._len, self._ptr, needle._len, needle._ptr); - self._len = ptr - self._ptr; - return self; - } - - /* - * @dev Splits the slice, setting \`self\` to everything after the first - * occurrence of \`needle\`, and \`token\` to everything before it. If - * \`needle\` does not occur in \`self\`, \`self\` is set to the empty slice, - * and \`token\` is set to the entirety of \`self\`. - * @param self The slice to split. - * @param needle The text to search for in \`self\`. - * @param token An output parameter to which the first token is written. - * @return \`token\`. - */ - function split(slice memory self, slice memory needle, slice memory token) internal pure returns (slice memory) { - uint ptr = findPtr(self._len, self._ptr, needle._len, needle._ptr); - token._ptr = self._ptr; - token._len = ptr - self._ptr; - if (ptr == self._ptr + self._len) { - // Not found - self._len = 0; - } else { - self._len -= token._len + needle._len; - self._ptr = ptr + needle._len; - } - return token; - } - - /* - * @dev Splits the slice, setting \`self\` to everything after the first - * occurrence of \`needle\`, and returning everything before it. If - * \`needle\` does not occur in \`self\`, \`self\` is set to the empty slice, - * and the entirety of \`self\` is returned. - * @param self The slice to split. - * @param needle The text to search for in \`self\`. - * @return The part of \`self\` up to the first occurrence of \`delim\`. - */ - function split(slice memory self, slice memory needle) internal pure returns (slice memory token) { - split(self, needle, token); - } - - /* - * @dev Splits the slice, setting \`self\` to everything before the last - * occurrence of \`needle\`, and \`token\` to everything after it. If - * \`needle\` does not occur in \`self\`, \`self\` is set to the empty slice, - * and \`token\` is set to the entirety of \`self\`. - * @param self The slice to split. - * @param needle The text to search for in \`self\`. - * @param token An output parameter to which the first token is written. - * @return \`token\`. - */ - function rsplit(slice memory self, slice memory needle, slice memory token) internal pure returns (slice memory) { - uint ptr = rfindPtr(self._len, self._ptr, needle._len, needle._ptr); - token._ptr = ptr; - token._len = self._len - (ptr - self._ptr); - if (ptr == self._ptr) { - // Not found - self._len = 0; - } else { - self._len -= token._len + needle._len; - } - return token; - } - - /* - * @dev Splits the slice, setting \`self\` to everything before the last - * occurrence of \`needle\`, and returning everything after it. If - * \`needle\` does not occur in \`self\`, \`self\` is set to the empty slice, - * and the entirety of \`self\` is returned. - * @param self The slice to split. - * @param needle The text to search for in \`self\`. - * @return The part of \`self\` after the last occurrence of \`delim\`. - */ - function rsplit(slice memory self, slice memory needle) internal pure returns (slice memory token) { - rsplit(self, needle, token); - } - - /* - * @dev Counts the number of nonoverlapping occurrences of \`needle\` in \`self\`. - * @param self The slice to search. - * @param needle The text to search for in \`self\`. - * @return The number of occurrences of \`needle\` found in \`self\`. - */ - function count(slice memory self, slice memory needle) internal pure returns (uint cnt) { - uint ptr = findPtr(self._len, self._ptr, needle._len, needle._ptr) + needle._len; - while (ptr <= self._ptr + self._len) { - cnt++; - ptr = findPtr(self._len - (ptr - self._ptr), ptr, needle._len, needle._ptr) + needle._len; - } - } - - /* - * @dev Returns True if \`self\` contains \`needle\`. - * @param self The slice to search. - * @param needle The text to search for in \`self\`. - * @return True if \`needle\` is found in \`self\`, false otherwise. - */ - function contains(slice memory self, slice memory needle) internal pure returns (bool) { - return rfindPtr(self._len, self._ptr, needle._len, needle._ptr) != self._ptr; - } - - /* - * @dev Returns a newly allocated string containing the concatenation of - * \`self\` and \`other\`. - * @param self The first slice to concatenate. - * @param other The second slice to concatenate. - * @return The concatenation of the two strings. - */ - function concat(slice memory self, slice memory other) internal pure returns (string memory) { - string memory ret = new string(self._len + other._len); - uint retptr; - assembly { retptr := add(ret, 32) } - memcpy(retptr, self._ptr, self._len); - memcpy(retptr + self._len, other._ptr, other._len); - return ret; - } - - /* - * @dev Joins an array of slices, using \`self\` as a delimiter, returning a - * newly allocated string. - * @param self The delimiter to use. - * @param parts A list of slices to join. - * @return A newly allocated string containing all the slices in \`parts\`, - * joined with \`self\`. - */ - function join(slice memory self, slice[] memory parts) internal pure returns (string memory) { - if (parts.length == 0) - return ""; - - uint length = self._len * (parts.length - 1); - for(uint i = 0; i < parts.length; i++) { - length += parts[i]._len; - } - - string memory ret = new string(length); - uint retptr; - assembly { retptr := add(ret, 32) } - - for(i = 0; i < parts.length; i++) { - memcpy(retptr, parts[i]._ptr, parts[i]._len); - retptr += parts[i]._len; - if (i < parts.length - 1) { - memcpy(retptr, self._ptr, self._len); - retptr += self._len; - } - } - - return ret; - } -} - -=====================================output===================================== -pragma solidity ^0.4.14; - -library strings { - struct slice { - uint _len; - uint _ptr; - } - - function memcpy(uint dest, uint src, uint len) private pure { - for (; len >= 32; len -= 32) { - assembly { - mstore(dest,mload(src)) - } - dest += 32; - src += 32; - } - - uint mask = 256 ** (32 - len) - 1; - assembly { - let srcpart := and(mload(src),not(mask)) - let destpart := and(mload(dest),mask) - mstore(dest,or(destpart,srcpart)) - } - } - - function toSlice(string memory self) internal pure returns (slice memory) { - uint ptr; - assembly { - ptr := add(self,0x20) - } - return slice(bytes(self).length, ptr); - } - - function len(bytes32 self) internal pure returns (uint) { - uint ret; - if (self == 0) return 0; - if (self & 0xffffffffffffffffffffffffffffffff == 0) { - ret += 16; - self = bytes32(uint(self) / 0x100000000000000000000000000000000); - } - if (self & 0xffffffffffffffff == 0) { - ret += 8; - self = bytes32(uint(self) / 0x10000000000000000); - } - if (self & 0xffffffff == 0) { - ret += 4; - self = bytes32(uint(self) / 0x100000000); - } - if (self & 0xffff == 0) { - ret += 2; - self = bytes32(uint(self) / 0x10000); - } - if (self & 0xff == 0) { - ret += 1; - } - return 32 - ret; - } - - function toSliceB32(bytes32 self) internal pure returns (slice memory ret) { - assembly { - let ptr := mload(0x40) - mstore(0x40,add(ptr,0x20)) - mstore(ptr,self) - mstore(add(ret,0x20),ptr) - } - ret._len = len(self); - } - - function copy(slice memory self) internal pure returns (slice memory) { - return slice(self._len, self._ptr); - } - - function toString(slice memory self) internal pure returns (string memory) { - string memory ret = new string(self._len); - uint retptr; - assembly { - retptr := add(ret,32) - } - - memcpy(retptr, self._ptr, self._len); - return ret; - } - - function len(slice memory self) internal pure returns (uint l) { - uint ptr = self._ptr - 31; - uint end = ptr + self._len; - for (l = 0; ptr < end; l++) { - uint8 b; - assembly { - b := and(mload(ptr),0xFF) - } - if (b < 0x80) { - ptr += 1; - } else if (b < 0xE0) { - ptr += 2; - } else if (b < 0xF0) { - ptr += 3; - } else if (b < 0xF8) { - ptr += 4; - } else if (b < 0xFC) { - ptr += 5; - } else { - ptr += 6; - } - } - } - - function empty(slice memory self) internal pure returns (bool) { - return self._len == 0; - } - - function compare( - slice memory self, - slice memory other - ) internal pure returns (int) { - uint shortest = self._len; - if (other._len < self._len) shortest = other._len; - - uint selfptr = self._ptr; - uint otherptr = other._ptr; - for (uint idx = 0; idx < shortest; idx += 32) { - uint a; - uint b; - assembly { - a := mload(selfptr) - b := mload(otherptr) - } - if (a != b) { - uint256 mask = uint256(-1); - if (shortest < 32) { - mask = ~(2 ** (8 * (32 - shortest + idx)) - 1); - } - uint256 diff = (a & mask) - (b & mask); - if (diff != 0) return int(diff); - } - selfptr += 32; - otherptr += 32; - } - return int(self._len) - int(other._len); - } - - function equals( - slice memory self, - slice memory other - ) internal pure returns (bool) { - return compare(self, other) == 0; - } - - function nextRune( - slice memory self, - slice memory rune - ) internal pure returns (slice memory) { - rune._ptr = self._ptr; - - if (self._len == 0) { - rune._len = 0; - return rune; - } - - uint l; - uint b; - assembly { - b := and(mload(sub(mload(add(self,32)),31)),0xFF) - } - if (b < 0x80) { - l = 1; - } else if (b < 0xE0) { - l = 2; - } else if (b < 0xF0) { - l = 3; - } else { - l = 4; - } - - if (l > self._len) { - rune._len = self._len; - self._ptr += self._len; - self._len = 0; - return rune; - } - - self._ptr += l; - self._len -= l; - rune._len = l; - return rune; - } - - function nextRune( - slice memory self - ) internal pure returns (slice memory ret) { - nextRune(self, ret); - } - - function ord(slice memory self) internal pure returns (uint ret) { - if (self._len == 0) { - return 0; - } - - uint word; - uint length; - uint divisor = 2 ** 248; - - assembly { - word := mload(mload(add(self,32))) - } - uint b = word / divisor; - if (b < 0x80) { - ret = b; - length = 1; - } else if (b < 0xE0) { - ret = b & 0x1F; - length = 2; - } else if (b < 0xF0) { - ret = b & 0x0F; - length = 3; - } else { - ret = b & 0x07; - length = 4; - } - - if (length > self._len) { - return 0; - } - - for (uint i = 1; i < length; i++) { - divisor = divisor / 256; - b = (word / divisor) & 0xFF; - if (b & 0xC0 != 0x80) { - return 0; - } - ret = (ret * 64) | (b & 0x3F); - } - - return ret; - } - - function keccak(slice memory self) internal pure returns (bytes32 ret) { - assembly { - ret := keccak256(mload(add(self,32)),mload(self)) - } - } - - function startsWith( - slice memory self, - slice memory needle - ) internal pure returns (bool) { - if (self._len < needle._len) { - return false; - } - - if (self._ptr == needle._ptr) { - return true; - } - - bool equal; - assembly { - let length := mload(needle) - let selfptr := mload(add(self,0x20)) - let needleptr := mload(add(needle,0x20)) - equal := eq(keccak256(selfptr,length),keccak256(needleptr,length)) - } - return equal; - } - - function beyond( - slice memory self, - slice memory needle - ) internal pure returns (slice memory) { - if (self._len < needle._len) { - return self; - } - - bool equal = true; - if (self._ptr != needle._ptr) { - assembly { - let length := mload(needle) - let selfptr := mload(add(self,0x20)) - let needleptr := mload(add(needle,0x20)) - equal := eq(keccak256(selfptr,length),keccak256(needleptr,length)) - } - } - - if (equal) { - self._len -= needle._len; - self._ptr += needle._len; - } - - return self; - } - - function endsWith( - slice memory self, - slice memory needle - ) internal pure returns (bool) { - if (self._len < needle._len) { - return false; - } - - uint selfptr = self._ptr + self._len - needle._len; - - if (selfptr == needle._ptr) { - return true; - } - - bool equal; - assembly { - let length := mload(needle) - let needleptr := mload(add(needle,0x20)) - equal := eq(keccak256(selfptr,length),keccak256(needleptr,length)) - } - - return equal; - } - - function until( - slice memory self, - slice memory needle - ) internal pure returns (slice memory) { - if (self._len < needle._len) { - return self; - } - - uint selfptr = self._ptr + self._len - needle._len; - bool equal = true; - if (selfptr != needle._ptr) { - assembly { - let length := mload(needle) - let needleptr := mload(add(needle,0x20)) - equal := eq(keccak256(selfptr,length),keccak256(needleptr,length)) - } - } - - if (equal) { - self._len -= needle._len; - } - - return self; - } - - function findPtr( - uint selflen, - uint selfptr, - uint needlelen, - uint needleptr - ) private pure returns (uint) { - uint ptr = selfptr; - uint idx; - - if (needlelen <= selflen) { - if (needlelen <= 32) { - bytes32 mask = bytes32(~(2 ** (8 * (32 - needlelen)) - 1)); - - bytes32 needledata; - assembly { - needledata := and(mload(needleptr),mask) - } - - uint end = selfptr + selflen - needlelen; - bytes32 ptrdata; - assembly { - ptrdata := and(mload(ptr),mask) - } - - while(ptrdata != needledata){ - if (ptr >= end) return selfptr + selflen; - ptr++; - assembly { - ptrdata := and(mload(ptr),mask) - } - } - return ptr; - } else { - bytes32 hash; - assembly { - hash := keccak256(needleptr,needlelen) - } - - for (idx = 0; idx <= selflen - needlelen; idx++) { - bytes32 testHash; - assembly { - testHash := keccak256(ptr,needlelen) - } - if (hash == testHash) return ptr; - ptr += 1; - } - } - } - return selfptr + selflen; - } - - function rfindPtr( - uint selflen, - uint selfptr, - uint needlelen, - uint needleptr - ) private pure returns (uint) { - uint ptr; - - if (needlelen <= selflen) { - if (needlelen <= 32) { - bytes32 mask = bytes32(~(2 ** (8 * (32 - needlelen)) - 1)); - - bytes32 needledata; - assembly { - needledata := and(mload(needleptr),mask) - } - - ptr = selfptr + selflen - needlelen; - bytes32 ptrdata; - assembly { - ptrdata := and(mload(ptr),mask) - } - - while(ptrdata != needledata){ - if (ptr <= selfptr) return selfptr; - ptr--; - assembly { - ptrdata := and(mload(ptr),mask) - } - } - return ptr + needlelen; - } else { - bytes32 hash; - assembly { - hash := keccak256(needleptr,needlelen) - } - ptr = selfptr + (selflen - needlelen); - while(ptr >= selfptr){ - bytes32 testHash; - assembly { - testHash := keccak256(ptr,needlelen) - } - if (hash == testHash) return ptr + needlelen; - ptr -= 1; - } - } - } - return selfptr; - } - - function find( - slice memory self, - slice memory needle - ) internal pure returns (slice memory) { - uint ptr = findPtr(self._len, self._ptr, needle._len, needle._ptr); - self._len -= ptr - self._ptr; - self._ptr = ptr; - return self; - } - - function rfind( - slice memory self, - slice memory needle - ) internal pure returns (slice memory) { - uint ptr = rfindPtr(self._len, self._ptr, needle._len, needle._ptr); - self._len = ptr - self._ptr; - return self; - } - - function split( - slice memory self, - slice memory needle, - slice memory token - ) internal pure returns (slice memory) { - uint ptr = findPtr(self._len, self._ptr, needle._len, needle._ptr); - token._ptr = self._ptr; - token._len = ptr - self._ptr; - if (ptr == self._ptr + self._len) { - self._len = 0; - } else { - self._len -= token._len + needle._len; - self._ptr = ptr + needle._len; - } - return token; - } - - function split( - slice memory self, - slice memory needle - ) internal pure returns (slice memory token) { - split(self, needle, token); - } - - function rsplit( - slice memory self, - slice memory needle, - slice memory token - ) internal pure returns (slice memory) { - uint ptr = rfindPtr(self._len, self._ptr, needle._len, needle._ptr); - token._ptr = ptr; - token._len = self._len - (ptr - self._ptr); - if (ptr == self._ptr) { - self._len = 0; - } else { - self._len -= token._len + needle._len; - } - return token; - } - - function rsplit( - slice memory self, - slice memory needle - ) internal pure returns (slice memory token) { - rsplit(self, needle, token); - } - - function count( - slice memory self, - slice memory needle - ) internal pure returns (uint cnt) { - uint ptr = findPtr(self._len, self._ptr, needle._len, needle._ptr) + - needle._len; - while(ptr <= self._ptr + self._len){ - cnt++; - ptr = - findPtr( - self._len - (ptr - self._ptr), - ptr, - needle._len, - needle._ptr - ) + - needle._len; - } - } - - function contains( - slice memory self, - slice memory needle - ) internal pure returns (bool) { - return rfindPtr(self._len, self._ptr, needle._len, needle._ptr) != - self._ptr; - } - - function concat( - slice memory self, - slice memory other - ) internal pure returns (string memory) { - string memory ret = new string(self._len + other._len); - uint retptr; - assembly { - retptr := add(ret,32) - } - memcpy(retptr, self._ptr, self._len); - memcpy(retptr + self._len, other._ptr, other._len); - return ret; - } - - function join( - slice memory self, - slice[] memory parts - ) internal pure returns (string memory) { - if (parts.length == 0) return ""; - - uint length = self._len * (parts.length - 1); - for (uint i = 0; i < parts.length; i++) { - length += parts[i]._len; - } - - string memory ret = new string(length); - uint retptr; - assembly { - retptr := add(ret,32) - } - - for (i = 0; i < parts.length; i++) { - memcpy(retptr, parts[i]._ptr, parts[i]._len); - retptr += parts[i]._len; - if (i < parts.length - 1) { - memcpy(retptr, self._ptr, self._len); - retptr += self._len; - } - } - - return ret; - } -} - -================================================================================ -`; diff --git a/tests/format/strings/jsfmt.spec.js b/tests/format/strings/jsfmt.spec.js index 2bfbc1a00..765dd60a6 100644 --- a/tests/format/strings/jsfmt.spec.js +++ b/tests/format/strings/jsfmt.spec.js @@ -1,2 +1 @@ run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['slang']); From 7e2e8b329ba987074324f3695fee2027943c4265 Mon Sep 17 00:00:00 2001 From: Klaus Date: Tue, 2 Jul 2024 13:30:54 +1200 Subject: [PATCH 039/160] Printing Comments --- src/common/slang-helpers.js | 43 +++++++++- src/index.js | 10 +-- src/slang-comments/handler.js | 80 +++++++++++++++++ .../handlers/handleWhileComments.js | 34 ++++++++ src/slang-comments/handlers/index.js | 3 + src/slang-comments/index.js | 2 + .../printer.js} | 2 +- src/slang-nodes/YulArguments.js | 9 +- src/slang-nodes/YulStatements.js | 11 ++- src/slangParser.js | 85 ++++++++++--------- 10 files changed, 221 insertions(+), 58 deletions(-) create mode 100644 src/slang-comments/handler.js create mode 100644 src/slang-comments/handlers/handleWhileComments.js create mode 100644 src/slang-comments/handlers/index.js create mode 100644 src/slang-comments/index.js rename src/{slangCommentPrinter.js => slang-comments/printer.js} (94%) diff --git a/src/common/slang-helpers.js b/src/common/slang-helpers.js index bf9c07e8b..e772eacb7 100644 --- a/src/common/slang-helpers.js +++ b/src/common/slang-helpers.js @@ -1,7 +1,11 @@ import { doc } from 'prettier'; -import { isLast, isNextLineEmpty } from './backward-compatibility.js'; +import { + isLast, + isNextLineEmpty, + isPrettier2 +} from './backward-compatibility.js'; -const { dedent, group, hardline, indent, line } = doc.builders; +const { dedent, group, hardline, indent, join, line } = doc.builders; export function createKindCheckFunction(kindsArray) { const kinds = new Set(kindsArray); @@ -38,7 +42,7 @@ export function printPreservingEmptyLines(path, key, options, print) { !isLast(childPath, key, index) && // Append an empty line if the original text already had an one after the // current `node` - isNextLineEmpty(options.originalText, options.locEnd(node)) + isNextLineEmpty(options.originalText, options.locEnd(node) - 1) ? hardline : '' ]; @@ -213,3 +217,36 @@ export function createHugFunction(huggableOperators) { return node; }; } + +export const locStart = (node) => node.loc.start; +export const locEnd = (node) => node.loc.end; + +export const printComments = (node, path, options) => { + if (!node.comments) return []; + const document = join( + line, + path + .map((commentPath) => { + const comment = commentPath.getValue(); + + if (comment.printed) { + return null; + } + comment.printed = true; + // TODO: prettier Prints leading and trailing comments anyway. + comment.leading = false; + comment.trailing = false; + return options.printer.printComment(commentPath, options); + }, 'comments') + .filter(Boolean) + ); + + // The following if statement 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 */ + return isPrettier2 + ? document.parts // Prettier V2 + : document; // Prettier V3 + /* c8 ignore stop */ +}; diff --git a/src/index.js b/src/index.js index cc408a008..8f1b0241e 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,5 @@ import * as comments from './comments/index.js'; +import * as slangComments from './slang-comments/index.js'; import massageAstNode from './clean.js'; import loc from './loc.js'; import options from './options.js'; @@ -7,7 +8,6 @@ import print from './printer.js'; import slangParse from './slangParser.js'; import slangPrint from './slangPrinter.js'; import { isComment, isBlockComment } from './common/slang-helpers.js'; -import { printComment } from './slangCommentPrinter.js'; const parserName = 'slang'; const astFormat = 'slang-ast'; @@ -63,14 +63,14 @@ const printers = { [astFormat]: { canAttachComment: slangCanAttachComment, handleComments: { - ownLine: comments.solidityHandleOwnLineComment, - endOfLine: comments.solidityHandleEndOfLineComment, - remaining: comments.solidityHandleRemainingComment + ownLine: slangComments.slangHandleOwnLineComment, + endOfLine: slangComments.slangHandleEndOfLineComment, + remaining: slangComments.slangHandleRemainingComment }, isBlockComment, massageAstNode, print: slangPrint, - printComment + printComment: slangComments.printComment } }; diff --git a/src/slang-comments/handler.js b/src/slang-comments/handler.js new file mode 100644 index 000000000..bc095d4ed --- /dev/null +++ b/src/slang-comments/handler.js @@ -0,0 +1,80 @@ +import handlers from './handlers/index.js'; + +export function slangHandleOwnLineComment( + comment, + text, + options, + ast, + isLastComment +) { + const { precedingNode, enclosingNode, followingNode } = comment; + const handlerArguments = { + text, + precedingNode, + enclosingNode, + followingNode, + comment, + ast, + isLastComment + }; + + return handlers.some((handler) => handler(handlerArguments)); +} + +export function slangHandleEndOfLineComment( + comment, + text, + options, + ast, + isLastComment +) { + const { precedingNode, enclosingNode, followingNode } = comment; + const handlerArguments = { + text, + precedingNode, + enclosingNode, + followingNode, + comment, + ast, + isLastComment + }; + + return handlers.some((handler) => handler(handlerArguments)); +} + +export function slangHandleRemainingComment( + comment, + text, + options, + ast, + isLastComment +) { + const { precedingNode, enclosingNode, followingNode } = comment; + const handlerArguments = { + text, + precedingNode, + enclosingNode, + followingNode, + comment, + ast, + isLastComment + }; + + return handlers.some((handler) => handler(handlerArguments)); +} + +export function isBlockComment(comment) { + return comment.type === 'BlockComment'; +} + +function isNodeOrComment(node) { + return node.type !== undefined; +} + +export function canAttachComment(node) { + return ( + isNodeOrComment(node) && + !isBlockComment(node) && + node.type !== 'LineComment' + ); +} diff --git a/src/slang-comments/handlers/handleWhileComments.js b/src/slang-comments/handlers/handleWhileComments.js new file mode 100644 index 000000000..ddba0501f --- /dev/null +++ b/src/slang-comments/handlers/handleWhileComments.js @@ -0,0 +1,34 @@ +import { util } from 'prettier'; +import { getNextNonSpaceNonCommentCharacter } from '../../common/backward-compatibility.js'; +import { locEnd } from '../../common/slang-helpers.js'; + +const { addTrailingComment } = util; + +export default function handleWhileComments({ + text, + precedingNode, + enclosingNode, + followingNode, + comment +}) { + if (enclosingNode?.kind !== 'WhileStatement' || !followingNode) { + return false; + } + + // We unfortunately have no way using the AST or location of nodes to know + // if the comment is positioned before the condition parenthesis: + // while (a /* comment */) {} + // The only workaround I found is to look at the next character to see if + // it is a ). + const nextCharacter = getNextNonSpaceNonCommentCharacter( + text, + comment, + locEnd + ); + if (nextCharacter === ')' || enclosingNode.condition === precedingNode) { + addTrailingComment(precedingNode, comment); + return true; + } + + return false; +} diff --git a/src/slang-comments/handlers/index.js b/src/slang-comments/handlers/index.js new file mode 100644 index 000000000..52c967ce5 --- /dev/null +++ b/src/slang-comments/handlers/index.js @@ -0,0 +1,3 @@ +import handleWhileComments from './handleWhileComments.js'; + +export default [handleWhileComments]; diff --git a/src/slang-comments/index.js b/src/slang-comments/index.js new file mode 100644 index 000000000..22efb5a89 --- /dev/null +++ b/src/slang-comments/index.js @@ -0,0 +1,2 @@ +export * from './handler.js'; +export * from './printer.js'; diff --git a/src/slangCommentPrinter.js b/src/slang-comments/printer.js similarity index 94% rename from src/slangCommentPrinter.js rename to src/slang-comments/printer.js index 066546af3..6e9c274d9 100644 --- a/src/slangCommentPrinter.js +++ b/src/slang-comments/printer.js @@ -1,5 +1,5 @@ import { doc } from 'prettier'; -import { isBlockComment, isLineComment } from './common/slang-helpers.js'; +import { isBlockComment, isLineComment } from '../common/slang-helpers.js'; const { hardline, join, literalline } = doc.builders; diff --git a/src/slang-nodes/YulArguments.js b/src/slang-nodes/YulArguments.js index 8eedba833..fb0b29d98 100644 --- a/src/slang-nodes/YulArguments.js +++ b/src/slang-nodes/YulArguments.js @@ -1,12 +1,9 @@ +import { printSeparatedList } from '../common/printer-helpers.js'; + export const YulArguments = { parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), - print: ({ node, path, print }) => - path - .map(print, 'items') - .map((item, index) => - index === 0 ? item : [node.separators[index - 1], item] - ) + print: ({ path, print }) => printSeparatedList(path.map(print, 'items')) }; diff --git a/src/slang-nodes/YulStatements.js b/src/slang-nodes/YulStatements.js index 462cbb354..3b58fc731 100644 --- a/src/slang-nodes/YulStatements.js +++ b/src/slang-nodes/YulStatements.js @@ -1,9 +1,14 @@ -import { printPreservingEmptyLines } from '../common/slang-helpers.js'; +import { + printComments, + printPreservingEmptyLines +} from '../common/slang-helpers.js'; export const YulStatements = { parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)) }), - print: ({ path, print, options }) => - printPreservingEmptyLines(path, 'items', options, print) + print: ({ node, path, print, options }) => + node.items.length > 0 + ? printPreservingEmptyLines(path, 'items', options, print) + : printComments(node, path, options) }; diff --git a/src/slangParser.js b/src/slangParser.js index 18a245814..e600efef7 100644 --- a/src/slangParser.js +++ b/src/slangParser.js @@ -8,58 +8,63 @@ import * as parsers from './slang-nodes/index.js'; import { isComment } from './common/slang-helpers.js'; const comments = []; -const getOffsets = (ast, initialOffset) => { +const getOffsets = (children, initialOffset) => { let offset = initialOffset; - let isLeadingTrivia = true; - let currentOffset = offset; - const offsets = ast.cst.children().reduce((offsetsArray, child) => { + const offsets = children.reduce((offsetsArray, child) => { if (child.type === 'Nonterminal') { - // The node's content starts when we find the first non-terminal, - // non-comment, non-whitespace token. - if (isLeadingTrivia) { - isLeadingTrivia = false; - currentOffset = offset; - } - offsetsArray.push(offset); } - if (child.type === 'Terminal') { - if (isComment(child)) { - // TODO: avoid collecting comments as a side effect of the functionality - // for retrieving offsets - comments.push({ - kind: child.kind, - value: child.text, - loc: { - start: offset, - end: offset + child.textLength.utf8 - } - }); - } - if ( - !isComment(child) && - child.kind !== 'EndOfLine' && - child.kind !== 'Whitespace' - ) { - // The content of the node started if we find a non-comment, - // non-whitespace token. - if (isLeadingTrivia) { - isLeadingTrivia = false; - currentOffset = offset; + if (child.type === 'Terminal' && isComment(child)) { + // TODO: avoid collecting comments as a side effect of the functionality + // for retrieving offsets + comments.push({ + kind: child.kind, + value: child.text, + loc: { + start: offset, + end: offset + child.textLength.utf8 } - } + }); } offset += child.textLength.utf8; return offsetsArray; }, []); - return { currentOffset, offsets }; + return offsets; +}; + +const getLeadingOffset = (children) => { + let offset = 0; + for (let i = 0; i < children.length; i += 1) { + const child = children[i]; + if (child.type === 'Nonterminal') { + // The node's content starts when we find the first non-terminal, + // non-comment, non-whitespace token. + return offset; + } + if ( + child.type === 'Terminal' && + !isComment(child) && + child.kind !== 'EndOfLine' && + child.kind !== 'Whitespace' + ) { + // The content of the node started if we find a non-comment, + // non-whitespace token. + return offset; + } + offset += child.textLength.utf8; + } + return offset; }; +const getTrailingOffset = (children) => getLeadingOffset(children.reverse()); function genericParse(ast, options, parseFunction, parentOffsets = [0]) { - const initialOffset = parentOffsets.shift(); - const { currentOffset, offsets } = getOffsets(ast, initialOffset); + const offset = parentOffsets.shift(); + const children = ast.cst.children(); + const offsets = getOffsets(children, offset); + const leadingOffset = getLeadingOffset(children); + const trailingOffset = getTrailingOffset(children); const node = parsers[ast.cst.kind].parse({ offsets, @@ -71,8 +76,8 @@ function genericParse(ast, options, parseFunction, parentOffsets = [0]) { node.kind = ast.cst.kind; node.loc = { // We ignore the leading trivia and assume the node starts after it - start: currentOffset, - end: initialOffset + ast.cst.textLength.utf8 + start: offset + leadingOffset, + end: offset + ast.cst.textLength.utf8 - trailingOffset }; if (node.kind === 'SourceUnit') { From 8756b139a1d3e497eb453ee393e6d1ed5a4fd000 Mon Sep 17 00:00:00 2001 From: Klaus Date: Tue, 2 Jul 2024 14:06:18 +1200 Subject: [PATCH 040/160] first batch of tests passing and tweaks on indentation on WhileStatements and Binary Statements --- src/common/slang-helpers.js | 14 +-- src/slang-nodes/ReturnStatement.js | 19 ++- src/slang-nodes/TupleValues.js | 7 +- src/slang-nodes/WhileStatement.js | 17 ++- tests/config/format-test.js | 45 ++++++- tests/format/Assembly/Assembly.sol | 54 --------- .../Assembly/__snapshots__/jsfmt.spec.js.snap | 110 ------------------ tests/format/AssemblyV0.4.26/Assembly.sol | 21 ++++ .../__snapshots__/jsfmt.spec.js.snap | 42 +++++++ .../__snapshots__/jsfmt.spec.js.snap | 3 +- tests/format/BasicIterator/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 8 +- tests/format/BinaryOperators/jsfmt.spec.js | 2 +- 13 files changed, 159 insertions(+), 185 deletions(-) diff --git a/src/common/slang-helpers.js b/src/common/slang-helpers.js index e772eacb7..f138a86fd 100644 --- a/src/common/slang-helpers.js +++ b/src/common/slang-helpers.js @@ -97,7 +97,8 @@ const binaryIndentRulesBuilder = (path) => (document) => { if (grandparentNode.kind === 'ReturnStatement') break; if ( !isBinaryOperation(grandparentNode) || - grandparentNode.kind === 'ComparisonExpression' + grandparentNode.kind === 'ComparisonExpression' || + grandparentNode.kind === 'EqualityExpression' ) { return indent(document); } @@ -108,17 +109,16 @@ const binaryIndentRulesBuilder = (path) => (document) => { }; const isStatementWithComparisonOperationWithoutIndentation = - createKindCheckFunction([ - 'ReturnStatement', - 'IfStatement', - 'ForStatement', - 'WhileStatement' - ]); + createKindCheckFunction(['ReturnStatement', 'IfStatement', 'WhileStatement']); const comparisonIndentRulesBuilder = (path) => (document) => { let node = path.getNode(); for (let i = 2; ; i += 2) { const grandparentNode = path.getNode(i); + if (grandparentNode.kind === 'ExpressionStatement') { + if (path.getNode(i + 1).kind === 'ForStatementCondition') break; + else return indent(document); + } if (isStatementWithComparisonOperationWithoutIndentation(grandparentNode)) break; if (!isBinaryOperation(grandparentNode)) return indent(document); diff --git a/src/slang-nodes/ReturnStatement.js b/src/slang-nodes/ReturnStatement.js index d1d4930dc..03f56814b 100644 --- a/src/slang-nodes/ReturnStatement.js +++ b/src/slang-nodes/ReturnStatement.js @@ -1,3 +1,18 @@ +import { doc } from 'prettier'; + +const { group, indent, line } = doc.builders; + +const expression = (node, path, print, options) => { + if (node.expression) { + return node.expression.variant.kind === 'TupleExpression' || + (options.experimentalTernaries && + node.expression.type === 'ConditionalExpression') + ? [' ', path.call(print, 'expression')] + : group(indent([line, path.call(print, 'expression')])); + } + return ''; +}; + export const ReturnStatement = { parse: ({ offsets, ast, options, parse }) => ({ returnKeyword: ast.returnKeyword.text, @@ -6,9 +21,9 @@ export const ReturnStatement = { : undefined, semicolon: ast.semicolon.text }), - print: ({ node, path, print }) => [ + print: ({ node, path, print, options }) => [ node.returnKeyword, - node.expression ? [' ', path.call(print, 'expression')] : '', + expression(node, path, print, options), node.semicolon ] }; diff --git a/src/slang-nodes/TupleValues.js b/src/slang-nodes/TupleValues.js index db23d2fbc..2445093c6 100644 --- a/src/slang-nodes/TupleValues.js +++ b/src/slang-nodes/TupleValues.js @@ -1,9 +1,14 @@ import { printSeparatedList } from '../common/printer-helpers.js'; +import { isBinaryOperation } from '../common/slang-helpers.js'; export const TupleValues = { parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), - print: ({ path, print }) => printSeparatedList(path.map(print, 'items')) + print: ({ node, path, print }) => + node.items.length === 1 && + isBinaryOperation(node.items[0].expression.variant) + ? path.map(print, 'items') + : printSeparatedList(path.map(print, 'items')) }; diff --git a/src/slang-nodes/WhileStatement.js b/src/slang-nodes/WhileStatement.js index a1cd49420..ad8c1e6ef 100644 --- a/src/slang-nodes/WhileStatement.js +++ b/src/slang-nodes/WhileStatement.js @@ -1,3 +1,13 @@ +import { doc } from 'prettier'; +import { printSeparatedItem } from '../common/printer-helpers.js'; + +const { group, indent, line } = doc.builders; + +const body = (node, path, print) => + node.body.variant.kind === 'Block' + ? [' ', path.call(print, 'body')] + : group(indent([line, path.call(print, 'body')])); + export const WhileStatement = { parse: ({ offsets, ast, options, parse }) => ({ whileKeyword: ast.whileKeyword.text, @@ -7,10 +17,9 @@ export const WhileStatement = { body: parse(ast.body, options, parse, offsets) }), print: ({ node, path, print }) => [ - node.whileKeyword, - node.openParen, - path.call(print, 'condition'), + `${node.whileKeyword} ${node.openParen}`, + printSeparatedItem(path.call(print, 'condition')), node.closeParen, - path.call(print, 'body') + body(node, path, print) ] }; diff --git a/tests/config/format-test.js b/tests/config/format-test.js index 5cd254548..d018227c2 100644 --- a/tests/config/format-test.js +++ b/tests/config/format-test.js @@ -38,6 +38,23 @@ const unstableAstTests = new Map( }) ); +const testsWithSlang = new Map( + [ + "AddressPayable/AddressPayable.sol", + "Arrays/Arrays.sol", + "Assembly/Assembly.sol", + // "AssemblyV0.4.26/Assembly.sol", + "BasicIterator/BasicIterator.sol", + "BinaryOperators/BinaryOperators.sol", + "BinaryOperators/Parentheses.sol", + ].map((fixture) => { + const [file, testSlang = () => true] = Array.isArray(fixture) + ? fixture + : [fixture]; + return [path.join(__dirname, "../format/", file), testSlang]; + }) +); + const testsWithAstChanges = new Map( [ "Parentheses/AddNoParentheses.sol", @@ -82,8 +99,17 @@ const isAstUnstable = (filename, options) => { return testFunction(options); }; +const shouldTestSlang = (filename, options) => { + const testFunction = testsWithSlang.get(filename); + + if (!testFunction) { + return false; + } + + return testFunction(options); +}; + const shouldCompareBytecode = (filename, options) => { - if (options.parser === "slang") return false; const testFunction = testsWithAstChanges.get(filename); if (!testFunction) { @@ -351,6 +377,23 @@ async function runTest({ expect(output).toEqual(expected); } + if (shouldTestSlang(filename, formatOptions)) { + const { input, output } = formatResult; + const prettier = await getPrettier(); + const slangOutput = await prettier.format(input, { + ...formatOptions, + parser: "slang", + }); + + // const slangOutput2 = await prettier.format(output, { + // ...formatOptions, + // parser: "slang", + // }); + + expect(slangOutput).toEqual(output); + // expect(slangOutput2).toEqual(output); + } + if (shouldCompareBytecode(filename, formatOptions)) { const output = compileContract(filename, formatResult.output); const expected = compileContract(filename, formatResult.input); diff --git a/tests/format/Assembly/Assembly.sol b/tests/format/Assembly/Assembly.sol index 7917b8281..91c77e8e0 100644 --- a/tests/format/Assembly/Assembly.sol +++ b/tests/format/Assembly/Assembly.sol @@ -107,39 +107,6 @@ for { let i := 0 } lt(i, x) { i := add(i, 1) } { y := mul(2, y) } } } - function assemblyLabels() { - assembly { - let n := calldataload(4) - let a := 1 - let b := a -loop: - jumpi(loopend, eq(n, 0)) - a add swap1 - n := sub(n, 1) - jump(loop) - -loopend: - mstore(0, a) - return(0, 0x20) -} - -assembly{ - let x := 8 - jump(two) - one: - // Here the stack height is 2 (because we pushed x and 7), - // but the assembler thinks it is 1 because it reads - // from top to bottom. - // Accessing the stack variable x here will lead to errors. - x := 9 - jump(three) - two: - 7 // push something onto the stack - jump(one) - three: -} -} - function assemblyFunctionNoReturn () { assembly { @@ -211,24 +178,3 @@ contract BooleanLiteralsInAssembly { } } } - -contract MultipleAssemblyAssignement { - function foo() public pure { - assembly { - function bar() -> a, b { - a := 1 - b := 2 - } - - let i, j := bar() - } - } -} - -contract AssemblyStackAssignment { - function f() public { - assembly { - 4 =: y - } - } -} diff --git a/tests/format/Assembly/__snapshots__/jsfmt.spec.js.snap b/tests/format/Assembly/__snapshots__/jsfmt.spec.js.snap index ed490afe9..ff775725d 100644 --- a/tests/format/Assembly/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Assembly/__snapshots__/jsfmt.spec.js.snap @@ -115,39 +115,6 @@ for { let i := 0 } lt(i, x) { i := add(i, 1) } { y := mul(2, y) } } } - function assemblyLabels() { - assembly { - let n := calldataload(4) - let a := 1 - let b := a -loop: - jumpi(loopend, eq(n, 0)) - a add swap1 - n := sub(n, 1) - jump(loop) - -loopend: - mstore(0, a) - return(0, 0x20) -} - -assembly{ - let x := 8 - jump(two) - one: - // Here the stack height is 2 (because we pushed x and 7), - // but the assembler thinks it is 1 because it reads - // from top to bottom. - // Accessing the stack variable x here will lead to errors. - x := 9 - jump(three) - two: - 7 // push something onto the stack - jump(one) - three: -} -} - function assemblyFunctionNoReturn () { assembly { @@ -220,27 +187,6 @@ contract BooleanLiteralsInAssembly { } } -contract MultipleAssemblyAssignement { - function foo() public pure { - assembly { - function bar() -> a, b { - a := 1 - b := 2 - } - - let i, j := bar() - } - } -} - -contract AssemblyStackAssignment { - function f() public { - assembly { - 4 =: y - } - } -} - =====================================output===================================== contract Assembly { function ifAssembly() { @@ -380,41 +326,6 @@ contract Assembly { } } - function assemblyLabels() { - assembly { - let n := calldataload(4) - let a := 1 - let b := a - loop: - jumpi(loopend, eq(n, 0)) - a - add - swap1 - n := sub(n, 1) - jump(loop) - - loopend: - mstore(0, a) - return(0, 0x20) - } - - assembly { - let x := 8 - jump(two) - one: - // Here the stack height is 2 (because we pushed x and 7), - // but the assembler thinks it is 1 because it reads - // from top to bottom. - // Accessing the stack variable x here will lead to errors. - x := 9 - jump(three) - two: - 7 // push something onto the stack - jump(one) - three: - } - } - function assemblyFunctionNoReturn() { assembly { function $somefn(somearg) { @@ -495,26 +406,5 @@ contract BooleanLiteralsInAssembly { } } -contract MultipleAssemblyAssignement { - function foo() public pure { - assembly { - function bar() -> a, b { - a := 1 - b := 2 - } - - let i, j := bar() - } - } -} - -contract AssemblyStackAssignment { - function f() public { - assembly { - 4 =: y - } - } -} - ================================================================================ `; diff --git a/tests/format/AssemblyV0.4.26/Assembly.sol b/tests/format/AssemblyV0.4.26/Assembly.sol index 536bcb652..cbe6b873e 100644 --- a/tests/format/AssemblyV0.4.26/Assembly.sol +++ b/tests/format/AssemblyV0.4.26/Assembly.sol @@ -34,3 +34,24 @@ assembly{ } } } + +contract MultipleAssemblyAssignement { + function foo() public pure { + assembly { + function bar() -> a, b { + a := 1 + b := 2 + } + + let i, j := bar() + } + } +} + +contract AssemblyStackAssignment { + function f() public { + assembly { + 4 =: y + } + } +} diff --git a/tests/format/AssemblyV0.4.26/__snapshots__/jsfmt.spec.js.snap b/tests/format/AssemblyV0.4.26/__snapshots__/jsfmt.spec.js.snap index 43771df49..35ca25460 100644 --- a/tests/format/AssemblyV0.4.26/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/AssemblyV0.4.26/__snapshots__/jsfmt.spec.js.snap @@ -44,6 +44,27 @@ assembly{ } } +contract MultipleAssemblyAssignement { + function foo() public pure { + assembly { + function bar() -> a, b { + a := 1 + b := 2 + } + + let i, j := bar() + } + } +} + +contract AssemblyStackAssignment { + function f() public { + assembly { + 4 =: y + } + } +} + =====================================output===================================== pragma solidity ^0.4.26; @@ -84,5 +105,26 @@ contract Assembly { } } +contract MultipleAssemblyAssignement { + function foo() public pure { + assembly { + function bar() -> a, b { + a := 1 + b := 2 + } + + let i, j := bar() + } + } +} + +contract AssemblyStackAssignment { + function f() public { + assembly { + 4 =: y + } + } +} + ================================================================================ `; diff --git a/tests/format/BasicIterator/__snapshots__/jsfmt.spec.js.snap b/tests/format/BasicIterator/__snapshots__/jsfmt.spec.js.snap index 8b650d09a..091266f11 100644 --- a/tests/format/BasicIterator/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/BasicIterator/__snapshots__/jsfmt.spec.js.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`BasicIterator.sol format 1`] = ` +exports[`BasicIterator.sol - {"compiler":"0.4.26"} format 1`] = ` ====================================options===================================== +compiler: "0.4.26" parsers: ["solidity-parse"] printWidth: 80 | printWidth diff --git a/tests/format/BasicIterator/jsfmt.spec.js b/tests/format/BasicIterator/jsfmt.spec.js index 765dd60a6..fb953582e 100644 --- a/tests/format/BasicIterator/jsfmt.spec.js +++ b/tests/format/BasicIterator/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse'], { compiler: '0.4.26' }); diff --git a/tests/format/BinaryOperators/__snapshots__/jsfmt.spec.js.snap b/tests/format/BinaryOperators/__snapshots__/jsfmt.spec.js.snap index fd5d8bb50..f3c990af5 100644 --- a/tests/format/BinaryOperators/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/BinaryOperators/__snapshots__/jsfmt.spec.js.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`BinaryOperators.sol format 1`] = ` +exports[`BinaryOperators.sol - {"compiler":"0.5.8"} format 1`] = ` ====================================options===================================== +compiler: "0.5.8" parsers: ["solidity-parse"] printWidth: 80 | printWidth @@ -685,8 +686,9 @@ contract LogicalOperators { ================================================================================ `; -exports[`Parentheses.sol format 1`] = ` +exports[`Parentheses.sol - {"compiler":"0.5.8"} format 1`] = ` ====================================options===================================== +compiler: "0.5.8" parsers: ["solidity-parse"] printWidth: 80 | printWidth @@ -889,7 +891,7 @@ contract Parentheses { a ** b * c; a ** b / c; a ** b % c; - a ** b ** c; + (a ** b) ** c; (a ** b) << c; (a ** b) >> c; (a ** b) & c; diff --git a/tests/format/BinaryOperators/jsfmt.spec.js b/tests/format/BinaryOperators/jsfmt.spec.js index 765dd60a6..946858815 100644 --- a/tests/format/BinaryOperators/jsfmt.spec.js +++ b/tests/format/BinaryOperators/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse'], { compiler: '0.5.8' }); From 0ebbc4753d3b20aeaa4f2a9e542681b53a42eead Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 3 Jul 2024 00:45:35 +1200 Subject: [PATCH 041/160] fixed bug with comments --- src/slangParser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/slangParser.js b/src/slangParser.js index e600efef7..038893310 100644 --- a/src/slangParser.js +++ b/src/slangParser.js @@ -81,7 +81,7 @@ function genericParse(ast, options, parseFunction, parentOffsets = [0]) { }; if (node.kind === 'SourceUnit') { - node.comments = comments; + node.comments = comments.splice(0); } return node; From b472bdc3411fb2b4456a59519168338113ea00db Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 3 Jul 2024 15:19:35 +1200 Subject: [PATCH 042/160] handling YulBlock comments --- src/common/slang-helpers.js | 8 ++++--- .../handlers/handleYulBlockComments.js | 23 +++++++++++++++++++ src/slang-comments/handlers/index.js | 3 ++- src/slang-nodes/Parameter.js | 15 ++++++++---- src/slang-nodes/ReturnsDeclaration.js | 6 ++++- 5 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 src/slang-comments/handlers/handleYulBlockComments.js diff --git a/src/common/slang-helpers.js b/src/common/slang-helpers.js index f138a86fd..160b491d8 100644 --- a/src/common/slang-helpers.js +++ b/src/common/slang-helpers.js @@ -221,15 +221,17 @@ export function createHugFunction(huggableOperators) { export const locStart = (node) => node.loc.start; export const locEnd = (node) => node.loc.end; -export const printComments = (node, path, options) => { +export const printComments = (node, path, options, filter = () => true) => { if (!node.comments) return []; const document = join( line, path .map((commentPath) => { const comment = commentPath.getValue(); - - if (comment.printed) { + if (comment.trailing || comment.leading || comment.printed) { + return null; + } + if (!filter(comment)) { return null; } comment.printed = true; diff --git a/src/slang-comments/handlers/handleYulBlockComments.js b/src/slang-comments/handlers/handleYulBlockComments.js new file mode 100644 index 000000000..24b97e160 --- /dev/null +++ b/src/slang-comments/handlers/handleYulBlockComments.js @@ -0,0 +1,23 @@ +import { util } from 'prettier'; + +const { addDanglingComment } = util; + +export default function handleYulBlockComments({ + precedingNode, + enclosingNode, + comment +}) { + if ( + enclosingNode?.kind !== 'YulBlock' && + precedingNode?.kind !== 'YulStatements' + ) { + return false; + } + + if (precedingNode.items.length === 0) { + addDanglingComment(precedingNode, comment); + return true; + } + + return false; +} diff --git a/src/slang-comments/handlers/index.js b/src/slang-comments/handlers/index.js index 52c967ce5..a69a81eab 100644 --- a/src/slang-comments/handlers/index.js +++ b/src/slang-comments/handlers/index.js @@ -1,3 +1,4 @@ import handleWhileComments from './handleWhileComments.js'; +import handleYulBlockComments from './handleYulBlockComments.js'; -export default [handleWhileComments]; +export default [handleWhileComments, handleYulBlockComments]; diff --git a/src/slang-nodes/Parameter.js b/src/slang-nodes/Parameter.js index 1df3111d9..7c91109c6 100644 --- a/src/slang-nodes/Parameter.js +++ b/src/slang-nodes/Parameter.js @@ -1,3 +1,7 @@ +import { doc } from 'prettier'; + +const { group } = doc.builders; + export const Parameter = { parse: ({ offsets, ast, options, parse }) => ({ typeName: parse(ast.typeName, options, parse, offsets), @@ -6,9 +10,10 @@ export const Parameter = { : undefined, name: ast.name?.text }), - print: ({ node, path, print }) => [ - path.call(print, 'typeName'), - node.storageLocation ? ` ${path.call(print, 'storageLocation')}` : '', - node.name ? ` ${node.name}` : '' - ] + print: ({ node, path, print }) => + group([ + path.call(print, 'typeName'), + node.storageLocation ? ` ${path.call(print, 'storageLocation')}` : '', + node.name ? ` ${node.name}` : '' + ]) }; diff --git a/src/slang-nodes/ReturnsDeclaration.js b/src/slang-nodes/ReturnsDeclaration.js index d922d4e51..1874cd761 100644 --- a/src/slang-nodes/ReturnsDeclaration.js +++ b/src/slang-nodes/ReturnsDeclaration.js @@ -1,3 +1,7 @@ +import { doc } from 'prettier'; + +const { group } = doc.builders; + export const ReturnsDeclaration = { parse: ({ offsets, ast, options, parse }) => ({ returnsKeyword: ast.returnsKeyword.text, @@ -5,6 +9,6 @@ export const ReturnsDeclaration = { }), print: ({ node, path, print }) => [ `${node.returnsKeyword} `, - path.call(print, 'variables') + group(path.call(print, 'variables')) ] }; From 901bea9b2f017af645be03d9124bc0b0a14c50de Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 3 Jul 2024 19:59:29 +1200 Subject: [PATCH 043/160] comments in Block and YulBlock finetunned --- .../handlers/handleBlockComments.js | 29 +++++++++++++++++++ .../handlers/handleYulBlockComments.js | 20 +++++++++---- src/slang-comments/handlers/index.js | 7 ++++- 3 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 src/slang-comments/handlers/handleBlockComments.js diff --git a/src/slang-comments/handlers/handleBlockComments.js b/src/slang-comments/handlers/handleBlockComments.js new file mode 100644 index 000000000..4bad11a95 --- /dev/null +++ b/src/slang-comments/handlers/handleBlockComments.js @@ -0,0 +1,29 @@ +import { util } from 'prettier'; + +const { addDanglingComment, addLeadingComment } = util; + +export default function handleBlockComments({ + precedingNode, + enclosingNode, + followingNode, + comment +}) { + if (enclosingNode?.kind !== 'Block') { + return false; + } + + if ( + precedingNode?.kind === 'Statements' && + precedingNode.items.length === 0 + ) { + addDanglingComment(precedingNode, comment); + return true; + } + + if (followingNode?.kind === 'Statements' && followingNode.items.length > 0) { + addLeadingComment(followingNode.items[0], comment); + return true; + } + + return false; +} diff --git a/src/slang-comments/handlers/handleYulBlockComments.js b/src/slang-comments/handlers/handleYulBlockComments.js index 24b97e160..335fa132f 100644 --- a/src/slang-comments/handlers/handleYulBlockComments.js +++ b/src/slang-comments/handlers/handleYulBlockComments.js @@ -1,23 +1,31 @@ import { util } from 'prettier'; -const { addDanglingComment } = util; +const { addLeadingComment, addDanglingComment } = util; export default function handleYulBlockComments({ precedingNode, enclosingNode, + followingNode, comment }) { - if ( - enclosingNode?.kind !== 'YulBlock' && - precedingNode?.kind !== 'YulStatements' - ) { + if (enclosingNode?.kind !== 'YulBlock') { return false; } - if (precedingNode.items.length === 0) { + if ( + precedingNode?.kind === 'YulStatements' && + precedingNode.items.length === 0 + ) { addDanglingComment(precedingNode, comment); return true; } + if ( + followingNode?.kind === 'YulStatements' && + followingNode.items.length > 0 + ) { + addLeadingComment(followingNode.items[0], comment); + return true; + } return false; } diff --git a/src/slang-comments/handlers/index.js b/src/slang-comments/handlers/index.js index a69a81eab..31013eb4a 100644 --- a/src/slang-comments/handlers/index.js +++ b/src/slang-comments/handlers/index.js @@ -1,4 +1,9 @@ +import handleBlockComments from './handleBlockComments.js'; import handleWhileComments from './handleWhileComments.js'; import handleYulBlockComments from './handleYulBlockComments.js'; -export default [handleWhileComments, handleYulBlockComments]; +export default [ + handleBlockComments, + handleWhileComments, + handleYulBlockComments +]; From 5e94cfd5ec70841561fd90a50e76a3f35d038a0e Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 3 Jul 2024 20:01:18 +1200 Subject: [PATCH 044/160] fixing parentheses on exponentiation before 0.8.0 --- src/slang-nodes/ExponentiationExpression.js | 44 +++++++++++++++++++ tests/config/format-test.js | 5 +++ .../BreakingChangesV0.8.0.sol | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 18 +++----- 4 files changed, 56 insertions(+), 14 deletions(-) diff --git a/src/slang-nodes/ExponentiationExpression.js b/src/slang-nodes/ExponentiationExpression.js index f461aeec2..b2031dbd7 100644 --- a/src/slang-nodes/ExponentiationExpression.js +++ b/src/slang-nodes/ExponentiationExpression.js @@ -20,6 +20,50 @@ export const ExponentiationExpression = { if (satisfies(compiler, '>=0.8.0')) { rightOperand = tryToHug(rightOperand); } else { + // Currently the parser considers exponentiation as having left + // association from 0.6.0. + // in reality solidity fixed this from 0.8.0. + // TODO: remove this once the parser has fixed this. + // https://github.com/NomicFoundation/slang/issues/1031 + if (rightOperand.variant.kind === 'ExponentiationExpression') { + const leftLoc = { + start: leftOperand.loc.start, + end: rightOperand.variant.leftOperand.loc.end + }; + leftOperand = { + kind: 'Expression', + loc: { ...leftLoc }, + variant: { + kind: 'TupleExpression', + loc: { ...leftLoc }, + openParen: '(', + items: { + kind: 'TupleValues', + loc: { ...leftLoc }, + items: [ + { + kind: 'TupleValue', + loc: { ...leftLoc }, + expression: { + kind: 'Expression', + loc: { ...leftLoc }, + variant: { + kind: 'ExponentiationExpression', + loc: { ...leftLoc }, + leftOperand, + operator: '**', + rightOperand: rightOperand.variant.leftOperand + } + } + } + ], + separators: [] + }, + closeParen: ')' + } + }; + rightOperand = rightOperand.variant.rightOperand; + } leftOperand = tryToHug(leftOperand); } } diff --git a/tests/config/format-test.js b/tests/config/format-test.js index d018227c2..355f8c6de 100644 --- a/tests/config/format-test.js +++ b/tests/config/format-test.js @@ -47,6 +47,11 @@ const testsWithSlang = new Map( "BasicIterator/BasicIterator.sol", "BinaryOperators/BinaryOperators.sol", "BinaryOperators/Parentheses.sol", + "BreakingChangesV0.7.4/BreakingChangesV0.7.4.sol", + [ + "BreakingChangesV0.8.0/BreakingChangesV0.8.0.sol", + (options) => options.compiler === "0.7.0", + ], ].map((fixture) => { const [file, testSlang = () => true] = Array.isArray(fixture) ? fixture diff --git a/tests/format/BreakingChangesV0.8.0/BreakingChangesV0.8.0.sol b/tests/format/BreakingChangesV0.8.0/BreakingChangesV0.8.0.sol index e5f6c1fb3..b1424cd4f 100644 --- a/tests/format/BreakingChangesV0.8.0/BreakingChangesV0.8.0.sol +++ b/tests/format/BreakingChangesV0.8.0/BreakingChangesV0.8.0.sol @@ -1,7 +1,6 @@ // SPDX-License-Identifier: MIT -// TODO: uncomment once NomicFoundation addresses Semver notations // https://github.com/NomicFoundation/slang/issues/986 -// pragma solidity >=0.7.0 <=0.8.5; +pragma solidity >=0.7.0 <=0.8.5; contract BreakingChangesV080 { /** diff --git a/tests/format/BreakingChangesV0.8.0/__snapshots__/jsfmt.spec.js.snap b/tests/format/BreakingChangesV0.8.0/__snapshots__/jsfmt.spec.js.snap index 2ad74c457..1c4a0278d 100644 --- a/tests/format/BreakingChangesV0.8.0/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/BreakingChangesV0.8.0/__snapshots__/jsfmt.spec.js.snap @@ -8,9 +8,8 @@ printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -// TODO: uncomment once NomicFoundation addresses Semver notations // https://github.com/NomicFoundation/slang/issues/986 -// pragma solidity >=0.7.0 <=0.8.5; +pragma solidity >=0.7.0 <=0.8.5; contract BreakingChangesV080 { /** @@ -54,9 +53,8 @@ contract BreakingChangesV080 { =====================================output===================================== // SPDX-License-Identifier: MIT -// TODO: uncomment once NomicFoundation addresses Semver notations // https://github.com/NomicFoundation/slang/issues/986 -// pragma solidity >=0.7.0 <=0.8.5; +pragma solidity >=0.7.0 <=0.8.5; contract BreakingChangesV080 { /** @@ -100,9 +98,8 @@ printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -// TODO: uncomment once NomicFoundation addresses Semver notations // https://github.com/NomicFoundation/slang/issues/986 -// pragma solidity >=0.7.0 <=0.8.5; +pragma solidity >=0.7.0 <=0.8.5; contract BreakingChangesV080 { /** @@ -146,9 +143,8 @@ contract BreakingChangesV080 { =====================================output===================================== // SPDX-License-Identifier: MIT -// TODO: uncomment once NomicFoundation addresses Semver notations // https://github.com/NomicFoundation/slang/issues/986 -// pragma solidity >=0.7.0 <=0.8.5; +pragma solidity >=0.7.0 <=0.8.5; contract BreakingChangesV080 { /** @@ -191,9 +187,8 @@ printWidth: 80 | printWidth =====================================input====================================== // SPDX-License-Identifier: MIT -// TODO: uncomment once NomicFoundation addresses Semver notations // https://github.com/NomicFoundation/slang/issues/986 -// pragma solidity >=0.7.0 <=0.8.5; +pragma solidity >=0.7.0 <=0.8.5; contract BreakingChangesV080 { /** @@ -237,9 +232,8 @@ contract BreakingChangesV080 { =====================================output===================================== // SPDX-License-Identifier: MIT -// TODO: uncomment once NomicFoundation addresses Semver notations // https://github.com/NomicFoundation/slang/issues/986 -// pragma solidity >=0.7.0 <=0.8.5; +pragma solidity >=0.7.0 <=0.8.5; contract BreakingChangesV080 { /** From 33be3fdbe34c6a2062f1e37e0ddcf25076e833e0 Mon Sep 17 00:00:00 2001 From: Klaus Date: Thu, 4 Jul 2024 12:25:42 +1200 Subject: [PATCH 045/160] comments in blocks fixed --- src/slang-nodes/Statements.js | 21 +++++++++++++------ src/slang-nodes/YulBlock.js | 10 +-------- src/slang-nodes/YulStatements.js | 19 ++++++++++++++--- tests/config/format-test.js | 2 ++ .../Comments/__snapshots__/jsfmt.spec.js.snap | 3 ++- tests/format/Comments/jsfmt.spec.js | 2 +- 6 files changed, 37 insertions(+), 20 deletions(-) diff --git a/src/slang-nodes/Statements.js b/src/slang-nodes/Statements.js index f2ccd8a43..12548a9b2 100644 --- a/src/slang-nodes/Statements.js +++ b/src/slang-nodes/Statements.js @@ -1,6 +1,9 @@ import { doc } from 'prettier'; import { printSeparatedItem } from '../common/printer-helpers.js'; -import { printPreservingEmptyLines } from '../common/slang-helpers.js'; +import { + printComments, + printPreservingEmptyLines +} from '../common/slang-helpers.js'; const { hardline } = doc.builders; @@ -9,10 +12,16 @@ export const Statements = { items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ node, path, options, print }) => - node.items.length > 0 - ? printSeparatedItem( - printPreservingEmptyLines(path, 'items', options, print), - { firstSeparator: hardline, grouped: false } + node.items.length === 0 && (!node.comments || node.comments.length === 0) + ? '' + : printSeparatedItem( + [ + printPreservingEmptyLines(path, 'items', options, print), + printComments(node, path, options) + ], + { + firstSeparator: hardline, + grouped: false + } ) - : '' }; diff --git a/src/slang-nodes/YulBlock.js b/src/slang-nodes/YulBlock.js index 8e4aae9a9..f17bc449c 100644 --- a/src/slang-nodes/YulBlock.js +++ b/src/slang-nodes/YulBlock.js @@ -1,8 +1,3 @@ -import { doc } from 'prettier'; -import { printSeparatedItem } from '../common/printer-helpers.js'; - -const { hardline } = doc.builders; - export const YulBlock = { parse: ({ offsets, ast, options, parse }) => ({ openBrace: ast.openBrace.text, @@ -11,10 +6,7 @@ export const YulBlock = { }), print: ({ node, print }) => [ node.openBrace, - printSeparatedItem(print.call(print, 'statements'), { - firstSeparator: hardline, - grouped: false - }), + print.call(print, 'statements'), node.closeBrace ] }; diff --git a/src/slang-nodes/YulStatements.js b/src/slang-nodes/YulStatements.js index 3b58fc731..96df74935 100644 --- a/src/slang-nodes/YulStatements.js +++ b/src/slang-nodes/YulStatements.js @@ -1,14 +1,27 @@ +import { doc } from 'prettier'; +import { printSeparatedItem } from '../common/printer-helpers.js'; import { printComments, printPreservingEmptyLines } from '../common/slang-helpers.js'; +const { hardline } = doc.builders; + export const YulStatements = { parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ node, path, print, options }) => - node.items.length > 0 - ? printPreservingEmptyLines(path, 'items', options, print) - : printComments(node, path, options) + node.items.length === 0 && (!node.comments || node.comments.length === 0) + ? '' + : printSeparatedItem( + [ + printPreservingEmptyLines(path, 'items', options, print), + printComments(node, path, options) + ], + { + firstSeparator: hardline, + grouped: false + } + ) }; diff --git a/tests/config/format-test.js b/tests/config/format-test.js index 355f8c6de..a6d4f9a8c 100644 --- a/tests/config/format-test.js +++ b/tests/config/format-test.js @@ -52,6 +52,8 @@ const testsWithSlang = new Map( "BreakingChangesV0.8.0/BreakingChangesV0.8.0.sol", (options) => options.compiler === "0.7.0", ], + "Comments/Comments.sol", + "Conditional/Conditional.sol", ].map((fixture) => { const [file, testSlang = () => true] = Array.isArray(fixture) ? fixture diff --git a/tests/format/Comments/__snapshots__/jsfmt.spec.js.snap b/tests/format/Comments/__snapshots__/jsfmt.spec.js.snap index 8592e9fbb..097b2df9e 100644 --- a/tests/format/Comments/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Comments/__snapshots__/jsfmt.spec.js.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Comments.sol format 1`] = ` +exports[`Comments.sol - {"compiler":"0.4.24"} format 1`] = ` ====================================options===================================== +compiler: "0.4.24" parsers: ["solidity-parse"] printWidth: 80 | printWidth diff --git a/tests/format/Comments/jsfmt.spec.js b/tests/format/Comments/jsfmt.spec.js index 765dd60a6..daacfb24c 100644 --- a/tests/format/Comments/jsfmt.spec.js +++ b/tests/format/Comments/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse'], { compiler: '0.4.24' }); From cd74c2734bafbc2fc904c7660b6ec17ff49843fe Mon Sep 17 00:00:00 2001 From: Klaus Date: Fri, 5 Jul 2024 22:34:16 +1200 Subject: [PATCH 046/160] ContractDefinition comments --- src/nodes/AssemblyBlock.js | 26 +++++---- .../handleContractDefinitionComments.js | 54 +++++++++++++++++++ src/slang-comments/handlers/index.js | 2 + src/slang-nodes/ContractDefinition.js | 2 +- src/slang-nodes/ContractMembers.js | 16 ++++-- src/slang-nodes/InheritanceSpecifier.js | 5 +- .../Assembly/__snapshots__/jsfmt.spec.js.snap | 18 ++----- 7 files changed, 88 insertions(+), 35 deletions(-) create mode 100644 src/slang-comments/handlers/handleContractDefinitionComments.js diff --git a/src/nodes/AssemblyBlock.js b/src/nodes/AssemblyBlock.js index 680790711..7271fadb1 100644 --- a/src/nodes/AssemblyBlock.js +++ b/src/nodes/AssemblyBlock.js @@ -8,15 +8,19 @@ import { const { hardline } = doc.builders; export const AssemblyBlock = { - print: ({ node, options, path, print }) => [ - '{', - printSeparatedItem( - [ - printPreservingEmptyLines(path, 'operations', options, print), - printComments(node, path, options) - ], - { firstSeparator: hardline, grouped: false } - ), - '}' - ] + print: ({ node, options, path, print }) => + // if block is empty, just return the pair of braces + node.operations.length === 0 && !node.comments + ? '{}' + : [ + '{', + printSeparatedItem( + [ + printPreservingEmptyLines(path, 'operations', options, print), + printComments(node, path, options) + ], + { firstSeparator: hardline, grouped: false } + ), + '}' + ] }; diff --git a/src/slang-comments/handlers/handleContractDefinitionComments.js b/src/slang-comments/handlers/handleContractDefinitionComments.js new file mode 100644 index 000000000..b764f974d --- /dev/null +++ b/src/slang-comments/handlers/handleContractDefinitionComments.js @@ -0,0 +1,54 @@ +import { util } from 'prettier'; +import { getNextNonSpaceNonCommentCharacter } from '../../common/backward-compatibility.js'; +import { locEnd } from '../../common/slang-helpers.js'; + +const { addLeadingComment, addDanglingComment, addTrailingComment } = util; + +export default function handleContractDefinitionComments({ + text, + precedingNode, + enclosingNode, + followingNode, + comment +}) { + if (enclosingNode?.kind !== 'ContractDefinition') { + return false; + } + + if ( + precedingNode?.kind === 'ContractMembers' && + precedingNode.items.length === 0 + ) { + addDanglingComment(precedingNode, comment); + return true; + } + + const nextCharacter = getNextNonSpaceNonCommentCharacter( + text, + comment, + locEnd + ); + if (nextCharacter === '{') { + if ( + precedingNode?.kind === 'InheritanceSpecifier' && + precedingNode.types.items.length > 0 + ) { + addTrailingComment( + precedingNode.types.items[precedingNode.types.items.length - 1], + comment + ); + return true; + } + + if (followingNode?.kind === 'ContractMembers') { + if (followingNode.items.length > 0) { + addLeadingComment(followingNode.items[0], comment); + } else { + addDanglingComment(followingNode, comment); + } + return true; + } + } + + return false; +} diff --git a/src/slang-comments/handlers/index.js b/src/slang-comments/handlers/index.js index 31013eb4a..de74df2f8 100644 --- a/src/slang-comments/handlers/index.js +++ b/src/slang-comments/handlers/index.js @@ -1,9 +1,11 @@ import handleBlockComments from './handleBlockComments.js'; +import handleContractDefinitionComments from './handleContractDefinitionComments.js'; import handleWhileComments from './handleWhileComments.js'; import handleYulBlockComments from './handleYulBlockComments.js'; export default [ handleBlockComments, + handleContractDefinitionComments, handleWhileComments, handleYulBlockComments ]; diff --git a/src/slang-nodes/ContractDefinition.js b/src/slang-nodes/ContractDefinition.js index 5190c046e..a3d680390 100644 --- a/src/slang-nodes/ContractDefinition.js +++ b/src/slang-nodes/ContractDefinition.js @@ -18,7 +18,7 @@ export const ContractDefinition = { group([ node.abstractKeyword ? `${node.abstractKeyword} ` : '', `${node.contractKeyword} ${node.name}`, - node.inheritance ? path.call(print, 'inheritance') : line, + node.inheritance ? [' ', path.call(print, 'inheritance')] : line, node.openBrace ]), path.call(print, 'members'), diff --git a/src/slang-nodes/ContractMembers.js b/src/slang-nodes/ContractMembers.js index 2ff014ed8..f0176a1eb 100644 --- a/src/slang-nodes/ContractMembers.js +++ b/src/slang-nodes/ContractMembers.js @@ -1,6 +1,9 @@ import { doc } from 'prettier'; import { printSeparatedItem } from '../common/printer-helpers.js'; -import { printPreservingEmptyLines } from '../common/slang-helpers.js'; +import { + printComments, + printPreservingEmptyLines +} from '../common/slang-helpers.js'; const { hardline } = doc.builders; @@ -9,10 +12,13 @@ export const ContractMembers = { items: ast.items.map((item) => parse(item, options, parse, offsets)) }), print: ({ node, options, path, print }) => - node.items.length > 0 - ? printSeparatedItem( - printPreservingEmptyLines(path, 'items', options, print), + node.items.length === 0 && (!node.comments || node.comments.length === 0) + ? '' + : printSeparatedItem( + [ + printPreservingEmptyLines(path, 'items', options, print), + printComments(node, path, options) + ], { firstSeparator: hardline, grouped: false } ) - : '' }; diff --git a/src/slang-nodes/InheritanceSpecifier.js b/src/slang-nodes/InheritanceSpecifier.js index b490fd856..6118d008e 100644 --- a/src/slang-nodes/InheritanceSpecifier.js +++ b/src/slang-nodes/InheritanceSpecifier.js @@ -3,8 +3,5 @@ export const InheritanceSpecifier = { isKeyword: ast.isKeyword.text, types: parse(ast.types, options, parse, offsets) }), - print: ({ node, path, print }) => [ - ` ${node.isKeyword}`, - path.call(print, 'types') - ] + print: ({ node, path, print }) => [node.isKeyword, path.call(print, 'types')] }; diff --git a/tests/format/Assembly/__snapshots__/jsfmt.spec.js.snap b/tests/format/Assembly/__snapshots__/jsfmt.spec.js.snap index ff775725d..41a84ad3b 100644 --- a/tests/format/Assembly/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Assembly/__snapshots__/jsfmt.spec.js.snap @@ -328,9 +328,7 @@ contract Assembly { function assemblyFunctionNoReturn() { assembly { - function $somefn(somearg) { - - } + function $somefn(somearg) {} } } @@ -356,23 +354,15 @@ contract Assembly { function withBreak() { assembly { - for { - - } 1 { - - } { + for {} 1 {} { break } } } function memorySafe() { - assembly ("memory-safe") { - - } - assembly "evmasm" ("memory-safe") { - - } + assembly ("memory-safe") {} + assembly "evmasm" ("memory-safe") {} } function continueAndBreak(uint256 x) public pure returns (uint a, uint b) { From 549db5ae11d4e6da1b91da01c6d2a5c0c4b04899 Mon Sep 17 00:00:00 2001 From: Klaus Date: Sun, 7 Jul 2024 13:24:28 +1200 Subject: [PATCH 047/160] tweaking Block and ContractDefinition comments --- src/common/slang-helpers.js | 2 +- .../handlers/handleBlockComments.js | 24 ++++++++---- .../handleContractDefinitionComments.js | 37 +++++++++++++++---- ...nts.js => handleWhileStatementComments.js} | 2 +- src/slang-comments/handlers/index.js | 4 +- src/slang-nodes/FunctionType.js | 2 +- tests/config/format-test.js | 11 +++++- 7 files changed, 59 insertions(+), 23 deletions(-) rename src/slang-comments/handlers/{handleWhileComments.js => handleWhileStatementComments.js} (94%) diff --git a/src/common/slang-helpers.js b/src/common/slang-helpers.js index 160b491d8..adf8cb50d 100644 --- a/src/common/slang-helpers.js +++ b/src/common/slang-helpers.js @@ -57,7 +57,7 @@ export const printFunction = (functionName, node, path, print) => [ group([ path.call(print, 'attributes'), node.returns ? [line, path.call(print, 'returns')] : '', - node.body?.variant !== ';' ? dedent(line) : '' + node.body && node.body.variant !== ';' ? dedent(line) : '' ]) ) ]), diff --git a/src/slang-comments/handlers/handleBlockComments.js b/src/slang-comments/handlers/handleBlockComments.js index 4bad11a95..9122f611f 100644 --- a/src/slang-comments/handlers/handleBlockComments.js +++ b/src/slang-comments/handlers/handleBlockComments.js @@ -1,6 +1,6 @@ import { util } from 'prettier'; -const { addDanglingComment, addLeadingComment } = util; +const { addDanglingComment, addLeadingComment, addTrailingComment } = util; export default function handleBlockComments({ precedingNode, @@ -12,16 +12,24 @@ export default function handleBlockComments({ return false; } - if ( - precedingNode?.kind === 'Statements' && - precedingNode.items.length === 0 - ) { - addDanglingComment(precedingNode, comment); + if (precedingNode?.kind === 'Statements') { + if (precedingNode.items.length === 0) { + addDanglingComment(precedingNode, comment); + } else { + addTrailingComment( + precedingNode.items[precedingNode.items.length - 1], + comment + ); + } return true; } - if (followingNode?.kind === 'Statements' && followingNode.items.length > 0) { - addLeadingComment(followingNode.items[0], comment); + if (followingNode?.kind === 'Statements') { + if (followingNode.items.length === 0) { + addDanglingComment(followingNode, comment); + } else { + addLeadingComment(followingNode.items[0], comment); + } return true; } diff --git a/src/slang-comments/handlers/handleContractDefinitionComments.js b/src/slang-comments/handlers/handleContractDefinitionComments.js index b764f974d..751388e61 100644 --- a/src/slang-comments/handlers/handleContractDefinitionComments.js +++ b/src/slang-comments/handlers/handleContractDefinitionComments.js @@ -15,20 +15,39 @@ export default function handleContractDefinitionComments({ return false; } - if ( - precedingNode?.kind === 'ContractMembers' && - precedingNode.items.length === 0 - ) { - addDanglingComment(precedingNode, comment); - return true; - } - const nextCharacter = getNextNonSpaceNonCommentCharacter( text, comment, locEnd ); + + // Everything before the InheritanceSpecifier is pushed onto the beginning of + // the ContractDefinition. + if ( + followingNode?.kind === 'InheritanceSpecifier' || + (followingNode?.kind === 'ContractMembers' && nextCharacter !== '{') + ) { + addLeadingComment(enclosingNode, comment); + return true; + } + + // The comment is at the end of the body of the ContractDefinition. + if (precedingNode?.kind === 'ContractMembers') { + if (precedingNode.items.length === 0) { + addDanglingComment(precedingNode, comment); + } else { + addTrailingComment( + precedingNode.items[precedingNode.items.length - 1], + comment + ); + } + return true; + } + + // The last comments before the body. if (nextCharacter === '{') { + // If there's an InheritanceSpecifier, the comment is appended to the last + // InheritanceType. if ( precedingNode?.kind === 'InheritanceSpecifier' && precedingNode.types.items.length > 0 @@ -40,6 +59,8 @@ export default function handleContractDefinitionComments({ return true; } + // If there's no InheritanceSpecifier, the comment before the body is + // assumed to be intended at the beginning of the body. if (followingNode?.kind === 'ContractMembers') { if (followingNode.items.length > 0) { addLeadingComment(followingNode.items[0], comment); diff --git a/src/slang-comments/handlers/handleWhileComments.js b/src/slang-comments/handlers/handleWhileStatementComments.js similarity index 94% rename from src/slang-comments/handlers/handleWhileComments.js rename to src/slang-comments/handlers/handleWhileStatementComments.js index ddba0501f..d17b40e3a 100644 --- a/src/slang-comments/handlers/handleWhileComments.js +++ b/src/slang-comments/handlers/handleWhileStatementComments.js @@ -4,7 +4,7 @@ import { locEnd } from '../../common/slang-helpers.js'; const { addTrailingComment } = util; -export default function handleWhileComments({ +export default function handleWhileStatementComments({ text, precedingNode, enclosingNode, diff --git a/src/slang-comments/handlers/index.js b/src/slang-comments/handlers/index.js index de74df2f8..3ebcb9aa6 100644 --- a/src/slang-comments/handlers/index.js +++ b/src/slang-comments/handlers/index.js @@ -1,11 +1,11 @@ import handleBlockComments from './handleBlockComments.js'; import handleContractDefinitionComments from './handleContractDefinitionComments.js'; -import handleWhileComments from './handleWhileComments.js'; +import handleWhileStatementComments from './handleWhileStatementComments.js'; import handleYulBlockComments from './handleYulBlockComments.js'; export default [ handleBlockComments, handleContractDefinitionComments, - handleWhileComments, + handleWhileStatementComments, handleYulBlockComments ]; diff --git a/src/slang-nodes/FunctionType.js b/src/slang-nodes/FunctionType.js index 1c6caca4b..750521cd1 100644 --- a/src/slang-nodes/FunctionType.js +++ b/src/slang-nodes/FunctionType.js @@ -10,5 +10,5 @@ export const FunctionType = { : undefined }), print: ({ node, path, print }) => - printFunction(`${node.functionKeyword} `, node, path, print) + printFunction(node.functionKeyword, node, path, print) }; diff --git a/tests/config/format-test.js b/tests/config/format-test.js index a6d4f9a8c..dc049dcc8 100644 --- a/tests/config/format-test.js +++ b/tests/config/format-test.js @@ -44,7 +44,7 @@ const testsWithSlang = new Map( "Arrays/Arrays.sol", "Assembly/Assembly.sol", // "AssemblyV0.4.26/Assembly.sol", - "BasicIterator/BasicIterator.sol", + // "BasicIterator/BasicIterator.sol", "BinaryOperators/BinaryOperators.sol", "BinaryOperators/Parentheses.sol", "BreakingChangesV0.7.4/BreakingChangesV0.7.4.sol", @@ -52,8 +52,15 @@ const testsWithSlang = new Map( "BreakingChangesV0.8.0/BreakingChangesV0.8.0.sol", (options) => options.compiler === "0.7.0", ], - "Comments/Comments.sol", + // "Comments/Comments.sol", "Conditional/Conditional.sol", + "Constructors/Constructors.sol", + "ContractDefinitions/ContractDefinitions.sol", + "CustomErrors/CustomErrors.sol", + "EnumDefinitions/EnumDefinitions.sol", + // "Etc/Etc.sol", + // "ExperimentalTernaries/ExperimentalTernaries.sol", // TODO: fix this one + "ForStatements/ForStatements.sol", ].map((fixture) => { const [file, testSlang = () => true] = Array.isArray(fixture) ? fixture From b73d03177dac21b72635b6471dcd1f7b4bff5dad Mon Sep 17 00:00:00 2001 From: Klaus Date: Sun, 7 Jul 2024 16:07:57 +1200 Subject: [PATCH 048/160] respecting bracketSpacing --- src/slang-nodes/NamedArguments.js | 8 +++++++- tests/config/format-test.js | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/slang-nodes/NamedArguments.js b/src/slang-nodes/NamedArguments.js index ef5e7294a..4aa0ac720 100644 --- a/src/slang-nodes/NamedArguments.js +++ b/src/slang-nodes/NamedArguments.js @@ -1,9 +1,15 @@ +import { doc } from 'prettier'; import { printSeparatedList } from '../common/printer-helpers.js'; +const { line, softline } = doc.builders; + export const NamedArguments = { parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), - print: ({ path, print }) => printSeparatedList(path.map(print, 'items')) + print: ({ path, print, options }) => + printSeparatedList(path.map(print, 'items'), { + firstSeparator: options.bracketSpacing ? line : softline + }) }; diff --git a/tests/config/format-test.js b/tests/config/format-test.js index dc049dcc8..53a2f6d0d 100644 --- a/tests/config/format-test.js +++ b/tests/config/format-test.js @@ -61,6 +61,7 @@ const testsWithSlang = new Map( // "Etc/Etc.sol", // "ExperimentalTernaries/ExperimentalTernaries.sol", // TODO: fix this one "ForStatements/ForStatements.sol", + "FunctionCalls/FunctionCalls.sol", ].map((fixture) => { const [file, testSlang = () => true] = Array.isArray(fixture) ? fixture From 229513efcadfb7d939b6506731ecbba31bb4b3c9 Mon Sep 17 00:00:00 2001 From: Klaus Date: Sun, 7 Jul 2024 22:40:43 +1200 Subject: [PATCH 049/160] sorting function attributes --- src/common/slang-helpers.js | 35 +++++++++++++++++++ src/slang-nodes/ConstructorAttributes.js | 5 ++- src/slang-nodes/FallbackFunctionAttributes.js | 5 ++- src/slang-nodes/FunctionAttributes.js | 5 ++- src/slang-nodes/FunctionTypeAttributes.js | 5 ++- src/slang-nodes/ModifierAttributes.js | 5 ++- src/slang-nodes/ReceiveFunctionAttributes.js | 5 ++- src/slang-nodes/UnnamedFunctionAttributes.js | 5 ++- tests/config/format-test.js | 1 + 9 files changed, 64 insertions(+), 7 deletions(-) diff --git a/src/common/slang-helpers.js b/src/common/slang-helpers.js index adf8cb50d..f14f57a10 100644 --- a/src/common/slang-helpers.js +++ b/src/common/slang-helpers.js @@ -64,6 +64,41 @@ export const printFunction = (functionName, node, path, print) => [ node.body ? path.call(print, 'body') : '' ]; +const visibilityKeyWords = ['external', 'internal', 'public', 'private']; +const mutabilityKeyWords = ['pure', 'constant', 'payable', 'view']; + +export const sortFunctionAttributes = (a, b) => { + const aIsString = typeof a.variant === 'string'; + const bIsString = typeof b.variant === 'string'; + + if (aIsString && !bIsString) return -1; + if (bIsString && !aIsString) return 1; + + // Both are strings + if (aIsString && bIsString) { + // Visibility First + if (visibilityKeyWords.includes(a.variant)) return -1; + if (visibilityKeyWords.includes(b.variant)) return 1; + // State Mutability Second + if (mutabilityKeyWords.includes(a.variant)) return -1; + if (mutabilityKeyWords.includes(b.variant)) return 1; + // Virtual keyword last + } else { + // Both are objects + if ( + a.variant.kind === 'OverrideSpecifier' && + b.variant.kind === 'ModifierInvocation' + ) + return -1; + if ( + b.variant.kind === 'OverrideSpecifier' && + a.variant.kind === 'ModifierInvocation' + ) + return 1; + } + return 0; +}; + export const isBinaryOperation = createKindCheckFunction([ 'AdditiveExpression', 'MultiplicativeExpression', diff --git a/src/slang-nodes/ConstructorAttributes.js b/src/slang-nodes/ConstructorAttributes.js index 6331077e9..1ab7f423e 100644 --- a/src/slang-nodes/ConstructorAttributes.js +++ b/src/slang-nodes/ConstructorAttributes.js @@ -1,10 +1,13 @@ import { doc } from 'prettier'; +import { sortFunctionAttributes } from '../common/slang-helpers.js'; const { line } = doc.builders; export const ConstructorAttributes = { parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)) + items: ast.items + .map((item) => parse(item, options, parse, offsets)) + .sort(sortFunctionAttributes) }), print: ({ path, print }) => path.map(print, 'items').map((item) => [line, item]) diff --git a/src/slang-nodes/FallbackFunctionAttributes.js b/src/slang-nodes/FallbackFunctionAttributes.js index cbe66818c..e705ac5c6 100644 --- a/src/slang-nodes/FallbackFunctionAttributes.js +++ b/src/slang-nodes/FallbackFunctionAttributes.js @@ -1,10 +1,13 @@ import { doc } from 'prettier'; +import { sortFunctionAttributes } from '../common/slang-helpers.js'; const { line } = doc.builders; export const FallbackFunctionAttributes = { parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)) + items: ast.items + .map((item) => parse(item, options, parse, offsets)) + .sort(sortFunctionAttributes) }), print: ({ path, print }) => path.map(print, 'items').map((item) => [line, item]) diff --git a/src/slang-nodes/FunctionAttributes.js b/src/slang-nodes/FunctionAttributes.js index fec1c5c4f..af8343898 100644 --- a/src/slang-nodes/FunctionAttributes.js +++ b/src/slang-nodes/FunctionAttributes.js @@ -1,10 +1,13 @@ import { doc } from 'prettier'; +import { sortFunctionAttributes } from '../common/slang-helpers.js'; const { line } = doc.builders; export const FunctionAttributes = { parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)) + items: ast.items + .map((item) => parse(item, options, parse, offsets)) + .sort(sortFunctionAttributes) }), print: ({ path, print }) => path.map(print, 'items').map((item) => [line, item]) diff --git a/src/slang-nodes/FunctionTypeAttributes.js b/src/slang-nodes/FunctionTypeAttributes.js index 4d9b7feab..ddc66dcb7 100644 --- a/src/slang-nodes/FunctionTypeAttributes.js +++ b/src/slang-nodes/FunctionTypeAttributes.js @@ -1,10 +1,13 @@ import { doc } from 'prettier'; +import { sortFunctionAttributes } from '../common/slang-helpers.js'; const { line } = doc.builders; export const FunctionTypeAttributes = { parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)) + items: ast.items + .map((item) => parse(item, options, parse, offsets)) + .sort(sortFunctionAttributes) }), print: ({ path, print }) => path.map(print, 'items').map((item) => [line, item]) diff --git a/src/slang-nodes/ModifierAttributes.js b/src/slang-nodes/ModifierAttributes.js index 26d9bd7e1..2c7c4b96e 100644 --- a/src/slang-nodes/ModifierAttributes.js +++ b/src/slang-nodes/ModifierAttributes.js @@ -1,10 +1,13 @@ import { doc } from 'prettier'; +import { sortFunctionAttributes } from '../common/slang-helpers.js'; const { line } = doc.builders; export const ModifierAttributes = { parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)) + items: ast.items + .map((item) => parse(item, options, parse, offsets)) + .sort(sortFunctionAttributes) }), print: ({ path, print }) => path.map(print, 'items').map((item) => [line, item]) diff --git a/src/slang-nodes/ReceiveFunctionAttributes.js b/src/slang-nodes/ReceiveFunctionAttributes.js index 2264d9f37..cfe1293e0 100644 --- a/src/slang-nodes/ReceiveFunctionAttributes.js +++ b/src/slang-nodes/ReceiveFunctionAttributes.js @@ -1,10 +1,13 @@ import { doc } from 'prettier'; +import { sortFunctionAttributes } from '../common/slang-helpers.js'; const { line } = doc.builders; export const ReceiveFunctionAttributes = { parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)) + items: ast.items + .map((item) => parse(item, options, parse, offsets)) + .sort(sortFunctionAttributes) }), print: ({ path, print }) => path.map(print, 'items').map((item) => [line, item]) diff --git a/src/slang-nodes/UnnamedFunctionAttributes.js b/src/slang-nodes/UnnamedFunctionAttributes.js index 9ab8dc343..08524de45 100644 --- a/src/slang-nodes/UnnamedFunctionAttributes.js +++ b/src/slang-nodes/UnnamedFunctionAttributes.js @@ -1,10 +1,13 @@ import { doc } from 'prettier'; +import { sortFunctionAttributes } from '../common/slang-helpers.js'; const { line } = doc.builders; export const UnnamedFunctionAttributes = { parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)) + items: ast.items + .map((item) => parse(item, options, parse, offsets)) + .sort(sortFunctionAttributes) }), print: ({ path, print }) => path.map(print, 'items').map((item) => [line, item]) diff --git a/tests/config/format-test.js b/tests/config/format-test.js index 53a2f6d0d..6814e88a8 100644 --- a/tests/config/format-test.js +++ b/tests/config/format-test.js @@ -62,6 +62,7 @@ const testsWithSlang = new Map( // "ExperimentalTernaries/ExperimentalTernaries.sol", // TODO: fix this one "ForStatements/ForStatements.sol", "FunctionCalls/FunctionCalls.sol", + "FunctionDefinitions/FunctionDefinitions.sol", ].map((fixture) => { const [file, testSlang = () => true] = Array.isArray(fixture) ? fixture From 169e0bdf466d9f33ba33ed05e7830b37a801f2dd Mon Sep 17 00:00:00 2001 From: Klaus Date: Mon, 8 Jul 2024 17:11:12 +1200 Subject: [PATCH 050/160] refactor combining all consecutive strings into one --- src/slang-nodes/AddressType.js | 6 ++---- src/slang-nodes/AssemblyStatement.js | 7 +++---- src/slang-nodes/ContractDefinition.js | 3 +-- src/slang-nodes/EnumMembers.js | 4 +--- src/slang-nodes/PragmaDirective.js | 3 +-- src/slang-nodes/UsingDirective.js | 10 +++------- src/slang-nodes/VariableDeclarationStatement.js | 4 ++-- src/slang-nodes/VersionPragma.js | 3 +-- src/slang-nodes/YulForStatement.js | 3 +-- src/slang-nodes/YulFunctionDefinition.js | 4 +--- src/slang-nodes/YulIfStatement.js | 3 +-- src/slang-nodes/YulLabel.js | 2 +- src/slang-nodes/YulSwitchStatement.js | 3 +-- src/slang-nodes/YulVariableDeclarationStatement.js | 5 +---- 14 files changed, 20 insertions(+), 40 deletions(-) diff --git a/src/slang-nodes/AddressType.js b/src/slang-nodes/AddressType.js index 75c8d2c8e..343893630 100644 --- a/src/slang-nodes/AddressType.js +++ b/src/slang-nodes/AddressType.js @@ -3,8 +3,6 @@ export const AddressType = { addressKeyword: ast.addressKeyword.text, payableKeyword: ast.payableKeyword?.text }), - print: ({ node }) => [ - node.addressKeyword, - node.payableKeyword ? ` ${node.payableKeyword}` : '' - ] + print: ({ node }) => + `${node.addressKeyword}${node.payableKeyword ? ` ${node.payableKeyword}` : ''}` }; diff --git a/src/slang-nodes/AssemblyStatement.js b/src/slang-nodes/AssemblyStatement.js index 45a13a89b..6f87405d0 100644 --- a/src/slang-nodes/AssemblyStatement.js +++ b/src/slang-nodes/AssemblyStatement.js @@ -6,10 +6,9 @@ export const AssemblyStatement = { body: parse(ast.body, options, parse, offsets) }), print: ({ node, path, print }) => [ - node.assemblyKeyword, - node.label ? [' ', path.call(print, 'label')] : '', - node.flags ? [' ', path.call(print, 'flags')] : '', - ' ', + `${node.assemblyKeyword} `, + node.label ? [path.call(print, 'label'), ' '] : '', + node.flags ? [path.call(print, 'flags'), ' '] : '', path.call(print, 'body') ] }; diff --git a/src/slang-nodes/ContractDefinition.js b/src/slang-nodes/ContractDefinition.js index a3d680390..6ff7f4705 100644 --- a/src/slang-nodes/ContractDefinition.js +++ b/src/slang-nodes/ContractDefinition.js @@ -16,8 +16,7 @@ export const ContractDefinition = { }), print: ({ node, path, print }) => [ group([ - node.abstractKeyword ? `${node.abstractKeyword} ` : '', - `${node.contractKeyword} ${node.name}`, + `${node.abstractKeyword ? `${node.abstractKeyword} ` : ''}${node.contractKeyword} ${node.name}`, node.inheritance ? [' ', path.call(print, 'inheritance')] : line, node.openBrace ]), diff --git a/src/slang-nodes/EnumMembers.js b/src/slang-nodes/EnumMembers.js index a741876bb..8a73d9c77 100644 --- a/src/slang-nodes/EnumMembers.js +++ b/src/slang-nodes/EnumMembers.js @@ -9,7 +9,5 @@ export const EnumMembers = { separators: ast.separators.map((separator) => separator.text) }), print: ({ node }) => - printSeparatedList(node.items, { - firstSeparator: hardline - }) + printSeparatedList(node.items, { firstSeparator: hardline }) }; diff --git a/src/slang-nodes/PragmaDirective.js b/src/slang-nodes/PragmaDirective.js index 35e81b3f2..9abcd1a6b 100644 --- a/src/slang-nodes/PragmaDirective.js +++ b/src/slang-nodes/PragmaDirective.js @@ -5,8 +5,7 @@ export const PragmaDirective = { semicolon: ast.semicolon.text }), print: ({ node, path, print }) => [ - node.pragmaKeyword, - ' ', + `${node.pragmaKeyword} `, path.call(print, 'pragma'), node.semicolon ] diff --git a/src/slang-nodes/UsingDirective.js b/src/slang-nodes/UsingDirective.js index d4a591c26..bf1cf518d 100644 --- a/src/slang-nodes/UsingDirective.js +++ b/src/slang-nodes/UsingDirective.js @@ -8,14 +8,10 @@ export const UsingDirective = { semicolon: ast.semicolon.text }), print: ({ node, path, print }) => [ - node.usingKeyword, - ' ', + `${node.usingKeyword} `, path.call(print, 'clause'), - ' ', - node.forKeyword, - ' ', + ` ${node.forKeyword} `, path.call(print, 'target'), - node.globalKeyword ? ` ${node.globalKeyword}` : '', - node.semicolon + `${node.globalKeyword ? ` ${node.globalKeyword}` : ''}${node.semicolon}` ] }; diff --git a/src/slang-nodes/VariableDeclarationStatement.js b/src/slang-nodes/VariableDeclarationStatement.js index 6d0160fa2..1dbda0c0e 100644 --- a/src/slang-nodes/VariableDeclarationStatement.js +++ b/src/slang-nodes/VariableDeclarationStatement.js @@ -10,8 +10,8 @@ export const VariableDeclarationStatement = { }), print: ({ node, path, print }) => [ path.call(print, 'variableType'), - node.storageLocation ? ` ${path.call(print, 'storageLocation')} ` : ' ', - node.name, + node.storageLocation ? [' ', path.call(print, 'storageLocation')] : '', + ` ${node.name}`, node.value ? path.call(print, 'value') : '', node.semicolon ] diff --git a/src/slang-nodes/VersionPragma.js b/src/slang-nodes/VersionPragma.js index daedaf415..fb9990c4c 100644 --- a/src/slang-nodes/VersionPragma.js +++ b/src/slang-nodes/VersionPragma.js @@ -4,8 +4,7 @@ export const VersionPragma = { sets: parse(ast.sets, options, parse, offsets) }), print: ({ node, path, print }) => [ - node.solidityKeyword, - ' ', + `${node.solidityKeyword} `, path.call(print, 'sets') ] }; diff --git a/src/slang-nodes/YulForStatement.js b/src/slang-nodes/YulForStatement.js index c488a2c51..340ff05cf 100644 --- a/src/slang-nodes/YulForStatement.js +++ b/src/slang-nodes/YulForStatement.js @@ -7,8 +7,7 @@ export const YulForStatement = { body: parse(ast.body, options, parse, offsets) }), print: ({ node, path, print }) => [ - node.forKeyword, - ' ', + `${node.forKeyword} `, path.call(print, 'initialization'), ' ', path.call(print, 'condition'), diff --git a/src/slang-nodes/YulFunctionDefinition.js b/src/slang-nodes/YulFunctionDefinition.js index 6698d3117..e709b637a 100644 --- a/src/slang-nodes/YulFunctionDefinition.js +++ b/src/slang-nodes/YulFunctionDefinition.js @@ -9,9 +9,7 @@ export const YulFunctionDefinition = { body: parse(ast.body, options, parse, offsets) }), print: ({ node, path, print }) => [ - node.functionKeyword, - ' ', - node.name, + `${node.functionKeyword} ${node.name}`, path.call(print, 'parameters'), node.returns ? path.call(print, 'returns') : ' ', path.call(print, 'body') diff --git a/src/slang-nodes/YulIfStatement.js b/src/slang-nodes/YulIfStatement.js index 9263c2b9b..03ff62ea9 100644 --- a/src/slang-nodes/YulIfStatement.js +++ b/src/slang-nodes/YulIfStatement.js @@ -5,8 +5,7 @@ export const YulIfStatement = { body: parse(ast.body, options, parse, offsets) }), print: ({ node, path, print }) => [ - node.ifKeyword, - ' ', + `${node.ifKeyword} `, path.call(print, 'condition'), ' ', path.call(print, 'body') diff --git a/src/slang-nodes/YulLabel.js b/src/slang-nodes/YulLabel.js index 3a7f4ab0e..fd469c373 100644 --- a/src/slang-nodes/YulLabel.js +++ b/src/slang-nodes/YulLabel.js @@ -7,5 +7,5 @@ export const YulLabel = { label: ast.label.text, colon: ast.colon.text }), - print: ({ node }) => [dedent(line), node.label, node.colon] + print: ({ node }) => [dedent(line), `${node.label}${node.colon}`] }; diff --git a/src/slang-nodes/YulSwitchStatement.js b/src/slang-nodes/YulSwitchStatement.js index ff8700a0b..83776dc4c 100644 --- a/src/slang-nodes/YulSwitchStatement.js +++ b/src/slang-nodes/YulSwitchStatement.js @@ -9,8 +9,7 @@ export const YulSwitchStatement = { cases: parse(ast.cases, options, parse, offsets) }), print: ({ node, path, print }) => [ - node.switchKeyword, - ' ', + `${node.switchKeyword} `, path.call(print, 'expression'), hardline, path.call(print, 'cases') diff --git a/src/slang-nodes/YulVariableDeclarationStatement.js b/src/slang-nodes/YulVariableDeclarationStatement.js index 9cf5f12bd..9a42670fc 100644 --- a/src/slang-nodes/YulVariableDeclarationStatement.js +++ b/src/slang-nodes/YulVariableDeclarationStatement.js @@ -5,10 +5,7 @@ export const YulVariableDeclarationStatement = { value: ast.value ? parse(ast.value, options, parse, offsets) : undefined }), print: ({ node, path, print }) => [ - node.letKeyword, - ' ', - node.names, - ' ', + `${node.letKeyword} ${node.names} `, node.value ? path.call(print, 'value') : '' ] }; From 34dd4cc385ab1c819244b6349c5ee9be122a9fa3 Mon Sep 17 00:00:00 2001 From: Klaus Date: Mon, 8 Jul 2024 17:52:36 +1200 Subject: [PATCH 051/160] group binary operations after equality --- src/common/slang-helpers.js | 5 +++-- tests/config/format-test.js | 5 ++++- .../__snapshots__/jsfmt.spec.js.snap | 3 ++- tests/format/FunctionDefinitionsv0.5.0/jsfmt.spec.js | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/common/slang-helpers.js b/src/common/slang-helpers.js index f14f57a10..625f59e27 100644 --- a/src/common/slang-helpers.js +++ b/src/common/slang-helpers.js @@ -84,7 +84,7 @@ export const sortFunctionAttributes = (a, b) => { if (mutabilityKeyWords.includes(b.variant)) return 1; // Virtual keyword last } else { - // Both are objects + // Both are nodes if ( a.variant.kind === 'OverrideSpecifier' && b.variant.kind === 'ModifierInvocation' @@ -118,7 +118,8 @@ const binaryGroupRulesBuilder = (path) => (document) => { const grandparentNode = path.getNode(2); if ( isBinaryOperation(grandparentNode) && - grandparentNode.kind !== 'ComparisonExpression' + grandparentNode.kind !== 'ComparisonExpression' && + grandparentNode.kind !== 'EqualityExpression' ) { return document; } diff --git a/tests/config/format-test.js b/tests/config/format-test.js index 6814e88a8..5bd82c6d3 100644 --- a/tests/config/format-test.js +++ b/tests/config/format-test.js @@ -62,7 +62,10 @@ const testsWithSlang = new Map( // "ExperimentalTernaries/ExperimentalTernaries.sol", // TODO: fix this one "ForStatements/ForStatements.sol", "FunctionCalls/FunctionCalls.sol", - "FunctionDefinitions/FunctionDefinitions.sol", + // "FunctionDefinitions/FunctionDefinitions.sol", + "FunctionDefinitionsv0.5.0/FunctionDefinitions.sol", + "HexLiteral/HexLiteral.sol", + "IfStatements/IfStatements.sol", ].map((fixture) => { const [file, testSlang = () => true] = Array.isArray(fixture) ? fixture diff --git a/tests/format/FunctionDefinitionsv0.5.0/__snapshots__/jsfmt.spec.js.snap b/tests/format/FunctionDefinitionsv0.5.0/__snapshots__/jsfmt.spec.js.snap index 900ffad07..095be0b0f 100644 --- a/tests/format/FunctionDefinitionsv0.5.0/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/FunctionDefinitionsv0.5.0/__snapshots__/jsfmt.spec.js.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`FunctionDefinitions.sol format 1`] = ` +exports[`FunctionDefinitions.sol - {"compiler":"0.5.0"} format 1`] = ` ====================================options===================================== +compiler: "0.5.0" parsers: ["solidity-parse"] printWidth: 80 | printWidth diff --git a/tests/format/FunctionDefinitionsv0.5.0/jsfmt.spec.js b/tests/format/FunctionDefinitionsv0.5.0/jsfmt.spec.js index 765dd60a6..417487a97 100644 --- a/tests/format/FunctionDefinitionsv0.5.0/jsfmt.spec.js +++ b/tests/format/FunctionDefinitionsv0.5.0/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse'], { compiler: '0.5.0' }); From 7a67fee115cb3450d9923721249a3506e55b8a69 Mon Sep 17 00:00:00 2001 From: Klaus Date: Mon, 8 Jul 2024 20:37:14 +1200 Subject: [PATCH 052/160] correcting syntax in tests --- tests/format/ImportDirective/ImportDirectives.sol | 2 +- .../ImportDirective/__snapshots__/jsfmt.spec.js.snap | 8 ++++---- tests/format/MemberAccess/MemberAccess.sol | 4 ++-- .../format/MemberAccess/__snapshots__/jsfmt.spec.js.snap | 8 ++++---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/format/ImportDirective/ImportDirectives.sol b/tests/format/ImportDirective/ImportDirectives.sol index 3ae21bc7f..78c55b4ea 100644 --- a/tests/format/ImportDirective/ImportDirectives.sol +++ b/tests/format/ImportDirective/ImportDirectives.sol @@ -1,5 +1,5 @@ import "SomeFile.sol"; import "SomeFile.sol" as SomeOtherFile; import * as SomeSymbol from "AnotherFile.sol"; -import {symbol1 as alias, symbol2} from "File.sol"; +import {symbol1 as alias1, symbol2} from "File.sol"; import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol"; diff --git a/tests/format/ImportDirective/__snapshots__/jsfmt.spec.js.snap b/tests/format/ImportDirective/__snapshots__/jsfmt.spec.js.snap index 3ec86c724..e727c6f72 100644 --- a/tests/format/ImportDirective/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/ImportDirective/__snapshots__/jsfmt.spec.js.snap @@ -10,14 +10,14 @@ printWidth: 80 import "SomeFile.sol"; import "SomeFile.sol" as SomeOtherFile; import * as SomeSymbol from "AnotherFile.sol"; -import {symbol1 as alias, symbol2} from "File.sol"; +import {symbol1 as alias1, symbol2} from "File.sol"; import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol"; =====================================output===================================== import "SomeFile.sol"; import "SomeFile.sol" as SomeOtherFile; import "AnotherFile.sol" as SomeSymbol; -import { symbol1 as alias, symbol2 } from "File.sol"; +import { symbol1 as alias1, symbol2 } from "File.sol"; import { symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4 } from "File2.sol"; ================================================================================ @@ -32,14 +32,14 @@ printWidth: 80 import "SomeFile.sol"; import "SomeFile.sol" as SomeOtherFile; import * as SomeSymbol from "AnotherFile.sol"; -import {symbol1 as alias, symbol2} from "File.sol"; +import {symbol1 as alias1, symbol2} from "File.sol"; import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol"; =====================================output===================================== import "SomeFile.sol"; import "SomeFile.sol" as SomeOtherFile; import "AnotherFile.sol" as SomeSymbol; -import {symbol1 as alias, symbol2} from "File.sol"; +import {symbol1 as alias1, symbol2} from "File.sol"; import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol"; ================================================================================ diff --git a/tests/format/MemberAccess/MemberAccess.sol b/tests/format/MemberAccess/MemberAccess.sol index 49660cb0d..10b9943d0 100644 --- a/tests/format/MemberAccess/MemberAccess.sol +++ b/tests/format/MemberAccess/MemberAccess.sol @@ -1,7 +1,7 @@ pragma solidity ^0.5.0; contract MemberAccess { - function() { + function foo() { int256 amount = SafeCast.toInt256(10**(18 - underlyingAssetDecimals)).neg(); longNameAmount = SafeCast.toInt256(10**(18 - underlyingAssetDecimals)).neg(); a.b.c.d; @@ -69,7 +69,7 @@ contract MemberAccessIsEndOfChainCases { // break if is an ReturnStatement uint a = b.c; - function() modifierCase(b.c) { + function foo() modifierCase(b.c) { // break if is an argument of a FunctionCall a(b.c); // break if is an index of an IndexAccess diff --git a/tests/format/MemberAccess/__snapshots__/jsfmt.spec.js.snap b/tests/format/MemberAccess/__snapshots__/jsfmt.spec.js.snap index ed290e0df..34d510ad1 100644 --- a/tests/format/MemberAccess/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/MemberAccess/__snapshots__/jsfmt.spec.js.snap @@ -9,7 +9,7 @@ printWidth: 80 pragma solidity ^0.5.0; contract MemberAccess { - function() { + function foo() { int256 amount = SafeCast.toInt256(10**(18 - underlyingAssetDecimals)).neg(); longNameAmount = SafeCast.toInt256(10**(18 - underlyingAssetDecimals)).neg(); a.b.c.d; @@ -77,7 +77,7 @@ contract MemberAccessIsEndOfChainCases { // break if is an ReturnStatement uint a = b.c; - function() modifierCase(b.c) { + function foo() modifierCase(b.c) { // break if is an argument of a FunctionCall a(b.c); // break if is an index of an IndexAccess @@ -118,7 +118,7 @@ contract MemberAccessIsEndOfChainCases { pragma solidity ^0.5.0; contract MemberAccess { - function() { + function foo() { int256 amount = SafeCast .toInt256(10 ** (18 - underlyingAssetDecimals)) .neg(); @@ -213,7 +213,7 @@ contract MemberAccessIsEndOfChainCases { // break if is an ReturnStatement uint a = b.c; - function() modifierCase(b.c) { + function foo() modifierCase(b.c) { // break if is an argument of a FunctionCall a(b.c); // break if is an index of an IndexAccess From aa067087f261541b01dad336517b609382f3eb48 Mon Sep 17 00:00:00 2001 From: Klaus Date: Tue, 9 Jul 2024 01:53:15 +1200 Subject: [PATCH 053/160] final tweaks to match both parsers --- src/common/slang-helpers.js | 12 +++ src/nodes/HexLiteral.js | 4 +- src/nodes/ModifierDefinition.js | 10 +-- src/slang-nodes/CallOptions.js | 8 +- src/slang-nodes/CatchClause.js | 4 +- src/slang-nodes/CatchClauseError.js | 6 +- src/slang-nodes/TryStatement.js | 2 +- .../VariableDeclarationStatement.js | 14 ++- src/slang-nodes/VersionExpressionSets.js | 2 +- src/slangPrinter.js | 4 +- tests/config/format-test.js | 89 +++++++++++++++---- .../__snapshots__/jsfmt.spec.js.snap | 6 +- .../__snapshots__/jsfmt.spec.js.snap | 4 +- .../Proxy/__snapshots__/jsfmt.spec.js.snap | 3 +- tests/format/Proxy/jsfmt.spec.js | 2 +- tests/format/StyleGuide/jsfmt.spec.js | 2 +- 16 files changed, 125 insertions(+), 47 deletions(-) diff --git a/src/common/slang-helpers.js b/src/common/slang-helpers.js index 625f59e27..cc897d1a1 100644 --- a/src/common/slang-helpers.js +++ b/src/common/slang-helpers.js @@ -99,6 +99,18 @@ export const sortFunctionAttributes = (a, b) => { return 0; }; +export function hasNodeIgnoreComment(node) { + return ( + node?.comments && + node.comments.some( + (comment) => + comment.value + .slice(2, isBlockComment(comment) ? -2 : undefined) + .trim() === 'prettier-ignore' + ) + ); +} + export const isBinaryOperation = createKindCheckFunction([ 'AdditiveExpression', 'MultiplicativeExpression', diff --git a/src/nodes/HexLiteral.js b/src/nodes/HexLiteral.js index 368d7001a..e8bc20603 100644 --- a/src/nodes/HexLiteral.js +++ b/src/nodes/HexLiteral.js @@ -1,11 +1,11 @@ import { doc } from 'prettier'; import { printString } from '../common/util.js'; -const { join, line } = doc.builders; +const { join, hardline } = doc.builders; export const HexLiteral = { print: ({ node, options }) => { const list = node.parts.map((part) => `hex${printString(part, options)}`); - return join(line, list); + return join(hardline, list); } }; diff --git a/src/nodes/ModifierDefinition.js b/src/nodes/ModifierDefinition.js index 296f2bbe4..d1ed07df9 100644 --- a/src/nodes/ModifierDefinition.js +++ b/src/nodes/ModifierDefinition.js @@ -1,20 +1,14 @@ import { doc } from 'prettier'; import { printSeparatedList } from '../common/printer-helpers.js'; -const { group, hardline, indent, line } = doc.builders; +const { group, indent, line } = doc.builders; const modifierParameters = (node, path, print) => { if (node.parameters?.length > 0) { return [ '(', printSeparatedList(path.map(print, 'parameters'), { - separator: [ - ',', - // To keep consistency any list of parameters will split if it's longer than 2. - // For more information see: - // https://github.com/prettier-solidity/prettier-plugin-solidity/issues/256 - node.parameters.length > 2 ? hardline : line - ] + separator: [',', line] }), ')' ]; diff --git a/src/slang-nodes/CallOptions.js b/src/slang-nodes/CallOptions.js index 1eaad1b40..2d85f6bbd 100644 --- a/src/slang-nodes/CallOptions.js +++ b/src/slang-nodes/CallOptions.js @@ -1,9 +1,15 @@ +import { doc } from 'prettier'; import { printSeparatedList } from '../common/printer-helpers.js'; +const { line, softline } = doc.builders; + export const CallOptions = { parse: ({ offsets, ast, options, parse }) => ({ items: ast.items.map((item) => parse(item, options, parse, offsets)), separators: ast.separators.map((separator) => separator.text) }), - print: ({ path, print }) => printSeparatedList(path.map(print, 'items')) + print: ({ path, print, options }) => + printSeparatedList(path.map(print, 'items'), { + firstSeparator: options.bracketSpacing ? line : softline + }) }; diff --git a/src/slang-nodes/CatchClause.js b/src/slang-nodes/CatchClause.js index 7cec9d289..22a29e829 100644 --- a/src/slang-nodes/CatchClause.js +++ b/src/slang-nodes/CatchClause.js @@ -5,8 +5,8 @@ export const CatchClause = { body: parse(ast.body, options, parse, offsets) }), print: ({ node, path, print }) => [ - node.catchKeyword, - node.error ? [' ', path.call(print, 'error')] : '', + `${node.catchKeyword} `, + node.error ? path.call(print, 'error') : '', path.call(print, 'body') ] }; diff --git a/src/slang-nodes/CatchClauseError.js b/src/slang-nodes/CatchClauseError.js index c6665c3a8..18f97430c 100644 --- a/src/slang-nodes/CatchClauseError.js +++ b/src/slang-nodes/CatchClauseError.js @@ -1,3 +1,7 @@ +import { doc } from 'prettier'; + +const { group } = doc.builders; + export const CatchClauseError = { parse: ({ offsets, ast, options, parse }) => ({ name: ast.name?.text, @@ -5,7 +9,7 @@ export const CatchClauseError = { }), print: ({ node, path, print }) => [ node.name ? node.name : '', - path.call(print, 'parameters'), + group(path.call(print, 'parameters')), ' ' ] }; diff --git a/src/slang-nodes/TryStatement.js b/src/slang-nodes/TryStatement.js index 1a7b14c52..466f86ef0 100644 --- a/src/slang-nodes/TryStatement.js +++ b/src/slang-nodes/TryStatement.js @@ -18,7 +18,7 @@ export const TryStatement = { printSeparatedItem(path.call(print, 'expression'), { firstSeparator: line }), - node.returns ? path.call(print, 'returns') : '', + node.returns ? [path.call(print, 'returns'), ' '] : '', path.call(print, 'body'), ' ', path.call(print, 'catchClauses') diff --git a/src/slang-nodes/VariableDeclarationStatement.js b/src/slang-nodes/VariableDeclarationStatement.js index 1dbda0c0e..80b56e8ec 100644 --- a/src/slang-nodes/VariableDeclarationStatement.js +++ b/src/slang-nodes/VariableDeclarationStatement.js @@ -1,3 +1,7 @@ +import { doc } from 'prettier'; + +const { group, indent } = doc.builders; + export const VariableDeclarationStatement = { parse: ({ offsets, ast, options, parse }) => ({ variableType: parse(ast.variableType, options, parse, offsets), @@ -9,9 +13,13 @@ export const VariableDeclarationStatement = { semicolon: ast.semicolon.text }), print: ({ node, path, print }) => [ - path.call(print, 'variableType'), - node.storageLocation ? [' ', path.call(print, 'storageLocation')] : '', - ` ${node.name}`, + group([ + path.call(print, 'variableType'), + indent([ + node.storageLocation ? [' ', path.call(print, 'storageLocation')] : '', + ` ${node.name}` + ]) + ]), node.value ? path.call(print, 'value') : '', node.semicolon ] diff --git a/src/slang-nodes/VersionExpressionSets.js b/src/slang-nodes/VersionExpressionSets.js index 7a75077df..dcab4810a 100644 --- a/src/slang-nodes/VersionExpressionSets.js +++ b/src/slang-nodes/VersionExpressionSets.js @@ -7,6 +7,6 @@ export const VersionExpressionSets = { path .map(print, 'items') .map((item, index) => - index === 0 ? item : [node.separators[index - 1], item] + index === 0 ? item : [` ${node.separators[index - 1]} `, item] ) }; diff --git a/src/slangPrinter.js b/src/slangPrinter.js index f85d1b8fc..84bed5449 100644 --- a/src/slangPrinter.js +++ b/src/slangPrinter.js @@ -1,8 +1,8 @@ import * as nodes from './slang-nodes/index.js'; import { - hasNodeIgnoreComment, prettierVersionSatisfies } from './common/util.js'; +import { hasNodeIgnoreComment } from './common/slang-helpers.js'; import ignoreComments from './comments/ignore.js'; let checked = false; @@ -60,7 +60,7 @@ function genericPrint(path, options, print) { return options.originalText.slice( options.locStart(node), - options.locEnd(node) + 1 + options.locEnd(node) ); } diff --git a/tests/config/format-test.js b/tests/config/format-test.js index 5bd82c6d3..64fb5a510 100644 --- a/tests/config/format-test.js +++ b/tests/config/format-test.js @@ -66,6 +66,62 @@ const testsWithSlang = new Map( "FunctionDefinitionsv0.5.0/FunctionDefinitions.sol", "HexLiteral/HexLiteral.sol", "IfStatements/IfStatements.sol", + "Immutable/Immutable.sol", + // "ImportDirective/ImportDirectives.sol", + "Inbox/Inbox.sol", + // "IndexOf/IndexOf.sol", + "IndexRangeAccess/IndexRangeAccess.sol", + "InheritanceSpecifier/InheritanceSpecifier.sol", + "Issues/Issue205.sol", + "Issues/Issue289.sol", + "Issues/Issue355.sol", + "Issues/Issue385.sol", + // "Issues/Issue564.sol", + "Issues/Issue799.sol", + "Issues/Issue843.sol", + "Libraries/Libraries.sol", + // "MemberAccess/MemberAccess.sol", + "ModifierDefinitions/ModifierDefinitions.sol", + // "ModifierInvocations/ModifierInvocations.sol", + "MultipartStrings/MultipartStrings.sol", + "NameValueExpression/NameValueExpression.sol", + "NumberLiteral/NumberLiteral.sol", + "Ownable/Ownable.sol", + "Parentheses/AddNoParentheses.sol", + "Parentheses/BitAndNoParentheses.sol", + "Parentheses/BitOrNoParentheses.sol", + "Parentheses/BitXorNoParentheses.sol", + "Parentheses/DivNoParentheses.sol", + "Parentheses/ExpNoParentheses.sol", + "Parentheses/LogicNoParentheses.sol", + "Parentheses/ModNoParentheses.sol", + "Parentheses/MulNoParentheses.sol", + "Parentheses/ShiftLNoParentheses.sol", + "Parentheses/ShiftRNoParentheses.sol", + "Parentheses/SubNoParentheses.sol", + "Pragma/Pragma.sol", + // "PrettierIgnore/PrettierIgnore.sol", + "Proxy/Proxy.sol", + "quotes/Quotes.sol", + "SampleCrowdsale/SampleCrowdsale.sol", + "SimpleAuction/SimpleAuction.sol", + "SimpleStorage/SimpleStorage.sol", + "SplittableCommodity/SplittableCommodity.sol", + "StateVariableDeclarations/StateVariableDeclarations.sol", + "StringLiteral/StringLiteral.sol", + "strings/strings.sol", + "StyleGuide/BlankLines.sol", + "StyleGuide/ControlStructures.sol", + "StyleGuide/FunctionDeclaration.sol", + "StyleGuide/Mappings.sol", + "StyleGuide/MaximumLineLength.sol", + "StyleGuide/OtherRecommendations.sol", + "StyleGuide/VariableDeclarations.sol", + "StyleGuide/WhitespaceInExpressions.sol", + "TryCatch/TryCatch.sol", + "Tupples/Tupples.sol", + "TypeDefinition/TypeDefinition.sol", + "WhileStatements/WhileStatements.sol", ].map((fixture) => { const [file, testSlang = () => true] = Array.isArray(fixture) ? fixture @@ -332,6 +388,22 @@ async function runTest({ }) ).toMatchSnapshot(); + if (shouldTestSlang(filename, formatOptions)) { + const { input, output } = formatResult; + const slangOptions = { + ...formatOptions, + parser: "slang", + }; + console.log(filename); + const prettier = await getPrettier(); + const slangOutput = await prettier.format(input, slangOptions); + + // const slangOutput2 = await prettier.format(output, slangOptions); + + expect(slangOutput).toEqual(output); + // expect(slangOutput2).toEqual(output); + } + if (!FULL_TEST) { return; } @@ -396,23 +468,6 @@ async function runTest({ expect(output).toEqual(expected); } - if (shouldTestSlang(filename, formatOptions)) { - const { input, output } = formatResult; - const prettier = await getPrettier(); - const slangOutput = await prettier.format(input, { - ...formatOptions, - parser: "slang", - }); - - // const slangOutput2 = await prettier.format(output, { - // ...formatOptions, - // parser: "slang", - // }); - - expect(slangOutput).toEqual(output); - // expect(slangOutput2).toEqual(output); - } - if (shouldCompareBytecode(filename, formatOptions)) { const output = compileContract(filename, formatResult.output); const expected = compileContract(filename, formatResult.input); diff --git a/tests/format/ModifierDefinitions/__snapshots__/jsfmt.spec.js.snap b/tests/format/ModifierDefinitions/__snapshots__/jsfmt.spec.js.snap index ffe001f38..2f827fb5b 100644 --- a/tests/format/ModifierDefinitions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/ModifierDefinitions/__snapshots__/jsfmt.spec.js.snap @@ -20,11 +20,7 @@ contract ModifierDefinitions { modifier noParams() {} modifier oneParam(uint a) {} modifier twoParams(uint a, uint b) {} - modifier threeParams( - uint a, - uint b, - uint c - ) {} + modifier threeParams(uint a, uint b, uint c) {} modifier test() virtual; modifier test() virtual {} } diff --git a/tests/format/MultipartStrings/__snapshots__/jsfmt.spec.js.snap b/tests/format/MultipartStrings/__snapshots__/jsfmt.spec.js.snap index 72f515f66..dc49ffb49 100644 --- a/tests/format/MultipartStrings/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/MultipartStrings/__snapshots__/jsfmt.spec.js.snap @@ -21,7 +21,9 @@ contract MultipartStrings { contract MultipartStrings { bytes b1 = hex"beef"; bytes b2 = hex"beef"; - bytes b3 = hex"beef" hex"c0ffee"; + bytes b3 = + hex"beef" + hex"c0ffee"; bytes b4 = hex"beeeeeeeeeeeeeeeeeeeeeef" hex"c0000000000ffeeeeeeeeeeeeeeeeeee"; diff --git a/tests/format/Proxy/__snapshots__/jsfmt.spec.js.snap b/tests/format/Proxy/__snapshots__/jsfmt.spec.js.snap index 41521a072..4f2521020 100644 --- a/tests/format/Proxy/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Proxy/__snapshots__/jsfmt.spec.js.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Proxy.sol format 1`] = ` +exports[`Proxy.sol - {"compiler":"0.4.24"} format 1`] = ` ====================================options===================================== +compiler: "0.4.24" parsers: ["solidity-parse"] printWidth: 80 | printWidth diff --git a/tests/format/Proxy/jsfmt.spec.js b/tests/format/Proxy/jsfmt.spec.js index 765dd60a6..daacfb24c 100644 --- a/tests/format/Proxy/jsfmt.spec.js +++ b/tests/format/Proxy/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse'], { compiler: '0.4.24' }); diff --git a/tests/format/StyleGuide/jsfmt.spec.js b/tests/format/StyleGuide/jsfmt.spec.js index 765dd60a6..417487a97 100644 --- a/tests/format/StyleGuide/jsfmt.spec.js +++ b/tests/format/StyleGuide/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse'], { compiler: '0.5.0' }); From a1196ddbdf7f0bbc6c02c3dac96e71bfe6d82721 Mon Sep 17 00:00:00 2001 From: Klaus Date: Tue, 9 Jul 2024 13:48:28 +1200 Subject: [PATCH 054/160] Using slang as the main parser on all passing tests --- tests/config/format-test.js | 65 +------------------ .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/AddressPayable/jsfmt.spec.js | 2 +- .../Arrays/__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/Arrays/jsfmt.spec.js | 2 +- .../Assembly/__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/Assembly/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 4 +- tests/format/BinaryOperators/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 12 ++-- .../BreakingChangesV0.7.4/jsfmt.spec.js | 20 ++---- .../__snapshots__/jsfmt.spec.js.snap | 2 +- .../BreakingChangesV0.8.0/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/Conditional/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/Constructors/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- .../format/ContractDefinitions/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/CustomErrors/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/EnumDefinitions/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/ForStatements/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 4 +- tests/format/FunctionCalls/jsfmt.spec.js | 4 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- .../FunctionDefinitionsv0.5.0/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 4 +- tests/format/HexLiteral/jsfmt.spec.js | 4 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/IfStatements/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/Immutable/jsfmt.spec.js | 2 +- .../Inbox/__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/Inbox/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/IndexRangeAccess/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- .../format/InheritanceSpecifier/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 4 +- tests/format/Libraries/jsfmt.spec.js | 4 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- .../format/ModifierDefinitions/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/MultipartStrings/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 4 +- .../format/NameValueExpression/jsfmt.spec.js | 4 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/NumberLiteral/jsfmt.spec.js | 2 +- .../Ownable/__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/Ownable/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 24 +++---- tests/format/Parentheses/jsfmt.spec.js | 2 +- .../Pragma/__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/Pragma/jsfmt.spec.js | 2 +- .../Proxy/__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/Proxy/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/SampleCrowdsale/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/SimpleAuction/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/SimpleStorage/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- .../format/SplittableCommodity/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- .../StateVariableDeclarations/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/StringLiteral/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 40 +++++++----- tests/format/StyleGuide/jsfmt.spec.js | 2 +- .../TryCatch/__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/TryCatch/jsfmt.spec.js | 2 +- .../Tupples/__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/Tupples/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/TypeDefinition/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/WhileStatements/jsfmt.spec.js | 2 +- .../quotes/__snapshots__/jsfmt.spec.js.snap | 4 +- tests/format/quotes/jsfmt.spec.js | 4 +- .../strings/__snapshots__/jsfmt.spec.js.snap | 2 +- tests/format/strings/jsfmt.spec.js | 2 +- 85 files changed, 140 insertions(+), 203 deletions(-) diff --git a/tests/config/format-test.js b/tests/config/format-test.js index 64fb5a510..8bd7696dd 100644 --- a/tests/config/format-test.js +++ b/tests/config/format-test.js @@ -40,38 +40,15 @@ const unstableAstTests = new Map( const testsWithSlang = new Map( [ - "AddressPayable/AddressPayable.sol", - "Arrays/Arrays.sol", - "Assembly/Assembly.sol", + // "AllSolidityFeatures/AllSolidityFeatures.sol", // "AssemblyV0.4.26/Assembly.sol", // "BasicIterator/BasicIterator.sol", - "BinaryOperators/BinaryOperators.sol", - "BinaryOperators/Parentheses.sol", - "BreakingChangesV0.7.4/BreakingChangesV0.7.4.sol", - [ - "BreakingChangesV0.8.0/BreakingChangesV0.8.0.sol", - (options) => options.compiler === "0.7.0", - ], // "Comments/Comments.sol", - "Conditional/Conditional.sol", - "Constructors/Constructors.sol", - "ContractDefinitions/ContractDefinitions.sol", - "CustomErrors/CustomErrors.sol", - "EnumDefinitions/EnumDefinitions.sol", // "Etc/Etc.sol", // "ExperimentalTernaries/ExperimentalTernaries.sol", // TODO: fix this one - "ForStatements/ForStatements.sol", - "FunctionCalls/FunctionCalls.sol", // "FunctionDefinitions/FunctionDefinitions.sol", - "FunctionDefinitionsv0.5.0/FunctionDefinitions.sol", - "HexLiteral/HexLiteral.sol", - "IfStatements/IfStatements.sol", - "Immutable/Immutable.sol", // "ImportDirective/ImportDirectives.sol", - "Inbox/Inbox.sol", // "IndexOf/IndexOf.sol", - "IndexRangeAccess/IndexRangeAccess.sol", - "InheritanceSpecifier/InheritanceSpecifier.sol", "Issues/Issue205.sol", "Issues/Issue289.sol", "Issues/Issue355.sol", @@ -79,49 +56,9 @@ const testsWithSlang = new Map( // "Issues/Issue564.sol", "Issues/Issue799.sol", "Issues/Issue843.sol", - "Libraries/Libraries.sol", // "MemberAccess/MemberAccess.sol", - "ModifierDefinitions/ModifierDefinitions.sol", // "ModifierInvocations/ModifierInvocations.sol", - "MultipartStrings/MultipartStrings.sol", - "NameValueExpression/NameValueExpression.sol", - "NumberLiteral/NumberLiteral.sol", - "Ownable/Ownable.sol", - "Parentheses/AddNoParentheses.sol", - "Parentheses/BitAndNoParentheses.sol", - "Parentheses/BitOrNoParentheses.sol", - "Parentheses/BitXorNoParentheses.sol", - "Parentheses/DivNoParentheses.sol", - "Parentheses/ExpNoParentheses.sol", - "Parentheses/LogicNoParentheses.sol", - "Parentheses/ModNoParentheses.sol", - "Parentheses/MulNoParentheses.sol", - "Parentheses/ShiftLNoParentheses.sol", - "Parentheses/ShiftRNoParentheses.sol", - "Parentheses/SubNoParentheses.sol", - "Pragma/Pragma.sol", // "PrettierIgnore/PrettierIgnore.sol", - "Proxy/Proxy.sol", - "quotes/Quotes.sol", - "SampleCrowdsale/SampleCrowdsale.sol", - "SimpleAuction/SimpleAuction.sol", - "SimpleStorage/SimpleStorage.sol", - "SplittableCommodity/SplittableCommodity.sol", - "StateVariableDeclarations/StateVariableDeclarations.sol", - "StringLiteral/StringLiteral.sol", - "strings/strings.sol", - "StyleGuide/BlankLines.sol", - "StyleGuide/ControlStructures.sol", - "StyleGuide/FunctionDeclaration.sol", - "StyleGuide/Mappings.sol", - "StyleGuide/MaximumLineLength.sol", - "StyleGuide/OtherRecommendations.sol", - "StyleGuide/VariableDeclarations.sol", - "StyleGuide/WhitespaceInExpressions.sol", - "TryCatch/TryCatch.sol", - "Tupples/Tupples.sol", - "TypeDefinition/TypeDefinition.sol", - "WhileStatements/WhileStatements.sol", ].map((fixture) => { const [file, testSlang = () => true] = Array.isArray(fixture) ? fixture diff --git a/tests/format/AddressPayable/__snapshots__/jsfmt.spec.js.snap b/tests/format/AddressPayable/__snapshots__/jsfmt.spec.js.snap index df021991a..b9c5fbd2a 100644 --- a/tests/format/AddressPayable/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/AddressPayable/__snapshots__/jsfmt.spec.js.snap @@ -2,7 +2,7 @@ exports[`AddressPayable.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/AddressPayable/jsfmt.spec.js b/tests/format/AddressPayable/jsfmt.spec.js index 765dd60a6..418f6872d 100644 --- a/tests/format/AddressPayable/jsfmt.spec.js +++ b/tests/format/AddressPayable/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/Arrays/__snapshots__/jsfmt.spec.js.snap b/tests/format/Arrays/__snapshots__/jsfmt.spec.js.snap index 8eb3ca39b..a9f96f9b8 100644 --- a/tests/format/Arrays/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Arrays/__snapshots__/jsfmt.spec.js.snap @@ -2,7 +2,7 @@ exports[`Arrays.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/Arrays/jsfmt.spec.js b/tests/format/Arrays/jsfmt.spec.js index 765dd60a6..418f6872d 100644 --- a/tests/format/Arrays/jsfmt.spec.js +++ b/tests/format/Arrays/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/Assembly/__snapshots__/jsfmt.spec.js.snap b/tests/format/Assembly/__snapshots__/jsfmt.spec.js.snap index 41a84ad3b..945feb270 100644 --- a/tests/format/Assembly/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Assembly/__snapshots__/jsfmt.spec.js.snap @@ -2,7 +2,7 @@ exports[`Assembly.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/Assembly/jsfmt.spec.js b/tests/format/Assembly/jsfmt.spec.js index 765dd60a6..418f6872d 100644 --- a/tests/format/Assembly/jsfmt.spec.js +++ b/tests/format/Assembly/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/BinaryOperators/__snapshots__/jsfmt.spec.js.snap b/tests/format/BinaryOperators/__snapshots__/jsfmt.spec.js.snap index f3c990af5..455ea4985 100644 --- a/tests/format/BinaryOperators/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/BinaryOperators/__snapshots__/jsfmt.spec.js.snap @@ -3,7 +3,7 @@ exports[`BinaryOperators.sol - {"compiler":"0.5.8"} format 1`] = ` ====================================options===================================== compiler: "0.5.8" -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -689,7 +689,7 @@ contract LogicalOperators { exports[`Parentheses.sol - {"compiler":"0.5.8"} format 1`] = ` ====================================options===================================== compiler: "0.5.8" -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/BinaryOperators/jsfmt.spec.js b/tests/format/BinaryOperators/jsfmt.spec.js index 946858815..2845e66fa 100644 --- a/tests/format/BinaryOperators/jsfmt.spec.js +++ b/tests/format/BinaryOperators/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse'], { compiler: '0.5.8' }); +run_spec(import.meta, ['slang'], { compiler: '0.5.8' }); diff --git a/tests/format/BreakingChangesV0.7.4/__snapshots__/jsfmt.spec.js.snap b/tests/format/BreakingChangesV0.7.4/__snapshots__/jsfmt.spec.js.snap index bf7c7307e..59db4e354 100644 --- a/tests/format/BreakingChangesV0.7.4/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/BreakingChangesV0.7.4/__snapshots__/jsfmt.spec.js.snap @@ -3,7 +3,7 @@ exports[`BreakingChangesV0.7.4.sol - {"bracketSpacing":true} format 1`] = ` ====================================options===================================== bracketSpacing: true -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -35,7 +35,7 @@ exports[`BreakingChangesV0.7.4.sol - {"compiler":"0.7.3","bracketSpacing":true} ====================================options===================================== bracketSpacing: true compiler: "0.7.3" -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -66,7 +66,7 @@ import { symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4 } from exports[`BreakingChangesV0.7.4.sol - {"compiler":"0.7.3"} format 1`] = ` ====================================options===================================== compiler: "0.7.3" -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -98,7 +98,7 @@ exports[`BreakingChangesV0.7.4.sol - {"compiler":"0.7.4","bracketSpacing":true} ====================================options===================================== bracketSpacing: true compiler: "0.7.4" -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -134,7 +134,7 @@ import { exports[`BreakingChangesV0.7.4.sol - {"compiler":"0.7.4"} format 1`] = ` ====================================options===================================== compiler: "0.7.4" -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -169,7 +169,7 @@ import { exports[`BreakingChangesV0.7.4.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/BreakingChangesV0.7.4/jsfmt.spec.js b/tests/format/BreakingChangesV0.7.4/jsfmt.spec.js index b64637462..5570c0e9d 100644 --- a/tests/format/BreakingChangesV0.7.4/jsfmt.spec.js +++ b/tests/format/BreakingChangesV0.7.4/jsfmt.spec.js @@ -1,14 +1,6 @@ -run_spec(import.meta, ['solidity-parse'], { compiler: '0.7.4' }); -run_spec(import.meta, ['solidity-parse'], { - compiler: '0.7.4', - bracketSpacing: true -}); -run_spec(import.meta, ['solidity-parse'], { compiler: '0.7.3' }); -run_spec(import.meta, ['solidity-parse'], { - compiler: '0.7.3', - bracketSpacing: true -}); -run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-parse'], { - bracketSpacing: true -}); +run_spec(import.meta, ['slang'], { compiler: '0.7.4' }); +run_spec(import.meta, ['slang'], { compiler: '0.7.4', bracketSpacing: true }); +run_spec(import.meta, ['slang'], { compiler: '0.7.3' }); +run_spec(import.meta, ['slang'], { compiler: '0.7.3', bracketSpacing: true }); +run_spec(import.meta, ['slang']); +run_spec(import.meta, ['slang'], { bracketSpacing: true }); diff --git a/tests/format/BreakingChangesV0.8.0/__snapshots__/jsfmt.spec.js.snap b/tests/format/BreakingChangesV0.8.0/__snapshots__/jsfmt.spec.js.snap index 1c4a0278d..cad378b63 100644 --- a/tests/format/BreakingChangesV0.8.0/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/BreakingChangesV0.8.0/__snapshots__/jsfmt.spec.js.snap @@ -3,7 +3,7 @@ exports[`BreakingChangesV0.8.0.sol - {"compiler":"0.7.0"} format 1`] = ` ====================================options===================================== compiler: "0.7.0" -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/BreakingChangesV0.8.0/jsfmt.spec.js b/tests/format/BreakingChangesV0.8.0/jsfmt.spec.js index 037d673ba..082b7093e 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(import.meta, ['solidity-parse']); run_spec(import.meta, ['solidity-parse'], { compiler: '0.8.0' }); -run_spec(import.meta, ['solidity-parse'], { compiler: '0.7.0' }); +run_spec(import.meta, ['slang'], { compiler: '0.7.0' }); diff --git a/tests/format/Conditional/__snapshots__/jsfmt.spec.js.snap b/tests/format/Conditional/__snapshots__/jsfmt.spec.js.snap index e74eccfaf..7aa465d6f 100644 --- a/tests/format/Conditional/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Conditional/__snapshots__/jsfmt.spec.js.snap @@ -2,7 +2,7 @@ exports[`Conditional.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/Conditional/jsfmt.spec.js b/tests/format/Conditional/jsfmt.spec.js index 765dd60a6..418f6872d 100644 --- a/tests/format/Conditional/jsfmt.spec.js +++ b/tests/format/Conditional/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/Constructors/__snapshots__/jsfmt.spec.js.snap b/tests/format/Constructors/__snapshots__/jsfmt.spec.js.snap index 08733dfa7..a6a29e947 100644 --- a/tests/format/Constructors/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Constructors/__snapshots__/jsfmt.spec.js.snap @@ -2,7 +2,7 @@ exports[`Constructors.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/Constructors/jsfmt.spec.js b/tests/format/Constructors/jsfmt.spec.js index 765dd60a6..418f6872d 100644 --- a/tests/format/Constructors/jsfmt.spec.js +++ b/tests/format/Constructors/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/ContractDefinitions/__snapshots__/jsfmt.spec.js.snap b/tests/format/ContractDefinitions/__snapshots__/jsfmt.spec.js.snap index 1621683a4..0e8ec3b52 100644 --- a/tests/format/ContractDefinitions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/ContractDefinitions/__snapshots__/jsfmt.spec.js.snap @@ -2,7 +2,7 @@ exports[`ContractDefinitions.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/ContractDefinitions/jsfmt.spec.js b/tests/format/ContractDefinitions/jsfmt.spec.js index 765dd60a6..418f6872d 100644 --- a/tests/format/ContractDefinitions/jsfmt.spec.js +++ b/tests/format/ContractDefinitions/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/CustomErrors/__snapshots__/jsfmt.spec.js.snap b/tests/format/CustomErrors/__snapshots__/jsfmt.spec.js.snap index 85f94cb7f..3afb775a2 100644 --- a/tests/format/CustomErrors/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/CustomErrors/__snapshots__/jsfmt.spec.js.snap @@ -2,7 +2,7 @@ exports[`CustomErrors.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/CustomErrors/jsfmt.spec.js b/tests/format/CustomErrors/jsfmt.spec.js index 765dd60a6..418f6872d 100644 --- a/tests/format/CustomErrors/jsfmt.spec.js +++ b/tests/format/CustomErrors/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/EnumDefinitions/__snapshots__/jsfmt.spec.js.snap b/tests/format/EnumDefinitions/__snapshots__/jsfmt.spec.js.snap index 64735676e..db46c7ea9 100644 --- a/tests/format/EnumDefinitions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/EnumDefinitions/__snapshots__/jsfmt.spec.js.snap @@ -2,7 +2,7 @@ exports[`EnumDefinitions.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/EnumDefinitions/jsfmt.spec.js b/tests/format/EnumDefinitions/jsfmt.spec.js index 765dd60a6..418f6872d 100644 --- a/tests/format/EnumDefinitions/jsfmt.spec.js +++ b/tests/format/EnumDefinitions/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/ForStatements/__snapshots__/jsfmt.spec.js.snap b/tests/format/ForStatements/__snapshots__/jsfmt.spec.js.snap index fa6d0e014..adfb5b037 100644 --- a/tests/format/ForStatements/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/ForStatements/__snapshots__/jsfmt.spec.js.snap @@ -2,7 +2,7 @@ exports[`ForStatements.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/ForStatements/jsfmt.spec.js b/tests/format/ForStatements/jsfmt.spec.js index 765dd60a6..418f6872d 100644 --- a/tests/format/ForStatements/jsfmt.spec.js +++ b/tests/format/ForStatements/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/FunctionCalls/__snapshots__/jsfmt.spec.js.snap b/tests/format/FunctionCalls/__snapshots__/jsfmt.spec.js.snap index 5e5db2ab9..083931c84 100644 --- a/tests/format/FunctionCalls/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/FunctionCalls/__snapshots__/jsfmt.spec.js.snap @@ -3,7 +3,7 @@ exports[`FunctionCalls.sol - {"bracketSpacing":true} format 1`] = ` ====================================options===================================== bracketSpacing: true -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -155,7 +155,7 @@ contract FunctionCalls { exports[`FunctionCalls.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/FunctionCalls/jsfmt.spec.js b/tests/format/FunctionCalls/jsfmt.spec.js index 993a81764..297dfaa0d 100644 --- a/tests/format/FunctionCalls/jsfmt.spec.js +++ b/tests/format/FunctionCalls/jsfmt.spec.js @@ -1,2 +1,2 @@ -run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-parse'], { bracketSpacing: true }); +run_spec(import.meta, ['slang']); +run_spec(import.meta, ['slang'], { bracketSpacing: true }); diff --git a/tests/format/FunctionDefinitionsv0.5.0/__snapshots__/jsfmt.spec.js.snap b/tests/format/FunctionDefinitionsv0.5.0/__snapshots__/jsfmt.spec.js.snap index 095be0b0f..00fd9faeb 100644 --- a/tests/format/FunctionDefinitionsv0.5.0/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/FunctionDefinitionsv0.5.0/__snapshots__/jsfmt.spec.js.snap @@ -3,7 +3,7 @@ exports[`FunctionDefinitions.sol - {"compiler":"0.5.0"} format 1`] = ` ====================================options===================================== compiler: "0.5.0" -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/FunctionDefinitionsv0.5.0/jsfmt.spec.js b/tests/format/FunctionDefinitionsv0.5.0/jsfmt.spec.js index 417487a97..50eb2964b 100644 --- a/tests/format/FunctionDefinitionsv0.5.0/jsfmt.spec.js +++ b/tests/format/FunctionDefinitionsv0.5.0/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse'], { compiler: '0.5.0' }); +run_spec(import.meta, ['slang'], { compiler: '0.5.0' }); diff --git a/tests/format/HexLiteral/__snapshots__/jsfmt.spec.js.snap b/tests/format/HexLiteral/__snapshots__/jsfmt.spec.js.snap index 8ae334be2..f0fc48cb5 100644 --- a/tests/format/HexLiteral/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/HexLiteral/__snapshots__/jsfmt.spec.js.snap @@ -2,7 +2,7 @@ exports[`HexLiteral.sol - {"singleQuote":false} format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 singleQuote: false | printWidth @@ -29,7 +29,7 @@ contract HexLiteral { exports[`HexLiteral.sol - {"singleQuote":true} format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 singleQuote: true | printWidth diff --git a/tests/format/HexLiteral/jsfmt.spec.js b/tests/format/HexLiteral/jsfmt.spec.js index 3272026cc..30121cb5f 100644 --- a/tests/format/HexLiteral/jsfmt.spec.js +++ b/tests/format/HexLiteral/jsfmt.spec.js @@ -1,2 +1,2 @@ -run_spec(import.meta, ['solidity-parse'], { singleQuote: true }); -run_spec(import.meta, ['solidity-parse'], { singleQuote: false }); +run_spec(import.meta, ['slang'], { singleQuote: true }); +run_spec(import.meta, ['slang'], { singleQuote: false }); diff --git a/tests/format/IfStatements/__snapshots__/jsfmt.spec.js.snap b/tests/format/IfStatements/__snapshots__/jsfmt.spec.js.snap index 7ef36a99a..d3095bdd2 100644 --- a/tests/format/IfStatements/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/IfStatements/__snapshots__/jsfmt.spec.js.snap @@ -2,7 +2,7 @@ exports[`IfStatements.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/IfStatements/jsfmt.spec.js b/tests/format/IfStatements/jsfmt.spec.js index 765dd60a6..418f6872d 100644 --- a/tests/format/IfStatements/jsfmt.spec.js +++ b/tests/format/IfStatements/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/Immutable/__snapshots__/jsfmt.spec.js.snap b/tests/format/Immutable/__snapshots__/jsfmt.spec.js.snap index 373e42afc..fd51e8314 100644 --- a/tests/format/Immutable/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Immutable/__snapshots__/jsfmt.spec.js.snap @@ -2,7 +2,7 @@ exports[`Immutable.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/Immutable/jsfmt.spec.js b/tests/format/Immutable/jsfmt.spec.js index 765dd60a6..418f6872d 100644 --- a/tests/format/Immutable/jsfmt.spec.js +++ b/tests/format/Immutable/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/Inbox/__snapshots__/jsfmt.spec.js.snap b/tests/format/Inbox/__snapshots__/jsfmt.spec.js.snap index 7ecbcae24..11fd276da 100644 --- a/tests/format/Inbox/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Inbox/__snapshots__/jsfmt.spec.js.snap @@ -2,7 +2,7 @@ exports[`Inbox.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/Inbox/jsfmt.spec.js b/tests/format/Inbox/jsfmt.spec.js index 765dd60a6..418f6872d 100644 --- a/tests/format/Inbox/jsfmt.spec.js +++ b/tests/format/Inbox/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/IndexRangeAccess/__snapshots__/jsfmt.spec.js.snap b/tests/format/IndexRangeAccess/__snapshots__/jsfmt.spec.js.snap index acc351b87..950524997 100644 --- a/tests/format/IndexRangeAccess/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/IndexRangeAccess/__snapshots__/jsfmt.spec.js.snap @@ -2,7 +2,7 @@ exports[`IndexRangeAccess.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/IndexRangeAccess/jsfmt.spec.js b/tests/format/IndexRangeAccess/jsfmt.spec.js index 765dd60a6..418f6872d 100644 --- a/tests/format/IndexRangeAccess/jsfmt.spec.js +++ b/tests/format/IndexRangeAccess/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/InheritanceSpecifier/__snapshots__/jsfmt.spec.js.snap b/tests/format/InheritanceSpecifier/__snapshots__/jsfmt.spec.js.snap index c95f10839..5ff4065fb 100644 --- a/tests/format/InheritanceSpecifier/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/InheritanceSpecifier/__snapshots__/jsfmt.spec.js.snap @@ -2,7 +2,7 @@ exports[`InheritanceSpecifier.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/InheritanceSpecifier/jsfmt.spec.js b/tests/format/InheritanceSpecifier/jsfmt.spec.js index 765dd60a6..418f6872d 100644 --- a/tests/format/InheritanceSpecifier/jsfmt.spec.js +++ b/tests/format/InheritanceSpecifier/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/Libraries/__snapshots__/jsfmt.spec.js.snap b/tests/format/Libraries/__snapshots__/jsfmt.spec.js.snap index 35b6b0e6b..3a44c27e4 100644 --- a/tests/format/Libraries/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Libraries/__snapshots__/jsfmt.spec.js.snap @@ -3,7 +3,7 @@ exports[`Libraries.sol - {"bracketSpacing":true} format 1`] = ` ====================================options===================================== bracketSpacing: true -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -55,7 +55,7 @@ using { exports[`Libraries.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/Libraries/jsfmt.spec.js b/tests/format/Libraries/jsfmt.spec.js index 993a81764..297dfaa0d 100644 --- a/tests/format/Libraries/jsfmt.spec.js +++ b/tests/format/Libraries/jsfmt.spec.js @@ -1,2 +1,2 @@ -run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-parse'], { bracketSpacing: true }); +run_spec(import.meta, ['slang']); +run_spec(import.meta, ['slang'], { bracketSpacing: true }); diff --git a/tests/format/ModifierDefinitions/__snapshots__/jsfmt.spec.js.snap b/tests/format/ModifierDefinitions/__snapshots__/jsfmt.spec.js.snap index 2f827fb5b..9ee03fde6 100644 --- a/tests/format/ModifierDefinitions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/ModifierDefinitions/__snapshots__/jsfmt.spec.js.snap @@ -2,7 +2,7 @@ exports[`ModifierDefinitions.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/ModifierDefinitions/jsfmt.spec.js b/tests/format/ModifierDefinitions/jsfmt.spec.js index 765dd60a6..418f6872d 100644 --- a/tests/format/ModifierDefinitions/jsfmt.spec.js +++ b/tests/format/ModifierDefinitions/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/MultipartStrings/__snapshots__/jsfmt.spec.js.snap b/tests/format/MultipartStrings/__snapshots__/jsfmt.spec.js.snap index dc49ffb49..65f5b3dbc 100644 --- a/tests/format/MultipartStrings/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/MultipartStrings/__snapshots__/jsfmt.spec.js.snap @@ -2,7 +2,7 @@ exports[`MultipartStrings.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/MultipartStrings/jsfmt.spec.js b/tests/format/MultipartStrings/jsfmt.spec.js index 765dd60a6..418f6872d 100644 --- a/tests/format/MultipartStrings/jsfmt.spec.js +++ b/tests/format/MultipartStrings/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/NameValueExpression/__snapshots__/jsfmt.spec.js.snap b/tests/format/NameValueExpression/__snapshots__/jsfmt.spec.js.snap index 7bb12c9a8..e40012c95 100644 --- a/tests/format/NameValueExpression/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/NameValueExpression/__snapshots__/jsfmt.spec.js.snap @@ -3,7 +3,7 @@ exports[`NameValueExpression.sol - {"bracketSpacing":true} format 1`] = ` ====================================options===================================== bracketSpacing: true -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -35,7 +35,7 @@ contract NameValueExpression { exports[`NameValueExpression.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/NameValueExpression/jsfmt.spec.js b/tests/format/NameValueExpression/jsfmt.spec.js index 993a81764..297dfaa0d 100644 --- a/tests/format/NameValueExpression/jsfmt.spec.js +++ b/tests/format/NameValueExpression/jsfmt.spec.js @@ -1,2 +1,2 @@ -run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-parse'], { bracketSpacing: true }); +run_spec(import.meta, ['slang']); +run_spec(import.meta, ['slang'], { bracketSpacing: true }); diff --git a/tests/format/NumberLiteral/__snapshots__/jsfmt.spec.js.snap b/tests/format/NumberLiteral/__snapshots__/jsfmt.spec.js.snap index 3392a346a..1bb8bcd55 100644 --- a/tests/format/NumberLiteral/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/NumberLiteral/__snapshots__/jsfmt.spec.js.snap @@ -2,7 +2,7 @@ exports[`NumberLiteral.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/NumberLiteral/jsfmt.spec.js b/tests/format/NumberLiteral/jsfmt.spec.js index 765dd60a6..418f6872d 100644 --- a/tests/format/NumberLiteral/jsfmt.spec.js +++ b/tests/format/NumberLiteral/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/Ownable/__snapshots__/jsfmt.spec.js.snap b/tests/format/Ownable/__snapshots__/jsfmt.spec.js.snap index a6a2b3930..5cfe91c64 100644 --- a/tests/format/Ownable/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Ownable/__snapshots__/jsfmt.spec.js.snap @@ -2,7 +2,7 @@ exports[`Ownable.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/Ownable/jsfmt.spec.js b/tests/format/Ownable/jsfmt.spec.js index 765dd60a6..418f6872d 100644 --- a/tests/format/Ownable/jsfmt.spec.js +++ b/tests/format/Ownable/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/Parentheses/__snapshots__/jsfmt.spec.js.snap b/tests/format/Parentheses/__snapshots__/jsfmt.spec.js.snap index 098c17a55..5e54f4832 100644 --- a/tests/format/Parentheses/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Parentheses/__snapshots__/jsfmt.spec.js.snap @@ -3,7 +3,7 @@ exports[`AddNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -200,7 +200,7 @@ contract AddNoParentheses { exports[`BitAndNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -397,7 +397,7 @@ contract BitAndNoParentheses { exports[`BitOrNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -594,7 +594,7 @@ contract BitOrNoParentheses { exports[`BitXorNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -791,7 +791,7 @@ contract BitXorNoParentheses { exports[`DivNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -988,7 +988,7 @@ contract DivNoParentheses { exports[`ExpNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -1185,7 +1185,7 @@ contract ExpNoParentheses { exports[`LogicNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -1238,7 +1238,7 @@ contract LogicNoParentheses { exports[`ModNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -1435,7 +1435,7 @@ contract ModNoParentheses { exports[`MulNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -1632,7 +1632,7 @@ contract MulNoParentheses { exports[`ShiftLNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -1829,7 +1829,7 @@ contract ShiftLNoParentheses { exports[`ShiftRNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -2026,7 +2026,7 @@ contract ShiftRNoParentheses { exports[`SubNoParentheses.sol - {"compiler":"0.8.6"} format 1`] = ` ====================================options===================================== compiler: "0.8.6" -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/Parentheses/jsfmt.spec.js b/tests/format/Parentheses/jsfmt.spec.js index 8c772cba0..15e75e6c2 100644 --- a/tests/format/Parentheses/jsfmt.spec.js +++ b/tests/format/Parentheses/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse'], { compiler: '0.8.6' }); +run_spec(import.meta, ['slang'], { compiler: '0.8.6' }); diff --git a/tests/format/Pragma/__snapshots__/jsfmt.spec.js.snap b/tests/format/Pragma/__snapshots__/jsfmt.spec.js.snap index 5971506a0..69e0101b1 100644 --- a/tests/format/Pragma/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Pragma/__snapshots__/jsfmt.spec.js.snap @@ -2,7 +2,7 @@ exports[`Pragma.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/Pragma/jsfmt.spec.js b/tests/format/Pragma/jsfmt.spec.js index 765dd60a6..418f6872d 100644 --- a/tests/format/Pragma/jsfmt.spec.js +++ b/tests/format/Pragma/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/Proxy/__snapshots__/jsfmt.spec.js.snap b/tests/format/Proxy/__snapshots__/jsfmt.spec.js.snap index 4f2521020..e13dd43b5 100644 --- a/tests/format/Proxy/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Proxy/__snapshots__/jsfmt.spec.js.snap @@ -3,7 +3,7 @@ exports[`Proxy.sol - {"compiler":"0.4.24"} format 1`] = ` ====================================options===================================== compiler: "0.4.24" -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/Proxy/jsfmt.spec.js b/tests/format/Proxy/jsfmt.spec.js index daacfb24c..8915712ba 100644 --- a/tests/format/Proxy/jsfmt.spec.js +++ b/tests/format/Proxy/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse'], { compiler: '0.4.24' }); +run_spec(import.meta, ['slang'], { compiler: '0.4.24' }); diff --git a/tests/format/SampleCrowdsale/__snapshots__/jsfmt.spec.js.snap b/tests/format/SampleCrowdsale/__snapshots__/jsfmt.spec.js.snap index 733a7d384..ceb4670d3 100644 --- a/tests/format/SampleCrowdsale/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/SampleCrowdsale/__snapshots__/jsfmt.spec.js.snap @@ -2,7 +2,7 @@ exports[`SampleCrowdsale.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/SampleCrowdsale/jsfmt.spec.js b/tests/format/SampleCrowdsale/jsfmt.spec.js index 765dd60a6..418f6872d 100644 --- a/tests/format/SampleCrowdsale/jsfmt.spec.js +++ b/tests/format/SampleCrowdsale/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/SimpleAuction/__snapshots__/jsfmt.spec.js.snap b/tests/format/SimpleAuction/__snapshots__/jsfmt.spec.js.snap index d980d9c1a..bf2c8db47 100644 --- a/tests/format/SimpleAuction/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/SimpleAuction/__snapshots__/jsfmt.spec.js.snap @@ -2,7 +2,7 @@ exports[`SimpleAuction.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/SimpleAuction/jsfmt.spec.js b/tests/format/SimpleAuction/jsfmt.spec.js index 765dd60a6..418f6872d 100644 --- a/tests/format/SimpleAuction/jsfmt.spec.js +++ b/tests/format/SimpleAuction/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/SimpleStorage/__snapshots__/jsfmt.spec.js.snap b/tests/format/SimpleStorage/__snapshots__/jsfmt.spec.js.snap index ab685ce2d..db687b891 100644 --- a/tests/format/SimpleStorage/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/SimpleStorage/__snapshots__/jsfmt.spec.js.snap @@ -2,7 +2,7 @@ exports[`SimpleStorage.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/SimpleStorage/jsfmt.spec.js b/tests/format/SimpleStorage/jsfmt.spec.js index 765dd60a6..418f6872d 100644 --- a/tests/format/SimpleStorage/jsfmt.spec.js +++ b/tests/format/SimpleStorage/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/SplittableCommodity/__snapshots__/jsfmt.spec.js.snap b/tests/format/SplittableCommodity/__snapshots__/jsfmt.spec.js.snap index 988eba232..99277a81b 100644 --- a/tests/format/SplittableCommodity/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/SplittableCommodity/__snapshots__/jsfmt.spec.js.snap @@ -2,7 +2,7 @@ exports[`SplittableCommodity.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/SplittableCommodity/jsfmt.spec.js b/tests/format/SplittableCommodity/jsfmt.spec.js index 765dd60a6..418f6872d 100644 --- a/tests/format/SplittableCommodity/jsfmt.spec.js +++ b/tests/format/SplittableCommodity/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/StateVariableDeclarations/__snapshots__/jsfmt.spec.js.snap b/tests/format/StateVariableDeclarations/__snapshots__/jsfmt.spec.js.snap index 9f48a411d..7a4344ecc 100644 --- a/tests/format/StateVariableDeclarations/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/StateVariableDeclarations/__snapshots__/jsfmt.spec.js.snap @@ -2,7 +2,7 @@ exports[`StateVariableDeclarations.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/StateVariableDeclarations/jsfmt.spec.js b/tests/format/StateVariableDeclarations/jsfmt.spec.js index 765dd60a6..418f6872d 100644 --- a/tests/format/StateVariableDeclarations/jsfmt.spec.js +++ b/tests/format/StateVariableDeclarations/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/StringLiteral/__snapshots__/jsfmt.spec.js.snap b/tests/format/StringLiteral/__snapshots__/jsfmt.spec.js.snap index 704ec50db..ee2cb840a 100644 --- a/tests/format/StringLiteral/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/StringLiteral/__snapshots__/jsfmt.spec.js.snap @@ -2,7 +2,7 @@ exports[`StringLiteral.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/StringLiteral/jsfmt.spec.js b/tests/format/StringLiteral/jsfmt.spec.js index 765dd60a6..418f6872d 100644 --- a/tests/format/StringLiteral/jsfmt.spec.js +++ b/tests/format/StringLiteral/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/StyleGuide/__snapshots__/jsfmt.spec.js.snap b/tests/format/StyleGuide/__snapshots__/jsfmt.spec.js.snap index b84c1da48..ee82866a9 100644 --- a/tests/format/StyleGuide/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/StyleGuide/__snapshots__/jsfmt.spec.js.snap @@ -1,8 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`BlankLines.sol format 1`] = ` +exports[`BlankLines.sol - {"compiler":"0.5.0"} format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +compiler: "0.5.0" +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -46,9 +47,10 @@ contract A { ================================================================================ `; -exports[`ControlStructures.sol format 1`] = ` +exports[`ControlStructures.sol - {"compiler":"0.5.0"} format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +compiler: "0.5.0" +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -167,9 +169,10 @@ contract ControlStructures { ================================================================================ `; -exports[`FunctionDeclaration.sol format 1`] = ` +exports[`FunctionDeclaration.sol - {"compiler":"0.5.0"} format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +compiler: "0.5.0" +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -458,9 +461,10 @@ contract X is B, C, D { ================================================================================ `; -exports[`Mappings.sol format 1`] = ` +exports[`Mappings.sol - {"compiler":"0.5.0"} format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +compiler: "0.5.0" +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -487,9 +491,10 @@ contract Mappings { ================================================================================ `; -exports[`MaximumLineLength.sol format 1`] = ` +exports[`MaximumLineLength.sol - {"compiler":"0.5.0"} format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +compiler: "0.5.0" +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -642,9 +647,10 @@ contract EventDefinitionsAndEventEmitters { ================================================================================ `; -exports[`OtherRecommendations.sol format 1`] = ` +exports[`OtherRecommendations.sol - {"compiler":"0.5.0"} format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +compiler: "0.5.0" +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -709,9 +715,10 @@ contract OtherRecommendations { ================================================================================ `; -exports[`VariableDeclarations.sol format 1`] = ` +exports[`VariableDeclarations.sol - {"compiler":"0.5.0"} format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +compiler: "0.5.0" +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -732,9 +739,10 @@ contract VariableDeclarations { ================================================================================ `; -exports[`WhitespaceInExpressions.sol format 1`] = ` +exports[`WhitespaceInExpressions.sol - {"compiler":"0.5.0"} format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +compiler: "0.5.0" +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/StyleGuide/jsfmt.spec.js b/tests/format/StyleGuide/jsfmt.spec.js index 417487a97..50eb2964b 100644 --- a/tests/format/StyleGuide/jsfmt.spec.js +++ b/tests/format/StyleGuide/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse'], { compiler: '0.5.0' }); +run_spec(import.meta, ['slang'], { compiler: '0.5.0' }); diff --git a/tests/format/TryCatch/__snapshots__/jsfmt.spec.js.snap b/tests/format/TryCatch/__snapshots__/jsfmt.spec.js.snap index 72355b966..80c1a633a 100644 --- a/tests/format/TryCatch/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/TryCatch/__snapshots__/jsfmt.spec.js.snap @@ -2,7 +2,7 @@ exports[`TryCatch.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/TryCatch/jsfmt.spec.js b/tests/format/TryCatch/jsfmt.spec.js index 765dd60a6..418f6872d 100644 --- a/tests/format/TryCatch/jsfmt.spec.js +++ b/tests/format/TryCatch/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/Tupples/__snapshots__/jsfmt.spec.js.snap b/tests/format/Tupples/__snapshots__/jsfmt.spec.js.snap index 4ddda35fc..5a1ceaf74 100644 --- a/tests/format/Tupples/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Tupples/__snapshots__/jsfmt.spec.js.snap @@ -2,7 +2,7 @@ exports[`Tupples.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/Tupples/jsfmt.spec.js b/tests/format/Tupples/jsfmt.spec.js index 765dd60a6..418f6872d 100644 --- a/tests/format/Tupples/jsfmt.spec.js +++ b/tests/format/Tupples/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/TypeDefinition/__snapshots__/jsfmt.spec.js.snap b/tests/format/TypeDefinition/__snapshots__/jsfmt.spec.js.snap index 04e77a23d..2981dcfed 100644 --- a/tests/format/TypeDefinition/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/TypeDefinition/__snapshots__/jsfmt.spec.js.snap @@ -2,7 +2,7 @@ exports[`TypeDefinition.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/TypeDefinition/jsfmt.spec.js b/tests/format/TypeDefinition/jsfmt.spec.js index 765dd60a6..418f6872d 100644 --- a/tests/format/TypeDefinition/jsfmt.spec.js +++ b/tests/format/TypeDefinition/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/WhileStatements/__snapshots__/jsfmt.spec.js.snap b/tests/format/WhileStatements/__snapshots__/jsfmt.spec.js.snap index e13595552..0e17b1dc0 100644 --- a/tests/format/WhileStatements/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/WhileStatements/__snapshots__/jsfmt.spec.js.snap @@ -2,7 +2,7 @@ exports[`WhileStatements.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/WhileStatements/jsfmt.spec.js b/tests/format/WhileStatements/jsfmt.spec.js index 765dd60a6..418f6872d 100644 --- a/tests/format/WhileStatements/jsfmt.spec.js +++ b/tests/format/WhileStatements/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['slang']); diff --git a/tests/format/quotes/__snapshots__/jsfmt.spec.js.snap b/tests/format/quotes/__snapshots__/jsfmt.spec.js.snap index ea7f83dd4..b0c6bbec2 100644 --- a/tests/format/quotes/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/quotes/__snapshots__/jsfmt.spec.js.snap @@ -2,7 +2,7 @@ exports[`Quotes.sol - {"singleQuote":false} format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 singleQuote: false | printWidth @@ -61,7 +61,7 @@ contract Foo { exports[`Quotes.sol - {"singleQuote":true} format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 singleQuote: true | printWidth diff --git a/tests/format/quotes/jsfmt.spec.js b/tests/format/quotes/jsfmt.spec.js index 3272026cc..30121cb5f 100644 --- a/tests/format/quotes/jsfmt.spec.js +++ b/tests/format/quotes/jsfmt.spec.js @@ -1,2 +1,2 @@ -run_spec(import.meta, ['solidity-parse'], { singleQuote: true }); -run_spec(import.meta, ['solidity-parse'], { singleQuote: false }); +run_spec(import.meta, ['slang'], { singleQuote: true }); +run_spec(import.meta, ['slang'], { singleQuote: false }); diff --git a/tests/format/strings/__snapshots__/jsfmt.spec.js.snap b/tests/format/strings/__snapshots__/jsfmt.spec.js.snap index 2ec8073d9..c60d36973 100644 --- a/tests/format/strings/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/strings/__snapshots__/jsfmt.spec.js.snap @@ -2,7 +2,7 @@ exports[`strings.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/strings/jsfmt.spec.js b/tests/format/strings/jsfmt.spec.js index 765dd60a6..418f6872d 100644 --- a/tests/format/strings/jsfmt.spec.js +++ b/tests/format/strings/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['slang']); From 0cd1c9dd41b4f54531332d0e207c062c1a9bc151 Mon Sep 17 00:00:00 2001 From: Klaus Date: Tue, 9 Jul 2024 19:23:37 +1200 Subject: [PATCH 055/160] modifier definitions without parameters are forced to have an empty () --- src/slang-nodes/ModifierDefinition.js | 13 ++++++++++++- tests/config/format-test.js | 20 ++++++++++---------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/slang-nodes/ModifierDefinition.js b/src/slang-nodes/ModifierDefinition.js index 0debe44c5..b7fdbbe9f 100644 --- a/src/slang-nodes/ModifierDefinition.js +++ b/src/slang-nodes/ModifierDefinition.js @@ -6,7 +6,18 @@ export const ModifierDefinition = { name: ast.name.text, parameters: ast.parameters ? parse(ast.parameters, options, parse, offsets) - : undefined, + : { + kind: 'ParametersDeclaration', + loc: { start: offsets[0], end: offsets[0] }, + openParen: '(', + parameters: { + kind: 'Parameters', + loc: { start: offsets[0], end: offsets[0] }, + items: [], + separators: [] + }, + closeParen: ')' + }, attributes: parse(ast.attributes, options, parse, offsets), body: parse(ast.body, options, parse, offsets) }), diff --git a/tests/config/format-test.js b/tests/config/format-test.js index 8bd7696dd..0d2fbd2df 100644 --- a/tests/config/format-test.js +++ b/tests/config/format-test.js @@ -41,23 +41,23 @@ const unstableAstTests = new Map( const testsWithSlang = new Map( [ // "AllSolidityFeatures/AllSolidityFeatures.sol", - // "AssemblyV0.4.26/Assembly.sol", - // "BasicIterator/BasicIterator.sol", - // "Comments/Comments.sol", - // "Etc/Etc.sol", + // "AssemblyV0.4.26/Assembly.sol", // TODO: Report to Nomic Foundation? + // "BasicIterator/BasicIterator.sol", // TODO: Fix solidity-parser comments + // "Comments/Comments.sol", // TODO: finish Comments + // "Etc/Etc.sol", // TODO: Fix solidity-parser function type // "ExperimentalTernaries/ExperimentalTernaries.sol", // TODO: fix this one - // "FunctionDefinitions/FunctionDefinitions.sol", - // "ImportDirective/ImportDirectives.sol", - // "IndexOf/IndexOf.sol", + // "FunctionDefinitions/FunctionDefinitions.sol", // TODO: remove () safely in modifiers without arguments + // "ImportDirective/ImportDirectives.sol", // TODO: separate tests for slang and solidity-parser + // "IndexOf/IndexOf.sol", // TODO: Finish comments and file level functions "Issues/Issue205.sol", "Issues/Issue289.sol", "Issues/Issue355.sol", "Issues/Issue385.sol", - // "Issues/Issue564.sol", + // "Issues/Issue564.sol", // TODO: solve indentation in variable declaration "Issues/Issue799.sol", "Issues/Issue843.sol", - // "MemberAccess/MemberAccess.sol", - // "ModifierInvocations/ModifierInvocations.sol", + // "MemberAccess/MemberAccess.sol", // TODO: Comments should be redone + "ModifierInvocations/ModifierInvocations.sol", // "PrettierIgnore/PrettierIgnore.sol", ].map((fixture) => { const [file, testSlang = () => true] = Array.isArray(fixture) From 2c89f1be9e65e74adff8e480eaf91507f028d477 Mon Sep 17 00:00:00 2001 From: Klaus Date: Tue, 9 Jul 2024 23:51:42 +1200 Subject: [PATCH 056/160] updating test framework --- .eslintrc | 2 +- jest.config.js | 4 +- tests/config/.prettierrc | 7 ++- tests/config/format-test-setup.js | 3 ++ tests/config/require-standalone.cjs | 4 +- .../{format-test.js => run-format-test.js} | 48 ++++++++++--------- tests/config/setup.js | 3 -- tests/config/utils/compile-contract.js | 2 +- tests/config/utils/consistent-end-of-line.js | 2 +- tests/config/utils/create-snapshot.js | 9 ++-- .../utils/stringify-options-for-title.js | 2 +- tests/config/utils/visualize-end-of-line.js | 2 +- tests/config/utils/visualize-range.js | 4 +- ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/AddressPayable/format.test.js | 1 + tests/format/AddressPayable/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 .../format/AllSolidityFeatures/format.test.js | 1 + .../format/AllSolidityFeatures/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/Arrays/format.test.js | 1 + tests/format/Arrays/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/Assembly/format.test.js | 1 + tests/format/Assembly/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/AssemblyV0.4.26/format.test.js | 1 + tests/format/AssemblyV0.4.26/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/BasicIterator/format.test.js | 1 + tests/format/BasicIterator/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/BinaryOperators/format.test.js | 1 + tests/format/BinaryOperators/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 .../BreakingChangesV0.7.4/format.test.js | 12 +++++ .../BreakingChangesV0.7.4/jsfmt.spec.js | 6 --- ...jsfmt.spec.js.snap => format.test.js.snap} | 0 .../BreakingChangesV0.8.0/format.test.js | 3 ++ .../BreakingChangesV0.8.0/jsfmt.spec.js | 3 -- ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/Comments/format.test.js | 1 + tests/format/Comments/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/Conditional/format.test.js | 1 + tests/format/Conditional/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/Constructors/format.test.js | 1 + tests/format/Constructors/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 .../format/ContractDefinitions/format.test.js | 1 + .../format/ContractDefinitions/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/CustomErrors/format.test.js | 1 + tests/format/CustomErrors/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/EnumDefinitions/format.test.js | 1 + tests/format/EnumDefinitions/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/Etc/format.test.js | 1 + tests/format/Etc/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 .../ExperimentalTernaries/format.test.js | 10 ++++ .../ExperimentalTernaries/jsfmt.spec.js | 10 ---- ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/ForStatements/format.test.js | 1 + tests/format/ForStatements/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/FunctionCalls/format.test.js | 2 + tests/format/FunctionCalls/jsfmt.spec.js | 2 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 .../format/FunctionDefinitions/format.test.js | 1 + .../format/FunctionDefinitions/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 .../FunctionDefinitionsv0.5.0/format.test.js | 1 + .../FunctionDefinitionsv0.5.0/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/HexLiteral/format.test.js | 2 + tests/format/HexLiteral/jsfmt.spec.js | 2 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/IfStatements/format.test.js | 1 + tests/format/IfStatements/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/Immutable/format.test.js | 1 + tests/format/Immutable/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/ImportDirective/format.test.js | 2 + tests/format/ImportDirective/jsfmt.spec.js | 2 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/Inbox/format.test.js | 1 + tests/format/Inbox/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/IndexOf/format.test.js | 1 + tests/format/IndexOf/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/IndexRangeAccess/format.test.js | 1 + tests/format/IndexRangeAccess/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 .../InheritanceSpecifier/format.test.js | 1 + .../format/InheritanceSpecifier/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/Issues/format.test.js | 1 + tests/format/Issues/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/Libraries/format.test.js | 2 + tests/format/Libraries/jsfmt.spec.js | 2 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/Markdown/format.test.js | 1 + tests/format/Markdown/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/MemberAccess/format.test.js | 1 + tests/format/MemberAccess/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 .../format/ModifierDefinitions/format.test.js | 1 + .../format/ModifierDefinitions/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 .../format/ModifierInvocations/format.test.js | 1 + .../format/ModifierInvocations/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/MultipartStrings/format.test.js | 1 + tests/format/MultipartStrings/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 .../format/NameValueExpression/format.test.js | 2 + .../format/NameValueExpression/jsfmt.spec.js | 2 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/NumberLiteral/format.test.js | 1 + tests/format/NumberLiteral/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/Ownable/format.test.js | 1 + tests/format/Ownable/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/Parentheses/format.test.js | 1 + tests/format/Parentheses/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/Pragma/format.test.js | 1 + tests/format/Pragma/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/PrettierIgnore/format.test.js | 1 + tests/format/PrettierIgnore/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/Proxy/format.test.js | 1 + tests/format/Proxy/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 .../RespectDefaultOptions/format.test.js | 1 + .../RespectDefaultOptions/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/SampleCrowdsale/format.test.js | 1 + tests/format/SampleCrowdsale/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/SimpleAuction/format.test.js | 1 + tests/format/SimpleAuction/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/SimpleStorage/format.test.js | 1 + tests/format/SimpleStorage/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 .../format/SplittableCommodity/format.test.js | 1 + .../format/SplittableCommodity/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 .../StateVariableDeclarations/format.test.js | 1 + .../StateVariableDeclarations/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/StringLiteral/format.test.js | 1 + tests/format/StringLiteral/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/StyleGuide/format.test.js | 1 + tests/format/StyleGuide/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/TryCatch/format.test.js | 1 + tests/format/TryCatch/jsfmt.spec.js | 1 - .../Tupples.sol => Tuples/Tuples.sol} | 0 .../__snapshots__/format.test.js.snap} | 2 +- tests/format/Tuples/format.test.js | 1 + tests/format/Tupples/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/TypeDefinition/format.test.js | 1 + tests/format/TypeDefinition/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/WhileStatements/format.test.js | 1 + tests/format/WhileStatements/jsfmt.spec.js | 1 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/WrongCompiler/format.test.js | 10 ++++ tests/format/WrongCompiler/jsfmt.spec.js | 10 ---- ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/quotes/format.test.js | 2 + tests/format/quotes/jsfmt.spec.js | 2 - ...jsfmt.spec.js.snap => format.test.js.snap} | 0 tests/format/strings/format.test.js | 1 + tests/format/strings/jsfmt.spec.js | 1 - 188 files changed, 143 insertions(+), 135 deletions(-) create mode 100644 tests/config/format-test-setup.js rename tests/config/{format-test.js => run-format-test.js} (96%) delete mode 100644 tests/config/setup.js rename tests/format/AddressPayable/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/AddressPayable/format.test.js delete mode 100644 tests/format/AddressPayable/jsfmt.spec.js rename tests/format/AllSolidityFeatures/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/AllSolidityFeatures/format.test.js delete mode 100644 tests/format/AllSolidityFeatures/jsfmt.spec.js rename tests/format/Arrays/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/Arrays/format.test.js delete mode 100644 tests/format/Arrays/jsfmt.spec.js rename tests/format/Assembly/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/Assembly/format.test.js delete mode 100644 tests/format/Assembly/jsfmt.spec.js rename tests/format/AssemblyV0.4.26/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/AssemblyV0.4.26/format.test.js delete mode 100644 tests/format/AssemblyV0.4.26/jsfmt.spec.js rename tests/format/BasicIterator/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/BasicIterator/format.test.js delete mode 100644 tests/format/BasicIterator/jsfmt.spec.js rename tests/format/BinaryOperators/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/BinaryOperators/format.test.js delete mode 100644 tests/format/BinaryOperators/jsfmt.spec.js rename tests/format/BreakingChangesV0.7.4/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/BreakingChangesV0.7.4/format.test.js delete mode 100644 tests/format/BreakingChangesV0.7.4/jsfmt.spec.js rename tests/format/BreakingChangesV0.8.0/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/BreakingChangesV0.8.0/format.test.js delete mode 100644 tests/format/BreakingChangesV0.8.0/jsfmt.spec.js rename tests/format/Comments/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/Comments/format.test.js delete mode 100644 tests/format/Comments/jsfmt.spec.js rename tests/format/Conditional/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/Conditional/format.test.js delete mode 100644 tests/format/Conditional/jsfmt.spec.js rename tests/format/Constructors/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/Constructors/format.test.js delete mode 100644 tests/format/Constructors/jsfmt.spec.js rename tests/format/ContractDefinitions/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/ContractDefinitions/format.test.js delete mode 100644 tests/format/ContractDefinitions/jsfmt.spec.js rename tests/format/CustomErrors/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/CustomErrors/format.test.js delete mode 100644 tests/format/CustomErrors/jsfmt.spec.js rename tests/format/EnumDefinitions/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/EnumDefinitions/format.test.js delete mode 100644 tests/format/EnumDefinitions/jsfmt.spec.js rename tests/format/Etc/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/Etc/format.test.js delete mode 100644 tests/format/Etc/jsfmt.spec.js rename tests/format/ExperimentalTernaries/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/ExperimentalTernaries/format.test.js delete mode 100644 tests/format/ExperimentalTernaries/jsfmt.spec.js rename tests/format/ForStatements/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/ForStatements/format.test.js delete mode 100644 tests/format/ForStatements/jsfmt.spec.js rename tests/format/FunctionCalls/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/FunctionCalls/format.test.js delete mode 100644 tests/format/FunctionCalls/jsfmt.spec.js rename tests/format/FunctionDefinitions/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/FunctionDefinitions/format.test.js delete mode 100644 tests/format/FunctionDefinitions/jsfmt.spec.js rename tests/format/FunctionDefinitionsv0.5.0/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/FunctionDefinitionsv0.5.0/format.test.js delete mode 100644 tests/format/FunctionDefinitionsv0.5.0/jsfmt.spec.js rename tests/format/HexLiteral/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/HexLiteral/format.test.js delete mode 100644 tests/format/HexLiteral/jsfmt.spec.js rename tests/format/IfStatements/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/IfStatements/format.test.js delete mode 100644 tests/format/IfStatements/jsfmt.spec.js rename tests/format/Immutable/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/Immutable/format.test.js delete mode 100644 tests/format/Immutable/jsfmt.spec.js rename tests/format/ImportDirective/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/ImportDirective/format.test.js delete mode 100644 tests/format/ImportDirective/jsfmt.spec.js rename tests/format/Inbox/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/Inbox/format.test.js delete mode 100644 tests/format/Inbox/jsfmt.spec.js rename tests/format/IndexOf/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/IndexOf/format.test.js delete mode 100644 tests/format/IndexOf/jsfmt.spec.js rename tests/format/IndexRangeAccess/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/IndexRangeAccess/format.test.js delete mode 100644 tests/format/IndexRangeAccess/jsfmt.spec.js rename tests/format/InheritanceSpecifier/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/InheritanceSpecifier/format.test.js delete mode 100644 tests/format/InheritanceSpecifier/jsfmt.spec.js rename tests/format/Issues/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/Issues/format.test.js delete mode 100644 tests/format/Issues/jsfmt.spec.js rename tests/format/Libraries/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/Libraries/format.test.js delete mode 100644 tests/format/Libraries/jsfmt.spec.js rename tests/format/Markdown/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/Markdown/format.test.js delete mode 100644 tests/format/Markdown/jsfmt.spec.js rename tests/format/MemberAccess/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/MemberAccess/format.test.js delete mode 100644 tests/format/MemberAccess/jsfmt.spec.js rename tests/format/ModifierDefinitions/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/ModifierDefinitions/format.test.js delete mode 100644 tests/format/ModifierDefinitions/jsfmt.spec.js rename tests/format/ModifierInvocations/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/ModifierInvocations/format.test.js delete mode 100644 tests/format/ModifierInvocations/jsfmt.spec.js rename tests/format/MultipartStrings/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/MultipartStrings/format.test.js delete mode 100644 tests/format/MultipartStrings/jsfmt.spec.js rename tests/format/NameValueExpression/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/NameValueExpression/format.test.js delete mode 100644 tests/format/NameValueExpression/jsfmt.spec.js rename tests/format/NumberLiteral/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/NumberLiteral/format.test.js delete mode 100644 tests/format/NumberLiteral/jsfmt.spec.js rename tests/format/Ownable/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/Ownable/format.test.js delete mode 100644 tests/format/Ownable/jsfmt.spec.js rename tests/format/Parentheses/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/Parentheses/format.test.js delete mode 100644 tests/format/Parentheses/jsfmt.spec.js rename tests/format/Pragma/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/Pragma/format.test.js delete mode 100644 tests/format/Pragma/jsfmt.spec.js rename tests/format/PrettierIgnore/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/PrettierIgnore/format.test.js delete mode 100644 tests/format/PrettierIgnore/jsfmt.spec.js rename tests/format/Proxy/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/Proxy/format.test.js delete mode 100644 tests/format/Proxy/jsfmt.spec.js rename tests/format/RespectDefaultOptions/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/RespectDefaultOptions/format.test.js delete mode 100644 tests/format/RespectDefaultOptions/jsfmt.spec.js rename tests/format/SampleCrowdsale/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/SampleCrowdsale/format.test.js delete mode 100644 tests/format/SampleCrowdsale/jsfmt.spec.js rename tests/format/SimpleAuction/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/SimpleAuction/format.test.js delete mode 100644 tests/format/SimpleAuction/jsfmt.spec.js rename tests/format/SimpleStorage/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/SimpleStorage/format.test.js delete mode 100644 tests/format/SimpleStorage/jsfmt.spec.js rename tests/format/SplittableCommodity/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/SplittableCommodity/format.test.js delete mode 100644 tests/format/SplittableCommodity/jsfmt.spec.js rename tests/format/StateVariableDeclarations/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/StateVariableDeclarations/format.test.js delete mode 100644 tests/format/StateVariableDeclarations/jsfmt.spec.js rename tests/format/StringLiteral/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/StringLiteral/format.test.js delete mode 100644 tests/format/StringLiteral/jsfmt.spec.js rename tests/format/StyleGuide/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/StyleGuide/format.test.js delete mode 100644 tests/format/StyleGuide/jsfmt.spec.js rename tests/format/TryCatch/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/TryCatch/format.test.js delete mode 100644 tests/format/TryCatch/jsfmt.spec.js rename tests/format/{Tupples/Tupples.sol => Tuples/Tuples.sol} (100%) rename tests/format/{Tupples/__snapshots__/jsfmt.spec.js.snap => Tuples/__snapshots__/format.test.js.snap} (98%) create mode 100644 tests/format/Tuples/format.test.js delete mode 100644 tests/format/Tupples/jsfmt.spec.js rename tests/format/TypeDefinition/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/TypeDefinition/format.test.js delete mode 100644 tests/format/TypeDefinition/jsfmt.spec.js rename tests/format/WhileStatements/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/WhileStatements/format.test.js delete mode 100644 tests/format/WhileStatements/jsfmt.spec.js rename tests/format/WrongCompiler/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/WrongCompiler/format.test.js delete mode 100644 tests/format/WrongCompiler/jsfmt.spec.js rename tests/format/quotes/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/quotes/format.test.js delete mode 100644 tests/format/quotes/jsfmt.spec.js rename tests/format/strings/__snapshots__/{jsfmt.spec.js.snap => format.test.js.snap} (100%) create mode 100644 tests/format/strings/format.test.js delete mode 100644 tests/format/strings/jsfmt.spec.js diff --git a/.eslintrc b/.eslintrc index eb3058129..740a32dbd 100644 --- a/.eslintrc +++ b/.eslintrc @@ -4,7 +4,7 @@ }, "extends": ["airbnb-base", "prettier"], "globals": { - "run_spec": false + "runFormatTest": false }, "parserOptions": { "ecmaVersion": "latest", diff --git a/jest.config.js b/jest.config.js index 79f72f497..2feb5fb4a 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,6 +1,6 @@ const TEST_STANDALONE = Boolean(process.env.TEST_STANDALONE); const testMatch = [ - '/tests/format/**/jsfmt.spec.js', + '/tests/format/**/format.test.js', '/tests/unit/**/*.test.js' ]; @@ -11,7 +11,7 @@ if (TEST_STANDALONE) { export default { runner: 'jest-light-runner', - setupFiles: ['/tests/config/setup.js'], + setupFiles: ['/tests/config/format-test-setup.js'], snapshotSerializers: [ 'jest-snapshot-serializer-raw', 'jest-snapshot-serializer-ansi' diff --git a/tests/config/.prettierrc b/tests/config/.prettierrc index befe74aca..f3bcd4c90 100644 --- a/tests/config/.prettierrc +++ b/tests/config/.prettierrc @@ -1,5 +1,4 @@ { - "singleQuote": false, - "trailingComma": "es5" - } - \ No newline at end of file + "singleQuote": false, + "trailingComma": "all" +} diff --git a/tests/config/format-test-setup.js b/tests/config/format-test-setup.js new file mode 100644 index 000000000..98222ffc2 --- /dev/null +++ b/tests/config/format-test-setup.js @@ -0,0 +1,3 @@ +import runFormatTest from "./run-format-test.js"; + +globalThis.runFormatTest = runFormatTest; diff --git a/tests/config/require-standalone.cjs b/tests/config/require-standalone.cjs index 2f2c10bbc..8b9d52d3a 100644 --- a/tests/config/require-standalone.cjs +++ b/tests/config/require-standalone.cjs @@ -35,7 +35,7 @@ module.exports = { }; prettier.formatWithCursor($$$input, options); `, - { $$$input: input, $$$options: options, ...sandbox } + { $$$input: input, $$$options: options, ...sandbox }, ); }, @@ -57,7 +57,7 @@ module.exports = { $$$options: options, $$$devOptions: devOptions, ...sandbox, - } + }, ); }, }, diff --git a/tests/config/format-test.js b/tests/config/run-format-test.js similarity index 96% rename from tests/config/format-test.js rename to tests/config/run-format-test.js index 0d2fbd2df..1ea19cd10 100644 --- a/tests/config/format-test.js +++ b/tests/config/run-format-test.js @@ -1,13 +1,15 @@ 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 createSnapshot from "./utils/create-snapshot.js"; import stringifyOptionsForTitle from "./utils/stringify-options-for-title.js"; +import visualizeEndOfLine from "./utils/visualize-end-of-line.js"; const { __dirname } = createEsmUtils(import.meta); @@ -25,7 +27,7 @@ const unstableTests = new Map( ? fixture : [fixture]; return [path.join(__dirname, "../format/", file), isUnstable]; - }) + }), ); // Here we add files that will not have the same AST after being formatted. @@ -35,7 +37,7 @@ const unstableAstTests = new Map( ? fixture : [fixture]; return [path.join(__dirname, "../format/", file), isAstUnstable]; - }) + }), ); const testsWithSlang = new Map( @@ -57,14 +59,14 @@ const testsWithSlang = new Map( "Issues/Issue799.sol", "Issues/Issue843.sol", // "MemberAccess/MemberAccess.sol", // TODO: Comments should be redone - "ModifierInvocations/ModifierInvocations.sol", + // "ModifierInvocations/ModifierInvocations.sol", // "PrettierIgnore/PrettierIgnore.sol", ].map((fixture) => { const [file, testSlang = () => true] = Array.isArray(fixture) ? fixture : [fixture]; return [path.join(__dirname, "../format/", file), testSlang]; - }) + }), ); const testsWithAstChanges = new Map( @@ -88,7 +90,7 @@ const testsWithAstChanges = new Map( ? fixture : [fixture]; return [path.join(__dirname, "../format/", file), compareBytecode]; - }) + }), ); const isUnstable = (filename, options) => { @@ -148,10 +150,10 @@ const shouldThrowOnFormat = (filename, options) => { const isTestDirectory = (dirname, name) => (dirname + path.sep).startsWith( - path.join(__dirname, "../format", name) + path.sep + path.join(__dirname, "../format", name) + path.sep, ); -function runSpec(fixtures, parsers, options) { +function runFormatTest(fixtures, parsers, options) { let { importMeta, snippets = [] } = fixtures.importMeta ? fixtures : { importMeta: fixtures }; @@ -160,7 +162,7 @@ function runSpec(fixtures, parsers, options) { // `IS_PARSER_INFERENCE_TESTS` mean to test `inferParser` on `standalone` const IS_PARSER_INFERENCE_TESTS = isTestDirectory( dirname, - "misc/parser-inference" + "misc/parser-inference", ); // `IS_ERROR_TESTS` mean to watch errors like: @@ -197,7 +199,7 @@ function runSpec(fixtures, parsers, options) { path.extname(basename) === ".snap" || !file.isFile() || basename[0] === "." || - basename === "jsfmt.spec.js" || + basename === "format.test.js" || // VSCode creates this file sometime https://github.com/microsoft/vscode/issues/105191 basename === "debug.log" ) { @@ -236,7 +238,7 @@ function runSpec(fixtures, parsers, options) { }; const shouldThrowOnMainParserFormat = shouldThrowOnFormat( name, - formatOptions + formatOptions, ); let mainParserFormatResult; @@ -305,13 +307,13 @@ async function runTest({ // Make sure output has consistent EOL expect(formatResult.eolVisualizedOutput).toEqual( - visualizeEndOfLine(consistentEndOfLine(formatResult.outputWithCursor)) + visualizeEndOfLine(consistentEndOfLine(formatResult.outputWithCursor)), ); // The result is assert to equals to `output` if (typeof output === "string") { expect(formatResult.eolVisualizedOutput).toEqual( - visualizeEndOfLine(output) + visualizeEndOfLine(output), ); return; } @@ -322,7 +324,7 @@ async function runTest({ parsers, formatOptions, CURSOR_PLACEHOLDER, - }) + }), ).toMatchSnapshot(); if (shouldTestSlang(filename, formatOptions)) { @@ -354,7 +356,7 @@ async function runTest({ const { eolVisualizedOutput: firstOutput, output } = formatResult; const { eolVisualizedOutput: secondOutput } = await format( output, - formatOptions + formatOptions, ); if (isUnstableTest) { // To keep eye on failed tests, this assert never supposed to pass, @@ -381,15 +383,15 @@ async function runTest({ if (!shouldSkipEolTest(code, formatResult.options)) { for (const eol of ["\r\n", "\r"]) { const { eolVisualizedOutput: output } = await format( - code.replace(/\n/g, eol), - formatOptions + code.replace(/\n/gu, eol), + formatOptions, ); // Only if `endOfLine: "auto"` the result will be different const expected = formatOptions.endOfLine === "auto" ? visualizeEndOfLine( // All `code` use `LF`, so the `eol` of result is always `LF` - formatResult.outputWithCursor.replace(/\n/g, eol) + formatResult.outputWithCursor.replace(/\n/gu, eol), ) : formatResult.eolVisualizedOutput; expect(output).toEqual(expected); @@ -399,7 +401,7 @@ async function runTest({ if (code.charAt(0) !== BOM) { const { eolVisualizedOutput: output } = await format( BOM + code, - formatOptions + formatOptions, ); const expected = BOM + formatResult.eolVisualizedOutput; expect(output).toEqual(expected); @@ -482,14 +484,14 @@ const insertCursor = (text, cursorOffset) => async function format(originalText, originalOptions) { const { text: input, options } = replacePlaceholders( originalText, - originalOptions + originalOptions, ); const inputWithCursor = insertCursor(input, options.cursorOffset); const prettier = await getPrettier(); const { formatted: output, cursorOffset } = await prettier.formatWithCursor( input, - options + options, ); const outputWithCursor = insertCursor(output, cursorOffset); const eolVisualizedOutput = visualizeEndOfLine(outputWithCursor); @@ -507,4 +509,4 @@ async function format(originalText, originalOptions) { }; } -export default runSpec; +export default runFormatTest; diff --git a/tests/config/setup.js b/tests/config/setup.js deleted file mode 100644 index 3d3b8b4c7..000000000 --- a/tests/config/setup.js +++ /dev/null @@ -1,3 +0,0 @@ -import runSpec from "./format-test.js"; - -globalThis.run_spec = runSpec; diff --git a/tests/config/utils/compile-contract.js b/tests/config/utils/compile-contract.js index 7a0474f8f..194eb0980 100644 --- a/tests/config/utils/compile-contract.js +++ b/tests/config/utils/compile-contract.js @@ -40,7 +40,7 @@ async function compileContract(filename, content) { ...byteCodes, [contractName]: compiledContracts[contractName].evm.bytecode.object, }), - {} + {}, ); } diff --git a/tests/config/utils/consistent-end-of-line.js b/tests/config/utils/consistent-end-of-line.js index e618ab542..ecedbf7b0 100644 --- a/tests/config/utils/consistent-end-of-line.js +++ b/tests/config/utils/consistent-end-of-line.js @@ -1,6 +1,6 @@ function consistentEndOfLine(text) { let firstEndOfLine; - return text.replace(/\r\n?|\n/g, (endOfLine) => { + return text.replace(/\r\n?|\n/gu, (endOfLine) => { firstEndOfLine = firstEndOfLine ?? endOfLine; return firstEndOfLine; }); diff --git a/tests/config/utils/create-snapshot.js b/tests/config/utils/create-snapshot.js index 5b122939a..1a898837f 100644 --- a/tests/config/utils/create-snapshot.js +++ b/tests/config/utils/create-snapshot.js @@ -1,6 +1,7 @@ import { wrap as raw } from "jest-snapshot-serializer-raw"; -import visualizeRange from "./visualize-range.js"; + import visualizeEndOfLine from "./visualize-end-of-line.js"; +import visualizeRange from "./visualize-range.js"; const SEPARATOR_WIDTH = 80; function printSeparator(description = "") { @@ -48,7 +49,7 @@ function printWidthIndicator(printWidth, offset) { function createSnapshot( formatResult, - { parsers, formatOptions, CURSOR_PLACEHOLDER } + { parsers, formatOptions, CURSOR_PLACEHOLDER }, ) { let { inputWithCursor: input, @@ -69,7 +70,7 @@ function createSnapshot( } input = visualizeRange(input, { rangeStart, rangeEnd }); - codeOffset = input.match(/^>?\s+1 \|/)[0].length + 1; + codeOffset = input.match(/^>?\s+1 \|/u)[0].length + 1; } if ("endOfLine" in formatOptions) { @@ -89,7 +90,7 @@ function createSnapshot( printSeparator("output"), output, printSeparator(), - ].join("\n") + ].join("\n"), ); } diff --git a/tests/config/utils/stringify-options-for-title.js b/tests/config/utils/stringify-options-for-title.js index 46921dc54..d25c671d5 100644 --- a/tests/config/utils/stringify-options-for-title.js +++ b/tests/config/utils/stringify-options-for-title.js @@ -4,7 +4,7 @@ function stringifyOptions(options) { ? undefined : value === Number.POSITIVE_INFINITY ? "Infinity" - : value + : value, ); return string === "{}" ? "" : string; diff --git a/tests/config/utils/visualize-end-of-line.js b/tests/config/utils/visualize-end-of-line.js index 9dec987e0..1db619aeb 100644 --- a/tests/config/utils/visualize-end-of-line.js +++ b/tests/config/utils/visualize-end-of-line.js @@ -1,5 +1,5 @@ function visualizeEndOfLine(text) { - return text.replace(/\r\n?|\n/g, (endOfLine) => { + return text.replace(/\r\n?|\n/gu, (endOfLine) => { switch (endOfLine) { case "\n": return "\n"; diff --git a/tests/config/utils/visualize-range.js b/tests/config/utils/visualize-range.js index 6d3762f7f..222bc7a6f 100644 --- a/tests/config/utils/visualize-range.js +++ b/tests/config/utils/visualize-range.js @@ -1,5 +1,5 @@ -import { LinesAndColumns } from "lines-and-columns"; import { codeFrameColumns } from "@babel/code-frame"; +import { LinesAndColumns } from "lines-and-columns"; const codeFrameColumnsOptions = { linesAbove: Number.POSITIVE_INFINITY, linesBelow: Number.POSITIVE_INFINITY, @@ -32,7 +32,7 @@ const visualizeRange = (text, { rangeStart = 0, rangeEnd = text.length }) => locationForRange(text, rangeStart, rangeEnd), rangeStart > rangeEnd ? { ...codeFrameColumnsOptions, message: "[Reversed range]" } - : codeFrameColumnsOptions + : codeFrameColumnsOptions, ); export default visualizeRange; diff --git a/tests/format/AddressPayable/__snapshots__/jsfmt.spec.js.snap b/tests/format/AddressPayable/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/AddressPayable/__snapshots__/jsfmt.spec.js.snap rename to tests/format/AddressPayable/__snapshots__/format.test.js.snap diff --git a/tests/format/AddressPayable/format.test.js b/tests/format/AddressPayable/format.test.js new file mode 100644 index 000000000..6021bbb0d --- /dev/null +++ b/tests/format/AddressPayable/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['slang']); diff --git a/tests/format/AddressPayable/jsfmt.spec.js b/tests/format/AddressPayable/jsfmt.spec.js deleted file mode 100644 index 418f6872d..000000000 --- a/tests/format/AddressPayable/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['slang']); diff --git a/tests/format/AllSolidityFeatures/__snapshots__/jsfmt.spec.js.snap b/tests/format/AllSolidityFeatures/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/AllSolidityFeatures/__snapshots__/jsfmt.spec.js.snap rename to tests/format/AllSolidityFeatures/__snapshots__/format.test.js.snap diff --git a/tests/format/AllSolidityFeatures/format.test.js b/tests/format/AllSolidityFeatures/format.test.js new file mode 100644 index 000000000..2ae629864 --- /dev/null +++ b/tests/format/AllSolidityFeatures/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['solidity-parse']); diff --git a/tests/format/AllSolidityFeatures/jsfmt.spec.js b/tests/format/AllSolidityFeatures/jsfmt.spec.js deleted file mode 100644 index 765dd60a6..000000000 --- a/tests/format/AllSolidityFeatures/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/Arrays/__snapshots__/jsfmt.spec.js.snap b/tests/format/Arrays/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/Arrays/__snapshots__/jsfmt.spec.js.snap rename to tests/format/Arrays/__snapshots__/format.test.js.snap diff --git a/tests/format/Arrays/format.test.js b/tests/format/Arrays/format.test.js new file mode 100644 index 000000000..6021bbb0d --- /dev/null +++ b/tests/format/Arrays/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['slang']); diff --git a/tests/format/Arrays/jsfmt.spec.js b/tests/format/Arrays/jsfmt.spec.js deleted file mode 100644 index 418f6872d..000000000 --- a/tests/format/Arrays/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['slang']); diff --git a/tests/format/Assembly/__snapshots__/jsfmt.spec.js.snap b/tests/format/Assembly/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/Assembly/__snapshots__/jsfmt.spec.js.snap rename to tests/format/Assembly/__snapshots__/format.test.js.snap diff --git a/tests/format/Assembly/format.test.js b/tests/format/Assembly/format.test.js new file mode 100644 index 000000000..6021bbb0d --- /dev/null +++ b/tests/format/Assembly/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['slang']); diff --git a/tests/format/Assembly/jsfmt.spec.js b/tests/format/Assembly/jsfmt.spec.js deleted file mode 100644 index 418f6872d..000000000 --- a/tests/format/Assembly/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['slang']); diff --git a/tests/format/AssemblyV0.4.26/__snapshots__/jsfmt.spec.js.snap b/tests/format/AssemblyV0.4.26/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/AssemblyV0.4.26/__snapshots__/jsfmt.spec.js.snap rename to tests/format/AssemblyV0.4.26/__snapshots__/format.test.js.snap diff --git a/tests/format/AssemblyV0.4.26/format.test.js b/tests/format/AssemblyV0.4.26/format.test.js new file mode 100644 index 000000000..94898ac13 --- /dev/null +++ b/tests/format/AssemblyV0.4.26/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['solidity-parse'], { compiler: '0.4.26' }); diff --git a/tests/format/AssemblyV0.4.26/jsfmt.spec.js b/tests/format/AssemblyV0.4.26/jsfmt.spec.js deleted file mode 100644 index fb953582e..000000000 --- a/tests/format/AssemblyV0.4.26/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['solidity-parse'], { compiler: '0.4.26' }); diff --git a/tests/format/BasicIterator/__snapshots__/jsfmt.spec.js.snap b/tests/format/BasicIterator/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/BasicIterator/__snapshots__/jsfmt.spec.js.snap rename to tests/format/BasicIterator/__snapshots__/format.test.js.snap diff --git a/tests/format/BasicIterator/format.test.js b/tests/format/BasicIterator/format.test.js new file mode 100644 index 000000000..94898ac13 --- /dev/null +++ b/tests/format/BasicIterator/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['solidity-parse'], { compiler: '0.4.26' }); diff --git a/tests/format/BasicIterator/jsfmt.spec.js b/tests/format/BasicIterator/jsfmt.spec.js deleted file mode 100644 index fb953582e..000000000 --- a/tests/format/BasicIterator/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['solidity-parse'], { compiler: '0.4.26' }); diff --git a/tests/format/BinaryOperators/__snapshots__/jsfmt.spec.js.snap b/tests/format/BinaryOperators/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/BinaryOperators/__snapshots__/jsfmt.spec.js.snap rename to tests/format/BinaryOperators/__snapshots__/format.test.js.snap diff --git a/tests/format/BinaryOperators/format.test.js b/tests/format/BinaryOperators/format.test.js new file mode 100644 index 000000000..6e40b58d0 --- /dev/null +++ b/tests/format/BinaryOperators/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['slang'], { compiler: '0.5.8' }); diff --git a/tests/format/BinaryOperators/jsfmt.spec.js b/tests/format/BinaryOperators/jsfmt.spec.js deleted file mode 100644 index 2845e66fa..000000000 --- a/tests/format/BinaryOperators/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['slang'], { compiler: '0.5.8' }); diff --git a/tests/format/BreakingChangesV0.7.4/__snapshots__/jsfmt.spec.js.snap b/tests/format/BreakingChangesV0.7.4/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/BreakingChangesV0.7.4/__snapshots__/jsfmt.spec.js.snap rename to tests/format/BreakingChangesV0.7.4/__snapshots__/format.test.js.snap diff --git a/tests/format/BreakingChangesV0.7.4/format.test.js b/tests/format/BreakingChangesV0.7.4/format.test.js new file mode 100644 index 000000000..8754901ae --- /dev/null +++ b/tests/format/BreakingChangesV0.7.4/format.test.js @@ -0,0 +1,12 @@ +runFormatTest(import.meta, ['slang'], { compiler: '0.7.4' }); +runFormatTest(import.meta, ['slang'], { + compiler: '0.7.4', + bracketSpacing: true +}); +runFormatTest(import.meta, ['slang'], { compiler: '0.7.3' }); +runFormatTest(import.meta, ['slang'], { + compiler: '0.7.3', + bracketSpacing: true +}); +runFormatTest(import.meta, ['slang']); +runFormatTest(import.meta, ['slang'], { bracketSpacing: true }); diff --git a/tests/format/BreakingChangesV0.7.4/jsfmt.spec.js b/tests/format/BreakingChangesV0.7.4/jsfmt.spec.js deleted file mode 100644 index 5570c0e9d..000000000 --- a/tests/format/BreakingChangesV0.7.4/jsfmt.spec.js +++ /dev/null @@ -1,6 +0,0 @@ -run_spec(import.meta, ['slang'], { compiler: '0.7.4' }); -run_spec(import.meta, ['slang'], { compiler: '0.7.4', bracketSpacing: true }); -run_spec(import.meta, ['slang'], { compiler: '0.7.3' }); -run_spec(import.meta, ['slang'], { compiler: '0.7.3', bracketSpacing: true }); -run_spec(import.meta, ['slang']); -run_spec(import.meta, ['slang'], { bracketSpacing: true }); diff --git a/tests/format/BreakingChangesV0.8.0/__snapshots__/jsfmt.spec.js.snap b/tests/format/BreakingChangesV0.8.0/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/BreakingChangesV0.8.0/__snapshots__/jsfmt.spec.js.snap rename to tests/format/BreakingChangesV0.8.0/__snapshots__/format.test.js.snap diff --git a/tests/format/BreakingChangesV0.8.0/format.test.js b/tests/format/BreakingChangesV0.8.0/format.test.js new file mode 100644 index 000000000..93ca0fd2b --- /dev/null +++ b/tests/format/BreakingChangesV0.8.0/format.test.js @@ -0,0 +1,3 @@ +runFormatTest(import.meta, ['solidity-parse']); +runFormatTest(import.meta, ['solidity-parse'], { compiler: '0.8.0' }); +runFormatTest(import.meta, ['slang'], { compiler: '0.7.0' }); diff --git a/tests/format/BreakingChangesV0.8.0/jsfmt.spec.js b/tests/format/BreakingChangesV0.8.0/jsfmt.spec.js deleted file mode 100644 index 082b7093e..000000000 --- a/tests/format/BreakingChangesV0.8.0/jsfmt.spec.js +++ /dev/null @@ -1,3 +0,0 @@ -run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-parse'], { compiler: '0.8.0' }); -run_spec(import.meta, ['slang'], { compiler: '0.7.0' }); diff --git a/tests/format/Comments/__snapshots__/jsfmt.spec.js.snap b/tests/format/Comments/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/Comments/__snapshots__/jsfmt.spec.js.snap rename to tests/format/Comments/__snapshots__/format.test.js.snap diff --git a/tests/format/Comments/format.test.js b/tests/format/Comments/format.test.js new file mode 100644 index 000000000..109c063bb --- /dev/null +++ b/tests/format/Comments/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['solidity-parse'], { compiler: '0.4.24' }); diff --git a/tests/format/Comments/jsfmt.spec.js b/tests/format/Comments/jsfmt.spec.js deleted file mode 100644 index daacfb24c..000000000 --- a/tests/format/Comments/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['solidity-parse'], { compiler: '0.4.24' }); diff --git a/tests/format/Conditional/__snapshots__/jsfmt.spec.js.snap b/tests/format/Conditional/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/Conditional/__snapshots__/jsfmt.spec.js.snap rename to tests/format/Conditional/__snapshots__/format.test.js.snap diff --git a/tests/format/Conditional/format.test.js b/tests/format/Conditional/format.test.js new file mode 100644 index 000000000..6021bbb0d --- /dev/null +++ b/tests/format/Conditional/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['slang']); diff --git a/tests/format/Conditional/jsfmt.spec.js b/tests/format/Conditional/jsfmt.spec.js deleted file mode 100644 index 418f6872d..000000000 --- a/tests/format/Conditional/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['slang']); diff --git a/tests/format/Constructors/__snapshots__/jsfmt.spec.js.snap b/tests/format/Constructors/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/Constructors/__snapshots__/jsfmt.spec.js.snap rename to tests/format/Constructors/__snapshots__/format.test.js.snap diff --git a/tests/format/Constructors/format.test.js b/tests/format/Constructors/format.test.js new file mode 100644 index 000000000..6021bbb0d --- /dev/null +++ b/tests/format/Constructors/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['slang']); diff --git a/tests/format/Constructors/jsfmt.spec.js b/tests/format/Constructors/jsfmt.spec.js deleted file mode 100644 index 418f6872d..000000000 --- a/tests/format/Constructors/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['slang']); diff --git a/tests/format/ContractDefinitions/__snapshots__/jsfmt.spec.js.snap b/tests/format/ContractDefinitions/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/ContractDefinitions/__snapshots__/jsfmt.spec.js.snap rename to tests/format/ContractDefinitions/__snapshots__/format.test.js.snap diff --git a/tests/format/ContractDefinitions/format.test.js b/tests/format/ContractDefinitions/format.test.js new file mode 100644 index 000000000..6021bbb0d --- /dev/null +++ b/tests/format/ContractDefinitions/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['slang']); diff --git a/tests/format/ContractDefinitions/jsfmt.spec.js b/tests/format/ContractDefinitions/jsfmt.spec.js deleted file mode 100644 index 418f6872d..000000000 --- a/tests/format/ContractDefinitions/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['slang']); diff --git a/tests/format/CustomErrors/__snapshots__/jsfmt.spec.js.snap b/tests/format/CustomErrors/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/CustomErrors/__snapshots__/jsfmt.spec.js.snap rename to tests/format/CustomErrors/__snapshots__/format.test.js.snap diff --git a/tests/format/CustomErrors/format.test.js b/tests/format/CustomErrors/format.test.js new file mode 100644 index 000000000..6021bbb0d --- /dev/null +++ b/tests/format/CustomErrors/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['slang']); diff --git a/tests/format/CustomErrors/jsfmt.spec.js b/tests/format/CustomErrors/jsfmt.spec.js deleted file mode 100644 index 418f6872d..000000000 --- a/tests/format/CustomErrors/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['slang']); diff --git a/tests/format/EnumDefinitions/__snapshots__/jsfmt.spec.js.snap b/tests/format/EnumDefinitions/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/EnumDefinitions/__snapshots__/jsfmt.spec.js.snap rename to tests/format/EnumDefinitions/__snapshots__/format.test.js.snap diff --git a/tests/format/EnumDefinitions/format.test.js b/tests/format/EnumDefinitions/format.test.js new file mode 100644 index 000000000..6021bbb0d --- /dev/null +++ b/tests/format/EnumDefinitions/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['slang']); diff --git a/tests/format/EnumDefinitions/jsfmt.spec.js b/tests/format/EnumDefinitions/jsfmt.spec.js deleted file mode 100644 index 418f6872d..000000000 --- a/tests/format/EnumDefinitions/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['slang']); diff --git a/tests/format/Etc/__snapshots__/jsfmt.spec.js.snap b/tests/format/Etc/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/Etc/__snapshots__/jsfmt.spec.js.snap rename to tests/format/Etc/__snapshots__/format.test.js.snap diff --git a/tests/format/Etc/format.test.js b/tests/format/Etc/format.test.js new file mode 100644 index 000000000..2ae629864 --- /dev/null +++ b/tests/format/Etc/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['solidity-parse']); diff --git a/tests/format/Etc/jsfmt.spec.js b/tests/format/Etc/jsfmt.spec.js deleted file mode 100644 index 765dd60a6..000000000 --- a/tests/format/Etc/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/ExperimentalTernaries/__snapshots__/jsfmt.spec.js.snap b/tests/format/ExperimentalTernaries/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/ExperimentalTernaries/__snapshots__/jsfmt.spec.js.snap rename to tests/format/ExperimentalTernaries/__snapshots__/format.test.js.snap diff --git a/tests/format/ExperimentalTernaries/format.test.js b/tests/format/ExperimentalTernaries/format.test.js new file mode 100644 index 000000000..d12aeb806 --- /dev/null +++ b/tests/format/ExperimentalTernaries/format.test.js @@ -0,0 +1,10 @@ +runFormatTest(import.meta, ['solidity-parse']); +runFormatTest(import.meta, ['solidity-parse'], { experimentalTernaries: true }); +runFormatTest(import.meta, ['solidity-parse'], { + experimentalTernaries: true, + tabWidth: 1 +}); +runFormatTest(import.meta, ['solidity-parse'], { + experimentalTernaries: true, + useTabs: true +}); diff --git a/tests/format/ExperimentalTernaries/jsfmt.spec.js b/tests/format/ExperimentalTernaries/jsfmt.spec.js deleted file mode 100644 index c79991703..000000000 --- a/tests/format/ExperimentalTernaries/jsfmt.spec.js +++ /dev/null @@ -1,10 +0,0 @@ -run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-parse'], { experimentalTernaries: true }); -run_spec(import.meta, ['solidity-parse'], { - experimentalTernaries: true, - tabWidth: 1 -}); -run_spec(import.meta, ['solidity-parse'], { - experimentalTernaries: true, - useTabs: true -}); diff --git a/tests/format/ForStatements/__snapshots__/jsfmt.spec.js.snap b/tests/format/ForStatements/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/ForStatements/__snapshots__/jsfmt.spec.js.snap rename to tests/format/ForStatements/__snapshots__/format.test.js.snap diff --git a/tests/format/ForStatements/format.test.js b/tests/format/ForStatements/format.test.js new file mode 100644 index 000000000..6021bbb0d --- /dev/null +++ b/tests/format/ForStatements/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['slang']); diff --git a/tests/format/ForStatements/jsfmt.spec.js b/tests/format/ForStatements/jsfmt.spec.js deleted file mode 100644 index 418f6872d..000000000 --- a/tests/format/ForStatements/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['slang']); diff --git a/tests/format/FunctionCalls/__snapshots__/jsfmt.spec.js.snap b/tests/format/FunctionCalls/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/FunctionCalls/__snapshots__/jsfmt.spec.js.snap rename to tests/format/FunctionCalls/__snapshots__/format.test.js.snap diff --git a/tests/format/FunctionCalls/format.test.js b/tests/format/FunctionCalls/format.test.js new file mode 100644 index 000000000..e49333cd8 --- /dev/null +++ b/tests/format/FunctionCalls/format.test.js @@ -0,0 +1,2 @@ +runFormatTest(import.meta, ['slang']); +runFormatTest(import.meta, ['slang'], { bracketSpacing: true }); diff --git a/tests/format/FunctionCalls/jsfmt.spec.js b/tests/format/FunctionCalls/jsfmt.spec.js deleted file mode 100644 index 297dfaa0d..000000000 --- a/tests/format/FunctionCalls/jsfmt.spec.js +++ /dev/null @@ -1,2 +0,0 @@ -run_spec(import.meta, ['slang']); -run_spec(import.meta, ['slang'], { bracketSpacing: true }); diff --git a/tests/format/FunctionDefinitions/__snapshots__/jsfmt.spec.js.snap b/tests/format/FunctionDefinitions/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/FunctionDefinitions/__snapshots__/jsfmt.spec.js.snap rename to tests/format/FunctionDefinitions/__snapshots__/format.test.js.snap diff --git a/tests/format/FunctionDefinitions/format.test.js b/tests/format/FunctionDefinitions/format.test.js new file mode 100644 index 000000000..2ae629864 --- /dev/null +++ b/tests/format/FunctionDefinitions/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['solidity-parse']); diff --git a/tests/format/FunctionDefinitions/jsfmt.spec.js b/tests/format/FunctionDefinitions/jsfmt.spec.js deleted file mode 100644 index 765dd60a6..000000000 --- a/tests/format/FunctionDefinitions/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/FunctionDefinitionsv0.5.0/__snapshots__/jsfmt.spec.js.snap b/tests/format/FunctionDefinitionsv0.5.0/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/FunctionDefinitionsv0.5.0/__snapshots__/jsfmt.spec.js.snap rename to tests/format/FunctionDefinitionsv0.5.0/__snapshots__/format.test.js.snap diff --git a/tests/format/FunctionDefinitionsv0.5.0/format.test.js b/tests/format/FunctionDefinitionsv0.5.0/format.test.js new file mode 100644 index 000000000..a5617bcf4 --- /dev/null +++ b/tests/format/FunctionDefinitionsv0.5.0/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['slang'], { compiler: '0.5.0' }); diff --git a/tests/format/FunctionDefinitionsv0.5.0/jsfmt.spec.js b/tests/format/FunctionDefinitionsv0.5.0/jsfmt.spec.js deleted file mode 100644 index 50eb2964b..000000000 --- a/tests/format/FunctionDefinitionsv0.5.0/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['slang'], { compiler: '0.5.0' }); diff --git a/tests/format/HexLiteral/__snapshots__/jsfmt.spec.js.snap b/tests/format/HexLiteral/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/HexLiteral/__snapshots__/jsfmt.spec.js.snap rename to tests/format/HexLiteral/__snapshots__/format.test.js.snap diff --git a/tests/format/HexLiteral/format.test.js b/tests/format/HexLiteral/format.test.js new file mode 100644 index 000000000..446f85680 --- /dev/null +++ b/tests/format/HexLiteral/format.test.js @@ -0,0 +1,2 @@ +runFormatTest(import.meta, ['slang'], { singleQuote: true }); +runFormatTest(import.meta, ['slang'], { singleQuote: false }); diff --git a/tests/format/HexLiteral/jsfmt.spec.js b/tests/format/HexLiteral/jsfmt.spec.js deleted file mode 100644 index 30121cb5f..000000000 --- a/tests/format/HexLiteral/jsfmt.spec.js +++ /dev/null @@ -1,2 +0,0 @@ -run_spec(import.meta, ['slang'], { singleQuote: true }); -run_spec(import.meta, ['slang'], { singleQuote: false }); diff --git a/tests/format/IfStatements/__snapshots__/jsfmt.spec.js.snap b/tests/format/IfStatements/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/IfStatements/__snapshots__/jsfmt.spec.js.snap rename to tests/format/IfStatements/__snapshots__/format.test.js.snap diff --git a/tests/format/IfStatements/format.test.js b/tests/format/IfStatements/format.test.js new file mode 100644 index 000000000..6021bbb0d --- /dev/null +++ b/tests/format/IfStatements/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['slang']); diff --git a/tests/format/IfStatements/jsfmt.spec.js b/tests/format/IfStatements/jsfmt.spec.js deleted file mode 100644 index 418f6872d..000000000 --- a/tests/format/IfStatements/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['slang']); diff --git a/tests/format/Immutable/__snapshots__/jsfmt.spec.js.snap b/tests/format/Immutable/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/Immutable/__snapshots__/jsfmt.spec.js.snap rename to tests/format/Immutable/__snapshots__/format.test.js.snap diff --git a/tests/format/Immutable/format.test.js b/tests/format/Immutable/format.test.js new file mode 100644 index 000000000..6021bbb0d --- /dev/null +++ b/tests/format/Immutable/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['slang']); diff --git a/tests/format/Immutable/jsfmt.spec.js b/tests/format/Immutable/jsfmt.spec.js deleted file mode 100644 index 418f6872d..000000000 --- a/tests/format/Immutable/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['slang']); diff --git a/tests/format/ImportDirective/__snapshots__/jsfmt.spec.js.snap b/tests/format/ImportDirective/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/ImportDirective/__snapshots__/jsfmt.spec.js.snap rename to tests/format/ImportDirective/__snapshots__/format.test.js.snap diff --git a/tests/format/ImportDirective/format.test.js b/tests/format/ImportDirective/format.test.js new file mode 100644 index 000000000..7bed92968 --- /dev/null +++ b/tests/format/ImportDirective/format.test.js @@ -0,0 +1,2 @@ +runFormatTest(import.meta, ['solidity-parse']); +runFormatTest(import.meta, ['solidity-parse'], { bracketSpacing: true }); diff --git a/tests/format/ImportDirective/jsfmt.spec.js b/tests/format/ImportDirective/jsfmt.spec.js deleted file mode 100644 index 993a81764..000000000 --- a/tests/format/ImportDirective/jsfmt.spec.js +++ /dev/null @@ -1,2 +0,0 @@ -run_spec(import.meta, ['solidity-parse']); -run_spec(import.meta, ['solidity-parse'], { bracketSpacing: true }); diff --git a/tests/format/Inbox/__snapshots__/jsfmt.spec.js.snap b/tests/format/Inbox/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/Inbox/__snapshots__/jsfmt.spec.js.snap rename to tests/format/Inbox/__snapshots__/format.test.js.snap diff --git a/tests/format/Inbox/format.test.js b/tests/format/Inbox/format.test.js new file mode 100644 index 000000000..6021bbb0d --- /dev/null +++ b/tests/format/Inbox/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['slang']); diff --git a/tests/format/Inbox/jsfmt.spec.js b/tests/format/Inbox/jsfmt.spec.js deleted file mode 100644 index 418f6872d..000000000 --- a/tests/format/Inbox/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['slang']); diff --git a/tests/format/IndexOf/__snapshots__/jsfmt.spec.js.snap b/tests/format/IndexOf/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/IndexOf/__snapshots__/jsfmt.spec.js.snap rename to tests/format/IndexOf/__snapshots__/format.test.js.snap diff --git a/tests/format/IndexOf/format.test.js b/tests/format/IndexOf/format.test.js new file mode 100644 index 000000000..2ae629864 --- /dev/null +++ b/tests/format/IndexOf/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['solidity-parse']); diff --git a/tests/format/IndexOf/jsfmt.spec.js b/tests/format/IndexOf/jsfmt.spec.js deleted file mode 100644 index 765dd60a6..000000000 --- a/tests/format/IndexOf/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/IndexRangeAccess/__snapshots__/jsfmt.spec.js.snap b/tests/format/IndexRangeAccess/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/IndexRangeAccess/__snapshots__/jsfmt.spec.js.snap rename to tests/format/IndexRangeAccess/__snapshots__/format.test.js.snap diff --git a/tests/format/IndexRangeAccess/format.test.js b/tests/format/IndexRangeAccess/format.test.js new file mode 100644 index 000000000..6021bbb0d --- /dev/null +++ b/tests/format/IndexRangeAccess/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['slang']); diff --git a/tests/format/IndexRangeAccess/jsfmt.spec.js b/tests/format/IndexRangeAccess/jsfmt.spec.js deleted file mode 100644 index 418f6872d..000000000 --- a/tests/format/IndexRangeAccess/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['slang']); diff --git a/tests/format/InheritanceSpecifier/__snapshots__/jsfmt.spec.js.snap b/tests/format/InheritanceSpecifier/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/InheritanceSpecifier/__snapshots__/jsfmt.spec.js.snap rename to tests/format/InheritanceSpecifier/__snapshots__/format.test.js.snap diff --git a/tests/format/InheritanceSpecifier/format.test.js b/tests/format/InheritanceSpecifier/format.test.js new file mode 100644 index 000000000..6021bbb0d --- /dev/null +++ b/tests/format/InheritanceSpecifier/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['slang']); diff --git a/tests/format/InheritanceSpecifier/jsfmt.spec.js b/tests/format/InheritanceSpecifier/jsfmt.spec.js deleted file mode 100644 index 418f6872d..000000000 --- a/tests/format/InheritanceSpecifier/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['slang']); diff --git a/tests/format/Issues/__snapshots__/jsfmt.spec.js.snap b/tests/format/Issues/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/Issues/__snapshots__/jsfmt.spec.js.snap rename to tests/format/Issues/__snapshots__/format.test.js.snap diff --git a/tests/format/Issues/format.test.js b/tests/format/Issues/format.test.js new file mode 100644 index 000000000..2ae629864 --- /dev/null +++ b/tests/format/Issues/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['solidity-parse']); diff --git a/tests/format/Issues/jsfmt.spec.js b/tests/format/Issues/jsfmt.spec.js deleted file mode 100644 index 765dd60a6..000000000 --- a/tests/format/Issues/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/Libraries/__snapshots__/jsfmt.spec.js.snap b/tests/format/Libraries/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/Libraries/__snapshots__/jsfmt.spec.js.snap rename to tests/format/Libraries/__snapshots__/format.test.js.snap diff --git a/tests/format/Libraries/format.test.js b/tests/format/Libraries/format.test.js new file mode 100644 index 000000000..e49333cd8 --- /dev/null +++ b/tests/format/Libraries/format.test.js @@ -0,0 +1,2 @@ +runFormatTest(import.meta, ['slang']); +runFormatTest(import.meta, ['slang'], { bracketSpacing: true }); diff --git a/tests/format/Libraries/jsfmt.spec.js b/tests/format/Libraries/jsfmt.spec.js deleted file mode 100644 index 297dfaa0d..000000000 --- a/tests/format/Libraries/jsfmt.spec.js +++ /dev/null @@ -1,2 +0,0 @@ -run_spec(import.meta, ['slang']); -run_spec(import.meta, ['slang'], { bracketSpacing: true }); diff --git a/tests/format/Markdown/__snapshots__/jsfmt.spec.js.snap b/tests/format/Markdown/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/Markdown/__snapshots__/jsfmt.spec.js.snap rename to tests/format/Markdown/__snapshots__/format.test.js.snap diff --git a/tests/format/Markdown/format.test.js b/tests/format/Markdown/format.test.js new file mode 100644 index 000000000..aa8606946 --- /dev/null +++ b/tests/format/Markdown/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['markdown']); diff --git a/tests/format/Markdown/jsfmt.spec.js b/tests/format/Markdown/jsfmt.spec.js deleted file mode 100644 index cca2da906..000000000 --- a/tests/format/Markdown/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['markdown']); diff --git a/tests/format/MemberAccess/__snapshots__/jsfmt.spec.js.snap b/tests/format/MemberAccess/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/MemberAccess/__snapshots__/jsfmt.spec.js.snap rename to tests/format/MemberAccess/__snapshots__/format.test.js.snap diff --git a/tests/format/MemberAccess/format.test.js b/tests/format/MemberAccess/format.test.js new file mode 100644 index 000000000..2ae629864 --- /dev/null +++ b/tests/format/MemberAccess/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['solidity-parse']); diff --git a/tests/format/MemberAccess/jsfmt.spec.js b/tests/format/MemberAccess/jsfmt.spec.js deleted file mode 100644 index 765dd60a6..000000000 --- a/tests/format/MemberAccess/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/ModifierDefinitions/__snapshots__/jsfmt.spec.js.snap b/tests/format/ModifierDefinitions/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/ModifierDefinitions/__snapshots__/jsfmt.spec.js.snap rename to tests/format/ModifierDefinitions/__snapshots__/format.test.js.snap diff --git a/tests/format/ModifierDefinitions/format.test.js b/tests/format/ModifierDefinitions/format.test.js new file mode 100644 index 000000000..6021bbb0d --- /dev/null +++ b/tests/format/ModifierDefinitions/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['slang']); diff --git a/tests/format/ModifierDefinitions/jsfmt.spec.js b/tests/format/ModifierDefinitions/jsfmt.spec.js deleted file mode 100644 index 418f6872d..000000000 --- a/tests/format/ModifierDefinitions/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['slang']); diff --git a/tests/format/ModifierInvocations/__snapshots__/jsfmt.spec.js.snap b/tests/format/ModifierInvocations/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/ModifierInvocations/__snapshots__/jsfmt.spec.js.snap rename to tests/format/ModifierInvocations/__snapshots__/format.test.js.snap diff --git a/tests/format/ModifierInvocations/format.test.js b/tests/format/ModifierInvocations/format.test.js new file mode 100644 index 000000000..2ae629864 --- /dev/null +++ b/tests/format/ModifierInvocations/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['solidity-parse']); diff --git a/tests/format/ModifierInvocations/jsfmt.spec.js b/tests/format/ModifierInvocations/jsfmt.spec.js deleted file mode 100644 index 765dd60a6..000000000 --- a/tests/format/ModifierInvocations/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/MultipartStrings/__snapshots__/jsfmt.spec.js.snap b/tests/format/MultipartStrings/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/MultipartStrings/__snapshots__/jsfmt.spec.js.snap rename to tests/format/MultipartStrings/__snapshots__/format.test.js.snap diff --git a/tests/format/MultipartStrings/format.test.js b/tests/format/MultipartStrings/format.test.js new file mode 100644 index 000000000..6021bbb0d --- /dev/null +++ b/tests/format/MultipartStrings/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['slang']); diff --git a/tests/format/MultipartStrings/jsfmt.spec.js b/tests/format/MultipartStrings/jsfmt.spec.js deleted file mode 100644 index 418f6872d..000000000 --- a/tests/format/MultipartStrings/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['slang']); diff --git a/tests/format/NameValueExpression/__snapshots__/jsfmt.spec.js.snap b/tests/format/NameValueExpression/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/NameValueExpression/__snapshots__/jsfmt.spec.js.snap rename to tests/format/NameValueExpression/__snapshots__/format.test.js.snap diff --git a/tests/format/NameValueExpression/format.test.js b/tests/format/NameValueExpression/format.test.js new file mode 100644 index 000000000..e49333cd8 --- /dev/null +++ b/tests/format/NameValueExpression/format.test.js @@ -0,0 +1,2 @@ +runFormatTest(import.meta, ['slang']); +runFormatTest(import.meta, ['slang'], { bracketSpacing: true }); diff --git a/tests/format/NameValueExpression/jsfmt.spec.js b/tests/format/NameValueExpression/jsfmt.spec.js deleted file mode 100644 index 297dfaa0d..000000000 --- a/tests/format/NameValueExpression/jsfmt.spec.js +++ /dev/null @@ -1,2 +0,0 @@ -run_spec(import.meta, ['slang']); -run_spec(import.meta, ['slang'], { bracketSpacing: true }); diff --git a/tests/format/NumberLiteral/__snapshots__/jsfmt.spec.js.snap b/tests/format/NumberLiteral/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/NumberLiteral/__snapshots__/jsfmt.spec.js.snap rename to tests/format/NumberLiteral/__snapshots__/format.test.js.snap diff --git a/tests/format/NumberLiteral/format.test.js b/tests/format/NumberLiteral/format.test.js new file mode 100644 index 000000000..6021bbb0d --- /dev/null +++ b/tests/format/NumberLiteral/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['slang']); diff --git a/tests/format/NumberLiteral/jsfmt.spec.js b/tests/format/NumberLiteral/jsfmt.spec.js deleted file mode 100644 index 418f6872d..000000000 --- a/tests/format/NumberLiteral/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['slang']); diff --git a/tests/format/Ownable/__snapshots__/jsfmt.spec.js.snap b/tests/format/Ownable/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/Ownable/__snapshots__/jsfmt.spec.js.snap rename to tests/format/Ownable/__snapshots__/format.test.js.snap diff --git a/tests/format/Ownable/format.test.js b/tests/format/Ownable/format.test.js new file mode 100644 index 000000000..6021bbb0d --- /dev/null +++ b/tests/format/Ownable/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['slang']); diff --git a/tests/format/Ownable/jsfmt.spec.js b/tests/format/Ownable/jsfmt.spec.js deleted file mode 100644 index 418f6872d..000000000 --- a/tests/format/Ownable/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['slang']); diff --git a/tests/format/Parentheses/__snapshots__/jsfmt.spec.js.snap b/tests/format/Parentheses/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/Parentheses/__snapshots__/jsfmt.spec.js.snap rename to tests/format/Parentheses/__snapshots__/format.test.js.snap diff --git a/tests/format/Parentheses/format.test.js b/tests/format/Parentheses/format.test.js new file mode 100644 index 000000000..5ea602491 --- /dev/null +++ b/tests/format/Parentheses/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['slang'], { compiler: '0.8.6' }); diff --git a/tests/format/Parentheses/jsfmt.spec.js b/tests/format/Parentheses/jsfmt.spec.js deleted file mode 100644 index 15e75e6c2..000000000 --- a/tests/format/Parentheses/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['slang'], { compiler: '0.8.6' }); diff --git a/tests/format/Pragma/__snapshots__/jsfmt.spec.js.snap b/tests/format/Pragma/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/Pragma/__snapshots__/jsfmt.spec.js.snap rename to tests/format/Pragma/__snapshots__/format.test.js.snap diff --git a/tests/format/Pragma/format.test.js b/tests/format/Pragma/format.test.js new file mode 100644 index 000000000..6021bbb0d --- /dev/null +++ b/tests/format/Pragma/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['slang']); diff --git a/tests/format/Pragma/jsfmt.spec.js b/tests/format/Pragma/jsfmt.spec.js deleted file mode 100644 index 418f6872d..000000000 --- a/tests/format/Pragma/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['slang']); diff --git a/tests/format/PrettierIgnore/__snapshots__/jsfmt.spec.js.snap b/tests/format/PrettierIgnore/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/PrettierIgnore/__snapshots__/jsfmt.spec.js.snap rename to tests/format/PrettierIgnore/__snapshots__/format.test.js.snap diff --git a/tests/format/PrettierIgnore/format.test.js b/tests/format/PrettierIgnore/format.test.js new file mode 100644 index 000000000..2ae629864 --- /dev/null +++ b/tests/format/PrettierIgnore/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['solidity-parse']); diff --git a/tests/format/PrettierIgnore/jsfmt.spec.js b/tests/format/PrettierIgnore/jsfmt.spec.js deleted file mode 100644 index 765dd60a6..000000000 --- a/tests/format/PrettierIgnore/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/Proxy/__snapshots__/jsfmt.spec.js.snap b/tests/format/Proxy/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/Proxy/__snapshots__/jsfmt.spec.js.snap rename to tests/format/Proxy/__snapshots__/format.test.js.snap diff --git a/tests/format/Proxy/format.test.js b/tests/format/Proxy/format.test.js new file mode 100644 index 000000000..b491a5bef --- /dev/null +++ b/tests/format/Proxy/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['slang'], { compiler: '0.4.24' }); diff --git a/tests/format/Proxy/jsfmt.spec.js b/tests/format/Proxy/jsfmt.spec.js deleted file mode 100644 index 8915712ba..000000000 --- a/tests/format/Proxy/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['slang'], { compiler: '0.4.24' }); diff --git a/tests/format/RespectDefaultOptions/__snapshots__/jsfmt.spec.js.snap b/tests/format/RespectDefaultOptions/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/RespectDefaultOptions/__snapshots__/jsfmt.spec.js.snap rename to tests/format/RespectDefaultOptions/__snapshots__/format.test.js.snap diff --git a/tests/format/RespectDefaultOptions/format.test.js b/tests/format/RespectDefaultOptions/format.test.js new file mode 100644 index 000000000..563faa86a --- /dev/null +++ b/tests/format/RespectDefaultOptions/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['babel']); diff --git a/tests/format/RespectDefaultOptions/jsfmt.spec.js b/tests/format/RespectDefaultOptions/jsfmt.spec.js deleted file mode 100644 index 21d1d2cb5..000000000 --- a/tests/format/RespectDefaultOptions/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['babel']); diff --git a/tests/format/SampleCrowdsale/__snapshots__/jsfmt.spec.js.snap b/tests/format/SampleCrowdsale/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/SampleCrowdsale/__snapshots__/jsfmt.spec.js.snap rename to tests/format/SampleCrowdsale/__snapshots__/format.test.js.snap diff --git a/tests/format/SampleCrowdsale/format.test.js b/tests/format/SampleCrowdsale/format.test.js new file mode 100644 index 000000000..6021bbb0d --- /dev/null +++ b/tests/format/SampleCrowdsale/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['slang']); diff --git a/tests/format/SampleCrowdsale/jsfmt.spec.js b/tests/format/SampleCrowdsale/jsfmt.spec.js deleted file mode 100644 index 418f6872d..000000000 --- a/tests/format/SampleCrowdsale/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['slang']); diff --git a/tests/format/SimpleAuction/__snapshots__/jsfmt.spec.js.snap b/tests/format/SimpleAuction/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/SimpleAuction/__snapshots__/jsfmt.spec.js.snap rename to tests/format/SimpleAuction/__snapshots__/format.test.js.snap diff --git a/tests/format/SimpleAuction/format.test.js b/tests/format/SimpleAuction/format.test.js new file mode 100644 index 000000000..6021bbb0d --- /dev/null +++ b/tests/format/SimpleAuction/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['slang']); diff --git a/tests/format/SimpleAuction/jsfmt.spec.js b/tests/format/SimpleAuction/jsfmt.spec.js deleted file mode 100644 index 418f6872d..000000000 --- a/tests/format/SimpleAuction/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['slang']); diff --git a/tests/format/SimpleStorage/__snapshots__/jsfmt.spec.js.snap b/tests/format/SimpleStorage/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/SimpleStorage/__snapshots__/jsfmt.spec.js.snap rename to tests/format/SimpleStorage/__snapshots__/format.test.js.snap diff --git a/tests/format/SimpleStorage/format.test.js b/tests/format/SimpleStorage/format.test.js new file mode 100644 index 000000000..6021bbb0d --- /dev/null +++ b/tests/format/SimpleStorage/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['slang']); diff --git a/tests/format/SimpleStorage/jsfmt.spec.js b/tests/format/SimpleStorage/jsfmt.spec.js deleted file mode 100644 index 418f6872d..000000000 --- a/tests/format/SimpleStorage/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['slang']); diff --git a/tests/format/SplittableCommodity/__snapshots__/jsfmt.spec.js.snap b/tests/format/SplittableCommodity/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/SplittableCommodity/__snapshots__/jsfmt.spec.js.snap rename to tests/format/SplittableCommodity/__snapshots__/format.test.js.snap diff --git a/tests/format/SplittableCommodity/format.test.js b/tests/format/SplittableCommodity/format.test.js new file mode 100644 index 000000000..6021bbb0d --- /dev/null +++ b/tests/format/SplittableCommodity/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['slang']); diff --git a/tests/format/SplittableCommodity/jsfmt.spec.js b/tests/format/SplittableCommodity/jsfmt.spec.js deleted file mode 100644 index 418f6872d..000000000 --- a/tests/format/SplittableCommodity/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['slang']); diff --git a/tests/format/StateVariableDeclarations/__snapshots__/jsfmt.spec.js.snap b/tests/format/StateVariableDeclarations/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/StateVariableDeclarations/__snapshots__/jsfmt.spec.js.snap rename to tests/format/StateVariableDeclarations/__snapshots__/format.test.js.snap diff --git a/tests/format/StateVariableDeclarations/format.test.js b/tests/format/StateVariableDeclarations/format.test.js new file mode 100644 index 000000000..6021bbb0d --- /dev/null +++ b/tests/format/StateVariableDeclarations/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['slang']); diff --git a/tests/format/StateVariableDeclarations/jsfmt.spec.js b/tests/format/StateVariableDeclarations/jsfmt.spec.js deleted file mode 100644 index 418f6872d..000000000 --- a/tests/format/StateVariableDeclarations/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['slang']); diff --git a/tests/format/StringLiteral/__snapshots__/jsfmt.spec.js.snap b/tests/format/StringLiteral/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/StringLiteral/__snapshots__/jsfmt.spec.js.snap rename to tests/format/StringLiteral/__snapshots__/format.test.js.snap diff --git a/tests/format/StringLiteral/format.test.js b/tests/format/StringLiteral/format.test.js new file mode 100644 index 000000000..6021bbb0d --- /dev/null +++ b/tests/format/StringLiteral/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['slang']); diff --git a/tests/format/StringLiteral/jsfmt.spec.js b/tests/format/StringLiteral/jsfmt.spec.js deleted file mode 100644 index 418f6872d..000000000 --- a/tests/format/StringLiteral/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['slang']); diff --git a/tests/format/StyleGuide/__snapshots__/jsfmt.spec.js.snap b/tests/format/StyleGuide/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/StyleGuide/__snapshots__/jsfmt.spec.js.snap rename to tests/format/StyleGuide/__snapshots__/format.test.js.snap diff --git a/tests/format/StyleGuide/format.test.js b/tests/format/StyleGuide/format.test.js new file mode 100644 index 000000000..a5617bcf4 --- /dev/null +++ b/tests/format/StyleGuide/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['slang'], { compiler: '0.5.0' }); diff --git a/tests/format/StyleGuide/jsfmt.spec.js b/tests/format/StyleGuide/jsfmt.spec.js deleted file mode 100644 index 50eb2964b..000000000 --- a/tests/format/StyleGuide/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['slang'], { compiler: '0.5.0' }); diff --git a/tests/format/TryCatch/__snapshots__/jsfmt.spec.js.snap b/tests/format/TryCatch/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/TryCatch/__snapshots__/jsfmt.spec.js.snap rename to tests/format/TryCatch/__snapshots__/format.test.js.snap diff --git a/tests/format/TryCatch/format.test.js b/tests/format/TryCatch/format.test.js new file mode 100644 index 000000000..6021bbb0d --- /dev/null +++ b/tests/format/TryCatch/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['slang']); diff --git a/tests/format/TryCatch/jsfmt.spec.js b/tests/format/TryCatch/jsfmt.spec.js deleted file mode 100644 index 418f6872d..000000000 --- a/tests/format/TryCatch/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['slang']); diff --git a/tests/format/Tupples/Tupples.sol b/tests/format/Tuples/Tuples.sol similarity index 100% rename from tests/format/Tupples/Tupples.sol rename to tests/format/Tuples/Tuples.sol diff --git a/tests/format/Tupples/__snapshots__/jsfmt.spec.js.snap b/tests/format/Tuples/__snapshots__/format.test.js.snap similarity index 98% rename from tests/format/Tupples/__snapshots__/jsfmt.spec.js.snap rename to tests/format/Tuples/__snapshots__/format.test.js.snap index 5a1ceaf74..9195646b8 100644 --- a/tests/format/Tupples/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/Tuples/__snapshots__/format.test.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Tupples.sol format 1`] = ` +exports[`Tuples.sol format 1`] = ` ====================================options===================================== parsers: ["slang"] printWidth: 80 diff --git a/tests/format/Tuples/format.test.js b/tests/format/Tuples/format.test.js new file mode 100644 index 000000000..6021bbb0d --- /dev/null +++ b/tests/format/Tuples/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['slang']); diff --git a/tests/format/Tupples/jsfmt.spec.js b/tests/format/Tupples/jsfmt.spec.js deleted file mode 100644 index 418f6872d..000000000 --- a/tests/format/Tupples/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['slang']); diff --git a/tests/format/TypeDefinition/__snapshots__/jsfmt.spec.js.snap b/tests/format/TypeDefinition/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/TypeDefinition/__snapshots__/jsfmt.spec.js.snap rename to tests/format/TypeDefinition/__snapshots__/format.test.js.snap diff --git a/tests/format/TypeDefinition/format.test.js b/tests/format/TypeDefinition/format.test.js new file mode 100644 index 000000000..6021bbb0d --- /dev/null +++ b/tests/format/TypeDefinition/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['slang']); diff --git a/tests/format/TypeDefinition/jsfmt.spec.js b/tests/format/TypeDefinition/jsfmt.spec.js deleted file mode 100644 index 418f6872d..000000000 --- a/tests/format/TypeDefinition/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['slang']); diff --git a/tests/format/WhileStatements/__snapshots__/jsfmt.spec.js.snap b/tests/format/WhileStatements/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/WhileStatements/__snapshots__/jsfmt.spec.js.snap rename to tests/format/WhileStatements/__snapshots__/format.test.js.snap diff --git a/tests/format/WhileStatements/format.test.js b/tests/format/WhileStatements/format.test.js new file mode 100644 index 000000000..6021bbb0d --- /dev/null +++ b/tests/format/WhileStatements/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['slang']); diff --git a/tests/format/WhileStatements/jsfmt.spec.js b/tests/format/WhileStatements/jsfmt.spec.js deleted file mode 100644 index 418f6872d..000000000 --- a/tests/format/WhileStatements/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['slang']); diff --git a/tests/format/WrongCompiler/__snapshots__/jsfmt.spec.js.snap b/tests/format/WrongCompiler/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/WrongCompiler/__snapshots__/jsfmt.spec.js.snap rename to tests/format/WrongCompiler/__snapshots__/format.test.js.snap diff --git a/tests/format/WrongCompiler/format.test.js b/tests/format/WrongCompiler/format.test.js new file mode 100644 index 000000000..2b6fb0aba --- /dev/null +++ b/tests/format/WrongCompiler/format.test.js @@ -0,0 +1,10 @@ +// Should warn twice +runFormatTest(import.meta, ['solidity-parse'], { compiler: '0.8.4' }); +// Should warn once +runFormatTest(import.meta, ['solidity-parse'], { + compiler: 'v0.7.5-nightly.2020.11.9+commit.41f50365' +}); +// Should not warn +runFormatTest(import.meta, ['solidity-parse'], { + compiler: 'v0.7.3+commit.9bfce1f6' +}); diff --git a/tests/format/WrongCompiler/jsfmt.spec.js b/tests/format/WrongCompiler/jsfmt.spec.js deleted file mode 100644 index 0e6bb7941..000000000 --- a/tests/format/WrongCompiler/jsfmt.spec.js +++ /dev/null @@ -1,10 +0,0 @@ -// Should warn twice -run_spec(import.meta, ['solidity-parse'], { compiler: '0.8.4' }); -// Should warn once -run_spec(import.meta, ['solidity-parse'], { - compiler: 'v0.7.5-nightly.2020.11.9+commit.41f50365' -}); -// Should not warn -run_spec(import.meta, ['solidity-parse'], { - compiler: 'v0.7.3+commit.9bfce1f6' -}); diff --git a/tests/format/quotes/__snapshots__/jsfmt.spec.js.snap b/tests/format/quotes/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/quotes/__snapshots__/jsfmt.spec.js.snap rename to tests/format/quotes/__snapshots__/format.test.js.snap diff --git a/tests/format/quotes/format.test.js b/tests/format/quotes/format.test.js new file mode 100644 index 000000000..446f85680 --- /dev/null +++ b/tests/format/quotes/format.test.js @@ -0,0 +1,2 @@ +runFormatTest(import.meta, ['slang'], { singleQuote: true }); +runFormatTest(import.meta, ['slang'], { singleQuote: false }); diff --git a/tests/format/quotes/jsfmt.spec.js b/tests/format/quotes/jsfmt.spec.js deleted file mode 100644 index 30121cb5f..000000000 --- a/tests/format/quotes/jsfmt.spec.js +++ /dev/null @@ -1,2 +0,0 @@ -run_spec(import.meta, ['slang'], { singleQuote: true }); -run_spec(import.meta, ['slang'], { singleQuote: false }); diff --git a/tests/format/strings/__snapshots__/jsfmt.spec.js.snap b/tests/format/strings/__snapshots__/format.test.js.snap similarity index 100% rename from tests/format/strings/__snapshots__/jsfmt.spec.js.snap rename to tests/format/strings/__snapshots__/format.test.js.snap diff --git a/tests/format/strings/format.test.js b/tests/format/strings/format.test.js new file mode 100644 index 000000000..6021bbb0d --- /dev/null +++ b/tests/format/strings/format.test.js @@ -0,0 +1 @@ +runFormatTest(import.meta, ['slang']); diff --git a/tests/format/strings/jsfmt.spec.js b/tests/format/strings/jsfmt.spec.js deleted file mode 100644 index 418f6872d..000000000 --- a/tests/format/strings/jsfmt.spec.js +++ /dev/null @@ -1 +0,0 @@ -run_spec(import.meta, ['slang']); From 53967bf4e0596a02c23af0680adba0a09a390dc7 Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 10 Jul 2024 11:56:22 +1200 Subject: [PATCH 057/160] NamedImport does not exist in solidity-parser so this syntax will generate 2 different results depending on the parser --- tests/config/run-format-test.js | 1 - .../__snapshots__/format.test.js.snap | 45 +++++++++++++++++++ tests/format/ImportDirective/format.test.js | 2 + 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/tests/config/run-format-test.js b/tests/config/run-format-test.js index 1ea19cd10..d19f3442b 100644 --- a/tests/config/run-format-test.js +++ b/tests/config/run-format-test.js @@ -49,7 +49,6 @@ const testsWithSlang = new Map( // "Etc/Etc.sol", // TODO: Fix solidity-parser function type // "ExperimentalTernaries/ExperimentalTernaries.sol", // TODO: fix this one // "FunctionDefinitions/FunctionDefinitions.sol", // TODO: remove () safely in modifiers without arguments - // "ImportDirective/ImportDirectives.sol", // TODO: separate tests for slang and solidity-parser // "IndexOf/IndexOf.sol", // TODO: Finish comments and file level functions "Issues/Issue205.sol", "Issues/Issue289.sol", diff --git a/tests/format/ImportDirective/__snapshots__/format.test.js.snap b/tests/format/ImportDirective/__snapshots__/format.test.js.snap index e727c6f72..8b818c6f2 100644 --- a/tests/format/ImportDirective/__snapshots__/format.test.js.snap +++ b/tests/format/ImportDirective/__snapshots__/format.test.js.snap @@ -3,6 +3,29 @@ exports[`ImportDirectives.sol - {"bracketSpacing":true} format 1`] = ` ====================================options===================================== bracketSpacing: true +parsers: ["slang"] +printWidth: 80 + | printWidth +=====================================input====================================== +import "SomeFile.sol"; +import "SomeFile.sol" as SomeOtherFile; +import * as SomeSymbol from "AnotherFile.sol"; +import {symbol1 as alias1, symbol2} from "File.sol"; +import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol"; + +=====================================output===================================== +import "SomeFile.sol"; +import "SomeFile.sol" as SomeOtherFile; +import * as SomeSymbol from "AnotherFile.sol"; +import { symbol1 as alias1, symbol2 } from "File.sol"; +import { symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4 } from "File2.sol"; + +================================================================================ +`; + +exports[`ImportDirectives.sol - {"bracketSpacing":true} format 2`] = ` +====================================options===================================== +bracketSpacing: true parsers: ["solidity-parse"] printWidth: 80 | printWidth @@ -25,6 +48,28 @@ import { symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4 } from exports[`ImportDirectives.sol format 1`] = ` ====================================options===================================== +parsers: ["slang"] +printWidth: 80 + | printWidth +=====================================input====================================== +import "SomeFile.sol"; +import "SomeFile.sol" as SomeOtherFile; +import * as SomeSymbol from "AnotherFile.sol"; +import {symbol1 as alias1, symbol2} from "File.sol"; +import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol"; + +=====================================output===================================== +import "SomeFile.sol"; +import "SomeFile.sol" as SomeOtherFile; +import * as SomeSymbol from "AnotherFile.sol"; +import {symbol1 as alias1, symbol2} from "File.sol"; +import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from "File2.sol"; + +================================================================================ +`; + +exports[`ImportDirectives.sol format 2`] = ` +====================================options===================================== parsers: ["solidity-parse"] printWidth: 80 | printWidth diff --git a/tests/format/ImportDirective/format.test.js b/tests/format/ImportDirective/format.test.js index 7bed92968..c05fd2a7b 100644 --- a/tests/format/ImportDirective/format.test.js +++ b/tests/format/ImportDirective/format.test.js @@ -1,2 +1,4 @@ +runFormatTest(import.meta, ['slang']); +runFormatTest(import.meta, ['slang'], { bracketSpacing: true }); runFormatTest(import.meta, ['solidity-parse']); runFormatTest(import.meta, ['solidity-parse'], { bracketSpacing: true }); From d2f044cb6642526376f0fc379b640d8232af6b66 Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 10 Jul 2024 11:58:07 +1200 Subject: [PATCH 058/160] comments are assigned at the end without using an if statement. --- src/slangParser.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/slangParser.js b/src/slangParser.js index 038893310..0f5df737e 100644 --- a/src/slangParser.js +++ b/src/slangParser.js @@ -16,8 +16,10 @@ const getOffsets = (children, initialOffset) => { offsetsArray.push(offset); } if (child.type === 'Terminal' && isComment(child)) { - // TODO: avoid collecting comments as a side effect of the functionality - // for retrieving offsets + // Since the fetching the comments and calculating offsets are both done + // as we iterate over the children and the comment also depends on the + // offset, it's hard to separate these responsibilities into different + // functions. comments.push({ kind: child.kind, value: child.text, @@ -80,10 +82,6 @@ function genericParse(ast, options, parseFunction, parentOffsets = [0]) { end: offset + ast.cst.textLength.utf8 - trailingOffset }; - if (node.kind === 'SourceUnit') { - node.comments = comments.splice(0); - } - return node; } @@ -91,11 +89,13 @@ function parse(text, _parsers, options = _parsers) { const compiler = coerce(options.compiler); const language = new Language(compiler?.version || '0.8.25'); - const parsed = new SourceUnit( + const ast = new SourceUnit( language.parse(NonterminalKind.SourceUnit, text).tree() ); - return genericParse(parsed, options, genericParse); + const parsed = genericParse(ast, options, genericParse); + parsed.comments = comments.splice(0); + return parsed; } export default parse; From 857d0d9bec771616fab728a54e2bd26731cefe99 Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 10 Jul 2024 12:00:16 +1200 Subject: [PATCH 059/160] clean up binary operations --- src/common/slang-helpers.js | 52 ++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/src/common/slang-helpers.js b/src/common/slang-helpers.js index cc897d1a1..ba3186dbd 100644 --- a/src/common/slang-helpers.js +++ b/src/common/slang-helpers.js @@ -126,13 +126,22 @@ export const isBinaryOperation = createKindCheckFunction([ 'ShiftExpression' ]); +export const isBinaryOperationWithoutComparison = createKindCheckFunction([ + 'AdditiveExpression', + 'MultiplicativeExpression', + 'ExponentiationExpression', + 'AssignmentExpression', + 'BitwiseAndExpression', + 'BitwiseOrExpression', + 'BitwiseXorExpression', + 'AndExpression', + 'OrExpression', + 'ShiftExpression' +]); + const binaryGroupRulesBuilder = (path) => (document) => { const grandparentNode = path.getNode(2); - if ( - isBinaryOperation(grandparentNode) && - grandparentNode.kind !== 'ComparisonExpression' && - grandparentNode.kind !== 'EqualityExpression' - ) { + if (isBinaryOperationWithoutComparison(grandparentNode)) { return document; } return group(document); @@ -143,11 +152,7 @@ const binaryIndentRulesBuilder = (path) => (document) => { for (let i = 2; ; i += 2) { const grandparentNode = path.getNode(i); if (grandparentNode.kind === 'ReturnStatement') break; - if ( - !isBinaryOperation(grandparentNode) || - grandparentNode.kind === 'ComparisonExpression' || - grandparentNode.kind === 'EqualityExpression' - ) { + if (!isBinaryOperationWithoutComparison(grandparentNode)) { return indent(document); } if (node === grandparentNode.rightOperand.variant) break; @@ -156,8 +161,11 @@ const binaryIndentRulesBuilder = (path) => (document) => { return document; }; -const isStatementWithComparisonOperationWithoutIndentation = - createKindCheckFunction(['ReturnStatement', 'IfStatement', 'WhileStatement']); +const isStatementWithoutIndentedOperation = createKindCheckFunction([ + 'ReturnStatement', + 'IfStatement', + 'WhileStatement' +]); const comparisonIndentRulesBuilder = (path) => (document) => { let node = path.getNode(); @@ -167,8 +175,7 @@ const comparisonIndentRulesBuilder = (path) => (document) => { if (path.getNode(i + 1).kind === 'ForStatementCondition') break; else return indent(document); } - if (isStatementWithComparisonOperationWithoutIndentation(grandparentNode)) - break; + if (isStatementWithoutIndentedOperation(grandparentNode)) break; if (!isBinaryOperation(grandparentNode)) return indent(document); if (node === grandparentNode.rightOperand.variant) break; node = grandparentNode; @@ -179,23 +186,20 @@ const comparisonIndentRulesBuilder = (path) => (document) => { const logicalGroupRulesBuilder = (path) => (document) => isBinaryOperation(path.getNode(2)) ? document : group(document); -const isStatementWithLogicalOperationWithoutIndentation = - createKindCheckFunction(['ReturnStatement', 'IfStatement', 'WhileStatement']); - const logicalIndentRulesBuilder = (path, options) => (document) => { let node = path.getNode(); for (let i = 2; ; i += 2) { - const parentNode = path.getNode(i); - if (isStatementWithLogicalOperationWithoutIndentation(parentNode)) break; + const grandparentNode = path.getNode(i); + if (isStatementWithoutIndentedOperation(grandparentNode)) break; if ( options.experimentalTernaries && - parentNode.kind === 'ConditionalExpression' && - parentNode.operand.variant === node + grandparentNode.kind === 'ConditionalExpression' && + grandparentNode.operand.variant === node ) break; - if (!isBinaryOperation(parentNode)) return indent(document); - if (node === parentNode.rightOperand.variant) break; - node = parentNode; + if (!isBinaryOperation(grandparentNode)) return indent(document); + if (node === grandparentNode.rightOperand.variant) break; + node = grandparentNode; } return document; }; From 2ad3d47aac8d5a8649d0cdd512e7d087f4205c07 Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 10 Jul 2024 13:15:20 +1200 Subject: [PATCH 060/160] node's start and end points are calculated to exclude Leading and Trailing comments to allow prettier to allocate them properly. --- src/common/slang-helpers.js | 2 +- src/slangParser.js | 54 +++++++++++++++++-- src/slangPrinter.js | 25 --------- tests/config/run-format-test.js | 2 - .../__snapshots__/format.test.js.snap | 2 +- tests/format/MemberAccess/format.test.js | 2 +- .../__snapshots__/format.test.js.snap | 2 +- tests/format/PrettierIgnore/format.test.js | 2 +- 8 files changed, 54 insertions(+), 37 deletions(-) diff --git a/src/common/slang-helpers.js b/src/common/slang-helpers.js index ba3186dbd..905fb3228 100644 --- a/src/common/slang-helpers.js +++ b/src/common/slang-helpers.js @@ -42,7 +42,7 @@ export function printPreservingEmptyLines(path, key, options, print) { !isLast(childPath, key, index) && // Append an empty line if the original text already had an one after the // current `node` - isNextLineEmpty(options.originalText, options.locEnd(node) - 1) + isNextLineEmpty(options.originalText, options.locEnd(node)) ? hardline : '' ]; diff --git a/src/slangParser.js b/src/slangParser.js index 0f5df737e..513b7155e 100644 --- a/src/slangParser.js +++ b/src/slangParser.js @@ -65,8 +65,6 @@ function genericParse(ast, options, parseFunction, parentOffsets = [0]) { const offset = parentOffsets.shift(); const children = ast.cst.children(); const offsets = getOffsets(children, offset); - const leadingOffset = getLeadingOffset(children); - const trailingOffset = getTrailingOffset(children); const node = parsers[ast.cst.kind].parse({ offsets, @@ -75,11 +73,57 @@ function genericParse(ast, options, parseFunction, parentOffsets = [0]) { parse: parseFunction }); + /** + * Leading and trailing Comments are considered by the parser as part of the + * innermost possible node. For example if there is a comment just before a + * variable assignment, the parser will consider the comment belongs to the + * variable name instead of the whole statement. + * + * This behaviour creates erratic outcomes when the new line of a + * SingleLineComment can trigger a group break or a prettier-ignore will + * apply to a subset of the intended nodes. + * + * ```Solidity + * // prettier-ignore + * matrix = [ + * 0, 1, 2, + * 3, 4, 5, + * 6, 7, 8 + * ]; + * ``` + */ + let leadingOffset = getLeadingOffset(children); + let trailingOffset = getTrailingOffset(children); + const startWithTrivia = offset; + const endWithTrivia = offset + ast.cst.textLength.utf8; + + if (leadingOffset === 0 || trailingOffset === 0) { + const childrenKeys = Object.keys(node); + + for (let i = 0; i < childrenKeys.length; i += 1) { + const childLoc = node[childrenKeys[i]]?.loc; + + if (childLoc) { + if ( + leadingOffset === 0 && + childLoc.startWithTrivia === startWithTrivia + ) { + leadingOffset = childLoc.start - startWithTrivia; + } + + if (trailingOffset === 0 && childLoc.endWithTrivia === endWithTrivia) { + trailingOffset = endWithTrivia - childLoc.end; + } + } + } + } + node.kind = ast.cst.kind; node.loc = { - // We ignore the leading trivia and assume the node starts after it - start: offset + leadingOffset, - end: offset + ast.cst.textLength.utf8 - trailingOffset + startWithTrivia, + start: startWithTrivia + leadingOffset, + endWithTrivia, + end: endWithTrivia - trailingOffset }; return node; diff --git a/src/slangPrinter.js b/src/slangPrinter.js index 84bed5449..62579359d 100644 --- a/src/slangPrinter.js +++ b/src/slangPrinter.js @@ -30,31 +30,6 @@ function genericPrint(path, options, print) { throw new Error(`Unknown type: ${JSON.stringify(nodeType)}`); } - // For some reason, prettier is duplicating comments when attaching them. - // This just removes the duplicated comments - // TODO: research why is this happening and report it to the prettier team - // and remove this once it's fixed. - if (node.comments) { - let i; - for (i = 0; i < node.comments.length; i += 1) { - node.comments[i].printed = true; - } - - node.comments = node.comments.filter( - (comment, index) => - index === - node.comments.findIndex( - (commentCheck) => - commentCheck.loc.start === comment.loc.start && - commentCheck.loc.end === comment.loc.end - ) - ); - - for (i = 0; i < node.comments.length; i += 1) { - node.comments[i].printed = false; - } - } - if (hasNodeIgnoreComment(node)) { ignoreComments(path); diff --git a/tests/config/run-format-test.js b/tests/config/run-format-test.js index d19f3442b..c47b066f0 100644 --- a/tests/config/run-format-test.js +++ b/tests/config/run-format-test.js @@ -57,9 +57,7 @@ const testsWithSlang = new Map( // "Issues/Issue564.sol", // TODO: solve indentation in variable declaration "Issues/Issue799.sol", "Issues/Issue843.sol", - // "MemberAccess/MemberAccess.sol", // TODO: Comments should be redone // "ModifierInvocations/ModifierInvocations.sol", - // "PrettierIgnore/PrettierIgnore.sol", ].map((fixture) => { const [file, testSlang = () => true] = Array.isArray(fixture) ? fixture diff --git a/tests/format/MemberAccess/__snapshots__/format.test.js.snap b/tests/format/MemberAccess/__snapshots__/format.test.js.snap index 34d510ad1..b58bdbf9b 100644 --- a/tests/format/MemberAccess/__snapshots__/format.test.js.snap +++ b/tests/format/MemberAccess/__snapshots__/format.test.js.snap @@ -2,7 +2,7 @@ exports[`MemberAccess.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/MemberAccess/format.test.js b/tests/format/MemberAccess/format.test.js index 2ae629864..6021bbb0d 100644 --- a/tests/format/MemberAccess/format.test.js +++ b/tests/format/MemberAccess/format.test.js @@ -1 +1 @@ -runFormatTest(import.meta, ['solidity-parse']); +runFormatTest(import.meta, ['slang']); diff --git a/tests/format/PrettierIgnore/__snapshots__/format.test.js.snap b/tests/format/PrettierIgnore/__snapshots__/format.test.js.snap index e945dda29..f9f43f5ac 100644 --- a/tests/format/PrettierIgnore/__snapshots__/format.test.js.snap +++ b/tests/format/PrettierIgnore/__snapshots__/format.test.js.snap @@ -2,7 +2,7 @@ exports[`PrettierIgnore.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/PrettierIgnore/format.test.js b/tests/format/PrettierIgnore/format.test.js index 2ae629864..6021bbb0d 100644 --- a/tests/format/PrettierIgnore/format.test.js +++ b/tests/format/PrettierIgnore/format.test.js @@ -1 +1 @@ -runFormatTest(import.meta, ['solidity-parse']); +runFormatTest(import.meta, ['slang']); From e9f6f927a0fce7a0c016108b211ee1774824b2dd Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 10 Jul 2024 16:07:41 +1200 Subject: [PATCH 061/160] function type should behave as the function definition --- src/nodes/FunctionTypeName.js | 27 ++++++++++--------- .../Etc/__snapshots__/format.test.js.snap | 16 ++++++++--- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/nodes/FunctionTypeName.js b/src/nodes/FunctionTypeName.js index 688117fa5..ee2e6589d 100644 --- a/src/nodes/FunctionTypeName.js +++ b/src/nodes/FunctionTypeName.js @@ -24,16 +24,19 @@ const stateMutability = (node) => : ''; export const FunctionTypeName = { - print: ({ node, path, print }) => [ - 'function(', - printSeparatedList(path.map(print, 'parameterTypes')), - ')', - indent( - group([ - visibility(node), - stateMutability(node), - returnTypes(node, path, print) - ]) - ) - ] + print: ({ node, path, print }) => + group([ + 'function(', + printSeparatedList(path.map(print, 'parameterTypes'), { + grouped: false + }), + ')', + indent( + group([ + visibility(node), + stateMutability(node), + returnTypes(node, path, print) + ]) + ) + ]) }; diff --git a/tests/format/Etc/__snapshots__/format.test.js.snap b/tests/format/Etc/__snapshots__/format.test.js.snap index 6662b381e..eee66d87d 100644 --- a/tests/format/Etc/__snapshots__/format.test.js.snap +++ b/tests/format/Etc/__snapshots__/format.test.js.snap @@ -67,7 +67,10 @@ pragma solidity ^0.4.24; contract Contract { struct StructWithFunctionTypes { function(uint, uint) returns (bool) a; - function(uint, uint) + function( + uint, + uint + ) returns ( bool, bytes32, @@ -80,9 +83,14 @@ contract Contract { ) a; function(bytes32, bytes32) internal view[] b; function(bytes32, bytes32) internal[] c; - function(bytes32, bytes32, bytes32, bytes32, bytes32, bytes32) - internal - view[] d; + function( + bytes32, + bytes32, + bytes32, + bytes32, + bytes32, + bytes32 + ) internal view[] d; function( bytes32, bytes32, From 0b6a23600eab875acdba8ddf15e93359ffe52018 Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 10 Jul 2024 19:10:35 +1200 Subject: [PATCH 062/160] Variable declaration indented --- .../VariableDeclarationStatement.js | 37 +++++++++++++------ tests/config/run-format-test.js | 9 +---- .../Issues/__snapshots__/format.test.js.snap | 14 +++---- tests/format/Issues/format.test.js | 2 +- 4 files changed, 34 insertions(+), 28 deletions(-) diff --git a/src/slang-nodes/VariableDeclarationStatement.js b/src/slang-nodes/VariableDeclarationStatement.js index 80b56e8ec..96e1f84da 100644 --- a/src/slang-nodes/VariableDeclarationStatement.js +++ b/src/slang-nodes/VariableDeclarationStatement.js @@ -1,7 +1,8 @@ import { doc } from 'prettier'; -const { group, indent } = doc.builders; +const { group, indent, indentIfBreak, line } = doc.builders; +let groupIndex = 0; export const VariableDeclarationStatement = { parse: ({ offsets, ast, options, parse }) => ({ variableType: parse(ast.variableType, options, parse, offsets), @@ -12,15 +13,27 @@ export const VariableDeclarationStatement = { value: ast.value ? parse(ast.value, options, parse, offsets) : undefined, semicolon: ast.semicolon.text }), - print: ({ node, path, print }) => [ - group([ - path.call(print, 'variableType'), - indent([ - node.storageLocation ? [' ', path.call(print, 'storageLocation')] : '', - ` ${node.name}` - ]) - ]), - node.value ? path.call(print, 'value') : '', - node.semicolon - ] + print: ({ node, path, print }) => { + const declarationDoc = group( + [ + path.call(print, 'variableType'), + indent([ + node.storageLocation + ? [line, path.call(print, 'storageLocation')] + : '', + ` ${node.name}` + ]) + ], + { id: `VariableDeclarationStatement.variables-${groupIndex}` } + ); + groupIndex += 1; + + return [ + declarationDoc, + indentIfBreak(node.value ? path.call(print, 'value') : '', { + groupId: declarationDoc.id + }), + node.semicolon + ]; + } }; diff --git a/tests/config/run-format-test.js b/tests/config/run-format-test.js index c47b066f0..69937b670 100644 --- a/tests/config/run-format-test.js +++ b/tests/config/run-format-test.js @@ -46,17 +46,10 @@ const testsWithSlang = new Map( // "AssemblyV0.4.26/Assembly.sol", // TODO: Report to Nomic Foundation? // "BasicIterator/BasicIterator.sol", // TODO: Fix solidity-parser comments // "Comments/Comments.sol", // TODO: finish Comments - // "Etc/Etc.sol", // TODO: Fix solidity-parser function type + // "Etc/Etc.sol", // TODO: Comments for if Statements // "ExperimentalTernaries/ExperimentalTernaries.sol", // TODO: fix this one // "FunctionDefinitions/FunctionDefinitions.sol", // TODO: remove () safely in modifiers without arguments // "IndexOf/IndexOf.sol", // TODO: Finish comments and file level functions - "Issues/Issue205.sol", - "Issues/Issue289.sol", - "Issues/Issue355.sol", - "Issues/Issue385.sol", - // "Issues/Issue564.sol", // TODO: solve indentation in variable declaration - "Issues/Issue799.sol", - "Issues/Issue843.sol", // "ModifierInvocations/ModifierInvocations.sol", ].map((fixture) => { const [file, testSlang = () => true] = Array.isArray(fixture) diff --git a/tests/format/Issues/__snapshots__/format.test.js.snap b/tests/format/Issues/__snapshots__/format.test.js.snap index 145090c30..0ca1fde74 100644 --- a/tests/format/Issues/__snapshots__/format.test.js.snap +++ b/tests/format/Issues/__snapshots__/format.test.js.snap @@ -2,7 +2,7 @@ exports[`Issue205.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -40,7 +40,7 @@ contract Example { exports[`Issue289.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -65,7 +65,7 @@ contract Issue289 { exports[`Issue355.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -101,7 +101,7 @@ contract Bug { exports[`Issue385.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -139,7 +139,7 @@ contract Issue385 { exports[`Issue564.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -172,7 +172,7 @@ contract Issue564 { exports[`Issue799.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -186,7 +186,7 @@ struct EmptyStruct {} exports[`Issue843.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/Issues/format.test.js b/tests/format/Issues/format.test.js index 2ae629864..6021bbb0d 100644 --- a/tests/format/Issues/format.test.js +++ b/tests/format/Issues/format.test.js @@ -1 +1 @@ -runFormatTest(import.meta, ['solidity-parse']); +runFormatTest(import.meta, ['slang']); From 757da83f8af15ff8aa25327555237103442762d0 Mon Sep 17 00:00:00 2001 From: Klaus Date: Fri, 12 Jul 2024 16:10:50 +1200 Subject: [PATCH 063/160] Experimental Ternaries fixed. --- src/slang-nodes/ConditionalExpression.js | 37 ++++++++++--------- src/slang-nodes/ReturnStatement.js | 2 +- tests/config/run-format-test.js | 1 - .../__snapshots__/format.test.js.snap | 8 ++-- .../ExperimentalTernaries/format.test.js | 8 ++-- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/slang-nodes/ConditionalExpression.js b/src/slang-nodes/ConditionalExpression.js index 2324e4698..51aa3bbf8 100644 --- a/src/slang-nodes/ConditionalExpression.js +++ b/src/slang-nodes/ConditionalExpression.js @@ -2,7 +2,7 @@ import { doc } from 'prettier'; import { printSeparatedItem } from '../common/printer-helpers.js'; -const { group, hardline, ifBreak, indent, line } = doc.builders; +const { group, hardline, ifBreak, indent, line, softline } = doc.builders; let groupIndex = 0; const experimentalTernaries = (node, path, print, options) => { @@ -52,23 +52,22 @@ const experimentalTernaries = (node, path, print, options) => { } const falseExpression = path.call(print, 'falseExpression'); - return group([ - conditionAndTrueExpressionGroup, - [ - falseExpressionIsTuple - ? ifBreak(line, ' ', { groupId: conditionAndTrueExpressionGroup.id }) - : isNested - ? hardline - : line, - node.colon, - falseExpressionInSameLine - ? [' ', falseExpression] - : ifBreak([fillTab, indent(falseExpression)], [' ', falseExpression], { - // We only add `fillTab` if we are sure the trueExpression is indented - groupId: conditionAndTrueExpressionGroup.id - }) - ] - ]); + const falseExpressionDoc = [ + isNested ? hardline : line, + node.colon, + falseExpressionInSameLine + ? [' ', falseExpression] + : ifBreak([fillTab, indent(falseExpression)], [' ', falseExpression], { + // We only add `fillTab` if we are sure the trueExpression is indented + groupId: conditionAndTrueExpressionGroup.id + }) + ]; + + const document = group([conditionAndTrueExpressionGroup, falseExpressionDoc]); + + return grandparent.kind === 'VariableDeclarationValue' + ? group(indent([softline, document])) + : document; }; const traditionalTernaries = (node, path, print) => @@ -95,6 +94,7 @@ export const ConditionalExpression = { if (options.experimentalTernaries) { // We can remove parentheses only because we are sure that the // `condition` must be a single `bool` value. + const operandLoc = operand.loc; while ( operand.variant.kind === 'TupleExpression' && operand.variant.items.items.length === 1 && @@ -103,6 +103,7 @@ export const ConditionalExpression = { ) { operand = operand.variant.items.items[0].expression; } + operand.loc = operandLoc; } return { diff --git a/src/slang-nodes/ReturnStatement.js b/src/slang-nodes/ReturnStatement.js index 03f56814b..f5c212963 100644 --- a/src/slang-nodes/ReturnStatement.js +++ b/src/slang-nodes/ReturnStatement.js @@ -6,7 +6,7 @@ const expression = (node, path, print, options) => { if (node.expression) { return node.expression.variant.kind === 'TupleExpression' || (options.experimentalTernaries && - node.expression.type === 'ConditionalExpression') + node.expression.variant.kind === 'ConditionalExpression') ? [' ', path.call(print, 'expression')] : group(indent([line, path.call(print, 'expression')])); } diff --git a/tests/config/run-format-test.js b/tests/config/run-format-test.js index 69937b670..7df969534 100644 --- a/tests/config/run-format-test.js +++ b/tests/config/run-format-test.js @@ -47,7 +47,6 @@ const testsWithSlang = new Map( // "BasicIterator/BasicIterator.sol", // TODO: Fix solidity-parser comments // "Comments/Comments.sol", // TODO: finish Comments // "Etc/Etc.sol", // TODO: Comments for if Statements - // "ExperimentalTernaries/ExperimentalTernaries.sol", // TODO: fix this one // "FunctionDefinitions/FunctionDefinitions.sol", // TODO: remove () safely in modifiers without arguments // "IndexOf/IndexOf.sol", // TODO: Finish comments and file level functions // "ModifierInvocations/ModifierInvocations.sol", diff --git a/tests/format/ExperimentalTernaries/__snapshots__/format.test.js.snap b/tests/format/ExperimentalTernaries/__snapshots__/format.test.js.snap index a290e72ad..3d76e3977 100644 --- a/tests/format/ExperimentalTernaries/__snapshots__/format.test.js.snap +++ b/tests/format/ExperimentalTernaries/__snapshots__/format.test.js.snap @@ -3,7 +3,7 @@ exports[`ExperimentalTernaries.sol - {"experimentalTernaries":true,"tabWidth":1} format 1`] = ` ====================================options===================================== experimentalTernaries: true -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 tabWidth: 1 | printWidth @@ -513,7 +513,7 @@ contract Conditional { exports[`ExperimentalTernaries.sol - {"experimentalTernaries":true,"useTabs":true} format 1`] = ` ====================================options===================================== experimentalTernaries: true -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 useTabs: true | printWidth @@ -1027,7 +1027,7 @@ contract Conditional { exports[`ExperimentalTernaries.sol - {"experimentalTernaries":true} format 1`] = ` ====================================options===================================== experimentalTernaries: true -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -1539,7 +1539,7 @@ contract Conditional { exports[`ExperimentalTernaries.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/ExperimentalTernaries/format.test.js b/tests/format/ExperimentalTernaries/format.test.js index d12aeb806..c4a5bb3d0 100644 --- a/tests/format/ExperimentalTernaries/format.test.js +++ b/tests/format/ExperimentalTernaries/format.test.js @@ -1,10 +1,10 @@ -runFormatTest(import.meta, ['solidity-parse']); -runFormatTest(import.meta, ['solidity-parse'], { experimentalTernaries: true }); -runFormatTest(import.meta, ['solidity-parse'], { +runFormatTest(import.meta, ['slang']); +runFormatTest(import.meta, ['slang'], { experimentalTernaries: true }); +runFormatTest(import.meta, ['slang'], { experimentalTernaries: true, tabWidth: 1 }); -runFormatTest(import.meta, ['solidity-parse'], { +runFormatTest(import.meta, ['slang'], { experimentalTernaries: true, useTabs: true }); From c11acc731c782339918871656606010cd57e5b86 Mon Sep 17 00:00:00 2001 From: Klaus Date: Sun, 14 Jul 2024 00:26:32 +1200 Subject: [PATCH 064/160] using classes instead of loose functions --- .eslintrc | 3 +- src/common/slang-helpers.js | 26 --- .../handleParametersDeclarationComments.js | 37 ++++ src/slang-comments/handlers/index.js | 2 + src/slang-nodes/ABICoderPragma.js | 25 ++- src/slang-nodes/AdditiveExpression.js | 38 +++-- src/slang-nodes/AddressType.js | 26 ++- src/slang-nodes/AndExpression.js | 28 ++- src/slang-nodes/ArgumentsDeclaration.js | 21 ++- src/slang-nodes/ArrayExpression.js | 33 +++- src/slang-nodes/ArrayTypeName.js | 45 +++-- src/slang-nodes/ArrayValues.js | 26 ++- src/slang-nodes/AssemblyFlags.js | 26 ++- src/slang-nodes/AssemblyFlagsDeclaration.js | 33 ++-- src/slang-nodes/AssemblyStatement.js | 47 ++++-- src/slang-nodes/AssignmentExpression.js | 40 +++-- src/slang-nodes/BitwiseAndExpression.js | 38 +++-- src/slang-nodes/BitwiseOrExpression.js | 38 +++-- src/slang-nodes/BitwiseXorExpression.js | 38 +++-- src/slang-nodes/Block.js | 33 ++-- src/slang-nodes/BreakStatement.js | 25 ++- src/slang-nodes/CallOptions.js | 29 +++- src/slang-nodes/CallOptionsExpression.js | 43 +++-- src/slang-nodes/CatchClause.js | 39 +++-- src/slang-nodes/CatchClauseError.js | 28 +-- src/slang-nodes/CatchClauses.js | 22 ++- src/slang-nodes/ComparisonExpression.js | 28 ++- src/slang-nodes/ConditionalExpression.js | 64 ++++--- src/slang-nodes/ConstantDefinition.js | 41 +++-- src/slang-nodes/ConstructorAttribute.js | 28 +-- src/slang-nodes/ConstructorAttributes.js | 25 ++- src/slang-nodes/ConstructorDefinition.js | 33 ++-- src/slang-nodes/ContinueStatement.js | 25 ++- src/slang-nodes/ContractDefinition.js | 64 ++++--- src/slang-nodes/ContractMember.js | 21 ++- src/slang-nodes/ContractMembers.js | 28 ++- src/slang-nodes/DecimalNumberExpression.js | 30 ++-- src/slang-nodes/DoWhileStatement.js | 56 ++++-- src/slang-nodes/ElementaryType.js | 28 +-- src/slang-nodes/ElseBranch.js | 27 +-- src/slang-nodes/EmitStatement.js | 43 +++-- src/slang-nodes/EnumDefinition.js | 45 +++-- src/slang-nodes/EnumMembers.js | 25 ++- src/slang-nodes/EqualityExpression.js | 28 ++- src/slang-nodes/ErrorDefinition.js | 41 +++-- src/slang-nodes/ErrorParameter.js | 32 ++-- src/slang-nodes/ErrorParameters.js | 29 +++- src/slang-nodes/ErrorParametersDeclaration.js | 33 ++-- src/slang-nodes/EventDefinition.js | 47 ++++-- src/slang-nodes/EventParameter.js | 37 ++-- src/slang-nodes/EventParameters.js | 29 +++- src/slang-nodes/EventParametersDeclaration.js | 33 ++-- src/slang-nodes/ExperimentalFeature.js | 33 ++-- src/slang-nodes/ExperimentalPragma.js | 33 ++-- src/slang-nodes/ExponentiationExpression.js | 159 +++++++++++------- src/slang-nodes/Expression.js | 38 +++-- src/slang-nodes/ExpressionStatement.js | 28 +-- src/slang-nodes/FallbackFunctionAttribute.js | 28 +-- src/slang-nodes/FallbackFunctionAttributes.js | 25 ++- src/slang-nodes/FallbackFunctionDefinition.js | 41 +++-- src/slang-nodes/ForStatement.js | 58 +++++-- src/slang-nodes/ForStatementCondition.js | 28 +-- src/slang-nodes/ForStatementInitialization.js | 28 +-- src/slang-nodes/FunctionAttribute.js | 28 +-- src/slang-nodes/FunctionAttributes.js | 25 ++- src/slang-nodes/FunctionBody.js | 28 +-- src/slang-nodes/FunctionCallExpression.js | 22 ++- src/slang-nodes/FunctionDefinition.js | 51 ++++-- src/slang-nodes/FunctionName.js | 21 ++- src/slang-nodes/FunctionType.js | 37 ++-- src/slang-nodes/FunctionTypeAttribute.js | 21 ++- src/slang-nodes/FunctionTypeAttributes.js | 25 ++- src/slang-nodes/HexNumberExpression.js | 30 ++-- src/slang-nodes/HexStringLiteral.js | 20 ++- src/slang-nodes/HexStringLiterals.js | 22 ++- src/slang-nodes/IdentifierPath.js | 30 ++-- src/slang-nodes/IfStatement.js | 50 ++++-- src/slang-nodes/ImportAlias.js | 25 ++- src/slang-nodes/ImportClause.js | 21 ++- src/slang-nodes/ImportDeconstruction.js | 47 ++++-- src/slang-nodes/ImportDeconstructionSymbol.js | 30 ++-- .../ImportDeconstructionSymbols.js | 24 ++- src/slang-nodes/ImportDirective.js | 37 ++-- src/slang-nodes/IndexAccessEnd.js | 30 ++-- src/slang-nodes/IndexAccessExpression.js | 46 +++-- src/slang-nodes/InheritanceSpecifier.js | 25 ++- src/slang-nodes/InheritanceType.js | 35 ++-- src/slang-nodes/InheritanceTypes.js | 29 +++- src/slang-nodes/InterfaceDefinition.js | 60 ++++--- src/slang-nodes/InterfaceMembers.js | 25 ++- src/slang-nodes/LibraryDefinition.js | 44 +++-- src/slang-nodes/LibraryMembers.js | 25 ++- src/slang-nodes/MappingKey.js | 28 +-- src/slang-nodes/MappingKeyType.js | 21 ++- src/slang-nodes/MappingType.js | 53 ++++-- src/slang-nodes/MappingValue.js | 28 +-- src/slang-nodes/MemberAccess.js | 21 ++- src/slang-nodes/MemberAccessExpression.js | 30 ++-- src/slang-nodes/ModifierAttribute.js | 28 +-- src/slang-nodes/ModifierAttributes.js | 25 ++- src/slang-nodes/ModifierDefinition.js | 65 +++++-- src/slang-nodes/ModifierInvocation.js | 47 ++++-- src/slang-nodes/MultiplicativeExpression.js | 46 ++--- src/slang-nodes/NamedArgument.js | 32 ++-- src/slang-nodes/NamedArgumentGroup.js | 33 ++-- src/slang-nodes/NamedArguments.js | 29 +++- src/slang-nodes/NamedArgumentsDeclaration.js | 41 +++-- src/slang-nodes/NamedImport.js | 43 +++-- src/slang-nodes/NewExpression.js | 28 +-- src/slang-nodes/NumberUnit.js | 21 ++- src/slang-nodes/OrExpression.js | 38 +++-- src/slang-nodes/OverridePaths.js | 27 ++- src/slang-nodes/OverridePathsDeclaration.js | 29 +++- src/slang-nodes/OverrideSpecifier.js | 35 ++-- src/slang-nodes/Parameter.js | 39 +++-- src/slang-nodes/Parameters.js | 52 ++++-- src/slang-nodes/ParametersDeclaration.js | 50 ++++-- src/slang-nodes/PathImport.js | 33 ++-- src/slang-nodes/PositionalArguments.js | 29 +++- .../PositionalArgumentsDeclaration.js | 33 ++-- src/slang-nodes/PostfixExpression.js | 25 ++- src/slang-nodes/Pragma.js | 30 +++- src/slang-nodes/PragmaDirective.js | 43 +++-- src/slang-nodes/PrefixExpression.js | 25 ++- src/slang-nodes/ReceiveFunctionAttribute.js | 28 +-- src/slang-nodes/ReceiveFunctionAttributes.js | 25 ++- src/slang-nodes/ReceiveFunctionDefinition.js | 33 ++-- src/slang-nodes/ReturnStatement.js | 40 +++-- src/slang-nodes/ReturnsDeclaration.js | 27 +-- src/slang-nodes/RevertStatement.js | 45 +++-- src/slang-nodes/ShiftExpression.js | 42 +++-- src/slang-nodes/SlangNode.js | 139 +++++++++++++++ src/slang-nodes/SourceUnit.js | 29 +++- src/slang-nodes/SourceUnitMember.js | 53 +++++- src/slang-nodes/SourceUnitMembers.js | 30 +++- src/slang-nodes/StateVariableAttribute.js | 28 +-- src/slang-nodes/StateVariableAttributes.js | 26 ++- src/slang-nodes/StateVariableDefinition.js | 51 ++++-- .../StateVariableDefinitionValue.js | 29 ++-- src/slang-nodes/Statement.js | 21 ++- src/slang-nodes/Statements.js | 28 ++- src/slang-nodes/StorageLocation.js | 21 ++- src/slang-nodes/StringExpression.js | 21 ++- src/slang-nodes/StringLiteral.js | 20 ++- src/slang-nodes/StringLiterals.js | 22 ++- src/slang-nodes/StructDefinition.js | 45 +++-- src/slang-nodes/StructMember.js | 32 ++-- src/slang-nodes/StructMembers.js | 25 ++- src/slang-nodes/ThrowStatement.js | 25 ++- src/slang-nodes/TryStatement.js | 58 ++++--- src/slang-nodes/TupleDeconstructionElement.js | 24 ++- .../TupleDeconstructionElements.js | 26 ++- .../TupleDeconstructionStatement.js | 64 ++++--- src/slang-nodes/TupleExpression.js | 41 +++-- src/slang-nodes/TupleMember.js | 21 ++- src/slang-nodes/TupleValue.js | 32 +++- src/slang-nodes/TupleValues.js | 38 +++-- src/slang-nodes/TypeExpression.js | 33 +++- src/slang-nodes/TypeName.js | 21 ++- src/slang-nodes/TypedTupleMember.js | 41 +++-- src/slang-nodes/UncheckedBlock.js | 28 +-- src/slang-nodes/UnicodeStringLiteral.js | 20 ++- src/slang-nodes/UnicodeStringLiterals.js | 22 ++- src/slang-nodes/UnnamedFunctionAttribute.js | 28 +-- src/slang-nodes/UnnamedFunctionAttributes.js | 25 ++- src/slang-nodes/UnnamedFunctionDefinition.js | 33 ++-- src/slang-nodes/UntypedTupleMember.js | 31 ++-- .../UserDefinedValueTypeDefinition.js | 45 +++-- src/slang-nodes/UsingAlias.js | 28 +-- src/slang-nodes/UsingClause.js | 21 ++- src/slang-nodes/UsingDeconstruction.js | 33 ++-- src/slang-nodes/UsingDeconstructionSymbol.js | 33 ++-- src/slang-nodes/UsingDeconstructionSymbols.js | 29 +++- src/slang-nodes/UsingDirective.js | 53 ++++-- src/slang-nodes/UsingOperator.js | 21 ++- src/slang-nodes/UsingTarget.js | 28 +-- .../VariableDeclarationStatement.js | 49 ++++-- src/slang-nodes/VariableDeclarationType.js | 28 +-- src/slang-nodes/VariableDeclarationValue.js | 28 +-- src/slang-nodes/VersionComparator.js | 25 ++- src/slang-nodes/VersionExpression.js | 28 +-- src/slang-nodes/VersionExpressionSet.js | 22 ++- src/slang-nodes/VersionExpressionSets.js | 32 ++-- src/slang-nodes/VersionPragma.js | 28 +-- src/slang-nodes/VersionRange.js | 29 +++- src/slang-nodes/VersionSpecifiers.js | 30 ++-- src/slang-nodes/WhileStatement.js | 46 +++-- src/slang-nodes/YulArguments.js | 26 ++- src/slang-nodes/YulAssignmentOperator.js | 28 +-- src/slang-nodes/YulAssignmentStatement.js | 41 +++-- src/slang-nodes/YulBlock.js | 33 ++-- src/slang-nodes/YulBreakStatement.js | 21 ++- src/slang-nodes/YulBuiltInFunction.js | 21 ++- src/slang-nodes/YulColonAndEqual.js | 25 ++- src/slang-nodes/YulContinueStatement.js | 21 ++- src/slang-nodes/YulDefaultCase.js | 28 +-- src/slang-nodes/YulExpression.js | 21 ++- src/slang-nodes/YulForStatement.js | 59 ++++--- src/slang-nodes/YulFunctionCallExpression.js | 43 +++-- src/slang-nodes/YulFunctionDefinition.js | 51 ++++-- src/slang-nodes/YulIfStatement.js | 39 +++-- src/slang-nodes/YulLabel.js | 23 ++- src/slang-nodes/YulLeaveStatement.js | 21 ++- src/slang-nodes/YulLiteral.js | 28 +-- src/slang-nodes/YulParameters.js | 24 ++- src/slang-nodes/YulParametersDeclaration.js | 33 ++-- src/slang-nodes/YulPath.js | 32 ++-- src/slang-nodes/YulPathComponent.js | 21 ++- src/slang-nodes/YulPaths.js | 32 ++-- src/slang-nodes/YulReturnVariables.js | 27 ++- src/slang-nodes/YulReturnsDeclaration.js | 32 ++-- src/slang-nodes/YulStatement.js | 21 ++- src/slang-nodes/YulStatements.js | 28 ++- src/slang-nodes/YulSwitchCase.js | 21 ++- src/slang-nodes/YulSwitchCases.js | 22 ++- src/slang-nodes/YulSwitchStatement.js | 38 +++-- src/slang-nodes/YulValueCase.js | 39 +++-- .../YulVariableAssignmentStatement.js | 41 +++-- .../YulVariableDeclarationStatement.js | 37 ++-- .../YulVariableDeclarationValue.js | 33 ++-- src/slang-utils/create-hug-function.js | 35 ++++ src/slangParser.js | 138 ++------------- src/slangPrinter.js | 12 +- 223 files changed, 5102 insertions(+), 2428 deletions(-) create mode 100644 src/slang-comments/handlers/handleParametersDeclarationComments.js create mode 100644 src/slang-nodes/SlangNode.js create mode 100644 src/slang-utils/create-hug-function.js diff --git a/.eslintrc b/.eslintrc index 740a32dbd..86187aaf2 100644 --- a/.eslintrc +++ b/.eslintrc @@ -12,6 +12,7 @@ }, "rules": { "import/extensions": "off", - "import/prefer-default-export": "off" + "import/prefer-default-export": "off", + "class-methods-use-this": "off" } } diff --git a/src/common/slang-helpers.js b/src/common/slang-helpers.js index 905fb3228..07a8da618 100644 --- a/src/common/slang-helpers.js +++ b/src/common/slang-helpers.js @@ -244,32 +244,6 @@ export const logicalOperationPrint = binaryOperationPrintBuilder( logicalIndentRulesBuilder ); -export function createHugFunction(huggableOperators) { - const operators = new Set(huggableOperators); - return (node) => { - if (isBinaryOperation(node.variant) && operators.has(node.variant.operator)) - return { - kind: 'Expression', - loc: { ...node.loc }, - variant: { - kind: 'TupleExpression', - loc: { ...node.loc }, - openParen: '(', - items: { - kind: 'TupleValues', - loc: { ...node.loc }, - items: [ - { kind: 'TupleValue', loc: { ...node.loc }, expression: node } - ], - separators: [] - }, - closeParen: ')' - } - }; - return node; - }; -} - export const locStart = (node) => node.loc.start; export const locEnd = (node) => node.loc.end; diff --git a/src/slang-comments/handlers/handleParametersDeclarationComments.js b/src/slang-comments/handlers/handleParametersDeclarationComments.js new file mode 100644 index 000000000..bcf81a61d --- /dev/null +++ b/src/slang-comments/handlers/handleParametersDeclarationComments.js @@ -0,0 +1,37 @@ +import { util } from 'prettier'; + +const { addDanglingComment, addLeadingComment, addTrailingComment } = util; + +export default function handleBlockComments({ + precedingNode, + enclosingNode, + followingNode, + comment +}) { + if (enclosingNode?.kind !== 'ParametersDeclaration') { + return false; + } + + if (precedingNode?.kind === 'Parameters') { + if (precedingNode.items.length === 0) { + addDanglingComment(precedingNode, comment); + } else { + addTrailingComment( + precedingNode.items[precedingNode.items.length - 1], + comment + ); + } + return true; + } + + if (followingNode?.kind === 'Parameters') { + if (followingNode.items.length === 0) { + addDanglingComment(followingNode, comment); + } else { + addLeadingComment(followingNode.items[0], comment); + } + return true; + } + + return false; +} diff --git a/src/slang-comments/handlers/index.js b/src/slang-comments/handlers/index.js index 3ebcb9aa6..09d543df9 100644 --- a/src/slang-comments/handlers/index.js +++ b/src/slang-comments/handlers/index.js @@ -1,11 +1,13 @@ import handleBlockComments from './handleBlockComments.js'; import handleContractDefinitionComments from './handleContractDefinitionComments.js'; +import handleParametersDeclarationComments from './handleParametersDeclarationComments.js'; import handleWhileStatementComments from './handleWhileStatementComments.js'; import handleYulBlockComments from './handleYulBlockComments.js'; export default [ handleBlockComments, handleContractDefinitionComments, + handleParametersDeclarationComments, handleWhileStatementComments, handleYulBlockComments ]; diff --git a/src/slang-nodes/ABICoderPragma.js b/src/slang-nodes/ABICoderPragma.js index 5de917342..70509921b 100644 --- a/src/slang-nodes/ABICoderPragma.js +++ b/src/slang-nodes/ABICoderPragma.js @@ -1,7 +1,18 @@ -export const ABICoderPragma = { - parse: ({ ast }) => ({ - abicoderKeyword: ast.abicoderKeyword.text, - version: ast.version.text - }), - print: ({ node }) => `${node.abicoderKeyword} ${node.version}` -}; +import { SlangNode } from './SlangNode.js'; + +export class ABICoderPragma extends SlangNode { + abicoderKeyword; + + version; + + constructor({ ast, offset }) { + super(ast, offset); + this.abicoderKeyword = ast.abicoderKeyword.text; + this.version = ast.version.text; + this.initiateLoc(ast); + } + + print() { + return `${this.abicoderKeyword} ${this.version}`; + } +} diff --git a/src/slang-nodes/AdditiveExpression.js b/src/slang-nodes/AdditiveExpression.js index 3f1344fd8..26cc22400 100644 --- a/src/slang-nodes/AdditiveExpression.js +++ b/src/slang-nodes/AdditiveExpression.js @@ -1,15 +1,29 @@ -import { - binaryOperationPrint, - createHugFunction -} from '../common/slang-helpers.js'; +import { binaryOperationPrint } from '../common/slang-helpers.js'; +import { createHugFunction } from '../slang-utils/create-hug-function.js'; +import { SlangNode } from './SlangNode.js'; const tryToHug = createHugFunction(['%']); -export const AdditiveExpression = { - parse: ({ offsets, ast, options, parse }) => ({ - leftOperand: tryToHug(parse(ast.leftOperand, options, parse, offsets)), - operator: ast.operator.text, - rightOperand: tryToHug(parse(ast.rightOperand, options, parse, offsets)) - }), - print: binaryOperationPrint -}; +export class AdditiveExpression extends SlangNode { + leftOperand; + + operator; + + rightOperand; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.leftOperand = tryToHug( + parse(ast.leftOperand, parse, this.nextChildOffset) + ); + this.operator = ast.operator.text; + this.rightOperand = tryToHug( + parse(ast.rightOperand, parse, this.nextChildOffset) + ); + this.initiateLoc(ast); + } + + print({ path, print, options }) { + return binaryOperationPrint({ node: this, path, print, options }); + } +} diff --git a/src/slang-nodes/AddressType.js b/src/slang-nodes/AddressType.js index 343893630..5fda9e012 100644 --- a/src/slang-nodes/AddressType.js +++ b/src/slang-nodes/AddressType.js @@ -1,8 +1,18 @@ -export const AddressType = { - parse: ({ ast }) => ({ - addressKeyword: ast.addressKeyword.text, - payableKeyword: ast.payableKeyword?.text - }), - print: ({ node }) => - `${node.addressKeyword}${node.payableKeyword ? ` ${node.payableKeyword}` : ''}` -}; +import { SlangNode } from './SlangNode.js'; + +export class AddressType extends SlangNode { + addressKeyword; + + payableKeyword; + + constructor({ ast, offset }) { + super(ast, offset); + this.addressKeyword = ast.addressKeyword.text; + this.payableKeyword = ast.payableKeyword?.text; + this.initiateLoc(ast); + } + + print() { + return `${this.addressKeyword}${this.payableKeyword ? ` ${this.payableKeyword}` : ''}`; + } +} diff --git a/src/slang-nodes/AndExpression.js b/src/slang-nodes/AndExpression.js index 9dad3a31f..db21004dd 100644 --- a/src/slang-nodes/AndExpression.js +++ b/src/slang-nodes/AndExpression.js @@ -1,10 +1,22 @@ import { logicalOperationPrint } from '../common/slang-helpers.js'; +import { SlangNode } from './SlangNode.js'; -export const AndExpression = { - parse: ({ offsets, ast, options, parse }) => ({ - leftOperand: parse(ast.leftOperand, options, parse, offsets), - operator: ast.operator.text, - rightOperand: parse(ast.rightOperand, options, parse, offsets) - }), - print: logicalOperationPrint -}; +export class AndExpression extends SlangNode { + leftOperand; + + operator; + + rightOperand; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.leftOperand = parse(ast.leftOperand, parse, this.nextChildOffset); + this.operator = ast.operator.text; + this.rightOperand = parse(ast.rightOperand, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print, options }) { + return logicalOperationPrint({ node: this, path, print, options }); + } +} diff --git a/src/slang-nodes/ArgumentsDeclaration.js b/src/slang-nodes/ArgumentsDeclaration.js index 707e4d0b4..dbf77dc9e 100644 --- a/src/slang-nodes/ArgumentsDeclaration.js +++ b/src/slang-nodes/ArgumentsDeclaration.js @@ -1,6 +1,15 @@ -export const ArgumentsDeclaration = { - parse: ({ offsets, ast, options, parse }) => ({ - variant: parse(ast.variant, options, parse, offsets) - }), - print: ({ path, print }) => path.call(print, 'variant') -}; +import { SlangNode } from './SlangNode.js'; + +export class ArgumentsDeclaration extends SlangNode { + variant; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.variant = parse(ast.variant, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/ArrayExpression.js b/src/slang-nodes/ArrayExpression.js index 0c6eda827..cfccb0d50 100644 --- a/src/slang-nodes/ArrayExpression.js +++ b/src/slang-nodes/ArrayExpression.js @@ -1,13 +1,28 @@ import { doc } from 'prettier'; +import { SlangNode } from './SlangNode.js'; const { group } = doc.builders; -export const ArrayExpression = { - parse: ({ offsets, ast, options, parse }) => ({ - openBracket: ast.openBracket.text, - items: parse(ast.items, options, parse, offsets), - closeBracket: ast.closeBracket.text - }), - print: ({ node, path, print }) => - group([node.openBracket, path.call(print, 'items'), node.closeBracket]) -}; +export class ArrayExpression extends SlangNode { + openBracket; + + items; + + closeBracket; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.openBracket = ast.openBracket.text; + this.items = parse(ast.items, parse, this.nextChildOffset); + this.closeBracket = ast.closeBracket.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return group([ + this.openBracket, + path.call(print, 'items'), + this.closeBracket + ]); + } +} diff --git a/src/slang-nodes/ArrayTypeName.js b/src/slang-nodes/ArrayTypeName.js index 2d2a629cc..26a0ec0b7 100644 --- a/src/slang-nodes/ArrayTypeName.js +++ b/src/slang-nodes/ArrayTypeName.js @@ -1,14 +1,31 @@ -export const ArrayTypeName = { - parse: ({ offsets, ast, options, parse }) => ({ - operand: parse(ast.operand, options, parse, offsets), - openBracket: ast.openBracket.text, - index: ast.index ? parse(ast.index, options, parse, offsets) : undefined, - closeBracket: ast.closeBracket.text - }), - print: ({ node, path, print }) => [ - path.call(print, 'operand'), - node.openBracket, - node.index ? path.call(print, 'index') : '', - node.closeBracket - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class ArrayTypeName extends SlangNode { + operand; + + openBracket; + + index; + + closeBracket; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.operand = parse(ast.operand, parse, this.nextChildOffset); + this.openBracket = ast.openBracket.text; + this.index = ast.index + ? parse(ast.index, parse, this.nextChildOffset) + : undefined; + this.closeBracket = ast.closeBracket.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + path.call(print, 'operand'), + this.openBracket, + this.index ? path.call(print, 'index') : '', + this.closeBracket + ]; + } +} diff --git a/src/slang-nodes/ArrayValues.js b/src/slang-nodes/ArrayValues.js index 984ffc130..1ce5079a9 100644 --- a/src/slang-nodes/ArrayValues.js +++ b/src/slang-nodes/ArrayValues.js @@ -1,9 +1,21 @@ import { printSeparatedList } from '../common/printer-helpers.js'; +import { SlangNode } from './SlangNode.js'; -export const ArrayValues = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)), - separators: ast.separators.map((separator) => separator.text) - }), - print: ({ path, print }) => printSeparatedList(path.map(print, 'items')) -}; +export class ArrayValues extends SlangNode { + items; + + separators; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items.map((item) => + parse(item, parse, this.nextChildOffset) + ); + this.separators = ast.separators.map((separator) => separator.text); + this.initiateLoc(ast); + } + + print({ path, print }) { + return printSeparatedList(path.map(print, 'items')); + } +} diff --git a/src/slang-nodes/AssemblyFlags.js b/src/slang-nodes/AssemblyFlags.js index 1f8cc5ccc..c0c87c01e 100644 --- a/src/slang-nodes/AssemblyFlags.js +++ b/src/slang-nodes/AssemblyFlags.js @@ -1,9 +1,21 @@ import { printSeparatedList } from '../common/printer-helpers.js'; +import { SlangNode } from './SlangNode.js'; -export const AssemblyFlags = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)), - separators: ast.separators.map((separator) => separator.text) - }), - print: ({ path, print }) => printSeparatedList(path.map(print, 'items')) -}; +export class AssemblyFlags extends SlangNode { + items; + + separators; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items.map((item) => + parse(item, parse, this.nextChildOffset) + ); + this.separators = ast.separators.map((separator) => separator.text); + this.initiateLoc(ast); + } + + print({ path, print }) { + return printSeparatedList(path.map(print, 'items')); + } +} diff --git a/src/slang-nodes/AssemblyFlagsDeclaration.js b/src/slang-nodes/AssemblyFlagsDeclaration.js index 7595f1c0d..b7504cfcf 100644 --- a/src/slang-nodes/AssemblyFlagsDeclaration.js +++ b/src/slang-nodes/AssemblyFlagsDeclaration.js @@ -1,12 +1,21 @@ -export const AssemblyFlagsDeclaration = { - parse: ({ offsets, ast, options, parse }) => ({ - openParen: ast.openParen.text, - flags: parse(ast.flags, options, parse, offsets), - closeParen: ast.closeParen.text - }), - print: ({ node, path, print }) => [ - node.openParen, - path.call(print, 'flags'), - node.closeParen - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class AssemblyFlagsDeclaration extends SlangNode { + openParen; + + flags; + + closeParen; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.openParen = ast.openParen.text; + this.flags = parse(ast.flags, parse, this.nextChildOffset); + this.closeParen = ast.closeParen.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [this.openParen, path.call(print, 'flags'), this.closeParen]; + } +} diff --git a/src/slang-nodes/AssemblyStatement.js b/src/slang-nodes/AssemblyStatement.js index 6f87405d0..b79024460 100644 --- a/src/slang-nodes/AssemblyStatement.js +++ b/src/slang-nodes/AssemblyStatement.js @@ -1,14 +1,33 @@ -export const AssemblyStatement = { - parse: ({ offsets, ast, options, parse }) => ({ - assemblyKeyword: ast.assemblyKeyword.text, - label: ast.label ? parse(ast.label, options, parse, offsets) : undefined, - flags: ast.flags ? parse(ast.flags, options, parse, offsets) : undefined, - body: parse(ast.body, options, parse, offsets) - }), - print: ({ node, path, print }) => [ - `${node.assemblyKeyword} `, - node.label ? [path.call(print, 'label'), ' '] : '', - node.flags ? [path.call(print, 'flags'), ' '] : '', - path.call(print, 'body') - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class AssemblyStatement extends SlangNode { + assemblyKeyword; + + label; + + flags; + + body; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.assemblyKeyword = ast.assemblyKeyword.text; + this.label = ast.label + ? parse(ast.label, parse, this.nextChildOffset) + : undefined; + this.flags = ast.flags + ? parse(ast.flags, parse, this.nextChildOffset) + : undefined; + this.body = parse(ast.body, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + `${this.assemblyKeyword} `, + this.label ? [path.call(print, 'label'), ' '] : '', + this.flags ? [path.call(print, 'flags'), ' '] : '', + path.call(print, 'body') + ]; + } +} diff --git a/src/slang-nodes/AssignmentExpression.js b/src/slang-nodes/AssignmentExpression.js index 33798ca78..5730bc8b8 100644 --- a/src/slang-nodes/AssignmentExpression.js +++ b/src/slang-nodes/AssignmentExpression.js @@ -1,19 +1,31 @@ import { doc } from 'prettier'; import { isBinaryOperation } from '../common/slang-helpers.js'; +import { SlangNode } from './SlangNode.js'; const { group, indent, line } = doc.builders; -export const AssignmentExpression = { - parse: ({ offsets, ast, options, parse }) => ({ - leftOperand: parse(ast.leftOperand, options, parse, offsets), - operator: ast.operator.text, - rightOperand: parse(ast.rightOperand, options, parse, offsets) - }), - print: ({ node, path, print }) => [ - path.call(print, 'leftOperand'), - ` ${node.operator}`, - isBinaryOperation(node.rightOperand.variant) - ? group(indent([line, path.call(print, 'rightOperand')])) - : [' ', path.call(print, 'rightOperand')] - ] -}; +export class AssignmentExpression extends SlangNode { + leftOperand; + + operator; + + rightOperand; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.leftOperand = parse(ast.leftOperand, parse, this.nextChildOffset); + this.operator = ast.operator.text; + this.rightOperand = parse(ast.rightOperand, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + path.call(print, 'leftOperand'), + ` ${this.operator}`, + isBinaryOperation(this.rightOperand.variant) + ? group(indent([line, path.call(print, 'rightOperand')])) + : [' ', path.call(print, 'rightOperand')] + ]; + } +} diff --git a/src/slang-nodes/BitwiseAndExpression.js b/src/slang-nodes/BitwiseAndExpression.js index 3c23df7d8..7a289727a 100644 --- a/src/slang-nodes/BitwiseAndExpression.js +++ b/src/slang-nodes/BitwiseAndExpression.js @@ -1,15 +1,29 @@ -import { - binaryOperationPrint, - createHugFunction -} from '../common/slang-helpers.js'; +import { binaryOperationPrint } from '../common/slang-helpers.js'; +import { createHugFunction } from '../slang-utils/create-hug-function.js'; +import { SlangNode } from './SlangNode.js'; const tryToHug = createHugFunction(['+', '-', '*', '/', '**', '<<', '>>']); -export const BitwiseAndExpression = { - parse: ({ offsets, ast, options, parse }) => ({ - leftOperand: tryToHug(parse(ast.leftOperand, options, parse, offsets)), - operator: ast.operator.text, - rightOperand: tryToHug(parse(ast.rightOperand, options, parse, offsets)) - }), - print: binaryOperationPrint -}; +export class BitwiseAndExpression extends SlangNode { + leftOperand; + + operator; + + rightOperand; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.leftOperand = tryToHug( + parse(ast.leftOperand, parse, this.nextChildOffset) + ); + this.operator = ast.operator.text; + this.rightOperand = tryToHug( + parse(ast.rightOperand, parse, this.nextChildOffset) + ); + this.initiateLoc(ast); + } + + print({ path, print, options }) { + return binaryOperationPrint({ node: this, path, print, options }); + } +} diff --git a/src/slang-nodes/BitwiseOrExpression.js b/src/slang-nodes/BitwiseOrExpression.js index d8fd7bcea..7a8c8784a 100644 --- a/src/slang-nodes/BitwiseOrExpression.js +++ b/src/slang-nodes/BitwiseOrExpression.js @@ -1,7 +1,6 @@ -import { - binaryOperationPrint, - createHugFunction -} from '../common/slang-helpers.js'; +import { binaryOperationPrint } from '../common/slang-helpers.js'; +import { createHugFunction } from '../slang-utils/create-hug-function.js'; +import { SlangNode } from './SlangNode.js'; const tryToHug = createHugFunction([ '+', @@ -15,11 +14,26 @@ const tryToHug = createHugFunction([ '^' ]); -export const BitwiseOrExpression = { - parse: ({ offsets, ast, options, parse }) => ({ - leftOperand: tryToHug(parse(ast.leftOperand, options, parse, offsets)), - operator: ast.operator.text, - rightOperand: tryToHug(parse(ast.rightOperand, options, parse, offsets)) - }), - print: binaryOperationPrint -}; +export class BitwiseOrExpression extends SlangNode { + leftOperand; + + operator; + + rightOperand; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.leftOperand = tryToHug( + parse(ast.leftOperand, parse, this.nextChildOffset) + ); + this.operator = ast.operator.text; + this.rightOperand = tryToHug( + parse(ast.rightOperand, parse, this.nextChildOffset) + ); + this.initiateLoc(ast); + } + + print({ path, print, options }) { + return binaryOperationPrint({ node: this, path, print, options }); + } +} diff --git a/src/slang-nodes/BitwiseXorExpression.js b/src/slang-nodes/BitwiseXorExpression.js index f64ed12e2..c26068396 100644 --- a/src/slang-nodes/BitwiseXorExpression.js +++ b/src/slang-nodes/BitwiseXorExpression.js @@ -1,15 +1,29 @@ -import { - binaryOperationPrint, - createHugFunction -} from '../common/slang-helpers.js'; +import { binaryOperationPrint } from '../common/slang-helpers.js'; +import { createHugFunction } from '../slang-utils/create-hug-function.js'; +import { SlangNode } from './SlangNode.js'; const tryToHug = createHugFunction(['+', '-', '*', '/', '**', '<<', '>>', '&']); -export const BitwiseXorExpression = { - parse: ({ offsets, ast, options, parse }) => ({ - leftOperand: tryToHug(parse(ast.leftOperand, options, parse, offsets)), - operator: ast.operator.text, - rightOperand: tryToHug(parse(ast.rightOperand, options, parse, offsets)) - }), - print: binaryOperationPrint -}; +export class BitwiseXorExpression extends SlangNode { + leftOperand; + + operator; + + rightOperand; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.leftOperand = tryToHug( + parse(ast.leftOperand, parse, this.nextChildOffset) + ); + this.operator = ast.operator.text; + this.rightOperand = tryToHug( + parse(ast.rightOperand, parse, this.nextChildOffset) + ); + this.initiateLoc(ast); + } + + print({ path, print, options }) { + return binaryOperationPrint({ node: this, path, print, options }); + } +} diff --git a/src/slang-nodes/Block.js b/src/slang-nodes/Block.js index c42738fc1..7dc7d854e 100644 --- a/src/slang-nodes/Block.js +++ b/src/slang-nodes/Block.js @@ -1,12 +1,21 @@ -export const Block = { - parse: ({ offsets, ast, options, parse }) => ({ - openBrace: ast.openBrace.text, - statements: parse(ast.statements, options, parse, offsets), - closeBrace: ast.closeBrace.text - }), - print: ({ node, path, print }) => [ - node.openBrace, - path.call(print, 'statements'), - node.closeBrace - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class Block extends SlangNode { + openBrace; + + statements; + + closeBrace; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.openBrace = ast.openBrace.text; + this.statements = parse(ast.statements, parse, this.nextChildOffset); + this.closeBrace = ast.closeBrace.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [this.openBrace, path.call(print, 'statements'), this.closeBrace]; + } +} diff --git a/src/slang-nodes/BreakStatement.js b/src/slang-nodes/BreakStatement.js index 4326e8a1a..5f37ef41f 100644 --- a/src/slang-nodes/BreakStatement.js +++ b/src/slang-nodes/BreakStatement.js @@ -1,7 +1,18 @@ -export const BreakStatement = { - parse: ({ ast }) => ({ - breakKeyword: ast.breakKeyword.text, - semicolon: ast.semicolon.text - }), - print: ({ node }) => `${node.breakKeyword}${node.semicolon}` -}; +import { SlangNode } from './SlangNode.js'; + +export class BreakStatement extends SlangNode { + breakKeyword; + + semicolon; + + constructor({ ast, offset }) { + super(ast, offset); + this.breakKeyword = ast.breakKeyword.text; + this.semicolon = ast.semicolon.text; + this.initiateLoc(ast); + } + + print() { + return `${this.breakKeyword}${this.semicolon}`; + } +} diff --git a/src/slang-nodes/CallOptions.js b/src/slang-nodes/CallOptions.js index 2d85f6bbd..aee87eebf 100644 --- a/src/slang-nodes/CallOptions.js +++ b/src/slang-nodes/CallOptions.js @@ -1,15 +1,26 @@ import { doc } from 'prettier'; import { printSeparatedList } from '../common/printer-helpers.js'; +import { SlangNode } from './SlangNode.js'; const { line, softline } = doc.builders; -export const CallOptions = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)), - separators: ast.separators.map((separator) => separator.text) - }), - print: ({ path, print, options }) => - printSeparatedList(path.map(print, 'items'), { +export class CallOptions extends SlangNode { + items; + + separators; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items.map((item) => + parse(item, parse, this.nextChildOffset) + ); + this.separators = ast.separators.map((separator) => separator.text); + this.initiateLoc(ast); + } + + print({ path, print, options }) { + return printSeparatedList(path.map(print, 'items'), { firstSeparator: options.bracketSpacing ? line : softline - }) -}; + }); + } +} diff --git a/src/slang-nodes/CallOptionsExpression.js b/src/slang-nodes/CallOptionsExpression.js index 25c1fab8a..0d11b3335 100644 --- a/src/slang-nodes/CallOptionsExpression.js +++ b/src/slang-nodes/CallOptionsExpression.js @@ -1,14 +1,29 @@ -export const CallOptionsExpression = { - parse: ({ offsets, ast, options, parse }) => ({ - operand: parse(ast.operand, options, parse, offsets), - openBrace: ast.openBrace.text, - options: parse(ast.options, options, parse, offsets), - closeBrace: ast.closeBrace.text - }), - print: ({ node, path, print }) => [ - path.call(print, 'operand'), - node.openBrace, - path.call(print, 'options'), - node.closeBrace - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class CallOptionsExpression extends SlangNode { + operand; + + openBrace; + + options; + + closeBrace; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.operand = parse(ast.operand, parse, this.nextChildOffset); + this.openBrace = ast.openBrace.text; + this.options = parse(ast.options, parse, this.nextChildOffset); + this.closeBrace = ast.closeBrace.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + path.call(print, 'operand'), + this.openBrace, + path.call(print, 'options'), + this.closeBrace + ]; + } +} diff --git a/src/slang-nodes/CatchClause.js b/src/slang-nodes/CatchClause.js index 22a29e829..3044f2b44 100644 --- a/src/slang-nodes/CatchClause.js +++ b/src/slang-nodes/CatchClause.js @@ -1,12 +1,27 @@ -export const CatchClause = { - parse: ({ offsets, ast, options, parse }) => ({ - catchKeyword: ast.catchKeyword.text, - error: ast.error ? parse(ast.error, options, parse, offsets) : undefined, - body: parse(ast.body, options, parse, offsets) - }), - print: ({ node, path, print }) => [ - `${node.catchKeyword} `, - node.error ? path.call(print, 'error') : '', - path.call(print, 'body') - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class CatchClause extends SlangNode { + catchKeyword; + + error; + + body; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.catchKeyword = ast.catchKeyword.text; + this.error = ast.error + ? parse(ast.error, parse, this.nextChildOffset) + : undefined; + this.body = parse(ast.body, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + `${this.catchKeyword} `, + this.error ? path.call(print, 'error') : '', + path.call(print, 'body') + ]; + } +} diff --git a/src/slang-nodes/CatchClauseError.js b/src/slang-nodes/CatchClauseError.js index 18f97430c..b83cb5630 100644 --- a/src/slang-nodes/CatchClauseError.js +++ b/src/slang-nodes/CatchClauseError.js @@ -1,15 +1,21 @@ import { doc } from 'prettier'; +import { SlangNode } from './SlangNode.js'; const { group } = doc.builders; -export const CatchClauseError = { - parse: ({ offsets, ast, options, parse }) => ({ - name: ast.name?.text, - parameters: parse(ast.parameters, options, parse, offsets) - }), - print: ({ node, path, print }) => [ - node.name ? node.name : '', - group(path.call(print, 'parameters')), - ' ' - ] -}; +export class CatchClauseError extends SlangNode { + name; + + parameters; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.name = ast.name?.text ?? ''; + this.parameters = parse(ast.parameters, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return [this.name, group(path.call(print, 'parameters')), ' ']; + } +} diff --git a/src/slang-nodes/CatchClauses.js b/src/slang-nodes/CatchClauses.js index 25de211aa..a1788e88c 100644 --- a/src/slang-nodes/CatchClauses.js +++ b/src/slang-nodes/CatchClauses.js @@ -1,10 +1,20 @@ import { doc } from 'prettier'; +import { SlangNode } from './SlangNode.js'; const { join } = doc.builders; -export const CatchClauses = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)) - }), - print: ({ path, print }) => join(' ', path.map(print, 'items')) -}; +export class CatchClauses extends SlangNode { + items; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items.map((item) => + parse(item, parse, this.nextChildOffset) + ); + this.initiateLoc(ast); + } + + print({ path, print }) { + return join(' ', path.map(print, 'items')); + } +} diff --git a/src/slang-nodes/ComparisonExpression.js b/src/slang-nodes/ComparisonExpression.js index d3aa5d3f6..6a8751dd2 100644 --- a/src/slang-nodes/ComparisonExpression.js +++ b/src/slang-nodes/ComparisonExpression.js @@ -1,10 +1,22 @@ import { comparisonOperationPrint } from '../common/slang-helpers.js'; +import { SlangNode } from './SlangNode.js'; -export const ComparisonExpression = { - parse: ({ offsets, ast, options, parse }) => ({ - leftOperand: parse(ast.leftOperand, options, parse, offsets), - operator: ast.operator.text, - rightOperand: parse(ast.rightOperand, options, parse, offsets) - }), - print: comparisonOperationPrint -}; +export class ComparisonExpression extends SlangNode { + leftOperand; + + operator; + + rightOperand; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.leftOperand = parse(ast.leftOperand, parse, this.nextChildOffset); + this.operator = ast.operator.text; + this.rightOperand = parse(ast.rightOperand, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print, options }) { + return comparisonOperationPrint({ node: this, path, print, options }); + } +} diff --git a/src/slang-nodes/ConditionalExpression.js b/src/slang-nodes/ConditionalExpression.js index 51aa3bbf8..e9260f4db 100644 --- a/src/slang-nodes/ConditionalExpression.js +++ b/src/slang-nodes/ConditionalExpression.js @@ -1,6 +1,7 @@ /* eslint-disable no-nested-ternary */ import { doc } from 'prettier'; import { printSeparatedItem } from '../common/printer-helpers.js'; +import { SlangNode } from './SlangNode.js'; const { group, hardline, ifBreak, indent, line, softline } = doc.builders; @@ -85,37 +86,56 @@ const traditionalTernaries = (node, path, print) => ]) ]); -export const ConditionalExpression = { - parse: ({ offsets, ast, options, parse }) => { - let operand = parse(ast.operand, options, parse, offsets); +export class ConditionalExpression extends SlangNode { + operand; + + questionMark; + + trueExpression; + + colon; + + falseExpression; + + constructor({ ast, options, parse, offset }) { + super(ast, offset); + this.operand = parse(ast.operand, parse, this.nextChildOffset); // TODO: while the behaviour is not stable, it should be behind the // experimentalTernaries flag. if (options.experimentalTernaries) { // We can remove parentheses only because we are sure that the // `condition` must be a single `bool` value. - const operandLoc = operand.loc; + const operandLoc = this.operand.loc; while ( - operand.variant.kind === 'TupleExpression' && - operand.variant.items.items.length === 1 && - operand.variant.items.items[0].expression.variant.kind !== + this.operand.variant.kind === 'TupleExpression' && + this.operand.variant.items.items.length === 1 && + this.operand.variant.items.items[0].expression.variant.kind !== 'ConditionalExpression' ) { - operand = operand.variant.items.items[0].expression; + this.operand = this.operand.variant.items.items[0].expression; } - operand.loc = operandLoc; + this.operand.loc = operandLoc; } - return { - operand, - questionMark: ast.questionMark.text, - trueExpression: parse(ast.trueExpression, options, parse, offsets), - colon: ast.colon.text, - falseExpression: parse(ast.falseExpression, options, parse, offsets) - }; - }, - print: ({ node, path, print, options }) => - options.experimentalTernaries - ? experimentalTernaries(node, path, print, options) - : traditionalTernaries(node, path, print) -}; + this.questionMark = ast.questionMark.text; + this.trueExpression = parse( + ast.trueExpression, + parse, + this.nextChildOffset + ); + this.colon = ast.colon.text; + this.falseExpression = parse( + ast.falseExpression, + parse, + this.nextChildOffset + ); + this.initiateLoc(ast); + } + + print({ path, print, options }) { + return options.experimentalTernaries + ? experimentalTernaries(this, path, print, options) + : traditionalTernaries(this, path, print); + } +} diff --git a/src/slang-nodes/ConstantDefinition.js b/src/slang-nodes/ConstantDefinition.js index a5f6868e0..91872e854 100644 --- a/src/slang-nodes/ConstantDefinition.js +++ b/src/slang-nodes/ConstantDefinition.js @@ -1,12 +1,31 @@ -export const ConstantDefinition = { - parse: ({ offsets, ast, options, parse }) => ({ - typeName: parse(ast.typeName, options, parse, offsets), - constantKeyword: ast.constantKeyword.text, - name: ast.name.text, - equal: ast.equal.text, - value: parse(ast.value, options, parse, offsets), - semicolon: ast.semicolon.text - }), +import { SlangNode } from './SlangNode.js'; + +export class ConstantDefinition extends SlangNode { + typeName; + + constantKeyword; + + name; + + equal; + + value; + + semicolon; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.typeName = parse(ast.typeName, parse, this.nextChildOffset); + this.constantKeyword = ast.constantKeyword.text; + this.name = ast.name.text; + this.equal = ast.equal.text; + this.value = parse(ast.value, parse, this.nextChildOffset); + this.semicolon = ast.semicolon.text; + this.initiateLoc(ast); + } + // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: ConstantDefinition'] -}; + print({ path, print, options }) { + return ['TODO: ConstantDefinition']; + } +} diff --git a/src/slang-nodes/ConstructorAttribute.js b/src/slang-nodes/ConstructorAttribute.js index 3bfb4491c..e7c137627 100644 --- a/src/slang-nodes/ConstructorAttribute.js +++ b/src/slang-nodes/ConstructorAttribute.js @@ -1,12 +1,20 @@ -export const ConstructorAttribute = { - parse: ({ offsets, ast, options, parse }) => ({ - variant: +import { SlangNode } from './SlangNode.js'; + +export class ConstructorAttribute extends SlangNode { + variant; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, options, parse, offsets) - }), - print: ({ node, path, print }) => - typeof node.variant === 'string' - ? node.variant - : path.call(print, 'variant') -}; + : parse(ast.variant, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/ConstructorAttributes.js b/src/slang-nodes/ConstructorAttributes.js index 1ab7f423e..dbe711795 100644 --- a/src/slang-nodes/ConstructorAttributes.js +++ b/src/slang-nodes/ConstructorAttributes.js @@ -1,14 +1,21 @@ import { doc } from 'prettier'; import { sortFunctionAttributes } from '../common/slang-helpers.js'; +import { SlangNode } from './SlangNode.js'; const { line } = doc.builders; -export const ConstructorAttributes = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items - .map((item) => parse(item, options, parse, offsets)) - .sort(sortFunctionAttributes) - }), - print: ({ path, print }) => - path.map(print, 'items').map((item) => [line, item]) -}; +export class ConstructorAttributes extends SlangNode { + items; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items + .map((item) => parse(item, parse, this.nextChildOffset)) + .sort(sortFunctionAttributes); + this.initiateLoc(ast); + } + + print({ path, print }) { + return path.map(print, 'items').map((item) => [line, item]); + } +} diff --git a/src/slang-nodes/ConstructorDefinition.js b/src/slang-nodes/ConstructorDefinition.js index cf478071c..d5f5452be 100644 --- a/src/slang-nodes/ConstructorDefinition.js +++ b/src/slang-nodes/ConstructorDefinition.js @@ -1,12 +1,25 @@ import { printFunction } from '../common/slang-helpers.js'; +import { SlangNode } from './SlangNode.js'; -export const ConstructorDefinition = { - parse: ({ offsets, ast, options, parse }) => ({ - constructorKeyword: ast.constructorKeyword.text, - parameters: parse(ast.parameters, options, parse, offsets), - attributes: parse(ast.attributes, options, parse, offsets), - body: parse(ast.body, options, parse, offsets) - }), - print: ({ node, path, print }) => - printFunction(node.constructorKeyword, node, path, print) -}; +export class ConstructorDefinition extends SlangNode { + constructorKeyword; + + parameters; + + attributes; + + body; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.constructorKeyword = ast.constructorKeyword.text; + this.parameters = parse(ast.parameters, parse, this.nextChildOffset); + this.attributes = parse(ast.attributes, parse, this.nextChildOffset); + this.body = parse(ast.body, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return printFunction(this.constructorKeyword, this, path, print); + } +} diff --git a/src/slang-nodes/ContinueStatement.js b/src/slang-nodes/ContinueStatement.js index 760347a99..aa3d92d1b 100644 --- a/src/slang-nodes/ContinueStatement.js +++ b/src/slang-nodes/ContinueStatement.js @@ -1,7 +1,18 @@ -export const ContinueStatement = { - parse: ({ ast }) => ({ - continueKeyword: ast.continueKeyword.text, - semicolon: ast.semicolon.text - }), - print: ({ node }) => `${node.continueKeyword}${node.semicolon}` -}; +import { SlangNode } from './SlangNode.js'; + +export class ContinueStatement extends SlangNode { + continueKeyword; + + semicolon; + + constructor({ ast, offset }) { + super(ast, offset); + this.continueKeyword = ast.continueKeyword.text; + this.semicolon = ast.semicolon.text; + this.initiateLoc(ast); + } + + print() { + return `${this.continueKeyword}${this.semicolon}`; + } +} diff --git a/src/slang-nodes/ContractDefinition.js b/src/slang-nodes/ContractDefinition.js index 6ff7f4705..b32c9eced 100644 --- a/src/slang-nodes/ContractDefinition.js +++ b/src/slang-nodes/ContractDefinition.js @@ -1,26 +1,46 @@ import { doc } from 'prettier'; +import { SlangNode } from './SlangNode.js'; const { group, line } = doc.builders; -export const ContractDefinition = { - parse: ({ offsets, ast, options, parse }) => ({ - abstractKeyword: ast.abstractKeyword?.text, - contractKeyword: ast.contractKeyword.text, - name: ast.name.text, - inheritance: ast.inheritance - ? parse(ast.inheritance, options, parse, offsets) - : undefined, - openBrace: ast.openBrace.text, - members: parse(ast.members, options, parse, offsets), - closeBrace: ast.closeBrace.text - }), - print: ({ node, path, print }) => [ - group([ - `${node.abstractKeyword ? `${node.abstractKeyword} ` : ''}${node.contractKeyword} ${node.name}`, - node.inheritance ? [' ', path.call(print, 'inheritance')] : line, - node.openBrace - ]), - path.call(print, 'members'), - node.closeBrace - ] -}; +export class ContractDefinition extends SlangNode { + abstractKeyword; + + contractKeyword; + + name; + + inheritance; + + openBrace; + + members; + + closeBrace; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.abstractKeyword = ast.abstractKeyword?.text; + this.contractKeyword = ast.contractKeyword.text; + this.name = ast.name.text; + this.inheritance = ast.inheritance + ? parse(ast.inheritance, parse, this.nextChildOffset) + : undefined; + this.openBrace = ast.openBrace.text; + this.members = parse(ast.members, parse, this.nextChildOffset); + this.closeBrace = ast.closeBrace.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + group([ + `${this.abstractKeyword ? `${this.abstractKeyword} ` : ''}${this.contractKeyword} ${this.name}`, + this.inheritance ? [' ', path.call(print, 'inheritance')] : line, + this.openBrace + ]), + path.call(print, 'members'), + this.closeBrace + ]; + } +} diff --git a/src/slang-nodes/ContractMember.js b/src/slang-nodes/ContractMember.js index 82fe9d048..d7ed08eaf 100644 --- a/src/slang-nodes/ContractMember.js +++ b/src/slang-nodes/ContractMember.js @@ -1,6 +1,15 @@ -export const ContractMember = { - parse: ({ offsets, ast, options, parse }) => ({ - variant: parse(ast.variant, options, parse, offsets) - }), - print: ({ path, print }) => path.call(print, 'variant') -}; +import { SlangNode } from './SlangNode.js'; + +export class ContractMember extends SlangNode { + variant; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.variant = parse(ast.variant, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/ContractMembers.js b/src/slang-nodes/ContractMembers.js index f0176a1eb..57f92feed 100644 --- a/src/slang-nodes/ContractMembers.js +++ b/src/slang-nodes/ContractMembers.js @@ -4,21 +4,31 @@ import { printComments, printPreservingEmptyLines } from '../common/slang-helpers.js'; +import { SlangNode } from './SlangNode.js'; const { hardline } = doc.builders; -export const ContractMembers = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)) - }), - print: ({ node, options, path, print }) => - node.items.length === 0 && (!node.comments || node.comments.length === 0) +export class ContractMembers extends SlangNode { + items; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items.map((item) => + parse(item, parse, this.nextChildOffset) + ); + this.initiateLoc(ast); + } + + print({ options, path, print }) { + return this.items.length === 0 && + (!this.comments || this.comments.length === 0) ? '' : printSeparatedItem( [ printPreservingEmptyLines(path, 'items', options, print), - printComments(node, path, options) + printComments(this, path, options) ], { firstSeparator: hardline, grouped: false } - ) -}; + ); + } +} diff --git a/src/slang-nodes/DecimalNumberExpression.js b/src/slang-nodes/DecimalNumberExpression.js index 2137c61bb..cbdbff69f 100644 --- a/src/slang-nodes/DecimalNumberExpression.js +++ b/src/slang-nodes/DecimalNumberExpression.js @@ -1,10 +1,20 @@ -export const DecimalNumberExpression = { - parse: ({ offsets, ast, options, parse }) => ({ - literal: ast.literal.text, - unit: ast.unit ? parse(ast.unit, options, parse, offsets) : undefined - }), - print: ({ node, path, print }) => [ - node.literal, - node.unit ? [' ', path.call(print, 'unit')] : '' - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class DecimalNumberExpression extends SlangNode { + literal; + + unit; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.literal = ast.literal.text; + this.unit = ast.unit + ? parse(ast.unit, parse, this.nextChildOffset) + : undefined; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [this.literal, this.unit ? [' ', path.call(print, 'unit')] : '']; + } +} diff --git a/src/slang-nodes/DoWhileStatement.js b/src/slang-nodes/DoWhileStatement.js index eedef4e75..57c09be9b 100644 --- a/src/slang-nodes/DoWhileStatement.js +++ b/src/slang-nodes/DoWhileStatement.js @@ -1,5 +1,6 @@ import { doc } from 'prettier'; import { printSeparatedItem } from '../common/printer-helpers.js'; +import { SlangNode } from './SlangNode.js'; const { group, indent, line } = doc.builders; @@ -8,21 +9,40 @@ const printBody = (node, path, print) => ? [' ', path.call(print, 'body'), ' '] : group([indent([line, path.call(print, 'body')]), line]); -export const DoWhileStatement = { - parse: ({ offsets, ast, options, parse }) => ({ - doKeyword: ast.doKeyword.text, - body: parse(ast.body, options, parse, offsets), - whileKeyword: ast.whileKeyword.text, - openParen: ast.openParen.text, - condition: parse(ast.condition, options, parse, offsets), - closeParen: ast.closeParen.text, - semicolon: ast.semicolon.text - }), - print: ({ node, path, print }) => [ - node.doKeyword, - printBody(node, path, print), - `${node.whileKeyword} ${node.openParen}`, - printSeparatedItem(path.call(print, 'condition')), - `${node.closeParen}${node.semicolon}` - ] -}; +export class DoWhileStatement extends SlangNode { + doKeyword; + + body; + + whileKeyword; + + openParen; + + condition; + + closeParen; + + semicolon; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.doKeyword = ast.doKeyword.text; + this.body = parse(ast.body, parse, this.nextChildOffset); + this.whileKeyword = ast.whileKeyword.text; + this.openParen = ast.openParen.text; + this.condition = parse(ast.condition, parse, this.nextChildOffset); + this.closeParen = ast.closeParen.text; + this.semicolon = ast.semicolon.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + this.doKeyword, + printBody(this, path, print), + `${this.whileKeyword} ${this.openParen}`, + printSeparatedItem(path.call(print, 'condition')), + `${this.closeParen}${this.semicolon}` + ]; + } +} diff --git a/src/slang-nodes/ElementaryType.js b/src/slang-nodes/ElementaryType.js index d6f336a2b..e4f2b1e85 100644 --- a/src/slang-nodes/ElementaryType.js +++ b/src/slang-nodes/ElementaryType.js @@ -1,12 +1,20 @@ -export const ElementaryType = { - parse: ({ offsets, ast, options, parse }) => ({ - variant: +import { SlangNode } from './SlangNode.js'; + +export class ElementaryType extends SlangNode { + variant; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, options, parse, offsets) - }), - print: ({ node, path, print }) => - typeof node.variant === 'string' - ? node.variant - : path.call(print, 'variant') -}; + : parse(ast.variant, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/ElseBranch.js b/src/slang-nodes/ElseBranch.js index 1648aa131..70737b5ce 100644 --- a/src/slang-nodes/ElseBranch.js +++ b/src/slang-nodes/ElseBranch.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { SlangNode } from './SlangNode.js'; const { group, indent, line } = doc.builders; @@ -7,13 +8,19 @@ const printBody = (bodyVariantKind, path, print) => ? [' ', path.call(print, 'body')] : group(indent([line, path.call(print, 'body')])); -export const ElseBranch = { - parse: ({ offsets, ast, options, parse }) => ({ - elseKeyword: ast.elseKeyword.text, - body: parse(ast.body, options, parse, offsets) - }), - print: ({ node, path, print }) => [ - node.elseKeyword, - printBody(node.body.variant.kind, path, print) - ] -}; +export class ElseBranch extends SlangNode { + elseKeyword; + + body; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.elseKeyword = ast.elseKeyword.text; + this.body = parse(ast.body, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return [this.elseKeyword, printBody(this.body.variant.kind, path, print)]; + } +} diff --git a/src/slang-nodes/EmitStatement.js b/src/slang-nodes/EmitStatement.js index b36e8a34b..7b80fbc23 100644 --- a/src/slang-nodes/EmitStatement.js +++ b/src/slang-nodes/EmitStatement.js @@ -1,14 +1,29 @@ -export const EmitStatement = { - parse: ({ offsets, ast, options, parse }) => ({ - emitKeyword: ast.emitKeyword.text, - event: parse(ast.event, options, parse, offsets), - arguments: parse(ast.arguments, options, parse, offsets), - semicolon: ast.semicolon.text - }), - print: ({ node, path, print }) => [ - `${node.emitKeyword} `, - path.call(print, 'event'), - path.call(print, 'arguments'), - node.semicolon - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class EmitStatement extends SlangNode { + emitKeyword; + + event; + + arguments; + + semicolon; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.emitKeyword = ast.emitKeyword.text; + this.event = parse(ast.event, parse, this.nextChildOffset); + this.arguments = parse(ast.arguments, parse, this.nextChildOffset); + this.semicolon = ast.semicolon.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + `${this.emitKeyword} `, + path.call(print, 'event'), + path.call(print, 'arguments'), + this.semicolon + ]; + } +} diff --git a/src/slang-nodes/EnumDefinition.js b/src/slang-nodes/EnumDefinition.js index 2021e404b..2c4ad105f 100644 --- a/src/slang-nodes/EnumDefinition.js +++ b/src/slang-nodes/EnumDefinition.js @@ -1,14 +1,31 @@ -export const EnumDefinition = { - parse: ({ offsets, ast, options, parse }) => ({ - enumKeyword: ast.enumKeyword.text, - name: ast.name.text, - openBrace: ast.openBrace.text, - members: parse(ast.members, options, parse, offsets), - closeBrace: ast.closeBrace.text - }), - print: ({ node, path, print }) => [ - `${node.enumKeyword} ${node.name} ${node.openBrace}`, - path.call(print, 'members'), - node.closeBrace - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class EnumDefinition extends SlangNode { + enumKeyword; + + name; + + openBrace; + + members; + + closeBrace; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.enumKeyword = ast.enumKeyword.text; + this.name = ast.name.text; + this.openBrace = ast.openBrace.text; + this.members = parse(ast.members, parse, this.nextChildOffset); + this.closeBrace = ast.closeBrace.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + `${this.enumKeyword} ${this.name} ${this.openBrace}`, + path.call(print, 'members'), + this.closeBrace + ]; + } +} diff --git a/src/slang-nodes/EnumMembers.js b/src/slang-nodes/EnumMembers.js index 8a73d9c77..e399758f3 100644 --- a/src/slang-nodes/EnumMembers.js +++ b/src/slang-nodes/EnumMembers.js @@ -1,13 +1,22 @@ import { doc } from 'prettier'; import { printSeparatedList } from '../common/printer-helpers.js'; +import { SlangNode } from './SlangNode.js'; const { hardline } = doc.builders; -export const EnumMembers = { - parse: ({ ast }) => ({ - items: ast.items.map((item) => item.text), - separators: ast.separators.map((separator) => separator.text) - }), - print: ({ node }) => - printSeparatedList(node.items, { firstSeparator: hardline }) -}; +export class EnumMembers extends SlangNode { + items; + + separators; + + constructor({ ast, offset }) { + super(ast, offset); + this.items = ast.items.map((item) => item.text); + this.separators = ast.separators.map((separator) => separator.text); + this.initiateLoc(ast); + } + + print() { + return printSeparatedList(this.items, { firstSeparator: hardline }); + } +} diff --git a/src/slang-nodes/EqualityExpression.js b/src/slang-nodes/EqualityExpression.js index 3a2f8fd0d..1b159be4a 100644 --- a/src/slang-nodes/EqualityExpression.js +++ b/src/slang-nodes/EqualityExpression.js @@ -1,10 +1,22 @@ import { comparisonOperationPrint } from '../common/slang-helpers.js'; +import { SlangNode } from './SlangNode.js'; -export const EqualityExpression = { - parse: ({ offsets, ast, options, parse }) => ({ - leftOperand: parse(ast.leftOperand, options, parse, offsets), - operator: ast.operator.text, - rightOperand: parse(ast.rightOperand, options, parse, offsets) - }), - print: comparisonOperationPrint -}; +export class EqualityExpression extends SlangNode { + leftOperand; + + operator; + + rightOperand; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.leftOperand = parse(ast.leftOperand, parse, this.nextChildOffset); + this.operator = ast.operator.text; + this.rightOperand = parse(ast.rightOperand, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print, options }) { + return comparisonOperationPrint({ node: this, path, print, options }); + } +} diff --git a/src/slang-nodes/ErrorDefinition.js b/src/slang-nodes/ErrorDefinition.js index b74b9e9a3..347f42b0b 100644 --- a/src/slang-nodes/ErrorDefinition.js +++ b/src/slang-nodes/ErrorDefinition.js @@ -1,13 +1,28 @@ -export const ErrorDefinition = { - parse: ({ offsets, ast, options, parse }) => ({ - errorKeyword: ast.errorKeyword.text, - name: ast.name.text, - members: parse(ast.members, options, parse, offsets), - semicolon: ast.semicolon.text - }), - print: ({ node, path, print }) => [ - `${node.errorKeyword} ${node.name}`, - path.call(print, 'members'), - node.semicolon - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class ErrorDefinition extends SlangNode { + errorKeyword; + + name; + + members; + + semicolon; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.errorKeyword = ast.errorKeyword.text; + this.name = ast.name.text; + this.members = parse(ast.members, parse, this.nextChildOffset); + this.semicolon = ast.semicolon.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + `${this.errorKeyword} ${this.name}`, + path.call(print, 'members'), + this.semicolon + ]; + } +} diff --git a/src/slang-nodes/ErrorParameter.js b/src/slang-nodes/ErrorParameter.js index 68dcbf772..4e28c8f5b 100644 --- a/src/slang-nodes/ErrorParameter.js +++ b/src/slang-nodes/ErrorParameter.js @@ -1,10 +1,22 @@ -export const ErrorParameter = { - parse: ({ offsets, ast, options, parse }) => ({ - typeName: parse(ast.typeName, options, parse, offsets), - name: ast.name?.text - }), - print: ({ node, path, print }) => [ - path.call(print, 'typeName'), - node.name ? ` ${node.name}` : '' - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class ErrorParameter extends SlangNode { + errorKeyword; + + name; + + members; + + semicolon; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.typeName = parse(ast.typeName, parse, this.nextChildOffset); + this.name = ast.name?.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [path.call(print, 'typeName'), this.name ? ` ${this.name}` : '']; + } +} diff --git a/src/slang-nodes/ErrorParameters.js b/src/slang-nodes/ErrorParameters.js index 85454e1bf..94c355096 100644 --- a/src/slang-nodes/ErrorParameters.js +++ b/src/slang-nodes/ErrorParameters.js @@ -1,10 +1,23 @@ import { printSeparatedList } from '../common/printer-helpers.js'; +import { SlangNode } from './SlangNode.js'; -export const ErrorParameters = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)), - separators: ast.separators.map((separator) => separator.text) - }), - print: ({ node, path, print }) => - node.items.length > 0 ? printSeparatedList(path.map(print, 'items')) : '' -}; +export class ErrorParameters extends SlangNode { + items; + + separators; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items.map((item) => + parse(item, parse, this.nextChildOffset) + ); + this.separators = ast.separators.map((separator) => separator.text); + this.initiateLoc(ast); + } + + print({ path, print }) { + return this.items.length > 0 + ? printSeparatedList(path.map(print, 'items')) + : ''; + } +} diff --git a/src/slang-nodes/ErrorParametersDeclaration.js b/src/slang-nodes/ErrorParametersDeclaration.js index cce0f25b5..74813c9a2 100644 --- a/src/slang-nodes/ErrorParametersDeclaration.js +++ b/src/slang-nodes/ErrorParametersDeclaration.js @@ -1,12 +1,21 @@ -export const ErrorParametersDeclaration = { - parse: ({ offsets, ast, options, parse }) => ({ - openParen: ast.openParen.text, - parameters: parse(ast.parameters, options, parse, offsets), - closeParen: ast.closeParen.text - }), - print: ({ node, path, print }) => [ - node.openParen, - path.call(print, 'parameters'), - node.closeParen - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class ErrorParametersDeclaration extends SlangNode { + openParen; + + parameters; + + closeParen; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.openParen = ast.openParen.text; + this.parameters = parse(ast.parameters, parse, this.nextChildOffset); + this.closeParen = ast.closeParen.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [this.openParen, path.call(print, 'parameters'), this.closeParen]; + } +} diff --git a/src/slang-nodes/EventDefinition.js b/src/slang-nodes/EventDefinition.js index 5b5a7a54a..9a3b2691d 100644 --- a/src/slang-nodes/EventDefinition.js +++ b/src/slang-nodes/EventDefinition.js @@ -1,15 +1,32 @@ -export const EventDefinition = { - parse: ({ offsets, ast, options, parse }) => ({ - eventKeyword: ast.eventKeyword.text, - name: ast.name.text, - parameters: parse(ast.parameters, options, parse, offsets), - anonymousKeyword: ast.anonymousKeyword?.text, - semicolon: ast.semicolon.text - }), - print: ({ node, path, print }) => [ - `${node.eventKeyword} ${node.name}`, - path.call(print, 'parameters'), - node.anonymousKeyword ? ` ${node.anonymousKeyword}` : '', - node.semicolon - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class EventDefinition extends SlangNode { + eventKeyword; + + name; + + parameters; + + anonymousKeyword; + + semicolon; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.eventKeyword = ast.eventKeyword.text; + this.name = ast.name.text; + this.parameters = parse(ast.parameters, parse, this.nextChildOffset); + this.anonymousKeyword = ast.anonymousKeyword?.text; + this.semicolon = ast.semicolon.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + `${this.eventKeyword} ${this.name}`, + path.call(print, 'parameters'), + this.anonymousKeyword ? ` ${this.anonymousKeyword}` : '', + this.semicolon + ]; + } +} diff --git a/src/slang-nodes/EventParameter.js b/src/slang-nodes/EventParameter.js index 5ae0ab6b6..517ac2cb0 100644 --- a/src/slang-nodes/EventParameter.js +++ b/src/slang-nodes/EventParameter.js @@ -1,12 +1,25 @@ -export const EventParameter = { - parse: ({ offsets, ast, options, parse }) => ({ - typeName: parse(ast.typeName, options, parse, offsets), - indexedKeyword: ast.indexedKeyword?.text, - name: ast.name?.text - }), - print: ({ node, path, print }) => [ - path.call(print, 'typeName'), - node.indexedKeyword ? ` ${node.indexedKeyword}` : '', - node.name ? ` ${node.name}` : '' - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class EventParameter extends SlangNode { + typeName; + + indexedKeyword; + + name; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.typeName = parse(ast.typeName, parse, this.nextChildOffset); + this.indexedKeyword = ast.indexedKeyword?.text; + this.name = ast.name?.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + path.call(print, 'typeName'), + this.indexedKeyword ? ` ${this.indexedKeyword}` : '', + this.name ? ` ${this.name}` : '' + ]; + } +} diff --git a/src/slang-nodes/EventParameters.js b/src/slang-nodes/EventParameters.js index 88501eb67..e7988cc6d 100644 --- a/src/slang-nodes/EventParameters.js +++ b/src/slang-nodes/EventParameters.js @@ -1,10 +1,23 @@ import { printSeparatedList } from '../common/printer-helpers.js'; +import { SlangNode } from './SlangNode.js'; -export const EventParameters = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)), - separators: ast.separators.map((separator) => separator.text) - }), - print: ({ node, path, print }) => - node.items.length > 0 ? printSeparatedList(path.map(print, 'items')) : '' -}; +export class EventParameters extends SlangNode { + items; + + separators; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items.map((item) => + parse(item, parse, this.nextChildOffset) + ); + this.separators = ast.separators.map((separator) => separator.text); + this.initiateLoc(ast); + } + + print({ path, print }) { + return this.items.length > 0 + ? printSeparatedList(path.map(print, 'items')) + : ''; + } +} diff --git a/src/slang-nodes/EventParametersDeclaration.js b/src/slang-nodes/EventParametersDeclaration.js index 874469597..7abbec387 100644 --- a/src/slang-nodes/EventParametersDeclaration.js +++ b/src/slang-nodes/EventParametersDeclaration.js @@ -1,12 +1,21 @@ -export const EventParametersDeclaration = { - parse: ({ offsets, ast, options, parse }) => ({ - openParen: ast.openParen.text, - parameters: parse(ast.parameters, options, parse, offsets), - closeParen: ast.closeParen.text - }), - print: ({ node, path, print }) => [ - node.openParen, - path.call(print, 'parameters'), - node.closeParen - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class EventParametersDeclaration extends SlangNode { + openParen; + + parameters; + + closeParen; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.openParen = ast.openParen.text; + this.parameters = parse(ast.parameters, parse, this.nextChildOffset); + this.closeParen = ast.closeParen.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [this.openParen, path.call(print, 'parameters'), this.closeParen]; + } +} diff --git a/src/slang-nodes/ExperimentalFeature.js b/src/slang-nodes/ExperimentalFeature.js index e61b524d2..1258da644 100644 --- a/src/slang-nodes/ExperimentalFeature.js +++ b/src/slang-nodes/ExperimentalFeature.js @@ -1,12 +1,25 @@ -export const ExperimentalFeature = { - parse: ({ offsets, ast, options, parse }) => ({ - variant: +import { SlangNode } from './SlangNode.js'; +import { StringLiteral } from './StringLiteral.js'; + +export class ExperimentalFeature extends SlangNode { + variant; + + constructor({ ast, offset, options }) { + super(ast, offset); + this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, options, parse, offsets) - }), - print: ({ node, path, print }) => - typeof node.variant === 'string' - ? node.variant - : path.call(print, 'variant') -}; + : new StringLiteral({ + ast: ast.variant, + offset: this.nextChildOffset, + options + }); + this.initiateLoc(ast); + } + + print({ path, print }) { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/ExperimentalPragma.js b/src/slang-nodes/ExperimentalPragma.js index dac744fed..0c26b59c2 100644 --- a/src/slang-nodes/ExperimentalPragma.js +++ b/src/slang-nodes/ExperimentalPragma.js @@ -1,10 +1,23 @@ -export const ExperimentalPragma = { - parse: ({ offsets, ast, options, parse }) => ({ - experimentalKeyword: ast.experimentalKeyword.text, - feature: parse(ast.feature, options, parse, offsets) - }), - print: ({ node, path, print }) => [ - `${node.experimentalKeyword} `, - path.call(print, 'feature') - ] -}; +import { SlangNode } from './SlangNode.js'; +import { ExperimentalFeature } from './ExperimentalFeature.js'; + +export class ExperimentalPragma extends SlangNode { + experimentalKeyword; + + feature; + + constructor({ ast, offset, options }) { + super(ast, offset); + this.experimentalKeyword = ast.experimentalKeyword.text; + this.feature = new ExperimentalFeature({ + ast: ast.feature, + offset: this.nextChildOffset, + options + }); + this.initiateLoc(ast); + } + + print({ path, print }) { + return [`${this.experimentalKeyword} `, path.call(print, 'feature')]; + } +} diff --git a/src/slang-nodes/ExponentiationExpression.js b/src/slang-nodes/ExponentiationExpression.js index b2031dbd7..e723332e1 100644 --- a/src/slang-nodes/ExponentiationExpression.js +++ b/src/slang-nodes/ExponentiationExpression.js @@ -1,80 +1,111 @@ import { doc } from 'prettier'; import coerce from 'semver/functions/coerce.js'; import satisfies from 'semver/functions/satisfies.js'; -import { - binaryOperationPrintBuilder, - createHugFunction -} from '../common/slang-helpers.js'; +import { binaryOperationPrintBuilder } from '../common/slang-helpers.js'; +import { createHugFunction } from '../slang-utils/create-hug-function.js'; +import { SlangNode } from './SlangNode.js'; +import { Expression } from './Expression.js'; +import { TupleExpression } from './TupleExpression.js'; +import { TupleValues } from './TupleValues.js'; +import { TupleValue } from './TupleValue.js'; const { group, indent } = doc.builders; const tryToHug = createHugFunction(['**']); -export const ExponentiationExpression = { - parse: ({ offsets, ast, options, parse }) => { - const compiler = coerce(options.compiler); - let leftOperand = parse(ast.leftOperand, options, parse, offsets); - let rightOperand = parse(ast.rightOperand, options, parse, offsets); +const exponentiationExpressionPrint = binaryOperationPrintBuilder( + () => (document) => group(document), // always group + () => (document) => indent(document) // always indent +); - if (compiler) { - if (satisfies(compiler, '>=0.8.0')) { - rightOperand = tryToHug(rightOperand); - } else { - // Currently the parser considers exponentiation as having left - // association from 0.6.0. - // in reality solidity fixed this from 0.8.0. - // TODO: remove this once the parser has fixed this. - // https://github.com/NomicFoundation/slang/issues/1031 - if (rightOperand.variant.kind === 'ExponentiationExpression') { - const leftLoc = { - start: leftOperand.loc.start, - end: rightOperand.variant.leftOperand.loc.end - }; - leftOperand = { - kind: 'Expression', - loc: { ...leftLoc }, - variant: { - kind: 'TupleExpression', +export class ExponentiationExpression extends SlangNode { + leftOperand; + + operator; + + rightOperand; + + constructor({ + ast, + options, + parse, + offset, + kind, + loc, + leftOperand, + operator, + rightOperand + }) { + super(ast, offset); + if (ast) { + const compiler = coerce(options.compiler); + this.leftOperand = parse(ast.leftOperand, parse, this.nextChildOffset); + this.rightOperand = parse(ast.rightOperand, parse, this.nextChildOffset); + + if (compiler) { + if (satisfies(compiler, '>=0.8.0')) { + this.rightOperand = tryToHug(this.rightOperand); + } else { + // Currently the parser considers exponentiation as having left + // association from 0.6.0. + // in reality solidity fixed this from 0.8.0. + // TODO: remove this once the parser has fixed this. + // https://github.com/NomicFoundation/slang/issues/1031 + if (this.rightOperand.variant.kind === 'ExponentiationExpression') { + const leftLoc = { + start: this.leftOperand.loc.start, + end: this.rightOperand.variant.leftOperand.loc.end + }; + this.leftOperand = new Expression({ + kind: 'Expression', loc: { ...leftLoc }, - openParen: '(', - items: { - kind: 'TupleValues', + variant: new TupleExpression({ + kind: 'TupleExpression', loc: { ...leftLoc }, - items: [ - { - kind: 'TupleValue', - loc: { ...leftLoc }, - expression: { - kind: 'Expression', + openParen: '(', + items: new TupleValues({ + kind: 'TupleValues', + loc: { ...leftLoc }, + items: [ + new TupleValue({ + kind: 'TupleValue', loc: { ...leftLoc }, - variant: { - kind: 'ExponentiationExpression', + expression: new Expression({ + kind: 'Expression', loc: { ...leftLoc }, - leftOperand, - operator: '**', - rightOperand: rightOperand.variant.leftOperand - } - } - } - ], - separators: [] - }, - closeParen: ')' - } - }; - rightOperand = rightOperand.variant.rightOperand; + variant: new ExponentiationExpression({ + kind: 'ExponentiationExpression', + loc: { ...leftLoc }, + leftOperand: this.leftOperand, + operator: '**', + rightOperand: this.rightOperand.variant.leftOperand + }) + }) + }) + ], + separators: [] + }), + closeParen: ')' + }) + }); + this.rightOperand = this.rightOperand.variant.rightOperand; + } + this.leftOperand = tryToHug(this.leftOperand); } - leftOperand = tryToHug(leftOperand); } + + this.operator = ast.operator.text; + this.initiateLoc(ast); + } else { + this.kind = kind; + this.loc = loc; + this.leftOperand = leftOperand; + this.operator = operator; + this.rightOperand = rightOperand; } - return { - leftOperand, - operator: ast.operator.text, - rightOperand - }; - }, - print: binaryOperationPrintBuilder( - () => (document) => group(document), // always group - () => (document) => indent(document) // always indent - ) -}; + } + + print({ path, print, options }) { + return exponentiationExpressionPrint({ node: this, path, print, options }); + } +} diff --git a/src/slang-nodes/Expression.js b/src/slang-nodes/Expression.js index 955e32ee9..2a49dd42c 100644 --- a/src/slang-nodes/Expression.js +++ b/src/slang-nodes/Expression.js @@ -1,12 +1,26 @@ -export const Expression = { - parse: ({ offsets, ast, options, parse }) => ({ - variant: - ast.variant.type === 'Terminal' - ? ast.variant.text - : parse(ast.variant, options, parse, offsets) - }), - print: ({ node, path, print }) => - typeof node.variant === 'string' - ? node.variant - : path.call(print, 'variant') -}; +import { SlangNode } from './SlangNode.js'; + +export class Expression extends SlangNode { + variant; + + constructor({ ast, parse, offset, options, kind, loc, variant }) { + super(ast, offset); + if (ast) { + this.variant = + ast.variant.type === 'Terminal' + ? ast.variant.text + : parse(ast.variant, parse, this.nextChildOffset); + this.initiateLoc(ast); + } else { + this.kind = kind; + this.loc = loc; + this.variant = variant; + } + } + + print({ path, print }) { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/ExpressionStatement.js b/src/slang-nodes/ExpressionStatement.js index f954820d8..942ecbb55 100644 --- a/src/slang-nodes/ExpressionStatement.js +++ b/src/slang-nodes/ExpressionStatement.js @@ -1,10 +1,18 @@ -export const ExpressionStatement = { - parse: ({ offsets, ast, options, parse }) => ({ - expression: parse(ast.expression, options, parse, offsets), - semicolon: ast.semicolon.text - }), - print: ({ node, path, print }) => [ - path.call(print, 'expression'), - node.semicolon - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class ExpressionStatement extends SlangNode { + expression; + + semicolon; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.expression = parse(ast.expression, parse, this.nextChildOffset); + this.semicolon = ast.semicolon.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [path.call(print, 'expression'), this.semicolon]; + } +} diff --git a/src/slang-nodes/FallbackFunctionAttribute.js b/src/slang-nodes/FallbackFunctionAttribute.js index 84c9a913b..8bce5720d 100644 --- a/src/slang-nodes/FallbackFunctionAttribute.js +++ b/src/slang-nodes/FallbackFunctionAttribute.js @@ -1,12 +1,20 @@ -export const FallbackFunctionAttribute = { - parse: ({ offsets, ast, options, parse }) => ({ - variant: +import { SlangNode } from './SlangNode.js'; + +export class FallbackFunctionAttribute extends SlangNode { + variant; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, options, parse, offsets) - }), - print: ({ node, path, print }) => - typeof node.variant === 'string' - ? node.variant - : path.call(print, 'variant') -}; + : parse(ast.variant, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/FallbackFunctionAttributes.js b/src/slang-nodes/FallbackFunctionAttributes.js index e705ac5c6..2deb9b009 100644 --- a/src/slang-nodes/FallbackFunctionAttributes.js +++ b/src/slang-nodes/FallbackFunctionAttributes.js @@ -1,14 +1,21 @@ import { doc } from 'prettier'; import { sortFunctionAttributes } from '../common/slang-helpers.js'; +import { SlangNode } from './SlangNode.js'; const { line } = doc.builders; -export const FallbackFunctionAttributes = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items - .map((item) => parse(item, options, parse, offsets)) - .sort(sortFunctionAttributes) - }), - print: ({ path, print }) => - path.map(print, 'items').map((item) => [line, item]) -}; +export class FallbackFunctionAttributes extends SlangNode { + items; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items + .map((item) => parse(item, parse, this.nextChildOffset)) + .sort(sortFunctionAttributes); + this.initiateLoc(ast); + } + + print({ path, print }) { + return path.map(print, 'items').map((item) => [line, item]); + } +} diff --git a/src/slang-nodes/FallbackFunctionDefinition.js b/src/slang-nodes/FallbackFunctionDefinition.js index 16834e18d..24b6b135d 100644 --- a/src/slang-nodes/FallbackFunctionDefinition.js +++ b/src/slang-nodes/FallbackFunctionDefinition.js @@ -1,15 +1,30 @@ import { printFunction } from '../common/slang-helpers.js'; +import { SlangNode } from './SlangNode.js'; -export const FallbackFunctionDefinition = { - parse: ({ offsets, ast, options, parse }) => ({ - fallbackKeyword: ast.fallbackKeyword.text, - parameters: parse(ast.parameters, options, parse, offsets), - attributes: parse(ast.attributes, options, parse, offsets), - returns: ast.returns - ? parse(ast.returns, options, parse, offsets) - : undefined, - body: parse(ast.body, options, parse, offsets) - }), - print: ({ node, path, print }) => - printFunction(node.fallbackKeyword, node, path, print) -}; +export class FallbackFunctionDefinition extends SlangNode { + fallbackKeyword; + + parameters; + + attributes; + + returns; + + body; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.fallbackKeyword = ast.fallbackKeyword.text; + this.parameters = parse(ast.parameters, parse, this.nextChildOffset); + this.attributes = parse(ast.attributes, parse, this.nextChildOffset); + this.returns = ast.returns + ? parse(ast.returns, parse, this.nextChildOffset) + : undefined; + this.body = parse(ast.body, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return printFunction(this.fallbackKeyword, this, path, print); + } +} diff --git a/src/slang-nodes/ForStatement.js b/src/slang-nodes/ForStatement.js index 626a100f0..9eec784b3 100644 --- a/src/slang-nodes/ForStatement.js +++ b/src/slang-nodes/ForStatement.js @@ -1,37 +1,59 @@ import { doc } from 'prettier'; import { printSeparatedList } from '../common/printer-helpers.js'; +import { SlangNode } from './SlangNode.js'; const { group, indent, line } = doc.builders; -export const ForStatement = { - parse: ({ offsets, ast, options, parse }) => ({ - forKeyword: ast.forKeyword.text, - openParen: ast.openParen.text, - initialization: parse(ast.initialization, options, parse, offsets), - condition: parse(ast.condition, options, parse, offsets), - iterator: ast.iterator - ? parse(ast.iterator, options, parse, offsets) - : undefined, - closeParen: ast.closeParen.text, - body: parse(ast.body, options, parse, offsets) - }), - print: ({ node, path, print }) => { +export class ForStatement extends SlangNode { + forKeyword; + + openParen; + + initialization; + + condition; + + iterator; + + closeParen; + + body; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.forKeyword = ast.forKeyword.text; + this.openParen = ast.openParen.text; + this.initialization = parse( + ast.initialization, + parse, + this.nextChildOffset + ); + this.condition = parse(ast.condition, parse, this.nextChildOffset); + this.iterator = ast.iterator + ? parse(ast.iterator, parse, this.nextChildOffset) + : undefined; + this.closeParen = ast.closeParen.text; + this.body = parse(ast.body, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { const initialization = path.call(print, 'initialization'); const condition = path.call(print, 'condition'); - const iterator = node.iterator ? path.call(print, 'iterator') : ''; + const iterator = this.iterator ? path.call(print, 'iterator') : ''; return [ - `${node.forKeyword} ${node.openParen}`, + `${this.forKeyword} ${this.openParen}`, printSeparatedList([initialization, condition, iterator], { separator: initialization !== ';' || condition !== ';' || iterator !== '' ? line : '' }), - node.closeParen, - node.body.variant.kind === 'Block' + this.closeParen, + this.body.variant.kind === 'Block' ? [' ', path.call(print, 'body')] : group(indent([line, path.call(print, 'body')])) ]; } -}; +} diff --git a/src/slang-nodes/ForStatementCondition.js b/src/slang-nodes/ForStatementCondition.js index 5b4ff65d5..a14752e82 100644 --- a/src/slang-nodes/ForStatementCondition.js +++ b/src/slang-nodes/ForStatementCondition.js @@ -1,12 +1,20 @@ -export const ForStatementCondition = { - parse: ({ offsets, ast, options, parse }) => ({ - variant: +import { SlangNode } from './SlangNode.js'; + +export class ForStatementCondition extends SlangNode { + variant; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, options, parse, offsets) - }), - print: ({ node, path, print }) => - typeof node.variant === 'string' - ? node.variant - : path.call(print, 'variant') -}; + : parse(ast.variant, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/ForStatementInitialization.js b/src/slang-nodes/ForStatementInitialization.js index 49d0fb98f..94bbb3c9e 100644 --- a/src/slang-nodes/ForStatementInitialization.js +++ b/src/slang-nodes/ForStatementInitialization.js @@ -1,12 +1,20 @@ -export const ForStatementInitialization = { - parse: ({ offsets, ast, options, parse }) => ({ - variant: +import { SlangNode } from './SlangNode.js'; + +export class ForStatementInitialization extends SlangNode { + variant; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, options, parse, offsets) - }), - print: ({ node, path, print }) => - typeof node.variant === 'string' - ? node.variant - : path.call(print, 'variant') -}; + : parse(ast.variant, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/FunctionAttribute.js b/src/slang-nodes/FunctionAttribute.js index 0518a885f..29e8fdd2b 100644 --- a/src/slang-nodes/FunctionAttribute.js +++ b/src/slang-nodes/FunctionAttribute.js @@ -1,12 +1,20 @@ -export const FunctionAttribute = { - parse: ({ offsets, ast, options, parse }) => ({ - variant: +import { SlangNode } from './SlangNode.js'; + +export class FunctionAttribute extends SlangNode { + variant; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, options, parse, offsets) - }), - print: ({ node, path, print }) => - typeof node.variant === 'string' - ? node.variant - : path.call(print, 'variant') -}; + : parse(ast.variant, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/FunctionAttributes.js b/src/slang-nodes/FunctionAttributes.js index af8343898..2f6772a9e 100644 --- a/src/slang-nodes/FunctionAttributes.js +++ b/src/slang-nodes/FunctionAttributes.js @@ -1,14 +1,21 @@ import { doc } from 'prettier'; import { sortFunctionAttributes } from '../common/slang-helpers.js'; +import { SlangNode } from './SlangNode.js'; const { line } = doc.builders; -export const FunctionAttributes = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items - .map((item) => parse(item, options, parse, offsets)) - .sort(sortFunctionAttributes) - }), - print: ({ path, print }) => - path.map(print, 'items').map((item) => [line, item]) -}; +export class FunctionAttributes extends SlangNode { + items; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items + .map((item) => parse(item, parse, this.nextChildOffset)) + .sort(sortFunctionAttributes); + this.initiateLoc(ast); + } + + print({ path, print }) { + return path.map(print, 'items').map((item) => [line, item]); + } +} diff --git a/src/slang-nodes/FunctionBody.js b/src/slang-nodes/FunctionBody.js index 82263ae77..5d1aece97 100644 --- a/src/slang-nodes/FunctionBody.js +++ b/src/slang-nodes/FunctionBody.js @@ -1,12 +1,20 @@ -export const FunctionBody = { - parse: ({ offsets, ast, options, parse }) => ({ - variant: +import { SlangNode } from './SlangNode.js'; + +export class FunctionBody extends SlangNode { + variant; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, options, parse, offsets) - }), - print: ({ node, path, print }) => - typeof node.variant === 'string' - ? node.variant - : path.call(print, 'variant') -}; + : parse(ast.variant, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/FunctionCallExpression.js b/src/slang-nodes/FunctionCallExpression.js index 222067a56..b90e4dd05 100644 --- a/src/slang-nodes/FunctionCallExpression.js +++ b/src/slang-nodes/FunctionCallExpression.js @@ -1,16 +1,24 @@ import { doc } from 'prettier'; import { isLabel } from '../common/util.js'; +import { SlangNode } from './SlangNode.js'; const { group, indentIfBreak, label } = doc.builders; let groupIndex = 0; -export const FunctionCallExpression = { - parse: ({ offsets, ast, options, parse }) => ({ - operand: parse(ast.operand, options, parse, offsets), - arguments: parse(ast.arguments, options, parse, offsets) - }), - print: ({ path, print }) => { +export class FunctionCallExpression extends SlangNode { + operand; + + arguments; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.operand = parse(ast.operand, parse, this.nextChildOffset); + this.arguments = parse(ast.arguments, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { let operandDoc = path.call(print, 'operand'); let argumentsDoc = path.call(print, 'arguments'); @@ -33,4 +41,4 @@ export const FunctionCallExpression = { return [operandDoc, argumentsDoc].flat(); } -}; +} diff --git a/src/slang-nodes/FunctionDefinition.js b/src/slang-nodes/FunctionDefinition.js index 44ed880d9..64d6dd9f2 100644 --- a/src/slang-nodes/FunctionDefinition.js +++ b/src/slang-nodes/FunctionDefinition.js @@ -1,21 +1,38 @@ import { printFunction } from '../common/slang-helpers.js'; +import { SlangNode } from './SlangNode.js'; -export const FunctionDefinition = { - parse: ({ offsets, ast, options, parse }) => ({ - functionKeyword: ast.functionKeyword.text, - name: parse(ast.name, options, parse, offsets), - parameters: parse(ast.parameters, options, parse, offsets), - attributes: parse(ast.attributes, options, parse, offsets), - returns: ast.returns - ? parse(ast.returns, options, parse, offsets) - : undefined, - body: parse(ast.body, options, parse, offsets) - }), - print: ({ node, path, print }) => - printFunction( - [`${node.functionKeyword} `, path.call(print, 'name')], - node, +export class FunctionDefinition extends SlangNode { + functionKeyword; + + name; + + parameters; + + attributes; + + returns; + + body; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.functionKeyword = ast.functionKeyword.text; + this.name = parse(ast.name, parse, this.nextChildOffset); + this.parameters = parse(ast.parameters, parse, this.nextChildOffset); + this.attributes = parse(ast.attributes, parse, this.nextChildOffset); + this.returns = ast.returns + ? parse(ast.returns, parse, this.nextChildOffset) + : undefined; + this.body = parse(ast.body, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return printFunction( + [`${this.functionKeyword} `, path.call(print, 'name')], + this, path, print - ) -}; + ); + } +} diff --git a/src/slang-nodes/FunctionName.js b/src/slang-nodes/FunctionName.js index 5cb2e0579..3ea2dda70 100644 --- a/src/slang-nodes/FunctionName.js +++ b/src/slang-nodes/FunctionName.js @@ -1,6 +1,15 @@ -export const FunctionName = { - parse: ({ ast }) => ({ - variant: ast.variant.text - }), - print: ({ node }) => node.variant -}; +import { SlangNode } from './SlangNode.js'; + +export class FunctionName extends SlangNode { + variant; + + constructor({ ast, offset }) { + super(ast, offset); + this.variant = ast.variant.text; + this.initiateLoc(ast); + } + + print() { + return this.variant; + } +} diff --git a/src/slang-nodes/FunctionType.js b/src/slang-nodes/FunctionType.js index 750521cd1..2c8a2f739 100644 --- a/src/slang-nodes/FunctionType.js +++ b/src/slang-nodes/FunctionType.js @@ -1,14 +1,27 @@ import { printFunction } from '../common/slang-helpers.js'; +import { SlangNode } from './SlangNode.js'; -export const FunctionType = { - parse: ({ offsets, ast, options, parse }) => ({ - functionKeyword: ast.functionKeyword.text, - parameters: parse(ast.parameters, options, parse, offsets), - attributes: parse(ast.attributes, options, parse, offsets), - returns: ast.returns - ? parse(ast.returns, options, parse, offsets) - : undefined - }), - print: ({ node, path, print }) => - printFunction(node.functionKeyword, node, path, print) -}; +export class FunctionType extends SlangNode { + functionKeyword; + + parameters; + + attributes; + + returns; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.functionKeyword = ast.functionKeyword.text; + this.parameters = parse(ast.parameters, parse, this.nextChildOffset); + this.attributes = parse(ast.attributes, parse, this.nextChildOffset); + this.returns = ast.returns + ? parse(ast.returns, parse, this.nextChildOffset) + : undefined; + this.initiateLoc(ast); + } + + print({ path, print }) { + return printFunction(this.functionKeyword, this, path, print); + } +} diff --git a/src/slang-nodes/FunctionTypeAttribute.js b/src/slang-nodes/FunctionTypeAttribute.js index 5cda4b957..4e372783e 100644 --- a/src/slang-nodes/FunctionTypeAttribute.js +++ b/src/slang-nodes/FunctionTypeAttribute.js @@ -1,6 +1,15 @@ -export const FunctionTypeAttribute = { - parse: ({ ast }) => ({ - variant: ast.variant.text - }), - print: ({ node }) => node.variant -}; +import { SlangNode } from './SlangNode.js'; + +export class FunctionTypeAttribute extends SlangNode { + variant; + + constructor({ ast, offset }) { + super(ast, offset); + this.variant = ast.variant.text; + this.initiateLoc(ast); + } + + print() { + return this.variant; + } +} diff --git a/src/slang-nodes/FunctionTypeAttributes.js b/src/slang-nodes/FunctionTypeAttributes.js index ddc66dcb7..ef77f36c4 100644 --- a/src/slang-nodes/FunctionTypeAttributes.js +++ b/src/slang-nodes/FunctionTypeAttributes.js @@ -1,14 +1,21 @@ import { doc } from 'prettier'; import { sortFunctionAttributes } from '../common/slang-helpers.js'; +import { SlangNode } from './SlangNode.js'; const { line } = doc.builders; -export const FunctionTypeAttributes = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items - .map((item) => parse(item, options, parse, offsets)) - .sort(sortFunctionAttributes) - }), - print: ({ path, print }) => - path.map(print, 'items').map((item) => [line, item]) -}; +export class FunctionTypeAttributes extends SlangNode { + items; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items + .map((item) => parse(item, parse, this.nextChildOffset)) + .sort(sortFunctionAttributes); + this.initiateLoc(ast); + } + + print({ path, print }) { + return path.map(print, 'items').map((item) => [line, item]); + } +} diff --git a/src/slang-nodes/HexNumberExpression.js b/src/slang-nodes/HexNumberExpression.js index 98fa1eded..b17940cc1 100644 --- a/src/slang-nodes/HexNumberExpression.js +++ b/src/slang-nodes/HexNumberExpression.js @@ -1,10 +1,20 @@ -export const HexNumberExpression = { - parse: ({ offsets, ast, options, parse }) => ({ - literal: ast.literal.text, - unit: ast.unit ? parse(ast.unit, options, parse, offsets) : undefined - }), - print: ({ node, path, print }) => [ - node.literal, - node.unit ? [' ', path.call(print, 'unit')] : '' - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class HexNumberExpression extends SlangNode { + literal; + + unit; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.literal = ast.literal.text; + this.unit = ast.unit + ? parse(ast.unit, parse, this.nextChildOffset) + : undefined; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [this.literal, this.unit ? [' ', path.call(print, 'unit')] : '']; + } +} diff --git a/src/slang-nodes/HexStringLiteral.js b/src/slang-nodes/HexStringLiteral.js index b16f31f2b..4b1b2c931 100644 --- a/src/slang-nodes/HexStringLiteral.js +++ b/src/slang-nodes/HexStringLiteral.js @@ -1,8 +1,16 @@ import { printString } from '../common/util.js'; +import { SlangNode } from './SlangNode.js'; -export const HexStringLiteral = { - parse: ({ ast, options }) => ({ - variant: `hex${printString(ast.variant.text.slice(4, -1), options)}` - }), - print: ({ node }) => node.variant -}; +export class HexStringLiteral extends SlangNode { + variant; + + constructor({ ast, options, offset }) { + super(ast, offset); + this.variant = `hex${printString(ast.variant.text.slice(4, -1), options)}`; + this.initiateLoc(ast); + } + + print() { + return this.variant; + } +} diff --git a/src/slang-nodes/HexStringLiterals.js b/src/slang-nodes/HexStringLiterals.js index eec902d0b..65dd0316a 100644 --- a/src/slang-nodes/HexStringLiterals.js +++ b/src/slang-nodes/HexStringLiterals.js @@ -1,10 +1,20 @@ import { doc } from 'prettier'; +import { SlangNode } from './SlangNode.js'; const { join, hardline } = doc.builders; -export const HexStringLiterals = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)) - }), - print: ({ path, print }) => join(hardline, path.map(print, 'items')) -}; +export class HexStringLiterals extends SlangNode { + items; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items.map((item) => + parse(item, parse, this.nextChildOffset) + ); + this.initiateLoc(ast); + } + + print({ path, print }) { + return join(hardline, path.map(print, 'items')); + } +} diff --git a/src/slang-nodes/IdentifierPath.js b/src/slang-nodes/IdentifierPath.js index 4b8dfb60d..294c58db7 100644 --- a/src/slang-nodes/IdentifierPath.js +++ b/src/slang-nodes/IdentifierPath.js @@ -1,10 +1,20 @@ -export const IdentifierPath = { - parse: ({ ast }) => ({ - items: ast.items.map((item) => item.text), - separators: ast.separators.map((separator) => separator.text) - }), - print: ({ node }) => - node.items.map((item, index) => - index === 0 ? item : [node.separators[index - 1], item] - ) -}; +import { SlangNode } from './SlangNode.js'; + +export class IdentifierPath extends SlangNode { + items; + + separators; + + constructor({ ast, offset }) { + super(ast, offset); + this.items = ast.items.map((item) => item.text); + this.separators = ast.separators.map((separator) => separator.text); + this.initiateLoc(ast); + } + + print() { + return this.items.map((item, index) => + index === 0 ? item : [this.separators[index - 1], item] + ); + } +} diff --git a/src/slang-nodes/IfStatement.js b/src/slang-nodes/IfStatement.js index 70c8e1513..e87d54086 100644 --- a/src/slang-nodes/IfStatement.js +++ b/src/slang-nodes/IfStatement.js @@ -1,5 +1,6 @@ import { doc } from 'prettier'; import { printSeparatedItem } from '../common/printer-helpers.js'; +import { SlangNode } from './SlangNode.js'; const { group, hardline, indent, line } = doc.builders; @@ -10,26 +11,41 @@ const printBody = (bodyVariantKind, path, print) => shouldBreak: bodyVariantKind === 'IfStatement' // `if` within `if` }); -export const IfStatement = { - parse: ({ offsets, ast, options, parse }) => ({ - ifKeyword: ast.ifKeyword.text, - openParen: ast.openParen.text, - condition: parse(ast.condition, options, parse, offsets), - closeParen: ast.closeParen.text, - body: parse(ast.body, options, parse, offsets), - elseBranch: ast.elseBranch - ? parse(ast.elseBranch, options, parse, offsets) - : undefined - }), - print: ({ node, path, print }) => { - const bodyVariantKind = node.body.variant.kind; +export class IfStatement extends SlangNode { + ifKeyword; + + openParen; + + condition; + + closeParen; + + body; + + elseBranch; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.ifKeyword = ast.ifKeyword.text; + this.openParen = ast.openParen.text; + this.condition = parse(ast.condition, parse, this.nextChildOffset); + this.closeParen = ast.closeParen.text; + this.body = parse(ast.body, parse, this.nextChildOffset); + this.elseBranch = ast.elseBranch + ? parse(ast.elseBranch, parse, this.nextChildOffset) + : undefined; + this.initiateLoc(ast); + } + + print({ path, print }) { + const bodyVariantKind = this.body.variant.kind; return [ - `${node.ifKeyword} ${node.openParen}`, + `${this.ifKeyword} ${this.openParen}`, printSeparatedItem(path.call(print, 'condition')), - node.closeParen, + this.closeParen, printBody(bodyVariantKind, path, print), - node.elseBranch + this.elseBranch ? [ bodyVariantKind !== 'Block' ? hardline // else on a new line if body is not a block @@ -39,4 +55,4 @@ export const IfStatement = { : '' ]; } -}; +} diff --git a/src/slang-nodes/ImportAlias.js b/src/slang-nodes/ImportAlias.js index 088d8cec9..267a2431f 100644 --- a/src/slang-nodes/ImportAlias.js +++ b/src/slang-nodes/ImportAlias.js @@ -1,7 +1,18 @@ -export const ImportAlias = { - parse: ({ ast }) => ({ - asKeyword: ast.asKeyword.text, - identifier: ast.identifier.text - }), - print: ({ node }) => ` ${node.asKeyword} ${node.identifier}` -}; +import { SlangNode } from './SlangNode.js'; + +export class ImportAlias extends SlangNode { + asKeyword; + + identifier; + + constructor({ ast, offset }) { + super(ast, offset); + this.asKeyword = ast.asKeyword.text; + this.identifier = ast.identifier.text; + this.initiateLoc(ast); + } + + print() { + return ` ${this.asKeyword} ${this.identifier}`; + } +} diff --git a/src/slang-nodes/ImportClause.js b/src/slang-nodes/ImportClause.js index 04ec7473e..1d3969e75 100644 --- a/src/slang-nodes/ImportClause.js +++ b/src/slang-nodes/ImportClause.js @@ -1,6 +1,15 @@ -export const ImportClause = { - parse: ({ offsets, ast, options, parse }) => ({ - variant: parse(ast.variant, options, parse, offsets) - }), - print: ({ path, print }) => path.call(print, 'variant') -}; +import { SlangNode } from './SlangNode.js'; + +export class ImportClause extends SlangNode { + variant; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.variant = parse(ast.variant, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/ImportDeconstruction.js b/src/slang-nodes/ImportDeconstruction.js index 2947be004..6ec3127ad 100644 --- a/src/slang-nodes/ImportDeconstruction.js +++ b/src/slang-nodes/ImportDeconstruction.js @@ -1,15 +1,32 @@ -export const ImportDeconstruction = { - parse: ({ offsets, ast, options, parse }) => ({ - openBrace: ast.openBrace.text, - symbols: parse(ast.symbols, options, parse, offsets), - closeBrace: ast.closeBrace.text, - fromKeyword: ast.fromKeyword.text, - path: parse(ast.path, options, parse, offsets) - }), - print: ({ node, path, print }) => [ - node.openBrace, - path.call(print, 'symbols'), - `${node.closeBrace} ${node.fromKeyword} `, - path.call(print, 'path') - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class ImportDeconstruction extends SlangNode { + openBrace; + + symbols; + + closeBrace; + + fromKeyword; + + path; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.openBrace = ast.openBrace.text; + this.symbols = parse(ast.symbols, parse, this.nextChildOffset); + this.closeBrace = ast.closeBrace.text; + this.fromKeyword = ast.fromKeyword.text; + this.path = parse(ast.path, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + this.openBrace, + path.call(print, 'symbols'), + `${this.closeBrace} ${this.fromKeyword} `, + path.call(print, 'path') + ]; + } +} diff --git a/src/slang-nodes/ImportDeconstructionSymbol.js b/src/slang-nodes/ImportDeconstructionSymbol.js index 748f49683..34c984456 100644 --- a/src/slang-nodes/ImportDeconstructionSymbol.js +++ b/src/slang-nodes/ImportDeconstructionSymbol.js @@ -1,10 +1,20 @@ -export const ImportDeconstructionSymbol = { - parse: ({ offsets, ast, options, parse }) => ({ - name: ast.name.text, - alias: ast.alias ? parse(ast.alias, options, parse, offsets) : undefined - }), - print: ({ node, path, print }) => [ - node.name, - node.alias ? path.call(print, 'alias') : '' - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class ImportDeconstructionSymbol extends SlangNode { + name; + + alias; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.name = ast.name.text; + this.alias = ast.alias + ? parse(ast.alias, parse, this.nextChildOffset) + : undefined; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [this.name, this.alias ? path.call(print, 'alias') : '']; + } +} diff --git a/src/slang-nodes/ImportDeconstructionSymbols.js b/src/slang-nodes/ImportDeconstructionSymbols.js index f15fec283..013b74530 100644 --- a/src/slang-nodes/ImportDeconstructionSymbols.js +++ b/src/slang-nodes/ImportDeconstructionSymbols.js @@ -2,15 +2,25 @@ 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 { SlangNode } from './SlangNode.js'; const { line, softline } = doc.builders; -export const ImportDeconstructionSymbols = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)), - separators: ast.separators.map((separator) => separator.text) - }), - print: ({ path, print, options }) => { +export class ImportDeconstructionSymbols extends SlangNode { + items; + + separators; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items.map((item) => + parse(item, parse, this.nextChildOffset) + ); + this.separators = ast.separators.map((separator) => separator.text); + this.initiateLoc(ast); + } + + print({ path, print, options }) { const compiler = coerce(options.compiler); let firstSeparator; let separator; @@ -31,4 +41,4 @@ export const ImportDeconstructionSymbols = { separator }); } -}; +} diff --git a/src/slang-nodes/ImportDirective.js b/src/slang-nodes/ImportDirective.js index 50c8c7889..abb316de2 100644 --- a/src/slang-nodes/ImportDirective.js +++ b/src/slang-nodes/ImportDirective.js @@ -1,12 +1,25 @@ -export const ImportDirective = { - parse: ({ offsets, ast, options, parse }) => ({ - importKeyword: ast.importKeyword.text, - clause: parse(ast.clause, options, parse, offsets), - semicolon: ast.semicolon.text - }), - print: ({ node, path, print }) => [ - `${node.importKeyword} `, - path.call(print, 'clause'), - node.semicolon - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class ImportDirective extends SlangNode { + importKeyword; + + clause; + + semicolon; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.importKeyword = ast.importKeyword.text; + this.clause = parse(ast.clause, parse, this.nextChildOffset); + this.semicolon = ast.semicolon.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + `${this.importKeyword} `, + path.call(print, 'clause'), + this.semicolon + ]; + } +} diff --git a/src/slang-nodes/IndexAccessEnd.js b/src/slang-nodes/IndexAccessEnd.js index acdc20242..a75966e63 100644 --- a/src/slang-nodes/IndexAccessEnd.js +++ b/src/slang-nodes/IndexAccessEnd.js @@ -1,10 +1,20 @@ -export const IndexAccessEnd = { - parse: ({ offsets, ast, options, parse }) => ({ - colon: ast.colon.text, - end: ast.end ? parse(ast.end, options, parse, offsets) : undefined - }), - print: ({ node, path, print }) => [ - node.colon, - node.end ? path.call(print, 'end') : '' - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class IndexAccessEnd extends SlangNode { + colon; + + end; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.colon = ast.colon.text; + this.end = ast.end + ? parse(ast.end, parse, this.nextChildOffset) + : undefined; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [this.colon, this.end ? path.call(print, 'end') : '']; + } +} diff --git a/src/slang-nodes/IndexAccessExpression.js b/src/slang-nodes/IndexAccessExpression.js index 332c94f56..81a5031c5 100644 --- a/src/slang-nodes/IndexAccessExpression.js +++ b/src/slang-nodes/IndexAccessExpression.js @@ -1,29 +1,47 @@ import { doc } from 'prettier'; import { isLabel } from '../common/util.js'; +import { SlangNode } from './SlangNode.js'; const { group, indent, indentIfBreak, label, softline } = doc.builders; let groupIndex = 0; -export const IndexAccessExpression = { - parse: ({ offsets, ast, options, parse }) => ({ - operand: parse(ast.operand, options, parse, offsets), - openBracket: ast.openBracket.text, - start: ast.start ? parse(ast.start, options, parse, offsets) : undefined, - end: ast.end ? parse(ast.end, options, parse, offsets) : undefined, - closeBracket: ast.closeBracket.text - }), - print: ({ node, path, print }) => { +export class IndexAccessExpression extends SlangNode { + operand; + + openBracket; + + start; + + end; + + closeBracket; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.operand = parse(ast.operand, parse, this.nextChildOffset); + this.openBracket = ast.openBracket.text; + this.start = ast.start + ? parse(ast.start, parse, this.nextChildOffset) + : undefined; + this.end = ast.end + ? parse(ast.end, parse, this.nextChildOffset) + : undefined; + this.closeBracket = ast.closeBracket.text; + this.initiateLoc(ast); + } + + print({ path, print }) { let operandDoc = path.call(print, 'operand'); let indexDoc = group([ - node.openBracket, + this.openBracket, indent([ softline, - node.start ? path.call(print, 'start') : '', - node.end ? path.call(print, 'end') : '' + this.start ? path.call(print, 'start') : '', + this.end ? path.call(print, 'end') : '' ]), softline, - node.closeBracket + this.closeBracket ]); // If we are at the end of a MemberAccessChain we should indent the @@ -45,4 +63,4 @@ export const IndexAccessExpression = { return [operandDoc, indexDoc].flat(); } -}; +} diff --git a/src/slang-nodes/InheritanceSpecifier.js b/src/slang-nodes/InheritanceSpecifier.js index 6118d008e..b609ef829 100644 --- a/src/slang-nodes/InheritanceSpecifier.js +++ b/src/slang-nodes/InheritanceSpecifier.js @@ -1,7 +1,18 @@ -export const InheritanceSpecifier = { - parse: ({ offsets, ast, options, parse }) => ({ - isKeyword: ast.isKeyword.text, - types: parse(ast.types, options, parse, offsets) - }), - print: ({ node, path, print }) => [node.isKeyword, path.call(print, 'types')] -}; +import { SlangNode } from './SlangNode.js'; + +export class InheritanceSpecifier extends SlangNode { + isKeyword; + + types; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.isKeyword = ast.isKeyword.text; + this.types = parse(ast.types, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return [this.isKeyword, path.call(print, 'types')]; + } +} diff --git a/src/slang-nodes/InheritanceType.js b/src/slang-nodes/InheritanceType.js index 5ba9c95cf..f5d06312e 100644 --- a/src/slang-nodes/InheritanceType.js +++ b/src/slang-nodes/InheritanceType.js @@ -1,12 +1,23 @@ -export const InheritanceType = { - parse: ({ offsets, ast, options, parse }) => ({ - typeName: parse(ast.typeName, options, parse, offsets), - arguments: ast.arguments - ? parse(ast.arguments, options, parse, offsets) - : undefined - }), - print: ({ node, path, print }) => [ - path.call(print, 'typeName'), - node.arguments ? path.call(print, 'arguments') : '' - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class InheritanceType extends SlangNode { + typeName; + + arguments; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.typeName = parse(ast.typeName, parse, this.nextChildOffset); + this.arguments = ast.arguments + ? parse(ast.arguments, parse, this.nextChildOffset) + : undefined; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + path.call(print, 'typeName'), + this.arguments ? path.call(print, 'arguments') : '' + ]; + } +} diff --git a/src/slang-nodes/InheritanceTypes.js b/src/slang-nodes/InheritanceTypes.js index 4471808df..771866f6b 100644 --- a/src/slang-nodes/InheritanceTypes.js +++ b/src/slang-nodes/InheritanceTypes.js @@ -1,15 +1,26 @@ import { doc } from 'prettier'; import { printSeparatedList } from '../common/printer-helpers.js'; +import { SlangNode } from './SlangNode.js'; const { line } = doc.builders; -export const InheritanceTypes = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)), - separators: ast.separators.map((separator) => separator.text) - }), - print: ({ path, print }) => - printSeparatedList(path.map(print, 'items'), { +export class InheritanceTypes extends SlangNode { + items; + + separators; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items.map((item) => + parse(item, parse, this.nextChildOffset) + ); + this.separators = ast.separators.map((separator) => separator.text); + this.initiateLoc(ast); + } + + print({ path, print }) { + return printSeparatedList(path.map(print, 'items'), { firstSeparator: line - }) -}; + }); + } +} diff --git a/src/slang-nodes/InterfaceDefinition.js b/src/slang-nodes/InterfaceDefinition.js index 40e3a4463..cad80e531 100644 --- a/src/slang-nodes/InterfaceDefinition.js +++ b/src/slang-nodes/InterfaceDefinition.js @@ -1,25 +1,43 @@ import { doc } from 'prettier'; +import { SlangNode } from './SlangNode.js'; const { group, line } = doc.builders; -export const InterfaceDefinition = { - parse: ({ offsets, ast, options, parse }) => ({ - interfaceKeyword: ast.interfaceKeyword.text, - name: ast.name.text, - inheritance: ast.inheritence - ? parse(ast.inheritance, options, parse, offsets) - : undefined, - openBrace: ast.openBrace.text, - members: parse(ast.members, options, parse, offsets), - closeBrace: ast.closeBrace.text - }), - print: ({ node, path, print }) => [ - group([ - `${node.interfaceKeyword} ${node.name}`, - node.inheritance ? path.call(print, 'inheritance') : line, - node.openBrace - ]), - path.call(print, 'members'), - node.closeBrace - ] -}; +export class InterfaceDefinition extends SlangNode { + interfaceKeyword; + + name; + + inheritance; + + openBrace; + + members; + + closeBrace; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.interfaceKeyword = ast.interfaceKeyword.text; + this.name = ast.name.text; + this.inheritance = ast.inheritence + ? parse(ast.inheritance, parse, this.nextChildOffset) + : undefined; + this.openBrace = ast.openBrace.text; + this.members = parse(ast.members, parse, this.nextChildOffset); + this.closeBrace = ast.closeBrace.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + group([ + `${this.interfaceKeyword} ${this.name}`, + this.inheritance ? path.call(print, 'inheritance') : line, + this.openBrace + ]), + path.call(print, 'members'), + this.closeBrace + ]; + } +} diff --git a/src/slang-nodes/InterfaceMembers.js b/src/slang-nodes/InterfaceMembers.js index 5c63ecd40..0cfe4b1af 100644 --- a/src/slang-nodes/InterfaceMembers.js +++ b/src/slang-nodes/InterfaceMembers.js @@ -1,18 +1,27 @@ import { doc } from 'prettier'; import { printSeparatedItem } from '../common/printer-helpers.js'; import { printPreservingEmptyLines } from '../common/slang-helpers.js'; +import { SlangNode } from './SlangNode.js'; const { hardline } = doc.builders; -export const InterfaceMembers = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)) - }), - print: ({ node, options, path, print }) => - node.items.length > 0 +export class InterfaceMembers extends SlangNode { + items; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items.map((item) => + parse(item, parse, this.nextChildOffset) + ); + this.initiateLoc(ast); + } + + print({ options, path, print }) { + return this.items.length > 0 ? printSeparatedItem( printPreservingEmptyLines(path, 'items', options, print), { firstSeparator: hardline, grouped: false } ) - : '' -}; + : ''; + } +} diff --git a/src/slang-nodes/LibraryDefinition.js b/src/slang-nodes/LibraryDefinition.js index 7df51a1f9..32f497f7a 100644 --- a/src/slang-nodes/LibraryDefinition.js +++ b/src/slang-nodes/LibraryDefinition.js @@ -1,18 +1,34 @@ import { doc } from 'prettier'; +import { SlangNode } from './SlangNode.js'; const { group, line } = doc.builders; -export const LibraryDefinition = { - parse: ({ offsets, ast, options, parse }) => ({ - libraryKeyword: ast.libraryKeyword.text, - name: ast.name.text, - openBrace: ast.openBrace.text, - members: parse(ast.members, options, parse, offsets), - closeBrace: ast.closeBrace.text - }), - print: ({ node, path, print }) => [ - group([`${node.libraryKeyword} ${node.name}`, line, node.openBrace]), - path.call(print, 'members'), - node.closeBrace - ] -}; +export class LibraryDefinition extends SlangNode { + libraryKeyword; + + name; + + openBrace; + + members; + + closeBrace; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.libraryKeyword = ast.libraryKeyword.text; + this.name = ast.name.text; + this.openBrace = ast.openBrace.text; + this.members = parse(ast.members, parse, this.nextChildOffset); + this.closeBrace = ast.closeBrace.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + group([`${this.libraryKeyword} ${this.name}`, line, this.openBrace]), + path.call(print, 'members'), + this.closeBrace + ]; + } +} diff --git a/src/slang-nodes/LibraryMembers.js b/src/slang-nodes/LibraryMembers.js index 5d6f78886..af3c367e5 100644 --- a/src/slang-nodes/LibraryMembers.js +++ b/src/slang-nodes/LibraryMembers.js @@ -1,18 +1,27 @@ import { doc } from 'prettier'; import { printSeparatedItem } from '../common/printer-helpers.js'; import { printPreservingEmptyLines } from '../common/slang-helpers.js'; +import { SlangNode } from './SlangNode.js'; const { hardline } = doc.builders; -export const LibraryMembers = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)) - }), - print: ({ node, path, print, options }) => - node.items.length > 0 +export class LibraryMembers extends SlangNode { + items; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items.map((item) => + parse(item, parse, this.nextChildOffset) + ); + this.initiateLoc(ast); + } + + print({ path, print, options }) { + return this.items.length > 0 ? printSeparatedItem( printPreservingEmptyLines(path, 'items', options, print), { firstSeparator: hardline, grouped: false } ) - : '' -}; + : ''; + } +} diff --git a/src/slang-nodes/MappingKey.js b/src/slang-nodes/MappingKey.js index 13053af70..3038948ba 100644 --- a/src/slang-nodes/MappingKey.js +++ b/src/slang-nodes/MappingKey.js @@ -1,10 +1,18 @@ -export const MappingKey = { - parse: ({ offsets, ast, options, parse }) => ({ - keyType: parse(ast.keyType, options, parse, offsets), - name: ast.name?.text - }), - print: ({ node, path, print }) => [ - path.call(print, 'keyType'), - node.name ? ` ${node.name}` : '' - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class MappingKey extends SlangNode { + keyType; + + name; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.keyType = parse(ast.keyType, parse, this.nextChildOffset); + this.name = ast.name?.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [path.call(print, 'keyType'), this.name ? ` ${this.name}` : '']; + } +} diff --git a/src/slang-nodes/MappingKeyType.js b/src/slang-nodes/MappingKeyType.js index eab4d9d49..d45f76868 100644 --- a/src/slang-nodes/MappingKeyType.js +++ b/src/slang-nodes/MappingKeyType.js @@ -1,6 +1,15 @@ -export const MappingKeyType = { - parse: ({ offsets, ast, options, parse }) => ({ - variant: parse(ast.variant, options, parse, offsets) - }), - print: ({ path, print }) => path.call(print, 'variant') -}; +import { SlangNode } from './SlangNode.js'; + +export class MappingKeyType extends SlangNode { + variant; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.variant = parse(ast.variant, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/MappingType.js b/src/slang-nodes/MappingType.js index 5f9708976..682cac690 100644 --- a/src/slang-nodes/MappingType.js +++ b/src/slang-nodes/MappingType.js @@ -1,17 +1,36 @@ -export const MappingType = { - parse: ({ offsets, ast, options, parse }) => ({ - mappingKeyword: ast.mappingKeyword.text, - openParen: ast.openParen.text, - keyType: parse(ast.keyType, options, parse, offsets), - equalGreaterThan: ast.equalGreaterThan.text, - valueType: parse(ast.valueType, options, parse, offsets), - closeParen: ast.closeParen.text - }), - print: ({ node, path, print }) => [ - `${node.mappingKeyword}${node.openParen}`, - path.call(print, 'keyType'), - ` ${node.equalGreaterThan} `, - path.call(print, 'valueType'), - node.closeParen - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class MappingType extends SlangNode { + mappingKeyword; + + openParen; + + keyType; + + equalGreaterThan; + + valueType; + + closeParen; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.mappingKeyword = ast.mappingKeyword.text; + this.openParen = ast.openParen.text; + this.keyType = parse(ast.keyType, parse, this.nextChildOffset); + this.equalGreaterThan = ast.equalGreaterThan.text; + this.valueType = parse(ast.valueType, parse, this.nextChildOffset); + this.closeParen = ast.closeParen.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + `${this.mappingKeyword}${this.openParen}`, + path.call(print, 'keyType'), + ` ${this.equalGreaterThan} `, + path.call(print, 'valueType'), + this.closeParen + ]; + } +} diff --git a/src/slang-nodes/MappingValue.js b/src/slang-nodes/MappingValue.js index e37e8a90f..efdbeab02 100644 --- a/src/slang-nodes/MappingValue.js +++ b/src/slang-nodes/MappingValue.js @@ -1,10 +1,18 @@ -export const MappingValue = { - parse: ({ offsets, ast, options, parse }) => ({ - typeName: parse(ast.typeName, options, parse, offsets), - name: ast.name?.text - }), - print: ({ node, path, print }) => [ - path.call(print, 'typeName'), - node.name ? ` ${node.name}` : '' - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class MappingValue extends SlangNode { + typeName; + + name; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.typeName = parse(ast.typeName, parse, this.nextChildOffset); + this.name = ast.name?.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [path.call(print, 'typeName'), this.name ? ` ${this.name}` : '']; + } +} diff --git a/src/slang-nodes/MemberAccess.js b/src/slang-nodes/MemberAccess.js index 780257c4a..79d73aede 100644 --- a/src/slang-nodes/MemberAccess.js +++ b/src/slang-nodes/MemberAccess.js @@ -1,6 +1,15 @@ -export const MemberAccess = { - parse: ({ ast }) => ({ - variant: ast.variant.text - }), - print: ({ node }) => node.variant -}; +import { SlangNode } from './SlangNode.js'; + +export class MemberAccess extends SlangNode { + variant; + + constructor({ ast, offset }) { + super(ast, offset); + this.variant = ast.variant.text; + this.initiateLoc(ast); + } + + print() { + return this.variant; + } +} diff --git a/src/slang-nodes/MemberAccessExpression.js b/src/slang-nodes/MemberAccessExpression.js index f80cac862..b8a75996b 100644 --- a/src/slang-nodes/MemberAccessExpression.js +++ b/src/slang-nodes/MemberAccessExpression.js @@ -1,6 +1,7 @@ import { doc } from 'prettier'; import { isLabel } from '../common/util.js'; import { createKindCheckFunction } from '../common/slang-helpers.js'; +import { SlangNode } from './SlangNode.js'; const { group, indent, label, softline } = doc.builders; @@ -104,13 +105,22 @@ const processChain = (chain) => { ]); }; -export const MemberAccessExpression = { - parse: ({ offsets, ast, options, parse }) => ({ - operand: parse(ast.operand, options, parse, offsets), - period: ast.period.text, - member: parse(ast.member, options, parse, offsets) - }), - print: ({ node, path, print }) => { +export class MemberAccessExpression extends SlangNode { + operand; + + period; + + member; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.operand = parse(ast.operand, parse, this.nextChildOffset); + this.period = ast.period.text; + this.member = parse(ast.member, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { let operandDoc = path.call(print, 'operand'); if (Array.isArray(operandDoc)) { operandDoc = operandDoc.flat(); @@ -118,10 +128,10 @@ export const MemberAccessExpression = { const document = [ operandDoc, - label('separator', [softline, node.period]), + label('separator', [softline, this.period]), path.call(print, 'member') ].flat(); - return isEndOfChain(node, path) ? processChain(document) : document; + return isEndOfChain(this, path) ? processChain(document) : document; } -}; +} diff --git a/src/slang-nodes/ModifierAttribute.js b/src/slang-nodes/ModifierAttribute.js index 7ddd1d2ec..c5374bb51 100644 --- a/src/slang-nodes/ModifierAttribute.js +++ b/src/slang-nodes/ModifierAttribute.js @@ -1,12 +1,20 @@ -export const ModifierAttribute = { - parse: ({ offsets, ast, options, parse }) => ({ - variant: +import { SlangNode } from './SlangNode.js'; + +export class ModifierAttribute extends SlangNode { + variant; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, options, parse, offsets) - }), - print: ({ node, path, print }) => - typeof node.variant === 'string' - ? node.variant - : path.call(print, 'variant') -}; + : parse(ast.variant, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/ModifierAttributes.js b/src/slang-nodes/ModifierAttributes.js index 2c7c4b96e..de07c1f75 100644 --- a/src/slang-nodes/ModifierAttributes.js +++ b/src/slang-nodes/ModifierAttributes.js @@ -1,14 +1,21 @@ import { doc } from 'prettier'; import { sortFunctionAttributes } from '../common/slang-helpers.js'; +import { SlangNode } from './SlangNode.js'; const { line } = doc.builders; -export const ModifierAttributes = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items - .map((item) => parse(item, options, parse, offsets)) - .sort(sortFunctionAttributes) - }), - print: ({ path, print }) => - path.map(print, 'items').map((item) => [line, item]) -}; +export class ModifierAttributes extends SlangNode { + items; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items + .map((item) => parse(item, parse, this.nextChildOffset)) + .sort(sortFunctionAttributes); + this.initiateLoc(ast); + } + + print({ path, print }) { + return path.map(print, 'items').map((item) => [line, item]); + } +} diff --git a/src/slang-nodes/ModifierDefinition.js b/src/slang-nodes/ModifierDefinition.js index b7fdbbe9f..40d36e1a4 100644 --- a/src/slang-nodes/ModifierDefinition.js +++ b/src/slang-nodes/ModifierDefinition.js @@ -1,26 +1,55 @@ import { printFunction } from '../common/slang-helpers.js'; +import { SlangNode } from './SlangNode.js'; +import { ParametersDeclaration } from './ParametersDeclaration.js'; +import { Parameters } from './Parameters.js'; -export const ModifierDefinition = { - parse: ({ offsets, ast, options, parse }) => ({ - modifierKeyword: ast.modifierKeyword.text, - name: ast.name.text, - parameters: ast.parameters - ? parse(ast.parameters, options, parse, offsets) - : { +export class ModifierDefinition extends SlangNode { + modifierKeyword; + + name; + + parameters; + + attributes; + + body; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.modifierKeyword = ast.modifierKeyword.text; + this.name = ast.name.text; + const parametersOffset = this.nextChildOffset; + this.parameters = ast.parameters + ? parse(ast.parameters, parse, parametersOffset) + : new ParametersDeclaration({ kind: 'ParametersDeclaration', - loc: { start: offsets[0], end: offsets[0] }, + loc: { + start: parametersOffset, + end: parametersOffset + }, openParen: '(', - parameters: { + parameters: new Parameters({ kind: 'Parameters', - loc: { start: offsets[0], end: offsets[0] }, + loc: { + start: parametersOffset, + end: parametersOffset + }, items: [], separators: [] - }, + }), closeParen: ')' - }, - attributes: parse(ast.attributes, options, parse, offsets), - body: parse(ast.body, options, parse, offsets) - }), - print: ({ node, path, print }) => - printFunction(`${node.modifierKeyword} ${node.name}`, node, path, print) -}; + }); + this.attributes = parse(ast.attributes, parse, this.nextChildOffset); + this.body = parse(ast.body, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return printFunction( + `${this.modifierKeyword} ${this.name}`, + this, + path, + print + ); + } +} diff --git a/src/slang-nodes/ModifierInvocation.js b/src/slang-nodes/ModifierInvocation.js index 2a90291f0..bd3cf51b3 100644 --- a/src/slang-nodes/ModifierInvocation.js +++ b/src/slang-nodes/ModifierInvocation.js @@ -1,12 +1,35 @@ -export const ModifierInvocation = { - parse: ({ offsets, ast, options, parse }) => ({ - name: parse(ast.name, options, parse, offsets), - arguments: ast.arguments - ? parse(ast.arguments, options, parse, offsets) - : undefined - }), - print: ({ node, path, print }) => [ - path.call(print, 'name'), - node.arguments ? path.call(print, 'arguments') : '' - ] -}; +import { isComment } from '../common/slang-helpers.js'; +import { SlangNode } from './SlangNode.js'; + +export class ModifierInvocation extends SlangNode { + name; + + arguments; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.name = parse(ast.name, parse, this.nextChildOffset); + this.arguments = ast.arguments + ? parse(ast.arguments, parse, this.nextChildOffset) + : undefined; + this.initiateLoc(ast); + } + + removeInvocationArguments() { + if ( + this.arguments && + this.arguments.variant.kind === 'PositionalArgumentsDeclaration' && + this.arguments.variant.arguments.items.length === 0 && // no arguments + !ast.arguments.variant.cst.children().some((child) => isComment(child)) // no comments + ) { + this.arguments = undefined; + } + } + + print({ path, print }) { + return [ + path.call(print, 'name'), + this.arguments ? path.call(print, 'arguments') : '' + ]; + } +} diff --git a/src/slang-nodes/MultiplicativeExpression.js b/src/slang-nodes/MultiplicativeExpression.js index 19d67e086..4817df890 100644 --- a/src/slang-nodes/MultiplicativeExpression.js +++ b/src/slang-nodes/MultiplicativeExpression.js @@ -1,36 +1,42 @@ -import { - binaryOperationPrint, - createHugFunction -} from '../common/slang-helpers.js'; +import { binaryOperationPrint } from '../common/slang-helpers.js'; +import { createHugFunction } from '../slang-utils/create-hug-function.js'; +import { SlangNode } from './SlangNode.js'; const multiplicationTryToHug = createHugFunction(['/', '%']); const divisionTryToHug = createHugFunction(['*', '%']); const moduloTryToHug = createHugFunction(['*', '/', '%']); -export const MultiplicativeExpression = { - parse: ({ offsets, ast, options, parse }) => { - let leftOperand = parse(ast.leftOperand, options, parse, offsets); - const operator = ast.operator.text; +export class MultiplicativeExpression extends SlangNode { + leftOperand; - switch (operator) { + operator; + + rightOperand; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.leftOperand = parse(ast.leftOperand, parse, this.nextChildOffset); + this.operator = ast.operator.text; + + switch (this.operator) { case '*': - leftOperand = multiplicationTryToHug(leftOperand); + this.leftOperand = multiplicationTryToHug(this.leftOperand); break; case '/': - leftOperand = divisionTryToHug(leftOperand); + this.leftOperand = divisionTryToHug(this.leftOperand); break; case '%': - leftOperand = moduloTryToHug(leftOperand); + this.leftOperand = moduloTryToHug(this.leftOperand); break; default: break; } - return { - leftOperand, - operator, - rightOperand: parse(ast.rightOperand, options, parse, offsets) - }; - }, - print: binaryOperationPrint -}; + this.rightOperand = parse(ast.rightOperand, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print, options }) { + return binaryOperationPrint({ node: this, path, print, options }); + } +} diff --git a/src/slang-nodes/NamedArgument.js b/src/slang-nodes/NamedArgument.js index fa9cd6be4..210204d1b 100644 --- a/src/slang-nodes/NamedArgument.js +++ b/src/slang-nodes/NamedArgument.js @@ -1,11 +1,21 @@ -export const NamedArgument = { - parse: ({ offsets, ast, options, parse }) => ({ - name: ast.name.text, - colon: ast.colon.text, - value: parse(ast.value, options, parse, offsets) - }), - print: ({ node, path, print }) => [ - `${node.name}${node.colon} `, - path.call(print, 'value') - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class NamedArgument extends SlangNode { + name; + + colon; + + value; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.name = ast.name.text; + this.colon = ast.colon.text; + this.value = parse(ast.value, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return [`${this.name}${this.colon} `, path.call(print, 'value')]; + } +} diff --git a/src/slang-nodes/NamedArgumentGroup.js b/src/slang-nodes/NamedArgumentGroup.js index e1f2770ae..0966759c4 100644 --- a/src/slang-nodes/NamedArgumentGroup.js +++ b/src/slang-nodes/NamedArgumentGroup.js @@ -1,12 +1,21 @@ -export const NamedArgumentGroup = { - parse: ({ offsets, ast, options, parse }) => ({ - openBrace: ast.openBrace.text, - arguments: parse(ast.arguments, options, parse, offsets), - closeBrace: ast.closeBrace.text - }), - print: ({ node, path, print }) => [ - node.openBrace, - path.call(print, 'arguments'), - node.closeBrace - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class NamedArgumentGroup extends SlangNode { + openBrace; + + arguments; + + closeBrace; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.openBrace = ast.openBrace.text; + this.arguments = parse(ast.arguments, parse, this.nextChildOffset); + this.closeBrace = ast.closeBrace.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [this.openBrace, path.call(print, 'arguments'), this.closeBrace]; + } +} diff --git a/src/slang-nodes/NamedArguments.js b/src/slang-nodes/NamedArguments.js index 4aa0ac720..7d907e5cf 100644 --- a/src/slang-nodes/NamedArguments.js +++ b/src/slang-nodes/NamedArguments.js @@ -1,15 +1,26 @@ import { doc } from 'prettier'; import { printSeparatedList } from '../common/printer-helpers.js'; +import { SlangNode } from './SlangNode.js'; const { line, softline } = doc.builders; -export const NamedArguments = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)), - separators: ast.separators.map((separator) => separator.text) - }), - print: ({ path, print, options }) => - printSeparatedList(path.map(print, 'items'), { +export class NamedArguments extends SlangNode { + items; + + separators; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items.map((item) => + parse(item, parse, this.nextChildOffset) + ); + this.separators = ast.separators.map((separator) => separator.text); + this.initiateLoc(ast); + } + + print({ path, print, options }) { + return printSeparatedList(path.map(print, 'items'), { firstSeparator: options.bracketSpacing ? line : softline - }) -}; + }); + } +} diff --git a/src/slang-nodes/NamedArgumentsDeclaration.js b/src/slang-nodes/NamedArgumentsDeclaration.js index 62bfe9177..c5440fe22 100644 --- a/src/slang-nodes/NamedArgumentsDeclaration.js +++ b/src/slang-nodes/NamedArgumentsDeclaration.js @@ -1,14 +1,27 @@ -export const NamedArgumentsDeclaration = { - parse: ({ offsets, ast, options, parse }) => ({ - openParen: ast.openParen.text, - arguments: ast.arguments - ? parse(ast.arguments, options, parse, offsets) - : undefined, - closeParen: ast.closeParen.text - }), - print: ({ node, path, print }) => [ - node.openParen, - node.arguments ? path.call(print, 'arguments') : '', - node.closeParen - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class NamedArgumentsDeclaration extends SlangNode { + openParen; + + arguments; + + closeParen; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.openParen = ast.openParen.text; + this.arguments = ast.arguments + ? parse(ast.arguments, parse, this.nextChildOffset) + : undefined; + this.closeParen = ast.closeParen.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + this.openParen, + this.arguments ? path.call(print, 'arguments') : '', + this.closeParen + ]; + } +} diff --git a/src/slang-nodes/NamedImport.js b/src/slang-nodes/NamedImport.js index 9e27dc34a..da661cc2c 100644 --- a/src/slang-nodes/NamedImport.js +++ b/src/slang-nodes/NamedImport.js @@ -1,14 +1,29 @@ -export const NamedImport = { - parse: ({ offsets, ast, options, parse }) => ({ - asterisk: ast.asterisk.text, - alias: parse(ast.alias, options, parse, offsets), - fromKeyword: ast.fromKeyword.text, - path: parse(ast.path, options, parse, offsets) - }), - print: ({ node, path, print }) => [ - node.asterisk, - path.call(print, 'alias'), - ` ${node.fromKeyword} `, - path.call(print, 'path') - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class NamedImport extends SlangNode { + asterisk; + + alias; + + fromKeyword; + + path; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.asterisk = ast.asterisk.text; + this.alias = parse(ast.alias, parse, this.nextChildOffset); + this.fromKeyword = ast.fromKeyword.text; + this.path = parse(ast.path, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + this.asterisk, + path.call(print, 'alias'), + ` ${this.fromKeyword} `, + path.call(print, 'path') + ]; + } +} diff --git a/src/slang-nodes/NewExpression.js b/src/slang-nodes/NewExpression.js index a88dd6473..071303288 100644 --- a/src/slang-nodes/NewExpression.js +++ b/src/slang-nodes/NewExpression.js @@ -1,10 +1,18 @@ -export const NewExpression = { - parse: ({ offsets, ast, options, parse }) => ({ - newKeyword: ast.newKeyword.text, - typeName: parse(ast.typeName, options, parse, offsets) - }), - print: ({ node, path, print }) => [ - `${node.newKeyword} `, - path.call(print, 'typeName') - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class NewExpression extends SlangNode { + newKeyword; + + typeName; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.newKeyword = ast.newKeyword.text; + this.typeName = parse(ast.typeName, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return [`${this.newKeyword} `, path.call(print, 'typeName')]; + } +} diff --git a/src/slang-nodes/NumberUnit.js b/src/slang-nodes/NumberUnit.js index 7b57c2db0..36c6819a3 100644 --- a/src/slang-nodes/NumberUnit.js +++ b/src/slang-nodes/NumberUnit.js @@ -1,6 +1,15 @@ -export const NumberUnit = { - parse: ({ ast }) => ({ - variant: ast.variant.text - }), - print: ({ node }) => node.variant -}; +import { SlangNode } from './SlangNode.js'; + +export class NumberUnit extends SlangNode { + variant; + + constructor({ ast, offset }) { + super(ast, offset); + this.variant = ast.variant.text; + this.initiateLoc(ast); + } + + print() { + return this.variant; + } +} diff --git a/src/slang-nodes/OrExpression.js b/src/slang-nodes/OrExpression.js index a3e7cb317..810fb7704 100644 --- a/src/slang-nodes/OrExpression.js +++ b/src/slang-nodes/OrExpression.js @@ -1,15 +1,29 @@ -import { - logicalOperationPrint, - createHugFunction -} from '../common/slang-helpers.js'; +import { logicalOperationPrint } from '../common/slang-helpers.js'; +import { createHugFunction } from '../slang-utils/create-hug-function.js'; +import { SlangNode } from './SlangNode.js'; const tryToHug = createHugFunction(['&&']); -export const OrExpression = { - parse: ({ offsets, ast, options, parse }) => ({ - leftOperand: tryToHug(parse(ast.leftOperand, options, parse, offsets)), - operator: ast.operator.text, - rightOperand: tryToHug(parse(ast.rightOperand, options, parse, offsets)) - }), - print: logicalOperationPrint -}; +export class OrExpression extends SlangNode { + leftOperand; + + operator; + + rightOperand; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.leftOperand = tryToHug( + parse(ast.leftOperand, parse, this.nextChildOffset) + ); + this.operator = ast.operator.text; + this.rightOperand = tryToHug( + parse(ast.rightOperand, parse, this.nextChildOffset) + ); + this.initiateLoc(ast); + } + + print({ path, print, options }) { + return logicalOperationPrint({ node: this, path, print, options }); + } +} diff --git a/src/slang-nodes/OverridePaths.js b/src/slang-nodes/OverridePaths.js index e5aa2a4f8..7f847a5a7 100644 --- a/src/slang-nodes/OverridePaths.js +++ b/src/slang-nodes/OverridePaths.js @@ -1,8 +1,21 @@ -export const OverridePaths = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)), - separators: ast.separators.map((separator) => separator) - }), +import { SlangNode } from './SlangNode.js'; + +export class OverridePaths extends SlangNode { + items; + + separators; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items.map((item) => + parse(item, parse, this.nextChildOffset) + ); + this.separators = ast.separators.map((separator) => separator); + this.initiateLoc(ast); + } + // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: OverridePaths'] -}; + print({ path, print, options }) { + return ['TODO: OverridePaths']; + } +} diff --git a/src/slang-nodes/OverridePathsDeclaration.js b/src/slang-nodes/OverridePathsDeclaration.js index d10e018a1..8622d4530 100644 --- a/src/slang-nodes/OverridePathsDeclaration.js +++ b/src/slang-nodes/OverridePathsDeclaration.js @@ -1,9 +1,22 @@ -export const OverridePathsDeclaration = { - parse: ({ offsets, ast, options, parse }) => ({ - openParen: ast.openParen.text, - paths: parse(ast.paths, options, parse, offsets), - closeParen: ast.closeParen.text - }), +import { SlangNode } from './SlangNode.js'; + +export class OverridePathsDeclaration extends SlangNode { + openParen; + + paths; + + closeParen; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.openParen = ast.openParen.text; + this.paths = parse(ast.paths, parse, this.nextChildOffset); + this.closeParen = ast.closeParen.text; + this.initiateLoc(ast); + } + // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: OverridePathsDeclaration'] -}; + print({ path, print, options }) { + return ['TODO: OverridePathsDeclaration']; + } +} diff --git a/src/slang-nodes/OverrideSpecifier.js b/src/slang-nodes/OverrideSpecifier.js index 8162267e7..f2bcc9ed4 100644 --- a/src/slang-nodes/OverrideSpecifier.js +++ b/src/slang-nodes/OverrideSpecifier.js @@ -1,12 +1,23 @@ -export const OverrideSpecifier = { - parse: ({ offsets, ast, options, parse }) => ({ - overrideKeyword: ast.overrideKeyword.text, - overridden: ast.overridden - ? parse(ast.overridden, options, parse, offsets) - : undefined - }), - print: ({ node, path, print }) => [ - node.overrideKeyword, - node.overridden ? path.call(print, 'overridden') : '' - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class OverrideSpecifier extends SlangNode { + overrideKeyword; + + overridden; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.overrideKeyword = ast.overrideKeyword.text; + this.overridden = ast.overridden + ? parse(ast.overridden, parse, this.nextChildOffset) + : undefined; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + this.overrideKeyword, + this.overridden ? path.call(print, 'overridden') : '' + ]; + } +} diff --git a/src/slang-nodes/Parameter.js b/src/slang-nodes/Parameter.js index 7c91109c6..6d9a1453d 100644 --- a/src/slang-nodes/Parameter.js +++ b/src/slang-nodes/Parameter.js @@ -1,19 +1,30 @@ import { doc } from 'prettier'; +import { SlangNode } from './SlangNode.js'; const { group } = doc.builders; -export const Parameter = { - parse: ({ offsets, ast, options, parse }) => ({ - typeName: parse(ast.typeName, options, parse, offsets), - storageLocation: ast.storageLocation - ? parse(ast.storageLocation, options, parse, offsets) - : undefined, - name: ast.name?.text - }), - print: ({ node, path, print }) => - group([ +export class Parameter extends SlangNode { + typeName; + + storageLocation; + + name; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.typeName = parse(ast.typeName, parse, this.nextChildOffset); + this.storageLocation = ast.storageLocation + ? parse(ast.storageLocation, parse, this.nextChildOffset) + : undefined; + this.name = ast.name?.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return group([ path.call(print, 'typeName'), - node.storageLocation ? ` ${path.call(print, 'storageLocation')}` : '', - node.name ? ` ${node.name}` : '' - ]) -}; + this.storageLocation ? ` ${path.call(print, 'storageLocation')}` : '', + this.name ? ` ${this.name}` : '' + ]); + } +} diff --git a/src/slang-nodes/Parameters.js b/src/slang-nodes/Parameters.js index 23c23ea8e..31abac212 100644 --- a/src/slang-nodes/Parameters.js +++ b/src/slang-nodes/Parameters.js @@ -1,12 +1,40 @@ -import { printSeparatedList } from '../common/printer-helpers.js'; - -export const Parameters = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)), - separators: ast.separators.map((separator) => separator.text) - }), - print: ({ node, path, print }) => - node.items.length > 0 - ? printSeparatedList(path.map(print, 'items'), { grouped: false }) - : '' -}; +import { + printSeparatedItem, + printSeparatedList +} from '../common/printer-helpers.js'; +import { printComments } from '../common/slang-helpers.js'; +import { SlangNode } from './SlangNode.js'; + +export class Parameters extends SlangNode { + items; + + separators; + + constructor({ ast, parse, offset, kind, loc, items, separators }) { + super(ast, offset); + if (ast) { + this.items = ast.items.map((item) => + parse(item, parse, this.nextChildOffset) + ); + this.separators = ast.separators.map((separator) => separator.text); + this.initiateLoc(ast); + } else { + this.kind = kind; + this.loc = loc; + this.items = items; + this.separators = separators; + } + } + + print({ path, print, options }) { + if (this.items.length > 0) { + return printSeparatedList(path.map(print, 'items'), { grouped: false }); + } + + const parameterComments = printComments(this, path, options); + + return parameterComments.length > 0 + ? printSeparatedItem(parameterComments) + : ''; + } +} diff --git a/src/slang-nodes/ParametersDeclaration.js b/src/slang-nodes/ParametersDeclaration.js index fa070f72c..c31bec0a6 100644 --- a/src/slang-nodes/ParametersDeclaration.js +++ b/src/slang-nodes/ParametersDeclaration.js @@ -1,12 +1,38 @@ -export const ParametersDeclaration = { - parse: ({ offsets, ast, options, parse }) => ({ - openParen: ast.openParen.text, - parameters: parse(ast.parameters, options, parse, offsets), - closeParen: ast.closeParen.text - }), - print: ({ node, path, print }) => [ - node.openParen, - path.call(print, 'parameters'), - node.closeParen - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class ParametersDeclaration extends SlangNode { + openParen; + + parameters; + + closeParen; + + constructor({ + ast, + parse, + offset, + kind, + loc, + openParen, + parameters, + closeParen + }) { + super(ast, offset); + if (ast) { + this.openParen = ast.openParen.text; + this.parameters = parse(ast.parameters, parse, this.nextChildOffset); + this.closeParen = ast.closeParen.text; + this.initiateLoc(ast); + } else { + this.kind = kind; + this.loc = loc; + this.openParen = openParen; + this.parameters = parameters; + this.closeParen = closeParen; + } + } + + print({ path, print }) { + return [this.openParen, path.call(print, 'parameters'), this.closeParen]; + } +} diff --git a/src/slang-nodes/PathImport.js b/src/slang-nodes/PathImport.js index ca781af99..01cf12faa 100644 --- a/src/slang-nodes/PathImport.js +++ b/src/slang-nodes/PathImport.js @@ -1,10 +1,23 @@ -export const PathImport = { - parse: ({ offsets, ast, options, parse }) => ({ - path: parse(ast.path, options, parse, offsets), - alias: ast.alias ? parse(ast.alias, options, parse, offsets) : undefined - }), - print: ({ node, path, print }) => [ - path.call(print, 'path'), - node.alias ? path.call(print, 'alias') : '' - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class PathImport extends SlangNode { + path; + + alias; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.path = parse(ast.path, parse, this.nextChildOffset); + this.alias = ast.alias + ? parse(ast.alias, parse, this.nextChildOffset) + : undefined; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + path.call(print, 'path'), + this.alias ? path.call(print, 'alias') : '' + ]; + } +} diff --git a/src/slang-nodes/PositionalArguments.js b/src/slang-nodes/PositionalArguments.js index f4ff4b2cd..f3a6a44ed 100644 --- a/src/slang-nodes/PositionalArguments.js +++ b/src/slang-nodes/PositionalArguments.js @@ -1,10 +1,23 @@ import { printSeparatedList } from '../common/printer-helpers.js'; +import { SlangNode } from './SlangNode.js'; -export const PositionalArguments = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)), - separators: ast.separators.map((separator) => separator.text) - }), - print: ({ node, path, print }) => - node.items.length > 0 ? printSeparatedList(path.map(print, 'items')) : '' -}; +export class PositionalArguments extends SlangNode { + items; + + separators; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items.map((item) => + parse(item, parse, this.nextChildOffset) + ); + this.separators = ast.separators.map((separator) => separator.text); + this.initiateLoc(ast); + } + + print({ path, print }) { + return this.items.length > 0 + ? printSeparatedList(path.map(print, 'items')) + : ''; + } +} diff --git a/src/slang-nodes/PositionalArgumentsDeclaration.js b/src/slang-nodes/PositionalArgumentsDeclaration.js index 24f0cfeb6..6f877ea31 100644 --- a/src/slang-nodes/PositionalArgumentsDeclaration.js +++ b/src/slang-nodes/PositionalArgumentsDeclaration.js @@ -1,12 +1,21 @@ -export const PositionalArgumentsDeclaration = { - parse: ({ offsets, ast, options, parse }) => ({ - openParen: ast.openParen.text, - arguments: parse(ast.arguments, options, parse, offsets), - closeParen: ast.closeParen.text - }), - print: ({ node, path, print }) => [ - node.openParen, - path.call(print, 'arguments'), - node.closeParen - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class PositionalArgumentsDeclaration extends SlangNode { + openParen; + + arguments; + + closeParen; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.openParen = ast.openParen.text; + this.arguments = parse(ast.arguments, parse, this.nextChildOffset); + this.closeParen = ast.closeParen.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [this.openParen, path.call(print, 'arguments'), this.closeParen]; + } +} diff --git a/src/slang-nodes/PostfixExpression.js b/src/slang-nodes/PostfixExpression.js index 6d4202e2a..e10c88c30 100644 --- a/src/slang-nodes/PostfixExpression.js +++ b/src/slang-nodes/PostfixExpression.js @@ -1,7 +1,18 @@ -export const PostfixExpression = { - parse: ({ offsets, ast, options, parse }) => ({ - operand: parse(ast.operand, options, parse, offsets), - operator: ast.operator.text - }), - print: ({ node, path, print }) => [path.call(print, 'operand'), node.operator] -}; +import { SlangNode } from './SlangNode.js'; + +export class PostfixExpression extends SlangNode { + operand; + + operator; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.operand = parse(ast.operand, parse, this.nextChildOffset); + this.operator = ast.operator.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [path.call(print, 'operand'), this.operator]; + } +} diff --git a/src/slang-nodes/Pragma.js b/src/slang-nodes/Pragma.js index 4dd057d81..1b9a5c2b6 100644 --- a/src/slang-nodes/Pragma.js +++ b/src/slang-nodes/Pragma.js @@ -1,6 +1,24 @@ -export const Pragma = { - parse: ({ offsets, ast, options, parse }) => ({ - variant: parse(ast.variant, options, parse, offsets) - }), - print: ({ path, print }) => path.call(print, 'variant') -}; +import { SlangNode } from './SlangNode.js'; +import { ABICoderPragma } from './ABICoderPragma.js'; +import { ExperimentalPragma } from './ExperimentalPragma.js'; +import { VersionPragma } from './VersionPragma.js'; + +const variants = { ABICoderPragma, ExperimentalPragma, VersionPragma }; + +export class Pragma extends SlangNode { + variant; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.variant = new variants[ast.variant.cst.kind]({ + ast: ast.variant, + parse, + offset: this.nextChildOffset + }); + this.initiateLoc(ast); + } + + print({ path, print }) { + return path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/PragmaDirective.js b/src/slang-nodes/PragmaDirective.js index 9abcd1a6b..84d111eb4 100644 --- a/src/slang-nodes/PragmaDirective.js +++ b/src/slang-nodes/PragmaDirective.js @@ -1,12 +1,31 @@ -export const PragmaDirective = { - parse: ({ offsets, ast, options, parse }) => ({ - pragmaKeyword: ast.pragmaKeyword.text, - pragma: parse(ast.pragma, options, parse, offsets), - semicolon: ast.semicolon.text - }), - print: ({ node, path, print }) => [ - `${node.pragmaKeyword} `, - path.call(print, 'pragma'), - node.semicolon - ] -}; +import { SlangNode } from './SlangNode.js'; +import { Pragma } from './Pragma.js'; + +export class PragmaDirective extends SlangNode { + pragmaKeyword; + + pragma; + + semicolon; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.pragmaKeyword = ast.pragmaKeyword.text; + this.pragma = new Pragma({ + ast: ast.pragma, + parse, + offset: this.nextChildOffset, + options + }); + this.semicolon = ast.semicolon.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + `${this.pragmaKeyword} `, + path.call(print, 'pragma'), + this.semicolon + ]; + } +} diff --git a/src/slang-nodes/PrefixExpression.js b/src/slang-nodes/PrefixExpression.js index 435c78f42..121c22845 100644 --- a/src/slang-nodes/PrefixExpression.js +++ b/src/slang-nodes/PrefixExpression.js @@ -1,7 +1,18 @@ -export const PrefixExpression = { - parse: ({ offsets, ast, options, parse }) => ({ - operator: ast.operator.text, - operand: parse(ast.operand, options, parse, offsets) - }), - print: ({ node, path, print }) => [node.operator, path.call(print, 'operand')] -}; +import { SlangNode } from './SlangNode.js'; + +export class PrefixExpression extends SlangNode { + operator; + + operand; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.operator = ast.operator.text; + this.operand = parse(ast.operand, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return [this.operator, path.call(print, 'operand')]; + } +} diff --git a/src/slang-nodes/ReceiveFunctionAttribute.js b/src/slang-nodes/ReceiveFunctionAttribute.js index 061fa8bb7..43b072fa1 100644 --- a/src/slang-nodes/ReceiveFunctionAttribute.js +++ b/src/slang-nodes/ReceiveFunctionAttribute.js @@ -1,12 +1,20 @@ -export const ReceiveFunctionAttribute = { - parse: ({ offsets, ast, options, parse }) => ({ - variant: +import { SlangNode } from './SlangNode.js'; + +export class ReceiveFunctionAttribute extends SlangNode { + variant; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, options, parse, offsets) - }), - print: ({ node, path, print }) => - typeof node.variant === 'string' - ? node.variant - : path.call(print, 'variant') -}; + : parse(ast.variant, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/ReceiveFunctionAttributes.js b/src/slang-nodes/ReceiveFunctionAttributes.js index cfe1293e0..e36270483 100644 --- a/src/slang-nodes/ReceiveFunctionAttributes.js +++ b/src/slang-nodes/ReceiveFunctionAttributes.js @@ -1,14 +1,21 @@ import { doc } from 'prettier'; import { sortFunctionAttributes } from '../common/slang-helpers.js'; +import { SlangNode } from './SlangNode.js'; const { line } = doc.builders; -export const ReceiveFunctionAttributes = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items - .map((item) => parse(item, options, parse, offsets)) - .sort(sortFunctionAttributes) - }), - print: ({ path, print }) => - path.map(print, 'items').map((item) => [line, item]) -}; +export class ReceiveFunctionAttributes extends SlangNode { + items; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items + .map((item) => parse(item, parse, this.nextChildOffset)) + .sort(sortFunctionAttributes); + this.initiateLoc(ast); + } + + print({ path, print }) { + return path.map(print, 'items').map((item) => [line, item]); + } +} diff --git a/src/slang-nodes/ReceiveFunctionDefinition.js b/src/slang-nodes/ReceiveFunctionDefinition.js index 009f8b137..d47745082 100644 --- a/src/slang-nodes/ReceiveFunctionDefinition.js +++ b/src/slang-nodes/ReceiveFunctionDefinition.js @@ -1,12 +1,25 @@ import { printFunction } from '../common/slang-helpers.js'; +import { SlangNode } from './SlangNode.js'; -export const ReceiveFunctionDefinition = { - parse: ({ offsets, ast, options, parse }) => ({ - receiveKeyword: ast.receiveKeyword.text, - parameters: parse(ast.parameters, options, parse, offsets), - attributes: parse(ast.attributes, options, parse, offsets), - body: parse(ast.body, options, parse, offsets) - }), - print: ({ node, path, print }) => - printFunction(node.receiveKeyword, node, path, print) -}; +export class ReceiveFunctionDefinition extends SlangNode { + receiveKeyword; + + parameters; + + attributes; + + body; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.receiveKeyword = ast.receiveKeyword.text; + this.parameters = parse(ast.parameters, parse, this.nextChildOffset); + this.attributes = parse(ast.attributes, parse, this.nextChildOffset); + this.body = parse(ast.body, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return printFunction(this.receiveKeyword, this, path, print); + } +} diff --git a/src/slang-nodes/ReturnStatement.js b/src/slang-nodes/ReturnStatement.js index f5c212963..cffc37945 100644 --- a/src/slang-nodes/ReturnStatement.js +++ b/src/slang-nodes/ReturnStatement.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { SlangNode } from './SlangNode.js'; const { group, indent, line } = doc.builders; @@ -13,17 +14,28 @@ const expression = (node, path, print, options) => { return ''; }; -export const ReturnStatement = { - parse: ({ offsets, ast, options, parse }) => ({ - returnKeyword: ast.returnKeyword.text, - expression: ast.expression - ? parse(ast.expression, options, parse, offsets) - : undefined, - semicolon: ast.semicolon.text - }), - print: ({ node, path, print, options }) => [ - node.returnKeyword, - expression(node, path, print, options), - node.semicolon - ] -}; +export class ReturnStatement extends SlangNode { + returnKeyword; + + expression; + + semicolon; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.returnKeyword = ast.returnKeyword.text; + this.expression = ast.expression + ? parse(ast.expression, parse, this.nextChildOffset) + : undefined; + this.semicolon = ast.semicolon.text; + this.initiateLoc(ast); + } + + print({ path, print, options }) { + return [ + this.returnKeyword, + expression(this, path, print, options), + this.semicolon + ]; + } +} diff --git a/src/slang-nodes/ReturnsDeclaration.js b/src/slang-nodes/ReturnsDeclaration.js index 1874cd761..f03f38a14 100644 --- a/src/slang-nodes/ReturnsDeclaration.js +++ b/src/slang-nodes/ReturnsDeclaration.js @@ -1,14 +1,21 @@ import { doc } from 'prettier'; +import { SlangNode } from './SlangNode.js'; const { group } = doc.builders; -export const ReturnsDeclaration = { - parse: ({ offsets, ast, options, parse }) => ({ - returnsKeyword: ast.returnsKeyword.text, - variables: parse(ast.variables, options, parse, offsets) - }), - print: ({ node, path, print }) => [ - `${node.returnsKeyword} `, - group(path.call(print, 'variables')) - ] -}; +export class ReturnsDeclaration extends SlangNode { + returnsKeyword; + + variables; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.returnsKeyword = ast.returnsKeyword.text; + this.variables = parse(ast.variables, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return [`${this.returnsKeyword} `, group(path.call(print, 'variables'))]; + } +} diff --git a/src/slang-nodes/RevertStatement.js b/src/slang-nodes/RevertStatement.js index e8677fe3e..4d1b17c57 100644 --- a/src/slang-nodes/RevertStatement.js +++ b/src/slang-nodes/RevertStatement.js @@ -1,14 +1,31 @@ -export const RevertStatement = { - parse: ({ offsets, ast, options, parse }) => ({ - revertKeyword: ast.revertKeyword.text, - error: ast.error ? parse(ast.error, options, parse, offsets) : undefined, - arguments: parse(ast.arguments, options, parse, offsets), - semicolon: ast.semicolon.text - }), - print: ({ node, path, print }) => [ - `${node.revertKeyword} `, - node.error ? path.call(print, 'error') : '', - path.call(print, 'arguments'), - node.semicolon - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class RevertStatement extends SlangNode { + revertKeyword; + + error; + + arguments; + + semicolon; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.revertKeyword = ast.revertKeyword.text; + this.error = ast.error + ? parse(ast.error, parse, this.nextChildOffset) + : undefined; + this.arguments = parse(ast.arguments, parse, this.nextChildOffset); + this.semicolon = ast.semicolon.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + `${this.revertKeyword} `, + this.error ? path.call(print, 'error') : '', + path.call(print, 'arguments'), + this.semicolon + ]; + } +} diff --git a/src/slang-nodes/ShiftExpression.js b/src/slang-nodes/ShiftExpression.js index 49beb3362..b4b4b0abc 100644 --- a/src/slang-nodes/ShiftExpression.js +++ b/src/slang-nodes/ShiftExpression.js @@ -1,7 +1,6 @@ -import { - binaryOperationPrint, - createHugFunction -} from '../common/slang-helpers.js'; +import { binaryOperationPrint } from '../common/slang-helpers.js'; +import { createHugFunction } from '../slang-utils/create-hug-function.js'; +import { SlangNode } from './SlangNode.js'; const tryToHugLeftOperand = createHugFunction([ '+', @@ -14,15 +13,26 @@ const tryToHugLeftOperand = createHugFunction([ ]); const tryToHugRightOperand = createHugFunction(['+', '-', '*', '/', '**']); -export const ShiftExpression = { - parse: ({ offsets, ast, options, parse }) => ({ - leftOperand: tryToHugLeftOperand( - parse(ast.leftOperand, options, parse, offsets) - ), - operator: ast.operator.text, - rightOperand: tryToHugRightOperand( - parse(ast.rightOperand, options, parse, offsets) - ) - }), - print: binaryOperationPrint -}; +export class ShiftExpression extends SlangNode { + leftOperand; + + operator; + + rightOperand; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.leftOperand = tryToHugLeftOperand( + parse(ast.leftOperand, parse, this.nextChildOffset) + ); + this.operator = ast.operator.text; + this.rightOperand = tryToHugRightOperand( + parse(ast.rightOperand, parse, this.nextChildOffset) + ); + this.initiateLoc(ast); + } + + print({ path, print, options }) { + return binaryOperationPrint({ node: this, path, print, options }); + } +} diff --git a/src/slang-nodes/SlangNode.js b/src/slang-nodes/SlangNode.js new file mode 100644 index 000000000..b296b0cb1 --- /dev/null +++ b/src/slang-nodes/SlangNode.js @@ -0,0 +1,139 @@ +import { isComment } from '../common/slang-helpers.js'; + +const comments = []; + +function getOffsets(children, initialOffset) { + let offset = initialOffset; + + const offsets = children.reduce((offsetsArray, child) => { + if (child.type === 'Nonterminal') { + offsetsArray.push(offset); + } + if (child.type === 'Terminal' && isComment(child)) { + // Since the fetching the comments and calculating offsets are both done + // as we iterate over the children and the comment also depends on the + // offset, it's hard to separate these responsibilities into different + // functions. + comments.push({ + kind: child.kind, + value: child.text, + loc: { + start: offset, + end: offset + child.textLength.utf8 + } + }); + } + + offset += child.textLength.utf8; + return offsetsArray; + }, []); + return offsets; +} + +const getLeadingOffset = (children) => { + let offset = 0; + for (let i = 0; i < children.length; i += 1) { + const child = children[i]; + if (child.type === 'Nonterminal') { + // The node's content starts when we find the first non-terminal, + // non-comment, non-whitespace token. + return offset; + } + if ( + child.type === 'Terminal' && + !isComment(child) && + child.kind !== 'EndOfLine' && + child.kind !== 'Whitespace' + ) { + // The content of the node started if we find a non-comment, + // non-whitespace token. + return offset; + } + offset += child.textLength.utf8; + } + return offset; +}; + +const getTrailingOffset = (children) => getLeadingOffset(children.reverse()); + +export class SlangNode { + kind; + + loc = { + childrenOffsets: [], + startWithTrivia: 0, + start: 0, + endWithTrivia: 0, + end: 0 + }; + + comments = []; + + constructor(ast, offset) { + if (!ast) return; + const children = ast.cst.children(); + this.kind = ast.cst.kind; + this.loc.childrenOffsets = getOffsets(children, offset); + this.loc.startWithTrivia = offset; + this.loc.endWithTrivia = offset + ast.cst.textLength.utf8; + } + + /** + * Leading and trailing Comments are considered by the parser as part of the + * innermost possible node. For example if there is a comment just before a + * variable assignment, the parser will consider the comment belongs to the + * variable name instead of the whole statement. + * + * This behaviour creates erratic outcomes when the new line of a + * SingleLineComment can trigger a group break or a prettier-ignore will + * apply to a subset of the intended nodes. + * + * ```Solidity + * // prettier-ignore + * matrix = [ + * 0, 1, 2, + * 3, 4, 5, + * 6, 7, 8 + * ]; + * ``` + */ + initiateLoc(ast) { + const children = ast.cst.children(); + let leadingOffset = getLeadingOffset(children); + let trailingOffset = getTrailingOffset(children); + + if (leadingOffset === 0 || trailingOffset === 0) { + const childrenKeys = Object.keys(this); + + for (let i = 0; i < childrenKeys.length; i += 1) { + const childLoc = this[childrenKeys[i]]?.loc; + + if (childLoc) { + if ( + leadingOffset === 0 && + childLoc.startWithTrivia === this.loc.startWithTrivia + ) { + leadingOffset = childLoc.start - childLoc.startWithTrivia; + } + + if ( + trailingOffset === 0 && + childLoc.endWithTrivia === this.loc.endWithTrivia + ) { + trailingOffset = childLoc.endWithTrivia - childLoc.end; + } + } + } + } + this.loc.start = this.loc.startWithTrivia + leadingOffset; + this.loc.end = this.loc.endWithTrivia - trailingOffset; + } + + get nextChildOffset() { + return this.loc.childrenOffsets.shift(); + } + + collectComments() { + this.comments = comments.splice(0); + } +} diff --git a/src/slang-nodes/SourceUnit.js b/src/slang-nodes/SourceUnit.js index 5564aa668..755ce3909 100644 --- a/src/slang-nodes/SourceUnit.js +++ b/src/slang-nodes/SourceUnit.js @@ -1,13 +1,24 @@ import { doc } from 'prettier'; +import { SlangNode } from './SlangNode.js'; +import { SourceUnitMembers } from './SourceUnitMembers.js'; const { line } = doc.builders; -export const SourceUnit = { - parse: ({ offsets, ast, options, parse }) => ({ - members: parse(ast.members, options, parse, offsets) - }), - print: ({ options, path, print }) => [ - path.call(print, 'members'), - options.parentParser ? '' : line - ] -}; +export class SourceUnit extends SlangNode { + members; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.members = new SourceUnitMembers({ + ast: ast.members, + parse, + offset: this.nextChildOffset, + options + }); + this.initiateLoc(ast); + } + + print({ options, path, print }) { + return [path.call(print, 'members'), options.parentParser ? '' : line]; + } +} diff --git a/src/slang-nodes/SourceUnitMember.js b/src/slang-nodes/SourceUnitMember.js index 6fc6afa65..f8edd4538 100644 --- a/src/slang-nodes/SourceUnitMember.js +++ b/src/slang-nodes/SourceUnitMember.js @@ -1,6 +1,49 @@ -export const SourceUnitMember = { - parse: ({ offsets, ast, options, parse }) => ({ - variant: parse(ast.variant, options, parse, offsets) - }), - print: ({ path, print }) => path.call(print, 'variant') +import { SlangNode } from './SlangNode.js'; +import { PragmaDirective } from './PragmaDirective.js'; +import { ImportDirective } from './ImportDirective.js'; +import { ContractDefinition } from './ContractDefinition.js'; +import { InterfaceDefinition } from './InterfaceDefinition.js'; +import { LibraryDefinition } from './LibraryDefinition.js'; +import { StructDefinition } from './StructDefinition.js'; +import { EnumDefinition } from './EnumDefinition.js'; +import { FunctionDefinition } from './FunctionDefinition.js'; +import { ConstantDefinition } from './ConstantDefinition.js'; +import { ErrorDefinition } from './ErrorDefinition.js'; +import { UserDefinedValueTypeDefinition } from './UserDefinedValueTypeDefinition.js'; +import { UsingDirective } from './UsingDirective.js'; +import { EventDefinition } from './EventDefinition.js'; + +const variants = { + PragmaDirective, + ImportDirective, + ContractDefinition, + InterfaceDefinition, + LibraryDefinition, + StructDefinition, + EnumDefinition, + FunctionDefinition, + ConstantDefinition, + ErrorDefinition, + UserDefinedValueTypeDefinition, + UsingDirective, + EventDefinition }; + +export class SourceUnitMember extends SlangNode { + variant; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.variant = new variants[ast.variant.cst.kind]({ + ast: ast.variant, + parse, + offset: this.nextChildOffset, + options + }); + this.initiateLoc(ast); + } + + print({ path, print }) { + return path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/SourceUnitMembers.js b/src/slang-nodes/SourceUnitMembers.js index a66df95f7..406f50a16 100644 --- a/src/slang-nodes/SourceUnitMembers.js +++ b/src/slang-nodes/SourceUnitMembers.js @@ -1,9 +1,25 @@ import { printPreservingEmptyLines } from '../common/slang-helpers.js'; +import { SlangNode } from './SlangNode.js'; +import { SourceUnitMember } from './SourceUnitMember.js'; -export const SourceUnitMembers = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)) - }), - print: ({ path, options, print }) => - printPreservingEmptyLines(path, 'items', options, print) -}; +export class SourceUnitMembers extends SlangNode { + items; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items.map( + (item) => + new SourceUnitMember({ + ast: item, + parse, + offset: this.nextChildOffset, + options + }) + ); + this.initiateLoc(ast); + } + + print({ path, options, print }) { + return printPreservingEmptyLines(path, 'items', options, print); + } +} diff --git a/src/slang-nodes/StateVariableAttribute.js b/src/slang-nodes/StateVariableAttribute.js index d09c6e1ac..cf1319ffe 100644 --- a/src/slang-nodes/StateVariableAttribute.js +++ b/src/slang-nodes/StateVariableAttribute.js @@ -1,12 +1,20 @@ -export const StateVariableAttribute = { - parse: ({ offsets, ast, options, parse }) => ({ - variant: +import { SlangNode } from './SlangNode.js'; + +export class StateVariableAttribute extends SlangNode { + variant; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, options, parse, offsets) - }), - print: ({ node, path, print }) => - typeof node.variant === 'string' - ? node.variant - : path.call(print, 'variant') -}; + : parse(ast.variant, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/StateVariableAttributes.js b/src/slang-nodes/StateVariableAttributes.js index 6520f31d5..ef1d99019 100644 --- a/src/slang-nodes/StateVariableAttributes.js +++ b/src/slang-nodes/StateVariableAttributes.js @@ -1,7 +1,19 @@ -export const StateVariableAttributes = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)) - }), - print: ({ node, path, print }) => - node.items.length ? path.map(print, 'items').map((item) => [' ', item]) : '' -}; +import { SlangNode } from './SlangNode.js'; + +export class StateVariableAttributes extends SlangNode { + items; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items.map((item) => + parse(item, parse, this.nextChildOffset) + ); + this.initiateLoc(ast); + } + + print({ path, print }) { + return this.items.length + ? path.map(print, 'items').map((item) => [' ', item]) + : ''; + } +} diff --git a/src/slang-nodes/StateVariableDefinition.js b/src/slang-nodes/StateVariableDefinition.js index 2c42598de..2cfa81297 100644 --- a/src/slang-nodes/StateVariableDefinition.js +++ b/src/slang-nodes/StateVariableDefinition.js @@ -1,16 +1,35 @@ -export const StateVariableDefinition = { - parse: ({ offsets, ast, options, parse }) => ({ - typeName: parse(ast.typeName, options, parse, offsets), - attributes: parse(ast.attributes, options, parse, offsets), - name: ast.name.text, - value: ast.value ? parse(ast.value, options, parse, offsets) : undefined, - semicolon: ast.semicolon.text - }), - print: ({ node, path, print }) => [ - path.call(print, 'typeName'), - path.call(print, 'attributes'), - ` ${node.name}`, - node.value ? path.call(print, 'value') : '', - node.semicolon - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class StateVariableDefinition extends SlangNode { + typeName; + + attributes; + + name; + + value; + + semicolon; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.typeName = parse(ast.typeName, parse, this.nextChildOffset); + this.attributes = parse(ast.attributes, parse, this.nextChildOffset); + this.name = ast.name.text; + this.value = ast.value + ? parse(ast.value, parse, this.nextChildOffset) + : undefined; + this.semicolon = ast.semicolon.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + path.call(print, 'typeName'), + path.call(print, 'attributes'), + ` ${this.name}`, + this.value ? path.call(print, 'value') : '', + this.semicolon + ]; + } +} diff --git a/src/slang-nodes/StateVariableDefinitionValue.js b/src/slang-nodes/StateVariableDefinitionValue.js index 53197daea..15fb44bbf 100644 --- a/src/slang-nodes/StateVariableDefinitionValue.js +++ b/src/slang-nodes/StateVariableDefinitionValue.js @@ -1,14 +1,23 @@ import { doc } from 'prettier'; +import { SlangNode } from './SlangNode.js'; const { group, indent, line } = doc.builders; -export const StateVariableDefinitionValue = { - parse: ({ offsets, ast, options, parse }) => ({ - equal: ast.equal.text, - value: parse(ast.value, options, parse, offsets) - }), - print: ({ node, path, print }) => - node.value.variant.kind === 'ArrayExpression' - ? [` ${node.equal} `, path.call(print, 'value')] - : group([` ${node.equal}`, indent([line, path.call(print, 'value')])]) -}; +export class StateVariableDefinitionValue extends SlangNode { + equal; + + value; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.equal = ast.equal.text; + this.value = parse(ast.value, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return this.value.variant.kind === 'ArrayExpression' + ? [` ${this.equal} `, path.call(print, 'value')] + : group([` ${this.equal}`, indent([line, path.call(print, 'value')])]); + } +} diff --git a/src/slang-nodes/Statement.js b/src/slang-nodes/Statement.js index 837527df7..0085d3b4e 100644 --- a/src/slang-nodes/Statement.js +++ b/src/slang-nodes/Statement.js @@ -1,6 +1,15 @@ -export const Statement = { - parse: ({ offsets, ast, options, parse }) => ({ - variant: parse(ast.variant, options, parse, offsets) - }), - print: ({ path, print }) => path.call(print, 'variant') -}; +import { SlangNode } from './SlangNode.js'; + +export class Statement extends SlangNode { + variant; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.variant = parse(ast.variant, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/Statements.js b/src/slang-nodes/Statements.js index 12548a9b2..8766b4cbb 100644 --- a/src/slang-nodes/Statements.js +++ b/src/slang-nodes/Statements.js @@ -4,24 +4,34 @@ import { printComments, printPreservingEmptyLines } from '../common/slang-helpers.js'; +import { SlangNode } from './SlangNode.js'; const { hardline } = doc.builders; -export const Statements = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)) - }), - print: ({ node, path, options, print }) => - node.items.length === 0 && (!node.comments || node.comments.length === 0) +export class Statements extends SlangNode { + items; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items.map((item) => + parse(item, parse, this.nextChildOffset) + ); + this.initiateLoc(ast); + } + + print({ path, options, print }) { + return this.items.length === 0 && + (!this.comments || this.comments.length === 0) ? '' : printSeparatedItem( [ printPreservingEmptyLines(path, 'items', options, print), - printComments(node, path, options) + printComments(this, path, options) ], { firstSeparator: hardline, grouped: false } - ) -}; + ); + } +} diff --git a/src/slang-nodes/StorageLocation.js b/src/slang-nodes/StorageLocation.js index 1f7e90481..a922891b7 100644 --- a/src/slang-nodes/StorageLocation.js +++ b/src/slang-nodes/StorageLocation.js @@ -1,6 +1,15 @@ -export const StorageLocation = { - parse: ({ ast }) => ({ - variant: ast.variant.text - }), - print: ({ node }) => node.variant -}; +import { SlangNode } from './SlangNode.js'; + +export class StorageLocation extends SlangNode { + variant; + + constructor({ ast, offset }) { + super(ast, offset); + this.variant = ast.variant.text; + this.initiateLoc(ast); + } + + print() { + return this.variant; + } +} diff --git a/src/slang-nodes/StringExpression.js b/src/slang-nodes/StringExpression.js index 73bb4023b..08cb7228a 100644 --- a/src/slang-nodes/StringExpression.js +++ b/src/slang-nodes/StringExpression.js @@ -1,6 +1,15 @@ -export const StringExpression = { - parse: ({ offsets, ast, options, parse }) => ({ - variant: parse(ast.variant, options, parse, offsets) - }), - print: ({ path, print }) => path.call(print, 'variant') -}; +import { SlangNode } from './SlangNode.js'; + +export class StringExpression extends SlangNode { + variant; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.variant = parse(ast.variant, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/StringLiteral.js b/src/slang-nodes/StringLiteral.js index ddd8896fd..b2727737f 100644 --- a/src/slang-nodes/StringLiteral.js +++ b/src/slang-nodes/StringLiteral.js @@ -1,8 +1,16 @@ import { printString } from '../common/util.js'; +import { SlangNode } from './SlangNode.js'; -export const StringLiteral = { - parse: ({ ast, options }) => ({ - variant: printString(ast.variant.text.slice(1, -1), options) - }), - print: ({ node }) => node.variant -}; +export class StringLiteral extends SlangNode { + variant; + + constructor({ ast, offset, options }) { + super(ast, offset); + this.variant = printString(ast.variant.text.slice(1, -1), options); + this.initiateLoc(ast); + } + + print() { + return this.variant; + } +} diff --git a/src/slang-nodes/StringLiterals.js b/src/slang-nodes/StringLiterals.js index df6ec7ea1..3e4d0da96 100644 --- a/src/slang-nodes/StringLiterals.js +++ b/src/slang-nodes/StringLiterals.js @@ -1,10 +1,20 @@ import { doc } from 'prettier'; +import { SlangNode } from './SlangNode.js'; const { join, hardline } = doc.builders; -export const StringLiterals = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)) - }), - print: ({ path, print }) => join(hardline, path.map(print, 'items')) -}; +export class StringLiterals extends SlangNode { + items; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items.map((item) => + parse(item, parse, this.nextChildOffset) + ); + this.initiateLoc(ast); + } + + print({ path, print }) { + return join(hardline, path.map(print, 'items')); + } +} diff --git a/src/slang-nodes/StructDefinition.js b/src/slang-nodes/StructDefinition.js index 04a0f5950..35927d4ec 100644 --- a/src/slang-nodes/StructDefinition.js +++ b/src/slang-nodes/StructDefinition.js @@ -1,14 +1,31 @@ -export const StructDefinition = { - parse: ({ offsets, ast, options, parse }) => ({ - structKeyword: ast.structKeyword.text, - name: ast.name.text, - openBrace: ast.openBrace.text, - members: parse(ast.members, options, parse, offsets), - closeBrace: ast.closeBrace.text - }), - print: ({ node, path, print }) => [ - `${node.structKeyword} ${node.name} ${node.openBrace}`, - path.call(print, 'members'), - node.closeBrace - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class StructDefinition extends SlangNode { + structKeyword; + + name; + + openBrace; + + members; + + closeBrace; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.structKeyword = ast.structKeyword.text; + this.name = ast.name.text; + this.openBrace = ast.openBrace.text; + this.members = parse(ast.members, parse, this.nextChildOffset); + this.closeBrace = ast.closeBrace.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + `${this.structKeyword} ${this.name} ${this.openBrace}`, + path.call(print, 'members'), + this.closeBrace + ]; + } +} diff --git a/src/slang-nodes/StructMember.js b/src/slang-nodes/StructMember.js index 09c6a576e..a8ccebd62 100644 --- a/src/slang-nodes/StructMember.js +++ b/src/slang-nodes/StructMember.js @@ -1,11 +1,21 @@ -export const StructMember = { - parse: ({ offsets, ast, options, parse }) => ({ - typeName: parse(ast.typeName, options, parse, offsets), - name: ast.name.text, - semicolon: ast.semicolon.text - }), - print: ({ node, path, print }) => [ - path.call(print, 'typeName'), - ` ${node.name}${node.semicolon}` - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class StructMember extends SlangNode { + typeName; + + name; + + semicolon; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.typeName = parse(ast.typeName, parse, this.nextChildOffset); + this.name = ast.name.text; + this.semicolon = ast.semicolon.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [path.call(print, 'typeName'), ` ${this.name}${this.semicolon}`]; + } +} diff --git a/src/slang-nodes/StructMembers.js b/src/slang-nodes/StructMembers.js index 233e1f3f1..c37b96ee4 100644 --- a/src/slang-nodes/StructMembers.js +++ b/src/slang-nodes/StructMembers.js @@ -1,17 +1,26 @@ import { doc } from 'prettier'; import { printSeparatedList } from '../common/printer-helpers.js'; +import { SlangNode } from './SlangNode.js'; const { hardline } = doc.builders; -export const StructMembers = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)) - }), - print: ({ node, path, print }) => - node.items.length > 0 +export class StructMembers extends SlangNode { + items; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items.map((item) => + parse(item, parse, this.nextChildOffset) + ); + this.initiateLoc(ast); + } + + print({ path, print }) { + return this.items.length > 0 ? printSeparatedList(path.map(print, 'items'), { firstSeparator: hardline, separator: hardline }) - : '' -}; + : ''; + } +} diff --git a/src/slang-nodes/ThrowStatement.js b/src/slang-nodes/ThrowStatement.js index e414091fd..9b4c31a53 100644 --- a/src/slang-nodes/ThrowStatement.js +++ b/src/slang-nodes/ThrowStatement.js @@ -1,8 +1,19 @@ -export const ThrowStatement = { - parse: ({ ast }) => ({ - throwKeyword: ast.throwKeyword.text, - semicolon: ast.semicolon.text - }), +import { SlangNode } from './SlangNode.js'; + +export class ThrowStatement extends SlangNode { + throwKeyword; + + semicolon; + + constructor({ ast, offset }) { + super(ast, offset); + this.throwKeyword = ast.throwKeyword.text; + this.semicolon = ast.semicolon.text; + this.initiateLoc(ast); + } + // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: ThrowStatement'] -}; + print({ path, print, options }) { + return ['TODO: ThrowStatement']; + } +} diff --git a/src/slang-nodes/TryStatement.js b/src/slang-nodes/TryStatement.js index 466f86ef0..0165b7277 100644 --- a/src/slang-nodes/TryStatement.js +++ b/src/slang-nodes/TryStatement.js @@ -1,26 +1,42 @@ import { doc } from 'prettier'; import { printSeparatedItem } from '../common/printer-helpers.js'; +import { SlangNode } from './SlangNode.js'; const { line } = doc.builders; -export const TryStatement = { - parse: ({ offsets, ast, options, parse }) => ({ - tryKeyword: ast.tryKeyword.text, - expression: parse(ast.expression, options, parse, offsets), - returns: ast.returns - ? parse(ast.returns, options, parse, offsets) - : undefined, - body: parse(ast.body, options, parse, offsets), - catchClauses: parse(ast.catchClauses, options, parse, offsets) - }), - print: ({ node, path, print }) => [ - node.tryKeyword, - printSeparatedItem(path.call(print, 'expression'), { - firstSeparator: line - }), - node.returns ? [path.call(print, 'returns'), ' '] : '', - path.call(print, 'body'), - ' ', - path.call(print, 'catchClauses') - ] -}; +export class TryStatement extends SlangNode { + tryKeyword; + + expression; + + returns; + + body; + + catchClauses; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.tryKeyword = ast.tryKeyword.text; + this.expression = parse(ast.expression, parse, this.nextChildOffset); + this.returns = ast.returns + ? parse(ast.returns, parse, this.nextChildOffset) + : undefined; + this.body = parse(ast.body, parse, this.nextChildOffset); + this.catchClauses = parse(ast.catchClauses, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + this.tryKeyword, + printSeparatedItem(path.call(print, 'expression'), { + firstSeparator: line + }), + this.returns ? [path.call(print, 'returns'), ' '] : '', + path.call(print, 'body'), + ' ', + path.call(print, 'catchClauses') + ]; + } +} diff --git a/src/slang-nodes/TupleDeconstructionElement.js b/src/slang-nodes/TupleDeconstructionElement.js index 8c4d10d3a..f8fc6d4b6 100644 --- a/src/slang-nodes/TupleDeconstructionElement.js +++ b/src/slang-nodes/TupleDeconstructionElement.js @@ -1,7 +1,17 @@ -export const TupleDeconstructionElement = { - parse: ({ offsets, ast, options, parse }) => ({ - member: ast.member ? parse(ast.member, options, parse, offsets) : undefined - }), - print: ({ node, path, print }) => - node.member ? path.call(print, 'member') : '' -}; +import { SlangNode } from './SlangNode.js'; + +export class TupleDeconstructionElement extends SlangNode { + member; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.member = ast.member + ? parse(ast.member, parse, this.nextChildOffset) + : undefined; + this.initiateLoc(ast); + } + + print({ path, print }) { + return this.member ? path.call(print, 'member') : ''; + } +} diff --git a/src/slang-nodes/TupleDeconstructionElements.js b/src/slang-nodes/TupleDeconstructionElements.js index f6e3a2b3c..4c7b7ecaf 100644 --- a/src/slang-nodes/TupleDeconstructionElements.js +++ b/src/slang-nodes/TupleDeconstructionElements.js @@ -1,9 +1,21 @@ import { printSeparatedList } from '../common/printer-helpers.js'; +import { SlangNode } from './SlangNode.js'; -export const TupleDeconstructionElements = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)), - separators: ast.separators.map((separator) => separator.text) - }), - print: ({ path, print }) => printSeparatedList(path.map(print, 'items')) -}; +export class TupleDeconstructionElements extends SlangNode { + items; + + separators; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items.map((item) => + parse(item, parse, this.nextChildOffset) + ); + this.separators = ast.separators.map((separator) => separator.text); + this.initiateLoc(ast); + } + + print({ path, print }) { + return printSeparatedList(path.map(print, 'items')); + } +} diff --git a/src/slang-nodes/TupleDeconstructionStatement.js b/src/slang-nodes/TupleDeconstructionStatement.js index 5f499cd1a..a780b587a 100644 --- a/src/slang-nodes/TupleDeconstructionStatement.js +++ b/src/slang-nodes/TupleDeconstructionStatement.js @@ -1,26 +1,46 @@ import { doc } from 'prettier'; +import { SlangNode } from './SlangNode.js'; const { group, indent, line } = doc.builders; -export const TupleDeconstructionStatement = { - parse: ({ offsets, ast, options, parse }) => ({ - varKeyword: ast.varKeyword?.text, - openParen: ast.openParen.text, - elements: parse(ast.elements, options, parse, offsets), - closeParen: ast.closeParen.text, - equal: ast.equal.text, - expression: parse(ast.expression, options, parse, offsets), - semicolon: ast.semicolon.text - }), - print: ({ node, path, print }) => [ - node.varKeyword ? node.varKeyword : '', - node.openParen, - path.call(print, 'elements'), - node.expression.variant.kind === 'TupleExpression' - ? [`${node.closeParen} ${node.equal} `, path.call(print, 'expression')] - : group([ - `${node.closeParen} ${node.equal}`, - indent([line, path.call(print, 'expression'), node.semicolon]) - ]) - ] -}; +export class TupleDeconstructionStatement extends SlangNode { + varKeyword; + + openParen; + + elements; + + closeParen; + + equal; + + expression; + + semicolon; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.varKeyword = ast.varKeyword?.text; + this.openParen = ast.openParen.text; + this.elements = parse(ast.elements, parse, this.nextChildOffset); + this.closeParen = ast.closeParen.text; + this.equal = ast.equal.text; + this.expression = parse(ast.expression, parse, this.nextChildOffset); + this.semicolon = ast.semicolon.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + this.varKeyword ? this.varKeyword : '', + this.openParen, + path.call(print, 'elements'), + this.expression.variant.kind === 'TupleExpression' + ? [`${this.closeParen} ${this.equal} `, path.call(print, 'expression')] + : group([ + `${this.closeParen} ${this.equal}`, + indent([line, path.call(print, 'expression'), this.semicolon]) + ]) + ]; + } +} diff --git a/src/slang-nodes/TupleExpression.js b/src/slang-nodes/TupleExpression.js index 98c506815..92960f792 100644 --- a/src/slang-nodes/TupleExpression.js +++ b/src/slang-nodes/TupleExpression.js @@ -1,12 +1,29 @@ -export const TupleExpression = { - parse: ({ offsets, ast, options, parse }) => ({ - openParen: ast.openParen.text, - items: parse(ast.items, options, parse, offsets), - closeParen: ast.closeParen.text - }), - print: ({ node, path, print }) => [ - node.openParen, - path.call(print, 'items'), - node.closeParen - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class TupleExpression extends SlangNode { + openParen; + + items; + + closeParen; + + constructor({ ast, parse, offset, kind, loc, openParen, items, closeParen }) { + super(ast, offset); + if (ast) { + this.openParen = ast.openParen.text; + this.items = parse(ast.items, parse, this.nextChildOffset); + this.closeParen = ast.closeParen.text; + this.initiateLoc(ast); + } else { + this.kind = kind; + this.loc = loc; + this.openParen = openParen; + this.items = items; + this.closeParen = closeParen; + } + } + + print({ path, print }) { + return [this.openParen, path.call(print, 'items'), this.closeParen]; + } +} diff --git a/src/slang-nodes/TupleMember.js b/src/slang-nodes/TupleMember.js index 2d29904f8..aec3af9ca 100644 --- a/src/slang-nodes/TupleMember.js +++ b/src/slang-nodes/TupleMember.js @@ -1,6 +1,15 @@ -export const TupleMember = { - parse: ({ offsets, ast, options, parse }) => ({ - variant: parse(ast.variant, options, parse, offsets) - }), - print: ({ path, print }) => path.call(print, 'variant') -}; +import { SlangNode } from './SlangNode.js'; + +export class TupleMember extends SlangNode { + variant; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.variant = parse(ast.variant, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/TupleValue.js b/src/slang-nodes/TupleValue.js index b8afab681..165a142b5 100644 --- a/src/slang-nodes/TupleValue.js +++ b/src/slang-nodes/TupleValue.js @@ -1,9 +1,23 @@ -export const TupleValue = { - parse: ({ offsets, ast, options, parse }) => ({ - expression: ast.expression - ? parse(ast.expression, options, parse, offsets) - : undefined - }), - print: ({ node, path, print }) => - node.expression ? path.call(print, 'expression') : '' -}; +import { SlangNode } from './SlangNode.js'; + +export class TupleValue extends SlangNode { + expression; + + constructor({ ast, parse, offset, kind, loc, expression }) { + super(ast, offset); + if (ast) { + this.expression = ast.expression + ? parse(ast.expression, parse, this.nextChildOffset) + : undefined; + this.initiateLoc(ast); + } else { + this.kind = kind; + this.loc = loc; + this.expression = expression; + } + } + + print({ path, print }) { + return this.expression ? path.call(print, 'expression') : ''; + } +} diff --git a/src/slang-nodes/TupleValues.js b/src/slang-nodes/TupleValues.js index 2445093c6..bd8a9591c 100644 --- a/src/slang-nodes/TupleValues.js +++ b/src/slang-nodes/TupleValues.js @@ -1,14 +1,32 @@ import { printSeparatedList } from '../common/printer-helpers.js'; import { isBinaryOperation } from '../common/slang-helpers.js'; +import { SlangNode } from './SlangNode.js'; -export const TupleValues = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)), - separators: ast.separators.map((separator) => separator.text) - }), - print: ({ node, path, print }) => - node.items.length === 1 && - isBinaryOperation(node.items[0].expression.variant) +export class TupleValues extends SlangNode { + items; + + separators; + + constructor({ ast, parse, offset, kind, loc, items, separators }) { + super(ast, offset); + if (ast) { + this.items = ast.items.map((item) => + parse(item, parse, this.nextChildOffset) + ); + this.separators = ast.separators.map((separator) => separator.text); + this.initiateLoc(ast); + } else { + this.kind = kind; + this.loc = loc; + this.items = items; + this.separators = separators; + } + } + + print({ path, print }) { + return this.items.length === 1 && + isBinaryOperation(this.items[0].expression.variant) ? path.map(print, 'items') - : printSeparatedList(path.map(print, 'items')) -}; + : printSeparatedList(path.map(print, 'items')); + } +} diff --git a/src/slang-nodes/TypeExpression.js b/src/slang-nodes/TypeExpression.js index 5216d4e5c..34ef6c576 100644 --- a/src/slang-nodes/TypeExpression.js +++ b/src/slang-nodes/TypeExpression.js @@ -1,10 +1,25 @@ -export const TypeExpression = { - parse: ({ offsets, ast, options, parse }) => ({ - typeKeyword: ast.typeKeyword.text, - openParen: ast.openParen.text, - typeName: parse(ast.typeName, options, parse, offsets), - closeParen: ast.closeParen.text - }), +import { SlangNode } from './SlangNode.js'; + +export class TypeExpression extends SlangNode { + typeKeyword; + + openParen; + + typeName; + + closeParen; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.typeKeyword = ast.typeKeyword.text; + this.openParen = ast.openParen.text; + this.typeName = parse(ast.typeName, parse, this.nextChildOffset); + this.closeParen = ast.closeParen.text; + this.initiateLoc(ast); + } + // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: TypeExpression'] -}; + print({ path, print, options }) { + return ['TODO: TypeExpression']; + } +} diff --git a/src/slang-nodes/TypeName.js b/src/slang-nodes/TypeName.js index 9d767be73..05bacdbfe 100644 --- a/src/slang-nodes/TypeName.js +++ b/src/slang-nodes/TypeName.js @@ -1,6 +1,15 @@ -export const TypeName = { - parse: ({ offsets, ast, options, parse }) => ({ - variant: parse(ast.variant, options, parse, offsets) - }), - print: ({ path, print }) => path.call(print, 'variant') -}; +import { SlangNode } from './SlangNode.js'; + +export class TypeName extends SlangNode { + variant; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.variant = parse(ast.variant, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/TypedTupleMember.js b/src/slang-nodes/TypedTupleMember.js index 9edac11e1..2cd964218 100644 --- a/src/slang-nodes/TypedTupleMember.js +++ b/src/slang-nodes/TypedTupleMember.js @@ -1,14 +1,27 @@ -export const TypedTupleMember = { - parse: ({ offsets, ast, options, parse }) => ({ - typeName: parse(ast.typeName, options, parse, offsets), - storageLocation: ast.storageLocation - ? parse(ast.storageLocation, options, parse, offsets) - : undefined, - name: ast.name.text - }), - print: ({ node, path, print }) => [ - path.call(print, 'typeName'), - node.storageLocation ? [' ', path.call(print, 'storageLocation')] : '', - ` ${node.name}` - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class TypedTupleMember extends SlangNode { + typeName; + + storageLocation; + + name; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.typeName = parse(ast.typeName, parse, this.nextChildOffset); + this.storageLocation = ast.storageLocation + ? parse(ast.storageLocation, parse, this.nextChildOffset) + : undefined; + this.name = ast.name.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + path.call(print, 'typeName'), + this.storageLocation ? [' ', path.call(print, 'storageLocation')] : '', + ` ${this.name}` + ]; + } +} diff --git a/src/slang-nodes/UncheckedBlock.js b/src/slang-nodes/UncheckedBlock.js index 3616d7d5f..6603a1d4c 100644 --- a/src/slang-nodes/UncheckedBlock.js +++ b/src/slang-nodes/UncheckedBlock.js @@ -1,10 +1,18 @@ -export const UncheckedBlock = { - parse: ({ offsets, ast, options, parse }) => ({ - uncheckedKeyword: ast.uncheckedKeyword.text, - block: parse(ast.block, options, parse, offsets) - }), - print: ({ node, path, print }) => [ - `${node.uncheckedKeyword} `, - path.call(print, 'block') - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class UncheckedBlock extends SlangNode { + uncheckedKeyword; + + block; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.uncheckedKeyword = ast.uncheckedKeyword.text; + this.block = parse(ast.block, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return [`${this.uncheckedKeyword} `, path.call(print, 'block')]; + } +} diff --git a/src/slang-nodes/UnicodeStringLiteral.js b/src/slang-nodes/UnicodeStringLiteral.js index 6add29a29..a2ef325d5 100644 --- a/src/slang-nodes/UnicodeStringLiteral.js +++ b/src/slang-nodes/UnicodeStringLiteral.js @@ -1,8 +1,16 @@ import { printString } from '../common/util.js'; +import { SlangNode } from './SlangNode.js'; -export const UnicodeStringLiteral = { - parse: ({ ast, options }) => ({ - variant: `unicode${printString(ast.variant.text.slice(8, -1), options)}` - }), - print: ({ node }) => node.variant -}; +export class UnicodeStringLiteral extends SlangNode { + variant; + + constructor({ ast, options, offset }) { + super(ast, offset); + this.variant = `unicode${printString(ast.variant.text.slice(8, -1), options)}`; + this.initiateLoc(ast); + } + + print() { + return this.variant; + } +} diff --git a/src/slang-nodes/UnicodeStringLiterals.js b/src/slang-nodes/UnicodeStringLiterals.js index 9009d4d1e..c2166bfda 100644 --- a/src/slang-nodes/UnicodeStringLiterals.js +++ b/src/slang-nodes/UnicodeStringLiterals.js @@ -1,10 +1,20 @@ import { doc } from 'prettier'; +import { SlangNode } from './SlangNode.js'; const { join, hardline } = doc.builders; -export const UnicodeStringLiterals = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)) - }), - print: ({ path, print }) => join(hardline, path.map(print, 'items')) -}; +export class UnicodeStringLiterals extends SlangNode { + items; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items.map((item) => + parse(item, parse, this.nextChildOffset) + ); + this.initiateLoc(ast); + } + + print({ path, print }) { + return join(hardline, path.map(print, 'items')); + } +} diff --git a/src/slang-nodes/UnnamedFunctionAttribute.js b/src/slang-nodes/UnnamedFunctionAttribute.js index 79f355cb7..dbd570464 100644 --- a/src/slang-nodes/UnnamedFunctionAttribute.js +++ b/src/slang-nodes/UnnamedFunctionAttribute.js @@ -1,12 +1,20 @@ -export const UnnamedFunctionAttribute = { - parse: ({ offsets, ast, options, parse }) => ({ - variant: +import { SlangNode } from './SlangNode.js'; + +export class UnnamedFunctionAttribute extends SlangNode { + variant; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, options, parse, offsets) - }), - print: ({ node, path, print }) => - typeof node.variant === 'string' - ? node.variant - : path.call(print, 'variant') -}; + : parse(ast.variant, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/UnnamedFunctionAttributes.js b/src/slang-nodes/UnnamedFunctionAttributes.js index 08524de45..618de8b86 100644 --- a/src/slang-nodes/UnnamedFunctionAttributes.js +++ b/src/slang-nodes/UnnamedFunctionAttributes.js @@ -1,14 +1,21 @@ import { doc } from 'prettier'; import { sortFunctionAttributes } from '../common/slang-helpers.js'; +import { SlangNode } from './SlangNode.js'; const { line } = doc.builders; -export const UnnamedFunctionAttributes = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items - .map((item) => parse(item, options, parse, offsets)) - .sort(sortFunctionAttributes) - }), - print: ({ path, print }) => - path.map(print, 'items').map((item) => [line, item]) -}; +export class UnnamedFunctionAttributes extends SlangNode { + items; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items + .map((item) => parse(item, parse, this.nextChildOffset)) + .sort(sortFunctionAttributes); + this.initiateLoc(ast); + } + + print({ path, print }) { + return path.map(print, 'items').map((item) => [line, item]); + } +} diff --git a/src/slang-nodes/UnnamedFunctionDefinition.js b/src/slang-nodes/UnnamedFunctionDefinition.js index 59d728690..c865e1747 100644 --- a/src/slang-nodes/UnnamedFunctionDefinition.js +++ b/src/slang-nodes/UnnamedFunctionDefinition.js @@ -1,12 +1,25 @@ import { printFunction } from '../common/slang-helpers.js'; +import { SlangNode } from './SlangNode.js'; -export const UnnamedFunctionDefinition = { - parse: ({ offsets, ast, options, parse }) => ({ - functionKeyword: ast.functionKeyword.text, - parameters: parse(ast.parameters, options, parse, offsets), - attributes: parse(ast.attributes, options, parse, offsets), - body: parse(ast.body, options, parse, offsets) - }), - print: ({ node, path, print }) => - printFunction(node.functionKeyword, node, path, print) -}; +export class UnnamedFunctionDefinition extends SlangNode { + functionKeyword; + + parameters; + + attributes; + + body; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.functionKeyword = ast.functionKeyword.text; + this.parameters = parse(ast.parameters, parse, this.nextChildOffset); + this.attributes = parse(ast.attributes, parse, this.nextChildOffset); + this.body = parse(ast.body, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return printFunction(this.functionKeyword, this, path, print); + } +} diff --git a/src/slang-nodes/UntypedTupleMember.js b/src/slang-nodes/UntypedTupleMember.js index c4824b36a..d5c102ea5 100644 --- a/src/slang-nodes/UntypedTupleMember.js +++ b/src/slang-nodes/UntypedTupleMember.js @@ -1,12 +1,21 @@ -export const UntypedTupleMember = { - parse: ({ offsets, ast, options, parse }) => ({ - storageLocation: ast.storageLocation - ? parse(ast.storageLocation, options, parse, offsets) - : undefined, - name: ast.name.text - }), +import { SlangNode } from './SlangNode.js'; + +export class UntypedTupleMember extends SlangNode { + storageLocation; + + name; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.storageLocation = ast.storageLocation + ? parse(ast.storageLocation, parse, this.nextChildOffset) + : undefined; + this.name = ast.name.text; + this.initiateLoc(ast); + } + // TODO: implement print - print: ({ node, path, print, options }) => [ - 'TODO: UntypedTupleMemberUntypedTupleMember' - ] -}; + print({ path, print, options }) { + return ['TODO: UntypedTupleMemberUntypedTupleMember']; + } +} diff --git a/src/slang-nodes/UserDefinedValueTypeDefinition.js b/src/slang-nodes/UserDefinedValueTypeDefinition.js index 6d3d7a238..7bc9e9f8a 100644 --- a/src/slang-nodes/UserDefinedValueTypeDefinition.js +++ b/src/slang-nodes/UserDefinedValueTypeDefinition.js @@ -1,14 +1,31 @@ -export const UserDefinedValueTypeDefinition = { - parse: ({ offsets, ast, options, parse }) => ({ - typeKeyword: ast.typeKeyword.text, - name: ast.name.text, - isKeyword: ast.isKeyword.text, - valueType: parse(ast.valueType, options, parse, offsets), - semicolon: ast.semicolon.text - }), - print: ({ node, path, print }) => [ - `${node.typeKeyword} ${node.name} ${node.isKeyword} `, - path.call(print, 'valueType'), - node.semicolon - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class UserDefinedValueTypeDefinition extends SlangNode { + typeKeyword; + + name; + + isKeyword; + + valueType; + + semicolon; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.typeKeyword = ast.typeKeyword.text; + this.name = ast.name.text; + this.isKeyword = ast.isKeyword.text; + this.valueType = parse(ast.valueType, parse, this.nextChildOffset); + this.semicolon = ast.semicolon.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + `${this.typeKeyword} ${this.name} ${this.isKeyword} `, + path.call(print, 'valueType'), + this.semicolon + ]; + } +} diff --git a/src/slang-nodes/UsingAlias.js b/src/slang-nodes/UsingAlias.js index 0d7d1b682..c7f114b19 100644 --- a/src/slang-nodes/UsingAlias.js +++ b/src/slang-nodes/UsingAlias.js @@ -1,10 +1,18 @@ -export const UsingAlias = { - parse: ({ offsets, ast, options, parse }) => ({ - asKeyword: ast.asKeyword.text, - operator: parse(ast.operator, options, parse, offsets) - }), - print: ({ node, path, print }) => [ - ` ${node.asKeyword} `, - path.call(print, 'operator') - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class UsingAlias extends SlangNode { + asKeyword; + + operator; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.asKeyword = ast.asKeyword.text; + this.operator = parse(ast.operator, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return [` ${this.asKeyword} `, path.call(print, 'operator')]; + } +} diff --git a/src/slang-nodes/UsingClause.js b/src/slang-nodes/UsingClause.js index 754b9cb90..7ce10f1b4 100644 --- a/src/slang-nodes/UsingClause.js +++ b/src/slang-nodes/UsingClause.js @@ -1,6 +1,15 @@ -export const UsingClause = { - parse: ({ offsets, ast, options, parse }) => ({ - variant: parse(ast.variant, options, parse, offsets) - }), - print: ({ path, print }) => path.call(print, 'variant') -}; +import { SlangNode } from './SlangNode.js'; + +export class UsingClause extends SlangNode { + variant; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.variant = parse(ast.variant, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/UsingDeconstruction.js b/src/slang-nodes/UsingDeconstruction.js index 6be559b79..ae784d77d 100644 --- a/src/slang-nodes/UsingDeconstruction.js +++ b/src/slang-nodes/UsingDeconstruction.js @@ -1,12 +1,21 @@ -export const UsingDeconstruction = { - parse: ({ offsets, ast, options, parse }) => ({ - openBrace: ast.openBrace.text, - symbols: parse(ast.symbols, options, parse, offsets), - closeBrace: ast.closeBrace.text - }), - print: ({ node, path, print }) => [ - node.openBrace, - path.call(print, 'symbols'), - node.closeBrace - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class UsingDeconstruction extends SlangNode { + openBrace; + + symbols; + + closeBrace; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.openBrace = ast.openBrace.text; + this.symbols = parse(ast.symbols, parse, this.nextChildOffset); + this.closeBrace = ast.closeBrace.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [this.openBrace, path.call(print, 'symbols'), this.closeBrace]; + } +} diff --git a/src/slang-nodes/UsingDeconstructionSymbol.js b/src/slang-nodes/UsingDeconstructionSymbol.js index 7a658fc25..449ae9fd0 100644 --- a/src/slang-nodes/UsingDeconstructionSymbol.js +++ b/src/slang-nodes/UsingDeconstructionSymbol.js @@ -1,10 +1,23 @@ -export const UsingDeconstructionSymbol = { - parse: ({ offsets, ast, options, parse }) => ({ - name: parse(ast.name, options, parse, offsets), - alias: ast.alias ? parse(ast.alias, options, parse, offsets) : undefined - }), - print: ({ node, path, print }) => [ - path.call(print, 'name'), - node.alias ? path.call(print, 'alias') : '' - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class UsingDeconstructionSymbol extends SlangNode { + name; + + alias; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.name = parse(ast.name, parse, this.nextChildOffset); + this.alias = ast.alias + ? parse(ast.alias, parse, this.nextChildOffset) + : undefined; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + path.call(print, 'name'), + this.alias ? path.call(print, 'alias') : '' + ]; + } +} diff --git a/src/slang-nodes/UsingDeconstructionSymbols.js b/src/slang-nodes/UsingDeconstructionSymbols.js index 9754883b9..76ec1afd7 100644 --- a/src/slang-nodes/UsingDeconstructionSymbols.js +++ b/src/slang-nodes/UsingDeconstructionSymbols.js @@ -1,15 +1,26 @@ import { doc } from 'prettier'; import { printSeparatedList } from '../common/printer-helpers.js'; +import { SlangNode } from './SlangNode.js'; const { line, softline } = doc.builders; -export const UsingDeconstructionSymbols = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)), - separators: ast.separators.map((separator) => separator.text) - }), - print: ({ path, print, options }) => - printSeparatedList(path.map(print, 'items'), { +export class UsingDeconstructionSymbols extends SlangNode { + items; + + separators; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items.map((item) => + parse(item, parse, this.nextChildOffset) + ); + this.separators = ast.separators.map((separator) => separator.text); + this.initiateLoc(ast); + } + + print({ path, print, options }) { + return printSeparatedList(path.map(print, 'items'), { firstSeparator: options.bracketSpacing ? line : softline - }) -}; + }); + } +} diff --git a/src/slang-nodes/UsingDirective.js b/src/slang-nodes/UsingDirective.js index bf1cf518d..b25971139 100644 --- a/src/slang-nodes/UsingDirective.js +++ b/src/slang-nodes/UsingDirective.js @@ -1,17 +1,36 @@ -export const UsingDirective = { - parse: ({ offsets, ast, options, parse }) => ({ - usingKeyword: ast.usingKeyword.text, - clause: parse(ast.clause, options, parse, offsets), - forKeyword: ast.forKeyword.text, - target: parse(ast.target, options, parse, offsets), - globalKeyword: ast.globalKeyword?.text, - semicolon: ast.semicolon.text - }), - print: ({ node, path, print }) => [ - `${node.usingKeyword} `, - path.call(print, 'clause'), - ` ${node.forKeyword} `, - path.call(print, 'target'), - `${node.globalKeyword ? ` ${node.globalKeyword}` : ''}${node.semicolon}` - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class UsingDirective extends SlangNode { + usingKeyword; + + clause; + + forKeyword; + + target; + + globalKeyword; + + semicolon; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.usingKeyword = ast.usingKeyword.text; + this.clause = parse(ast.clause, parse, this.nextChildOffset); + this.forKeyword = ast.forKeyword.text; + this.target = parse(ast.target, parse, this.nextChildOffset); + this.globalKeyword = ast.globalKeyword?.text; + this.semicolon = ast.semicolon.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + `${this.usingKeyword} `, + path.call(print, 'clause'), + ` ${this.forKeyword} `, + path.call(print, 'target'), + `${this.globalKeyword ? ` ${this.globalKeyword}` : ''}${this.semicolon}` + ]; + } +} diff --git a/src/slang-nodes/UsingOperator.js b/src/slang-nodes/UsingOperator.js index 3514cd39f..abe45fc5a 100644 --- a/src/slang-nodes/UsingOperator.js +++ b/src/slang-nodes/UsingOperator.js @@ -1,6 +1,15 @@ -export const UsingOperator = { - parse: ({ ast }) => ({ - variant: ast.variant.text - }), - print: ({ node }) => node.variant -}; +import { SlangNode } from './SlangNode.js'; + +export class UsingOperator extends SlangNode { + variant; + + constructor({ ast, offset }) { + super(ast, offset); + this.variant = ast.variant.text; + this.initiateLoc(ast); + } + + print() { + return this.variant; + } +} diff --git a/src/slang-nodes/UsingTarget.js b/src/slang-nodes/UsingTarget.js index 22eb7691f..558e5c7bc 100644 --- a/src/slang-nodes/UsingTarget.js +++ b/src/slang-nodes/UsingTarget.js @@ -1,12 +1,20 @@ -export const UsingTarget = { - parse: ({ offsets, ast, options, parse }) => ({ - variant: +import { SlangNode } from './SlangNode.js'; + +export class UsingTarget extends SlangNode { + variant; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, options, parse, offsets) - }), - print: ({ node, path, print }) => - typeof node.variant === 'string' - ? node.variant - : path.call(print, 'variant') -}; + : parse(ast.variant, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/VariableDeclarationStatement.js b/src/slang-nodes/VariableDeclarationStatement.js index 96e1f84da..d2724aadf 100644 --- a/src/slang-nodes/VariableDeclarationStatement.js +++ b/src/slang-nodes/VariableDeclarationStatement.js @@ -1,27 +1,44 @@ import { doc } from 'prettier'; +import { SlangNode } from './SlangNode.js'; const { group, indent, indentIfBreak, line } = doc.builders; let groupIndex = 0; -export const VariableDeclarationStatement = { - parse: ({ offsets, ast, options, parse }) => ({ - variableType: parse(ast.variableType, options, parse, offsets), - storageLocation: ast.storageLocation - ? parse(ast.storageLocation, options, parse, offsets) - : undefined, - name: ast.name.text, - value: ast.value ? parse(ast.value, options, parse, offsets) : undefined, - semicolon: ast.semicolon.text - }), - print: ({ node, path, print }) => { + +export class VariableDeclarationStatement extends SlangNode { + variableType; + + storageLocation; + + name; + + value; + + semicolon; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.variableType = parse(ast.variableType, parse, this.nextChildOffset); + this.storageLocation = ast.storageLocation + ? parse(ast.storageLocation, parse, this.nextChildOffset) + : undefined; + this.name = ast.name.text; + this.value = ast.value + ? parse(ast.value, parse, this.nextChildOffset) + : undefined; + this.semicolon = ast.semicolon.text; + this.initiateLoc(ast); + } + + print({ path, print }) { const declarationDoc = group( [ path.call(print, 'variableType'), indent([ - node.storageLocation + this.storageLocation ? [line, path.call(print, 'storageLocation')] : '', - ` ${node.name}` + ` ${this.name}` ]) ], { id: `VariableDeclarationStatement.variables-${groupIndex}` } @@ -30,10 +47,10 @@ export const VariableDeclarationStatement = { return [ declarationDoc, - indentIfBreak(node.value ? path.call(print, 'value') : '', { + indentIfBreak(this.value ? path.call(print, 'value') : '', { groupId: declarationDoc.id }), - node.semicolon + this.semicolon ]; } -}; +} diff --git a/src/slang-nodes/VariableDeclarationType.js b/src/slang-nodes/VariableDeclarationType.js index b13dfe6b7..03989f148 100644 --- a/src/slang-nodes/VariableDeclarationType.js +++ b/src/slang-nodes/VariableDeclarationType.js @@ -1,12 +1,20 @@ -export const VariableDeclarationType = { - parse: ({ offsets, ast, options, parse }) => ({ - variant: +import { SlangNode } from './SlangNode.js'; + +export class VariableDeclarationType extends SlangNode { + variant; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, options, parse, offsets) - }), - print: ({ node, path, print }) => - typeof node.variant === 'string' - ? node.variant - : path.call(print, 'variant') -}; + : parse(ast.variant, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/VariableDeclarationValue.js b/src/slang-nodes/VariableDeclarationValue.js index f99d44d4b..96ab7323c 100644 --- a/src/slang-nodes/VariableDeclarationValue.js +++ b/src/slang-nodes/VariableDeclarationValue.js @@ -1,10 +1,18 @@ -export const VariableDeclarationValue = { - parse: ({ offsets, ast, options, parse }) => ({ - equal: ast.equal.text, - expression: parse(ast.expression, options, parse, offsets) - }), - print: ({ node, path, print }) => [ - ` ${node.equal} `, - path.call(print, 'expression') - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class VariableDeclarationValue extends SlangNode { + equal; + + expression; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.equal = ast.equal.text; + this.expression = parse(ast.expression, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return [` ${this.equal} `, path.call(print, 'expression')]; + } +} diff --git a/src/slang-nodes/VersionComparator.js b/src/slang-nodes/VersionComparator.js index 1a1b8b599..5b4d25d4d 100644 --- a/src/slang-nodes/VersionComparator.js +++ b/src/slang-nodes/VersionComparator.js @@ -1,7 +1,18 @@ -export const VersionComparator = { - parse: ({ offsets, ast, options, parse }) => ({ - operator: ast.operator.text, - operand: parse(ast.operand, options, parse, offsets) - }), - print: ({ node, path, print }) => [node.operator, path.call(print, 'operand')] -}; +import { SlangNode } from './SlangNode.js'; + +export class VersionComparator extends SlangNode { + operator; + + operand; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.operator = ast.operator.text; + this.operand = parse(ast.operand, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return [this.operator, path.call(print, 'operand')]; + } +} diff --git a/src/slang-nodes/VersionExpression.js b/src/slang-nodes/VersionExpression.js index bb5fae09e..b51dfad32 100644 --- a/src/slang-nodes/VersionExpression.js +++ b/src/slang-nodes/VersionExpression.js @@ -1,12 +1,20 @@ -export const VersionExpression = { - parse: ({ offsets, ast, options, parse }) => ({ - variant: +import { SlangNode } from './SlangNode.js'; + +export class VersionExpression extends SlangNode { + variant; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, options, parse, offsets) - }), - print: ({ node, path, print }) => - typeof node.variant === 'string' - ? node.variant - : path.call(print, 'variant') -}; + : parse(ast.variant, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/VersionExpressionSet.js b/src/slang-nodes/VersionExpressionSet.js index 6c65c0586..8fe7e3d13 100644 --- a/src/slang-nodes/VersionExpressionSet.js +++ b/src/slang-nodes/VersionExpressionSet.js @@ -1,10 +1,20 @@ import { doc } from 'prettier'; +import { SlangNode } from './SlangNode.js'; const { join } = doc.builders; -export const VersionExpressionSet = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)) - }), - print: ({ path, print }) => join(' ', path.map(print, 'items')) -}; +export class VersionExpressionSet extends SlangNode { + items; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items.map((item) => + parse(item, parse, this.nextChildOffset) + ); + this.initiateLoc(ast); + } + + print({ path, print }) { + return join(' ', path.map(print, 'items')); + } +} diff --git a/src/slang-nodes/VersionExpressionSets.js b/src/slang-nodes/VersionExpressionSets.js index dcab4810a..a4d645c70 100644 --- a/src/slang-nodes/VersionExpressionSets.js +++ b/src/slang-nodes/VersionExpressionSets.js @@ -1,12 +1,24 @@ -export const VersionExpressionSets = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)), - separators: ast.separators.map((separator) => separator.text) - }), - print: ({ node, path, print }) => - path +import { SlangNode } from './SlangNode.js'; + +export class VersionExpressionSets extends SlangNode { + items; + + separators; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items.map((item) => + parse(item, parse, this.nextChildOffset) + ); + this.separators = ast.separators.map((separator) => separator.text); + this.initiateLoc(ast); + } + + print({ path, print }) { + return path .map(print, 'items') .map((item, index) => - index === 0 ? item : [` ${node.separators[index - 1]} `, item] - ) -}; + index === 0 ? item : [` ${this.separators[index - 1]} `, item] + ); + } +} diff --git a/src/slang-nodes/VersionPragma.js b/src/slang-nodes/VersionPragma.js index fb9990c4c..cb3742161 100644 --- a/src/slang-nodes/VersionPragma.js +++ b/src/slang-nodes/VersionPragma.js @@ -1,10 +1,18 @@ -export const VersionPragma = { - parse: ({ offsets, ast, options, parse }) => ({ - solidityKeyword: ast.solidityKeyword.text, - sets: parse(ast.sets, options, parse, offsets) - }), - print: ({ node, path, print }) => [ - `${node.solidityKeyword} `, - path.call(print, 'sets') - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class VersionPragma extends SlangNode { + solidityKeyword; + + sets; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.solidityKeyword = ast.solidityKeyword.text; + this.sets = parse(ast.sets, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return [`${this.solidityKeyword} `, path.call(print, 'sets')]; + } +} diff --git a/src/slang-nodes/VersionRange.js b/src/slang-nodes/VersionRange.js index e846b9e84..faf7e8537 100644 --- a/src/slang-nodes/VersionRange.js +++ b/src/slang-nodes/VersionRange.js @@ -1,9 +1,22 @@ -export const VersionRange = { - parse: ({ offsets, ast, options, parse }) => ({ - leftOperand: parse(ast.leftOperand, options, parse, offsets), - operator: ast.operator.text, - rightOperand: parse(ast.rightOperand, options, parse, offsets) - }), +import { SlangNode } from './SlangNode.js'; + +export class VersionRange extends SlangNode { + leftOperand; + + operator; + + rightOperand; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.leftOperand = parse(ast.leftOperand, parse, this.nextChildOffset); + this.operator = ast.operator.text; + this.rightOperand = parse(ast.rightOperand, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: VersionRange'] -}; + print({ path, print, options }) { + return ['TODO: VersionRange']; + } +} diff --git a/src/slang-nodes/VersionSpecifiers.js b/src/slang-nodes/VersionSpecifiers.js index e08e48a0e..c84143ff6 100644 --- a/src/slang-nodes/VersionSpecifiers.js +++ b/src/slang-nodes/VersionSpecifiers.js @@ -1,10 +1,20 @@ -export const VersionSpecifiers = { - parse: ({ ast }) => ({ - items: ast.items.map((item) => item.text), - separators: ast.separators.map((separator) => separator.text) - }), - print: ({ node }) => - node.items.map((item, index) => - index === 0 ? item : [node.separators[index - 1], item] - ) -}; +import { SlangNode } from './SlangNode.js'; + +export class VersionSpecifiers extends SlangNode { + items; + + separators; + + constructor({ ast, offset }) { + super(ast, offset); + this.items = ast.items.map((item) => item.text); + this.separators = ast.separators.map((separator) => separator.text); + this.initiateLoc(ast); + } + + print() { + return this.items.map((item, index) => + index === 0 ? item : [this.separators[index - 1], item] + ); + } +} diff --git a/src/slang-nodes/WhileStatement.js b/src/slang-nodes/WhileStatement.js index ad8c1e6ef..88d08aa70 100644 --- a/src/slang-nodes/WhileStatement.js +++ b/src/slang-nodes/WhileStatement.js @@ -1,5 +1,6 @@ import { doc } from 'prettier'; import { printSeparatedItem } from '../common/printer-helpers.js'; +import { SlangNode } from './SlangNode.js'; const { group, indent, line } = doc.builders; @@ -8,18 +9,33 @@ const body = (node, path, print) => ? [' ', path.call(print, 'body')] : group(indent([line, path.call(print, 'body')])); -export const WhileStatement = { - parse: ({ offsets, ast, options, parse }) => ({ - whileKeyword: ast.whileKeyword.text, - openParen: ast.openParen.text, - condition: parse(ast.condition, options, parse, offsets), - closeParen: ast.closeParen.text, - body: parse(ast.body, options, parse, offsets) - }), - print: ({ node, path, print }) => [ - `${node.whileKeyword} ${node.openParen}`, - printSeparatedItem(path.call(print, 'condition')), - node.closeParen, - body(node, path, print) - ] -}; +export class WhileStatement extends SlangNode { + whileKeyword; + + openParen; + + condition; + + closeParen; + + body; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.whileKeyword = ast.whileKeyword.text; + this.openParen = ast.openParen.text; + this.condition = parse(ast.condition, parse, this.nextChildOffset); + this.closeParen = ast.closeParen.text; + this.body = parse(ast.body, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + `${this.whileKeyword} ${this.openParen}`, + printSeparatedItem(path.call(print, 'condition')), + this.closeParen, + body(this, path, print) + ]; + } +} diff --git a/src/slang-nodes/YulArguments.js b/src/slang-nodes/YulArguments.js index fb0b29d98..9dfc2907b 100644 --- a/src/slang-nodes/YulArguments.js +++ b/src/slang-nodes/YulArguments.js @@ -1,9 +1,21 @@ import { printSeparatedList } from '../common/printer-helpers.js'; +import { SlangNode } from './SlangNode.js'; -export const YulArguments = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)), - separators: ast.separators.map((separator) => separator.text) - }), - print: ({ path, print }) => printSeparatedList(path.map(print, 'items')) -}; +export class YulArguments extends SlangNode { + items; + + separators; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items.map((item) => + parse(item, parse, this.nextChildOffset) + ); + this.separators = ast.separators.map((separator) => separator.text); + this.initiateLoc(ast); + } + + print({ path, print }) { + return printSeparatedList(path.map(print, 'items')); + } +} diff --git a/src/slang-nodes/YulAssignmentOperator.js b/src/slang-nodes/YulAssignmentOperator.js index 66d0f7e1c..fd12cd4f1 100644 --- a/src/slang-nodes/YulAssignmentOperator.js +++ b/src/slang-nodes/YulAssignmentOperator.js @@ -1,12 +1,20 @@ -export const YulAssignmentOperator = { - parse: ({ offsets, ast, options, parse }) => ({ - variant: +import { SlangNode } from './SlangNode.js'; + +export class YulAssignmentOperator extends SlangNode { + variant; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, options, parse, offsets) - }), - print: ({ node, path, print }) => - typeof node.variant === 'string' - ? node.variant - : path.call(print, 'variant') -}; + : parse(ast.variant, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/YulAssignmentStatement.js b/src/slang-nodes/YulAssignmentStatement.js index 04dbc7d2d..c49db3d89 100644 --- a/src/slang-nodes/YulAssignmentStatement.js +++ b/src/slang-nodes/YulAssignmentStatement.js @@ -1,14 +1,27 @@ -export const YulAssignmentStatement = { - parse: ({ offsets, ast, options, parse }) => ({ - names: parse(ast.names, options, parse, offsets), - assignment: parse(ast.assignment, options, parse, offsets), - expression: parse(ast.expression, options, parse, offsets) - }), - print: ({ path, print }) => [ - path.call(print, 'names'), - ' ', - path.call(print, 'assignment'), - ' ', - path.call(print, 'expression') - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class YulAssignmentStatement extends SlangNode { + names; + + assignment; + + expression; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.names = parse(ast.names, parse, this.nextChildOffset); + this.assignment = parse(ast.assignment, parse, this.nextChildOffset); + this.expression = parse(ast.expression, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + path.call(print, 'names'), + ' ', + path.call(print, 'assignment'), + ' ', + path.call(print, 'expression') + ]; + } +} diff --git a/src/slang-nodes/YulBlock.js b/src/slang-nodes/YulBlock.js index f17bc449c..d328701f9 100644 --- a/src/slang-nodes/YulBlock.js +++ b/src/slang-nodes/YulBlock.js @@ -1,12 +1,21 @@ -export const YulBlock = { - parse: ({ offsets, ast, options, parse }) => ({ - openBrace: ast.openBrace.text, - statements: parse(ast.statements, options, parse, offsets), - closeBrace: ast.closeBrace.text - }), - print: ({ node, print }) => [ - node.openBrace, - print.call(print, 'statements'), - node.closeBrace - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class YulBlock extends SlangNode { + openBrace; + + statements; + + closeBrace; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.openBrace = ast.openBrace.text; + this.statements = parse(ast.statements, parse, this.nextChildOffset); + this.closeBrace = ast.closeBrace.text; + this.initiateLoc(ast); + } + + print({ print }) { + return [this.openBrace, print.call(print, 'statements'), this.closeBrace]; + } +} diff --git a/src/slang-nodes/YulBreakStatement.js b/src/slang-nodes/YulBreakStatement.js index 4062e1a00..7e7c9484a 100644 --- a/src/slang-nodes/YulBreakStatement.js +++ b/src/slang-nodes/YulBreakStatement.js @@ -1,6 +1,15 @@ -export const YulBreakStatement = { - parse: ({ ast }) => ({ - breakKeyword: ast.breakKeyword.text - }), - print: ({ node }) => node.breakKeyword -}; +import { SlangNode } from './SlangNode.js'; + +export class YulBreakStatement extends SlangNode { + breakKeyword; + + constructor({ ast, offset }) { + super(ast, offset); + this.breakKeyword = ast.breakKeyword.text; + this.initiateLoc(ast); + } + + print() { + return this.breakKeyword; + } +} diff --git a/src/slang-nodes/YulBuiltInFunction.js b/src/slang-nodes/YulBuiltInFunction.js index ce31570da..dc0396546 100644 --- a/src/slang-nodes/YulBuiltInFunction.js +++ b/src/slang-nodes/YulBuiltInFunction.js @@ -1,6 +1,15 @@ -export const YulBuiltInFunction = { - parse: ({ ast }) => ({ - variant: ast.variant.text - }), - print: ({ node }) => node.variant -}; +import { SlangNode } from './SlangNode.js'; + +export class YulBuiltInFunction extends SlangNode { + variant; + + constructor({ ast, offset }) { + super(ast, offset); + this.variant = ast.variant.text; + this.initiateLoc(ast); + } + + print() { + return this.variant; + } +} diff --git a/src/slang-nodes/YulColonAndEqual.js b/src/slang-nodes/YulColonAndEqual.js index e9a02962a..0f714cfb0 100644 --- a/src/slang-nodes/YulColonAndEqual.js +++ b/src/slang-nodes/YulColonAndEqual.js @@ -1,8 +1,19 @@ -export const YulColonAndEqual = { - parse: ({ ast }) => ({ - colon: ast.colon.text, - equal: ast.equal.text - }), +import { SlangNode } from './SlangNode.js'; + +export class YulColonAndEqual extends SlangNode { + colon; + + equal; + + constructor({ ast, offset }) { + super(ast, offset); + this.colon = ast.colon.text; + this.equal = ast.equal.text; + this.initiateLoc(ast); + } + // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: YulColonAndEqual'] -}; + print({ path, print, options }) { + return ['TODO: YulColonAndEqual']; + } +} diff --git a/src/slang-nodes/YulContinueStatement.js b/src/slang-nodes/YulContinueStatement.js index d70042ed8..11369ead7 100644 --- a/src/slang-nodes/YulContinueStatement.js +++ b/src/slang-nodes/YulContinueStatement.js @@ -1,6 +1,15 @@ -export const YulContinueStatement = { - parse: ({ ast }) => ({ - continueKeyword: ast.continueKeyword.text - }), - print: ({ node }) => node.continueKeyword -}; +import { SlangNode } from './SlangNode.js'; + +export class YulContinueStatement extends SlangNode { + continueKeyword; + + constructor({ ast, offset }) { + super(ast, offset); + this.continueKeyword = ast.continueKeyword.text; + this.initiateLoc(ast); + } + + print() { + return this.continueKeyword; + } +} diff --git a/src/slang-nodes/YulDefaultCase.js b/src/slang-nodes/YulDefaultCase.js index 28d47cc00..e962fdc1b 100644 --- a/src/slang-nodes/YulDefaultCase.js +++ b/src/slang-nodes/YulDefaultCase.js @@ -1,10 +1,18 @@ -export const YulDefaultCase = { - parse: ({ offsets, ast, options, parse }) => ({ - defaultKeyword: ast.defaultKeyword.text, - body: parse(ast.body, options, parse, offsets) - }), - print: ({ node, path, print }) => [ - `${node.defaultKeyword} `, - path.call(print, 'body') - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class YulDefaultCase extends SlangNode { + defaultKeyword; + + body; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.defaultKeyword = ast.defaultKeyword.text; + this.body = parse(ast.body, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return [`${this.defaultKeyword} `, path.call(print, 'body')]; + } +} diff --git a/src/slang-nodes/YulExpression.js b/src/slang-nodes/YulExpression.js index a46f2af5f..4d9eca4c9 100644 --- a/src/slang-nodes/YulExpression.js +++ b/src/slang-nodes/YulExpression.js @@ -1,6 +1,15 @@ -export const YulExpression = { - parse: ({ offsets, ast, options, parse }) => ({ - variant: parse(ast.variant, options, parse, offsets) - }), - print: ({ path, print }) => path.call(print, 'variant') -}; +import { SlangNode } from './SlangNode.js'; + +export class YulExpression extends SlangNode { + variant; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.variant = parse(ast.variant, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/YulForStatement.js b/src/slang-nodes/YulForStatement.js index 340ff05cf..6190d0991 100644 --- a/src/slang-nodes/YulForStatement.js +++ b/src/slang-nodes/YulForStatement.js @@ -1,19 +1,40 @@ -export const YulForStatement = { - parse: ({ offsets, ast, options, parse }) => ({ - forKeyword: ast.forKeyword.text, - initialization: parse(ast.initialization, options, parse, offsets), - condition: parse(ast.condition, options, parse, offsets), - iterator: parse(ast.iterator, options, parse, offsets), - body: parse(ast.body, options, parse, offsets) - }), - print: ({ node, path, print }) => [ - `${node.forKeyword} `, - path.call(print, 'initialization'), - ' ', - path.call(print, 'condition'), - ' ', - path.call(print, 'iterator'), - ' ', - path.call(print, 'body') - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class YulForStatement extends SlangNode { + forKeyword; + + initialization; + + condition; + + iterator; + + body; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.forKeyword = ast.forKeyword.text; + this.initialization = parse( + ast.initialization, + parse, + this.nextChildOffset + ); + this.condition = parse(ast.condition, parse, this.nextChildOffset); + this.iterator = parse(ast.iterator, parse, this.nextChildOffset); + this.body = parse(ast.body, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + `${this.forKeyword} `, + path.call(print, 'initialization'), + ' ', + path.call(print, 'condition'), + ' ', + path.call(print, 'iterator'), + ' ', + path.call(print, 'body') + ]; + } +} diff --git a/src/slang-nodes/YulFunctionCallExpression.js b/src/slang-nodes/YulFunctionCallExpression.js index 744d9ac17..e697f1d36 100644 --- a/src/slang-nodes/YulFunctionCallExpression.js +++ b/src/slang-nodes/YulFunctionCallExpression.js @@ -1,14 +1,29 @@ -export const YulFunctionCallExpression = { - parse: ({ offsets, ast, options, parse }) => ({ - operand: parse(ast.operand, options, parse, offsets), - openParen: ast.openParen.text, - arguments: parse(ast.arguments, options, parse, offsets), - closeParen: ast.closeParen.text - }), - print: ({ node, path, print }) => [ - path.call(print, 'operand'), - node.openParen, - path.call(print, 'arguments'), - node.closeParen - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class YulFunctionCallExpression extends SlangNode { + operand; + + openParen; + + arguments; + + closeParen; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.operand = parse(ast.operand, parse, this.nextChildOffset); + this.openParen = ast.openParen.text; + this.arguments = parse(ast.arguments, parse, this.nextChildOffset); + this.closeParen = ast.closeParen.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + path.call(print, 'operand'), + this.openParen, + path.call(print, 'arguments'), + this.closeParen + ]; + } +} diff --git a/src/slang-nodes/YulFunctionDefinition.js b/src/slang-nodes/YulFunctionDefinition.js index e709b637a..0d21545a9 100644 --- a/src/slang-nodes/YulFunctionDefinition.js +++ b/src/slang-nodes/YulFunctionDefinition.js @@ -1,17 +1,34 @@ -export const YulFunctionDefinition = { - parse: ({ offsets, ast, options, parse }) => ({ - functionKeyword: ast.functionKeyword.text, - name: ast.name.text, - parameters: parse(ast.parameters, options, parse, offsets), - returns: ast.returns - ? parse(ast.returns, options, parse, offsets) - : undefined, - body: parse(ast.body, options, parse, offsets) - }), - print: ({ node, path, print }) => [ - `${node.functionKeyword} ${node.name}`, - path.call(print, 'parameters'), - node.returns ? path.call(print, 'returns') : ' ', - path.call(print, 'body') - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class YulFunctionDefinition extends SlangNode { + functionKeyword; + + name; + + parameters; + + returns; + + body; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.functionKeyword = ast.functionKeyword.text; + this.name = ast.name.text; + this.parameters = parse(ast.parameters, parse, this.nextChildOffset); + this.returns = ast.returns + ? parse(ast.returns, parse, this.nextChildOffset) + : undefined; + this.body = parse(ast.body, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + `${this.functionKeyword} ${this.name}`, + path.call(print, 'parameters'), + this.returns ? path.call(print, 'returns') : ' ', + path.call(print, 'body') + ]; + } +} diff --git a/src/slang-nodes/YulIfStatement.js b/src/slang-nodes/YulIfStatement.js index 03ff62ea9..95d1df0b6 100644 --- a/src/slang-nodes/YulIfStatement.js +++ b/src/slang-nodes/YulIfStatement.js @@ -1,13 +1,26 @@ -export const YulIfStatement = { - parse: ({ offsets, ast, options, parse }) => ({ - ifKeyword: ast.ifKeyword.text, - condition: parse(ast.condition, options, parse, offsets), - body: parse(ast.body, options, parse, offsets) - }), - print: ({ node, path, print }) => [ - `${node.ifKeyword} `, - path.call(print, 'condition'), - ' ', - path.call(print, 'body') - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class YulIfStatement extends SlangNode { + ifKeyword; + + condition; + + body; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.ifKeyword = ast.ifKeyword.text; + this.condition = parse(ast.condition, parse, this.nextChildOffset); + this.body = parse(ast.body, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + `${this.ifKeyword} `, + path.call(print, 'condition'), + ' ', + path.call(print, 'body') + ]; + } +} diff --git a/src/slang-nodes/YulLabel.js b/src/slang-nodes/YulLabel.js index fd469c373..3e0dbf674 100644 --- a/src/slang-nodes/YulLabel.js +++ b/src/slang-nodes/YulLabel.js @@ -1,11 +1,20 @@ import { doc } from 'prettier'; +import { SlangNode } from './SlangNode.js'; const { dedent, line } = doc.builders; +export class YulLabel extends SlangNode { + label; -export const YulLabel = { - parse: ({ ast }) => ({ - label: ast.label.text, - colon: ast.colon.text - }), - print: ({ node }) => [dedent(line), `${node.label}${node.colon}`] -}; + colon; + + constructor({ ast, offset }) { + super(ast, offset); + this.label = ast.label.text; + this.colon = ast.colon.text; + this.initiateLoc(ast); + } + + print() { + return [dedent(line), `${this.label}${this.colon}`]; + } +} diff --git a/src/slang-nodes/YulLeaveStatement.js b/src/slang-nodes/YulLeaveStatement.js index d014e23fe..289ef9ae9 100644 --- a/src/slang-nodes/YulLeaveStatement.js +++ b/src/slang-nodes/YulLeaveStatement.js @@ -1,7 +1,16 @@ -export const YulLeaveStatement = { - parse: ({ ast }) => ({ - leaveKeyword: ast.leaveKeyword.text - }), +import { SlangNode } from './SlangNode.js'; + +export class YulLeaveStatement extends SlangNode { + leaveKeyword; + + constructor({ ast, offset }) { + super(ast, offset); + this.leaveKeyword = ast.leaveKeyword.text; + this.initiateLoc(ast); + } + // TODO: implement print - print: ({ node, path, print, options }) => ['TODO: YulLeaveStatement'] -}; + print({ path, print, options }) { + return ['TODO: YulLeaveStatement']; + } +} diff --git a/src/slang-nodes/YulLiteral.js b/src/slang-nodes/YulLiteral.js index 0a2064a4d..2d0c7dce9 100644 --- a/src/slang-nodes/YulLiteral.js +++ b/src/slang-nodes/YulLiteral.js @@ -1,12 +1,20 @@ -export const YulLiteral = { - parse: ({ offsets, ast, options, parse }) => ({ - variant: +import { SlangNode } from './SlangNode.js'; + +export class YulLiteral extends SlangNode { + variant; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, options, parse, offsets) - }), - print: ({ node, path, print }) => - typeof node.variant === 'string' - ? node.variant - : path.call(print, 'variant') -}; + : parse(ast.variant, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/YulParameters.js b/src/slang-nodes/YulParameters.js index cdc084191..8a7e77306 100644 --- a/src/slang-nodes/YulParameters.js +++ b/src/slang-nodes/YulParameters.js @@ -1,9 +1,19 @@ import { printSeparatedList } from '../common/printer-helpers.js'; +import { SlangNode } from './SlangNode.js'; -export const YulParameters = { - parse: ({ ast }) => ({ - items: ast.items.map((item) => item.text), - separators: ast.separators.map((separator) => separator.text) - }), - print: ({ node }) => printSeparatedList(node.items) -}; +export class YulParameters extends SlangNode { + items; + + separators; + + constructor({ ast, offset }) { + super(ast, offset); + this.items = ast.items.map((item) => item.text); + this.separators = ast.separators.map((separator) => separator.text); + this.initiateLoc(ast); + } + + print() { + return printSeparatedList(this.items); + } +} diff --git a/src/slang-nodes/YulParametersDeclaration.js b/src/slang-nodes/YulParametersDeclaration.js index 1b2962fc0..dd8349cf5 100644 --- a/src/slang-nodes/YulParametersDeclaration.js +++ b/src/slang-nodes/YulParametersDeclaration.js @@ -1,12 +1,21 @@ -export const YulParametersDeclaration = { - parse: ({ offsets, ast, options, parse }) => ({ - openParen: ast.openParen.text, - parameters: parse(ast.parameters, options, parse, offsets), - closeParen: ast.closeParen.text - }), - print: ({ node, path, print }) => [ - node.openParen, - path.call(print, 'parameters'), - node.closeParen - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class YulParametersDeclaration extends SlangNode { + openParen; + + parameters; + + closeParen; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.openParen = ast.openParen.text; + this.parameters = parse(ast.parameters, parse, this.nextChildOffset); + this.closeParen = ast.closeParen.text; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [this.openParen, path.call(print, 'parameters'), this.closeParen]; + } +} diff --git a/src/slang-nodes/YulPath.js b/src/slang-nodes/YulPath.js index 89d1f7239..acf1a0aec 100644 --- a/src/slang-nodes/YulPath.js +++ b/src/slang-nodes/YulPath.js @@ -1,12 +1,24 @@ -export const YulPath = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)), - separators: ast.separators.map((separator) => separator.text) - }), - print: ({ node, path, print }) => - path +import { SlangNode } from './SlangNode.js'; + +export class YulPath extends SlangNode { + items; + + separators; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items.map((item) => + parse(item, parse, this.nextChildOffset) + ); + this.separators = ast.separators.map((separator) => separator.text); + this.initiateLoc(ast); + } + + print({ path, print }) { + return path .map(print, 'items') .map((item, index) => - index === 0 ? item : [node.separators[index - 1], item] - ) -}; + index === 0 ? item : [this.separators[index - 1], item] + ); + } +} diff --git a/src/slang-nodes/YulPathComponent.js b/src/slang-nodes/YulPathComponent.js index 411333dc8..8f02274c6 100644 --- a/src/slang-nodes/YulPathComponent.js +++ b/src/slang-nodes/YulPathComponent.js @@ -1,6 +1,15 @@ -export const YulPathComponent = { - parse: ({ ast }) => ({ - variant: ast.variant.text - }), - print: ({ node }) => node.variant -}; +import { SlangNode } from './SlangNode.js'; + +export class YulPathComponent extends SlangNode { + variant; + + constructor({ ast, offset }) { + super(ast, offset); + this.variant = ast.variant.text; + this.initiateLoc(ast); + } + + print() { + return this.variant; + } +} diff --git a/src/slang-nodes/YulPaths.js b/src/slang-nodes/YulPaths.js index 7506d60fc..328a8238e 100644 --- a/src/slang-nodes/YulPaths.js +++ b/src/slang-nodes/YulPaths.js @@ -1,12 +1,24 @@ -export const YulPaths = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)), - separators: ast.separators.map((separator) => separator.text) - }), - print: ({ node, path, print }) => - path +import { SlangNode } from './SlangNode.js'; + +export class YulPaths extends SlangNode { + items; + + separators; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items.map((item) => + parse(item, parse, this.nextChildOffset) + ); + this.separators = ast.separators.map((separator) => separator.text); + this.initiateLoc(ast); + } + + print({ path, print }) { + return path .map(print, 'items') .map((item, index) => - index === 0 ? item : [node.separators[index - 1], item] - ) -}; + index === 0 ? item : [this.separators[index - 1], item] + ); + } +} diff --git a/src/slang-nodes/YulReturnVariables.js b/src/slang-nodes/YulReturnVariables.js index 10093aa1a..49499d93b 100644 --- a/src/slang-nodes/YulReturnVariables.js +++ b/src/slang-nodes/YulReturnVariables.js @@ -1,16 +1,25 @@ import { doc } from 'prettier'; import { printSeparatedList } from '../common/printer-helpers.js'; +import { SlangNode } from './SlangNode.js'; const { line } = doc.builders; -export const YulReturnVariables = { - parse: ({ ast }) => ({ - items: ast.items.map((item) => item.text), - separators: ast.separators.map((separator) => separator.text) - }), - print: ({ node }) => - printSeparatedList(node.items, { +export class YulReturnVariables extends SlangNode { + items; + + separators; + + constructor({ ast, offset }) { + super(ast, offset); + this.items = ast.items.map((item) => item.text); + this.separators = ast.separators.map((separator) => separator.text); + this.initiateLoc(ast); + } + + print() { + return printSeparatedList(this.items, { firstSeparator: line, lastSeparator: '' - }) -}; + }); + } +} diff --git a/src/slang-nodes/YulReturnsDeclaration.js b/src/slang-nodes/YulReturnsDeclaration.js index d51337b97..f2f0a792f 100644 --- a/src/slang-nodes/YulReturnsDeclaration.js +++ b/src/slang-nodes/YulReturnsDeclaration.js @@ -1,15 +1,27 @@ import { doc } from 'prettier'; import { printSeparatedItem } from '../common/printer-helpers.js'; +import { SlangNode } from './SlangNode.js'; const { line } = doc.builders; -export const YulReturnsDeclaration = { - parse: ({ offsets, ast, options, parse }) => ({ - minusGreaterThan: ast.minusGreaterThan.text, - variables: parse(ast.variables, options, parse, offsets) - }), - print: ({ node, path, print }) => - printSeparatedItem([node.minusGreaterThan, path.call(print, 'variables')], { - firstSeparator: line - }) -}; +export class YulReturnsDeclaration extends SlangNode { + minusGreaterThan; + + variables; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.minusGreaterThan = ast.minusGreaterThan.text; + this.variables = parse(ast.variables, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return printSeparatedItem( + [this.minusGreaterThan, path.call(print, 'variables')], + { + firstSeparator: line + } + ); + } +} diff --git a/src/slang-nodes/YulStatement.js b/src/slang-nodes/YulStatement.js index 294a19308..82a9860e6 100644 --- a/src/slang-nodes/YulStatement.js +++ b/src/slang-nodes/YulStatement.js @@ -1,6 +1,15 @@ -export const YulStatement = { - parse: ({ offsets, ast, options, parse }) => ({ - variant: parse(ast.variant, options, parse, offsets) - }), - print: ({ path, print }) => path.call(print, 'variant') -}; +import { SlangNode } from './SlangNode.js'; + +export class YulStatement extends SlangNode { + variant; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.variant = parse(ast.variant, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/YulStatements.js b/src/slang-nodes/YulStatements.js index 96df74935..e343c5c05 100644 --- a/src/slang-nodes/YulStatements.js +++ b/src/slang-nodes/YulStatements.js @@ -4,24 +4,34 @@ import { printComments, printPreservingEmptyLines } from '../common/slang-helpers.js'; +import { SlangNode } from './SlangNode.js'; const { hardline } = doc.builders; -export const YulStatements = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)) - }), - print: ({ node, path, print, options }) => - node.items.length === 0 && (!node.comments || node.comments.length === 0) +export class YulStatements extends SlangNode { + items; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items.map((item) => + parse(item, parse, this.nextChildOffset) + ); + this.initiateLoc(ast); + } + + print({ path, print, options }) { + return this.items.length === 0 && + (!this.comments || this.comments.length === 0) ? '' : printSeparatedItem( [ printPreservingEmptyLines(path, 'items', options, print), - printComments(node, path, options) + printComments(this, path, options) ], { firstSeparator: hardline, grouped: false } - ) -}; + ); + } +} diff --git a/src/slang-nodes/YulSwitchCase.js b/src/slang-nodes/YulSwitchCase.js index f97bd724c..17567bec6 100644 --- a/src/slang-nodes/YulSwitchCase.js +++ b/src/slang-nodes/YulSwitchCase.js @@ -1,6 +1,15 @@ -export const YulSwitchCase = { - parse: ({ offsets, ast, options, parse }) => ({ - variant: parse(ast.variant, options, parse, offsets) - }), - print: ({ path, print }) => path.call(print, 'variant') -}; +import { SlangNode } from './SlangNode.js'; + +export class YulSwitchCase extends SlangNode { + variant; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.variant = parse(ast.variant, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/YulSwitchCases.js b/src/slang-nodes/YulSwitchCases.js index af7c0865a..991683e8b 100644 --- a/src/slang-nodes/YulSwitchCases.js +++ b/src/slang-nodes/YulSwitchCases.js @@ -1,10 +1,20 @@ import { doc } from 'prettier'; +import { SlangNode } from './SlangNode.js'; const { hardline, join } = doc.builders; -export const YulSwitchCases = { - parse: ({ offsets, ast, options, parse }) => ({ - items: ast.items.map((item) => parse(item, options, parse, offsets)) - }), - print: ({ path, print }) => join(hardline, path.map(print, 'items')) -}; +export class YulSwitchCases extends SlangNode { + items; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.items = ast.items.map((item) => + parse(item, parse, this.nextChildOffset) + ); + this.initiateLoc(ast); + } + + print({ path, print }) { + return join(hardline, path.map(print, 'items')); + } +} diff --git a/src/slang-nodes/YulSwitchStatement.js b/src/slang-nodes/YulSwitchStatement.js index 83776dc4c..a2fad14cf 100644 --- a/src/slang-nodes/YulSwitchStatement.js +++ b/src/slang-nodes/YulSwitchStatement.js @@ -1,17 +1,29 @@ import { doc } from 'prettier'; +import { SlangNode } from './SlangNode.js'; const { hardline } = doc.builders; -export const YulSwitchStatement = { - parse: ({ offsets, ast, options, parse }) => ({ - switchKeyword: ast.switchKeyword.text, - expression: parse(ast.expression, options, parse, offsets), - cases: parse(ast.cases, options, parse, offsets) - }), - print: ({ node, path, print }) => [ - `${node.switchKeyword} `, - path.call(print, 'expression'), - hardline, - path.call(print, 'cases') - ] -}; +export class YulSwitchStatement extends SlangNode { + switchKeyword; + + expression; + + cases; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.switchKeyword = ast.switchKeyword.text; + this.expression = parse(ast.expression, parse, this.nextChildOffset); + this.cases = parse(ast.cases, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + `${this.switchKeyword} `, + path.call(print, 'expression'), + hardline, + path.call(print, 'cases') + ]; + } +} diff --git a/src/slang-nodes/YulValueCase.js b/src/slang-nodes/YulValueCase.js index 6b4a27f40..b7e3bcafc 100644 --- a/src/slang-nodes/YulValueCase.js +++ b/src/slang-nodes/YulValueCase.js @@ -1,13 +1,26 @@ -export const YulValueCase = { - parse: ({ offsets, ast, options, parse }) => ({ - caseKeyword: ast.caseKeyword.text, - value: parse(ast.value, options, parse, offsets), - body: parse(ast.body, options, parse, offsets) - }), - print: ({ node, path, print }) => [ - `${node.caseKeyword} `, - path.call(print, 'value'), - ' ', - path.call(print, 'body') - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class YulValueCase extends SlangNode { + caseKeyword; + + value; + + body; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.caseKeyword = ast.caseKeyword.text; + this.value = parse(ast.value, parse, this.nextChildOffset); + this.body = parse(ast.body, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + `${this.caseKeyword} `, + path.call(print, 'value'), + ' ', + path.call(print, 'body') + ]; + } +} diff --git a/src/slang-nodes/YulVariableAssignmentStatement.js b/src/slang-nodes/YulVariableAssignmentStatement.js index 01f0dffc7..6169c1778 100644 --- a/src/slang-nodes/YulVariableAssignmentStatement.js +++ b/src/slang-nodes/YulVariableAssignmentStatement.js @@ -1,14 +1,27 @@ -export const YulVariableAssignmentStatement = { - parse: ({ offsets, ast, options, parse }) => ({ - names: parse(ast.names, options, parse, offsets), - assignment: parse(ast.assignment, options, parse, offsets), - expression: parse(ast.expression, options, parse, offsets) - }), - print: ({ path, print }) => [ - path.call(print, 'names'), - ' ', - path.call(print, 'assignment'), - ' ', - path.call(print, 'expression') - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class YulVariableAssignmentStatement extends SlangNode { + names; + + assignment; + + expression; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.names = parse(ast.names, parse, this.nextChildOffset); + this.assignment = parse(ast.assignment, parse, this.nextChildOffset); + this.expression = parse(ast.expression, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + path.call(print, 'names'), + ' ', + path.call(print, 'assignment'), + ' ', + path.call(print, 'expression') + ]; + } +} diff --git a/src/slang-nodes/YulVariableDeclarationStatement.js b/src/slang-nodes/YulVariableDeclarationStatement.js index 9a42670fc..bdc5abf34 100644 --- a/src/slang-nodes/YulVariableDeclarationStatement.js +++ b/src/slang-nodes/YulVariableDeclarationStatement.js @@ -1,11 +1,26 @@ -export const YulVariableDeclarationStatement = { - parse: ({ offsets, ast, options, parse }) => ({ - letKeyword: ast.letKeyword.text, - names: ast.names.text, - value: ast.value ? parse(ast.value, options, parse, offsets) : undefined - }), - print: ({ node, path, print }) => [ - `${node.letKeyword} ${node.names} `, - node.value ? path.call(print, 'value') : '' - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class YulVariableDeclarationStatement extends SlangNode { + letKeyword; + + names; + + value; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.letKeyword = ast.letKeyword.text; + this.names = ast.names.text; + this.value = ast.value + ? parse(ast.value, parse, this.nextChildOffset) + : undefined; + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + `${this.letKeyword} ${this.names} `, + this.value ? path.call(print, 'value') : '' + ]; + } +} diff --git a/src/slang-nodes/YulVariableDeclarationValue.js b/src/slang-nodes/YulVariableDeclarationValue.js index b9634dac0..556558094 100644 --- a/src/slang-nodes/YulVariableDeclarationValue.js +++ b/src/slang-nodes/YulVariableDeclarationValue.js @@ -1,11 +1,22 @@ -export const YulVariableDeclarationValue = { - parse: ({ offsets, ast, options, parse }) => ({ - assignment: parse(ast.assignment, options, parse, offsets), - expression: parse(ast.expression, options, parse, offsets) - }), - print: ({ path, print }) => [ - path.call(print, 'assignment'), - ' ', - path.call(print, 'expression') - ] -}; +import { SlangNode } from './SlangNode.js'; + +export class YulVariableDeclarationValue extends SlangNode { + assignment; + + expression; + + constructor({ ast, parse, offset, options }) { + super(ast, offset); + this.assignment = parse(ast.assignment, parse, this.nextChildOffset); + this.expression = parse(ast.expression, parse, this.nextChildOffset); + this.initiateLoc(ast); + } + + print({ path, print }) { + return [ + path.call(print, 'assignment'), + ' ', + path.call(print, 'expression') + ]; + } +} diff --git a/src/slang-utils/create-hug-function.js b/src/slang-utils/create-hug-function.js new file mode 100644 index 000000000..83fa9c690 --- /dev/null +++ b/src/slang-utils/create-hug-function.js @@ -0,0 +1,35 @@ +import { isBinaryOperation } from '../common/slang-helpers.js'; +import { Expression } from '../slang-nodes/Expression.js'; +import { TupleExpression } from '../slang-nodes/TupleExpression.js'; +import { TupleValues } from '../slang-nodes/TupleValues.js'; +import { TupleValue } from '../slang-nodes/TupleValue.js'; + +export function createHugFunction(huggableOperators) { + const operators = new Set(huggableOperators); + return (node) => { + if (isBinaryOperation(node.variant) && operators.has(node.variant.operator)) + return new Expression({ + kind: 'Expression', + loc: { ...node.loc }, + variant: new TupleExpression({ + kind: 'TupleExpression', + loc: { ...node.loc }, + openParen: '(', + items: new TupleValues({ + kind: 'TupleValues', + loc: { ...node.loc }, + items: [ + new TupleValue({ + kind: 'TupleValue', + loc: { ...node.loc }, + expression: node + }) + ], + separators: [] + }), + closeParen: ')' + }) + }); + return node; + }; +} diff --git a/src/slangParser.js b/src/slangParser.js index 513b7155e..006b22aa2 100644 --- a/src/slangParser.js +++ b/src/slangParser.js @@ -5,129 +5,16 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SourceUnit } from '@nomicfoundation/slang/ast/index.js'; import coerce from 'semver/functions/coerce.js'; import * as parsers from './slang-nodes/index.js'; -import { isComment } from './common/slang-helpers.js'; -const comments = []; -const getOffsets = (children, initialOffset) => { - let offset = initialOffset; - - const offsets = children.reduce((offsetsArray, child) => { - if (child.type === 'Nonterminal') { - offsetsArray.push(offset); - } - if (child.type === 'Terminal' && isComment(child)) { - // Since the fetching the comments and calculating offsets are both done - // as we iterate over the children and the comment also depends on the - // offset, it's hard to separate these responsibilities into different - // functions. - comments.push({ - kind: child.kind, - value: child.text, - loc: { - start: offset, - end: offset + child.textLength.utf8 - } - }); - } - - offset += child.textLength.utf8; - return offsetsArray; - }, []); - return offsets; -}; - -const getLeadingOffset = (children) => { - let offset = 0; - for (let i = 0; i < children.length; i += 1) { - const child = children[i]; - if (child.type === 'Nonterminal') { - // The node's content starts when we find the first non-terminal, - // non-comment, non-whitespace token. - return offset; - } - if ( - child.type === 'Terminal' && - !isComment(child) && - child.kind !== 'EndOfLine' && - child.kind !== 'Whitespace' - ) { - // The content of the node started if we find a non-comment, - // non-whitespace token. - return offset; - } - offset += child.textLength.utf8; - } - return offset; -}; -const getTrailingOffset = (children) => getLeadingOffset(children.reverse()); - -function genericParse(ast, options, parseFunction, parentOffsets = [0]) { - const offset = parentOffsets.shift(); - const children = ast.cst.children(); - const offsets = getOffsets(children, offset); - - const node = parsers[ast.cst.kind].parse({ - offsets, - ast, - options, - parse: parseFunction - }); - - /** - * Leading and trailing Comments are considered by the parser as part of the - * innermost possible node. For example if there is a comment just before a - * variable assignment, the parser will consider the comment belongs to the - * variable name instead of the whole statement. - * - * This behaviour creates erratic outcomes when the new line of a - * SingleLineComment can trigger a group break or a prettier-ignore will - * apply to a subset of the intended nodes. - * - * ```Solidity - * // prettier-ignore - * matrix = [ - * 0, 1, 2, - * 3, 4, 5, - * 6, 7, 8 - * ]; - * ``` - */ - let leadingOffset = getLeadingOffset(children); - let trailingOffset = getTrailingOffset(children); - const startWithTrivia = offset; - const endWithTrivia = offset + ast.cst.textLength.utf8; - - if (leadingOffset === 0 || trailingOffset === 0) { - const childrenKeys = Object.keys(node); - - for (let i = 0; i < childrenKeys.length; i += 1) { - const childLoc = node[childrenKeys[i]]?.loc; - - if (childLoc) { - if ( - leadingOffset === 0 && - childLoc.startWithTrivia === startWithTrivia - ) { - leadingOffset = childLoc.start - startWithTrivia; - } - - if (trailingOffset === 0 && childLoc.endWithTrivia === endWithTrivia) { - trailingOffset = endWithTrivia - childLoc.end; - } - } - } - } - - node.kind = ast.cst.kind; - node.loc = { - startWithTrivia, - start: startWithTrivia + leadingOffset, - endWithTrivia, - end: endWithTrivia - trailingOffset - }; - - return node; -} +const genericParseBuilder = + (options) => + (ast, parseFunction, offset = 0) => + new parsers[ast.cst.kind]({ + ast, + options, + parse: parseFunction, + offset + }); function parse(text, _parsers, options = _parsers) { const compiler = coerce(options.compiler); @@ -137,8 +24,11 @@ function parse(text, _parsers, options = _parsers) { language.parse(NonterminalKind.SourceUnit, text).tree() ); - const parsed = genericParse(ast, options, genericParse); - parsed.comments = comments.splice(0); + const genericParse = genericParseBuilder(options); + const parsed = genericParse(ast, genericParse); + + parsed.collectComments(); + return parsed; } diff --git a/src/slangPrinter.js b/src/slangPrinter.js index 62579359d..32f66791c 100644 --- a/src/slangPrinter.js +++ b/src/slangPrinter.js @@ -38,8 +38,16 @@ function genericPrint(path, options, print) { options.locEnd(node) ); } - - return nodes[nodeType].print({ node, options, path, print }); + let ret; + try { + ret = node.print({ options, path, print }); + if (typeof ret === 'undefined') { + console.log(nodeType); + } + } catch (error) { + throw new Error(`${JSON.stringify(node)} ${error}\n`); + } + return ret; } export default genericPrint; From 128f27a9d6b9777e212fedca473eb4be100c2edb Mon Sep 17 00:00:00 2001 From: Klaus Date: Sun, 14 Jul 2024 01:41:36 +1200 Subject: [PATCH 065/160] changing constructor signature --- src/slang-nodes/ABICoderPragma.js | 2 +- src/slang-nodes/AdditiveExpression.js | 2 +- src/slang-nodes/AddressType.js | 2 +- src/slang-nodes/AndExpression.js | 2 +- src/slang-nodes/ArgumentsDeclaration.js | 2 +- src/slang-nodes/ArrayExpression.js | 2 +- src/slang-nodes/ArrayTypeName.js | 2 +- src/slang-nodes/ArrayValues.js | 2 +- src/slang-nodes/AssemblyFlags.js | 2 +- src/slang-nodes/AssemblyFlagsDeclaration.js | 2 +- src/slang-nodes/AssemblyStatement.js | 2 +- src/slang-nodes/AssignmentExpression.js | 2 +- src/slang-nodes/BitwiseAndExpression.js | 2 +- src/slang-nodes/BitwiseOrExpression.js | 2 +- src/slang-nodes/BitwiseXorExpression.js | 2 +- src/slang-nodes/Block.js | 2 +- src/slang-nodes/BreakStatement.js | 2 +- src/slang-nodes/CallOptions.js | 2 +- src/slang-nodes/CallOptionsExpression.js | 2 +- src/slang-nodes/CatchClause.js | 2 +- src/slang-nodes/CatchClauseError.js | 2 +- src/slang-nodes/CatchClauses.js | 2 +- src/slang-nodes/ComparisonExpression.js | 2 +- src/slang-nodes/ConditionalExpression.js | 2 +- src/slang-nodes/ConstantDefinition.js | 2 +- src/slang-nodes/ConstructorAttribute.js | 2 +- src/slang-nodes/ConstructorAttributes.js | 2 +- src/slang-nodes/ConstructorDefinition.js | 2 +- src/slang-nodes/ContinueStatement.js | 2 +- src/slang-nodes/ContractDefinition.js | 2 +- src/slang-nodes/ContractMember.js | 2 +- src/slang-nodes/ContractMembers.js | 2 +- src/slang-nodes/DecimalNumberExpression.js | 2 +- src/slang-nodes/DoWhileStatement.js | 2 +- src/slang-nodes/ElementaryType.js | 2 +- src/slang-nodes/ElseBranch.js | 2 +- src/slang-nodes/EmitStatement.js | 2 +- src/slang-nodes/EnumDefinition.js | 2 +- src/slang-nodes/EnumMembers.js | 2 +- src/slang-nodes/EqualityExpression.js | 2 +- src/slang-nodes/ErrorDefinition.js | 2 +- src/slang-nodes/ErrorParameter.js | 2 +- src/slang-nodes/ErrorParameters.js | 2 +- src/slang-nodes/ErrorParametersDeclaration.js | 2 +- src/slang-nodes/EventDefinition.js | 2 +- src/slang-nodes/EventParameter.js | 2 +- src/slang-nodes/EventParameters.js | 2 +- src/slang-nodes/EventParametersDeclaration.js | 2 +- src/slang-nodes/ExperimentalFeature.js | 8 ++----- src/slang-nodes/ExperimentalPragma.js | 10 ++++---- src/slang-nodes/ExponentiationExpression.js | 24 ++++++------------- src/slang-nodes/Expression.js | 10 ++++---- src/slang-nodes/ExpressionStatement.js | 2 +- src/slang-nodes/FallbackFunctionAttribute.js | 2 +- src/slang-nodes/FallbackFunctionAttributes.js | 2 +- src/slang-nodes/FallbackFunctionDefinition.js | 2 +- src/slang-nodes/ForStatement.js | 2 +- src/slang-nodes/ForStatementCondition.js | 2 +- src/slang-nodes/ForStatementInitialization.js | 2 +- src/slang-nodes/FunctionAttribute.js | 2 +- src/slang-nodes/FunctionAttributes.js | 2 +- src/slang-nodes/FunctionBody.js | 2 +- src/slang-nodes/FunctionCallExpression.js | 2 +- src/slang-nodes/FunctionDefinition.js | 2 +- src/slang-nodes/FunctionName.js | 2 +- src/slang-nodes/FunctionType.js | 2 +- src/slang-nodes/FunctionTypeAttribute.js | 2 +- src/slang-nodes/FunctionTypeAttributes.js | 2 +- src/slang-nodes/HexNumberExpression.js | 2 +- src/slang-nodes/HexStringLiteral.js | 2 +- src/slang-nodes/HexStringLiterals.js | 2 +- src/slang-nodes/IdentifierPath.js | 2 +- src/slang-nodes/IfStatement.js | 2 +- src/slang-nodes/ImportAlias.js | 2 +- src/slang-nodes/ImportClause.js | 2 +- src/slang-nodes/ImportDeconstruction.js | 2 +- src/slang-nodes/ImportDeconstructionSymbol.js | 2 +- .../ImportDeconstructionSymbols.js | 2 +- src/slang-nodes/ImportDirective.js | 2 +- src/slang-nodes/IndexAccessEnd.js | 2 +- src/slang-nodes/IndexAccessExpression.js | 2 +- src/slang-nodes/InheritanceSpecifier.js | 2 +- src/slang-nodes/InheritanceType.js | 2 +- src/slang-nodes/InheritanceTypes.js | 2 +- src/slang-nodes/InterfaceDefinition.js | 2 +- src/slang-nodes/InterfaceMembers.js | 2 +- src/slang-nodes/LibraryDefinition.js | 2 +- src/slang-nodes/LibraryMembers.js | 2 +- src/slang-nodes/MappingKey.js | 2 +- src/slang-nodes/MappingKeyType.js | 2 +- src/slang-nodes/MappingType.js | 2 +- src/slang-nodes/MappingValue.js | 2 +- src/slang-nodes/MemberAccess.js | 2 +- src/slang-nodes/MemberAccessExpression.js | 2 +- src/slang-nodes/ModifierAttribute.js | 2 +- src/slang-nodes/ModifierAttributes.js | 2 +- src/slang-nodes/ModifierDefinition.js | 2 +- src/slang-nodes/ModifierInvocation.js | 2 +- src/slang-nodes/MultiplicativeExpression.js | 2 +- src/slang-nodes/NamedArgument.js | 2 +- src/slang-nodes/NamedArgumentGroup.js | 2 +- src/slang-nodes/NamedArguments.js | 2 +- src/slang-nodes/NamedArgumentsDeclaration.js | 2 +- src/slang-nodes/NamedImport.js | 2 +- src/slang-nodes/NewExpression.js | 2 +- src/slang-nodes/NumberUnit.js | 2 +- src/slang-nodes/OrExpression.js | 2 +- src/slang-nodes/OverridePaths.js | 2 +- src/slang-nodes/OverridePathsDeclaration.js | 2 +- src/slang-nodes/OverrideSpecifier.js | 2 +- src/slang-nodes/Parameter.js | 2 +- src/slang-nodes/Parameters.js | 12 +++++----- src/slang-nodes/ParametersDeclaration.js | 23 ++++++------------ src/slang-nodes/PathImport.js | 2 +- src/slang-nodes/PositionalArguments.js | 2 +- .../PositionalArgumentsDeclaration.js | 2 +- src/slang-nodes/PostfixExpression.js | 2 +- src/slang-nodes/Pragma.js | 11 +++++---- src/slang-nodes/PragmaDirective.js | 9 ++----- src/slang-nodes/PrefixExpression.js | 2 +- src/slang-nodes/ReceiveFunctionAttribute.js | 2 +- src/slang-nodes/ReceiveFunctionAttributes.js | 2 +- src/slang-nodes/ReceiveFunctionDefinition.js | 2 +- src/slang-nodes/ReturnStatement.js | 2 +- src/slang-nodes/ReturnsDeclaration.js | 2 +- src/slang-nodes/RevertStatement.js | 2 +- src/slang-nodes/ShiftExpression.js | 2 +- src/slang-nodes/SlangNode.js | 2 +- src/slang-nodes/SourceUnit.js | 10 ++++---- src/slang-nodes/SourceUnitMember.js | 10 ++++---- src/slang-nodes/SourceUnitMembers.js | 10 ++------ src/slang-nodes/StateVariableAttribute.js | 2 +- src/slang-nodes/StateVariableAttributes.js | 2 +- src/slang-nodes/StateVariableDefinition.js | 2 +- .../StateVariableDefinitionValue.js | 2 +- src/slang-nodes/Statement.js | 2 +- src/slang-nodes/Statements.js | 2 +- src/slang-nodes/StorageLocation.js | 2 +- src/slang-nodes/StringExpression.js | 2 +- src/slang-nodes/StringLiteral.js | 2 +- src/slang-nodes/StringLiterals.js | 2 +- src/slang-nodes/StructDefinition.js | 2 +- src/slang-nodes/StructMember.js | 2 +- src/slang-nodes/StructMembers.js | 2 +- src/slang-nodes/ThrowStatement.js | 2 +- src/slang-nodes/TryStatement.js | 2 +- src/slang-nodes/TupleDeconstructionElement.js | 2 +- .../TupleDeconstructionElements.js | 2 +- .../TupleDeconstructionStatement.js | 2 +- src/slang-nodes/TupleExpression.js | 14 +++++------ src/slang-nodes/TupleMember.js | 2 +- src/slang-nodes/TupleValue.js | 10 ++++---- src/slang-nodes/TupleValues.js | 12 +++++----- src/slang-nodes/TypeExpression.js | 2 +- src/slang-nodes/TypeName.js | 2 +- src/slang-nodes/TypedTupleMember.js | 2 +- src/slang-nodes/UncheckedBlock.js | 2 +- src/slang-nodes/UnicodeStringLiteral.js | 2 +- src/slang-nodes/UnicodeStringLiterals.js | 2 +- src/slang-nodes/UnnamedFunctionAttribute.js | 2 +- src/slang-nodes/UnnamedFunctionAttributes.js | 2 +- src/slang-nodes/UnnamedFunctionDefinition.js | 2 +- src/slang-nodes/UntypedTupleMember.js | 2 +- .../UserDefinedValueTypeDefinition.js | 2 +- src/slang-nodes/UsingAlias.js | 2 +- src/slang-nodes/UsingClause.js | 2 +- src/slang-nodes/UsingDeconstruction.js | 2 +- src/slang-nodes/UsingDeconstructionSymbol.js | 2 +- src/slang-nodes/UsingDeconstructionSymbols.js | 2 +- src/slang-nodes/UsingDirective.js | 2 +- src/slang-nodes/UsingOperator.js | 2 +- src/slang-nodes/UsingTarget.js | 2 +- .../VariableDeclarationStatement.js | 2 +- src/slang-nodes/VariableDeclarationType.js | 2 +- src/slang-nodes/VariableDeclarationValue.js | 2 +- src/slang-nodes/VersionComparator.js | 2 +- src/slang-nodes/VersionExpression.js | 2 +- src/slang-nodes/VersionExpressionSet.js | 2 +- src/slang-nodes/VersionExpressionSets.js | 2 +- src/slang-nodes/VersionPragma.js | 2 +- src/slang-nodes/VersionRange.js | 2 +- src/slang-nodes/VersionSpecifiers.js | 2 +- src/slang-nodes/WhileStatement.js | 2 +- src/slang-nodes/YulArguments.js | 2 +- src/slang-nodes/YulAssignmentOperator.js | 2 +- src/slang-nodes/YulAssignmentStatement.js | 2 +- src/slang-nodes/YulBlock.js | 2 +- src/slang-nodes/YulBreakStatement.js | 2 +- src/slang-nodes/YulBuiltInFunction.js | 2 +- src/slang-nodes/YulColonAndEqual.js | 2 +- src/slang-nodes/YulContinueStatement.js | 2 +- src/slang-nodes/YulDefaultCase.js | 2 +- src/slang-nodes/YulExpression.js | 2 +- src/slang-nodes/YulForStatement.js | 2 +- src/slang-nodes/YulFunctionCallExpression.js | 2 +- src/slang-nodes/YulFunctionDefinition.js | 2 +- src/slang-nodes/YulIfStatement.js | 2 +- src/slang-nodes/YulLabel.js | 2 +- src/slang-nodes/YulLeaveStatement.js | 2 +- src/slang-nodes/YulLiteral.js | 2 +- src/slang-nodes/YulParameters.js | 2 +- src/slang-nodes/YulParametersDeclaration.js | 2 +- src/slang-nodes/YulPath.js | 2 +- src/slang-nodes/YulPathComponent.js | 2 +- src/slang-nodes/YulPaths.js | 2 +- src/slang-nodes/YulReturnVariables.js | 2 +- src/slang-nodes/YulReturnsDeclaration.js | 2 +- src/slang-nodes/YulStatement.js | 2 +- src/slang-nodes/YulStatements.js | 2 +- src/slang-nodes/YulSwitchCase.js | 2 +- src/slang-nodes/YulSwitchCases.js | 2 +- src/slang-nodes/YulSwitchStatement.js | 2 +- src/slang-nodes/YulValueCase.js | 2 +- .../YulVariableAssignmentStatement.js | 2 +- .../YulVariableDeclarationStatement.js | 2 +- .../YulVariableDeclarationValue.js | 2 +- src/slangParser.js | 7 +----- src/slangPrinter.js | 2 +- tests/config/run-format-test.js | 2 +- 219 files changed, 275 insertions(+), 313 deletions(-) diff --git a/src/slang-nodes/ABICoderPragma.js b/src/slang-nodes/ABICoderPragma.js index 70509921b..f4b577b43 100644 --- a/src/slang-nodes/ABICoderPragma.js +++ b/src/slang-nodes/ABICoderPragma.js @@ -5,7 +5,7 @@ export class ABICoderPragma extends SlangNode { version; - constructor({ ast, offset }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.abicoderKeyword = ast.abicoderKeyword.text; this.version = ast.version.text; diff --git a/src/slang-nodes/AdditiveExpression.js b/src/slang-nodes/AdditiveExpression.js index 26cc22400..22c99d5d0 100644 --- a/src/slang-nodes/AdditiveExpression.js +++ b/src/slang-nodes/AdditiveExpression.js @@ -11,7 +11,7 @@ export class AdditiveExpression extends SlangNode { rightOperand; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.leftOperand = tryToHug( parse(ast.leftOperand, parse, this.nextChildOffset) diff --git a/src/slang-nodes/AddressType.js b/src/slang-nodes/AddressType.js index 5fda9e012..8bcf5919c 100644 --- a/src/slang-nodes/AddressType.js +++ b/src/slang-nodes/AddressType.js @@ -5,7 +5,7 @@ export class AddressType extends SlangNode { payableKeyword; - constructor({ ast, offset }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.addressKeyword = ast.addressKeyword.text; this.payableKeyword = ast.payableKeyword?.text; diff --git a/src/slang-nodes/AndExpression.js b/src/slang-nodes/AndExpression.js index db21004dd..6d9718120 100644 --- a/src/slang-nodes/AndExpression.js +++ b/src/slang-nodes/AndExpression.js @@ -8,7 +8,7 @@ export class AndExpression extends SlangNode { rightOperand; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.leftOperand = parse(ast.leftOperand, parse, this.nextChildOffset); this.operator = ast.operator.text; diff --git a/src/slang-nodes/ArgumentsDeclaration.js b/src/slang-nodes/ArgumentsDeclaration.js index dbf77dc9e..8927bd752 100644 --- a/src/slang-nodes/ArgumentsDeclaration.js +++ b/src/slang-nodes/ArgumentsDeclaration.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class ArgumentsDeclaration extends SlangNode { variant; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = parse(ast.variant, parse, this.nextChildOffset); this.initiateLoc(ast); diff --git a/src/slang-nodes/ArrayExpression.js b/src/slang-nodes/ArrayExpression.js index cfccb0d50..f45472f98 100644 --- a/src/slang-nodes/ArrayExpression.js +++ b/src/slang-nodes/ArrayExpression.js @@ -10,7 +10,7 @@ export class ArrayExpression extends SlangNode { closeBracket; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.openBracket = ast.openBracket.text; this.items = parse(ast.items, parse, this.nextChildOffset); diff --git a/src/slang-nodes/ArrayTypeName.js b/src/slang-nodes/ArrayTypeName.js index 26a0ec0b7..174018c77 100644 --- a/src/slang-nodes/ArrayTypeName.js +++ b/src/slang-nodes/ArrayTypeName.js @@ -9,7 +9,7 @@ export class ArrayTypeName extends SlangNode { closeBracket; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.operand = parse(ast.operand, parse, this.nextChildOffset); this.openBracket = ast.openBracket.text; diff --git a/src/slang-nodes/ArrayValues.js b/src/slang-nodes/ArrayValues.js index 1ce5079a9..87a2d3831 100644 --- a/src/slang-nodes/ArrayValues.js +++ b/src/slang-nodes/ArrayValues.js @@ -6,7 +6,7 @@ export class ArrayValues extends SlangNode { separators; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/AssemblyFlags.js b/src/slang-nodes/AssemblyFlags.js index c0c87c01e..3395f4391 100644 --- a/src/slang-nodes/AssemblyFlags.js +++ b/src/slang-nodes/AssemblyFlags.js @@ -6,7 +6,7 @@ export class AssemblyFlags extends SlangNode { separators; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/AssemblyFlagsDeclaration.js b/src/slang-nodes/AssemblyFlagsDeclaration.js index b7504cfcf..d067ef05c 100644 --- a/src/slang-nodes/AssemblyFlagsDeclaration.js +++ b/src/slang-nodes/AssemblyFlagsDeclaration.js @@ -7,7 +7,7 @@ export class AssemblyFlagsDeclaration extends SlangNode { closeParen; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.openParen = ast.openParen.text; this.flags = parse(ast.flags, parse, this.nextChildOffset); diff --git a/src/slang-nodes/AssemblyStatement.js b/src/slang-nodes/AssemblyStatement.js index b79024460..964e4b64b 100644 --- a/src/slang-nodes/AssemblyStatement.js +++ b/src/slang-nodes/AssemblyStatement.js @@ -9,7 +9,7 @@ export class AssemblyStatement extends SlangNode { body; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.assemblyKeyword = ast.assemblyKeyword.text; this.label = ast.label diff --git a/src/slang-nodes/AssignmentExpression.js b/src/slang-nodes/AssignmentExpression.js index 5730bc8b8..0a3529f36 100644 --- a/src/slang-nodes/AssignmentExpression.js +++ b/src/slang-nodes/AssignmentExpression.js @@ -11,7 +11,7 @@ export class AssignmentExpression extends SlangNode { rightOperand; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.leftOperand = parse(ast.leftOperand, parse, this.nextChildOffset); this.operator = ast.operator.text; diff --git a/src/slang-nodes/BitwiseAndExpression.js b/src/slang-nodes/BitwiseAndExpression.js index 7a289727a..3696e30e0 100644 --- a/src/slang-nodes/BitwiseAndExpression.js +++ b/src/slang-nodes/BitwiseAndExpression.js @@ -11,7 +11,7 @@ export class BitwiseAndExpression extends SlangNode { rightOperand; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.leftOperand = tryToHug( parse(ast.leftOperand, parse, this.nextChildOffset) diff --git a/src/slang-nodes/BitwiseOrExpression.js b/src/slang-nodes/BitwiseOrExpression.js index 7a8c8784a..fa820c145 100644 --- a/src/slang-nodes/BitwiseOrExpression.js +++ b/src/slang-nodes/BitwiseOrExpression.js @@ -21,7 +21,7 @@ export class BitwiseOrExpression extends SlangNode { rightOperand; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.leftOperand = tryToHug( parse(ast.leftOperand, parse, this.nextChildOffset) diff --git a/src/slang-nodes/BitwiseXorExpression.js b/src/slang-nodes/BitwiseXorExpression.js index c26068396..d98e44101 100644 --- a/src/slang-nodes/BitwiseXorExpression.js +++ b/src/slang-nodes/BitwiseXorExpression.js @@ -11,7 +11,7 @@ export class BitwiseXorExpression extends SlangNode { rightOperand; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.leftOperand = tryToHug( parse(ast.leftOperand, parse, this.nextChildOffset) diff --git a/src/slang-nodes/Block.js b/src/slang-nodes/Block.js index 7dc7d854e..7d4a41af7 100644 --- a/src/slang-nodes/Block.js +++ b/src/slang-nodes/Block.js @@ -7,7 +7,7 @@ export class Block extends SlangNode { closeBrace; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.openBrace = ast.openBrace.text; this.statements = parse(ast.statements, parse, this.nextChildOffset); diff --git a/src/slang-nodes/BreakStatement.js b/src/slang-nodes/BreakStatement.js index 5f37ef41f..bb119408c 100644 --- a/src/slang-nodes/BreakStatement.js +++ b/src/slang-nodes/BreakStatement.js @@ -5,7 +5,7 @@ export class BreakStatement extends SlangNode { semicolon; - constructor({ ast, offset }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.breakKeyword = ast.breakKeyword.text; this.semicolon = ast.semicolon.text; diff --git a/src/slang-nodes/CallOptions.js b/src/slang-nodes/CallOptions.js index aee87eebf..56e440bde 100644 --- a/src/slang-nodes/CallOptions.js +++ b/src/slang-nodes/CallOptions.js @@ -9,7 +9,7 @@ export class CallOptions extends SlangNode { separators; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/CallOptionsExpression.js b/src/slang-nodes/CallOptionsExpression.js index 0d11b3335..1b840d7de 100644 --- a/src/slang-nodes/CallOptionsExpression.js +++ b/src/slang-nodes/CallOptionsExpression.js @@ -9,7 +9,7 @@ export class CallOptionsExpression extends SlangNode { closeBrace; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.operand = parse(ast.operand, parse, this.nextChildOffset); this.openBrace = ast.openBrace.text; diff --git a/src/slang-nodes/CatchClause.js b/src/slang-nodes/CatchClause.js index 3044f2b44..2f857fbca 100644 --- a/src/slang-nodes/CatchClause.js +++ b/src/slang-nodes/CatchClause.js @@ -7,7 +7,7 @@ export class CatchClause extends SlangNode { body; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.catchKeyword = ast.catchKeyword.text; this.error = ast.error diff --git a/src/slang-nodes/CatchClauseError.js b/src/slang-nodes/CatchClauseError.js index b83cb5630..d84641028 100644 --- a/src/slang-nodes/CatchClauseError.js +++ b/src/slang-nodes/CatchClauseError.js @@ -8,7 +8,7 @@ export class CatchClauseError extends SlangNode { parameters; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.name = ast.name?.text ?? ''; this.parameters = parse(ast.parameters, parse, this.nextChildOffset); diff --git a/src/slang-nodes/CatchClauses.js b/src/slang-nodes/CatchClauses.js index a1788e88c..c641bed9a 100644 --- a/src/slang-nodes/CatchClauses.js +++ b/src/slang-nodes/CatchClauses.js @@ -6,7 +6,7 @@ const { join } = doc.builders; export class CatchClauses extends SlangNode { items; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/ComparisonExpression.js b/src/slang-nodes/ComparisonExpression.js index 6a8751dd2..cf3b2f2b0 100644 --- a/src/slang-nodes/ComparisonExpression.js +++ b/src/slang-nodes/ComparisonExpression.js @@ -8,7 +8,7 @@ export class ComparisonExpression extends SlangNode { rightOperand; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.leftOperand = parse(ast.leftOperand, parse, this.nextChildOffset); this.operator = ast.operator.text; diff --git a/src/slang-nodes/ConditionalExpression.js b/src/slang-nodes/ConditionalExpression.js index e9260f4db..8c8a91427 100644 --- a/src/slang-nodes/ConditionalExpression.js +++ b/src/slang-nodes/ConditionalExpression.js @@ -97,7 +97,7 @@ export class ConditionalExpression extends SlangNode { falseExpression; - constructor({ ast, options, parse, offset }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.operand = parse(ast.operand, parse, this.nextChildOffset); diff --git a/src/slang-nodes/ConstantDefinition.js b/src/slang-nodes/ConstantDefinition.js index 91872e854..fe514710f 100644 --- a/src/slang-nodes/ConstantDefinition.js +++ b/src/slang-nodes/ConstantDefinition.js @@ -13,7 +13,7 @@ export class ConstantDefinition extends SlangNode { semicolon; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.typeName = parse(ast.typeName, parse, this.nextChildOffset); this.constantKeyword = ast.constantKeyword.text; diff --git a/src/slang-nodes/ConstructorAttribute.js b/src/slang-nodes/ConstructorAttribute.js index e7c137627..2f3911083 100644 --- a/src/slang-nodes/ConstructorAttribute.js +++ b/src/slang-nodes/ConstructorAttribute.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class ConstructorAttribute extends SlangNode { variant; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = ast.variant.type === 'Terminal' diff --git a/src/slang-nodes/ConstructorAttributes.js b/src/slang-nodes/ConstructorAttributes.js index dbe711795..0f0385e41 100644 --- a/src/slang-nodes/ConstructorAttributes.js +++ b/src/slang-nodes/ConstructorAttributes.js @@ -7,7 +7,7 @@ const { line } = doc.builders; export class ConstructorAttributes extends SlangNode { items; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items .map((item) => parse(item, parse, this.nextChildOffset)) diff --git a/src/slang-nodes/ConstructorDefinition.js b/src/slang-nodes/ConstructorDefinition.js index d5f5452be..9ae919813 100644 --- a/src/slang-nodes/ConstructorDefinition.js +++ b/src/slang-nodes/ConstructorDefinition.js @@ -10,7 +10,7 @@ export class ConstructorDefinition extends SlangNode { body; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.constructorKeyword = ast.constructorKeyword.text; this.parameters = parse(ast.parameters, parse, this.nextChildOffset); diff --git a/src/slang-nodes/ContinueStatement.js b/src/slang-nodes/ContinueStatement.js index aa3d92d1b..a84e3d0dd 100644 --- a/src/slang-nodes/ContinueStatement.js +++ b/src/slang-nodes/ContinueStatement.js @@ -5,7 +5,7 @@ export class ContinueStatement extends SlangNode { semicolon; - constructor({ ast, offset }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.continueKeyword = ast.continueKeyword.text; this.semicolon = ast.semicolon.text; diff --git a/src/slang-nodes/ContractDefinition.js b/src/slang-nodes/ContractDefinition.js index b32c9eced..ad92684e7 100644 --- a/src/slang-nodes/ContractDefinition.js +++ b/src/slang-nodes/ContractDefinition.js @@ -18,7 +18,7 @@ export class ContractDefinition extends SlangNode { closeBrace; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.abstractKeyword = ast.abstractKeyword?.text; this.contractKeyword = ast.contractKeyword.text; diff --git a/src/slang-nodes/ContractMember.js b/src/slang-nodes/ContractMember.js index d7ed08eaf..9b609a921 100644 --- a/src/slang-nodes/ContractMember.js +++ b/src/slang-nodes/ContractMember.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class ContractMember extends SlangNode { variant; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = parse(ast.variant, parse, this.nextChildOffset); this.initiateLoc(ast); diff --git a/src/slang-nodes/ContractMembers.js b/src/slang-nodes/ContractMembers.js index 57f92feed..0724431af 100644 --- a/src/slang-nodes/ContractMembers.js +++ b/src/slang-nodes/ContractMembers.js @@ -11,7 +11,7 @@ const { hardline } = doc.builders; export class ContractMembers extends SlangNode { items; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/DecimalNumberExpression.js b/src/slang-nodes/DecimalNumberExpression.js index cbdbff69f..8e6b36bfd 100644 --- a/src/slang-nodes/DecimalNumberExpression.js +++ b/src/slang-nodes/DecimalNumberExpression.js @@ -5,7 +5,7 @@ export class DecimalNumberExpression extends SlangNode { unit; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.literal = ast.literal.text; this.unit = ast.unit diff --git a/src/slang-nodes/DoWhileStatement.js b/src/slang-nodes/DoWhileStatement.js index 57c09be9b..083dbc8ca 100644 --- a/src/slang-nodes/DoWhileStatement.js +++ b/src/slang-nodes/DoWhileStatement.js @@ -24,7 +24,7 @@ export class DoWhileStatement extends SlangNode { semicolon; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.doKeyword = ast.doKeyword.text; this.body = parse(ast.body, parse, this.nextChildOffset); diff --git a/src/slang-nodes/ElementaryType.js b/src/slang-nodes/ElementaryType.js index e4f2b1e85..32f806a54 100644 --- a/src/slang-nodes/ElementaryType.js +++ b/src/slang-nodes/ElementaryType.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class ElementaryType extends SlangNode { variant; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = ast.variant.type === 'Terminal' diff --git a/src/slang-nodes/ElseBranch.js b/src/slang-nodes/ElseBranch.js index 70737b5ce..e878c6b5b 100644 --- a/src/slang-nodes/ElseBranch.js +++ b/src/slang-nodes/ElseBranch.js @@ -13,7 +13,7 @@ export class ElseBranch extends SlangNode { body; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.elseKeyword = ast.elseKeyword.text; this.body = parse(ast.body, parse, this.nextChildOffset); diff --git a/src/slang-nodes/EmitStatement.js b/src/slang-nodes/EmitStatement.js index 7b80fbc23..6c7c8b726 100644 --- a/src/slang-nodes/EmitStatement.js +++ b/src/slang-nodes/EmitStatement.js @@ -9,7 +9,7 @@ export class EmitStatement extends SlangNode { semicolon; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.emitKeyword = ast.emitKeyword.text; this.event = parse(ast.event, parse, this.nextChildOffset); diff --git a/src/slang-nodes/EnumDefinition.js b/src/slang-nodes/EnumDefinition.js index 2c4ad105f..7778c4f4d 100644 --- a/src/slang-nodes/EnumDefinition.js +++ b/src/slang-nodes/EnumDefinition.js @@ -11,7 +11,7 @@ export class EnumDefinition extends SlangNode { closeBrace; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.enumKeyword = ast.enumKeyword.text; this.name = ast.name.text; diff --git a/src/slang-nodes/EnumMembers.js b/src/slang-nodes/EnumMembers.js index e399758f3..6d01cef29 100644 --- a/src/slang-nodes/EnumMembers.js +++ b/src/slang-nodes/EnumMembers.js @@ -9,7 +9,7 @@ export class EnumMembers extends SlangNode { separators; - constructor({ ast, offset }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items.map((item) => item.text); this.separators = ast.separators.map((separator) => separator.text); diff --git a/src/slang-nodes/EqualityExpression.js b/src/slang-nodes/EqualityExpression.js index 1b159be4a..a1a85c0c9 100644 --- a/src/slang-nodes/EqualityExpression.js +++ b/src/slang-nodes/EqualityExpression.js @@ -8,7 +8,7 @@ export class EqualityExpression extends SlangNode { rightOperand; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.leftOperand = parse(ast.leftOperand, parse, this.nextChildOffset); this.operator = ast.operator.text; diff --git a/src/slang-nodes/ErrorDefinition.js b/src/slang-nodes/ErrorDefinition.js index 347f42b0b..c47b88c94 100644 --- a/src/slang-nodes/ErrorDefinition.js +++ b/src/slang-nodes/ErrorDefinition.js @@ -9,7 +9,7 @@ export class ErrorDefinition extends SlangNode { semicolon; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.errorKeyword = ast.errorKeyword.text; this.name = ast.name.text; diff --git a/src/slang-nodes/ErrorParameter.js b/src/slang-nodes/ErrorParameter.js index 4e28c8f5b..27f374677 100644 --- a/src/slang-nodes/ErrorParameter.js +++ b/src/slang-nodes/ErrorParameter.js @@ -9,7 +9,7 @@ export class ErrorParameter extends SlangNode { semicolon; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.typeName = parse(ast.typeName, parse, this.nextChildOffset); this.name = ast.name?.text; diff --git a/src/slang-nodes/ErrorParameters.js b/src/slang-nodes/ErrorParameters.js index 94c355096..49f4188e8 100644 --- a/src/slang-nodes/ErrorParameters.js +++ b/src/slang-nodes/ErrorParameters.js @@ -6,7 +6,7 @@ export class ErrorParameters extends SlangNode { separators; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/ErrorParametersDeclaration.js b/src/slang-nodes/ErrorParametersDeclaration.js index 74813c9a2..4c14870d5 100644 --- a/src/slang-nodes/ErrorParametersDeclaration.js +++ b/src/slang-nodes/ErrorParametersDeclaration.js @@ -7,7 +7,7 @@ export class ErrorParametersDeclaration extends SlangNode { closeParen; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.openParen = ast.openParen.text; this.parameters = parse(ast.parameters, parse, this.nextChildOffset); diff --git a/src/slang-nodes/EventDefinition.js b/src/slang-nodes/EventDefinition.js index 9a3b2691d..aadf8de7b 100644 --- a/src/slang-nodes/EventDefinition.js +++ b/src/slang-nodes/EventDefinition.js @@ -11,7 +11,7 @@ export class EventDefinition extends SlangNode { semicolon; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.eventKeyword = ast.eventKeyword.text; this.name = ast.name.text; diff --git a/src/slang-nodes/EventParameter.js b/src/slang-nodes/EventParameter.js index 517ac2cb0..18fb797c1 100644 --- a/src/slang-nodes/EventParameter.js +++ b/src/slang-nodes/EventParameter.js @@ -7,7 +7,7 @@ export class EventParameter extends SlangNode { name; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.typeName = parse(ast.typeName, parse, this.nextChildOffset); this.indexedKeyword = ast.indexedKeyword?.text; diff --git a/src/slang-nodes/EventParameters.js b/src/slang-nodes/EventParameters.js index e7988cc6d..dda55fdd3 100644 --- a/src/slang-nodes/EventParameters.js +++ b/src/slang-nodes/EventParameters.js @@ -6,7 +6,7 @@ export class EventParameters extends SlangNode { separators; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/EventParametersDeclaration.js b/src/slang-nodes/EventParametersDeclaration.js index 7abbec387..16367be51 100644 --- a/src/slang-nodes/EventParametersDeclaration.js +++ b/src/slang-nodes/EventParametersDeclaration.js @@ -7,7 +7,7 @@ export class EventParametersDeclaration extends SlangNode { closeParen; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.openParen = ast.openParen.text; this.parameters = parse(ast.parameters, parse, this.nextChildOffset); diff --git a/src/slang-nodes/ExperimentalFeature.js b/src/slang-nodes/ExperimentalFeature.js index 1258da644..48adcef0f 100644 --- a/src/slang-nodes/ExperimentalFeature.js +++ b/src/slang-nodes/ExperimentalFeature.js @@ -4,16 +4,12 @@ import { StringLiteral } from './StringLiteral.js'; export class ExperimentalFeature extends SlangNode { variant; - constructor({ ast, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : new StringLiteral({ - ast: ast.variant, - offset: this.nextChildOffset, - options - }); + : new StringLiteral(ast.variant, this.nextChildOffset, options); this.initiateLoc(ast); } diff --git a/src/slang-nodes/ExperimentalPragma.js b/src/slang-nodes/ExperimentalPragma.js index 0c26b59c2..66031cbd1 100644 --- a/src/slang-nodes/ExperimentalPragma.js +++ b/src/slang-nodes/ExperimentalPragma.js @@ -6,14 +6,14 @@ export class ExperimentalPragma extends SlangNode { feature; - constructor({ ast, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.experimentalKeyword = ast.experimentalKeyword.text; - this.feature = new ExperimentalFeature({ - ast: ast.feature, - offset: this.nextChildOffset, + this.feature = new ExperimentalFeature( + ast.feature, + this.nextChildOffset, options - }); + ); this.initiateLoc(ast); } diff --git a/src/slang-nodes/ExponentiationExpression.js b/src/slang-nodes/ExponentiationExpression.js index e723332e1..44f325fcd 100644 --- a/src/slang-nodes/ExponentiationExpression.js +++ b/src/slang-nodes/ExponentiationExpression.js @@ -25,19 +25,9 @@ export class ExponentiationExpression extends SlangNode { rightOperand; - constructor({ - ast, - options, - parse, - offset, - kind, - loc, - leftOperand, - operator, - rightOperand - }) { + constructor(ast, offset, parse, options) { super(ast, offset); - if (ast) { + if (offset) { const compiler = coerce(options.compiler); this.leftOperand = parse(ast.leftOperand, parse, this.nextChildOffset); this.rightOperand = parse(ast.rightOperand, parse, this.nextChildOffset); @@ -97,11 +87,11 @@ export class ExponentiationExpression extends SlangNode { this.operator = ast.operator.text; this.initiateLoc(ast); } else { - this.kind = kind; - this.loc = loc; - this.leftOperand = leftOperand; - this.operator = operator; - this.rightOperand = rightOperand; + this.kind = ast.kind; + this.loc = ast.loc; + this.leftOperand = ast.leftOperand; + this.operator = ast.operator; + this.rightOperand = ast.rightOperand; } } diff --git a/src/slang-nodes/Expression.js b/src/slang-nodes/Expression.js index 2a49dd42c..118c60554 100644 --- a/src/slang-nodes/Expression.js +++ b/src/slang-nodes/Expression.js @@ -3,18 +3,18 @@ import { SlangNode } from './SlangNode.js'; export class Expression extends SlangNode { variant; - constructor({ ast, parse, offset, options, kind, loc, variant }) { + constructor(ast, offset, parse, options) { super(ast, offset); - if (ast) { + if (offset) { this.variant = ast.variant.type === 'Terminal' ? ast.variant.text : parse(ast.variant, parse, this.nextChildOffset); this.initiateLoc(ast); } else { - this.kind = kind; - this.loc = loc; - this.variant = variant; + this.kind = ast.kind; + this.loc = ast.loc; + this.variant = ast.variant; } } diff --git a/src/slang-nodes/ExpressionStatement.js b/src/slang-nodes/ExpressionStatement.js index 942ecbb55..fc2a0c2fc 100644 --- a/src/slang-nodes/ExpressionStatement.js +++ b/src/slang-nodes/ExpressionStatement.js @@ -5,7 +5,7 @@ export class ExpressionStatement extends SlangNode { semicolon; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.expression = parse(ast.expression, parse, this.nextChildOffset); this.semicolon = ast.semicolon.text; diff --git a/src/slang-nodes/FallbackFunctionAttribute.js b/src/slang-nodes/FallbackFunctionAttribute.js index 8bce5720d..4d3acd682 100644 --- a/src/slang-nodes/FallbackFunctionAttribute.js +++ b/src/slang-nodes/FallbackFunctionAttribute.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class FallbackFunctionAttribute extends SlangNode { variant; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = ast.variant.type === 'Terminal' diff --git a/src/slang-nodes/FallbackFunctionAttributes.js b/src/slang-nodes/FallbackFunctionAttributes.js index 2deb9b009..62437f307 100644 --- a/src/slang-nodes/FallbackFunctionAttributes.js +++ b/src/slang-nodes/FallbackFunctionAttributes.js @@ -7,7 +7,7 @@ const { line } = doc.builders; export class FallbackFunctionAttributes extends SlangNode { items; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items .map((item) => parse(item, parse, this.nextChildOffset)) diff --git a/src/slang-nodes/FallbackFunctionDefinition.js b/src/slang-nodes/FallbackFunctionDefinition.js index 24b6b135d..d950c3d6f 100644 --- a/src/slang-nodes/FallbackFunctionDefinition.js +++ b/src/slang-nodes/FallbackFunctionDefinition.js @@ -12,7 +12,7 @@ export class FallbackFunctionDefinition extends SlangNode { body; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.fallbackKeyword = ast.fallbackKeyword.text; this.parameters = parse(ast.parameters, parse, this.nextChildOffset); diff --git a/src/slang-nodes/ForStatement.js b/src/slang-nodes/ForStatement.js index 9eec784b3..662ae7362 100644 --- a/src/slang-nodes/ForStatement.js +++ b/src/slang-nodes/ForStatement.js @@ -19,7 +19,7 @@ export class ForStatement extends SlangNode { body; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.forKeyword = ast.forKeyword.text; this.openParen = ast.openParen.text; diff --git a/src/slang-nodes/ForStatementCondition.js b/src/slang-nodes/ForStatementCondition.js index a14752e82..3911fce10 100644 --- a/src/slang-nodes/ForStatementCondition.js +++ b/src/slang-nodes/ForStatementCondition.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class ForStatementCondition extends SlangNode { variant; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = ast.variant.type === 'Terminal' diff --git a/src/slang-nodes/ForStatementInitialization.js b/src/slang-nodes/ForStatementInitialization.js index 94bbb3c9e..0d935ff48 100644 --- a/src/slang-nodes/ForStatementInitialization.js +++ b/src/slang-nodes/ForStatementInitialization.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class ForStatementInitialization extends SlangNode { variant; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = ast.variant.type === 'Terminal' diff --git a/src/slang-nodes/FunctionAttribute.js b/src/slang-nodes/FunctionAttribute.js index 29e8fdd2b..38eac2534 100644 --- a/src/slang-nodes/FunctionAttribute.js +++ b/src/slang-nodes/FunctionAttribute.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class FunctionAttribute extends SlangNode { variant; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = ast.variant.type === 'Terminal' diff --git a/src/slang-nodes/FunctionAttributes.js b/src/slang-nodes/FunctionAttributes.js index 2f6772a9e..be065249f 100644 --- a/src/slang-nodes/FunctionAttributes.js +++ b/src/slang-nodes/FunctionAttributes.js @@ -7,7 +7,7 @@ const { line } = doc.builders; export class FunctionAttributes extends SlangNode { items; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items .map((item) => parse(item, parse, this.nextChildOffset)) diff --git a/src/slang-nodes/FunctionBody.js b/src/slang-nodes/FunctionBody.js index 5d1aece97..25d7df6ab 100644 --- a/src/slang-nodes/FunctionBody.js +++ b/src/slang-nodes/FunctionBody.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class FunctionBody extends SlangNode { variant; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = ast.variant.type === 'Terminal' diff --git a/src/slang-nodes/FunctionCallExpression.js b/src/slang-nodes/FunctionCallExpression.js index b90e4dd05..b0e58013b 100644 --- a/src/slang-nodes/FunctionCallExpression.js +++ b/src/slang-nodes/FunctionCallExpression.js @@ -11,7 +11,7 @@ export class FunctionCallExpression extends SlangNode { arguments; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.operand = parse(ast.operand, parse, this.nextChildOffset); this.arguments = parse(ast.arguments, parse, this.nextChildOffset); diff --git a/src/slang-nodes/FunctionDefinition.js b/src/slang-nodes/FunctionDefinition.js index 64d6dd9f2..66e667d94 100644 --- a/src/slang-nodes/FunctionDefinition.js +++ b/src/slang-nodes/FunctionDefinition.js @@ -14,7 +14,7 @@ export class FunctionDefinition extends SlangNode { body; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.functionKeyword = ast.functionKeyword.text; this.name = parse(ast.name, parse, this.nextChildOffset); diff --git a/src/slang-nodes/FunctionName.js b/src/slang-nodes/FunctionName.js index 3ea2dda70..2857c5223 100644 --- a/src/slang-nodes/FunctionName.js +++ b/src/slang-nodes/FunctionName.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class FunctionName extends SlangNode { variant; - constructor({ ast, offset }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = ast.variant.text; this.initiateLoc(ast); diff --git a/src/slang-nodes/FunctionType.js b/src/slang-nodes/FunctionType.js index 2c8a2f739..74d79f87e 100644 --- a/src/slang-nodes/FunctionType.js +++ b/src/slang-nodes/FunctionType.js @@ -10,7 +10,7 @@ export class FunctionType extends SlangNode { returns; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.functionKeyword = ast.functionKeyword.text; this.parameters = parse(ast.parameters, parse, this.nextChildOffset); diff --git a/src/slang-nodes/FunctionTypeAttribute.js b/src/slang-nodes/FunctionTypeAttribute.js index 4e372783e..381f8e93f 100644 --- a/src/slang-nodes/FunctionTypeAttribute.js +++ b/src/slang-nodes/FunctionTypeAttribute.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class FunctionTypeAttribute extends SlangNode { variant; - constructor({ ast, offset }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = ast.variant.text; this.initiateLoc(ast); diff --git a/src/slang-nodes/FunctionTypeAttributes.js b/src/slang-nodes/FunctionTypeAttributes.js index ef77f36c4..3058e9059 100644 --- a/src/slang-nodes/FunctionTypeAttributes.js +++ b/src/slang-nodes/FunctionTypeAttributes.js @@ -7,7 +7,7 @@ const { line } = doc.builders; export class FunctionTypeAttributes extends SlangNode { items; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items .map((item) => parse(item, parse, this.nextChildOffset)) diff --git a/src/slang-nodes/HexNumberExpression.js b/src/slang-nodes/HexNumberExpression.js index b17940cc1..abe93ef47 100644 --- a/src/slang-nodes/HexNumberExpression.js +++ b/src/slang-nodes/HexNumberExpression.js @@ -5,7 +5,7 @@ export class HexNumberExpression extends SlangNode { unit; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.literal = ast.literal.text; this.unit = ast.unit diff --git a/src/slang-nodes/HexStringLiteral.js b/src/slang-nodes/HexStringLiteral.js index 4b1b2c931..0c07153f0 100644 --- a/src/slang-nodes/HexStringLiteral.js +++ b/src/slang-nodes/HexStringLiteral.js @@ -4,7 +4,7 @@ import { SlangNode } from './SlangNode.js'; export class HexStringLiteral extends SlangNode { variant; - constructor({ ast, options, offset }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = `hex${printString(ast.variant.text.slice(4, -1), options)}`; this.initiateLoc(ast); diff --git a/src/slang-nodes/HexStringLiterals.js b/src/slang-nodes/HexStringLiterals.js index 65dd0316a..46914254d 100644 --- a/src/slang-nodes/HexStringLiterals.js +++ b/src/slang-nodes/HexStringLiterals.js @@ -6,7 +6,7 @@ const { join, hardline } = doc.builders; export class HexStringLiterals extends SlangNode { items; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/IdentifierPath.js b/src/slang-nodes/IdentifierPath.js index 294c58db7..eb6e05c88 100644 --- a/src/slang-nodes/IdentifierPath.js +++ b/src/slang-nodes/IdentifierPath.js @@ -5,7 +5,7 @@ export class IdentifierPath extends SlangNode { separators; - constructor({ ast, offset }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items.map((item) => item.text); this.separators = ast.separators.map((separator) => separator.text); diff --git a/src/slang-nodes/IfStatement.js b/src/slang-nodes/IfStatement.js index e87d54086..c2295f8e5 100644 --- a/src/slang-nodes/IfStatement.js +++ b/src/slang-nodes/IfStatement.js @@ -24,7 +24,7 @@ export class IfStatement extends SlangNode { elseBranch; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.ifKeyword = ast.ifKeyword.text; this.openParen = ast.openParen.text; diff --git a/src/slang-nodes/ImportAlias.js b/src/slang-nodes/ImportAlias.js index 267a2431f..d136a6461 100644 --- a/src/slang-nodes/ImportAlias.js +++ b/src/slang-nodes/ImportAlias.js @@ -5,7 +5,7 @@ export class ImportAlias extends SlangNode { identifier; - constructor({ ast, offset }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.asKeyword = ast.asKeyword.text; this.identifier = ast.identifier.text; diff --git a/src/slang-nodes/ImportClause.js b/src/slang-nodes/ImportClause.js index 1d3969e75..eae4d8e00 100644 --- a/src/slang-nodes/ImportClause.js +++ b/src/slang-nodes/ImportClause.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class ImportClause extends SlangNode { variant; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = parse(ast.variant, parse, this.nextChildOffset); this.initiateLoc(ast); diff --git a/src/slang-nodes/ImportDeconstruction.js b/src/slang-nodes/ImportDeconstruction.js index 6ec3127ad..74c57c502 100644 --- a/src/slang-nodes/ImportDeconstruction.js +++ b/src/slang-nodes/ImportDeconstruction.js @@ -11,7 +11,7 @@ export class ImportDeconstruction extends SlangNode { path; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.openBrace = ast.openBrace.text; this.symbols = parse(ast.symbols, parse, this.nextChildOffset); diff --git a/src/slang-nodes/ImportDeconstructionSymbol.js b/src/slang-nodes/ImportDeconstructionSymbol.js index 34c984456..0712334c3 100644 --- a/src/slang-nodes/ImportDeconstructionSymbol.js +++ b/src/slang-nodes/ImportDeconstructionSymbol.js @@ -5,7 +5,7 @@ export class ImportDeconstructionSymbol extends SlangNode { alias; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.name = ast.name.text; this.alias = ast.alias diff --git a/src/slang-nodes/ImportDeconstructionSymbols.js b/src/slang-nodes/ImportDeconstructionSymbols.js index 013b74530..ae4bcd138 100644 --- a/src/slang-nodes/ImportDeconstructionSymbols.js +++ b/src/slang-nodes/ImportDeconstructionSymbols.js @@ -11,7 +11,7 @@ export class ImportDeconstructionSymbols extends SlangNode { separators; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/ImportDirective.js b/src/slang-nodes/ImportDirective.js index abb316de2..4caf80846 100644 --- a/src/slang-nodes/ImportDirective.js +++ b/src/slang-nodes/ImportDirective.js @@ -7,7 +7,7 @@ export class ImportDirective extends SlangNode { semicolon; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.importKeyword = ast.importKeyword.text; this.clause = parse(ast.clause, parse, this.nextChildOffset); diff --git a/src/slang-nodes/IndexAccessEnd.js b/src/slang-nodes/IndexAccessEnd.js index a75966e63..3b0e05c2d 100644 --- a/src/slang-nodes/IndexAccessEnd.js +++ b/src/slang-nodes/IndexAccessEnd.js @@ -5,7 +5,7 @@ export class IndexAccessEnd extends SlangNode { end; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.colon = ast.colon.text; this.end = ast.end diff --git a/src/slang-nodes/IndexAccessExpression.js b/src/slang-nodes/IndexAccessExpression.js index 81a5031c5..751001a7c 100644 --- a/src/slang-nodes/IndexAccessExpression.js +++ b/src/slang-nodes/IndexAccessExpression.js @@ -17,7 +17,7 @@ export class IndexAccessExpression extends SlangNode { closeBracket; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.operand = parse(ast.operand, parse, this.nextChildOffset); this.openBracket = ast.openBracket.text; diff --git a/src/slang-nodes/InheritanceSpecifier.js b/src/slang-nodes/InheritanceSpecifier.js index b609ef829..c53bba06b 100644 --- a/src/slang-nodes/InheritanceSpecifier.js +++ b/src/slang-nodes/InheritanceSpecifier.js @@ -5,7 +5,7 @@ export class InheritanceSpecifier extends SlangNode { types; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.isKeyword = ast.isKeyword.text; this.types = parse(ast.types, parse, this.nextChildOffset); diff --git a/src/slang-nodes/InheritanceType.js b/src/slang-nodes/InheritanceType.js index f5d06312e..5aeabf05c 100644 --- a/src/slang-nodes/InheritanceType.js +++ b/src/slang-nodes/InheritanceType.js @@ -5,7 +5,7 @@ export class InheritanceType extends SlangNode { arguments; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.typeName = parse(ast.typeName, parse, this.nextChildOffset); this.arguments = ast.arguments diff --git a/src/slang-nodes/InheritanceTypes.js b/src/slang-nodes/InheritanceTypes.js index 771866f6b..fd8c544f8 100644 --- a/src/slang-nodes/InheritanceTypes.js +++ b/src/slang-nodes/InheritanceTypes.js @@ -9,7 +9,7 @@ export class InheritanceTypes extends SlangNode { separators; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/InterfaceDefinition.js b/src/slang-nodes/InterfaceDefinition.js index cad80e531..773998c9b 100644 --- a/src/slang-nodes/InterfaceDefinition.js +++ b/src/slang-nodes/InterfaceDefinition.js @@ -16,7 +16,7 @@ export class InterfaceDefinition extends SlangNode { closeBrace; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.interfaceKeyword = ast.interfaceKeyword.text; this.name = ast.name.text; diff --git a/src/slang-nodes/InterfaceMembers.js b/src/slang-nodes/InterfaceMembers.js index 0cfe4b1af..874635dce 100644 --- a/src/slang-nodes/InterfaceMembers.js +++ b/src/slang-nodes/InterfaceMembers.js @@ -8,7 +8,7 @@ const { hardline } = doc.builders; export class InterfaceMembers extends SlangNode { items; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/LibraryDefinition.js b/src/slang-nodes/LibraryDefinition.js index 32f497f7a..6d0a3918a 100644 --- a/src/slang-nodes/LibraryDefinition.js +++ b/src/slang-nodes/LibraryDefinition.js @@ -14,7 +14,7 @@ export class LibraryDefinition extends SlangNode { closeBrace; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.libraryKeyword = ast.libraryKeyword.text; this.name = ast.name.text; diff --git a/src/slang-nodes/LibraryMembers.js b/src/slang-nodes/LibraryMembers.js index af3c367e5..6d448c302 100644 --- a/src/slang-nodes/LibraryMembers.js +++ b/src/slang-nodes/LibraryMembers.js @@ -8,7 +8,7 @@ const { hardline } = doc.builders; export class LibraryMembers extends SlangNode { items; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/MappingKey.js b/src/slang-nodes/MappingKey.js index 3038948ba..2729f1a6e 100644 --- a/src/slang-nodes/MappingKey.js +++ b/src/slang-nodes/MappingKey.js @@ -5,7 +5,7 @@ export class MappingKey extends SlangNode { name; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.keyType = parse(ast.keyType, parse, this.nextChildOffset); this.name = ast.name?.text; diff --git a/src/slang-nodes/MappingKeyType.js b/src/slang-nodes/MappingKeyType.js index d45f76868..78a9b49dc 100644 --- a/src/slang-nodes/MappingKeyType.js +++ b/src/slang-nodes/MappingKeyType.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class MappingKeyType extends SlangNode { variant; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = parse(ast.variant, parse, this.nextChildOffset); this.initiateLoc(ast); diff --git a/src/slang-nodes/MappingType.js b/src/slang-nodes/MappingType.js index 682cac690..851368873 100644 --- a/src/slang-nodes/MappingType.js +++ b/src/slang-nodes/MappingType.js @@ -13,7 +13,7 @@ export class MappingType extends SlangNode { closeParen; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.mappingKeyword = ast.mappingKeyword.text; this.openParen = ast.openParen.text; diff --git a/src/slang-nodes/MappingValue.js b/src/slang-nodes/MappingValue.js index efdbeab02..63c3b3792 100644 --- a/src/slang-nodes/MappingValue.js +++ b/src/slang-nodes/MappingValue.js @@ -5,7 +5,7 @@ export class MappingValue extends SlangNode { name; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.typeName = parse(ast.typeName, parse, this.nextChildOffset); this.name = ast.name?.text; diff --git a/src/slang-nodes/MemberAccess.js b/src/slang-nodes/MemberAccess.js index 79d73aede..fe2805dc7 100644 --- a/src/slang-nodes/MemberAccess.js +++ b/src/slang-nodes/MemberAccess.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class MemberAccess extends SlangNode { variant; - constructor({ ast, offset }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = ast.variant.text; this.initiateLoc(ast); diff --git a/src/slang-nodes/MemberAccessExpression.js b/src/slang-nodes/MemberAccessExpression.js index b8a75996b..db628bdfc 100644 --- a/src/slang-nodes/MemberAccessExpression.js +++ b/src/slang-nodes/MemberAccessExpression.js @@ -112,7 +112,7 @@ export class MemberAccessExpression extends SlangNode { member; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.operand = parse(ast.operand, parse, this.nextChildOffset); this.period = ast.period.text; diff --git a/src/slang-nodes/ModifierAttribute.js b/src/slang-nodes/ModifierAttribute.js index c5374bb51..3506dde06 100644 --- a/src/slang-nodes/ModifierAttribute.js +++ b/src/slang-nodes/ModifierAttribute.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class ModifierAttribute extends SlangNode { variant; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = ast.variant.type === 'Terminal' diff --git a/src/slang-nodes/ModifierAttributes.js b/src/slang-nodes/ModifierAttributes.js index de07c1f75..7df2831cf 100644 --- a/src/slang-nodes/ModifierAttributes.js +++ b/src/slang-nodes/ModifierAttributes.js @@ -7,7 +7,7 @@ const { line } = doc.builders; export class ModifierAttributes extends SlangNode { items; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items .map((item) => parse(item, parse, this.nextChildOffset)) diff --git a/src/slang-nodes/ModifierDefinition.js b/src/slang-nodes/ModifierDefinition.js index 40d36e1a4..10a2216c3 100644 --- a/src/slang-nodes/ModifierDefinition.js +++ b/src/slang-nodes/ModifierDefinition.js @@ -14,7 +14,7 @@ export class ModifierDefinition extends SlangNode { body; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.modifierKeyword = ast.modifierKeyword.text; this.name = ast.name.text; diff --git a/src/slang-nodes/ModifierInvocation.js b/src/slang-nodes/ModifierInvocation.js index bd3cf51b3..ae4a40de0 100644 --- a/src/slang-nodes/ModifierInvocation.js +++ b/src/slang-nodes/ModifierInvocation.js @@ -6,7 +6,7 @@ export class ModifierInvocation extends SlangNode { arguments; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.name = parse(ast.name, parse, this.nextChildOffset); this.arguments = ast.arguments diff --git a/src/slang-nodes/MultiplicativeExpression.js b/src/slang-nodes/MultiplicativeExpression.js index 4817df890..1ef6febf0 100644 --- a/src/slang-nodes/MultiplicativeExpression.js +++ b/src/slang-nodes/MultiplicativeExpression.js @@ -13,7 +13,7 @@ export class MultiplicativeExpression extends SlangNode { rightOperand; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.leftOperand = parse(ast.leftOperand, parse, this.nextChildOffset); this.operator = ast.operator.text; diff --git a/src/slang-nodes/NamedArgument.js b/src/slang-nodes/NamedArgument.js index 210204d1b..4890aa592 100644 --- a/src/slang-nodes/NamedArgument.js +++ b/src/slang-nodes/NamedArgument.js @@ -7,7 +7,7 @@ export class NamedArgument extends SlangNode { value; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.name = ast.name.text; this.colon = ast.colon.text; diff --git a/src/slang-nodes/NamedArgumentGroup.js b/src/slang-nodes/NamedArgumentGroup.js index 0966759c4..92b8cbf83 100644 --- a/src/slang-nodes/NamedArgumentGroup.js +++ b/src/slang-nodes/NamedArgumentGroup.js @@ -7,7 +7,7 @@ export class NamedArgumentGroup extends SlangNode { closeBrace; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.openBrace = ast.openBrace.text; this.arguments = parse(ast.arguments, parse, this.nextChildOffset); diff --git a/src/slang-nodes/NamedArguments.js b/src/slang-nodes/NamedArguments.js index 7d907e5cf..974fb7bff 100644 --- a/src/slang-nodes/NamedArguments.js +++ b/src/slang-nodes/NamedArguments.js @@ -9,7 +9,7 @@ export class NamedArguments extends SlangNode { separators; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/NamedArgumentsDeclaration.js b/src/slang-nodes/NamedArgumentsDeclaration.js index c5440fe22..4974d95e1 100644 --- a/src/slang-nodes/NamedArgumentsDeclaration.js +++ b/src/slang-nodes/NamedArgumentsDeclaration.js @@ -7,7 +7,7 @@ export class NamedArgumentsDeclaration extends SlangNode { closeParen; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.openParen = ast.openParen.text; this.arguments = ast.arguments diff --git a/src/slang-nodes/NamedImport.js b/src/slang-nodes/NamedImport.js index da661cc2c..74f3b7c1f 100644 --- a/src/slang-nodes/NamedImport.js +++ b/src/slang-nodes/NamedImport.js @@ -9,7 +9,7 @@ export class NamedImport extends SlangNode { path; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.asterisk = ast.asterisk.text; this.alias = parse(ast.alias, parse, this.nextChildOffset); diff --git a/src/slang-nodes/NewExpression.js b/src/slang-nodes/NewExpression.js index 071303288..7c6910620 100644 --- a/src/slang-nodes/NewExpression.js +++ b/src/slang-nodes/NewExpression.js @@ -5,7 +5,7 @@ export class NewExpression extends SlangNode { typeName; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.newKeyword = ast.newKeyword.text; this.typeName = parse(ast.typeName, parse, this.nextChildOffset); diff --git a/src/slang-nodes/NumberUnit.js b/src/slang-nodes/NumberUnit.js index 36c6819a3..932feb935 100644 --- a/src/slang-nodes/NumberUnit.js +++ b/src/slang-nodes/NumberUnit.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class NumberUnit extends SlangNode { variant; - constructor({ ast, offset }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = ast.variant.text; this.initiateLoc(ast); diff --git a/src/slang-nodes/OrExpression.js b/src/slang-nodes/OrExpression.js index 810fb7704..ff3c1371e 100644 --- a/src/slang-nodes/OrExpression.js +++ b/src/slang-nodes/OrExpression.js @@ -11,7 +11,7 @@ export class OrExpression extends SlangNode { rightOperand; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.leftOperand = tryToHug( parse(ast.leftOperand, parse, this.nextChildOffset) diff --git a/src/slang-nodes/OverridePaths.js b/src/slang-nodes/OverridePaths.js index 7f847a5a7..88a0e6912 100644 --- a/src/slang-nodes/OverridePaths.js +++ b/src/slang-nodes/OverridePaths.js @@ -5,7 +5,7 @@ export class OverridePaths extends SlangNode { separators; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/OverridePathsDeclaration.js b/src/slang-nodes/OverridePathsDeclaration.js index 8622d4530..1824736dc 100644 --- a/src/slang-nodes/OverridePathsDeclaration.js +++ b/src/slang-nodes/OverridePathsDeclaration.js @@ -7,7 +7,7 @@ export class OverridePathsDeclaration extends SlangNode { closeParen; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.openParen = ast.openParen.text; this.paths = parse(ast.paths, parse, this.nextChildOffset); diff --git a/src/slang-nodes/OverrideSpecifier.js b/src/slang-nodes/OverrideSpecifier.js index f2bcc9ed4..7d0c1d655 100644 --- a/src/slang-nodes/OverrideSpecifier.js +++ b/src/slang-nodes/OverrideSpecifier.js @@ -5,7 +5,7 @@ export class OverrideSpecifier extends SlangNode { overridden; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.overrideKeyword = ast.overrideKeyword.text; this.overridden = ast.overridden diff --git a/src/slang-nodes/Parameter.js b/src/slang-nodes/Parameter.js index 6d9a1453d..43eb68cf9 100644 --- a/src/slang-nodes/Parameter.js +++ b/src/slang-nodes/Parameter.js @@ -10,7 +10,7 @@ export class Parameter extends SlangNode { name; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.typeName = parse(ast.typeName, parse, this.nextChildOffset); this.storageLocation = ast.storageLocation diff --git a/src/slang-nodes/Parameters.js b/src/slang-nodes/Parameters.js index 31abac212..2c8355984 100644 --- a/src/slang-nodes/Parameters.js +++ b/src/slang-nodes/Parameters.js @@ -10,19 +10,19 @@ export class Parameters extends SlangNode { separators; - constructor({ ast, parse, offset, kind, loc, items, separators }) { + constructor(ast, offset, parse, options) { super(ast, offset); - if (ast) { + if (offset) { this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) ); this.separators = ast.separators.map((separator) => separator.text); this.initiateLoc(ast); } else { - this.kind = kind; - this.loc = loc; - this.items = items; - this.separators = separators; + this.kind = ast.kind; + this.loc = ast.loc; + this.items = ast.items; + this.separators = ast.separators; } } diff --git a/src/slang-nodes/ParametersDeclaration.js b/src/slang-nodes/ParametersDeclaration.js index c31bec0a6..67cfa61b4 100644 --- a/src/slang-nodes/ParametersDeclaration.js +++ b/src/slang-nodes/ParametersDeclaration.js @@ -7,28 +7,19 @@ export class ParametersDeclaration extends SlangNode { closeParen; - constructor({ - ast, - parse, - offset, - kind, - loc, - openParen, - parameters, - closeParen - }) { + constructor(ast, offset, parse, options) { super(ast, offset); - if (ast) { + if (offset) { this.openParen = ast.openParen.text; this.parameters = parse(ast.parameters, parse, this.nextChildOffset); this.closeParen = ast.closeParen.text; this.initiateLoc(ast); } else { - this.kind = kind; - this.loc = loc; - this.openParen = openParen; - this.parameters = parameters; - this.closeParen = closeParen; + this.kind = ast.kind; + this.loc = ast.loc; + this.openParen = ast.openParen; + this.parameters = ast.parameters; + this.closeParen = ast.closeParen; } } diff --git a/src/slang-nodes/PathImport.js b/src/slang-nodes/PathImport.js index 01cf12faa..3c9b1b6ef 100644 --- a/src/slang-nodes/PathImport.js +++ b/src/slang-nodes/PathImport.js @@ -5,7 +5,7 @@ export class PathImport extends SlangNode { alias; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.path = parse(ast.path, parse, this.nextChildOffset); this.alias = ast.alias diff --git a/src/slang-nodes/PositionalArguments.js b/src/slang-nodes/PositionalArguments.js index f3a6a44ed..c970b9c5c 100644 --- a/src/slang-nodes/PositionalArguments.js +++ b/src/slang-nodes/PositionalArguments.js @@ -6,7 +6,7 @@ export class PositionalArguments extends SlangNode { separators; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/PositionalArgumentsDeclaration.js b/src/slang-nodes/PositionalArgumentsDeclaration.js index 6f877ea31..0e696dc3f 100644 --- a/src/slang-nodes/PositionalArgumentsDeclaration.js +++ b/src/slang-nodes/PositionalArgumentsDeclaration.js @@ -7,7 +7,7 @@ export class PositionalArgumentsDeclaration extends SlangNode { closeParen; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.openParen = ast.openParen.text; this.arguments = parse(ast.arguments, parse, this.nextChildOffset); diff --git a/src/slang-nodes/PostfixExpression.js b/src/slang-nodes/PostfixExpression.js index e10c88c30..7411a2d65 100644 --- a/src/slang-nodes/PostfixExpression.js +++ b/src/slang-nodes/PostfixExpression.js @@ -5,7 +5,7 @@ export class PostfixExpression extends SlangNode { operator; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.operand = parse(ast.operand, parse, this.nextChildOffset); this.operator = ast.operator.text; diff --git a/src/slang-nodes/Pragma.js b/src/slang-nodes/Pragma.js index 1b9a5c2b6..4520eba11 100644 --- a/src/slang-nodes/Pragma.js +++ b/src/slang-nodes/Pragma.js @@ -8,13 +8,14 @@ const variants = { ABICoderPragma, ExperimentalPragma, VersionPragma }; export class Pragma extends SlangNode { variant; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); - this.variant = new variants[ast.variant.cst.kind]({ - ast: ast.variant, + this.variant = new variants[ast.variant.cst.kind]( + ast.variant, + this.nextChildOffset, parse, - offset: this.nextChildOffset - }); + options + ); this.initiateLoc(ast); } diff --git a/src/slang-nodes/PragmaDirective.js b/src/slang-nodes/PragmaDirective.js index 84d111eb4..14b88f772 100644 --- a/src/slang-nodes/PragmaDirective.js +++ b/src/slang-nodes/PragmaDirective.js @@ -8,15 +8,10 @@ export class PragmaDirective extends SlangNode { semicolon; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.pragmaKeyword = ast.pragmaKeyword.text; - this.pragma = new Pragma({ - ast: ast.pragma, - parse, - offset: this.nextChildOffset, - options - }); + this.pragma = new Pragma(ast.pragma, this.nextChildOffset, parse, options); this.semicolon = ast.semicolon.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/PrefixExpression.js b/src/slang-nodes/PrefixExpression.js index 121c22845..d66fbdfb8 100644 --- a/src/slang-nodes/PrefixExpression.js +++ b/src/slang-nodes/PrefixExpression.js @@ -5,7 +5,7 @@ export class PrefixExpression extends SlangNode { operand; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.operator = ast.operator.text; this.operand = parse(ast.operand, parse, this.nextChildOffset); diff --git a/src/slang-nodes/ReceiveFunctionAttribute.js b/src/slang-nodes/ReceiveFunctionAttribute.js index 43b072fa1..4d77f9f2e 100644 --- a/src/slang-nodes/ReceiveFunctionAttribute.js +++ b/src/slang-nodes/ReceiveFunctionAttribute.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class ReceiveFunctionAttribute extends SlangNode { variant; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = ast.variant.type === 'Terminal' diff --git a/src/slang-nodes/ReceiveFunctionAttributes.js b/src/slang-nodes/ReceiveFunctionAttributes.js index e36270483..0cf478733 100644 --- a/src/slang-nodes/ReceiveFunctionAttributes.js +++ b/src/slang-nodes/ReceiveFunctionAttributes.js @@ -7,7 +7,7 @@ const { line } = doc.builders; export class ReceiveFunctionAttributes extends SlangNode { items; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items .map((item) => parse(item, parse, this.nextChildOffset)) diff --git a/src/slang-nodes/ReceiveFunctionDefinition.js b/src/slang-nodes/ReceiveFunctionDefinition.js index d47745082..adda23d13 100644 --- a/src/slang-nodes/ReceiveFunctionDefinition.js +++ b/src/slang-nodes/ReceiveFunctionDefinition.js @@ -10,7 +10,7 @@ export class ReceiveFunctionDefinition extends SlangNode { body; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.receiveKeyword = ast.receiveKeyword.text; this.parameters = parse(ast.parameters, parse, this.nextChildOffset); diff --git a/src/slang-nodes/ReturnStatement.js b/src/slang-nodes/ReturnStatement.js index cffc37945..ce42967fa 100644 --- a/src/slang-nodes/ReturnStatement.js +++ b/src/slang-nodes/ReturnStatement.js @@ -21,7 +21,7 @@ export class ReturnStatement extends SlangNode { semicolon; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.returnKeyword = ast.returnKeyword.text; this.expression = ast.expression diff --git a/src/slang-nodes/ReturnsDeclaration.js b/src/slang-nodes/ReturnsDeclaration.js index f03f38a14..2c2f67ef1 100644 --- a/src/slang-nodes/ReturnsDeclaration.js +++ b/src/slang-nodes/ReturnsDeclaration.js @@ -8,7 +8,7 @@ export class ReturnsDeclaration extends SlangNode { variables; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.returnsKeyword = ast.returnsKeyword.text; this.variables = parse(ast.variables, parse, this.nextChildOffset); diff --git a/src/slang-nodes/RevertStatement.js b/src/slang-nodes/RevertStatement.js index 4d1b17c57..1e2ad9810 100644 --- a/src/slang-nodes/RevertStatement.js +++ b/src/slang-nodes/RevertStatement.js @@ -9,7 +9,7 @@ export class RevertStatement extends SlangNode { semicolon; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.revertKeyword = ast.revertKeyword.text; this.error = ast.error diff --git a/src/slang-nodes/ShiftExpression.js b/src/slang-nodes/ShiftExpression.js index b4b4b0abc..4a38b92bb 100644 --- a/src/slang-nodes/ShiftExpression.js +++ b/src/slang-nodes/ShiftExpression.js @@ -20,7 +20,7 @@ export class ShiftExpression extends SlangNode { rightOperand; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.leftOperand = tryToHugLeftOperand( parse(ast.leftOperand, parse, this.nextChildOffset) diff --git a/src/slang-nodes/SlangNode.js b/src/slang-nodes/SlangNode.js index b296b0cb1..3903559e0 100644 --- a/src/slang-nodes/SlangNode.js +++ b/src/slang-nodes/SlangNode.js @@ -70,7 +70,7 @@ export class SlangNode { comments = []; constructor(ast, offset) { - if (!ast) return; + if (typeof offset === 'undefined') return; const children = ast.cst.children(); this.kind = ast.cst.kind; this.loc.childrenOffsets = getOffsets(children, offset); diff --git a/src/slang-nodes/SourceUnit.js b/src/slang-nodes/SourceUnit.js index 755ce3909..37ba99852 100644 --- a/src/slang-nodes/SourceUnit.js +++ b/src/slang-nodes/SourceUnit.js @@ -7,14 +7,14 @@ const { line } = doc.builders; export class SourceUnit extends SlangNode { members; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); - this.members = new SourceUnitMembers({ - ast: ast.members, + this.members = new SourceUnitMembers( + ast.members, + this.nextChildOffset, parse, - offset: this.nextChildOffset, options - }); + ); this.initiateLoc(ast); } diff --git a/src/slang-nodes/SourceUnitMember.js b/src/slang-nodes/SourceUnitMember.js index f8edd4538..489f563ae 100644 --- a/src/slang-nodes/SourceUnitMember.js +++ b/src/slang-nodes/SourceUnitMember.js @@ -32,14 +32,14 @@ const variants = { export class SourceUnitMember extends SlangNode { variant; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); - this.variant = new variants[ast.variant.cst.kind]({ - ast: ast.variant, + this.variant = new variants[ast.variant.cst.kind]( + ast.variant, + this.nextChildOffset, parse, - offset: this.nextChildOffset, options - }); + ); this.initiateLoc(ast); } diff --git a/src/slang-nodes/SourceUnitMembers.js b/src/slang-nodes/SourceUnitMembers.js index 406f50a16..7743f3c00 100644 --- a/src/slang-nodes/SourceUnitMembers.js +++ b/src/slang-nodes/SourceUnitMembers.js @@ -5,16 +5,10 @@ import { SourceUnitMember } from './SourceUnitMember.js'; export class SourceUnitMembers extends SlangNode { items; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items.map( - (item) => - new SourceUnitMember({ - ast: item, - parse, - offset: this.nextChildOffset, - options - }) + (item) => new SourceUnitMember(item, this.nextChildOffset, parse, options) ); this.initiateLoc(ast); } diff --git a/src/slang-nodes/StateVariableAttribute.js b/src/slang-nodes/StateVariableAttribute.js index cf1319ffe..fb047494a 100644 --- a/src/slang-nodes/StateVariableAttribute.js +++ b/src/slang-nodes/StateVariableAttribute.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class StateVariableAttribute extends SlangNode { variant; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = ast.variant.type === 'Terminal' diff --git a/src/slang-nodes/StateVariableAttributes.js b/src/slang-nodes/StateVariableAttributes.js index ef1d99019..768d911e9 100644 --- a/src/slang-nodes/StateVariableAttributes.js +++ b/src/slang-nodes/StateVariableAttributes.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class StateVariableAttributes extends SlangNode { items; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/StateVariableDefinition.js b/src/slang-nodes/StateVariableDefinition.js index 2cfa81297..b95592121 100644 --- a/src/slang-nodes/StateVariableDefinition.js +++ b/src/slang-nodes/StateVariableDefinition.js @@ -11,7 +11,7 @@ export class StateVariableDefinition extends SlangNode { semicolon; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.typeName = parse(ast.typeName, parse, this.nextChildOffset); this.attributes = parse(ast.attributes, parse, this.nextChildOffset); diff --git a/src/slang-nodes/StateVariableDefinitionValue.js b/src/slang-nodes/StateVariableDefinitionValue.js index 15fb44bbf..cc6479465 100644 --- a/src/slang-nodes/StateVariableDefinitionValue.js +++ b/src/slang-nodes/StateVariableDefinitionValue.js @@ -8,7 +8,7 @@ export class StateVariableDefinitionValue extends SlangNode { value; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.equal = ast.equal.text; this.value = parse(ast.value, parse, this.nextChildOffset); diff --git a/src/slang-nodes/Statement.js b/src/slang-nodes/Statement.js index 0085d3b4e..5d73f9b86 100644 --- a/src/slang-nodes/Statement.js +++ b/src/slang-nodes/Statement.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class Statement extends SlangNode { variant; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = parse(ast.variant, parse, this.nextChildOffset); this.initiateLoc(ast); diff --git a/src/slang-nodes/Statements.js b/src/slang-nodes/Statements.js index 8766b4cbb..5cea1bc81 100644 --- a/src/slang-nodes/Statements.js +++ b/src/slang-nodes/Statements.js @@ -11,7 +11,7 @@ const { hardline } = doc.builders; export class Statements extends SlangNode { items; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/StorageLocation.js b/src/slang-nodes/StorageLocation.js index a922891b7..52ec21f0f 100644 --- a/src/slang-nodes/StorageLocation.js +++ b/src/slang-nodes/StorageLocation.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class StorageLocation extends SlangNode { variant; - constructor({ ast, offset }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = ast.variant.text; this.initiateLoc(ast); diff --git a/src/slang-nodes/StringExpression.js b/src/slang-nodes/StringExpression.js index 08cb7228a..a12d47c97 100644 --- a/src/slang-nodes/StringExpression.js +++ b/src/slang-nodes/StringExpression.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class StringExpression extends SlangNode { variant; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = parse(ast.variant, parse, this.nextChildOffset); this.initiateLoc(ast); diff --git a/src/slang-nodes/StringLiteral.js b/src/slang-nodes/StringLiteral.js index b2727737f..a3f45b4e6 100644 --- a/src/slang-nodes/StringLiteral.js +++ b/src/slang-nodes/StringLiteral.js @@ -4,7 +4,7 @@ import { SlangNode } from './SlangNode.js'; export class StringLiteral extends SlangNode { variant; - constructor({ ast, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = printString(ast.variant.text.slice(1, -1), options); this.initiateLoc(ast); diff --git a/src/slang-nodes/StringLiterals.js b/src/slang-nodes/StringLiterals.js index 3e4d0da96..0e54c37ef 100644 --- a/src/slang-nodes/StringLiterals.js +++ b/src/slang-nodes/StringLiterals.js @@ -6,7 +6,7 @@ const { join, hardline } = doc.builders; export class StringLiterals extends SlangNode { items; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/StructDefinition.js b/src/slang-nodes/StructDefinition.js index 35927d4ec..7dbce931b 100644 --- a/src/slang-nodes/StructDefinition.js +++ b/src/slang-nodes/StructDefinition.js @@ -11,7 +11,7 @@ export class StructDefinition extends SlangNode { closeBrace; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.structKeyword = ast.structKeyword.text; this.name = ast.name.text; diff --git a/src/slang-nodes/StructMember.js b/src/slang-nodes/StructMember.js index a8ccebd62..f7379e517 100644 --- a/src/slang-nodes/StructMember.js +++ b/src/slang-nodes/StructMember.js @@ -7,7 +7,7 @@ export class StructMember extends SlangNode { semicolon; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.typeName = parse(ast.typeName, parse, this.nextChildOffset); this.name = ast.name.text; diff --git a/src/slang-nodes/StructMembers.js b/src/slang-nodes/StructMembers.js index c37b96ee4..00c862976 100644 --- a/src/slang-nodes/StructMembers.js +++ b/src/slang-nodes/StructMembers.js @@ -7,7 +7,7 @@ const { hardline } = doc.builders; export class StructMembers extends SlangNode { items; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/ThrowStatement.js b/src/slang-nodes/ThrowStatement.js index 9b4c31a53..85b8f5a20 100644 --- a/src/slang-nodes/ThrowStatement.js +++ b/src/slang-nodes/ThrowStatement.js @@ -5,7 +5,7 @@ export class ThrowStatement extends SlangNode { semicolon; - constructor({ ast, offset }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.throwKeyword = ast.throwKeyword.text; this.semicolon = ast.semicolon.text; diff --git a/src/slang-nodes/TryStatement.js b/src/slang-nodes/TryStatement.js index 0165b7277..70bb22294 100644 --- a/src/slang-nodes/TryStatement.js +++ b/src/slang-nodes/TryStatement.js @@ -15,7 +15,7 @@ export class TryStatement extends SlangNode { catchClauses; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.tryKeyword = ast.tryKeyword.text; this.expression = parse(ast.expression, parse, this.nextChildOffset); diff --git a/src/slang-nodes/TupleDeconstructionElement.js b/src/slang-nodes/TupleDeconstructionElement.js index f8fc6d4b6..5bae8fbbd 100644 --- a/src/slang-nodes/TupleDeconstructionElement.js +++ b/src/slang-nodes/TupleDeconstructionElement.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class TupleDeconstructionElement extends SlangNode { member; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.member = ast.member ? parse(ast.member, parse, this.nextChildOffset) diff --git a/src/slang-nodes/TupleDeconstructionElements.js b/src/slang-nodes/TupleDeconstructionElements.js index 4c7b7ecaf..ff07aa03a 100644 --- a/src/slang-nodes/TupleDeconstructionElements.js +++ b/src/slang-nodes/TupleDeconstructionElements.js @@ -6,7 +6,7 @@ export class TupleDeconstructionElements extends SlangNode { separators; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/TupleDeconstructionStatement.js b/src/slang-nodes/TupleDeconstructionStatement.js index a780b587a..fc1702da0 100644 --- a/src/slang-nodes/TupleDeconstructionStatement.js +++ b/src/slang-nodes/TupleDeconstructionStatement.js @@ -18,7 +18,7 @@ export class TupleDeconstructionStatement extends SlangNode { semicolon; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.varKeyword = ast.varKeyword?.text; this.openParen = ast.openParen.text; diff --git a/src/slang-nodes/TupleExpression.js b/src/slang-nodes/TupleExpression.js index 92960f792..efcdf05be 100644 --- a/src/slang-nodes/TupleExpression.js +++ b/src/slang-nodes/TupleExpression.js @@ -7,19 +7,19 @@ export class TupleExpression extends SlangNode { closeParen; - constructor({ ast, parse, offset, kind, loc, openParen, items, closeParen }) { + constructor(ast, offset, parse, options) { super(ast, offset); - if (ast) { + if (offset) { this.openParen = ast.openParen.text; this.items = parse(ast.items, parse, this.nextChildOffset); this.closeParen = ast.closeParen.text; this.initiateLoc(ast); } else { - this.kind = kind; - this.loc = loc; - this.openParen = openParen; - this.items = items; - this.closeParen = closeParen; + this.kind = ast.kind; + this.loc = ast.loc; + this.openParen = ast.openParen; + this.items = ast.items; + this.closeParen = ast.closeParen; } } diff --git a/src/slang-nodes/TupleMember.js b/src/slang-nodes/TupleMember.js index aec3af9ca..ddb09ab8f 100644 --- a/src/slang-nodes/TupleMember.js +++ b/src/slang-nodes/TupleMember.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class TupleMember extends SlangNode { variant; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = parse(ast.variant, parse, this.nextChildOffset); this.initiateLoc(ast); diff --git a/src/slang-nodes/TupleValue.js b/src/slang-nodes/TupleValue.js index 165a142b5..916566563 100644 --- a/src/slang-nodes/TupleValue.js +++ b/src/slang-nodes/TupleValue.js @@ -3,17 +3,17 @@ import { SlangNode } from './SlangNode.js'; export class TupleValue extends SlangNode { expression; - constructor({ ast, parse, offset, kind, loc, expression }) { + constructor(ast, offset, parse, options) { super(ast, offset); - if (ast) { + if (offset) { this.expression = ast.expression ? parse(ast.expression, parse, this.nextChildOffset) : undefined; this.initiateLoc(ast); } else { - this.kind = kind; - this.loc = loc; - this.expression = expression; + this.kind = ast.kind; + this.loc = ast.loc; + this.expression = ast.expression; } } diff --git a/src/slang-nodes/TupleValues.js b/src/slang-nodes/TupleValues.js index bd8a9591c..96920413d 100644 --- a/src/slang-nodes/TupleValues.js +++ b/src/slang-nodes/TupleValues.js @@ -7,19 +7,19 @@ export class TupleValues extends SlangNode { separators; - constructor({ ast, parse, offset, kind, loc, items, separators }) { + constructor(ast, offset, parse, options) { super(ast, offset); - if (ast) { + if (offset) { this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) ); this.separators = ast.separators.map((separator) => separator.text); this.initiateLoc(ast); } else { - this.kind = kind; - this.loc = loc; - this.items = items; - this.separators = separators; + this.kind = ast.kind; + this.loc = ast.loc; + this.items = ast.items; + this.separators = ast.separators; } } diff --git a/src/slang-nodes/TypeExpression.js b/src/slang-nodes/TypeExpression.js index 34ef6c576..64be3ef3d 100644 --- a/src/slang-nodes/TypeExpression.js +++ b/src/slang-nodes/TypeExpression.js @@ -9,7 +9,7 @@ export class TypeExpression extends SlangNode { closeParen; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.typeKeyword = ast.typeKeyword.text; this.openParen = ast.openParen.text; diff --git a/src/slang-nodes/TypeName.js b/src/slang-nodes/TypeName.js index 05bacdbfe..df155dca3 100644 --- a/src/slang-nodes/TypeName.js +++ b/src/slang-nodes/TypeName.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class TypeName extends SlangNode { variant; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = parse(ast.variant, parse, this.nextChildOffset); this.initiateLoc(ast); diff --git a/src/slang-nodes/TypedTupleMember.js b/src/slang-nodes/TypedTupleMember.js index 2cd964218..b9f43b006 100644 --- a/src/slang-nodes/TypedTupleMember.js +++ b/src/slang-nodes/TypedTupleMember.js @@ -7,7 +7,7 @@ export class TypedTupleMember extends SlangNode { name; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.typeName = parse(ast.typeName, parse, this.nextChildOffset); this.storageLocation = ast.storageLocation diff --git a/src/slang-nodes/UncheckedBlock.js b/src/slang-nodes/UncheckedBlock.js index 6603a1d4c..95fd10901 100644 --- a/src/slang-nodes/UncheckedBlock.js +++ b/src/slang-nodes/UncheckedBlock.js @@ -5,7 +5,7 @@ export class UncheckedBlock extends SlangNode { block; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.uncheckedKeyword = ast.uncheckedKeyword.text; this.block = parse(ast.block, parse, this.nextChildOffset); diff --git a/src/slang-nodes/UnicodeStringLiteral.js b/src/slang-nodes/UnicodeStringLiteral.js index a2ef325d5..a05199e24 100644 --- a/src/slang-nodes/UnicodeStringLiteral.js +++ b/src/slang-nodes/UnicodeStringLiteral.js @@ -4,7 +4,7 @@ import { SlangNode } from './SlangNode.js'; export class UnicodeStringLiteral extends SlangNode { variant; - constructor({ ast, options, offset }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = `unicode${printString(ast.variant.text.slice(8, -1), options)}`; this.initiateLoc(ast); diff --git a/src/slang-nodes/UnicodeStringLiterals.js b/src/slang-nodes/UnicodeStringLiterals.js index c2166bfda..8829277b6 100644 --- a/src/slang-nodes/UnicodeStringLiterals.js +++ b/src/slang-nodes/UnicodeStringLiterals.js @@ -6,7 +6,7 @@ const { join, hardline } = doc.builders; export class UnicodeStringLiterals extends SlangNode { items; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/UnnamedFunctionAttribute.js b/src/slang-nodes/UnnamedFunctionAttribute.js index dbd570464..de334543d 100644 --- a/src/slang-nodes/UnnamedFunctionAttribute.js +++ b/src/slang-nodes/UnnamedFunctionAttribute.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class UnnamedFunctionAttribute extends SlangNode { variant; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = ast.variant.type === 'Terminal' diff --git a/src/slang-nodes/UnnamedFunctionAttributes.js b/src/slang-nodes/UnnamedFunctionAttributes.js index 618de8b86..9c7845328 100644 --- a/src/slang-nodes/UnnamedFunctionAttributes.js +++ b/src/slang-nodes/UnnamedFunctionAttributes.js @@ -7,7 +7,7 @@ const { line } = doc.builders; export class UnnamedFunctionAttributes extends SlangNode { items; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items .map((item) => parse(item, parse, this.nextChildOffset)) diff --git a/src/slang-nodes/UnnamedFunctionDefinition.js b/src/slang-nodes/UnnamedFunctionDefinition.js index c865e1747..d00bae4f1 100644 --- a/src/slang-nodes/UnnamedFunctionDefinition.js +++ b/src/slang-nodes/UnnamedFunctionDefinition.js @@ -10,7 +10,7 @@ export class UnnamedFunctionDefinition extends SlangNode { body; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.functionKeyword = ast.functionKeyword.text; this.parameters = parse(ast.parameters, parse, this.nextChildOffset); diff --git a/src/slang-nodes/UntypedTupleMember.js b/src/slang-nodes/UntypedTupleMember.js index d5c102ea5..385493c4c 100644 --- a/src/slang-nodes/UntypedTupleMember.js +++ b/src/slang-nodes/UntypedTupleMember.js @@ -5,7 +5,7 @@ export class UntypedTupleMember extends SlangNode { name; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.storageLocation = ast.storageLocation ? parse(ast.storageLocation, parse, this.nextChildOffset) diff --git a/src/slang-nodes/UserDefinedValueTypeDefinition.js b/src/slang-nodes/UserDefinedValueTypeDefinition.js index 7bc9e9f8a..dfb6965fe 100644 --- a/src/slang-nodes/UserDefinedValueTypeDefinition.js +++ b/src/slang-nodes/UserDefinedValueTypeDefinition.js @@ -11,7 +11,7 @@ export class UserDefinedValueTypeDefinition extends SlangNode { semicolon; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.typeKeyword = ast.typeKeyword.text; this.name = ast.name.text; diff --git a/src/slang-nodes/UsingAlias.js b/src/slang-nodes/UsingAlias.js index c7f114b19..4fedb8d1c 100644 --- a/src/slang-nodes/UsingAlias.js +++ b/src/slang-nodes/UsingAlias.js @@ -5,7 +5,7 @@ export class UsingAlias extends SlangNode { operator; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.asKeyword = ast.asKeyword.text; this.operator = parse(ast.operator, parse, this.nextChildOffset); diff --git a/src/slang-nodes/UsingClause.js b/src/slang-nodes/UsingClause.js index 7ce10f1b4..abc0cd40a 100644 --- a/src/slang-nodes/UsingClause.js +++ b/src/slang-nodes/UsingClause.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class UsingClause extends SlangNode { variant; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = parse(ast.variant, parse, this.nextChildOffset); this.initiateLoc(ast); diff --git a/src/slang-nodes/UsingDeconstruction.js b/src/slang-nodes/UsingDeconstruction.js index ae784d77d..959b274eb 100644 --- a/src/slang-nodes/UsingDeconstruction.js +++ b/src/slang-nodes/UsingDeconstruction.js @@ -7,7 +7,7 @@ export class UsingDeconstruction extends SlangNode { closeBrace; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.openBrace = ast.openBrace.text; this.symbols = parse(ast.symbols, parse, this.nextChildOffset); diff --git a/src/slang-nodes/UsingDeconstructionSymbol.js b/src/slang-nodes/UsingDeconstructionSymbol.js index 449ae9fd0..bf740de6c 100644 --- a/src/slang-nodes/UsingDeconstructionSymbol.js +++ b/src/slang-nodes/UsingDeconstructionSymbol.js @@ -5,7 +5,7 @@ export class UsingDeconstructionSymbol extends SlangNode { alias; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.name = parse(ast.name, parse, this.nextChildOffset); this.alias = ast.alias diff --git a/src/slang-nodes/UsingDeconstructionSymbols.js b/src/slang-nodes/UsingDeconstructionSymbols.js index 76ec1afd7..e0442274d 100644 --- a/src/slang-nodes/UsingDeconstructionSymbols.js +++ b/src/slang-nodes/UsingDeconstructionSymbols.js @@ -9,7 +9,7 @@ export class UsingDeconstructionSymbols extends SlangNode { separators; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/UsingDirective.js b/src/slang-nodes/UsingDirective.js index b25971139..8319c6265 100644 --- a/src/slang-nodes/UsingDirective.js +++ b/src/slang-nodes/UsingDirective.js @@ -13,7 +13,7 @@ export class UsingDirective extends SlangNode { semicolon; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.usingKeyword = ast.usingKeyword.text; this.clause = parse(ast.clause, parse, this.nextChildOffset); diff --git a/src/slang-nodes/UsingOperator.js b/src/slang-nodes/UsingOperator.js index abe45fc5a..ce704784c 100644 --- a/src/slang-nodes/UsingOperator.js +++ b/src/slang-nodes/UsingOperator.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class UsingOperator extends SlangNode { variant; - constructor({ ast, offset }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = ast.variant.text; this.initiateLoc(ast); diff --git a/src/slang-nodes/UsingTarget.js b/src/slang-nodes/UsingTarget.js index 558e5c7bc..ffcc61b06 100644 --- a/src/slang-nodes/UsingTarget.js +++ b/src/slang-nodes/UsingTarget.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class UsingTarget extends SlangNode { variant; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = ast.variant.type === 'Terminal' diff --git a/src/slang-nodes/VariableDeclarationStatement.js b/src/slang-nodes/VariableDeclarationStatement.js index d2724aadf..4f83a6eec 100644 --- a/src/slang-nodes/VariableDeclarationStatement.js +++ b/src/slang-nodes/VariableDeclarationStatement.js @@ -16,7 +16,7 @@ export class VariableDeclarationStatement extends SlangNode { semicolon; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variableType = parse(ast.variableType, parse, this.nextChildOffset); this.storageLocation = ast.storageLocation diff --git a/src/slang-nodes/VariableDeclarationType.js b/src/slang-nodes/VariableDeclarationType.js index 03989f148..b8012a2f6 100644 --- a/src/slang-nodes/VariableDeclarationType.js +++ b/src/slang-nodes/VariableDeclarationType.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class VariableDeclarationType extends SlangNode { variant; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = ast.variant.type === 'Terminal' diff --git a/src/slang-nodes/VariableDeclarationValue.js b/src/slang-nodes/VariableDeclarationValue.js index 96ab7323c..037ede3fb 100644 --- a/src/slang-nodes/VariableDeclarationValue.js +++ b/src/slang-nodes/VariableDeclarationValue.js @@ -5,7 +5,7 @@ export class VariableDeclarationValue extends SlangNode { expression; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.equal = ast.equal.text; this.expression = parse(ast.expression, parse, this.nextChildOffset); diff --git a/src/slang-nodes/VersionComparator.js b/src/slang-nodes/VersionComparator.js index 5b4d25d4d..c302a4790 100644 --- a/src/slang-nodes/VersionComparator.js +++ b/src/slang-nodes/VersionComparator.js @@ -5,7 +5,7 @@ export class VersionComparator extends SlangNode { operand; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.operator = ast.operator.text; this.operand = parse(ast.operand, parse, this.nextChildOffset); diff --git a/src/slang-nodes/VersionExpression.js b/src/slang-nodes/VersionExpression.js index b51dfad32..ac5f05996 100644 --- a/src/slang-nodes/VersionExpression.js +++ b/src/slang-nodes/VersionExpression.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class VersionExpression extends SlangNode { variant; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = ast.variant.type === 'Terminal' diff --git a/src/slang-nodes/VersionExpressionSet.js b/src/slang-nodes/VersionExpressionSet.js index 8fe7e3d13..8ac475e99 100644 --- a/src/slang-nodes/VersionExpressionSet.js +++ b/src/slang-nodes/VersionExpressionSet.js @@ -6,7 +6,7 @@ const { join } = doc.builders; export class VersionExpressionSet extends SlangNode { items; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/VersionExpressionSets.js b/src/slang-nodes/VersionExpressionSets.js index a4d645c70..cd9dd1333 100644 --- a/src/slang-nodes/VersionExpressionSets.js +++ b/src/slang-nodes/VersionExpressionSets.js @@ -5,7 +5,7 @@ export class VersionExpressionSets extends SlangNode { separators; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/VersionPragma.js b/src/slang-nodes/VersionPragma.js index cb3742161..a4cb5e094 100644 --- a/src/slang-nodes/VersionPragma.js +++ b/src/slang-nodes/VersionPragma.js @@ -5,7 +5,7 @@ export class VersionPragma extends SlangNode { sets; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.solidityKeyword = ast.solidityKeyword.text; this.sets = parse(ast.sets, parse, this.nextChildOffset); diff --git a/src/slang-nodes/VersionRange.js b/src/slang-nodes/VersionRange.js index faf7e8537..4cda609d3 100644 --- a/src/slang-nodes/VersionRange.js +++ b/src/slang-nodes/VersionRange.js @@ -7,7 +7,7 @@ export class VersionRange extends SlangNode { rightOperand; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.leftOperand = parse(ast.leftOperand, parse, this.nextChildOffset); this.operator = ast.operator.text; diff --git a/src/slang-nodes/VersionSpecifiers.js b/src/slang-nodes/VersionSpecifiers.js index c84143ff6..da591cd40 100644 --- a/src/slang-nodes/VersionSpecifiers.js +++ b/src/slang-nodes/VersionSpecifiers.js @@ -5,7 +5,7 @@ export class VersionSpecifiers extends SlangNode { separators; - constructor({ ast, offset }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items.map((item) => item.text); this.separators = ast.separators.map((separator) => separator.text); diff --git a/src/slang-nodes/WhileStatement.js b/src/slang-nodes/WhileStatement.js index 88d08aa70..281d66a3f 100644 --- a/src/slang-nodes/WhileStatement.js +++ b/src/slang-nodes/WhileStatement.js @@ -20,7 +20,7 @@ export class WhileStatement extends SlangNode { body; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.whileKeyword = ast.whileKeyword.text; this.openParen = ast.openParen.text; diff --git a/src/slang-nodes/YulArguments.js b/src/slang-nodes/YulArguments.js index 9dfc2907b..d6e50d03c 100644 --- a/src/slang-nodes/YulArguments.js +++ b/src/slang-nodes/YulArguments.js @@ -6,7 +6,7 @@ export class YulArguments extends SlangNode { separators; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/YulAssignmentOperator.js b/src/slang-nodes/YulAssignmentOperator.js index fd12cd4f1..acfe45c95 100644 --- a/src/slang-nodes/YulAssignmentOperator.js +++ b/src/slang-nodes/YulAssignmentOperator.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class YulAssignmentOperator extends SlangNode { variant; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = ast.variant.type === 'Terminal' diff --git a/src/slang-nodes/YulAssignmentStatement.js b/src/slang-nodes/YulAssignmentStatement.js index c49db3d89..9da493a2d 100644 --- a/src/slang-nodes/YulAssignmentStatement.js +++ b/src/slang-nodes/YulAssignmentStatement.js @@ -7,7 +7,7 @@ export class YulAssignmentStatement extends SlangNode { expression; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.names = parse(ast.names, parse, this.nextChildOffset); this.assignment = parse(ast.assignment, parse, this.nextChildOffset); diff --git a/src/slang-nodes/YulBlock.js b/src/slang-nodes/YulBlock.js index d328701f9..8a1358f94 100644 --- a/src/slang-nodes/YulBlock.js +++ b/src/slang-nodes/YulBlock.js @@ -7,7 +7,7 @@ export class YulBlock extends SlangNode { closeBrace; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.openBrace = ast.openBrace.text; this.statements = parse(ast.statements, parse, this.nextChildOffset); diff --git a/src/slang-nodes/YulBreakStatement.js b/src/slang-nodes/YulBreakStatement.js index 7e7c9484a..b986c8558 100644 --- a/src/slang-nodes/YulBreakStatement.js +++ b/src/slang-nodes/YulBreakStatement.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class YulBreakStatement extends SlangNode { breakKeyword; - constructor({ ast, offset }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.breakKeyword = ast.breakKeyword.text; this.initiateLoc(ast); diff --git a/src/slang-nodes/YulBuiltInFunction.js b/src/slang-nodes/YulBuiltInFunction.js index dc0396546..3c3ff0a51 100644 --- a/src/slang-nodes/YulBuiltInFunction.js +++ b/src/slang-nodes/YulBuiltInFunction.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class YulBuiltInFunction extends SlangNode { variant; - constructor({ ast, offset }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = ast.variant.text; this.initiateLoc(ast); diff --git a/src/slang-nodes/YulColonAndEqual.js b/src/slang-nodes/YulColonAndEqual.js index 0f714cfb0..f812dbef2 100644 --- a/src/slang-nodes/YulColonAndEqual.js +++ b/src/slang-nodes/YulColonAndEqual.js @@ -5,7 +5,7 @@ export class YulColonAndEqual extends SlangNode { equal; - constructor({ ast, offset }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.colon = ast.colon.text; this.equal = ast.equal.text; diff --git a/src/slang-nodes/YulContinueStatement.js b/src/slang-nodes/YulContinueStatement.js index 11369ead7..10b4b6241 100644 --- a/src/slang-nodes/YulContinueStatement.js +++ b/src/slang-nodes/YulContinueStatement.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class YulContinueStatement extends SlangNode { continueKeyword; - constructor({ ast, offset }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.continueKeyword = ast.continueKeyword.text; this.initiateLoc(ast); diff --git a/src/slang-nodes/YulDefaultCase.js b/src/slang-nodes/YulDefaultCase.js index e962fdc1b..20168bba5 100644 --- a/src/slang-nodes/YulDefaultCase.js +++ b/src/slang-nodes/YulDefaultCase.js @@ -5,7 +5,7 @@ export class YulDefaultCase extends SlangNode { body; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.defaultKeyword = ast.defaultKeyword.text; this.body = parse(ast.body, parse, this.nextChildOffset); diff --git a/src/slang-nodes/YulExpression.js b/src/slang-nodes/YulExpression.js index 4d9eca4c9..71b585f99 100644 --- a/src/slang-nodes/YulExpression.js +++ b/src/slang-nodes/YulExpression.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class YulExpression extends SlangNode { variant; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = parse(ast.variant, parse, this.nextChildOffset); this.initiateLoc(ast); diff --git a/src/slang-nodes/YulForStatement.js b/src/slang-nodes/YulForStatement.js index 6190d0991..e6fce20a8 100644 --- a/src/slang-nodes/YulForStatement.js +++ b/src/slang-nodes/YulForStatement.js @@ -11,7 +11,7 @@ export class YulForStatement extends SlangNode { body; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.forKeyword = ast.forKeyword.text; this.initialization = parse( diff --git a/src/slang-nodes/YulFunctionCallExpression.js b/src/slang-nodes/YulFunctionCallExpression.js index e697f1d36..119052cf5 100644 --- a/src/slang-nodes/YulFunctionCallExpression.js +++ b/src/slang-nodes/YulFunctionCallExpression.js @@ -9,7 +9,7 @@ export class YulFunctionCallExpression extends SlangNode { closeParen; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.operand = parse(ast.operand, parse, this.nextChildOffset); this.openParen = ast.openParen.text; diff --git a/src/slang-nodes/YulFunctionDefinition.js b/src/slang-nodes/YulFunctionDefinition.js index 0d21545a9..f09181414 100644 --- a/src/slang-nodes/YulFunctionDefinition.js +++ b/src/slang-nodes/YulFunctionDefinition.js @@ -11,7 +11,7 @@ export class YulFunctionDefinition extends SlangNode { body; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.functionKeyword = ast.functionKeyword.text; this.name = ast.name.text; diff --git a/src/slang-nodes/YulIfStatement.js b/src/slang-nodes/YulIfStatement.js index 95d1df0b6..6cdd27366 100644 --- a/src/slang-nodes/YulIfStatement.js +++ b/src/slang-nodes/YulIfStatement.js @@ -7,7 +7,7 @@ export class YulIfStatement extends SlangNode { body; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.ifKeyword = ast.ifKeyword.text; this.condition = parse(ast.condition, parse, this.nextChildOffset); diff --git a/src/slang-nodes/YulLabel.js b/src/slang-nodes/YulLabel.js index 3e0dbf674..b79ff5828 100644 --- a/src/slang-nodes/YulLabel.js +++ b/src/slang-nodes/YulLabel.js @@ -7,7 +7,7 @@ export class YulLabel extends SlangNode { colon; - constructor({ ast, offset }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.label = ast.label.text; this.colon = ast.colon.text; diff --git a/src/slang-nodes/YulLeaveStatement.js b/src/slang-nodes/YulLeaveStatement.js index 289ef9ae9..47d408a96 100644 --- a/src/slang-nodes/YulLeaveStatement.js +++ b/src/slang-nodes/YulLeaveStatement.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class YulLeaveStatement extends SlangNode { leaveKeyword; - constructor({ ast, offset }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.leaveKeyword = ast.leaveKeyword.text; this.initiateLoc(ast); diff --git a/src/slang-nodes/YulLiteral.js b/src/slang-nodes/YulLiteral.js index 2d0c7dce9..62b66f88b 100644 --- a/src/slang-nodes/YulLiteral.js +++ b/src/slang-nodes/YulLiteral.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class YulLiteral extends SlangNode { variant; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = ast.variant.type === 'Terminal' diff --git a/src/slang-nodes/YulParameters.js b/src/slang-nodes/YulParameters.js index 8a7e77306..c75267a93 100644 --- a/src/slang-nodes/YulParameters.js +++ b/src/slang-nodes/YulParameters.js @@ -6,7 +6,7 @@ export class YulParameters extends SlangNode { separators; - constructor({ ast, offset }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items.map((item) => item.text); this.separators = ast.separators.map((separator) => separator.text); diff --git a/src/slang-nodes/YulParametersDeclaration.js b/src/slang-nodes/YulParametersDeclaration.js index dd8349cf5..a27702136 100644 --- a/src/slang-nodes/YulParametersDeclaration.js +++ b/src/slang-nodes/YulParametersDeclaration.js @@ -7,7 +7,7 @@ export class YulParametersDeclaration extends SlangNode { closeParen; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.openParen = ast.openParen.text; this.parameters = parse(ast.parameters, parse, this.nextChildOffset); diff --git a/src/slang-nodes/YulPath.js b/src/slang-nodes/YulPath.js index acf1a0aec..d540d2180 100644 --- a/src/slang-nodes/YulPath.js +++ b/src/slang-nodes/YulPath.js @@ -5,7 +5,7 @@ export class YulPath extends SlangNode { separators; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/YulPathComponent.js b/src/slang-nodes/YulPathComponent.js index 8f02274c6..ae06ca440 100644 --- a/src/slang-nodes/YulPathComponent.js +++ b/src/slang-nodes/YulPathComponent.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class YulPathComponent extends SlangNode { variant; - constructor({ ast, offset }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = ast.variant.text; this.initiateLoc(ast); diff --git a/src/slang-nodes/YulPaths.js b/src/slang-nodes/YulPaths.js index 328a8238e..c7737f59f 100644 --- a/src/slang-nodes/YulPaths.js +++ b/src/slang-nodes/YulPaths.js @@ -5,7 +5,7 @@ export class YulPaths extends SlangNode { separators; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/YulReturnVariables.js b/src/slang-nodes/YulReturnVariables.js index 49499d93b..e963f0e83 100644 --- a/src/slang-nodes/YulReturnVariables.js +++ b/src/slang-nodes/YulReturnVariables.js @@ -9,7 +9,7 @@ export class YulReturnVariables extends SlangNode { separators; - constructor({ ast, offset }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items.map((item) => item.text); this.separators = ast.separators.map((separator) => separator.text); diff --git a/src/slang-nodes/YulReturnsDeclaration.js b/src/slang-nodes/YulReturnsDeclaration.js index f2f0a792f..d578e8cbd 100644 --- a/src/slang-nodes/YulReturnsDeclaration.js +++ b/src/slang-nodes/YulReturnsDeclaration.js @@ -9,7 +9,7 @@ export class YulReturnsDeclaration extends SlangNode { variables; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.minusGreaterThan = ast.minusGreaterThan.text; this.variables = parse(ast.variables, parse, this.nextChildOffset); diff --git a/src/slang-nodes/YulStatement.js b/src/slang-nodes/YulStatement.js index 82a9860e6..720f4aaeb 100644 --- a/src/slang-nodes/YulStatement.js +++ b/src/slang-nodes/YulStatement.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class YulStatement extends SlangNode { variant; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = parse(ast.variant, parse, this.nextChildOffset); this.initiateLoc(ast); diff --git a/src/slang-nodes/YulStatements.js b/src/slang-nodes/YulStatements.js index e343c5c05..ee90e0054 100644 --- a/src/slang-nodes/YulStatements.js +++ b/src/slang-nodes/YulStatements.js @@ -11,7 +11,7 @@ const { hardline } = doc.builders; export class YulStatements extends SlangNode { items; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/YulSwitchCase.js b/src/slang-nodes/YulSwitchCase.js index 17567bec6..666c3c2f8 100644 --- a/src/slang-nodes/YulSwitchCase.js +++ b/src/slang-nodes/YulSwitchCase.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class YulSwitchCase extends SlangNode { variant; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.variant = parse(ast.variant, parse, this.nextChildOffset); this.initiateLoc(ast); diff --git a/src/slang-nodes/YulSwitchCases.js b/src/slang-nodes/YulSwitchCases.js index 991683e8b..dbbbaf9cc 100644 --- a/src/slang-nodes/YulSwitchCases.js +++ b/src/slang-nodes/YulSwitchCases.js @@ -6,7 +6,7 @@ const { hardline, join } = doc.builders; export class YulSwitchCases extends SlangNode { items; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/YulSwitchStatement.js b/src/slang-nodes/YulSwitchStatement.js index a2fad14cf..4e6c7493c 100644 --- a/src/slang-nodes/YulSwitchStatement.js +++ b/src/slang-nodes/YulSwitchStatement.js @@ -10,7 +10,7 @@ export class YulSwitchStatement extends SlangNode { cases; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.switchKeyword = ast.switchKeyword.text; this.expression = parse(ast.expression, parse, this.nextChildOffset); diff --git a/src/slang-nodes/YulValueCase.js b/src/slang-nodes/YulValueCase.js index b7e3bcafc..0bbd022da 100644 --- a/src/slang-nodes/YulValueCase.js +++ b/src/slang-nodes/YulValueCase.js @@ -7,7 +7,7 @@ export class YulValueCase extends SlangNode { body; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.caseKeyword = ast.caseKeyword.text; this.value = parse(ast.value, parse, this.nextChildOffset); diff --git a/src/slang-nodes/YulVariableAssignmentStatement.js b/src/slang-nodes/YulVariableAssignmentStatement.js index 6169c1778..cf81a43d6 100644 --- a/src/slang-nodes/YulVariableAssignmentStatement.js +++ b/src/slang-nodes/YulVariableAssignmentStatement.js @@ -7,7 +7,7 @@ export class YulVariableAssignmentStatement extends SlangNode { expression; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.names = parse(ast.names, parse, this.nextChildOffset); this.assignment = parse(ast.assignment, parse, this.nextChildOffset); diff --git a/src/slang-nodes/YulVariableDeclarationStatement.js b/src/slang-nodes/YulVariableDeclarationStatement.js index bdc5abf34..34ba10439 100644 --- a/src/slang-nodes/YulVariableDeclarationStatement.js +++ b/src/slang-nodes/YulVariableDeclarationStatement.js @@ -7,7 +7,7 @@ export class YulVariableDeclarationStatement extends SlangNode { value; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.letKeyword = ast.letKeyword.text; this.names = ast.names.text; diff --git a/src/slang-nodes/YulVariableDeclarationValue.js b/src/slang-nodes/YulVariableDeclarationValue.js index 556558094..d59c8bb03 100644 --- a/src/slang-nodes/YulVariableDeclarationValue.js +++ b/src/slang-nodes/YulVariableDeclarationValue.js @@ -5,7 +5,7 @@ export class YulVariableDeclarationValue extends SlangNode { expression; - constructor({ ast, parse, offset, options }) { + constructor(ast, offset, parse, options) { super(ast, offset); this.assignment = parse(ast.assignment, parse, this.nextChildOffset); this.expression = parse(ast.expression, parse, this.nextChildOffset); diff --git a/src/slangParser.js b/src/slangParser.js index 006b22aa2..924bdd8d4 100644 --- a/src/slangParser.js +++ b/src/slangParser.js @@ -9,12 +9,7 @@ import * as parsers from './slang-nodes/index.js'; const genericParseBuilder = (options) => (ast, parseFunction, offset = 0) => - new parsers[ast.cst.kind]({ - ast, - options, - parse: parseFunction, - offset - }); + new parsers[ast.cst.kind](ast, offset, parseFunction, options); function parse(text, _parsers, options = _parsers) { const compiler = coerce(options.compiler); diff --git a/src/slangPrinter.js b/src/slangPrinter.js index 32f66791c..4a6e64654 100644 --- a/src/slangPrinter.js +++ b/src/slangPrinter.js @@ -45,7 +45,7 @@ function genericPrint(path, options, print) { console.log(nodeType); } } catch (error) { - throw new Error(`${JSON.stringify(node)} ${error}\n`); + throw new Error(`${JSON.stringify(nodeType)} ${error}\n`); } return ret; } diff --git a/tests/config/run-format-test.js b/tests/config/run-format-test.js index 7df969534..2375dadde 100644 --- a/tests/config/run-format-test.js +++ b/tests/config/run-format-test.js @@ -45,7 +45,7 @@ const testsWithSlang = new Map( // "AllSolidityFeatures/AllSolidityFeatures.sol", // "AssemblyV0.4.26/Assembly.sol", // TODO: Report to Nomic Foundation? // "BasicIterator/BasicIterator.sol", // TODO: Fix solidity-parser comments - // "Comments/Comments.sol", // TODO: finish Comments + "Comments/Comments.sol", // TODO: finish Comments // "Etc/Etc.sol", // TODO: Comments for if Statements // "FunctionDefinitions/FunctionDefinitions.sol", // TODO: remove () safely in modifiers without arguments // "IndexOf/IndexOf.sol", // TODO: Finish comments and file level functions From 61c94836acca66be698a0a99a3dbc2fff370a010 Mon Sep 17 00:00:00 2001 From: Klaus Date: Sun, 14 Jul 2024 01:51:38 +1200 Subject: [PATCH 066/160] simplifying print function signature --- src/slang-nodes/AdditiveExpression.js | 2 +- src/slang-nodes/AndExpression.js | 2 +- src/slang-nodes/ArgumentsDeclaration.js | 2 +- src/slang-nodes/ArrayExpression.js | 2 +- src/slang-nodes/ArrayTypeName.js | 2 +- src/slang-nodes/ArrayValues.js | 2 +- src/slang-nodes/AssemblyFlags.js | 2 +- src/slang-nodes/AssemblyFlagsDeclaration.js | 2 +- src/slang-nodes/AssemblyStatement.js | 2 +- src/slang-nodes/AssignmentExpression.js | 2 +- src/slang-nodes/BitwiseAndExpression.js | 2 +- src/slang-nodes/BitwiseOrExpression.js | 2 +- src/slang-nodes/BitwiseXorExpression.js | 2 +- src/slang-nodes/Block.js | 2 +- src/slang-nodes/CallOptions.js | 2 +- src/slang-nodes/CallOptionsExpression.js | 2 +- src/slang-nodes/CatchClause.js | 2 +- src/slang-nodes/CatchClauseError.js | 2 +- src/slang-nodes/CatchClauses.js | 2 +- src/slang-nodes/ComparisonExpression.js | 2 +- src/slang-nodes/ConditionalExpression.js | 2 +- src/slang-nodes/ConstantDefinition.js | 2 +- src/slang-nodes/ConstructorAttribute.js | 2 +- src/slang-nodes/ConstructorAttributes.js | 2 +- src/slang-nodes/ConstructorDefinition.js | 2 +- src/slang-nodes/ContractDefinition.js | 2 +- src/slang-nodes/ContractMember.js | 2 +- src/slang-nodes/ContractMembers.js | 2 +- src/slang-nodes/DecimalNumberExpression.js | 2 +- src/slang-nodes/DoWhileStatement.js | 2 +- src/slang-nodes/ElementaryType.js | 2 +- src/slang-nodes/ElseBranch.js | 2 +- src/slang-nodes/EmitStatement.js | 2 +- src/slang-nodes/EnumDefinition.js | 2 +- src/slang-nodes/EqualityExpression.js | 2 +- src/slang-nodes/ErrorDefinition.js | 2 +- src/slang-nodes/ErrorParameter.js | 2 +- src/slang-nodes/ErrorParameters.js | 2 +- src/slang-nodes/ErrorParametersDeclaration.js | 2 +- src/slang-nodes/EventDefinition.js | 2 +- src/slang-nodes/EventParameter.js | 2 +- src/slang-nodes/EventParameters.js | 2 +- src/slang-nodes/EventParametersDeclaration.js | 2 +- src/slang-nodes/ExperimentalFeature.js | 2 +- src/slang-nodes/ExperimentalPragma.js | 2 +- src/slang-nodes/ExponentiationExpression.js | 2 +- src/slang-nodes/Expression.js | 2 +- src/slang-nodes/ExpressionStatement.js | 2 +- src/slang-nodes/FallbackFunctionAttribute.js | 2 +- src/slang-nodes/FallbackFunctionAttributes.js | 2 +- src/slang-nodes/FallbackFunctionDefinition.js | 2 +- src/slang-nodes/ForStatement.js | 2 +- src/slang-nodes/ForStatementCondition.js | 2 +- src/slang-nodes/ForStatementInitialization.js | 2 +- src/slang-nodes/FunctionAttribute.js | 2 +- src/slang-nodes/FunctionAttributes.js | 2 +- src/slang-nodes/FunctionBody.js | 2 +- src/slang-nodes/FunctionCallExpression.js | 2 +- src/slang-nodes/FunctionDefinition.js | 2 +- src/slang-nodes/FunctionType.js | 2 +- src/slang-nodes/FunctionTypeAttributes.js | 2 +- src/slang-nodes/HexNumberExpression.js | 2 +- src/slang-nodes/HexStringLiterals.js | 2 +- src/slang-nodes/IfStatement.js | 2 +- src/slang-nodes/ImportClause.js | 2 +- src/slang-nodes/ImportDeconstruction.js | 2 +- src/slang-nodes/ImportDeconstructionSymbol.js | 2 +- src/slang-nodes/ImportDeconstructionSymbols.js | 2 +- src/slang-nodes/ImportDirective.js | 2 +- src/slang-nodes/IndexAccessEnd.js | 2 +- src/slang-nodes/IndexAccessExpression.js | 2 +- src/slang-nodes/InheritanceSpecifier.js | 2 +- src/slang-nodes/InheritanceType.js | 2 +- src/slang-nodes/InheritanceTypes.js | 2 +- src/slang-nodes/InterfaceDefinition.js | 2 +- src/slang-nodes/InterfaceMembers.js | 2 +- src/slang-nodes/LibraryDefinition.js | 2 +- src/slang-nodes/LibraryMembers.js | 2 +- src/slang-nodes/MappingKey.js | 2 +- src/slang-nodes/MappingKeyType.js | 2 +- src/slang-nodes/MappingType.js | 2 +- src/slang-nodes/MappingValue.js | 2 +- src/slang-nodes/MemberAccessExpression.js | 2 +- src/slang-nodes/ModifierAttribute.js | 2 +- src/slang-nodes/ModifierAttributes.js | 2 +- src/slang-nodes/ModifierDefinition.js | 2 +- src/slang-nodes/ModifierInvocation.js | 2 +- src/slang-nodes/MultiplicativeExpression.js | 2 +- src/slang-nodes/NamedArgument.js | 2 +- src/slang-nodes/NamedArgumentGroup.js | 2 +- src/slang-nodes/NamedArguments.js | 2 +- src/slang-nodes/NamedArgumentsDeclaration.js | 2 +- src/slang-nodes/NamedImport.js | 2 +- src/slang-nodes/NewExpression.js | 2 +- src/slang-nodes/OrExpression.js | 2 +- src/slang-nodes/OverridePaths.js | 2 +- src/slang-nodes/OverridePathsDeclaration.js | 2 +- src/slang-nodes/OverrideSpecifier.js | 2 +- src/slang-nodes/Parameter.js | 2 +- src/slang-nodes/Parameters.js | 2 +- src/slang-nodes/ParametersDeclaration.js | 2 +- src/slang-nodes/PathImport.js | 2 +- src/slang-nodes/PositionalArguments.js | 2 +- src/slang-nodes/PositionalArgumentsDeclaration.js | 2 +- src/slang-nodes/PostfixExpression.js | 2 +- src/slang-nodes/Pragma.js | 2 +- src/slang-nodes/PragmaDirective.js | 2 +- src/slang-nodes/PrefixExpression.js | 2 +- src/slang-nodes/ReceiveFunctionAttribute.js | 2 +- src/slang-nodes/ReceiveFunctionAttributes.js | 2 +- src/slang-nodes/ReceiveFunctionDefinition.js | 2 +- src/slang-nodes/ReturnStatement.js | 2 +- src/slang-nodes/ReturnsDeclaration.js | 2 +- src/slang-nodes/RevertStatement.js | 2 +- src/slang-nodes/ShiftExpression.js | 2 +- src/slang-nodes/SourceUnit.js | 2 +- src/slang-nodes/SourceUnitMember.js | 2 +- src/slang-nodes/SourceUnitMembers.js | 2 +- src/slang-nodes/StateVariableAttribute.js | 2 +- src/slang-nodes/StateVariableAttributes.js | 2 +- src/slang-nodes/StateVariableDefinition.js | 2 +- src/slang-nodes/StateVariableDefinitionValue.js | 2 +- src/slang-nodes/Statement.js | 2 +- src/slang-nodes/Statements.js | 2 +- src/slang-nodes/StringExpression.js | 2 +- src/slang-nodes/StringLiterals.js | 2 +- src/slang-nodes/StructDefinition.js | 2 +- src/slang-nodes/StructMember.js | 2 +- src/slang-nodes/StructMembers.js | 2 +- src/slang-nodes/ThrowStatement.js | 2 +- src/slang-nodes/TryStatement.js | 2 +- src/slang-nodes/TupleDeconstructionElement.js | 2 +- src/slang-nodes/TupleDeconstructionElements.js | 2 +- src/slang-nodes/TupleDeconstructionStatement.js | 2 +- src/slang-nodes/TupleExpression.js | 2 +- src/slang-nodes/TupleMember.js | 2 +- src/slang-nodes/TupleValue.js | 2 +- src/slang-nodes/TupleValues.js | 2 +- src/slang-nodes/TypeExpression.js | 2 +- src/slang-nodes/TypeName.js | 2 +- src/slang-nodes/TypedTupleMember.js | 2 +- src/slang-nodes/UncheckedBlock.js | 2 +- src/slang-nodes/UnicodeStringLiterals.js | 2 +- src/slang-nodes/UnnamedFunctionAttribute.js | 2 +- src/slang-nodes/UnnamedFunctionAttributes.js | 2 +- src/slang-nodes/UnnamedFunctionDefinition.js | 2 +- src/slang-nodes/UntypedTupleMember.js | 2 +- src/slang-nodes/UserDefinedValueTypeDefinition.js | 2 +- src/slang-nodes/UsingAlias.js | 2 +- src/slang-nodes/UsingClause.js | 2 +- src/slang-nodes/UsingDeconstruction.js | 2 +- src/slang-nodes/UsingDeconstructionSymbol.js | 2 +- src/slang-nodes/UsingDeconstructionSymbols.js | 2 +- src/slang-nodes/UsingDirective.js | 2 +- src/slang-nodes/UsingTarget.js | 2 +- src/slang-nodes/VariableDeclarationStatement.js | 2 +- src/slang-nodes/VariableDeclarationType.js | 2 +- src/slang-nodes/VariableDeclarationValue.js | 2 +- src/slang-nodes/VersionComparator.js | 2 +- src/slang-nodes/VersionExpression.js | 2 +- src/slang-nodes/VersionExpressionSet.js | 2 +- src/slang-nodes/VersionExpressionSets.js | 2 +- src/slang-nodes/VersionPragma.js | 2 +- src/slang-nodes/VersionRange.js | 2 +- src/slang-nodes/WhileStatement.js | 2 +- src/slang-nodes/YulArguments.js | 2 +- src/slang-nodes/YulAssignmentOperator.js | 2 +- src/slang-nodes/YulAssignmentStatement.js | 2 +- src/slang-nodes/YulBlock.js | 4 ++-- src/slang-nodes/YulColonAndEqual.js | 2 +- src/slang-nodes/YulDefaultCase.js | 2 +- src/slang-nodes/YulExpression.js | 2 +- src/slang-nodes/YulForStatement.js | 2 +- src/slang-nodes/YulFunctionCallExpression.js | 2 +- src/slang-nodes/YulFunctionDefinition.js | 2 +- src/slang-nodes/YulIfStatement.js | 2 +- src/slang-nodes/YulLeaveStatement.js | 2 +- src/slang-nodes/YulLiteral.js | 2 +- src/slang-nodes/YulParametersDeclaration.js | 2 +- src/slang-nodes/YulPath.js | 2 +- src/slang-nodes/YulPaths.js | 2 +- src/slang-nodes/YulReturnsDeclaration.js | 2 +- src/slang-nodes/YulStatement.js | 2 +- src/slang-nodes/YulStatements.js | 2 +- src/slang-nodes/YulSwitchCase.js | 2 +- src/slang-nodes/YulSwitchCases.js | 2 +- src/slang-nodes/YulSwitchStatement.js | 2 +- src/slang-nodes/YulValueCase.js | 2 +- src/slang-nodes/YulVariableAssignmentStatement.js | 2 +- src/slang-nodes/YulVariableDeclarationStatement.js | 2 +- src/slang-nodes/YulVariableDeclarationValue.js | 2 +- src/slangPrinter.js | 2 +- 192 files changed, 193 insertions(+), 193 deletions(-) diff --git a/src/slang-nodes/AdditiveExpression.js b/src/slang-nodes/AdditiveExpression.js index 22c99d5d0..e6cafb191 100644 --- a/src/slang-nodes/AdditiveExpression.js +++ b/src/slang-nodes/AdditiveExpression.js @@ -23,7 +23,7 @@ export class AdditiveExpression extends SlangNode { this.initiateLoc(ast); } - print({ path, print, options }) { + print(path, print, options) { return binaryOperationPrint({ node: this, path, print, options }); } } diff --git a/src/slang-nodes/AndExpression.js b/src/slang-nodes/AndExpression.js index 6d9718120..397004d7d 100644 --- a/src/slang-nodes/AndExpression.js +++ b/src/slang-nodes/AndExpression.js @@ -16,7 +16,7 @@ export class AndExpression extends SlangNode { this.initiateLoc(ast); } - print({ path, print, options }) { + print(path, print, options) { return logicalOperationPrint({ node: this, path, print, options }); } } diff --git a/src/slang-nodes/ArgumentsDeclaration.js b/src/slang-nodes/ArgumentsDeclaration.js index 8927bd752..214a2e2cb 100644 --- a/src/slang-nodes/ArgumentsDeclaration.js +++ b/src/slang-nodes/ArgumentsDeclaration.js @@ -9,7 +9,7 @@ export class ArgumentsDeclaration extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/ArrayExpression.js b/src/slang-nodes/ArrayExpression.js index f45472f98..fcb3fc108 100644 --- a/src/slang-nodes/ArrayExpression.js +++ b/src/slang-nodes/ArrayExpression.js @@ -18,7 +18,7 @@ export class ArrayExpression extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return group([ this.openBracket, path.call(print, 'items'), diff --git a/src/slang-nodes/ArrayTypeName.js b/src/slang-nodes/ArrayTypeName.js index 174018c77..ef9591dcd 100644 --- a/src/slang-nodes/ArrayTypeName.js +++ b/src/slang-nodes/ArrayTypeName.js @@ -20,7 +20,7 @@ export class ArrayTypeName extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ path.call(print, 'operand'), this.openBracket, diff --git a/src/slang-nodes/ArrayValues.js b/src/slang-nodes/ArrayValues.js index 87a2d3831..88276fe70 100644 --- a/src/slang-nodes/ArrayValues.js +++ b/src/slang-nodes/ArrayValues.js @@ -15,7 +15,7 @@ export class ArrayValues extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return printSeparatedList(path.map(print, 'items')); } } diff --git a/src/slang-nodes/AssemblyFlags.js b/src/slang-nodes/AssemblyFlags.js index 3395f4391..4d7c6e73d 100644 --- a/src/slang-nodes/AssemblyFlags.js +++ b/src/slang-nodes/AssemblyFlags.js @@ -15,7 +15,7 @@ export class AssemblyFlags extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return printSeparatedList(path.map(print, 'items')); } } diff --git a/src/slang-nodes/AssemblyFlagsDeclaration.js b/src/slang-nodes/AssemblyFlagsDeclaration.js index d067ef05c..f48ac709e 100644 --- a/src/slang-nodes/AssemblyFlagsDeclaration.js +++ b/src/slang-nodes/AssemblyFlagsDeclaration.js @@ -15,7 +15,7 @@ export class AssemblyFlagsDeclaration extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [this.openParen, path.call(print, 'flags'), this.closeParen]; } } diff --git a/src/slang-nodes/AssemblyStatement.js b/src/slang-nodes/AssemblyStatement.js index 964e4b64b..d6e5bdf10 100644 --- a/src/slang-nodes/AssemblyStatement.js +++ b/src/slang-nodes/AssemblyStatement.js @@ -22,7 +22,7 @@ export class AssemblyStatement extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ `${this.assemblyKeyword} `, this.label ? [path.call(print, 'label'), ' '] : '', diff --git a/src/slang-nodes/AssignmentExpression.js b/src/slang-nodes/AssignmentExpression.js index 0a3529f36..ba1156323 100644 --- a/src/slang-nodes/AssignmentExpression.js +++ b/src/slang-nodes/AssignmentExpression.js @@ -19,7 +19,7 @@ export class AssignmentExpression extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ path.call(print, 'leftOperand'), ` ${this.operator}`, diff --git a/src/slang-nodes/BitwiseAndExpression.js b/src/slang-nodes/BitwiseAndExpression.js index 3696e30e0..a10aff3be 100644 --- a/src/slang-nodes/BitwiseAndExpression.js +++ b/src/slang-nodes/BitwiseAndExpression.js @@ -23,7 +23,7 @@ export class BitwiseAndExpression extends SlangNode { this.initiateLoc(ast); } - print({ path, print, options }) { + print(path, print, options) { return binaryOperationPrint({ node: this, path, print, options }); } } diff --git a/src/slang-nodes/BitwiseOrExpression.js b/src/slang-nodes/BitwiseOrExpression.js index fa820c145..2762c281b 100644 --- a/src/slang-nodes/BitwiseOrExpression.js +++ b/src/slang-nodes/BitwiseOrExpression.js @@ -33,7 +33,7 @@ export class BitwiseOrExpression extends SlangNode { this.initiateLoc(ast); } - print({ path, print, options }) { + print(path, print, options) { return binaryOperationPrint({ node: this, path, print, options }); } } diff --git a/src/slang-nodes/BitwiseXorExpression.js b/src/slang-nodes/BitwiseXorExpression.js index d98e44101..4b282e0e5 100644 --- a/src/slang-nodes/BitwiseXorExpression.js +++ b/src/slang-nodes/BitwiseXorExpression.js @@ -23,7 +23,7 @@ export class BitwiseXorExpression extends SlangNode { this.initiateLoc(ast); } - print({ path, print, options }) { + print(path, print, options) { return binaryOperationPrint({ node: this, path, print, options }); } } diff --git a/src/slang-nodes/Block.js b/src/slang-nodes/Block.js index 7d4a41af7..e29886656 100644 --- a/src/slang-nodes/Block.js +++ b/src/slang-nodes/Block.js @@ -15,7 +15,7 @@ export class Block extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [this.openBrace, path.call(print, 'statements'), this.closeBrace]; } } diff --git a/src/slang-nodes/CallOptions.js b/src/slang-nodes/CallOptions.js index 56e440bde..8519b0a5b 100644 --- a/src/slang-nodes/CallOptions.js +++ b/src/slang-nodes/CallOptions.js @@ -18,7 +18,7 @@ export class CallOptions extends SlangNode { this.initiateLoc(ast); } - print({ path, print, options }) { + print(path, print, options) { return printSeparatedList(path.map(print, 'items'), { firstSeparator: options.bracketSpacing ? line : softline }); diff --git a/src/slang-nodes/CallOptionsExpression.js b/src/slang-nodes/CallOptionsExpression.js index 1b840d7de..c477d5943 100644 --- a/src/slang-nodes/CallOptionsExpression.js +++ b/src/slang-nodes/CallOptionsExpression.js @@ -18,7 +18,7 @@ export class CallOptionsExpression extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ path.call(print, 'operand'), this.openBrace, diff --git a/src/slang-nodes/CatchClause.js b/src/slang-nodes/CatchClause.js index 2f857fbca..f5c7b64b1 100644 --- a/src/slang-nodes/CatchClause.js +++ b/src/slang-nodes/CatchClause.js @@ -17,7 +17,7 @@ export class CatchClause extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ `${this.catchKeyword} `, this.error ? path.call(print, 'error') : '', diff --git a/src/slang-nodes/CatchClauseError.js b/src/slang-nodes/CatchClauseError.js index d84641028..51681dc72 100644 --- a/src/slang-nodes/CatchClauseError.js +++ b/src/slang-nodes/CatchClauseError.js @@ -15,7 +15,7 @@ export class CatchClauseError extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [this.name, group(path.call(print, 'parameters')), ' ']; } } diff --git a/src/slang-nodes/CatchClauses.js b/src/slang-nodes/CatchClauses.js index c641bed9a..1dd8cee54 100644 --- a/src/slang-nodes/CatchClauses.js +++ b/src/slang-nodes/CatchClauses.js @@ -14,7 +14,7 @@ export class CatchClauses extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return join(' ', path.map(print, 'items')); } } diff --git a/src/slang-nodes/ComparisonExpression.js b/src/slang-nodes/ComparisonExpression.js index cf3b2f2b0..1a4e3a6bc 100644 --- a/src/slang-nodes/ComparisonExpression.js +++ b/src/slang-nodes/ComparisonExpression.js @@ -16,7 +16,7 @@ export class ComparisonExpression extends SlangNode { this.initiateLoc(ast); } - print({ path, print, options }) { + print(path, print, options) { return comparisonOperationPrint({ node: this, path, print, options }); } } diff --git a/src/slang-nodes/ConditionalExpression.js b/src/slang-nodes/ConditionalExpression.js index 8c8a91427..e0c0a5936 100644 --- a/src/slang-nodes/ConditionalExpression.js +++ b/src/slang-nodes/ConditionalExpression.js @@ -133,7 +133,7 @@ export class ConditionalExpression extends SlangNode { this.initiateLoc(ast); } - print({ path, print, options }) { + print(path, print, options) { return options.experimentalTernaries ? experimentalTernaries(this, path, print, options) : traditionalTernaries(this, path, print); diff --git a/src/slang-nodes/ConstantDefinition.js b/src/slang-nodes/ConstantDefinition.js index fe514710f..ffb70741d 100644 --- a/src/slang-nodes/ConstantDefinition.js +++ b/src/slang-nodes/ConstantDefinition.js @@ -25,7 +25,7 @@ export class ConstantDefinition extends SlangNode { } // TODO: implement print - print({ path, print, options }) { + print(path, print, options) { return ['TODO: ConstantDefinition']; } } diff --git a/src/slang-nodes/ConstructorAttribute.js b/src/slang-nodes/ConstructorAttribute.js index 2f3911083..149ab5ec9 100644 --- a/src/slang-nodes/ConstructorAttribute.js +++ b/src/slang-nodes/ConstructorAttribute.js @@ -12,7 +12,7 @@ export class ConstructorAttribute extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/ConstructorAttributes.js b/src/slang-nodes/ConstructorAttributes.js index 0f0385e41..c6dcfe94b 100644 --- a/src/slang-nodes/ConstructorAttributes.js +++ b/src/slang-nodes/ConstructorAttributes.js @@ -15,7 +15,7 @@ export class ConstructorAttributes extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return path.map(print, 'items').map((item) => [line, item]); } } diff --git a/src/slang-nodes/ConstructorDefinition.js b/src/slang-nodes/ConstructorDefinition.js index 9ae919813..75319f054 100644 --- a/src/slang-nodes/ConstructorDefinition.js +++ b/src/slang-nodes/ConstructorDefinition.js @@ -19,7 +19,7 @@ export class ConstructorDefinition extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return printFunction(this.constructorKeyword, this, path, print); } } diff --git a/src/slang-nodes/ContractDefinition.js b/src/slang-nodes/ContractDefinition.js index ad92684e7..d792ca0cf 100644 --- a/src/slang-nodes/ContractDefinition.js +++ b/src/slang-nodes/ContractDefinition.js @@ -32,7 +32,7 @@ export class ContractDefinition extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ group([ `${this.abstractKeyword ? `${this.abstractKeyword} ` : ''}${this.contractKeyword} ${this.name}`, diff --git a/src/slang-nodes/ContractMember.js b/src/slang-nodes/ContractMember.js index 9b609a921..b3ba7e32e 100644 --- a/src/slang-nodes/ContractMember.js +++ b/src/slang-nodes/ContractMember.js @@ -9,7 +9,7 @@ export class ContractMember extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/ContractMembers.js b/src/slang-nodes/ContractMembers.js index 0724431af..8efc6a0cf 100644 --- a/src/slang-nodes/ContractMembers.js +++ b/src/slang-nodes/ContractMembers.js @@ -19,7 +19,7 @@ export class ContractMembers extends SlangNode { this.initiateLoc(ast); } - print({ options, path, print }) { + print(path, print, options) { return this.items.length === 0 && (!this.comments || this.comments.length === 0) ? '' diff --git a/src/slang-nodes/DecimalNumberExpression.js b/src/slang-nodes/DecimalNumberExpression.js index 8e6b36bfd..393f8d975 100644 --- a/src/slang-nodes/DecimalNumberExpression.js +++ b/src/slang-nodes/DecimalNumberExpression.js @@ -14,7 +14,7 @@ export class DecimalNumberExpression extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [this.literal, this.unit ? [' ', path.call(print, 'unit')] : '']; } } diff --git a/src/slang-nodes/DoWhileStatement.js b/src/slang-nodes/DoWhileStatement.js index 083dbc8ca..ef0206cfb 100644 --- a/src/slang-nodes/DoWhileStatement.js +++ b/src/slang-nodes/DoWhileStatement.js @@ -36,7 +36,7 @@ export class DoWhileStatement extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ this.doKeyword, printBody(this, path, print), diff --git a/src/slang-nodes/ElementaryType.js b/src/slang-nodes/ElementaryType.js index 32f806a54..2680d9f9d 100644 --- a/src/slang-nodes/ElementaryType.js +++ b/src/slang-nodes/ElementaryType.js @@ -12,7 +12,7 @@ export class ElementaryType extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/ElseBranch.js b/src/slang-nodes/ElseBranch.js index e878c6b5b..7041d1045 100644 --- a/src/slang-nodes/ElseBranch.js +++ b/src/slang-nodes/ElseBranch.js @@ -20,7 +20,7 @@ export class ElseBranch extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [this.elseKeyword, printBody(this.body.variant.kind, path, print)]; } } diff --git a/src/slang-nodes/EmitStatement.js b/src/slang-nodes/EmitStatement.js index 6c7c8b726..33832a00d 100644 --- a/src/slang-nodes/EmitStatement.js +++ b/src/slang-nodes/EmitStatement.js @@ -18,7 +18,7 @@ export class EmitStatement extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ `${this.emitKeyword} `, path.call(print, 'event'), diff --git a/src/slang-nodes/EnumDefinition.js b/src/slang-nodes/EnumDefinition.js index 7778c4f4d..e3a871ecc 100644 --- a/src/slang-nodes/EnumDefinition.js +++ b/src/slang-nodes/EnumDefinition.js @@ -21,7 +21,7 @@ export class EnumDefinition extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ `${this.enumKeyword} ${this.name} ${this.openBrace}`, path.call(print, 'members'), diff --git a/src/slang-nodes/EqualityExpression.js b/src/slang-nodes/EqualityExpression.js index a1a85c0c9..a83f7bfd3 100644 --- a/src/slang-nodes/EqualityExpression.js +++ b/src/slang-nodes/EqualityExpression.js @@ -16,7 +16,7 @@ export class EqualityExpression extends SlangNode { this.initiateLoc(ast); } - print({ path, print, options }) { + print(path, print, options) { return comparisonOperationPrint({ node: this, path, print, options }); } } diff --git a/src/slang-nodes/ErrorDefinition.js b/src/slang-nodes/ErrorDefinition.js index c47b88c94..97f5630c1 100644 --- a/src/slang-nodes/ErrorDefinition.js +++ b/src/slang-nodes/ErrorDefinition.js @@ -18,7 +18,7 @@ export class ErrorDefinition extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ `${this.errorKeyword} ${this.name}`, path.call(print, 'members'), diff --git a/src/slang-nodes/ErrorParameter.js b/src/slang-nodes/ErrorParameter.js index 27f374677..dbe08b255 100644 --- a/src/slang-nodes/ErrorParameter.js +++ b/src/slang-nodes/ErrorParameter.js @@ -16,7 +16,7 @@ export class ErrorParameter extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [path.call(print, 'typeName'), this.name ? ` ${this.name}` : '']; } } diff --git a/src/slang-nodes/ErrorParameters.js b/src/slang-nodes/ErrorParameters.js index 49f4188e8..25d9dec9b 100644 --- a/src/slang-nodes/ErrorParameters.js +++ b/src/slang-nodes/ErrorParameters.js @@ -15,7 +15,7 @@ export class ErrorParameters extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return this.items.length > 0 ? printSeparatedList(path.map(print, 'items')) : ''; diff --git a/src/slang-nodes/ErrorParametersDeclaration.js b/src/slang-nodes/ErrorParametersDeclaration.js index 4c14870d5..30faba6ba 100644 --- a/src/slang-nodes/ErrorParametersDeclaration.js +++ b/src/slang-nodes/ErrorParametersDeclaration.js @@ -15,7 +15,7 @@ export class ErrorParametersDeclaration extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [this.openParen, path.call(print, 'parameters'), this.closeParen]; } } diff --git a/src/slang-nodes/EventDefinition.js b/src/slang-nodes/EventDefinition.js index aadf8de7b..02d2aff9b 100644 --- a/src/slang-nodes/EventDefinition.js +++ b/src/slang-nodes/EventDefinition.js @@ -21,7 +21,7 @@ export class EventDefinition extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ `${this.eventKeyword} ${this.name}`, path.call(print, 'parameters'), diff --git a/src/slang-nodes/EventParameter.js b/src/slang-nodes/EventParameter.js index 18fb797c1..730a7c6ec 100644 --- a/src/slang-nodes/EventParameter.js +++ b/src/slang-nodes/EventParameter.js @@ -15,7 +15,7 @@ export class EventParameter extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ path.call(print, 'typeName'), this.indexedKeyword ? ` ${this.indexedKeyword}` : '', diff --git a/src/slang-nodes/EventParameters.js b/src/slang-nodes/EventParameters.js index dda55fdd3..d28fc963f 100644 --- a/src/slang-nodes/EventParameters.js +++ b/src/slang-nodes/EventParameters.js @@ -15,7 +15,7 @@ export class EventParameters extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return this.items.length > 0 ? printSeparatedList(path.map(print, 'items')) : ''; diff --git a/src/slang-nodes/EventParametersDeclaration.js b/src/slang-nodes/EventParametersDeclaration.js index 16367be51..a7bfe98c2 100644 --- a/src/slang-nodes/EventParametersDeclaration.js +++ b/src/slang-nodes/EventParametersDeclaration.js @@ -15,7 +15,7 @@ export class EventParametersDeclaration extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [this.openParen, path.call(print, 'parameters'), this.closeParen]; } } diff --git a/src/slang-nodes/ExperimentalFeature.js b/src/slang-nodes/ExperimentalFeature.js index 48adcef0f..8a81ecafb 100644 --- a/src/slang-nodes/ExperimentalFeature.js +++ b/src/slang-nodes/ExperimentalFeature.js @@ -13,7 +13,7 @@ export class ExperimentalFeature extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/ExperimentalPragma.js b/src/slang-nodes/ExperimentalPragma.js index 66031cbd1..5bda847bb 100644 --- a/src/slang-nodes/ExperimentalPragma.js +++ b/src/slang-nodes/ExperimentalPragma.js @@ -17,7 +17,7 @@ export class ExperimentalPragma extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [`${this.experimentalKeyword} `, path.call(print, 'feature')]; } } diff --git a/src/slang-nodes/ExponentiationExpression.js b/src/slang-nodes/ExponentiationExpression.js index 44f325fcd..da0194c51 100644 --- a/src/slang-nodes/ExponentiationExpression.js +++ b/src/slang-nodes/ExponentiationExpression.js @@ -95,7 +95,7 @@ export class ExponentiationExpression extends SlangNode { } } - print({ path, print, options }) { + print(path, print, options) { return exponentiationExpressionPrint({ node: this, path, print, options }); } } diff --git a/src/slang-nodes/Expression.js b/src/slang-nodes/Expression.js index 118c60554..408004eec 100644 --- a/src/slang-nodes/Expression.js +++ b/src/slang-nodes/Expression.js @@ -18,7 +18,7 @@ export class Expression extends SlangNode { } } - print({ path, print }) { + print(path, print) { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/ExpressionStatement.js b/src/slang-nodes/ExpressionStatement.js index fc2a0c2fc..39c997276 100644 --- a/src/slang-nodes/ExpressionStatement.js +++ b/src/slang-nodes/ExpressionStatement.js @@ -12,7 +12,7 @@ export class ExpressionStatement extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [path.call(print, 'expression'), this.semicolon]; } } diff --git a/src/slang-nodes/FallbackFunctionAttribute.js b/src/slang-nodes/FallbackFunctionAttribute.js index 4d3acd682..e1b58da9e 100644 --- a/src/slang-nodes/FallbackFunctionAttribute.js +++ b/src/slang-nodes/FallbackFunctionAttribute.js @@ -12,7 +12,7 @@ export class FallbackFunctionAttribute extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/FallbackFunctionAttributes.js b/src/slang-nodes/FallbackFunctionAttributes.js index 62437f307..c5ae18392 100644 --- a/src/slang-nodes/FallbackFunctionAttributes.js +++ b/src/slang-nodes/FallbackFunctionAttributes.js @@ -15,7 +15,7 @@ export class FallbackFunctionAttributes extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return path.map(print, 'items').map((item) => [line, item]); } } diff --git a/src/slang-nodes/FallbackFunctionDefinition.js b/src/slang-nodes/FallbackFunctionDefinition.js index d950c3d6f..e4498c9eb 100644 --- a/src/slang-nodes/FallbackFunctionDefinition.js +++ b/src/slang-nodes/FallbackFunctionDefinition.js @@ -24,7 +24,7 @@ export class FallbackFunctionDefinition extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return printFunction(this.fallbackKeyword, this, path, print); } } diff --git a/src/slang-nodes/ForStatement.js b/src/slang-nodes/ForStatement.js index 662ae7362..110edf63e 100644 --- a/src/slang-nodes/ForStatement.js +++ b/src/slang-nodes/ForStatement.js @@ -37,7 +37,7 @@ export class ForStatement extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { const initialization = path.call(print, 'initialization'); const condition = path.call(print, 'condition'); const iterator = this.iterator ? path.call(print, 'iterator') : ''; diff --git a/src/slang-nodes/ForStatementCondition.js b/src/slang-nodes/ForStatementCondition.js index 3911fce10..b3f5dff44 100644 --- a/src/slang-nodes/ForStatementCondition.js +++ b/src/slang-nodes/ForStatementCondition.js @@ -12,7 +12,7 @@ export class ForStatementCondition extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/ForStatementInitialization.js b/src/slang-nodes/ForStatementInitialization.js index 0d935ff48..cfcf0e124 100644 --- a/src/slang-nodes/ForStatementInitialization.js +++ b/src/slang-nodes/ForStatementInitialization.js @@ -12,7 +12,7 @@ export class ForStatementInitialization extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/FunctionAttribute.js b/src/slang-nodes/FunctionAttribute.js index 38eac2534..ed24fb0c0 100644 --- a/src/slang-nodes/FunctionAttribute.js +++ b/src/slang-nodes/FunctionAttribute.js @@ -12,7 +12,7 @@ export class FunctionAttribute extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/FunctionAttributes.js b/src/slang-nodes/FunctionAttributes.js index be065249f..0840190da 100644 --- a/src/slang-nodes/FunctionAttributes.js +++ b/src/slang-nodes/FunctionAttributes.js @@ -15,7 +15,7 @@ export class FunctionAttributes extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return path.map(print, 'items').map((item) => [line, item]); } } diff --git a/src/slang-nodes/FunctionBody.js b/src/slang-nodes/FunctionBody.js index 25d7df6ab..0900cff9a 100644 --- a/src/slang-nodes/FunctionBody.js +++ b/src/slang-nodes/FunctionBody.js @@ -12,7 +12,7 @@ export class FunctionBody extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/FunctionCallExpression.js b/src/slang-nodes/FunctionCallExpression.js index b0e58013b..be524fdcf 100644 --- a/src/slang-nodes/FunctionCallExpression.js +++ b/src/slang-nodes/FunctionCallExpression.js @@ -18,7 +18,7 @@ export class FunctionCallExpression extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { let operandDoc = path.call(print, 'operand'); let argumentsDoc = path.call(print, 'arguments'); diff --git a/src/slang-nodes/FunctionDefinition.js b/src/slang-nodes/FunctionDefinition.js index 66e667d94..f6ecdff5e 100644 --- a/src/slang-nodes/FunctionDefinition.js +++ b/src/slang-nodes/FunctionDefinition.js @@ -27,7 +27,7 @@ export class FunctionDefinition extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return printFunction( [`${this.functionKeyword} `, path.call(print, 'name')], this, diff --git a/src/slang-nodes/FunctionType.js b/src/slang-nodes/FunctionType.js index 74d79f87e..60054f5f3 100644 --- a/src/slang-nodes/FunctionType.js +++ b/src/slang-nodes/FunctionType.js @@ -21,7 +21,7 @@ export class FunctionType extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return printFunction(this.functionKeyword, this, path, print); } } diff --git a/src/slang-nodes/FunctionTypeAttributes.js b/src/slang-nodes/FunctionTypeAttributes.js index 3058e9059..8c62cb164 100644 --- a/src/slang-nodes/FunctionTypeAttributes.js +++ b/src/slang-nodes/FunctionTypeAttributes.js @@ -15,7 +15,7 @@ export class FunctionTypeAttributes extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return path.map(print, 'items').map((item) => [line, item]); } } diff --git a/src/slang-nodes/HexNumberExpression.js b/src/slang-nodes/HexNumberExpression.js index abe93ef47..62a9b34f2 100644 --- a/src/slang-nodes/HexNumberExpression.js +++ b/src/slang-nodes/HexNumberExpression.js @@ -14,7 +14,7 @@ export class HexNumberExpression extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [this.literal, this.unit ? [' ', path.call(print, 'unit')] : '']; } } diff --git a/src/slang-nodes/HexStringLiterals.js b/src/slang-nodes/HexStringLiterals.js index 46914254d..2c396344d 100644 --- a/src/slang-nodes/HexStringLiterals.js +++ b/src/slang-nodes/HexStringLiterals.js @@ -14,7 +14,7 @@ export class HexStringLiterals extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return join(hardline, path.map(print, 'items')); } } diff --git a/src/slang-nodes/IfStatement.js b/src/slang-nodes/IfStatement.js index c2295f8e5..6cb023eed 100644 --- a/src/slang-nodes/IfStatement.js +++ b/src/slang-nodes/IfStatement.js @@ -37,7 +37,7 @@ export class IfStatement extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { const bodyVariantKind = this.body.variant.kind; return [ diff --git a/src/slang-nodes/ImportClause.js b/src/slang-nodes/ImportClause.js index eae4d8e00..d32fb2b2e 100644 --- a/src/slang-nodes/ImportClause.js +++ b/src/slang-nodes/ImportClause.js @@ -9,7 +9,7 @@ export class ImportClause extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/ImportDeconstruction.js b/src/slang-nodes/ImportDeconstruction.js index 74c57c502..c58f089e8 100644 --- a/src/slang-nodes/ImportDeconstruction.js +++ b/src/slang-nodes/ImportDeconstruction.js @@ -21,7 +21,7 @@ export class ImportDeconstruction extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ this.openBrace, path.call(print, 'symbols'), diff --git a/src/slang-nodes/ImportDeconstructionSymbol.js b/src/slang-nodes/ImportDeconstructionSymbol.js index 0712334c3..4506ff392 100644 --- a/src/slang-nodes/ImportDeconstructionSymbol.js +++ b/src/slang-nodes/ImportDeconstructionSymbol.js @@ -14,7 +14,7 @@ export class ImportDeconstructionSymbol extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [this.name, this.alias ? path.call(print, 'alias') : '']; } } diff --git a/src/slang-nodes/ImportDeconstructionSymbols.js b/src/slang-nodes/ImportDeconstructionSymbols.js index ae4bcd138..0226470ec 100644 --- a/src/slang-nodes/ImportDeconstructionSymbols.js +++ b/src/slang-nodes/ImportDeconstructionSymbols.js @@ -20,7 +20,7 @@ export class ImportDeconstructionSymbols extends SlangNode { this.initiateLoc(ast); } - print({ path, print, options }) { + print(path, print, options) { const compiler = coerce(options.compiler); let firstSeparator; let separator; diff --git a/src/slang-nodes/ImportDirective.js b/src/slang-nodes/ImportDirective.js index 4caf80846..2d65e7e3b 100644 --- a/src/slang-nodes/ImportDirective.js +++ b/src/slang-nodes/ImportDirective.js @@ -15,7 +15,7 @@ export class ImportDirective extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ `${this.importKeyword} `, path.call(print, 'clause'), diff --git a/src/slang-nodes/IndexAccessEnd.js b/src/slang-nodes/IndexAccessEnd.js index 3b0e05c2d..2815bfa08 100644 --- a/src/slang-nodes/IndexAccessEnd.js +++ b/src/slang-nodes/IndexAccessEnd.js @@ -14,7 +14,7 @@ export class IndexAccessEnd extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [this.colon, this.end ? path.call(print, 'end') : '']; } } diff --git a/src/slang-nodes/IndexAccessExpression.js b/src/slang-nodes/IndexAccessExpression.js index 751001a7c..316dd15a5 100644 --- a/src/slang-nodes/IndexAccessExpression.js +++ b/src/slang-nodes/IndexAccessExpression.js @@ -31,7 +31,7 @@ export class IndexAccessExpression extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { let operandDoc = path.call(print, 'operand'); let indexDoc = group([ this.openBracket, diff --git a/src/slang-nodes/InheritanceSpecifier.js b/src/slang-nodes/InheritanceSpecifier.js index c53bba06b..3b2859215 100644 --- a/src/slang-nodes/InheritanceSpecifier.js +++ b/src/slang-nodes/InheritanceSpecifier.js @@ -12,7 +12,7 @@ export class InheritanceSpecifier extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [this.isKeyword, path.call(print, 'types')]; } } diff --git a/src/slang-nodes/InheritanceType.js b/src/slang-nodes/InheritanceType.js index 5aeabf05c..8148a5e7e 100644 --- a/src/slang-nodes/InheritanceType.js +++ b/src/slang-nodes/InheritanceType.js @@ -14,7 +14,7 @@ export class InheritanceType extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ path.call(print, 'typeName'), this.arguments ? path.call(print, 'arguments') : '' diff --git a/src/slang-nodes/InheritanceTypes.js b/src/slang-nodes/InheritanceTypes.js index fd8c544f8..491313ab3 100644 --- a/src/slang-nodes/InheritanceTypes.js +++ b/src/slang-nodes/InheritanceTypes.js @@ -18,7 +18,7 @@ export class InheritanceTypes extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return printSeparatedList(path.map(print, 'items'), { firstSeparator: line }); diff --git a/src/slang-nodes/InterfaceDefinition.js b/src/slang-nodes/InterfaceDefinition.js index 773998c9b..ca225f4ab 100644 --- a/src/slang-nodes/InterfaceDefinition.js +++ b/src/slang-nodes/InterfaceDefinition.js @@ -29,7 +29,7 @@ export class InterfaceDefinition extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ group([ `${this.interfaceKeyword} ${this.name}`, diff --git a/src/slang-nodes/InterfaceMembers.js b/src/slang-nodes/InterfaceMembers.js index 874635dce..1eee103f5 100644 --- a/src/slang-nodes/InterfaceMembers.js +++ b/src/slang-nodes/InterfaceMembers.js @@ -16,7 +16,7 @@ export class InterfaceMembers extends SlangNode { this.initiateLoc(ast); } - print({ options, path, print }) { + print(path, print, options) { return this.items.length > 0 ? printSeparatedItem( printPreservingEmptyLines(path, 'items', options, print), diff --git a/src/slang-nodes/LibraryDefinition.js b/src/slang-nodes/LibraryDefinition.js index 6d0a3918a..147cbcaed 100644 --- a/src/slang-nodes/LibraryDefinition.js +++ b/src/slang-nodes/LibraryDefinition.js @@ -24,7 +24,7 @@ export class LibraryDefinition extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ group([`${this.libraryKeyword} ${this.name}`, line, this.openBrace]), path.call(print, 'members'), diff --git a/src/slang-nodes/LibraryMembers.js b/src/slang-nodes/LibraryMembers.js index 6d448c302..b578f2a8f 100644 --- a/src/slang-nodes/LibraryMembers.js +++ b/src/slang-nodes/LibraryMembers.js @@ -16,7 +16,7 @@ export class LibraryMembers extends SlangNode { this.initiateLoc(ast); } - print({ path, print, options }) { + print(path, print, options) { return this.items.length > 0 ? printSeparatedItem( printPreservingEmptyLines(path, 'items', options, print), diff --git a/src/slang-nodes/MappingKey.js b/src/slang-nodes/MappingKey.js index 2729f1a6e..a2fdf8ede 100644 --- a/src/slang-nodes/MappingKey.js +++ b/src/slang-nodes/MappingKey.js @@ -12,7 +12,7 @@ export class MappingKey extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [path.call(print, 'keyType'), this.name ? ` ${this.name}` : '']; } } diff --git a/src/slang-nodes/MappingKeyType.js b/src/slang-nodes/MappingKeyType.js index 78a9b49dc..ce60f2fd4 100644 --- a/src/slang-nodes/MappingKeyType.js +++ b/src/slang-nodes/MappingKeyType.js @@ -9,7 +9,7 @@ export class MappingKeyType extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/MappingType.js b/src/slang-nodes/MappingType.js index 851368873..a57817a46 100644 --- a/src/slang-nodes/MappingType.js +++ b/src/slang-nodes/MappingType.js @@ -24,7 +24,7 @@ export class MappingType extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ `${this.mappingKeyword}${this.openParen}`, path.call(print, 'keyType'), diff --git a/src/slang-nodes/MappingValue.js b/src/slang-nodes/MappingValue.js index 63c3b3792..5be330318 100644 --- a/src/slang-nodes/MappingValue.js +++ b/src/slang-nodes/MappingValue.js @@ -12,7 +12,7 @@ export class MappingValue extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [path.call(print, 'typeName'), this.name ? ` ${this.name}` : '']; } } diff --git a/src/slang-nodes/MemberAccessExpression.js b/src/slang-nodes/MemberAccessExpression.js index db628bdfc..b9b9601a9 100644 --- a/src/slang-nodes/MemberAccessExpression.js +++ b/src/slang-nodes/MemberAccessExpression.js @@ -120,7 +120,7 @@ export class MemberAccessExpression extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { let operandDoc = path.call(print, 'operand'); if (Array.isArray(operandDoc)) { operandDoc = operandDoc.flat(); diff --git a/src/slang-nodes/ModifierAttribute.js b/src/slang-nodes/ModifierAttribute.js index 3506dde06..a145a28f7 100644 --- a/src/slang-nodes/ModifierAttribute.js +++ b/src/slang-nodes/ModifierAttribute.js @@ -12,7 +12,7 @@ export class ModifierAttribute extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/ModifierAttributes.js b/src/slang-nodes/ModifierAttributes.js index 7df2831cf..2f877122a 100644 --- a/src/slang-nodes/ModifierAttributes.js +++ b/src/slang-nodes/ModifierAttributes.js @@ -15,7 +15,7 @@ export class ModifierAttributes extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return path.map(print, 'items').map((item) => [line, item]); } } diff --git a/src/slang-nodes/ModifierDefinition.js b/src/slang-nodes/ModifierDefinition.js index 10a2216c3..167e09cd3 100644 --- a/src/slang-nodes/ModifierDefinition.js +++ b/src/slang-nodes/ModifierDefinition.js @@ -44,7 +44,7 @@ export class ModifierDefinition extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return printFunction( `${this.modifierKeyword} ${this.name}`, this, diff --git a/src/slang-nodes/ModifierInvocation.js b/src/slang-nodes/ModifierInvocation.js index ae4a40de0..2255b70ce 100644 --- a/src/slang-nodes/ModifierInvocation.js +++ b/src/slang-nodes/ModifierInvocation.js @@ -26,7 +26,7 @@ export class ModifierInvocation extends SlangNode { } } - print({ path, print }) { + print(path, print) { return [ path.call(print, 'name'), this.arguments ? path.call(print, 'arguments') : '' diff --git a/src/slang-nodes/MultiplicativeExpression.js b/src/slang-nodes/MultiplicativeExpression.js index 1ef6febf0..90919c63f 100644 --- a/src/slang-nodes/MultiplicativeExpression.js +++ b/src/slang-nodes/MultiplicativeExpression.js @@ -36,7 +36,7 @@ export class MultiplicativeExpression extends SlangNode { this.initiateLoc(ast); } - print({ path, print, options }) { + print(path, print, options) { return binaryOperationPrint({ node: this, path, print, options }); } } diff --git a/src/slang-nodes/NamedArgument.js b/src/slang-nodes/NamedArgument.js index 4890aa592..2f310ba58 100644 --- a/src/slang-nodes/NamedArgument.js +++ b/src/slang-nodes/NamedArgument.js @@ -15,7 +15,7 @@ export class NamedArgument extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [`${this.name}${this.colon} `, path.call(print, 'value')]; } } diff --git a/src/slang-nodes/NamedArgumentGroup.js b/src/slang-nodes/NamedArgumentGroup.js index 92b8cbf83..99a2f5c5d 100644 --- a/src/slang-nodes/NamedArgumentGroup.js +++ b/src/slang-nodes/NamedArgumentGroup.js @@ -15,7 +15,7 @@ export class NamedArgumentGroup extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [this.openBrace, path.call(print, 'arguments'), this.closeBrace]; } } diff --git a/src/slang-nodes/NamedArguments.js b/src/slang-nodes/NamedArguments.js index 974fb7bff..b57109d62 100644 --- a/src/slang-nodes/NamedArguments.js +++ b/src/slang-nodes/NamedArguments.js @@ -18,7 +18,7 @@ export class NamedArguments extends SlangNode { this.initiateLoc(ast); } - print({ path, print, options }) { + print(path, print, options) { return printSeparatedList(path.map(print, 'items'), { firstSeparator: options.bracketSpacing ? line : softline }); diff --git a/src/slang-nodes/NamedArgumentsDeclaration.js b/src/slang-nodes/NamedArgumentsDeclaration.js index 4974d95e1..9308b2806 100644 --- a/src/slang-nodes/NamedArgumentsDeclaration.js +++ b/src/slang-nodes/NamedArgumentsDeclaration.js @@ -17,7 +17,7 @@ export class NamedArgumentsDeclaration extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ this.openParen, this.arguments ? path.call(print, 'arguments') : '', diff --git a/src/slang-nodes/NamedImport.js b/src/slang-nodes/NamedImport.js index 74f3b7c1f..11d00f53f 100644 --- a/src/slang-nodes/NamedImport.js +++ b/src/slang-nodes/NamedImport.js @@ -18,7 +18,7 @@ export class NamedImport extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ this.asterisk, path.call(print, 'alias'), diff --git a/src/slang-nodes/NewExpression.js b/src/slang-nodes/NewExpression.js index 7c6910620..a504ec777 100644 --- a/src/slang-nodes/NewExpression.js +++ b/src/slang-nodes/NewExpression.js @@ -12,7 +12,7 @@ export class NewExpression extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [`${this.newKeyword} `, path.call(print, 'typeName')]; } } diff --git a/src/slang-nodes/OrExpression.js b/src/slang-nodes/OrExpression.js index ff3c1371e..fc2284be8 100644 --- a/src/slang-nodes/OrExpression.js +++ b/src/slang-nodes/OrExpression.js @@ -23,7 +23,7 @@ export class OrExpression extends SlangNode { this.initiateLoc(ast); } - print({ path, print, options }) { + print(path, print, options) { return logicalOperationPrint({ node: this, path, print, options }); } } diff --git a/src/slang-nodes/OverridePaths.js b/src/slang-nodes/OverridePaths.js index 88a0e6912..d0c9910a2 100644 --- a/src/slang-nodes/OverridePaths.js +++ b/src/slang-nodes/OverridePaths.js @@ -15,7 +15,7 @@ export class OverridePaths extends SlangNode { } // TODO: implement print - print({ path, print, options }) { + print(path, print, options) { return ['TODO: OverridePaths']; } } diff --git a/src/slang-nodes/OverridePathsDeclaration.js b/src/slang-nodes/OverridePathsDeclaration.js index 1824736dc..a168eb020 100644 --- a/src/slang-nodes/OverridePathsDeclaration.js +++ b/src/slang-nodes/OverridePathsDeclaration.js @@ -16,7 +16,7 @@ export class OverridePathsDeclaration extends SlangNode { } // TODO: implement print - print({ path, print, options }) { + print(path, print, options) { return ['TODO: OverridePathsDeclaration']; } } diff --git a/src/slang-nodes/OverrideSpecifier.js b/src/slang-nodes/OverrideSpecifier.js index 7d0c1d655..d36804ba9 100644 --- a/src/slang-nodes/OverrideSpecifier.js +++ b/src/slang-nodes/OverrideSpecifier.js @@ -14,7 +14,7 @@ export class OverrideSpecifier extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ this.overrideKeyword, this.overridden ? path.call(print, 'overridden') : '' diff --git a/src/slang-nodes/Parameter.js b/src/slang-nodes/Parameter.js index 43eb68cf9..838c922b7 100644 --- a/src/slang-nodes/Parameter.js +++ b/src/slang-nodes/Parameter.js @@ -20,7 +20,7 @@ export class Parameter extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return group([ path.call(print, 'typeName'), this.storageLocation ? ` ${path.call(print, 'storageLocation')}` : '', diff --git a/src/slang-nodes/Parameters.js b/src/slang-nodes/Parameters.js index 2c8355984..ab46d5745 100644 --- a/src/slang-nodes/Parameters.js +++ b/src/slang-nodes/Parameters.js @@ -26,7 +26,7 @@ export class Parameters extends SlangNode { } } - print({ path, print, options }) { + print(path, print, options) { if (this.items.length > 0) { return printSeparatedList(path.map(print, 'items'), { grouped: false }); } diff --git a/src/slang-nodes/ParametersDeclaration.js b/src/slang-nodes/ParametersDeclaration.js index 67cfa61b4..8130648f5 100644 --- a/src/slang-nodes/ParametersDeclaration.js +++ b/src/slang-nodes/ParametersDeclaration.js @@ -23,7 +23,7 @@ export class ParametersDeclaration extends SlangNode { } } - print({ path, print }) { + print(path, print) { return [this.openParen, path.call(print, 'parameters'), this.closeParen]; } } diff --git a/src/slang-nodes/PathImport.js b/src/slang-nodes/PathImport.js index 3c9b1b6ef..7c9a9ed97 100644 --- a/src/slang-nodes/PathImport.js +++ b/src/slang-nodes/PathImport.js @@ -14,7 +14,7 @@ export class PathImport extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ path.call(print, 'path'), this.alias ? path.call(print, 'alias') : '' diff --git a/src/slang-nodes/PositionalArguments.js b/src/slang-nodes/PositionalArguments.js index c970b9c5c..3ad4f5044 100644 --- a/src/slang-nodes/PositionalArguments.js +++ b/src/slang-nodes/PositionalArguments.js @@ -15,7 +15,7 @@ export class PositionalArguments extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return this.items.length > 0 ? printSeparatedList(path.map(print, 'items')) : ''; diff --git a/src/slang-nodes/PositionalArgumentsDeclaration.js b/src/slang-nodes/PositionalArgumentsDeclaration.js index 0e696dc3f..3a65e0a51 100644 --- a/src/slang-nodes/PositionalArgumentsDeclaration.js +++ b/src/slang-nodes/PositionalArgumentsDeclaration.js @@ -15,7 +15,7 @@ export class PositionalArgumentsDeclaration extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [this.openParen, path.call(print, 'arguments'), this.closeParen]; } } diff --git a/src/slang-nodes/PostfixExpression.js b/src/slang-nodes/PostfixExpression.js index 7411a2d65..54db16ba8 100644 --- a/src/slang-nodes/PostfixExpression.js +++ b/src/slang-nodes/PostfixExpression.js @@ -12,7 +12,7 @@ export class PostfixExpression extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [path.call(print, 'operand'), this.operator]; } } diff --git a/src/slang-nodes/Pragma.js b/src/slang-nodes/Pragma.js index 4520eba11..1650fc1d0 100644 --- a/src/slang-nodes/Pragma.js +++ b/src/slang-nodes/Pragma.js @@ -19,7 +19,7 @@ export class Pragma extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/PragmaDirective.js b/src/slang-nodes/PragmaDirective.js index 14b88f772..8c43b3fb4 100644 --- a/src/slang-nodes/PragmaDirective.js +++ b/src/slang-nodes/PragmaDirective.js @@ -16,7 +16,7 @@ export class PragmaDirective extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ `${this.pragmaKeyword} `, path.call(print, 'pragma'), diff --git a/src/slang-nodes/PrefixExpression.js b/src/slang-nodes/PrefixExpression.js index d66fbdfb8..d08f72495 100644 --- a/src/slang-nodes/PrefixExpression.js +++ b/src/slang-nodes/PrefixExpression.js @@ -12,7 +12,7 @@ export class PrefixExpression extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [this.operator, path.call(print, 'operand')]; } } diff --git a/src/slang-nodes/ReceiveFunctionAttribute.js b/src/slang-nodes/ReceiveFunctionAttribute.js index 4d77f9f2e..c3719c981 100644 --- a/src/slang-nodes/ReceiveFunctionAttribute.js +++ b/src/slang-nodes/ReceiveFunctionAttribute.js @@ -12,7 +12,7 @@ export class ReceiveFunctionAttribute extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/ReceiveFunctionAttributes.js b/src/slang-nodes/ReceiveFunctionAttributes.js index 0cf478733..82d9fe1a2 100644 --- a/src/slang-nodes/ReceiveFunctionAttributes.js +++ b/src/slang-nodes/ReceiveFunctionAttributes.js @@ -15,7 +15,7 @@ export class ReceiveFunctionAttributes extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return path.map(print, 'items').map((item) => [line, item]); } } diff --git a/src/slang-nodes/ReceiveFunctionDefinition.js b/src/slang-nodes/ReceiveFunctionDefinition.js index adda23d13..e3b0f6972 100644 --- a/src/slang-nodes/ReceiveFunctionDefinition.js +++ b/src/slang-nodes/ReceiveFunctionDefinition.js @@ -19,7 +19,7 @@ export class ReceiveFunctionDefinition extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return printFunction(this.receiveKeyword, this, path, print); } } diff --git a/src/slang-nodes/ReturnStatement.js b/src/slang-nodes/ReturnStatement.js index ce42967fa..3fab97ebf 100644 --- a/src/slang-nodes/ReturnStatement.js +++ b/src/slang-nodes/ReturnStatement.js @@ -31,7 +31,7 @@ export class ReturnStatement extends SlangNode { this.initiateLoc(ast); } - print({ path, print, options }) { + print(path, print, options) { return [ this.returnKeyword, expression(this, path, print, options), diff --git a/src/slang-nodes/ReturnsDeclaration.js b/src/slang-nodes/ReturnsDeclaration.js index 2c2f67ef1..85cdd7fd2 100644 --- a/src/slang-nodes/ReturnsDeclaration.js +++ b/src/slang-nodes/ReturnsDeclaration.js @@ -15,7 +15,7 @@ export class ReturnsDeclaration extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [`${this.returnsKeyword} `, group(path.call(print, 'variables'))]; } } diff --git a/src/slang-nodes/RevertStatement.js b/src/slang-nodes/RevertStatement.js index 1e2ad9810..0fd36f9c0 100644 --- a/src/slang-nodes/RevertStatement.js +++ b/src/slang-nodes/RevertStatement.js @@ -20,7 +20,7 @@ export class RevertStatement extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ `${this.revertKeyword} `, this.error ? path.call(print, 'error') : '', diff --git a/src/slang-nodes/ShiftExpression.js b/src/slang-nodes/ShiftExpression.js index 4a38b92bb..3ba6a4b0a 100644 --- a/src/slang-nodes/ShiftExpression.js +++ b/src/slang-nodes/ShiftExpression.js @@ -32,7 +32,7 @@ export class ShiftExpression extends SlangNode { this.initiateLoc(ast); } - print({ path, print, options }) { + print(path, print, options) { return binaryOperationPrint({ node: this, path, print, options }); } } diff --git a/src/slang-nodes/SourceUnit.js b/src/slang-nodes/SourceUnit.js index 37ba99852..080faec56 100644 --- a/src/slang-nodes/SourceUnit.js +++ b/src/slang-nodes/SourceUnit.js @@ -18,7 +18,7 @@ export class SourceUnit extends SlangNode { this.initiateLoc(ast); } - print({ options, path, print }) { + print(path, print, options) { return [path.call(print, 'members'), options.parentParser ? '' : line]; } } diff --git a/src/slang-nodes/SourceUnitMember.js b/src/slang-nodes/SourceUnitMember.js index 489f563ae..428f89f9e 100644 --- a/src/slang-nodes/SourceUnitMember.js +++ b/src/slang-nodes/SourceUnitMember.js @@ -43,7 +43,7 @@ export class SourceUnitMember extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/SourceUnitMembers.js b/src/slang-nodes/SourceUnitMembers.js index 7743f3c00..c4d727ac5 100644 --- a/src/slang-nodes/SourceUnitMembers.js +++ b/src/slang-nodes/SourceUnitMembers.js @@ -13,7 +13,7 @@ export class SourceUnitMembers extends SlangNode { this.initiateLoc(ast); } - print({ path, options, print }) { + print(path, print, options) { return printPreservingEmptyLines(path, 'items', options, print); } } diff --git a/src/slang-nodes/StateVariableAttribute.js b/src/slang-nodes/StateVariableAttribute.js index fb047494a..3d21eb5a8 100644 --- a/src/slang-nodes/StateVariableAttribute.js +++ b/src/slang-nodes/StateVariableAttribute.js @@ -12,7 +12,7 @@ export class StateVariableAttribute extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/StateVariableAttributes.js b/src/slang-nodes/StateVariableAttributes.js index 768d911e9..2d5c62aa8 100644 --- a/src/slang-nodes/StateVariableAttributes.js +++ b/src/slang-nodes/StateVariableAttributes.js @@ -11,7 +11,7 @@ export class StateVariableAttributes extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return this.items.length ? path.map(print, 'items').map((item) => [' ', item]) : ''; diff --git a/src/slang-nodes/StateVariableDefinition.js b/src/slang-nodes/StateVariableDefinition.js index b95592121..acc14a711 100644 --- a/src/slang-nodes/StateVariableDefinition.js +++ b/src/slang-nodes/StateVariableDefinition.js @@ -23,7 +23,7 @@ export class StateVariableDefinition extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ path.call(print, 'typeName'), path.call(print, 'attributes'), diff --git a/src/slang-nodes/StateVariableDefinitionValue.js b/src/slang-nodes/StateVariableDefinitionValue.js index cc6479465..682528384 100644 --- a/src/slang-nodes/StateVariableDefinitionValue.js +++ b/src/slang-nodes/StateVariableDefinitionValue.js @@ -15,7 +15,7 @@ export class StateVariableDefinitionValue extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return this.value.variant.kind === 'ArrayExpression' ? [` ${this.equal} `, path.call(print, 'value')] : group([` ${this.equal}`, indent([line, path.call(print, 'value')])]); diff --git a/src/slang-nodes/Statement.js b/src/slang-nodes/Statement.js index 5d73f9b86..95e899da8 100644 --- a/src/slang-nodes/Statement.js +++ b/src/slang-nodes/Statement.js @@ -9,7 +9,7 @@ export class Statement extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/Statements.js b/src/slang-nodes/Statements.js index 5cea1bc81..84e698e9c 100644 --- a/src/slang-nodes/Statements.js +++ b/src/slang-nodes/Statements.js @@ -19,7 +19,7 @@ export class Statements extends SlangNode { this.initiateLoc(ast); } - print({ path, options, print }) { + print(path, print, options) { return this.items.length === 0 && (!this.comments || this.comments.length === 0) ? '' diff --git a/src/slang-nodes/StringExpression.js b/src/slang-nodes/StringExpression.js index a12d47c97..e13dbcbd5 100644 --- a/src/slang-nodes/StringExpression.js +++ b/src/slang-nodes/StringExpression.js @@ -9,7 +9,7 @@ export class StringExpression extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/StringLiterals.js b/src/slang-nodes/StringLiterals.js index 0e54c37ef..b1ca841ed 100644 --- a/src/slang-nodes/StringLiterals.js +++ b/src/slang-nodes/StringLiterals.js @@ -14,7 +14,7 @@ export class StringLiterals extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return join(hardline, path.map(print, 'items')); } } diff --git a/src/slang-nodes/StructDefinition.js b/src/slang-nodes/StructDefinition.js index 7dbce931b..0b762493f 100644 --- a/src/slang-nodes/StructDefinition.js +++ b/src/slang-nodes/StructDefinition.js @@ -21,7 +21,7 @@ export class StructDefinition extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ `${this.structKeyword} ${this.name} ${this.openBrace}`, path.call(print, 'members'), diff --git a/src/slang-nodes/StructMember.js b/src/slang-nodes/StructMember.js index f7379e517..d31039dfb 100644 --- a/src/slang-nodes/StructMember.js +++ b/src/slang-nodes/StructMember.js @@ -15,7 +15,7 @@ export class StructMember extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [path.call(print, 'typeName'), ` ${this.name}${this.semicolon}`]; } } diff --git a/src/slang-nodes/StructMembers.js b/src/slang-nodes/StructMembers.js index 00c862976..ed5f5a2c2 100644 --- a/src/slang-nodes/StructMembers.js +++ b/src/slang-nodes/StructMembers.js @@ -15,7 +15,7 @@ export class StructMembers extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return this.items.length > 0 ? printSeparatedList(path.map(print, 'items'), { firstSeparator: hardline, diff --git a/src/slang-nodes/ThrowStatement.js b/src/slang-nodes/ThrowStatement.js index 85b8f5a20..c9c0c211e 100644 --- a/src/slang-nodes/ThrowStatement.js +++ b/src/slang-nodes/ThrowStatement.js @@ -13,7 +13,7 @@ export class ThrowStatement extends SlangNode { } // TODO: implement print - print({ path, print, options }) { + print(path, print, options) { return ['TODO: ThrowStatement']; } } diff --git a/src/slang-nodes/TryStatement.js b/src/slang-nodes/TryStatement.js index 70bb22294..cdc7f769f 100644 --- a/src/slang-nodes/TryStatement.js +++ b/src/slang-nodes/TryStatement.js @@ -27,7 +27,7 @@ export class TryStatement extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ this.tryKeyword, printSeparatedItem(path.call(print, 'expression'), { diff --git a/src/slang-nodes/TupleDeconstructionElement.js b/src/slang-nodes/TupleDeconstructionElement.js index 5bae8fbbd..615265acd 100644 --- a/src/slang-nodes/TupleDeconstructionElement.js +++ b/src/slang-nodes/TupleDeconstructionElement.js @@ -11,7 +11,7 @@ export class TupleDeconstructionElement extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return this.member ? path.call(print, 'member') : ''; } } diff --git a/src/slang-nodes/TupleDeconstructionElements.js b/src/slang-nodes/TupleDeconstructionElements.js index ff07aa03a..ddd01183d 100644 --- a/src/slang-nodes/TupleDeconstructionElements.js +++ b/src/slang-nodes/TupleDeconstructionElements.js @@ -15,7 +15,7 @@ export class TupleDeconstructionElements extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return printSeparatedList(path.map(print, 'items')); } } diff --git a/src/slang-nodes/TupleDeconstructionStatement.js b/src/slang-nodes/TupleDeconstructionStatement.js index fc1702da0..8d937e26f 100644 --- a/src/slang-nodes/TupleDeconstructionStatement.js +++ b/src/slang-nodes/TupleDeconstructionStatement.js @@ -30,7 +30,7 @@ export class TupleDeconstructionStatement extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ this.varKeyword ? this.varKeyword : '', this.openParen, diff --git a/src/slang-nodes/TupleExpression.js b/src/slang-nodes/TupleExpression.js index efcdf05be..53b9f88a2 100644 --- a/src/slang-nodes/TupleExpression.js +++ b/src/slang-nodes/TupleExpression.js @@ -23,7 +23,7 @@ export class TupleExpression extends SlangNode { } } - print({ path, print }) { + print(path, print) { return [this.openParen, path.call(print, 'items'), this.closeParen]; } } diff --git a/src/slang-nodes/TupleMember.js b/src/slang-nodes/TupleMember.js index ddb09ab8f..1ac3b77a5 100644 --- a/src/slang-nodes/TupleMember.js +++ b/src/slang-nodes/TupleMember.js @@ -9,7 +9,7 @@ export class TupleMember extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/TupleValue.js b/src/slang-nodes/TupleValue.js index 916566563..80fb7e7d4 100644 --- a/src/slang-nodes/TupleValue.js +++ b/src/slang-nodes/TupleValue.js @@ -17,7 +17,7 @@ export class TupleValue extends SlangNode { } } - print({ path, print }) { + print(path, print) { return this.expression ? path.call(print, 'expression') : ''; } } diff --git a/src/slang-nodes/TupleValues.js b/src/slang-nodes/TupleValues.js index 96920413d..08d12da05 100644 --- a/src/slang-nodes/TupleValues.js +++ b/src/slang-nodes/TupleValues.js @@ -23,7 +23,7 @@ export class TupleValues extends SlangNode { } } - print({ path, print }) { + print(path, print) { return this.items.length === 1 && isBinaryOperation(this.items[0].expression.variant) ? path.map(print, 'items') diff --git a/src/slang-nodes/TypeExpression.js b/src/slang-nodes/TypeExpression.js index 64be3ef3d..a621aa8e2 100644 --- a/src/slang-nodes/TypeExpression.js +++ b/src/slang-nodes/TypeExpression.js @@ -19,7 +19,7 @@ export class TypeExpression extends SlangNode { } // TODO: implement print - print({ path, print, options }) { + print(path, print, options) { return ['TODO: TypeExpression']; } } diff --git a/src/slang-nodes/TypeName.js b/src/slang-nodes/TypeName.js index df155dca3..63c025782 100644 --- a/src/slang-nodes/TypeName.js +++ b/src/slang-nodes/TypeName.js @@ -9,7 +9,7 @@ export class TypeName extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/TypedTupleMember.js b/src/slang-nodes/TypedTupleMember.js index b9f43b006..b2fb2fdfd 100644 --- a/src/slang-nodes/TypedTupleMember.js +++ b/src/slang-nodes/TypedTupleMember.js @@ -17,7 +17,7 @@ export class TypedTupleMember extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ path.call(print, 'typeName'), this.storageLocation ? [' ', path.call(print, 'storageLocation')] : '', diff --git a/src/slang-nodes/UncheckedBlock.js b/src/slang-nodes/UncheckedBlock.js index 95fd10901..0d21df976 100644 --- a/src/slang-nodes/UncheckedBlock.js +++ b/src/slang-nodes/UncheckedBlock.js @@ -12,7 +12,7 @@ export class UncheckedBlock extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [`${this.uncheckedKeyword} `, path.call(print, 'block')]; } } diff --git a/src/slang-nodes/UnicodeStringLiterals.js b/src/slang-nodes/UnicodeStringLiterals.js index 8829277b6..f656b2b15 100644 --- a/src/slang-nodes/UnicodeStringLiterals.js +++ b/src/slang-nodes/UnicodeStringLiterals.js @@ -14,7 +14,7 @@ export class UnicodeStringLiterals extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return join(hardline, path.map(print, 'items')); } } diff --git a/src/slang-nodes/UnnamedFunctionAttribute.js b/src/slang-nodes/UnnamedFunctionAttribute.js index de334543d..a7c31335b 100644 --- a/src/slang-nodes/UnnamedFunctionAttribute.js +++ b/src/slang-nodes/UnnamedFunctionAttribute.js @@ -12,7 +12,7 @@ export class UnnamedFunctionAttribute extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/UnnamedFunctionAttributes.js b/src/slang-nodes/UnnamedFunctionAttributes.js index 9c7845328..3311fd90e 100644 --- a/src/slang-nodes/UnnamedFunctionAttributes.js +++ b/src/slang-nodes/UnnamedFunctionAttributes.js @@ -15,7 +15,7 @@ export class UnnamedFunctionAttributes extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return path.map(print, 'items').map((item) => [line, item]); } } diff --git a/src/slang-nodes/UnnamedFunctionDefinition.js b/src/slang-nodes/UnnamedFunctionDefinition.js index d00bae4f1..0f8e31404 100644 --- a/src/slang-nodes/UnnamedFunctionDefinition.js +++ b/src/slang-nodes/UnnamedFunctionDefinition.js @@ -19,7 +19,7 @@ export class UnnamedFunctionDefinition extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return printFunction(this.functionKeyword, this, path, print); } } diff --git a/src/slang-nodes/UntypedTupleMember.js b/src/slang-nodes/UntypedTupleMember.js index 385493c4c..7ec5b3273 100644 --- a/src/slang-nodes/UntypedTupleMember.js +++ b/src/slang-nodes/UntypedTupleMember.js @@ -15,7 +15,7 @@ export class UntypedTupleMember extends SlangNode { } // TODO: implement print - print({ path, print, options }) { + print(path, print, options) { return ['TODO: UntypedTupleMemberUntypedTupleMember']; } } diff --git a/src/slang-nodes/UserDefinedValueTypeDefinition.js b/src/slang-nodes/UserDefinedValueTypeDefinition.js index dfb6965fe..209e09a8c 100644 --- a/src/slang-nodes/UserDefinedValueTypeDefinition.js +++ b/src/slang-nodes/UserDefinedValueTypeDefinition.js @@ -21,7 +21,7 @@ export class UserDefinedValueTypeDefinition extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ `${this.typeKeyword} ${this.name} ${this.isKeyword} `, path.call(print, 'valueType'), diff --git a/src/slang-nodes/UsingAlias.js b/src/slang-nodes/UsingAlias.js index 4fedb8d1c..8950bca2f 100644 --- a/src/slang-nodes/UsingAlias.js +++ b/src/slang-nodes/UsingAlias.js @@ -12,7 +12,7 @@ export class UsingAlias extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [` ${this.asKeyword} `, path.call(print, 'operator')]; } } diff --git a/src/slang-nodes/UsingClause.js b/src/slang-nodes/UsingClause.js index abc0cd40a..8eb5a1785 100644 --- a/src/slang-nodes/UsingClause.js +++ b/src/slang-nodes/UsingClause.js @@ -9,7 +9,7 @@ export class UsingClause extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/UsingDeconstruction.js b/src/slang-nodes/UsingDeconstruction.js index 959b274eb..0d0822b7c 100644 --- a/src/slang-nodes/UsingDeconstruction.js +++ b/src/slang-nodes/UsingDeconstruction.js @@ -15,7 +15,7 @@ export class UsingDeconstruction extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [this.openBrace, path.call(print, 'symbols'), this.closeBrace]; } } diff --git a/src/slang-nodes/UsingDeconstructionSymbol.js b/src/slang-nodes/UsingDeconstructionSymbol.js index bf740de6c..563b66a2b 100644 --- a/src/slang-nodes/UsingDeconstructionSymbol.js +++ b/src/slang-nodes/UsingDeconstructionSymbol.js @@ -14,7 +14,7 @@ export class UsingDeconstructionSymbol extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ path.call(print, 'name'), this.alias ? path.call(print, 'alias') : '' diff --git a/src/slang-nodes/UsingDeconstructionSymbols.js b/src/slang-nodes/UsingDeconstructionSymbols.js index e0442274d..1cdbe0bdb 100644 --- a/src/slang-nodes/UsingDeconstructionSymbols.js +++ b/src/slang-nodes/UsingDeconstructionSymbols.js @@ -18,7 +18,7 @@ export class UsingDeconstructionSymbols extends SlangNode { this.initiateLoc(ast); } - print({ path, print, options }) { + print(path, print, options) { return printSeparatedList(path.map(print, 'items'), { firstSeparator: options.bracketSpacing ? line : softline }); diff --git a/src/slang-nodes/UsingDirective.js b/src/slang-nodes/UsingDirective.js index 8319c6265..63b90712c 100644 --- a/src/slang-nodes/UsingDirective.js +++ b/src/slang-nodes/UsingDirective.js @@ -24,7 +24,7 @@ export class UsingDirective extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ `${this.usingKeyword} `, path.call(print, 'clause'), diff --git a/src/slang-nodes/UsingTarget.js b/src/slang-nodes/UsingTarget.js index ffcc61b06..548c99d79 100644 --- a/src/slang-nodes/UsingTarget.js +++ b/src/slang-nodes/UsingTarget.js @@ -12,7 +12,7 @@ export class UsingTarget extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/VariableDeclarationStatement.js b/src/slang-nodes/VariableDeclarationStatement.js index 4f83a6eec..d10febb63 100644 --- a/src/slang-nodes/VariableDeclarationStatement.js +++ b/src/slang-nodes/VariableDeclarationStatement.js @@ -30,7 +30,7 @@ export class VariableDeclarationStatement extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { const declarationDoc = group( [ path.call(print, 'variableType'), diff --git a/src/slang-nodes/VariableDeclarationType.js b/src/slang-nodes/VariableDeclarationType.js index b8012a2f6..54039899f 100644 --- a/src/slang-nodes/VariableDeclarationType.js +++ b/src/slang-nodes/VariableDeclarationType.js @@ -12,7 +12,7 @@ export class VariableDeclarationType extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/VariableDeclarationValue.js b/src/slang-nodes/VariableDeclarationValue.js index 037ede3fb..37db434bc 100644 --- a/src/slang-nodes/VariableDeclarationValue.js +++ b/src/slang-nodes/VariableDeclarationValue.js @@ -12,7 +12,7 @@ export class VariableDeclarationValue extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [` ${this.equal} `, path.call(print, 'expression')]; } } diff --git a/src/slang-nodes/VersionComparator.js b/src/slang-nodes/VersionComparator.js index c302a4790..3897b186a 100644 --- a/src/slang-nodes/VersionComparator.js +++ b/src/slang-nodes/VersionComparator.js @@ -12,7 +12,7 @@ export class VersionComparator extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [this.operator, path.call(print, 'operand')]; } } diff --git a/src/slang-nodes/VersionExpression.js b/src/slang-nodes/VersionExpression.js index ac5f05996..1bb1ceddf 100644 --- a/src/slang-nodes/VersionExpression.js +++ b/src/slang-nodes/VersionExpression.js @@ -12,7 +12,7 @@ export class VersionExpression extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/VersionExpressionSet.js b/src/slang-nodes/VersionExpressionSet.js index 8ac475e99..4c18ae29e 100644 --- a/src/slang-nodes/VersionExpressionSet.js +++ b/src/slang-nodes/VersionExpressionSet.js @@ -14,7 +14,7 @@ export class VersionExpressionSet extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return join(' ', path.map(print, 'items')); } } diff --git a/src/slang-nodes/VersionExpressionSets.js b/src/slang-nodes/VersionExpressionSets.js index cd9dd1333..ff2ac9585 100644 --- a/src/slang-nodes/VersionExpressionSets.js +++ b/src/slang-nodes/VersionExpressionSets.js @@ -14,7 +14,7 @@ export class VersionExpressionSets extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return path .map(print, 'items') .map((item, index) => diff --git a/src/slang-nodes/VersionPragma.js b/src/slang-nodes/VersionPragma.js index a4cb5e094..d4262e8ea 100644 --- a/src/slang-nodes/VersionPragma.js +++ b/src/slang-nodes/VersionPragma.js @@ -12,7 +12,7 @@ export class VersionPragma extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [`${this.solidityKeyword} `, path.call(print, 'sets')]; } } diff --git a/src/slang-nodes/VersionRange.js b/src/slang-nodes/VersionRange.js index 4cda609d3..17a3ce601 100644 --- a/src/slang-nodes/VersionRange.js +++ b/src/slang-nodes/VersionRange.js @@ -16,7 +16,7 @@ export class VersionRange extends SlangNode { } // TODO: implement print - print({ path, print, options }) { + print(path, print, options) { return ['TODO: VersionRange']; } } diff --git a/src/slang-nodes/WhileStatement.js b/src/slang-nodes/WhileStatement.js index 281d66a3f..d80a6511b 100644 --- a/src/slang-nodes/WhileStatement.js +++ b/src/slang-nodes/WhileStatement.js @@ -30,7 +30,7 @@ export class WhileStatement extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ `${this.whileKeyword} ${this.openParen}`, printSeparatedItem(path.call(print, 'condition')), diff --git a/src/slang-nodes/YulArguments.js b/src/slang-nodes/YulArguments.js index d6e50d03c..a4cb9b942 100644 --- a/src/slang-nodes/YulArguments.js +++ b/src/slang-nodes/YulArguments.js @@ -15,7 +15,7 @@ export class YulArguments extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return printSeparatedList(path.map(print, 'items')); } } diff --git a/src/slang-nodes/YulAssignmentOperator.js b/src/slang-nodes/YulAssignmentOperator.js index acfe45c95..4b152f7bf 100644 --- a/src/slang-nodes/YulAssignmentOperator.js +++ b/src/slang-nodes/YulAssignmentOperator.js @@ -12,7 +12,7 @@ export class YulAssignmentOperator extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/YulAssignmentStatement.js b/src/slang-nodes/YulAssignmentStatement.js index 9da493a2d..0f2e7faec 100644 --- a/src/slang-nodes/YulAssignmentStatement.js +++ b/src/slang-nodes/YulAssignmentStatement.js @@ -15,7 +15,7 @@ export class YulAssignmentStatement extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ path.call(print, 'names'), ' ', diff --git a/src/slang-nodes/YulBlock.js b/src/slang-nodes/YulBlock.js index 8a1358f94..d805c96c2 100644 --- a/src/slang-nodes/YulBlock.js +++ b/src/slang-nodes/YulBlock.js @@ -15,7 +15,7 @@ export class YulBlock extends SlangNode { this.initiateLoc(ast); } - print({ print }) { - return [this.openBrace, print.call(print, 'statements'), this.closeBrace]; + print(path, print) { + return [this.openBrace, path.call(print, 'statements'), this.closeBrace]; } } diff --git a/src/slang-nodes/YulColonAndEqual.js b/src/slang-nodes/YulColonAndEqual.js index f812dbef2..99ca0a27f 100644 --- a/src/slang-nodes/YulColonAndEqual.js +++ b/src/slang-nodes/YulColonAndEqual.js @@ -13,7 +13,7 @@ export class YulColonAndEqual extends SlangNode { } // TODO: implement print - print({ path, print, options }) { + print(path, print, options) { return ['TODO: YulColonAndEqual']; } } diff --git a/src/slang-nodes/YulDefaultCase.js b/src/slang-nodes/YulDefaultCase.js index 20168bba5..46712a3bb 100644 --- a/src/slang-nodes/YulDefaultCase.js +++ b/src/slang-nodes/YulDefaultCase.js @@ -12,7 +12,7 @@ export class YulDefaultCase extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [`${this.defaultKeyword} `, path.call(print, 'body')]; } } diff --git a/src/slang-nodes/YulExpression.js b/src/slang-nodes/YulExpression.js index 71b585f99..b9a120908 100644 --- a/src/slang-nodes/YulExpression.js +++ b/src/slang-nodes/YulExpression.js @@ -9,7 +9,7 @@ export class YulExpression extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/YulForStatement.js b/src/slang-nodes/YulForStatement.js index e6fce20a8..f0266aef3 100644 --- a/src/slang-nodes/YulForStatement.js +++ b/src/slang-nodes/YulForStatement.js @@ -25,7 +25,7 @@ export class YulForStatement extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ `${this.forKeyword} `, path.call(print, 'initialization'), diff --git a/src/slang-nodes/YulFunctionCallExpression.js b/src/slang-nodes/YulFunctionCallExpression.js index 119052cf5..633658e74 100644 --- a/src/slang-nodes/YulFunctionCallExpression.js +++ b/src/slang-nodes/YulFunctionCallExpression.js @@ -18,7 +18,7 @@ export class YulFunctionCallExpression extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ path.call(print, 'operand'), this.openParen, diff --git a/src/slang-nodes/YulFunctionDefinition.js b/src/slang-nodes/YulFunctionDefinition.js index f09181414..a7b5a6aed 100644 --- a/src/slang-nodes/YulFunctionDefinition.js +++ b/src/slang-nodes/YulFunctionDefinition.js @@ -23,7 +23,7 @@ export class YulFunctionDefinition extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ `${this.functionKeyword} ${this.name}`, path.call(print, 'parameters'), diff --git a/src/slang-nodes/YulIfStatement.js b/src/slang-nodes/YulIfStatement.js index 6cdd27366..066edbe03 100644 --- a/src/slang-nodes/YulIfStatement.js +++ b/src/slang-nodes/YulIfStatement.js @@ -15,7 +15,7 @@ export class YulIfStatement extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ `${this.ifKeyword} `, path.call(print, 'condition'), diff --git a/src/slang-nodes/YulLeaveStatement.js b/src/slang-nodes/YulLeaveStatement.js index 47d408a96..96d816f8a 100644 --- a/src/slang-nodes/YulLeaveStatement.js +++ b/src/slang-nodes/YulLeaveStatement.js @@ -10,7 +10,7 @@ export class YulLeaveStatement extends SlangNode { } // TODO: implement print - print({ path, print, options }) { + print(path, print, options) { return ['TODO: YulLeaveStatement']; } } diff --git a/src/slang-nodes/YulLiteral.js b/src/slang-nodes/YulLiteral.js index 62b66f88b..6d0af89f3 100644 --- a/src/slang-nodes/YulLiteral.js +++ b/src/slang-nodes/YulLiteral.js @@ -12,7 +12,7 @@ export class YulLiteral extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/YulParametersDeclaration.js b/src/slang-nodes/YulParametersDeclaration.js index a27702136..effb4486f 100644 --- a/src/slang-nodes/YulParametersDeclaration.js +++ b/src/slang-nodes/YulParametersDeclaration.js @@ -15,7 +15,7 @@ export class YulParametersDeclaration extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [this.openParen, path.call(print, 'parameters'), this.closeParen]; } } diff --git a/src/slang-nodes/YulPath.js b/src/slang-nodes/YulPath.js index d540d2180..3c4301eae 100644 --- a/src/slang-nodes/YulPath.js +++ b/src/slang-nodes/YulPath.js @@ -14,7 +14,7 @@ export class YulPath extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return path .map(print, 'items') .map((item, index) => diff --git a/src/slang-nodes/YulPaths.js b/src/slang-nodes/YulPaths.js index c7737f59f..3ed3dac1a 100644 --- a/src/slang-nodes/YulPaths.js +++ b/src/slang-nodes/YulPaths.js @@ -14,7 +14,7 @@ export class YulPaths extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return path .map(print, 'items') .map((item, index) => diff --git a/src/slang-nodes/YulReturnsDeclaration.js b/src/slang-nodes/YulReturnsDeclaration.js index d578e8cbd..3ebd13c4a 100644 --- a/src/slang-nodes/YulReturnsDeclaration.js +++ b/src/slang-nodes/YulReturnsDeclaration.js @@ -16,7 +16,7 @@ export class YulReturnsDeclaration extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return printSeparatedItem( [this.minusGreaterThan, path.call(print, 'variables')], { diff --git a/src/slang-nodes/YulStatement.js b/src/slang-nodes/YulStatement.js index 720f4aaeb..7383821e4 100644 --- a/src/slang-nodes/YulStatement.js +++ b/src/slang-nodes/YulStatement.js @@ -9,7 +9,7 @@ export class YulStatement extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/YulStatements.js b/src/slang-nodes/YulStatements.js index ee90e0054..747c85ef1 100644 --- a/src/slang-nodes/YulStatements.js +++ b/src/slang-nodes/YulStatements.js @@ -19,7 +19,7 @@ export class YulStatements extends SlangNode { this.initiateLoc(ast); } - print({ path, print, options }) { + print(path, print, options) { return this.items.length === 0 && (!this.comments || this.comments.length === 0) ? '' diff --git a/src/slang-nodes/YulSwitchCase.js b/src/slang-nodes/YulSwitchCase.js index 666c3c2f8..9a6a10ce9 100644 --- a/src/slang-nodes/YulSwitchCase.js +++ b/src/slang-nodes/YulSwitchCase.js @@ -9,7 +9,7 @@ export class YulSwitchCase extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/YulSwitchCases.js b/src/slang-nodes/YulSwitchCases.js index dbbbaf9cc..b17c61ea2 100644 --- a/src/slang-nodes/YulSwitchCases.js +++ b/src/slang-nodes/YulSwitchCases.js @@ -14,7 +14,7 @@ export class YulSwitchCases extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return join(hardline, path.map(print, 'items')); } } diff --git a/src/slang-nodes/YulSwitchStatement.js b/src/slang-nodes/YulSwitchStatement.js index 4e6c7493c..6faf6965d 100644 --- a/src/slang-nodes/YulSwitchStatement.js +++ b/src/slang-nodes/YulSwitchStatement.js @@ -18,7 +18,7 @@ export class YulSwitchStatement extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ `${this.switchKeyword} `, path.call(print, 'expression'), diff --git a/src/slang-nodes/YulValueCase.js b/src/slang-nodes/YulValueCase.js index 0bbd022da..843a8e1c8 100644 --- a/src/slang-nodes/YulValueCase.js +++ b/src/slang-nodes/YulValueCase.js @@ -15,7 +15,7 @@ export class YulValueCase extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ `${this.caseKeyword} `, path.call(print, 'value'), diff --git a/src/slang-nodes/YulVariableAssignmentStatement.js b/src/slang-nodes/YulVariableAssignmentStatement.js index cf81a43d6..9cbc4b552 100644 --- a/src/slang-nodes/YulVariableAssignmentStatement.js +++ b/src/slang-nodes/YulVariableAssignmentStatement.js @@ -15,7 +15,7 @@ export class YulVariableAssignmentStatement extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ path.call(print, 'names'), ' ', diff --git a/src/slang-nodes/YulVariableDeclarationStatement.js b/src/slang-nodes/YulVariableDeclarationStatement.js index 34ba10439..400ed83ea 100644 --- a/src/slang-nodes/YulVariableDeclarationStatement.js +++ b/src/slang-nodes/YulVariableDeclarationStatement.js @@ -17,7 +17,7 @@ export class YulVariableDeclarationStatement extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ `${this.letKeyword} ${this.names} `, this.value ? path.call(print, 'value') : '' diff --git a/src/slang-nodes/YulVariableDeclarationValue.js b/src/slang-nodes/YulVariableDeclarationValue.js index d59c8bb03..4ab935294 100644 --- a/src/slang-nodes/YulVariableDeclarationValue.js +++ b/src/slang-nodes/YulVariableDeclarationValue.js @@ -12,7 +12,7 @@ export class YulVariableDeclarationValue extends SlangNode { this.initiateLoc(ast); } - print({ path, print }) { + print(path, print) { return [ path.call(print, 'assignment'), ' ', diff --git a/src/slangPrinter.js b/src/slangPrinter.js index 4a6e64654..94c5b73b4 100644 --- a/src/slangPrinter.js +++ b/src/slangPrinter.js @@ -40,7 +40,7 @@ function genericPrint(path, options, print) { } let ret; try { - ret = node.print({ options, path, print }); + ret = node.print(path, print, options); if (typeof ret === 'undefined') { console.log(nodeType); } From 3902bfe0f990ff9759df639067ade797cdf909af Mon Sep 17 00:00:00 2001 From: Klaus Date: Sun, 14 Jul 2024 02:19:54 +1200 Subject: [PATCH 067/160] reordering parameter order so they can safely be removed if not needed --- src/slang-nodes/ABICoderPragma.js | 2 +- src/slang-nodes/AdditiveExpression.js | 2 +- src/slang-nodes/AddressType.js | 2 +- src/slang-nodes/AndExpression.js | 2 +- src/slang-nodes/ArgumentsDeclaration.js | 2 +- src/slang-nodes/ArrayExpression.js | 2 +- src/slang-nodes/ArrayTypeName.js | 2 +- src/slang-nodes/ArrayValues.js | 2 +- src/slang-nodes/AssemblyFlags.js | 2 +- src/slang-nodes/AssemblyFlagsDeclaration.js | 2 +- src/slang-nodes/AssemblyStatement.js | 2 +- src/slang-nodes/AssignmentExpression.js | 2 +- src/slang-nodes/BitwiseAndExpression.js | 2 +- src/slang-nodes/BitwiseOrExpression.js | 2 +- src/slang-nodes/BitwiseXorExpression.js | 2 +- src/slang-nodes/Block.js | 2 +- src/slang-nodes/BreakStatement.js | 2 +- src/slang-nodes/CallOptions.js | 2 +- src/slang-nodes/CallOptionsExpression.js | 2 +- src/slang-nodes/CatchClause.js | 2 +- src/slang-nodes/CatchClauseError.js | 2 +- src/slang-nodes/CatchClauses.js | 2 +- src/slang-nodes/ComparisonExpression.js | 2 +- src/slang-nodes/ConditionalExpression.js | 2 +- src/slang-nodes/ConstantDefinition.js | 2 +- src/slang-nodes/ConstructorAttribute.js | 2 +- src/slang-nodes/ConstructorAttributes.js | 2 +- src/slang-nodes/ConstructorDefinition.js | 2 +- src/slang-nodes/ContinueStatement.js | 2 +- src/slang-nodes/ContractDefinition.js | 2 +- src/slang-nodes/ContractMember.js | 2 +- src/slang-nodes/ContractMembers.js | 2 +- src/slang-nodes/DecimalNumberExpression.js | 2 +- src/slang-nodes/DoWhileStatement.js | 2 +- src/slang-nodes/ElementaryType.js | 2 +- src/slang-nodes/ElseBranch.js | 2 +- src/slang-nodes/EmitStatement.js | 2 +- src/slang-nodes/EnumDefinition.js | 2 +- src/slang-nodes/EnumMembers.js | 2 +- src/slang-nodes/EqualityExpression.js | 2 +- src/slang-nodes/ErrorDefinition.js | 2 +- src/slang-nodes/ErrorParameter.js | 2 +- src/slang-nodes/ErrorParameters.js | 2 +- src/slang-nodes/ErrorParametersDeclaration.js | 2 +- src/slang-nodes/EventDefinition.js | 2 +- src/slang-nodes/EventParameter.js | 2 +- src/slang-nodes/EventParameters.js | 2 +- src/slang-nodes/EventParametersDeclaration.js | 2 +- src/slang-nodes/ExperimentalFeature.js | 4 ++-- src/slang-nodes/ExperimentalPragma.js | 5 +++-- src/slang-nodes/ExponentiationExpression.js | 2 +- src/slang-nodes/Expression.js | 2 +- src/slang-nodes/ExpressionStatement.js | 2 +- src/slang-nodes/FallbackFunctionAttribute.js | 2 +- src/slang-nodes/FallbackFunctionAttributes.js | 2 +- src/slang-nodes/FallbackFunctionDefinition.js | 2 +- src/slang-nodes/ForStatement.js | 2 +- src/slang-nodes/ForStatementCondition.js | 2 +- src/slang-nodes/ForStatementInitialization.js | 2 +- src/slang-nodes/FunctionAttribute.js | 2 +- src/slang-nodes/FunctionAttributes.js | 2 +- src/slang-nodes/FunctionBody.js | 2 +- src/slang-nodes/FunctionCallExpression.js | 2 +- src/slang-nodes/FunctionDefinition.js | 2 +- src/slang-nodes/FunctionName.js | 2 +- src/slang-nodes/FunctionType.js | 2 +- src/slang-nodes/FunctionTypeAttribute.js | 2 +- src/slang-nodes/FunctionTypeAttributes.js | 2 +- src/slang-nodes/HexNumberExpression.js | 2 +- src/slang-nodes/HexStringLiteral.js | 2 +- src/slang-nodes/HexStringLiterals.js | 2 +- src/slang-nodes/IdentifierPath.js | 2 +- src/slang-nodes/IfStatement.js | 2 +- src/slang-nodes/ImportAlias.js | 2 +- src/slang-nodes/ImportClause.js | 2 +- src/slang-nodes/ImportDeconstruction.js | 2 +- src/slang-nodes/ImportDeconstructionSymbol.js | 2 +- src/slang-nodes/ImportDeconstructionSymbols.js | 2 +- src/slang-nodes/ImportDirective.js | 2 +- src/slang-nodes/IndexAccessEnd.js | 2 +- src/slang-nodes/IndexAccessExpression.js | 2 +- src/slang-nodes/InheritanceSpecifier.js | 2 +- src/slang-nodes/InheritanceType.js | 2 +- src/slang-nodes/InheritanceTypes.js | 2 +- src/slang-nodes/InterfaceDefinition.js | 2 +- src/slang-nodes/InterfaceMembers.js | 2 +- src/slang-nodes/LibraryDefinition.js | 2 +- src/slang-nodes/LibraryMembers.js | 2 +- src/slang-nodes/MappingKey.js | 2 +- src/slang-nodes/MappingKeyType.js | 2 +- src/slang-nodes/MappingType.js | 2 +- src/slang-nodes/MappingValue.js | 2 +- src/slang-nodes/MemberAccess.js | 2 +- src/slang-nodes/MemberAccessExpression.js | 2 +- src/slang-nodes/ModifierAttribute.js | 2 +- src/slang-nodes/ModifierAttributes.js | 2 +- src/slang-nodes/ModifierDefinition.js | 2 +- src/slang-nodes/ModifierInvocation.js | 2 +- src/slang-nodes/MultiplicativeExpression.js | 2 +- src/slang-nodes/NamedArgument.js | 2 +- src/slang-nodes/NamedArgumentGroup.js | 2 +- src/slang-nodes/NamedArguments.js | 2 +- src/slang-nodes/NamedArgumentsDeclaration.js | 2 +- src/slang-nodes/NamedImport.js | 2 +- src/slang-nodes/NewExpression.js | 2 +- src/slang-nodes/NumberUnit.js | 2 +- src/slang-nodes/OrExpression.js | 2 +- src/slang-nodes/OverridePaths.js | 2 +- src/slang-nodes/OverridePathsDeclaration.js | 2 +- src/slang-nodes/OverrideSpecifier.js | 2 +- src/slang-nodes/Parameter.js | 2 +- src/slang-nodes/Parameters.js | 2 +- src/slang-nodes/ParametersDeclaration.js | 2 +- src/slang-nodes/PathImport.js | 2 +- src/slang-nodes/PositionalArguments.js | 2 +- src/slang-nodes/PositionalArgumentsDeclaration.js | 2 +- src/slang-nodes/PostfixExpression.js | 2 +- src/slang-nodes/Pragma.js | 6 +++--- src/slang-nodes/PragmaDirective.js | 4 ++-- src/slang-nodes/PrefixExpression.js | 2 +- src/slang-nodes/ReceiveFunctionAttribute.js | 2 +- src/slang-nodes/ReceiveFunctionAttributes.js | 2 +- src/slang-nodes/ReceiveFunctionDefinition.js | 2 +- src/slang-nodes/ReturnStatement.js | 2 +- src/slang-nodes/ReturnsDeclaration.js | 2 +- src/slang-nodes/RevertStatement.js | 2 +- src/slang-nodes/ShiftExpression.js | 2 +- src/slang-nodes/SourceUnit.js | 6 +++--- src/slang-nodes/SourceUnitMember.js | 6 +++--- src/slang-nodes/SourceUnitMembers.js | 4 ++-- src/slang-nodes/StateVariableAttribute.js | 2 +- src/slang-nodes/StateVariableAttributes.js | 2 +- src/slang-nodes/StateVariableDefinition.js | 2 +- src/slang-nodes/StateVariableDefinitionValue.js | 2 +- src/slang-nodes/Statement.js | 2 +- src/slang-nodes/Statements.js | 2 +- src/slang-nodes/StorageLocation.js | 2 +- src/slang-nodes/StringExpression.js | 2 +- src/slang-nodes/StringLiteral.js | 2 +- src/slang-nodes/StringLiterals.js | 2 +- src/slang-nodes/StructDefinition.js | 2 +- src/slang-nodes/StructMember.js | 2 +- src/slang-nodes/StructMembers.js | 2 +- src/slang-nodes/ThrowStatement.js | 2 +- src/slang-nodes/TryStatement.js | 2 +- src/slang-nodes/TupleDeconstructionElement.js | 2 +- src/slang-nodes/TupleDeconstructionElements.js | 2 +- src/slang-nodes/TupleDeconstructionStatement.js | 2 +- src/slang-nodes/TupleExpression.js | 2 +- src/slang-nodes/TupleMember.js | 2 +- src/slang-nodes/TupleValue.js | 2 +- src/slang-nodes/TupleValues.js | 2 +- src/slang-nodes/TypeExpression.js | 2 +- src/slang-nodes/TypeName.js | 2 +- src/slang-nodes/TypedTupleMember.js | 2 +- src/slang-nodes/UncheckedBlock.js | 2 +- src/slang-nodes/UnicodeStringLiteral.js | 2 +- src/slang-nodes/UnicodeStringLiterals.js | 2 +- src/slang-nodes/UnnamedFunctionAttribute.js | 2 +- src/slang-nodes/UnnamedFunctionAttributes.js | 2 +- src/slang-nodes/UnnamedFunctionDefinition.js | 2 +- src/slang-nodes/UntypedTupleMember.js | 2 +- src/slang-nodes/UserDefinedValueTypeDefinition.js | 2 +- src/slang-nodes/UsingAlias.js | 2 +- src/slang-nodes/UsingClause.js | 2 +- src/slang-nodes/UsingDeconstruction.js | 2 +- src/slang-nodes/UsingDeconstructionSymbol.js | 2 +- src/slang-nodes/UsingDeconstructionSymbols.js | 2 +- src/slang-nodes/UsingDirective.js | 2 +- src/slang-nodes/UsingOperator.js | 2 +- src/slang-nodes/UsingTarget.js | 2 +- src/slang-nodes/VariableDeclarationStatement.js | 2 +- src/slang-nodes/VariableDeclarationType.js | 2 +- src/slang-nodes/VariableDeclarationValue.js | 2 +- src/slang-nodes/VersionComparator.js | 2 +- src/slang-nodes/VersionExpression.js | 2 +- src/slang-nodes/VersionExpressionSet.js | 2 +- src/slang-nodes/VersionExpressionSets.js | 2 +- src/slang-nodes/VersionPragma.js | 2 +- src/slang-nodes/VersionRange.js | 2 +- src/slang-nodes/VersionSpecifiers.js | 2 +- src/slang-nodes/WhileStatement.js | 2 +- src/slang-nodes/YulArguments.js | 2 +- src/slang-nodes/YulAssignmentOperator.js | 2 +- src/slang-nodes/YulAssignmentStatement.js | 2 +- src/slang-nodes/YulBlock.js | 2 +- src/slang-nodes/YulBreakStatement.js | 2 +- src/slang-nodes/YulBuiltInFunction.js | 2 +- src/slang-nodes/YulColonAndEqual.js | 2 +- src/slang-nodes/YulContinueStatement.js | 2 +- src/slang-nodes/YulDefaultCase.js | 2 +- src/slang-nodes/YulExpression.js | 2 +- src/slang-nodes/YulForStatement.js | 2 +- src/slang-nodes/YulFunctionCallExpression.js | 2 +- src/slang-nodes/YulFunctionDefinition.js | 2 +- src/slang-nodes/YulIfStatement.js | 2 +- src/slang-nodes/YulLabel.js | 2 +- src/slang-nodes/YulLeaveStatement.js | 2 +- src/slang-nodes/YulLiteral.js | 2 +- src/slang-nodes/YulParameters.js | 2 +- src/slang-nodes/YulParametersDeclaration.js | 2 +- src/slang-nodes/YulPath.js | 2 +- src/slang-nodes/YulPathComponent.js | 2 +- src/slang-nodes/YulPaths.js | 2 +- src/slang-nodes/YulReturnVariables.js | 2 +- src/slang-nodes/YulReturnsDeclaration.js | 2 +- src/slang-nodes/YulStatement.js | 2 +- src/slang-nodes/YulStatements.js | 2 +- src/slang-nodes/YulSwitchCase.js | 2 +- src/slang-nodes/YulSwitchCases.js | 2 +- src/slang-nodes/YulSwitchStatement.js | 2 +- src/slang-nodes/YulValueCase.js | 2 +- src/slang-nodes/YulVariableAssignmentStatement.js | 2 +- src/slang-nodes/YulVariableDeclarationStatement.js | 2 +- src/slang-nodes/YulVariableDeclarationValue.js | 2 +- src/slangParser.js | 2 +- 216 files changed, 227 insertions(+), 226 deletions(-) diff --git a/src/slang-nodes/ABICoderPragma.js b/src/slang-nodes/ABICoderPragma.js index f4b577b43..868d4e85d 100644 --- a/src/slang-nodes/ABICoderPragma.js +++ b/src/slang-nodes/ABICoderPragma.js @@ -5,7 +5,7 @@ export class ABICoderPragma extends SlangNode { version; - constructor(ast, offset, parse, options) { + constructor(ast, offset) { super(ast, offset); this.abicoderKeyword = ast.abicoderKeyword.text; this.version = ast.version.text; diff --git a/src/slang-nodes/AdditiveExpression.js b/src/slang-nodes/AdditiveExpression.js index e6cafb191..f8ce0d5d5 100644 --- a/src/slang-nodes/AdditiveExpression.js +++ b/src/slang-nodes/AdditiveExpression.js @@ -11,7 +11,7 @@ export class AdditiveExpression extends SlangNode { rightOperand; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.leftOperand = tryToHug( parse(ast.leftOperand, parse, this.nextChildOffset) diff --git a/src/slang-nodes/AddressType.js b/src/slang-nodes/AddressType.js index 8bcf5919c..670be207d 100644 --- a/src/slang-nodes/AddressType.js +++ b/src/slang-nodes/AddressType.js @@ -5,7 +5,7 @@ export class AddressType extends SlangNode { payableKeyword; - constructor(ast, offset, parse, options) { + constructor(ast, offset) { super(ast, offset); this.addressKeyword = ast.addressKeyword.text; this.payableKeyword = ast.payableKeyword?.text; diff --git a/src/slang-nodes/AndExpression.js b/src/slang-nodes/AndExpression.js index 397004d7d..faca0d3b7 100644 --- a/src/slang-nodes/AndExpression.js +++ b/src/slang-nodes/AndExpression.js @@ -8,7 +8,7 @@ export class AndExpression extends SlangNode { rightOperand; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.leftOperand = parse(ast.leftOperand, parse, this.nextChildOffset); this.operator = ast.operator.text; diff --git a/src/slang-nodes/ArgumentsDeclaration.js b/src/slang-nodes/ArgumentsDeclaration.js index 214a2e2cb..57fdb376c 100644 --- a/src/slang-nodes/ArgumentsDeclaration.js +++ b/src/slang-nodes/ArgumentsDeclaration.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class ArgumentsDeclaration extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.variant = parse(ast.variant, parse, this.nextChildOffset); this.initiateLoc(ast); diff --git a/src/slang-nodes/ArrayExpression.js b/src/slang-nodes/ArrayExpression.js index fcb3fc108..0a12ef40d 100644 --- a/src/slang-nodes/ArrayExpression.js +++ b/src/slang-nodes/ArrayExpression.js @@ -10,7 +10,7 @@ export class ArrayExpression extends SlangNode { closeBracket; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.openBracket = ast.openBracket.text; this.items = parse(ast.items, parse, this.nextChildOffset); diff --git a/src/slang-nodes/ArrayTypeName.js b/src/slang-nodes/ArrayTypeName.js index ef9591dcd..0c24a25a6 100644 --- a/src/slang-nodes/ArrayTypeName.js +++ b/src/slang-nodes/ArrayTypeName.js @@ -9,7 +9,7 @@ export class ArrayTypeName extends SlangNode { closeBracket; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.operand = parse(ast.operand, parse, this.nextChildOffset); this.openBracket = ast.openBracket.text; diff --git a/src/slang-nodes/ArrayValues.js b/src/slang-nodes/ArrayValues.js index 88276fe70..a967d7872 100644 --- a/src/slang-nodes/ArrayValues.js +++ b/src/slang-nodes/ArrayValues.js @@ -6,7 +6,7 @@ export class ArrayValues extends SlangNode { separators; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/AssemblyFlags.js b/src/slang-nodes/AssemblyFlags.js index 4d7c6e73d..d0d2743d2 100644 --- a/src/slang-nodes/AssemblyFlags.js +++ b/src/slang-nodes/AssemblyFlags.js @@ -6,7 +6,7 @@ export class AssemblyFlags extends SlangNode { separators; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/AssemblyFlagsDeclaration.js b/src/slang-nodes/AssemblyFlagsDeclaration.js index f48ac709e..2e1b53942 100644 --- a/src/slang-nodes/AssemblyFlagsDeclaration.js +++ b/src/slang-nodes/AssemblyFlagsDeclaration.js @@ -7,7 +7,7 @@ export class AssemblyFlagsDeclaration extends SlangNode { closeParen; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.openParen = ast.openParen.text; this.flags = parse(ast.flags, parse, this.nextChildOffset); diff --git a/src/slang-nodes/AssemblyStatement.js b/src/slang-nodes/AssemblyStatement.js index d6e5bdf10..6a9c786c5 100644 --- a/src/slang-nodes/AssemblyStatement.js +++ b/src/slang-nodes/AssemblyStatement.js @@ -9,7 +9,7 @@ export class AssemblyStatement extends SlangNode { body; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.assemblyKeyword = ast.assemblyKeyword.text; this.label = ast.label diff --git a/src/slang-nodes/AssignmentExpression.js b/src/slang-nodes/AssignmentExpression.js index ba1156323..6ff7127cc 100644 --- a/src/slang-nodes/AssignmentExpression.js +++ b/src/slang-nodes/AssignmentExpression.js @@ -11,7 +11,7 @@ export class AssignmentExpression extends SlangNode { rightOperand; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.leftOperand = parse(ast.leftOperand, parse, this.nextChildOffset); this.operator = ast.operator.text; diff --git a/src/slang-nodes/BitwiseAndExpression.js b/src/slang-nodes/BitwiseAndExpression.js index a10aff3be..4a23e6d3b 100644 --- a/src/slang-nodes/BitwiseAndExpression.js +++ b/src/slang-nodes/BitwiseAndExpression.js @@ -11,7 +11,7 @@ export class BitwiseAndExpression extends SlangNode { rightOperand; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.leftOperand = tryToHug( parse(ast.leftOperand, parse, this.nextChildOffset) diff --git a/src/slang-nodes/BitwiseOrExpression.js b/src/slang-nodes/BitwiseOrExpression.js index 2762c281b..ee1d3fb38 100644 --- a/src/slang-nodes/BitwiseOrExpression.js +++ b/src/slang-nodes/BitwiseOrExpression.js @@ -21,7 +21,7 @@ export class BitwiseOrExpression extends SlangNode { rightOperand; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.leftOperand = tryToHug( parse(ast.leftOperand, parse, this.nextChildOffset) diff --git a/src/slang-nodes/BitwiseXorExpression.js b/src/slang-nodes/BitwiseXorExpression.js index 4b282e0e5..8d3b18d2b 100644 --- a/src/slang-nodes/BitwiseXorExpression.js +++ b/src/slang-nodes/BitwiseXorExpression.js @@ -11,7 +11,7 @@ export class BitwiseXorExpression extends SlangNode { rightOperand; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.leftOperand = tryToHug( parse(ast.leftOperand, parse, this.nextChildOffset) diff --git a/src/slang-nodes/Block.js b/src/slang-nodes/Block.js index e29886656..6e8b7debc 100644 --- a/src/slang-nodes/Block.js +++ b/src/slang-nodes/Block.js @@ -7,7 +7,7 @@ export class Block extends SlangNode { closeBrace; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.openBrace = ast.openBrace.text; this.statements = parse(ast.statements, parse, this.nextChildOffset); diff --git a/src/slang-nodes/BreakStatement.js b/src/slang-nodes/BreakStatement.js index bb119408c..be3e1d179 100644 --- a/src/slang-nodes/BreakStatement.js +++ b/src/slang-nodes/BreakStatement.js @@ -5,7 +5,7 @@ export class BreakStatement extends SlangNode { semicolon; - constructor(ast, offset, parse, options) { + constructor(ast, offset) { super(ast, offset); this.breakKeyword = ast.breakKeyword.text; this.semicolon = ast.semicolon.text; diff --git a/src/slang-nodes/CallOptions.js b/src/slang-nodes/CallOptions.js index 8519b0a5b..90690c7f4 100644 --- a/src/slang-nodes/CallOptions.js +++ b/src/slang-nodes/CallOptions.js @@ -9,7 +9,7 @@ export class CallOptions extends SlangNode { separators; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/CallOptionsExpression.js b/src/slang-nodes/CallOptionsExpression.js index c477d5943..e999dd5f5 100644 --- a/src/slang-nodes/CallOptionsExpression.js +++ b/src/slang-nodes/CallOptionsExpression.js @@ -9,7 +9,7 @@ export class CallOptionsExpression extends SlangNode { closeBrace; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.operand = parse(ast.operand, parse, this.nextChildOffset); this.openBrace = ast.openBrace.text; diff --git a/src/slang-nodes/CatchClause.js b/src/slang-nodes/CatchClause.js index f5c7b64b1..0bfe834f4 100644 --- a/src/slang-nodes/CatchClause.js +++ b/src/slang-nodes/CatchClause.js @@ -7,7 +7,7 @@ export class CatchClause extends SlangNode { body; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.catchKeyword = ast.catchKeyword.text; this.error = ast.error diff --git a/src/slang-nodes/CatchClauseError.js b/src/slang-nodes/CatchClauseError.js index 51681dc72..c3fab705d 100644 --- a/src/slang-nodes/CatchClauseError.js +++ b/src/slang-nodes/CatchClauseError.js @@ -8,7 +8,7 @@ export class CatchClauseError extends SlangNode { parameters; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.name = ast.name?.text ?? ''; this.parameters = parse(ast.parameters, parse, this.nextChildOffset); diff --git a/src/slang-nodes/CatchClauses.js b/src/slang-nodes/CatchClauses.js index 1dd8cee54..2f29db1ef 100644 --- a/src/slang-nodes/CatchClauses.js +++ b/src/slang-nodes/CatchClauses.js @@ -6,7 +6,7 @@ const { join } = doc.builders; export class CatchClauses extends SlangNode { items; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/ComparisonExpression.js b/src/slang-nodes/ComparisonExpression.js index 1a4e3a6bc..6def23b09 100644 --- a/src/slang-nodes/ComparisonExpression.js +++ b/src/slang-nodes/ComparisonExpression.js @@ -8,7 +8,7 @@ export class ComparisonExpression extends SlangNode { rightOperand; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.leftOperand = parse(ast.leftOperand, parse, this.nextChildOffset); this.operator = ast.operator.text; diff --git a/src/slang-nodes/ConditionalExpression.js b/src/slang-nodes/ConditionalExpression.js index e0c0a5936..74eafec2a 100644 --- a/src/slang-nodes/ConditionalExpression.js +++ b/src/slang-nodes/ConditionalExpression.js @@ -97,7 +97,7 @@ export class ConditionalExpression extends SlangNode { falseExpression; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.operand = parse(ast.operand, parse, this.nextChildOffset); diff --git a/src/slang-nodes/ConstantDefinition.js b/src/slang-nodes/ConstantDefinition.js index ffb70741d..34d331fa5 100644 --- a/src/slang-nodes/ConstantDefinition.js +++ b/src/slang-nodes/ConstantDefinition.js @@ -13,7 +13,7 @@ export class ConstantDefinition extends SlangNode { semicolon; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.typeName = parse(ast.typeName, parse, this.nextChildOffset); this.constantKeyword = ast.constantKeyword.text; diff --git a/src/slang-nodes/ConstructorAttribute.js b/src/slang-nodes/ConstructorAttribute.js index 149ab5ec9..fd720bd3a 100644 --- a/src/slang-nodes/ConstructorAttribute.js +++ b/src/slang-nodes/ConstructorAttribute.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class ConstructorAttribute extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.variant = ast.variant.type === 'Terminal' diff --git a/src/slang-nodes/ConstructorAttributes.js b/src/slang-nodes/ConstructorAttributes.js index c6dcfe94b..ff6785fac 100644 --- a/src/slang-nodes/ConstructorAttributes.js +++ b/src/slang-nodes/ConstructorAttributes.js @@ -7,7 +7,7 @@ const { line } = doc.builders; export class ConstructorAttributes extends SlangNode { items; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items .map((item) => parse(item, parse, this.nextChildOffset)) diff --git a/src/slang-nodes/ConstructorDefinition.js b/src/slang-nodes/ConstructorDefinition.js index 75319f054..5d494fddc 100644 --- a/src/slang-nodes/ConstructorDefinition.js +++ b/src/slang-nodes/ConstructorDefinition.js @@ -10,7 +10,7 @@ export class ConstructorDefinition extends SlangNode { body; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.constructorKeyword = ast.constructorKeyword.text; this.parameters = parse(ast.parameters, parse, this.nextChildOffset); diff --git a/src/slang-nodes/ContinueStatement.js b/src/slang-nodes/ContinueStatement.js index a84e3d0dd..f93aa7f28 100644 --- a/src/slang-nodes/ContinueStatement.js +++ b/src/slang-nodes/ContinueStatement.js @@ -5,7 +5,7 @@ export class ContinueStatement extends SlangNode { semicolon; - constructor(ast, offset, parse, options) { + constructor(ast, offset) { super(ast, offset); this.continueKeyword = ast.continueKeyword.text; this.semicolon = ast.semicolon.text; diff --git a/src/slang-nodes/ContractDefinition.js b/src/slang-nodes/ContractDefinition.js index d792ca0cf..9af214640 100644 --- a/src/slang-nodes/ContractDefinition.js +++ b/src/slang-nodes/ContractDefinition.js @@ -18,7 +18,7 @@ export class ContractDefinition extends SlangNode { closeBrace; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.abstractKeyword = ast.abstractKeyword?.text; this.contractKeyword = ast.contractKeyword.text; diff --git a/src/slang-nodes/ContractMember.js b/src/slang-nodes/ContractMember.js index b3ba7e32e..d5687e85e 100644 --- a/src/slang-nodes/ContractMember.js +++ b/src/slang-nodes/ContractMember.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class ContractMember extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.variant = parse(ast.variant, parse, this.nextChildOffset); this.initiateLoc(ast); diff --git a/src/slang-nodes/ContractMembers.js b/src/slang-nodes/ContractMembers.js index 8efc6a0cf..1af44fe81 100644 --- a/src/slang-nodes/ContractMembers.js +++ b/src/slang-nodes/ContractMembers.js @@ -11,7 +11,7 @@ const { hardline } = doc.builders; export class ContractMembers extends SlangNode { items; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/DecimalNumberExpression.js b/src/slang-nodes/DecimalNumberExpression.js index 393f8d975..18d5d1e69 100644 --- a/src/slang-nodes/DecimalNumberExpression.js +++ b/src/slang-nodes/DecimalNumberExpression.js @@ -5,7 +5,7 @@ export class DecimalNumberExpression extends SlangNode { unit; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.literal = ast.literal.text; this.unit = ast.unit diff --git a/src/slang-nodes/DoWhileStatement.js b/src/slang-nodes/DoWhileStatement.js index ef0206cfb..7c27f23a0 100644 --- a/src/slang-nodes/DoWhileStatement.js +++ b/src/slang-nodes/DoWhileStatement.js @@ -24,7 +24,7 @@ export class DoWhileStatement extends SlangNode { semicolon; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.doKeyword = ast.doKeyword.text; this.body = parse(ast.body, parse, this.nextChildOffset); diff --git a/src/slang-nodes/ElementaryType.js b/src/slang-nodes/ElementaryType.js index 2680d9f9d..2b7a9d337 100644 --- a/src/slang-nodes/ElementaryType.js +++ b/src/slang-nodes/ElementaryType.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class ElementaryType extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.variant = ast.variant.type === 'Terminal' diff --git a/src/slang-nodes/ElseBranch.js b/src/slang-nodes/ElseBranch.js index 7041d1045..26ce5266d 100644 --- a/src/slang-nodes/ElseBranch.js +++ b/src/slang-nodes/ElseBranch.js @@ -13,7 +13,7 @@ export class ElseBranch extends SlangNode { body; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.elseKeyword = ast.elseKeyword.text; this.body = parse(ast.body, parse, this.nextChildOffset); diff --git a/src/slang-nodes/EmitStatement.js b/src/slang-nodes/EmitStatement.js index 33832a00d..991957aa2 100644 --- a/src/slang-nodes/EmitStatement.js +++ b/src/slang-nodes/EmitStatement.js @@ -9,7 +9,7 @@ export class EmitStatement extends SlangNode { semicolon; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.emitKeyword = ast.emitKeyword.text; this.event = parse(ast.event, parse, this.nextChildOffset); diff --git a/src/slang-nodes/EnumDefinition.js b/src/slang-nodes/EnumDefinition.js index e3a871ecc..b4b77cbfa 100644 --- a/src/slang-nodes/EnumDefinition.js +++ b/src/slang-nodes/EnumDefinition.js @@ -11,7 +11,7 @@ export class EnumDefinition extends SlangNode { closeBrace; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.enumKeyword = ast.enumKeyword.text; this.name = ast.name.text; diff --git a/src/slang-nodes/EnumMembers.js b/src/slang-nodes/EnumMembers.js index 6d01cef29..5986345dd 100644 --- a/src/slang-nodes/EnumMembers.js +++ b/src/slang-nodes/EnumMembers.js @@ -9,7 +9,7 @@ export class EnumMembers extends SlangNode { separators; - constructor(ast, offset, parse, options) { + constructor(ast, offset) { super(ast, offset); this.items = ast.items.map((item) => item.text); this.separators = ast.separators.map((separator) => separator.text); diff --git a/src/slang-nodes/EqualityExpression.js b/src/slang-nodes/EqualityExpression.js index a83f7bfd3..b8667cf0c 100644 --- a/src/slang-nodes/EqualityExpression.js +++ b/src/slang-nodes/EqualityExpression.js @@ -8,7 +8,7 @@ export class EqualityExpression extends SlangNode { rightOperand; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.leftOperand = parse(ast.leftOperand, parse, this.nextChildOffset); this.operator = ast.operator.text; diff --git a/src/slang-nodes/ErrorDefinition.js b/src/slang-nodes/ErrorDefinition.js index 97f5630c1..aa6384d33 100644 --- a/src/slang-nodes/ErrorDefinition.js +++ b/src/slang-nodes/ErrorDefinition.js @@ -9,7 +9,7 @@ export class ErrorDefinition extends SlangNode { semicolon; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.errorKeyword = ast.errorKeyword.text; this.name = ast.name.text; diff --git a/src/slang-nodes/ErrorParameter.js b/src/slang-nodes/ErrorParameter.js index dbe08b255..c6a29d00b 100644 --- a/src/slang-nodes/ErrorParameter.js +++ b/src/slang-nodes/ErrorParameter.js @@ -9,7 +9,7 @@ export class ErrorParameter extends SlangNode { semicolon; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.typeName = parse(ast.typeName, parse, this.nextChildOffset); this.name = ast.name?.text; diff --git a/src/slang-nodes/ErrorParameters.js b/src/slang-nodes/ErrorParameters.js index 25d9dec9b..3658df411 100644 --- a/src/slang-nodes/ErrorParameters.js +++ b/src/slang-nodes/ErrorParameters.js @@ -6,7 +6,7 @@ export class ErrorParameters extends SlangNode { separators; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/ErrorParametersDeclaration.js b/src/slang-nodes/ErrorParametersDeclaration.js index 30faba6ba..ddd001f79 100644 --- a/src/slang-nodes/ErrorParametersDeclaration.js +++ b/src/slang-nodes/ErrorParametersDeclaration.js @@ -7,7 +7,7 @@ export class ErrorParametersDeclaration extends SlangNode { closeParen; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.openParen = ast.openParen.text; this.parameters = parse(ast.parameters, parse, this.nextChildOffset); diff --git a/src/slang-nodes/EventDefinition.js b/src/slang-nodes/EventDefinition.js index 02d2aff9b..fa47eb435 100644 --- a/src/slang-nodes/EventDefinition.js +++ b/src/slang-nodes/EventDefinition.js @@ -11,7 +11,7 @@ export class EventDefinition extends SlangNode { semicolon; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.eventKeyword = ast.eventKeyword.text; this.name = ast.name.text; diff --git a/src/slang-nodes/EventParameter.js b/src/slang-nodes/EventParameter.js index 730a7c6ec..a2c5cddb7 100644 --- a/src/slang-nodes/EventParameter.js +++ b/src/slang-nodes/EventParameter.js @@ -7,7 +7,7 @@ export class EventParameter extends SlangNode { name; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.typeName = parse(ast.typeName, parse, this.nextChildOffset); this.indexedKeyword = ast.indexedKeyword?.text; diff --git a/src/slang-nodes/EventParameters.js b/src/slang-nodes/EventParameters.js index d28fc963f..65b91ae9a 100644 --- a/src/slang-nodes/EventParameters.js +++ b/src/slang-nodes/EventParameters.js @@ -6,7 +6,7 @@ export class EventParameters extends SlangNode { separators; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/EventParametersDeclaration.js b/src/slang-nodes/EventParametersDeclaration.js index a7bfe98c2..9648c0ac1 100644 --- a/src/slang-nodes/EventParametersDeclaration.js +++ b/src/slang-nodes/EventParametersDeclaration.js @@ -7,7 +7,7 @@ export class EventParametersDeclaration extends SlangNode { closeParen; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.openParen = ast.openParen.text; this.parameters = parse(ast.parameters, parse, this.nextChildOffset); diff --git a/src/slang-nodes/ExperimentalFeature.js b/src/slang-nodes/ExperimentalFeature.js index 8a81ecafb..ed671bf0a 100644 --- a/src/slang-nodes/ExperimentalFeature.js +++ b/src/slang-nodes/ExperimentalFeature.js @@ -4,12 +4,12 @@ import { StringLiteral } from './StringLiteral.js'; export class ExperimentalFeature extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : new StringLiteral(ast.variant, this.nextChildOffset, options); + : new StringLiteral(ast.variant, this.nextChildOffset, options, parse); this.initiateLoc(ast); } diff --git a/src/slang-nodes/ExperimentalPragma.js b/src/slang-nodes/ExperimentalPragma.js index 5bda847bb..ef316a28a 100644 --- a/src/slang-nodes/ExperimentalPragma.js +++ b/src/slang-nodes/ExperimentalPragma.js @@ -6,13 +6,14 @@ export class ExperimentalPragma extends SlangNode { feature; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.experimentalKeyword = ast.experimentalKeyword.text; this.feature = new ExperimentalFeature( ast.feature, this.nextChildOffset, - options + options, + parse ); this.initiateLoc(ast); } diff --git a/src/slang-nodes/ExponentiationExpression.js b/src/slang-nodes/ExponentiationExpression.js index da0194c51..46fec4144 100644 --- a/src/slang-nodes/ExponentiationExpression.js +++ b/src/slang-nodes/ExponentiationExpression.js @@ -25,7 +25,7 @@ export class ExponentiationExpression extends SlangNode { rightOperand; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); if (offset) { const compiler = coerce(options.compiler); diff --git a/src/slang-nodes/Expression.js b/src/slang-nodes/Expression.js index 408004eec..8cb2148dd 100644 --- a/src/slang-nodes/Expression.js +++ b/src/slang-nodes/Expression.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class Expression extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); if (offset) { this.variant = diff --git a/src/slang-nodes/ExpressionStatement.js b/src/slang-nodes/ExpressionStatement.js index 39c997276..1ba8ca676 100644 --- a/src/slang-nodes/ExpressionStatement.js +++ b/src/slang-nodes/ExpressionStatement.js @@ -5,7 +5,7 @@ export class ExpressionStatement extends SlangNode { semicolon; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.expression = parse(ast.expression, parse, this.nextChildOffset); this.semicolon = ast.semicolon.text; diff --git a/src/slang-nodes/FallbackFunctionAttribute.js b/src/slang-nodes/FallbackFunctionAttribute.js index e1b58da9e..46c6dc40a 100644 --- a/src/slang-nodes/FallbackFunctionAttribute.js +++ b/src/slang-nodes/FallbackFunctionAttribute.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class FallbackFunctionAttribute extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.variant = ast.variant.type === 'Terminal' diff --git a/src/slang-nodes/FallbackFunctionAttributes.js b/src/slang-nodes/FallbackFunctionAttributes.js index c5ae18392..0792e909f 100644 --- a/src/slang-nodes/FallbackFunctionAttributes.js +++ b/src/slang-nodes/FallbackFunctionAttributes.js @@ -7,7 +7,7 @@ const { line } = doc.builders; export class FallbackFunctionAttributes extends SlangNode { items; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items .map((item) => parse(item, parse, this.nextChildOffset)) diff --git a/src/slang-nodes/FallbackFunctionDefinition.js b/src/slang-nodes/FallbackFunctionDefinition.js index e4498c9eb..4e0116368 100644 --- a/src/slang-nodes/FallbackFunctionDefinition.js +++ b/src/slang-nodes/FallbackFunctionDefinition.js @@ -12,7 +12,7 @@ export class FallbackFunctionDefinition extends SlangNode { body; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.fallbackKeyword = ast.fallbackKeyword.text; this.parameters = parse(ast.parameters, parse, this.nextChildOffset); diff --git a/src/slang-nodes/ForStatement.js b/src/slang-nodes/ForStatement.js index 110edf63e..ffea49172 100644 --- a/src/slang-nodes/ForStatement.js +++ b/src/slang-nodes/ForStatement.js @@ -19,7 +19,7 @@ export class ForStatement extends SlangNode { body; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.forKeyword = ast.forKeyword.text; this.openParen = ast.openParen.text; diff --git a/src/slang-nodes/ForStatementCondition.js b/src/slang-nodes/ForStatementCondition.js index b3f5dff44..e09617795 100644 --- a/src/slang-nodes/ForStatementCondition.js +++ b/src/slang-nodes/ForStatementCondition.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class ForStatementCondition extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.variant = ast.variant.type === 'Terminal' diff --git a/src/slang-nodes/ForStatementInitialization.js b/src/slang-nodes/ForStatementInitialization.js index cfcf0e124..9ba60b979 100644 --- a/src/slang-nodes/ForStatementInitialization.js +++ b/src/slang-nodes/ForStatementInitialization.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class ForStatementInitialization extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.variant = ast.variant.type === 'Terminal' diff --git a/src/slang-nodes/FunctionAttribute.js b/src/slang-nodes/FunctionAttribute.js index ed24fb0c0..2b1381a87 100644 --- a/src/slang-nodes/FunctionAttribute.js +++ b/src/slang-nodes/FunctionAttribute.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class FunctionAttribute extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.variant = ast.variant.type === 'Terminal' diff --git a/src/slang-nodes/FunctionAttributes.js b/src/slang-nodes/FunctionAttributes.js index 0840190da..5ab9a3dd6 100644 --- a/src/slang-nodes/FunctionAttributes.js +++ b/src/slang-nodes/FunctionAttributes.js @@ -7,7 +7,7 @@ const { line } = doc.builders; export class FunctionAttributes extends SlangNode { items; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items .map((item) => parse(item, parse, this.nextChildOffset)) diff --git a/src/slang-nodes/FunctionBody.js b/src/slang-nodes/FunctionBody.js index 0900cff9a..0ed1d0614 100644 --- a/src/slang-nodes/FunctionBody.js +++ b/src/slang-nodes/FunctionBody.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class FunctionBody extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.variant = ast.variant.type === 'Terminal' diff --git a/src/slang-nodes/FunctionCallExpression.js b/src/slang-nodes/FunctionCallExpression.js index be524fdcf..c7ec89e69 100644 --- a/src/slang-nodes/FunctionCallExpression.js +++ b/src/slang-nodes/FunctionCallExpression.js @@ -11,7 +11,7 @@ export class FunctionCallExpression extends SlangNode { arguments; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.operand = parse(ast.operand, parse, this.nextChildOffset); this.arguments = parse(ast.arguments, parse, this.nextChildOffset); diff --git a/src/slang-nodes/FunctionDefinition.js b/src/slang-nodes/FunctionDefinition.js index f6ecdff5e..6c942af6b 100644 --- a/src/slang-nodes/FunctionDefinition.js +++ b/src/slang-nodes/FunctionDefinition.js @@ -14,7 +14,7 @@ export class FunctionDefinition extends SlangNode { body; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.functionKeyword = ast.functionKeyword.text; this.name = parse(ast.name, parse, this.nextChildOffset); diff --git a/src/slang-nodes/FunctionName.js b/src/slang-nodes/FunctionName.js index 2857c5223..2adc6e126 100644 --- a/src/slang-nodes/FunctionName.js +++ b/src/slang-nodes/FunctionName.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class FunctionName extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset) { super(ast, offset); this.variant = ast.variant.text; this.initiateLoc(ast); diff --git a/src/slang-nodes/FunctionType.js b/src/slang-nodes/FunctionType.js index 60054f5f3..693901caf 100644 --- a/src/slang-nodes/FunctionType.js +++ b/src/slang-nodes/FunctionType.js @@ -10,7 +10,7 @@ export class FunctionType extends SlangNode { returns; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.functionKeyword = ast.functionKeyword.text; this.parameters = parse(ast.parameters, parse, this.nextChildOffset); diff --git a/src/slang-nodes/FunctionTypeAttribute.js b/src/slang-nodes/FunctionTypeAttribute.js index 381f8e93f..928e1e21e 100644 --- a/src/slang-nodes/FunctionTypeAttribute.js +++ b/src/slang-nodes/FunctionTypeAttribute.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class FunctionTypeAttribute extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset) { super(ast, offset); this.variant = ast.variant.text; this.initiateLoc(ast); diff --git a/src/slang-nodes/FunctionTypeAttributes.js b/src/slang-nodes/FunctionTypeAttributes.js index 8c62cb164..3e9b2f79f 100644 --- a/src/slang-nodes/FunctionTypeAttributes.js +++ b/src/slang-nodes/FunctionTypeAttributes.js @@ -7,7 +7,7 @@ const { line } = doc.builders; export class FunctionTypeAttributes extends SlangNode { items; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items .map((item) => parse(item, parse, this.nextChildOffset)) diff --git a/src/slang-nodes/HexNumberExpression.js b/src/slang-nodes/HexNumberExpression.js index 62a9b34f2..be6cb1142 100644 --- a/src/slang-nodes/HexNumberExpression.js +++ b/src/slang-nodes/HexNumberExpression.js @@ -5,7 +5,7 @@ export class HexNumberExpression extends SlangNode { unit; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.literal = ast.literal.text; this.unit = ast.unit diff --git a/src/slang-nodes/HexStringLiteral.js b/src/slang-nodes/HexStringLiteral.js index 0c07153f0..cc8e63ede 100644 --- a/src/slang-nodes/HexStringLiteral.js +++ b/src/slang-nodes/HexStringLiteral.js @@ -4,7 +4,7 @@ import { SlangNode } from './SlangNode.js'; export class HexStringLiteral extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options) { super(ast, offset); this.variant = `hex${printString(ast.variant.text.slice(4, -1), options)}`; this.initiateLoc(ast); diff --git a/src/slang-nodes/HexStringLiterals.js b/src/slang-nodes/HexStringLiterals.js index 2c396344d..3988b875c 100644 --- a/src/slang-nodes/HexStringLiterals.js +++ b/src/slang-nodes/HexStringLiterals.js @@ -6,7 +6,7 @@ const { join, hardline } = doc.builders; export class HexStringLiterals extends SlangNode { items; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/IdentifierPath.js b/src/slang-nodes/IdentifierPath.js index eb6e05c88..d4359c37b 100644 --- a/src/slang-nodes/IdentifierPath.js +++ b/src/slang-nodes/IdentifierPath.js @@ -5,7 +5,7 @@ export class IdentifierPath extends SlangNode { separators; - constructor(ast, offset, parse, options) { + constructor(ast, offset) { super(ast, offset); this.items = ast.items.map((item) => item.text); this.separators = ast.separators.map((separator) => separator.text); diff --git a/src/slang-nodes/IfStatement.js b/src/slang-nodes/IfStatement.js index 6cb023eed..0ce8538e4 100644 --- a/src/slang-nodes/IfStatement.js +++ b/src/slang-nodes/IfStatement.js @@ -24,7 +24,7 @@ export class IfStatement extends SlangNode { elseBranch; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.ifKeyword = ast.ifKeyword.text; this.openParen = ast.openParen.text; diff --git a/src/slang-nodes/ImportAlias.js b/src/slang-nodes/ImportAlias.js index d136a6461..f0ad38366 100644 --- a/src/slang-nodes/ImportAlias.js +++ b/src/slang-nodes/ImportAlias.js @@ -5,7 +5,7 @@ export class ImportAlias extends SlangNode { identifier; - constructor(ast, offset, parse, options) { + constructor(ast, offset) { super(ast, offset); this.asKeyword = ast.asKeyword.text; this.identifier = ast.identifier.text; diff --git a/src/slang-nodes/ImportClause.js b/src/slang-nodes/ImportClause.js index d32fb2b2e..68419fcc7 100644 --- a/src/slang-nodes/ImportClause.js +++ b/src/slang-nodes/ImportClause.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class ImportClause extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.variant = parse(ast.variant, parse, this.nextChildOffset); this.initiateLoc(ast); diff --git a/src/slang-nodes/ImportDeconstruction.js b/src/slang-nodes/ImportDeconstruction.js index c58f089e8..115bc5df7 100644 --- a/src/slang-nodes/ImportDeconstruction.js +++ b/src/slang-nodes/ImportDeconstruction.js @@ -11,7 +11,7 @@ export class ImportDeconstruction extends SlangNode { path; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.openBrace = ast.openBrace.text; this.symbols = parse(ast.symbols, parse, this.nextChildOffset); diff --git a/src/slang-nodes/ImportDeconstructionSymbol.js b/src/slang-nodes/ImportDeconstructionSymbol.js index 4506ff392..7e0aede70 100644 --- a/src/slang-nodes/ImportDeconstructionSymbol.js +++ b/src/slang-nodes/ImportDeconstructionSymbol.js @@ -5,7 +5,7 @@ export class ImportDeconstructionSymbol extends SlangNode { alias; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.name = ast.name.text; this.alias = ast.alias diff --git a/src/slang-nodes/ImportDeconstructionSymbols.js b/src/slang-nodes/ImportDeconstructionSymbols.js index 0226470ec..5e4934330 100644 --- a/src/slang-nodes/ImportDeconstructionSymbols.js +++ b/src/slang-nodes/ImportDeconstructionSymbols.js @@ -11,7 +11,7 @@ export class ImportDeconstructionSymbols extends SlangNode { separators; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/ImportDirective.js b/src/slang-nodes/ImportDirective.js index 2d65e7e3b..b857ad3f4 100644 --- a/src/slang-nodes/ImportDirective.js +++ b/src/slang-nodes/ImportDirective.js @@ -7,7 +7,7 @@ export class ImportDirective extends SlangNode { semicolon; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.importKeyword = ast.importKeyword.text; this.clause = parse(ast.clause, parse, this.nextChildOffset); diff --git a/src/slang-nodes/IndexAccessEnd.js b/src/slang-nodes/IndexAccessEnd.js index 2815bfa08..a92a55f04 100644 --- a/src/slang-nodes/IndexAccessEnd.js +++ b/src/slang-nodes/IndexAccessEnd.js @@ -5,7 +5,7 @@ export class IndexAccessEnd extends SlangNode { end; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.colon = ast.colon.text; this.end = ast.end diff --git a/src/slang-nodes/IndexAccessExpression.js b/src/slang-nodes/IndexAccessExpression.js index 316dd15a5..50dc9aae2 100644 --- a/src/slang-nodes/IndexAccessExpression.js +++ b/src/slang-nodes/IndexAccessExpression.js @@ -17,7 +17,7 @@ export class IndexAccessExpression extends SlangNode { closeBracket; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.operand = parse(ast.operand, parse, this.nextChildOffset); this.openBracket = ast.openBracket.text; diff --git a/src/slang-nodes/InheritanceSpecifier.js b/src/slang-nodes/InheritanceSpecifier.js index 3b2859215..265a21a83 100644 --- a/src/slang-nodes/InheritanceSpecifier.js +++ b/src/slang-nodes/InheritanceSpecifier.js @@ -5,7 +5,7 @@ export class InheritanceSpecifier extends SlangNode { types; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.isKeyword = ast.isKeyword.text; this.types = parse(ast.types, parse, this.nextChildOffset); diff --git a/src/slang-nodes/InheritanceType.js b/src/slang-nodes/InheritanceType.js index 8148a5e7e..40ae0f85a 100644 --- a/src/slang-nodes/InheritanceType.js +++ b/src/slang-nodes/InheritanceType.js @@ -5,7 +5,7 @@ export class InheritanceType extends SlangNode { arguments; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.typeName = parse(ast.typeName, parse, this.nextChildOffset); this.arguments = ast.arguments diff --git a/src/slang-nodes/InheritanceTypes.js b/src/slang-nodes/InheritanceTypes.js index 491313ab3..da4a66e41 100644 --- a/src/slang-nodes/InheritanceTypes.js +++ b/src/slang-nodes/InheritanceTypes.js @@ -9,7 +9,7 @@ export class InheritanceTypes extends SlangNode { separators; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/InterfaceDefinition.js b/src/slang-nodes/InterfaceDefinition.js index ca225f4ab..cf2f9259c 100644 --- a/src/slang-nodes/InterfaceDefinition.js +++ b/src/slang-nodes/InterfaceDefinition.js @@ -16,7 +16,7 @@ export class InterfaceDefinition extends SlangNode { closeBrace; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.interfaceKeyword = ast.interfaceKeyword.text; this.name = ast.name.text; diff --git a/src/slang-nodes/InterfaceMembers.js b/src/slang-nodes/InterfaceMembers.js index 1eee103f5..71a2fe5dc 100644 --- a/src/slang-nodes/InterfaceMembers.js +++ b/src/slang-nodes/InterfaceMembers.js @@ -8,7 +8,7 @@ const { hardline } = doc.builders; export class InterfaceMembers extends SlangNode { items; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/LibraryDefinition.js b/src/slang-nodes/LibraryDefinition.js index 147cbcaed..257b2fe5f 100644 --- a/src/slang-nodes/LibraryDefinition.js +++ b/src/slang-nodes/LibraryDefinition.js @@ -14,7 +14,7 @@ export class LibraryDefinition extends SlangNode { closeBrace; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.libraryKeyword = ast.libraryKeyword.text; this.name = ast.name.text; diff --git a/src/slang-nodes/LibraryMembers.js b/src/slang-nodes/LibraryMembers.js index b578f2a8f..cbcb23459 100644 --- a/src/slang-nodes/LibraryMembers.js +++ b/src/slang-nodes/LibraryMembers.js @@ -8,7 +8,7 @@ const { hardline } = doc.builders; export class LibraryMembers extends SlangNode { items; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/MappingKey.js b/src/slang-nodes/MappingKey.js index a2fdf8ede..e45b90fef 100644 --- a/src/slang-nodes/MappingKey.js +++ b/src/slang-nodes/MappingKey.js @@ -5,7 +5,7 @@ export class MappingKey extends SlangNode { name; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.keyType = parse(ast.keyType, parse, this.nextChildOffset); this.name = ast.name?.text; diff --git a/src/slang-nodes/MappingKeyType.js b/src/slang-nodes/MappingKeyType.js index ce60f2fd4..e26a2a830 100644 --- a/src/slang-nodes/MappingKeyType.js +++ b/src/slang-nodes/MappingKeyType.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class MappingKeyType extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.variant = parse(ast.variant, parse, this.nextChildOffset); this.initiateLoc(ast); diff --git a/src/slang-nodes/MappingType.js b/src/slang-nodes/MappingType.js index a57817a46..83b9a6500 100644 --- a/src/slang-nodes/MappingType.js +++ b/src/slang-nodes/MappingType.js @@ -13,7 +13,7 @@ export class MappingType extends SlangNode { closeParen; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.mappingKeyword = ast.mappingKeyword.text; this.openParen = ast.openParen.text; diff --git a/src/slang-nodes/MappingValue.js b/src/slang-nodes/MappingValue.js index 5be330318..1ef7b3527 100644 --- a/src/slang-nodes/MappingValue.js +++ b/src/slang-nodes/MappingValue.js @@ -5,7 +5,7 @@ export class MappingValue extends SlangNode { name; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.typeName = parse(ast.typeName, parse, this.nextChildOffset); this.name = ast.name?.text; diff --git a/src/slang-nodes/MemberAccess.js b/src/slang-nodes/MemberAccess.js index fe2805dc7..fb2767ea0 100644 --- a/src/slang-nodes/MemberAccess.js +++ b/src/slang-nodes/MemberAccess.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class MemberAccess extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset) { super(ast, offset); this.variant = ast.variant.text; this.initiateLoc(ast); diff --git a/src/slang-nodes/MemberAccessExpression.js b/src/slang-nodes/MemberAccessExpression.js index b9b9601a9..93ca44c92 100644 --- a/src/slang-nodes/MemberAccessExpression.js +++ b/src/slang-nodes/MemberAccessExpression.js @@ -112,7 +112,7 @@ export class MemberAccessExpression extends SlangNode { member; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.operand = parse(ast.operand, parse, this.nextChildOffset); this.period = ast.period.text; diff --git a/src/slang-nodes/ModifierAttribute.js b/src/slang-nodes/ModifierAttribute.js index a145a28f7..b62bb5be9 100644 --- a/src/slang-nodes/ModifierAttribute.js +++ b/src/slang-nodes/ModifierAttribute.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class ModifierAttribute extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.variant = ast.variant.type === 'Terminal' diff --git a/src/slang-nodes/ModifierAttributes.js b/src/slang-nodes/ModifierAttributes.js index 2f877122a..c9f1ac280 100644 --- a/src/slang-nodes/ModifierAttributes.js +++ b/src/slang-nodes/ModifierAttributes.js @@ -7,7 +7,7 @@ const { line } = doc.builders; export class ModifierAttributes extends SlangNode { items; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items .map((item) => parse(item, parse, this.nextChildOffset)) diff --git a/src/slang-nodes/ModifierDefinition.js b/src/slang-nodes/ModifierDefinition.js index 167e09cd3..d04dd2d63 100644 --- a/src/slang-nodes/ModifierDefinition.js +++ b/src/slang-nodes/ModifierDefinition.js @@ -14,7 +14,7 @@ export class ModifierDefinition extends SlangNode { body; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.modifierKeyword = ast.modifierKeyword.text; this.name = ast.name.text; diff --git a/src/slang-nodes/ModifierInvocation.js b/src/slang-nodes/ModifierInvocation.js index 2255b70ce..d38488e46 100644 --- a/src/slang-nodes/ModifierInvocation.js +++ b/src/slang-nodes/ModifierInvocation.js @@ -6,7 +6,7 @@ export class ModifierInvocation extends SlangNode { arguments; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.name = parse(ast.name, parse, this.nextChildOffset); this.arguments = ast.arguments diff --git a/src/slang-nodes/MultiplicativeExpression.js b/src/slang-nodes/MultiplicativeExpression.js index 90919c63f..ab85e9a3f 100644 --- a/src/slang-nodes/MultiplicativeExpression.js +++ b/src/slang-nodes/MultiplicativeExpression.js @@ -13,7 +13,7 @@ export class MultiplicativeExpression extends SlangNode { rightOperand; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.leftOperand = parse(ast.leftOperand, parse, this.nextChildOffset); this.operator = ast.operator.text; diff --git a/src/slang-nodes/NamedArgument.js b/src/slang-nodes/NamedArgument.js index 2f310ba58..2b288c744 100644 --- a/src/slang-nodes/NamedArgument.js +++ b/src/slang-nodes/NamedArgument.js @@ -7,7 +7,7 @@ export class NamedArgument extends SlangNode { value; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.name = ast.name.text; this.colon = ast.colon.text; diff --git a/src/slang-nodes/NamedArgumentGroup.js b/src/slang-nodes/NamedArgumentGroup.js index 99a2f5c5d..3885f023f 100644 --- a/src/slang-nodes/NamedArgumentGroup.js +++ b/src/slang-nodes/NamedArgumentGroup.js @@ -7,7 +7,7 @@ export class NamedArgumentGroup extends SlangNode { closeBrace; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.openBrace = ast.openBrace.text; this.arguments = parse(ast.arguments, parse, this.nextChildOffset); diff --git a/src/slang-nodes/NamedArguments.js b/src/slang-nodes/NamedArguments.js index b57109d62..56eabd04f 100644 --- a/src/slang-nodes/NamedArguments.js +++ b/src/slang-nodes/NamedArguments.js @@ -9,7 +9,7 @@ export class NamedArguments extends SlangNode { separators; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/NamedArgumentsDeclaration.js b/src/slang-nodes/NamedArgumentsDeclaration.js index 9308b2806..a90581867 100644 --- a/src/slang-nodes/NamedArgumentsDeclaration.js +++ b/src/slang-nodes/NamedArgumentsDeclaration.js @@ -7,7 +7,7 @@ export class NamedArgumentsDeclaration extends SlangNode { closeParen; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.openParen = ast.openParen.text; this.arguments = ast.arguments diff --git a/src/slang-nodes/NamedImport.js b/src/slang-nodes/NamedImport.js index 11d00f53f..1502e0b8c 100644 --- a/src/slang-nodes/NamedImport.js +++ b/src/slang-nodes/NamedImport.js @@ -9,7 +9,7 @@ export class NamedImport extends SlangNode { path; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.asterisk = ast.asterisk.text; this.alias = parse(ast.alias, parse, this.nextChildOffset); diff --git a/src/slang-nodes/NewExpression.js b/src/slang-nodes/NewExpression.js index a504ec777..e69ca5acb 100644 --- a/src/slang-nodes/NewExpression.js +++ b/src/slang-nodes/NewExpression.js @@ -5,7 +5,7 @@ export class NewExpression extends SlangNode { typeName; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.newKeyword = ast.newKeyword.text; this.typeName = parse(ast.typeName, parse, this.nextChildOffset); diff --git a/src/slang-nodes/NumberUnit.js b/src/slang-nodes/NumberUnit.js index 932feb935..ac0941f36 100644 --- a/src/slang-nodes/NumberUnit.js +++ b/src/slang-nodes/NumberUnit.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class NumberUnit extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset) { super(ast, offset); this.variant = ast.variant.text; this.initiateLoc(ast); diff --git a/src/slang-nodes/OrExpression.js b/src/slang-nodes/OrExpression.js index fc2284be8..9e9e86208 100644 --- a/src/slang-nodes/OrExpression.js +++ b/src/slang-nodes/OrExpression.js @@ -11,7 +11,7 @@ export class OrExpression extends SlangNode { rightOperand; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.leftOperand = tryToHug( parse(ast.leftOperand, parse, this.nextChildOffset) diff --git a/src/slang-nodes/OverridePaths.js b/src/slang-nodes/OverridePaths.js index d0c9910a2..41eeef7d5 100644 --- a/src/slang-nodes/OverridePaths.js +++ b/src/slang-nodes/OverridePaths.js @@ -5,7 +5,7 @@ export class OverridePaths extends SlangNode { separators; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/OverridePathsDeclaration.js b/src/slang-nodes/OverridePathsDeclaration.js index a168eb020..97a4263f1 100644 --- a/src/slang-nodes/OverridePathsDeclaration.js +++ b/src/slang-nodes/OverridePathsDeclaration.js @@ -7,7 +7,7 @@ export class OverridePathsDeclaration extends SlangNode { closeParen; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.openParen = ast.openParen.text; this.paths = parse(ast.paths, parse, this.nextChildOffset); diff --git a/src/slang-nodes/OverrideSpecifier.js b/src/slang-nodes/OverrideSpecifier.js index d36804ba9..ee3b8d587 100644 --- a/src/slang-nodes/OverrideSpecifier.js +++ b/src/slang-nodes/OverrideSpecifier.js @@ -5,7 +5,7 @@ export class OverrideSpecifier extends SlangNode { overridden; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.overrideKeyword = ast.overrideKeyword.text; this.overridden = ast.overridden diff --git a/src/slang-nodes/Parameter.js b/src/slang-nodes/Parameter.js index 838c922b7..92e08a759 100644 --- a/src/slang-nodes/Parameter.js +++ b/src/slang-nodes/Parameter.js @@ -10,7 +10,7 @@ export class Parameter extends SlangNode { name; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.typeName = parse(ast.typeName, parse, this.nextChildOffset); this.storageLocation = ast.storageLocation diff --git a/src/slang-nodes/Parameters.js b/src/slang-nodes/Parameters.js index ab46d5745..6a2cec6e5 100644 --- a/src/slang-nodes/Parameters.js +++ b/src/slang-nodes/Parameters.js @@ -10,7 +10,7 @@ export class Parameters extends SlangNode { separators; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); if (offset) { this.items = ast.items.map((item) => diff --git a/src/slang-nodes/ParametersDeclaration.js b/src/slang-nodes/ParametersDeclaration.js index 8130648f5..85b9df0fd 100644 --- a/src/slang-nodes/ParametersDeclaration.js +++ b/src/slang-nodes/ParametersDeclaration.js @@ -7,7 +7,7 @@ export class ParametersDeclaration extends SlangNode { closeParen; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); if (offset) { this.openParen = ast.openParen.text; diff --git a/src/slang-nodes/PathImport.js b/src/slang-nodes/PathImport.js index 7c9a9ed97..16de718f8 100644 --- a/src/slang-nodes/PathImport.js +++ b/src/slang-nodes/PathImport.js @@ -5,7 +5,7 @@ export class PathImport extends SlangNode { alias; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.path = parse(ast.path, parse, this.nextChildOffset); this.alias = ast.alias diff --git a/src/slang-nodes/PositionalArguments.js b/src/slang-nodes/PositionalArguments.js index 3ad4f5044..38840fbda 100644 --- a/src/slang-nodes/PositionalArguments.js +++ b/src/slang-nodes/PositionalArguments.js @@ -6,7 +6,7 @@ export class PositionalArguments extends SlangNode { separators; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/PositionalArgumentsDeclaration.js b/src/slang-nodes/PositionalArgumentsDeclaration.js index 3a65e0a51..b6ccb0ac8 100644 --- a/src/slang-nodes/PositionalArgumentsDeclaration.js +++ b/src/slang-nodes/PositionalArgumentsDeclaration.js @@ -7,7 +7,7 @@ export class PositionalArgumentsDeclaration extends SlangNode { closeParen; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.openParen = ast.openParen.text; this.arguments = parse(ast.arguments, parse, this.nextChildOffset); diff --git a/src/slang-nodes/PostfixExpression.js b/src/slang-nodes/PostfixExpression.js index 54db16ba8..3d3904385 100644 --- a/src/slang-nodes/PostfixExpression.js +++ b/src/slang-nodes/PostfixExpression.js @@ -5,7 +5,7 @@ export class PostfixExpression extends SlangNode { operator; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.operand = parse(ast.operand, parse, this.nextChildOffset); this.operator = ast.operator.text; diff --git a/src/slang-nodes/Pragma.js b/src/slang-nodes/Pragma.js index 1650fc1d0..d766addd8 100644 --- a/src/slang-nodes/Pragma.js +++ b/src/slang-nodes/Pragma.js @@ -8,13 +8,13 @@ const variants = { ABICoderPragma, ExperimentalPragma, VersionPragma }; export class Pragma extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.variant = new variants[ast.variant.cst.kind]( ast.variant, this.nextChildOffset, - parse, - options + options, + parse ); this.initiateLoc(ast); } diff --git a/src/slang-nodes/PragmaDirective.js b/src/slang-nodes/PragmaDirective.js index 8c43b3fb4..129e210b0 100644 --- a/src/slang-nodes/PragmaDirective.js +++ b/src/slang-nodes/PragmaDirective.js @@ -8,10 +8,10 @@ export class PragmaDirective extends SlangNode { semicolon; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.pragmaKeyword = ast.pragmaKeyword.text; - this.pragma = new Pragma(ast.pragma, this.nextChildOffset, parse, options); + this.pragma = new Pragma(ast.pragma, this.nextChildOffset, options, parse); this.semicolon = ast.semicolon.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/PrefixExpression.js b/src/slang-nodes/PrefixExpression.js index d08f72495..aea50bbbd 100644 --- a/src/slang-nodes/PrefixExpression.js +++ b/src/slang-nodes/PrefixExpression.js @@ -5,7 +5,7 @@ export class PrefixExpression extends SlangNode { operand; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.operator = ast.operator.text; this.operand = parse(ast.operand, parse, this.nextChildOffset); diff --git a/src/slang-nodes/ReceiveFunctionAttribute.js b/src/slang-nodes/ReceiveFunctionAttribute.js index c3719c981..13baa33ab 100644 --- a/src/slang-nodes/ReceiveFunctionAttribute.js +++ b/src/slang-nodes/ReceiveFunctionAttribute.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class ReceiveFunctionAttribute extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.variant = ast.variant.type === 'Terminal' diff --git a/src/slang-nodes/ReceiveFunctionAttributes.js b/src/slang-nodes/ReceiveFunctionAttributes.js index 82d9fe1a2..c85d3f7d0 100644 --- a/src/slang-nodes/ReceiveFunctionAttributes.js +++ b/src/slang-nodes/ReceiveFunctionAttributes.js @@ -7,7 +7,7 @@ const { line } = doc.builders; export class ReceiveFunctionAttributes extends SlangNode { items; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items .map((item) => parse(item, parse, this.nextChildOffset)) diff --git a/src/slang-nodes/ReceiveFunctionDefinition.js b/src/slang-nodes/ReceiveFunctionDefinition.js index e3b0f6972..3155b2e3e 100644 --- a/src/slang-nodes/ReceiveFunctionDefinition.js +++ b/src/slang-nodes/ReceiveFunctionDefinition.js @@ -10,7 +10,7 @@ export class ReceiveFunctionDefinition extends SlangNode { body; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.receiveKeyword = ast.receiveKeyword.text; this.parameters = parse(ast.parameters, parse, this.nextChildOffset); diff --git a/src/slang-nodes/ReturnStatement.js b/src/slang-nodes/ReturnStatement.js index 3fab97ebf..1a1803ead 100644 --- a/src/slang-nodes/ReturnStatement.js +++ b/src/slang-nodes/ReturnStatement.js @@ -21,7 +21,7 @@ export class ReturnStatement extends SlangNode { semicolon; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.returnKeyword = ast.returnKeyword.text; this.expression = ast.expression diff --git a/src/slang-nodes/ReturnsDeclaration.js b/src/slang-nodes/ReturnsDeclaration.js index 85cdd7fd2..949e94250 100644 --- a/src/slang-nodes/ReturnsDeclaration.js +++ b/src/slang-nodes/ReturnsDeclaration.js @@ -8,7 +8,7 @@ export class ReturnsDeclaration extends SlangNode { variables; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.returnsKeyword = ast.returnsKeyword.text; this.variables = parse(ast.variables, parse, this.nextChildOffset); diff --git a/src/slang-nodes/RevertStatement.js b/src/slang-nodes/RevertStatement.js index 0fd36f9c0..55c6317c7 100644 --- a/src/slang-nodes/RevertStatement.js +++ b/src/slang-nodes/RevertStatement.js @@ -9,7 +9,7 @@ export class RevertStatement extends SlangNode { semicolon; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.revertKeyword = ast.revertKeyword.text; this.error = ast.error diff --git a/src/slang-nodes/ShiftExpression.js b/src/slang-nodes/ShiftExpression.js index 3ba6a4b0a..f09a0d417 100644 --- a/src/slang-nodes/ShiftExpression.js +++ b/src/slang-nodes/ShiftExpression.js @@ -20,7 +20,7 @@ export class ShiftExpression extends SlangNode { rightOperand; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.leftOperand = tryToHugLeftOperand( parse(ast.leftOperand, parse, this.nextChildOffset) diff --git a/src/slang-nodes/SourceUnit.js b/src/slang-nodes/SourceUnit.js index 080faec56..c163801d2 100644 --- a/src/slang-nodes/SourceUnit.js +++ b/src/slang-nodes/SourceUnit.js @@ -7,13 +7,13 @@ const { line } = doc.builders; export class SourceUnit extends SlangNode { members; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.members = new SourceUnitMembers( ast.members, this.nextChildOffset, - parse, - options + options, + parse ); this.initiateLoc(ast); } diff --git a/src/slang-nodes/SourceUnitMember.js b/src/slang-nodes/SourceUnitMember.js index 428f89f9e..f4b391a57 100644 --- a/src/slang-nodes/SourceUnitMember.js +++ b/src/slang-nodes/SourceUnitMember.js @@ -32,13 +32,13 @@ const variants = { export class SourceUnitMember extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.variant = new variants[ast.variant.cst.kind]( ast.variant, this.nextChildOffset, - parse, - options + options, + parse ); this.initiateLoc(ast); } diff --git a/src/slang-nodes/SourceUnitMembers.js b/src/slang-nodes/SourceUnitMembers.js index c4d727ac5..162bd41e2 100644 --- a/src/slang-nodes/SourceUnitMembers.js +++ b/src/slang-nodes/SourceUnitMembers.js @@ -5,10 +5,10 @@ import { SourceUnitMember } from './SourceUnitMember.js'; export class SourceUnitMembers extends SlangNode { items; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items.map( - (item) => new SourceUnitMember(item, this.nextChildOffset, parse, options) + (item) => new SourceUnitMember(item, this.nextChildOffset, options, parse) ); this.initiateLoc(ast); } diff --git a/src/slang-nodes/StateVariableAttribute.js b/src/slang-nodes/StateVariableAttribute.js index 3d21eb5a8..96a347184 100644 --- a/src/slang-nodes/StateVariableAttribute.js +++ b/src/slang-nodes/StateVariableAttribute.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class StateVariableAttribute extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.variant = ast.variant.type === 'Terminal' diff --git a/src/slang-nodes/StateVariableAttributes.js b/src/slang-nodes/StateVariableAttributes.js index 2d5c62aa8..cc3d732f9 100644 --- a/src/slang-nodes/StateVariableAttributes.js +++ b/src/slang-nodes/StateVariableAttributes.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class StateVariableAttributes extends SlangNode { items; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/StateVariableDefinition.js b/src/slang-nodes/StateVariableDefinition.js index acc14a711..746ad75a0 100644 --- a/src/slang-nodes/StateVariableDefinition.js +++ b/src/slang-nodes/StateVariableDefinition.js @@ -11,7 +11,7 @@ export class StateVariableDefinition extends SlangNode { semicolon; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.typeName = parse(ast.typeName, parse, this.nextChildOffset); this.attributes = parse(ast.attributes, parse, this.nextChildOffset); diff --git a/src/slang-nodes/StateVariableDefinitionValue.js b/src/slang-nodes/StateVariableDefinitionValue.js index 682528384..145960cb0 100644 --- a/src/slang-nodes/StateVariableDefinitionValue.js +++ b/src/slang-nodes/StateVariableDefinitionValue.js @@ -8,7 +8,7 @@ export class StateVariableDefinitionValue extends SlangNode { value; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.equal = ast.equal.text; this.value = parse(ast.value, parse, this.nextChildOffset); diff --git a/src/slang-nodes/Statement.js b/src/slang-nodes/Statement.js index 95e899da8..b25dfe9ad 100644 --- a/src/slang-nodes/Statement.js +++ b/src/slang-nodes/Statement.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class Statement extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.variant = parse(ast.variant, parse, this.nextChildOffset); this.initiateLoc(ast); diff --git a/src/slang-nodes/Statements.js b/src/slang-nodes/Statements.js index 84e698e9c..d574e63fb 100644 --- a/src/slang-nodes/Statements.js +++ b/src/slang-nodes/Statements.js @@ -11,7 +11,7 @@ const { hardline } = doc.builders; export class Statements extends SlangNode { items; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/StorageLocation.js b/src/slang-nodes/StorageLocation.js index 52ec21f0f..2c3b16656 100644 --- a/src/slang-nodes/StorageLocation.js +++ b/src/slang-nodes/StorageLocation.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class StorageLocation extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset) { super(ast, offset); this.variant = ast.variant.text; this.initiateLoc(ast); diff --git a/src/slang-nodes/StringExpression.js b/src/slang-nodes/StringExpression.js index e13dbcbd5..a78521777 100644 --- a/src/slang-nodes/StringExpression.js +++ b/src/slang-nodes/StringExpression.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class StringExpression extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.variant = parse(ast.variant, parse, this.nextChildOffset); this.initiateLoc(ast); diff --git a/src/slang-nodes/StringLiteral.js b/src/slang-nodes/StringLiteral.js index a3f45b4e6..551b84d94 100644 --- a/src/slang-nodes/StringLiteral.js +++ b/src/slang-nodes/StringLiteral.js @@ -4,7 +4,7 @@ import { SlangNode } from './SlangNode.js'; export class StringLiteral extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options) { super(ast, offset); this.variant = printString(ast.variant.text.slice(1, -1), options); this.initiateLoc(ast); diff --git a/src/slang-nodes/StringLiterals.js b/src/slang-nodes/StringLiterals.js index b1ca841ed..457b5fe81 100644 --- a/src/slang-nodes/StringLiterals.js +++ b/src/slang-nodes/StringLiterals.js @@ -6,7 +6,7 @@ const { join, hardline } = doc.builders; export class StringLiterals extends SlangNode { items; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/StructDefinition.js b/src/slang-nodes/StructDefinition.js index 0b762493f..aadea0ddd 100644 --- a/src/slang-nodes/StructDefinition.js +++ b/src/slang-nodes/StructDefinition.js @@ -11,7 +11,7 @@ export class StructDefinition extends SlangNode { closeBrace; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.structKeyword = ast.structKeyword.text; this.name = ast.name.text; diff --git a/src/slang-nodes/StructMember.js b/src/slang-nodes/StructMember.js index d31039dfb..878ae9eaf 100644 --- a/src/slang-nodes/StructMember.js +++ b/src/slang-nodes/StructMember.js @@ -7,7 +7,7 @@ export class StructMember extends SlangNode { semicolon; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.typeName = parse(ast.typeName, parse, this.nextChildOffset); this.name = ast.name.text; diff --git a/src/slang-nodes/StructMembers.js b/src/slang-nodes/StructMembers.js index ed5f5a2c2..2eeb3e3b6 100644 --- a/src/slang-nodes/StructMembers.js +++ b/src/slang-nodes/StructMembers.js @@ -7,7 +7,7 @@ const { hardline } = doc.builders; export class StructMembers extends SlangNode { items; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/ThrowStatement.js b/src/slang-nodes/ThrowStatement.js index c9c0c211e..21bdbc4fa 100644 --- a/src/slang-nodes/ThrowStatement.js +++ b/src/slang-nodes/ThrowStatement.js @@ -5,7 +5,7 @@ export class ThrowStatement extends SlangNode { semicolon; - constructor(ast, offset, parse, options) { + constructor(ast, offset) { super(ast, offset); this.throwKeyword = ast.throwKeyword.text; this.semicolon = ast.semicolon.text; diff --git a/src/slang-nodes/TryStatement.js b/src/slang-nodes/TryStatement.js index cdc7f769f..66dee4097 100644 --- a/src/slang-nodes/TryStatement.js +++ b/src/slang-nodes/TryStatement.js @@ -15,7 +15,7 @@ export class TryStatement extends SlangNode { catchClauses; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.tryKeyword = ast.tryKeyword.text; this.expression = parse(ast.expression, parse, this.nextChildOffset); diff --git a/src/slang-nodes/TupleDeconstructionElement.js b/src/slang-nodes/TupleDeconstructionElement.js index 615265acd..92011380d 100644 --- a/src/slang-nodes/TupleDeconstructionElement.js +++ b/src/slang-nodes/TupleDeconstructionElement.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class TupleDeconstructionElement extends SlangNode { member; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.member = ast.member ? parse(ast.member, parse, this.nextChildOffset) diff --git a/src/slang-nodes/TupleDeconstructionElements.js b/src/slang-nodes/TupleDeconstructionElements.js index ddd01183d..256a96ac0 100644 --- a/src/slang-nodes/TupleDeconstructionElements.js +++ b/src/slang-nodes/TupleDeconstructionElements.js @@ -6,7 +6,7 @@ export class TupleDeconstructionElements extends SlangNode { separators; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/TupleDeconstructionStatement.js b/src/slang-nodes/TupleDeconstructionStatement.js index 8d937e26f..0ec271506 100644 --- a/src/slang-nodes/TupleDeconstructionStatement.js +++ b/src/slang-nodes/TupleDeconstructionStatement.js @@ -18,7 +18,7 @@ export class TupleDeconstructionStatement extends SlangNode { semicolon; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.varKeyword = ast.varKeyword?.text; this.openParen = ast.openParen.text; diff --git a/src/slang-nodes/TupleExpression.js b/src/slang-nodes/TupleExpression.js index 53b9f88a2..dc7914cbb 100644 --- a/src/slang-nodes/TupleExpression.js +++ b/src/slang-nodes/TupleExpression.js @@ -7,7 +7,7 @@ export class TupleExpression extends SlangNode { closeParen; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); if (offset) { this.openParen = ast.openParen.text; diff --git a/src/slang-nodes/TupleMember.js b/src/slang-nodes/TupleMember.js index 1ac3b77a5..2bd5e463d 100644 --- a/src/slang-nodes/TupleMember.js +++ b/src/slang-nodes/TupleMember.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class TupleMember extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.variant = parse(ast.variant, parse, this.nextChildOffset); this.initiateLoc(ast); diff --git a/src/slang-nodes/TupleValue.js b/src/slang-nodes/TupleValue.js index 80fb7e7d4..ee275f625 100644 --- a/src/slang-nodes/TupleValue.js +++ b/src/slang-nodes/TupleValue.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class TupleValue extends SlangNode { expression; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); if (offset) { this.expression = ast.expression diff --git a/src/slang-nodes/TupleValues.js b/src/slang-nodes/TupleValues.js index 08d12da05..fc3cdcba0 100644 --- a/src/slang-nodes/TupleValues.js +++ b/src/slang-nodes/TupleValues.js @@ -7,7 +7,7 @@ export class TupleValues extends SlangNode { separators; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); if (offset) { this.items = ast.items.map((item) => diff --git a/src/slang-nodes/TypeExpression.js b/src/slang-nodes/TypeExpression.js index a621aa8e2..95ad58bc7 100644 --- a/src/slang-nodes/TypeExpression.js +++ b/src/slang-nodes/TypeExpression.js @@ -9,7 +9,7 @@ export class TypeExpression extends SlangNode { closeParen; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.typeKeyword = ast.typeKeyword.text; this.openParen = ast.openParen.text; diff --git a/src/slang-nodes/TypeName.js b/src/slang-nodes/TypeName.js index 63c025782..8097dcacb 100644 --- a/src/slang-nodes/TypeName.js +++ b/src/slang-nodes/TypeName.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class TypeName extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.variant = parse(ast.variant, parse, this.nextChildOffset); this.initiateLoc(ast); diff --git a/src/slang-nodes/TypedTupleMember.js b/src/slang-nodes/TypedTupleMember.js index b2fb2fdfd..bcb9784b5 100644 --- a/src/slang-nodes/TypedTupleMember.js +++ b/src/slang-nodes/TypedTupleMember.js @@ -7,7 +7,7 @@ export class TypedTupleMember extends SlangNode { name; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.typeName = parse(ast.typeName, parse, this.nextChildOffset); this.storageLocation = ast.storageLocation diff --git a/src/slang-nodes/UncheckedBlock.js b/src/slang-nodes/UncheckedBlock.js index 0d21df976..5b59a7c3e 100644 --- a/src/slang-nodes/UncheckedBlock.js +++ b/src/slang-nodes/UncheckedBlock.js @@ -5,7 +5,7 @@ export class UncheckedBlock extends SlangNode { block; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.uncheckedKeyword = ast.uncheckedKeyword.text; this.block = parse(ast.block, parse, this.nextChildOffset); diff --git a/src/slang-nodes/UnicodeStringLiteral.js b/src/slang-nodes/UnicodeStringLiteral.js index a05199e24..ab78996cc 100644 --- a/src/slang-nodes/UnicodeStringLiteral.js +++ b/src/slang-nodes/UnicodeStringLiteral.js @@ -4,7 +4,7 @@ import { SlangNode } from './SlangNode.js'; export class UnicodeStringLiteral extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options) { super(ast, offset); this.variant = `unicode${printString(ast.variant.text.slice(8, -1), options)}`; this.initiateLoc(ast); diff --git a/src/slang-nodes/UnicodeStringLiterals.js b/src/slang-nodes/UnicodeStringLiterals.js index f656b2b15..a38fb4ce9 100644 --- a/src/slang-nodes/UnicodeStringLiterals.js +++ b/src/slang-nodes/UnicodeStringLiterals.js @@ -6,7 +6,7 @@ const { join, hardline } = doc.builders; export class UnicodeStringLiterals extends SlangNode { items; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/UnnamedFunctionAttribute.js b/src/slang-nodes/UnnamedFunctionAttribute.js index a7c31335b..2d1df0e5a 100644 --- a/src/slang-nodes/UnnamedFunctionAttribute.js +++ b/src/slang-nodes/UnnamedFunctionAttribute.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class UnnamedFunctionAttribute extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.variant = ast.variant.type === 'Terminal' diff --git a/src/slang-nodes/UnnamedFunctionAttributes.js b/src/slang-nodes/UnnamedFunctionAttributes.js index 3311fd90e..d404cc66d 100644 --- a/src/slang-nodes/UnnamedFunctionAttributes.js +++ b/src/slang-nodes/UnnamedFunctionAttributes.js @@ -7,7 +7,7 @@ const { line } = doc.builders; export class UnnamedFunctionAttributes extends SlangNode { items; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items .map((item) => parse(item, parse, this.nextChildOffset)) diff --git a/src/slang-nodes/UnnamedFunctionDefinition.js b/src/slang-nodes/UnnamedFunctionDefinition.js index 0f8e31404..29fcd9279 100644 --- a/src/slang-nodes/UnnamedFunctionDefinition.js +++ b/src/slang-nodes/UnnamedFunctionDefinition.js @@ -10,7 +10,7 @@ export class UnnamedFunctionDefinition extends SlangNode { body; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.functionKeyword = ast.functionKeyword.text; this.parameters = parse(ast.parameters, parse, this.nextChildOffset); diff --git a/src/slang-nodes/UntypedTupleMember.js b/src/slang-nodes/UntypedTupleMember.js index 7ec5b3273..49a1df681 100644 --- a/src/slang-nodes/UntypedTupleMember.js +++ b/src/slang-nodes/UntypedTupleMember.js @@ -5,7 +5,7 @@ export class UntypedTupleMember extends SlangNode { name; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.storageLocation = ast.storageLocation ? parse(ast.storageLocation, parse, this.nextChildOffset) diff --git a/src/slang-nodes/UserDefinedValueTypeDefinition.js b/src/slang-nodes/UserDefinedValueTypeDefinition.js index 209e09a8c..96087beef 100644 --- a/src/slang-nodes/UserDefinedValueTypeDefinition.js +++ b/src/slang-nodes/UserDefinedValueTypeDefinition.js @@ -11,7 +11,7 @@ export class UserDefinedValueTypeDefinition extends SlangNode { semicolon; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.typeKeyword = ast.typeKeyword.text; this.name = ast.name.text; diff --git a/src/slang-nodes/UsingAlias.js b/src/slang-nodes/UsingAlias.js index 8950bca2f..dfa40f03e 100644 --- a/src/slang-nodes/UsingAlias.js +++ b/src/slang-nodes/UsingAlias.js @@ -5,7 +5,7 @@ export class UsingAlias extends SlangNode { operator; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.asKeyword = ast.asKeyword.text; this.operator = parse(ast.operator, parse, this.nextChildOffset); diff --git a/src/slang-nodes/UsingClause.js b/src/slang-nodes/UsingClause.js index 8eb5a1785..2536fbfce 100644 --- a/src/slang-nodes/UsingClause.js +++ b/src/slang-nodes/UsingClause.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class UsingClause extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.variant = parse(ast.variant, parse, this.nextChildOffset); this.initiateLoc(ast); diff --git a/src/slang-nodes/UsingDeconstruction.js b/src/slang-nodes/UsingDeconstruction.js index 0d0822b7c..920d663da 100644 --- a/src/slang-nodes/UsingDeconstruction.js +++ b/src/slang-nodes/UsingDeconstruction.js @@ -7,7 +7,7 @@ export class UsingDeconstruction extends SlangNode { closeBrace; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.openBrace = ast.openBrace.text; this.symbols = parse(ast.symbols, parse, this.nextChildOffset); diff --git a/src/slang-nodes/UsingDeconstructionSymbol.js b/src/slang-nodes/UsingDeconstructionSymbol.js index 563b66a2b..e7f6a97f8 100644 --- a/src/slang-nodes/UsingDeconstructionSymbol.js +++ b/src/slang-nodes/UsingDeconstructionSymbol.js @@ -5,7 +5,7 @@ export class UsingDeconstructionSymbol extends SlangNode { alias; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.name = parse(ast.name, parse, this.nextChildOffset); this.alias = ast.alias diff --git a/src/slang-nodes/UsingDeconstructionSymbols.js b/src/slang-nodes/UsingDeconstructionSymbols.js index 1cdbe0bdb..4a546a11e 100644 --- a/src/slang-nodes/UsingDeconstructionSymbols.js +++ b/src/slang-nodes/UsingDeconstructionSymbols.js @@ -9,7 +9,7 @@ export class UsingDeconstructionSymbols extends SlangNode { separators; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/UsingDirective.js b/src/slang-nodes/UsingDirective.js index 63b90712c..eff919233 100644 --- a/src/slang-nodes/UsingDirective.js +++ b/src/slang-nodes/UsingDirective.js @@ -13,7 +13,7 @@ export class UsingDirective extends SlangNode { semicolon; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.usingKeyword = ast.usingKeyword.text; this.clause = parse(ast.clause, parse, this.nextChildOffset); diff --git a/src/slang-nodes/UsingOperator.js b/src/slang-nodes/UsingOperator.js index ce704784c..b38045122 100644 --- a/src/slang-nodes/UsingOperator.js +++ b/src/slang-nodes/UsingOperator.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class UsingOperator extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset) { super(ast, offset); this.variant = ast.variant.text; this.initiateLoc(ast); diff --git a/src/slang-nodes/UsingTarget.js b/src/slang-nodes/UsingTarget.js index 548c99d79..59fbc0064 100644 --- a/src/slang-nodes/UsingTarget.js +++ b/src/slang-nodes/UsingTarget.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class UsingTarget extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.variant = ast.variant.type === 'Terminal' diff --git a/src/slang-nodes/VariableDeclarationStatement.js b/src/slang-nodes/VariableDeclarationStatement.js index d10febb63..609da2294 100644 --- a/src/slang-nodes/VariableDeclarationStatement.js +++ b/src/slang-nodes/VariableDeclarationStatement.js @@ -16,7 +16,7 @@ export class VariableDeclarationStatement extends SlangNode { semicolon; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.variableType = parse(ast.variableType, parse, this.nextChildOffset); this.storageLocation = ast.storageLocation diff --git a/src/slang-nodes/VariableDeclarationType.js b/src/slang-nodes/VariableDeclarationType.js index 54039899f..ea41ed1e1 100644 --- a/src/slang-nodes/VariableDeclarationType.js +++ b/src/slang-nodes/VariableDeclarationType.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class VariableDeclarationType extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.variant = ast.variant.type === 'Terminal' diff --git a/src/slang-nodes/VariableDeclarationValue.js b/src/slang-nodes/VariableDeclarationValue.js index 37db434bc..9477210a2 100644 --- a/src/slang-nodes/VariableDeclarationValue.js +++ b/src/slang-nodes/VariableDeclarationValue.js @@ -5,7 +5,7 @@ export class VariableDeclarationValue extends SlangNode { expression; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.equal = ast.equal.text; this.expression = parse(ast.expression, parse, this.nextChildOffset); diff --git a/src/slang-nodes/VersionComparator.js b/src/slang-nodes/VersionComparator.js index 3897b186a..e87e42a02 100644 --- a/src/slang-nodes/VersionComparator.js +++ b/src/slang-nodes/VersionComparator.js @@ -5,7 +5,7 @@ export class VersionComparator extends SlangNode { operand; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.operator = ast.operator.text; this.operand = parse(ast.operand, parse, this.nextChildOffset); diff --git a/src/slang-nodes/VersionExpression.js b/src/slang-nodes/VersionExpression.js index 1bb1ceddf..6cf8fdc11 100644 --- a/src/slang-nodes/VersionExpression.js +++ b/src/slang-nodes/VersionExpression.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class VersionExpression extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.variant = ast.variant.type === 'Terminal' diff --git a/src/slang-nodes/VersionExpressionSet.js b/src/slang-nodes/VersionExpressionSet.js index 4c18ae29e..9d44916cf 100644 --- a/src/slang-nodes/VersionExpressionSet.js +++ b/src/slang-nodes/VersionExpressionSet.js @@ -6,7 +6,7 @@ const { join } = doc.builders; export class VersionExpressionSet extends SlangNode { items; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/VersionExpressionSets.js b/src/slang-nodes/VersionExpressionSets.js index ff2ac9585..87528395e 100644 --- a/src/slang-nodes/VersionExpressionSets.js +++ b/src/slang-nodes/VersionExpressionSets.js @@ -5,7 +5,7 @@ export class VersionExpressionSets extends SlangNode { separators; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/VersionPragma.js b/src/slang-nodes/VersionPragma.js index d4262e8ea..96a5a3ab7 100644 --- a/src/slang-nodes/VersionPragma.js +++ b/src/slang-nodes/VersionPragma.js @@ -5,7 +5,7 @@ export class VersionPragma extends SlangNode { sets; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.solidityKeyword = ast.solidityKeyword.text; this.sets = parse(ast.sets, parse, this.nextChildOffset); diff --git a/src/slang-nodes/VersionRange.js b/src/slang-nodes/VersionRange.js index 17a3ce601..57f6aa8a8 100644 --- a/src/slang-nodes/VersionRange.js +++ b/src/slang-nodes/VersionRange.js @@ -7,7 +7,7 @@ export class VersionRange extends SlangNode { rightOperand; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.leftOperand = parse(ast.leftOperand, parse, this.nextChildOffset); this.operator = ast.operator.text; diff --git a/src/slang-nodes/VersionSpecifiers.js b/src/slang-nodes/VersionSpecifiers.js index da591cd40..569aea278 100644 --- a/src/slang-nodes/VersionSpecifiers.js +++ b/src/slang-nodes/VersionSpecifiers.js @@ -5,7 +5,7 @@ export class VersionSpecifiers extends SlangNode { separators; - constructor(ast, offset, parse, options) { + constructor(ast, offset) { super(ast, offset); this.items = ast.items.map((item) => item.text); this.separators = ast.separators.map((separator) => separator.text); diff --git a/src/slang-nodes/WhileStatement.js b/src/slang-nodes/WhileStatement.js index d80a6511b..af18753f2 100644 --- a/src/slang-nodes/WhileStatement.js +++ b/src/slang-nodes/WhileStatement.js @@ -20,7 +20,7 @@ export class WhileStatement extends SlangNode { body; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.whileKeyword = ast.whileKeyword.text; this.openParen = ast.openParen.text; diff --git a/src/slang-nodes/YulArguments.js b/src/slang-nodes/YulArguments.js index a4cb9b942..10d479405 100644 --- a/src/slang-nodes/YulArguments.js +++ b/src/slang-nodes/YulArguments.js @@ -6,7 +6,7 @@ export class YulArguments extends SlangNode { separators; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/YulAssignmentOperator.js b/src/slang-nodes/YulAssignmentOperator.js index 4b152f7bf..832d53d24 100644 --- a/src/slang-nodes/YulAssignmentOperator.js +++ b/src/slang-nodes/YulAssignmentOperator.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class YulAssignmentOperator extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.variant = ast.variant.type === 'Terminal' diff --git a/src/slang-nodes/YulAssignmentStatement.js b/src/slang-nodes/YulAssignmentStatement.js index 0f2e7faec..a35c00108 100644 --- a/src/slang-nodes/YulAssignmentStatement.js +++ b/src/slang-nodes/YulAssignmentStatement.js @@ -7,7 +7,7 @@ export class YulAssignmentStatement extends SlangNode { expression; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.names = parse(ast.names, parse, this.nextChildOffset); this.assignment = parse(ast.assignment, parse, this.nextChildOffset); diff --git a/src/slang-nodes/YulBlock.js b/src/slang-nodes/YulBlock.js index d805c96c2..4e52bbc5a 100644 --- a/src/slang-nodes/YulBlock.js +++ b/src/slang-nodes/YulBlock.js @@ -7,7 +7,7 @@ export class YulBlock extends SlangNode { closeBrace; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.openBrace = ast.openBrace.text; this.statements = parse(ast.statements, parse, this.nextChildOffset); diff --git a/src/slang-nodes/YulBreakStatement.js b/src/slang-nodes/YulBreakStatement.js index b986c8558..dc24e1ad4 100644 --- a/src/slang-nodes/YulBreakStatement.js +++ b/src/slang-nodes/YulBreakStatement.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class YulBreakStatement extends SlangNode { breakKeyword; - constructor(ast, offset, parse, options) { + constructor(ast, offset) { super(ast, offset); this.breakKeyword = ast.breakKeyword.text; this.initiateLoc(ast); diff --git a/src/slang-nodes/YulBuiltInFunction.js b/src/slang-nodes/YulBuiltInFunction.js index 3c3ff0a51..fab564369 100644 --- a/src/slang-nodes/YulBuiltInFunction.js +++ b/src/slang-nodes/YulBuiltInFunction.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class YulBuiltInFunction extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset) { super(ast, offset); this.variant = ast.variant.text; this.initiateLoc(ast); diff --git a/src/slang-nodes/YulColonAndEqual.js b/src/slang-nodes/YulColonAndEqual.js index 99ca0a27f..a6a432da2 100644 --- a/src/slang-nodes/YulColonAndEqual.js +++ b/src/slang-nodes/YulColonAndEqual.js @@ -5,7 +5,7 @@ export class YulColonAndEqual extends SlangNode { equal; - constructor(ast, offset, parse, options) { + constructor(ast, offset) { super(ast, offset); this.colon = ast.colon.text; this.equal = ast.equal.text; diff --git a/src/slang-nodes/YulContinueStatement.js b/src/slang-nodes/YulContinueStatement.js index 10b4b6241..6e5858716 100644 --- a/src/slang-nodes/YulContinueStatement.js +++ b/src/slang-nodes/YulContinueStatement.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class YulContinueStatement extends SlangNode { continueKeyword; - constructor(ast, offset, parse, options) { + constructor(ast, offset) { super(ast, offset); this.continueKeyword = ast.continueKeyword.text; this.initiateLoc(ast); diff --git a/src/slang-nodes/YulDefaultCase.js b/src/slang-nodes/YulDefaultCase.js index 46712a3bb..6045dd21e 100644 --- a/src/slang-nodes/YulDefaultCase.js +++ b/src/slang-nodes/YulDefaultCase.js @@ -5,7 +5,7 @@ export class YulDefaultCase extends SlangNode { body; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.defaultKeyword = ast.defaultKeyword.text; this.body = parse(ast.body, parse, this.nextChildOffset); diff --git a/src/slang-nodes/YulExpression.js b/src/slang-nodes/YulExpression.js index b9a120908..927cea4f1 100644 --- a/src/slang-nodes/YulExpression.js +++ b/src/slang-nodes/YulExpression.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class YulExpression extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.variant = parse(ast.variant, parse, this.nextChildOffset); this.initiateLoc(ast); diff --git a/src/slang-nodes/YulForStatement.js b/src/slang-nodes/YulForStatement.js index f0266aef3..8aeb9a675 100644 --- a/src/slang-nodes/YulForStatement.js +++ b/src/slang-nodes/YulForStatement.js @@ -11,7 +11,7 @@ export class YulForStatement extends SlangNode { body; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.forKeyword = ast.forKeyword.text; this.initialization = parse( diff --git a/src/slang-nodes/YulFunctionCallExpression.js b/src/slang-nodes/YulFunctionCallExpression.js index 633658e74..c163987ca 100644 --- a/src/slang-nodes/YulFunctionCallExpression.js +++ b/src/slang-nodes/YulFunctionCallExpression.js @@ -9,7 +9,7 @@ export class YulFunctionCallExpression extends SlangNode { closeParen; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.operand = parse(ast.operand, parse, this.nextChildOffset); this.openParen = ast.openParen.text; diff --git a/src/slang-nodes/YulFunctionDefinition.js b/src/slang-nodes/YulFunctionDefinition.js index a7b5a6aed..765b420be 100644 --- a/src/slang-nodes/YulFunctionDefinition.js +++ b/src/slang-nodes/YulFunctionDefinition.js @@ -11,7 +11,7 @@ export class YulFunctionDefinition extends SlangNode { body; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.functionKeyword = ast.functionKeyword.text; this.name = ast.name.text; diff --git a/src/slang-nodes/YulIfStatement.js b/src/slang-nodes/YulIfStatement.js index 066edbe03..6bcf0eed5 100644 --- a/src/slang-nodes/YulIfStatement.js +++ b/src/slang-nodes/YulIfStatement.js @@ -7,7 +7,7 @@ export class YulIfStatement extends SlangNode { body; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.ifKeyword = ast.ifKeyword.text; this.condition = parse(ast.condition, parse, this.nextChildOffset); diff --git a/src/slang-nodes/YulLabel.js b/src/slang-nodes/YulLabel.js index b79ff5828..3333e22a0 100644 --- a/src/slang-nodes/YulLabel.js +++ b/src/slang-nodes/YulLabel.js @@ -7,7 +7,7 @@ export class YulLabel extends SlangNode { colon; - constructor(ast, offset, parse, options) { + constructor(ast, offset) { super(ast, offset); this.label = ast.label.text; this.colon = ast.colon.text; diff --git a/src/slang-nodes/YulLeaveStatement.js b/src/slang-nodes/YulLeaveStatement.js index 96d816f8a..5dff1ae1f 100644 --- a/src/slang-nodes/YulLeaveStatement.js +++ b/src/slang-nodes/YulLeaveStatement.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class YulLeaveStatement extends SlangNode { leaveKeyword; - constructor(ast, offset, parse, options) { + constructor(ast, offset) { super(ast, offset); this.leaveKeyword = ast.leaveKeyword.text; this.initiateLoc(ast); diff --git a/src/slang-nodes/YulLiteral.js b/src/slang-nodes/YulLiteral.js index 6d0af89f3..1d844d9c4 100644 --- a/src/slang-nodes/YulLiteral.js +++ b/src/slang-nodes/YulLiteral.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class YulLiteral extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.variant = ast.variant.type === 'Terminal' diff --git a/src/slang-nodes/YulParameters.js b/src/slang-nodes/YulParameters.js index c75267a93..01d2ec7a2 100644 --- a/src/slang-nodes/YulParameters.js +++ b/src/slang-nodes/YulParameters.js @@ -6,7 +6,7 @@ export class YulParameters extends SlangNode { separators; - constructor(ast, offset, parse, options) { + constructor(ast, offset) { super(ast, offset); this.items = ast.items.map((item) => item.text); this.separators = ast.separators.map((separator) => separator.text); diff --git a/src/slang-nodes/YulParametersDeclaration.js b/src/slang-nodes/YulParametersDeclaration.js index effb4486f..2cd190d7c 100644 --- a/src/slang-nodes/YulParametersDeclaration.js +++ b/src/slang-nodes/YulParametersDeclaration.js @@ -7,7 +7,7 @@ export class YulParametersDeclaration extends SlangNode { closeParen; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.openParen = ast.openParen.text; this.parameters = parse(ast.parameters, parse, this.nextChildOffset); diff --git a/src/slang-nodes/YulPath.js b/src/slang-nodes/YulPath.js index 3c4301eae..212bd0f4c 100644 --- a/src/slang-nodes/YulPath.js +++ b/src/slang-nodes/YulPath.js @@ -5,7 +5,7 @@ export class YulPath extends SlangNode { separators; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/YulPathComponent.js b/src/slang-nodes/YulPathComponent.js index ae06ca440..8e7cf56d9 100644 --- a/src/slang-nodes/YulPathComponent.js +++ b/src/slang-nodes/YulPathComponent.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class YulPathComponent extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset) { super(ast, offset); this.variant = ast.variant.text; this.initiateLoc(ast); diff --git a/src/slang-nodes/YulPaths.js b/src/slang-nodes/YulPaths.js index 3ed3dac1a..ddc46eea7 100644 --- a/src/slang-nodes/YulPaths.js +++ b/src/slang-nodes/YulPaths.js @@ -5,7 +5,7 @@ export class YulPaths extends SlangNode { separators; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/YulReturnVariables.js b/src/slang-nodes/YulReturnVariables.js index e963f0e83..734065480 100644 --- a/src/slang-nodes/YulReturnVariables.js +++ b/src/slang-nodes/YulReturnVariables.js @@ -9,7 +9,7 @@ export class YulReturnVariables extends SlangNode { separators; - constructor(ast, offset, parse, options) { + constructor(ast, offset) { super(ast, offset); this.items = ast.items.map((item) => item.text); this.separators = ast.separators.map((separator) => separator.text); diff --git a/src/slang-nodes/YulReturnsDeclaration.js b/src/slang-nodes/YulReturnsDeclaration.js index 3ebd13c4a..c08828ed5 100644 --- a/src/slang-nodes/YulReturnsDeclaration.js +++ b/src/slang-nodes/YulReturnsDeclaration.js @@ -9,7 +9,7 @@ export class YulReturnsDeclaration extends SlangNode { variables; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.minusGreaterThan = ast.minusGreaterThan.text; this.variables = parse(ast.variables, parse, this.nextChildOffset); diff --git a/src/slang-nodes/YulStatement.js b/src/slang-nodes/YulStatement.js index 7383821e4..5c5676ff3 100644 --- a/src/slang-nodes/YulStatement.js +++ b/src/slang-nodes/YulStatement.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class YulStatement extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.variant = parse(ast.variant, parse, this.nextChildOffset); this.initiateLoc(ast); diff --git a/src/slang-nodes/YulStatements.js b/src/slang-nodes/YulStatements.js index 747c85ef1..97478d773 100644 --- a/src/slang-nodes/YulStatements.js +++ b/src/slang-nodes/YulStatements.js @@ -11,7 +11,7 @@ const { hardline } = doc.builders; export class YulStatements extends SlangNode { items; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/YulSwitchCase.js b/src/slang-nodes/YulSwitchCase.js index 9a6a10ce9..68e8f5b57 100644 --- a/src/slang-nodes/YulSwitchCase.js +++ b/src/slang-nodes/YulSwitchCase.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class YulSwitchCase extends SlangNode { variant; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.variant = parse(ast.variant, parse, this.nextChildOffset); this.initiateLoc(ast); diff --git a/src/slang-nodes/YulSwitchCases.js b/src/slang-nodes/YulSwitchCases.js index b17c61ea2..9fc6d0f8b 100644 --- a/src/slang-nodes/YulSwitchCases.js +++ b/src/slang-nodes/YulSwitchCases.js @@ -6,7 +6,7 @@ const { hardline, join } = doc.builders; export class YulSwitchCases extends SlangNode { items; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items.map((item) => parse(item, parse, this.nextChildOffset) diff --git a/src/slang-nodes/YulSwitchStatement.js b/src/slang-nodes/YulSwitchStatement.js index 6faf6965d..21545835b 100644 --- a/src/slang-nodes/YulSwitchStatement.js +++ b/src/slang-nodes/YulSwitchStatement.js @@ -10,7 +10,7 @@ export class YulSwitchStatement extends SlangNode { cases; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.switchKeyword = ast.switchKeyword.text; this.expression = parse(ast.expression, parse, this.nextChildOffset); diff --git a/src/slang-nodes/YulValueCase.js b/src/slang-nodes/YulValueCase.js index 843a8e1c8..7abf0532b 100644 --- a/src/slang-nodes/YulValueCase.js +++ b/src/slang-nodes/YulValueCase.js @@ -7,7 +7,7 @@ export class YulValueCase extends SlangNode { body; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.caseKeyword = ast.caseKeyword.text; this.value = parse(ast.value, parse, this.nextChildOffset); diff --git a/src/slang-nodes/YulVariableAssignmentStatement.js b/src/slang-nodes/YulVariableAssignmentStatement.js index 9cbc4b552..423197387 100644 --- a/src/slang-nodes/YulVariableAssignmentStatement.js +++ b/src/slang-nodes/YulVariableAssignmentStatement.js @@ -7,7 +7,7 @@ export class YulVariableAssignmentStatement extends SlangNode { expression; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.names = parse(ast.names, parse, this.nextChildOffset); this.assignment = parse(ast.assignment, parse, this.nextChildOffset); diff --git a/src/slang-nodes/YulVariableDeclarationStatement.js b/src/slang-nodes/YulVariableDeclarationStatement.js index 400ed83ea..fda218e6a 100644 --- a/src/slang-nodes/YulVariableDeclarationStatement.js +++ b/src/slang-nodes/YulVariableDeclarationStatement.js @@ -7,7 +7,7 @@ export class YulVariableDeclarationStatement extends SlangNode { value; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.letKeyword = ast.letKeyword.text; this.names = ast.names.text; diff --git a/src/slang-nodes/YulVariableDeclarationValue.js b/src/slang-nodes/YulVariableDeclarationValue.js index 4ab935294..582cac527 100644 --- a/src/slang-nodes/YulVariableDeclarationValue.js +++ b/src/slang-nodes/YulVariableDeclarationValue.js @@ -5,7 +5,7 @@ export class YulVariableDeclarationValue extends SlangNode { expression; - constructor(ast, offset, parse, options) { + constructor(ast, offset, options, parse) { super(ast, offset); this.assignment = parse(ast.assignment, parse, this.nextChildOffset); this.expression = parse(ast.expression, parse, this.nextChildOffset); diff --git a/src/slangParser.js b/src/slangParser.js index 924bdd8d4..a40164559 100644 --- a/src/slangParser.js +++ b/src/slangParser.js @@ -9,7 +9,7 @@ import * as parsers from './slang-nodes/index.js'; const genericParseBuilder = (options) => (ast, parseFunction, offset = 0) => - new parsers[ast.cst.kind](ast, offset, parseFunction, options); + new parsers[ast.cst.kind](ast, offset, options, parseFunction); function parse(text, _parsers, options = _parsers) { const compiler = coerce(options.compiler); From 06ebc09fa80bf7bc85020a6db5ae81dcb93581a2 Mon Sep 17 00:00:00 2001 From: Klaus Date: Sun, 14 Jul 2024 11:19:07 +1200 Subject: [PATCH 068/160] remove parentheses from modifier invocations without arguments with the exception of constructors --- src/slang-nodes/ContractDefinition.js | 20 +++++++++++++++++++ src/slang-nodes/FallbackFunctionDefinition.js | 10 ++++++++++ src/slang-nodes/FunctionDefinition.js | 17 ++++++++++++++++ src/slang-nodes/ModifierInvocation.js | 9 +++++++-- src/slang-nodes/ReceiveFunctionDefinition.js | 10 ++++++++++ src/slang-nodes/UnnamedFunctionDefinition.js | 10 ++++++++++ tests/config/run-format-test.js | 4 +--- .../__snapshots__/format.test.js.snap | 5 +++-- .../format/FunctionDefinitions/format.test.js | 2 +- .../__snapshots__/format.test.js.snap | 5 +++-- .../format/ModifierInvocations/format.test.js | 2 +- 11 files changed, 83 insertions(+), 11 deletions(-) diff --git a/src/slang-nodes/ContractDefinition.js b/src/slang-nodes/ContractDefinition.js index 9af214640..92a92b9af 100644 --- a/src/slang-nodes/ContractDefinition.js +++ b/src/slang-nodes/ContractDefinition.js @@ -1,4 +1,6 @@ import { doc } from 'prettier'; +import coerce from 'semver/functions/coerce.js'; +import satisfies from 'semver/functions/satisfies.js'; import { SlangNode } from './SlangNode.js'; const { group, line } = doc.builders; @@ -29,9 +31,27 @@ export class ContractDefinition extends SlangNode { this.openBrace = ast.openBrace.text; this.members = parse(ast.members, parse, this.nextChildOffset); this.closeBrace = ast.closeBrace.text; + + this.cleanModifierInvocationArguments(options); this.initiateLoc(ast); } + cleanModifierInvocationArguments(options) { + // Older versions of Solidity defined a constructor as a function having + // the same name as the contract. + const compiler = coerce(options.compiler); + if (compiler && !satisfies(compiler, '>=0.5.0')) { + this.members.items.forEach((member) => { + if ( + member.variant.kind === 'FunctionDefinition' && + member.variant.name.variant !== this.name + ) { + member.variant.cleanModifierInvocationArguments(); + } + }); + } + } + print(path, print) { return [ group([ diff --git a/src/slang-nodes/FallbackFunctionDefinition.js b/src/slang-nodes/FallbackFunctionDefinition.js index 4e0116368..cb60d5ac9 100644 --- a/src/slang-nodes/FallbackFunctionDefinition.js +++ b/src/slang-nodes/FallbackFunctionDefinition.js @@ -21,9 +21,19 @@ export class FallbackFunctionDefinition extends SlangNode { ? parse(ast.returns, parse, this.nextChildOffset) : undefined; this.body = parse(ast.body, parse, this.nextChildOffset); + + this.cleanModifierInvocationArguments(); this.initiateLoc(ast); } + cleanModifierInvocationArguments() { + this.attributes.items.forEach((attribute) => { + if (attribute.variant.kind === 'ModifierInvocation') { + attribute.variant.cleanModifierInvocationArguments(); + } + }); + } + print(path, print) { return printFunction(this.fallbackKeyword, this, path, print); } diff --git a/src/slang-nodes/FunctionDefinition.js b/src/slang-nodes/FunctionDefinition.js index 6c942af6b..a8392f0bc 100644 --- a/src/slang-nodes/FunctionDefinition.js +++ b/src/slang-nodes/FunctionDefinition.js @@ -1,3 +1,5 @@ +import coerce from 'semver/functions/coerce.js'; +import satisfies from 'semver/functions/satisfies.js'; import { printFunction } from '../common/slang-helpers.js'; import { SlangNode } from './SlangNode.js'; @@ -24,9 +26,24 @@ export class FunctionDefinition extends SlangNode { ? parse(ast.returns, parse, this.nextChildOffset) : undefined; this.body = parse(ast.body, parse, this.nextChildOffset); + + // Older versions of Solidity defined a constructor as a function having + // the same name as the contract. + const compiler = coerce(options.compiler); + if (compiler && satisfies(compiler, '>=0.5.0')) { + this.cleanModifierInvocationArguments(); + } this.initiateLoc(ast); } + cleanModifierInvocationArguments() { + this.attributes.items.forEach((attribute) => { + if (attribute.variant.kind === 'ModifierInvocation') { + attribute.variant.cleanModifierInvocationArguments(); + } + }); + } + print(path, print) { return printFunction( [`${this.functionKeyword} `, path.call(print, 'name')], diff --git a/src/slang-nodes/ModifierInvocation.js b/src/slang-nodes/ModifierInvocation.js index d38488e46..78e3be44c 100644 --- a/src/slang-nodes/ModifierInvocation.js +++ b/src/slang-nodes/ModifierInvocation.js @@ -2,12 +2,15 @@ import { isComment } from '../common/slang-helpers.js'; import { SlangNode } from './SlangNode.js'; export class ModifierInvocation extends SlangNode { + #ast; + name; arguments; constructor(ast, offset, options, parse) { super(ast, offset); + this.#ast = ast; this.name = parse(ast.name, parse, this.nextChildOffset); this.arguments = ast.arguments ? parse(ast.arguments, parse, this.nextChildOffset) @@ -15,12 +18,14 @@ export class ModifierInvocation extends SlangNode { this.initiateLoc(ast); } - removeInvocationArguments() { + cleanModifierInvocationArguments() { if ( this.arguments && this.arguments.variant.kind === 'PositionalArgumentsDeclaration' && this.arguments.variant.arguments.items.length === 0 && // no arguments - !ast.arguments.variant.cst.children().some((child) => isComment(child)) // no comments + !this.#ast.arguments.variant.cst + .children() + .some((child) => isComment(child)) // no comments ) { this.arguments = undefined; } diff --git a/src/slang-nodes/ReceiveFunctionDefinition.js b/src/slang-nodes/ReceiveFunctionDefinition.js index 3155b2e3e..a9f46140d 100644 --- a/src/slang-nodes/ReceiveFunctionDefinition.js +++ b/src/slang-nodes/ReceiveFunctionDefinition.js @@ -16,9 +16,19 @@ export class ReceiveFunctionDefinition extends SlangNode { this.parameters = parse(ast.parameters, parse, this.nextChildOffset); this.attributes = parse(ast.attributes, parse, this.nextChildOffset); this.body = parse(ast.body, parse, this.nextChildOffset); + + this.cleanModifierInvocationArguments(); this.initiateLoc(ast); } + cleanModifierInvocationArguments() { + this.attributes.items.forEach((attribute) => { + if (attribute.variant.kind === 'ModifierInvocation') { + attribute.variant.cleanModifierInvocationArguments(); + } + }); + } + print(path, print) { return printFunction(this.receiveKeyword, this, path, print); } diff --git a/src/slang-nodes/UnnamedFunctionDefinition.js b/src/slang-nodes/UnnamedFunctionDefinition.js index 29fcd9279..86f6a3e39 100644 --- a/src/slang-nodes/UnnamedFunctionDefinition.js +++ b/src/slang-nodes/UnnamedFunctionDefinition.js @@ -16,9 +16,19 @@ export class UnnamedFunctionDefinition extends SlangNode { this.parameters = parse(ast.parameters, parse, this.nextChildOffset); this.attributes = parse(ast.attributes, parse, this.nextChildOffset); this.body = parse(ast.body, parse, this.nextChildOffset); + + this.cleanModifierInvocationArguments(); this.initiateLoc(ast); } + cleanModifierInvocationArguments() { + this.attributes.items.forEach((attribute) => { + if (attribute.variant.kind === 'ModifierInvocation') { + attribute.variant.cleanModifierInvocationArguments(); + } + }); + } + print(path, print) { return printFunction(this.functionKeyword, this, path, print); } diff --git a/tests/config/run-format-test.js b/tests/config/run-format-test.js index 2375dadde..8b5164dd3 100644 --- a/tests/config/run-format-test.js +++ b/tests/config/run-format-test.js @@ -45,11 +45,9 @@ const testsWithSlang = new Map( // "AllSolidityFeatures/AllSolidityFeatures.sol", // "AssemblyV0.4.26/Assembly.sol", // TODO: Report to Nomic Foundation? // "BasicIterator/BasicIterator.sol", // TODO: Fix solidity-parser comments - "Comments/Comments.sol", // TODO: finish Comments + // "Comments/Comments.sol", // TODO: finish Comments // "Etc/Etc.sol", // TODO: Comments for if Statements - // "FunctionDefinitions/FunctionDefinitions.sol", // TODO: remove () safely in modifiers without arguments // "IndexOf/IndexOf.sol", // TODO: Finish comments and file level functions - // "ModifierInvocations/ModifierInvocations.sol", ].map((fixture) => { const [file, testSlang = () => true] = Array.isArray(fixture) ? fixture diff --git a/tests/format/FunctionDefinitions/__snapshots__/format.test.js.snap b/tests/format/FunctionDefinitions/__snapshots__/format.test.js.snap index df0c891f8..0a2801fdc 100644 --- a/tests/format/FunctionDefinitions/__snapshots__/format.test.js.snap +++ b/tests/format/FunctionDefinitions/__snapshots__/format.test.js.snap @@ -1,8 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`FunctionDefinitions.sol format 1`] = ` +exports[`FunctionDefinitions.sol - {"compiler":"0.8.0"} format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +compiler: "0.8.0" +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/FunctionDefinitions/format.test.js b/tests/format/FunctionDefinitions/format.test.js index 2ae629864..875eca87d 100644 --- a/tests/format/FunctionDefinitions/format.test.js +++ b/tests/format/FunctionDefinitions/format.test.js @@ -1 +1 @@ -runFormatTest(import.meta, ['solidity-parse']); +runFormatTest(import.meta, ['slang'], { compiler: '0.8.0' }); diff --git a/tests/format/ModifierInvocations/__snapshots__/format.test.js.snap b/tests/format/ModifierInvocations/__snapshots__/format.test.js.snap index 4e84fd7ab..9b116c29d 100644 --- a/tests/format/ModifierInvocations/__snapshots__/format.test.js.snap +++ b/tests/format/ModifierInvocations/__snapshots__/format.test.js.snap @@ -1,8 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`ModifierInvocations.sol format 1`] = ` +exports[`ModifierInvocations.sol - {"compiler":"0.8.0"} format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +compiler: "0.8.0" +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/ModifierInvocations/format.test.js b/tests/format/ModifierInvocations/format.test.js index 2ae629864..875eca87d 100644 --- a/tests/format/ModifierInvocations/format.test.js +++ b/tests/format/ModifierInvocations/format.test.js @@ -1 +1 @@ -runFormatTest(import.meta, ['solidity-parse']); +runFormatTest(import.meta, ['slang'], { compiler: '0.8.0' }); From 1ac663a0315696d05c0f69c0ef134a9c31d80c76 Mon Sep 17 00:00:00 2001 From: Klaus Date: Sun, 14 Jul 2024 21:11:32 +1200 Subject: [PATCH 069/160] genericParse function no longer requires to have a parseFunction function passed across the node tree --- src/slang-nodes/AdditiveExpression.js | 8 +--- src/slang-nodes/AndExpression.js | 4 +- src/slang-nodes/ArgumentsDeclaration.js | 2 +- src/slang-nodes/ArrayExpression.js | 2 +- src/slang-nodes/ArrayTypeName.js | 6 +-- src/slang-nodes/ArrayValues.js | 4 +- src/slang-nodes/AssemblyFlags.js | 4 +- src/slang-nodes/AssemblyFlagsDeclaration.js | 2 +- src/slang-nodes/AssemblyStatement.js | 10 ++-- src/slang-nodes/AssignmentExpression.js | 4 +- src/slang-nodes/BitwiseAndExpression.js | 8 +--- src/slang-nodes/BitwiseOrExpression.js | 8 +--- src/slang-nodes/BitwiseXorExpression.js | 8 +--- src/slang-nodes/Block.js | 2 +- src/slang-nodes/CallOptions.js | 4 +- src/slang-nodes/CallOptionsExpression.js | 4 +- src/slang-nodes/CatchClause.js | 6 +-- src/slang-nodes/CatchClauseError.js | 2 +- src/slang-nodes/CatchClauses.js | 4 +- src/slang-nodes/ComparisonExpression.js | 4 +- src/slang-nodes/ConditionalExpression.js | 14 ++---- src/slang-nodes/ConstantDefinition.js | 4 +- src/slang-nodes/ConstructorAttribute.js | 2 +- src/slang-nodes/ConstructorAttributes.js | 2 +- src/slang-nodes/ConstructorDefinition.js | 6 +-- src/slang-nodes/ContractDefinition.js | 4 +- src/slang-nodes/ContractMember.js | 2 +- src/slang-nodes/ContractMembers.js | 4 +- src/slang-nodes/DecimalNumberExpression.js | 4 +- src/slang-nodes/DoWhileStatement.js | 4 +- src/slang-nodes/ElementaryType.js | 2 +- src/slang-nodes/ElseBranch.js | 2 +- src/slang-nodes/EmitStatement.js | 4 +- src/slang-nodes/EnumDefinition.js | 2 +- src/slang-nodes/EqualityExpression.js | 4 +- src/slang-nodes/ErrorDefinition.js | 2 +- src/slang-nodes/ErrorParameter.js | 2 +- src/slang-nodes/ErrorParameters.js | 4 +- src/slang-nodes/ErrorParametersDeclaration.js | 2 +- src/slang-nodes/EventDefinition.js | 2 +- src/slang-nodes/EventParameter.js | 2 +- src/slang-nodes/EventParameters.js | 4 +- src/slang-nodes/EventParametersDeclaration.js | 2 +- src/slang-nodes/ExperimentalFeature.js | 3 +- src/slang-nodes/ExperimentalPragma.js | 8 +--- src/slang-nodes/ExponentiationExpression.js | 4 +- src/slang-nodes/Expression.js | 2 +- src/slang-nodes/ExpressionStatement.js | 2 +- src/slang-nodes/FallbackFunctionAttribute.js | 2 +- src/slang-nodes/FallbackFunctionAttributes.js | 2 +- src/slang-nodes/FallbackFunctionDefinition.js | 8 ++-- src/slang-nodes/ForStatement.js | 12 ++--- src/slang-nodes/ForStatementCondition.js | 2 +- src/slang-nodes/ForStatementInitialization.js | 2 +- src/slang-nodes/FunctionAttribute.js | 2 +- src/slang-nodes/FunctionAttributes.js | 2 +- src/slang-nodes/FunctionBody.js | 2 +- src/slang-nodes/FunctionCallExpression.js | 4 +- src/slang-nodes/FunctionDefinition.js | 10 ++-- src/slang-nodes/FunctionType.js | 6 +-- src/slang-nodes/FunctionTypeAttributes.js | 2 +- src/slang-nodes/HexNumberExpression.js | 4 +- src/slang-nodes/HexStringLiterals.js | 4 +- src/slang-nodes/IfStatement.js | 6 +-- src/slang-nodes/ImportClause.js | 2 +- src/slang-nodes/ImportDeconstruction.js | 4 +- src/slang-nodes/ImportDeconstructionSymbol.js | 4 +- .../ImportDeconstructionSymbols.js | 4 +- src/slang-nodes/ImportDirective.js | 2 +- src/slang-nodes/IndexAccessEnd.js | 4 +- src/slang-nodes/IndexAccessExpression.js | 10 ++-- src/slang-nodes/InheritanceSpecifier.js | 2 +- src/slang-nodes/InheritanceType.js | 4 +- src/slang-nodes/InheritanceTypes.js | 4 +- src/slang-nodes/InterfaceDefinition.js | 4 +- src/slang-nodes/InterfaceMembers.js | 4 +- src/slang-nodes/LibraryDefinition.js | 2 +- src/slang-nodes/LibraryMembers.js | 4 +- src/slang-nodes/MappingKey.js | 2 +- src/slang-nodes/MappingKeyType.js | 2 +- src/slang-nodes/MappingType.js | 4 +- src/slang-nodes/MappingValue.js | 2 +- src/slang-nodes/MemberAccessExpression.js | 4 +- src/slang-nodes/ModifierAttribute.js | 2 +- src/slang-nodes/ModifierAttributes.js | 2 +- src/slang-nodes/ModifierDefinition.js | 47 ++++++++++--------- src/slang-nodes/ModifierInvocation.js | 4 +- src/slang-nodes/MultiplicativeExpression.js | 4 +- src/slang-nodes/NamedArgument.js | 2 +- src/slang-nodes/NamedArgumentGroup.js | 2 +- src/slang-nodes/NamedArguments.js | 4 +- src/slang-nodes/NamedArgumentsDeclaration.js | 2 +- src/slang-nodes/NamedImport.js | 4 +- src/slang-nodes/NewExpression.js | 2 +- src/slang-nodes/OrExpression.js | 8 +--- src/slang-nodes/OverridePaths.js | 4 +- src/slang-nodes/OverridePathsDeclaration.js | 2 +- src/slang-nodes/OverrideSpecifier.js | 2 +- src/slang-nodes/Parameter.js | 4 +- src/slang-nodes/Parameters.js | 4 +- src/slang-nodes/ParametersDeclaration.js | 2 +- src/slang-nodes/PathImport.js | 6 +-- src/slang-nodes/PositionalArguments.js | 4 +- .../PositionalArgumentsDeclaration.js | 2 +- src/slang-nodes/PostfixExpression.js | 2 +- src/slang-nodes/Pragma.js | 12 +---- src/slang-nodes/PragmaDirective.js | 3 +- src/slang-nodes/PrefixExpression.js | 2 +- src/slang-nodes/ReceiveFunctionAttribute.js | 2 +- src/slang-nodes/ReceiveFunctionAttributes.js | 2 +- src/slang-nodes/ReceiveFunctionDefinition.js | 6 +-- src/slang-nodes/ReturnStatement.js | 2 +- src/slang-nodes/ReturnsDeclaration.js | 2 +- src/slang-nodes/RevertStatement.js | 6 +-- src/slang-nodes/ShiftExpression.js | 4 +- src/slang-nodes/SourceUnit.js | 8 +--- src/slang-nodes/SourceUnitMember.js | 36 +------------- src/slang-nodes/SourceUnitMembers.js | 5 +- src/slang-nodes/StateVariableAttribute.js | 2 +- src/slang-nodes/StateVariableAttributes.js | 4 +- src/slang-nodes/StateVariableDefinition.js | 8 ++-- .../StateVariableDefinitionValue.js | 2 +- src/slang-nodes/Statement.js | 2 +- src/slang-nodes/Statements.js | 4 +- src/slang-nodes/StringExpression.js | 2 +- src/slang-nodes/StringLiterals.js | 4 +- src/slang-nodes/StructDefinition.js | 2 +- src/slang-nodes/StructMember.js | 2 +- src/slang-nodes/StructMembers.js | 4 +- src/slang-nodes/TryStatement.js | 8 ++-- src/slang-nodes/TupleDeconstructionElement.js | 2 +- .../TupleDeconstructionElements.js | 4 +- .../TupleDeconstructionStatement.js | 4 +- src/slang-nodes/TupleExpression.js | 2 +- src/slang-nodes/TupleMember.js | 2 +- src/slang-nodes/TupleValue.js | 2 +- src/slang-nodes/TupleValues.js | 4 +- src/slang-nodes/TypeExpression.js | 2 +- src/slang-nodes/TypeName.js | 2 +- src/slang-nodes/TypedTupleMember.js | 4 +- src/slang-nodes/UncheckedBlock.js | 2 +- src/slang-nodes/UnicodeStringLiterals.js | 4 +- src/slang-nodes/UnnamedFunctionAttribute.js | 2 +- src/slang-nodes/UnnamedFunctionAttributes.js | 2 +- src/slang-nodes/UnnamedFunctionDefinition.js | 6 +-- src/slang-nodes/UntypedTupleMember.js | 2 +- .../UserDefinedValueTypeDefinition.js | 2 +- src/slang-nodes/UsingAlias.js | 2 +- src/slang-nodes/UsingClause.js | 2 +- src/slang-nodes/UsingDeconstruction.js | 2 +- src/slang-nodes/UsingDeconstructionSymbol.js | 6 +-- src/slang-nodes/UsingDeconstructionSymbols.js | 4 +- src/slang-nodes/UsingDirective.js | 4 +- src/slang-nodes/UsingTarget.js | 2 +- .../VariableDeclarationStatement.js | 8 ++-- src/slang-nodes/VariableDeclarationType.js | 2 +- src/slang-nodes/VariableDeclarationValue.js | 2 +- src/slang-nodes/VersionComparator.js | 2 +- src/slang-nodes/VersionExpression.js | 2 +- src/slang-nodes/VersionExpressionSet.js | 4 +- src/slang-nodes/VersionExpressionSets.js | 4 +- src/slang-nodes/VersionPragma.js | 2 +- src/slang-nodes/VersionRange.js | 4 +- src/slang-nodes/WhileStatement.js | 4 +- src/slang-nodes/YulArguments.js | 4 +- src/slang-nodes/YulAssignmentOperator.js | 2 +- src/slang-nodes/YulAssignmentStatement.js | 6 +-- src/slang-nodes/YulBlock.js | 2 +- src/slang-nodes/YulDefaultCase.js | 2 +- src/slang-nodes/YulExpression.js | 2 +- src/slang-nodes/YulForStatement.js | 12 ++--- src/slang-nodes/YulFunctionCallExpression.js | 4 +- src/slang-nodes/YulFunctionDefinition.js | 6 +-- src/slang-nodes/YulIfStatement.js | 4 +- src/slang-nodes/YulLiteral.js | 2 +- src/slang-nodes/YulParametersDeclaration.js | 2 +- src/slang-nodes/YulPath.js | 4 +- src/slang-nodes/YulPaths.js | 4 +- src/slang-nodes/YulReturnsDeclaration.js | 2 +- src/slang-nodes/YulStatement.js | 2 +- src/slang-nodes/YulStatements.js | 4 +- src/slang-nodes/YulSwitchCase.js | 2 +- src/slang-nodes/YulSwitchCases.js | 4 +- src/slang-nodes/YulSwitchStatement.js | 4 +- src/slang-nodes/YulValueCase.js | 4 +- .../YulVariableAssignmentStatement.js | 6 +-- .../YulVariableDeclarationStatement.js | 4 +- .../YulVariableDeclarationValue.js | 4 +- src/slangParser.js | 11 +++-- src/slangPrinter.js | 12 +---- 190 files changed, 302 insertions(+), 499 deletions(-) diff --git a/src/slang-nodes/AdditiveExpression.js b/src/slang-nodes/AdditiveExpression.js index f8ce0d5d5..313cace30 100644 --- a/src/slang-nodes/AdditiveExpression.js +++ b/src/slang-nodes/AdditiveExpression.js @@ -13,13 +13,9 @@ export class AdditiveExpression extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.leftOperand = tryToHug( - parse(ast.leftOperand, parse, this.nextChildOffset) - ); + this.leftOperand = tryToHug(parse(ast.leftOperand, this.nextChildOffset)); this.operator = ast.operator.text; - this.rightOperand = tryToHug( - parse(ast.rightOperand, parse, this.nextChildOffset) - ); + this.rightOperand = tryToHug(parse(ast.rightOperand, this.nextChildOffset)); this.initiateLoc(ast); } diff --git a/src/slang-nodes/AndExpression.js b/src/slang-nodes/AndExpression.js index faca0d3b7..57751941e 100644 --- a/src/slang-nodes/AndExpression.js +++ b/src/slang-nodes/AndExpression.js @@ -10,9 +10,9 @@ export class AndExpression extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.leftOperand = parse(ast.leftOperand, parse, this.nextChildOffset); + this.leftOperand = parse(ast.leftOperand, this.nextChildOffset); this.operator = ast.operator.text; - this.rightOperand = parse(ast.rightOperand, parse, this.nextChildOffset); + this.rightOperand = parse(ast.rightOperand, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/ArgumentsDeclaration.js b/src/slang-nodes/ArgumentsDeclaration.js index 57fdb376c..5e4e14963 100644 --- a/src/slang-nodes/ArgumentsDeclaration.js +++ b/src/slang-nodes/ArgumentsDeclaration.js @@ -5,7 +5,7 @@ export class ArgumentsDeclaration extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.variant = parse(ast.variant, parse, this.nextChildOffset); + this.variant = parse(ast.variant, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/ArrayExpression.js b/src/slang-nodes/ArrayExpression.js index 0a12ef40d..93fc4e361 100644 --- a/src/slang-nodes/ArrayExpression.js +++ b/src/slang-nodes/ArrayExpression.js @@ -13,7 +13,7 @@ export class ArrayExpression extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.openBracket = ast.openBracket.text; - this.items = parse(ast.items, parse, this.nextChildOffset); + this.items = parse(ast.items, this.nextChildOffset); this.closeBracket = ast.closeBracket.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/ArrayTypeName.js b/src/slang-nodes/ArrayTypeName.js index 0c24a25a6..618e61a92 100644 --- a/src/slang-nodes/ArrayTypeName.js +++ b/src/slang-nodes/ArrayTypeName.js @@ -11,11 +11,9 @@ export class ArrayTypeName extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.operand = parse(ast.operand, parse, this.nextChildOffset); + this.operand = parse(ast.operand, this.nextChildOffset); this.openBracket = ast.openBracket.text; - this.index = ast.index - ? parse(ast.index, parse, this.nextChildOffset) - : undefined; + this.index = ast.index ? parse(ast.index, this.nextChildOffset) : undefined; this.closeBracket = ast.closeBracket.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/ArrayValues.js b/src/slang-nodes/ArrayValues.js index a967d7872..b070521ef 100644 --- a/src/slang-nodes/ArrayValues.js +++ b/src/slang-nodes/ArrayValues.js @@ -8,9 +8,7 @@ export class ArrayValues extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.items = ast.items.map((item) => - parse(item, parse, this.nextChildOffset) - ); + this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); this.separators = ast.separators.map((separator) => separator.text); this.initiateLoc(ast); } diff --git a/src/slang-nodes/AssemblyFlags.js b/src/slang-nodes/AssemblyFlags.js index d0d2743d2..aad4032df 100644 --- a/src/slang-nodes/AssemblyFlags.js +++ b/src/slang-nodes/AssemblyFlags.js @@ -8,9 +8,7 @@ export class AssemblyFlags extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.items = ast.items.map((item) => - parse(item, parse, this.nextChildOffset) - ); + this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); this.separators = ast.separators.map((separator) => separator.text); this.initiateLoc(ast); } diff --git a/src/slang-nodes/AssemblyFlagsDeclaration.js b/src/slang-nodes/AssemblyFlagsDeclaration.js index 2e1b53942..acc1b4f55 100644 --- a/src/slang-nodes/AssemblyFlagsDeclaration.js +++ b/src/slang-nodes/AssemblyFlagsDeclaration.js @@ -10,7 +10,7 @@ export class AssemblyFlagsDeclaration extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.openParen = ast.openParen.text; - this.flags = parse(ast.flags, parse, this.nextChildOffset); + this.flags = parse(ast.flags, this.nextChildOffset); this.closeParen = ast.closeParen.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/AssemblyStatement.js b/src/slang-nodes/AssemblyStatement.js index 6a9c786c5..8ef7041e1 100644 --- a/src/slang-nodes/AssemblyStatement.js +++ b/src/slang-nodes/AssemblyStatement.js @@ -12,13 +12,9 @@ export class AssemblyStatement extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.assemblyKeyword = ast.assemblyKeyword.text; - this.label = ast.label - ? parse(ast.label, parse, this.nextChildOffset) - : undefined; - this.flags = ast.flags - ? parse(ast.flags, parse, this.nextChildOffset) - : undefined; - this.body = parse(ast.body, parse, this.nextChildOffset); + this.label = ast.label ? parse(ast.label, this.nextChildOffset) : undefined; + this.flags = ast.flags ? parse(ast.flags, this.nextChildOffset) : undefined; + this.body = parse(ast.body, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/AssignmentExpression.js b/src/slang-nodes/AssignmentExpression.js index 6ff7127cc..4378c3c84 100644 --- a/src/slang-nodes/AssignmentExpression.js +++ b/src/slang-nodes/AssignmentExpression.js @@ -13,9 +13,9 @@ export class AssignmentExpression extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.leftOperand = parse(ast.leftOperand, parse, this.nextChildOffset); + this.leftOperand = parse(ast.leftOperand, this.nextChildOffset); this.operator = ast.operator.text; - this.rightOperand = parse(ast.rightOperand, parse, this.nextChildOffset); + this.rightOperand = parse(ast.rightOperand, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/BitwiseAndExpression.js b/src/slang-nodes/BitwiseAndExpression.js index 4a23e6d3b..a8343aef5 100644 --- a/src/slang-nodes/BitwiseAndExpression.js +++ b/src/slang-nodes/BitwiseAndExpression.js @@ -13,13 +13,9 @@ export class BitwiseAndExpression extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.leftOperand = tryToHug( - parse(ast.leftOperand, parse, this.nextChildOffset) - ); + this.leftOperand = tryToHug(parse(ast.leftOperand, this.nextChildOffset)); this.operator = ast.operator.text; - this.rightOperand = tryToHug( - parse(ast.rightOperand, parse, this.nextChildOffset) - ); + this.rightOperand = tryToHug(parse(ast.rightOperand, this.nextChildOffset)); this.initiateLoc(ast); } diff --git a/src/slang-nodes/BitwiseOrExpression.js b/src/slang-nodes/BitwiseOrExpression.js index ee1d3fb38..1c2914373 100644 --- a/src/slang-nodes/BitwiseOrExpression.js +++ b/src/slang-nodes/BitwiseOrExpression.js @@ -23,13 +23,9 @@ export class BitwiseOrExpression extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.leftOperand = tryToHug( - parse(ast.leftOperand, parse, this.nextChildOffset) - ); + this.leftOperand = tryToHug(parse(ast.leftOperand, this.nextChildOffset)); this.operator = ast.operator.text; - this.rightOperand = tryToHug( - parse(ast.rightOperand, parse, this.nextChildOffset) - ); + this.rightOperand = tryToHug(parse(ast.rightOperand, this.nextChildOffset)); this.initiateLoc(ast); } diff --git a/src/slang-nodes/BitwiseXorExpression.js b/src/slang-nodes/BitwiseXorExpression.js index 8d3b18d2b..0c4470fa8 100644 --- a/src/slang-nodes/BitwiseXorExpression.js +++ b/src/slang-nodes/BitwiseXorExpression.js @@ -13,13 +13,9 @@ export class BitwiseXorExpression extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.leftOperand = tryToHug( - parse(ast.leftOperand, parse, this.nextChildOffset) - ); + this.leftOperand = tryToHug(parse(ast.leftOperand, this.nextChildOffset)); this.operator = ast.operator.text; - this.rightOperand = tryToHug( - parse(ast.rightOperand, parse, this.nextChildOffset) - ); + this.rightOperand = tryToHug(parse(ast.rightOperand, this.nextChildOffset)); this.initiateLoc(ast); } diff --git a/src/slang-nodes/Block.js b/src/slang-nodes/Block.js index 6e8b7debc..810cf0453 100644 --- a/src/slang-nodes/Block.js +++ b/src/slang-nodes/Block.js @@ -10,7 +10,7 @@ export class Block extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.openBrace = ast.openBrace.text; - this.statements = parse(ast.statements, parse, this.nextChildOffset); + this.statements = parse(ast.statements, this.nextChildOffset); this.closeBrace = ast.closeBrace.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/CallOptions.js b/src/slang-nodes/CallOptions.js index 90690c7f4..231dd1767 100644 --- a/src/slang-nodes/CallOptions.js +++ b/src/slang-nodes/CallOptions.js @@ -11,9 +11,7 @@ export class CallOptions extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.items = ast.items.map((item) => - parse(item, parse, this.nextChildOffset) - ); + this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); this.separators = ast.separators.map((separator) => separator.text); this.initiateLoc(ast); } diff --git a/src/slang-nodes/CallOptionsExpression.js b/src/slang-nodes/CallOptionsExpression.js index e999dd5f5..40d62508c 100644 --- a/src/slang-nodes/CallOptionsExpression.js +++ b/src/slang-nodes/CallOptionsExpression.js @@ -11,9 +11,9 @@ export class CallOptionsExpression extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.operand = parse(ast.operand, parse, this.nextChildOffset); + this.operand = parse(ast.operand, this.nextChildOffset); this.openBrace = ast.openBrace.text; - this.options = parse(ast.options, parse, this.nextChildOffset); + this.options = parse(ast.options, this.nextChildOffset); this.closeBrace = ast.closeBrace.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/CatchClause.js b/src/slang-nodes/CatchClause.js index 0bfe834f4..17c0a2a4b 100644 --- a/src/slang-nodes/CatchClause.js +++ b/src/slang-nodes/CatchClause.js @@ -10,10 +10,8 @@ export class CatchClause extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.catchKeyword = ast.catchKeyword.text; - this.error = ast.error - ? parse(ast.error, parse, this.nextChildOffset) - : undefined; - this.body = parse(ast.body, parse, this.nextChildOffset); + this.error = ast.error ? parse(ast.error, this.nextChildOffset) : undefined; + this.body = parse(ast.body, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/CatchClauseError.js b/src/slang-nodes/CatchClauseError.js index c3fab705d..e2f3f5d58 100644 --- a/src/slang-nodes/CatchClauseError.js +++ b/src/slang-nodes/CatchClauseError.js @@ -11,7 +11,7 @@ export class CatchClauseError extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.name = ast.name?.text ?? ''; - this.parameters = parse(ast.parameters, parse, this.nextChildOffset); + this.parameters = parse(ast.parameters, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/CatchClauses.js b/src/slang-nodes/CatchClauses.js index 2f29db1ef..36e5597c0 100644 --- a/src/slang-nodes/CatchClauses.js +++ b/src/slang-nodes/CatchClauses.js @@ -8,9 +8,7 @@ export class CatchClauses extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.items = ast.items.map((item) => - parse(item, parse, this.nextChildOffset) - ); + this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); this.initiateLoc(ast); } diff --git a/src/slang-nodes/ComparisonExpression.js b/src/slang-nodes/ComparisonExpression.js index 6def23b09..18940a683 100644 --- a/src/slang-nodes/ComparisonExpression.js +++ b/src/slang-nodes/ComparisonExpression.js @@ -10,9 +10,9 @@ export class ComparisonExpression extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.leftOperand = parse(ast.leftOperand, parse, this.nextChildOffset); + this.leftOperand = parse(ast.leftOperand, this.nextChildOffset); this.operator = ast.operator.text; - this.rightOperand = parse(ast.rightOperand, parse, this.nextChildOffset); + this.rightOperand = parse(ast.rightOperand, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/ConditionalExpression.js b/src/slang-nodes/ConditionalExpression.js index 74eafec2a..f3b486849 100644 --- a/src/slang-nodes/ConditionalExpression.js +++ b/src/slang-nodes/ConditionalExpression.js @@ -99,7 +99,7 @@ export class ConditionalExpression extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.operand = parse(ast.operand, parse, this.nextChildOffset); + this.operand = parse(ast.operand, this.nextChildOffset); // TODO: while the behaviour is not stable, it should be behind the // experimentalTernaries flag. @@ -119,17 +119,9 @@ export class ConditionalExpression extends SlangNode { } this.questionMark = ast.questionMark.text; - this.trueExpression = parse( - ast.trueExpression, - parse, - this.nextChildOffset - ); + this.trueExpression = parse(ast.trueExpression, this.nextChildOffset); this.colon = ast.colon.text; - this.falseExpression = parse( - ast.falseExpression, - parse, - this.nextChildOffset - ); + this.falseExpression = parse(ast.falseExpression, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/ConstantDefinition.js b/src/slang-nodes/ConstantDefinition.js index 34d331fa5..c9ee7ef96 100644 --- a/src/slang-nodes/ConstantDefinition.js +++ b/src/slang-nodes/ConstantDefinition.js @@ -15,11 +15,11 @@ export class ConstantDefinition extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.typeName = parse(ast.typeName, parse, this.nextChildOffset); + this.typeName = parse(ast.typeName, this.nextChildOffset); this.constantKeyword = ast.constantKeyword.text; this.name = ast.name.text; this.equal = ast.equal.text; - this.value = parse(ast.value, parse, this.nextChildOffset); + this.value = parse(ast.value, this.nextChildOffset); this.semicolon = ast.semicolon.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/ConstructorAttribute.js b/src/slang-nodes/ConstructorAttribute.js index fd720bd3a..590de7ec2 100644 --- a/src/slang-nodes/ConstructorAttribute.js +++ b/src/slang-nodes/ConstructorAttribute.js @@ -8,7 +8,7 @@ export class ConstructorAttribute extends SlangNode { this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, parse, this.nextChildOffset); + : parse(ast.variant, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/ConstructorAttributes.js b/src/slang-nodes/ConstructorAttributes.js index ff6785fac..ad26afe1b 100644 --- a/src/slang-nodes/ConstructorAttributes.js +++ b/src/slang-nodes/ConstructorAttributes.js @@ -10,7 +10,7 @@ export class ConstructorAttributes extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items - .map((item) => parse(item, parse, this.nextChildOffset)) + .map((item) => parse(item, this.nextChildOffset)) .sort(sortFunctionAttributes); this.initiateLoc(ast); } diff --git a/src/slang-nodes/ConstructorDefinition.js b/src/slang-nodes/ConstructorDefinition.js index 5d494fddc..9e5629540 100644 --- a/src/slang-nodes/ConstructorDefinition.js +++ b/src/slang-nodes/ConstructorDefinition.js @@ -13,9 +13,9 @@ export class ConstructorDefinition extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.constructorKeyword = ast.constructorKeyword.text; - this.parameters = parse(ast.parameters, parse, this.nextChildOffset); - this.attributes = parse(ast.attributes, parse, this.nextChildOffset); - this.body = parse(ast.body, parse, this.nextChildOffset); + this.parameters = parse(ast.parameters, this.nextChildOffset); + this.attributes = parse(ast.attributes, this.nextChildOffset); + this.body = parse(ast.body, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/ContractDefinition.js b/src/slang-nodes/ContractDefinition.js index 92a92b9af..e27c607f2 100644 --- a/src/slang-nodes/ContractDefinition.js +++ b/src/slang-nodes/ContractDefinition.js @@ -26,10 +26,10 @@ export class ContractDefinition extends SlangNode { this.contractKeyword = ast.contractKeyword.text; this.name = ast.name.text; this.inheritance = ast.inheritance - ? parse(ast.inheritance, parse, this.nextChildOffset) + ? parse(ast.inheritance, this.nextChildOffset) : undefined; this.openBrace = ast.openBrace.text; - this.members = parse(ast.members, parse, this.nextChildOffset); + this.members = parse(ast.members, this.nextChildOffset); this.closeBrace = ast.closeBrace.text; this.cleanModifierInvocationArguments(options); diff --git a/src/slang-nodes/ContractMember.js b/src/slang-nodes/ContractMember.js index d5687e85e..9db5a5bbe 100644 --- a/src/slang-nodes/ContractMember.js +++ b/src/slang-nodes/ContractMember.js @@ -5,7 +5,7 @@ export class ContractMember extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.variant = parse(ast.variant, parse, this.nextChildOffset); + this.variant = parse(ast.variant, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/ContractMembers.js b/src/slang-nodes/ContractMembers.js index 1af44fe81..f70299ff6 100644 --- a/src/slang-nodes/ContractMembers.js +++ b/src/slang-nodes/ContractMembers.js @@ -13,9 +13,7 @@ export class ContractMembers extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.items = ast.items.map((item) => - parse(item, parse, this.nextChildOffset) - ); + this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); this.initiateLoc(ast); } diff --git a/src/slang-nodes/DecimalNumberExpression.js b/src/slang-nodes/DecimalNumberExpression.js index 18d5d1e69..7d9c5d217 100644 --- a/src/slang-nodes/DecimalNumberExpression.js +++ b/src/slang-nodes/DecimalNumberExpression.js @@ -8,9 +8,7 @@ export class DecimalNumberExpression extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.literal = ast.literal.text; - this.unit = ast.unit - ? parse(ast.unit, parse, this.nextChildOffset) - : undefined; + this.unit = ast.unit ? parse(ast.unit, this.nextChildOffset) : undefined; this.initiateLoc(ast); } diff --git a/src/slang-nodes/DoWhileStatement.js b/src/slang-nodes/DoWhileStatement.js index 7c27f23a0..c1d0e037c 100644 --- a/src/slang-nodes/DoWhileStatement.js +++ b/src/slang-nodes/DoWhileStatement.js @@ -27,10 +27,10 @@ export class DoWhileStatement extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.doKeyword = ast.doKeyword.text; - this.body = parse(ast.body, parse, this.nextChildOffset); + this.body = parse(ast.body, this.nextChildOffset); this.whileKeyword = ast.whileKeyword.text; this.openParen = ast.openParen.text; - this.condition = parse(ast.condition, parse, this.nextChildOffset); + this.condition = parse(ast.condition, this.nextChildOffset); this.closeParen = ast.closeParen.text; this.semicolon = ast.semicolon.text; this.initiateLoc(ast); diff --git a/src/slang-nodes/ElementaryType.js b/src/slang-nodes/ElementaryType.js index 2b7a9d337..cc2f026de 100644 --- a/src/slang-nodes/ElementaryType.js +++ b/src/slang-nodes/ElementaryType.js @@ -8,7 +8,7 @@ export class ElementaryType extends SlangNode { this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, parse, this.nextChildOffset); + : parse(ast.variant, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/ElseBranch.js b/src/slang-nodes/ElseBranch.js index 26ce5266d..826b8545b 100644 --- a/src/slang-nodes/ElseBranch.js +++ b/src/slang-nodes/ElseBranch.js @@ -16,7 +16,7 @@ export class ElseBranch extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.elseKeyword = ast.elseKeyword.text; - this.body = parse(ast.body, parse, this.nextChildOffset); + this.body = parse(ast.body, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/EmitStatement.js b/src/slang-nodes/EmitStatement.js index 991957aa2..63ecd5835 100644 --- a/src/slang-nodes/EmitStatement.js +++ b/src/slang-nodes/EmitStatement.js @@ -12,8 +12,8 @@ export class EmitStatement extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.emitKeyword = ast.emitKeyword.text; - this.event = parse(ast.event, parse, this.nextChildOffset); - this.arguments = parse(ast.arguments, parse, this.nextChildOffset); + this.event = parse(ast.event, this.nextChildOffset); + this.arguments = parse(ast.arguments, this.nextChildOffset); this.semicolon = ast.semicolon.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/EnumDefinition.js b/src/slang-nodes/EnumDefinition.js index b4b77cbfa..fb49a4a32 100644 --- a/src/slang-nodes/EnumDefinition.js +++ b/src/slang-nodes/EnumDefinition.js @@ -16,7 +16,7 @@ export class EnumDefinition extends SlangNode { this.enumKeyword = ast.enumKeyword.text; this.name = ast.name.text; this.openBrace = ast.openBrace.text; - this.members = parse(ast.members, parse, this.nextChildOffset); + this.members = parse(ast.members, this.nextChildOffset); this.closeBrace = ast.closeBrace.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/EqualityExpression.js b/src/slang-nodes/EqualityExpression.js index b8667cf0c..df6a148ee 100644 --- a/src/slang-nodes/EqualityExpression.js +++ b/src/slang-nodes/EqualityExpression.js @@ -10,9 +10,9 @@ export class EqualityExpression extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.leftOperand = parse(ast.leftOperand, parse, this.nextChildOffset); + this.leftOperand = parse(ast.leftOperand, this.nextChildOffset); this.operator = ast.operator.text; - this.rightOperand = parse(ast.rightOperand, parse, this.nextChildOffset); + this.rightOperand = parse(ast.rightOperand, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/ErrorDefinition.js b/src/slang-nodes/ErrorDefinition.js index aa6384d33..c5caf0794 100644 --- a/src/slang-nodes/ErrorDefinition.js +++ b/src/slang-nodes/ErrorDefinition.js @@ -13,7 +13,7 @@ export class ErrorDefinition extends SlangNode { super(ast, offset); this.errorKeyword = ast.errorKeyword.text; this.name = ast.name.text; - this.members = parse(ast.members, parse, this.nextChildOffset); + this.members = parse(ast.members, this.nextChildOffset); this.semicolon = ast.semicolon.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/ErrorParameter.js b/src/slang-nodes/ErrorParameter.js index c6a29d00b..7e0958106 100644 --- a/src/slang-nodes/ErrorParameter.js +++ b/src/slang-nodes/ErrorParameter.js @@ -11,7 +11,7 @@ export class ErrorParameter extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.typeName = parse(ast.typeName, parse, this.nextChildOffset); + this.typeName = parse(ast.typeName, this.nextChildOffset); this.name = ast.name?.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/ErrorParameters.js b/src/slang-nodes/ErrorParameters.js index 3658df411..f2f006ee4 100644 --- a/src/slang-nodes/ErrorParameters.js +++ b/src/slang-nodes/ErrorParameters.js @@ -8,9 +8,7 @@ export class ErrorParameters extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.items = ast.items.map((item) => - parse(item, parse, this.nextChildOffset) - ); + this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); this.separators = ast.separators.map((separator) => separator.text); this.initiateLoc(ast); } diff --git a/src/slang-nodes/ErrorParametersDeclaration.js b/src/slang-nodes/ErrorParametersDeclaration.js index ddd001f79..599c253a5 100644 --- a/src/slang-nodes/ErrorParametersDeclaration.js +++ b/src/slang-nodes/ErrorParametersDeclaration.js @@ -10,7 +10,7 @@ export class ErrorParametersDeclaration extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.openParen = ast.openParen.text; - this.parameters = parse(ast.parameters, parse, this.nextChildOffset); + this.parameters = parse(ast.parameters, this.nextChildOffset); this.closeParen = ast.closeParen.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/EventDefinition.js b/src/slang-nodes/EventDefinition.js index fa47eb435..7f2987483 100644 --- a/src/slang-nodes/EventDefinition.js +++ b/src/slang-nodes/EventDefinition.js @@ -15,7 +15,7 @@ export class EventDefinition extends SlangNode { super(ast, offset); this.eventKeyword = ast.eventKeyword.text; this.name = ast.name.text; - this.parameters = parse(ast.parameters, parse, this.nextChildOffset); + this.parameters = parse(ast.parameters, this.nextChildOffset); this.anonymousKeyword = ast.anonymousKeyword?.text; this.semicolon = ast.semicolon.text; this.initiateLoc(ast); diff --git a/src/slang-nodes/EventParameter.js b/src/slang-nodes/EventParameter.js index a2c5cddb7..bcd1779e9 100644 --- a/src/slang-nodes/EventParameter.js +++ b/src/slang-nodes/EventParameter.js @@ -9,7 +9,7 @@ export class EventParameter extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.typeName = parse(ast.typeName, parse, this.nextChildOffset); + this.typeName = parse(ast.typeName, this.nextChildOffset); this.indexedKeyword = ast.indexedKeyword?.text; this.name = ast.name?.text; this.initiateLoc(ast); diff --git a/src/slang-nodes/EventParameters.js b/src/slang-nodes/EventParameters.js index 65b91ae9a..4c6f90c3c 100644 --- a/src/slang-nodes/EventParameters.js +++ b/src/slang-nodes/EventParameters.js @@ -8,9 +8,7 @@ export class EventParameters extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.items = ast.items.map((item) => - parse(item, parse, this.nextChildOffset) - ); + this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); this.separators = ast.separators.map((separator) => separator.text); this.initiateLoc(ast); } diff --git a/src/slang-nodes/EventParametersDeclaration.js b/src/slang-nodes/EventParametersDeclaration.js index 9648c0ac1..40e2f1593 100644 --- a/src/slang-nodes/EventParametersDeclaration.js +++ b/src/slang-nodes/EventParametersDeclaration.js @@ -10,7 +10,7 @@ export class EventParametersDeclaration extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.openParen = ast.openParen.text; - this.parameters = parse(ast.parameters, parse, this.nextChildOffset); + this.parameters = parse(ast.parameters, this.nextChildOffset); this.closeParen = ast.closeParen.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/ExperimentalFeature.js b/src/slang-nodes/ExperimentalFeature.js index ed671bf0a..c1d7f884f 100644 --- a/src/slang-nodes/ExperimentalFeature.js +++ b/src/slang-nodes/ExperimentalFeature.js @@ -1,5 +1,4 @@ import { SlangNode } from './SlangNode.js'; -import { StringLiteral } from './StringLiteral.js'; export class ExperimentalFeature extends SlangNode { variant; @@ -9,7 +8,7 @@ export class ExperimentalFeature extends SlangNode { this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : new StringLiteral(ast.variant, this.nextChildOffset, options, parse); + : parse(ast.variant, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/ExperimentalPragma.js b/src/slang-nodes/ExperimentalPragma.js index ef316a28a..3a348f5b1 100644 --- a/src/slang-nodes/ExperimentalPragma.js +++ b/src/slang-nodes/ExperimentalPragma.js @@ -1,5 +1,4 @@ import { SlangNode } from './SlangNode.js'; -import { ExperimentalFeature } from './ExperimentalFeature.js'; export class ExperimentalPragma extends SlangNode { experimentalKeyword; @@ -9,12 +8,7 @@ export class ExperimentalPragma extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.experimentalKeyword = ast.experimentalKeyword.text; - this.feature = new ExperimentalFeature( - ast.feature, - this.nextChildOffset, - options, - parse - ); + this.feature = parse(ast.feature, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/ExponentiationExpression.js b/src/slang-nodes/ExponentiationExpression.js index 46fec4144..62bff0b09 100644 --- a/src/slang-nodes/ExponentiationExpression.js +++ b/src/slang-nodes/ExponentiationExpression.js @@ -29,8 +29,8 @@ export class ExponentiationExpression extends SlangNode { super(ast, offset); if (offset) { const compiler = coerce(options.compiler); - this.leftOperand = parse(ast.leftOperand, parse, this.nextChildOffset); - this.rightOperand = parse(ast.rightOperand, parse, this.nextChildOffset); + this.leftOperand = parse(ast.leftOperand, this.nextChildOffset); + this.rightOperand = parse(ast.rightOperand, this.nextChildOffset); if (compiler) { if (satisfies(compiler, '>=0.8.0')) { diff --git a/src/slang-nodes/Expression.js b/src/slang-nodes/Expression.js index 8cb2148dd..904103e6a 100644 --- a/src/slang-nodes/Expression.js +++ b/src/slang-nodes/Expression.js @@ -9,7 +9,7 @@ export class Expression extends SlangNode { this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, parse, this.nextChildOffset); + : parse(ast.variant, this.nextChildOffset); this.initiateLoc(ast); } else { this.kind = ast.kind; diff --git a/src/slang-nodes/ExpressionStatement.js b/src/slang-nodes/ExpressionStatement.js index 1ba8ca676..291bc4358 100644 --- a/src/slang-nodes/ExpressionStatement.js +++ b/src/slang-nodes/ExpressionStatement.js @@ -7,7 +7,7 @@ export class ExpressionStatement extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.expression = parse(ast.expression, parse, this.nextChildOffset); + this.expression = parse(ast.expression, this.nextChildOffset); this.semicolon = ast.semicolon.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/FallbackFunctionAttribute.js b/src/slang-nodes/FallbackFunctionAttribute.js index 46c6dc40a..305ccfde6 100644 --- a/src/slang-nodes/FallbackFunctionAttribute.js +++ b/src/slang-nodes/FallbackFunctionAttribute.js @@ -8,7 +8,7 @@ export class FallbackFunctionAttribute extends SlangNode { this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, parse, this.nextChildOffset); + : parse(ast.variant, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/FallbackFunctionAttributes.js b/src/slang-nodes/FallbackFunctionAttributes.js index 0792e909f..1ed5e61d2 100644 --- a/src/slang-nodes/FallbackFunctionAttributes.js +++ b/src/slang-nodes/FallbackFunctionAttributes.js @@ -10,7 +10,7 @@ export class FallbackFunctionAttributes extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items - .map((item) => parse(item, parse, this.nextChildOffset)) + .map((item) => parse(item, this.nextChildOffset)) .sort(sortFunctionAttributes); this.initiateLoc(ast); } diff --git a/src/slang-nodes/FallbackFunctionDefinition.js b/src/slang-nodes/FallbackFunctionDefinition.js index cb60d5ac9..7150a3adf 100644 --- a/src/slang-nodes/FallbackFunctionDefinition.js +++ b/src/slang-nodes/FallbackFunctionDefinition.js @@ -15,12 +15,12 @@ export class FallbackFunctionDefinition extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.fallbackKeyword = ast.fallbackKeyword.text; - this.parameters = parse(ast.parameters, parse, this.nextChildOffset); - this.attributes = parse(ast.attributes, parse, this.nextChildOffset); + this.parameters = parse(ast.parameters, this.nextChildOffset); + this.attributes = parse(ast.attributes, this.nextChildOffset); this.returns = ast.returns - ? parse(ast.returns, parse, this.nextChildOffset) + ? parse(ast.returns, this.nextChildOffset) : undefined; - this.body = parse(ast.body, parse, this.nextChildOffset); + this.body = parse(ast.body, this.nextChildOffset); this.cleanModifierInvocationArguments(); this.initiateLoc(ast); diff --git a/src/slang-nodes/ForStatement.js b/src/slang-nodes/ForStatement.js index ffea49172..76a4fefc7 100644 --- a/src/slang-nodes/ForStatement.js +++ b/src/slang-nodes/ForStatement.js @@ -23,17 +23,13 @@ export class ForStatement extends SlangNode { super(ast, offset); this.forKeyword = ast.forKeyword.text; this.openParen = ast.openParen.text; - this.initialization = parse( - ast.initialization, - parse, - this.nextChildOffset - ); - this.condition = parse(ast.condition, parse, this.nextChildOffset); + this.initialization = parse(ast.initialization, this.nextChildOffset); + this.condition = parse(ast.condition, this.nextChildOffset); this.iterator = ast.iterator - ? parse(ast.iterator, parse, this.nextChildOffset) + ? parse(ast.iterator, this.nextChildOffset) : undefined; this.closeParen = ast.closeParen.text; - this.body = parse(ast.body, parse, this.nextChildOffset); + this.body = parse(ast.body, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/ForStatementCondition.js b/src/slang-nodes/ForStatementCondition.js index e09617795..672c92e6b 100644 --- a/src/slang-nodes/ForStatementCondition.js +++ b/src/slang-nodes/ForStatementCondition.js @@ -8,7 +8,7 @@ export class ForStatementCondition extends SlangNode { this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, parse, this.nextChildOffset); + : parse(ast.variant, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/ForStatementInitialization.js b/src/slang-nodes/ForStatementInitialization.js index 9ba60b979..842bc95d3 100644 --- a/src/slang-nodes/ForStatementInitialization.js +++ b/src/slang-nodes/ForStatementInitialization.js @@ -8,7 +8,7 @@ export class ForStatementInitialization extends SlangNode { this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, parse, this.nextChildOffset); + : parse(ast.variant, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/FunctionAttribute.js b/src/slang-nodes/FunctionAttribute.js index 2b1381a87..3ca164625 100644 --- a/src/slang-nodes/FunctionAttribute.js +++ b/src/slang-nodes/FunctionAttribute.js @@ -8,7 +8,7 @@ export class FunctionAttribute extends SlangNode { this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, parse, this.nextChildOffset); + : parse(ast.variant, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/FunctionAttributes.js b/src/slang-nodes/FunctionAttributes.js index 5ab9a3dd6..9180f2832 100644 --- a/src/slang-nodes/FunctionAttributes.js +++ b/src/slang-nodes/FunctionAttributes.js @@ -10,7 +10,7 @@ export class FunctionAttributes extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items - .map((item) => parse(item, parse, this.nextChildOffset)) + .map((item) => parse(item, this.nextChildOffset)) .sort(sortFunctionAttributes); this.initiateLoc(ast); } diff --git a/src/slang-nodes/FunctionBody.js b/src/slang-nodes/FunctionBody.js index 0ed1d0614..ef441d953 100644 --- a/src/slang-nodes/FunctionBody.js +++ b/src/slang-nodes/FunctionBody.js @@ -8,7 +8,7 @@ export class FunctionBody extends SlangNode { this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, parse, this.nextChildOffset); + : parse(ast.variant, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/FunctionCallExpression.js b/src/slang-nodes/FunctionCallExpression.js index c7ec89e69..11e726dc9 100644 --- a/src/slang-nodes/FunctionCallExpression.js +++ b/src/slang-nodes/FunctionCallExpression.js @@ -13,8 +13,8 @@ export class FunctionCallExpression extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.operand = parse(ast.operand, parse, this.nextChildOffset); - this.arguments = parse(ast.arguments, parse, this.nextChildOffset); + this.operand = parse(ast.operand, this.nextChildOffset); + this.arguments = parse(ast.arguments, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/FunctionDefinition.js b/src/slang-nodes/FunctionDefinition.js index a8392f0bc..f53390c06 100644 --- a/src/slang-nodes/FunctionDefinition.js +++ b/src/slang-nodes/FunctionDefinition.js @@ -19,13 +19,13 @@ export class FunctionDefinition extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.functionKeyword = ast.functionKeyword.text; - this.name = parse(ast.name, parse, this.nextChildOffset); - this.parameters = parse(ast.parameters, parse, this.nextChildOffset); - this.attributes = parse(ast.attributes, parse, this.nextChildOffset); + this.name = parse(ast.name, this.nextChildOffset); + this.parameters = parse(ast.parameters, this.nextChildOffset); + this.attributes = parse(ast.attributes, this.nextChildOffset); this.returns = ast.returns - ? parse(ast.returns, parse, this.nextChildOffset) + ? parse(ast.returns, this.nextChildOffset) : undefined; - this.body = parse(ast.body, parse, this.nextChildOffset); + this.body = parse(ast.body, this.nextChildOffset); // Older versions of Solidity defined a constructor as a function having // the same name as the contract. diff --git a/src/slang-nodes/FunctionType.js b/src/slang-nodes/FunctionType.js index 693901caf..fc1c03245 100644 --- a/src/slang-nodes/FunctionType.js +++ b/src/slang-nodes/FunctionType.js @@ -13,10 +13,10 @@ export class FunctionType extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.functionKeyword = ast.functionKeyword.text; - this.parameters = parse(ast.parameters, parse, this.nextChildOffset); - this.attributes = parse(ast.attributes, parse, this.nextChildOffset); + this.parameters = parse(ast.parameters, this.nextChildOffset); + this.attributes = parse(ast.attributes, this.nextChildOffset); this.returns = ast.returns - ? parse(ast.returns, parse, this.nextChildOffset) + ? parse(ast.returns, this.nextChildOffset) : undefined; this.initiateLoc(ast); } diff --git a/src/slang-nodes/FunctionTypeAttributes.js b/src/slang-nodes/FunctionTypeAttributes.js index 3e9b2f79f..4ea79d6cc 100644 --- a/src/slang-nodes/FunctionTypeAttributes.js +++ b/src/slang-nodes/FunctionTypeAttributes.js @@ -10,7 +10,7 @@ export class FunctionTypeAttributes extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items - .map((item) => parse(item, parse, this.nextChildOffset)) + .map((item) => parse(item, this.nextChildOffset)) .sort(sortFunctionAttributes); this.initiateLoc(ast); } diff --git a/src/slang-nodes/HexNumberExpression.js b/src/slang-nodes/HexNumberExpression.js index be6cb1142..321cec17b 100644 --- a/src/slang-nodes/HexNumberExpression.js +++ b/src/slang-nodes/HexNumberExpression.js @@ -8,9 +8,7 @@ export class HexNumberExpression extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.literal = ast.literal.text; - this.unit = ast.unit - ? parse(ast.unit, parse, this.nextChildOffset) - : undefined; + this.unit = ast.unit ? parse(ast.unit, this.nextChildOffset) : undefined; this.initiateLoc(ast); } diff --git a/src/slang-nodes/HexStringLiterals.js b/src/slang-nodes/HexStringLiterals.js index 3988b875c..cc48aa9ec 100644 --- a/src/slang-nodes/HexStringLiterals.js +++ b/src/slang-nodes/HexStringLiterals.js @@ -8,9 +8,7 @@ export class HexStringLiterals extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.items = ast.items.map((item) => - parse(item, parse, this.nextChildOffset) - ); + this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); this.initiateLoc(ast); } diff --git a/src/slang-nodes/IfStatement.js b/src/slang-nodes/IfStatement.js index 0ce8538e4..b41267971 100644 --- a/src/slang-nodes/IfStatement.js +++ b/src/slang-nodes/IfStatement.js @@ -28,11 +28,11 @@ export class IfStatement extends SlangNode { super(ast, offset); this.ifKeyword = ast.ifKeyword.text; this.openParen = ast.openParen.text; - this.condition = parse(ast.condition, parse, this.nextChildOffset); + this.condition = parse(ast.condition, this.nextChildOffset); this.closeParen = ast.closeParen.text; - this.body = parse(ast.body, parse, this.nextChildOffset); + this.body = parse(ast.body, this.nextChildOffset); this.elseBranch = ast.elseBranch - ? parse(ast.elseBranch, parse, this.nextChildOffset) + ? parse(ast.elseBranch, this.nextChildOffset) : undefined; this.initiateLoc(ast); } diff --git a/src/slang-nodes/ImportClause.js b/src/slang-nodes/ImportClause.js index 68419fcc7..f66ff2286 100644 --- a/src/slang-nodes/ImportClause.js +++ b/src/slang-nodes/ImportClause.js @@ -5,7 +5,7 @@ export class ImportClause extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.variant = parse(ast.variant, parse, this.nextChildOffset); + this.variant = parse(ast.variant, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/ImportDeconstruction.js b/src/slang-nodes/ImportDeconstruction.js index 115bc5df7..ee02e3bd1 100644 --- a/src/slang-nodes/ImportDeconstruction.js +++ b/src/slang-nodes/ImportDeconstruction.js @@ -14,10 +14,10 @@ export class ImportDeconstruction extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.openBrace = ast.openBrace.text; - this.symbols = parse(ast.symbols, parse, this.nextChildOffset); + this.symbols = parse(ast.symbols, this.nextChildOffset); this.closeBrace = ast.closeBrace.text; this.fromKeyword = ast.fromKeyword.text; - this.path = parse(ast.path, parse, this.nextChildOffset); + this.path = parse(ast.path, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/ImportDeconstructionSymbol.js b/src/slang-nodes/ImportDeconstructionSymbol.js index 7e0aede70..0be18fba4 100644 --- a/src/slang-nodes/ImportDeconstructionSymbol.js +++ b/src/slang-nodes/ImportDeconstructionSymbol.js @@ -8,9 +8,7 @@ export class ImportDeconstructionSymbol extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.name = ast.name.text; - this.alias = ast.alias - ? parse(ast.alias, parse, this.nextChildOffset) - : undefined; + this.alias = ast.alias ? parse(ast.alias, this.nextChildOffset) : undefined; this.initiateLoc(ast); } diff --git a/src/slang-nodes/ImportDeconstructionSymbols.js b/src/slang-nodes/ImportDeconstructionSymbols.js index 5e4934330..ddeb1b276 100644 --- a/src/slang-nodes/ImportDeconstructionSymbols.js +++ b/src/slang-nodes/ImportDeconstructionSymbols.js @@ -13,9 +13,7 @@ export class ImportDeconstructionSymbols extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.items = ast.items.map((item) => - parse(item, parse, this.nextChildOffset) - ); + this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); this.separators = ast.separators.map((separator) => separator.text); this.initiateLoc(ast); } diff --git a/src/slang-nodes/ImportDirective.js b/src/slang-nodes/ImportDirective.js index b857ad3f4..52a2d6905 100644 --- a/src/slang-nodes/ImportDirective.js +++ b/src/slang-nodes/ImportDirective.js @@ -10,7 +10,7 @@ export class ImportDirective extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.importKeyword = ast.importKeyword.text; - this.clause = parse(ast.clause, parse, this.nextChildOffset); + this.clause = parse(ast.clause, this.nextChildOffset); this.semicolon = ast.semicolon.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/IndexAccessEnd.js b/src/slang-nodes/IndexAccessEnd.js index a92a55f04..89e218e7b 100644 --- a/src/slang-nodes/IndexAccessEnd.js +++ b/src/slang-nodes/IndexAccessEnd.js @@ -8,9 +8,7 @@ export class IndexAccessEnd extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.colon = ast.colon.text; - this.end = ast.end - ? parse(ast.end, parse, this.nextChildOffset) - : undefined; + this.end = ast.end ? parse(ast.end, this.nextChildOffset) : undefined; this.initiateLoc(ast); } diff --git a/src/slang-nodes/IndexAccessExpression.js b/src/slang-nodes/IndexAccessExpression.js index 50dc9aae2..7bddd1814 100644 --- a/src/slang-nodes/IndexAccessExpression.js +++ b/src/slang-nodes/IndexAccessExpression.js @@ -19,14 +19,10 @@ export class IndexAccessExpression extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.operand = parse(ast.operand, parse, this.nextChildOffset); + this.operand = parse(ast.operand, this.nextChildOffset); this.openBracket = ast.openBracket.text; - this.start = ast.start - ? parse(ast.start, parse, this.nextChildOffset) - : undefined; - this.end = ast.end - ? parse(ast.end, parse, this.nextChildOffset) - : undefined; + this.start = ast.start ? parse(ast.start, this.nextChildOffset) : undefined; + this.end = ast.end ? parse(ast.end, this.nextChildOffset) : undefined; this.closeBracket = ast.closeBracket.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/InheritanceSpecifier.js b/src/slang-nodes/InheritanceSpecifier.js index 265a21a83..c1b6845c6 100644 --- a/src/slang-nodes/InheritanceSpecifier.js +++ b/src/slang-nodes/InheritanceSpecifier.js @@ -8,7 +8,7 @@ export class InheritanceSpecifier extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.isKeyword = ast.isKeyword.text; - this.types = parse(ast.types, parse, this.nextChildOffset); + this.types = parse(ast.types, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/InheritanceType.js b/src/slang-nodes/InheritanceType.js index 40ae0f85a..250781108 100644 --- a/src/slang-nodes/InheritanceType.js +++ b/src/slang-nodes/InheritanceType.js @@ -7,9 +7,9 @@ export class InheritanceType extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.typeName = parse(ast.typeName, parse, this.nextChildOffset); + this.typeName = parse(ast.typeName, this.nextChildOffset); this.arguments = ast.arguments - ? parse(ast.arguments, parse, this.nextChildOffset) + ? parse(ast.arguments, this.nextChildOffset) : undefined; this.initiateLoc(ast); } diff --git a/src/slang-nodes/InheritanceTypes.js b/src/slang-nodes/InheritanceTypes.js index da4a66e41..f86124074 100644 --- a/src/slang-nodes/InheritanceTypes.js +++ b/src/slang-nodes/InheritanceTypes.js @@ -11,9 +11,7 @@ export class InheritanceTypes extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.items = ast.items.map((item) => - parse(item, parse, this.nextChildOffset) - ); + this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); this.separators = ast.separators.map((separator) => separator.text); this.initiateLoc(ast); } diff --git a/src/slang-nodes/InterfaceDefinition.js b/src/slang-nodes/InterfaceDefinition.js index cf2f9259c..7ea7aad84 100644 --- a/src/slang-nodes/InterfaceDefinition.js +++ b/src/slang-nodes/InterfaceDefinition.js @@ -21,10 +21,10 @@ export class InterfaceDefinition extends SlangNode { this.interfaceKeyword = ast.interfaceKeyword.text; this.name = ast.name.text; this.inheritance = ast.inheritence - ? parse(ast.inheritance, parse, this.nextChildOffset) + ? parse(ast.inheritance, this.nextChildOffset) : undefined; this.openBrace = ast.openBrace.text; - this.members = parse(ast.members, parse, this.nextChildOffset); + this.members = parse(ast.members, this.nextChildOffset); this.closeBrace = ast.closeBrace.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/InterfaceMembers.js b/src/slang-nodes/InterfaceMembers.js index 71a2fe5dc..4dad9e3dd 100644 --- a/src/slang-nodes/InterfaceMembers.js +++ b/src/slang-nodes/InterfaceMembers.js @@ -10,9 +10,7 @@ export class InterfaceMembers extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.items = ast.items.map((item) => - parse(item, parse, this.nextChildOffset) - ); + this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); this.initiateLoc(ast); } diff --git a/src/slang-nodes/LibraryDefinition.js b/src/slang-nodes/LibraryDefinition.js index 257b2fe5f..544b33b13 100644 --- a/src/slang-nodes/LibraryDefinition.js +++ b/src/slang-nodes/LibraryDefinition.js @@ -19,7 +19,7 @@ export class LibraryDefinition extends SlangNode { this.libraryKeyword = ast.libraryKeyword.text; this.name = ast.name.text; this.openBrace = ast.openBrace.text; - this.members = parse(ast.members, parse, this.nextChildOffset); + this.members = parse(ast.members, this.nextChildOffset); this.closeBrace = ast.closeBrace.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/LibraryMembers.js b/src/slang-nodes/LibraryMembers.js index cbcb23459..2cbf0f178 100644 --- a/src/slang-nodes/LibraryMembers.js +++ b/src/slang-nodes/LibraryMembers.js @@ -10,9 +10,7 @@ export class LibraryMembers extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.items = ast.items.map((item) => - parse(item, parse, this.nextChildOffset) - ); + this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); this.initiateLoc(ast); } diff --git a/src/slang-nodes/MappingKey.js b/src/slang-nodes/MappingKey.js index e45b90fef..a38c249b5 100644 --- a/src/slang-nodes/MappingKey.js +++ b/src/slang-nodes/MappingKey.js @@ -7,7 +7,7 @@ export class MappingKey extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.keyType = parse(ast.keyType, parse, this.nextChildOffset); + this.keyType = parse(ast.keyType, this.nextChildOffset); this.name = ast.name?.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/MappingKeyType.js b/src/slang-nodes/MappingKeyType.js index e26a2a830..cb19925f2 100644 --- a/src/slang-nodes/MappingKeyType.js +++ b/src/slang-nodes/MappingKeyType.js @@ -5,7 +5,7 @@ export class MappingKeyType extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.variant = parse(ast.variant, parse, this.nextChildOffset); + this.variant = parse(ast.variant, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/MappingType.js b/src/slang-nodes/MappingType.js index 83b9a6500..381867d5f 100644 --- a/src/slang-nodes/MappingType.js +++ b/src/slang-nodes/MappingType.js @@ -17,9 +17,9 @@ export class MappingType extends SlangNode { super(ast, offset); this.mappingKeyword = ast.mappingKeyword.text; this.openParen = ast.openParen.text; - this.keyType = parse(ast.keyType, parse, this.nextChildOffset); + this.keyType = parse(ast.keyType, this.nextChildOffset); this.equalGreaterThan = ast.equalGreaterThan.text; - this.valueType = parse(ast.valueType, parse, this.nextChildOffset); + this.valueType = parse(ast.valueType, this.nextChildOffset); this.closeParen = ast.closeParen.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/MappingValue.js b/src/slang-nodes/MappingValue.js index 1ef7b3527..e2a971256 100644 --- a/src/slang-nodes/MappingValue.js +++ b/src/slang-nodes/MappingValue.js @@ -7,7 +7,7 @@ export class MappingValue extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.typeName = parse(ast.typeName, parse, this.nextChildOffset); + this.typeName = parse(ast.typeName, this.nextChildOffset); this.name = ast.name?.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/MemberAccessExpression.js b/src/slang-nodes/MemberAccessExpression.js index 93ca44c92..384240d41 100644 --- a/src/slang-nodes/MemberAccessExpression.js +++ b/src/slang-nodes/MemberAccessExpression.js @@ -114,9 +114,9 @@ export class MemberAccessExpression extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.operand = parse(ast.operand, parse, this.nextChildOffset); + this.operand = parse(ast.operand, this.nextChildOffset); this.period = ast.period.text; - this.member = parse(ast.member, parse, this.nextChildOffset); + this.member = parse(ast.member, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/ModifierAttribute.js b/src/slang-nodes/ModifierAttribute.js index b62bb5be9..3efcfc415 100644 --- a/src/slang-nodes/ModifierAttribute.js +++ b/src/slang-nodes/ModifierAttribute.js @@ -8,7 +8,7 @@ export class ModifierAttribute extends SlangNode { this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, parse, this.nextChildOffset); + : parse(ast.variant, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/ModifierAttributes.js b/src/slang-nodes/ModifierAttributes.js index c9f1ac280..05d57a504 100644 --- a/src/slang-nodes/ModifierAttributes.js +++ b/src/slang-nodes/ModifierAttributes.js @@ -10,7 +10,7 @@ export class ModifierAttributes extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items - .map((item) => parse(item, parse, this.nextChildOffset)) + .map((item) => parse(item, this.nextChildOffset)) .sort(sortFunctionAttributes); this.initiateLoc(ast); } diff --git a/src/slang-nodes/ModifierDefinition.js b/src/slang-nodes/ModifierDefinition.js index d04dd2d63..0b0ff4aa7 100644 --- a/src/slang-nodes/ModifierDefinition.js +++ b/src/slang-nodes/ModifierDefinition.js @@ -18,29 +18,30 @@ export class ModifierDefinition extends SlangNode { super(ast, offset); this.modifierKeyword = ast.modifierKeyword.text; this.name = ast.name.text; - const parametersOffset = this.nextChildOffset; - this.parameters = ast.parameters - ? parse(ast.parameters, parse, parametersOffset) - : new ParametersDeclaration({ - kind: 'ParametersDeclaration', - loc: { - start: parametersOffset, - end: parametersOffset - }, - openParen: '(', - parameters: new Parameters({ - kind: 'Parameters', - loc: { - start: parametersOffset, - end: parametersOffset - }, - items: [], - separators: [] - }), - closeParen: ')' - }); - this.attributes = parse(ast.attributes, parse, this.nextChildOffset); - this.body = parse(ast.body, parse, this.nextChildOffset); + if (ast.parameters) { + this.parameters = parse(ast.parameters, this.nextChildOffset); + } else { + const parametersLoc = { + startWithTrivia: this.loc.childrenOffsets[0], + start: this.loc.childrenOffsets[0], + endWithTrivia: this.loc.childrenOffsets[0], + end: this.loc.childrenOffsets[0] + }; + this.parameters = new ParametersDeclaration({ + kind: 'ParametersDeclaration', + loc: { ...parametersLoc }, + openParen: '(', + parameters: new Parameters({ + kind: 'Parameters', + loc: { ...parametersLoc }, + items: [], + separators: [] + }), + closeParen: ')' + }); + } + this.attributes = parse(ast.attributes, this.nextChildOffset); + this.body = parse(ast.body, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/ModifierInvocation.js b/src/slang-nodes/ModifierInvocation.js index 78e3be44c..a7fd4980b 100644 --- a/src/slang-nodes/ModifierInvocation.js +++ b/src/slang-nodes/ModifierInvocation.js @@ -11,9 +11,9 @@ export class ModifierInvocation extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.#ast = ast; - this.name = parse(ast.name, parse, this.nextChildOffset); + this.name = parse(ast.name, this.nextChildOffset); this.arguments = ast.arguments - ? parse(ast.arguments, parse, this.nextChildOffset) + ? parse(ast.arguments, this.nextChildOffset) : undefined; this.initiateLoc(ast); } diff --git a/src/slang-nodes/MultiplicativeExpression.js b/src/slang-nodes/MultiplicativeExpression.js index ab85e9a3f..5fadfa40d 100644 --- a/src/slang-nodes/MultiplicativeExpression.js +++ b/src/slang-nodes/MultiplicativeExpression.js @@ -15,7 +15,7 @@ export class MultiplicativeExpression extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.leftOperand = parse(ast.leftOperand, parse, this.nextChildOffset); + this.leftOperand = parse(ast.leftOperand, this.nextChildOffset); this.operator = ast.operator.text; switch (this.operator) { @@ -32,7 +32,7 @@ export class MultiplicativeExpression extends SlangNode { break; } - this.rightOperand = parse(ast.rightOperand, parse, this.nextChildOffset); + this.rightOperand = parse(ast.rightOperand, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/NamedArgument.js b/src/slang-nodes/NamedArgument.js index 2b288c744..7801914b4 100644 --- a/src/slang-nodes/NamedArgument.js +++ b/src/slang-nodes/NamedArgument.js @@ -11,7 +11,7 @@ export class NamedArgument extends SlangNode { super(ast, offset); this.name = ast.name.text; this.colon = ast.colon.text; - this.value = parse(ast.value, parse, this.nextChildOffset); + this.value = parse(ast.value, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/NamedArgumentGroup.js b/src/slang-nodes/NamedArgumentGroup.js index 3885f023f..cd9365746 100644 --- a/src/slang-nodes/NamedArgumentGroup.js +++ b/src/slang-nodes/NamedArgumentGroup.js @@ -10,7 +10,7 @@ export class NamedArgumentGroup extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.openBrace = ast.openBrace.text; - this.arguments = parse(ast.arguments, parse, this.nextChildOffset); + this.arguments = parse(ast.arguments, this.nextChildOffset); this.closeBrace = ast.closeBrace.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/NamedArguments.js b/src/slang-nodes/NamedArguments.js index 56eabd04f..9e48cec49 100644 --- a/src/slang-nodes/NamedArguments.js +++ b/src/slang-nodes/NamedArguments.js @@ -11,9 +11,7 @@ export class NamedArguments extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.items = ast.items.map((item) => - parse(item, parse, this.nextChildOffset) - ); + this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); this.separators = ast.separators.map((separator) => separator.text); this.initiateLoc(ast); } diff --git a/src/slang-nodes/NamedArgumentsDeclaration.js b/src/slang-nodes/NamedArgumentsDeclaration.js index a90581867..aaa27e997 100644 --- a/src/slang-nodes/NamedArgumentsDeclaration.js +++ b/src/slang-nodes/NamedArgumentsDeclaration.js @@ -11,7 +11,7 @@ export class NamedArgumentsDeclaration extends SlangNode { super(ast, offset); this.openParen = ast.openParen.text; this.arguments = ast.arguments - ? parse(ast.arguments, parse, this.nextChildOffset) + ? parse(ast.arguments, this.nextChildOffset) : undefined; this.closeParen = ast.closeParen.text; this.initiateLoc(ast); diff --git a/src/slang-nodes/NamedImport.js b/src/slang-nodes/NamedImport.js index 1502e0b8c..4eb2f5210 100644 --- a/src/slang-nodes/NamedImport.js +++ b/src/slang-nodes/NamedImport.js @@ -12,9 +12,9 @@ export class NamedImport extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.asterisk = ast.asterisk.text; - this.alias = parse(ast.alias, parse, this.nextChildOffset); + this.alias = parse(ast.alias, this.nextChildOffset); this.fromKeyword = ast.fromKeyword.text; - this.path = parse(ast.path, parse, this.nextChildOffset); + this.path = parse(ast.path, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/NewExpression.js b/src/slang-nodes/NewExpression.js index e69ca5acb..d46353bb9 100644 --- a/src/slang-nodes/NewExpression.js +++ b/src/slang-nodes/NewExpression.js @@ -8,7 +8,7 @@ export class NewExpression extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.newKeyword = ast.newKeyword.text; - this.typeName = parse(ast.typeName, parse, this.nextChildOffset); + this.typeName = parse(ast.typeName, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/OrExpression.js b/src/slang-nodes/OrExpression.js index 9e9e86208..89b7b877f 100644 --- a/src/slang-nodes/OrExpression.js +++ b/src/slang-nodes/OrExpression.js @@ -13,13 +13,9 @@ export class OrExpression extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.leftOperand = tryToHug( - parse(ast.leftOperand, parse, this.nextChildOffset) - ); + this.leftOperand = tryToHug(parse(ast.leftOperand, this.nextChildOffset)); this.operator = ast.operator.text; - this.rightOperand = tryToHug( - parse(ast.rightOperand, parse, this.nextChildOffset) - ); + this.rightOperand = tryToHug(parse(ast.rightOperand, this.nextChildOffset)); this.initiateLoc(ast); } diff --git a/src/slang-nodes/OverridePaths.js b/src/slang-nodes/OverridePaths.js index 41eeef7d5..4a69435a6 100644 --- a/src/slang-nodes/OverridePaths.js +++ b/src/slang-nodes/OverridePaths.js @@ -7,9 +7,7 @@ export class OverridePaths extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.items = ast.items.map((item) => - parse(item, parse, this.nextChildOffset) - ); + this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); this.separators = ast.separators.map((separator) => separator); this.initiateLoc(ast); } diff --git a/src/slang-nodes/OverridePathsDeclaration.js b/src/slang-nodes/OverridePathsDeclaration.js index 97a4263f1..3c02c102a 100644 --- a/src/slang-nodes/OverridePathsDeclaration.js +++ b/src/slang-nodes/OverridePathsDeclaration.js @@ -10,7 +10,7 @@ export class OverridePathsDeclaration extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.openParen = ast.openParen.text; - this.paths = parse(ast.paths, parse, this.nextChildOffset); + this.paths = parse(ast.paths, this.nextChildOffset); this.closeParen = ast.closeParen.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/OverrideSpecifier.js b/src/slang-nodes/OverrideSpecifier.js index ee3b8d587..9e340abd3 100644 --- a/src/slang-nodes/OverrideSpecifier.js +++ b/src/slang-nodes/OverrideSpecifier.js @@ -9,7 +9,7 @@ export class OverrideSpecifier extends SlangNode { super(ast, offset); this.overrideKeyword = ast.overrideKeyword.text; this.overridden = ast.overridden - ? parse(ast.overridden, parse, this.nextChildOffset) + ? parse(ast.overridden, this.nextChildOffset) : undefined; this.initiateLoc(ast); } diff --git a/src/slang-nodes/Parameter.js b/src/slang-nodes/Parameter.js index 92e08a759..ceba4609b 100644 --- a/src/slang-nodes/Parameter.js +++ b/src/slang-nodes/Parameter.js @@ -12,9 +12,9 @@ export class Parameter extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.typeName = parse(ast.typeName, parse, this.nextChildOffset); + this.typeName = parse(ast.typeName, this.nextChildOffset); this.storageLocation = ast.storageLocation - ? parse(ast.storageLocation, parse, this.nextChildOffset) + ? parse(ast.storageLocation, this.nextChildOffset) : undefined; this.name = ast.name?.text; this.initiateLoc(ast); diff --git a/src/slang-nodes/Parameters.js b/src/slang-nodes/Parameters.js index 6a2cec6e5..d2cb23467 100644 --- a/src/slang-nodes/Parameters.js +++ b/src/slang-nodes/Parameters.js @@ -13,9 +13,7 @@ export class Parameters extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); if (offset) { - this.items = ast.items.map((item) => - parse(item, parse, this.nextChildOffset) - ); + this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); this.separators = ast.separators.map((separator) => separator.text); this.initiateLoc(ast); } else { diff --git a/src/slang-nodes/ParametersDeclaration.js b/src/slang-nodes/ParametersDeclaration.js index 85b9df0fd..a0baaa323 100644 --- a/src/slang-nodes/ParametersDeclaration.js +++ b/src/slang-nodes/ParametersDeclaration.js @@ -11,7 +11,7 @@ export class ParametersDeclaration extends SlangNode { super(ast, offset); if (offset) { this.openParen = ast.openParen.text; - this.parameters = parse(ast.parameters, parse, this.nextChildOffset); + this.parameters = parse(ast.parameters, this.nextChildOffset); this.closeParen = ast.closeParen.text; this.initiateLoc(ast); } else { diff --git a/src/slang-nodes/PathImport.js b/src/slang-nodes/PathImport.js index 16de718f8..5d414cd13 100644 --- a/src/slang-nodes/PathImport.js +++ b/src/slang-nodes/PathImport.js @@ -7,10 +7,8 @@ export class PathImport extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.path = parse(ast.path, parse, this.nextChildOffset); - this.alias = ast.alias - ? parse(ast.alias, parse, this.nextChildOffset) - : undefined; + this.path = parse(ast.path, this.nextChildOffset); + this.alias = ast.alias ? parse(ast.alias, this.nextChildOffset) : undefined; this.initiateLoc(ast); } diff --git a/src/slang-nodes/PositionalArguments.js b/src/slang-nodes/PositionalArguments.js index 38840fbda..8d4d3aa62 100644 --- a/src/slang-nodes/PositionalArguments.js +++ b/src/slang-nodes/PositionalArguments.js @@ -8,9 +8,7 @@ export class PositionalArguments extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.items = ast.items.map((item) => - parse(item, parse, this.nextChildOffset) - ); + this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); this.separators = ast.separators.map((separator) => separator.text); this.initiateLoc(ast); } diff --git a/src/slang-nodes/PositionalArgumentsDeclaration.js b/src/slang-nodes/PositionalArgumentsDeclaration.js index b6ccb0ac8..95c2a1d20 100644 --- a/src/slang-nodes/PositionalArgumentsDeclaration.js +++ b/src/slang-nodes/PositionalArgumentsDeclaration.js @@ -10,7 +10,7 @@ export class PositionalArgumentsDeclaration extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.openParen = ast.openParen.text; - this.arguments = parse(ast.arguments, parse, this.nextChildOffset); + this.arguments = parse(ast.arguments, this.nextChildOffset); this.closeParen = ast.closeParen.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/PostfixExpression.js b/src/slang-nodes/PostfixExpression.js index 3d3904385..eb7676c29 100644 --- a/src/slang-nodes/PostfixExpression.js +++ b/src/slang-nodes/PostfixExpression.js @@ -7,7 +7,7 @@ export class PostfixExpression extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.operand = parse(ast.operand, parse, this.nextChildOffset); + this.operand = parse(ast.operand, this.nextChildOffset); this.operator = ast.operator.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/Pragma.js b/src/slang-nodes/Pragma.js index d766addd8..a1b78e7d1 100644 --- a/src/slang-nodes/Pragma.js +++ b/src/slang-nodes/Pragma.js @@ -1,21 +1,11 @@ import { SlangNode } from './SlangNode.js'; -import { ABICoderPragma } from './ABICoderPragma.js'; -import { ExperimentalPragma } from './ExperimentalPragma.js'; -import { VersionPragma } from './VersionPragma.js'; - -const variants = { ABICoderPragma, ExperimentalPragma, VersionPragma }; export class Pragma extends SlangNode { variant; constructor(ast, offset, options, parse) { super(ast, offset); - this.variant = new variants[ast.variant.cst.kind]( - ast.variant, - this.nextChildOffset, - options, - parse - ); + this.variant = parse(ast.variant, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/PragmaDirective.js b/src/slang-nodes/PragmaDirective.js index 129e210b0..3b65cfd13 100644 --- a/src/slang-nodes/PragmaDirective.js +++ b/src/slang-nodes/PragmaDirective.js @@ -1,5 +1,4 @@ import { SlangNode } from './SlangNode.js'; -import { Pragma } from './Pragma.js'; export class PragmaDirective extends SlangNode { pragmaKeyword; @@ -11,7 +10,7 @@ export class PragmaDirective extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.pragmaKeyword = ast.pragmaKeyword.text; - this.pragma = new Pragma(ast.pragma, this.nextChildOffset, options, parse); + this.pragma = parse(ast.pragma, this.nextChildOffset); this.semicolon = ast.semicolon.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/PrefixExpression.js b/src/slang-nodes/PrefixExpression.js index aea50bbbd..06c483e4c 100644 --- a/src/slang-nodes/PrefixExpression.js +++ b/src/slang-nodes/PrefixExpression.js @@ -8,7 +8,7 @@ export class PrefixExpression extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.operator = ast.operator.text; - this.operand = parse(ast.operand, parse, this.nextChildOffset); + this.operand = parse(ast.operand, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/ReceiveFunctionAttribute.js b/src/slang-nodes/ReceiveFunctionAttribute.js index 13baa33ab..9e8ff79bd 100644 --- a/src/slang-nodes/ReceiveFunctionAttribute.js +++ b/src/slang-nodes/ReceiveFunctionAttribute.js @@ -8,7 +8,7 @@ export class ReceiveFunctionAttribute extends SlangNode { this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, parse, this.nextChildOffset); + : parse(ast.variant, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/ReceiveFunctionAttributes.js b/src/slang-nodes/ReceiveFunctionAttributes.js index c85d3f7d0..3c30c781c 100644 --- a/src/slang-nodes/ReceiveFunctionAttributes.js +++ b/src/slang-nodes/ReceiveFunctionAttributes.js @@ -10,7 +10,7 @@ export class ReceiveFunctionAttributes extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items - .map((item) => parse(item, parse, this.nextChildOffset)) + .map((item) => parse(item, this.nextChildOffset)) .sort(sortFunctionAttributes); this.initiateLoc(ast); } diff --git a/src/slang-nodes/ReceiveFunctionDefinition.js b/src/slang-nodes/ReceiveFunctionDefinition.js index a9f46140d..cc6b47e17 100644 --- a/src/slang-nodes/ReceiveFunctionDefinition.js +++ b/src/slang-nodes/ReceiveFunctionDefinition.js @@ -13,9 +13,9 @@ export class ReceiveFunctionDefinition extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.receiveKeyword = ast.receiveKeyword.text; - this.parameters = parse(ast.parameters, parse, this.nextChildOffset); - this.attributes = parse(ast.attributes, parse, this.nextChildOffset); - this.body = parse(ast.body, parse, this.nextChildOffset); + this.parameters = parse(ast.parameters, this.nextChildOffset); + this.attributes = parse(ast.attributes, this.nextChildOffset); + this.body = parse(ast.body, this.nextChildOffset); this.cleanModifierInvocationArguments(); this.initiateLoc(ast); diff --git a/src/slang-nodes/ReturnStatement.js b/src/slang-nodes/ReturnStatement.js index 1a1803ead..b90da5f80 100644 --- a/src/slang-nodes/ReturnStatement.js +++ b/src/slang-nodes/ReturnStatement.js @@ -25,7 +25,7 @@ export class ReturnStatement extends SlangNode { super(ast, offset); this.returnKeyword = ast.returnKeyword.text; this.expression = ast.expression - ? parse(ast.expression, parse, this.nextChildOffset) + ? parse(ast.expression, this.nextChildOffset) : undefined; this.semicolon = ast.semicolon.text; this.initiateLoc(ast); diff --git a/src/slang-nodes/ReturnsDeclaration.js b/src/slang-nodes/ReturnsDeclaration.js index 949e94250..f551ce098 100644 --- a/src/slang-nodes/ReturnsDeclaration.js +++ b/src/slang-nodes/ReturnsDeclaration.js @@ -11,7 +11,7 @@ export class ReturnsDeclaration extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.returnsKeyword = ast.returnsKeyword.text; - this.variables = parse(ast.variables, parse, this.nextChildOffset); + this.variables = parse(ast.variables, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/RevertStatement.js b/src/slang-nodes/RevertStatement.js index 55c6317c7..89d686d8e 100644 --- a/src/slang-nodes/RevertStatement.js +++ b/src/slang-nodes/RevertStatement.js @@ -12,10 +12,8 @@ export class RevertStatement extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.revertKeyword = ast.revertKeyword.text; - this.error = ast.error - ? parse(ast.error, parse, this.nextChildOffset) - : undefined; - this.arguments = parse(ast.arguments, parse, this.nextChildOffset); + this.error = ast.error ? parse(ast.error, this.nextChildOffset) : undefined; + this.arguments = parse(ast.arguments, this.nextChildOffset); this.semicolon = ast.semicolon.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/ShiftExpression.js b/src/slang-nodes/ShiftExpression.js index f09a0d417..b859ce0f6 100644 --- a/src/slang-nodes/ShiftExpression.js +++ b/src/slang-nodes/ShiftExpression.js @@ -23,11 +23,11 @@ export class ShiftExpression extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.leftOperand = tryToHugLeftOperand( - parse(ast.leftOperand, parse, this.nextChildOffset) + parse(ast.leftOperand, this.nextChildOffset) ); this.operator = ast.operator.text; this.rightOperand = tryToHugRightOperand( - parse(ast.rightOperand, parse, this.nextChildOffset) + parse(ast.rightOperand, this.nextChildOffset) ); this.initiateLoc(ast); } diff --git a/src/slang-nodes/SourceUnit.js b/src/slang-nodes/SourceUnit.js index c163801d2..1aa1755b3 100644 --- a/src/slang-nodes/SourceUnit.js +++ b/src/slang-nodes/SourceUnit.js @@ -1,6 +1,5 @@ import { doc } from 'prettier'; import { SlangNode } from './SlangNode.js'; -import { SourceUnitMembers } from './SourceUnitMembers.js'; const { line } = doc.builders; @@ -9,12 +8,7 @@ export class SourceUnit extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.members = new SourceUnitMembers( - ast.members, - this.nextChildOffset, - options, - parse - ); + this.members = parse(ast.members, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/SourceUnitMember.js b/src/slang-nodes/SourceUnitMember.js index f4b391a57..bad3a0a2f 100644 --- a/src/slang-nodes/SourceUnitMember.js +++ b/src/slang-nodes/SourceUnitMember.js @@ -1,45 +1,11 @@ import { SlangNode } from './SlangNode.js'; -import { PragmaDirective } from './PragmaDirective.js'; -import { ImportDirective } from './ImportDirective.js'; -import { ContractDefinition } from './ContractDefinition.js'; -import { InterfaceDefinition } from './InterfaceDefinition.js'; -import { LibraryDefinition } from './LibraryDefinition.js'; -import { StructDefinition } from './StructDefinition.js'; -import { EnumDefinition } from './EnumDefinition.js'; -import { FunctionDefinition } from './FunctionDefinition.js'; -import { ConstantDefinition } from './ConstantDefinition.js'; -import { ErrorDefinition } from './ErrorDefinition.js'; -import { UserDefinedValueTypeDefinition } from './UserDefinedValueTypeDefinition.js'; -import { UsingDirective } from './UsingDirective.js'; -import { EventDefinition } from './EventDefinition.js'; - -const variants = { - PragmaDirective, - ImportDirective, - ContractDefinition, - InterfaceDefinition, - LibraryDefinition, - StructDefinition, - EnumDefinition, - FunctionDefinition, - ConstantDefinition, - ErrorDefinition, - UserDefinedValueTypeDefinition, - UsingDirective, - EventDefinition -}; export class SourceUnitMember extends SlangNode { variant; constructor(ast, offset, options, parse) { super(ast, offset); - this.variant = new variants[ast.variant.cst.kind]( - ast.variant, - this.nextChildOffset, - options, - parse - ); + this.variant = parse(ast.variant, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/SourceUnitMembers.js b/src/slang-nodes/SourceUnitMembers.js index 162bd41e2..8003b5524 100644 --- a/src/slang-nodes/SourceUnitMembers.js +++ b/src/slang-nodes/SourceUnitMembers.js @@ -1,15 +1,12 @@ import { printPreservingEmptyLines } from '../common/slang-helpers.js'; import { SlangNode } from './SlangNode.js'; -import { SourceUnitMember } from './SourceUnitMember.js'; export class SourceUnitMembers extends SlangNode { items; constructor(ast, offset, options, parse) { super(ast, offset); - this.items = ast.items.map( - (item) => new SourceUnitMember(item, this.nextChildOffset, options, parse) - ); + this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); this.initiateLoc(ast); } diff --git a/src/slang-nodes/StateVariableAttribute.js b/src/slang-nodes/StateVariableAttribute.js index 96a347184..cf520a8f5 100644 --- a/src/slang-nodes/StateVariableAttribute.js +++ b/src/slang-nodes/StateVariableAttribute.js @@ -8,7 +8,7 @@ export class StateVariableAttribute extends SlangNode { this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, parse, this.nextChildOffset); + : parse(ast.variant, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/StateVariableAttributes.js b/src/slang-nodes/StateVariableAttributes.js index cc3d732f9..73c965794 100644 --- a/src/slang-nodes/StateVariableAttributes.js +++ b/src/slang-nodes/StateVariableAttributes.js @@ -5,9 +5,7 @@ export class StateVariableAttributes extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.items = ast.items.map((item) => - parse(item, parse, this.nextChildOffset) - ); + this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); this.initiateLoc(ast); } diff --git a/src/slang-nodes/StateVariableDefinition.js b/src/slang-nodes/StateVariableDefinition.js index 746ad75a0..304210f37 100644 --- a/src/slang-nodes/StateVariableDefinition.js +++ b/src/slang-nodes/StateVariableDefinition.js @@ -13,12 +13,10 @@ export class StateVariableDefinition extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.typeName = parse(ast.typeName, parse, this.nextChildOffset); - this.attributes = parse(ast.attributes, parse, this.nextChildOffset); + this.typeName = parse(ast.typeName, this.nextChildOffset); + this.attributes = parse(ast.attributes, this.nextChildOffset); this.name = ast.name.text; - this.value = ast.value - ? parse(ast.value, parse, this.nextChildOffset) - : undefined; + this.value = ast.value ? parse(ast.value, this.nextChildOffset) : undefined; this.semicolon = ast.semicolon.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/StateVariableDefinitionValue.js b/src/slang-nodes/StateVariableDefinitionValue.js index 145960cb0..04da873f8 100644 --- a/src/slang-nodes/StateVariableDefinitionValue.js +++ b/src/slang-nodes/StateVariableDefinitionValue.js @@ -11,7 +11,7 @@ export class StateVariableDefinitionValue extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.equal = ast.equal.text; - this.value = parse(ast.value, parse, this.nextChildOffset); + this.value = parse(ast.value, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/Statement.js b/src/slang-nodes/Statement.js index b25dfe9ad..9f09dbcda 100644 --- a/src/slang-nodes/Statement.js +++ b/src/slang-nodes/Statement.js @@ -5,7 +5,7 @@ export class Statement extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.variant = parse(ast.variant, parse, this.nextChildOffset); + this.variant = parse(ast.variant, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/Statements.js b/src/slang-nodes/Statements.js index d574e63fb..edab6914f 100644 --- a/src/slang-nodes/Statements.js +++ b/src/slang-nodes/Statements.js @@ -13,9 +13,7 @@ export class Statements extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.items = ast.items.map((item) => - parse(item, parse, this.nextChildOffset) - ); + this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); this.initiateLoc(ast); } diff --git a/src/slang-nodes/StringExpression.js b/src/slang-nodes/StringExpression.js index a78521777..736cd19bb 100644 --- a/src/slang-nodes/StringExpression.js +++ b/src/slang-nodes/StringExpression.js @@ -5,7 +5,7 @@ export class StringExpression extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.variant = parse(ast.variant, parse, this.nextChildOffset); + this.variant = parse(ast.variant, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/StringLiterals.js b/src/slang-nodes/StringLiterals.js index 457b5fe81..d46500447 100644 --- a/src/slang-nodes/StringLiterals.js +++ b/src/slang-nodes/StringLiterals.js @@ -8,9 +8,7 @@ export class StringLiterals extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.items = ast.items.map((item) => - parse(item, parse, this.nextChildOffset) - ); + this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); this.initiateLoc(ast); } diff --git a/src/slang-nodes/StructDefinition.js b/src/slang-nodes/StructDefinition.js index aadea0ddd..f063e7b4c 100644 --- a/src/slang-nodes/StructDefinition.js +++ b/src/slang-nodes/StructDefinition.js @@ -16,7 +16,7 @@ export class StructDefinition extends SlangNode { this.structKeyword = ast.structKeyword.text; this.name = ast.name.text; this.openBrace = ast.openBrace.text; - this.members = parse(ast.members, parse, this.nextChildOffset); + this.members = parse(ast.members, this.nextChildOffset); this.closeBrace = ast.closeBrace.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/StructMember.js b/src/slang-nodes/StructMember.js index 878ae9eaf..d75330b2d 100644 --- a/src/slang-nodes/StructMember.js +++ b/src/slang-nodes/StructMember.js @@ -9,7 +9,7 @@ export class StructMember extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.typeName = parse(ast.typeName, parse, this.nextChildOffset); + this.typeName = parse(ast.typeName, this.nextChildOffset); this.name = ast.name.text; this.semicolon = ast.semicolon.text; this.initiateLoc(ast); diff --git a/src/slang-nodes/StructMembers.js b/src/slang-nodes/StructMembers.js index 2eeb3e3b6..5de7363da 100644 --- a/src/slang-nodes/StructMembers.js +++ b/src/slang-nodes/StructMembers.js @@ -9,9 +9,7 @@ export class StructMembers extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.items = ast.items.map((item) => - parse(item, parse, this.nextChildOffset) - ); + this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); this.initiateLoc(ast); } diff --git a/src/slang-nodes/TryStatement.js b/src/slang-nodes/TryStatement.js index 66dee4097..3ef0bce53 100644 --- a/src/slang-nodes/TryStatement.js +++ b/src/slang-nodes/TryStatement.js @@ -18,12 +18,12 @@ export class TryStatement extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.tryKeyword = ast.tryKeyword.text; - this.expression = parse(ast.expression, parse, this.nextChildOffset); + this.expression = parse(ast.expression, this.nextChildOffset); this.returns = ast.returns - ? parse(ast.returns, parse, this.nextChildOffset) + ? parse(ast.returns, this.nextChildOffset) : undefined; - this.body = parse(ast.body, parse, this.nextChildOffset); - this.catchClauses = parse(ast.catchClauses, parse, this.nextChildOffset); + this.body = parse(ast.body, this.nextChildOffset); + this.catchClauses = parse(ast.catchClauses, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/TupleDeconstructionElement.js b/src/slang-nodes/TupleDeconstructionElement.js index 92011380d..bd466706c 100644 --- a/src/slang-nodes/TupleDeconstructionElement.js +++ b/src/slang-nodes/TupleDeconstructionElement.js @@ -6,7 +6,7 @@ export class TupleDeconstructionElement extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.member = ast.member - ? parse(ast.member, parse, this.nextChildOffset) + ? parse(ast.member, this.nextChildOffset) : undefined; this.initiateLoc(ast); } diff --git a/src/slang-nodes/TupleDeconstructionElements.js b/src/slang-nodes/TupleDeconstructionElements.js index 256a96ac0..ecb12a599 100644 --- a/src/slang-nodes/TupleDeconstructionElements.js +++ b/src/slang-nodes/TupleDeconstructionElements.js @@ -8,9 +8,7 @@ export class TupleDeconstructionElements extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.items = ast.items.map((item) => - parse(item, parse, this.nextChildOffset) - ); + this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); this.separators = ast.separators.map((separator) => separator.text); this.initiateLoc(ast); } diff --git a/src/slang-nodes/TupleDeconstructionStatement.js b/src/slang-nodes/TupleDeconstructionStatement.js index 0ec271506..7e947a469 100644 --- a/src/slang-nodes/TupleDeconstructionStatement.js +++ b/src/slang-nodes/TupleDeconstructionStatement.js @@ -22,10 +22,10 @@ export class TupleDeconstructionStatement extends SlangNode { super(ast, offset); this.varKeyword = ast.varKeyword?.text; this.openParen = ast.openParen.text; - this.elements = parse(ast.elements, parse, this.nextChildOffset); + this.elements = parse(ast.elements, this.nextChildOffset); this.closeParen = ast.closeParen.text; this.equal = ast.equal.text; - this.expression = parse(ast.expression, parse, this.nextChildOffset); + this.expression = parse(ast.expression, this.nextChildOffset); this.semicolon = ast.semicolon.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/TupleExpression.js b/src/slang-nodes/TupleExpression.js index dc7914cbb..a1546defc 100644 --- a/src/slang-nodes/TupleExpression.js +++ b/src/slang-nodes/TupleExpression.js @@ -11,7 +11,7 @@ export class TupleExpression extends SlangNode { super(ast, offset); if (offset) { this.openParen = ast.openParen.text; - this.items = parse(ast.items, parse, this.nextChildOffset); + this.items = parse(ast.items, this.nextChildOffset); this.closeParen = ast.closeParen.text; this.initiateLoc(ast); } else { diff --git a/src/slang-nodes/TupleMember.js b/src/slang-nodes/TupleMember.js index 2bd5e463d..1c6262b40 100644 --- a/src/slang-nodes/TupleMember.js +++ b/src/slang-nodes/TupleMember.js @@ -5,7 +5,7 @@ export class TupleMember extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.variant = parse(ast.variant, parse, this.nextChildOffset); + this.variant = parse(ast.variant, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/TupleValue.js b/src/slang-nodes/TupleValue.js index ee275f625..00efa8661 100644 --- a/src/slang-nodes/TupleValue.js +++ b/src/slang-nodes/TupleValue.js @@ -7,7 +7,7 @@ export class TupleValue extends SlangNode { super(ast, offset); if (offset) { this.expression = ast.expression - ? parse(ast.expression, parse, this.nextChildOffset) + ? parse(ast.expression, this.nextChildOffset) : undefined; this.initiateLoc(ast); } else { diff --git a/src/slang-nodes/TupleValues.js b/src/slang-nodes/TupleValues.js index fc3cdcba0..fdf061047 100644 --- a/src/slang-nodes/TupleValues.js +++ b/src/slang-nodes/TupleValues.js @@ -10,9 +10,7 @@ export class TupleValues extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); if (offset) { - this.items = ast.items.map((item) => - parse(item, parse, this.nextChildOffset) - ); + this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); this.separators = ast.separators.map((separator) => separator.text); this.initiateLoc(ast); } else { diff --git a/src/slang-nodes/TypeExpression.js b/src/slang-nodes/TypeExpression.js index 95ad58bc7..270c208ca 100644 --- a/src/slang-nodes/TypeExpression.js +++ b/src/slang-nodes/TypeExpression.js @@ -13,7 +13,7 @@ export class TypeExpression extends SlangNode { super(ast, offset); this.typeKeyword = ast.typeKeyword.text; this.openParen = ast.openParen.text; - this.typeName = parse(ast.typeName, parse, this.nextChildOffset); + this.typeName = parse(ast.typeName, this.nextChildOffset); this.closeParen = ast.closeParen.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/TypeName.js b/src/slang-nodes/TypeName.js index 8097dcacb..63184a218 100644 --- a/src/slang-nodes/TypeName.js +++ b/src/slang-nodes/TypeName.js @@ -5,7 +5,7 @@ export class TypeName extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.variant = parse(ast.variant, parse, this.nextChildOffset); + this.variant = parse(ast.variant, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/TypedTupleMember.js b/src/slang-nodes/TypedTupleMember.js index bcb9784b5..4d6dc2439 100644 --- a/src/slang-nodes/TypedTupleMember.js +++ b/src/slang-nodes/TypedTupleMember.js @@ -9,9 +9,9 @@ export class TypedTupleMember extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.typeName = parse(ast.typeName, parse, this.nextChildOffset); + this.typeName = parse(ast.typeName, this.nextChildOffset); this.storageLocation = ast.storageLocation - ? parse(ast.storageLocation, parse, this.nextChildOffset) + ? parse(ast.storageLocation, this.nextChildOffset) : undefined; this.name = ast.name.text; this.initiateLoc(ast); diff --git a/src/slang-nodes/UncheckedBlock.js b/src/slang-nodes/UncheckedBlock.js index 5b59a7c3e..4038f1735 100644 --- a/src/slang-nodes/UncheckedBlock.js +++ b/src/slang-nodes/UncheckedBlock.js @@ -8,7 +8,7 @@ export class UncheckedBlock extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.uncheckedKeyword = ast.uncheckedKeyword.text; - this.block = parse(ast.block, parse, this.nextChildOffset); + this.block = parse(ast.block, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/UnicodeStringLiterals.js b/src/slang-nodes/UnicodeStringLiterals.js index a38fb4ce9..f44a11a6a 100644 --- a/src/slang-nodes/UnicodeStringLiterals.js +++ b/src/slang-nodes/UnicodeStringLiterals.js @@ -8,9 +8,7 @@ export class UnicodeStringLiterals extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.items = ast.items.map((item) => - parse(item, parse, this.nextChildOffset) - ); + this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); this.initiateLoc(ast); } diff --git a/src/slang-nodes/UnnamedFunctionAttribute.js b/src/slang-nodes/UnnamedFunctionAttribute.js index 2d1df0e5a..ab5cc9649 100644 --- a/src/slang-nodes/UnnamedFunctionAttribute.js +++ b/src/slang-nodes/UnnamedFunctionAttribute.js @@ -8,7 +8,7 @@ export class UnnamedFunctionAttribute extends SlangNode { this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, parse, this.nextChildOffset); + : parse(ast.variant, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/UnnamedFunctionAttributes.js b/src/slang-nodes/UnnamedFunctionAttributes.js index d404cc66d..267d1ba60 100644 --- a/src/slang-nodes/UnnamedFunctionAttributes.js +++ b/src/slang-nodes/UnnamedFunctionAttributes.js @@ -10,7 +10,7 @@ export class UnnamedFunctionAttributes extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.items = ast.items - .map((item) => parse(item, parse, this.nextChildOffset)) + .map((item) => parse(item, this.nextChildOffset)) .sort(sortFunctionAttributes); this.initiateLoc(ast); } diff --git a/src/slang-nodes/UnnamedFunctionDefinition.js b/src/slang-nodes/UnnamedFunctionDefinition.js index 86f6a3e39..7e93dc387 100644 --- a/src/slang-nodes/UnnamedFunctionDefinition.js +++ b/src/slang-nodes/UnnamedFunctionDefinition.js @@ -13,9 +13,9 @@ export class UnnamedFunctionDefinition extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.functionKeyword = ast.functionKeyword.text; - this.parameters = parse(ast.parameters, parse, this.nextChildOffset); - this.attributes = parse(ast.attributes, parse, this.nextChildOffset); - this.body = parse(ast.body, parse, this.nextChildOffset); + this.parameters = parse(ast.parameters, this.nextChildOffset); + this.attributes = parse(ast.attributes, this.nextChildOffset); + this.body = parse(ast.body, this.nextChildOffset); this.cleanModifierInvocationArguments(); this.initiateLoc(ast); diff --git a/src/slang-nodes/UntypedTupleMember.js b/src/slang-nodes/UntypedTupleMember.js index 49a1df681..71b1d17a7 100644 --- a/src/slang-nodes/UntypedTupleMember.js +++ b/src/slang-nodes/UntypedTupleMember.js @@ -8,7 +8,7 @@ export class UntypedTupleMember extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.storageLocation = ast.storageLocation - ? parse(ast.storageLocation, parse, this.nextChildOffset) + ? parse(ast.storageLocation, this.nextChildOffset) : undefined; this.name = ast.name.text; this.initiateLoc(ast); diff --git a/src/slang-nodes/UserDefinedValueTypeDefinition.js b/src/slang-nodes/UserDefinedValueTypeDefinition.js index 96087beef..e8c76e1d5 100644 --- a/src/slang-nodes/UserDefinedValueTypeDefinition.js +++ b/src/slang-nodes/UserDefinedValueTypeDefinition.js @@ -16,7 +16,7 @@ export class UserDefinedValueTypeDefinition extends SlangNode { this.typeKeyword = ast.typeKeyword.text; this.name = ast.name.text; this.isKeyword = ast.isKeyword.text; - this.valueType = parse(ast.valueType, parse, this.nextChildOffset); + this.valueType = parse(ast.valueType, this.nextChildOffset); this.semicolon = ast.semicolon.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/UsingAlias.js b/src/slang-nodes/UsingAlias.js index dfa40f03e..d320ea4c9 100644 --- a/src/slang-nodes/UsingAlias.js +++ b/src/slang-nodes/UsingAlias.js @@ -8,7 +8,7 @@ export class UsingAlias extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.asKeyword = ast.asKeyword.text; - this.operator = parse(ast.operator, parse, this.nextChildOffset); + this.operator = parse(ast.operator, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/UsingClause.js b/src/slang-nodes/UsingClause.js index 2536fbfce..8e8ad515c 100644 --- a/src/slang-nodes/UsingClause.js +++ b/src/slang-nodes/UsingClause.js @@ -5,7 +5,7 @@ export class UsingClause extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.variant = parse(ast.variant, parse, this.nextChildOffset); + this.variant = parse(ast.variant, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/UsingDeconstruction.js b/src/slang-nodes/UsingDeconstruction.js index 920d663da..ccdea6f73 100644 --- a/src/slang-nodes/UsingDeconstruction.js +++ b/src/slang-nodes/UsingDeconstruction.js @@ -10,7 +10,7 @@ export class UsingDeconstruction extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.openBrace = ast.openBrace.text; - this.symbols = parse(ast.symbols, parse, this.nextChildOffset); + this.symbols = parse(ast.symbols, this.nextChildOffset); this.closeBrace = ast.closeBrace.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/UsingDeconstructionSymbol.js b/src/slang-nodes/UsingDeconstructionSymbol.js index e7f6a97f8..846abb70c 100644 --- a/src/slang-nodes/UsingDeconstructionSymbol.js +++ b/src/slang-nodes/UsingDeconstructionSymbol.js @@ -7,10 +7,8 @@ export class UsingDeconstructionSymbol extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.name = parse(ast.name, parse, this.nextChildOffset); - this.alias = ast.alias - ? parse(ast.alias, parse, this.nextChildOffset) - : undefined; + this.name = parse(ast.name, this.nextChildOffset); + this.alias = ast.alias ? parse(ast.alias, this.nextChildOffset) : undefined; this.initiateLoc(ast); } diff --git a/src/slang-nodes/UsingDeconstructionSymbols.js b/src/slang-nodes/UsingDeconstructionSymbols.js index 4a546a11e..6f2d05da3 100644 --- a/src/slang-nodes/UsingDeconstructionSymbols.js +++ b/src/slang-nodes/UsingDeconstructionSymbols.js @@ -11,9 +11,7 @@ export class UsingDeconstructionSymbols extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.items = ast.items.map((item) => - parse(item, parse, this.nextChildOffset) - ); + this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); this.separators = ast.separators.map((separator) => separator.text); this.initiateLoc(ast); } diff --git a/src/slang-nodes/UsingDirective.js b/src/slang-nodes/UsingDirective.js index eff919233..f87275fab 100644 --- a/src/slang-nodes/UsingDirective.js +++ b/src/slang-nodes/UsingDirective.js @@ -16,9 +16,9 @@ export class UsingDirective extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.usingKeyword = ast.usingKeyword.text; - this.clause = parse(ast.clause, parse, this.nextChildOffset); + this.clause = parse(ast.clause, this.nextChildOffset); this.forKeyword = ast.forKeyword.text; - this.target = parse(ast.target, parse, this.nextChildOffset); + this.target = parse(ast.target, this.nextChildOffset); this.globalKeyword = ast.globalKeyword?.text; this.semicolon = ast.semicolon.text; this.initiateLoc(ast); diff --git a/src/slang-nodes/UsingTarget.js b/src/slang-nodes/UsingTarget.js index 59fbc0064..6c6a65058 100644 --- a/src/slang-nodes/UsingTarget.js +++ b/src/slang-nodes/UsingTarget.js @@ -8,7 +8,7 @@ export class UsingTarget extends SlangNode { this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, parse, this.nextChildOffset); + : parse(ast.variant, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/VariableDeclarationStatement.js b/src/slang-nodes/VariableDeclarationStatement.js index 609da2294..524704528 100644 --- a/src/slang-nodes/VariableDeclarationStatement.js +++ b/src/slang-nodes/VariableDeclarationStatement.js @@ -18,14 +18,12 @@ export class VariableDeclarationStatement extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.variableType = parse(ast.variableType, parse, this.nextChildOffset); + this.variableType = parse(ast.variableType, this.nextChildOffset); this.storageLocation = ast.storageLocation - ? parse(ast.storageLocation, parse, this.nextChildOffset) + ? parse(ast.storageLocation, this.nextChildOffset) : undefined; this.name = ast.name.text; - this.value = ast.value - ? parse(ast.value, parse, this.nextChildOffset) - : undefined; + this.value = ast.value ? parse(ast.value, this.nextChildOffset) : undefined; this.semicolon = ast.semicolon.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/VariableDeclarationType.js b/src/slang-nodes/VariableDeclarationType.js index ea41ed1e1..b1fd6b4b3 100644 --- a/src/slang-nodes/VariableDeclarationType.js +++ b/src/slang-nodes/VariableDeclarationType.js @@ -8,7 +8,7 @@ export class VariableDeclarationType extends SlangNode { this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, parse, this.nextChildOffset); + : parse(ast.variant, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/VariableDeclarationValue.js b/src/slang-nodes/VariableDeclarationValue.js index 9477210a2..231864d67 100644 --- a/src/slang-nodes/VariableDeclarationValue.js +++ b/src/slang-nodes/VariableDeclarationValue.js @@ -8,7 +8,7 @@ export class VariableDeclarationValue extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.equal = ast.equal.text; - this.expression = parse(ast.expression, parse, this.nextChildOffset); + this.expression = parse(ast.expression, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/VersionComparator.js b/src/slang-nodes/VersionComparator.js index e87e42a02..a00e9ccf4 100644 --- a/src/slang-nodes/VersionComparator.js +++ b/src/slang-nodes/VersionComparator.js @@ -8,7 +8,7 @@ export class VersionComparator extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.operator = ast.operator.text; - this.operand = parse(ast.operand, parse, this.nextChildOffset); + this.operand = parse(ast.operand, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/VersionExpression.js b/src/slang-nodes/VersionExpression.js index 6cf8fdc11..ec4e93726 100644 --- a/src/slang-nodes/VersionExpression.js +++ b/src/slang-nodes/VersionExpression.js @@ -8,7 +8,7 @@ export class VersionExpression extends SlangNode { this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, parse, this.nextChildOffset); + : parse(ast.variant, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/VersionExpressionSet.js b/src/slang-nodes/VersionExpressionSet.js index 9d44916cf..59c66c5c8 100644 --- a/src/slang-nodes/VersionExpressionSet.js +++ b/src/slang-nodes/VersionExpressionSet.js @@ -8,9 +8,7 @@ export class VersionExpressionSet extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.items = ast.items.map((item) => - parse(item, parse, this.nextChildOffset) - ); + this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); this.initiateLoc(ast); } diff --git a/src/slang-nodes/VersionExpressionSets.js b/src/slang-nodes/VersionExpressionSets.js index 87528395e..358a23023 100644 --- a/src/slang-nodes/VersionExpressionSets.js +++ b/src/slang-nodes/VersionExpressionSets.js @@ -7,9 +7,7 @@ export class VersionExpressionSets extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.items = ast.items.map((item) => - parse(item, parse, this.nextChildOffset) - ); + this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); this.separators = ast.separators.map((separator) => separator.text); this.initiateLoc(ast); } diff --git a/src/slang-nodes/VersionPragma.js b/src/slang-nodes/VersionPragma.js index 96a5a3ab7..97e20ac64 100644 --- a/src/slang-nodes/VersionPragma.js +++ b/src/slang-nodes/VersionPragma.js @@ -8,7 +8,7 @@ export class VersionPragma extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.solidityKeyword = ast.solidityKeyword.text; - this.sets = parse(ast.sets, parse, this.nextChildOffset); + this.sets = parse(ast.sets, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/VersionRange.js b/src/slang-nodes/VersionRange.js index 57f6aa8a8..74dde93b7 100644 --- a/src/slang-nodes/VersionRange.js +++ b/src/slang-nodes/VersionRange.js @@ -9,9 +9,9 @@ export class VersionRange extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.leftOperand = parse(ast.leftOperand, parse, this.nextChildOffset); + this.leftOperand = parse(ast.leftOperand, this.nextChildOffset); this.operator = ast.operator.text; - this.rightOperand = parse(ast.rightOperand, parse, this.nextChildOffset); + this.rightOperand = parse(ast.rightOperand, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/WhileStatement.js b/src/slang-nodes/WhileStatement.js index af18753f2..400638a84 100644 --- a/src/slang-nodes/WhileStatement.js +++ b/src/slang-nodes/WhileStatement.js @@ -24,9 +24,9 @@ export class WhileStatement extends SlangNode { super(ast, offset); this.whileKeyword = ast.whileKeyword.text; this.openParen = ast.openParen.text; - this.condition = parse(ast.condition, parse, this.nextChildOffset); + this.condition = parse(ast.condition, this.nextChildOffset); this.closeParen = ast.closeParen.text; - this.body = parse(ast.body, parse, this.nextChildOffset); + this.body = parse(ast.body, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/YulArguments.js b/src/slang-nodes/YulArguments.js index 10d479405..e83cbcb82 100644 --- a/src/slang-nodes/YulArguments.js +++ b/src/slang-nodes/YulArguments.js @@ -8,9 +8,7 @@ export class YulArguments extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.items = ast.items.map((item) => - parse(item, parse, this.nextChildOffset) - ); + this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); this.separators = ast.separators.map((separator) => separator.text); this.initiateLoc(ast); } diff --git a/src/slang-nodes/YulAssignmentOperator.js b/src/slang-nodes/YulAssignmentOperator.js index 832d53d24..4300e0563 100644 --- a/src/slang-nodes/YulAssignmentOperator.js +++ b/src/slang-nodes/YulAssignmentOperator.js @@ -8,7 +8,7 @@ export class YulAssignmentOperator extends SlangNode { this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, parse, this.nextChildOffset); + : parse(ast.variant, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/YulAssignmentStatement.js b/src/slang-nodes/YulAssignmentStatement.js index a35c00108..8f8665878 100644 --- a/src/slang-nodes/YulAssignmentStatement.js +++ b/src/slang-nodes/YulAssignmentStatement.js @@ -9,9 +9,9 @@ export class YulAssignmentStatement extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.names = parse(ast.names, parse, this.nextChildOffset); - this.assignment = parse(ast.assignment, parse, this.nextChildOffset); - this.expression = parse(ast.expression, parse, this.nextChildOffset); + this.names = parse(ast.names, this.nextChildOffset); + this.assignment = parse(ast.assignment, this.nextChildOffset); + this.expression = parse(ast.expression, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/YulBlock.js b/src/slang-nodes/YulBlock.js index 4e52bbc5a..ab6eb665a 100644 --- a/src/slang-nodes/YulBlock.js +++ b/src/slang-nodes/YulBlock.js @@ -10,7 +10,7 @@ export class YulBlock extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.openBrace = ast.openBrace.text; - this.statements = parse(ast.statements, parse, this.nextChildOffset); + this.statements = parse(ast.statements, this.nextChildOffset); this.closeBrace = ast.closeBrace.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/YulDefaultCase.js b/src/slang-nodes/YulDefaultCase.js index 6045dd21e..f99d9b8ca 100644 --- a/src/slang-nodes/YulDefaultCase.js +++ b/src/slang-nodes/YulDefaultCase.js @@ -8,7 +8,7 @@ export class YulDefaultCase extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.defaultKeyword = ast.defaultKeyword.text; - this.body = parse(ast.body, parse, this.nextChildOffset); + this.body = parse(ast.body, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/YulExpression.js b/src/slang-nodes/YulExpression.js index 927cea4f1..d906a04ae 100644 --- a/src/slang-nodes/YulExpression.js +++ b/src/slang-nodes/YulExpression.js @@ -5,7 +5,7 @@ export class YulExpression extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.variant = parse(ast.variant, parse, this.nextChildOffset); + this.variant = parse(ast.variant, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/YulForStatement.js b/src/slang-nodes/YulForStatement.js index 8aeb9a675..a8ce174d3 100644 --- a/src/slang-nodes/YulForStatement.js +++ b/src/slang-nodes/YulForStatement.js @@ -14,14 +14,10 @@ export class YulForStatement extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.forKeyword = ast.forKeyword.text; - this.initialization = parse( - ast.initialization, - parse, - this.nextChildOffset - ); - this.condition = parse(ast.condition, parse, this.nextChildOffset); - this.iterator = parse(ast.iterator, parse, this.nextChildOffset); - this.body = parse(ast.body, parse, this.nextChildOffset); + this.initialization = parse(ast.initialization, this.nextChildOffset); + this.condition = parse(ast.condition, this.nextChildOffset); + this.iterator = parse(ast.iterator, this.nextChildOffset); + this.body = parse(ast.body, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/YulFunctionCallExpression.js b/src/slang-nodes/YulFunctionCallExpression.js index c163987ca..47657c7f0 100644 --- a/src/slang-nodes/YulFunctionCallExpression.js +++ b/src/slang-nodes/YulFunctionCallExpression.js @@ -11,9 +11,9 @@ export class YulFunctionCallExpression extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.operand = parse(ast.operand, parse, this.nextChildOffset); + this.operand = parse(ast.operand, this.nextChildOffset); this.openParen = ast.openParen.text; - this.arguments = parse(ast.arguments, parse, this.nextChildOffset); + this.arguments = parse(ast.arguments, this.nextChildOffset); this.closeParen = ast.closeParen.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/YulFunctionDefinition.js b/src/slang-nodes/YulFunctionDefinition.js index 765b420be..37d9263d1 100644 --- a/src/slang-nodes/YulFunctionDefinition.js +++ b/src/slang-nodes/YulFunctionDefinition.js @@ -15,11 +15,11 @@ export class YulFunctionDefinition extends SlangNode { super(ast, offset); this.functionKeyword = ast.functionKeyword.text; this.name = ast.name.text; - this.parameters = parse(ast.parameters, parse, this.nextChildOffset); + this.parameters = parse(ast.parameters, this.nextChildOffset); this.returns = ast.returns - ? parse(ast.returns, parse, this.nextChildOffset) + ? parse(ast.returns, this.nextChildOffset) : undefined; - this.body = parse(ast.body, parse, this.nextChildOffset); + this.body = parse(ast.body, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/YulIfStatement.js b/src/slang-nodes/YulIfStatement.js index 6bcf0eed5..d67191370 100644 --- a/src/slang-nodes/YulIfStatement.js +++ b/src/slang-nodes/YulIfStatement.js @@ -10,8 +10,8 @@ export class YulIfStatement extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.ifKeyword = ast.ifKeyword.text; - this.condition = parse(ast.condition, parse, this.nextChildOffset); - this.body = parse(ast.body, parse, this.nextChildOffset); + this.condition = parse(ast.condition, this.nextChildOffset); + this.body = parse(ast.body, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/YulLiteral.js b/src/slang-nodes/YulLiteral.js index 1d844d9c4..648454502 100644 --- a/src/slang-nodes/YulLiteral.js +++ b/src/slang-nodes/YulLiteral.js @@ -8,7 +8,7 @@ export class YulLiteral extends SlangNode { this.variant = ast.variant.type === 'Terminal' ? ast.variant.text - : parse(ast.variant, parse, this.nextChildOffset); + : parse(ast.variant, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/YulParametersDeclaration.js b/src/slang-nodes/YulParametersDeclaration.js index 2cd190d7c..7f7af6f9e 100644 --- a/src/slang-nodes/YulParametersDeclaration.js +++ b/src/slang-nodes/YulParametersDeclaration.js @@ -10,7 +10,7 @@ export class YulParametersDeclaration extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.openParen = ast.openParen.text; - this.parameters = parse(ast.parameters, parse, this.nextChildOffset); + this.parameters = parse(ast.parameters, this.nextChildOffset); this.closeParen = ast.closeParen.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/YulPath.js b/src/slang-nodes/YulPath.js index 212bd0f4c..84fa4e8c0 100644 --- a/src/slang-nodes/YulPath.js +++ b/src/slang-nodes/YulPath.js @@ -7,9 +7,7 @@ export class YulPath extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.items = ast.items.map((item) => - parse(item, parse, this.nextChildOffset) - ); + this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); this.separators = ast.separators.map((separator) => separator.text); this.initiateLoc(ast); } diff --git a/src/slang-nodes/YulPaths.js b/src/slang-nodes/YulPaths.js index ddc46eea7..f4db66bed 100644 --- a/src/slang-nodes/YulPaths.js +++ b/src/slang-nodes/YulPaths.js @@ -7,9 +7,7 @@ export class YulPaths extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.items = ast.items.map((item) => - parse(item, parse, this.nextChildOffset) - ); + this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); this.separators = ast.separators.map((separator) => separator.text); this.initiateLoc(ast); } diff --git a/src/slang-nodes/YulReturnsDeclaration.js b/src/slang-nodes/YulReturnsDeclaration.js index c08828ed5..6080251db 100644 --- a/src/slang-nodes/YulReturnsDeclaration.js +++ b/src/slang-nodes/YulReturnsDeclaration.js @@ -12,7 +12,7 @@ export class YulReturnsDeclaration extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.minusGreaterThan = ast.minusGreaterThan.text; - this.variables = parse(ast.variables, parse, this.nextChildOffset); + this.variables = parse(ast.variables, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/YulStatement.js b/src/slang-nodes/YulStatement.js index 5c5676ff3..616cbd80b 100644 --- a/src/slang-nodes/YulStatement.js +++ b/src/slang-nodes/YulStatement.js @@ -5,7 +5,7 @@ export class YulStatement extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.variant = parse(ast.variant, parse, this.nextChildOffset); + this.variant = parse(ast.variant, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/YulStatements.js b/src/slang-nodes/YulStatements.js index 97478d773..bee818af1 100644 --- a/src/slang-nodes/YulStatements.js +++ b/src/slang-nodes/YulStatements.js @@ -13,9 +13,7 @@ export class YulStatements extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.items = ast.items.map((item) => - parse(item, parse, this.nextChildOffset) - ); + this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); this.initiateLoc(ast); } diff --git a/src/slang-nodes/YulSwitchCase.js b/src/slang-nodes/YulSwitchCase.js index 68e8f5b57..df593f0bc 100644 --- a/src/slang-nodes/YulSwitchCase.js +++ b/src/slang-nodes/YulSwitchCase.js @@ -5,7 +5,7 @@ export class YulSwitchCase extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.variant = parse(ast.variant, parse, this.nextChildOffset); + this.variant = parse(ast.variant, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/YulSwitchCases.js b/src/slang-nodes/YulSwitchCases.js index 9fc6d0f8b..41b003256 100644 --- a/src/slang-nodes/YulSwitchCases.js +++ b/src/slang-nodes/YulSwitchCases.js @@ -8,9 +8,7 @@ export class YulSwitchCases extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.items = ast.items.map((item) => - parse(item, parse, this.nextChildOffset) - ); + this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); this.initiateLoc(ast); } diff --git a/src/slang-nodes/YulSwitchStatement.js b/src/slang-nodes/YulSwitchStatement.js index 21545835b..1d67cc164 100644 --- a/src/slang-nodes/YulSwitchStatement.js +++ b/src/slang-nodes/YulSwitchStatement.js @@ -13,8 +13,8 @@ export class YulSwitchStatement extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.switchKeyword = ast.switchKeyword.text; - this.expression = parse(ast.expression, parse, this.nextChildOffset); - this.cases = parse(ast.cases, parse, this.nextChildOffset); + this.expression = parse(ast.expression, this.nextChildOffset); + this.cases = parse(ast.cases, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/YulValueCase.js b/src/slang-nodes/YulValueCase.js index 7abf0532b..be822c0e8 100644 --- a/src/slang-nodes/YulValueCase.js +++ b/src/slang-nodes/YulValueCase.js @@ -10,8 +10,8 @@ export class YulValueCase extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.caseKeyword = ast.caseKeyword.text; - this.value = parse(ast.value, parse, this.nextChildOffset); - this.body = parse(ast.body, parse, this.nextChildOffset); + this.value = parse(ast.value, this.nextChildOffset); + this.body = parse(ast.body, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/YulVariableAssignmentStatement.js b/src/slang-nodes/YulVariableAssignmentStatement.js index 423197387..6f0a3c394 100644 --- a/src/slang-nodes/YulVariableAssignmentStatement.js +++ b/src/slang-nodes/YulVariableAssignmentStatement.js @@ -9,9 +9,9 @@ export class YulVariableAssignmentStatement extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.names = parse(ast.names, parse, this.nextChildOffset); - this.assignment = parse(ast.assignment, parse, this.nextChildOffset); - this.expression = parse(ast.expression, parse, this.nextChildOffset); + this.names = parse(ast.names, this.nextChildOffset); + this.assignment = parse(ast.assignment, this.nextChildOffset); + this.expression = parse(ast.expression, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/YulVariableDeclarationStatement.js b/src/slang-nodes/YulVariableDeclarationStatement.js index fda218e6a..55a043528 100644 --- a/src/slang-nodes/YulVariableDeclarationStatement.js +++ b/src/slang-nodes/YulVariableDeclarationStatement.js @@ -11,9 +11,7 @@ export class YulVariableDeclarationStatement extends SlangNode { super(ast, offset); this.letKeyword = ast.letKeyword.text; this.names = ast.names.text; - this.value = ast.value - ? parse(ast.value, parse, this.nextChildOffset) - : undefined; + this.value = ast.value ? parse(ast.value, this.nextChildOffset) : undefined; this.initiateLoc(ast); } diff --git a/src/slang-nodes/YulVariableDeclarationValue.js b/src/slang-nodes/YulVariableDeclarationValue.js index 582cac527..9060fe1a5 100644 --- a/src/slang-nodes/YulVariableDeclarationValue.js +++ b/src/slang-nodes/YulVariableDeclarationValue.js @@ -7,8 +7,8 @@ export class YulVariableDeclarationValue extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.assignment = parse(ast.assignment, parse, this.nextChildOffset); - this.expression = parse(ast.expression, parse, this.nextChildOffset); + this.assignment = parse(ast.assignment, this.nextChildOffset); + this.expression = parse(ast.expression, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slangParser.js b/src/slangParser.js index a40164559..60782e727 100644 --- a/src/slangParser.js +++ b/src/slangParser.js @@ -6,10 +6,11 @@ import { SourceUnit } from '@nomicfoundation/slang/ast/index.js'; import coerce from 'semver/functions/coerce.js'; import * as parsers from './slang-nodes/index.js'; -const genericParseBuilder = - (options) => - (ast, parseFunction, offset = 0) => - new parsers[ast.cst.kind](ast, offset, options, parseFunction); +function genericParseBuilder(options) { + return function genericParse(ast, offset = 0) { + return new parsers[ast.cst.kind](ast, offset, options, genericParse); + }; +} function parse(text, _parsers, options = _parsers) { const compiler = coerce(options.compiler); @@ -20,7 +21,7 @@ function parse(text, _parsers, options = _parsers) { ); const genericParse = genericParseBuilder(options); - const parsed = genericParse(ast, genericParse); + const parsed = genericParse(ast); parsed.collectComments(); diff --git a/src/slangPrinter.js b/src/slangPrinter.js index 94c5b73b4..79b41b583 100644 --- a/src/slangPrinter.js +++ b/src/slangPrinter.js @@ -38,16 +38,8 @@ function genericPrint(path, options, print) { options.locEnd(node) ); } - let ret; - try { - ret = node.print(path, print, options); - if (typeof ret === 'undefined') { - console.log(nodeType); - } - } catch (error) { - throw new Error(`${JSON.stringify(nodeType)} ${error}\n`); - } - return ret; + + return node.print(path, print, options); } export default genericPrint; From 19bcd2bfff342b8ec2cee75367f23a45cc60f16e Mon Sep 17 00:00:00 2001 From: Klaus Date: Sun, 14 Jul 2024 21:13:20 +1200 Subject: [PATCH 070/160] using unique Symbol instead of an incremental counter --- src/nodes/Conditional.js | 5 +---- src/nodes/FunctionCall.js | 5 +---- src/nodes/IndexAccess.js | 5 +---- src/nodes/VariableDeclarationStatement.js | 4 +--- src/slang-nodes/ConditionalExpression.js | 5 +---- src/slang-nodes/FunctionCallExpression.js | 6 +----- src/slang-nodes/IndexAccessExpression.js | 6 +----- src/slang-nodes/VariableDeclarationStatement.js | 5 +---- 8 files changed, 8 insertions(+), 33 deletions(-) diff --git a/src/nodes/Conditional.js b/src/nodes/Conditional.js index b6f74eb02..e49f03b81 100644 --- a/src/nodes/Conditional.js +++ b/src/nodes/Conditional.js @@ -3,7 +3,6 @@ import { printSeparatedItem } from '../common/printer-helpers.js'; const { group, hardline, ifBreak, indent, line, softline } = doc.builders; -let groupIndex = 0; const experimentalTernaries = (node, path, print, options) => { const parent = path.getParentNode(); const isNested = parent.type === 'Conditional'; @@ -30,11 +29,9 @@ const experimentalTernaries = (node, path, print, options) => { const conditionAndTrueExpressionGroup = group( [conditionDoc, trueExpressionDoc], - { id: `Conditional.trueExpressionDoc-${groupIndex}` } + { id: Symbol('Conditional.trueExpression') } ); - groupIndex += 1; - // For the odd case of `tabWidth` of 1 or 0 we initiate `fillTab` as a single // space. let fillTab = ' '; diff --git a/src/nodes/FunctionCall.js b/src/nodes/FunctionCall.js index 865966805..05c54256b 100644 --- a/src/nodes/FunctionCall.js +++ b/src/nodes/FunctionCall.js @@ -24,7 +24,6 @@ const printArguments = (path, print) => lastSeparator: [softline, ')'] }); -let groupIndex = 0; export const FunctionCall = { print: ({ node, path, print, options }) => { let expressionDoc = path.call(print, 'expression'); @@ -42,11 +41,9 @@ export const FunctionCall = { // arguments accordingly. if (expressionDoc.label === 'MemberAccessChain') { expressionDoc = group(expressionDoc.contents, { - id: `FunctionCall.expression-${groupIndex}` + id: Symbol('FunctionCall.expression') }); - groupIndex += 1; - argumentsDoc = indentIfBreak(argumentsDoc, { groupId: expressionDoc.id }); diff --git a/src/nodes/IndexAccess.js b/src/nodes/IndexAccess.js index bb38d3857..3205388b7 100644 --- a/src/nodes/IndexAccess.js +++ b/src/nodes/IndexAccess.js @@ -2,7 +2,6 @@ import { doc } from 'prettier'; const { group, indent, indentIfBreak, label, softline } = doc.builders; -let groupIndex = 0; export const IndexAccess = { print: ({ path, print }) => { let baseDoc = path.call(print, 'base'); @@ -16,11 +15,9 @@ export const IndexAccess = { // arguments accordingly. if (baseDoc.label === 'MemberAccessChain') { baseDoc = group(baseDoc.contents, { - id: `IndexAccess.base-${groupIndex}` + id: Symbol('IndexAccess.base') }); - groupIndex += 1; - indexDoc = indentIfBreak(indexDoc, { groupId: baseDoc.id }); diff --git a/src/nodes/VariableDeclarationStatement.js b/src/nodes/VariableDeclarationStatement.js index 7f078bf1a..ae08a94a6 100644 --- a/src/nodes/VariableDeclarationStatement.js +++ b/src/nodes/VariableDeclarationStatement.js @@ -9,7 +9,6 @@ const embraceVariables = (document, embrace) => const initialValue = (node, path, print) => node.initialValue ? [' = ', path.call(print, 'initialValue')] : ''; -let groupIndex = 0; export const VariableDeclarationStatement = { print: ({ node, path, print }) => { const startsWithVar = @@ -23,9 +22,8 @@ export const VariableDeclarationStatement = { node.variables.length > 1 || startsWithVar ) ], - { id: `VariableDeclarationStatement.variables-${groupIndex}` } + { id: Symbol('VariableDeclarationStatement.variables') } ); - groupIndex += 1; const initialValueDoc = initialValue(node, path, print); return group([ diff --git a/src/slang-nodes/ConditionalExpression.js b/src/slang-nodes/ConditionalExpression.js index f3b486849..defdb688c 100644 --- a/src/slang-nodes/ConditionalExpression.js +++ b/src/slang-nodes/ConditionalExpression.js @@ -5,7 +5,6 @@ import { SlangNode } from './SlangNode.js'; const { group, hardline, ifBreak, indent, line, softline } = doc.builders; -let groupIndex = 0; const experimentalTernaries = (node, path, print, options) => { const grandparent = path.getNode(2); const isNested = grandparent.kind === 'ConditionalExpression'; @@ -37,11 +36,9 @@ const experimentalTernaries = (node, path, print, options) => { const conditionAndTrueExpressionGroup = group( [operandDoc, trueExpressionDoc], - { id: Symbol(`Slang.ConditionalExpression.trueExpression-${groupIndex}`) } + { id: Symbol('Slang.ConditionalExpression.trueExpression') } ); - groupIndex += 1; - // For the odd case of `tabWidth` of 1 or 0 we initiate `fillTab` as a single // space. let fillTab = ' '; diff --git a/src/slang-nodes/FunctionCallExpression.js b/src/slang-nodes/FunctionCallExpression.js index 11e726dc9..48b0c3a73 100644 --- a/src/slang-nodes/FunctionCallExpression.js +++ b/src/slang-nodes/FunctionCallExpression.js @@ -4,8 +4,6 @@ import { SlangNode } from './SlangNode.js'; const { group, indentIfBreak, label } = doc.builders; -let groupIndex = 0; - export class FunctionCallExpression extends SlangNode { operand; @@ -26,11 +24,9 @@ export class FunctionCallExpression extends SlangNode { // arguments accordingly. if (isLabel(operandDoc) && operandDoc.label === 'MemberAccessChain') { operandDoc = group(operandDoc.contents, { - id: `FunctionCallExpression.operand-${groupIndex}` + id: Symbol('FunctionCallExpression.operand') }); - groupIndex += 1; - argumentsDoc = indentIfBreak(argumentsDoc, { groupId: operandDoc.id }); diff --git a/src/slang-nodes/IndexAccessExpression.js b/src/slang-nodes/IndexAccessExpression.js index 7bddd1814..9d506ffd6 100644 --- a/src/slang-nodes/IndexAccessExpression.js +++ b/src/slang-nodes/IndexAccessExpression.js @@ -4,8 +4,6 @@ import { SlangNode } from './SlangNode.js'; const { group, indent, indentIfBreak, label, softline } = doc.builders; -let groupIndex = 0; - export class IndexAccessExpression extends SlangNode { operand; @@ -44,11 +42,9 @@ export class IndexAccessExpression extends SlangNode { // arguments accordingly. if (isLabel(operandDoc) && operandDoc.label === 'MemberAccessChain') { operandDoc = group(operandDoc.contents, { - id: `IndexAccessExpression.operand-${groupIndex}` + id: Symbol('IndexAccessExpression.operand') }); - groupIndex += 1; - indexDoc = indentIfBreak(indexDoc, { groupId: operandDoc.id }); diff --git a/src/slang-nodes/VariableDeclarationStatement.js b/src/slang-nodes/VariableDeclarationStatement.js index 524704528..c518fba33 100644 --- a/src/slang-nodes/VariableDeclarationStatement.js +++ b/src/slang-nodes/VariableDeclarationStatement.js @@ -3,8 +3,6 @@ import { SlangNode } from './SlangNode.js'; const { group, indent, indentIfBreak, line } = doc.builders; -let groupIndex = 0; - export class VariableDeclarationStatement extends SlangNode { variableType; @@ -39,9 +37,8 @@ export class VariableDeclarationStatement extends SlangNode { ` ${this.name}` ]) ], - { id: `VariableDeclarationStatement.variables-${groupIndex}` } + { id: 'VariableDeclarationStatement.variables' } ); - groupIndex += 1; return [ declarationDoc, From fde597e0e2b5b67192431935a09dcfc5cab8970a Mon Sep 17 00:00:00 2001 From: Klaus Date: Sun, 14 Jul 2024 21:40:41 +1200 Subject: [PATCH 071/160] adding startWithTrivia and endWithTrivia to generated loc objects --- src/slang-nodes/ExponentiationExpression.js | 3 +++ src/slang-utils/create-hug-function.js | 22 ++++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/slang-nodes/ExponentiationExpression.js b/src/slang-nodes/ExponentiationExpression.js index 62bff0b09..fe644acb6 100644 --- a/src/slang-nodes/ExponentiationExpression.js +++ b/src/slang-nodes/ExponentiationExpression.js @@ -43,7 +43,10 @@ export class ExponentiationExpression extends SlangNode { // https://github.com/NomicFoundation/slang/issues/1031 if (this.rightOperand.variant.kind === 'ExponentiationExpression') { const leftLoc = { + startWithTrivia: this.leftOperand.loc.startWithTrivia, start: this.leftOperand.loc.start, + endWithTrivia: + this.rightOperand.variant.leftOperand.loc.endWithTrivia, end: this.rightOperand.variant.leftOperand.loc.end }; this.leftOperand = new Expression({ diff --git a/src/slang-utils/create-hug-function.js b/src/slang-utils/create-hug-function.js index 83fa9c690..b4ccaef55 100644 --- a/src/slang-utils/create-hug-function.js +++ b/src/slang-utils/create-hug-function.js @@ -7,21 +7,31 @@ import { TupleValue } from '../slang-nodes/TupleValue.js'; export function createHugFunction(huggableOperators) { const operators = new Set(huggableOperators); return (node) => { - if (isBinaryOperation(node.variant) && operators.has(node.variant.operator)) + if ( + isBinaryOperation(node.variant) && + operators.has(node.variant.operator) + ) { + const loc = { + startWithTrivia: node.loc.startWithTrivia, + start: node.loc.start, + endWithTrivia: node.loc.endWithTrivia, + end: node.loc.end + }; + return new Expression({ kind: 'Expression', - loc: { ...node.loc }, + loc: { ...loc }, variant: new TupleExpression({ kind: 'TupleExpression', - loc: { ...node.loc }, + loc: { ...loc }, openParen: '(', items: new TupleValues({ kind: 'TupleValues', - loc: { ...node.loc }, + loc: { ...loc }, items: [ new TupleValue({ kind: 'TupleValue', - loc: { ...node.loc }, + loc: { ...loc }, expression: node }) ], @@ -30,6 +40,8 @@ export function createHugFunction(huggableOperators) { closeParen: ')' }) }); + } + return node; }; } From 85e7d9e8228accf7bb3226e1332724aeb4f9d43a Mon Sep 17 00:00:00 2001 From: Klaus Date: Sun, 14 Jul 2024 21:50:15 +1200 Subject: [PATCH 072/160] avoiding explicitly setting undefined --- src/slang-nodes/ArrayTypeName.js | 4 +++- src/slang-nodes/AssemblyStatement.js | 8 ++++++-- src/slang-nodes/CatchClause.js | 4 +++- src/slang-nodes/CatchClauseError.js | 4 ++-- src/slang-nodes/ContractDefinition.js | 6 +++--- src/slang-nodes/DecimalNumberExpression.js | 4 +++- src/slang-nodes/FallbackFunctionDefinition.js | 6 +++--- src/slang-nodes/ForStatement.js | 6 +++--- src/slang-nodes/FunctionDefinition.js | 6 +++--- src/slang-nodes/FunctionType.js | 6 +++--- src/slang-nodes/HexNumberExpression.js | 4 +++- src/slang-nodes/IfStatement.js | 6 +++--- src/slang-nodes/ImportDeconstructionSymbol.js | 4 +++- src/slang-nodes/IndexAccessEnd.js | 4 +++- src/slang-nodes/IndexAccessExpression.js | 8 ++++++-- src/slang-nodes/InheritanceType.js | 6 +++--- src/slang-nodes/InterfaceDefinition.js | 6 +++--- src/slang-nodes/ModifierInvocation.js | 6 +++--- src/slang-nodes/NamedArgumentsDeclaration.js | 6 +++--- src/slang-nodes/OverrideSpecifier.js | 6 +++--- src/slang-nodes/Parameter.js | 6 +++--- src/slang-nodes/PathImport.js | 4 +++- src/slang-nodes/ReturnStatement.js | 6 +++--- src/slang-nodes/RevertStatement.js | 4 +++- src/slang-nodes/StateVariableDefinition.js | 4 +++- src/slang-nodes/TryStatement.js | 6 +++--- src/slang-nodes/TupleDeconstructionElement.js | 6 +++--- src/slang-nodes/TupleValue.js | 6 +++--- src/slang-nodes/TypedTupleMember.js | 6 +++--- src/slang-nodes/UntypedTupleMember.js | 6 +++--- src/slang-nodes/UsingDeconstructionSymbol.js | 4 +++- src/slang-nodes/VariableDeclarationStatement.js | 10 ++++++---- src/slang-nodes/YulFunctionDefinition.js | 6 +++--- src/slang-nodes/YulVariableDeclarationStatement.js | 4 +++- 34 files changed, 110 insertions(+), 78 deletions(-) diff --git a/src/slang-nodes/ArrayTypeName.js b/src/slang-nodes/ArrayTypeName.js index 618e61a92..610e85bf8 100644 --- a/src/slang-nodes/ArrayTypeName.js +++ b/src/slang-nodes/ArrayTypeName.js @@ -13,7 +13,9 @@ export class ArrayTypeName extends SlangNode { super(ast, offset); this.operand = parse(ast.operand, this.nextChildOffset); this.openBracket = ast.openBracket.text; - this.index = ast.index ? parse(ast.index, this.nextChildOffset) : undefined; + if (ast.index) { + this.index = parse(ast.index, this.nextChildOffset); + } this.closeBracket = ast.closeBracket.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/AssemblyStatement.js b/src/slang-nodes/AssemblyStatement.js index 8ef7041e1..6e0c92fe5 100644 --- a/src/slang-nodes/AssemblyStatement.js +++ b/src/slang-nodes/AssemblyStatement.js @@ -12,8 +12,12 @@ export class AssemblyStatement extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.assemblyKeyword = ast.assemblyKeyword.text; - this.label = ast.label ? parse(ast.label, this.nextChildOffset) : undefined; - this.flags = ast.flags ? parse(ast.flags, this.nextChildOffset) : undefined; + if (ast.label) { + this.label = parse(ast.label, this.nextChildOffset); + } + if (ast.flags) { + this.flags = parse(ast.flags, this.nextChildOffset); + } this.body = parse(ast.body, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/CatchClause.js b/src/slang-nodes/CatchClause.js index 17c0a2a4b..e95527609 100644 --- a/src/slang-nodes/CatchClause.js +++ b/src/slang-nodes/CatchClause.js @@ -10,7 +10,9 @@ export class CatchClause extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.catchKeyword = ast.catchKeyword.text; - this.error = ast.error ? parse(ast.error, this.nextChildOffset) : undefined; + if (ast.error) { + this.error = parse(ast.error, this.nextChildOffset); + } this.body = parse(ast.body, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/CatchClauseError.js b/src/slang-nodes/CatchClauseError.js index e2f3f5d58..57f5700b6 100644 --- a/src/slang-nodes/CatchClauseError.js +++ b/src/slang-nodes/CatchClauseError.js @@ -10,12 +10,12 @@ export class CatchClauseError extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.name = ast.name?.text ?? ''; + this.name = ast.name?.text; this.parameters = parse(ast.parameters, this.nextChildOffset); this.initiateLoc(ast); } print(path, print) { - return [this.name, group(path.call(print, 'parameters')), ' ']; + return [`${this.name ?? ''}`, group(path.call(print, 'parameters')), ' ']; } } diff --git a/src/slang-nodes/ContractDefinition.js b/src/slang-nodes/ContractDefinition.js index e27c607f2..0c32064c0 100644 --- a/src/slang-nodes/ContractDefinition.js +++ b/src/slang-nodes/ContractDefinition.js @@ -25,9 +25,9 @@ export class ContractDefinition extends SlangNode { this.abstractKeyword = ast.abstractKeyword?.text; this.contractKeyword = ast.contractKeyword.text; this.name = ast.name.text; - this.inheritance = ast.inheritance - ? parse(ast.inheritance, this.nextChildOffset) - : undefined; + if (ast.inheritance) { + this.inheritance = parse(ast.inheritance, this.nextChildOffset); + } this.openBrace = ast.openBrace.text; this.members = parse(ast.members, this.nextChildOffset); this.closeBrace = ast.closeBrace.text; diff --git a/src/slang-nodes/DecimalNumberExpression.js b/src/slang-nodes/DecimalNumberExpression.js index 7d9c5d217..29b9a8efb 100644 --- a/src/slang-nodes/DecimalNumberExpression.js +++ b/src/slang-nodes/DecimalNumberExpression.js @@ -8,7 +8,9 @@ export class DecimalNumberExpression extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.literal = ast.literal.text; - this.unit = ast.unit ? parse(ast.unit, this.nextChildOffset) : undefined; + if (ast.unit) { + this.unit = parse(ast.unit, this.nextChildOffset); + } this.initiateLoc(ast); } diff --git a/src/slang-nodes/FallbackFunctionDefinition.js b/src/slang-nodes/FallbackFunctionDefinition.js index 7150a3adf..267a72b5c 100644 --- a/src/slang-nodes/FallbackFunctionDefinition.js +++ b/src/slang-nodes/FallbackFunctionDefinition.js @@ -17,9 +17,9 @@ export class FallbackFunctionDefinition extends SlangNode { this.fallbackKeyword = ast.fallbackKeyword.text; this.parameters = parse(ast.parameters, this.nextChildOffset); this.attributes = parse(ast.attributes, this.nextChildOffset); - this.returns = ast.returns - ? parse(ast.returns, this.nextChildOffset) - : undefined; + if (ast.returns) { + this.returns = parse(ast.returns, this.nextChildOffset); + } this.body = parse(ast.body, this.nextChildOffset); this.cleanModifierInvocationArguments(); diff --git a/src/slang-nodes/ForStatement.js b/src/slang-nodes/ForStatement.js index 76a4fefc7..cbd4c11e7 100644 --- a/src/slang-nodes/ForStatement.js +++ b/src/slang-nodes/ForStatement.js @@ -25,9 +25,9 @@ export class ForStatement extends SlangNode { this.openParen = ast.openParen.text; this.initialization = parse(ast.initialization, this.nextChildOffset); this.condition = parse(ast.condition, this.nextChildOffset); - this.iterator = ast.iterator - ? parse(ast.iterator, this.nextChildOffset) - : undefined; + if (ast.iterator) { + this.iterator = parse(ast.iterator, this.nextChildOffset); + } this.closeParen = ast.closeParen.text; this.body = parse(ast.body, this.nextChildOffset); this.initiateLoc(ast); diff --git a/src/slang-nodes/FunctionDefinition.js b/src/slang-nodes/FunctionDefinition.js index f53390c06..a000984fd 100644 --- a/src/slang-nodes/FunctionDefinition.js +++ b/src/slang-nodes/FunctionDefinition.js @@ -22,9 +22,9 @@ export class FunctionDefinition extends SlangNode { this.name = parse(ast.name, this.nextChildOffset); this.parameters = parse(ast.parameters, this.nextChildOffset); this.attributes = parse(ast.attributes, this.nextChildOffset); - this.returns = ast.returns - ? parse(ast.returns, this.nextChildOffset) - : undefined; + if (ast.returns) { + this.returns = parse(ast.returns, this.nextChildOffset); + } this.body = parse(ast.body, this.nextChildOffset); // Older versions of Solidity defined a constructor as a function having diff --git a/src/slang-nodes/FunctionType.js b/src/slang-nodes/FunctionType.js index fc1c03245..642eb7d90 100644 --- a/src/slang-nodes/FunctionType.js +++ b/src/slang-nodes/FunctionType.js @@ -15,9 +15,9 @@ export class FunctionType extends SlangNode { this.functionKeyword = ast.functionKeyword.text; this.parameters = parse(ast.parameters, this.nextChildOffset); this.attributes = parse(ast.attributes, this.nextChildOffset); - this.returns = ast.returns - ? parse(ast.returns, this.nextChildOffset) - : undefined; + if (ast.returns) { + this.returns = parse(ast.returns, this.nextChildOffset); + } this.initiateLoc(ast); } diff --git a/src/slang-nodes/HexNumberExpression.js b/src/slang-nodes/HexNumberExpression.js index 321cec17b..ebf012a09 100644 --- a/src/slang-nodes/HexNumberExpression.js +++ b/src/slang-nodes/HexNumberExpression.js @@ -8,7 +8,9 @@ export class HexNumberExpression extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.literal = ast.literal.text; - this.unit = ast.unit ? parse(ast.unit, this.nextChildOffset) : undefined; + if (ast.unit) { + this.unit = parse(ast.unit, this.nextChildOffset); + } this.initiateLoc(ast); } diff --git a/src/slang-nodes/IfStatement.js b/src/slang-nodes/IfStatement.js index b41267971..294a9891f 100644 --- a/src/slang-nodes/IfStatement.js +++ b/src/slang-nodes/IfStatement.js @@ -31,9 +31,9 @@ export class IfStatement extends SlangNode { this.condition = parse(ast.condition, this.nextChildOffset); this.closeParen = ast.closeParen.text; this.body = parse(ast.body, this.nextChildOffset); - this.elseBranch = ast.elseBranch - ? parse(ast.elseBranch, this.nextChildOffset) - : undefined; + if (ast.elseBranch) { + this.elseBranch = parse(ast.elseBranch, this.nextChildOffset); + } this.initiateLoc(ast); } diff --git a/src/slang-nodes/ImportDeconstructionSymbol.js b/src/slang-nodes/ImportDeconstructionSymbol.js index 0be18fba4..abea1ba5f 100644 --- a/src/slang-nodes/ImportDeconstructionSymbol.js +++ b/src/slang-nodes/ImportDeconstructionSymbol.js @@ -8,7 +8,9 @@ export class ImportDeconstructionSymbol extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.name = ast.name.text; - this.alias = ast.alias ? parse(ast.alias, this.nextChildOffset) : undefined; + if (ast.alias) { + this.alias = parse(ast.alias, this.nextChildOffset); + } this.initiateLoc(ast); } diff --git a/src/slang-nodes/IndexAccessEnd.js b/src/slang-nodes/IndexAccessEnd.js index 89e218e7b..ae2d441fa 100644 --- a/src/slang-nodes/IndexAccessEnd.js +++ b/src/slang-nodes/IndexAccessEnd.js @@ -8,7 +8,9 @@ export class IndexAccessEnd extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.colon = ast.colon.text; - this.end = ast.end ? parse(ast.end, this.nextChildOffset) : undefined; + if (ast.end) { + this.end = parse(ast.end, this.nextChildOffset); + } this.initiateLoc(ast); } diff --git a/src/slang-nodes/IndexAccessExpression.js b/src/slang-nodes/IndexAccessExpression.js index 9d506ffd6..493a3a522 100644 --- a/src/slang-nodes/IndexAccessExpression.js +++ b/src/slang-nodes/IndexAccessExpression.js @@ -19,8 +19,12 @@ export class IndexAccessExpression extends SlangNode { super(ast, offset); this.operand = parse(ast.operand, this.nextChildOffset); this.openBracket = ast.openBracket.text; - this.start = ast.start ? parse(ast.start, this.nextChildOffset) : undefined; - this.end = ast.end ? parse(ast.end, this.nextChildOffset) : undefined; + if (ast.start) { + this.start = parse(ast.start, this.nextChildOffset); + } + if (ast.end) { + this.end = parse(ast.end, this.nextChildOffset); + } this.closeBracket = ast.closeBracket.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/InheritanceType.js b/src/slang-nodes/InheritanceType.js index 250781108..a050e6c0a 100644 --- a/src/slang-nodes/InheritanceType.js +++ b/src/slang-nodes/InheritanceType.js @@ -8,9 +8,9 @@ export class InheritanceType extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.typeName = parse(ast.typeName, this.nextChildOffset); - this.arguments = ast.arguments - ? parse(ast.arguments, this.nextChildOffset) - : undefined; + if (ast.arguments) { + this.arguments = parse(ast.arguments, this.nextChildOffset); + } this.initiateLoc(ast); } diff --git a/src/slang-nodes/InterfaceDefinition.js b/src/slang-nodes/InterfaceDefinition.js index 7ea7aad84..73d28eda6 100644 --- a/src/slang-nodes/InterfaceDefinition.js +++ b/src/slang-nodes/InterfaceDefinition.js @@ -20,9 +20,9 @@ export class InterfaceDefinition extends SlangNode { super(ast, offset); this.interfaceKeyword = ast.interfaceKeyword.text; this.name = ast.name.text; - this.inheritance = ast.inheritence - ? parse(ast.inheritance, this.nextChildOffset) - : undefined; + if (ast.inheritence) { + this.inheritance = parse(ast.inheritance, this.nextChildOffset); + } this.openBrace = ast.openBrace.text; this.members = parse(ast.members, this.nextChildOffset); this.closeBrace = ast.closeBrace.text; diff --git a/src/slang-nodes/ModifierInvocation.js b/src/slang-nodes/ModifierInvocation.js index a7fd4980b..794ea6d07 100644 --- a/src/slang-nodes/ModifierInvocation.js +++ b/src/slang-nodes/ModifierInvocation.js @@ -12,9 +12,9 @@ export class ModifierInvocation extends SlangNode { super(ast, offset); this.#ast = ast; this.name = parse(ast.name, this.nextChildOffset); - this.arguments = ast.arguments - ? parse(ast.arguments, this.nextChildOffset) - : undefined; + if (ast.arguments) { + this.arguments = parse(ast.arguments, this.nextChildOffset); + } this.initiateLoc(ast); } diff --git a/src/slang-nodes/NamedArgumentsDeclaration.js b/src/slang-nodes/NamedArgumentsDeclaration.js index aaa27e997..de9528326 100644 --- a/src/slang-nodes/NamedArgumentsDeclaration.js +++ b/src/slang-nodes/NamedArgumentsDeclaration.js @@ -10,9 +10,9 @@ export class NamedArgumentsDeclaration extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.openParen = ast.openParen.text; - this.arguments = ast.arguments - ? parse(ast.arguments, this.nextChildOffset) - : undefined; + if (ast.arguments) { + this.arguments = parse(ast.arguments, this.nextChildOffset); + } this.closeParen = ast.closeParen.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/OverrideSpecifier.js b/src/slang-nodes/OverrideSpecifier.js index 9e340abd3..f0ac1f30e 100644 --- a/src/slang-nodes/OverrideSpecifier.js +++ b/src/slang-nodes/OverrideSpecifier.js @@ -8,9 +8,9 @@ export class OverrideSpecifier extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.overrideKeyword = ast.overrideKeyword.text; - this.overridden = ast.overridden - ? parse(ast.overridden, this.nextChildOffset) - : undefined; + if (ast.overridden) { + this.overridden = parse(ast.overridden, this.nextChildOffset); + } this.initiateLoc(ast); } diff --git a/src/slang-nodes/Parameter.js b/src/slang-nodes/Parameter.js index ceba4609b..c23313bee 100644 --- a/src/slang-nodes/Parameter.js +++ b/src/slang-nodes/Parameter.js @@ -13,9 +13,9 @@ export class Parameter extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.typeName = parse(ast.typeName, this.nextChildOffset); - this.storageLocation = ast.storageLocation - ? parse(ast.storageLocation, this.nextChildOffset) - : undefined; + if (ast.storageLocation) { + this.storageLocation = parse(ast.storageLocation, this.nextChildOffset); + } this.name = ast.name?.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/PathImport.js b/src/slang-nodes/PathImport.js index 5d414cd13..4b5fb5539 100644 --- a/src/slang-nodes/PathImport.js +++ b/src/slang-nodes/PathImport.js @@ -8,7 +8,9 @@ export class PathImport extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.path = parse(ast.path, this.nextChildOffset); - this.alias = ast.alias ? parse(ast.alias, this.nextChildOffset) : undefined; + if (ast.alias) { + this.alias = parse(ast.alias, this.nextChildOffset); + } this.initiateLoc(ast); } diff --git a/src/slang-nodes/ReturnStatement.js b/src/slang-nodes/ReturnStatement.js index b90da5f80..abc4512b5 100644 --- a/src/slang-nodes/ReturnStatement.js +++ b/src/slang-nodes/ReturnStatement.js @@ -24,9 +24,9 @@ export class ReturnStatement extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.returnKeyword = ast.returnKeyword.text; - this.expression = ast.expression - ? parse(ast.expression, this.nextChildOffset) - : undefined; + if (ast.expression) { + this.expression = parse(ast.expression, this.nextChildOffset); + } this.semicolon = ast.semicolon.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/RevertStatement.js b/src/slang-nodes/RevertStatement.js index 89d686d8e..11c6fc923 100644 --- a/src/slang-nodes/RevertStatement.js +++ b/src/slang-nodes/RevertStatement.js @@ -12,7 +12,9 @@ export class RevertStatement extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.revertKeyword = ast.revertKeyword.text; - this.error = ast.error ? parse(ast.error, this.nextChildOffset) : undefined; + if (ast.error) { + this.error = parse(ast.error, this.nextChildOffset); + } this.arguments = parse(ast.arguments, this.nextChildOffset); this.semicolon = ast.semicolon.text; this.initiateLoc(ast); diff --git a/src/slang-nodes/StateVariableDefinition.js b/src/slang-nodes/StateVariableDefinition.js index 304210f37..064c71673 100644 --- a/src/slang-nodes/StateVariableDefinition.js +++ b/src/slang-nodes/StateVariableDefinition.js @@ -16,7 +16,9 @@ export class StateVariableDefinition extends SlangNode { this.typeName = parse(ast.typeName, this.nextChildOffset); this.attributes = parse(ast.attributes, this.nextChildOffset); this.name = ast.name.text; - this.value = ast.value ? parse(ast.value, this.nextChildOffset) : undefined; + if (ast.value) { + this.value = parse(ast.value, this.nextChildOffset); + } this.semicolon = ast.semicolon.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/TryStatement.js b/src/slang-nodes/TryStatement.js index 3ef0bce53..8c2335237 100644 --- a/src/slang-nodes/TryStatement.js +++ b/src/slang-nodes/TryStatement.js @@ -19,9 +19,9 @@ export class TryStatement extends SlangNode { super(ast, offset); this.tryKeyword = ast.tryKeyword.text; this.expression = parse(ast.expression, this.nextChildOffset); - this.returns = ast.returns - ? parse(ast.returns, this.nextChildOffset) - : undefined; + if (ast.returns) { + this.returns = parse(ast.returns, this.nextChildOffset); + } this.body = parse(ast.body, this.nextChildOffset); this.catchClauses = parse(ast.catchClauses, this.nextChildOffset); this.initiateLoc(ast); diff --git a/src/slang-nodes/TupleDeconstructionElement.js b/src/slang-nodes/TupleDeconstructionElement.js index bd466706c..429115704 100644 --- a/src/slang-nodes/TupleDeconstructionElement.js +++ b/src/slang-nodes/TupleDeconstructionElement.js @@ -5,9 +5,9 @@ export class TupleDeconstructionElement extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.member = ast.member - ? parse(ast.member, this.nextChildOffset) - : undefined; + if (ast.member) { + this.member = parse(ast.member, this.nextChildOffset); + } this.initiateLoc(ast); } diff --git a/src/slang-nodes/TupleValue.js b/src/slang-nodes/TupleValue.js index 00efa8661..60c70449d 100644 --- a/src/slang-nodes/TupleValue.js +++ b/src/slang-nodes/TupleValue.js @@ -6,9 +6,9 @@ export class TupleValue extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); if (offset) { - this.expression = ast.expression - ? parse(ast.expression, this.nextChildOffset) - : undefined; + if (ast.expression) { + this.expression = parse(ast.expression, this.nextChildOffset); + } this.initiateLoc(ast); } else { this.kind = ast.kind; diff --git a/src/slang-nodes/TypedTupleMember.js b/src/slang-nodes/TypedTupleMember.js index 4d6dc2439..7302d770d 100644 --- a/src/slang-nodes/TypedTupleMember.js +++ b/src/slang-nodes/TypedTupleMember.js @@ -10,9 +10,9 @@ export class TypedTupleMember extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.typeName = parse(ast.typeName, this.nextChildOffset); - this.storageLocation = ast.storageLocation - ? parse(ast.storageLocation, this.nextChildOffset) - : undefined; + if (ast.storageLocation) { + this.storageLocation = parse(ast.storageLocation, this.nextChildOffset); + } this.name = ast.name.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/UntypedTupleMember.js b/src/slang-nodes/UntypedTupleMember.js index 71b1d17a7..fb09e6a2a 100644 --- a/src/slang-nodes/UntypedTupleMember.js +++ b/src/slang-nodes/UntypedTupleMember.js @@ -7,9 +7,9 @@ export class UntypedTupleMember extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); - this.storageLocation = ast.storageLocation - ? parse(ast.storageLocation, this.nextChildOffset) - : undefined; + if (ast.storageLocation) { + this.storageLocation = parse(ast.storageLocation, this.nextChildOffset); + } this.name = ast.name.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/UsingDeconstructionSymbol.js b/src/slang-nodes/UsingDeconstructionSymbol.js index 846abb70c..88997845c 100644 --- a/src/slang-nodes/UsingDeconstructionSymbol.js +++ b/src/slang-nodes/UsingDeconstructionSymbol.js @@ -8,7 +8,9 @@ export class UsingDeconstructionSymbol extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.name = parse(ast.name, this.nextChildOffset); - this.alias = ast.alias ? parse(ast.alias, this.nextChildOffset) : undefined; + if (ast.alias) { + this.alias = parse(ast.alias, this.nextChildOffset); + } this.initiateLoc(ast); } diff --git a/src/slang-nodes/VariableDeclarationStatement.js b/src/slang-nodes/VariableDeclarationStatement.js index c518fba33..8c5c50598 100644 --- a/src/slang-nodes/VariableDeclarationStatement.js +++ b/src/slang-nodes/VariableDeclarationStatement.js @@ -17,11 +17,13 @@ export class VariableDeclarationStatement extends SlangNode { constructor(ast, offset, options, parse) { super(ast, offset); this.variableType = parse(ast.variableType, this.nextChildOffset); - this.storageLocation = ast.storageLocation - ? parse(ast.storageLocation, this.nextChildOffset) - : undefined; + if (ast.storageLocation) { + this.storageLocation = parse(ast.storageLocation, this.nextChildOffset); + } this.name = ast.name.text; - this.value = ast.value ? parse(ast.value, this.nextChildOffset) : undefined; + if (ast.value) { + this.value = parse(ast.value, this.nextChildOffset); + } this.semicolon = ast.semicolon.text; this.initiateLoc(ast); } diff --git a/src/slang-nodes/YulFunctionDefinition.js b/src/slang-nodes/YulFunctionDefinition.js index 37d9263d1..a3044eade 100644 --- a/src/slang-nodes/YulFunctionDefinition.js +++ b/src/slang-nodes/YulFunctionDefinition.js @@ -16,9 +16,9 @@ export class YulFunctionDefinition extends SlangNode { this.functionKeyword = ast.functionKeyword.text; this.name = ast.name.text; this.parameters = parse(ast.parameters, this.nextChildOffset); - this.returns = ast.returns - ? parse(ast.returns, this.nextChildOffset) - : undefined; + if (ast.returns) { + this.returns = parse(ast.returns, this.nextChildOffset); + } this.body = parse(ast.body, this.nextChildOffset); this.initiateLoc(ast); } diff --git a/src/slang-nodes/YulVariableDeclarationStatement.js b/src/slang-nodes/YulVariableDeclarationStatement.js index 55a043528..85e67c5ec 100644 --- a/src/slang-nodes/YulVariableDeclarationStatement.js +++ b/src/slang-nodes/YulVariableDeclarationStatement.js @@ -11,7 +11,9 @@ export class YulVariableDeclarationStatement extends SlangNode { super(ast, offset); this.letKeyword = ast.letKeyword.text; this.names = ast.names.text; - this.value = ast.value ? parse(ast.value, this.nextChildOffset) : undefined; + if (ast.value) { + this.value = parse(ast.value, this.nextChildOffset); + } this.initiateLoc(ast); } From 269f09f24c4223f674164d8f60ae1e7f64b72166 Mon Sep 17 00:00:00 2001 From: Klaus Date: Mon, 15 Jul 2024 00:30:42 +1200 Subject: [PATCH 073/160] populating properties' values automatically, instead of setting each one by one --- src/slang-nodes/ABICoderPragma.js | 8 ++--- src/slang-nodes/AdditiveExpression.js | 11 ++++--- src/slang-nodes/AddressType.js | 8 ++--- src/slang-nodes/AndExpression.js | 9 +++--- src/slang-nodes/ArgumentsDeclaration.js | 7 ++-- src/slang-nodes/ArrayExpression.js | 9 +++--- src/slang-nodes/ArrayTypeName.js | 12 +++---- src/slang-nodes/ArrayValues.js | 8 ++--- src/slang-nodes/AssemblyFlags.js | 8 ++--- src/slang-nodes/AssemblyFlagsDeclaration.js | 9 +++--- src/slang-nodes/AssemblyStatement.js | 14 +++----- src/slang-nodes/AssignmentExpression.js | 9 +++--- src/slang-nodes/BitwiseAndExpression.js | 11 ++++--- src/slang-nodes/BitwiseOrExpression.js | 11 ++++--- src/slang-nodes/BitwiseXorExpression.js | 11 ++++--- src/slang-nodes/Block.js | 9 +++--- src/slang-nodes/BreakStatement.js | 8 ++--- src/slang-nodes/CallOptions.js | 8 ++--- src/slang-nodes/CallOptionsExpression.js | 10 +++--- src/slang-nodes/CatchClause.js | 11 +++---- src/slang-nodes/CatchClauseError.js | 8 ++--- src/slang-nodes/CatchClauses.js | 7 ++-- src/slang-nodes/ComparisonExpression.js | 9 +++--- src/slang-nodes/ConditionalExpression.js | 12 +++---- src/slang-nodes/ConstantDefinition.js | 12 +++---- src/slang-nodes/ConstructorAttribute.js | 10 +++--- src/slang-nodes/ConstructorAttributes.js | 10 +++--- src/slang-nodes/ConstructorDefinition.js | 10 +++--- src/slang-nodes/ContinueStatement.js | 8 ++--- src/slang-nodes/ContractDefinition.js | 16 +++------- src/slang-nodes/ContractMember.js | 7 ++-- src/slang-nodes/ContractMembers.js | 7 ++-- src/slang-nodes/DecimalNumberExpression.js | 10 +++--- src/slang-nodes/DoWhileStatement.js | 13 +++----- src/slang-nodes/ElementaryType.js | 10 +++--- src/slang-nodes/ElseBranch.js | 8 ++--- src/slang-nodes/EmitStatement.js | 10 +++--- src/slang-nodes/EnumDefinition.js | 11 +++---- src/slang-nodes/EnumMembers.js | 8 ++--- src/slang-nodes/EqualityExpression.js | 9 +++--- src/slang-nodes/ErrorDefinition.js | 10 +++--- src/slang-nodes/ErrorParameter.js | 14 +++----- src/slang-nodes/ErrorParameters.js | 8 ++--- src/slang-nodes/ErrorParametersDeclaration.js | 9 +++--- src/slang-nodes/EventDefinition.js | 11 +++---- src/slang-nodes/EventParameter.js | 9 +++--- src/slang-nodes/EventParameters.js | 8 ++--- src/slang-nodes/EventParametersDeclaration.js | 9 +++--- src/slang-nodes/ExperimentalFeature.js | 10 +++--- src/slang-nodes/ExperimentalPragma.js | 8 ++--- src/slang-nodes/ExponentiationExpression.js | 11 +++---- src/slang-nodes/Expression.js | 10 +++--- src/slang-nodes/ExpressionStatement.js | 8 ++--- src/slang-nodes/FallbackFunctionAttribute.js | 10 +++--- src/slang-nodes/FallbackFunctionAttributes.js | 10 +++--- src/slang-nodes/FallbackFunctionDefinition.js | 14 +++----- src/slang-nodes/ForStatement.js | 15 +++------ src/slang-nodes/ForStatementCondition.js | 10 +++--- src/slang-nodes/ForStatementInitialization.js | 10 +++--- src/slang-nodes/FunctionAttribute.js | 10 +++--- src/slang-nodes/FunctionAttributes.js | 10 +++--- src/slang-nodes/FunctionBody.js | 10 +++--- src/slang-nodes/FunctionCallExpression.js | 8 ++--- src/slang-nodes/FunctionDefinition.js | 15 +++------ src/slang-nodes/FunctionName.js | 7 ++-- src/slang-nodes/FunctionType.js | 12 +++---- src/slang-nodes/FunctionTypeAttribute.js | 7 ++-- src/slang-nodes/FunctionTypeAttributes.js | 10 +++--- src/slang-nodes/HexNumberExpression.js | 10 +++--- src/slang-nodes/HexStringLiteral.js | 8 +++-- src/slang-nodes/HexStringLiterals.js | 7 ++-- src/slang-nodes/IdentifierPath.js | 8 ++--- src/slang-nodes/IfStatement.js | 14 +++----- src/slang-nodes/ImportAlias.js | 8 ++--- src/slang-nodes/ImportClause.js | 7 ++-- src/slang-nodes/ImportDeconstruction.js | 11 +++---- src/slang-nodes/ImportDeconstructionSymbol.js | 10 +++--- .../ImportDeconstructionSymbols.js | 8 ++--- src/slang-nodes/ImportDirective.js | 9 +++--- src/slang-nodes/IndexAccessEnd.js | 10 +++--- src/slang-nodes/IndexAccessExpression.js | 14 +++----- src/slang-nodes/InheritanceSpecifier.js | 8 ++--- src/slang-nodes/InheritanceType.js | 10 +++--- src/slang-nodes/InheritanceTypes.js | 8 ++--- src/slang-nodes/InterfaceDefinition.js | 14 +++----- src/slang-nodes/InterfaceMembers.js | 7 ++-- src/slang-nodes/LibraryDefinition.js | 11 +++---- src/slang-nodes/LibraryMembers.js | 7 ++-- src/slang-nodes/MappingKey.js | 8 ++--- src/slang-nodes/MappingKeyType.js | 7 ++-- src/slang-nodes/MappingType.js | 12 +++---- src/slang-nodes/MappingValue.js | 8 ++--- src/slang-nodes/MemberAccess.js | 7 ++-- src/slang-nodes/MemberAccessExpression.js | 9 +++--- src/slang-nodes/ModifierAttribute.js | 10 +++--- src/slang-nodes/ModifierAttributes.js | 10 +++--- src/slang-nodes/ModifierDefinition.js | 22 ++++++------- src/slang-nodes/ModifierInvocation.js | 10 +++--- src/slang-nodes/MultiplicativeExpression.js | 9 +++--- src/slang-nodes/NamedArgument.js | 9 +++--- src/slang-nodes/NamedArgumentGroup.js | 9 +++--- src/slang-nodes/NamedArguments.js | 8 ++--- src/slang-nodes/NamedArgumentsDeclaration.js | 11 +++---- src/slang-nodes/NamedImport.js | 10 +++--- src/slang-nodes/NewExpression.js | 8 ++--- src/slang-nodes/NumberUnit.js | 7 ++-- src/slang-nodes/OrExpression.js | 11 ++++--- src/slang-nodes/OverridePaths.js | 8 ++--- src/slang-nodes/OverridePathsDeclaration.js | 9 +++--- src/slang-nodes/OverrideSpecifier.js | 10 +++--- src/slang-nodes/Parameter.js | 11 +++---- src/slang-nodes/Parameters.js | 8 ++--- src/slang-nodes/ParametersDeclaration.js | 9 +++--- src/slang-nodes/PathImport.js | 10 +++--- src/slang-nodes/PositionalArguments.js | 8 ++--- .../PositionalArgumentsDeclaration.js | 9 +++--- src/slang-nodes/PostfixExpression.js | 8 ++--- src/slang-nodes/Pragma.js | 7 ++-- src/slang-nodes/PragmaDirective.js | 9 +++--- src/slang-nodes/PrefixExpression.js | 8 ++--- src/slang-nodes/ReceiveFunctionAttribute.js | 10 +++--- src/slang-nodes/ReceiveFunctionAttributes.js | 10 +++--- src/slang-nodes/ReceiveFunctionDefinition.js | 11 +++---- src/slang-nodes/ReturnStatement.js | 11 +++---- src/slang-nodes/ReturnsDeclaration.js | 8 ++--- src/slang-nodes/RevertStatement.js | 12 +++---- src/slang-nodes/ShiftExpression.js | 15 ++++----- src/slang-nodes/SlangNode.js | 32 ++++++++++++++++--- src/slang-nodes/SourceUnit.js | 7 ++-- src/slang-nodes/SourceUnitMember.js | 7 ++-- src/slang-nodes/SourceUnitMembers.js | 7 ++-- src/slang-nodes/StateVariableAttribute.js | 10 +++--- src/slang-nodes/StateVariableAttributes.js | 7 ++-- src/slang-nodes/StateVariableDefinition.js | 13 +++----- .../StateVariableDefinitionValue.js | 8 ++--- src/slang-nodes/Statement.js | 7 ++-- src/slang-nodes/Statements.js | 7 ++-- src/slang-nodes/StorageLocation.js | 7 ++-- src/slang-nodes/StringExpression.js | 7 ++-- src/slang-nodes/StringLiteral.js | 8 +++-- src/slang-nodes/StringLiterals.js | 7 ++-- src/slang-nodes/StructDefinition.js | 11 +++---- src/slang-nodes/StructMember.js | 9 +++--- src/slang-nodes/StructMembers.js | 7 ++-- src/slang-nodes/ThrowStatement.js | 8 ++--- src/slang-nodes/TryStatement.js | 13 +++----- src/slang-nodes/TupleDeconstructionElement.js | 9 +++--- .../TupleDeconstructionElements.js | 8 ++--- .../TupleDeconstructionStatement.js | 13 +++----- src/slang-nodes/TupleExpression.js | 9 +++--- src/slang-nodes/TupleMember.js | 7 ++-- src/slang-nodes/TupleValue.js | 9 +++--- src/slang-nodes/TupleValues.js | 8 ++--- src/slang-nodes/TypeExpression.js | 10 +++--- src/slang-nodes/TypeName.js | 7 ++-- src/slang-nodes/TypedTupleMember.js | 11 +++---- src/slang-nodes/UncheckedBlock.js | 8 ++--- src/slang-nodes/UnicodeStringLiteral.js | 8 +++-- src/slang-nodes/UnicodeStringLiterals.js | 7 ++-- src/slang-nodes/UnnamedFunctionAttribute.js | 10 +++--- src/slang-nodes/UnnamedFunctionAttributes.js | 10 +++--- src/slang-nodes/UnnamedFunctionDefinition.js | 11 +++---- src/slang-nodes/UntypedTupleMember.js | 10 +++--- .../UserDefinedValueTypeDefinition.js | 11 +++---- src/slang-nodes/UsingAlias.js | 8 ++--- src/slang-nodes/UsingClause.js | 7 ++-- src/slang-nodes/UsingDeconstruction.js | 9 +++--- src/slang-nodes/UsingDeconstructionSymbol.js | 10 +++--- src/slang-nodes/UsingDeconstructionSymbols.js | 8 ++--- src/slang-nodes/UsingDirective.js | 12 +++---- src/slang-nodes/UsingOperator.js | 7 ++-- src/slang-nodes/UsingTarget.js | 10 +++--- .../VariableDeclarationStatement.js | 15 +++------ src/slang-nodes/VariableDeclarationType.js | 10 +++--- src/slang-nodes/VariableDeclarationValue.js | 8 ++--- src/slang-nodes/VersionComparator.js | 8 ++--- src/slang-nodes/VersionExpression.js | 10 +++--- src/slang-nodes/VersionExpressionSet.js | 7 ++-- src/slang-nodes/VersionExpressionSets.js | 8 ++--- src/slang-nodes/VersionPragma.js | 8 ++--- src/slang-nodes/VersionRange.js | 9 +++--- src/slang-nodes/VersionSpecifiers.js | 8 ++--- src/slang-nodes/WhileStatement.js | 11 +++---- src/slang-nodes/YulArguments.js | 8 ++--- src/slang-nodes/YulAssignmentOperator.js | 10 +++--- src/slang-nodes/YulAssignmentStatement.js | 9 +++--- src/slang-nodes/YulBlock.js | 9 +++--- src/slang-nodes/YulBreakStatement.js | 7 ++-- src/slang-nodes/YulBuiltInFunction.js | 7 ++-- src/slang-nodes/YulColonAndEqual.js | 8 ++--- src/slang-nodes/YulContinueStatement.js | 7 ++-- src/slang-nodes/YulDefaultCase.js | 8 ++--- src/slang-nodes/YulExpression.js | 7 ++-- src/slang-nodes/YulForStatement.js | 11 +++---- src/slang-nodes/YulFunctionCallExpression.js | 10 +++--- src/slang-nodes/YulFunctionDefinition.js | 13 +++----- src/slang-nodes/YulIfStatement.js | 9 +++--- src/slang-nodes/YulLabel.js | 8 ++--- src/slang-nodes/YulLeaveStatement.js | 7 ++-- src/slang-nodes/YulLiteral.js | 10 +++--- src/slang-nodes/YulParameters.js | 8 ++--- src/slang-nodes/YulParametersDeclaration.js | 9 +++--- src/slang-nodes/YulPath.js | 8 ++--- src/slang-nodes/YulPathComponent.js | 7 ++-- src/slang-nodes/YulPaths.js | 8 ++--- src/slang-nodes/YulReturnVariables.js | 8 ++--- src/slang-nodes/YulReturnsDeclaration.js | 8 ++--- src/slang-nodes/YulStatement.js | 7 ++-- src/slang-nodes/YulStatements.js | 7 ++-- src/slang-nodes/YulSwitchCase.js | 7 ++-- src/slang-nodes/YulSwitchCases.js | 7 ++-- src/slang-nodes/YulSwitchStatement.js | 9 +++--- src/slang-nodes/YulValueCase.js | 9 +++--- .../YulVariableAssignmentStatement.js | 9 +++--- .../YulVariableDeclarationStatement.js | 11 +++---- .../YulVariableDeclarationValue.js | 8 ++--- src/slangParser.js | 2 +- 217 files changed, 919 insertions(+), 1116 deletions(-) diff --git a/src/slang-nodes/ABICoderPragma.js b/src/slang-nodes/ABICoderPragma.js index 868d4e85d..35439dbe5 100644 --- a/src/slang-nodes/ABICoderPragma.js +++ b/src/slang-nodes/ABICoderPragma.js @@ -5,11 +5,11 @@ export class ABICoderPragma extends SlangNode { version; - constructor(ast, offset) { + constructor(ast, offset, parse) { super(ast, offset); - this.abicoderKeyword = ast.abicoderKeyword.text; - this.version = ast.version.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print() { diff --git a/src/slang-nodes/AdditiveExpression.js b/src/slang-nodes/AdditiveExpression.js index 313cace30..cc631e264 100644 --- a/src/slang-nodes/AdditiveExpression.js +++ b/src/slang-nodes/AdditiveExpression.js @@ -11,12 +11,13 @@ export class AdditiveExpression extends SlangNode { rightOperand; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.leftOperand = tryToHug(parse(ast.leftOperand, this.nextChildOffset)); - this.operator = ast.operator.text; - this.rightOperand = tryToHug(parse(ast.rightOperand, this.nextChildOffset)); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.leftOperand = tryToHug(this.leftOperand); + this.rightOperand = tryToHug(this.rightOperand); + this.initializeLoc(ast); } print(path, print, options) { diff --git a/src/slang-nodes/AddressType.js b/src/slang-nodes/AddressType.js index 670be207d..09b952831 100644 --- a/src/slang-nodes/AddressType.js +++ b/src/slang-nodes/AddressType.js @@ -5,11 +5,11 @@ export class AddressType extends SlangNode { payableKeyword; - constructor(ast, offset) { + constructor(ast, offset, parse) { super(ast, offset); - this.addressKeyword = ast.addressKeyword.text; - this.payableKeyword = ast.payableKeyword?.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print() { diff --git a/src/slang-nodes/AndExpression.js b/src/slang-nodes/AndExpression.js index 57751941e..9c62740c0 100644 --- a/src/slang-nodes/AndExpression.js +++ b/src/slang-nodes/AndExpression.js @@ -8,12 +8,11 @@ export class AndExpression extends SlangNode { rightOperand; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.leftOperand = parse(ast.leftOperand, this.nextChildOffset); - this.operator = ast.operator.text; - this.rightOperand = parse(ast.rightOperand, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print, options) { diff --git a/src/slang-nodes/ArgumentsDeclaration.js b/src/slang-nodes/ArgumentsDeclaration.js index 5e4e14963..8e582772d 100644 --- a/src/slang-nodes/ArgumentsDeclaration.js +++ b/src/slang-nodes/ArgumentsDeclaration.js @@ -3,10 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class ArgumentsDeclaration extends SlangNode { variant; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = parse(ast.variant, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/ArrayExpression.js b/src/slang-nodes/ArrayExpression.js index 93fc4e361..b8f28ca06 100644 --- a/src/slang-nodes/ArrayExpression.js +++ b/src/slang-nodes/ArrayExpression.js @@ -10,12 +10,11 @@ export class ArrayExpression extends SlangNode { closeBracket; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.openBracket = ast.openBracket.text; - this.items = parse(ast.items, this.nextChildOffset); - this.closeBracket = ast.closeBracket.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/ArrayTypeName.js b/src/slang-nodes/ArrayTypeName.js index 610e85bf8..b3f608df4 100644 --- a/src/slang-nodes/ArrayTypeName.js +++ b/src/slang-nodes/ArrayTypeName.js @@ -9,15 +9,11 @@ export class ArrayTypeName extends SlangNode { closeBracket; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.operand = parse(ast.operand, this.nextChildOffset); - this.openBracket = ast.openBracket.text; - if (ast.index) { - this.index = parse(ast.index, this.nextChildOffset); - } - this.closeBracket = ast.closeBracket.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/ArrayValues.js b/src/slang-nodes/ArrayValues.js index b070521ef..3397ba975 100644 --- a/src/slang-nodes/ArrayValues.js +++ b/src/slang-nodes/ArrayValues.js @@ -6,11 +6,11 @@ export class ArrayValues extends SlangNode { separators; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); - this.separators = ast.separators.map((separator) => separator.text); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/AssemblyFlags.js b/src/slang-nodes/AssemblyFlags.js index aad4032df..a5e897026 100644 --- a/src/slang-nodes/AssemblyFlags.js +++ b/src/slang-nodes/AssemblyFlags.js @@ -6,11 +6,11 @@ export class AssemblyFlags extends SlangNode { separators; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); - this.separators = ast.separators.map((separator) => separator.text); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/AssemblyFlagsDeclaration.js b/src/slang-nodes/AssemblyFlagsDeclaration.js index acc1b4f55..c9d279524 100644 --- a/src/slang-nodes/AssemblyFlagsDeclaration.js +++ b/src/slang-nodes/AssemblyFlagsDeclaration.js @@ -7,12 +7,11 @@ export class AssemblyFlagsDeclaration extends SlangNode { closeParen; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.openParen = ast.openParen.text; - this.flags = parse(ast.flags, this.nextChildOffset); - this.closeParen = ast.closeParen.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/AssemblyStatement.js b/src/slang-nodes/AssemblyStatement.js index 6e0c92fe5..2a652ddb2 100644 --- a/src/slang-nodes/AssemblyStatement.js +++ b/src/slang-nodes/AssemblyStatement.js @@ -9,17 +9,11 @@ export class AssemblyStatement extends SlangNode { body; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.assemblyKeyword = ast.assemblyKeyword.text; - if (ast.label) { - this.label = parse(ast.label, this.nextChildOffset); - } - if (ast.flags) { - this.flags = parse(ast.flags, this.nextChildOffset); - } - this.body = parse(ast.body, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/AssignmentExpression.js b/src/slang-nodes/AssignmentExpression.js index 4378c3c84..c19c1607a 100644 --- a/src/slang-nodes/AssignmentExpression.js +++ b/src/slang-nodes/AssignmentExpression.js @@ -11,12 +11,11 @@ export class AssignmentExpression extends SlangNode { rightOperand; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.leftOperand = parse(ast.leftOperand, this.nextChildOffset); - this.operator = ast.operator.text; - this.rightOperand = parse(ast.rightOperand, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/BitwiseAndExpression.js b/src/slang-nodes/BitwiseAndExpression.js index a8343aef5..04d872b2f 100644 --- a/src/slang-nodes/BitwiseAndExpression.js +++ b/src/slang-nodes/BitwiseAndExpression.js @@ -11,12 +11,13 @@ export class BitwiseAndExpression extends SlangNode { rightOperand; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.leftOperand = tryToHug(parse(ast.leftOperand, this.nextChildOffset)); - this.operator = ast.operator.text; - this.rightOperand = tryToHug(parse(ast.rightOperand, this.nextChildOffset)); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.leftOperand = tryToHug(this.leftOperand); + this.rightOperand = tryToHug(this.rightOperand); + this.initializeLoc(ast); } print(path, print, options) { diff --git a/src/slang-nodes/BitwiseOrExpression.js b/src/slang-nodes/BitwiseOrExpression.js index 1c2914373..f855028ba 100644 --- a/src/slang-nodes/BitwiseOrExpression.js +++ b/src/slang-nodes/BitwiseOrExpression.js @@ -21,12 +21,13 @@ export class BitwiseOrExpression extends SlangNode { rightOperand; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.leftOperand = tryToHug(parse(ast.leftOperand, this.nextChildOffset)); - this.operator = ast.operator.text; - this.rightOperand = tryToHug(parse(ast.rightOperand, this.nextChildOffset)); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.leftOperand = tryToHug(this.leftOperand); + this.rightOperand = tryToHug(this.rightOperand); + this.initializeLoc(ast); } print(path, print, options) { diff --git a/src/slang-nodes/BitwiseXorExpression.js b/src/slang-nodes/BitwiseXorExpression.js index 0c4470fa8..933dc06e4 100644 --- a/src/slang-nodes/BitwiseXorExpression.js +++ b/src/slang-nodes/BitwiseXorExpression.js @@ -11,12 +11,13 @@ export class BitwiseXorExpression extends SlangNode { rightOperand; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.leftOperand = tryToHug(parse(ast.leftOperand, this.nextChildOffset)); - this.operator = ast.operator.text; - this.rightOperand = tryToHug(parse(ast.rightOperand, this.nextChildOffset)); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.leftOperand = tryToHug(this.leftOperand); + this.rightOperand = tryToHug(this.rightOperand); + this.initializeLoc(ast); } print(path, print, options) { diff --git a/src/slang-nodes/Block.js b/src/slang-nodes/Block.js index 810cf0453..a1a9af108 100644 --- a/src/slang-nodes/Block.js +++ b/src/slang-nodes/Block.js @@ -7,12 +7,11 @@ export class Block extends SlangNode { closeBrace; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.openBrace = ast.openBrace.text; - this.statements = parse(ast.statements, this.nextChildOffset); - this.closeBrace = ast.closeBrace.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/BreakStatement.js b/src/slang-nodes/BreakStatement.js index be3e1d179..8b12741fe 100644 --- a/src/slang-nodes/BreakStatement.js +++ b/src/slang-nodes/BreakStatement.js @@ -5,11 +5,11 @@ export class BreakStatement extends SlangNode { semicolon; - constructor(ast, offset) { + constructor(ast, offset, parse) { super(ast, offset); - this.breakKeyword = ast.breakKeyword.text; - this.semicolon = ast.semicolon.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print() { diff --git a/src/slang-nodes/CallOptions.js b/src/slang-nodes/CallOptions.js index 231dd1767..6ecfb5024 100644 --- a/src/slang-nodes/CallOptions.js +++ b/src/slang-nodes/CallOptions.js @@ -9,11 +9,11 @@ export class CallOptions extends SlangNode { separators; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); - this.separators = ast.separators.map((separator) => separator.text); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print, options) { diff --git a/src/slang-nodes/CallOptionsExpression.js b/src/slang-nodes/CallOptionsExpression.js index 40d62508c..72f406862 100644 --- a/src/slang-nodes/CallOptionsExpression.js +++ b/src/slang-nodes/CallOptionsExpression.js @@ -9,13 +9,11 @@ export class CallOptionsExpression extends SlangNode { closeBrace; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.operand = parse(ast.operand, this.nextChildOffset); - this.openBrace = ast.openBrace.text; - this.options = parse(ast.options, this.nextChildOffset); - this.closeBrace = ast.closeBrace.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/CatchClause.js b/src/slang-nodes/CatchClause.js index e95527609..878075855 100644 --- a/src/slang-nodes/CatchClause.js +++ b/src/slang-nodes/CatchClause.js @@ -7,14 +7,11 @@ export class CatchClause extends SlangNode { body; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.catchKeyword = ast.catchKeyword.text; - if (ast.error) { - this.error = parse(ast.error, this.nextChildOffset); - } - this.body = parse(ast.body, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/CatchClauseError.js b/src/slang-nodes/CatchClauseError.js index 57f5700b6..0940ce5be 100644 --- a/src/slang-nodes/CatchClauseError.js +++ b/src/slang-nodes/CatchClauseError.js @@ -8,11 +8,11 @@ export class CatchClauseError extends SlangNode { parameters; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.name = ast.name?.text; - this.parameters = parse(ast.parameters, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/CatchClauses.js b/src/slang-nodes/CatchClauses.js index 36e5597c0..04225e2fc 100644 --- a/src/slang-nodes/CatchClauses.js +++ b/src/slang-nodes/CatchClauses.js @@ -6,10 +6,11 @@ const { join } = doc.builders; export class CatchClauses extends SlangNode { items; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/ComparisonExpression.js b/src/slang-nodes/ComparisonExpression.js index 18940a683..ad9ed2235 100644 --- a/src/slang-nodes/ComparisonExpression.js +++ b/src/slang-nodes/ComparisonExpression.js @@ -8,12 +8,11 @@ export class ComparisonExpression extends SlangNode { rightOperand; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.leftOperand = parse(ast.leftOperand, this.nextChildOffset); - this.operator = ast.operator.text; - this.rightOperand = parse(ast.rightOperand, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print, options) { diff --git a/src/slang-nodes/ConditionalExpression.js b/src/slang-nodes/ConditionalExpression.js index defdb688c..ab47a7aba 100644 --- a/src/slang-nodes/ConditionalExpression.js +++ b/src/slang-nodes/ConditionalExpression.js @@ -94,9 +94,10 @@ export class ConditionalExpression extends SlangNode { falseExpression; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse, options) { super(ast, offset); - this.operand = parse(ast.operand, this.nextChildOffset); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); // TODO: while the behaviour is not stable, it should be behind the // experimentalTernaries flag. @@ -112,14 +113,11 @@ export class ConditionalExpression extends SlangNode { ) { this.operand = this.operand.variant.items.items[0].expression; } + this.operand.loc = operandLoc; } - this.questionMark = ast.questionMark.text; - this.trueExpression = parse(ast.trueExpression, this.nextChildOffset); - this.colon = ast.colon.text; - this.falseExpression = parse(ast.falseExpression, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeLoc(ast); } print(path, print, options) { diff --git a/src/slang-nodes/ConstantDefinition.js b/src/slang-nodes/ConstantDefinition.js index c9ee7ef96..f8f0edabb 100644 --- a/src/slang-nodes/ConstantDefinition.js +++ b/src/slang-nodes/ConstantDefinition.js @@ -13,15 +13,11 @@ export class ConstantDefinition extends SlangNode { semicolon; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.typeName = parse(ast.typeName, this.nextChildOffset); - this.constantKeyword = ast.constantKeyword.text; - this.name = ast.name.text; - this.equal = ast.equal.text; - this.value = parse(ast.value, this.nextChildOffset); - this.semicolon = ast.semicolon.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } // TODO: implement print diff --git a/src/slang-nodes/ConstructorAttribute.js b/src/slang-nodes/ConstructorAttribute.js index 590de7ec2..abb91ae1a 100644 --- a/src/slang-nodes/ConstructorAttribute.js +++ b/src/slang-nodes/ConstructorAttribute.js @@ -3,13 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class ConstructorAttribute extends SlangNode { variant; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = - ast.variant.type === 'Terminal' - ? ast.variant.text - : parse(ast.variant, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/ConstructorAttributes.js b/src/slang-nodes/ConstructorAttributes.js index ad26afe1b..c52994f4e 100644 --- a/src/slang-nodes/ConstructorAttributes.js +++ b/src/slang-nodes/ConstructorAttributes.js @@ -7,12 +7,12 @@ const { line } = doc.builders; export class ConstructorAttributes extends SlangNode { items; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items - .map((item) => parse(item, this.nextChildOffset)) - .sort(sortFunctionAttributes); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.items = this.items.sort(sortFunctionAttributes); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/ConstructorDefinition.js b/src/slang-nodes/ConstructorDefinition.js index 9e5629540..36ddf4dd5 100644 --- a/src/slang-nodes/ConstructorDefinition.js +++ b/src/slang-nodes/ConstructorDefinition.js @@ -10,13 +10,11 @@ export class ConstructorDefinition extends SlangNode { body; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.constructorKeyword = ast.constructorKeyword.text; - this.parameters = parse(ast.parameters, this.nextChildOffset); - this.attributes = parse(ast.attributes, this.nextChildOffset); - this.body = parse(ast.body, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/ContinueStatement.js b/src/slang-nodes/ContinueStatement.js index f93aa7f28..c2522086e 100644 --- a/src/slang-nodes/ContinueStatement.js +++ b/src/slang-nodes/ContinueStatement.js @@ -5,11 +5,11 @@ export class ContinueStatement extends SlangNode { semicolon; - constructor(ast, offset) { + constructor(ast, offset, parse) { super(ast, offset); - this.continueKeyword = ast.continueKeyword.text; - this.semicolon = ast.semicolon.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print() { diff --git a/src/slang-nodes/ContractDefinition.js b/src/slang-nodes/ContractDefinition.js index 0c32064c0..71dfbfe65 100644 --- a/src/slang-nodes/ContractDefinition.js +++ b/src/slang-nodes/ContractDefinition.js @@ -20,20 +20,12 @@ export class ContractDefinition extends SlangNode { closeBrace; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse, options) { super(ast, offset); - this.abstractKeyword = ast.abstractKeyword?.text; - this.contractKeyword = ast.contractKeyword.text; - this.name = ast.name.text; - if (ast.inheritance) { - this.inheritance = parse(ast.inheritance, this.nextChildOffset); - } - this.openBrace = ast.openBrace.text; - this.members = parse(ast.members, this.nextChildOffset); - this.closeBrace = ast.closeBrace.text; - + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); this.cleanModifierInvocationArguments(options); - this.initiateLoc(ast); + this.initializeLoc(ast); } cleanModifierInvocationArguments(options) { diff --git a/src/slang-nodes/ContractMember.js b/src/slang-nodes/ContractMember.js index 9db5a5bbe..df7a3056d 100644 --- a/src/slang-nodes/ContractMember.js +++ b/src/slang-nodes/ContractMember.js @@ -3,10 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class ContractMember extends SlangNode { variant; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = parse(ast.variant, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/ContractMembers.js b/src/slang-nodes/ContractMembers.js index f70299ff6..14446d61f 100644 --- a/src/slang-nodes/ContractMembers.js +++ b/src/slang-nodes/ContractMembers.js @@ -11,10 +11,11 @@ const { hardline } = doc.builders; export class ContractMembers extends SlangNode { items; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print, options) { diff --git a/src/slang-nodes/DecimalNumberExpression.js b/src/slang-nodes/DecimalNumberExpression.js index 29b9a8efb..45300fe6d 100644 --- a/src/slang-nodes/DecimalNumberExpression.js +++ b/src/slang-nodes/DecimalNumberExpression.js @@ -5,13 +5,11 @@ export class DecimalNumberExpression extends SlangNode { unit; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.literal = ast.literal.text; - if (ast.unit) { - this.unit = parse(ast.unit, this.nextChildOffset); - } - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/DoWhileStatement.js b/src/slang-nodes/DoWhileStatement.js index c1d0e037c..010ca3fae 100644 --- a/src/slang-nodes/DoWhileStatement.js +++ b/src/slang-nodes/DoWhileStatement.js @@ -24,16 +24,11 @@ export class DoWhileStatement extends SlangNode { semicolon; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.doKeyword = ast.doKeyword.text; - this.body = parse(ast.body, this.nextChildOffset); - this.whileKeyword = ast.whileKeyword.text; - this.openParen = ast.openParen.text; - this.condition = parse(ast.condition, this.nextChildOffset); - this.closeParen = ast.closeParen.text; - this.semicolon = ast.semicolon.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/ElementaryType.js b/src/slang-nodes/ElementaryType.js index cc2f026de..4a9f4540f 100644 --- a/src/slang-nodes/ElementaryType.js +++ b/src/slang-nodes/ElementaryType.js @@ -3,13 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class ElementaryType extends SlangNode { variant; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = - ast.variant.type === 'Terminal' - ? ast.variant.text - : parse(ast.variant, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/ElseBranch.js b/src/slang-nodes/ElseBranch.js index 826b8545b..5802c966a 100644 --- a/src/slang-nodes/ElseBranch.js +++ b/src/slang-nodes/ElseBranch.js @@ -13,11 +13,11 @@ export class ElseBranch extends SlangNode { body; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.elseKeyword = ast.elseKeyword.text; - this.body = parse(ast.body, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/EmitStatement.js b/src/slang-nodes/EmitStatement.js index 63ecd5835..826c44581 100644 --- a/src/slang-nodes/EmitStatement.js +++ b/src/slang-nodes/EmitStatement.js @@ -9,13 +9,11 @@ export class EmitStatement extends SlangNode { semicolon; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.emitKeyword = ast.emitKeyword.text; - this.event = parse(ast.event, this.nextChildOffset); - this.arguments = parse(ast.arguments, this.nextChildOffset); - this.semicolon = ast.semicolon.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/EnumDefinition.js b/src/slang-nodes/EnumDefinition.js index fb49a4a32..021eedb7d 100644 --- a/src/slang-nodes/EnumDefinition.js +++ b/src/slang-nodes/EnumDefinition.js @@ -11,14 +11,11 @@ export class EnumDefinition extends SlangNode { closeBrace; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.enumKeyword = ast.enumKeyword.text; - this.name = ast.name.text; - this.openBrace = ast.openBrace.text; - this.members = parse(ast.members, this.nextChildOffset); - this.closeBrace = ast.closeBrace.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/EnumMembers.js b/src/slang-nodes/EnumMembers.js index 5986345dd..6a768dcf9 100644 --- a/src/slang-nodes/EnumMembers.js +++ b/src/slang-nodes/EnumMembers.js @@ -9,11 +9,11 @@ export class EnumMembers extends SlangNode { separators; - constructor(ast, offset) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items.map((item) => item.text); - this.separators = ast.separators.map((separator) => separator.text); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print() { diff --git a/src/slang-nodes/EqualityExpression.js b/src/slang-nodes/EqualityExpression.js index df6a148ee..36eda5835 100644 --- a/src/slang-nodes/EqualityExpression.js +++ b/src/slang-nodes/EqualityExpression.js @@ -8,12 +8,11 @@ export class EqualityExpression extends SlangNode { rightOperand; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.leftOperand = parse(ast.leftOperand, this.nextChildOffset); - this.operator = ast.operator.text; - this.rightOperand = parse(ast.rightOperand, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print, options) { diff --git a/src/slang-nodes/ErrorDefinition.js b/src/slang-nodes/ErrorDefinition.js index c5caf0794..099a27eed 100644 --- a/src/slang-nodes/ErrorDefinition.js +++ b/src/slang-nodes/ErrorDefinition.js @@ -9,13 +9,11 @@ export class ErrorDefinition extends SlangNode { semicolon; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.errorKeyword = ast.errorKeyword.text; - this.name = ast.name.text; - this.members = parse(ast.members, this.nextChildOffset); - this.semicolon = ast.semicolon.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/ErrorParameter.js b/src/slang-nodes/ErrorParameter.js index 7e0958106..730ad0cd1 100644 --- a/src/slang-nodes/ErrorParameter.js +++ b/src/slang-nodes/ErrorParameter.js @@ -1,19 +1,15 @@ import { SlangNode } from './SlangNode.js'; export class ErrorParameter extends SlangNode { - errorKeyword; + typeName; name; - members; - - semicolon; - - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.typeName = parse(ast.typeName, this.nextChildOffset); - this.name = ast.name?.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/ErrorParameters.js b/src/slang-nodes/ErrorParameters.js index f2f006ee4..6adf54532 100644 --- a/src/slang-nodes/ErrorParameters.js +++ b/src/slang-nodes/ErrorParameters.js @@ -6,11 +6,11 @@ export class ErrorParameters extends SlangNode { separators; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); - this.separators = ast.separators.map((separator) => separator.text); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/ErrorParametersDeclaration.js b/src/slang-nodes/ErrorParametersDeclaration.js index 599c253a5..22c990918 100644 --- a/src/slang-nodes/ErrorParametersDeclaration.js +++ b/src/slang-nodes/ErrorParametersDeclaration.js @@ -7,12 +7,11 @@ export class ErrorParametersDeclaration extends SlangNode { closeParen; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.openParen = ast.openParen.text; - this.parameters = parse(ast.parameters, this.nextChildOffset); - this.closeParen = ast.closeParen.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/EventDefinition.js b/src/slang-nodes/EventDefinition.js index 7f2987483..9e403aab1 100644 --- a/src/slang-nodes/EventDefinition.js +++ b/src/slang-nodes/EventDefinition.js @@ -11,14 +11,11 @@ export class EventDefinition extends SlangNode { semicolon; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.eventKeyword = ast.eventKeyword.text; - this.name = ast.name.text; - this.parameters = parse(ast.parameters, this.nextChildOffset); - this.anonymousKeyword = ast.anonymousKeyword?.text; - this.semicolon = ast.semicolon.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/EventParameter.js b/src/slang-nodes/EventParameter.js index bcd1779e9..51ec24534 100644 --- a/src/slang-nodes/EventParameter.js +++ b/src/slang-nodes/EventParameter.js @@ -7,12 +7,11 @@ export class EventParameter extends SlangNode { name; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.typeName = parse(ast.typeName, this.nextChildOffset); - this.indexedKeyword = ast.indexedKeyword?.text; - this.name = ast.name?.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/EventParameters.js b/src/slang-nodes/EventParameters.js index 4c6f90c3c..97c689c36 100644 --- a/src/slang-nodes/EventParameters.js +++ b/src/slang-nodes/EventParameters.js @@ -6,11 +6,11 @@ export class EventParameters extends SlangNode { separators; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); - this.separators = ast.separators.map((separator) => separator.text); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/EventParametersDeclaration.js b/src/slang-nodes/EventParametersDeclaration.js index 40e2f1593..2f0d57691 100644 --- a/src/slang-nodes/EventParametersDeclaration.js +++ b/src/slang-nodes/EventParametersDeclaration.js @@ -7,12 +7,11 @@ export class EventParametersDeclaration extends SlangNode { closeParen; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.openParen = ast.openParen.text; - this.parameters = parse(ast.parameters, this.nextChildOffset); - this.closeParen = ast.closeParen.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/ExperimentalFeature.js b/src/slang-nodes/ExperimentalFeature.js index c1d7f884f..a52dd44b9 100644 --- a/src/slang-nodes/ExperimentalFeature.js +++ b/src/slang-nodes/ExperimentalFeature.js @@ -3,13 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class ExperimentalFeature extends SlangNode { variant; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = - ast.variant.type === 'Terminal' - ? ast.variant.text - : parse(ast.variant, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/ExperimentalPragma.js b/src/slang-nodes/ExperimentalPragma.js index 3a348f5b1..f179e5bba 100644 --- a/src/slang-nodes/ExperimentalPragma.js +++ b/src/slang-nodes/ExperimentalPragma.js @@ -5,11 +5,11 @@ export class ExperimentalPragma extends SlangNode { feature; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.experimentalKeyword = ast.experimentalKeyword.text; - this.feature = parse(ast.feature, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/ExponentiationExpression.js b/src/slang-nodes/ExponentiationExpression.js index fe644acb6..ef6f34bee 100644 --- a/src/slang-nodes/ExponentiationExpression.js +++ b/src/slang-nodes/ExponentiationExpression.js @@ -25,13 +25,13 @@ export class ExponentiationExpression extends SlangNode { rightOperand; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse, options) { super(ast, offset); if (offset) { - const compiler = coerce(options.compiler); - this.leftOperand = parse(ast.leftOperand, this.nextChildOffset); - this.rightOperand = parse(ast.rightOperand, this.nextChildOffset); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + const compiler = coerce(options.compiler); if (compiler) { if (satisfies(compiler, '>=0.8.0')) { this.rightOperand = tryToHug(this.rightOperand); @@ -87,8 +87,7 @@ export class ExponentiationExpression extends SlangNode { } } - this.operator = ast.operator.text; - this.initiateLoc(ast); + this.initializeLoc(ast); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/Expression.js b/src/slang-nodes/Expression.js index 904103e6a..0f22f1715 100644 --- a/src/slang-nodes/Expression.js +++ b/src/slang-nodes/Expression.js @@ -3,14 +3,12 @@ import { SlangNode } from './SlangNode.js'; export class Expression extends SlangNode { variant; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); if (offset) { - this.variant = - ast.variant.type === 'Terminal' - ? ast.variant.text - : parse(ast.variant, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/ExpressionStatement.js b/src/slang-nodes/ExpressionStatement.js index 291bc4358..ae04926d0 100644 --- a/src/slang-nodes/ExpressionStatement.js +++ b/src/slang-nodes/ExpressionStatement.js @@ -5,11 +5,11 @@ export class ExpressionStatement extends SlangNode { semicolon; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.expression = parse(ast.expression, this.nextChildOffset); - this.semicolon = ast.semicolon.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/FallbackFunctionAttribute.js b/src/slang-nodes/FallbackFunctionAttribute.js index 305ccfde6..1b14b60f6 100644 --- a/src/slang-nodes/FallbackFunctionAttribute.js +++ b/src/slang-nodes/FallbackFunctionAttribute.js @@ -3,13 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class FallbackFunctionAttribute extends SlangNode { variant; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = - ast.variant.type === 'Terminal' - ? ast.variant.text - : parse(ast.variant, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/FallbackFunctionAttributes.js b/src/slang-nodes/FallbackFunctionAttributes.js index 1ed5e61d2..470d77f6a 100644 --- a/src/slang-nodes/FallbackFunctionAttributes.js +++ b/src/slang-nodes/FallbackFunctionAttributes.js @@ -7,12 +7,12 @@ const { line } = doc.builders; export class FallbackFunctionAttributes extends SlangNode { items; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items - .map((item) => parse(item, this.nextChildOffset)) - .sort(sortFunctionAttributes); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.items = this.items.sort(sortFunctionAttributes); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/FallbackFunctionDefinition.js b/src/slang-nodes/FallbackFunctionDefinition.js index 267a72b5c..7fd3e49e7 100644 --- a/src/slang-nodes/FallbackFunctionDefinition.js +++ b/src/slang-nodes/FallbackFunctionDefinition.js @@ -12,18 +12,12 @@ export class FallbackFunctionDefinition extends SlangNode { body; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.fallbackKeyword = ast.fallbackKeyword.text; - this.parameters = parse(ast.parameters, this.nextChildOffset); - this.attributes = parse(ast.attributes, this.nextChildOffset); - if (ast.returns) { - this.returns = parse(ast.returns, this.nextChildOffset); - } - this.body = parse(ast.body, this.nextChildOffset); - + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); this.cleanModifierInvocationArguments(); - this.initiateLoc(ast); + this.initializeLoc(ast); } cleanModifierInvocationArguments() { diff --git a/src/slang-nodes/ForStatement.js b/src/slang-nodes/ForStatement.js index cbd4c11e7..2560920f6 100644 --- a/src/slang-nodes/ForStatement.js +++ b/src/slang-nodes/ForStatement.js @@ -19,18 +19,11 @@ export class ForStatement extends SlangNode { body; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.forKeyword = ast.forKeyword.text; - this.openParen = ast.openParen.text; - this.initialization = parse(ast.initialization, this.nextChildOffset); - this.condition = parse(ast.condition, this.nextChildOffset); - if (ast.iterator) { - this.iterator = parse(ast.iterator, this.nextChildOffset); - } - this.closeParen = ast.closeParen.text; - this.body = parse(ast.body, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/ForStatementCondition.js b/src/slang-nodes/ForStatementCondition.js index 672c92e6b..373dc6795 100644 --- a/src/slang-nodes/ForStatementCondition.js +++ b/src/slang-nodes/ForStatementCondition.js @@ -3,13 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class ForStatementCondition extends SlangNode { variant; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = - ast.variant.type === 'Terminal' - ? ast.variant.text - : parse(ast.variant, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/ForStatementInitialization.js b/src/slang-nodes/ForStatementInitialization.js index 842bc95d3..06a32696e 100644 --- a/src/slang-nodes/ForStatementInitialization.js +++ b/src/slang-nodes/ForStatementInitialization.js @@ -3,13 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class ForStatementInitialization extends SlangNode { variant; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = - ast.variant.type === 'Terminal' - ? ast.variant.text - : parse(ast.variant, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/FunctionAttribute.js b/src/slang-nodes/FunctionAttribute.js index 3ca164625..83a1fb452 100644 --- a/src/slang-nodes/FunctionAttribute.js +++ b/src/slang-nodes/FunctionAttribute.js @@ -3,13 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class FunctionAttribute extends SlangNode { variant; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = - ast.variant.type === 'Terminal' - ? ast.variant.text - : parse(ast.variant, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/FunctionAttributes.js b/src/slang-nodes/FunctionAttributes.js index 9180f2832..d32ef4b0d 100644 --- a/src/slang-nodes/FunctionAttributes.js +++ b/src/slang-nodes/FunctionAttributes.js @@ -7,12 +7,12 @@ const { line } = doc.builders; export class FunctionAttributes extends SlangNode { items; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items - .map((item) => parse(item, this.nextChildOffset)) - .sort(sortFunctionAttributes); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.items = this.items.sort(sortFunctionAttributes); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/FunctionBody.js b/src/slang-nodes/FunctionBody.js index ef441d953..5f34234a5 100644 --- a/src/slang-nodes/FunctionBody.js +++ b/src/slang-nodes/FunctionBody.js @@ -3,13 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class FunctionBody extends SlangNode { variant; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = - ast.variant.type === 'Terminal' - ? ast.variant.text - : parse(ast.variant, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/FunctionCallExpression.js b/src/slang-nodes/FunctionCallExpression.js index 48b0c3a73..6e2f60df2 100644 --- a/src/slang-nodes/FunctionCallExpression.js +++ b/src/slang-nodes/FunctionCallExpression.js @@ -9,11 +9,11 @@ export class FunctionCallExpression extends SlangNode { arguments; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.operand = parse(ast.operand, this.nextChildOffset); - this.arguments = parse(ast.arguments, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/FunctionDefinition.js b/src/slang-nodes/FunctionDefinition.js index a000984fd..67dc0ea56 100644 --- a/src/slang-nodes/FunctionDefinition.js +++ b/src/slang-nodes/FunctionDefinition.js @@ -16,16 +16,10 @@ export class FunctionDefinition extends SlangNode { body; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse, options) { super(ast, offset); - this.functionKeyword = ast.functionKeyword.text; - this.name = parse(ast.name, this.nextChildOffset); - this.parameters = parse(ast.parameters, this.nextChildOffset); - this.attributes = parse(ast.attributes, this.nextChildOffset); - if (ast.returns) { - this.returns = parse(ast.returns, this.nextChildOffset); - } - this.body = parse(ast.body, this.nextChildOffset); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); // Older versions of Solidity defined a constructor as a function having // the same name as the contract. @@ -33,7 +27,8 @@ export class FunctionDefinition extends SlangNode { if (compiler && satisfies(compiler, '>=0.5.0')) { this.cleanModifierInvocationArguments(); } - this.initiateLoc(ast); + + this.initializeLoc(ast); } cleanModifierInvocationArguments() { diff --git a/src/slang-nodes/FunctionName.js b/src/slang-nodes/FunctionName.js index 2adc6e126..d08c1bb6c 100644 --- a/src/slang-nodes/FunctionName.js +++ b/src/slang-nodes/FunctionName.js @@ -3,10 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class FunctionName extends SlangNode { variant; - constructor(ast, offset) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = ast.variant.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print() { diff --git a/src/slang-nodes/FunctionType.js b/src/slang-nodes/FunctionType.js index 642eb7d90..fc1ef3e6c 100644 --- a/src/slang-nodes/FunctionType.js +++ b/src/slang-nodes/FunctionType.js @@ -10,15 +10,11 @@ export class FunctionType extends SlangNode { returns; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.functionKeyword = ast.functionKeyword.text; - this.parameters = parse(ast.parameters, this.nextChildOffset); - this.attributes = parse(ast.attributes, this.nextChildOffset); - if (ast.returns) { - this.returns = parse(ast.returns, this.nextChildOffset); - } - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/FunctionTypeAttribute.js b/src/slang-nodes/FunctionTypeAttribute.js index 928e1e21e..e8e71a358 100644 --- a/src/slang-nodes/FunctionTypeAttribute.js +++ b/src/slang-nodes/FunctionTypeAttribute.js @@ -3,10 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class FunctionTypeAttribute extends SlangNode { variant; - constructor(ast, offset) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = ast.variant.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print() { diff --git a/src/slang-nodes/FunctionTypeAttributes.js b/src/slang-nodes/FunctionTypeAttributes.js index 4ea79d6cc..d119adec0 100644 --- a/src/slang-nodes/FunctionTypeAttributes.js +++ b/src/slang-nodes/FunctionTypeAttributes.js @@ -7,12 +7,12 @@ const { line } = doc.builders; export class FunctionTypeAttributes extends SlangNode { items; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items - .map((item) => parse(item, this.nextChildOffset)) - .sort(sortFunctionAttributes); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.items = this.items.sort(sortFunctionAttributes); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/HexNumberExpression.js b/src/slang-nodes/HexNumberExpression.js index ebf012a09..77ad85cd6 100644 --- a/src/slang-nodes/HexNumberExpression.js +++ b/src/slang-nodes/HexNumberExpression.js @@ -5,13 +5,11 @@ export class HexNumberExpression extends SlangNode { unit; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.literal = ast.literal.text; - if (ast.unit) { - this.unit = parse(ast.unit, this.nextChildOffset); - } - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/HexStringLiteral.js b/src/slang-nodes/HexStringLiteral.js index cc8e63ede..578b4c0e8 100644 --- a/src/slang-nodes/HexStringLiteral.js +++ b/src/slang-nodes/HexStringLiteral.js @@ -4,10 +4,12 @@ import { SlangNode } from './SlangNode.js'; export class HexStringLiteral extends SlangNode { variant; - constructor(ast, offset, options) { + constructor(ast, offset, parse, options) { super(ast, offset); - this.variant = `hex${printString(ast.variant.text.slice(4, -1), options)}`; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.variant = `hex${printString(this.variant.slice(4, -1), options)}`; + this.initializeLoc(ast); } print() { diff --git a/src/slang-nodes/HexStringLiterals.js b/src/slang-nodes/HexStringLiterals.js index cc48aa9ec..5cdcab78f 100644 --- a/src/slang-nodes/HexStringLiterals.js +++ b/src/slang-nodes/HexStringLiterals.js @@ -6,10 +6,11 @@ const { join, hardline } = doc.builders; export class HexStringLiterals extends SlangNode { items; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/IdentifierPath.js b/src/slang-nodes/IdentifierPath.js index d4359c37b..656928b79 100644 --- a/src/slang-nodes/IdentifierPath.js +++ b/src/slang-nodes/IdentifierPath.js @@ -5,11 +5,11 @@ export class IdentifierPath extends SlangNode { separators; - constructor(ast, offset) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items.map((item) => item.text); - this.separators = ast.separators.map((separator) => separator.text); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print() { diff --git a/src/slang-nodes/IfStatement.js b/src/slang-nodes/IfStatement.js index 294a9891f..cea04ab20 100644 --- a/src/slang-nodes/IfStatement.js +++ b/src/slang-nodes/IfStatement.js @@ -24,17 +24,11 @@ export class IfStatement extends SlangNode { elseBranch; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.ifKeyword = ast.ifKeyword.text; - this.openParen = ast.openParen.text; - this.condition = parse(ast.condition, this.nextChildOffset); - this.closeParen = ast.closeParen.text; - this.body = parse(ast.body, this.nextChildOffset); - if (ast.elseBranch) { - this.elseBranch = parse(ast.elseBranch, this.nextChildOffset); - } - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/ImportAlias.js b/src/slang-nodes/ImportAlias.js index f0ad38366..56df14a52 100644 --- a/src/slang-nodes/ImportAlias.js +++ b/src/slang-nodes/ImportAlias.js @@ -5,11 +5,11 @@ export class ImportAlias extends SlangNode { identifier; - constructor(ast, offset) { + constructor(ast, offset, parse) { super(ast, offset); - this.asKeyword = ast.asKeyword.text; - this.identifier = ast.identifier.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print() { diff --git a/src/slang-nodes/ImportClause.js b/src/slang-nodes/ImportClause.js index f66ff2286..13bbc7ea4 100644 --- a/src/slang-nodes/ImportClause.js +++ b/src/slang-nodes/ImportClause.js @@ -3,10 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class ImportClause extends SlangNode { variant; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = parse(ast.variant, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/ImportDeconstruction.js b/src/slang-nodes/ImportDeconstruction.js index ee02e3bd1..1e7cf4c34 100644 --- a/src/slang-nodes/ImportDeconstruction.js +++ b/src/slang-nodes/ImportDeconstruction.js @@ -11,14 +11,11 @@ export class ImportDeconstruction extends SlangNode { path; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.openBrace = ast.openBrace.text; - this.symbols = parse(ast.symbols, this.nextChildOffset); - this.closeBrace = ast.closeBrace.text; - this.fromKeyword = ast.fromKeyword.text; - this.path = parse(ast.path, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/ImportDeconstructionSymbol.js b/src/slang-nodes/ImportDeconstructionSymbol.js index abea1ba5f..c09e62691 100644 --- a/src/slang-nodes/ImportDeconstructionSymbol.js +++ b/src/slang-nodes/ImportDeconstructionSymbol.js @@ -5,13 +5,11 @@ export class ImportDeconstructionSymbol extends SlangNode { alias; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.name = ast.name.text; - if (ast.alias) { - this.alias = parse(ast.alias, this.nextChildOffset); - } - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/ImportDeconstructionSymbols.js b/src/slang-nodes/ImportDeconstructionSymbols.js index ddeb1b276..02bbd19c0 100644 --- a/src/slang-nodes/ImportDeconstructionSymbols.js +++ b/src/slang-nodes/ImportDeconstructionSymbols.js @@ -11,11 +11,11 @@ export class ImportDeconstructionSymbols extends SlangNode { separators; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); - this.separators = ast.separators.map((separator) => separator.text); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print, options) { diff --git a/src/slang-nodes/ImportDirective.js b/src/slang-nodes/ImportDirective.js index 52a2d6905..9bd015ad9 100644 --- a/src/slang-nodes/ImportDirective.js +++ b/src/slang-nodes/ImportDirective.js @@ -7,12 +7,11 @@ export class ImportDirective extends SlangNode { semicolon; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.importKeyword = ast.importKeyword.text; - this.clause = parse(ast.clause, this.nextChildOffset); - this.semicolon = ast.semicolon.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/IndexAccessEnd.js b/src/slang-nodes/IndexAccessEnd.js index ae2d441fa..0125d5100 100644 --- a/src/slang-nodes/IndexAccessEnd.js +++ b/src/slang-nodes/IndexAccessEnd.js @@ -5,13 +5,11 @@ export class IndexAccessEnd extends SlangNode { end; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.colon = ast.colon.text; - if (ast.end) { - this.end = parse(ast.end, this.nextChildOffset); - } - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/IndexAccessExpression.js b/src/slang-nodes/IndexAccessExpression.js index 493a3a522..d0fb9a66b 100644 --- a/src/slang-nodes/IndexAccessExpression.js +++ b/src/slang-nodes/IndexAccessExpression.js @@ -15,18 +15,12 @@ export class IndexAccessExpression extends SlangNode { closeBracket; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.operand = parse(ast.operand, this.nextChildOffset); - this.openBracket = ast.openBracket.text; - if (ast.start) { - this.start = parse(ast.start, this.nextChildOffset); - } - if (ast.end) { - this.end = parse(ast.end, this.nextChildOffset); - } this.closeBracket = ast.closeBracket.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/InheritanceSpecifier.js b/src/slang-nodes/InheritanceSpecifier.js index c1b6845c6..aabcbe995 100644 --- a/src/slang-nodes/InheritanceSpecifier.js +++ b/src/slang-nodes/InheritanceSpecifier.js @@ -5,11 +5,11 @@ export class InheritanceSpecifier extends SlangNode { types; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.isKeyword = ast.isKeyword.text; - this.types = parse(ast.types, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/InheritanceType.js b/src/slang-nodes/InheritanceType.js index a050e6c0a..d21a96893 100644 --- a/src/slang-nodes/InheritanceType.js +++ b/src/slang-nodes/InheritanceType.js @@ -5,13 +5,11 @@ export class InheritanceType extends SlangNode { arguments; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.typeName = parse(ast.typeName, this.nextChildOffset); - if (ast.arguments) { - this.arguments = parse(ast.arguments, this.nextChildOffset); - } - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/InheritanceTypes.js b/src/slang-nodes/InheritanceTypes.js index f86124074..c570e81f9 100644 --- a/src/slang-nodes/InheritanceTypes.js +++ b/src/slang-nodes/InheritanceTypes.js @@ -9,11 +9,11 @@ export class InheritanceTypes extends SlangNode { separators; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); - this.separators = ast.separators.map((separator) => separator.text); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/InterfaceDefinition.js b/src/slang-nodes/InterfaceDefinition.js index 73d28eda6..4b7dc294b 100644 --- a/src/slang-nodes/InterfaceDefinition.js +++ b/src/slang-nodes/InterfaceDefinition.js @@ -16,17 +16,11 @@ export class InterfaceDefinition extends SlangNode { closeBrace; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.interfaceKeyword = ast.interfaceKeyword.text; - this.name = ast.name.text; - if (ast.inheritence) { - this.inheritance = parse(ast.inheritance, this.nextChildOffset); - } - this.openBrace = ast.openBrace.text; - this.members = parse(ast.members, this.nextChildOffset); - this.closeBrace = ast.closeBrace.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/InterfaceMembers.js b/src/slang-nodes/InterfaceMembers.js index 4dad9e3dd..59a63fe5a 100644 --- a/src/slang-nodes/InterfaceMembers.js +++ b/src/slang-nodes/InterfaceMembers.js @@ -8,10 +8,11 @@ const { hardline } = doc.builders; export class InterfaceMembers extends SlangNode { items; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print, options) { diff --git a/src/slang-nodes/LibraryDefinition.js b/src/slang-nodes/LibraryDefinition.js index 544b33b13..f1f55eb55 100644 --- a/src/slang-nodes/LibraryDefinition.js +++ b/src/slang-nodes/LibraryDefinition.js @@ -14,14 +14,11 @@ export class LibraryDefinition extends SlangNode { closeBrace; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.libraryKeyword = ast.libraryKeyword.text; - this.name = ast.name.text; - this.openBrace = ast.openBrace.text; - this.members = parse(ast.members, this.nextChildOffset); - this.closeBrace = ast.closeBrace.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/LibraryMembers.js b/src/slang-nodes/LibraryMembers.js index 2cbf0f178..903364ff7 100644 --- a/src/slang-nodes/LibraryMembers.js +++ b/src/slang-nodes/LibraryMembers.js @@ -8,10 +8,11 @@ const { hardline } = doc.builders; export class LibraryMembers extends SlangNode { items; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print, options) { diff --git a/src/slang-nodes/MappingKey.js b/src/slang-nodes/MappingKey.js index a38c249b5..ebb849e63 100644 --- a/src/slang-nodes/MappingKey.js +++ b/src/slang-nodes/MappingKey.js @@ -5,11 +5,11 @@ export class MappingKey extends SlangNode { name; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.keyType = parse(ast.keyType, this.nextChildOffset); - this.name = ast.name?.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/MappingKeyType.js b/src/slang-nodes/MappingKeyType.js index cb19925f2..7687969ba 100644 --- a/src/slang-nodes/MappingKeyType.js +++ b/src/slang-nodes/MappingKeyType.js @@ -3,10 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class MappingKeyType extends SlangNode { variant; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = parse(ast.variant, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/MappingType.js b/src/slang-nodes/MappingType.js index 381867d5f..3a64fe3b2 100644 --- a/src/slang-nodes/MappingType.js +++ b/src/slang-nodes/MappingType.js @@ -13,15 +13,11 @@ export class MappingType extends SlangNode { closeParen; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.mappingKeyword = ast.mappingKeyword.text; - this.openParen = ast.openParen.text; - this.keyType = parse(ast.keyType, this.nextChildOffset); - this.equalGreaterThan = ast.equalGreaterThan.text; - this.valueType = parse(ast.valueType, this.nextChildOffset); - this.closeParen = ast.closeParen.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/MappingValue.js b/src/slang-nodes/MappingValue.js index e2a971256..30172c704 100644 --- a/src/slang-nodes/MappingValue.js +++ b/src/slang-nodes/MappingValue.js @@ -5,11 +5,11 @@ export class MappingValue extends SlangNode { name; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.typeName = parse(ast.typeName, this.nextChildOffset); - this.name = ast.name?.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/MemberAccess.js b/src/slang-nodes/MemberAccess.js index fb2767ea0..056891331 100644 --- a/src/slang-nodes/MemberAccess.js +++ b/src/slang-nodes/MemberAccess.js @@ -3,10 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class MemberAccess extends SlangNode { variant; - constructor(ast, offset) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = ast.variant.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print() { diff --git a/src/slang-nodes/MemberAccessExpression.js b/src/slang-nodes/MemberAccessExpression.js index 384240d41..8c4c39605 100644 --- a/src/slang-nodes/MemberAccessExpression.js +++ b/src/slang-nodes/MemberAccessExpression.js @@ -112,12 +112,11 @@ export class MemberAccessExpression extends SlangNode { member; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.operand = parse(ast.operand, this.nextChildOffset); - this.period = ast.period.text; - this.member = parse(ast.member, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/ModifierAttribute.js b/src/slang-nodes/ModifierAttribute.js index 3efcfc415..97e8b44cf 100644 --- a/src/slang-nodes/ModifierAttribute.js +++ b/src/slang-nodes/ModifierAttribute.js @@ -3,13 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class ModifierAttribute extends SlangNode { variant; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = - ast.variant.type === 'Terminal' - ? ast.variant.text - : parse(ast.variant, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/ModifierAttributes.js b/src/slang-nodes/ModifierAttributes.js index 05d57a504..0566b39fb 100644 --- a/src/slang-nodes/ModifierAttributes.js +++ b/src/slang-nodes/ModifierAttributes.js @@ -7,12 +7,12 @@ const { line } = doc.builders; export class ModifierAttributes extends SlangNode { items; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items - .map((item) => parse(item, this.nextChildOffset)) - .sort(sortFunctionAttributes); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.items = this.items.sort(sortFunctionAttributes); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/ModifierDefinition.js b/src/slang-nodes/ModifierDefinition.js index 0b0ff4aa7..69b07c138 100644 --- a/src/slang-nodes/ModifierDefinition.js +++ b/src/slang-nodes/ModifierDefinition.js @@ -14,18 +14,16 @@ export class ModifierDefinition extends SlangNode { body; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.modifierKeyword = ast.modifierKeyword.text; - this.name = ast.name.text; - if (ast.parameters) { - this.parameters = parse(ast.parameters, this.nextChildOffset); - } else { + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + if (typeof this.parameters === 'undefined') { const parametersLoc = { - startWithTrivia: this.loc.childrenOffsets[0], - start: this.loc.childrenOffsets[0], - endWithTrivia: this.loc.childrenOffsets[0], - end: this.loc.childrenOffsets[0] + startWithTrivia: this.attributes.loc.startWithTrivia, + start: this.attributes.loc.startWithTrivia, + endWithTrivia: this.attributes.loc.startWithTrivia, + end: this.attributes.loc.startWithTrivia }; this.parameters = new ParametersDeclaration({ kind: 'ParametersDeclaration', @@ -40,9 +38,7 @@ export class ModifierDefinition extends SlangNode { closeParen: ')' }); } - this.attributes = parse(ast.attributes, this.nextChildOffset); - this.body = parse(ast.body, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/ModifierInvocation.js b/src/slang-nodes/ModifierInvocation.js index 794ea6d07..aec8d7664 100644 --- a/src/slang-nodes/ModifierInvocation.js +++ b/src/slang-nodes/ModifierInvocation.js @@ -8,14 +8,12 @@ export class ModifierInvocation extends SlangNode { arguments; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); this.#ast = ast; - this.name = parse(ast.name, this.nextChildOffset); - if (ast.arguments) { - this.arguments = parse(ast.arguments, this.nextChildOffset); - } - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } cleanModifierInvocationArguments() { diff --git a/src/slang-nodes/MultiplicativeExpression.js b/src/slang-nodes/MultiplicativeExpression.js index 5fadfa40d..3776a3574 100644 --- a/src/slang-nodes/MultiplicativeExpression.js +++ b/src/slang-nodes/MultiplicativeExpression.js @@ -13,10 +13,10 @@ export class MultiplicativeExpression extends SlangNode { rightOperand; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.leftOperand = parse(ast.leftOperand, this.nextChildOffset); - this.operator = ast.operator.text; + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); switch (this.operator) { case '*': @@ -32,8 +32,7 @@ export class MultiplicativeExpression extends SlangNode { break; } - this.rightOperand = parse(ast.rightOperand, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeLoc(ast); } print(path, print, options) { diff --git a/src/slang-nodes/NamedArgument.js b/src/slang-nodes/NamedArgument.js index 7801914b4..8b0c94eb2 100644 --- a/src/slang-nodes/NamedArgument.js +++ b/src/slang-nodes/NamedArgument.js @@ -7,12 +7,11 @@ export class NamedArgument extends SlangNode { value; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.name = ast.name.text; - this.colon = ast.colon.text; - this.value = parse(ast.value, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/NamedArgumentGroup.js b/src/slang-nodes/NamedArgumentGroup.js index cd9365746..975ea2568 100644 --- a/src/slang-nodes/NamedArgumentGroup.js +++ b/src/slang-nodes/NamedArgumentGroup.js @@ -7,12 +7,11 @@ export class NamedArgumentGroup extends SlangNode { closeBrace; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.openBrace = ast.openBrace.text; - this.arguments = parse(ast.arguments, this.nextChildOffset); - this.closeBrace = ast.closeBrace.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/NamedArguments.js b/src/slang-nodes/NamedArguments.js index 9e48cec49..faef85c40 100644 --- a/src/slang-nodes/NamedArguments.js +++ b/src/slang-nodes/NamedArguments.js @@ -9,11 +9,11 @@ export class NamedArguments extends SlangNode { separators; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); - this.separators = ast.separators.map((separator) => separator.text); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print, options) { diff --git a/src/slang-nodes/NamedArgumentsDeclaration.js b/src/slang-nodes/NamedArgumentsDeclaration.js index de9528326..f0a7b36d7 100644 --- a/src/slang-nodes/NamedArgumentsDeclaration.js +++ b/src/slang-nodes/NamedArgumentsDeclaration.js @@ -7,14 +7,11 @@ export class NamedArgumentsDeclaration extends SlangNode { closeParen; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.openParen = ast.openParen.text; - if (ast.arguments) { - this.arguments = parse(ast.arguments, this.nextChildOffset); - } - this.closeParen = ast.closeParen.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/NamedImport.js b/src/slang-nodes/NamedImport.js index 4eb2f5210..952ea1abf 100644 --- a/src/slang-nodes/NamedImport.js +++ b/src/slang-nodes/NamedImport.js @@ -9,13 +9,11 @@ export class NamedImport extends SlangNode { path; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.asterisk = ast.asterisk.text; - this.alias = parse(ast.alias, this.nextChildOffset); - this.fromKeyword = ast.fromKeyword.text; - this.path = parse(ast.path, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/NewExpression.js b/src/slang-nodes/NewExpression.js index d46353bb9..95d4e761f 100644 --- a/src/slang-nodes/NewExpression.js +++ b/src/slang-nodes/NewExpression.js @@ -5,11 +5,11 @@ export class NewExpression extends SlangNode { typeName; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.newKeyword = ast.newKeyword.text; - this.typeName = parse(ast.typeName, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/NumberUnit.js b/src/slang-nodes/NumberUnit.js index ac0941f36..71483ad29 100644 --- a/src/slang-nodes/NumberUnit.js +++ b/src/slang-nodes/NumberUnit.js @@ -3,10 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class NumberUnit extends SlangNode { variant; - constructor(ast, offset) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = ast.variant.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print() { diff --git a/src/slang-nodes/OrExpression.js b/src/slang-nodes/OrExpression.js index 89b7b877f..64d03e4fa 100644 --- a/src/slang-nodes/OrExpression.js +++ b/src/slang-nodes/OrExpression.js @@ -11,12 +11,13 @@ export class OrExpression extends SlangNode { rightOperand; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.leftOperand = tryToHug(parse(ast.leftOperand, this.nextChildOffset)); - this.operator = ast.operator.text; - this.rightOperand = tryToHug(parse(ast.rightOperand, this.nextChildOffset)); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.leftOperand = tryToHug(this.leftOperand); + this.rightOperand = tryToHug(this.rightOperand); + this.initializeLoc(ast); } print(path, print, options) { diff --git a/src/slang-nodes/OverridePaths.js b/src/slang-nodes/OverridePaths.js index 4a69435a6..aec11fcc4 100644 --- a/src/slang-nodes/OverridePaths.js +++ b/src/slang-nodes/OverridePaths.js @@ -5,11 +5,11 @@ export class OverridePaths extends SlangNode { separators; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); - this.separators = ast.separators.map((separator) => separator); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } // TODO: implement print diff --git a/src/slang-nodes/OverridePathsDeclaration.js b/src/slang-nodes/OverridePathsDeclaration.js index 3c02c102a..afe77983f 100644 --- a/src/slang-nodes/OverridePathsDeclaration.js +++ b/src/slang-nodes/OverridePathsDeclaration.js @@ -7,12 +7,11 @@ export class OverridePathsDeclaration extends SlangNode { closeParen; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.openParen = ast.openParen.text; - this.paths = parse(ast.paths, this.nextChildOffset); - this.closeParen = ast.closeParen.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } // TODO: implement print diff --git a/src/slang-nodes/OverrideSpecifier.js b/src/slang-nodes/OverrideSpecifier.js index f0ac1f30e..133526e2b 100644 --- a/src/slang-nodes/OverrideSpecifier.js +++ b/src/slang-nodes/OverrideSpecifier.js @@ -5,13 +5,11 @@ export class OverrideSpecifier extends SlangNode { overridden; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.overrideKeyword = ast.overrideKeyword.text; - if (ast.overridden) { - this.overridden = parse(ast.overridden, this.nextChildOffset); - } - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/Parameter.js b/src/slang-nodes/Parameter.js index c23313bee..82043139c 100644 --- a/src/slang-nodes/Parameter.js +++ b/src/slang-nodes/Parameter.js @@ -10,14 +10,11 @@ export class Parameter extends SlangNode { name; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.typeName = parse(ast.typeName, this.nextChildOffset); - if (ast.storageLocation) { - this.storageLocation = parse(ast.storageLocation, this.nextChildOffset); - } - this.name = ast.name?.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/Parameters.js b/src/slang-nodes/Parameters.js index d2cb23467..fc161fab4 100644 --- a/src/slang-nodes/Parameters.js +++ b/src/slang-nodes/Parameters.js @@ -10,12 +10,12 @@ export class Parameters extends SlangNode { separators; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); if (offset) { - this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); - this.separators = ast.separators.map((separator) => separator.text); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/ParametersDeclaration.js b/src/slang-nodes/ParametersDeclaration.js index a0baaa323..fcf99fc07 100644 --- a/src/slang-nodes/ParametersDeclaration.js +++ b/src/slang-nodes/ParametersDeclaration.js @@ -7,13 +7,12 @@ export class ParametersDeclaration extends SlangNode { closeParen; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); if (offset) { - this.openParen = ast.openParen.text; - this.parameters = parse(ast.parameters, this.nextChildOffset); - this.closeParen = ast.closeParen.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/PathImport.js b/src/slang-nodes/PathImport.js index 4b5fb5539..8d3279508 100644 --- a/src/slang-nodes/PathImport.js +++ b/src/slang-nodes/PathImport.js @@ -5,13 +5,11 @@ export class PathImport extends SlangNode { alias; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.path = parse(ast.path, this.nextChildOffset); - if (ast.alias) { - this.alias = parse(ast.alias, this.nextChildOffset); - } - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/PositionalArguments.js b/src/slang-nodes/PositionalArguments.js index 8d4d3aa62..9c4316ce3 100644 --- a/src/slang-nodes/PositionalArguments.js +++ b/src/slang-nodes/PositionalArguments.js @@ -6,11 +6,11 @@ export class PositionalArguments extends SlangNode { separators; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); - this.separators = ast.separators.map((separator) => separator.text); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/PositionalArgumentsDeclaration.js b/src/slang-nodes/PositionalArgumentsDeclaration.js index 95c2a1d20..cbd73b76a 100644 --- a/src/slang-nodes/PositionalArgumentsDeclaration.js +++ b/src/slang-nodes/PositionalArgumentsDeclaration.js @@ -7,12 +7,11 @@ export class PositionalArgumentsDeclaration extends SlangNode { closeParen; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.openParen = ast.openParen.text; - this.arguments = parse(ast.arguments, this.nextChildOffset); - this.closeParen = ast.closeParen.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/PostfixExpression.js b/src/slang-nodes/PostfixExpression.js index eb7676c29..8bce41214 100644 --- a/src/slang-nodes/PostfixExpression.js +++ b/src/slang-nodes/PostfixExpression.js @@ -5,11 +5,11 @@ export class PostfixExpression extends SlangNode { operator; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.operand = parse(ast.operand, this.nextChildOffset); - this.operator = ast.operator.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/Pragma.js b/src/slang-nodes/Pragma.js index a1b78e7d1..d943c8dac 100644 --- a/src/slang-nodes/Pragma.js +++ b/src/slang-nodes/Pragma.js @@ -3,10 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class Pragma extends SlangNode { variant; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = parse(ast.variant, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/PragmaDirective.js b/src/slang-nodes/PragmaDirective.js index 3b65cfd13..63217e50a 100644 --- a/src/slang-nodes/PragmaDirective.js +++ b/src/slang-nodes/PragmaDirective.js @@ -7,12 +7,11 @@ export class PragmaDirective extends SlangNode { semicolon; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.pragmaKeyword = ast.pragmaKeyword.text; - this.pragma = parse(ast.pragma, this.nextChildOffset); - this.semicolon = ast.semicolon.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/PrefixExpression.js b/src/slang-nodes/PrefixExpression.js index 06c483e4c..ce58bc2bf 100644 --- a/src/slang-nodes/PrefixExpression.js +++ b/src/slang-nodes/PrefixExpression.js @@ -5,11 +5,11 @@ export class PrefixExpression extends SlangNode { operand; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.operator = ast.operator.text; - this.operand = parse(ast.operand, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/ReceiveFunctionAttribute.js b/src/slang-nodes/ReceiveFunctionAttribute.js index 9e8ff79bd..d693d374c 100644 --- a/src/slang-nodes/ReceiveFunctionAttribute.js +++ b/src/slang-nodes/ReceiveFunctionAttribute.js @@ -3,13 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class ReceiveFunctionAttribute extends SlangNode { variant; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = - ast.variant.type === 'Terminal' - ? ast.variant.text - : parse(ast.variant, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/ReceiveFunctionAttributes.js b/src/slang-nodes/ReceiveFunctionAttributes.js index 3c30c781c..66e47ceb9 100644 --- a/src/slang-nodes/ReceiveFunctionAttributes.js +++ b/src/slang-nodes/ReceiveFunctionAttributes.js @@ -7,12 +7,12 @@ const { line } = doc.builders; export class ReceiveFunctionAttributes extends SlangNode { items; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items - .map((item) => parse(item, this.nextChildOffset)) - .sort(sortFunctionAttributes); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.items = this.items.sort(sortFunctionAttributes); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/ReceiveFunctionDefinition.js b/src/slang-nodes/ReceiveFunctionDefinition.js index cc6b47e17..df3355e0b 100644 --- a/src/slang-nodes/ReceiveFunctionDefinition.js +++ b/src/slang-nodes/ReceiveFunctionDefinition.js @@ -10,15 +10,12 @@ export class ReceiveFunctionDefinition extends SlangNode { body; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.receiveKeyword = ast.receiveKeyword.text; - this.parameters = parse(ast.parameters, this.nextChildOffset); - this.attributes = parse(ast.attributes, this.nextChildOffset); - this.body = parse(ast.body, this.nextChildOffset); - + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); this.cleanModifierInvocationArguments(); - this.initiateLoc(ast); + this.initializeLoc(ast); } cleanModifierInvocationArguments() { diff --git a/src/slang-nodes/ReturnStatement.js b/src/slang-nodes/ReturnStatement.js index abc4512b5..9cd4cd66a 100644 --- a/src/slang-nodes/ReturnStatement.js +++ b/src/slang-nodes/ReturnStatement.js @@ -21,14 +21,11 @@ export class ReturnStatement extends SlangNode { semicolon; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.returnKeyword = ast.returnKeyword.text; - if (ast.expression) { - this.expression = parse(ast.expression, this.nextChildOffset); - } - this.semicolon = ast.semicolon.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print, options) { diff --git a/src/slang-nodes/ReturnsDeclaration.js b/src/slang-nodes/ReturnsDeclaration.js index f551ce098..0a9d0f4b4 100644 --- a/src/slang-nodes/ReturnsDeclaration.js +++ b/src/slang-nodes/ReturnsDeclaration.js @@ -8,11 +8,11 @@ export class ReturnsDeclaration extends SlangNode { variables; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.returnsKeyword = ast.returnsKeyword.text; - this.variables = parse(ast.variables, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/RevertStatement.js b/src/slang-nodes/RevertStatement.js index 11c6fc923..32bcd8cd3 100644 --- a/src/slang-nodes/RevertStatement.js +++ b/src/slang-nodes/RevertStatement.js @@ -9,15 +9,11 @@ export class RevertStatement extends SlangNode { semicolon; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.revertKeyword = ast.revertKeyword.text; - if (ast.error) { - this.error = parse(ast.error, this.nextChildOffset); - } - this.arguments = parse(ast.arguments, this.nextChildOffset); - this.semicolon = ast.semicolon.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/ShiftExpression.js b/src/slang-nodes/ShiftExpression.js index b859ce0f6..bdacdcf2d 100644 --- a/src/slang-nodes/ShiftExpression.js +++ b/src/slang-nodes/ShiftExpression.js @@ -20,16 +20,13 @@ export class ShiftExpression extends SlangNode { rightOperand; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.leftOperand = tryToHugLeftOperand( - parse(ast.leftOperand, this.nextChildOffset) - ); - this.operator = ast.operator.text; - this.rightOperand = tryToHugRightOperand( - parse(ast.rightOperand, this.nextChildOffset) - ); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.leftOperand = tryToHugLeftOperand(this.leftOperand); + this.rightOperand = tryToHugRightOperand(this.rightOperand); + this.initializeLoc(ast); } print(path, print, options) { diff --git a/src/slang-nodes/SlangNode.js b/src/slang-nodes/SlangNode.js index 3903559e0..84e6a1dfe 100644 --- a/src/slang-nodes/SlangNode.js +++ b/src/slang-nodes/SlangNode.js @@ -57,6 +57,8 @@ const getLeadingOffset = (children) => { const getTrailingOffset = (children) => getLeadingOffset(children.reverse()); export class SlangNode { + #childrenKeys; + kind; loc = { @@ -78,6 +80,28 @@ export class SlangNode { this.loc.endWithTrivia = offset + ast.cst.textLength.utf8; } + initializeChildrenKeys() { + this.#childrenKeys = Object.keys(this).slice(3); + } + + parseChildrenNodes(ast, parse) { + const getValue = (astChild) => + astChild.type === 'Terminal' + ? astChild.text + : parse(astChild, this.nextChildOffset); + + this.#childrenKeys.forEach((childNodeName) => { + const astChild = ast[childNodeName]; + if (astChild) { + if (Array.isArray(astChild)) { + this[childNodeName] = astChild.map(getValue); + } else { + this[childNodeName] = getValue(astChild); + } + } + }); + } + /** * Leading and trailing Comments are considered by the parser as part of the * innermost possible node. For example if there is a comment just before a @@ -97,16 +121,14 @@ export class SlangNode { * ]; * ``` */ - initiateLoc(ast) { + initializeLoc(ast) { const children = ast.cst.children(); let leadingOffset = getLeadingOffset(children); let trailingOffset = getTrailingOffset(children); if (leadingOffset === 0 || trailingOffset === 0) { - const childrenKeys = Object.keys(this); - - for (let i = 0; i < childrenKeys.length; i += 1) { - const childLoc = this[childrenKeys[i]]?.loc; + for (let i = 0; i < this.#childrenKeys.length; i += 1) { + const childLoc = this[this.#childrenKeys[i]]?.loc; if (childLoc) { if ( diff --git a/src/slang-nodes/SourceUnit.js b/src/slang-nodes/SourceUnit.js index 1aa1755b3..c239a8edd 100644 --- a/src/slang-nodes/SourceUnit.js +++ b/src/slang-nodes/SourceUnit.js @@ -6,10 +6,11 @@ const { line } = doc.builders; export class SourceUnit extends SlangNode { members; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.members = parse(ast.members, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print, options) { diff --git a/src/slang-nodes/SourceUnitMember.js b/src/slang-nodes/SourceUnitMember.js index bad3a0a2f..c3dbc8a88 100644 --- a/src/slang-nodes/SourceUnitMember.js +++ b/src/slang-nodes/SourceUnitMember.js @@ -3,10 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class SourceUnitMember extends SlangNode { variant; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = parse(ast.variant, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/SourceUnitMembers.js b/src/slang-nodes/SourceUnitMembers.js index 8003b5524..2b9a9f748 100644 --- a/src/slang-nodes/SourceUnitMembers.js +++ b/src/slang-nodes/SourceUnitMembers.js @@ -4,10 +4,11 @@ import { SlangNode } from './SlangNode.js'; export class SourceUnitMembers extends SlangNode { items; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print, options) { diff --git a/src/slang-nodes/StateVariableAttribute.js b/src/slang-nodes/StateVariableAttribute.js index cf520a8f5..d5f21275e 100644 --- a/src/slang-nodes/StateVariableAttribute.js +++ b/src/slang-nodes/StateVariableAttribute.js @@ -3,13 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class StateVariableAttribute extends SlangNode { variant; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = - ast.variant.type === 'Terminal' - ? ast.variant.text - : parse(ast.variant, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/StateVariableAttributes.js b/src/slang-nodes/StateVariableAttributes.js index 73c965794..17b7c14a0 100644 --- a/src/slang-nodes/StateVariableAttributes.js +++ b/src/slang-nodes/StateVariableAttributes.js @@ -3,10 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class StateVariableAttributes extends SlangNode { items; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/StateVariableDefinition.js b/src/slang-nodes/StateVariableDefinition.js index 064c71673..ac71d82d8 100644 --- a/src/slang-nodes/StateVariableDefinition.js +++ b/src/slang-nodes/StateVariableDefinition.js @@ -11,16 +11,11 @@ export class StateVariableDefinition extends SlangNode { semicolon; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.typeName = parse(ast.typeName, this.nextChildOffset); - this.attributes = parse(ast.attributes, this.nextChildOffset); - this.name = ast.name.text; - if (ast.value) { - this.value = parse(ast.value, this.nextChildOffset); - } - this.semicolon = ast.semicolon.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/StateVariableDefinitionValue.js b/src/slang-nodes/StateVariableDefinitionValue.js index 04da873f8..59e3b7754 100644 --- a/src/slang-nodes/StateVariableDefinitionValue.js +++ b/src/slang-nodes/StateVariableDefinitionValue.js @@ -8,11 +8,11 @@ export class StateVariableDefinitionValue extends SlangNode { value; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.equal = ast.equal.text; - this.value = parse(ast.value, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/Statement.js b/src/slang-nodes/Statement.js index 9f09dbcda..d98a6be7b 100644 --- a/src/slang-nodes/Statement.js +++ b/src/slang-nodes/Statement.js @@ -3,10 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class Statement extends SlangNode { variant; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = parse(ast.variant, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/Statements.js b/src/slang-nodes/Statements.js index edab6914f..615e6ae7a 100644 --- a/src/slang-nodes/Statements.js +++ b/src/slang-nodes/Statements.js @@ -11,10 +11,11 @@ const { hardline } = doc.builders; export class Statements extends SlangNode { items; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print, options) { diff --git a/src/slang-nodes/StorageLocation.js b/src/slang-nodes/StorageLocation.js index 2c3b16656..55181d541 100644 --- a/src/slang-nodes/StorageLocation.js +++ b/src/slang-nodes/StorageLocation.js @@ -3,10 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class StorageLocation extends SlangNode { variant; - constructor(ast, offset) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = ast.variant.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print() { diff --git a/src/slang-nodes/StringExpression.js b/src/slang-nodes/StringExpression.js index 736cd19bb..02c51174a 100644 --- a/src/slang-nodes/StringExpression.js +++ b/src/slang-nodes/StringExpression.js @@ -3,10 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class StringExpression extends SlangNode { variant; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = parse(ast.variant, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/StringLiteral.js b/src/slang-nodes/StringLiteral.js index 551b84d94..a0d677f87 100644 --- a/src/slang-nodes/StringLiteral.js +++ b/src/slang-nodes/StringLiteral.js @@ -4,10 +4,12 @@ import { SlangNode } from './SlangNode.js'; export class StringLiteral extends SlangNode { variant; - constructor(ast, offset, options) { + constructor(ast, offset, parse, options) { super(ast, offset); - this.variant = printString(ast.variant.text.slice(1, -1), options); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.variant = printString(this.variant.slice(1, -1), options); + this.initializeLoc(ast); } print() { diff --git a/src/slang-nodes/StringLiterals.js b/src/slang-nodes/StringLiterals.js index d46500447..cd6106546 100644 --- a/src/slang-nodes/StringLiterals.js +++ b/src/slang-nodes/StringLiterals.js @@ -6,10 +6,11 @@ const { join, hardline } = doc.builders; export class StringLiterals extends SlangNode { items; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/StructDefinition.js b/src/slang-nodes/StructDefinition.js index f063e7b4c..fb37cafaf 100644 --- a/src/slang-nodes/StructDefinition.js +++ b/src/slang-nodes/StructDefinition.js @@ -11,14 +11,11 @@ export class StructDefinition extends SlangNode { closeBrace; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.structKeyword = ast.structKeyword.text; - this.name = ast.name.text; - this.openBrace = ast.openBrace.text; - this.members = parse(ast.members, this.nextChildOffset); - this.closeBrace = ast.closeBrace.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/StructMember.js b/src/slang-nodes/StructMember.js index d75330b2d..7b2613a50 100644 --- a/src/slang-nodes/StructMember.js +++ b/src/slang-nodes/StructMember.js @@ -7,12 +7,11 @@ export class StructMember extends SlangNode { semicolon; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.typeName = parse(ast.typeName, this.nextChildOffset); - this.name = ast.name.text; - this.semicolon = ast.semicolon.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/StructMembers.js b/src/slang-nodes/StructMembers.js index 5de7363da..538b92ce6 100644 --- a/src/slang-nodes/StructMembers.js +++ b/src/slang-nodes/StructMembers.js @@ -7,10 +7,11 @@ const { hardline } = doc.builders; export class StructMembers extends SlangNode { items; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/ThrowStatement.js b/src/slang-nodes/ThrowStatement.js index 21bdbc4fa..8b90d986c 100644 --- a/src/slang-nodes/ThrowStatement.js +++ b/src/slang-nodes/ThrowStatement.js @@ -5,11 +5,11 @@ export class ThrowStatement extends SlangNode { semicolon; - constructor(ast, offset) { + constructor(ast, offset, parse) { super(ast, offset); - this.throwKeyword = ast.throwKeyword.text; - this.semicolon = ast.semicolon.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } // TODO: implement print diff --git a/src/slang-nodes/TryStatement.js b/src/slang-nodes/TryStatement.js index 8c2335237..cb587cef2 100644 --- a/src/slang-nodes/TryStatement.js +++ b/src/slang-nodes/TryStatement.js @@ -15,16 +15,11 @@ export class TryStatement extends SlangNode { catchClauses; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.tryKeyword = ast.tryKeyword.text; - this.expression = parse(ast.expression, this.nextChildOffset); - if (ast.returns) { - this.returns = parse(ast.returns, this.nextChildOffset); - } - this.body = parse(ast.body, this.nextChildOffset); - this.catchClauses = parse(ast.catchClauses, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/TupleDeconstructionElement.js b/src/slang-nodes/TupleDeconstructionElement.js index 429115704..5bbda7e4f 100644 --- a/src/slang-nodes/TupleDeconstructionElement.js +++ b/src/slang-nodes/TupleDeconstructionElement.js @@ -3,12 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class TupleDeconstructionElement extends SlangNode { member; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - if (ast.member) { - this.member = parse(ast.member, this.nextChildOffset); - } - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/TupleDeconstructionElements.js b/src/slang-nodes/TupleDeconstructionElements.js index ecb12a599..dc5b908c3 100644 --- a/src/slang-nodes/TupleDeconstructionElements.js +++ b/src/slang-nodes/TupleDeconstructionElements.js @@ -6,11 +6,11 @@ export class TupleDeconstructionElements extends SlangNode { separators; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); - this.separators = ast.separators.map((separator) => separator.text); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/TupleDeconstructionStatement.js b/src/slang-nodes/TupleDeconstructionStatement.js index 7e947a469..f0730e170 100644 --- a/src/slang-nodes/TupleDeconstructionStatement.js +++ b/src/slang-nodes/TupleDeconstructionStatement.js @@ -18,16 +18,11 @@ export class TupleDeconstructionStatement extends SlangNode { semicolon; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.varKeyword = ast.varKeyword?.text; - this.openParen = ast.openParen.text; - this.elements = parse(ast.elements, this.nextChildOffset); - this.closeParen = ast.closeParen.text; - this.equal = ast.equal.text; - this.expression = parse(ast.expression, this.nextChildOffset); - this.semicolon = ast.semicolon.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/TupleExpression.js b/src/slang-nodes/TupleExpression.js index a1546defc..40879c9c8 100644 --- a/src/slang-nodes/TupleExpression.js +++ b/src/slang-nodes/TupleExpression.js @@ -7,13 +7,12 @@ export class TupleExpression extends SlangNode { closeParen; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); if (offset) { - this.openParen = ast.openParen.text; - this.items = parse(ast.items, this.nextChildOffset); - this.closeParen = ast.closeParen.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/TupleMember.js b/src/slang-nodes/TupleMember.js index 1c6262b40..23ed9d9cc 100644 --- a/src/slang-nodes/TupleMember.js +++ b/src/slang-nodes/TupleMember.js @@ -3,10 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class TupleMember extends SlangNode { variant; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = parse(ast.variant, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/TupleValue.js b/src/slang-nodes/TupleValue.js index 60c70449d..a5f45101d 100644 --- a/src/slang-nodes/TupleValue.js +++ b/src/slang-nodes/TupleValue.js @@ -3,13 +3,12 @@ import { SlangNode } from './SlangNode.js'; export class TupleValue extends SlangNode { expression; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); if (offset) { - if (ast.expression) { - this.expression = parse(ast.expression, this.nextChildOffset); - } - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/TupleValues.js b/src/slang-nodes/TupleValues.js index fdf061047..678ce9090 100644 --- a/src/slang-nodes/TupleValues.js +++ b/src/slang-nodes/TupleValues.js @@ -7,12 +7,12 @@ export class TupleValues extends SlangNode { separators; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); if (offset) { - this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); - this.separators = ast.separators.map((separator) => separator.text); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/TypeExpression.js b/src/slang-nodes/TypeExpression.js index 270c208ca..ead8f981e 100644 --- a/src/slang-nodes/TypeExpression.js +++ b/src/slang-nodes/TypeExpression.js @@ -9,13 +9,11 @@ export class TypeExpression extends SlangNode { closeParen; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.typeKeyword = ast.typeKeyword.text; - this.openParen = ast.openParen.text; - this.typeName = parse(ast.typeName, this.nextChildOffset); - this.closeParen = ast.closeParen.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } // TODO: implement print diff --git a/src/slang-nodes/TypeName.js b/src/slang-nodes/TypeName.js index 63184a218..b6326b5a9 100644 --- a/src/slang-nodes/TypeName.js +++ b/src/slang-nodes/TypeName.js @@ -3,10 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class TypeName extends SlangNode { variant; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = parse(ast.variant, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/TypedTupleMember.js b/src/slang-nodes/TypedTupleMember.js index 7302d770d..30f6de0b4 100644 --- a/src/slang-nodes/TypedTupleMember.js +++ b/src/slang-nodes/TypedTupleMember.js @@ -7,14 +7,11 @@ export class TypedTupleMember extends SlangNode { name; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.typeName = parse(ast.typeName, this.nextChildOffset); - if (ast.storageLocation) { - this.storageLocation = parse(ast.storageLocation, this.nextChildOffset); - } - this.name = ast.name.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/UncheckedBlock.js b/src/slang-nodes/UncheckedBlock.js index 4038f1735..1c58c1f3e 100644 --- a/src/slang-nodes/UncheckedBlock.js +++ b/src/slang-nodes/UncheckedBlock.js @@ -5,11 +5,11 @@ export class UncheckedBlock extends SlangNode { block; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.uncheckedKeyword = ast.uncheckedKeyword.text; - this.block = parse(ast.block, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/UnicodeStringLiteral.js b/src/slang-nodes/UnicodeStringLiteral.js index ab78996cc..abdf2d2a8 100644 --- a/src/slang-nodes/UnicodeStringLiteral.js +++ b/src/slang-nodes/UnicodeStringLiteral.js @@ -4,10 +4,12 @@ import { SlangNode } from './SlangNode.js'; export class UnicodeStringLiteral extends SlangNode { variant; - constructor(ast, offset, options) { + constructor(ast, offset, parse, options) { super(ast, offset); - this.variant = `unicode${printString(ast.variant.text.slice(8, -1), options)}`; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.variant = `unicode${printString(this.variant.slice(8, -1), options)}`; + this.initializeLoc(ast); } print() { diff --git a/src/slang-nodes/UnicodeStringLiterals.js b/src/slang-nodes/UnicodeStringLiterals.js index f44a11a6a..f9079b272 100644 --- a/src/slang-nodes/UnicodeStringLiterals.js +++ b/src/slang-nodes/UnicodeStringLiterals.js @@ -6,10 +6,11 @@ const { join, hardline } = doc.builders; export class UnicodeStringLiterals extends SlangNode { items; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/UnnamedFunctionAttribute.js b/src/slang-nodes/UnnamedFunctionAttribute.js index ab5cc9649..913a72303 100644 --- a/src/slang-nodes/UnnamedFunctionAttribute.js +++ b/src/slang-nodes/UnnamedFunctionAttribute.js @@ -3,13 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class UnnamedFunctionAttribute extends SlangNode { variant; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = - ast.variant.type === 'Terminal' - ? ast.variant.text - : parse(ast.variant, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/UnnamedFunctionAttributes.js b/src/slang-nodes/UnnamedFunctionAttributes.js index 267d1ba60..ea153afa2 100644 --- a/src/slang-nodes/UnnamedFunctionAttributes.js +++ b/src/slang-nodes/UnnamedFunctionAttributes.js @@ -7,12 +7,12 @@ const { line } = doc.builders; export class UnnamedFunctionAttributes extends SlangNode { items; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items - .map((item) => parse(item, this.nextChildOffset)) - .sort(sortFunctionAttributes); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.items = this.items.sort(sortFunctionAttributes); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/UnnamedFunctionDefinition.js b/src/slang-nodes/UnnamedFunctionDefinition.js index 7e93dc387..7250e187e 100644 --- a/src/slang-nodes/UnnamedFunctionDefinition.js +++ b/src/slang-nodes/UnnamedFunctionDefinition.js @@ -10,15 +10,12 @@ export class UnnamedFunctionDefinition extends SlangNode { body; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.functionKeyword = ast.functionKeyword.text; - this.parameters = parse(ast.parameters, this.nextChildOffset); - this.attributes = parse(ast.attributes, this.nextChildOffset); - this.body = parse(ast.body, this.nextChildOffset); - + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); this.cleanModifierInvocationArguments(); - this.initiateLoc(ast); + this.initializeLoc(ast); } cleanModifierInvocationArguments() { diff --git a/src/slang-nodes/UntypedTupleMember.js b/src/slang-nodes/UntypedTupleMember.js index fb09e6a2a..12a2a0bff 100644 --- a/src/slang-nodes/UntypedTupleMember.js +++ b/src/slang-nodes/UntypedTupleMember.js @@ -5,13 +5,11 @@ export class UntypedTupleMember extends SlangNode { name; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - if (ast.storageLocation) { - this.storageLocation = parse(ast.storageLocation, this.nextChildOffset); - } - this.name = ast.name.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } // TODO: implement print diff --git a/src/slang-nodes/UserDefinedValueTypeDefinition.js b/src/slang-nodes/UserDefinedValueTypeDefinition.js index e8c76e1d5..a8b96b8f2 100644 --- a/src/slang-nodes/UserDefinedValueTypeDefinition.js +++ b/src/slang-nodes/UserDefinedValueTypeDefinition.js @@ -11,14 +11,11 @@ export class UserDefinedValueTypeDefinition extends SlangNode { semicolon; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.typeKeyword = ast.typeKeyword.text; - this.name = ast.name.text; - this.isKeyword = ast.isKeyword.text; - this.valueType = parse(ast.valueType, this.nextChildOffset); - this.semicolon = ast.semicolon.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/UsingAlias.js b/src/slang-nodes/UsingAlias.js index d320ea4c9..8848ef56d 100644 --- a/src/slang-nodes/UsingAlias.js +++ b/src/slang-nodes/UsingAlias.js @@ -5,11 +5,11 @@ export class UsingAlias extends SlangNode { operator; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.asKeyword = ast.asKeyword.text; - this.operator = parse(ast.operator, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/UsingClause.js b/src/slang-nodes/UsingClause.js index 8e8ad515c..aceca101b 100644 --- a/src/slang-nodes/UsingClause.js +++ b/src/slang-nodes/UsingClause.js @@ -3,10 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class UsingClause extends SlangNode { variant; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = parse(ast.variant, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/UsingDeconstruction.js b/src/slang-nodes/UsingDeconstruction.js index ccdea6f73..de6d6eaa5 100644 --- a/src/slang-nodes/UsingDeconstruction.js +++ b/src/slang-nodes/UsingDeconstruction.js @@ -7,12 +7,11 @@ export class UsingDeconstruction extends SlangNode { closeBrace; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.openBrace = ast.openBrace.text; - this.symbols = parse(ast.symbols, this.nextChildOffset); - this.closeBrace = ast.closeBrace.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/UsingDeconstructionSymbol.js b/src/slang-nodes/UsingDeconstructionSymbol.js index 88997845c..41a41bd6a 100644 --- a/src/slang-nodes/UsingDeconstructionSymbol.js +++ b/src/slang-nodes/UsingDeconstructionSymbol.js @@ -5,13 +5,11 @@ export class UsingDeconstructionSymbol extends SlangNode { alias; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.name = parse(ast.name, this.nextChildOffset); - if (ast.alias) { - this.alias = parse(ast.alias, this.nextChildOffset); - } - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/UsingDeconstructionSymbols.js b/src/slang-nodes/UsingDeconstructionSymbols.js index 6f2d05da3..f99f3b7bb 100644 --- a/src/slang-nodes/UsingDeconstructionSymbols.js +++ b/src/slang-nodes/UsingDeconstructionSymbols.js @@ -9,11 +9,11 @@ export class UsingDeconstructionSymbols extends SlangNode { separators; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); - this.separators = ast.separators.map((separator) => separator.text); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print, options) { diff --git a/src/slang-nodes/UsingDirective.js b/src/slang-nodes/UsingDirective.js index f87275fab..df4d85caa 100644 --- a/src/slang-nodes/UsingDirective.js +++ b/src/slang-nodes/UsingDirective.js @@ -13,15 +13,11 @@ export class UsingDirective extends SlangNode { semicolon; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.usingKeyword = ast.usingKeyword.text; - this.clause = parse(ast.clause, this.nextChildOffset); - this.forKeyword = ast.forKeyword.text; - this.target = parse(ast.target, this.nextChildOffset); - this.globalKeyword = ast.globalKeyword?.text; - this.semicolon = ast.semicolon.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/UsingOperator.js b/src/slang-nodes/UsingOperator.js index b38045122..9500dc2cf 100644 --- a/src/slang-nodes/UsingOperator.js +++ b/src/slang-nodes/UsingOperator.js @@ -3,10 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class UsingOperator extends SlangNode { variant; - constructor(ast, offset) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = ast.variant.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print() { diff --git a/src/slang-nodes/UsingTarget.js b/src/slang-nodes/UsingTarget.js index 6c6a65058..0d70b4783 100644 --- a/src/slang-nodes/UsingTarget.js +++ b/src/slang-nodes/UsingTarget.js @@ -3,13 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class UsingTarget extends SlangNode { variant; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = - ast.variant.type === 'Terminal' - ? ast.variant.text - : parse(ast.variant, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/VariableDeclarationStatement.js b/src/slang-nodes/VariableDeclarationStatement.js index 8c5c50598..7b911a4dd 100644 --- a/src/slang-nodes/VariableDeclarationStatement.js +++ b/src/slang-nodes/VariableDeclarationStatement.js @@ -14,18 +14,11 @@ export class VariableDeclarationStatement extends SlangNode { semicolon; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.variableType = parse(ast.variableType, this.nextChildOffset); - if (ast.storageLocation) { - this.storageLocation = parse(ast.storageLocation, this.nextChildOffset); - } - this.name = ast.name.text; - if (ast.value) { - this.value = parse(ast.value, this.nextChildOffset); - } - this.semicolon = ast.semicolon.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/VariableDeclarationType.js b/src/slang-nodes/VariableDeclarationType.js index b1fd6b4b3..81aabc23f 100644 --- a/src/slang-nodes/VariableDeclarationType.js +++ b/src/slang-nodes/VariableDeclarationType.js @@ -3,13 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class VariableDeclarationType extends SlangNode { variant; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = - ast.variant.type === 'Terminal' - ? ast.variant.text - : parse(ast.variant, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/VariableDeclarationValue.js b/src/slang-nodes/VariableDeclarationValue.js index 231864d67..96f7b2097 100644 --- a/src/slang-nodes/VariableDeclarationValue.js +++ b/src/slang-nodes/VariableDeclarationValue.js @@ -5,11 +5,11 @@ export class VariableDeclarationValue extends SlangNode { expression; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.equal = ast.equal.text; - this.expression = parse(ast.expression, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/VersionComparator.js b/src/slang-nodes/VersionComparator.js index a00e9ccf4..9fc464d62 100644 --- a/src/slang-nodes/VersionComparator.js +++ b/src/slang-nodes/VersionComparator.js @@ -5,11 +5,11 @@ export class VersionComparator extends SlangNode { operand; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.operator = ast.operator.text; - this.operand = parse(ast.operand, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/VersionExpression.js b/src/slang-nodes/VersionExpression.js index ec4e93726..f17d87e83 100644 --- a/src/slang-nodes/VersionExpression.js +++ b/src/slang-nodes/VersionExpression.js @@ -3,13 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class VersionExpression extends SlangNode { variant; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = - ast.variant.type === 'Terminal' - ? ast.variant.text - : parse(ast.variant, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/VersionExpressionSet.js b/src/slang-nodes/VersionExpressionSet.js index 59c66c5c8..ba63ad1b9 100644 --- a/src/slang-nodes/VersionExpressionSet.js +++ b/src/slang-nodes/VersionExpressionSet.js @@ -6,10 +6,11 @@ const { join } = doc.builders; export class VersionExpressionSet extends SlangNode { items; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/VersionExpressionSets.js b/src/slang-nodes/VersionExpressionSets.js index 358a23023..598588a84 100644 --- a/src/slang-nodes/VersionExpressionSets.js +++ b/src/slang-nodes/VersionExpressionSets.js @@ -5,11 +5,11 @@ export class VersionExpressionSets extends SlangNode { separators; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); - this.separators = ast.separators.map((separator) => separator.text); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/VersionPragma.js b/src/slang-nodes/VersionPragma.js index 97e20ac64..0595e1bac 100644 --- a/src/slang-nodes/VersionPragma.js +++ b/src/slang-nodes/VersionPragma.js @@ -5,11 +5,11 @@ export class VersionPragma extends SlangNode { sets; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.solidityKeyword = ast.solidityKeyword.text; - this.sets = parse(ast.sets, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/VersionRange.js b/src/slang-nodes/VersionRange.js index 74dde93b7..134471a28 100644 --- a/src/slang-nodes/VersionRange.js +++ b/src/slang-nodes/VersionRange.js @@ -7,12 +7,11 @@ export class VersionRange extends SlangNode { rightOperand; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.leftOperand = parse(ast.leftOperand, this.nextChildOffset); - this.operator = ast.operator.text; - this.rightOperand = parse(ast.rightOperand, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } // TODO: implement print diff --git a/src/slang-nodes/VersionSpecifiers.js b/src/slang-nodes/VersionSpecifiers.js index 569aea278..208ac4355 100644 --- a/src/slang-nodes/VersionSpecifiers.js +++ b/src/slang-nodes/VersionSpecifiers.js @@ -5,11 +5,11 @@ export class VersionSpecifiers extends SlangNode { separators; - constructor(ast, offset) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items.map((item) => item.text); - this.separators = ast.separators.map((separator) => separator.text); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print() { diff --git a/src/slang-nodes/WhileStatement.js b/src/slang-nodes/WhileStatement.js index 400638a84..c5f9a18c6 100644 --- a/src/slang-nodes/WhileStatement.js +++ b/src/slang-nodes/WhileStatement.js @@ -20,14 +20,11 @@ export class WhileStatement extends SlangNode { body; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.whileKeyword = ast.whileKeyword.text; - this.openParen = ast.openParen.text; - this.condition = parse(ast.condition, this.nextChildOffset); - this.closeParen = ast.closeParen.text; - this.body = parse(ast.body, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/YulArguments.js b/src/slang-nodes/YulArguments.js index e83cbcb82..d2f26e548 100644 --- a/src/slang-nodes/YulArguments.js +++ b/src/slang-nodes/YulArguments.js @@ -6,11 +6,11 @@ export class YulArguments extends SlangNode { separators; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); - this.separators = ast.separators.map((separator) => separator.text); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/YulAssignmentOperator.js b/src/slang-nodes/YulAssignmentOperator.js index 4300e0563..0f64ba3ab 100644 --- a/src/slang-nodes/YulAssignmentOperator.js +++ b/src/slang-nodes/YulAssignmentOperator.js @@ -3,13 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class YulAssignmentOperator extends SlangNode { variant; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = - ast.variant.type === 'Terminal' - ? ast.variant.text - : parse(ast.variant, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/YulAssignmentStatement.js b/src/slang-nodes/YulAssignmentStatement.js index 8f8665878..c73dd5f44 100644 --- a/src/slang-nodes/YulAssignmentStatement.js +++ b/src/slang-nodes/YulAssignmentStatement.js @@ -7,12 +7,11 @@ export class YulAssignmentStatement extends SlangNode { expression; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.names = parse(ast.names, this.nextChildOffset); - this.assignment = parse(ast.assignment, this.nextChildOffset); - this.expression = parse(ast.expression, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/YulBlock.js b/src/slang-nodes/YulBlock.js index ab6eb665a..171e2878c 100644 --- a/src/slang-nodes/YulBlock.js +++ b/src/slang-nodes/YulBlock.js @@ -7,12 +7,11 @@ export class YulBlock extends SlangNode { closeBrace; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.openBrace = ast.openBrace.text; - this.statements = parse(ast.statements, this.nextChildOffset); - this.closeBrace = ast.closeBrace.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/YulBreakStatement.js b/src/slang-nodes/YulBreakStatement.js index dc24e1ad4..3ac57fd05 100644 --- a/src/slang-nodes/YulBreakStatement.js +++ b/src/slang-nodes/YulBreakStatement.js @@ -3,10 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class YulBreakStatement extends SlangNode { breakKeyword; - constructor(ast, offset) { + constructor(ast, offset, parse) { super(ast, offset); - this.breakKeyword = ast.breakKeyword.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print() { diff --git a/src/slang-nodes/YulBuiltInFunction.js b/src/slang-nodes/YulBuiltInFunction.js index fab564369..7398e3ea0 100644 --- a/src/slang-nodes/YulBuiltInFunction.js +++ b/src/slang-nodes/YulBuiltInFunction.js @@ -3,10 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class YulBuiltInFunction extends SlangNode { variant; - constructor(ast, offset) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = ast.variant.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print() { diff --git a/src/slang-nodes/YulColonAndEqual.js b/src/slang-nodes/YulColonAndEqual.js index a6a432da2..162ab9374 100644 --- a/src/slang-nodes/YulColonAndEqual.js +++ b/src/slang-nodes/YulColonAndEqual.js @@ -5,11 +5,11 @@ export class YulColonAndEqual extends SlangNode { equal; - constructor(ast, offset) { + constructor(ast, offset, parse) { super(ast, offset); - this.colon = ast.colon.text; - this.equal = ast.equal.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } // TODO: implement print diff --git a/src/slang-nodes/YulContinueStatement.js b/src/slang-nodes/YulContinueStatement.js index 6e5858716..bb8f52e2f 100644 --- a/src/slang-nodes/YulContinueStatement.js +++ b/src/slang-nodes/YulContinueStatement.js @@ -3,10 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class YulContinueStatement extends SlangNode { continueKeyword; - constructor(ast, offset) { + constructor(ast, offset, parse) { super(ast, offset); - this.continueKeyword = ast.continueKeyword.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print() { diff --git a/src/slang-nodes/YulDefaultCase.js b/src/slang-nodes/YulDefaultCase.js index f99d9b8ca..b5934f15c 100644 --- a/src/slang-nodes/YulDefaultCase.js +++ b/src/slang-nodes/YulDefaultCase.js @@ -5,11 +5,11 @@ export class YulDefaultCase extends SlangNode { body; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.defaultKeyword = ast.defaultKeyword.text; - this.body = parse(ast.body, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/YulExpression.js b/src/slang-nodes/YulExpression.js index d906a04ae..d79da0023 100644 --- a/src/slang-nodes/YulExpression.js +++ b/src/slang-nodes/YulExpression.js @@ -3,10 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class YulExpression extends SlangNode { variant; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = parse(ast.variant, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/YulForStatement.js b/src/slang-nodes/YulForStatement.js index a8ce174d3..e290e24f7 100644 --- a/src/slang-nodes/YulForStatement.js +++ b/src/slang-nodes/YulForStatement.js @@ -11,14 +11,11 @@ export class YulForStatement extends SlangNode { body; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.forKeyword = ast.forKeyword.text; - this.initialization = parse(ast.initialization, this.nextChildOffset); - this.condition = parse(ast.condition, this.nextChildOffset); - this.iterator = parse(ast.iterator, this.nextChildOffset); - this.body = parse(ast.body, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/YulFunctionCallExpression.js b/src/slang-nodes/YulFunctionCallExpression.js index 47657c7f0..921025230 100644 --- a/src/slang-nodes/YulFunctionCallExpression.js +++ b/src/slang-nodes/YulFunctionCallExpression.js @@ -9,13 +9,11 @@ export class YulFunctionCallExpression extends SlangNode { closeParen; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.operand = parse(ast.operand, this.nextChildOffset); - this.openParen = ast.openParen.text; - this.arguments = parse(ast.arguments, this.nextChildOffset); - this.closeParen = ast.closeParen.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/YulFunctionDefinition.js b/src/slang-nodes/YulFunctionDefinition.js index a3044eade..c5e998811 100644 --- a/src/slang-nodes/YulFunctionDefinition.js +++ b/src/slang-nodes/YulFunctionDefinition.js @@ -11,16 +11,11 @@ export class YulFunctionDefinition extends SlangNode { body; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.functionKeyword = ast.functionKeyword.text; - this.name = ast.name.text; - this.parameters = parse(ast.parameters, this.nextChildOffset); - if (ast.returns) { - this.returns = parse(ast.returns, this.nextChildOffset); - } - this.body = parse(ast.body, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/YulIfStatement.js b/src/slang-nodes/YulIfStatement.js index d67191370..da2ccb64f 100644 --- a/src/slang-nodes/YulIfStatement.js +++ b/src/slang-nodes/YulIfStatement.js @@ -7,12 +7,11 @@ export class YulIfStatement extends SlangNode { body; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.ifKeyword = ast.ifKeyword.text; - this.condition = parse(ast.condition, this.nextChildOffset); - this.body = parse(ast.body, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/YulLabel.js b/src/slang-nodes/YulLabel.js index 3333e22a0..27fbe5f3d 100644 --- a/src/slang-nodes/YulLabel.js +++ b/src/slang-nodes/YulLabel.js @@ -7,11 +7,11 @@ export class YulLabel extends SlangNode { colon; - constructor(ast, offset) { + constructor(ast, offset, parse) { super(ast, offset); - this.label = ast.label.text; - this.colon = ast.colon.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print() { diff --git a/src/slang-nodes/YulLeaveStatement.js b/src/slang-nodes/YulLeaveStatement.js index 5dff1ae1f..731fc744e 100644 --- a/src/slang-nodes/YulLeaveStatement.js +++ b/src/slang-nodes/YulLeaveStatement.js @@ -3,10 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class YulLeaveStatement extends SlangNode { leaveKeyword; - constructor(ast, offset) { + constructor(ast, offset, parse) { super(ast, offset); - this.leaveKeyword = ast.leaveKeyword.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } // TODO: implement print diff --git a/src/slang-nodes/YulLiteral.js b/src/slang-nodes/YulLiteral.js index 648454502..eb4fe64f1 100644 --- a/src/slang-nodes/YulLiteral.js +++ b/src/slang-nodes/YulLiteral.js @@ -3,13 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class YulLiteral extends SlangNode { variant; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = - ast.variant.type === 'Terminal' - ? ast.variant.text - : parse(ast.variant, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/YulParameters.js b/src/slang-nodes/YulParameters.js index 01d2ec7a2..f50e849c8 100644 --- a/src/slang-nodes/YulParameters.js +++ b/src/slang-nodes/YulParameters.js @@ -6,11 +6,11 @@ export class YulParameters extends SlangNode { separators; - constructor(ast, offset) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items.map((item) => item.text); - this.separators = ast.separators.map((separator) => separator.text); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print() { diff --git a/src/slang-nodes/YulParametersDeclaration.js b/src/slang-nodes/YulParametersDeclaration.js index 7f7af6f9e..c62b47303 100644 --- a/src/slang-nodes/YulParametersDeclaration.js +++ b/src/slang-nodes/YulParametersDeclaration.js @@ -7,12 +7,11 @@ export class YulParametersDeclaration extends SlangNode { closeParen; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.openParen = ast.openParen.text; - this.parameters = parse(ast.parameters, this.nextChildOffset); - this.closeParen = ast.closeParen.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/YulPath.js b/src/slang-nodes/YulPath.js index 84fa4e8c0..64a09b9da 100644 --- a/src/slang-nodes/YulPath.js +++ b/src/slang-nodes/YulPath.js @@ -5,11 +5,11 @@ export class YulPath extends SlangNode { separators; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); - this.separators = ast.separators.map((separator) => separator.text); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/YulPathComponent.js b/src/slang-nodes/YulPathComponent.js index 8e7cf56d9..69a570276 100644 --- a/src/slang-nodes/YulPathComponent.js +++ b/src/slang-nodes/YulPathComponent.js @@ -3,10 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class YulPathComponent extends SlangNode { variant; - constructor(ast, offset) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = ast.variant.text; - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print() { diff --git a/src/slang-nodes/YulPaths.js b/src/slang-nodes/YulPaths.js index f4db66bed..e4a7b5248 100644 --- a/src/slang-nodes/YulPaths.js +++ b/src/slang-nodes/YulPaths.js @@ -5,11 +5,11 @@ export class YulPaths extends SlangNode { separators; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); - this.separators = ast.separators.map((separator) => separator.text); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/YulReturnVariables.js b/src/slang-nodes/YulReturnVariables.js index 734065480..b51709a93 100644 --- a/src/slang-nodes/YulReturnVariables.js +++ b/src/slang-nodes/YulReturnVariables.js @@ -9,11 +9,11 @@ export class YulReturnVariables extends SlangNode { separators; - constructor(ast, offset) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items.map((item) => item.text); - this.separators = ast.separators.map((separator) => separator.text); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print() { diff --git a/src/slang-nodes/YulReturnsDeclaration.js b/src/slang-nodes/YulReturnsDeclaration.js index 6080251db..812ac222a 100644 --- a/src/slang-nodes/YulReturnsDeclaration.js +++ b/src/slang-nodes/YulReturnsDeclaration.js @@ -9,11 +9,11 @@ export class YulReturnsDeclaration extends SlangNode { variables; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.minusGreaterThan = ast.minusGreaterThan.text; - this.variables = parse(ast.variables, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/YulStatement.js b/src/slang-nodes/YulStatement.js index 616cbd80b..58ea9c4ed 100644 --- a/src/slang-nodes/YulStatement.js +++ b/src/slang-nodes/YulStatement.js @@ -3,10 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class YulStatement extends SlangNode { variant; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = parse(ast.variant, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/YulStatements.js b/src/slang-nodes/YulStatements.js index bee818af1..efa9ab58b 100644 --- a/src/slang-nodes/YulStatements.js +++ b/src/slang-nodes/YulStatements.js @@ -11,10 +11,11 @@ const { hardline } = doc.builders; export class YulStatements extends SlangNode { items; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print, options) { diff --git a/src/slang-nodes/YulSwitchCase.js b/src/slang-nodes/YulSwitchCase.js index df593f0bc..8a2b1518f 100644 --- a/src/slang-nodes/YulSwitchCase.js +++ b/src/slang-nodes/YulSwitchCase.js @@ -3,10 +3,11 @@ import { SlangNode } from './SlangNode.js'; export class YulSwitchCase extends SlangNode { variant; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.variant = parse(ast.variant, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/YulSwitchCases.js b/src/slang-nodes/YulSwitchCases.js index 41b003256..f87fb679a 100644 --- a/src/slang-nodes/YulSwitchCases.js +++ b/src/slang-nodes/YulSwitchCases.js @@ -6,10 +6,11 @@ const { hardline, join } = doc.builders; export class YulSwitchCases extends SlangNode { items; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.items = ast.items.map((item) => parse(item, this.nextChildOffset)); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/YulSwitchStatement.js b/src/slang-nodes/YulSwitchStatement.js index 1d67cc164..7bf57b17b 100644 --- a/src/slang-nodes/YulSwitchStatement.js +++ b/src/slang-nodes/YulSwitchStatement.js @@ -10,12 +10,11 @@ export class YulSwitchStatement extends SlangNode { cases; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.switchKeyword = ast.switchKeyword.text; - this.expression = parse(ast.expression, this.nextChildOffset); - this.cases = parse(ast.cases, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/YulValueCase.js b/src/slang-nodes/YulValueCase.js index be822c0e8..46a51b049 100644 --- a/src/slang-nodes/YulValueCase.js +++ b/src/slang-nodes/YulValueCase.js @@ -7,12 +7,11 @@ export class YulValueCase extends SlangNode { body; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.caseKeyword = ast.caseKeyword.text; - this.value = parse(ast.value, this.nextChildOffset); - this.body = parse(ast.body, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/YulVariableAssignmentStatement.js b/src/slang-nodes/YulVariableAssignmentStatement.js index 6f0a3c394..c389a755d 100644 --- a/src/slang-nodes/YulVariableAssignmentStatement.js +++ b/src/slang-nodes/YulVariableAssignmentStatement.js @@ -7,12 +7,11 @@ export class YulVariableAssignmentStatement extends SlangNode { expression; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.names = parse(ast.names, this.nextChildOffset); - this.assignment = parse(ast.assignment, this.nextChildOffset); - this.expression = parse(ast.expression, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/YulVariableDeclarationStatement.js b/src/slang-nodes/YulVariableDeclarationStatement.js index 85e67c5ec..180a1817b 100644 --- a/src/slang-nodes/YulVariableDeclarationStatement.js +++ b/src/slang-nodes/YulVariableDeclarationStatement.js @@ -7,14 +7,11 @@ export class YulVariableDeclarationStatement extends SlangNode { value; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.letKeyword = ast.letKeyword.text; - this.names = ast.names.text; - if (ast.value) { - this.value = parse(ast.value, this.nextChildOffset); - } - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slang-nodes/YulVariableDeclarationValue.js b/src/slang-nodes/YulVariableDeclarationValue.js index 9060fe1a5..3b508b9b8 100644 --- a/src/slang-nodes/YulVariableDeclarationValue.js +++ b/src/slang-nodes/YulVariableDeclarationValue.js @@ -5,11 +5,11 @@ export class YulVariableDeclarationValue extends SlangNode { expression; - constructor(ast, offset, options, parse) { + constructor(ast, offset, parse) { super(ast, offset); - this.assignment = parse(ast.assignment, this.nextChildOffset); - this.expression = parse(ast.expression, this.nextChildOffset); - this.initiateLoc(ast); + this.initializeChildrenKeys(); + this.parseChildrenNodes(ast, parse); + this.initializeLoc(ast); } print(path, print) { diff --git a/src/slangParser.js b/src/slangParser.js index 60782e727..a833577cd 100644 --- a/src/slangParser.js +++ b/src/slangParser.js @@ -8,7 +8,7 @@ import * as parsers from './slang-nodes/index.js'; function genericParseBuilder(options) { return function genericParse(ast, offset = 0) { - return new parsers[ast.cst.kind](ast, offset, options, genericParse); + return new parsers[ast.cst.kind](ast, offset, genericParse, options); }; } From 5629334ecb8ead0dce4b8b564a180fdc1e334cf0 Mon Sep 17 00:00:00 2001 From: Klaus Date: Mon, 15 Jul 2024 09:58:16 +1200 Subject: [PATCH 074/160] remove extra function call --- src/slang-nodes/ABICoderPragma.js | 1 - src/slang-nodes/AdditiveExpression.js | 1 - src/slang-nodes/AddressType.js | 1 - src/slang-nodes/AndExpression.js | 1 - src/slang-nodes/ArgumentsDeclaration.js | 1 - src/slang-nodes/ArrayExpression.js | 1 - src/slang-nodes/ArrayTypeName.js | 1 - src/slang-nodes/ArrayValues.js | 1 - src/slang-nodes/AssemblyFlags.js | 1 - src/slang-nodes/AssemblyFlagsDeclaration.js | 1 - src/slang-nodes/AssemblyStatement.js | 1 - src/slang-nodes/AssignmentExpression.js | 1 - src/slang-nodes/BitwiseAndExpression.js | 1 - src/slang-nodes/BitwiseOrExpression.js | 1 - src/slang-nodes/BitwiseXorExpression.js | 1 - src/slang-nodes/Block.js | 1 - src/slang-nodes/BreakStatement.js | 1 - src/slang-nodes/CallOptions.js | 1 - src/slang-nodes/CallOptionsExpression.js | 1 - src/slang-nodes/CatchClause.js | 1 - src/slang-nodes/CatchClauseError.js | 1 - src/slang-nodes/CatchClauses.js | 1 - src/slang-nodes/ComparisonExpression.js | 1 - src/slang-nodes/ConditionalExpression.js | 1 - src/slang-nodes/ConstantDefinition.js | 1 - src/slang-nodes/ConstructorAttribute.js | 1 - src/slang-nodes/ConstructorAttributes.js | 1 - src/slang-nodes/ConstructorDefinition.js | 1 - src/slang-nodes/ContinueStatement.js | 1 - src/slang-nodes/ContractDefinition.js | 1 - src/slang-nodes/ContractMember.js | 1 - src/slang-nodes/ContractMembers.js | 1 - src/slang-nodes/DecimalNumberExpression.js | 1 - src/slang-nodes/DoWhileStatement.js | 1 - src/slang-nodes/ElementaryType.js | 1 - src/slang-nodes/ElseBranch.js | 1 - src/slang-nodes/EmitStatement.js | 1 - src/slang-nodes/EnumDefinition.js | 1 - src/slang-nodes/EnumMembers.js | 1 - src/slang-nodes/EqualityExpression.js | 1 - src/slang-nodes/ErrorDefinition.js | 1 - src/slang-nodes/ErrorParameter.js | 1 - src/slang-nodes/ErrorParameters.js | 1 - src/slang-nodes/ErrorParametersDeclaration.js | 1 - src/slang-nodes/EventDefinition.js | 1 - src/slang-nodes/EventParameter.js | 1 - src/slang-nodes/EventParameters.js | 1 - src/slang-nodes/EventParametersDeclaration.js | 1 - src/slang-nodes/ExperimentalFeature.js | 1 - src/slang-nodes/ExperimentalPragma.js | 1 - src/slang-nodes/ExponentiationExpression.js | 1 - src/slang-nodes/Expression.js | 1 - src/slang-nodes/ExpressionStatement.js | 1 - src/slang-nodes/FallbackFunctionAttribute.js | 1 - src/slang-nodes/FallbackFunctionAttributes.js | 1 - src/slang-nodes/FallbackFunctionDefinition.js | 1 - src/slang-nodes/ForStatement.js | 1 - src/slang-nodes/ForStatementCondition.js | 1 - src/slang-nodes/ForStatementInitialization.js | 1 - src/slang-nodes/FunctionAttribute.js | 1 - src/slang-nodes/FunctionAttributes.js | 1 - src/slang-nodes/FunctionBody.js | 1 - src/slang-nodes/FunctionCallExpression.js | 1 - src/slang-nodes/FunctionDefinition.js | 1 - src/slang-nodes/FunctionName.js | 1 - src/slang-nodes/FunctionType.js | 1 - src/slang-nodes/FunctionTypeAttribute.js | 1 - src/slang-nodes/FunctionTypeAttributes.js | 1 - src/slang-nodes/HexNumberExpression.js | 1 - src/slang-nodes/HexStringLiteral.js | 1 - src/slang-nodes/HexStringLiterals.js | 1 - src/slang-nodes/IdentifierPath.js | 1 - src/slang-nodes/IfStatement.js | 1 - src/slang-nodes/ImportAlias.js | 1 - src/slang-nodes/ImportClause.js | 1 - src/slang-nodes/ImportDeconstruction.js | 1 - src/slang-nodes/ImportDeconstructionSymbol.js | 1 - .../ImportDeconstructionSymbols.js | 1 - src/slang-nodes/ImportDirective.js | 1 - src/slang-nodes/IndexAccessEnd.js | 1 - src/slang-nodes/IndexAccessExpression.js | 1 - src/slang-nodes/InheritanceSpecifier.js | 1 - src/slang-nodes/InheritanceType.js | 1 - src/slang-nodes/InheritanceTypes.js | 1 - src/slang-nodes/InterfaceDefinition.js | 1 - src/slang-nodes/InterfaceMembers.js | 1 - src/slang-nodes/LibraryDefinition.js | 1 - src/slang-nodes/LibraryMembers.js | 1 - src/slang-nodes/MappingKey.js | 1 - src/slang-nodes/MappingKeyType.js | 1 - src/slang-nodes/MappingType.js | 1 - src/slang-nodes/MappingValue.js | 1 - src/slang-nodes/MemberAccess.js | 1 - src/slang-nodes/MemberAccessExpression.js | 1 - src/slang-nodes/ModifierAttribute.js | 1 - src/slang-nodes/ModifierAttributes.js | 1 - src/slang-nodes/ModifierDefinition.js | 1 - src/slang-nodes/ModifierInvocation.js | 1 - src/slang-nodes/MultiplicativeExpression.js | 1 - src/slang-nodes/NamedArgument.js | 1 - src/slang-nodes/NamedArgumentGroup.js | 1 - src/slang-nodes/NamedArguments.js | 1 - src/slang-nodes/NamedArgumentsDeclaration.js | 1 - src/slang-nodes/NamedImport.js | 1 - src/slang-nodes/NewExpression.js | 1 - src/slang-nodes/NumberUnit.js | 1 - src/slang-nodes/OrExpression.js | 1 - src/slang-nodes/OverridePaths.js | 1 - src/slang-nodes/OverridePathsDeclaration.js | 1 - src/slang-nodes/OverrideSpecifier.js | 1 - src/slang-nodes/Parameter.js | 1 - src/slang-nodes/Parameters.js | 1 - src/slang-nodes/ParametersDeclaration.js | 1 - src/slang-nodes/PathImport.js | 1 - src/slang-nodes/PositionalArguments.js | 1 - .../PositionalArgumentsDeclaration.js | 1 - src/slang-nodes/PostfixExpression.js | 1 - src/slang-nodes/Pragma.js | 1 - src/slang-nodes/PragmaDirective.js | 1 - src/slang-nodes/PrefixExpression.js | 1 - src/slang-nodes/ReceiveFunctionAttribute.js | 1 - src/slang-nodes/ReceiveFunctionAttributes.js | 1 - src/slang-nodes/ReceiveFunctionDefinition.js | 1 - src/slang-nodes/ReturnStatement.js | 1 - src/slang-nodes/ReturnsDeclaration.js | 1 - src/slang-nodes/RevertStatement.js | 1 - src/slang-nodes/ShiftExpression.js | 1 - src/slang-nodes/SlangNode.js | 31 +++++++++---------- src/slang-nodes/SourceUnit.js | 1 - src/slang-nodes/SourceUnitMember.js | 1 - src/slang-nodes/SourceUnitMembers.js | 1 - src/slang-nodes/StateVariableAttribute.js | 1 - src/slang-nodes/StateVariableAttributes.js | 1 - src/slang-nodes/StateVariableDefinition.js | 1 - .../StateVariableDefinitionValue.js | 1 - src/slang-nodes/Statement.js | 1 - src/slang-nodes/Statements.js | 1 - src/slang-nodes/StorageLocation.js | 1 - src/slang-nodes/StringExpression.js | 1 - src/slang-nodes/StringLiteral.js | 1 - src/slang-nodes/StringLiterals.js | 1 - src/slang-nodes/StructDefinition.js | 1 - src/slang-nodes/StructMember.js | 1 - src/slang-nodes/StructMembers.js | 1 - src/slang-nodes/ThrowStatement.js | 1 - src/slang-nodes/TryStatement.js | 1 - src/slang-nodes/TupleDeconstructionElement.js | 1 - .../TupleDeconstructionElements.js | 1 - .../TupleDeconstructionStatement.js | 1 - src/slang-nodes/TupleExpression.js | 1 - src/slang-nodes/TupleMember.js | 1 - src/slang-nodes/TupleValue.js | 1 - src/slang-nodes/TupleValues.js | 1 - src/slang-nodes/TypeExpression.js | 1 - src/slang-nodes/TypeName.js | 1 - src/slang-nodes/TypedTupleMember.js | 1 - src/slang-nodes/UncheckedBlock.js | 1 - src/slang-nodes/UnicodeStringLiteral.js | 1 - src/slang-nodes/UnicodeStringLiterals.js | 1 - src/slang-nodes/UnnamedFunctionAttribute.js | 1 - src/slang-nodes/UnnamedFunctionAttributes.js | 1 - src/slang-nodes/UnnamedFunctionDefinition.js | 1 - src/slang-nodes/UntypedTupleMember.js | 1 - .../UserDefinedValueTypeDefinition.js | 1 - src/slang-nodes/UsingAlias.js | 1 - src/slang-nodes/UsingClause.js | 1 - src/slang-nodes/UsingDeconstruction.js | 1 - src/slang-nodes/UsingDeconstructionSymbol.js | 1 - src/slang-nodes/UsingDeconstructionSymbols.js | 1 - src/slang-nodes/UsingDirective.js | 1 - src/slang-nodes/UsingOperator.js | 1 - src/slang-nodes/UsingTarget.js | 1 - .../VariableDeclarationStatement.js | 1 - src/slang-nodes/VariableDeclarationType.js | 1 - src/slang-nodes/VariableDeclarationValue.js | 1 - src/slang-nodes/VersionComparator.js | 1 - src/slang-nodes/VersionExpression.js | 1 - src/slang-nodes/VersionExpressionSet.js | 1 - src/slang-nodes/VersionExpressionSets.js | 1 - src/slang-nodes/VersionPragma.js | 1 - src/slang-nodes/VersionRange.js | 1 - src/slang-nodes/VersionSpecifiers.js | 1 - src/slang-nodes/WhileStatement.js | 1 - src/slang-nodes/YulArguments.js | 1 - src/slang-nodes/YulAssignmentOperator.js | 1 - src/slang-nodes/YulAssignmentStatement.js | 1 - src/slang-nodes/YulBlock.js | 1 - src/slang-nodes/YulBreakStatement.js | 1 - src/slang-nodes/YulBuiltInFunction.js | 1 - src/slang-nodes/YulColonAndEqual.js | 1 - src/slang-nodes/YulContinueStatement.js | 1 - src/slang-nodes/YulDefaultCase.js | 1 - src/slang-nodes/YulExpression.js | 1 - src/slang-nodes/YulForStatement.js | 1 - src/slang-nodes/YulFunctionCallExpression.js | 1 - src/slang-nodes/YulFunctionDefinition.js | 1 - src/slang-nodes/YulIfStatement.js | 1 - src/slang-nodes/YulLabel.js | 1 - src/slang-nodes/YulLeaveStatement.js | 1 - src/slang-nodes/YulLiteral.js | 1 - src/slang-nodes/YulParameters.js | 1 - src/slang-nodes/YulParametersDeclaration.js | 1 - src/slang-nodes/YulPath.js | 1 - src/slang-nodes/YulPathComponent.js | 1 - src/slang-nodes/YulPaths.js | 1 - src/slang-nodes/YulReturnVariables.js | 1 - src/slang-nodes/YulReturnsDeclaration.js | 1 - src/slang-nodes/YulStatement.js | 1 - src/slang-nodes/YulStatements.js | 1 - src/slang-nodes/YulSwitchCase.js | 1 - src/slang-nodes/YulSwitchCases.js | 1 - src/slang-nodes/YulSwitchStatement.js | 1 - src/slang-nodes/YulValueCase.js | 1 - .../YulVariableAssignmentStatement.js | 1 - .../YulVariableDeclarationStatement.js | 1 - .../YulVariableDeclarationValue.js | 1 - 216 files changed, 14 insertions(+), 232 deletions(-) diff --git a/src/slang-nodes/ABICoderPragma.js b/src/slang-nodes/ABICoderPragma.js index 35439dbe5..ccf9ce765 100644 --- a/src/slang-nodes/ABICoderPragma.js +++ b/src/slang-nodes/ABICoderPragma.js @@ -7,7 +7,6 @@ export class ABICoderPragma extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/AdditiveExpression.js b/src/slang-nodes/AdditiveExpression.js index cc631e264..8b9dbcab3 100644 --- a/src/slang-nodes/AdditiveExpression.js +++ b/src/slang-nodes/AdditiveExpression.js @@ -13,7 +13,6 @@ export class AdditiveExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); diff --git a/src/slang-nodes/AddressType.js b/src/slang-nodes/AddressType.js index 09b952831..744b1fe5a 100644 --- a/src/slang-nodes/AddressType.js +++ b/src/slang-nodes/AddressType.js @@ -7,7 +7,6 @@ export class AddressType extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/AndExpression.js b/src/slang-nodes/AndExpression.js index 9c62740c0..2178d142d 100644 --- a/src/slang-nodes/AndExpression.js +++ b/src/slang-nodes/AndExpression.js @@ -10,7 +10,6 @@ export class AndExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/ArgumentsDeclaration.js b/src/slang-nodes/ArgumentsDeclaration.js index 8e582772d..d8f287ad6 100644 --- a/src/slang-nodes/ArgumentsDeclaration.js +++ b/src/slang-nodes/ArgumentsDeclaration.js @@ -5,7 +5,6 @@ export class ArgumentsDeclaration extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/ArrayExpression.js b/src/slang-nodes/ArrayExpression.js index b8f28ca06..c56fb797e 100644 --- a/src/slang-nodes/ArrayExpression.js +++ b/src/slang-nodes/ArrayExpression.js @@ -12,7 +12,6 @@ export class ArrayExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/ArrayTypeName.js b/src/slang-nodes/ArrayTypeName.js index b3f608df4..39ab612dd 100644 --- a/src/slang-nodes/ArrayTypeName.js +++ b/src/slang-nodes/ArrayTypeName.js @@ -11,7 +11,6 @@ export class ArrayTypeName extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/ArrayValues.js b/src/slang-nodes/ArrayValues.js index 3397ba975..6f56fe944 100644 --- a/src/slang-nodes/ArrayValues.js +++ b/src/slang-nodes/ArrayValues.js @@ -8,7 +8,6 @@ export class ArrayValues extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/AssemblyFlags.js b/src/slang-nodes/AssemblyFlags.js index a5e897026..6eebf9b65 100644 --- a/src/slang-nodes/AssemblyFlags.js +++ b/src/slang-nodes/AssemblyFlags.js @@ -8,7 +8,6 @@ export class AssemblyFlags extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/AssemblyFlagsDeclaration.js b/src/slang-nodes/AssemblyFlagsDeclaration.js index c9d279524..843282388 100644 --- a/src/slang-nodes/AssemblyFlagsDeclaration.js +++ b/src/slang-nodes/AssemblyFlagsDeclaration.js @@ -9,7 +9,6 @@ export class AssemblyFlagsDeclaration extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/AssemblyStatement.js b/src/slang-nodes/AssemblyStatement.js index 2a652ddb2..d4b9c1afb 100644 --- a/src/slang-nodes/AssemblyStatement.js +++ b/src/slang-nodes/AssemblyStatement.js @@ -11,7 +11,6 @@ export class AssemblyStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/AssignmentExpression.js b/src/slang-nodes/AssignmentExpression.js index c19c1607a..888f7d413 100644 --- a/src/slang-nodes/AssignmentExpression.js +++ b/src/slang-nodes/AssignmentExpression.js @@ -13,7 +13,6 @@ export class AssignmentExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/BitwiseAndExpression.js b/src/slang-nodes/BitwiseAndExpression.js index 04d872b2f..3a89f5c2b 100644 --- a/src/slang-nodes/BitwiseAndExpression.js +++ b/src/slang-nodes/BitwiseAndExpression.js @@ -13,7 +13,6 @@ export class BitwiseAndExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); diff --git a/src/slang-nodes/BitwiseOrExpression.js b/src/slang-nodes/BitwiseOrExpression.js index f855028ba..e52878cec 100644 --- a/src/slang-nodes/BitwiseOrExpression.js +++ b/src/slang-nodes/BitwiseOrExpression.js @@ -23,7 +23,6 @@ export class BitwiseOrExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); diff --git a/src/slang-nodes/BitwiseXorExpression.js b/src/slang-nodes/BitwiseXorExpression.js index 933dc06e4..3b94a0a6a 100644 --- a/src/slang-nodes/BitwiseXorExpression.js +++ b/src/slang-nodes/BitwiseXorExpression.js @@ -13,7 +13,6 @@ export class BitwiseXorExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); diff --git a/src/slang-nodes/Block.js b/src/slang-nodes/Block.js index a1a9af108..cf55dda0d 100644 --- a/src/slang-nodes/Block.js +++ b/src/slang-nodes/Block.js @@ -9,7 +9,6 @@ export class Block extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/BreakStatement.js b/src/slang-nodes/BreakStatement.js index 8b12741fe..e5d7b7651 100644 --- a/src/slang-nodes/BreakStatement.js +++ b/src/slang-nodes/BreakStatement.js @@ -7,7 +7,6 @@ export class BreakStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/CallOptions.js b/src/slang-nodes/CallOptions.js index 6ecfb5024..abc5eef79 100644 --- a/src/slang-nodes/CallOptions.js +++ b/src/slang-nodes/CallOptions.js @@ -11,7 +11,6 @@ export class CallOptions extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/CallOptionsExpression.js b/src/slang-nodes/CallOptionsExpression.js index 72f406862..6a77b4463 100644 --- a/src/slang-nodes/CallOptionsExpression.js +++ b/src/slang-nodes/CallOptionsExpression.js @@ -11,7 +11,6 @@ export class CallOptionsExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/CatchClause.js b/src/slang-nodes/CatchClause.js index 878075855..b11494793 100644 --- a/src/slang-nodes/CatchClause.js +++ b/src/slang-nodes/CatchClause.js @@ -9,7 +9,6 @@ export class CatchClause extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/CatchClauseError.js b/src/slang-nodes/CatchClauseError.js index 0940ce5be..1d0ca3339 100644 --- a/src/slang-nodes/CatchClauseError.js +++ b/src/slang-nodes/CatchClauseError.js @@ -10,7 +10,6 @@ export class CatchClauseError extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/CatchClauses.js b/src/slang-nodes/CatchClauses.js index 04225e2fc..42db034d7 100644 --- a/src/slang-nodes/CatchClauses.js +++ b/src/slang-nodes/CatchClauses.js @@ -8,7 +8,6 @@ export class CatchClauses extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/ComparisonExpression.js b/src/slang-nodes/ComparisonExpression.js index ad9ed2235..4e8d95b9b 100644 --- a/src/slang-nodes/ComparisonExpression.js +++ b/src/slang-nodes/ComparisonExpression.js @@ -10,7 +10,6 @@ export class ComparisonExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/ConditionalExpression.js b/src/slang-nodes/ConditionalExpression.js index ab47a7aba..f8dfb5800 100644 --- a/src/slang-nodes/ConditionalExpression.js +++ b/src/slang-nodes/ConditionalExpression.js @@ -96,7 +96,6 @@ export class ConditionalExpression extends SlangNode { constructor(ast, offset, parse, options) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); // TODO: while the behaviour is not stable, it should be behind the diff --git a/src/slang-nodes/ConstantDefinition.js b/src/slang-nodes/ConstantDefinition.js index f8f0edabb..5533bbe69 100644 --- a/src/slang-nodes/ConstantDefinition.js +++ b/src/slang-nodes/ConstantDefinition.js @@ -15,7 +15,6 @@ export class ConstantDefinition extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/ConstructorAttribute.js b/src/slang-nodes/ConstructorAttribute.js index abb91ae1a..f118db072 100644 --- a/src/slang-nodes/ConstructorAttribute.js +++ b/src/slang-nodes/ConstructorAttribute.js @@ -5,7 +5,6 @@ export class ConstructorAttribute extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/ConstructorAttributes.js b/src/slang-nodes/ConstructorAttributes.js index c52994f4e..f1205137d 100644 --- a/src/slang-nodes/ConstructorAttributes.js +++ b/src/slang-nodes/ConstructorAttributes.js @@ -9,7 +9,6 @@ export class ConstructorAttributes extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.items = this.items.sort(sortFunctionAttributes); this.initializeLoc(ast); diff --git a/src/slang-nodes/ConstructorDefinition.js b/src/slang-nodes/ConstructorDefinition.js index 36ddf4dd5..f0aa0ed29 100644 --- a/src/slang-nodes/ConstructorDefinition.js +++ b/src/slang-nodes/ConstructorDefinition.js @@ -12,7 +12,6 @@ export class ConstructorDefinition extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/ContinueStatement.js b/src/slang-nodes/ContinueStatement.js index c2522086e..9074645a8 100644 --- a/src/slang-nodes/ContinueStatement.js +++ b/src/slang-nodes/ContinueStatement.js @@ -7,7 +7,6 @@ export class ContinueStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/ContractDefinition.js b/src/slang-nodes/ContractDefinition.js index 71dfbfe65..07b157ebe 100644 --- a/src/slang-nodes/ContractDefinition.js +++ b/src/slang-nodes/ContractDefinition.js @@ -22,7 +22,6 @@ export class ContractDefinition extends SlangNode { constructor(ast, offset, parse, options) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.cleanModifierInvocationArguments(options); this.initializeLoc(ast); diff --git a/src/slang-nodes/ContractMember.js b/src/slang-nodes/ContractMember.js index df7a3056d..6cffb3cb3 100644 --- a/src/slang-nodes/ContractMember.js +++ b/src/slang-nodes/ContractMember.js @@ -5,7 +5,6 @@ export class ContractMember extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/ContractMembers.js b/src/slang-nodes/ContractMembers.js index 14446d61f..7de63be7b 100644 --- a/src/slang-nodes/ContractMembers.js +++ b/src/slang-nodes/ContractMembers.js @@ -13,7 +13,6 @@ export class ContractMembers extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/DecimalNumberExpression.js b/src/slang-nodes/DecimalNumberExpression.js index 45300fe6d..cdd1c2f42 100644 --- a/src/slang-nodes/DecimalNumberExpression.js +++ b/src/slang-nodes/DecimalNumberExpression.js @@ -7,7 +7,6 @@ export class DecimalNumberExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/DoWhileStatement.js b/src/slang-nodes/DoWhileStatement.js index 010ca3fae..2d2dd5baf 100644 --- a/src/slang-nodes/DoWhileStatement.js +++ b/src/slang-nodes/DoWhileStatement.js @@ -26,7 +26,6 @@ export class DoWhileStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/ElementaryType.js b/src/slang-nodes/ElementaryType.js index 4a9f4540f..3b74918cf 100644 --- a/src/slang-nodes/ElementaryType.js +++ b/src/slang-nodes/ElementaryType.js @@ -5,7 +5,6 @@ export class ElementaryType extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/ElseBranch.js b/src/slang-nodes/ElseBranch.js index 5802c966a..c2944147a 100644 --- a/src/slang-nodes/ElseBranch.js +++ b/src/slang-nodes/ElseBranch.js @@ -15,7 +15,6 @@ export class ElseBranch extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/EmitStatement.js b/src/slang-nodes/EmitStatement.js index 826c44581..381ec0e24 100644 --- a/src/slang-nodes/EmitStatement.js +++ b/src/slang-nodes/EmitStatement.js @@ -11,7 +11,6 @@ export class EmitStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/EnumDefinition.js b/src/slang-nodes/EnumDefinition.js index 021eedb7d..47f911a10 100644 --- a/src/slang-nodes/EnumDefinition.js +++ b/src/slang-nodes/EnumDefinition.js @@ -13,7 +13,6 @@ export class EnumDefinition extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/EnumMembers.js b/src/slang-nodes/EnumMembers.js index 6a768dcf9..bd8a68c57 100644 --- a/src/slang-nodes/EnumMembers.js +++ b/src/slang-nodes/EnumMembers.js @@ -11,7 +11,6 @@ export class EnumMembers extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/EqualityExpression.js b/src/slang-nodes/EqualityExpression.js index 36eda5835..eda4e48de 100644 --- a/src/slang-nodes/EqualityExpression.js +++ b/src/slang-nodes/EqualityExpression.js @@ -10,7 +10,6 @@ export class EqualityExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/ErrorDefinition.js b/src/slang-nodes/ErrorDefinition.js index 099a27eed..cb6614e82 100644 --- a/src/slang-nodes/ErrorDefinition.js +++ b/src/slang-nodes/ErrorDefinition.js @@ -11,7 +11,6 @@ export class ErrorDefinition extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/ErrorParameter.js b/src/slang-nodes/ErrorParameter.js index 730ad0cd1..df7b91553 100644 --- a/src/slang-nodes/ErrorParameter.js +++ b/src/slang-nodes/ErrorParameter.js @@ -7,7 +7,6 @@ export class ErrorParameter extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/ErrorParameters.js b/src/slang-nodes/ErrorParameters.js index 6adf54532..ebfedd4ec 100644 --- a/src/slang-nodes/ErrorParameters.js +++ b/src/slang-nodes/ErrorParameters.js @@ -8,7 +8,6 @@ export class ErrorParameters extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/ErrorParametersDeclaration.js b/src/slang-nodes/ErrorParametersDeclaration.js index 22c990918..337309302 100644 --- a/src/slang-nodes/ErrorParametersDeclaration.js +++ b/src/slang-nodes/ErrorParametersDeclaration.js @@ -9,7 +9,6 @@ export class ErrorParametersDeclaration extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/EventDefinition.js b/src/slang-nodes/EventDefinition.js index 9e403aab1..d95d0db0a 100644 --- a/src/slang-nodes/EventDefinition.js +++ b/src/slang-nodes/EventDefinition.js @@ -13,7 +13,6 @@ export class EventDefinition extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/EventParameter.js b/src/slang-nodes/EventParameter.js index 51ec24534..24db125bb 100644 --- a/src/slang-nodes/EventParameter.js +++ b/src/slang-nodes/EventParameter.js @@ -9,7 +9,6 @@ export class EventParameter extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/EventParameters.js b/src/slang-nodes/EventParameters.js index 97c689c36..027828124 100644 --- a/src/slang-nodes/EventParameters.js +++ b/src/slang-nodes/EventParameters.js @@ -8,7 +8,6 @@ export class EventParameters extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/EventParametersDeclaration.js b/src/slang-nodes/EventParametersDeclaration.js index 2f0d57691..cbdd3c555 100644 --- a/src/slang-nodes/EventParametersDeclaration.js +++ b/src/slang-nodes/EventParametersDeclaration.js @@ -9,7 +9,6 @@ export class EventParametersDeclaration extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/ExperimentalFeature.js b/src/slang-nodes/ExperimentalFeature.js index a52dd44b9..997ce143a 100644 --- a/src/slang-nodes/ExperimentalFeature.js +++ b/src/slang-nodes/ExperimentalFeature.js @@ -5,7 +5,6 @@ export class ExperimentalFeature extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/ExperimentalPragma.js b/src/slang-nodes/ExperimentalPragma.js index f179e5bba..f859a4558 100644 --- a/src/slang-nodes/ExperimentalPragma.js +++ b/src/slang-nodes/ExperimentalPragma.js @@ -7,7 +7,6 @@ export class ExperimentalPragma extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/ExponentiationExpression.js b/src/slang-nodes/ExponentiationExpression.js index ef6f34bee..6b7760638 100644 --- a/src/slang-nodes/ExponentiationExpression.js +++ b/src/slang-nodes/ExponentiationExpression.js @@ -28,7 +28,6 @@ export class ExponentiationExpression extends SlangNode { constructor(ast, offset, parse, options) { super(ast, offset); if (offset) { - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); const compiler = coerce(options.compiler); diff --git a/src/slang-nodes/Expression.js b/src/slang-nodes/Expression.js index 0f22f1715..81f8aebaf 100644 --- a/src/slang-nodes/Expression.js +++ b/src/slang-nodes/Expression.js @@ -6,7 +6,6 @@ export class Expression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); if (offset) { - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } else { diff --git a/src/slang-nodes/ExpressionStatement.js b/src/slang-nodes/ExpressionStatement.js index ae04926d0..53ef51799 100644 --- a/src/slang-nodes/ExpressionStatement.js +++ b/src/slang-nodes/ExpressionStatement.js @@ -7,7 +7,6 @@ export class ExpressionStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/FallbackFunctionAttribute.js b/src/slang-nodes/FallbackFunctionAttribute.js index 1b14b60f6..5c442bef0 100644 --- a/src/slang-nodes/FallbackFunctionAttribute.js +++ b/src/slang-nodes/FallbackFunctionAttribute.js @@ -5,7 +5,6 @@ export class FallbackFunctionAttribute extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/FallbackFunctionAttributes.js b/src/slang-nodes/FallbackFunctionAttributes.js index 470d77f6a..16e5146a2 100644 --- a/src/slang-nodes/FallbackFunctionAttributes.js +++ b/src/slang-nodes/FallbackFunctionAttributes.js @@ -9,7 +9,6 @@ export class FallbackFunctionAttributes extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.items = this.items.sort(sortFunctionAttributes); this.initializeLoc(ast); diff --git a/src/slang-nodes/FallbackFunctionDefinition.js b/src/slang-nodes/FallbackFunctionDefinition.js index 7fd3e49e7..c21eac69f 100644 --- a/src/slang-nodes/FallbackFunctionDefinition.js +++ b/src/slang-nodes/FallbackFunctionDefinition.js @@ -14,7 +14,6 @@ export class FallbackFunctionDefinition extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.cleanModifierInvocationArguments(); this.initializeLoc(ast); diff --git a/src/slang-nodes/ForStatement.js b/src/slang-nodes/ForStatement.js index 2560920f6..6084e082f 100644 --- a/src/slang-nodes/ForStatement.js +++ b/src/slang-nodes/ForStatement.js @@ -21,7 +21,6 @@ export class ForStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/ForStatementCondition.js b/src/slang-nodes/ForStatementCondition.js index 373dc6795..c3edffcfa 100644 --- a/src/slang-nodes/ForStatementCondition.js +++ b/src/slang-nodes/ForStatementCondition.js @@ -5,7 +5,6 @@ export class ForStatementCondition extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/ForStatementInitialization.js b/src/slang-nodes/ForStatementInitialization.js index 06a32696e..1fff1978a 100644 --- a/src/slang-nodes/ForStatementInitialization.js +++ b/src/slang-nodes/ForStatementInitialization.js @@ -5,7 +5,6 @@ export class ForStatementInitialization extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/FunctionAttribute.js b/src/slang-nodes/FunctionAttribute.js index 83a1fb452..a96e7675b 100644 --- a/src/slang-nodes/FunctionAttribute.js +++ b/src/slang-nodes/FunctionAttribute.js @@ -5,7 +5,6 @@ export class FunctionAttribute extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/FunctionAttributes.js b/src/slang-nodes/FunctionAttributes.js index d32ef4b0d..501dba1d1 100644 --- a/src/slang-nodes/FunctionAttributes.js +++ b/src/slang-nodes/FunctionAttributes.js @@ -9,7 +9,6 @@ export class FunctionAttributes extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.items = this.items.sort(sortFunctionAttributes); this.initializeLoc(ast); diff --git a/src/slang-nodes/FunctionBody.js b/src/slang-nodes/FunctionBody.js index 5f34234a5..7376fe491 100644 --- a/src/slang-nodes/FunctionBody.js +++ b/src/slang-nodes/FunctionBody.js @@ -5,7 +5,6 @@ export class FunctionBody extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/FunctionCallExpression.js b/src/slang-nodes/FunctionCallExpression.js index 6e2f60df2..cd021021e 100644 --- a/src/slang-nodes/FunctionCallExpression.js +++ b/src/slang-nodes/FunctionCallExpression.js @@ -11,7 +11,6 @@ export class FunctionCallExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/FunctionDefinition.js b/src/slang-nodes/FunctionDefinition.js index 67dc0ea56..eea7f357a 100644 --- a/src/slang-nodes/FunctionDefinition.js +++ b/src/slang-nodes/FunctionDefinition.js @@ -18,7 +18,6 @@ export class FunctionDefinition extends SlangNode { constructor(ast, offset, parse, options) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); // Older versions of Solidity defined a constructor as a function having diff --git a/src/slang-nodes/FunctionName.js b/src/slang-nodes/FunctionName.js index d08c1bb6c..1d04f40f3 100644 --- a/src/slang-nodes/FunctionName.js +++ b/src/slang-nodes/FunctionName.js @@ -5,7 +5,6 @@ export class FunctionName extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/FunctionType.js b/src/slang-nodes/FunctionType.js index fc1ef3e6c..6e02f733b 100644 --- a/src/slang-nodes/FunctionType.js +++ b/src/slang-nodes/FunctionType.js @@ -12,7 +12,6 @@ export class FunctionType extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/FunctionTypeAttribute.js b/src/slang-nodes/FunctionTypeAttribute.js index e8e71a358..03143386d 100644 --- a/src/slang-nodes/FunctionTypeAttribute.js +++ b/src/slang-nodes/FunctionTypeAttribute.js @@ -5,7 +5,6 @@ export class FunctionTypeAttribute extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/FunctionTypeAttributes.js b/src/slang-nodes/FunctionTypeAttributes.js index d119adec0..8f3df7016 100644 --- a/src/slang-nodes/FunctionTypeAttributes.js +++ b/src/slang-nodes/FunctionTypeAttributes.js @@ -9,7 +9,6 @@ export class FunctionTypeAttributes extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.items = this.items.sort(sortFunctionAttributes); this.initializeLoc(ast); diff --git a/src/slang-nodes/HexNumberExpression.js b/src/slang-nodes/HexNumberExpression.js index 77ad85cd6..cccb0009d 100644 --- a/src/slang-nodes/HexNumberExpression.js +++ b/src/slang-nodes/HexNumberExpression.js @@ -7,7 +7,6 @@ export class HexNumberExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/HexStringLiteral.js b/src/slang-nodes/HexStringLiteral.js index 578b4c0e8..88d2fb132 100644 --- a/src/slang-nodes/HexStringLiteral.js +++ b/src/slang-nodes/HexStringLiteral.js @@ -6,7 +6,6 @@ export class HexStringLiteral extends SlangNode { constructor(ast, offset, parse, options) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.variant = `hex${printString(this.variant.slice(4, -1), options)}`; this.initializeLoc(ast); diff --git a/src/slang-nodes/HexStringLiterals.js b/src/slang-nodes/HexStringLiterals.js index 5cdcab78f..f5f0ade25 100644 --- a/src/slang-nodes/HexStringLiterals.js +++ b/src/slang-nodes/HexStringLiterals.js @@ -8,7 +8,6 @@ export class HexStringLiterals extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/IdentifierPath.js b/src/slang-nodes/IdentifierPath.js index 656928b79..513b62450 100644 --- a/src/slang-nodes/IdentifierPath.js +++ b/src/slang-nodes/IdentifierPath.js @@ -7,7 +7,6 @@ export class IdentifierPath extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/IfStatement.js b/src/slang-nodes/IfStatement.js index cea04ab20..dfe9a9e4c 100644 --- a/src/slang-nodes/IfStatement.js +++ b/src/slang-nodes/IfStatement.js @@ -26,7 +26,6 @@ export class IfStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/ImportAlias.js b/src/slang-nodes/ImportAlias.js index 56df14a52..3e769916c 100644 --- a/src/slang-nodes/ImportAlias.js +++ b/src/slang-nodes/ImportAlias.js @@ -7,7 +7,6 @@ export class ImportAlias extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/ImportClause.js b/src/slang-nodes/ImportClause.js index 13bbc7ea4..2b4873e28 100644 --- a/src/slang-nodes/ImportClause.js +++ b/src/slang-nodes/ImportClause.js @@ -5,7 +5,6 @@ export class ImportClause extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/ImportDeconstruction.js b/src/slang-nodes/ImportDeconstruction.js index 1e7cf4c34..3dab6db76 100644 --- a/src/slang-nodes/ImportDeconstruction.js +++ b/src/slang-nodes/ImportDeconstruction.js @@ -13,7 +13,6 @@ export class ImportDeconstruction extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/ImportDeconstructionSymbol.js b/src/slang-nodes/ImportDeconstructionSymbol.js index c09e62691..e8e57ed6e 100644 --- a/src/slang-nodes/ImportDeconstructionSymbol.js +++ b/src/slang-nodes/ImportDeconstructionSymbol.js @@ -7,7 +7,6 @@ export class ImportDeconstructionSymbol extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/ImportDeconstructionSymbols.js b/src/slang-nodes/ImportDeconstructionSymbols.js index 02bbd19c0..ade8a5380 100644 --- a/src/slang-nodes/ImportDeconstructionSymbols.js +++ b/src/slang-nodes/ImportDeconstructionSymbols.js @@ -13,7 +13,6 @@ export class ImportDeconstructionSymbols extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/ImportDirective.js b/src/slang-nodes/ImportDirective.js index 9bd015ad9..c55abf6f6 100644 --- a/src/slang-nodes/ImportDirective.js +++ b/src/slang-nodes/ImportDirective.js @@ -9,7 +9,6 @@ export class ImportDirective extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/IndexAccessEnd.js b/src/slang-nodes/IndexAccessEnd.js index 0125d5100..1df0f29e5 100644 --- a/src/slang-nodes/IndexAccessEnd.js +++ b/src/slang-nodes/IndexAccessEnd.js @@ -7,7 +7,6 @@ export class IndexAccessEnd extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/IndexAccessExpression.js b/src/slang-nodes/IndexAccessExpression.js index d0fb9a66b..821bcc1ea 100644 --- a/src/slang-nodes/IndexAccessExpression.js +++ b/src/slang-nodes/IndexAccessExpression.js @@ -18,7 +18,6 @@ export class IndexAccessExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); this.closeBracket = ast.closeBracket.text; - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/InheritanceSpecifier.js b/src/slang-nodes/InheritanceSpecifier.js index aabcbe995..d45f45202 100644 --- a/src/slang-nodes/InheritanceSpecifier.js +++ b/src/slang-nodes/InheritanceSpecifier.js @@ -7,7 +7,6 @@ export class InheritanceSpecifier extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/InheritanceType.js b/src/slang-nodes/InheritanceType.js index d21a96893..20f3eaeba 100644 --- a/src/slang-nodes/InheritanceType.js +++ b/src/slang-nodes/InheritanceType.js @@ -7,7 +7,6 @@ export class InheritanceType extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/InheritanceTypes.js b/src/slang-nodes/InheritanceTypes.js index c570e81f9..776ae01cd 100644 --- a/src/slang-nodes/InheritanceTypes.js +++ b/src/slang-nodes/InheritanceTypes.js @@ -11,7 +11,6 @@ export class InheritanceTypes extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/InterfaceDefinition.js b/src/slang-nodes/InterfaceDefinition.js index 4b7dc294b..71aaf3906 100644 --- a/src/slang-nodes/InterfaceDefinition.js +++ b/src/slang-nodes/InterfaceDefinition.js @@ -18,7 +18,6 @@ export class InterfaceDefinition extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/InterfaceMembers.js b/src/slang-nodes/InterfaceMembers.js index 59a63fe5a..8c7e05841 100644 --- a/src/slang-nodes/InterfaceMembers.js +++ b/src/slang-nodes/InterfaceMembers.js @@ -10,7 +10,6 @@ export class InterfaceMembers extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/LibraryDefinition.js b/src/slang-nodes/LibraryDefinition.js index f1f55eb55..aed2092da 100644 --- a/src/slang-nodes/LibraryDefinition.js +++ b/src/slang-nodes/LibraryDefinition.js @@ -16,7 +16,6 @@ export class LibraryDefinition extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/LibraryMembers.js b/src/slang-nodes/LibraryMembers.js index 903364ff7..a6cc9c3c3 100644 --- a/src/slang-nodes/LibraryMembers.js +++ b/src/slang-nodes/LibraryMembers.js @@ -10,7 +10,6 @@ export class LibraryMembers extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/MappingKey.js b/src/slang-nodes/MappingKey.js index ebb849e63..31f99c23d 100644 --- a/src/slang-nodes/MappingKey.js +++ b/src/slang-nodes/MappingKey.js @@ -7,7 +7,6 @@ export class MappingKey extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/MappingKeyType.js b/src/slang-nodes/MappingKeyType.js index 7687969ba..ab34da02f 100644 --- a/src/slang-nodes/MappingKeyType.js +++ b/src/slang-nodes/MappingKeyType.js @@ -5,7 +5,6 @@ export class MappingKeyType extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/MappingType.js b/src/slang-nodes/MappingType.js index 3a64fe3b2..3547e7cd6 100644 --- a/src/slang-nodes/MappingType.js +++ b/src/slang-nodes/MappingType.js @@ -15,7 +15,6 @@ export class MappingType extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/MappingValue.js b/src/slang-nodes/MappingValue.js index 30172c704..ca4f0f139 100644 --- a/src/slang-nodes/MappingValue.js +++ b/src/slang-nodes/MappingValue.js @@ -7,7 +7,6 @@ export class MappingValue extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/MemberAccess.js b/src/slang-nodes/MemberAccess.js index 056891331..c4d88776f 100644 --- a/src/slang-nodes/MemberAccess.js +++ b/src/slang-nodes/MemberAccess.js @@ -5,7 +5,6 @@ export class MemberAccess extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/MemberAccessExpression.js b/src/slang-nodes/MemberAccessExpression.js index 8c4c39605..dad4e93d1 100644 --- a/src/slang-nodes/MemberAccessExpression.js +++ b/src/slang-nodes/MemberAccessExpression.js @@ -114,7 +114,6 @@ export class MemberAccessExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/ModifierAttribute.js b/src/slang-nodes/ModifierAttribute.js index 97e8b44cf..b260805d8 100644 --- a/src/slang-nodes/ModifierAttribute.js +++ b/src/slang-nodes/ModifierAttribute.js @@ -5,7 +5,6 @@ export class ModifierAttribute extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/ModifierAttributes.js b/src/slang-nodes/ModifierAttributes.js index 0566b39fb..94120d859 100644 --- a/src/slang-nodes/ModifierAttributes.js +++ b/src/slang-nodes/ModifierAttributes.js @@ -9,7 +9,6 @@ export class ModifierAttributes extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.items = this.items.sort(sortFunctionAttributes); this.initializeLoc(ast); diff --git a/src/slang-nodes/ModifierDefinition.js b/src/slang-nodes/ModifierDefinition.js index 69b07c138..2501328e7 100644 --- a/src/slang-nodes/ModifierDefinition.js +++ b/src/slang-nodes/ModifierDefinition.js @@ -16,7 +16,6 @@ export class ModifierDefinition extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); if (typeof this.parameters === 'undefined') { const parametersLoc = { diff --git a/src/slang-nodes/ModifierInvocation.js b/src/slang-nodes/ModifierInvocation.js index aec8d7664..40a1346b6 100644 --- a/src/slang-nodes/ModifierInvocation.js +++ b/src/slang-nodes/ModifierInvocation.js @@ -11,7 +11,6 @@ export class ModifierInvocation extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); this.#ast = ast; - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/MultiplicativeExpression.js b/src/slang-nodes/MultiplicativeExpression.js index 3776a3574..59cb9da81 100644 --- a/src/slang-nodes/MultiplicativeExpression.js +++ b/src/slang-nodes/MultiplicativeExpression.js @@ -15,7 +15,6 @@ export class MultiplicativeExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); switch (this.operator) { diff --git a/src/slang-nodes/NamedArgument.js b/src/slang-nodes/NamedArgument.js index 8b0c94eb2..3198c7a73 100644 --- a/src/slang-nodes/NamedArgument.js +++ b/src/slang-nodes/NamedArgument.js @@ -9,7 +9,6 @@ export class NamedArgument extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/NamedArgumentGroup.js b/src/slang-nodes/NamedArgumentGroup.js index 975ea2568..930e9e39a 100644 --- a/src/slang-nodes/NamedArgumentGroup.js +++ b/src/slang-nodes/NamedArgumentGroup.js @@ -9,7 +9,6 @@ export class NamedArgumentGroup extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/NamedArguments.js b/src/slang-nodes/NamedArguments.js index faef85c40..8e687f206 100644 --- a/src/slang-nodes/NamedArguments.js +++ b/src/slang-nodes/NamedArguments.js @@ -11,7 +11,6 @@ export class NamedArguments extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/NamedArgumentsDeclaration.js b/src/slang-nodes/NamedArgumentsDeclaration.js index f0a7b36d7..81fbde148 100644 --- a/src/slang-nodes/NamedArgumentsDeclaration.js +++ b/src/slang-nodes/NamedArgumentsDeclaration.js @@ -9,7 +9,6 @@ export class NamedArgumentsDeclaration extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/NamedImport.js b/src/slang-nodes/NamedImport.js index 952ea1abf..343b0ee8a 100644 --- a/src/slang-nodes/NamedImport.js +++ b/src/slang-nodes/NamedImport.js @@ -11,7 +11,6 @@ export class NamedImport extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/NewExpression.js b/src/slang-nodes/NewExpression.js index 95d4e761f..8482188a0 100644 --- a/src/slang-nodes/NewExpression.js +++ b/src/slang-nodes/NewExpression.js @@ -7,7 +7,6 @@ export class NewExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/NumberUnit.js b/src/slang-nodes/NumberUnit.js index 71483ad29..cd5a51482 100644 --- a/src/slang-nodes/NumberUnit.js +++ b/src/slang-nodes/NumberUnit.js @@ -5,7 +5,6 @@ export class NumberUnit extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/OrExpression.js b/src/slang-nodes/OrExpression.js index 64d03e4fa..97fd3ebf0 100644 --- a/src/slang-nodes/OrExpression.js +++ b/src/slang-nodes/OrExpression.js @@ -13,7 +13,6 @@ export class OrExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); diff --git a/src/slang-nodes/OverridePaths.js b/src/slang-nodes/OverridePaths.js index aec11fcc4..bdf91e734 100644 --- a/src/slang-nodes/OverridePaths.js +++ b/src/slang-nodes/OverridePaths.js @@ -7,7 +7,6 @@ export class OverridePaths extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/OverridePathsDeclaration.js b/src/slang-nodes/OverridePathsDeclaration.js index afe77983f..69ec3813c 100644 --- a/src/slang-nodes/OverridePathsDeclaration.js +++ b/src/slang-nodes/OverridePathsDeclaration.js @@ -9,7 +9,6 @@ export class OverridePathsDeclaration extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/OverrideSpecifier.js b/src/slang-nodes/OverrideSpecifier.js index 133526e2b..c7d552f08 100644 --- a/src/slang-nodes/OverrideSpecifier.js +++ b/src/slang-nodes/OverrideSpecifier.js @@ -7,7 +7,6 @@ export class OverrideSpecifier extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/Parameter.js b/src/slang-nodes/Parameter.js index 82043139c..d2a926752 100644 --- a/src/slang-nodes/Parameter.js +++ b/src/slang-nodes/Parameter.js @@ -12,7 +12,6 @@ export class Parameter extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/Parameters.js b/src/slang-nodes/Parameters.js index fc161fab4..8ffd81faf 100644 --- a/src/slang-nodes/Parameters.js +++ b/src/slang-nodes/Parameters.js @@ -13,7 +13,6 @@ export class Parameters extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); if (offset) { - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } else { diff --git a/src/slang-nodes/ParametersDeclaration.js b/src/slang-nodes/ParametersDeclaration.js index fcf99fc07..7f3eaf372 100644 --- a/src/slang-nodes/ParametersDeclaration.js +++ b/src/slang-nodes/ParametersDeclaration.js @@ -10,7 +10,6 @@ export class ParametersDeclaration extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); if (offset) { - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } else { diff --git a/src/slang-nodes/PathImport.js b/src/slang-nodes/PathImport.js index 8d3279508..35fd7915c 100644 --- a/src/slang-nodes/PathImport.js +++ b/src/slang-nodes/PathImport.js @@ -7,7 +7,6 @@ export class PathImport extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/PositionalArguments.js b/src/slang-nodes/PositionalArguments.js index 9c4316ce3..b0fbd5dcd 100644 --- a/src/slang-nodes/PositionalArguments.js +++ b/src/slang-nodes/PositionalArguments.js @@ -8,7 +8,6 @@ export class PositionalArguments extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/PositionalArgumentsDeclaration.js b/src/slang-nodes/PositionalArgumentsDeclaration.js index cbd73b76a..4a239fa58 100644 --- a/src/slang-nodes/PositionalArgumentsDeclaration.js +++ b/src/slang-nodes/PositionalArgumentsDeclaration.js @@ -9,7 +9,6 @@ export class PositionalArgumentsDeclaration extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/PostfixExpression.js b/src/slang-nodes/PostfixExpression.js index 8bce41214..09823f9de 100644 --- a/src/slang-nodes/PostfixExpression.js +++ b/src/slang-nodes/PostfixExpression.js @@ -7,7 +7,6 @@ export class PostfixExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/Pragma.js b/src/slang-nodes/Pragma.js index d943c8dac..17282cde3 100644 --- a/src/slang-nodes/Pragma.js +++ b/src/slang-nodes/Pragma.js @@ -5,7 +5,6 @@ export class Pragma extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/PragmaDirective.js b/src/slang-nodes/PragmaDirective.js index 63217e50a..6dbed2613 100644 --- a/src/slang-nodes/PragmaDirective.js +++ b/src/slang-nodes/PragmaDirective.js @@ -9,7 +9,6 @@ export class PragmaDirective extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/PrefixExpression.js b/src/slang-nodes/PrefixExpression.js index ce58bc2bf..661207109 100644 --- a/src/slang-nodes/PrefixExpression.js +++ b/src/slang-nodes/PrefixExpression.js @@ -7,7 +7,6 @@ export class PrefixExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/ReceiveFunctionAttribute.js b/src/slang-nodes/ReceiveFunctionAttribute.js index d693d374c..8c838c771 100644 --- a/src/slang-nodes/ReceiveFunctionAttribute.js +++ b/src/slang-nodes/ReceiveFunctionAttribute.js @@ -5,7 +5,6 @@ export class ReceiveFunctionAttribute extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/ReceiveFunctionAttributes.js b/src/slang-nodes/ReceiveFunctionAttributes.js index 66e47ceb9..bf422cd6d 100644 --- a/src/slang-nodes/ReceiveFunctionAttributes.js +++ b/src/slang-nodes/ReceiveFunctionAttributes.js @@ -9,7 +9,6 @@ export class ReceiveFunctionAttributes extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.items = this.items.sort(sortFunctionAttributes); this.initializeLoc(ast); diff --git a/src/slang-nodes/ReceiveFunctionDefinition.js b/src/slang-nodes/ReceiveFunctionDefinition.js index df3355e0b..213f70608 100644 --- a/src/slang-nodes/ReceiveFunctionDefinition.js +++ b/src/slang-nodes/ReceiveFunctionDefinition.js @@ -12,7 +12,6 @@ export class ReceiveFunctionDefinition extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.cleanModifierInvocationArguments(); this.initializeLoc(ast); diff --git a/src/slang-nodes/ReturnStatement.js b/src/slang-nodes/ReturnStatement.js index 9cd4cd66a..39f403358 100644 --- a/src/slang-nodes/ReturnStatement.js +++ b/src/slang-nodes/ReturnStatement.js @@ -23,7 +23,6 @@ export class ReturnStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/ReturnsDeclaration.js b/src/slang-nodes/ReturnsDeclaration.js index 0a9d0f4b4..70d2777da 100644 --- a/src/slang-nodes/ReturnsDeclaration.js +++ b/src/slang-nodes/ReturnsDeclaration.js @@ -10,7 +10,6 @@ export class ReturnsDeclaration extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/RevertStatement.js b/src/slang-nodes/RevertStatement.js index 32bcd8cd3..f3f610429 100644 --- a/src/slang-nodes/RevertStatement.js +++ b/src/slang-nodes/RevertStatement.js @@ -11,7 +11,6 @@ export class RevertStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/ShiftExpression.js b/src/slang-nodes/ShiftExpression.js index bdacdcf2d..d844d4f8a 100644 --- a/src/slang-nodes/ShiftExpression.js +++ b/src/slang-nodes/ShiftExpression.js @@ -22,7 +22,6 @@ export class ShiftExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.leftOperand = tryToHugLeftOperand(this.leftOperand); this.rightOperand = tryToHugRightOperand(this.rightOperand); diff --git a/src/slang-nodes/SlangNode.js b/src/slang-nodes/SlangNode.js index 84e6a1dfe..f15795b72 100644 --- a/src/slang-nodes/SlangNode.js +++ b/src/slang-nodes/SlangNode.js @@ -57,8 +57,6 @@ const getLeadingOffset = (children) => { const getTrailingOffset = (children) => getLeadingOffset(children.reverse()); export class SlangNode { - #childrenKeys; - kind; loc = { @@ -80,26 +78,24 @@ export class SlangNode { this.loc.endWithTrivia = offset + ast.cst.textLength.utf8; } - initializeChildrenKeys() { - this.#childrenKeys = Object.keys(this).slice(3); - } - parseChildrenNodes(ast, parse) { const getValue = (astChild) => astChild.type === 'Terminal' ? astChild.text : parse(astChild, this.nextChildOffset); - this.#childrenKeys.forEach((childNodeName) => { - const astChild = ast[childNodeName]; - if (astChild) { - if (Array.isArray(astChild)) { - this[childNodeName] = astChild.map(getValue); - } else { - this[childNodeName] = getValue(astChild); + Object.keys(this) + .slice(3) + .forEach((childNodeName) => { + const astChild = ast[childNodeName]; + if (astChild) { + if (Array.isArray(astChild)) { + this[childNodeName] = astChild.map(getValue); + } else { + this[childNodeName] = getValue(astChild); + } } - } - }); + }); } /** @@ -127,8 +123,9 @@ export class SlangNode { let trailingOffset = getTrailingOffset(children); if (leadingOffset === 0 || trailingOffset === 0) { - for (let i = 0; i < this.#childrenKeys.length; i += 1) { - const childLoc = this[this.#childrenKeys[i]]?.loc; + const childrenKeys = Object.keys(this).slice(3); + for (let i = 0; i < childrenKeys.length; i += 1) { + const childLoc = this[childrenKeys[i]]?.loc; if (childLoc) { if ( diff --git a/src/slang-nodes/SourceUnit.js b/src/slang-nodes/SourceUnit.js index c239a8edd..3afaca81b 100644 --- a/src/slang-nodes/SourceUnit.js +++ b/src/slang-nodes/SourceUnit.js @@ -8,7 +8,6 @@ export class SourceUnit extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/SourceUnitMember.js b/src/slang-nodes/SourceUnitMember.js index c3dbc8a88..6920ef5b6 100644 --- a/src/slang-nodes/SourceUnitMember.js +++ b/src/slang-nodes/SourceUnitMember.js @@ -5,7 +5,6 @@ export class SourceUnitMember extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/SourceUnitMembers.js b/src/slang-nodes/SourceUnitMembers.js index 2b9a9f748..b34d585ef 100644 --- a/src/slang-nodes/SourceUnitMembers.js +++ b/src/slang-nodes/SourceUnitMembers.js @@ -6,7 +6,6 @@ export class SourceUnitMembers extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/StateVariableAttribute.js b/src/slang-nodes/StateVariableAttribute.js index d5f21275e..9d1150dff 100644 --- a/src/slang-nodes/StateVariableAttribute.js +++ b/src/slang-nodes/StateVariableAttribute.js @@ -5,7 +5,6 @@ export class StateVariableAttribute extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/StateVariableAttributes.js b/src/slang-nodes/StateVariableAttributes.js index 17b7c14a0..cae993605 100644 --- a/src/slang-nodes/StateVariableAttributes.js +++ b/src/slang-nodes/StateVariableAttributes.js @@ -5,7 +5,6 @@ export class StateVariableAttributes extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/StateVariableDefinition.js b/src/slang-nodes/StateVariableDefinition.js index ac71d82d8..aeff98fb2 100644 --- a/src/slang-nodes/StateVariableDefinition.js +++ b/src/slang-nodes/StateVariableDefinition.js @@ -13,7 +13,6 @@ export class StateVariableDefinition extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/StateVariableDefinitionValue.js b/src/slang-nodes/StateVariableDefinitionValue.js index 59e3b7754..e6d7bfa34 100644 --- a/src/slang-nodes/StateVariableDefinitionValue.js +++ b/src/slang-nodes/StateVariableDefinitionValue.js @@ -10,7 +10,6 @@ export class StateVariableDefinitionValue extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/Statement.js b/src/slang-nodes/Statement.js index d98a6be7b..860b4b53b 100644 --- a/src/slang-nodes/Statement.js +++ b/src/slang-nodes/Statement.js @@ -5,7 +5,6 @@ export class Statement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/Statements.js b/src/slang-nodes/Statements.js index 615e6ae7a..0fd1ad73c 100644 --- a/src/slang-nodes/Statements.js +++ b/src/slang-nodes/Statements.js @@ -13,7 +13,6 @@ export class Statements extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/StorageLocation.js b/src/slang-nodes/StorageLocation.js index 55181d541..86b4c4e24 100644 --- a/src/slang-nodes/StorageLocation.js +++ b/src/slang-nodes/StorageLocation.js @@ -5,7 +5,6 @@ export class StorageLocation extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/StringExpression.js b/src/slang-nodes/StringExpression.js index 02c51174a..50f2acf7c 100644 --- a/src/slang-nodes/StringExpression.js +++ b/src/slang-nodes/StringExpression.js @@ -5,7 +5,6 @@ export class StringExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/StringLiteral.js b/src/slang-nodes/StringLiteral.js index a0d677f87..fdc4819b0 100644 --- a/src/slang-nodes/StringLiteral.js +++ b/src/slang-nodes/StringLiteral.js @@ -6,7 +6,6 @@ export class StringLiteral extends SlangNode { constructor(ast, offset, parse, options) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.variant = printString(this.variant.slice(1, -1), options); this.initializeLoc(ast); diff --git a/src/slang-nodes/StringLiterals.js b/src/slang-nodes/StringLiterals.js index cd6106546..91f5ead36 100644 --- a/src/slang-nodes/StringLiterals.js +++ b/src/slang-nodes/StringLiterals.js @@ -8,7 +8,6 @@ export class StringLiterals extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/StructDefinition.js b/src/slang-nodes/StructDefinition.js index fb37cafaf..c88281ace 100644 --- a/src/slang-nodes/StructDefinition.js +++ b/src/slang-nodes/StructDefinition.js @@ -13,7 +13,6 @@ export class StructDefinition extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/StructMember.js b/src/slang-nodes/StructMember.js index 7b2613a50..53a3948cb 100644 --- a/src/slang-nodes/StructMember.js +++ b/src/slang-nodes/StructMember.js @@ -9,7 +9,6 @@ export class StructMember extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/StructMembers.js b/src/slang-nodes/StructMembers.js index 538b92ce6..4debfe9cb 100644 --- a/src/slang-nodes/StructMembers.js +++ b/src/slang-nodes/StructMembers.js @@ -9,7 +9,6 @@ export class StructMembers extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/ThrowStatement.js b/src/slang-nodes/ThrowStatement.js index 8b90d986c..8f5483fe6 100644 --- a/src/slang-nodes/ThrowStatement.js +++ b/src/slang-nodes/ThrowStatement.js @@ -7,7 +7,6 @@ export class ThrowStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/TryStatement.js b/src/slang-nodes/TryStatement.js index cb587cef2..042c93150 100644 --- a/src/slang-nodes/TryStatement.js +++ b/src/slang-nodes/TryStatement.js @@ -17,7 +17,6 @@ export class TryStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/TupleDeconstructionElement.js b/src/slang-nodes/TupleDeconstructionElement.js index 5bbda7e4f..570c6de75 100644 --- a/src/slang-nodes/TupleDeconstructionElement.js +++ b/src/slang-nodes/TupleDeconstructionElement.js @@ -5,7 +5,6 @@ export class TupleDeconstructionElement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/TupleDeconstructionElements.js b/src/slang-nodes/TupleDeconstructionElements.js index dc5b908c3..a4013e315 100644 --- a/src/slang-nodes/TupleDeconstructionElements.js +++ b/src/slang-nodes/TupleDeconstructionElements.js @@ -8,7 +8,6 @@ export class TupleDeconstructionElements extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/TupleDeconstructionStatement.js b/src/slang-nodes/TupleDeconstructionStatement.js index f0730e170..a70af8423 100644 --- a/src/slang-nodes/TupleDeconstructionStatement.js +++ b/src/slang-nodes/TupleDeconstructionStatement.js @@ -20,7 +20,6 @@ export class TupleDeconstructionStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/TupleExpression.js b/src/slang-nodes/TupleExpression.js index 40879c9c8..3c935e747 100644 --- a/src/slang-nodes/TupleExpression.js +++ b/src/slang-nodes/TupleExpression.js @@ -10,7 +10,6 @@ export class TupleExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); if (offset) { - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } else { diff --git a/src/slang-nodes/TupleMember.js b/src/slang-nodes/TupleMember.js index 23ed9d9cc..545c72122 100644 --- a/src/slang-nodes/TupleMember.js +++ b/src/slang-nodes/TupleMember.js @@ -5,7 +5,6 @@ export class TupleMember extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/TupleValue.js b/src/slang-nodes/TupleValue.js index a5f45101d..09434c9be 100644 --- a/src/slang-nodes/TupleValue.js +++ b/src/slang-nodes/TupleValue.js @@ -6,7 +6,6 @@ export class TupleValue extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); if (offset) { - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } else { diff --git a/src/slang-nodes/TupleValues.js b/src/slang-nodes/TupleValues.js index 678ce9090..a9b29a934 100644 --- a/src/slang-nodes/TupleValues.js +++ b/src/slang-nodes/TupleValues.js @@ -10,7 +10,6 @@ export class TupleValues extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); if (offset) { - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } else { diff --git a/src/slang-nodes/TypeExpression.js b/src/slang-nodes/TypeExpression.js index ead8f981e..29aab9776 100644 --- a/src/slang-nodes/TypeExpression.js +++ b/src/slang-nodes/TypeExpression.js @@ -11,7 +11,6 @@ export class TypeExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/TypeName.js b/src/slang-nodes/TypeName.js index b6326b5a9..be3f0a1be 100644 --- a/src/slang-nodes/TypeName.js +++ b/src/slang-nodes/TypeName.js @@ -5,7 +5,6 @@ export class TypeName extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/TypedTupleMember.js b/src/slang-nodes/TypedTupleMember.js index 30f6de0b4..b337d8e02 100644 --- a/src/slang-nodes/TypedTupleMember.js +++ b/src/slang-nodes/TypedTupleMember.js @@ -9,7 +9,6 @@ export class TypedTupleMember extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/UncheckedBlock.js b/src/slang-nodes/UncheckedBlock.js index 1c58c1f3e..323ed5853 100644 --- a/src/slang-nodes/UncheckedBlock.js +++ b/src/slang-nodes/UncheckedBlock.js @@ -7,7 +7,6 @@ export class UncheckedBlock extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/UnicodeStringLiteral.js b/src/slang-nodes/UnicodeStringLiteral.js index abdf2d2a8..041d85ff1 100644 --- a/src/slang-nodes/UnicodeStringLiteral.js +++ b/src/slang-nodes/UnicodeStringLiteral.js @@ -6,7 +6,6 @@ export class UnicodeStringLiteral extends SlangNode { constructor(ast, offset, parse, options) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.variant = `unicode${printString(this.variant.slice(8, -1), options)}`; this.initializeLoc(ast); diff --git a/src/slang-nodes/UnicodeStringLiterals.js b/src/slang-nodes/UnicodeStringLiterals.js index f9079b272..a1b96597b 100644 --- a/src/slang-nodes/UnicodeStringLiterals.js +++ b/src/slang-nodes/UnicodeStringLiterals.js @@ -8,7 +8,6 @@ export class UnicodeStringLiterals extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/UnnamedFunctionAttribute.js b/src/slang-nodes/UnnamedFunctionAttribute.js index 913a72303..7413cde45 100644 --- a/src/slang-nodes/UnnamedFunctionAttribute.js +++ b/src/slang-nodes/UnnamedFunctionAttribute.js @@ -5,7 +5,6 @@ export class UnnamedFunctionAttribute extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/UnnamedFunctionAttributes.js b/src/slang-nodes/UnnamedFunctionAttributes.js index ea153afa2..045bfa7cc 100644 --- a/src/slang-nodes/UnnamedFunctionAttributes.js +++ b/src/slang-nodes/UnnamedFunctionAttributes.js @@ -9,7 +9,6 @@ export class UnnamedFunctionAttributes extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.items = this.items.sort(sortFunctionAttributes); this.initializeLoc(ast); diff --git a/src/slang-nodes/UnnamedFunctionDefinition.js b/src/slang-nodes/UnnamedFunctionDefinition.js index 7250e187e..eaad52fe8 100644 --- a/src/slang-nodes/UnnamedFunctionDefinition.js +++ b/src/slang-nodes/UnnamedFunctionDefinition.js @@ -12,7 +12,6 @@ export class UnnamedFunctionDefinition extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.cleanModifierInvocationArguments(); this.initializeLoc(ast); diff --git a/src/slang-nodes/UntypedTupleMember.js b/src/slang-nodes/UntypedTupleMember.js index 12a2a0bff..5aa86aa0a 100644 --- a/src/slang-nodes/UntypedTupleMember.js +++ b/src/slang-nodes/UntypedTupleMember.js @@ -7,7 +7,6 @@ export class UntypedTupleMember extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/UserDefinedValueTypeDefinition.js b/src/slang-nodes/UserDefinedValueTypeDefinition.js index a8b96b8f2..31761c4df 100644 --- a/src/slang-nodes/UserDefinedValueTypeDefinition.js +++ b/src/slang-nodes/UserDefinedValueTypeDefinition.js @@ -13,7 +13,6 @@ export class UserDefinedValueTypeDefinition extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/UsingAlias.js b/src/slang-nodes/UsingAlias.js index 8848ef56d..2fd42f4b0 100644 --- a/src/slang-nodes/UsingAlias.js +++ b/src/slang-nodes/UsingAlias.js @@ -7,7 +7,6 @@ export class UsingAlias extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/UsingClause.js b/src/slang-nodes/UsingClause.js index aceca101b..4e2ba3ccf 100644 --- a/src/slang-nodes/UsingClause.js +++ b/src/slang-nodes/UsingClause.js @@ -5,7 +5,6 @@ export class UsingClause extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/UsingDeconstruction.js b/src/slang-nodes/UsingDeconstruction.js index de6d6eaa5..8dedc7c94 100644 --- a/src/slang-nodes/UsingDeconstruction.js +++ b/src/slang-nodes/UsingDeconstruction.js @@ -9,7 +9,6 @@ export class UsingDeconstruction extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/UsingDeconstructionSymbol.js b/src/slang-nodes/UsingDeconstructionSymbol.js index 41a41bd6a..d255452e5 100644 --- a/src/slang-nodes/UsingDeconstructionSymbol.js +++ b/src/slang-nodes/UsingDeconstructionSymbol.js @@ -7,7 +7,6 @@ export class UsingDeconstructionSymbol extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/UsingDeconstructionSymbols.js b/src/slang-nodes/UsingDeconstructionSymbols.js index f99f3b7bb..903d66414 100644 --- a/src/slang-nodes/UsingDeconstructionSymbols.js +++ b/src/slang-nodes/UsingDeconstructionSymbols.js @@ -11,7 +11,6 @@ export class UsingDeconstructionSymbols extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/UsingDirective.js b/src/slang-nodes/UsingDirective.js index df4d85caa..69e5d6755 100644 --- a/src/slang-nodes/UsingDirective.js +++ b/src/slang-nodes/UsingDirective.js @@ -15,7 +15,6 @@ export class UsingDirective extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/UsingOperator.js b/src/slang-nodes/UsingOperator.js index 9500dc2cf..dd7c73a32 100644 --- a/src/slang-nodes/UsingOperator.js +++ b/src/slang-nodes/UsingOperator.js @@ -5,7 +5,6 @@ export class UsingOperator extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/UsingTarget.js b/src/slang-nodes/UsingTarget.js index 0d70b4783..87e57ca68 100644 --- a/src/slang-nodes/UsingTarget.js +++ b/src/slang-nodes/UsingTarget.js @@ -5,7 +5,6 @@ export class UsingTarget extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/VariableDeclarationStatement.js b/src/slang-nodes/VariableDeclarationStatement.js index 7b911a4dd..35e41c9e9 100644 --- a/src/slang-nodes/VariableDeclarationStatement.js +++ b/src/slang-nodes/VariableDeclarationStatement.js @@ -16,7 +16,6 @@ export class VariableDeclarationStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/VariableDeclarationType.js b/src/slang-nodes/VariableDeclarationType.js index 81aabc23f..975830355 100644 --- a/src/slang-nodes/VariableDeclarationType.js +++ b/src/slang-nodes/VariableDeclarationType.js @@ -5,7 +5,6 @@ export class VariableDeclarationType extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/VariableDeclarationValue.js b/src/slang-nodes/VariableDeclarationValue.js index 96f7b2097..5a20a3364 100644 --- a/src/slang-nodes/VariableDeclarationValue.js +++ b/src/slang-nodes/VariableDeclarationValue.js @@ -7,7 +7,6 @@ export class VariableDeclarationValue extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/VersionComparator.js b/src/slang-nodes/VersionComparator.js index 9fc464d62..fbc4e9fed 100644 --- a/src/slang-nodes/VersionComparator.js +++ b/src/slang-nodes/VersionComparator.js @@ -7,7 +7,6 @@ export class VersionComparator extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/VersionExpression.js b/src/slang-nodes/VersionExpression.js index f17d87e83..fc1455f2d 100644 --- a/src/slang-nodes/VersionExpression.js +++ b/src/slang-nodes/VersionExpression.js @@ -5,7 +5,6 @@ export class VersionExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/VersionExpressionSet.js b/src/slang-nodes/VersionExpressionSet.js index ba63ad1b9..e33410a63 100644 --- a/src/slang-nodes/VersionExpressionSet.js +++ b/src/slang-nodes/VersionExpressionSet.js @@ -8,7 +8,6 @@ export class VersionExpressionSet extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/VersionExpressionSets.js b/src/slang-nodes/VersionExpressionSets.js index 598588a84..d1be6330b 100644 --- a/src/slang-nodes/VersionExpressionSets.js +++ b/src/slang-nodes/VersionExpressionSets.js @@ -7,7 +7,6 @@ export class VersionExpressionSets extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/VersionPragma.js b/src/slang-nodes/VersionPragma.js index 0595e1bac..c9065cc04 100644 --- a/src/slang-nodes/VersionPragma.js +++ b/src/slang-nodes/VersionPragma.js @@ -7,7 +7,6 @@ export class VersionPragma extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/VersionRange.js b/src/slang-nodes/VersionRange.js index 134471a28..35d5534ae 100644 --- a/src/slang-nodes/VersionRange.js +++ b/src/slang-nodes/VersionRange.js @@ -9,7 +9,6 @@ export class VersionRange extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/VersionSpecifiers.js b/src/slang-nodes/VersionSpecifiers.js index 208ac4355..484684687 100644 --- a/src/slang-nodes/VersionSpecifiers.js +++ b/src/slang-nodes/VersionSpecifiers.js @@ -7,7 +7,6 @@ export class VersionSpecifiers extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/WhileStatement.js b/src/slang-nodes/WhileStatement.js index c5f9a18c6..4243299f2 100644 --- a/src/slang-nodes/WhileStatement.js +++ b/src/slang-nodes/WhileStatement.js @@ -22,7 +22,6 @@ export class WhileStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/YulArguments.js b/src/slang-nodes/YulArguments.js index d2f26e548..12460827d 100644 --- a/src/slang-nodes/YulArguments.js +++ b/src/slang-nodes/YulArguments.js @@ -8,7 +8,6 @@ export class YulArguments extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/YulAssignmentOperator.js b/src/slang-nodes/YulAssignmentOperator.js index 0f64ba3ab..3949af8a0 100644 --- a/src/slang-nodes/YulAssignmentOperator.js +++ b/src/slang-nodes/YulAssignmentOperator.js @@ -5,7 +5,6 @@ export class YulAssignmentOperator extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/YulAssignmentStatement.js b/src/slang-nodes/YulAssignmentStatement.js index c73dd5f44..653f96fa1 100644 --- a/src/slang-nodes/YulAssignmentStatement.js +++ b/src/slang-nodes/YulAssignmentStatement.js @@ -9,7 +9,6 @@ export class YulAssignmentStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/YulBlock.js b/src/slang-nodes/YulBlock.js index 171e2878c..53eb2e0a6 100644 --- a/src/slang-nodes/YulBlock.js +++ b/src/slang-nodes/YulBlock.js @@ -9,7 +9,6 @@ export class YulBlock extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/YulBreakStatement.js b/src/slang-nodes/YulBreakStatement.js index 3ac57fd05..202b8c777 100644 --- a/src/slang-nodes/YulBreakStatement.js +++ b/src/slang-nodes/YulBreakStatement.js @@ -5,7 +5,6 @@ export class YulBreakStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/YulBuiltInFunction.js b/src/slang-nodes/YulBuiltInFunction.js index 7398e3ea0..f8b477f3e 100644 --- a/src/slang-nodes/YulBuiltInFunction.js +++ b/src/slang-nodes/YulBuiltInFunction.js @@ -5,7 +5,6 @@ export class YulBuiltInFunction extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/YulColonAndEqual.js b/src/slang-nodes/YulColonAndEqual.js index 162ab9374..fd5eb4f43 100644 --- a/src/slang-nodes/YulColonAndEqual.js +++ b/src/slang-nodes/YulColonAndEqual.js @@ -7,7 +7,6 @@ export class YulColonAndEqual extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/YulContinueStatement.js b/src/slang-nodes/YulContinueStatement.js index bb8f52e2f..dce33fdda 100644 --- a/src/slang-nodes/YulContinueStatement.js +++ b/src/slang-nodes/YulContinueStatement.js @@ -5,7 +5,6 @@ export class YulContinueStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/YulDefaultCase.js b/src/slang-nodes/YulDefaultCase.js index b5934f15c..7d3c1aef2 100644 --- a/src/slang-nodes/YulDefaultCase.js +++ b/src/slang-nodes/YulDefaultCase.js @@ -7,7 +7,6 @@ export class YulDefaultCase extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/YulExpression.js b/src/slang-nodes/YulExpression.js index d79da0023..0bfd5a53a 100644 --- a/src/slang-nodes/YulExpression.js +++ b/src/slang-nodes/YulExpression.js @@ -5,7 +5,6 @@ export class YulExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/YulForStatement.js b/src/slang-nodes/YulForStatement.js index e290e24f7..96793b418 100644 --- a/src/slang-nodes/YulForStatement.js +++ b/src/slang-nodes/YulForStatement.js @@ -13,7 +13,6 @@ export class YulForStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/YulFunctionCallExpression.js b/src/slang-nodes/YulFunctionCallExpression.js index 921025230..7f0a42afc 100644 --- a/src/slang-nodes/YulFunctionCallExpression.js +++ b/src/slang-nodes/YulFunctionCallExpression.js @@ -11,7 +11,6 @@ export class YulFunctionCallExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/YulFunctionDefinition.js b/src/slang-nodes/YulFunctionDefinition.js index c5e998811..543c4d802 100644 --- a/src/slang-nodes/YulFunctionDefinition.js +++ b/src/slang-nodes/YulFunctionDefinition.js @@ -13,7 +13,6 @@ export class YulFunctionDefinition extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/YulIfStatement.js b/src/slang-nodes/YulIfStatement.js index da2ccb64f..cbe133b41 100644 --- a/src/slang-nodes/YulIfStatement.js +++ b/src/slang-nodes/YulIfStatement.js @@ -9,7 +9,6 @@ export class YulIfStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/YulLabel.js b/src/slang-nodes/YulLabel.js index 27fbe5f3d..865aee911 100644 --- a/src/slang-nodes/YulLabel.js +++ b/src/slang-nodes/YulLabel.js @@ -9,7 +9,6 @@ export class YulLabel extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/YulLeaveStatement.js b/src/slang-nodes/YulLeaveStatement.js index 731fc744e..f6e70309f 100644 --- a/src/slang-nodes/YulLeaveStatement.js +++ b/src/slang-nodes/YulLeaveStatement.js @@ -5,7 +5,6 @@ export class YulLeaveStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/YulLiteral.js b/src/slang-nodes/YulLiteral.js index eb4fe64f1..df17dd57c 100644 --- a/src/slang-nodes/YulLiteral.js +++ b/src/slang-nodes/YulLiteral.js @@ -5,7 +5,6 @@ export class YulLiteral extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/YulParameters.js b/src/slang-nodes/YulParameters.js index f50e849c8..9839f21aa 100644 --- a/src/slang-nodes/YulParameters.js +++ b/src/slang-nodes/YulParameters.js @@ -8,7 +8,6 @@ export class YulParameters extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/YulParametersDeclaration.js b/src/slang-nodes/YulParametersDeclaration.js index c62b47303..030440af4 100644 --- a/src/slang-nodes/YulParametersDeclaration.js +++ b/src/slang-nodes/YulParametersDeclaration.js @@ -9,7 +9,6 @@ export class YulParametersDeclaration extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/YulPath.js b/src/slang-nodes/YulPath.js index 64a09b9da..4429925f7 100644 --- a/src/slang-nodes/YulPath.js +++ b/src/slang-nodes/YulPath.js @@ -7,7 +7,6 @@ export class YulPath extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/YulPathComponent.js b/src/slang-nodes/YulPathComponent.js index 69a570276..62ca3224e 100644 --- a/src/slang-nodes/YulPathComponent.js +++ b/src/slang-nodes/YulPathComponent.js @@ -5,7 +5,6 @@ export class YulPathComponent extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/YulPaths.js b/src/slang-nodes/YulPaths.js index e4a7b5248..785f39c1c 100644 --- a/src/slang-nodes/YulPaths.js +++ b/src/slang-nodes/YulPaths.js @@ -7,7 +7,6 @@ export class YulPaths extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/YulReturnVariables.js b/src/slang-nodes/YulReturnVariables.js index b51709a93..a71dae060 100644 --- a/src/slang-nodes/YulReturnVariables.js +++ b/src/slang-nodes/YulReturnVariables.js @@ -11,7 +11,6 @@ export class YulReturnVariables extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/YulReturnsDeclaration.js b/src/slang-nodes/YulReturnsDeclaration.js index 812ac222a..f18d2bd00 100644 --- a/src/slang-nodes/YulReturnsDeclaration.js +++ b/src/slang-nodes/YulReturnsDeclaration.js @@ -11,7 +11,6 @@ export class YulReturnsDeclaration extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/YulStatement.js b/src/slang-nodes/YulStatement.js index 58ea9c4ed..3219dc107 100644 --- a/src/slang-nodes/YulStatement.js +++ b/src/slang-nodes/YulStatement.js @@ -5,7 +5,6 @@ export class YulStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/YulStatements.js b/src/slang-nodes/YulStatements.js index efa9ab58b..eb40b3829 100644 --- a/src/slang-nodes/YulStatements.js +++ b/src/slang-nodes/YulStatements.js @@ -13,7 +13,6 @@ export class YulStatements extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/YulSwitchCase.js b/src/slang-nodes/YulSwitchCase.js index 8a2b1518f..f56dd8132 100644 --- a/src/slang-nodes/YulSwitchCase.js +++ b/src/slang-nodes/YulSwitchCase.js @@ -5,7 +5,6 @@ export class YulSwitchCase extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/YulSwitchCases.js b/src/slang-nodes/YulSwitchCases.js index f87fb679a..710a2f960 100644 --- a/src/slang-nodes/YulSwitchCases.js +++ b/src/slang-nodes/YulSwitchCases.js @@ -8,7 +8,6 @@ export class YulSwitchCases extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/YulSwitchStatement.js b/src/slang-nodes/YulSwitchStatement.js index 7bf57b17b..3d6433273 100644 --- a/src/slang-nodes/YulSwitchStatement.js +++ b/src/slang-nodes/YulSwitchStatement.js @@ -12,7 +12,6 @@ export class YulSwitchStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/YulValueCase.js b/src/slang-nodes/YulValueCase.js index 46a51b049..19015f9b5 100644 --- a/src/slang-nodes/YulValueCase.js +++ b/src/slang-nodes/YulValueCase.js @@ -9,7 +9,6 @@ export class YulValueCase extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/YulVariableAssignmentStatement.js b/src/slang-nodes/YulVariableAssignmentStatement.js index c389a755d..587559519 100644 --- a/src/slang-nodes/YulVariableAssignmentStatement.js +++ b/src/slang-nodes/YulVariableAssignmentStatement.js @@ -9,7 +9,6 @@ export class YulVariableAssignmentStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/YulVariableDeclarationStatement.js b/src/slang-nodes/YulVariableDeclarationStatement.js index 180a1817b..d00265b81 100644 --- a/src/slang-nodes/YulVariableDeclarationStatement.js +++ b/src/slang-nodes/YulVariableDeclarationStatement.js @@ -9,7 +9,6 @@ export class YulVariableDeclarationStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } diff --git a/src/slang-nodes/YulVariableDeclarationValue.js b/src/slang-nodes/YulVariableDeclarationValue.js index 3b508b9b8..3fad03e0f 100644 --- a/src/slang-nodes/YulVariableDeclarationValue.js +++ b/src/slang-nodes/YulVariableDeclarationValue.js @@ -7,7 +7,6 @@ export class YulVariableDeclarationValue extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.initializeChildrenKeys(); this.parseChildrenNodes(ast, parse); this.initializeLoc(ast); } From 130a48ba78e3946ac05e9c2aaff5048978f48b0e Mon Sep 17 00:00:00 2001 From: Klaus Date: Mon, 15 Jul 2024 10:02:24 +1200 Subject: [PATCH 075/160] mainly using => notation for anonymous functions --- src/common/slang-helpers.js | 42 ++++++++++++----------- src/slang-nodes/ConditionalExpression.js | 9 ++--- src/slang-nodes/DoWhileStatement.js | 9 ++--- src/slang-nodes/ElseBranch.js | 14 ++++---- src/slang-nodes/IfStatement.js | 17 ++++----- src/slang-nodes/MemberAccessExpression.js | 8 ++--- src/slang-nodes/ReturnStatement.js | 4 +-- src/slang-nodes/SlangNode.js | 20 +++++------ src/slang-nodes/WhileStatement.js | 9 ++--- 9 files changed, 63 insertions(+), 69 deletions(-) diff --git a/src/common/slang-helpers.js b/src/common/slang-helpers.js index 07a8da618..8115ce604 100644 --- a/src/common/slang-helpers.js +++ b/src/common/slang-helpers.js @@ -49,25 +49,27 @@ export function printPreservingEmptyLines(path, key, options, print) { }, key); } -export const printFunction = (functionName, node, path, print) => [ - group([ - functionName, - path.call(print, 'parameters'), - indent( - group([ - path.call(print, 'attributes'), - node.returns ? [line, path.call(print, 'returns')] : '', - node.body && node.body.variant !== ';' ? dedent(line) : '' - ]) - ) - ]), - node.body ? path.call(print, 'body') : '' -]; +export function printFunction(functionName, node, path, print) { + return [ + group([ + functionName, + path.call(print, 'parameters'), + indent( + group([ + path.call(print, 'attributes'), + node.returns ? [line, path.call(print, 'returns')] : '', + node.body && node.body.variant !== ';' ? dedent(line) : '' + ]) + ) + ]), + node.body ? path.call(print, 'body') : '' + ]; +} const visibilityKeyWords = ['external', 'internal', 'public', 'private']; const mutabilityKeyWords = ['pure', 'constant', 'payable', 'view']; -export const sortFunctionAttributes = (a, b) => { +export function sortFunctionAttributes(a, b) { const aIsString = typeof a.variant === 'string'; const bIsString = typeof b.variant === 'string'; @@ -97,7 +99,7 @@ export const sortFunctionAttributes = (a, b) => { return 1; } return 0; -}; +} export function hasNodeIgnoreComment(node) { return ( @@ -204,7 +206,7 @@ const logicalIndentRulesBuilder = (path, options) => (document) => { return document; }; -export const rightOperandPrint = (node, path, print) => { +export function rightOperandPrint(node, path, print) { const rightOperand = [line, path.call(print, 'rightOperand')]; // If it's a single binary operation, avoid having a small right @@ -214,7 +216,7 @@ export const rightOperandPrint = (node, path, print) => { !isBinaryOperation(path.getNode(2)); return shouldGroup ? group(rightOperand) : rightOperand; -}; +} export const binaryOperationPrintBuilder = (groupRulesBuilder, indentRulesBuilder) => @@ -247,7 +249,7 @@ export const logicalOperationPrint = binaryOperationPrintBuilder( export const locStart = (node) => node.loc.start; export const locEnd = (node) => node.loc.end; -export const printComments = (node, path, options, filter = () => true) => { +export function printComments(node, path, options, filter = () => true) { if (!node.comments) return []; const document = join( line, @@ -277,4 +279,4 @@ export const printComments = (node, path, options, filter = () => true) => { ? document.parts // Prettier V2 : document; // Prettier V3 /* c8 ignore stop */ -}; +} diff --git a/src/slang-nodes/ConditionalExpression.js b/src/slang-nodes/ConditionalExpression.js index f8dfb5800..df701857e 100644 --- a/src/slang-nodes/ConditionalExpression.js +++ b/src/slang-nodes/ConditionalExpression.js @@ -5,7 +5,7 @@ import { SlangNode } from './SlangNode.js'; const { group, hardline, ifBreak, indent, line, softline } = doc.builders; -const experimentalTernaries = (node, path, print, options) => { +function experimentalTernaries(node, path, print, options) { const grandparent = path.getNode(2); const isNested = grandparent.kind === 'ConditionalExpression'; const isNestedAsTrueExpression = @@ -66,10 +66,10 @@ const experimentalTernaries = (node, path, print, options) => { return grandparent.kind === 'VariableDeclarationValue' ? group(indent([softline, document])) : document; -}; +} -const traditionalTernaries = (node, path, print) => - group([ +function traditionalTernaries(node, path, print) { + return group([ path.call(print, 'operand'), indent([ // Nested trueExpression and falseExpression are always printed in a new @@ -82,6 +82,7 @@ const traditionalTernaries = (node, path, print) => path.call(print, 'falseExpression') ]) ]); +} export class ConditionalExpression extends SlangNode { operand; diff --git a/src/slang-nodes/DoWhileStatement.js b/src/slang-nodes/DoWhileStatement.js index 2d2dd5baf..c486b4558 100644 --- a/src/slang-nodes/DoWhileStatement.js +++ b/src/slang-nodes/DoWhileStatement.js @@ -4,11 +4,6 @@ import { SlangNode } from './SlangNode.js'; const { group, indent, line } = doc.builders; -const printBody = (node, path, print) => - node.body.variant.kind === 'Block' - ? [' ', path.call(print, 'body'), ' '] - : group([indent([line, path.call(print, 'body')]), line]); - export class DoWhileStatement extends SlangNode { doKeyword; @@ -33,7 +28,9 @@ export class DoWhileStatement extends SlangNode { print(path, print) { return [ this.doKeyword, - printBody(this, path, print), + this.body.variant.kind === 'Block' + ? [' ', path.call(print, 'body'), ' '] + : group([indent([line, path.call(print, 'body')]), line]), `${this.whileKeyword} ${this.openParen}`, printSeparatedItem(path.call(print, 'condition')), `${this.closeParen}${this.semicolon}` diff --git a/src/slang-nodes/ElseBranch.js b/src/slang-nodes/ElseBranch.js index c2944147a..d2b3c946b 100644 --- a/src/slang-nodes/ElseBranch.js +++ b/src/slang-nodes/ElseBranch.js @@ -1,13 +1,10 @@ import { doc } from 'prettier'; import { SlangNode } from './SlangNode.js'; +import { createKindCheckFunction } from '../common/slang-helpers.js'; const { group, indent, line } = doc.builders; -const printBody = (bodyVariantKind, path, print) => - bodyVariantKind === 'Block' || bodyVariantKind === 'IfStatement' - ? [' ', path.call(print, 'body')] - : group(indent([line, path.call(print, 'body')])); - +const isIfStatementOrBlock = createKindCheckFunction(['Block', 'IfStatement']); export class ElseBranch extends SlangNode { elseKeyword; @@ -20,6 +17,11 @@ export class ElseBranch extends SlangNode { } print(path, print) { - return [this.elseKeyword, printBody(this.body.variant.kind, path, print)]; + return [ + this.elseKeyword, + isIfStatementOrBlock(this.body.variant) + ? [' ', path.call(print, 'body')] + : group(indent([line, path.call(print, 'body')])) + ]; } } diff --git a/src/slang-nodes/IfStatement.js b/src/slang-nodes/IfStatement.js index dfe9a9e4c..bd132e9e5 100644 --- a/src/slang-nodes/IfStatement.js +++ b/src/slang-nodes/IfStatement.js @@ -4,13 +4,6 @@ import { SlangNode } from './SlangNode.js'; const { group, hardline, indent, line } = doc.builders; -const printBody = (bodyVariantKind, path, print) => - bodyVariantKind === 'Block' - ? [' ', path.call(print, 'body')] - : group(indent([line, path.call(print, 'body')]), { - shouldBreak: bodyVariantKind === 'IfStatement' // `if` within `if` - }); - export class IfStatement extends SlangNode { ifKeyword; @@ -31,16 +24,18 @@ export class IfStatement extends SlangNode { } print(path, print) { - const bodyVariantKind = this.body.variant.kind; - return [ `${this.ifKeyword} ${this.openParen}`, printSeparatedItem(path.call(print, 'condition')), this.closeParen, - printBody(bodyVariantKind, path, print), + this.body.variant.kind === 'Block' + ? [' ', path.call(print, 'body')] + : group(indent([line, path.call(print, 'body')]), { + shouldBreak: this.body.variant.kind === 'IfStatement' // `if` within `if` + }), this.elseBranch ? [ - bodyVariantKind !== 'Block' + this.body.variant.kind !== 'Block' ? hardline // else on a new line if body is not a block : ' ', path.call(print, 'elseBranch') diff --git a/src/slang-nodes/MemberAccessExpression.js b/src/slang-nodes/MemberAccessExpression.js index dad4e93d1..df42b12bc 100644 --- a/src/slang-nodes/MemberAccessExpression.js +++ b/src/slang-nodes/MemberAccessExpression.js @@ -11,7 +11,7 @@ const isChainableExpression = createKindCheckFunction([ 'MemberAccessExpression' ]); -const isEndOfChain = (node, path) => { +function isEndOfChain(node, path) { for ( let i = 0, currentNode = node, grandparentNode = path.getNode(i + 2); isChainableExpression(grandparentNode); @@ -42,7 +42,7 @@ const isEndOfChain = (node, path) => { } } return true; -}; +} /** * processChain expects the doc[] of the full chain of MemberAccess. @@ -90,7 +90,7 @@ const isEndOfChain = (node, path) => { * @returns a processed doc[] with the proper grouping and indentation ready to * be printed. */ -const processChain = (chain) => { +function processChain(chain) { const firstSeparatorIndex = chain.findIndex( (element) => isLabel(element) && element.label === 'separator' ); @@ -103,7 +103,7 @@ const processChain = (chain) => { // The doc[] containing the rest of the chain group(indent(chain.slice(firstSeparatorIndex))) ]); -}; +} export class MemberAccessExpression extends SlangNode { operand; diff --git a/src/slang-nodes/ReturnStatement.js b/src/slang-nodes/ReturnStatement.js index 39f403358..25a13e4df 100644 --- a/src/slang-nodes/ReturnStatement.js +++ b/src/slang-nodes/ReturnStatement.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; const { group, indent, line } = doc.builders; -const expression = (node, path, print, options) => { +function expression(node, path, print, options) { if (node.expression) { return node.expression.variant.kind === 'TupleExpression' || (options.experimentalTernaries && @@ -12,7 +12,7 @@ const expression = (node, path, print, options) => { : group(indent([line, path.call(print, 'expression')])); } return ''; -}; +} export class ReturnStatement extends SlangNode { returnKeyword; diff --git a/src/slang-nodes/SlangNode.js b/src/slang-nodes/SlangNode.js index f15795b72..af32559e9 100644 --- a/src/slang-nodes/SlangNode.js +++ b/src/slang-nodes/SlangNode.js @@ -30,7 +30,7 @@ function getOffsets(children, initialOffset) { return offsets; } -const getLeadingOffset = (children) => { +function getLeadingOffset(children) { let offset = 0; for (let i = 0; i < children.length; i += 1) { const child = children[i]; @@ -52,9 +52,11 @@ const getLeadingOffset = (children) => { offset += child.textLength.utf8; } return offset; -}; +} -const getTrailingOffset = (children) => getLeadingOffset(children.reverse()); +function getTrailingOffset(children) { + return getLeadingOffset(children.reverse()); +} export class SlangNode { kind; @@ -86,14 +88,12 @@ export class SlangNode { Object.keys(this) .slice(3) - .forEach((childNodeName) => { - const astChild = ast[childNodeName]; + .forEach((childKey) => { + const astChild = ast[childKey]; if (astChild) { - if (Array.isArray(astChild)) { - this[childNodeName] = astChild.map(getValue); - } else { - this[childNodeName] = getValue(astChild); - } + this[childKey] = Array.isArray(astChild) + ? astChild.map(getValue) + : getValue(astChild); } }); } diff --git a/src/slang-nodes/WhileStatement.js b/src/slang-nodes/WhileStatement.js index 4243299f2..51ac74287 100644 --- a/src/slang-nodes/WhileStatement.js +++ b/src/slang-nodes/WhileStatement.js @@ -4,11 +4,6 @@ import { SlangNode } from './SlangNode.js'; const { group, indent, line } = doc.builders; -const body = (node, path, print) => - node.body.variant.kind === 'Block' - ? [' ', path.call(print, 'body')] - : group(indent([line, path.call(print, 'body')])); - export class WhileStatement extends SlangNode { whileKeyword; @@ -31,7 +26,9 @@ export class WhileStatement extends SlangNode { `${this.whileKeyword} ${this.openParen}`, printSeparatedItem(path.call(print, 'condition')), this.closeParen, - body(this, path, print) + this.body.variant.kind === 'Block' + ? [' ', path.call(print, 'body')] + : group(indent([line, path.call(print, 'body')])) ]; } } From 746ad88e27ed4229827695d4dd9c988ac4c732ac Mon Sep 17 00:00:00 2001 From: Klaus Date: Mon, 15 Jul 2024 11:28:16 +1200 Subject: [PATCH 076/160] renaming lifecycle functions --- src/index.js | 5 +-- src/slang-nodes/ABICoderPragma.js | 4 +-- src/slang-nodes/AdditiveExpression.js | 4 +-- src/slang-nodes/AddressType.js | 4 +-- src/slang-nodes/AndExpression.js | 4 +-- src/slang-nodes/ArgumentsDeclaration.js | 4 +-- src/slang-nodes/ArrayExpression.js | 4 +-- src/slang-nodes/ArrayTypeName.js | 4 +-- src/slang-nodes/ArrayValues.js | 4 +-- src/slang-nodes/AssemblyFlags.js | 4 +-- src/slang-nodes/AssemblyFlagsDeclaration.js | 4 +-- src/slang-nodes/AssemblyStatement.js | 4 +-- src/slang-nodes/AssignmentExpression.js | 4 +-- src/slang-nodes/BitwiseAndExpression.js | 4 +-- src/slang-nodes/BitwiseOrExpression.js | 4 +-- src/slang-nodes/BitwiseXorExpression.js | 4 +-- src/slang-nodes/Block.js | 4 +-- src/slang-nodes/BreakStatement.js | 4 +-- src/slang-nodes/CallOptions.js | 4 +-- src/slang-nodes/CallOptionsExpression.js | 4 +-- src/slang-nodes/CatchClause.js | 4 +-- src/slang-nodes/CatchClauseError.js | 4 +-- src/slang-nodes/CatchClauses.js | 4 +-- src/slang-nodes/ComparisonExpression.js | 4 +-- src/slang-nodes/ConditionalExpression.js | 4 +-- src/slang-nodes/ConstantDefinition.js | 4 +-- src/slang-nodes/ConstructorAttribute.js | 4 +-- src/slang-nodes/ConstructorAttributes.js | 4 +-- src/slang-nodes/ConstructorDefinition.js | 4 +-- src/slang-nodes/ContinueStatement.js | 4 +-- src/slang-nodes/ContractDefinition.js | 4 +-- src/slang-nodes/ContractMember.js | 4 +-- src/slang-nodes/ContractMembers.js | 4 +-- src/slang-nodes/DecimalNumberExpression.js | 4 +-- src/slang-nodes/DoWhileStatement.js | 4 +-- src/slang-nodes/ElementaryType.js | 4 +-- src/slang-nodes/ElseBranch.js | 4 +-- src/slang-nodes/EmitStatement.js | 4 +-- src/slang-nodes/EnumDefinition.js | 4 +-- src/slang-nodes/EnumMembers.js | 4 +-- src/slang-nodes/EqualityExpression.js | 4 +-- src/slang-nodes/ErrorDefinition.js | 4 +-- src/slang-nodes/ErrorParameter.js | 4 +-- src/slang-nodes/ErrorParameters.js | 4 +-- src/slang-nodes/ErrorParametersDeclaration.js | 4 +-- src/slang-nodes/EventDefinition.js | 4 +-- src/slang-nodes/EventParameter.js | 4 +-- src/slang-nodes/EventParameters.js | 4 +-- src/slang-nodes/EventParametersDeclaration.js | 4 +-- src/slang-nodes/ExperimentalFeature.js | 4 +-- src/slang-nodes/ExperimentalPragma.js | 4 +-- src/slang-nodes/ExponentiationExpression.js | 17 ++++----- src/slang-nodes/Expression.js | 4 +-- src/slang-nodes/ExpressionStatement.js | 4 +-- src/slang-nodes/FallbackFunctionAttribute.js | 4 +-- src/slang-nodes/FallbackFunctionAttributes.js | 4 +-- src/slang-nodes/FallbackFunctionDefinition.js | 4 +-- src/slang-nodes/ForStatement.js | 4 +-- src/slang-nodes/ForStatementCondition.js | 4 +-- src/slang-nodes/ForStatementInitialization.js | 4 +-- src/slang-nodes/FunctionAttribute.js | 4 +-- src/slang-nodes/FunctionAttributes.js | 4 +-- src/slang-nodes/FunctionBody.js | 4 +-- src/slang-nodes/FunctionCallExpression.js | 4 +-- src/slang-nodes/FunctionDefinition.js | 4 +-- src/slang-nodes/FunctionName.js | 4 +-- src/slang-nodes/FunctionType.js | 4 +-- src/slang-nodes/FunctionTypeAttribute.js | 4 +-- src/slang-nodes/FunctionTypeAttributes.js | 4 +-- src/slang-nodes/HexNumberExpression.js | 4 +-- src/slang-nodes/HexStringLiteral.js | 4 +-- src/slang-nodes/HexStringLiterals.js | 4 +-- src/slang-nodes/IdentifierPath.js | 4 +-- src/slang-nodes/IfStatement.js | 4 +-- src/slang-nodes/ImportAlias.js | 4 +-- src/slang-nodes/ImportClause.js | 4 +-- src/slang-nodes/ImportDeconstruction.js | 4 +-- src/slang-nodes/ImportDeconstructionSymbol.js | 4 +-- .../ImportDeconstructionSymbols.js | 4 +-- src/slang-nodes/ImportDirective.js | 4 +-- src/slang-nodes/IndexAccessEnd.js | 4 +-- src/slang-nodes/IndexAccessExpression.js | 4 +-- src/slang-nodes/InheritanceSpecifier.js | 4 +-- src/slang-nodes/InheritanceType.js | 4 +-- src/slang-nodes/InheritanceTypes.js | 4 +-- src/slang-nodes/InterfaceDefinition.js | 4 +-- src/slang-nodes/InterfaceMembers.js | 4 +-- src/slang-nodes/LibraryDefinition.js | 4 +-- src/slang-nodes/LibraryMembers.js | 4 +-- src/slang-nodes/MappingKey.js | 4 +-- src/slang-nodes/MappingKeyType.js | 4 +-- src/slang-nodes/MappingType.js | 4 +-- src/slang-nodes/MappingValue.js | 4 +-- src/slang-nodes/MemberAccess.js | 4 +-- src/slang-nodes/MemberAccessExpression.js | 4 +-- src/slang-nodes/ModifierAttribute.js | 4 +-- src/slang-nodes/ModifierAttributes.js | 4 +-- src/slang-nodes/ModifierDefinition.js | 13 ++++--- src/slang-nodes/ModifierInvocation.js | 4 +-- src/slang-nodes/MultiplicativeExpression.js | 4 +-- src/slang-nodes/NamedArgument.js | 4 +-- src/slang-nodes/NamedArgumentGroup.js | 4 +-- src/slang-nodes/NamedArguments.js | 4 +-- src/slang-nodes/NamedArgumentsDeclaration.js | 4 +-- src/slang-nodes/NamedImport.js | 4 +-- src/slang-nodes/NewExpression.js | 4 +-- src/slang-nodes/NumberUnit.js | 4 +-- src/slang-nodes/OrExpression.js | 4 +-- src/slang-nodes/OverridePaths.js | 4 +-- src/slang-nodes/OverridePathsDeclaration.js | 4 +-- src/slang-nodes/OverrideSpecifier.js | 4 +-- src/slang-nodes/Parameter.js | 4 +-- src/slang-nodes/Parameters.js | 4 +-- src/slang-nodes/ParametersDeclaration.js | 4 +-- src/slang-nodes/PathImport.js | 4 +-- src/slang-nodes/PositionalArguments.js | 4 +-- .../PositionalArgumentsDeclaration.js | 4 +-- src/slang-nodes/PostfixExpression.js | 4 +-- src/slang-nodes/Pragma.js | 4 +-- src/slang-nodes/PragmaDirective.js | 4 +-- src/slang-nodes/PrefixExpression.js | 4 +-- src/slang-nodes/ReceiveFunctionAttribute.js | 4 +-- src/slang-nodes/ReceiveFunctionAttributes.js | 4 +-- src/slang-nodes/ReceiveFunctionDefinition.js | 4 +-- src/slang-nodes/ReturnStatement.js | 4 +-- src/slang-nodes/ReturnsDeclaration.js | 4 +-- src/slang-nodes/RevertStatement.js | 4 +-- src/slang-nodes/ShiftExpression.js | 4 +-- src/slang-nodes/SlangNode.js | 35 ++++++++----------- src/slang-nodes/SourceUnit.js | 4 +-- src/slang-nodes/SourceUnitMember.js | 4 +-- src/slang-nodes/SourceUnitMembers.js | 4 +-- src/slang-nodes/StateVariableAttribute.js | 4 +-- src/slang-nodes/StateVariableAttributes.js | 4 +-- src/slang-nodes/StateVariableDefinition.js | 4 +-- .../StateVariableDefinitionValue.js | 4 +-- src/slang-nodes/Statement.js | 4 +-- src/slang-nodes/Statements.js | 4 +-- src/slang-nodes/StorageLocation.js | 4 +-- src/slang-nodes/StringExpression.js | 4 +-- src/slang-nodes/StringLiteral.js | 4 +-- src/slang-nodes/StringLiterals.js | 4 +-- src/slang-nodes/StructDefinition.js | 4 +-- src/slang-nodes/StructMember.js | 4 +-- src/slang-nodes/StructMembers.js | 4 +-- src/slang-nodes/ThrowStatement.js | 4 +-- src/slang-nodes/TryStatement.js | 4 +-- src/slang-nodes/TupleDeconstructionElement.js | 4 +-- .../TupleDeconstructionElements.js | 4 +-- .../TupleDeconstructionStatement.js | 4 +-- src/slang-nodes/TupleExpression.js | 4 +-- src/slang-nodes/TupleMember.js | 4 +-- src/slang-nodes/TupleValue.js | 4 +-- src/slang-nodes/TupleValues.js | 4 +-- src/slang-nodes/TypeExpression.js | 4 +-- src/slang-nodes/TypeName.js | 4 +-- src/slang-nodes/TypedTupleMember.js | 4 +-- src/slang-nodes/UncheckedBlock.js | 4 +-- src/slang-nodes/UnicodeStringLiteral.js | 4 +-- src/slang-nodes/UnicodeStringLiterals.js | 4 +-- src/slang-nodes/UnnamedFunctionAttribute.js | 4 +-- src/slang-nodes/UnnamedFunctionAttributes.js | 4 +-- src/slang-nodes/UnnamedFunctionDefinition.js | 4 +-- src/slang-nodes/UntypedTupleMember.js | 4 +-- .../UserDefinedValueTypeDefinition.js | 4 +-- src/slang-nodes/UsingAlias.js | 4 +-- src/slang-nodes/UsingClause.js | 4 +-- src/slang-nodes/UsingDeconstruction.js | 4 +-- src/slang-nodes/UsingDeconstructionSymbol.js | 4 +-- src/slang-nodes/UsingDeconstructionSymbols.js | 4 +-- src/slang-nodes/UsingDirective.js | 4 +-- src/slang-nodes/UsingOperator.js | 4 +-- src/slang-nodes/UsingTarget.js | 4 +-- .../VariableDeclarationStatement.js | 4 +-- src/slang-nodes/VariableDeclarationType.js | 4 +-- src/slang-nodes/VariableDeclarationValue.js | 4 +-- src/slang-nodes/VersionComparator.js | 4 +-- src/slang-nodes/VersionExpression.js | 4 +-- src/slang-nodes/VersionExpressionSet.js | 4 +-- src/slang-nodes/VersionExpressionSets.js | 4 +-- src/slang-nodes/VersionPragma.js | 4 +-- src/slang-nodes/VersionRange.js | 4 +-- src/slang-nodes/VersionSpecifiers.js | 4 +-- src/slang-nodes/WhileStatement.js | 4 +-- src/slang-nodes/YulArguments.js | 4 +-- src/slang-nodes/YulAssignmentOperator.js | 4 +-- src/slang-nodes/YulAssignmentStatement.js | 4 +-- src/slang-nodes/YulBlock.js | 4 +-- src/slang-nodes/YulBreakStatement.js | 4 +-- src/slang-nodes/YulBuiltInFunction.js | 4 +-- src/slang-nodes/YulColonAndEqual.js | 4 +-- src/slang-nodes/YulContinueStatement.js | 4 +-- src/slang-nodes/YulDefaultCase.js | 4 +-- src/slang-nodes/YulExpression.js | 4 +-- src/slang-nodes/YulForStatement.js | 4 +-- src/slang-nodes/YulFunctionCallExpression.js | 4 +-- src/slang-nodes/YulFunctionDefinition.js | 4 +-- src/slang-nodes/YulIfStatement.js | 4 +-- src/slang-nodes/YulLabel.js | 4 +-- src/slang-nodes/YulLeaveStatement.js | 4 +-- src/slang-nodes/YulLiteral.js | 4 +-- src/slang-nodes/YulParameters.js | 4 +-- src/slang-nodes/YulParametersDeclaration.js | 4 +-- src/slang-nodes/YulPath.js | 4 +-- src/slang-nodes/YulPathComponent.js | 4 +-- src/slang-nodes/YulPaths.js | 4 +-- src/slang-nodes/YulReturnVariables.js | 4 +-- src/slang-nodes/YulReturnsDeclaration.js | 4 +-- src/slang-nodes/YulStatement.js | 4 +-- src/slang-nodes/YulStatements.js | 4 +-- src/slang-nodes/YulSwitchCase.js | 4 +-- src/slang-nodes/YulSwitchCases.js | 4 +-- src/slang-nodes/YulSwitchStatement.js | 4 +-- src/slang-nodes/YulValueCase.js | 4 +-- .../YulVariableAssignmentStatement.js | 4 +-- .../YulVariableDeclarationStatement.js | 4 +-- .../YulVariableDeclarationValue.js | 4 +-- src/slang-utils/loc.js | 31 ++++++++++++++++ 218 files changed, 489 insertions(+), 464 deletions(-) create mode 100644 src/slang-utils/loc.js diff --git a/src/index.js b/src/index.js index 8f1b0241e..041353b12 100644 --- a/src/index.js +++ b/src/index.js @@ -8,6 +8,7 @@ import print from './printer.js'; import slangParse from './slangParser.js'; import slangPrint from './slangPrinter.js'; import { isComment, isBlockComment } from './common/slang-helpers.js'; +import { locEnd, locStart } from './slang-utils/loc.js'; const parserName = 'slang'; const astFormat = 'slang-ast'; @@ -33,8 +34,8 @@ const parser = { astFormat: 'solidity-ast', parse, ...loc }; const slangParser = { astFormat, parse: slangParse, - locStart: (node) => node.loc.start, - locEnd: (node) => node.loc.end + locStart, + locEnd }; const parsers = { 'solidity-parse': parser, diff --git a/src/slang-nodes/ABICoderPragma.js b/src/slang-nodes/ABICoderPragma.js index ccf9ce765..c08dc54fc 100644 --- a/src/slang-nodes/ABICoderPragma.js +++ b/src/slang-nodes/ABICoderPragma.js @@ -7,8 +7,8 @@ export class ABICoderPragma extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print() { diff --git a/src/slang-nodes/AdditiveExpression.js b/src/slang-nodes/AdditiveExpression.js index 8b9dbcab3..bba14ea8b 100644 --- a/src/slang-nodes/AdditiveExpression.js +++ b/src/slang-nodes/AdditiveExpression.js @@ -13,10 +13,10 @@ export class AdditiveExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); + this.initialize(ast, parse); this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); - this.initializeLoc(ast); + this.finalize(ast); } print(path, print, options) { diff --git a/src/slang-nodes/AddressType.js b/src/slang-nodes/AddressType.js index 744b1fe5a..2fb5a5f04 100644 --- a/src/slang-nodes/AddressType.js +++ b/src/slang-nodes/AddressType.js @@ -7,8 +7,8 @@ export class AddressType extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print() { diff --git a/src/slang-nodes/AndExpression.js b/src/slang-nodes/AndExpression.js index 2178d142d..3c860086e 100644 --- a/src/slang-nodes/AndExpression.js +++ b/src/slang-nodes/AndExpression.js @@ -10,8 +10,8 @@ export class AndExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print, options) { diff --git a/src/slang-nodes/ArgumentsDeclaration.js b/src/slang-nodes/ArgumentsDeclaration.js index d8f287ad6..661693ac4 100644 --- a/src/slang-nodes/ArgumentsDeclaration.js +++ b/src/slang-nodes/ArgumentsDeclaration.js @@ -5,8 +5,8 @@ export class ArgumentsDeclaration extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/ArrayExpression.js b/src/slang-nodes/ArrayExpression.js index c56fb797e..7f8907328 100644 --- a/src/slang-nodes/ArrayExpression.js +++ b/src/slang-nodes/ArrayExpression.js @@ -12,8 +12,8 @@ export class ArrayExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/ArrayTypeName.js b/src/slang-nodes/ArrayTypeName.js index 39ab612dd..d8ee3f88c 100644 --- a/src/slang-nodes/ArrayTypeName.js +++ b/src/slang-nodes/ArrayTypeName.js @@ -11,8 +11,8 @@ export class ArrayTypeName extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/ArrayValues.js b/src/slang-nodes/ArrayValues.js index 6f56fe944..a0f9385cd 100644 --- a/src/slang-nodes/ArrayValues.js +++ b/src/slang-nodes/ArrayValues.js @@ -8,8 +8,8 @@ export class ArrayValues extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/AssemblyFlags.js b/src/slang-nodes/AssemblyFlags.js index 6eebf9b65..6228531f9 100644 --- a/src/slang-nodes/AssemblyFlags.js +++ b/src/slang-nodes/AssemblyFlags.js @@ -8,8 +8,8 @@ export class AssemblyFlags extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/AssemblyFlagsDeclaration.js b/src/slang-nodes/AssemblyFlagsDeclaration.js index 843282388..ae9df8171 100644 --- a/src/slang-nodes/AssemblyFlagsDeclaration.js +++ b/src/slang-nodes/AssemblyFlagsDeclaration.js @@ -9,8 +9,8 @@ export class AssemblyFlagsDeclaration extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/AssemblyStatement.js b/src/slang-nodes/AssemblyStatement.js index d4b9c1afb..5eedabd76 100644 --- a/src/slang-nodes/AssemblyStatement.js +++ b/src/slang-nodes/AssemblyStatement.js @@ -11,8 +11,8 @@ export class AssemblyStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/AssignmentExpression.js b/src/slang-nodes/AssignmentExpression.js index 888f7d413..3a8af59b7 100644 --- a/src/slang-nodes/AssignmentExpression.js +++ b/src/slang-nodes/AssignmentExpression.js @@ -13,8 +13,8 @@ export class AssignmentExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/BitwiseAndExpression.js b/src/slang-nodes/BitwiseAndExpression.js index 3a89f5c2b..4e54703a6 100644 --- a/src/slang-nodes/BitwiseAndExpression.js +++ b/src/slang-nodes/BitwiseAndExpression.js @@ -13,10 +13,10 @@ export class BitwiseAndExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); + this.initialize(ast, parse); this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); - this.initializeLoc(ast); + this.finalize(ast); } print(path, print, options) { diff --git a/src/slang-nodes/BitwiseOrExpression.js b/src/slang-nodes/BitwiseOrExpression.js index e52878cec..0bf5e5b75 100644 --- a/src/slang-nodes/BitwiseOrExpression.js +++ b/src/slang-nodes/BitwiseOrExpression.js @@ -23,10 +23,10 @@ export class BitwiseOrExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); + this.initialize(ast, parse); this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); - this.initializeLoc(ast); + this.finalize(ast); } print(path, print, options) { diff --git a/src/slang-nodes/BitwiseXorExpression.js b/src/slang-nodes/BitwiseXorExpression.js index 3b94a0a6a..c43cc986b 100644 --- a/src/slang-nodes/BitwiseXorExpression.js +++ b/src/slang-nodes/BitwiseXorExpression.js @@ -13,10 +13,10 @@ export class BitwiseXorExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); + this.initialize(ast, parse); this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); - this.initializeLoc(ast); + this.finalize(ast); } print(path, print, options) { diff --git a/src/slang-nodes/Block.js b/src/slang-nodes/Block.js index cf55dda0d..24fda66d3 100644 --- a/src/slang-nodes/Block.js +++ b/src/slang-nodes/Block.js @@ -9,8 +9,8 @@ export class Block extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/BreakStatement.js b/src/slang-nodes/BreakStatement.js index e5d7b7651..1dae8df81 100644 --- a/src/slang-nodes/BreakStatement.js +++ b/src/slang-nodes/BreakStatement.js @@ -7,8 +7,8 @@ export class BreakStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print() { diff --git a/src/slang-nodes/CallOptions.js b/src/slang-nodes/CallOptions.js index abc5eef79..3037a19a9 100644 --- a/src/slang-nodes/CallOptions.js +++ b/src/slang-nodes/CallOptions.js @@ -11,8 +11,8 @@ export class CallOptions extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print, options) { diff --git a/src/slang-nodes/CallOptionsExpression.js b/src/slang-nodes/CallOptionsExpression.js index 6a77b4463..de3f7dcb9 100644 --- a/src/slang-nodes/CallOptionsExpression.js +++ b/src/slang-nodes/CallOptionsExpression.js @@ -11,8 +11,8 @@ export class CallOptionsExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/CatchClause.js b/src/slang-nodes/CatchClause.js index b11494793..e64c73294 100644 --- a/src/slang-nodes/CatchClause.js +++ b/src/slang-nodes/CatchClause.js @@ -9,8 +9,8 @@ export class CatchClause extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/CatchClauseError.js b/src/slang-nodes/CatchClauseError.js index 1d0ca3339..699e81cbc 100644 --- a/src/slang-nodes/CatchClauseError.js +++ b/src/slang-nodes/CatchClauseError.js @@ -10,8 +10,8 @@ export class CatchClauseError extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/CatchClauses.js b/src/slang-nodes/CatchClauses.js index 42db034d7..8ee7a5e92 100644 --- a/src/slang-nodes/CatchClauses.js +++ b/src/slang-nodes/CatchClauses.js @@ -8,8 +8,8 @@ export class CatchClauses extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/ComparisonExpression.js b/src/slang-nodes/ComparisonExpression.js index 4e8d95b9b..b32b3cf87 100644 --- a/src/slang-nodes/ComparisonExpression.js +++ b/src/slang-nodes/ComparisonExpression.js @@ -10,8 +10,8 @@ export class ComparisonExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print, options) { diff --git a/src/slang-nodes/ConditionalExpression.js b/src/slang-nodes/ConditionalExpression.js index df701857e..afbcb1806 100644 --- a/src/slang-nodes/ConditionalExpression.js +++ b/src/slang-nodes/ConditionalExpression.js @@ -97,7 +97,7 @@ export class ConditionalExpression extends SlangNode { constructor(ast, offset, parse, options) { super(ast, offset); - this.parseChildrenNodes(ast, parse); + this.initialize(ast, parse); // TODO: while the behaviour is not stable, it should be behind the // experimentalTernaries flag. @@ -117,7 +117,7 @@ export class ConditionalExpression extends SlangNode { this.operand.loc = operandLoc; } - this.initializeLoc(ast); + this.finalize(ast); } print(path, print, options) { diff --git a/src/slang-nodes/ConstantDefinition.js b/src/slang-nodes/ConstantDefinition.js index 5533bbe69..41760f673 100644 --- a/src/slang-nodes/ConstantDefinition.js +++ b/src/slang-nodes/ConstantDefinition.js @@ -15,8 +15,8 @@ export class ConstantDefinition extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } // TODO: implement print diff --git a/src/slang-nodes/ConstructorAttribute.js b/src/slang-nodes/ConstructorAttribute.js index f118db072..0810d751a 100644 --- a/src/slang-nodes/ConstructorAttribute.js +++ b/src/slang-nodes/ConstructorAttribute.js @@ -5,8 +5,8 @@ export class ConstructorAttribute extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/ConstructorAttributes.js b/src/slang-nodes/ConstructorAttributes.js index f1205137d..342fc4ef0 100644 --- a/src/slang-nodes/ConstructorAttributes.js +++ b/src/slang-nodes/ConstructorAttributes.js @@ -9,9 +9,9 @@ export class ConstructorAttributes extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); + this.initialize(ast, parse); this.items = this.items.sort(sortFunctionAttributes); - this.initializeLoc(ast); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/ConstructorDefinition.js b/src/slang-nodes/ConstructorDefinition.js index f0aa0ed29..30433a334 100644 --- a/src/slang-nodes/ConstructorDefinition.js +++ b/src/slang-nodes/ConstructorDefinition.js @@ -12,8 +12,8 @@ export class ConstructorDefinition extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/ContinueStatement.js b/src/slang-nodes/ContinueStatement.js index 9074645a8..acf721503 100644 --- a/src/slang-nodes/ContinueStatement.js +++ b/src/slang-nodes/ContinueStatement.js @@ -7,8 +7,8 @@ export class ContinueStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print() { diff --git a/src/slang-nodes/ContractDefinition.js b/src/slang-nodes/ContractDefinition.js index 07b157ebe..dc3263b50 100644 --- a/src/slang-nodes/ContractDefinition.js +++ b/src/slang-nodes/ContractDefinition.js @@ -22,9 +22,9 @@ export class ContractDefinition extends SlangNode { constructor(ast, offset, parse, options) { super(ast, offset); - this.parseChildrenNodes(ast, parse); + this.initialize(ast, parse); this.cleanModifierInvocationArguments(options); - this.initializeLoc(ast); + this.finalize(ast); } cleanModifierInvocationArguments(options) { diff --git a/src/slang-nodes/ContractMember.js b/src/slang-nodes/ContractMember.js index 6cffb3cb3..ef8bcc3a2 100644 --- a/src/slang-nodes/ContractMember.js +++ b/src/slang-nodes/ContractMember.js @@ -5,8 +5,8 @@ export class ContractMember extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/ContractMembers.js b/src/slang-nodes/ContractMembers.js index 7de63be7b..21fd75340 100644 --- a/src/slang-nodes/ContractMembers.js +++ b/src/slang-nodes/ContractMembers.js @@ -13,8 +13,8 @@ export class ContractMembers extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print, options) { diff --git a/src/slang-nodes/DecimalNumberExpression.js b/src/slang-nodes/DecimalNumberExpression.js index cdd1c2f42..1c8b786f6 100644 --- a/src/slang-nodes/DecimalNumberExpression.js +++ b/src/slang-nodes/DecimalNumberExpression.js @@ -7,8 +7,8 @@ export class DecimalNumberExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/DoWhileStatement.js b/src/slang-nodes/DoWhileStatement.js index c486b4558..17759774e 100644 --- a/src/slang-nodes/DoWhileStatement.js +++ b/src/slang-nodes/DoWhileStatement.js @@ -21,8 +21,8 @@ export class DoWhileStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/ElementaryType.js b/src/slang-nodes/ElementaryType.js index 3b74918cf..9d55b96b6 100644 --- a/src/slang-nodes/ElementaryType.js +++ b/src/slang-nodes/ElementaryType.js @@ -5,8 +5,8 @@ export class ElementaryType extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/ElseBranch.js b/src/slang-nodes/ElseBranch.js index d2b3c946b..ecc8ed2ed 100644 --- a/src/slang-nodes/ElseBranch.js +++ b/src/slang-nodes/ElseBranch.js @@ -12,8 +12,8 @@ export class ElseBranch extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/EmitStatement.js b/src/slang-nodes/EmitStatement.js index 381ec0e24..cd6978775 100644 --- a/src/slang-nodes/EmitStatement.js +++ b/src/slang-nodes/EmitStatement.js @@ -11,8 +11,8 @@ export class EmitStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/EnumDefinition.js b/src/slang-nodes/EnumDefinition.js index 47f911a10..f2de83ef8 100644 --- a/src/slang-nodes/EnumDefinition.js +++ b/src/slang-nodes/EnumDefinition.js @@ -13,8 +13,8 @@ export class EnumDefinition extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/EnumMembers.js b/src/slang-nodes/EnumMembers.js index bd8a68c57..127b1744a 100644 --- a/src/slang-nodes/EnumMembers.js +++ b/src/slang-nodes/EnumMembers.js @@ -11,8 +11,8 @@ export class EnumMembers extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print() { diff --git a/src/slang-nodes/EqualityExpression.js b/src/slang-nodes/EqualityExpression.js index eda4e48de..d94afacb7 100644 --- a/src/slang-nodes/EqualityExpression.js +++ b/src/slang-nodes/EqualityExpression.js @@ -10,8 +10,8 @@ export class EqualityExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print, options) { diff --git a/src/slang-nodes/ErrorDefinition.js b/src/slang-nodes/ErrorDefinition.js index cb6614e82..31d9cd0b0 100644 --- a/src/slang-nodes/ErrorDefinition.js +++ b/src/slang-nodes/ErrorDefinition.js @@ -11,8 +11,8 @@ export class ErrorDefinition extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/ErrorParameter.js b/src/slang-nodes/ErrorParameter.js index df7b91553..37d68daa7 100644 --- a/src/slang-nodes/ErrorParameter.js +++ b/src/slang-nodes/ErrorParameter.js @@ -7,8 +7,8 @@ export class ErrorParameter extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/ErrorParameters.js b/src/slang-nodes/ErrorParameters.js index ebfedd4ec..dfa2c61b7 100644 --- a/src/slang-nodes/ErrorParameters.js +++ b/src/slang-nodes/ErrorParameters.js @@ -8,8 +8,8 @@ export class ErrorParameters extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/ErrorParametersDeclaration.js b/src/slang-nodes/ErrorParametersDeclaration.js index 337309302..3d30b0412 100644 --- a/src/slang-nodes/ErrorParametersDeclaration.js +++ b/src/slang-nodes/ErrorParametersDeclaration.js @@ -9,8 +9,8 @@ export class ErrorParametersDeclaration extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/EventDefinition.js b/src/slang-nodes/EventDefinition.js index d95d0db0a..03284f44d 100644 --- a/src/slang-nodes/EventDefinition.js +++ b/src/slang-nodes/EventDefinition.js @@ -13,8 +13,8 @@ export class EventDefinition extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/EventParameter.js b/src/slang-nodes/EventParameter.js index 24db125bb..096403c69 100644 --- a/src/slang-nodes/EventParameter.js +++ b/src/slang-nodes/EventParameter.js @@ -9,8 +9,8 @@ export class EventParameter extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/EventParameters.js b/src/slang-nodes/EventParameters.js index 027828124..01cf84e87 100644 --- a/src/slang-nodes/EventParameters.js +++ b/src/slang-nodes/EventParameters.js @@ -8,8 +8,8 @@ export class EventParameters extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/EventParametersDeclaration.js b/src/slang-nodes/EventParametersDeclaration.js index cbdd3c555..d5390cb63 100644 --- a/src/slang-nodes/EventParametersDeclaration.js +++ b/src/slang-nodes/EventParametersDeclaration.js @@ -9,8 +9,8 @@ export class EventParametersDeclaration extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/ExperimentalFeature.js b/src/slang-nodes/ExperimentalFeature.js index 997ce143a..dbe37b1d6 100644 --- a/src/slang-nodes/ExperimentalFeature.js +++ b/src/slang-nodes/ExperimentalFeature.js @@ -5,8 +5,8 @@ export class ExperimentalFeature extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/ExperimentalPragma.js b/src/slang-nodes/ExperimentalPragma.js index f859a4558..d584d65e2 100644 --- a/src/slang-nodes/ExperimentalPragma.js +++ b/src/slang-nodes/ExperimentalPragma.js @@ -7,8 +7,8 @@ export class ExperimentalPragma extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/ExponentiationExpression.js b/src/slang-nodes/ExponentiationExpression.js index 6b7760638..3c5df9edd 100644 --- a/src/slang-nodes/ExponentiationExpression.js +++ b/src/slang-nodes/ExponentiationExpression.js @@ -3,6 +3,7 @@ import coerce from 'semver/functions/coerce.js'; import satisfies from 'semver/functions/satisfies.js'; import { binaryOperationPrintBuilder } from '../common/slang-helpers.js'; import { createHugFunction } from '../slang-utils/create-hug-function.js'; +import { Loc } from '../slang-utils/loc.js'; import { SlangNode } from './SlangNode.js'; import { Expression } from './Expression.js'; import { TupleExpression } from './TupleExpression.js'; @@ -28,7 +29,7 @@ export class ExponentiationExpression extends SlangNode { constructor(ast, offset, parse, options) { super(ast, offset); if (offset) { - this.parseChildrenNodes(ast, parse); + this.initialize(ast, parse); const compiler = coerce(options.compiler); if (compiler) { @@ -50,24 +51,24 @@ export class ExponentiationExpression extends SlangNode { }; this.leftOperand = new Expression({ kind: 'Expression', - loc: { ...leftLoc }, + loc: new Loc(leftLoc), variant: new TupleExpression({ kind: 'TupleExpression', - loc: { ...leftLoc }, + loc: new Loc(leftLoc), openParen: '(', items: new TupleValues({ kind: 'TupleValues', - loc: { ...leftLoc }, + loc: new Loc(leftLoc), items: [ new TupleValue({ kind: 'TupleValue', - loc: { ...leftLoc }, + loc: new Loc(leftLoc), expression: new Expression({ kind: 'Expression', - loc: { ...leftLoc }, + loc: new Loc(leftLoc), variant: new ExponentiationExpression({ kind: 'ExponentiationExpression', - loc: { ...leftLoc }, + loc: new Loc(leftLoc), leftOperand: this.leftOperand, operator: '**', rightOperand: this.rightOperand.variant.leftOperand @@ -86,7 +87,7 @@ export class ExponentiationExpression extends SlangNode { } } - this.initializeLoc(ast); + this.finalize(ast); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/Expression.js b/src/slang-nodes/Expression.js index 81f8aebaf..89b8b273d 100644 --- a/src/slang-nodes/Expression.js +++ b/src/slang-nodes/Expression.js @@ -6,8 +6,8 @@ export class Expression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); if (offset) { - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/ExpressionStatement.js b/src/slang-nodes/ExpressionStatement.js index 53ef51799..5915a5b7c 100644 --- a/src/slang-nodes/ExpressionStatement.js +++ b/src/slang-nodes/ExpressionStatement.js @@ -7,8 +7,8 @@ export class ExpressionStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/FallbackFunctionAttribute.js b/src/slang-nodes/FallbackFunctionAttribute.js index 5c442bef0..9f46e51d7 100644 --- a/src/slang-nodes/FallbackFunctionAttribute.js +++ b/src/slang-nodes/FallbackFunctionAttribute.js @@ -5,8 +5,8 @@ export class FallbackFunctionAttribute extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/FallbackFunctionAttributes.js b/src/slang-nodes/FallbackFunctionAttributes.js index 16e5146a2..dfde6ee9e 100644 --- a/src/slang-nodes/FallbackFunctionAttributes.js +++ b/src/slang-nodes/FallbackFunctionAttributes.js @@ -9,9 +9,9 @@ export class FallbackFunctionAttributes extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); + this.initialize(ast, parse); this.items = this.items.sort(sortFunctionAttributes); - this.initializeLoc(ast); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/FallbackFunctionDefinition.js b/src/slang-nodes/FallbackFunctionDefinition.js index c21eac69f..7cd43f4f0 100644 --- a/src/slang-nodes/FallbackFunctionDefinition.js +++ b/src/slang-nodes/FallbackFunctionDefinition.js @@ -14,9 +14,9 @@ export class FallbackFunctionDefinition extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); + this.initialize(ast, parse); this.cleanModifierInvocationArguments(); - this.initializeLoc(ast); + this.finalize(ast); } cleanModifierInvocationArguments() { diff --git a/src/slang-nodes/ForStatement.js b/src/slang-nodes/ForStatement.js index 6084e082f..81022e07c 100644 --- a/src/slang-nodes/ForStatement.js +++ b/src/slang-nodes/ForStatement.js @@ -21,8 +21,8 @@ export class ForStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/ForStatementCondition.js b/src/slang-nodes/ForStatementCondition.js index c3edffcfa..f35ddcf77 100644 --- a/src/slang-nodes/ForStatementCondition.js +++ b/src/slang-nodes/ForStatementCondition.js @@ -5,8 +5,8 @@ export class ForStatementCondition extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/ForStatementInitialization.js b/src/slang-nodes/ForStatementInitialization.js index 1fff1978a..02881ee66 100644 --- a/src/slang-nodes/ForStatementInitialization.js +++ b/src/slang-nodes/ForStatementInitialization.js @@ -5,8 +5,8 @@ export class ForStatementInitialization extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/FunctionAttribute.js b/src/slang-nodes/FunctionAttribute.js index a96e7675b..04b90b403 100644 --- a/src/slang-nodes/FunctionAttribute.js +++ b/src/slang-nodes/FunctionAttribute.js @@ -5,8 +5,8 @@ export class FunctionAttribute extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/FunctionAttributes.js b/src/slang-nodes/FunctionAttributes.js index 501dba1d1..311889573 100644 --- a/src/slang-nodes/FunctionAttributes.js +++ b/src/slang-nodes/FunctionAttributes.js @@ -9,9 +9,9 @@ export class FunctionAttributes extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); + this.initialize(ast, parse); this.items = this.items.sort(sortFunctionAttributes); - this.initializeLoc(ast); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/FunctionBody.js b/src/slang-nodes/FunctionBody.js index 7376fe491..15171f8ba 100644 --- a/src/slang-nodes/FunctionBody.js +++ b/src/slang-nodes/FunctionBody.js @@ -5,8 +5,8 @@ export class FunctionBody extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/FunctionCallExpression.js b/src/slang-nodes/FunctionCallExpression.js index cd021021e..b7c410e6d 100644 --- a/src/slang-nodes/FunctionCallExpression.js +++ b/src/slang-nodes/FunctionCallExpression.js @@ -11,8 +11,8 @@ export class FunctionCallExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/FunctionDefinition.js b/src/slang-nodes/FunctionDefinition.js index eea7f357a..348b1c7b6 100644 --- a/src/slang-nodes/FunctionDefinition.js +++ b/src/slang-nodes/FunctionDefinition.js @@ -18,7 +18,7 @@ export class FunctionDefinition extends SlangNode { constructor(ast, offset, parse, options) { super(ast, offset); - this.parseChildrenNodes(ast, parse); + this.initialize(ast, parse); // Older versions of Solidity defined a constructor as a function having // the same name as the contract. @@ -27,7 +27,7 @@ export class FunctionDefinition extends SlangNode { this.cleanModifierInvocationArguments(); } - this.initializeLoc(ast); + this.finalize(ast); } cleanModifierInvocationArguments() { diff --git a/src/slang-nodes/FunctionName.js b/src/slang-nodes/FunctionName.js index 1d04f40f3..e64ff8d28 100644 --- a/src/slang-nodes/FunctionName.js +++ b/src/slang-nodes/FunctionName.js @@ -5,8 +5,8 @@ export class FunctionName extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print() { diff --git a/src/slang-nodes/FunctionType.js b/src/slang-nodes/FunctionType.js index 6e02f733b..e1cf753db 100644 --- a/src/slang-nodes/FunctionType.js +++ b/src/slang-nodes/FunctionType.js @@ -12,8 +12,8 @@ export class FunctionType extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/FunctionTypeAttribute.js b/src/slang-nodes/FunctionTypeAttribute.js index 03143386d..a879d8576 100644 --- a/src/slang-nodes/FunctionTypeAttribute.js +++ b/src/slang-nodes/FunctionTypeAttribute.js @@ -5,8 +5,8 @@ export class FunctionTypeAttribute extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print() { diff --git a/src/slang-nodes/FunctionTypeAttributes.js b/src/slang-nodes/FunctionTypeAttributes.js index 8f3df7016..899fa962d 100644 --- a/src/slang-nodes/FunctionTypeAttributes.js +++ b/src/slang-nodes/FunctionTypeAttributes.js @@ -9,9 +9,9 @@ export class FunctionTypeAttributes extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); + this.initialize(ast, parse); this.items = this.items.sort(sortFunctionAttributes); - this.initializeLoc(ast); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/HexNumberExpression.js b/src/slang-nodes/HexNumberExpression.js index cccb0009d..46eef7078 100644 --- a/src/slang-nodes/HexNumberExpression.js +++ b/src/slang-nodes/HexNumberExpression.js @@ -7,8 +7,8 @@ export class HexNumberExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/HexStringLiteral.js b/src/slang-nodes/HexStringLiteral.js index 88d2fb132..493248e03 100644 --- a/src/slang-nodes/HexStringLiteral.js +++ b/src/slang-nodes/HexStringLiteral.js @@ -6,9 +6,9 @@ export class HexStringLiteral extends SlangNode { constructor(ast, offset, parse, options) { super(ast, offset); - this.parseChildrenNodes(ast, parse); + this.initialize(ast, parse); this.variant = `hex${printString(this.variant.slice(4, -1), options)}`; - this.initializeLoc(ast); + this.finalize(ast); } print() { diff --git a/src/slang-nodes/HexStringLiterals.js b/src/slang-nodes/HexStringLiterals.js index f5f0ade25..633b86188 100644 --- a/src/slang-nodes/HexStringLiterals.js +++ b/src/slang-nodes/HexStringLiterals.js @@ -8,8 +8,8 @@ export class HexStringLiterals extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/IdentifierPath.js b/src/slang-nodes/IdentifierPath.js index 513b62450..d68466bb5 100644 --- a/src/slang-nodes/IdentifierPath.js +++ b/src/slang-nodes/IdentifierPath.js @@ -7,8 +7,8 @@ export class IdentifierPath extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print() { diff --git a/src/slang-nodes/IfStatement.js b/src/slang-nodes/IfStatement.js index bd132e9e5..7eb0b40ce 100644 --- a/src/slang-nodes/IfStatement.js +++ b/src/slang-nodes/IfStatement.js @@ -19,8 +19,8 @@ export class IfStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/ImportAlias.js b/src/slang-nodes/ImportAlias.js index 3e769916c..441c69e8b 100644 --- a/src/slang-nodes/ImportAlias.js +++ b/src/slang-nodes/ImportAlias.js @@ -7,8 +7,8 @@ export class ImportAlias extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print() { diff --git a/src/slang-nodes/ImportClause.js b/src/slang-nodes/ImportClause.js index 2b4873e28..58d5fbc64 100644 --- a/src/slang-nodes/ImportClause.js +++ b/src/slang-nodes/ImportClause.js @@ -5,8 +5,8 @@ export class ImportClause extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/ImportDeconstruction.js b/src/slang-nodes/ImportDeconstruction.js index 3dab6db76..c30bab6be 100644 --- a/src/slang-nodes/ImportDeconstruction.js +++ b/src/slang-nodes/ImportDeconstruction.js @@ -13,8 +13,8 @@ export class ImportDeconstruction extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/ImportDeconstructionSymbol.js b/src/slang-nodes/ImportDeconstructionSymbol.js index e8e57ed6e..4e35a6fd6 100644 --- a/src/slang-nodes/ImportDeconstructionSymbol.js +++ b/src/slang-nodes/ImportDeconstructionSymbol.js @@ -7,8 +7,8 @@ export class ImportDeconstructionSymbol extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/ImportDeconstructionSymbols.js b/src/slang-nodes/ImportDeconstructionSymbols.js index ade8a5380..b276f59d7 100644 --- a/src/slang-nodes/ImportDeconstructionSymbols.js +++ b/src/slang-nodes/ImportDeconstructionSymbols.js @@ -13,8 +13,8 @@ export class ImportDeconstructionSymbols extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print, options) { diff --git a/src/slang-nodes/ImportDirective.js b/src/slang-nodes/ImportDirective.js index c55abf6f6..3f4d598e1 100644 --- a/src/slang-nodes/ImportDirective.js +++ b/src/slang-nodes/ImportDirective.js @@ -9,8 +9,8 @@ export class ImportDirective extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/IndexAccessEnd.js b/src/slang-nodes/IndexAccessEnd.js index 1df0f29e5..b216e6ed3 100644 --- a/src/slang-nodes/IndexAccessEnd.js +++ b/src/slang-nodes/IndexAccessEnd.js @@ -7,8 +7,8 @@ export class IndexAccessEnd extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/IndexAccessExpression.js b/src/slang-nodes/IndexAccessExpression.js index 821bcc1ea..663c6c2dd 100644 --- a/src/slang-nodes/IndexAccessExpression.js +++ b/src/slang-nodes/IndexAccessExpression.js @@ -18,8 +18,8 @@ export class IndexAccessExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); this.closeBracket = ast.closeBracket.text; - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/InheritanceSpecifier.js b/src/slang-nodes/InheritanceSpecifier.js index d45f45202..d85af9ab2 100644 --- a/src/slang-nodes/InheritanceSpecifier.js +++ b/src/slang-nodes/InheritanceSpecifier.js @@ -7,8 +7,8 @@ export class InheritanceSpecifier extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/InheritanceType.js b/src/slang-nodes/InheritanceType.js index 20f3eaeba..1d4a68528 100644 --- a/src/slang-nodes/InheritanceType.js +++ b/src/slang-nodes/InheritanceType.js @@ -7,8 +7,8 @@ export class InheritanceType extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/InheritanceTypes.js b/src/slang-nodes/InheritanceTypes.js index 776ae01cd..91c0dbdeb 100644 --- a/src/slang-nodes/InheritanceTypes.js +++ b/src/slang-nodes/InheritanceTypes.js @@ -11,8 +11,8 @@ export class InheritanceTypes extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/InterfaceDefinition.js b/src/slang-nodes/InterfaceDefinition.js index 71aaf3906..70529c7ac 100644 --- a/src/slang-nodes/InterfaceDefinition.js +++ b/src/slang-nodes/InterfaceDefinition.js @@ -18,8 +18,8 @@ export class InterfaceDefinition extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/InterfaceMembers.js b/src/slang-nodes/InterfaceMembers.js index 8c7e05841..2a6b6fd1e 100644 --- a/src/slang-nodes/InterfaceMembers.js +++ b/src/slang-nodes/InterfaceMembers.js @@ -10,8 +10,8 @@ export class InterfaceMembers extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print, options) { diff --git a/src/slang-nodes/LibraryDefinition.js b/src/slang-nodes/LibraryDefinition.js index aed2092da..8b2957280 100644 --- a/src/slang-nodes/LibraryDefinition.js +++ b/src/slang-nodes/LibraryDefinition.js @@ -16,8 +16,8 @@ export class LibraryDefinition extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/LibraryMembers.js b/src/slang-nodes/LibraryMembers.js index a6cc9c3c3..660b83291 100644 --- a/src/slang-nodes/LibraryMembers.js +++ b/src/slang-nodes/LibraryMembers.js @@ -10,8 +10,8 @@ export class LibraryMembers extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print, options) { diff --git a/src/slang-nodes/MappingKey.js b/src/slang-nodes/MappingKey.js index 31f99c23d..647c9e920 100644 --- a/src/slang-nodes/MappingKey.js +++ b/src/slang-nodes/MappingKey.js @@ -7,8 +7,8 @@ export class MappingKey extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/MappingKeyType.js b/src/slang-nodes/MappingKeyType.js index ab34da02f..9041ea229 100644 --- a/src/slang-nodes/MappingKeyType.js +++ b/src/slang-nodes/MappingKeyType.js @@ -5,8 +5,8 @@ export class MappingKeyType extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/MappingType.js b/src/slang-nodes/MappingType.js index 3547e7cd6..e8746ebb6 100644 --- a/src/slang-nodes/MappingType.js +++ b/src/slang-nodes/MappingType.js @@ -15,8 +15,8 @@ export class MappingType extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/MappingValue.js b/src/slang-nodes/MappingValue.js index ca4f0f139..770d44225 100644 --- a/src/slang-nodes/MappingValue.js +++ b/src/slang-nodes/MappingValue.js @@ -7,8 +7,8 @@ export class MappingValue extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/MemberAccess.js b/src/slang-nodes/MemberAccess.js index c4d88776f..3b5a3b47d 100644 --- a/src/slang-nodes/MemberAccess.js +++ b/src/slang-nodes/MemberAccess.js @@ -5,8 +5,8 @@ export class MemberAccess extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print() { diff --git a/src/slang-nodes/MemberAccessExpression.js b/src/slang-nodes/MemberAccessExpression.js index df42b12bc..fbed559c9 100644 --- a/src/slang-nodes/MemberAccessExpression.js +++ b/src/slang-nodes/MemberAccessExpression.js @@ -114,8 +114,8 @@ export class MemberAccessExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/ModifierAttribute.js b/src/slang-nodes/ModifierAttribute.js index b260805d8..d714b9d68 100644 --- a/src/slang-nodes/ModifierAttribute.js +++ b/src/slang-nodes/ModifierAttribute.js @@ -5,8 +5,8 @@ export class ModifierAttribute extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/ModifierAttributes.js b/src/slang-nodes/ModifierAttributes.js index 94120d859..ed71cd3a8 100644 --- a/src/slang-nodes/ModifierAttributes.js +++ b/src/slang-nodes/ModifierAttributes.js @@ -9,9 +9,9 @@ export class ModifierAttributes extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); + this.initialize(ast, parse); this.items = this.items.sort(sortFunctionAttributes); - this.initializeLoc(ast); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/ModifierDefinition.js b/src/slang-nodes/ModifierDefinition.js index 2501328e7..93fb71747 100644 --- a/src/slang-nodes/ModifierDefinition.js +++ b/src/slang-nodes/ModifierDefinition.js @@ -2,6 +2,7 @@ import { printFunction } from '../common/slang-helpers.js'; import { SlangNode } from './SlangNode.js'; import { ParametersDeclaration } from './ParametersDeclaration.js'; import { Parameters } from './Parameters.js'; +import { Loc } from '../slang-utils/loc.js'; export class ModifierDefinition extends SlangNode { modifierKeyword; @@ -16,28 +17,26 @@ export class ModifierDefinition extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); + this.initialize(ast, parse); if (typeof this.parameters === 'undefined') { const parametersLoc = { startWithTrivia: this.attributes.loc.startWithTrivia, - start: this.attributes.loc.startWithTrivia, - endWithTrivia: this.attributes.loc.startWithTrivia, - end: this.attributes.loc.startWithTrivia + endWithTrivia: this.attributes.loc.startWithTrivia }; this.parameters = new ParametersDeclaration({ kind: 'ParametersDeclaration', - loc: { ...parametersLoc }, + loc: new Loc(parametersLoc), openParen: '(', parameters: new Parameters({ kind: 'Parameters', - loc: { ...parametersLoc }, + loc: new Loc(parametersLoc), items: [], separators: [] }), closeParen: ')' }); } - this.initializeLoc(ast); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/ModifierInvocation.js b/src/slang-nodes/ModifierInvocation.js index 40a1346b6..3c13d95ff 100644 --- a/src/slang-nodes/ModifierInvocation.js +++ b/src/slang-nodes/ModifierInvocation.js @@ -11,8 +11,8 @@ export class ModifierInvocation extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); this.#ast = ast; - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } cleanModifierInvocationArguments() { diff --git a/src/slang-nodes/MultiplicativeExpression.js b/src/slang-nodes/MultiplicativeExpression.js index 59cb9da81..a5732cb21 100644 --- a/src/slang-nodes/MultiplicativeExpression.js +++ b/src/slang-nodes/MultiplicativeExpression.js @@ -15,7 +15,7 @@ export class MultiplicativeExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); + this.initialize(ast, parse); switch (this.operator) { case '*': @@ -31,7 +31,7 @@ export class MultiplicativeExpression extends SlangNode { break; } - this.initializeLoc(ast); + this.finalize(ast); } print(path, print, options) { diff --git a/src/slang-nodes/NamedArgument.js b/src/slang-nodes/NamedArgument.js index 3198c7a73..be4cf57ae 100644 --- a/src/slang-nodes/NamedArgument.js +++ b/src/slang-nodes/NamedArgument.js @@ -9,8 +9,8 @@ export class NamedArgument extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/NamedArgumentGroup.js b/src/slang-nodes/NamedArgumentGroup.js index 930e9e39a..d6c555539 100644 --- a/src/slang-nodes/NamedArgumentGroup.js +++ b/src/slang-nodes/NamedArgumentGroup.js @@ -9,8 +9,8 @@ export class NamedArgumentGroup extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/NamedArguments.js b/src/slang-nodes/NamedArguments.js index 8e687f206..25fdc37cb 100644 --- a/src/slang-nodes/NamedArguments.js +++ b/src/slang-nodes/NamedArguments.js @@ -11,8 +11,8 @@ export class NamedArguments extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print, options) { diff --git a/src/slang-nodes/NamedArgumentsDeclaration.js b/src/slang-nodes/NamedArgumentsDeclaration.js index 81fbde148..36916def9 100644 --- a/src/slang-nodes/NamedArgumentsDeclaration.js +++ b/src/slang-nodes/NamedArgumentsDeclaration.js @@ -9,8 +9,8 @@ export class NamedArgumentsDeclaration extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/NamedImport.js b/src/slang-nodes/NamedImport.js index 343b0ee8a..50ca26ae5 100644 --- a/src/slang-nodes/NamedImport.js +++ b/src/slang-nodes/NamedImport.js @@ -11,8 +11,8 @@ export class NamedImport extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/NewExpression.js b/src/slang-nodes/NewExpression.js index 8482188a0..d768134b6 100644 --- a/src/slang-nodes/NewExpression.js +++ b/src/slang-nodes/NewExpression.js @@ -7,8 +7,8 @@ export class NewExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/NumberUnit.js b/src/slang-nodes/NumberUnit.js index cd5a51482..7e8fd8c34 100644 --- a/src/slang-nodes/NumberUnit.js +++ b/src/slang-nodes/NumberUnit.js @@ -5,8 +5,8 @@ export class NumberUnit extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print() { diff --git a/src/slang-nodes/OrExpression.js b/src/slang-nodes/OrExpression.js index 97fd3ebf0..12ac0f1b5 100644 --- a/src/slang-nodes/OrExpression.js +++ b/src/slang-nodes/OrExpression.js @@ -13,10 +13,10 @@ export class OrExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); + this.initialize(ast, parse); this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); - this.initializeLoc(ast); + this.finalize(ast); } print(path, print, options) { diff --git a/src/slang-nodes/OverridePaths.js b/src/slang-nodes/OverridePaths.js index bdf91e734..5851677f5 100644 --- a/src/slang-nodes/OverridePaths.js +++ b/src/slang-nodes/OverridePaths.js @@ -7,8 +7,8 @@ export class OverridePaths extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } // TODO: implement print diff --git a/src/slang-nodes/OverridePathsDeclaration.js b/src/slang-nodes/OverridePathsDeclaration.js index 69ec3813c..0610ab99a 100644 --- a/src/slang-nodes/OverridePathsDeclaration.js +++ b/src/slang-nodes/OverridePathsDeclaration.js @@ -9,8 +9,8 @@ export class OverridePathsDeclaration extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } // TODO: implement print diff --git a/src/slang-nodes/OverrideSpecifier.js b/src/slang-nodes/OverrideSpecifier.js index c7d552f08..74e7f3ff8 100644 --- a/src/slang-nodes/OverrideSpecifier.js +++ b/src/slang-nodes/OverrideSpecifier.js @@ -7,8 +7,8 @@ export class OverrideSpecifier extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/Parameter.js b/src/slang-nodes/Parameter.js index d2a926752..e6cfecdd9 100644 --- a/src/slang-nodes/Parameter.js +++ b/src/slang-nodes/Parameter.js @@ -12,8 +12,8 @@ export class Parameter extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/Parameters.js b/src/slang-nodes/Parameters.js index 8ffd81faf..59dc98233 100644 --- a/src/slang-nodes/Parameters.js +++ b/src/slang-nodes/Parameters.js @@ -13,8 +13,8 @@ export class Parameters extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); if (offset) { - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/ParametersDeclaration.js b/src/slang-nodes/ParametersDeclaration.js index 7f3eaf372..f95fff306 100644 --- a/src/slang-nodes/ParametersDeclaration.js +++ b/src/slang-nodes/ParametersDeclaration.js @@ -10,8 +10,8 @@ export class ParametersDeclaration extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); if (offset) { - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/PathImport.js b/src/slang-nodes/PathImport.js index 35fd7915c..60611185a 100644 --- a/src/slang-nodes/PathImport.js +++ b/src/slang-nodes/PathImport.js @@ -7,8 +7,8 @@ export class PathImport extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/PositionalArguments.js b/src/slang-nodes/PositionalArguments.js index b0fbd5dcd..e6e19223b 100644 --- a/src/slang-nodes/PositionalArguments.js +++ b/src/slang-nodes/PositionalArguments.js @@ -8,8 +8,8 @@ export class PositionalArguments extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/PositionalArgumentsDeclaration.js b/src/slang-nodes/PositionalArgumentsDeclaration.js index 4a239fa58..2f290051f 100644 --- a/src/slang-nodes/PositionalArgumentsDeclaration.js +++ b/src/slang-nodes/PositionalArgumentsDeclaration.js @@ -9,8 +9,8 @@ export class PositionalArgumentsDeclaration extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/PostfixExpression.js b/src/slang-nodes/PostfixExpression.js index 09823f9de..c49f746f3 100644 --- a/src/slang-nodes/PostfixExpression.js +++ b/src/slang-nodes/PostfixExpression.js @@ -7,8 +7,8 @@ export class PostfixExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/Pragma.js b/src/slang-nodes/Pragma.js index 17282cde3..b1ed1191a 100644 --- a/src/slang-nodes/Pragma.js +++ b/src/slang-nodes/Pragma.js @@ -5,8 +5,8 @@ export class Pragma extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/PragmaDirective.js b/src/slang-nodes/PragmaDirective.js index 6dbed2613..8b5c005ae 100644 --- a/src/slang-nodes/PragmaDirective.js +++ b/src/slang-nodes/PragmaDirective.js @@ -9,8 +9,8 @@ export class PragmaDirective extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/PrefixExpression.js b/src/slang-nodes/PrefixExpression.js index 661207109..53aa9c3c9 100644 --- a/src/slang-nodes/PrefixExpression.js +++ b/src/slang-nodes/PrefixExpression.js @@ -7,8 +7,8 @@ export class PrefixExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/ReceiveFunctionAttribute.js b/src/slang-nodes/ReceiveFunctionAttribute.js index 8c838c771..52675ec94 100644 --- a/src/slang-nodes/ReceiveFunctionAttribute.js +++ b/src/slang-nodes/ReceiveFunctionAttribute.js @@ -5,8 +5,8 @@ export class ReceiveFunctionAttribute extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/ReceiveFunctionAttributes.js b/src/slang-nodes/ReceiveFunctionAttributes.js index bf422cd6d..ad80bab78 100644 --- a/src/slang-nodes/ReceiveFunctionAttributes.js +++ b/src/slang-nodes/ReceiveFunctionAttributes.js @@ -9,9 +9,9 @@ export class ReceiveFunctionAttributes extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); + this.initialize(ast, parse); this.items = this.items.sort(sortFunctionAttributes); - this.initializeLoc(ast); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/ReceiveFunctionDefinition.js b/src/slang-nodes/ReceiveFunctionDefinition.js index 213f70608..1ac9d3e4c 100644 --- a/src/slang-nodes/ReceiveFunctionDefinition.js +++ b/src/slang-nodes/ReceiveFunctionDefinition.js @@ -12,9 +12,9 @@ export class ReceiveFunctionDefinition extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); + this.initialize(ast, parse); this.cleanModifierInvocationArguments(); - this.initializeLoc(ast); + this.finalize(ast); } cleanModifierInvocationArguments() { diff --git a/src/slang-nodes/ReturnStatement.js b/src/slang-nodes/ReturnStatement.js index 25a13e4df..3234e6575 100644 --- a/src/slang-nodes/ReturnStatement.js +++ b/src/slang-nodes/ReturnStatement.js @@ -23,8 +23,8 @@ export class ReturnStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print, options) { diff --git a/src/slang-nodes/ReturnsDeclaration.js b/src/slang-nodes/ReturnsDeclaration.js index 70d2777da..7938b0bd1 100644 --- a/src/slang-nodes/ReturnsDeclaration.js +++ b/src/slang-nodes/ReturnsDeclaration.js @@ -10,8 +10,8 @@ export class ReturnsDeclaration extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/RevertStatement.js b/src/slang-nodes/RevertStatement.js index f3f610429..da4999311 100644 --- a/src/slang-nodes/RevertStatement.js +++ b/src/slang-nodes/RevertStatement.js @@ -11,8 +11,8 @@ export class RevertStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/ShiftExpression.js b/src/slang-nodes/ShiftExpression.js index d844d4f8a..efbd55c96 100644 --- a/src/slang-nodes/ShiftExpression.js +++ b/src/slang-nodes/ShiftExpression.js @@ -22,10 +22,10 @@ export class ShiftExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); + this.initialize(ast, parse); this.leftOperand = tryToHugLeftOperand(this.leftOperand); this.rightOperand = tryToHugRightOperand(this.rightOperand); - this.initializeLoc(ast); + this.finalize(ast); } print(path, print, options) { diff --git a/src/slang-nodes/SlangNode.js b/src/slang-nodes/SlangNode.js index af32559e9..3a9d7f163 100644 --- a/src/slang-nodes/SlangNode.js +++ b/src/slang-nodes/SlangNode.js @@ -1,4 +1,5 @@ import { isComment } from '../common/slang-helpers.js'; +import { Loc } from '../slang-utils/loc.js'; const comments = []; @@ -17,10 +18,10 @@ function getOffsets(children, initialOffset) { comments.push({ kind: child.kind, value: child.text, - loc: { - start: offset, - end: offset + child.textLength.utf8 - } + loc: new Loc({ + startWithTrivia: offset, + endWithTrivia: offset + child.textLength.utf8 + }) }); } @@ -61,13 +62,7 @@ function getTrailingOffset(children) { export class SlangNode { kind; - loc = { - childrenOffsets: [], - startWithTrivia: 0, - start: 0, - endWithTrivia: 0, - end: 0 - }; + loc; comments = []; @@ -75,16 +70,18 @@ export class SlangNode { if (typeof offset === 'undefined') return; const children = ast.cst.children(); this.kind = ast.cst.kind; - this.loc.childrenOffsets = getOffsets(children, offset); - this.loc.startWithTrivia = offset; - this.loc.endWithTrivia = offset + ast.cst.textLength.utf8; + this.loc = new Loc({ + startWithTrivia: offset, + endWithTrivia: offset + ast.cst.textLength.utf8, + childrenOffsets: getOffsets(children, offset) + }); } - parseChildrenNodes(ast, parse) { + initialize(ast, parse) { const getValue = (astChild) => astChild.type === 'Terminal' ? astChild.text - : parse(astChild, this.nextChildOffset); + : parse(astChild, this.loc.childrenOffsets.shift()); Object.keys(this) .slice(3) @@ -117,7 +114,7 @@ export class SlangNode { * ]; * ``` */ - initializeLoc(ast) { + finalize(ast) { const children = ast.cst.children(); let leadingOffset = getLeadingOffset(children); let trailingOffset = getTrailingOffset(children); @@ -148,10 +145,6 @@ export class SlangNode { this.loc.end = this.loc.endWithTrivia - trailingOffset; } - get nextChildOffset() { - return this.loc.childrenOffsets.shift(); - } - collectComments() { this.comments = comments.splice(0); } diff --git a/src/slang-nodes/SourceUnit.js b/src/slang-nodes/SourceUnit.js index 3afaca81b..c2585ac01 100644 --- a/src/slang-nodes/SourceUnit.js +++ b/src/slang-nodes/SourceUnit.js @@ -8,8 +8,8 @@ export class SourceUnit extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print, options) { diff --git a/src/slang-nodes/SourceUnitMember.js b/src/slang-nodes/SourceUnitMember.js index 6920ef5b6..304e0ccd7 100644 --- a/src/slang-nodes/SourceUnitMember.js +++ b/src/slang-nodes/SourceUnitMember.js @@ -5,8 +5,8 @@ export class SourceUnitMember extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/SourceUnitMembers.js b/src/slang-nodes/SourceUnitMembers.js index b34d585ef..1b12be354 100644 --- a/src/slang-nodes/SourceUnitMembers.js +++ b/src/slang-nodes/SourceUnitMembers.js @@ -6,8 +6,8 @@ export class SourceUnitMembers extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print, options) { diff --git a/src/slang-nodes/StateVariableAttribute.js b/src/slang-nodes/StateVariableAttribute.js index 9d1150dff..1f9ba8121 100644 --- a/src/slang-nodes/StateVariableAttribute.js +++ b/src/slang-nodes/StateVariableAttribute.js @@ -5,8 +5,8 @@ export class StateVariableAttribute extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/StateVariableAttributes.js b/src/slang-nodes/StateVariableAttributes.js index cae993605..07c48de5e 100644 --- a/src/slang-nodes/StateVariableAttributes.js +++ b/src/slang-nodes/StateVariableAttributes.js @@ -5,8 +5,8 @@ export class StateVariableAttributes extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/StateVariableDefinition.js b/src/slang-nodes/StateVariableDefinition.js index aeff98fb2..aa7203091 100644 --- a/src/slang-nodes/StateVariableDefinition.js +++ b/src/slang-nodes/StateVariableDefinition.js @@ -13,8 +13,8 @@ export class StateVariableDefinition extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/StateVariableDefinitionValue.js b/src/slang-nodes/StateVariableDefinitionValue.js index e6d7bfa34..67dc0caac 100644 --- a/src/slang-nodes/StateVariableDefinitionValue.js +++ b/src/slang-nodes/StateVariableDefinitionValue.js @@ -10,8 +10,8 @@ export class StateVariableDefinitionValue extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/Statement.js b/src/slang-nodes/Statement.js index 860b4b53b..17af3e269 100644 --- a/src/slang-nodes/Statement.js +++ b/src/slang-nodes/Statement.js @@ -5,8 +5,8 @@ export class Statement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/Statements.js b/src/slang-nodes/Statements.js index 0fd1ad73c..4ffcb7f0d 100644 --- a/src/slang-nodes/Statements.js +++ b/src/slang-nodes/Statements.js @@ -13,8 +13,8 @@ export class Statements extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print, options) { diff --git a/src/slang-nodes/StorageLocation.js b/src/slang-nodes/StorageLocation.js index 86b4c4e24..15124b498 100644 --- a/src/slang-nodes/StorageLocation.js +++ b/src/slang-nodes/StorageLocation.js @@ -5,8 +5,8 @@ export class StorageLocation extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print() { diff --git a/src/slang-nodes/StringExpression.js b/src/slang-nodes/StringExpression.js index 50f2acf7c..f18b47e5f 100644 --- a/src/slang-nodes/StringExpression.js +++ b/src/slang-nodes/StringExpression.js @@ -5,8 +5,8 @@ export class StringExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/StringLiteral.js b/src/slang-nodes/StringLiteral.js index fdc4819b0..07b36aecb 100644 --- a/src/slang-nodes/StringLiteral.js +++ b/src/slang-nodes/StringLiteral.js @@ -6,9 +6,9 @@ export class StringLiteral extends SlangNode { constructor(ast, offset, parse, options) { super(ast, offset); - this.parseChildrenNodes(ast, parse); + this.initialize(ast, parse); this.variant = printString(this.variant.slice(1, -1), options); - this.initializeLoc(ast); + this.finalize(ast); } print() { diff --git a/src/slang-nodes/StringLiterals.js b/src/slang-nodes/StringLiterals.js index 91f5ead36..21d88c47f 100644 --- a/src/slang-nodes/StringLiterals.js +++ b/src/slang-nodes/StringLiterals.js @@ -8,8 +8,8 @@ export class StringLiterals extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/StructDefinition.js b/src/slang-nodes/StructDefinition.js index c88281ace..af3ddd9db 100644 --- a/src/slang-nodes/StructDefinition.js +++ b/src/slang-nodes/StructDefinition.js @@ -13,8 +13,8 @@ export class StructDefinition extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/StructMember.js b/src/slang-nodes/StructMember.js index 53a3948cb..2a1448bfc 100644 --- a/src/slang-nodes/StructMember.js +++ b/src/slang-nodes/StructMember.js @@ -9,8 +9,8 @@ export class StructMember extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/StructMembers.js b/src/slang-nodes/StructMembers.js index 4debfe9cb..73bbcc514 100644 --- a/src/slang-nodes/StructMembers.js +++ b/src/slang-nodes/StructMembers.js @@ -9,8 +9,8 @@ export class StructMembers extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/ThrowStatement.js b/src/slang-nodes/ThrowStatement.js index 8f5483fe6..75af926e8 100644 --- a/src/slang-nodes/ThrowStatement.js +++ b/src/slang-nodes/ThrowStatement.js @@ -7,8 +7,8 @@ export class ThrowStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } // TODO: implement print diff --git a/src/slang-nodes/TryStatement.js b/src/slang-nodes/TryStatement.js index 042c93150..b23ac6a20 100644 --- a/src/slang-nodes/TryStatement.js +++ b/src/slang-nodes/TryStatement.js @@ -17,8 +17,8 @@ export class TryStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/TupleDeconstructionElement.js b/src/slang-nodes/TupleDeconstructionElement.js index 570c6de75..f27067da9 100644 --- a/src/slang-nodes/TupleDeconstructionElement.js +++ b/src/slang-nodes/TupleDeconstructionElement.js @@ -5,8 +5,8 @@ export class TupleDeconstructionElement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/TupleDeconstructionElements.js b/src/slang-nodes/TupleDeconstructionElements.js index a4013e315..54dbd3558 100644 --- a/src/slang-nodes/TupleDeconstructionElements.js +++ b/src/slang-nodes/TupleDeconstructionElements.js @@ -8,8 +8,8 @@ export class TupleDeconstructionElements extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/TupleDeconstructionStatement.js b/src/slang-nodes/TupleDeconstructionStatement.js index a70af8423..e0e583ec2 100644 --- a/src/slang-nodes/TupleDeconstructionStatement.js +++ b/src/slang-nodes/TupleDeconstructionStatement.js @@ -20,8 +20,8 @@ export class TupleDeconstructionStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/TupleExpression.js b/src/slang-nodes/TupleExpression.js index 3c935e747..e83b52b05 100644 --- a/src/slang-nodes/TupleExpression.js +++ b/src/slang-nodes/TupleExpression.js @@ -10,8 +10,8 @@ export class TupleExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); if (offset) { - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/TupleMember.js b/src/slang-nodes/TupleMember.js index 545c72122..02d546d58 100644 --- a/src/slang-nodes/TupleMember.js +++ b/src/slang-nodes/TupleMember.js @@ -5,8 +5,8 @@ export class TupleMember extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/TupleValue.js b/src/slang-nodes/TupleValue.js index 09434c9be..1deab07ed 100644 --- a/src/slang-nodes/TupleValue.js +++ b/src/slang-nodes/TupleValue.js @@ -6,8 +6,8 @@ export class TupleValue extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); if (offset) { - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/TupleValues.js b/src/slang-nodes/TupleValues.js index a9b29a934..b9a262906 100644 --- a/src/slang-nodes/TupleValues.js +++ b/src/slang-nodes/TupleValues.js @@ -10,8 +10,8 @@ export class TupleValues extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); if (offset) { - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/TypeExpression.js b/src/slang-nodes/TypeExpression.js index 29aab9776..f8c1c86e6 100644 --- a/src/slang-nodes/TypeExpression.js +++ b/src/slang-nodes/TypeExpression.js @@ -11,8 +11,8 @@ export class TypeExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } // TODO: implement print diff --git a/src/slang-nodes/TypeName.js b/src/slang-nodes/TypeName.js index be3f0a1be..5656963d2 100644 --- a/src/slang-nodes/TypeName.js +++ b/src/slang-nodes/TypeName.js @@ -5,8 +5,8 @@ export class TypeName extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/TypedTupleMember.js b/src/slang-nodes/TypedTupleMember.js index b337d8e02..011f9ed2a 100644 --- a/src/slang-nodes/TypedTupleMember.js +++ b/src/slang-nodes/TypedTupleMember.js @@ -9,8 +9,8 @@ export class TypedTupleMember extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/UncheckedBlock.js b/src/slang-nodes/UncheckedBlock.js index 323ed5853..4f7e470a8 100644 --- a/src/slang-nodes/UncheckedBlock.js +++ b/src/slang-nodes/UncheckedBlock.js @@ -7,8 +7,8 @@ export class UncheckedBlock extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/UnicodeStringLiteral.js b/src/slang-nodes/UnicodeStringLiteral.js index 041d85ff1..821092d8c 100644 --- a/src/slang-nodes/UnicodeStringLiteral.js +++ b/src/slang-nodes/UnicodeStringLiteral.js @@ -6,9 +6,9 @@ export class UnicodeStringLiteral extends SlangNode { constructor(ast, offset, parse, options) { super(ast, offset); - this.parseChildrenNodes(ast, parse); + this.initialize(ast, parse); this.variant = `unicode${printString(this.variant.slice(8, -1), options)}`; - this.initializeLoc(ast); + this.finalize(ast); } print() { diff --git a/src/slang-nodes/UnicodeStringLiterals.js b/src/slang-nodes/UnicodeStringLiterals.js index a1b96597b..cba611b9e 100644 --- a/src/slang-nodes/UnicodeStringLiterals.js +++ b/src/slang-nodes/UnicodeStringLiterals.js @@ -8,8 +8,8 @@ export class UnicodeStringLiterals extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/UnnamedFunctionAttribute.js b/src/slang-nodes/UnnamedFunctionAttribute.js index 7413cde45..88fef9653 100644 --- a/src/slang-nodes/UnnamedFunctionAttribute.js +++ b/src/slang-nodes/UnnamedFunctionAttribute.js @@ -5,8 +5,8 @@ export class UnnamedFunctionAttribute extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/UnnamedFunctionAttributes.js b/src/slang-nodes/UnnamedFunctionAttributes.js index 045bfa7cc..ed3761a7f 100644 --- a/src/slang-nodes/UnnamedFunctionAttributes.js +++ b/src/slang-nodes/UnnamedFunctionAttributes.js @@ -9,9 +9,9 @@ export class UnnamedFunctionAttributes extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); + this.initialize(ast, parse); this.items = this.items.sort(sortFunctionAttributes); - this.initializeLoc(ast); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/UnnamedFunctionDefinition.js b/src/slang-nodes/UnnamedFunctionDefinition.js index eaad52fe8..b2595c2e4 100644 --- a/src/slang-nodes/UnnamedFunctionDefinition.js +++ b/src/slang-nodes/UnnamedFunctionDefinition.js @@ -12,9 +12,9 @@ export class UnnamedFunctionDefinition extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); + this.initialize(ast, parse); this.cleanModifierInvocationArguments(); - this.initializeLoc(ast); + this.finalize(ast); } cleanModifierInvocationArguments() { diff --git a/src/slang-nodes/UntypedTupleMember.js b/src/slang-nodes/UntypedTupleMember.js index 5aa86aa0a..1b5f9bf03 100644 --- a/src/slang-nodes/UntypedTupleMember.js +++ b/src/slang-nodes/UntypedTupleMember.js @@ -7,8 +7,8 @@ export class UntypedTupleMember extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } // TODO: implement print diff --git a/src/slang-nodes/UserDefinedValueTypeDefinition.js b/src/slang-nodes/UserDefinedValueTypeDefinition.js index 31761c4df..2cabd2ad1 100644 --- a/src/slang-nodes/UserDefinedValueTypeDefinition.js +++ b/src/slang-nodes/UserDefinedValueTypeDefinition.js @@ -13,8 +13,8 @@ export class UserDefinedValueTypeDefinition extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/UsingAlias.js b/src/slang-nodes/UsingAlias.js index 2fd42f4b0..eaeab1584 100644 --- a/src/slang-nodes/UsingAlias.js +++ b/src/slang-nodes/UsingAlias.js @@ -7,8 +7,8 @@ export class UsingAlias extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/UsingClause.js b/src/slang-nodes/UsingClause.js index 4e2ba3ccf..f8f84b2d8 100644 --- a/src/slang-nodes/UsingClause.js +++ b/src/slang-nodes/UsingClause.js @@ -5,8 +5,8 @@ export class UsingClause extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/UsingDeconstruction.js b/src/slang-nodes/UsingDeconstruction.js index 8dedc7c94..ec222e78f 100644 --- a/src/slang-nodes/UsingDeconstruction.js +++ b/src/slang-nodes/UsingDeconstruction.js @@ -9,8 +9,8 @@ export class UsingDeconstruction extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/UsingDeconstructionSymbol.js b/src/slang-nodes/UsingDeconstructionSymbol.js index d255452e5..eaae89def 100644 --- a/src/slang-nodes/UsingDeconstructionSymbol.js +++ b/src/slang-nodes/UsingDeconstructionSymbol.js @@ -7,8 +7,8 @@ export class UsingDeconstructionSymbol extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/UsingDeconstructionSymbols.js b/src/slang-nodes/UsingDeconstructionSymbols.js index 903d66414..0419a5008 100644 --- a/src/slang-nodes/UsingDeconstructionSymbols.js +++ b/src/slang-nodes/UsingDeconstructionSymbols.js @@ -11,8 +11,8 @@ export class UsingDeconstructionSymbols extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print, options) { diff --git a/src/slang-nodes/UsingDirective.js b/src/slang-nodes/UsingDirective.js index 69e5d6755..80d594d5b 100644 --- a/src/slang-nodes/UsingDirective.js +++ b/src/slang-nodes/UsingDirective.js @@ -15,8 +15,8 @@ export class UsingDirective extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/UsingOperator.js b/src/slang-nodes/UsingOperator.js index dd7c73a32..1bf811179 100644 --- a/src/slang-nodes/UsingOperator.js +++ b/src/slang-nodes/UsingOperator.js @@ -5,8 +5,8 @@ export class UsingOperator extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print() { diff --git a/src/slang-nodes/UsingTarget.js b/src/slang-nodes/UsingTarget.js index 87e57ca68..14f098684 100644 --- a/src/slang-nodes/UsingTarget.js +++ b/src/slang-nodes/UsingTarget.js @@ -5,8 +5,8 @@ export class UsingTarget extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/VariableDeclarationStatement.js b/src/slang-nodes/VariableDeclarationStatement.js index 35e41c9e9..327b37c2d 100644 --- a/src/slang-nodes/VariableDeclarationStatement.js +++ b/src/slang-nodes/VariableDeclarationStatement.js @@ -16,8 +16,8 @@ export class VariableDeclarationStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/VariableDeclarationType.js b/src/slang-nodes/VariableDeclarationType.js index 975830355..21b2924f2 100644 --- a/src/slang-nodes/VariableDeclarationType.js +++ b/src/slang-nodes/VariableDeclarationType.js @@ -5,8 +5,8 @@ export class VariableDeclarationType extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/VariableDeclarationValue.js b/src/slang-nodes/VariableDeclarationValue.js index 5a20a3364..1bd351d33 100644 --- a/src/slang-nodes/VariableDeclarationValue.js +++ b/src/slang-nodes/VariableDeclarationValue.js @@ -7,8 +7,8 @@ export class VariableDeclarationValue extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/VersionComparator.js b/src/slang-nodes/VersionComparator.js index fbc4e9fed..c6a221f86 100644 --- a/src/slang-nodes/VersionComparator.js +++ b/src/slang-nodes/VersionComparator.js @@ -7,8 +7,8 @@ export class VersionComparator extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/VersionExpression.js b/src/slang-nodes/VersionExpression.js index fc1455f2d..16001179e 100644 --- a/src/slang-nodes/VersionExpression.js +++ b/src/slang-nodes/VersionExpression.js @@ -5,8 +5,8 @@ export class VersionExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/VersionExpressionSet.js b/src/slang-nodes/VersionExpressionSet.js index e33410a63..a016c2e67 100644 --- a/src/slang-nodes/VersionExpressionSet.js +++ b/src/slang-nodes/VersionExpressionSet.js @@ -8,8 +8,8 @@ export class VersionExpressionSet extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/VersionExpressionSets.js b/src/slang-nodes/VersionExpressionSets.js index d1be6330b..26936dacc 100644 --- a/src/slang-nodes/VersionExpressionSets.js +++ b/src/slang-nodes/VersionExpressionSets.js @@ -7,8 +7,8 @@ export class VersionExpressionSets extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/VersionPragma.js b/src/slang-nodes/VersionPragma.js index c9065cc04..d380d3fa9 100644 --- a/src/slang-nodes/VersionPragma.js +++ b/src/slang-nodes/VersionPragma.js @@ -7,8 +7,8 @@ export class VersionPragma extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/VersionRange.js b/src/slang-nodes/VersionRange.js index 35d5534ae..eadf4f02a 100644 --- a/src/slang-nodes/VersionRange.js +++ b/src/slang-nodes/VersionRange.js @@ -9,8 +9,8 @@ export class VersionRange extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } // TODO: implement print diff --git a/src/slang-nodes/VersionSpecifiers.js b/src/slang-nodes/VersionSpecifiers.js index 484684687..6a66f8be0 100644 --- a/src/slang-nodes/VersionSpecifiers.js +++ b/src/slang-nodes/VersionSpecifiers.js @@ -7,8 +7,8 @@ export class VersionSpecifiers extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print() { diff --git a/src/slang-nodes/WhileStatement.js b/src/slang-nodes/WhileStatement.js index 51ac74287..6d0be2623 100644 --- a/src/slang-nodes/WhileStatement.js +++ b/src/slang-nodes/WhileStatement.js @@ -17,8 +17,8 @@ export class WhileStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/YulArguments.js b/src/slang-nodes/YulArguments.js index 12460827d..3e7afa42d 100644 --- a/src/slang-nodes/YulArguments.js +++ b/src/slang-nodes/YulArguments.js @@ -8,8 +8,8 @@ export class YulArguments extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/YulAssignmentOperator.js b/src/slang-nodes/YulAssignmentOperator.js index 3949af8a0..023b9c418 100644 --- a/src/slang-nodes/YulAssignmentOperator.js +++ b/src/slang-nodes/YulAssignmentOperator.js @@ -5,8 +5,8 @@ export class YulAssignmentOperator extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/YulAssignmentStatement.js b/src/slang-nodes/YulAssignmentStatement.js index 653f96fa1..1a7d781fb 100644 --- a/src/slang-nodes/YulAssignmentStatement.js +++ b/src/slang-nodes/YulAssignmentStatement.js @@ -9,8 +9,8 @@ export class YulAssignmentStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/YulBlock.js b/src/slang-nodes/YulBlock.js index 53eb2e0a6..1851371bb 100644 --- a/src/slang-nodes/YulBlock.js +++ b/src/slang-nodes/YulBlock.js @@ -9,8 +9,8 @@ export class YulBlock extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/YulBreakStatement.js b/src/slang-nodes/YulBreakStatement.js index 202b8c777..96a242e9b 100644 --- a/src/slang-nodes/YulBreakStatement.js +++ b/src/slang-nodes/YulBreakStatement.js @@ -5,8 +5,8 @@ export class YulBreakStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print() { diff --git a/src/slang-nodes/YulBuiltInFunction.js b/src/slang-nodes/YulBuiltInFunction.js index f8b477f3e..c657e86ff 100644 --- a/src/slang-nodes/YulBuiltInFunction.js +++ b/src/slang-nodes/YulBuiltInFunction.js @@ -5,8 +5,8 @@ export class YulBuiltInFunction extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print() { diff --git a/src/slang-nodes/YulColonAndEqual.js b/src/slang-nodes/YulColonAndEqual.js index fd5eb4f43..8067233e5 100644 --- a/src/slang-nodes/YulColonAndEqual.js +++ b/src/slang-nodes/YulColonAndEqual.js @@ -7,8 +7,8 @@ export class YulColonAndEqual extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } // TODO: implement print diff --git a/src/slang-nodes/YulContinueStatement.js b/src/slang-nodes/YulContinueStatement.js index dce33fdda..009b1cbd6 100644 --- a/src/slang-nodes/YulContinueStatement.js +++ b/src/slang-nodes/YulContinueStatement.js @@ -5,8 +5,8 @@ export class YulContinueStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print() { diff --git a/src/slang-nodes/YulDefaultCase.js b/src/slang-nodes/YulDefaultCase.js index 7d3c1aef2..af554bd86 100644 --- a/src/slang-nodes/YulDefaultCase.js +++ b/src/slang-nodes/YulDefaultCase.js @@ -7,8 +7,8 @@ export class YulDefaultCase extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/YulExpression.js b/src/slang-nodes/YulExpression.js index 0bfd5a53a..0d3c5d1b7 100644 --- a/src/slang-nodes/YulExpression.js +++ b/src/slang-nodes/YulExpression.js @@ -5,8 +5,8 @@ export class YulExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/YulForStatement.js b/src/slang-nodes/YulForStatement.js index 96793b418..6d73a8764 100644 --- a/src/slang-nodes/YulForStatement.js +++ b/src/slang-nodes/YulForStatement.js @@ -13,8 +13,8 @@ export class YulForStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/YulFunctionCallExpression.js b/src/slang-nodes/YulFunctionCallExpression.js index 7f0a42afc..349c16b65 100644 --- a/src/slang-nodes/YulFunctionCallExpression.js +++ b/src/slang-nodes/YulFunctionCallExpression.js @@ -11,8 +11,8 @@ export class YulFunctionCallExpression extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/YulFunctionDefinition.js b/src/slang-nodes/YulFunctionDefinition.js index 543c4d802..17702b3b0 100644 --- a/src/slang-nodes/YulFunctionDefinition.js +++ b/src/slang-nodes/YulFunctionDefinition.js @@ -13,8 +13,8 @@ export class YulFunctionDefinition extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/YulIfStatement.js b/src/slang-nodes/YulIfStatement.js index cbe133b41..d1b08fe1b 100644 --- a/src/slang-nodes/YulIfStatement.js +++ b/src/slang-nodes/YulIfStatement.js @@ -9,8 +9,8 @@ export class YulIfStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/YulLabel.js b/src/slang-nodes/YulLabel.js index 865aee911..a6c13e630 100644 --- a/src/slang-nodes/YulLabel.js +++ b/src/slang-nodes/YulLabel.js @@ -9,8 +9,8 @@ export class YulLabel extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print() { diff --git a/src/slang-nodes/YulLeaveStatement.js b/src/slang-nodes/YulLeaveStatement.js index f6e70309f..8907e8d9a 100644 --- a/src/slang-nodes/YulLeaveStatement.js +++ b/src/slang-nodes/YulLeaveStatement.js @@ -5,8 +5,8 @@ export class YulLeaveStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } // TODO: implement print diff --git a/src/slang-nodes/YulLiteral.js b/src/slang-nodes/YulLiteral.js index df17dd57c..0511d3f39 100644 --- a/src/slang-nodes/YulLiteral.js +++ b/src/slang-nodes/YulLiteral.js @@ -5,8 +5,8 @@ export class YulLiteral extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/YulParameters.js b/src/slang-nodes/YulParameters.js index 9839f21aa..16098c2ed 100644 --- a/src/slang-nodes/YulParameters.js +++ b/src/slang-nodes/YulParameters.js @@ -8,8 +8,8 @@ export class YulParameters extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print() { diff --git a/src/slang-nodes/YulParametersDeclaration.js b/src/slang-nodes/YulParametersDeclaration.js index 030440af4..2c133ab68 100644 --- a/src/slang-nodes/YulParametersDeclaration.js +++ b/src/slang-nodes/YulParametersDeclaration.js @@ -9,8 +9,8 @@ export class YulParametersDeclaration extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/YulPath.js b/src/slang-nodes/YulPath.js index 4429925f7..a26c81f48 100644 --- a/src/slang-nodes/YulPath.js +++ b/src/slang-nodes/YulPath.js @@ -7,8 +7,8 @@ export class YulPath extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/YulPathComponent.js b/src/slang-nodes/YulPathComponent.js index 62ca3224e..823d9c6e1 100644 --- a/src/slang-nodes/YulPathComponent.js +++ b/src/slang-nodes/YulPathComponent.js @@ -5,8 +5,8 @@ export class YulPathComponent extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print() { diff --git a/src/slang-nodes/YulPaths.js b/src/slang-nodes/YulPaths.js index 785f39c1c..63d429f79 100644 --- a/src/slang-nodes/YulPaths.js +++ b/src/slang-nodes/YulPaths.js @@ -7,8 +7,8 @@ export class YulPaths extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/YulReturnVariables.js b/src/slang-nodes/YulReturnVariables.js index a71dae060..a6d17a264 100644 --- a/src/slang-nodes/YulReturnVariables.js +++ b/src/slang-nodes/YulReturnVariables.js @@ -11,8 +11,8 @@ export class YulReturnVariables extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print() { diff --git a/src/slang-nodes/YulReturnsDeclaration.js b/src/slang-nodes/YulReturnsDeclaration.js index f18d2bd00..cdb0d1847 100644 --- a/src/slang-nodes/YulReturnsDeclaration.js +++ b/src/slang-nodes/YulReturnsDeclaration.js @@ -11,8 +11,8 @@ export class YulReturnsDeclaration extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/YulStatement.js b/src/slang-nodes/YulStatement.js index 3219dc107..fa52577f4 100644 --- a/src/slang-nodes/YulStatement.js +++ b/src/slang-nodes/YulStatement.js @@ -5,8 +5,8 @@ export class YulStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/YulStatements.js b/src/slang-nodes/YulStatements.js index eb40b3829..8c693d470 100644 --- a/src/slang-nodes/YulStatements.js +++ b/src/slang-nodes/YulStatements.js @@ -13,8 +13,8 @@ export class YulStatements extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print, options) { diff --git a/src/slang-nodes/YulSwitchCase.js b/src/slang-nodes/YulSwitchCase.js index f56dd8132..8911049f4 100644 --- a/src/slang-nodes/YulSwitchCase.js +++ b/src/slang-nodes/YulSwitchCase.js @@ -5,8 +5,8 @@ export class YulSwitchCase extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/YulSwitchCases.js b/src/slang-nodes/YulSwitchCases.js index 710a2f960..de018c0d0 100644 --- a/src/slang-nodes/YulSwitchCases.js +++ b/src/slang-nodes/YulSwitchCases.js @@ -8,8 +8,8 @@ export class YulSwitchCases extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/YulSwitchStatement.js b/src/slang-nodes/YulSwitchStatement.js index 3d6433273..6b18d49c8 100644 --- a/src/slang-nodes/YulSwitchStatement.js +++ b/src/slang-nodes/YulSwitchStatement.js @@ -12,8 +12,8 @@ export class YulSwitchStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/YulValueCase.js b/src/slang-nodes/YulValueCase.js index 19015f9b5..2e67607ce 100644 --- a/src/slang-nodes/YulValueCase.js +++ b/src/slang-nodes/YulValueCase.js @@ -9,8 +9,8 @@ export class YulValueCase extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/YulVariableAssignmentStatement.js b/src/slang-nodes/YulVariableAssignmentStatement.js index 587559519..a8f3e6ed7 100644 --- a/src/slang-nodes/YulVariableAssignmentStatement.js +++ b/src/slang-nodes/YulVariableAssignmentStatement.js @@ -9,8 +9,8 @@ export class YulVariableAssignmentStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/YulVariableDeclarationStatement.js b/src/slang-nodes/YulVariableDeclarationStatement.js index d00265b81..4d5431f14 100644 --- a/src/slang-nodes/YulVariableDeclarationStatement.js +++ b/src/slang-nodes/YulVariableDeclarationStatement.js @@ -9,8 +9,8 @@ export class YulVariableDeclarationStatement extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/YulVariableDeclarationValue.js b/src/slang-nodes/YulVariableDeclarationValue.js index 3fad03e0f..407d136a4 100644 --- a/src/slang-nodes/YulVariableDeclarationValue.js +++ b/src/slang-nodes/YulVariableDeclarationValue.js @@ -7,8 +7,8 @@ export class YulVariableDeclarationValue extends SlangNode { constructor(ast, offset, parse) { super(ast, offset); - this.parseChildrenNodes(ast, parse); - this.initializeLoc(ast); + this.initialize(ast, parse); + this.finalize(ast); } print(path, print) { diff --git a/src/slang-utils/loc.js b/src/slang-utils/loc.js new file mode 100644 index 000000000..508212fd3 --- /dev/null +++ b/src/slang-utils/loc.js @@ -0,0 +1,31 @@ +export class Loc { + childrenOffsets = []; + + startWithTrivia; + + start; + + endWithTrivia; + + end; + + constructor({ startWithTrivia, endWithTrivia, start, end, childrenOffsets }) { + if (typeof childrenOffsets !== 'undefined') { + this.childrenOffsets = childrenOffsets; + } + + this.startWithTrivia = startWithTrivia; + this.endWithTrivia = endWithTrivia; + + this.start = typeof start === 'undefined' ? startWithTrivia : start; + this.end = typeof end === 'undefined' ? endWithTrivia : end; + } +} + +export function locStart(node) { + return node.loc.start; +} + +export function locEnd(node) { + return node.loc.end; +} From 99720654351229bf7a74de3dc0e9664b3746dbeb Mon Sep 17 00:00:00 2001 From: Klaus Date: Mon, 15 Jul 2024 12:12:43 +1200 Subject: [PATCH 077/160] separating slang-helpers functionality into smaller files with specific responsibilities --- src/common/printer-helpers.js | 2 +- src/common/slang-helpers.js | 282 ------------------ src/index.js | 2 +- .../handleContractDefinitionComments.js | 2 +- .../handlers/handleWhileStatementComments.js | 2 +- src/slang-comments/printer.js | 2 +- src/slang-nodes/AdditiveExpression.js | 4 +- src/slang-nodes/AndExpression.js | 4 +- src/slang-nodes/AssignmentExpression.js | 2 +- src/slang-nodes/BitwiseAndExpression.js | 4 +- src/slang-nodes/BitwiseOrExpression.js | 4 +- src/slang-nodes/BitwiseXorExpression.js | 4 +- src/slang-nodes/ComparisonExpression.js | 4 +- src/slang-nodes/ConstructorAttributes.js | 2 +- src/slang-nodes/ConstructorDefinition.js | 2 +- src/slang-nodes/ContractMembers.js | 6 +- src/slang-nodes/ElseBranch.js | 2 +- src/slang-nodes/EqualityExpression.js | 4 +- src/slang-nodes/ExponentiationExpression.js | 6 +- src/slang-nodes/FallbackFunctionAttributes.js | 2 +- src/slang-nodes/FallbackFunctionDefinition.js | 2 +- src/slang-nodes/FunctionAttributes.js | 2 +- src/slang-nodes/FunctionDefinition.js | 2 +- src/slang-nodes/FunctionType.js | 2 +- src/slang-nodes/FunctionTypeAttributes.js | 2 +- src/slang-nodes/HexStringLiteral.js | 2 +- src/slang-nodes/InterfaceMembers.js | 2 +- src/slang-nodes/LibraryMembers.js | 2 +- src/slang-nodes/MemberAccessExpression.js | 2 +- src/slang-nodes/ModifierAttributes.js | 2 +- src/slang-nodes/ModifierDefinition.js | 2 +- src/slang-nodes/ModifierInvocation.js | 2 +- src/slang-nodes/MultiplicativeExpression.js | 4 +- src/slang-nodes/OrExpression.js | 4 +- src/slang-nodes/Parameters.js | 2 +- src/slang-nodes/ReceiveFunctionAttributes.js | 2 +- src/slang-nodes/ReceiveFunctionDefinition.js | 2 +- src/slang-nodes/ShiftExpression.js | 4 +- src/slang-nodes/SlangNode.js | 2 +- src/slang-nodes/SourceUnitMembers.js | 2 +- src/slang-nodes/Statements.js | 7 +- src/slang-nodes/StringLiteral.js | 2 +- src/slang-nodes/TupleValues.js | 2 +- src/slang-nodes/UnicodeStringLiteral.js | 2 +- src/slang-nodes/UnnamedFunctionAttributes.js | 2 +- src/slang-nodes/UnnamedFunctionDefinition.js | 2 +- src/slang-nodes/YulStatements.js | 6 +- .../create-binary-operation-printer.js | 29 ++ src/slang-printers/print-binary-operation.js | 45 +++ src/slang-printers/print-comments.js | 36 +++ .../print-comparison-operation.js | 33 ++ src/slang-printers/print-function.js | 20 ++ src/slang-printers/print-logical-operation.js | 38 +++ .../print-preserving-empty-lines.js | 27 ++ src/slang-printers/print-string.js | 36 +++ src/slang-utils/create-hug-function.js | 2 +- src/slang-utils/create-kind-check-function.js | 4 + src/slang-utils/is-binary-operation.js | 16 + src/slang-utils/is-comment.js | 18 ++ src/slang-utils/sort-function-attributes.js | 40 +++ src/slangPrinter.js | 18 +- 61 files changed, 419 insertions(+), 354 deletions(-) delete mode 100644 src/common/slang-helpers.js create mode 100644 src/slang-printers/create-binary-operation-printer.js create mode 100644 src/slang-printers/print-binary-operation.js create mode 100644 src/slang-printers/print-comments.js create mode 100644 src/slang-printers/print-comparison-operation.js create mode 100644 src/slang-printers/print-function.js create mode 100644 src/slang-printers/print-logical-operation.js create mode 100644 src/slang-printers/print-preserving-empty-lines.js create mode 100644 src/slang-printers/print-string.js create mode 100644 src/slang-utils/create-kind-check-function.js create mode 100644 src/slang-utils/is-binary-operation.js create mode 100644 src/slang-utils/is-comment.js create mode 100644 src/slang-utils/sort-function-attributes.js diff --git a/src/common/printer-helpers.js b/src/common/printer-helpers.js index 15ce5e4de..858f9976a 100644 --- a/src/common/printer-helpers.js +++ b/src/common/printer-helpers.js @@ -8,7 +8,7 @@ import { const { group, indent, join, line, softline, hardline } = doc.builders; export const printComments = (node, path, options, filter = () => true) => { - if (!node.comments) return ''; + if (!node.comments) return []; const document = join( line, path diff --git a/src/common/slang-helpers.js b/src/common/slang-helpers.js deleted file mode 100644 index 8115ce604..000000000 --- a/src/common/slang-helpers.js +++ /dev/null @@ -1,282 +0,0 @@ -import { doc } from 'prettier'; -import { - isLast, - isNextLineEmpty, - isPrettier2 -} from './backward-compatibility.js'; - -const { dedent, group, hardline, indent, join, line } = doc.builders; - -export function createKindCheckFunction(kindsArray) { - const kinds = new Set(kindsArray); - return (node) => kinds.has(node?.kind); -} - -export const isBlockComment = createKindCheckFunction([ - 'MultiLineComment', - 'MultiLineNatSpecComment' -]); - -export const isLineComment = createKindCheckFunction([ - 'SingleLineComment', - 'SingleLineNatSpecComment' -]); - -export function isComment(node) { - return isBlockComment(node) || isLineComment(node); -} - -export function printPreservingEmptyLines(path, key, options, print) { - return path.map((childPath, index) => { - const node = childPath.getNode(); - - return [ - // Only attempt to prepend an empty line if `node` is not the first item - index > 0 && - // YulLabel adds a dedented line so we don't have to prepend a hardline. - (node.kind !== 'YulStatement' || node.variant.kind !== 'YulLabel') - ? hardline - : '', - print(childPath), - // Only attempt to append an empty line if `node` is not the last item - !isLast(childPath, key, index) && - // Append an empty line if the original text already had an one after the - // current `node` - isNextLineEmpty(options.originalText, options.locEnd(node)) - ? hardline - : '' - ]; - }, key); -} - -export function printFunction(functionName, node, path, print) { - return [ - group([ - functionName, - path.call(print, 'parameters'), - indent( - group([ - path.call(print, 'attributes'), - node.returns ? [line, path.call(print, 'returns')] : '', - node.body && node.body.variant !== ';' ? dedent(line) : '' - ]) - ) - ]), - node.body ? path.call(print, 'body') : '' - ]; -} - -const visibilityKeyWords = ['external', 'internal', 'public', 'private']; -const mutabilityKeyWords = ['pure', 'constant', 'payable', 'view']; - -export function sortFunctionAttributes(a, b) { - const aIsString = typeof a.variant === 'string'; - const bIsString = typeof b.variant === 'string'; - - if (aIsString && !bIsString) return -1; - if (bIsString && !aIsString) return 1; - - // Both are strings - if (aIsString && bIsString) { - // Visibility First - if (visibilityKeyWords.includes(a.variant)) return -1; - if (visibilityKeyWords.includes(b.variant)) return 1; - // State Mutability Second - if (mutabilityKeyWords.includes(a.variant)) return -1; - if (mutabilityKeyWords.includes(b.variant)) return 1; - // Virtual keyword last - } else { - // Both are nodes - if ( - a.variant.kind === 'OverrideSpecifier' && - b.variant.kind === 'ModifierInvocation' - ) - return -1; - if ( - b.variant.kind === 'OverrideSpecifier' && - a.variant.kind === 'ModifierInvocation' - ) - return 1; - } - return 0; -} - -export function hasNodeIgnoreComment(node) { - return ( - node?.comments && - node.comments.some( - (comment) => - comment.value - .slice(2, isBlockComment(comment) ? -2 : undefined) - .trim() === 'prettier-ignore' - ) - ); -} - -export const isBinaryOperation = createKindCheckFunction([ - 'AdditiveExpression', - 'MultiplicativeExpression', - 'ExponentiationExpression', - 'AssignmentExpression', - 'BitwiseAndExpression', - 'BitwiseOrExpression', - 'BitwiseXorExpression', - 'ComparisonExpression', - 'EqualityExpression', - 'AndExpression', - 'OrExpression', - 'ShiftExpression' -]); - -export const isBinaryOperationWithoutComparison = createKindCheckFunction([ - 'AdditiveExpression', - 'MultiplicativeExpression', - 'ExponentiationExpression', - 'AssignmentExpression', - 'BitwiseAndExpression', - 'BitwiseOrExpression', - 'BitwiseXorExpression', - 'AndExpression', - 'OrExpression', - 'ShiftExpression' -]); - -const binaryGroupRulesBuilder = (path) => (document) => { - const grandparentNode = path.getNode(2); - if (isBinaryOperationWithoutComparison(grandparentNode)) { - return document; - } - return group(document); -}; - -const binaryIndentRulesBuilder = (path) => (document) => { - let node = path.getNode(); - for (let i = 2; ; i += 2) { - const grandparentNode = path.getNode(i); - if (grandparentNode.kind === 'ReturnStatement') break; - if (!isBinaryOperationWithoutComparison(grandparentNode)) { - return indent(document); - } - if (node === grandparentNode.rightOperand.variant) break; - node = grandparentNode; - } - return document; -}; - -const isStatementWithoutIndentedOperation = createKindCheckFunction([ - 'ReturnStatement', - 'IfStatement', - 'WhileStatement' -]); - -const comparisonIndentRulesBuilder = (path) => (document) => { - let node = path.getNode(); - for (let i = 2; ; i += 2) { - const grandparentNode = path.getNode(i); - if (grandparentNode.kind === 'ExpressionStatement') { - if (path.getNode(i + 1).kind === 'ForStatementCondition') break; - else return indent(document); - } - if (isStatementWithoutIndentedOperation(grandparentNode)) break; - if (!isBinaryOperation(grandparentNode)) return indent(document); - if (node === grandparentNode.rightOperand.variant) break; - node = grandparentNode; - } - return document; -}; - -const logicalGroupRulesBuilder = (path) => (document) => - isBinaryOperation(path.getNode(2)) ? document : group(document); - -const logicalIndentRulesBuilder = (path, options) => (document) => { - let node = path.getNode(); - for (let i = 2; ; i += 2) { - const grandparentNode = path.getNode(i); - if (isStatementWithoutIndentedOperation(grandparentNode)) break; - if ( - options.experimentalTernaries && - grandparentNode.kind === 'ConditionalExpression' && - grandparentNode.operand.variant === node - ) - break; - if (!isBinaryOperation(grandparentNode)) return indent(document); - if (node === grandparentNode.rightOperand.variant) break; - node = grandparentNode; - } - return document; -}; - -export function rightOperandPrint(node, path, print) { - const rightOperand = [line, path.call(print, 'rightOperand')]; - - // If it's a single binary operation, avoid having a small right - // operand like - 1 on its own line - const shouldGroup = - !isBinaryOperation(node.leftOperand.variant) && - !isBinaryOperation(path.getNode(2)); - - return shouldGroup ? group(rightOperand) : rightOperand; -} - -export const binaryOperationPrintBuilder = - (groupRulesBuilder, indentRulesBuilder) => - ({ node, path, print, options }) => { - const groupRules = groupRulesBuilder(path); - const indentRules = indentRulesBuilder(path, options); - - return groupRules([ - path.call(print, 'leftOperand'), - ` ${node.operator}`, - indentRules(rightOperandPrint(node, path, print)) - ]); - }; - -export const binaryOperationPrint = binaryOperationPrintBuilder( - binaryGroupRulesBuilder, - binaryIndentRulesBuilder -); - -export const comparisonOperationPrint = binaryOperationPrintBuilder( - () => (document) => group(document), // always group - comparisonIndentRulesBuilder -); - -export const logicalOperationPrint = binaryOperationPrintBuilder( - logicalGroupRulesBuilder, - logicalIndentRulesBuilder -); - -export const locStart = (node) => node.loc.start; -export const locEnd = (node) => node.loc.end; - -export function printComments(node, path, options, filter = () => true) { - if (!node.comments) return []; - const document = join( - line, - path - .map((commentPath) => { - const comment = commentPath.getValue(); - if (comment.trailing || comment.leading || comment.printed) { - return null; - } - if (!filter(comment)) { - return null; - } - comment.printed = true; - // TODO: prettier Prints leading and trailing comments anyway. - comment.leading = false; - comment.trailing = false; - return options.printer.printComment(commentPath, options); - }, 'comments') - .filter(Boolean) - ); - - // The following if statement 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 */ - return isPrettier2 - ? document.parts // Prettier V2 - : document; // Prettier V3 - /* c8 ignore stop */ -} diff --git a/src/index.js b/src/index.js index 041353b12..96b7bbe4a 100644 --- a/src/index.js +++ b/src/index.js @@ -7,7 +7,7 @@ import parse from './parser.js'; import print from './printer.js'; import slangParse from './slangParser.js'; import slangPrint from './slangPrinter.js'; -import { isComment, isBlockComment } from './common/slang-helpers.js'; +import { isComment, isBlockComment } from './slang-utils/is-comment.js'; import { locEnd, locStart } from './slang-utils/loc.js'; const parserName = 'slang'; diff --git a/src/slang-comments/handlers/handleContractDefinitionComments.js b/src/slang-comments/handlers/handleContractDefinitionComments.js index 751388e61..c45eb522a 100644 --- a/src/slang-comments/handlers/handleContractDefinitionComments.js +++ b/src/slang-comments/handlers/handleContractDefinitionComments.js @@ -1,6 +1,6 @@ import { util } from 'prettier'; import { getNextNonSpaceNonCommentCharacter } from '../../common/backward-compatibility.js'; -import { locEnd } from '../../common/slang-helpers.js'; +import { locEnd } from '../../slang-utils/loc.js'; const { addLeadingComment, addDanglingComment, addTrailingComment } = util; diff --git a/src/slang-comments/handlers/handleWhileStatementComments.js b/src/slang-comments/handlers/handleWhileStatementComments.js index d17b40e3a..64b604a3f 100644 --- a/src/slang-comments/handlers/handleWhileStatementComments.js +++ b/src/slang-comments/handlers/handleWhileStatementComments.js @@ -1,6 +1,6 @@ import { util } from 'prettier'; import { getNextNonSpaceNonCommentCharacter } from '../../common/backward-compatibility.js'; -import { locEnd } from '../../common/slang-helpers.js'; +import { locEnd } from '../../slang-utils/loc.js'; const { addTrailingComment } = util; diff --git a/src/slang-comments/printer.js b/src/slang-comments/printer.js index 6e9c274d9..ce9646e78 100644 --- a/src/slang-comments/printer.js +++ b/src/slang-comments/printer.js @@ -1,5 +1,5 @@ import { doc } from 'prettier'; -import { isBlockComment, isLineComment } from '../common/slang-helpers.js'; +import { isBlockComment, isLineComment } from '../slang-utils/is-comment.js'; const { hardline, join, literalline } = doc.builders; diff --git a/src/slang-nodes/AdditiveExpression.js b/src/slang-nodes/AdditiveExpression.js index bba14ea8b..51d3f6dc7 100644 --- a/src/slang-nodes/AdditiveExpression.js +++ b/src/slang-nodes/AdditiveExpression.js @@ -1,4 +1,4 @@ -import { binaryOperationPrint } from '../common/slang-helpers.js'; +import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; import { createHugFunction } from '../slang-utils/create-hug-function.js'; import { SlangNode } from './SlangNode.js'; @@ -20,6 +20,6 @@ export class AdditiveExpression extends SlangNode { } print(path, print, options) { - return binaryOperationPrint({ node: this, path, print, options }); + return printBinaryOperation({ node: this, path, print, options }); } } diff --git a/src/slang-nodes/AndExpression.js b/src/slang-nodes/AndExpression.js index 3c860086e..25838c71b 100644 --- a/src/slang-nodes/AndExpression.js +++ b/src/slang-nodes/AndExpression.js @@ -1,4 +1,4 @@ -import { logicalOperationPrint } from '../common/slang-helpers.js'; +import { printLogicalOperation } from '../slang-printers/print-logical-operation.js'; import { SlangNode } from './SlangNode.js'; export class AndExpression extends SlangNode { @@ -15,6 +15,6 @@ export class AndExpression extends SlangNode { } print(path, print, options) { - return logicalOperationPrint({ node: this, path, print, options }); + return printLogicalOperation({ node: this, path, print, options }); } } diff --git a/src/slang-nodes/AssignmentExpression.js b/src/slang-nodes/AssignmentExpression.js index 3a8af59b7..68de7a785 100644 --- a/src/slang-nodes/AssignmentExpression.js +++ b/src/slang-nodes/AssignmentExpression.js @@ -1,5 +1,5 @@ import { doc } from 'prettier'; -import { isBinaryOperation } from '../common/slang-helpers.js'; +import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; import { SlangNode } from './SlangNode.js'; const { group, indent, line } = doc.builders; diff --git a/src/slang-nodes/BitwiseAndExpression.js b/src/slang-nodes/BitwiseAndExpression.js index 4e54703a6..e2c3315ca 100644 --- a/src/slang-nodes/BitwiseAndExpression.js +++ b/src/slang-nodes/BitwiseAndExpression.js @@ -1,4 +1,4 @@ -import { binaryOperationPrint } from '../common/slang-helpers.js'; +import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; import { createHugFunction } from '../slang-utils/create-hug-function.js'; import { SlangNode } from './SlangNode.js'; @@ -20,6 +20,6 @@ export class BitwiseAndExpression extends SlangNode { } print(path, print, options) { - return binaryOperationPrint({ node: this, path, print, options }); + return printBinaryOperation({ node: this, path, print, options }); } } diff --git a/src/slang-nodes/BitwiseOrExpression.js b/src/slang-nodes/BitwiseOrExpression.js index 0bf5e5b75..942007a75 100644 --- a/src/slang-nodes/BitwiseOrExpression.js +++ b/src/slang-nodes/BitwiseOrExpression.js @@ -1,4 +1,4 @@ -import { binaryOperationPrint } from '../common/slang-helpers.js'; +import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; import { createHugFunction } from '../slang-utils/create-hug-function.js'; import { SlangNode } from './SlangNode.js'; @@ -30,6 +30,6 @@ export class BitwiseOrExpression extends SlangNode { } print(path, print, options) { - return binaryOperationPrint({ node: this, path, print, options }); + return printBinaryOperation({ node: this, path, print, options }); } } diff --git a/src/slang-nodes/BitwiseXorExpression.js b/src/slang-nodes/BitwiseXorExpression.js index c43cc986b..3cb6578a8 100644 --- a/src/slang-nodes/BitwiseXorExpression.js +++ b/src/slang-nodes/BitwiseXorExpression.js @@ -1,4 +1,4 @@ -import { binaryOperationPrint } from '../common/slang-helpers.js'; +import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; import { createHugFunction } from '../slang-utils/create-hug-function.js'; import { SlangNode } from './SlangNode.js'; @@ -20,6 +20,6 @@ export class BitwiseXorExpression extends SlangNode { } print(path, print, options) { - return binaryOperationPrint({ node: this, path, print, options }); + return printBinaryOperation({ node: this, path, print, options }); } } diff --git a/src/slang-nodes/ComparisonExpression.js b/src/slang-nodes/ComparisonExpression.js index b32b3cf87..a9274f610 100644 --- a/src/slang-nodes/ComparisonExpression.js +++ b/src/slang-nodes/ComparisonExpression.js @@ -1,4 +1,4 @@ -import { comparisonOperationPrint } from '../common/slang-helpers.js'; +import { printComparisonOperation } from '../slang-printers/print-comparison-operation.js'; import { SlangNode } from './SlangNode.js'; export class ComparisonExpression extends SlangNode { @@ -15,6 +15,6 @@ export class ComparisonExpression extends SlangNode { } print(path, print, options) { - return comparisonOperationPrint({ node: this, path, print, options }); + return printComparisonOperation({ node: this, path, print, options }); } } diff --git a/src/slang-nodes/ConstructorAttributes.js b/src/slang-nodes/ConstructorAttributes.js index 342fc4ef0..4d7295df9 100644 --- a/src/slang-nodes/ConstructorAttributes.js +++ b/src/slang-nodes/ConstructorAttributes.js @@ -1,5 +1,5 @@ import { doc } from 'prettier'; -import { sortFunctionAttributes } from '../common/slang-helpers.js'; +import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; import { SlangNode } from './SlangNode.js'; const { line } = doc.builders; diff --git a/src/slang-nodes/ConstructorDefinition.js b/src/slang-nodes/ConstructorDefinition.js index 30433a334..84976edc3 100644 --- a/src/slang-nodes/ConstructorDefinition.js +++ b/src/slang-nodes/ConstructorDefinition.js @@ -1,4 +1,4 @@ -import { printFunction } from '../common/slang-helpers.js'; +import { printFunction } from '../slang-printers/print-function.js'; import { SlangNode } from './SlangNode.js'; export class ConstructorDefinition extends SlangNode { diff --git a/src/slang-nodes/ContractMembers.js b/src/slang-nodes/ContractMembers.js index 21fd75340..f3ddc4f07 100644 --- a/src/slang-nodes/ContractMembers.js +++ b/src/slang-nodes/ContractMembers.js @@ -1,9 +1,7 @@ import { doc } from 'prettier'; import { printSeparatedItem } from '../common/printer-helpers.js'; -import { - printComments, - printPreservingEmptyLines -} from '../common/slang-helpers.js'; +import { printComments } from '../slang-printers/print-comments.js'; +import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; import { SlangNode } from './SlangNode.js'; const { hardline } = doc.builders; diff --git a/src/slang-nodes/ElseBranch.js b/src/slang-nodes/ElseBranch.js index ecc8ed2ed..a28cc0d0b 100644 --- a/src/slang-nodes/ElseBranch.js +++ b/src/slang-nodes/ElseBranch.js @@ -1,6 +1,6 @@ import { doc } from 'prettier'; import { SlangNode } from './SlangNode.js'; -import { createKindCheckFunction } from '../common/slang-helpers.js'; +import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js'; const { group, indent, line } = doc.builders; diff --git a/src/slang-nodes/EqualityExpression.js b/src/slang-nodes/EqualityExpression.js index d94afacb7..92e162a03 100644 --- a/src/slang-nodes/EqualityExpression.js +++ b/src/slang-nodes/EqualityExpression.js @@ -1,4 +1,4 @@ -import { comparisonOperationPrint } from '../common/slang-helpers.js'; +import { printComparisonOperation } from '../slang-printers/print-comparison-operation.js'; import { SlangNode } from './SlangNode.js'; export class EqualityExpression extends SlangNode { @@ -15,6 +15,6 @@ export class EqualityExpression extends SlangNode { } print(path, print, options) { - return comparisonOperationPrint({ node: this, path, print, options }); + return printComparisonOperation({ node: this, path, print, options }); } } diff --git a/src/slang-nodes/ExponentiationExpression.js b/src/slang-nodes/ExponentiationExpression.js index 3c5df9edd..075ecbfe6 100644 --- a/src/slang-nodes/ExponentiationExpression.js +++ b/src/slang-nodes/ExponentiationExpression.js @@ -1,7 +1,7 @@ import { doc } from 'prettier'; import coerce from 'semver/functions/coerce.js'; import satisfies from 'semver/functions/satisfies.js'; -import { binaryOperationPrintBuilder } from '../common/slang-helpers.js'; +import { createBinaryOperationPrinter } from '../slang-printers/create-binary-operation-printer.js'; import { createHugFunction } from '../slang-utils/create-hug-function.js'; import { Loc } from '../slang-utils/loc.js'; import { SlangNode } from './SlangNode.js'; @@ -14,7 +14,7 @@ const { group, indent } = doc.builders; const tryToHug = createHugFunction(['**']); -const exponentiationExpressionPrint = binaryOperationPrintBuilder( +const printExponentiationExpression = createBinaryOperationPrinter( () => (document) => group(document), // always group () => (document) => indent(document) // always indent ); @@ -98,6 +98,6 @@ export class ExponentiationExpression extends SlangNode { } print(path, print, options) { - return exponentiationExpressionPrint({ node: this, path, print, options }); + return printExponentiationExpression({ node: this, path, print, options }); } } diff --git a/src/slang-nodes/FallbackFunctionAttributes.js b/src/slang-nodes/FallbackFunctionAttributes.js index dfde6ee9e..cabc721b8 100644 --- a/src/slang-nodes/FallbackFunctionAttributes.js +++ b/src/slang-nodes/FallbackFunctionAttributes.js @@ -1,5 +1,5 @@ import { doc } from 'prettier'; -import { sortFunctionAttributes } from '../common/slang-helpers.js'; +import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; import { SlangNode } from './SlangNode.js'; const { line } = doc.builders; diff --git a/src/slang-nodes/FallbackFunctionDefinition.js b/src/slang-nodes/FallbackFunctionDefinition.js index 7cd43f4f0..1eeded617 100644 --- a/src/slang-nodes/FallbackFunctionDefinition.js +++ b/src/slang-nodes/FallbackFunctionDefinition.js @@ -1,4 +1,4 @@ -import { printFunction } from '../common/slang-helpers.js'; +import { printFunction } from '../slang-printers/print-function.js'; import { SlangNode } from './SlangNode.js'; export class FallbackFunctionDefinition extends SlangNode { diff --git a/src/slang-nodes/FunctionAttributes.js b/src/slang-nodes/FunctionAttributes.js index 311889573..339305918 100644 --- a/src/slang-nodes/FunctionAttributes.js +++ b/src/slang-nodes/FunctionAttributes.js @@ -1,5 +1,5 @@ import { doc } from 'prettier'; -import { sortFunctionAttributes } from '../common/slang-helpers.js'; +import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; import { SlangNode } from './SlangNode.js'; const { line } = doc.builders; diff --git a/src/slang-nodes/FunctionDefinition.js b/src/slang-nodes/FunctionDefinition.js index 348b1c7b6..5bbbb059f 100644 --- a/src/slang-nodes/FunctionDefinition.js +++ b/src/slang-nodes/FunctionDefinition.js @@ -1,6 +1,6 @@ import coerce from 'semver/functions/coerce.js'; import satisfies from 'semver/functions/satisfies.js'; -import { printFunction } from '../common/slang-helpers.js'; +import { printFunction } from '../slang-printers/print-function.js'; import { SlangNode } from './SlangNode.js'; export class FunctionDefinition extends SlangNode { diff --git a/src/slang-nodes/FunctionType.js b/src/slang-nodes/FunctionType.js index e1cf753db..4dbe62f93 100644 --- a/src/slang-nodes/FunctionType.js +++ b/src/slang-nodes/FunctionType.js @@ -1,4 +1,4 @@ -import { printFunction } from '../common/slang-helpers.js'; +import { printFunction } from '../slang-printers/print-function.js'; import { SlangNode } from './SlangNode.js'; export class FunctionType extends SlangNode { diff --git a/src/slang-nodes/FunctionTypeAttributes.js b/src/slang-nodes/FunctionTypeAttributes.js index 899fa962d..1d97020ff 100644 --- a/src/slang-nodes/FunctionTypeAttributes.js +++ b/src/slang-nodes/FunctionTypeAttributes.js @@ -1,5 +1,5 @@ import { doc } from 'prettier'; -import { sortFunctionAttributes } from '../common/slang-helpers.js'; +import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; import { SlangNode } from './SlangNode.js'; const { line } = doc.builders; diff --git a/src/slang-nodes/HexStringLiteral.js b/src/slang-nodes/HexStringLiteral.js index 493248e03..723b24141 100644 --- a/src/slang-nodes/HexStringLiteral.js +++ b/src/slang-nodes/HexStringLiteral.js @@ -1,4 +1,4 @@ -import { printString } from '../common/util.js'; +import { printString } from '../slang-printers/print-string.js'; import { SlangNode } from './SlangNode.js'; export class HexStringLiteral extends SlangNode { diff --git a/src/slang-nodes/InterfaceMembers.js b/src/slang-nodes/InterfaceMembers.js index 2a6b6fd1e..4752b7fd5 100644 --- a/src/slang-nodes/InterfaceMembers.js +++ b/src/slang-nodes/InterfaceMembers.js @@ -1,6 +1,6 @@ import { doc } from 'prettier'; import { printSeparatedItem } from '../common/printer-helpers.js'; -import { printPreservingEmptyLines } from '../common/slang-helpers.js'; +import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; import { SlangNode } from './SlangNode.js'; const { hardline } = doc.builders; diff --git a/src/slang-nodes/LibraryMembers.js b/src/slang-nodes/LibraryMembers.js index 660b83291..250781812 100644 --- a/src/slang-nodes/LibraryMembers.js +++ b/src/slang-nodes/LibraryMembers.js @@ -1,6 +1,6 @@ import { doc } from 'prettier'; import { printSeparatedItem } from '../common/printer-helpers.js'; -import { printPreservingEmptyLines } from '../common/slang-helpers.js'; +import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; import { SlangNode } from './SlangNode.js'; const { hardline } = doc.builders; diff --git a/src/slang-nodes/MemberAccessExpression.js b/src/slang-nodes/MemberAccessExpression.js index fbed559c9..c3104d175 100644 --- a/src/slang-nodes/MemberAccessExpression.js +++ b/src/slang-nodes/MemberAccessExpression.js @@ -1,6 +1,6 @@ import { doc } from 'prettier'; import { isLabel } from '../common/util.js'; -import { createKindCheckFunction } from '../common/slang-helpers.js'; +import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js'; import { SlangNode } from './SlangNode.js'; const { group, indent, label, softline } = doc.builders; diff --git a/src/slang-nodes/ModifierAttributes.js b/src/slang-nodes/ModifierAttributes.js index ed71cd3a8..cb0188bc5 100644 --- a/src/slang-nodes/ModifierAttributes.js +++ b/src/slang-nodes/ModifierAttributes.js @@ -1,5 +1,5 @@ import { doc } from 'prettier'; -import { sortFunctionAttributes } from '../common/slang-helpers.js'; +import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; import { SlangNode } from './SlangNode.js'; const { line } = doc.builders; diff --git a/src/slang-nodes/ModifierDefinition.js b/src/slang-nodes/ModifierDefinition.js index 93fb71747..f2079e0c4 100644 --- a/src/slang-nodes/ModifierDefinition.js +++ b/src/slang-nodes/ModifierDefinition.js @@ -1,4 +1,4 @@ -import { printFunction } from '../common/slang-helpers.js'; +import { printFunction } from '../slang-printers/print-function.js'; import { SlangNode } from './SlangNode.js'; import { ParametersDeclaration } from './ParametersDeclaration.js'; import { Parameters } from './Parameters.js'; diff --git a/src/slang-nodes/ModifierInvocation.js b/src/slang-nodes/ModifierInvocation.js index 3c13d95ff..10e585ba6 100644 --- a/src/slang-nodes/ModifierInvocation.js +++ b/src/slang-nodes/ModifierInvocation.js @@ -1,4 +1,4 @@ -import { isComment } from '../common/slang-helpers.js'; +import { isComment } from '../slang-utils/is-comment.js'; import { SlangNode } from './SlangNode.js'; export class ModifierInvocation extends SlangNode { diff --git a/src/slang-nodes/MultiplicativeExpression.js b/src/slang-nodes/MultiplicativeExpression.js index a5732cb21..f990153c3 100644 --- a/src/slang-nodes/MultiplicativeExpression.js +++ b/src/slang-nodes/MultiplicativeExpression.js @@ -1,4 +1,4 @@ -import { binaryOperationPrint } from '../common/slang-helpers.js'; +import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; import { createHugFunction } from '../slang-utils/create-hug-function.js'; import { SlangNode } from './SlangNode.js'; @@ -35,6 +35,6 @@ export class MultiplicativeExpression extends SlangNode { } print(path, print, options) { - return binaryOperationPrint({ node: this, path, print, options }); + return printBinaryOperation({ node: this, path, print, options }); } } diff --git a/src/slang-nodes/OrExpression.js b/src/slang-nodes/OrExpression.js index 12ac0f1b5..d1f51dc1c 100644 --- a/src/slang-nodes/OrExpression.js +++ b/src/slang-nodes/OrExpression.js @@ -1,4 +1,4 @@ -import { logicalOperationPrint } from '../common/slang-helpers.js'; +import { printLogicalOperation } from '../slang-printers/print-logical-operation.js'; import { createHugFunction } from '../slang-utils/create-hug-function.js'; import { SlangNode } from './SlangNode.js'; @@ -20,6 +20,6 @@ export class OrExpression extends SlangNode { } print(path, print, options) { - return logicalOperationPrint({ node: this, path, print, options }); + return printLogicalOperation({ node: this, path, print, options }); } } diff --git a/src/slang-nodes/Parameters.js b/src/slang-nodes/Parameters.js index 59dc98233..cdab9064e 100644 --- a/src/slang-nodes/Parameters.js +++ b/src/slang-nodes/Parameters.js @@ -2,7 +2,7 @@ import { printSeparatedItem, printSeparatedList } from '../common/printer-helpers.js'; -import { printComments } from '../common/slang-helpers.js'; +import { printComments } from '../slang-printers/print-comments.js'; import { SlangNode } from './SlangNode.js'; export class Parameters extends SlangNode { diff --git a/src/slang-nodes/ReceiveFunctionAttributes.js b/src/slang-nodes/ReceiveFunctionAttributes.js index ad80bab78..7b0292929 100644 --- a/src/slang-nodes/ReceiveFunctionAttributes.js +++ b/src/slang-nodes/ReceiveFunctionAttributes.js @@ -1,5 +1,5 @@ import { doc } from 'prettier'; -import { sortFunctionAttributes } from '../common/slang-helpers.js'; +import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; import { SlangNode } from './SlangNode.js'; const { line } = doc.builders; diff --git a/src/slang-nodes/ReceiveFunctionDefinition.js b/src/slang-nodes/ReceiveFunctionDefinition.js index 1ac9d3e4c..4abec0828 100644 --- a/src/slang-nodes/ReceiveFunctionDefinition.js +++ b/src/slang-nodes/ReceiveFunctionDefinition.js @@ -1,4 +1,4 @@ -import { printFunction } from '../common/slang-helpers.js'; +import { printFunction } from '../slang-printers/print-function.js'; import { SlangNode } from './SlangNode.js'; export class ReceiveFunctionDefinition extends SlangNode { diff --git a/src/slang-nodes/ShiftExpression.js b/src/slang-nodes/ShiftExpression.js index efbd55c96..7622cc061 100644 --- a/src/slang-nodes/ShiftExpression.js +++ b/src/slang-nodes/ShiftExpression.js @@ -1,4 +1,4 @@ -import { binaryOperationPrint } from '../common/slang-helpers.js'; +import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; import { createHugFunction } from '../slang-utils/create-hug-function.js'; import { SlangNode } from './SlangNode.js'; @@ -29,6 +29,6 @@ export class ShiftExpression extends SlangNode { } print(path, print, options) { - return binaryOperationPrint({ node: this, path, print, options }); + return printBinaryOperation({ node: this, path, print, options }); } } diff --git a/src/slang-nodes/SlangNode.js b/src/slang-nodes/SlangNode.js index 3a9d7f163..35de0ea6e 100644 --- a/src/slang-nodes/SlangNode.js +++ b/src/slang-nodes/SlangNode.js @@ -1,4 +1,4 @@ -import { isComment } from '../common/slang-helpers.js'; +import { isComment } from '../slang-utils/is-comment.js'; import { Loc } from '../slang-utils/loc.js'; const comments = []; diff --git a/src/slang-nodes/SourceUnitMembers.js b/src/slang-nodes/SourceUnitMembers.js index 1b12be354..a9ebf130e 100644 --- a/src/slang-nodes/SourceUnitMembers.js +++ b/src/slang-nodes/SourceUnitMembers.js @@ -1,4 +1,4 @@ -import { printPreservingEmptyLines } from '../common/slang-helpers.js'; +import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; import { SlangNode } from './SlangNode.js'; export class SourceUnitMembers extends SlangNode { diff --git a/src/slang-nodes/Statements.js b/src/slang-nodes/Statements.js index 4ffcb7f0d..c0f9fa4da 100644 --- a/src/slang-nodes/Statements.js +++ b/src/slang-nodes/Statements.js @@ -1,9 +1,8 @@ import { doc } from 'prettier'; import { printSeparatedItem } from '../common/printer-helpers.js'; -import { - printComments, - printPreservingEmptyLines -} from '../common/slang-helpers.js'; +import { printComments } from '../slang-printers/print-comments.js'; +import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; + import { SlangNode } from './SlangNode.js'; const { hardline } = doc.builders; diff --git a/src/slang-nodes/StringLiteral.js b/src/slang-nodes/StringLiteral.js index 07b36aecb..2b9202172 100644 --- a/src/slang-nodes/StringLiteral.js +++ b/src/slang-nodes/StringLiteral.js @@ -1,4 +1,4 @@ -import { printString } from '../common/util.js'; +import { printString } from '../slang-printers/print-string.js'; import { SlangNode } from './SlangNode.js'; export class StringLiteral extends SlangNode { diff --git a/src/slang-nodes/TupleValues.js b/src/slang-nodes/TupleValues.js index b9a262906..450578c46 100644 --- a/src/slang-nodes/TupleValues.js +++ b/src/slang-nodes/TupleValues.js @@ -1,5 +1,5 @@ import { printSeparatedList } from '../common/printer-helpers.js'; -import { isBinaryOperation } from '../common/slang-helpers.js'; +import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; import { SlangNode } from './SlangNode.js'; export class TupleValues extends SlangNode { diff --git a/src/slang-nodes/UnicodeStringLiteral.js b/src/slang-nodes/UnicodeStringLiteral.js index 821092d8c..73517eae5 100644 --- a/src/slang-nodes/UnicodeStringLiteral.js +++ b/src/slang-nodes/UnicodeStringLiteral.js @@ -1,4 +1,4 @@ -import { printString } from '../common/util.js'; +import { printString } from '../slang-printers/print-string.js'; import { SlangNode } from './SlangNode.js'; export class UnicodeStringLiteral extends SlangNode { diff --git a/src/slang-nodes/UnnamedFunctionAttributes.js b/src/slang-nodes/UnnamedFunctionAttributes.js index ed3761a7f..72fb2efda 100644 --- a/src/slang-nodes/UnnamedFunctionAttributes.js +++ b/src/slang-nodes/UnnamedFunctionAttributes.js @@ -1,5 +1,5 @@ import { doc } from 'prettier'; -import { sortFunctionAttributes } from '../common/slang-helpers.js'; +import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; import { SlangNode } from './SlangNode.js'; const { line } = doc.builders; diff --git a/src/slang-nodes/UnnamedFunctionDefinition.js b/src/slang-nodes/UnnamedFunctionDefinition.js index b2595c2e4..ead1da672 100644 --- a/src/slang-nodes/UnnamedFunctionDefinition.js +++ b/src/slang-nodes/UnnamedFunctionDefinition.js @@ -1,4 +1,4 @@ -import { printFunction } from '../common/slang-helpers.js'; +import { printFunction } from '../slang-printers/print-function.js'; import { SlangNode } from './SlangNode.js'; export class UnnamedFunctionDefinition extends SlangNode { diff --git a/src/slang-nodes/YulStatements.js b/src/slang-nodes/YulStatements.js index 8c693d470..f498c7c47 100644 --- a/src/slang-nodes/YulStatements.js +++ b/src/slang-nodes/YulStatements.js @@ -1,9 +1,7 @@ import { doc } from 'prettier'; import { printSeparatedItem } from '../common/printer-helpers.js'; -import { - printComments, - printPreservingEmptyLines -} from '../common/slang-helpers.js'; +import { printComments } from '../slang-printers/print-comments.js'; +import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; import { SlangNode } from './SlangNode.js'; const { hardline } = doc.builders; diff --git a/src/slang-printers/create-binary-operation-printer.js b/src/slang-printers/create-binary-operation-printer.js new file mode 100644 index 000000000..1ac732228 --- /dev/null +++ b/src/slang-printers/create-binary-operation-printer.js @@ -0,0 +1,29 @@ +import { doc } from 'prettier'; +import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; + +const { group, line } = doc.builders; + +function rightOperandPrint(node, path, print) { + const rightOperand = [line, path.call(print, 'rightOperand')]; + + // If it's a single binary operation, avoid having a small right + // operand like - 1 on its own line + const shouldGroup = + !isBinaryOperation(node.leftOperand.variant) && + !isBinaryOperation(path.getNode(2)); + + return shouldGroup ? group(rightOperand) : rightOperand; +} + +export const createBinaryOperationPrinter = + (groupRulesBuilder, indentRulesBuilder) => + ({ node, path, print, options }) => { + const groupRules = groupRulesBuilder(path); + const indentRules = indentRulesBuilder(path, options); + + return groupRules([ + path.call(print, 'leftOperand'), + ` ${node.operator}`, + indentRules(rightOperandPrint(node, path, print)) + ]); + }; diff --git a/src/slang-printers/print-binary-operation.js b/src/slang-printers/print-binary-operation.js new file mode 100644 index 000000000..6aee39f90 --- /dev/null +++ b/src/slang-printers/print-binary-operation.js @@ -0,0 +1,45 @@ +import { doc } from 'prettier'; +import { createBinaryOperationPrinter } from './create-binary-operation-printer.js'; +import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js'; + +const { group, indent } = doc.builders; + +const isBinaryOperationWithoutComparison = createKindCheckFunction([ + 'AdditiveExpression', + 'MultiplicativeExpression', + 'ExponentiationExpression', + 'AssignmentExpression', + 'BitwiseAndExpression', + 'BitwiseOrExpression', + 'BitwiseXorExpression', + 'AndExpression', + 'OrExpression', + 'ShiftExpression' +]); + +const binaryGroupRulesBuilder = (path) => (document) => { + const grandparentNode = path.getNode(2); + if (isBinaryOperationWithoutComparison(grandparentNode)) { + return document; + } + return group(document); +}; + +const binaryIndentRulesBuilder = (path) => (document) => { + let node = path.getNode(); + for (let i = 2; ; i += 2) { + const grandparentNode = path.getNode(i); + if (grandparentNode.kind === 'ReturnStatement') break; + if (!isBinaryOperationWithoutComparison(grandparentNode)) { + return indent(document); + } + if (node === grandparentNode.rightOperand.variant) break; + node = grandparentNode; + } + return document; +}; + +export const printBinaryOperation = createBinaryOperationPrinter( + binaryGroupRulesBuilder, + binaryIndentRulesBuilder +); diff --git a/src/slang-printers/print-comments.js b/src/slang-printers/print-comments.js new file mode 100644 index 000000000..7450a0095 --- /dev/null +++ b/src/slang-printers/print-comments.js @@ -0,0 +1,36 @@ +import { doc } from 'prettier'; +import { isPrettier2 } from '../common/backward-compatibility.js'; + +const { join, line } = doc.builders; + +export function printComments(node, path, options, filter = () => true) { + if (!node.comments) return []; + const document = join( + line, + path + .map((commentPath) => { + const comment = commentPath.getValue(); + if (comment.trailing || comment.leading || comment.printed) { + return null; + } + if (!filter(comment)) { + return null; + } + comment.printed = true; + // TODO: prettier Prints leading and trailing comments anyway. + comment.leading = false; + comment.trailing = false; + return options.printer.printComment(commentPath, options); + }, 'comments') + .filter(Boolean) + ); + + // The following if statement 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 */ + return isPrettier2 + ? document.parts // Prettier V2 + : document; // Prettier V3 + /* c8 ignore stop */ +} diff --git a/src/slang-printers/print-comparison-operation.js b/src/slang-printers/print-comparison-operation.js new file mode 100644 index 000000000..09a84c58b --- /dev/null +++ b/src/slang-printers/print-comparison-operation.js @@ -0,0 +1,33 @@ +import { doc } from 'prettier'; +import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js'; +import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; +import { createBinaryOperationPrinter } from './create-binary-operation-printer.js'; + +const { group, indent } = doc.builders; + +const isStatementWithoutIndentedOperation = createKindCheckFunction([ + 'ReturnStatement', + 'IfStatement', + 'WhileStatement' +]); + +const comparisonIndentRulesBuilder = (path) => (document) => { + let node = path.getNode(); + for (let i = 2; ; i += 2) { + const grandparentNode = path.getNode(i); + if (grandparentNode.kind === 'ExpressionStatement') { + if (path.getNode(i + 1).kind === 'ForStatementCondition') break; + else return indent(document); + } + if (isStatementWithoutIndentedOperation(grandparentNode)) break; + if (!isBinaryOperation(grandparentNode)) return indent(document); + if (node === grandparentNode.rightOperand.variant) break; + node = grandparentNode; + } + return document; +}; + +export const printComparisonOperation = createBinaryOperationPrinter( + () => (document) => group(document), // always group + comparisonIndentRulesBuilder +); diff --git a/src/slang-printers/print-function.js b/src/slang-printers/print-function.js new file mode 100644 index 000000000..5f97ecdb6 --- /dev/null +++ b/src/slang-printers/print-function.js @@ -0,0 +1,20 @@ +import { doc } from 'prettier'; + +const { dedent, group, indent, line } = doc.builders; + +export function printFunction(functionName, node, path, print) { + return [ + group([ + functionName, + path.call(print, 'parameters'), + indent( + group([ + path.call(print, 'attributes'), + node.returns ? [line, path.call(print, 'returns')] : '', + node.body && node.body.variant !== ';' ? dedent(line) : '' + ]) + ) + ]), + node.body ? path.call(print, 'body') : '' + ]; +} diff --git a/src/slang-printers/print-logical-operation.js b/src/slang-printers/print-logical-operation.js new file mode 100644 index 000000000..5eb588b01 --- /dev/null +++ b/src/slang-printers/print-logical-operation.js @@ -0,0 +1,38 @@ +import { doc } from 'prettier'; +import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js'; +import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; +import { createBinaryOperationPrinter } from './create-binary-operation-printer.js'; + +const { group, indent } = doc.builders; + +const isStatementWithoutIndentedOperation = createKindCheckFunction([ + 'ReturnStatement', + 'IfStatement', + 'WhileStatement' +]); + +const logicalGroupRulesBuilder = (path) => (document) => + isBinaryOperation(path.getNode(2)) ? document : group(document); + +const logicalIndentRulesBuilder = (path, options) => (document) => { + let node = path.getNode(); + for (let i = 2; ; i += 2) { + const grandparentNode = path.getNode(i); + if (isStatementWithoutIndentedOperation(grandparentNode)) break; + if ( + options.experimentalTernaries && + grandparentNode.kind === 'ConditionalExpression' && + grandparentNode.operand.variant === node + ) + break; + if (!isBinaryOperation(grandparentNode)) return indent(document); + if (node === grandparentNode.rightOperand.variant) break; + node = grandparentNode; + } + return document; +}; + +export const printLogicalOperation = createBinaryOperationPrinter( + logicalGroupRulesBuilder, + logicalIndentRulesBuilder +); diff --git a/src/slang-printers/print-preserving-empty-lines.js b/src/slang-printers/print-preserving-empty-lines.js new file mode 100644 index 000000000..1240d0add --- /dev/null +++ b/src/slang-printers/print-preserving-empty-lines.js @@ -0,0 +1,27 @@ +import { doc } from 'prettier'; +import { isLast, isNextLineEmpty } from '../common/backward-compatibility.js'; + +const { hardline } = doc.builders; + +export function printPreservingEmptyLines(path, key, options, print) { + return path.map((childPath, index) => { + const node = childPath.getNode(); + + return [ + // Only attempt to prepend an empty line if `node` is not the first item + index > 0 && + // YulLabel adds a dedented line so we don't have to prepend a hardline. + (node.kind !== 'YulStatement' || node.variant.kind !== 'YulLabel') + ? hardline + : '', + print(childPath), + // Only attempt to append an empty line if `node` is not the last item + !isLast(childPath, key, index) && + // Append an empty line if the original text already had an one after the + // current `node` + isNextLineEmpty(options.originalText, options.locEnd(node)) + ? hardline + : '' + ]; + }, key); +} diff --git a/src/slang-printers/print-string.js b/src/slang-printers/print-string.js new file mode 100644 index 000000000..23e327824 --- /dev/null +++ b/src/slang-printers/print-string.js @@ -0,0 +1,36 @@ +import { util } from 'prettier'; + +const double = { quote: '"', regex: /"/g }; +const single = { quote: "'", regex: /'/g }; + +export function printString(rawContent, options) { + const preferred = options.singleQuote ? single : double; + const alternate = preferred === single ? double : single; + + let shouldUseAlternateQuote = false; + + // If `rawContent` contains at least one of the quote preferred for enclosing + // the string, we might want to enclose with the alternate quote instead, to + // minimize the number of escaped quotes. + // Also check for the alternate quote, to determine if we're allowed to swap + // the quotes on a DirectiveLiteral. + if ( + rawContent.includes(preferred.quote) || + rawContent.includes(alternate.quote) + ) { + const numPreferredQuotes = (rawContent.match(preferred.regex) || []).length; + const numAlternateQuotes = (rawContent.match(alternate.regex) || []).length; + + shouldUseAlternateQuote = numPreferredQuotes > numAlternateQuotes; + } + + const enclosingQuote = shouldUseAlternateQuote + ? alternate.quote + : preferred.quote; + + // It might sound unnecessary to use `makeString` even if the string already + // is enclosed with `enclosingQuote`, but it isn't. The string could contain + // unnecessary escapes (such as in `"\'"`). Always using `makeString` makes + // sure that we consistently output the minimum amount of escaped quotes. + return util.makeString(rawContent, enclosingQuote); +} diff --git a/src/slang-utils/create-hug-function.js b/src/slang-utils/create-hug-function.js index b4ccaef55..c86ab8ee3 100644 --- a/src/slang-utils/create-hug-function.js +++ b/src/slang-utils/create-hug-function.js @@ -1,8 +1,8 @@ -import { isBinaryOperation } from '../common/slang-helpers.js'; import { Expression } from '../slang-nodes/Expression.js'; import { TupleExpression } from '../slang-nodes/TupleExpression.js'; import { TupleValues } from '../slang-nodes/TupleValues.js'; import { TupleValue } from '../slang-nodes/TupleValue.js'; +import { isBinaryOperation } from './is-binary-operation.js'; export function createHugFunction(huggableOperators) { const operators = new Set(huggableOperators); diff --git a/src/slang-utils/create-kind-check-function.js b/src/slang-utils/create-kind-check-function.js new file mode 100644 index 000000000..4f3517ed8 --- /dev/null +++ b/src/slang-utils/create-kind-check-function.js @@ -0,0 +1,4 @@ +export function createKindCheckFunction(kindsArray) { + const kinds = new Set(kindsArray); + return (node) => kinds.has(node?.kind); +} diff --git a/src/slang-utils/is-binary-operation.js b/src/slang-utils/is-binary-operation.js new file mode 100644 index 000000000..be3e669b2 --- /dev/null +++ b/src/slang-utils/is-binary-operation.js @@ -0,0 +1,16 @@ +import { createKindCheckFunction } from './create-kind-check-function.js'; + +export const isBinaryOperation = createKindCheckFunction([ + 'AdditiveExpression', + 'MultiplicativeExpression', + 'ExponentiationExpression', + 'AssignmentExpression', + 'BitwiseAndExpression', + 'BitwiseOrExpression', + 'BitwiseXorExpression', + 'ComparisonExpression', + 'EqualityExpression', + 'AndExpression', + 'OrExpression', + 'ShiftExpression' +]); diff --git a/src/slang-utils/is-comment.js b/src/slang-utils/is-comment.js new file mode 100644 index 000000000..24ef85e9d --- /dev/null +++ b/src/slang-utils/is-comment.js @@ -0,0 +1,18 @@ +import { createKindCheckFunction } from './create-kind-check-function.js'; + +export const isBlockComment = createKindCheckFunction([ + 'MultiLineComment', + 'MultiLineNatSpecComment' +]); + +export const isLineComment = createKindCheckFunction([ + 'SingleLineComment', + 'SingleLineNatSpecComment' +]); + +export const isComment = createKindCheckFunction([ + 'MultiLineComment', + 'MultiLineNatSpecComment', + 'SingleLineComment', + 'SingleLineNatSpecComment' +]); diff --git a/src/slang-utils/sort-function-attributes.js b/src/slang-utils/sort-function-attributes.js new file mode 100644 index 000000000..fd1eee9b0 --- /dev/null +++ b/src/slang-utils/sort-function-attributes.js @@ -0,0 +1,40 @@ +const visibilityKeyWords = new Set([ + 'external', + 'internal', + 'public', + 'private' +]); + +const mutabilityKeyWords = new Set(['pure', 'constant', 'payable', 'view']); + +export function sortFunctionAttributes(a, b) { + const aIsString = typeof a.variant === 'string'; + const bIsString = typeof b.variant === 'string'; + + if (aIsString && !bIsString) return -1; + if (bIsString && !aIsString) return 1; + + // Both are strings + if (aIsString && bIsString) { + // Visibility First + if (visibilityKeyWords.has(a.variant)) return -1; + if (visibilityKeyWords.has(b.variant)) return 1; + // State Mutability Second + if (mutabilityKeyWords.has(a.variant)) return -1; + if (mutabilityKeyWords.has(b.variant)) return 1; + // Virtual keyword last + } else { + // Both are nodes + if ( + a.variant.kind === 'OverrideSpecifier' && + b.variant.kind === 'ModifierInvocation' + ) + return -1; + if ( + b.variant.kind === 'OverrideSpecifier' && + a.variant.kind === 'ModifierInvocation' + ) + return 1; + } + return 0; +} diff --git a/src/slangPrinter.js b/src/slangPrinter.js index 79b41b583..ef2ba4dfc 100644 --- a/src/slangPrinter.js +++ b/src/slangPrinter.js @@ -1,8 +1,6 @@ import * as nodes from './slang-nodes/index.js'; -import { - prettierVersionSatisfies -} from './common/util.js'; -import { hasNodeIgnoreComment } from './common/slang-helpers.js'; +import { prettierVersionSatisfies } from './common/util.js'; +import { isBlockComment } from './slang-utils/is-comment.js'; import ignoreComments from './comments/ignore.js'; let checked = false; @@ -17,6 +15,18 @@ function prettierVersionCheck() { checked = true; } +function hasNodeIgnoreComment(node) { + return ( + node?.comments && + node.comments.some( + (comment) => + comment.value + .slice(2, isBlockComment(comment) ? -2 : undefined) + .trim() === 'prettier-ignore' + ) + ); +} + function genericPrint(path, options, print) { prettierVersionCheck(); From c9b09d756d36e55fc4d4d846a88b3c41710b018d Mon Sep 17 00:00:00 2001 From: Klaus Date: Mon, 15 Jul 2024 12:31:25 +1200 Subject: [PATCH 078/160] missing using Loc class instead of object --- src/slang-utils/create-hug-function.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/slang-utils/create-hug-function.js b/src/slang-utils/create-hug-function.js index c86ab8ee3..35160f8ef 100644 --- a/src/slang-utils/create-hug-function.js +++ b/src/slang-utils/create-hug-function.js @@ -3,6 +3,7 @@ import { TupleExpression } from '../slang-nodes/TupleExpression.js'; import { TupleValues } from '../slang-nodes/TupleValues.js'; import { TupleValue } from '../slang-nodes/TupleValue.js'; import { isBinaryOperation } from './is-binary-operation.js'; +import { Loc } from './loc.js'; export function createHugFunction(huggableOperators) { const operators = new Set(huggableOperators); @@ -20,18 +21,18 @@ export function createHugFunction(huggableOperators) { return new Expression({ kind: 'Expression', - loc: { ...loc }, + loc: new Loc(loc), variant: new TupleExpression({ kind: 'TupleExpression', - loc: { ...loc }, + loc: new Loc(loc), openParen: '(', items: new TupleValues({ kind: 'TupleValues', - loc: { ...loc }, + loc: new Loc(loc), items: [ new TupleValue({ kind: 'TupleValue', - loc: { ...loc }, + loc: new Loc(loc), expression: node }) ], From b5a60c68e144b9c042d711a6b862f5fdc4e785ae Mon Sep 17 00:00:00 2001 From: Klaus Date: Mon, 15 Jul 2024 12:36:42 +1200 Subject: [PATCH 079/160] updating dependencies --- package-lock.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package-lock.json b/package-lock.json index 510f0bda2..57f1d48b2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6466,6 +6466,7 @@ "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz", "integrity": "sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==", "dev": true, + "license": "MIT", "bin": { "prettier": "bin/prettier.cjs" }, From 7cb86e7ede7a17ebb46be3cfac6746635be049d3 Mon Sep 17 00:00:00 2001 From: Klaus Date: Mon, 15 Jul 2024 13:08:18 +1200 Subject: [PATCH 080/160] comments no longer collected out of scope --- src/slang-nodes/ABICoderPragma.js | 4 ++-- src/slang-nodes/AdditiveExpression.js | 4 ++-- src/slang-nodes/AddressType.js | 4 ++-- src/slang-nodes/AndExpression.js | 4 ++-- src/slang-nodes/ArgumentsDeclaration.js | 4 ++-- src/slang-nodes/ArrayExpression.js | 4 ++-- src/slang-nodes/ArrayTypeName.js | 4 ++-- src/slang-nodes/ArrayValues.js | 4 ++-- src/slang-nodes/AssemblyFlags.js | 4 ++-- src/slang-nodes/AssemblyFlagsDeclaration.js | 4 ++-- src/slang-nodes/AssemblyStatement.js | 4 ++-- src/slang-nodes/AssignmentExpression.js | 4 ++-- src/slang-nodes/BitwiseAndExpression.js | 4 ++-- src/slang-nodes/BitwiseOrExpression.js | 4 ++-- src/slang-nodes/BitwiseXorExpression.js | 4 ++-- src/slang-nodes/Block.js | 4 ++-- src/slang-nodes/BreakStatement.js | 4 ++-- src/slang-nodes/CallOptions.js | 4 ++-- src/slang-nodes/CallOptionsExpression.js | 4 ++-- src/slang-nodes/CatchClause.js | 4 ++-- src/slang-nodes/CatchClauseError.js | 4 ++-- src/slang-nodes/CatchClauses.js | 4 ++-- src/slang-nodes/ComparisonExpression.js | 4 ++-- src/slang-nodes/ConditionalExpression.js | 4 ++-- src/slang-nodes/ConstantDefinition.js | 4 ++-- src/slang-nodes/ConstructorAttribute.js | 4 ++-- src/slang-nodes/ConstructorAttributes.js | 4 ++-- src/slang-nodes/ConstructorDefinition.js | 4 ++-- src/slang-nodes/ContinueStatement.js | 4 ++-- src/slang-nodes/ContractDefinition.js | 4 ++-- src/slang-nodes/ContractMember.js | 4 ++-- src/slang-nodes/ContractMembers.js | 4 ++-- src/slang-nodes/DecimalNumberExpression.js | 4 ++-- src/slang-nodes/DoWhileStatement.js | 4 ++-- src/slang-nodes/ElementaryType.js | 4 ++-- src/slang-nodes/ElseBranch.js | 4 ++-- src/slang-nodes/EmitStatement.js | 4 ++-- src/slang-nodes/EnumDefinition.js | 4 ++-- src/slang-nodes/EnumMembers.js | 4 ++-- src/slang-nodes/EqualityExpression.js | 4 ++-- src/slang-nodes/ErrorDefinition.js | 4 ++-- src/slang-nodes/ErrorParameter.js | 4 ++-- src/slang-nodes/ErrorParameters.js | 4 ++-- src/slang-nodes/ErrorParametersDeclaration.js | 4 ++-- src/slang-nodes/EventDefinition.js | 4 ++-- src/slang-nodes/EventParameter.js | 4 ++-- src/slang-nodes/EventParameters.js | 4 ++-- src/slang-nodes/EventParametersDeclaration.js | 4 ++-- src/slang-nodes/ExperimentalFeature.js | 4 ++-- src/slang-nodes/ExperimentalPragma.js | 4 ++-- src/slang-nodes/ExponentiationExpression.js | 4 ++-- src/slang-nodes/Expression.js | 4 ++-- src/slang-nodes/ExpressionStatement.js | 4 ++-- src/slang-nodes/FallbackFunctionAttribute.js | 4 ++-- src/slang-nodes/FallbackFunctionAttributes.js | 4 ++-- src/slang-nodes/FallbackFunctionDefinition.js | 4 ++-- src/slang-nodes/ForStatement.js | 4 ++-- src/slang-nodes/ForStatementCondition.js | 4 ++-- src/slang-nodes/ForStatementInitialization.js | 4 ++-- src/slang-nodes/FunctionAttribute.js | 4 ++-- src/slang-nodes/FunctionAttributes.js | 4 ++-- src/slang-nodes/FunctionBody.js | 4 ++-- src/slang-nodes/FunctionCallExpression.js | 4 ++-- src/slang-nodes/FunctionDefinition.js | 4 ++-- src/slang-nodes/FunctionName.js | 4 ++-- src/slang-nodes/FunctionType.js | 4 ++-- src/slang-nodes/FunctionTypeAttribute.js | 4 ++-- src/slang-nodes/FunctionTypeAttributes.js | 4 ++-- src/slang-nodes/HexNumberExpression.js | 4 ++-- src/slang-nodes/HexStringLiteral.js | 4 ++-- src/slang-nodes/HexStringLiterals.js | 4 ++-- src/slang-nodes/IdentifierPath.js | 4 ++-- src/slang-nodes/IfStatement.js | 4 ++-- src/slang-nodes/ImportAlias.js | 4 ++-- src/slang-nodes/ImportClause.js | 4 ++-- src/slang-nodes/ImportDeconstruction.js | 4 ++-- src/slang-nodes/ImportDeconstructionSymbol.js | 4 ++-- src/slang-nodes/ImportDeconstructionSymbols.js | 4 ++-- src/slang-nodes/ImportDirective.js | 4 ++-- src/slang-nodes/IndexAccessEnd.js | 4 ++-- src/slang-nodes/IndexAccessExpression.js | 4 ++-- src/slang-nodes/InheritanceSpecifier.js | 4 ++-- src/slang-nodes/InheritanceType.js | 4 ++-- src/slang-nodes/InheritanceTypes.js | 4 ++-- src/slang-nodes/InterfaceDefinition.js | 4 ++-- src/slang-nodes/InterfaceMembers.js | 4 ++-- src/slang-nodes/LibraryDefinition.js | 4 ++-- src/slang-nodes/LibraryMembers.js | 4 ++-- src/slang-nodes/MappingKey.js | 4 ++-- src/slang-nodes/MappingKeyType.js | 4 ++-- src/slang-nodes/MappingType.js | 4 ++-- src/slang-nodes/MappingValue.js | 4 ++-- src/slang-nodes/MemberAccess.js | 4 ++-- src/slang-nodes/MemberAccessExpression.js | 4 ++-- src/slang-nodes/ModifierAttribute.js | 4 ++-- src/slang-nodes/ModifierAttributes.js | 4 ++-- src/slang-nodes/ModifierDefinition.js | 4 ++-- src/slang-nodes/ModifierInvocation.js | 4 ++-- src/slang-nodes/MultiplicativeExpression.js | 4 ++-- src/slang-nodes/NamedArgument.js | 4 ++-- src/slang-nodes/NamedArgumentGroup.js | 4 ++-- src/slang-nodes/NamedArguments.js | 4 ++-- src/slang-nodes/NamedArgumentsDeclaration.js | 4 ++-- src/slang-nodes/NamedImport.js | 4 ++-- src/slang-nodes/NewExpression.js | 4 ++-- src/slang-nodes/NumberUnit.js | 4 ++-- src/slang-nodes/OrExpression.js | 4 ++-- src/slang-nodes/OverridePaths.js | 4 ++-- src/slang-nodes/OverridePathsDeclaration.js | 4 ++-- src/slang-nodes/OverrideSpecifier.js | 4 ++-- src/slang-nodes/Parameter.js | 4 ++-- src/slang-nodes/Parameters.js | 4 ++-- src/slang-nodes/ParametersDeclaration.js | 4 ++-- src/slang-nodes/PathImport.js | 4 ++-- src/slang-nodes/PositionalArguments.js | 4 ++-- .../PositionalArgumentsDeclaration.js | 4 ++-- src/slang-nodes/PostfixExpression.js | 4 ++-- src/slang-nodes/Pragma.js | 4 ++-- src/slang-nodes/PragmaDirective.js | 4 ++-- src/slang-nodes/PrefixExpression.js | 4 ++-- src/slang-nodes/ReceiveFunctionAttribute.js | 4 ++-- src/slang-nodes/ReceiveFunctionAttributes.js | 4 ++-- src/slang-nodes/ReceiveFunctionDefinition.js | 4 ++-- src/slang-nodes/ReturnStatement.js | 4 ++-- src/slang-nodes/ReturnsDeclaration.js | 4 ++-- src/slang-nodes/RevertStatement.js | 4 ++-- src/slang-nodes/ShiftExpression.js | 4 ++-- src/slang-nodes/SlangNode.js | 12 +++--------- src/slang-nodes/SourceUnit.js | 4 ++-- src/slang-nodes/SourceUnitMember.js | 4 ++-- src/slang-nodes/SourceUnitMembers.js | 4 ++-- src/slang-nodes/StateVariableAttribute.js | 4 ++-- src/slang-nodes/StateVariableAttributes.js | 4 ++-- src/slang-nodes/StateVariableDefinition.js | 4 ++-- src/slang-nodes/StateVariableDefinitionValue.js | 4 ++-- src/slang-nodes/Statement.js | 4 ++-- src/slang-nodes/Statements.js | 4 ++-- src/slang-nodes/StorageLocation.js | 4 ++-- src/slang-nodes/StringExpression.js | 4 ++-- src/slang-nodes/StringLiteral.js | 4 ++-- src/slang-nodes/StringLiterals.js | 4 ++-- src/slang-nodes/StructDefinition.js | 4 ++-- src/slang-nodes/StructMember.js | 4 ++-- src/slang-nodes/StructMembers.js | 4 ++-- src/slang-nodes/ThrowStatement.js | 4 ++-- src/slang-nodes/TryStatement.js | 4 ++-- src/slang-nodes/TupleDeconstructionElement.js | 4 ++-- src/slang-nodes/TupleDeconstructionElements.js | 4 ++-- src/slang-nodes/TupleDeconstructionStatement.js | 4 ++-- src/slang-nodes/TupleExpression.js | 4 ++-- src/slang-nodes/TupleMember.js | 4 ++-- src/slang-nodes/TupleValue.js | 4 ++-- src/slang-nodes/TupleValues.js | 4 ++-- src/slang-nodes/TypeExpression.js | 4 ++-- src/slang-nodes/TypeName.js | 4 ++-- src/slang-nodes/TypedTupleMember.js | 4 ++-- src/slang-nodes/UncheckedBlock.js | 4 ++-- src/slang-nodes/UnicodeStringLiteral.js | 4 ++-- src/slang-nodes/UnicodeStringLiterals.js | 4 ++-- src/slang-nodes/UnnamedFunctionAttribute.js | 4 ++-- src/slang-nodes/UnnamedFunctionAttributes.js | 4 ++-- src/slang-nodes/UnnamedFunctionDefinition.js | 4 ++-- src/slang-nodes/UntypedTupleMember.js | 4 ++-- .../UserDefinedValueTypeDefinition.js | 4 ++-- src/slang-nodes/UsingAlias.js | 4 ++-- src/slang-nodes/UsingClause.js | 4 ++-- src/slang-nodes/UsingDeconstruction.js | 4 ++-- src/slang-nodes/UsingDeconstructionSymbol.js | 4 ++-- src/slang-nodes/UsingDeconstructionSymbols.js | 4 ++-- src/slang-nodes/UsingDirective.js | 4 ++-- src/slang-nodes/UsingOperator.js | 4 ++-- src/slang-nodes/UsingTarget.js | 4 ++-- src/slang-nodes/VariableDeclarationStatement.js | 4 ++-- src/slang-nodes/VariableDeclarationType.js | 4 ++-- src/slang-nodes/VariableDeclarationValue.js | 4 ++-- src/slang-nodes/VersionComparator.js | 4 ++-- src/slang-nodes/VersionExpression.js | 4 ++-- src/slang-nodes/VersionExpressionSet.js | 4 ++-- src/slang-nodes/VersionExpressionSets.js | 4 ++-- src/slang-nodes/VersionPragma.js | 4 ++-- src/slang-nodes/VersionRange.js | 4 ++-- src/slang-nodes/VersionSpecifiers.js | 4 ++-- src/slang-nodes/WhileStatement.js | 4 ++-- src/slang-nodes/YulArguments.js | 4 ++-- src/slang-nodes/YulAssignmentOperator.js | 4 ++-- src/slang-nodes/YulAssignmentStatement.js | 4 ++-- src/slang-nodes/YulBlock.js | 4 ++-- src/slang-nodes/YulBreakStatement.js | 4 ++-- src/slang-nodes/YulBuiltInFunction.js | 4 ++-- src/slang-nodes/YulColonAndEqual.js | 4 ++-- src/slang-nodes/YulContinueStatement.js | 4 ++-- src/slang-nodes/YulDefaultCase.js | 4 ++-- src/slang-nodes/YulExpression.js | 4 ++-- src/slang-nodes/YulForStatement.js | 4 ++-- src/slang-nodes/YulFunctionCallExpression.js | 4 ++-- src/slang-nodes/YulFunctionDefinition.js | 4 ++-- src/slang-nodes/YulIfStatement.js | 4 ++-- src/slang-nodes/YulLabel.js | 4 ++-- src/slang-nodes/YulLeaveStatement.js | 4 ++-- src/slang-nodes/YulLiteral.js | 4 ++-- src/slang-nodes/YulParameters.js | 4 ++-- src/slang-nodes/YulParametersDeclaration.js | 4 ++-- src/slang-nodes/YulPath.js | 4 ++-- src/slang-nodes/YulPathComponent.js | 4 ++-- src/slang-nodes/YulPaths.js | 4 ++-- src/slang-nodes/YulReturnVariables.js | 4 ++-- src/slang-nodes/YulReturnsDeclaration.js | 4 ++-- src/slang-nodes/YulStatement.js | 4 ++-- src/slang-nodes/YulStatements.js | 4 ++-- src/slang-nodes/YulSwitchCase.js | 4 ++-- src/slang-nodes/YulSwitchCases.js | 4 ++-- src/slang-nodes/YulSwitchStatement.js | 4 ++-- src/slang-nodes/YulValueCase.js | 4 ++-- .../YulVariableAssignmentStatement.js | 4 ++-- .../YulVariableDeclarationStatement.js | 4 ++-- src/slang-nodes/YulVariableDeclarationValue.js | 4 ++-- src/slangParser.js | 16 ++++++++++++---- 217 files changed, 445 insertions(+), 443 deletions(-) diff --git a/src/slang-nodes/ABICoderPragma.js b/src/slang-nodes/ABICoderPragma.js index c08dc54fc..fe9dc853e 100644 --- a/src/slang-nodes/ABICoderPragma.js +++ b/src/slang-nodes/ABICoderPragma.js @@ -5,8 +5,8 @@ export class ABICoderPragma extends SlangNode { version; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/AdditiveExpression.js b/src/slang-nodes/AdditiveExpression.js index 51d3f6dc7..d5cd658a4 100644 --- a/src/slang-nodes/AdditiveExpression.js +++ b/src/slang-nodes/AdditiveExpression.js @@ -11,8 +11,8 @@ export class AdditiveExpression extends SlangNode { rightOperand; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); diff --git a/src/slang-nodes/AddressType.js b/src/slang-nodes/AddressType.js index 2fb5a5f04..200bde5f8 100644 --- a/src/slang-nodes/AddressType.js +++ b/src/slang-nodes/AddressType.js @@ -5,8 +5,8 @@ export class AddressType extends SlangNode { payableKeyword; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/AndExpression.js b/src/slang-nodes/AndExpression.js index 25838c71b..fbbb7d09c 100644 --- a/src/slang-nodes/AndExpression.js +++ b/src/slang-nodes/AndExpression.js @@ -8,8 +8,8 @@ export class AndExpression extends SlangNode { rightOperand; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/ArgumentsDeclaration.js b/src/slang-nodes/ArgumentsDeclaration.js index 661693ac4..f9368f1cf 100644 --- a/src/slang-nodes/ArgumentsDeclaration.js +++ b/src/slang-nodes/ArgumentsDeclaration.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class ArgumentsDeclaration extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/ArrayExpression.js b/src/slang-nodes/ArrayExpression.js index 7f8907328..c2bfa45b7 100644 --- a/src/slang-nodes/ArrayExpression.js +++ b/src/slang-nodes/ArrayExpression.js @@ -10,8 +10,8 @@ export class ArrayExpression extends SlangNode { closeBracket; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/ArrayTypeName.js b/src/slang-nodes/ArrayTypeName.js index d8ee3f88c..752509de6 100644 --- a/src/slang-nodes/ArrayTypeName.js +++ b/src/slang-nodes/ArrayTypeName.js @@ -9,8 +9,8 @@ export class ArrayTypeName extends SlangNode { closeBracket; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/ArrayValues.js b/src/slang-nodes/ArrayValues.js index a0f9385cd..33394cd9a 100644 --- a/src/slang-nodes/ArrayValues.js +++ b/src/slang-nodes/ArrayValues.js @@ -6,8 +6,8 @@ export class ArrayValues extends SlangNode { separators; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/AssemblyFlags.js b/src/slang-nodes/AssemblyFlags.js index 6228531f9..e6d060f26 100644 --- a/src/slang-nodes/AssemblyFlags.js +++ b/src/slang-nodes/AssemblyFlags.js @@ -6,8 +6,8 @@ export class AssemblyFlags extends SlangNode { separators; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/AssemblyFlagsDeclaration.js b/src/slang-nodes/AssemblyFlagsDeclaration.js index ae9df8171..703cd794c 100644 --- a/src/slang-nodes/AssemblyFlagsDeclaration.js +++ b/src/slang-nodes/AssemblyFlagsDeclaration.js @@ -7,8 +7,8 @@ export class AssemblyFlagsDeclaration extends SlangNode { closeParen; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/AssemblyStatement.js b/src/slang-nodes/AssemblyStatement.js index 5eedabd76..223035d28 100644 --- a/src/slang-nodes/AssemblyStatement.js +++ b/src/slang-nodes/AssemblyStatement.js @@ -9,8 +9,8 @@ export class AssemblyStatement extends SlangNode { body; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/AssignmentExpression.js b/src/slang-nodes/AssignmentExpression.js index 68de7a785..dd9d23f34 100644 --- a/src/slang-nodes/AssignmentExpression.js +++ b/src/slang-nodes/AssignmentExpression.js @@ -11,8 +11,8 @@ export class AssignmentExpression extends SlangNode { rightOperand; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/BitwiseAndExpression.js b/src/slang-nodes/BitwiseAndExpression.js index e2c3315ca..fb172133e 100644 --- a/src/slang-nodes/BitwiseAndExpression.js +++ b/src/slang-nodes/BitwiseAndExpression.js @@ -11,8 +11,8 @@ export class BitwiseAndExpression extends SlangNode { rightOperand; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); diff --git a/src/slang-nodes/BitwiseOrExpression.js b/src/slang-nodes/BitwiseOrExpression.js index 942007a75..df9913b0c 100644 --- a/src/slang-nodes/BitwiseOrExpression.js +++ b/src/slang-nodes/BitwiseOrExpression.js @@ -21,8 +21,8 @@ export class BitwiseOrExpression extends SlangNode { rightOperand; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); diff --git a/src/slang-nodes/BitwiseXorExpression.js b/src/slang-nodes/BitwiseXorExpression.js index 3cb6578a8..444ba0057 100644 --- a/src/slang-nodes/BitwiseXorExpression.js +++ b/src/slang-nodes/BitwiseXorExpression.js @@ -11,8 +11,8 @@ export class BitwiseXorExpression extends SlangNode { rightOperand; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); diff --git a/src/slang-nodes/Block.js b/src/slang-nodes/Block.js index 24fda66d3..d87acff3e 100644 --- a/src/slang-nodes/Block.js +++ b/src/slang-nodes/Block.js @@ -7,8 +7,8 @@ export class Block extends SlangNode { closeBrace; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/BreakStatement.js b/src/slang-nodes/BreakStatement.js index 1dae8df81..4edd55db6 100644 --- a/src/slang-nodes/BreakStatement.js +++ b/src/slang-nodes/BreakStatement.js @@ -5,8 +5,8 @@ export class BreakStatement extends SlangNode { semicolon; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/CallOptions.js b/src/slang-nodes/CallOptions.js index 3037a19a9..cea72611a 100644 --- a/src/slang-nodes/CallOptions.js +++ b/src/slang-nodes/CallOptions.js @@ -9,8 +9,8 @@ export class CallOptions extends SlangNode { separators; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/CallOptionsExpression.js b/src/slang-nodes/CallOptionsExpression.js index de3f7dcb9..a71a57a13 100644 --- a/src/slang-nodes/CallOptionsExpression.js +++ b/src/slang-nodes/CallOptionsExpression.js @@ -9,8 +9,8 @@ export class CallOptionsExpression extends SlangNode { closeBrace; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/CatchClause.js b/src/slang-nodes/CatchClause.js index e64c73294..bd0a26b89 100644 --- a/src/slang-nodes/CatchClause.js +++ b/src/slang-nodes/CatchClause.js @@ -7,8 +7,8 @@ export class CatchClause extends SlangNode { body; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/CatchClauseError.js b/src/slang-nodes/CatchClauseError.js index 699e81cbc..e33bc7375 100644 --- a/src/slang-nodes/CatchClauseError.js +++ b/src/slang-nodes/CatchClauseError.js @@ -8,8 +8,8 @@ export class CatchClauseError extends SlangNode { parameters; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/CatchClauses.js b/src/slang-nodes/CatchClauses.js index 8ee7a5e92..eda8162d1 100644 --- a/src/slang-nodes/CatchClauses.js +++ b/src/slang-nodes/CatchClauses.js @@ -6,8 +6,8 @@ const { join } = doc.builders; export class CatchClauses extends SlangNode { items; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/ComparisonExpression.js b/src/slang-nodes/ComparisonExpression.js index a9274f610..8721f800f 100644 --- a/src/slang-nodes/ComparisonExpression.js +++ b/src/slang-nodes/ComparisonExpression.js @@ -8,8 +8,8 @@ export class ComparisonExpression extends SlangNode { rightOperand; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/ConditionalExpression.js b/src/slang-nodes/ConditionalExpression.js index afbcb1806..0a83fa291 100644 --- a/src/slang-nodes/ConditionalExpression.js +++ b/src/slang-nodes/ConditionalExpression.js @@ -95,8 +95,8 @@ export class ConditionalExpression extends SlangNode { falseExpression; - constructor(ast, offset, parse, options) { - super(ast, offset); + constructor(ast, offset, comments, parse, options) { + super(ast, offset, comments); this.initialize(ast, parse); // TODO: while the behaviour is not stable, it should be behind the diff --git a/src/slang-nodes/ConstantDefinition.js b/src/slang-nodes/ConstantDefinition.js index 41760f673..71c81e53d 100644 --- a/src/slang-nodes/ConstantDefinition.js +++ b/src/slang-nodes/ConstantDefinition.js @@ -13,8 +13,8 @@ export class ConstantDefinition extends SlangNode { semicolon; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/ConstructorAttribute.js b/src/slang-nodes/ConstructorAttribute.js index 0810d751a..297e7d3a1 100644 --- a/src/slang-nodes/ConstructorAttribute.js +++ b/src/slang-nodes/ConstructorAttribute.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class ConstructorAttribute extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/ConstructorAttributes.js b/src/slang-nodes/ConstructorAttributes.js index 4d7295df9..a27fa04e2 100644 --- a/src/slang-nodes/ConstructorAttributes.js +++ b/src/slang-nodes/ConstructorAttributes.js @@ -7,8 +7,8 @@ const { line } = doc.builders; export class ConstructorAttributes extends SlangNode { items; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.items = this.items.sort(sortFunctionAttributes); this.finalize(ast); diff --git a/src/slang-nodes/ConstructorDefinition.js b/src/slang-nodes/ConstructorDefinition.js index 84976edc3..ac8dbc812 100644 --- a/src/slang-nodes/ConstructorDefinition.js +++ b/src/slang-nodes/ConstructorDefinition.js @@ -10,8 +10,8 @@ export class ConstructorDefinition extends SlangNode { body; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/ContinueStatement.js b/src/slang-nodes/ContinueStatement.js index acf721503..5d0809c1d 100644 --- a/src/slang-nodes/ContinueStatement.js +++ b/src/slang-nodes/ContinueStatement.js @@ -5,8 +5,8 @@ export class ContinueStatement extends SlangNode { semicolon; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/ContractDefinition.js b/src/slang-nodes/ContractDefinition.js index dc3263b50..7120f5e97 100644 --- a/src/slang-nodes/ContractDefinition.js +++ b/src/slang-nodes/ContractDefinition.js @@ -20,8 +20,8 @@ export class ContractDefinition extends SlangNode { closeBrace; - constructor(ast, offset, parse, options) { - super(ast, offset); + constructor(ast, offset, comments, parse, options) { + super(ast, offset, comments); this.initialize(ast, parse); this.cleanModifierInvocationArguments(options); this.finalize(ast); diff --git a/src/slang-nodes/ContractMember.js b/src/slang-nodes/ContractMember.js index ef8bcc3a2..8d539dd57 100644 --- a/src/slang-nodes/ContractMember.js +++ b/src/slang-nodes/ContractMember.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class ContractMember extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/ContractMembers.js b/src/slang-nodes/ContractMembers.js index f3ddc4f07..ad9190ec7 100644 --- a/src/slang-nodes/ContractMembers.js +++ b/src/slang-nodes/ContractMembers.js @@ -9,8 +9,8 @@ const { hardline } = doc.builders; export class ContractMembers extends SlangNode { items; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/DecimalNumberExpression.js b/src/slang-nodes/DecimalNumberExpression.js index 1c8b786f6..a6c1141e1 100644 --- a/src/slang-nodes/DecimalNumberExpression.js +++ b/src/slang-nodes/DecimalNumberExpression.js @@ -5,8 +5,8 @@ export class DecimalNumberExpression extends SlangNode { unit; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/DoWhileStatement.js b/src/slang-nodes/DoWhileStatement.js index 17759774e..129ee6ab8 100644 --- a/src/slang-nodes/DoWhileStatement.js +++ b/src/slang-nodes/DoWhileStatement.js @@ -19,8 +19,8 @@ export class DoWhileStatement extends SlangNode { semicolon; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/ElementaryType.js b/src/slang-nodes/ElementaryType.js index 9d55b96b6..0d65d0ed9 100644 --- a/src/slang-nodes/ElementaryType.js +++ b/src/slang-nodes/ElementaryType.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class ElementaryType extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/ElseBranch.js b/src/slang-nodes/ElseBranch.js index a28cc0d0b..e14abecc1 100644 --- a/src/slang-nodes/ElseBranch.js +++ b/src/slang-nodes/ElseBranch.js @@ -10,8 +10,8 @@ export class ElseBranch extends SlangNode { body; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/EmitStatement.js b/src/slang-nodes/EmitStatement.js index cd6978775..26ee7de8f 100644 --- a/src/slang-nodes/EmitStatement.js +++ b/src/slang-nodes/EmitStatement.js @@ -9,8 +9,8 @@ export class EmitStatement extends SlangNode { semicolon; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/EnumDefinition.js b/src/slang-nodes/EnumDefinition.js index f2de83ef8..3a50d3c81 100644 --- a/src/slang-nodes/EnumDefinition.js +++ b/src/slang-nodes/EnumDefinition.js @@ -11,8 +11,8 @@ export class EnumDefinition extends SlangNode { closeBrace; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/EnumMembers.js b/src/slang-nodes/EnumMembers.js index 127b1744a..5a6182526 100644 --- a/src/slang-nodes/EnumMembers.js +++ b/src/slang-nodes/EnumMembers.js @@ -9,8 +9,8 @@ export class EnumMembers extends SlangNode { separators; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/EqualityExpression.js b/src/slang-nodes/EqualityExpression.js index 92e162a03..58cf38fc3 100644 --- a/src/slang-nodes/EqualityExpression.js +++ b/src/slang-nodes/EqualityExpression.js @@ -8,8 +8,8 @@ export class EqualityExpression extends SlangNode { rightOperand; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/ErrorDefinition.js b/src/slang-nodes/ErrorDefinition.js index 31d9cd0b0..d0cbd33be 100644 --- a/src/slang-nodes/ErrorDefinition.js +++ b/src/slang-nodes/ErrorDefinition.js @@ -9,8 +9,8 @@ export class ErrorDefinition extends SlangNode { semicolon; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/ErrorParameter.js b/src/slang-nodes/ErrorParameter.js index 37d68daa7..7254260e9 100644 --- a/src/slang-nodes/ErrorParameter.js +++ b/src/slang-nodes/ErrorParameter.js @@ -5,8 +5,8 @@ export class ErrorParameter extends SlangNode { name; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/ErrorParameters.js b/src/slang-nodes/ErrorParameters.js index dfa2c61b7..e6f49123b 100644 --- a/src/slang-nodes/ErrorParameters.js +++ b/src/slang-nodes/ErrorParameters.js @@ -6,8 +6,8 @@ export class ErrorParameters extends SlangNode { separators; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/ErrorParametersDeclaration.js b/src/slang-nodes/ErrorParametersDeclaration.js index 3d30b0412..2efe4a887 100644 --- a/src/slang-nodes/ErrorParametersDeclaration.js +++ b/src/slang-nodes/ErrorParametersDeclaration.js @@ -7,8 +7,8 @@ export class ErrorParametersDeclaration extends SlangNode { closeParen; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/EventDefinition.js b/src/slang-nodes/EventDefinition.js index 03284f44d..1e869547b 100644 --- a/src/slang-nodes/EventDefinition.js +++ b/src/slang-nodes/EventDefinition.js @@ -11,8 +11,8 @@ export class EventDefinition extends SlangNode { semicolon; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/EventParameter.js b/src/slang-nodes/EventParameter.js index 096403c69..21d8b06ed 100644 --- a/src/slang-nodes/EventParameter.js +++ b/src/slang-nodes/EventParameter.js @@ -7,8 +7,8 @@ export class EventParameter extends SlangNode { name; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/EventParameters.js b/src/slang-nodes/EventParameters.js index 01cf84e87..37f230f0b 100644 --- a/src/slang-nodes/EventParameters.js +++ b/src/slang-nodes/EventParameters.js @@ -6,8 +6,8 @@ export class EventParameters extends SlangNode { separators; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/EventParametersDeclaration.js b/src/slang-nodes/EventParametersDeclaration.js index d5390cb63..3d5673280 100644 --- a/src/slang-nodes/EventParametersDeclaration.js +++ b/src/slang-nodes/EventParametersDeclaration.js @@ -7,8 +7,8 @@ export class EventParametersDeclaration extends SlangNode { closeParen; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/ExperimentalFeature.js b/src/slang-nodes/ExperimentalFeature.js index dbe37b1d6..574d2c15a 100644 --- a/src/slang-nodes/ExperimentalFeature.js +++ b/src/slang-nodes/ExperimentalFeature.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class ExperimentalFeature extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/ExperimentalPragma.js b/src/slang-nodes/ExperimentalPragma.js index d584d65e2..d60dcb30e 100644 --- a/src/slang-nodes/ExperimentalPragma.js +++ b/src/slang-nodes/ExperimentalPragma.js @@ -5,8 +5,8 @@ export class ExperimentalPragma extends SlangNode { feature; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/ExponentiationExpression.js b/src/slang-nodes/ExponentiationExpression.js index 075ecbfe6..6950a074a 100644 --- a/src/slang-nodes/ExponentiationExpression.js +++ b/src/slang-nodes/ExponentiationExpression.js @@ -26,8 +26,8 @@ export class ExponentiationExpression extends SlangNode { rightOperand; - constructor(ast, offset, parse, options) { - super(ast, offset); + constructor(ast, offset, comments, parse, options) { + super(ast, offset, comments); if (offset) { this.initialize(ast, parse); diff --git a/src/slang-nodes/Expression.js b/src/slang-nodes/Expression.js index 89b8b273d..ffccdfd36 100644 --- a/src/slang-nodes/Expression.js +++ b/src/slang-nodes/Expression.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class Expression extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); if (offset) { this.initialize(ast, parse); this.finalize(ast); diff --git a/src/slang-nodes/ExpressionStatement.js b/src/slang-nodes/ExpressionStatement.js index 5915a5b7c..578f6c2ec 100644 --- a/src/slang-nodes/ExpressionStatement.js +++ b/src/slang-nodes/ExpressionStatement.js @@ -5,8 +5,8 @@ export class ExpressionStatement extends SlangNode { semicolon; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/FallbackFunctionAttribute.js b/src/slang-nodes/FallbackFunctionAttribute.js index 9f46e51d7..8f1d4833d 100644 --- a/src/slang-nodes/FallbackFunctionAttribute.js +++ b/src/slang-nodes/FallbackFunctionAttribute.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class FallbackFunctionAttribute extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/FallbackFunctionAttributes.js b/src/slang-nodes/FallbackFunctionAttributes.js index cabc721b8..4444f9060 100644 --- a/src/slang-nodes/FallbackFunctionAttributes.js +++ b/src/slang-nodes/FallbackFunctionAttributes.js @@ -7,8 +7,8 @@ const { line } = doc.builders; export class FallbackFunctionAttributes extends SlangNode { items; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.items = this.items.sort(sortFunctionAttributes); this.finalize(ast); diff --git a/src/slang-nodes/FallbackFunctionDefinition.js b/src/slang-nodes/FallbackFunctionDefinition.js index 1eeded617..f97c6cbda 100644 --- a/src/slang-nodes/FallbackFunctionDefinition.js +++ b/src/slang-nodes/FallbackFunctionDefinition.js @@ -12,8 +12,8 @@ export class FallbackFunctionDefinition extends SlangNode { body; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.cleanModifierInvocationArguments(); this.finalize(ast); diff --git a/src/slang-nodes/ForStatement.js b/src/slang-nodes/ForStatement.js index 81022e07c..0ac35f4af 100644 --- a/src/slang-nodes/ForStatement.js +++ b/src/slang-nodes/ForStatement.js @@ -19,8 +19,8 @@ export class ForStatement extends SlangNode { body; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/ForStatementCondition.js b/src/slang-nodes/ForStatementCondition.js index f35ddcf77..bfe9a8b62 100644 --- a/src/slang-nodes/ForStatementCondition.js +++ b/src/slang-nodes/ForStatementCondition.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class ForStatementCondition extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/ForStatementInitialization.js b/src/slang-nodes/ForStatementInitialization.js index 02881ee66..5ce7e38ef 100644 --- a/src/slang-nodes/ForStatementInitialization.js +++ b/src/slang-nodes/ForStatementInitialization.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class ForStatementInitialization extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/FunctionAttribute.js b/src/slang-nodes/FunctionAttribute.js index 04b90b403..f1759bfa1 100644 --- a/src/slang-nodes/FunctionAttribute.js +++ b/src/slang-nodes/FunctionAttribute.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class FunctionAttribute extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/FunctionAttributes.js b/src/slang-nodes/FunctionAttributes.js index 339305918..5f7f63820 100644 --- a/src/slang-nodes/FunctionAttributes.js +++ b/src/slang-nodes/FunctionAttributes.js @@ -7,8 +7,8 @@ const { line } = doc.builders; export class FunctionAttributes extends SlangNode { items; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.items = this.items.sort(sortFunctionAttributes); this.finalize(ast); diff --git a/src/slang-nodes/FunctionBody.js b/src/slang-nodes/FunctionBody.js index 15171f8ba..f41ae0666 100644 --- a/src/slang-nodes/FunctionBody.js +++ b/src/slang-nodes/FunctionBody.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class FunctionBody extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/FunctionCallExpression.js b/src/slang-nodes/FunctionCallExpression.js index b7c410e6d..7c2be86e9 100644 --- a/src/slang-nodes/FunctionCallExpression.js +++ b/src/slang-nodes/FunctionCallExpression.js @@ -9,8 +9,8 @@ export class FunctionCallExpression extends SlangNode { arguments; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/FunctionDefinition.js b/src/slang-nodes/FunctionDefinition.js index 5bbbb059f..dfd60e243 100644 --- a/src/slang-nodes/FunctionDefinition.js +++ b/src/slang-nodes/FunctionDefinition.js @@ -16,8 +16,8 @@ export class FunctionDefinition extends SlangNode { body; - constructor(ast, offset, parse, options) { - super(ast, offset); + constructor(ast, offset, comments, parse, options) { + super(ast, offset, comments); this.initialize(ast, parse); // Older versions of Solidity defined a constructor as a function having diff --git a/src/slang-nodes/FunctionName.js b/src/slang-nodes/FunctionName.js index e64ff8d28..c12099bf3 100644 --- a/src/slang-nodes/FunctionName.js +++ b/src/slang-nodes/FunctionName.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class FunctionName extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/FunctionType.js b/src/slang-nodes/FunctionType.js index 4dbe62f93..69aef20c4 100644 --- a/src/slang-nodes/FunctionType.js +++ b/src/slang-nodes/FunctionType.js @@ -10,8 +10,8 @@ export class FunctionType extends SlangNode { returns; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/FunctionTypeAttribute.js b/src/slang-nodes/FunctionTypeAttribute.js index a879d8576..4d69e5e19 100644 --- a/src/slang-nodes/FunctionTypeAttribute.js +++ b/src/slang-nodes/FunctionTypeAttribute.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class FunctionTypeAttribute extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/FunctionTypeAttributes.js b/src/slang-nodes/FunctionTypeAttributes.js index 1d97020ff..08b3dfb6a 100644 --- a/src/slang-nodes/FunctionTypeAttributes.js +++ b/src/slang-nodes/FunctionTypeAttributes.js @@ -7,8 +7,8 @@ const { line } = doc.builders; export class FunctionTypeAttributes extends SlangNode { items; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.items = this.items.sort(sortFunctionAttributes); this.finalize(ast); diff --git a/src/slang-nodes/HexNumberExpression.js b/src/slang-nodes/HexNumberExpression.js index 46eef7078..dfc81497f 100644 --- a/src/slang-nodes/HexNumberExpression.js +++ b/src/slang-nodes/HexNumberExpression.js @@ -5,8 +5,8 @@ export class HexNumberExpression extends SlangNode { unit; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/HexStringLiteral.js b/src/slang-nodes/HexStringLiteral.js index 723b24141..f6456cf42 100644 --- a/src/slang-nodes/HexStringLiteral.js +++ b/src/slang-nodes/HexStringLiteral.js @@ -4,8 +4,8 @@ import { SlangNode } from './SlangNode.js'; export class HexStringLiteral extends SlangNode { variant; - constructor(ast, offset, parse, options) { - super(ast, offset); + constructor(ast, offset, comments, parse, options) { + super(ast, offset, comments); this.initialize(ast, parse); this.variant = `hex${printString(this.variant.slice(4, -1), options)}`; this.finalize(ast); diff --git a/src/slang-nodes/HexStringLiterals.js b/src/slang-nodes/HexStringLiterals.js index 633b86188..a6bb2462b 100644 --- a/src/slang-nodes/HexStringLiterals.js +++ b/src/slang-nodes/HexStringLiterals.js @@ -6,8 +6,8 @@ const { join, hardline } = doc.builders; export class HexStringLiterals extends SlangNode { items; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/IdentifierPath.js b/src/slang-nodes/IdentifierPath.js index d68466bb5..35ca3af46 100644 --- a/src/slang-nodes/IdentifierPath.js +++ b/src/slang-nodes/IdentifierPath.js @@ -5,8 +5,8 @@ export class IdentifierPath extends SlangNode { separators; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/IfStatement.js b/src/slang-nodes/IfStatement.js index 7eb0b40ce..507d39fd3 100644 --- a/src/slang-nodes/IfStatement.js +++ b/src/slang-nodes/IfStatement.js @@ -17,8 +17,8 @@ export class IfStatement extends SlangNode { elseBranch; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/ImportAlias.js b/src/slang-nodes/ImportAlias.js index 441c69e8b..495dcd487 100644 --- a/src/slang-nodes/ImportAlias.js +++ b/src/slang-nodes/ImportAlias.js @@ -5,8 +5,8 @@ export class ImportAlias extends SlangNode { identifier; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/ImportClause.js b/src/slang-nodes/ImportClause.js index 58d5fbc64..e18b2ba25 100644 --- a/src/slang-nodes/ImportClause.js +++ b/src/slang-nodes/ImportClause.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class ImportClause extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/ImportDeconstruction.js b/src/slang-nodes/ImportDeconstruction.js index c30bab6be..e87e7edb2 100644 --- a/src/slang-nodes/ImportDeconstruction.js +++ b/src/slang-nodes/ImportDeconstruction.js @@ -11,8 +11,8 @@ export class ImportDeconstruction extends SlangNode { path; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/ImportDeconstructionSymbol.js b/src/slang-nodes/ImportDeconstructionSymbol.js index 4e35a6fd6..3d587130a 100644 --- a/src/slang-nodes/ImportDeconstructionSymbol.js +++ b/src/slang-nodes/ImportDeconstructionSymbol.js @@ -5,8 +5,8 @@ export class ImportDeconstructionSymbol extends SlangNode { alias; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/ImportDeconstructionSymbols.js b/src/slang-nodes/ImportDeconstructionSymbols.js index b276f59d7..d0dd60005 100644 --- a/src/slang-nodes/ImportDeconstructionSymbols.js +++ b/src/slang-nodes/ImportDeconstructionSymbols.js @@ -11,8 +11,8 @@ export class ImportDeconstructionSymbols extends SlangNode { separators; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/ImportDirective.js b/src/slang-nodes/ImportDirective.js index 3f4d598e1..a321315e0 100644 --- a/src/slang-nodes/ImportDirective.js +++ b/src/slang-nodes/ImportDirective.js @@ -7,8 +7,8 @@ export class ImportDirective extends SlangNode { semicolon; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/IndexAccessEnd.js b/src/slang-nodes/IndexAccessEnd.js index b216e6ed3..eeec3e5cd 100644 --- a/src/slang-nodes/IndexAccessEnd.js +++ b/src/slang-nodes/IndexAccessEnd.js @@ -5,8 +5,8 @@ export class IndexAccessEnd extends SlangNode { end; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/IndexAccessExpression.js b/src/slang-nodes/IndexAccessExpression.js index 663c6c2dd..9e0245b06 100644 --- a/src/slang-nodes/IndexAccessExpression.js +++ b/src/slang-nodes/IndexAccessExpression.js @@ -15,8 +15,8 @@ export class IndexAccessExpression extends SlangNode { closeBracket; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.closeBracket = ast.closeBracket.text; this.initialize(ast, parse); this.finalize(ast); diff --git a/src/slang-nodes/InheritanceSpecifier.js b/src/slang-nodes/InheritanceSpecifier.js index d85af9ab2..426c3ff80 100644 --- a/src/slang-nodes/InheritanceSpecifier.js +++ b/src/slang-nodes/InheritanceSpecifier.js @@ -5,8 +5,8 @@ export class InheritanceSpecifier extends SlangNode { types; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/InheritanceType.js b/src/slang-nodes/InheritanceType.js index 1d4a68528..93783322c 100644 --- a/src/slang-nodes/InheritanceType.js +++ b/src/slang-nodes/InheritanceType.js @@ -5,8 +5,8 @@ export class InheritanceType extends SlangNode { arguments; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/InheritanceTypes.js b/src/slang-nodes/InheritanceTypes.js index 91c0dbdeb..9c18b2d76 100644 --- a/src/slang-nodes/InheritanceTypes.js +++ b/src/slang-nodes/InheritanceTypes.js @@ -9,8 +9,8 @@ export class InheritanceTypes extends SlangNode { separators; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/InterfaceDefinition.js b/src/slang-nodes/InterfaceDefinition.js index 70529c7ac..e0b158e33 100644 --- a/src/slang-nodes/InterfaceDefinition.js +++ b/src/slang-nodes/InterfaceDefinition.js @@ -16,8 +16,8 @@ export class InterfaceDefinition extends SlangNode { closeBrace; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/InterfaceMembers.js b/src/slang-nodes/InterfaceMembers.js index 4752b7fd5..94a69b09b 100644 --- a/src/slang-nodes/InterfaceMembers.js +++ b/src/slang-nodes/InterfaceMembers.js @@ -8,8 +8,8 @@ const { hardline } = doc.builders; export class InterfaceMembers extends SlangNode { items; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/LibraryDefinition.js b/src/slang-nodes/LibraryDefinition.js index 8b2957280..4c38f9b58 100644 --- a/src/slang-nodes/LibraryDefinition.js +++ b/src/slang-nodes/LibraryDefinition.js @@ -14,8 +14,8 @@ export class LibraryDefinition extends SlangNode { closeBrace; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/LibraryMembers.js b/src/slang-nodes/LibraryMembers.js index 250781812..d03ac295c 100644 --- a/src/slang-nodes/LibraryMembers.js +++ b/src/slang-nodes/LibraryMembers.js @@ -8,8 +8,8 @@ const { hardline } = doc.builders; export class LibraryMembers extends SlangNode { items; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/MappingKey.js b/src/slang-nodes/MappingKey.js index 647c9e920..2e0e0403e 100644 --- a/src/slang-nodes/MappingKey.js +++ b/src/slang-nodes/MappingKey.js @@ -5,8 +5,8 @@ export class MappingKey extends SlangNode { name; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/MappingKeyType.js b/src/slang-nodes/MappingKeyType.js index 9041ea229..2c9d3127c 100644 --- a/src/slang-nodes/MappingKeyType.js +++ b/src/slang-nodes/MappingKeyType.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class MappingKeyType extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/MappingType.js b/src/slang-nodes/MappingType.js index e8746ebb6..fda7c3de4 100644 --- a/src/slang-nodes/MappingType.js +++ b/src/slang-nodes/MappingType.js @@ -13,8 +13,8 @@ export class MappingType extends SlangNode { closeParen; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/MappingValue.js b/src/slang-nodes/MappingValue.js index 770d44225..dd1e19114 100644 --- a/src/slang-nodes/MappingValue.js +++ b/src/slang-nodes/MappingValue.js @@ -5,8 +5,8 @@ export class MappingValue extends SlangNode { name; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/MemberAccess.js b/src/slang-nodes/MemberAccess.js index 3b5a3b47d..3616fc5d4 100644 --- a/src/slang-nodes/MemberAccess.js +++ b/src/slang-nodes/MemberAccess.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class MemberAccess extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/MemberAccessExpression.js b/src/slang-nodes/MemberAccessExpression.js index c3104d175..6c63ca0b1 100644 --- a/src/slang-nodes/MemberAccessExpression.js +++ b/src/slang-nodes/MemberAccessExpression.js @@ -112,8 +112,8 @@ export class MemberAccessExpression extends SlangNode { member; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/ModifierAttribute.js b/src/slang-nodes/ModifierAttribute.js index d714b9d68..92f4f8b96 100644 --- a/src/slang-nodes/ModifierAttribute.js +++ b/src/slang-nodes/ModifierAttribute.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class ModifierAttribute extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/ModifierAttributes.js b/src/slang-nodes/ModifierAttributes.js index cb0188bc5..c1761ad2c 100644 --- a/src/slang-nodes/ModifierAttributes.js +++ b/src/slang-nodes/ModifierAttributes.js @@ -7,8 +7,8 @@ const { line } = doc.builders; export class ModifierAttributes extends SlangNode { items; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.items = this.items.sort(sortFunctionAttributes); this.finalize(ast); diff --git a/src/slang-nodes/ModifierDefinition.js b/src/slang-nodes/ModifierDefinition.js index f2079e0c4..3e947769b 100644 --- a/src/slang-nodes/ModifierDefinition.js +++ b/src/slang-nodes/ModifierDefinition.js @@ -15,8 +15,8 @@ export class ModifierDefinition extends SlangNode { body; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); if (typeof this.parameters === 'undefined') { const parametersLoc = { diff --git a/src/slang-nodes/ModifierInvocation.js b/src/slang-nodes/ModifierInvocation.js index 10e585ba6..c08ecbeeb 100644 --- a/src/slang-nodes/ModifierInvocation.js +++ b/src/slang-nodes/ModifierInvocation.js @@ -8,8 +8,8 @@ export class ModifierInvocation extends SlangNode { arguments; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.#ast = ast; this.initialize(ast, parse); this.finalize(ast); diff --git a/src/slang-nodes/MultiplicativeExpression.js b/src/slang-nodes/MultiplicativeExpression.js index f990153c3..dcc04417e 100644 --- a/src/slang-nodes/MultiplicativeExpression.js +++ b/src/slang-nodes/MultiplicativeExpression.js @@ -13,8 +13,8 @@ export class MultiplicativeExpression extends SlangNode { rightOperand; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); switch (this.operator) { diff --git a/src/slang-nodes/NamedArgument.js b/src/slang-nodes/NamedArgument.js index be4cf57ae..6006df72a 100644 --- a/src/slang-nodes/NamedArgument.js +++ b/src/slang-nodes/NamedArgument.js @@ -7,8 +7,8 @@ export class NamedArgument extends SlangNode { value; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/NamedArgumentGroup.js b/src/slang-nodes/NamedArgumentGroup.js index d6c555539..0d8241006 100644 --- a/src/slang-nodes/NamedArgumentGroup.js +++ b/src/slang-nodes/NamedArgumentGroup.js @@ -7,8 +7,8 @@ export class NamedArgumentGroup extends SlangNode { closeBrace; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/NamedArguments.js b/src/slang-nodes/NamedArguments.js index 25fdc37cb..38e1a2c42 100644 --- a/src/slang-nodes/NamedArguments.js +++ b/src/slang-nodes/NamedArguments.js @@ -9,8 +9,8 @@ export class NamedArguments extends SlangNode { separators; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/NamedArgumentsDeclaration.js b/src/slang-nodes/NamedArgumentsDeclaration.js index 36916def9..b09d6ae84 100644 --- a/src/slang-nodes/NamedArgumentsDeclaration.js +++ b/src/slang-nodes/NamedArgumentsDeclaration.js @@ -7,8 +7,8 @@ export class NamedArgumentsDeclaration extends SlangNode { closeParen; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/NamedImport.js b/src/slang-nodes/NamedImport.js index 50ca26ae5..a24b7176e 100644 --- a/src/slang-nodes/NamedImport.js +++ b/src/slang-nodes/NamedImport.js @@ -9,8 +9,8 @@ export class NamedImport extends SlangNode { path; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/NewExpression.js b/src/slang-nodes/NewExpression.js index d768134b6..860cec90d 100644 --- a/src/slang-nodes/NewExpression.js +++ b/src/slang-nodes/NewExpression.js @@ -5,8 +5,8 @@ export class NewExpression extends SlangNode { typeName; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/NumberUnit.js b/src/slang-nodes/NumberUnit.js index 7e8fd8c34..fdce5827c 100644 --- a/src/slang-nodes/NumberUnit.js +++ b/src/slang-nodes/NumberUnit.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class NumberUnit extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/OrExpression.js b/src/slang-nodes/OrExpression.js index d1f51dc1c..85f2e4276 100644 --- a/src/slang-nodes/OrExpression.js +++ b/src/slang-nodes/OrExpression.js @@ -11,8 +11,8 @@ export class OrExpression extends SlangNode { rightOperand; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); diff --git a/src/slang-nodes/OverridePaths.js b/src/slang-nodes/OverridePaths.js index 5851677f5..de25a5afe 100644 --- a/src/slang-nodes/OverridePaths.js +++ b/src/slang-nodes/OverridePaths.js @@ -5,8 +5,8 @@ export class OverridePaths extends SlangNode { separators; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/OverridePathsDeclaration.js b/src/slang-nodes/OverridePathsDeclaration.js index 0610ab99a..a70cea509 100644 --- a/src/slang-nodes/OverridePathsDeclaration.js +++ b/src/slang-nodes/OverridePathsDeclaration.js @@ -7,8 +7,8 @@ export class OverridePathsDeclaration extends SlangNode { closeParen; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/OverrideSpecifier.js b/src/slang-nodes/OverrideSpecifier.js index 74e7f3ff8..cab6269e8 100644 --- a/src/slang-nodes/OverrideSpecifier.js +++ b/src/slang-nodes/OverrideSpecifier.js @@ -5,8 +5,8 @@ export class OverrideSpecifier extends SlangNode { overridden; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/Parameter.js b/src/slang-nodes/Parameter.js index e6cfecdd9..4ddcea0ac 100644 --- a/src/slang-nodes/Parameter.js +++ b/src/slang-nodes/Parameter.js @@ -10,8 +10,8 @@ export class Parameter extends SlangNode { name; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/Parameters.js b/src/slang-nodes/Parameters.js index cdab9064e..e48db64c3 100644 --- a/src/slang-nodes/Parameters.js +++ b/src/slang-nodes/Parameters.js @@ -10,8 +10,8 @@ export class Parameters extends SlangNode { separators; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); if (offset) { this.initialize(ast, parse); this.finalize(ast); diff --git a/src/slang-nodes/ParametersDeclaration.js b/src/slang-nodes/ParametersDeclaration.js index f95fff306..c8642ce24 100644 --- a/src/slang-nodes/ParametersDeclaration.js +++ b/src/slang-nodes/ParametersDeclaration.js @@ -7,8 +7,8 @@ export class ParametersDeclaration extends SlangNode { closeParen; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); if (offset) { this.initialize(ast, parse); this.finalize(ast); diff --git a/src/slang-nodes/PathImport.js b/src/slang-nodes/PathImport.js index 60611185a..69f19d5e5 100644 --- a/src/slang-nodes/PathImport.js +++ b/src/slang-nodes/PathImport.js @@ -5,8 +5,8 @@ export class PathImport extends SlangNode { alias; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/PositionalArguments.js b/src/slang-nodes/PositionalArguments.js index e6e19223b..f65e1c73a 100644 --- a/src/slang-nodes/PositionalArguments.js +++ b/src/slang-nodes/PositionalArguments.js @@ -6,8 +6,8 @@ export class PositionalArguments extends SlangNode { separators; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/PositionalArgumentsDeclaration.js b/src/slang-nodes/PositionalArgumentsDeclaration.js index 2f290051f..159430d58 100644 --- a/src/slang-nodes/PositionalArgumentsDeclaration.js +++ b/src/slang-nodes/PositionalArgumentsDeclaration.js @@ -7,8 +7,8 @@ export class PositionalArgumentsDeclaration extends SlangNode { closeParen; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/PostfixExpression.js b/src/slang-nodes/PostfixExpression.js index c49f746f3..9675de7c2 100644 --- a/src/slang-nodes/PostfixExpression.js +++ b/src/slang-nodes/PostfixExpression.js @@ -5,8 +5,8 @@ export class PostfixExpression extends SlangNode { operator; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/Pragma.js b/src/slang-nodes/Pragma.js index b1ed1191a..178d65c0a 100644 --- a/src/slang-nodes/Pragma.js +++ b/src/slang-nodes/Pragma.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class Pragma extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/PragmaDirective.js b/src/slang-nodes/PragmaDirective.js index 8b5c005ae..dac4aa233 100644 --- a/src/slang-nodes/PragmaDirective.js +++ b/src/slang-nodes/PragmaDirective.js @@ -7,8 +7,8 @@ export class PragmaDirective extends SlangNode { semicolon; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/PrefixExpression.js b/src/slang-nodes/PrefixExpression.js index 53aa9c3c9..51d11cba2 100644 --- a/src/slang-nodes/PrefixExpression.js +++ b/src/slang-nodes/PrefixExpression.js @@ -5,8 +5,8 @@ export class PrefixExpression extends SlangNode { operand; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/ReceiveFunctionAttribute.js b/src/slang-nodes/ReceiveFunctionAttribute.js index 52675ec94..95f01249b 100644 --- a/src/slang-nodes/ReceiveFunctionAttribute.js +++ b/src/slang-nodes/ReceiveFunctionAttribute.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class ReceiveFunctionAttribute extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/ReceiveFunctionAttributes.js b/src/slang-nodes/ReceiveFunctionAttributes.js index 7b0292929..a12aa3d29 100644 --- a/src/slang-nodes/ReceiveFunctionAttributes.js +++ b/src/slang-nodes/ReceiveFunctionAttributes.js @@ -7,8 +7,8 @@ const { line } = doc.builders; export class ReceiveFunctionAttributes extends SlangNode { items; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.items = this.items.sort(sortFunctionAttributes); this.finalize(ast); diff --git a/src/slang-nodes/ReceiveFunctionDefinition.js b/src/slang-nodes/ReceiveFunctionDefinition.js index 4abec0828..6b2d4238b 100644 --- a/src/slang-nodes/ReceiveFunctionDefinition.js +++ b/src/slang-nodes/ReceiveFunctionDefinition.js @@ -10,8 +10,8 @@ export class ReceiveFunctionDefinition extends SlangNode { body; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.cleanModifierInvocationArguments(); this.finalize(ast); diff --git a/src/slang-nodes/ReturnStatement.js b/src/slang-nodes/ReturnStatement.js index 3234e6575..e0b47f4b4 100644 --- a/src/slang-nodes/ReturnStatement.js +++ b/src/slang-nodes/ReturnStatement.js @@ -21,8 +21,8 @@ export class ReturnStatement extends SlangNode { semicolon; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/ReturnsDeclaration.js b/src/slang-nodes/ReturnsDeclaration.js index 7938b0bd1..4de594069 100644 --- a/src/slang-nodes/ReturnsDeclaration.js +++ b/src/slang-nodes/ReturnsDeclaration.js @@ -8,8 +8,8 @@ export class ReturnsDeclaration extends SlangNode { variables; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/RevertStatement.js b/src/slang-nodes/RevertStatement.js index da4999311..3b0426877 100644 --- a/src/slang-nodes/RevertStatement.js +++ b/src/slang-nodes/RevertStatement.js @@ -9,8 +9,8 @@ export class RevertStatement extends SlangNode { semicolon; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/ShiftExpression.js b/src/slang-nodes/ShiftExpression.js index 7622cc061..92cff0f8d 100644 --- a/src/slang-nodes/ShiftExpression.js +++ b/src/slang-nodes/ShiftExpression.js @@ -20,8 +20,8 @@ export class ShiftExpression extends SlangNode { rightOperand; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.leftOperand = tryToHugLeftOperand(this.leftOperand); this.rightOperand = tryToHugRightOperand(this.rightOperand); diff --git a/src/slang-nodes/SlangNode.js b/src/slang-nodes/SlangNode.js index 35de0ea6e..bca37e5f1 100644 --- a/src/slang-nodes/SlangNode.js +++ b/src/slang-nodes/SlangNode.js @@ -1,9 +1,7 @@ import { isComment } from '../slang-utils/is-comment.js'; import { Loc } from '../slang-utils/loc.js'; -const comments = []; - -function getOffsets(children, initialOffset) { +function getOffsets(children, initialOffset, comments) { let offset = initialOffset; const offsets = children.reduce((offsetsArray, child) => { @@ -66,14 +64,14 @@ export class SlangNode { comments = []; - constructor(ast, offset) { + constructor(ast, offset, comments) { if (typeof offset === 'undefined') return; const children = ast.cst.children(); this.kind = ast.cst.kind; this.loc = new Loc({ startWithTrivia: offset, endWithTrivia: offset + ast.cst.textLength.utf8, - childrenOffsets: getOffsets(children, offset) + childrenOffsets: getOffsets(children, offset, comments) }); } @@ -144,8 +142,4 @@ export class SlangNode { this.loc.start = this.loc.startWithTrivia + leadingOffset; this.loc.end = this.loc.endWithTrivia - trailingOffset; } - - collectComments() { - this.comments = comments.splice(0); - } } diff --git a/src/slang-nodes/SourceUnit.js b/src/slang-nodes/SourceUnit.js index c2585ac01..e059c0eec 100644 --- a/src/slang-nodes/SourceUnit.js +++ b/src/slang-nodes/SourceUnit.js @@ -6,8 +6,8 @@ const { line } = doc.builders; export class SourceUnit extends SlangNode { members; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/SourceUnitMember.js b/src/slang-nodes/SourceUnitMember.js index 304e0ccd7..bd582b0e3 100644 --- a/src/slang-nodes/SourceUnitMember.js +++ b/src/slang-nodes/SourceUnitMember.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class SourceUnitMember extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/SourceUnitMembers.js b/src/slang-nodes/SourceUnitMembers.js index a9ebf130e..6c4b75103 100644 --- a/src/slang-nodes/SourceUnitMembers.js +++ b/src/slang-nodes/SourceUnitMembers.js @@ -4,8 +4,8 @@ import { SlangNode } from './SlangNode.js'; export class SourceUnitMembers extends SlangNode { items; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/StateVariableAttribute.js b/src/slang-nodes/StateVariableAttribute.js index 1f9ba8121..94b375c1c 100644 --- a/src/slang-nodes/StateVariableAttribute.js +++ b/src/slang-nodes/StateVariableAttribute.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class StateVariableAttribute extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/StateVariableAttributes.js b/src/slang-nodes/StateVariableAttributes.js index 07c48de5e..e06371fcf 100644 --- a/src/slang-nodes/StateVariableAttributes.js +++ b/src/slang-nodes/StateVariableAttributes.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class StateVariableAttributes extends SlangNode { items; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/StateVariableDefinition.js b/src/slang-nodes/StateVariableDefinition.js index aa7203091..1499bc94c 100644 --- a/src/slang-nodes/StateVariableDefinition.js +++ b/src/slang-nodes/StateVariableDefinition.js @@ -11,8 +11,8 @@ export class StateVariableDefinition extends SlangNode { semicolon; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/StateVariableDefinitionValue.js b/src/slang-nodes/StateVariableDefinitionValue.js index 67dc0caac..9c75dab87 100644 --- a/src/slang-nodes/StateVariableDefinitionValue.js +++ b/src/slang-nodes/StateVariableDefinitionValue.js @@ -8,8 +8,8 @@ export class StateVariableDefinitionValue extends SlangNode { value; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/Statement.js b/src/slang-nodes/Statement.js index 17af3e269..d8d4d06dd 100644 --- a/src/slang-nodes/Statement.js +++ b/src/slang-nodes/Statement.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class Statement extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/Statements.js b/src/slang-nodes/Statements.js index c0f9fa4da..79938d886 100644 --- a/src/slang-nodes/Statements.js +++ b/src/slang-nodes/Statements.js @@ -10,8 +10,8 @@ const { hardline } = doc.builders; export class Statements extends SlangNode { items; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/StorageLocation.js b/src/slang-nodes/StorageLocation.js index 15124b498..33d3c065f 100644 --- a/src/slang-nodes/StorageLocation.js +++ b/src/slang-nodes/StorageLocation.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class StorageLocation extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/StringExpression.js b/src/slang-nodes/StringExpression.js index f18b47e5f..afa078b78 100644 --- a/src/slang-nodes/StringExpression.js +++ b/src/slang-nodes/StringExpression.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class StringExpression extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/StringLiteral.js b/src/slang-nodes/StringLiteral.js index 2b9202172..e22904666 100644 --- a/src/slang-nodes/StringLiteral.js +++ b/src/slang-nodes/StringLiteral.js @@ -4,8 +4,8 @@ import { SlangNode } from './SlangNode.js'; export class StringLiteral extends SlangNode { variant; - constructor(ast, offset, parse, options) { - super(ast, offset); + constructor(ast, offset, comments, parse, options) { + super(ast, offset, comments); this.initialize(ast, parse); this.variant = printString(this.variant.slice(1, -1), options); this.finalize(ast); diff --git a/src/slang-nodes/StringLiterals.js b/src/slang-nodes/StringLiterals.js index 21d88c47f..c1b08b789 100644 --- a/src/slang-nodes/StringLiterals.js +++ b/src/slang-nodes/StringLiterals.js @@ -6,8 +6,8 @@ const { join, hardline } = doc.builders; export class StringLiterals extends SlangNode { items; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/StructDefinition.js b/src/slang-nodes/StructDefinition.js index af3ddd9db..a7d1294a1 100644 --- a/src/slang-nodes/StructDefinition.js +++ b/src/slang-nodes/StructDefinition.js @@ -11,8 +11,8 @@ export class StructDefinition extends SlangNode { closeBrace; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/StructMember.js b/src/slang-nodes/StructMember.js index 2a1448bfc..9ec9984d9 100644 --- a/src/slang-nodes/StructMember.js +++ b/src/slang-nodes/StructMember.js @@ -7,8 +7,8 @@ export class StructMember extends SlangNode { semicolon; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/StructMembers.js b/src/slang-nodes/StructMembers.js index 73bbcc514..784ef3029 100644 --- a/src/slang-nodes/StructMembers.js +++ b/src/slang-nodes/StructMembers.js @@ -7,8 +7,8 @@ const { hardline } = doc.builders; export class StructMembers extends SlangNode { items; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/ThrowStatement.js b/src/slang-nodes/ThrowStatement.js index 75af926e8..7238bcb39 100644 --- a/src/slang-nodes/ThrowStatement.js +++ b/src/slang-nodes/ThrowStatement.js @@ -5,8 +5,8 @@ export class ThrowStatement extends SlangNode { semicolon; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/TryStatement.js b/src/slang-nodes/TryStatement.js index b23ac6a20..772f2bf27 100644 --- a/src/slang-nodes/TryStatement.js +++ b/src/slang-nodes/TryStatement.js @@ -15,8 +15,8 @@ export class TryStatement extends SlangNode { catchClauses; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/TupleDeconstructionElement.js b/src/slang-nodes/TupleDeconstructionElement.js index f27067da9..1060086d5 100644 --- a/src/slang-nodes/TupleDeconstructionElement.js +++ b/src/slang-nodes/TupleDeconstructionElement.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class TupleDeconstructionElement extends SlangNode { member; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/TupleDeconstructionElements.js b/src/slang-nodes/TupleDeconstructionElements.js index 54dbd3558..22eeeffd1 100644 --- a/src/slang-nodes/TupleDeconstructionElements.js +++ b/src/slang-nodes/TupleDeconstructionElements.js @@ -6,8 +6,8 @@ export class TupleDeconstructionElements extends SlangNode { separators; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/TupleDeconstructionStatement.js b/src/slang-nodes/TupleDeconstructionStatement.js index e0e583ec2..ce9abecf4 100644 --- a/src/slang-nodes/TupleDeconstructionStatement.js +++ b/src/slang-nodes/TupleDeconstructionStatement.js @@ -18,8 +18,8 @@ export class TupleDeconstructionStatement extends SlangNode { semicolon; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/TupleExpression.js b/src/slang-nodes/TupleExpression.js index e83b52b05..7f2a59ce3 100644 --- a/src/slang-nodes/TupleExpression.js +++ b/src/slang-nodes/TupleExpression.js @@ -7,8 +7,8 @@ export class TupleExpression extends SlangNode { closeParen; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); if (offset) { this.initialize(ast, parse); this.finalize(ast); diff --git a/src/slang-nodes/TupleMember.js b/src/slang-nodes/TupleMember.js index 02d546d58..ad3766748 100644 --- a/src/slang-nodes/TupleMember.js +++ b/src/slang-nodes/TupleMember.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class TupleMember extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/TupleValue.js b/src/slang-nodes/TupleValue.js index 1deab07ed..9d6bed418 100644 --- a/src/slang-nodes/TupleValue.js +++ b/src/slang-nodes/TupleValue.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class TupleValue extends SlangNode { expression; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); if (offset) { this.initialize(ast, parse); this.finalize(ast); diff --git a/src/slang-nodes/TupleValues.js b/src/slang-nodes/TupleValues.js index 450578c46..bfeaab9ac 100644 --- a/src/slang-nodes/TupleValues.js +++ b/src/slang-nodes/TupleValues.js @@ -7,8 +7,8 @@ export class TupleValues extends SlangNode { separators; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); if (offset) { this.initialize(ast, parse); this.finalize(ast); diff --git a/src/slang-nodes/TypeExpression.js b/src/slang-nodes/TypeExpression.js index f8c1c86e6..6962deb28 100644 --- a/src/slang-nodes/TypeExpression.js +++ b/src/slang-nodes/TypeExpression.js @@ -9,8 +9,8 @@ export class TypeExpression extends SlangNode { closeParen; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/TypeName.js b/src/slang-nodes/TypeName.js index 5656963d2..25e756b7d 100644 --- a/src/slang-nodes/TypeName.js +++ b/src/slang-nodes/TypeName.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class TypeName extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/TypedTupleMember.js b/src/slang-nodes/TypedTupleMember.js index 011f9ed2a..37c44a1b7 100644 --- a/src/slang-nodes/TypedTupleMember.js +++ b/src/slang-nodes/TypedTupleMember.js @@ -7,8 +7,8 @@ export class TypedTupleMember extends SlangNode { name; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/UncheckedBlock.js b/src/slang-nodes/UncheckedBlock.js index 4f7e470a8..ce81a00bc 100644 --- a/src/slang-nodes/UncheckedBlock.js +++ b/src/slang-nodes/UncheckedBlock.js @@ -5,8 +5,8 @@ export class UncheckedBlock extends SlangNode { block; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/UnicodeStringLiteral.js b/src/slang-nodes/UnicodeStringLiteral.js index 73517eae5..d93ab3fea 100644 --- a/src/slang-nodes/UnicodeStringLiteral.js +++ b/src/slang-nodes/UnicodeStringLiteral.js @@ -4,8 +4,8 @@ import { SlangNode } from './SlangNode.js'; export class UnicodeStringLiteral extends SlangNode { variant; - constructor(ast, offset, parse, options) { - super(ast, offset); + constructor(ast, offset, comments, parse, options) { + super(ast, offset, comments); this.initialize(ast, parse); this.variant = `unicode${printString(this.variant.slice(8, -1), options)}`; this.finalize(ast); diff --git a/src/slang-nodes/UnicodeStringLiterals.js b/src/slang-nodes/UnicodeStringLiterals.js index cba611b9e..06768ba8c 100644 --- a/src/slang-nodes/UnicodeStringLiterals.js +++ b/src/slang-nodes/UnicodeStringLiterals.js @@ -6,8 +6,8 @@ const { join, hardline } = doc.builders; export class UnicodeStringLiterals extends SlangNode { items; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/UnnamedFunctionAttribute.js b/src/slang-nodes/UnnamedFunctionAttribute.js index 88fef9653..cdfc8ed85 100644 --- a/src/slang-nodes/UnnamedFunctionAttribute.js +++ b/src/slang-nodes/UnnamedFunctionAttribute.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class UnnamedFunctionAttribute extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/UnnamedFunctionAttributes.js b/src/slang-nodes/UnnamedFunctionAttributes.js index 72fb2efda..fb223e789 100644 --- a/src/slang-nodes/UnnamedFunctionAttributes.js +++ b/src/slang-nodes/UnnamedFunctionAttributes.js @@ -7,8 +7,8 @@ const { line } = doc.builders; export class UnnamedFunctionAttributes extends SlangNode { items; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.items = this.items.sort(sortFunctionAttributes); this.finalize(ast); diff --git a/src/slang-nodes/UnnamedFunctionDefinition.js b/src/slang-nodes/UnnamedFunctionDefinition.js index ead1da672..c2345b1c6 100644 --- a/src/slang-nodes/UnnamedFunctionDefinition.js +++ b/src/slang-nodes/UnnamedFunctionDefinition.js @@ -10,8 +10,8 @@ export class UnnamedFunctionDefinition extends SlangNode { body; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.cleanModifierInvocationArguments(); this.finalize(ast); diff --git a/src/slang-nodes/UntypedTupleMember.js b/src/slang-nodes/UntypedTupleMember.js index 1b5f9bf03..279dea115 100644 --- a/src/slang-nodes/UntypedTupleMember.js +++ b/src/slang-nodes/UntypedTupleMember.js @@ -5,8 +5,8 @@ export class UntypedTupleMember extends SlangNode { name; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/UserDefinedValueTypeDefinition.js b/src/slang-nodes/UserDefinedValueTypeDefinition.js index 2cabd2ad1..da83770a8 100644 --- a/src/slang-nodes/UserDefinedValueTypeDefinition.js +++ b/src/slang-nodes/UserDefinedValueTypeDefinition.js @@ -11,8 +11,8 @@ export class UserDefinedValueTypeDefinition extends SlangNode { semicolon; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/UsingAlias.js b/src/slang-nodes/UsingAlias.js index eaeab1584..c7765a3ad 100644 --- a/src/slang-nodes/UsingAlias.js +++ b/src/slang-nodes/UsingAlias.js @@ -5,8 +5,8 @@ export class UsingAlias extends SlangNode { operator; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/UsingClause.js b/src/slang-nodes/UsingClause.js index f8f84b2d8..bf36909ce 100644 --- a/src/slang-nodes/UsingClause.js +++ b/src/slang-nodes/UsingClause.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class UsingClause extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/UsingDeconstruction.js b/src/slang-nodes/UsingDeconstruction.js index ec222e78f..67520bf00 100644 --- a/src/slang-nodes/UsingDeconstruction.js +++ b/src/slang-nodes/UsingDeconstruction.js @@ -7,8 +7,8 @@ export class UsingDeconstruction extends SlangNode { closeBrace; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/UsingDeconstructionSymbol.js b/src/slang-nodes/UsingDeconstructionSymbol.js index eaae89def..3f5c5244b 100644 --- a/src/slang-nodes/UsingDeconstructionSymbol.js +++ b/src/slang-nodes/UsingDeconstructionSymbol.js @@ -5,8 +5,8 @@ export class UsingDeconstructionSymbol extends SlangNode { alias; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/UsingDeconstructionSymbols.js b/src/slang-nodes/UsingDeconstructionSymbols.js index 0419a5008..2f7363a9b 100644 --- a/src/slang-nodes/UsingDeconstructionSymbols.js +++ b/src/slang-nodes/UsingDeconstructionSymbols.js @@ -9,8 +9,8 @@ export class UsingDeconstructionSymbols extends SlangNode { separators; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/UsingDirective.js b/src/slang-nodes/UsingDirective.js index 80d594d5b..635b7e527 100644 --- a/src/slang-nodes/UsingDirective.js +++ b/src/slang-nodes/UsingDirective.js @@ -13,8 +13,8 @@ export class UsingDirective extends SlangNode { semicolon; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/UsingOperator.js b/src/slang-nodes/UsingOperator.js index 1bf811179..5dba403be 100644 --- a/src/slang-nodes/UsingOperator.js +++ b/src/slang-nodes/UsingOperator.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class UsingOperator extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/UsingTarget.js b/src/slang-nodes/UsingTarget.js index 14f098684..314665114 100644 --- a/src/slang-nodes/UsingTarget.js +++ b/src/slang-nodes/UsingTarget.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class UsingTarget extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/VariableDeclarationStatement.js b/src/slang-nodes/VariableDeclarationStatement.js index 327b37c2d..01b943b4f 100644 --- a/src/slang-nodes/VariableDeclarationStatement.js +++ b/src/slang-nodes/VariableDeclarationStatement.js @@ -14,8 +14,8 @@ export class VariableDeclarationStatement extends SlangNode { semicolon; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/VariableDeclarationType.js b/src/slang-nodes/VariableDeclarationType.js index 21b2924f2..c2c6f09ac 100644 --- a/src/slang-nodes/VariableDeclarationType.js +++ b/src/slang-nodes/VariableDeclarationType.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class VariableDeclarationType extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/VariableDeclarationValue.js b/src/slang-nodes/VariableDeclarationValue.js index 1bd351d33..0c068324f 100644 --- a/src/slang-nodes/VariableDeclarationValue.js +++ b/src/slang-nodes/VariableDeclarationValue.js @@ -5,8 +5,8 @@ export class VariableDeclarationValue extends SlangNode { expression; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/VersionComparator.js b/src/slang-nodes/VersionComparator.js index c6a221f86..1ae2e9d5b 100644 --- a/src/slang-nodes/VersionComparator.js +++ b/src/slang-nodes/VersionComparator.js @@ -5,8 +5,8 @@ export class VersionComparator extends SlangNode { operand; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/VersionExpression.js b/src/slang-nodes/VersionExpression.js index 16001179e..dac6a5679 100644 --- a/src/slang-nodes/VersionExpression.js +++ b/src/slang-nodes/VersionExpression.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class VersionExpression extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/VersionExpressionSet.js b/src/slang-nodes/VersionExpressionSet.js index a016c2e67..c49fe2b2a 100644 --- a/src/slang-nodes/VersionExpressionSet.js +++ b/src/slang-nodes/VersionExpressionSet.js @@ -6,8 +6,8 @@ const { join } = doc.builders; export class VersionExpressionSet extends SlangNode { items; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/VersionExpressionSets.js b/src/slang-nodes/VersionExpressionSets.js index 26936dacc..669386ddf 100644 --- a/src/slang-nodes/VersionExpressionSets.js +++ b/src/slang-nodes/VersionExpressionSets.js @@ -5,8 +5,8 @@ export class VersionExpressionSets extends SlangNode { separators; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/VersionPragma.js b/src/slang-nodes/VersionPragma.js index d380d3fa9..46b98267e 100644 --- a/src/slang-nodes/VersionPragma.js +++ b/src/slang-nodes/VersionPragma.js @@ -5,8 +5,8 @@ export class VersionPragma extends SlangNode { sets; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/VersionRange.js b/src/slang-nodes/VersionRange.js index eadf4f02a..c00505113 100644 --- a/src/slang-nodes/VersionRange.js +++ b/src/slang-nodes/VersionRange.js @@ -7,8 +7,8 @@ export class VersionRange extends SlangNode { rightOperand; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/VersionSpecifiers.js b/src/slang-nodes/VersionSpecifiers.js index 6a66f8be0..c6d2b0bbe 100644 --- a/src/slang-nodes/VersionSpecifiers.js +++ b/src/slang-nodes/VersionSpecifiers.js @@ -5,8 +5,8 @@ export class VersionSpecifiers extends SlangNode { separators; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/WhileStatement.js b/src/slang-nodes/WhileStatement.js index 6d0be2623..2d604aaaf 100644 --- a/src/slang-nodes/WhileStatement.js +++ b/src/slang-nodes/WhileStatement.js @@ -15,8 +15,8 @@ export class WhileStatement extends SlangNode { body; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/YulArguments.js b/src/slang-nodes/YulArguments.js index 3e7afa42d..890b15f08 100644 --- a/src/slang-nodes/YulArguments.js +++ b/src/slang-nodes/YulArguments.js @@ -6,8 +6,8 @@ export class YulArguments extends SlangNode { separators; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/YulAssignmentOperator.js b/src/slang-nodes/YulAssignmentOperator.js index 023b9c418..917ca3cef 100644 --- a/src/slang-nodes/YulAssignmentOperator.js +++ b/src/slang-nodes/YulAssignmentOperator.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class YulAssignmentOperator extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/YulAssignmentStatement.js b/src/slang-nodes/YulAssignmentStatement.js index 1a7d781fb..4ec4dc499 100644 --- a/src/slang-nodes/YulAssignmentStatement.js +++ b/src/slang-nodes/YulAssignmentStatement.js @@ -7,8 +7,8 @@ export class YulAssignmentStatement extends SlangNode { expression; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/YulBlock.js b/src/slang-nodes/YulBlock.js index 1851371bb..b34774fb3 100644 --- a/src/slang-nodes/YulBlock.js +++ b/src/slang-nodes/YulBlock.js @@ -7,8 +7,8 @@ export class YulBlock extends SlangNode { closeBrace; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/YulBreakStatement.js b/src/slang-nodes/YulBreakStatement.js index 96a242e9b..830155439 100644 --- a/src/slang-nodes/YulBreakStatement.js +++ b/src/slang-nodes/YulBreakStatement.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class YulBreakStatement extends SlangNode { breakKeyword; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/YulBuiltInFunction.js b/src/slang-nodes/YulBuiltInFunction.js index c657e86ff..af0212b9d 100644 --- a/src/slang-nodes/YulBuiltInFunction.js +++ b/src/slang-nodes/YulBuiltInFunction.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class YulBuiltInFunction extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/YulColonAndEqual.js b/src/slang-nodes/YulColonAndEqual.js index 8067233e5..e900e2d1c 100644 --- a/src/slang-nodes/YulColonAndEqual.js +++ b/src/slang-nodes/YulColonAndEqual.js @@ -5,8 +5,8 @@ export class YulColonAndEqual extends SlangNode { equal; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/YulContinueStatement.js b/src/slang-nodes/YulContinueStatement.js index 009b1cbd6..5fe979ee3 100644 --- a/src/slang-nodes/YulContinueStatement.js +++ b/src/slang-nodes/YulContinueStatement.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class YulContinueStatement extends SlangNode { continueKeyword; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/YulDefaultCase.js b/src/slang-nodes/YulDefaultCase.js index af554bd86..1e856f068 100644 --- a/src/slang-nodes/YulDefaultCase.js +++ b/src/slang-nodes/YulDefaultCase.js @@ -5,8 +5,8 @@ export class YulDefaultCase extends SlangNode { body; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/YulExpression.js b/src/slang-nodes/YulExpression.js index 0d3c5d1b7..361750fd2 100644 --- a/src/slang-nodes/YulExpression.js +++ b/src/slang-nodes/YulExpression.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class YulExpression extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/YulForStatement.js b/src/slang-nodes/YulForStatement.js index 6d73a8764..3d723b017 100644 --- a/src/slang-nodes/YulForStatement.js +++ b/src/slang-nodes/YulForStatement.js @@ -11,8 +11,8 @@ export class YulForStatement extends SlangNode { body; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/YulFunctionCallExpression.js b/src/slang-nodes/YulFunctionCallExpression.js index 349c16b65..196802886 100644 --- a/src/slang-nodes/YulFunctionCallExpression.js +++ b/src/slang-nodes/YulFunctionCallExpression.js @@ -9,8 +9,8 @@ export class YulFunctionCallExpression extends SlangNode { closeParen; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/YulFunctionDefinition.js b/src/slang-nodes/YulFunctionDefinition.js index 17702b3b0..41d2c89e9 100644 --- a/src/slang-nodes/YulFunctionDefinition.js +++ b/src/slang-nodes/YulFunctionDefinition.js @@ -11,8 +11,8 @@ export class YulFunctionDefinition extends SlangNode { body; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/YulIfStatement.js b/src/slang-nodes/YulIfStatement.js index d1b08fe1b..9a952ec01 100644 --- a/src/slang-nodes/YulIfStatement.js +++ b/src/slang-nodes/YulIfStatement.js @@ -7,8 +7,8 @@ export class YulIfStatement extends SlangNode { body; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/YulLabel.js b/src/slang-nodes/YulLabel.js index a6c13e630..ed4d71e9f 100644 --- a/src/slang-nodes/YulLabel.js +++ b/src/slang-nodes/YulLabel.js @@ -7,8 +7,8 @@ export class YulLabel extends SlangNode { colon; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/YulLeaveStatement.js b/src/slang-nodes/YulLeaveStatement.js index 8907e8d9a..527d0ac3d 100644 --- a/src/slang-nodes/YulLeaveStatement.js +++ b/src/slang-nodes/YulLeaveStatement.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class YulLeaveStatement extends SlangNode { leaveKeyword; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/YulLiteral.js b/src/slang-nodes/YulLiteral.js index 0511d3f39..f2beb34a8 100644 --- a/src/slang-nodes/YulLiteral.js +++ b/src/slang-nodes/YulLiteral.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class YulLiteral extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/YulParameters.js b/src/slang-nodes/YulParameters.js index 16098c2ed..7d73cf157 100644 --- a/src/slang-nodes/YulParameters.js +++ b/src/slang-nodes/YulParameters.js @@ -6,8 +6,8 @@ export class YulParameters extends SlangNode { separators; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/YulParametersDeclaration.js b/src/slang-nodes/YulParametersDeclaration.js index 2c133ab68..80430319b 100644 --- a/src/slang-nodes/YulParametersDeclaration.js +++ b/src/slang-nodes/YulParametersDeclaration.js @@ -7,8 +7,8 @@ export class YulParametersDeclaration extends SlangNode { closeParen; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/YulPath.js b/src/slang-nodes/YulPath.js index a26c81f48..72cfacd46 100644 --- a/src/slang-nodes/YulPath.js +++ b/src/slang-nodes/YulPath.js @@ -5,8 +5,8 @@ export class YulPath extends SlangNode { separators; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/YulPathComponent.js b/src/slang-nodes/YulPathComponent.js index 823d9c6e1..3fc421293 100644 --- a/src/slang-nodes/YulPathComponent.js +++ b/src/slang-nodes/YulPathComponent.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class YulPathComponent extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/YulPaths.js b/src/slang-nodes/YulPaths.js index 63d429f79..f81f3e617 100644 --- a/src/slang-nodes/YulPaths.js +++ b/src/slang-nodes/YulPaths.js @@ -5,8 +5,8 @@ export class YulPaths extends SlangNode { separators; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/YulReturnVariables.js b/src/slang-nodes/YulReturnVariables.js index a6d17a264..740aab75f 100644 --- a/src/slang-nodes/YulReturnVariables.js +++ b/src/slang-nodes/YulReturnVariables.js @@ -9,8 +9,8 @@ export class YulReturnVariables extends SlangNode { separators; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/YulReturnsDeclaration.js b/src/slang-nodes/YulReturnsDeclaration.js index cdb0d1847..c815952fa 100644 --- a/src/slang-nodes/YulReturnsDeclaration.js +++ b/src/slang-nodes/YulReturnsDeclaration.js @@ -9,8 +9,8 @@ export class YulReturnsDeclaration extends SlangNode { variables; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/YulStatement.js b/src/slang-nodes/YulStatement.js index fa52577f4..26b7c7043 100644 --- a/src/slang-nodes/YulStatement.js +++ b/src/slang-nodes/YulStatement.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class YulStatement extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/YulStatements.js b/src/slang-nodes/YulStatements.js index f498c7c47..5ca85781e 100644 --- a/src/slang-nodes/YulStatements.js +++ b/src/slang-nodes/YulStatements.js @@ -9,8 +9,8 @@ const { hardline } = doc.builders; export class YulStatements extends SlangNode { items; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/YulSwitchCase.js b/src/slang-nodes/YulSwitchCase.js index 8911049f4..ac4edf7ce 100644 --- a/src/slang-nodes/YulSwitchCase.js +++ b/src/slang-nodes/YulSwitchCase.js @@ -3,8 +3,8 @@ import { SlangNode } from './SlangNode.js'; export class YulSwitchCase extends SlangNode { variant; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/YulSwitchCases.js b/src/slang-nodes/YulSwitchCases.js index de018c0d0..60f65c6dc 100644 --- a/src/slang-nodes/YulSwitchCases.js +++ b/src/slang-nodes/YulSwitchCases.js @@ -6,8 +6,8 @@ const { hardline, join } = doc.builders; export class YulSwitchCases extends SlangNode { items; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/YulSwitchStatement.js b/src/slang-nodes/YulSwitchStatement.js index 6b18d49c8..88cf5bd0c 100644 --- a/src/slang-nodes/YulSwitchStatement.js +++ b/src/slang-nodes/YulSwitchStatement.js @@ -10,8 +10,8 @@ export class YulSwitchStatement extends SlangNode { cases; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/YulValueCase.js b/src/slang-nodes/YulValueCase.js index 2e67607ce..0d1aacee9 100644 --- a/src/slang-nodes/YulValueCase.js +++ b/src/slang-nodes/YulValueCase.js @@ -7,8 +7,8 @@ export class YulValueCase extends SlangNode { body; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/YulVariableAssignmentStatement.js b/src/slang-nodes/YulVariableAssignmentStatement.js index a8f3e6ed7..a74c721c1 100644 --- a/src/slang-nodes/YulVariableAssignmentStatement.js +++ b/src/slang-nodes/YulVariableAssignmentStatement.js @@ -7,8 +7,8 @@ export class YulVariableAssignmentStatement extends SlangNode { expression; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/YulVariableDeclarationStatement.js b/src/slang-nodes/YulVariableDeclarationStatement.js index 4d5431f14..e117964e5 100644 --- a/src/slang-nodes/YulVariableDeclarationStatement.js +++ b/src/slang-nodes/YulVariableDeclarationStatement.js @@ -7,8 +7,8 @@ export class YulVariableDeclarationStatement extends SlangNode { value; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slang-nodes/YulVariableDeclarationValue.js b/src/slang-nodes/YulVariableDeclarationValue.js index 407d136a4..231920228 100644 --- a/src/slang-nodes/YulVariableDeclarationValue.js +++ b/src/slang-nodes/YulVariableDeclarationValue.js @@ -5,8 +5,8 @@ export class YulVariableDeclarationValue extends SlangNode { expression; - constructor(ast, offset, parse) { - super(ast, offset); + constructor(ast, offset, comments, parse) { + super(ast, offset, comments); this.initialize(ast, parse); this.finalize(ast); } diff --git a/src/slangParser.js b/src/slangParser.js index a833577cd..364198db3 100644 --- a/src/slangParser.js +++ b/src/slangParser.js @@ -6,9 +6,15 @@ import { SourceUnit } from '@nomicfoundation/slang/ast/index.js'; import coerce from 'semver/functions/coerce.js'; import * as parsers from './slang-nodes/index.js'; -function genericParseBuilder(options) { +function createGenericParse(options, comments) { return function genericParse(ast, offset = 0) { - return new parsers[ast.cst.kind](ast, offset, genericParse, options); + return new parsers[ast.cst.kind]( + ast, + offset, + comments, + genericParse, + options + ); }; } @@ -20,10 +26,12 @@ function parse(text, _parsers, options = _parsers) { language.parse(NonterminalKind.SourceUnit, text).tree() ); - const genericParse = genericParseBuilder(options); + const comments = []; + + const genericParse = createGenericParse(options, comments); const parsed = genericParse(ast); - parsed.collectComments(); + parsed.comments = comments; return parsed; } From 84e2b78ee85a776879a0919fabaef9fb8243d0e3 Mon Sep 17 00:00:00 2001 From: Klaus Date: Tue, 16 Jul 2024 12:20:11 +1200 Subject: [PATCH 081/160] smaller boilerplate --- src/slang-nodes/ABICoderPragma.js | 5 +- src/slang-nodes/AdditiveExpression.js | 6 +- src/slang-nodes/AddressType.js | 5 +- src/slang-nodes/AndExpression.js | 5 +- src/slang-nodes/ArgumentsDeclaration.js | 5 +- src/slang-nodes/ArrayExpression.js | 5 +- src/slang-nodes/ArrayTypeName.js | 5 +- src/slang-nodes/ArrayValues.js | 5 +- src/slang-nodes/AssemblyFlags.js | 5 +- src/slang-nodes/AssemblyFlagsDeclaration.js | 5 +- src/slang-nodes/AssemblyStatement.js | 5 +- src/slang-nodes/AssignmentExpression.js | 5 +- src/slang-nodes/BitwiseAndExpression.js | 6 +- src/slang-nodes/BitwiseOrExpression.js | 6 +- src/slang-nodes/BitwiseXorExpression.js | 6 +- src/slang-nodes/Block.js | 5 +- src/slang-nodes/BreakStatement.js | 5 +- src/slang-nodes/CallOptions.js | 5 +- src/slang-nodes/CallOptionsExpression.js | 5 +- src/slang-nodes/CatchClause.js | 5 +- src/slang-nodes/CatchClauseError.js | 5 +- src/slang-nodes/CatchClauses.js | 5 +- src/slang-nodes/ComparisonExpression.js | 5 +- src/slang-nodes/ConditionalExpression.js | 6 +- src/slang-nodes/ConstantDefinition.js | 5 +- src/slang-nodes/ConstructorAttribute.js | 5 +- src/slang-nodes/ConstructorAttributes.js | 6 +- src/slang-nodes/ConstructorDefinition.js | 5 +- src/slang-nodes/ContinueStatement.js | 5 +- src/slang-nodes/ContractDefinition.js | 6 +- src/slang-nodes/ContractMember.js | 5 +- src/slang-nodes/ContractMembers.js | 5 +- src/slang-nodes/DecimalNumberExpression.js | 5 +- src/slang-nodes/DoWhileStatement.js | 5 +- src/slang-nodes/ElementaryType.js | 5 +- src/slang-nodes/ElseBranch.js | 6 +- src/slang-nodes/EmitStatement.js | 5 +- src/slang-nodes/EnumDefinition.js | 5 +- src/slang-nodes/EnumMembers.js | 5 +- src/slang-nodes/EqualityExpression.js | 5 +- src/slang-nodes/ErrorDefinition.js | 5 +- src/slang-nodes/ErrorParameter.js | 5 +- src/slang-nodes/ErrorParameters.js | 5 +- src/slang-nodes/ErrorParametersDeclaration.js | 5 +- src/slang-nodes/EventDefinition.js | 5 +- src/slang-nodes/EventParameter.js | 5 +- src/slang-nodes/EventParameters.js | 5 +- src/slang-nodes/EventParametersDeclaration.js | 5 +- src/slang-nodes/ExperimentalFeature.js | 5 +- src/slang-nodes/ExperimentalPragma.js | 5 +- src/slang-nodes/ExponentiationExpression.js | 6 +- src/slang-nodes/Expression.js | 5 +- src/slang-nodes/ExpressionStatement.js | 5 +- src/slang-nodes/FallbackFunctionAttribute.js | 5 +- src/slang-nodes/FallbackFunctionAttributes.js | 6 +- src/slang-nodes/FallbackFunctionDefinition.js | 6 +- src/slang-nodes/ForStatement.js | 5 +- src/slang-nodes/ForStatementCondition.js | 5 +- src/slang-nodes/ForStatementInitialization.js | 5 +- src/slang-nodes/FunctionAttribute.js | 5 +- src/slang-nodes/FunctionAttributes.js | 6 +- src/slang-nodes/FunctionBody.js | 5 +- src/slang-nodes/FunctionCallExpression.js | 5 +- src/slang-nodes/FunctionDefinition.js | 6 +- src/slang-nodes/FunctionName.js | 5 +- src/slang-nodes/FunctionType.js | 5 +- src/slang-nodes/FunctionTypeAttribute.js | 5 +- src/slang-nodes/FunctionTypeAttributes.js | 6 +- src/slang-nodes/HexNumberExpression.js | 5 +- src/slang-nodes/HexStringLiteral.js | 6 +- src/slang-nodes/HexStringLiterals.js | 5 +- src/slang-nodes/IdentifierPath.js | 5 +- src/slang-nodes/IfStatement.js | 5 +- src/slang-nodes/ImportAlias.js | 5 +- src/slang-nodes/ImportClause.js | 5 +- src/slang-nodes/ImportDeconstruction.js | 5 +- src/slang-nodes/ImportDeconstructionSymbol.js | 5 +- .../ImportDeconstructionSymbols.js | 5 +- src/slang-nodes/ImportDirective.js | 5 +- src/slang-nodes/IndexAccessEnd.js | 5 +- src/slang-nodes/IndexAccessExpression.js | 6 +- src/slang-nodes/InheritanceSpecifier.js | 5 +- src/slang-nodes/InheritanceType.js | 5 +- src/slang-nodes/InheritanceTypes.js | 5 +- src/slang-nodes/InterfaceDefinition.js | 5 +- src/slang-nodes/InterfaceMembers.js | 5 +- src/slang-nodes/LibraryDefinition.js | 5 +- src/slang-nodes/LibraryMembers.js | 5 +- src/slang-nodes/MappingKey.js | 5 +- src/slang-nodes/MappingKeyType.js | 5 +- src/slang-nodes/MappingType.js | 5 +- src/slang-nodes/MappingValue.js | 5 +- src/slang-nodes/MemberAccess.js | 5 +- src/slang-nodes/MemberAccessExpression.js | 5 +- src/slang-nodes/ModifierAttribute.js | 5 +- src/slang-nodes/ModifierAttributes.js | 6 +- src/slang-nodes/ModifierDefinition.js | 6 +- src/slang-nodes/ModifierInvocation.js | 6 +- src/slang-nodes/MultiplicativeExpression.js | 6 +- src/slang-nodes/NamedArgument.js | 5 +- src/slang-nodes/NamedArgumentGroup.js | 5 +- src/slang-nodes/NamedArguments.js | 5 +- src/slang-nodes/NamedArgumentsDeclaration.js | 5 +- src/slang-nodes/NamedImport.js | 5 +- src/slang-nodes/NewExpression.js | 5 +- src/slang-nodes/NumberUnit.js | 5 +- src/slang-nodes/OrExpression.js | 6 +- src/slang-nodes/OverridePaths.js | 5 +- src/slang-nodes/OverridePathsDeclaration.js | 5 +- src/slang-nodes/OverrideSpecifier.js | 5 +- src/slang-nodes/Parameter.js | 5 +- src/slang-nodes/Parameters.js | 5 +- src/slang-nodes/ParametersDeclaration.js | 5 +- src/slang-nodes/PathImport.js | 5 +- src/slang-nodes/PositionalArguments.js | 5 +- .../PositionalArgumentsDeclaration.js | 5 +- src/slang-nodes/PostfixExpression.js | 5 +- src/slang-nodes/Pragma.js | 5 +- src/slang-nodes/PragmaDirective.js | 5 +- src/slang-nodes/PrefixExpression.js | 5 +- src/slang-nodes/ReceiveFunctionAttribute.js | 5 +- src/slang-nodes/ReceiveFunctionAttributes.js | 6 +- src/slang-nodes/ReceiveFunctionDefinition.js | 6 +- src/slang-nodes/ReturnStatement.js | 5 +- src/slang-nodes/ReturnsDeclaration.js | 5 +- src/slang-nodes/RevertStatement.js | 5 +- src/slang-nodes/ShiftExpression.js | 6 +- src/slang-nodes/SlangNode.js | 139 +++++------------- src/slang-nodes/SourceUnit.js | 5 +- src/slang-nodes/SourceUnitMember.js | 5 +- src/slang-nodes/SourceUnitMembers.js | 5 +- src/slang-nodes/StateVariableAttribute.js | 5 +- src/slang-nodes/StateVariableAttributes.js | 5 +- src/slang-nodes/StateVariableDefinition.js | 5 +- .../StateVariableDefinitionValue.js | 5 +- src/slang-nodes/Statement.js | 5 +- src/slang-nodes/Statements.js | 6 +- src/slang-nodes/StorageLocation.js | 5 +- src/slang-nodes/StringExpression.js | 5 +- src/slang-nodes/StringLiteral.js | 6 +- src/slang-nodes/StringLiterals.js | 5 +- src/slang-nodes/StructDefinition.js | 5 +- src/slang-nodes/StructMember.js | 5 +- src/slang-nodes/StructMembers.js | 5 +- src/slang-nodes/ThrowStatement.js | 5 +- src/slang-nodes/TryStatement.js | 5 +- src/slang-nodes/TupleDeconstructionElement.js | 5 +- .../TupleDeconstructionElements.js | 5 +- .../TupleDeconstructionStatement.js | 5 +- src/slang-nodes/TupleExpression.js | 5 +- src/slang-nodes/TupleMember.js | 5 +- src/slang-nodes/TupleValue.js | 5 +- src/slang-nodes/TupleValues.js | 5 +- src/slang-nodes/TypeExpression.js | 5 +- src/slang-nodes/TypeName.js | 5 +- src/slang-nodes/TypedTupleMember.js | 5 +- src/slang-nodes/UncheckedBlock.js | 5 +- src/slang-nodes/UnicodeStringLiteral.js | 6 +- src/slang-nodes/UnicodeStringLiterals.js | 5 +- src/slang-nodes/UnnamedFunctionAttribute.js | 5 +- src/slang-nodes/UnnamedFunctionAttributes.js | 6 +- src/slang-nodes/UnnamedFunctionDefinition.js | 6 +- src/slang-nodes/UntypedTupleMember.js | 5 +- .../UserDefinedValueTypeDefinition.js | 5 +- src/slang-nodes/UsingAlias.js | 5 +- src/slang-nodes/UsingClause.js | 5 +- src/slang-nodes/UsingDeconstruction.js | 5 +- src/slang-nodes/UsingDeconstructionSymbol.js | 5 +- src/slang-nodes/UsingDeconstructionSymbols.js | 5 +- src/slang-nodes/UsingDirective.js | 5 +- src/slang-nodes/UsingOperator.js | 5 +- src/slang-nodes/UsingTarget.js | 5 +- .../VariableDeclarationStatement.js | 5 +- src/slang-nodes/VariableDeclarationType.js | 5 +- src/slang-nodes/VariableDeclarationValue.js | 5 +- src/slang-nodes/VersionComparator.js | 5 +- src/slang-nodes/VersionExpression.js | 5 +- src/slang-nodes/VersionExpressionSet.js | 5 +- src/slang-nodes/VersionExpressionSets.js | 5 +- src/slang-nodes/VersionPragma.js | 5 +- src/slang-nodes/VersionRange.js | 5 +- src/slang-nodes/VersionSpecifiers.js | 5 +- src/slang-nodes/WhileStatement.js | 5 +- src/slang-nodes/YulArguments.js | 5 +- src/slang-nodes/YulAssignmentOperator.js | 5 +- src/slang-nodes/YulAssignmentStatement.js | 5 +- src/slang-nodes/YulBlock.js | 5 +- src/slang-nodes/YulBreakStatement.js | 5 +- src/slang-nodes/YulBuiltInFunction.js | 5 +- src/slang-nodes/YulColonAndEqual.js | 5 +- src/slang-nodes/YulContinueStatement.js | 5 +- src/slang-nodes/YulDefaultCase.js | 5 +- src/slang-nodes/YulExpression.js | 5 +- src/slang-nodes/YulForStatement.js | 5 +- src/slang-nodes/YulFunctionCallExpression.js | 5 +- src/slang-nodes/YulFunctionDefinition.js | 5 +- src/slang-nodes/YulIfStatement.js | 5 +- src/slang-nodes/YulLabel.js | 6 +- src/slang-nodes/YulLeaveStatement.js | 5 +- src/slang-nodes/YulLiteral.js | 5 +- src/slang-nodes/YulParameters.js | 5 +- src/slang-nodes/YulParametersDeclaration.js | 5 +- src/slang-nodes/YulPath.js | 5 +- src/slang-nodes/YulPathComponent.js | 5 +- src/slang-nodes/YulPaths.js | 5 +- src/slang-nodes/YulReturnVariables.js | 5 +- src/slang-nodes/YulReturnsDeclaration.js | 5 +- src/slang-nodes/YulStatement.js | 5 +- src/slang-nodes/YulStatements.js | 5 +- src/slang-nodes/YulSwitchCase.js | 5 +- src/slang-nodes/YulSwitchCases.js | 5 +- src/slang-nodes/YulSwitchStatement.js | 5 +- src/slang-nodes/YulValueCase.js | 5 +- .../YulVariableAssignmentStatement.js | 5 +- .../YulVariableDeclarationStatement.js | 5 +- .../YulVariableDeclarationValue.js | 5 +- src/slang-utils/get-offsets.js | 58 ++++++++ src/slang-utils/loc.js | 8 +- 218 files changed, 546 insertions(+), 764 deletions(-) create mode 100644 src/slang-utils/get-offsets.js diff --git a/src/slang-nodes/ABICoderPragma.js b/src/slang-nodes/ABICoderPragma.js index fe9dc853e..65def6c35 100644 --- a/src/slang-nodes/ABICoderPragma.js +++ b/src/slang-nodes/ABICoderPragma.js @@ -6,9 +6,8 @@ export class ABICoderPragma extends SlangNode { version; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print() { diff --git a/src/slang-nodes/AdditiveExpression.js b/src/slang-nodes/AdditiveExpression.js index d5cd658a4..ef447c583 100644 --- a/src/slang-nodes/AdditiveExpression.js +++ b/src/slang-nodes/AdditiveExpression.js @@ -12,11 +12,11 @@ export class AdditiveExpression extends SlangNode { rightOperand; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); + super(); + this.initialize(ast, offset, comments, parse); + this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); - this.finalize(ast); } print(path, print, options) { diff --git a/src/slang-nodes/AddressType.js b/src/slang-nodes/AddressType.js index 200bde5f8..067f8282e 100644 --- a/src/slang-nodes/AddressType.js +++ b/src/slang-nodes/AddressType.js @@ -6,9 +6,8 @@ export class AddressType extends SlangNode { payableKeyword; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print() { diff --git a/src/slang-nodes/AndExpression.js b/src/slang-nodes/AndExpression.js index fbbb7d09c..160f10486 100644 --- a/src/slang-nodes/AndExpression.js +++ b/src/slang-nodes/AndExpression.js @@ -9,9 +9,8 @@ export class AndExpression extends SlangNode { rightOperand; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print, options) { diff --git a/src/slang-nodes/ArgumentsDeclaration.js b/src/slang-nodes/ArgumentsDeclaration.js index f9368f1cf..03ab626ca 100644 --- a/src/slang-nodes/ArgumentsDeclaration.js +++ b/src/slang-nodes/ArgumentsDeclaration.js @@ -4,9 +4,8 @@ export class ArgumentsDeclaration extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/ArrayExpression.js b/src/slang-nodes/ArrayExpression.js index c2bfa45b7..c38adc90a 100644 --- a/src/slang-nodes/ArrayExpression.js +++ b/src/slang-nodes/ArrayExpression.js @@ -11,9 +11,8 @@ export class ArrayExpression extends SlangNode { closeBracket; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/ArrayTypeName.js b/src/slang-nodes/ArrayTypeName.js index 752509de6..64b98d963 100644 --- a/src/slang-nodes/ArrayTypeName.js +++ b/src/slang-nodes/ArrayTypeName.js @@ -10,9 +10,8 @@ export class ArrayTypeName extends SlangNode { closeBracket; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/ArrayValues.js b/src/slang-nodes/ArrayValues.js index 33394cd9a..b0a16aa8a 100644 --- a/src/slang-nodes/ArrayValues.js +++ b/src/slang-nodes/ArrayValues.js @@ -7,9 +7,8 @@ export class ArrayValues extends SlangNode { separators; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/AssemblyFlags.js b/src/slang-nodes/AssemblyFlags.js index e6d060f26..f8b6df147 100644 --- a/src/slang-nodes/AssemblyFlags.js +++ b/src/slang-nodes/AssemblyFlags.js @@ -7,9 +7,8 @@ export class AssemblyFlags extends SlangNode { separators; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/AssemblyFlagsDeclaration.js b/src/slang-nodes/AssemblyFlagsDeclaration.js index 703cd794c..e37d2c003 100644 --- a/src/slang-nodes/AssemblyFlagsDeclaration.js +++ b/src/slang-nodes/AssemblyFlagsDeclaration.js @@ -8,9 +8,8 @@ export class AssemblyFlagsDeclaration extends SlangNode { closeParen; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/AssemblyStatement.js b/src/slang-nodes/AssemblyStatement.js index 223035d28..6e0eb5a0c 100644 --- a/src/slang-nodes/AssemblyStatement.js +++ b/src/slang-nodes/AssemblyStatement.js @@ -10,9 +10,8 @@ export class AssemblyStatement extends SlangNode { body; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/AssignmentExpression.js b/src/slang-nodes/AssignmentExpression.js index dd9d23f34..c7afc7046 100644 --- a/src/slang-nodes/AssignmentExpression.js +++ b/src/slang-nodes/AssignmentExpression.js @@ -12,9 +12,8 @@ export class AssignmentExpression extends SlangNode { rightOperand; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/BitwiseAndExpression.js b/src/slang-nodes/BitwiseAndExpression.js index fb172133e..c3f2de493 100644 --- a/src/slang-nodes/BitwiseAndExpression.js +++ b/src/slang-nodes/BitwiseAndExpression.js @@ -12,11 +12,11 @@ export class BitwiseAndExpression extends SlangNode { rightOperand; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); + super(); + this.initialize(ast, offset, comments, parse); + this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); - this.finalize(ast); } print(path, print, options) { diff --git a/src/slang-nodes/BitwiseOrExpression.js b/src/slang-nodes/BitwiseOrExpression.js index df9913b0c..277ba1dfa 100644 --- a/src/slang-nodes/BitwiseOrExpression.js +++ b/src/slang-nodes/BitwiseOrExpression.js @@ -22,11 +22,11 @@ export class BitwiseOrExpression extends SlangNode { rightOperand; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); + super(); + this.initialize(ast, offset, comments, parse); + this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); - this.finalize(ast); } print(path, print, options) { diff --git a/src/slang-nodes/BitwiseXorExpression.js b/src/slang-nodes/BitwiseXorExpression.js index 444ba0057..18085126e 100644 --- a/src/slang-nodes/BitwiseXorExpression.js +++ b/src/slang-nodes/BitwiseXorExpression.js @@ -12,11 +12,11 @@ export class BitwiseXorExpression extends SlangNode { rightOperand; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); + super(); + this.initialize(ast, offset, comments, parse); + this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); - this.finalize(ast); } print(path, print, options) { diff --git a/src/slang-nodes/Block.js b/src/slang-nodes/Block.js index d87acff3e..9facac25e 100644 --- a/src/slang-nodes/Block.js +++ b/src/slang-nodes/Block.js @@ -8,9 +8,8 @@ export class Block extends SlangNode { closeBrace; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/BreakStatement.js b/src/slang-nodes/BreakStatement.js index 4edd55db6..4d99ecdea 100644 --- a/src/slang-nodes/BreakStatement.js +++ b/src/slang-nodes/BreakStatement.js @@ -6,9 +6,8 @@ export class BreakStatement extends SlangNode { semicolon; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print() { diff --git a/src/slang-nodes/CallOptions.js b/src/slang-nodes/CallOptions.js index cea72611a..b6c96129b 100644 --- a/src/slang-nodes/CallOptions.js +++ b/src/slang-nodes/CallOptions.js @@ -10,9 +10,8 @@ export class CallOptions extends SlangNode { separators; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print, options) { diff --git a/src/slang-nodes/CallOptionsExpression.js b/src/slang-nodes/CallOptionsExpression.js index a71a57a13..91c07ead0 100644 --- a/src/slang-nodes/CallOptionsExpression.js +++ b/src/slang-nodes/CallOptionsExpression.js @@ -10,9 +10,8 @@ export class CallOptionsExpression extends SlangNode { closeBrace; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/CatchClause.js b/src/slang-nodes/CatchClause.js index bd0a26b89..d09c56d6c 100644 --- a/src/slang-nodes/CatchClause.js +++ b/src/slang-nodes/CatchClause.js @@ -8,9 +8,8 @@ export class CatchClause extends SlangNode { body; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/CatchClauseError.js b/src/slang-nodes/CatchClauseError.js index e33bc7375..0f68da221 100644 --- a/src/slang-nodes/CatchClauseError.js +++ b/src/slang-nodes/CatchClauseError.js @@ -9,9 +9,8 @@ export class CatchClauseError extends SlangNode { parameters; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/CatchClauses.js b/src/slang-nodes/CatchClauses.js index eda8162d1..8f3cdba39 100644 --- a/src/slang-nodes/CatchClauses.js +++ b/src/slang-nodes/CatchClauses.js @@ -7,9 +7,8 @@ export class CatchClauses extends SlangNode { items; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/ComparisonExpression.js b/src/slang-nodes/ComparisonExpression.js index 8721f800f..ad42086f2 100644 --- a/src/slang-nodes/ComparisonExpression.js +++ b/src/slang-nodes/ComparisonExpression.js @@ -9,9 +9,8 @@ export class ComparisonExpression extends SlangNode { rightOperand; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print, options) { diff --git a/src/slang-nodes/ConditionalExpression.js b/src/slang-nodes/ConditionalExpression.js index 0a83fa291..dfabbe743 100644 --- a/src/slang-nodes/ConditionalExpression.js +++ b/src/slang-nodes/ConditionalExpression.js @@ -96,8 +96,8 @@ export class ConditionalExpression extends SlangNode { falseExpression; constructor(ast, offset, comments, parse, options) { - super(ast, offset, comments); - this.initialize(ast, parse); + super(); + this.initialize(ast, offset, comments, parse); // TODO: while the behaviour is not stable, it should be behind the // experimentalTernaries flag. @@ -116,8 +116,6 @@ export class ConditionalExpression extends SlangNode { this.operand.loc = operandLoc; } - - this.finalize(ast); } print(path, print, options) { diff --git a/src/slang-nodes/ConstantDefinition.js b/src/slang-nodes/ConstantDefinition.js index 71c81e53d..55adc3f7b 100644 --- a/src/slang-nodes/ConstantDefinition.js +++ b/src/slang-nodes/ConstantDefinition.js @@ -14,9 +14,8 @@ export class ConstantDefinition extends SlangNode { semicolon; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } // TODO: implement print diff --git a/src/slang-nodes/ConstructorAttribute.js b/src/slang-nodes/ConstructorAttribute.js index 297e7d3a1..04394f671 100644 --- a/src/slang-nodes/ConstructorAttribute.js +++ b/src/slang-nodes/ConstructorAttribute.js @@ -4,9 +4,8 @@ export class ConstructorAttribute extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/ConstructorAttributes.js b/src/slang-nodes/ConstructorAttributes.js index a27fa04e2..b06d64988 100644 --- a/src/slang-nodes/ConstructorAttributes.js +++ b/src/slang-nodes/ConstructorAttributes.js @@ -8,10 +8,10 @@ export class ConstructorAttributes extends SlangNode { items; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); + super(); + this.initialize(ast, offset, comments, parse); + this.items = this.items.sort(sortFunctionAttributes); - this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/ConstructorDefinition.js b/src/slang-nodes/ConstructorDefinition.js index ac8dbc812..400378ce3 100644 --- a/src/slang-nodes/ConstructorDefinition.js +++ b/src/slang-nodes/ConstructorDefinition.js @@ -11,9 +11,8 @@ export class ConstructorDefinition extends SlangNode { body; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/ContinueStatement.js b/src/slang-nodes/ContinueStatement.js index 5d0809c1d..f8a54bcb3 100644 --- a/src/slang-nodes/ContinueStatement.js +++ b/src/slang-nodes/ContinueStatement.js @@ -6,9 +6,8 @@ export class ContinueStatement extends SlangNode { semicolon; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print() { diff --git a/src/slang-nodes/ContractDefinition.js b/src/slang-nodes/ContractDefinition.js index 7120f5e97..28f4986cb 100644 --- a/src/slang-nodes/ContractDefinition.js +++ b/src/slang-nodes/ContractDefinition.js @@ -21,10 +21,10 @@ export class ContractDefinition extends SlangNode { closeBrace; constructor(ast, offset, comments, parse, options) { - super(ast, offset, comments); - this.initialize(ast, parse); + super(); + this.initialize(ast, offset, comments, parse); + this.cleanModifierInvocationArguments(options); - this.finalize(ast); } cleanModifierInvocationArguments(options) { diff --git a/src/slang-nodes/ContractMember.js b/src/slang-nodes/ContractMember.js index 8d539dd57..92b5beac7 100644 --- a/src/slang-nodes/ContractMember.js +++ b/src/slang-nodes/ContractMember.js @@ -4,9 +4,8 @@ export class ContractMember extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/ContractMembers.js b/src/slang-nodes/ContractMembers.js index ad9190ec7..53520a7fa 100644 --- a/src/slang-nodes/ContractMembers.js +++ b/src/slang-nodes/ContractMembers.js @@ -10,9 +10,8 @@ export class ContractMembers extends SlangNode { items; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print, options) { diff --git a/src/slang-nodes/DecimalNumberExpression.js b/src/slang-nodes/DecimalNumberExpression.js index a6c1141e1..2038b898e 100644 --- a/src/slang-nodes/DecimalNumberExpression.js +++ b/src/slang-nodes/DecimalNumberExpression.js @@ -6,9 +6,8 @@ export class DecimalNumberExpression extends SlangNode { unit; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/DoWhileStatement.js b/src/slang-nodes/DoWhileStatement.js index 129ee6ab8..f04479069 100644 --- a/src/slang-nodes/DoWhileStatement.js +++ b/src/slang-nodes/DoWhileStatement.js @@ -20,9 +20,8 @@ export class DoWhileStatement extends SlangNode { semicolon; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/ElementaryType.js b/src/slang-nodes/ElementaryType.js index 0d65d0ed9..1e0e0ab95 100644 --- a/src/slang-nodes/ElementaryType.js +++ b/src/slang-nodes/ElementaryType.js @@ -4,9 +4,8 @@ export class ElementaryType extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/ElseBranch.js b/src/slang-nodes/ElseBranch.js index e14abecc1..239762ff7 100644 --- a/src/slang-nodes/ElseBranch.js +++ b/src/slang-nodes/ElseBranch.js @@ -5,15 +5,15 @@ import { createKindCheckFunction } from '../slang-utils/create-kind-check-functi const { group, indent, line } = doc.builders; const isIfStatementOrBlock = createKindCheckFunction(['Block', 'IfStatement']); + export class ElseBranch extends SlangNode { elseKeyword; body; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/EmitStatement.js b/src/slang-nodes/EmitStatement.js index 26ee7de8f..bd97bbbb2 100644 --- a/src/slang-nodes/EmitStatement.js +++ b/src/slang-nodes/EmitStatement.js @@ -10,9 +10,8 @@ export class EmitStatement extends SlangNode { semicolon; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/EnumDefinition.js b/src/slang-nodes/EnumDefinition.js index 3a50d3c81..355c9aa95 100644 --- a/src/slang-nodes/EnumDefinition.js +++ b/src/slang-nodes/EnumDefinition.js @@ -12,9 +12,8 @@ export class EnumDefinition extends SlangNode { closeBrace; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/EnumMembers.js b/src/slang-nodes/EnumMembers.js index 5a6182526..eaa3c71e6 100644 --- a/src/slang-nodes/EnumMembers.js +++ b/src/slang-nodes/EnumMembers.js @@ -10,9 +10,8 @@ export class EnumMembers extends SlangNode { separators; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print() { diff --git a/src/slang-nodes/EqualityExpression.js b/src/slang-nodes/EqualityExpression.js index 58cf38fc3..e695b93ed 100644 --- a/src/slang-nodes/EqualityExpression.js +++ b/src/slang-nodes/EqualityExpression.js @@ -9,9 +9,8 @@ export class EqualityExpression extends SlangNode { rightOperand; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print, options) { diff --git a/src/slang-nodes/ErrorDefinition.js b/src/slang-nodes/ErrorDefinition.js index d0cbd33be..768b164b8 100644 --- a/src/slang-nodes/ErrorDefinition.js +++ b/src/slang-nodes/ErrorDefinition.js @@ -10,9 +10,8 @@ export class ErrorDefinition extends SlangNode { semicolon; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/ErrorParameter.js b/src/slang-nodes/ErrorParameter.js index 7254260e9..850fe7815 100644 --- a/src/slang-nodes/ErrorParameter.js +++ b/src/slang-nodes/ErrorParameter.js @@ -6,9 +6,8 @@ export class ErrorParameter extends SlangNode { name; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/ErrorParameters.js b/src/slang-nodes/ErrorParameters.js index e6f49123b..de1939126 100644 --- a/src/slang-nodes/ErrorParameters.js +++ b/src/slang-nodes/ErrorParameters.js @@ -7,9 +7,8 @@ export class ErrorParameters extends SlangNode { separators; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/ErrorParametersDeclaration.js b/src/slang-nodes/ErrorParametersDeclaration.js index 2efe4a887..178287cb2 100644 --- a/src/slang-nodes/ErrorParametersDeclaration.js +++ b/src/slang-nodes/ErrorParametersDeclaration.js @@ -8,9 +8,8 @@ export class ErrorParametersDeclaration extends SlangNode { closeParen; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/EventDefinition.js b/src/slang-nodes/EventDefinition.js index 1e869547b..0ab1c7fc2 100644 --- a/src/slang-nodes/EventDefinition.js +++ b/src/slang-nodes/EventDefinition.js @@ -12,9 +12,8 @@ export class EventDefinition extends SlangNode { semicolon; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/EventParameter.js b/src/slang-nodes/EventParameter.js index 21d8b06ed..5324c704b 100644 --- a/src/slang-nodes/EventParameter.js +++ b/src/slang-nodes/EventParameter.js @@ -8,9 +8,8 @@ export class EventParameter extends SlangNode { name; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/EventParameters.js b/src/slang-nodes/EventParameters.js index 37f230f0b..60ab7a430 100644 --- a/src/slang-nodes/EventParameters.js +++ b/src/slang-nodes/EventParameters.js @@ -7,9 +7,8 @@ export class EventParameters extends SlangNode { separators; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/EventParametersDeclaration.js b/src/slang-nodes/EventParametersDeclaration.js index 3d5673280..abab19091 100644 --- a/src/slang-nodes/EventParametersDeclaration.js +++ b/src/slang-nodes/EventParametersDeclaration.js @@ -8,9 +8,8 @@ export class EventParametersDeclaration extends SlangNode { closeParen; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/ExperimentalFeature.js b/src/slang-nodes/ExperimentalFeature.js index 574d2c15a..9c9b93880 100644 --- a/src/slang-nodes/ExperimentalFeature.js +++ b/src/slang-nodes/ExperimentalFeature.js @@ -4,9 +4,8 @@ export class ExperimentalFeature extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/ExperimentalPragma.js b/src/slang-nodes/ExperimentalPragma.js index d60dcb30e..269e6b9eb 100644 --- a/src/slang-nodes/ExperimentalPragma.js +++ b/src/slang-nodes/ExperimentalPragma.js @@ -6,9 +6,8 @@ export class ExperimentalPragma extends SlangNode { feature; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/ExponentiationExpression.js b/src/slang-nodes/ExponentiationExpression.js index 6950a074a..6b4aaaca8 100644 --- a/src/slang-nodes/ExponentiationExpression.js +++ b/src/slang-nodes/ExponentiationExpression.js @@ -27,9 +27,9 @@ export class ExponentiationExpression extends SlangNode { rightOperand; constructor(ast, offset, comments, parse, options) { - super(ast, offset, comments); + super(); if (offset) { - this.initialize(ast, parse); + this.initialize(ast, offset, comments, parse); const compiler = coerce(options.compiler); if (compiler) { @@ -86,8 +86,6 @@ export class ExponentiationExpression extends SlangNode { this.leftOperand = tryToHug(this.leftOperand); } } - - this.finalize(ast); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/Expression.js b/src/slang-nodes/Expression.js index ffccdfd36..72e79365f 100644 --- a/src/slang-nodes/Expression.js +++ b/src/slang-nodes/Expression.js @@ -4,10 +4,9 @@ export class Expression extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); + super(); if (offset) { - this.initialize(ast, parse); - this.finalize(ast); + this.initialize(ast, offset, comments, parse); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/ExpressionStatement.js b/src/slang-nodes/ExpressionStatement.js index 578f6c2ec..0d409cde4 100644 --- a/src/slang-nodes/ExpressionStatement.js +++ b/src/slang-nodes/ExpressionStatement.js @@ -6,9 +6,8 @@ export class ExpressionStatement extends SlangNode { semicolon; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/FallbackFunctionAttribute.js b/src/slang-nodes/FallbackFunctionAttribute.js index 8f1d4833d..f0c8cb89f 100644 --- a/src/slang-nodes/FallbackFunctionAttribute.js +++ b/src/slang-nodes/FallbackFunctionAttribute.js @@ -4,9 +4,8 @@ export class FallbackFunctionAttribute extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/FallbackFunctionAttributes.js b/src/slang-nodes/FallbackFunctionAttributes.js index 4444f9060..9b6d623b3 100644 --- a/src/slang-nodes/FallbackFunctionAttributes.js +++ b/src/slang-nodes/FallbackFunctionAttributes.js @@ -8,10 +8,10 @@ export class FallbackFunctionAttributes extends SlangNode { items; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); + super(); + this.initialize(ast, offset, comments, parse); + this.items = this.items.sort(sortFunctionAttributes); - this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/FallbackFunctionDefinition.js b/src/slang-nodes/FallbackFunctionDefinition.js index f97c6cbda..d21245791 100644 --- a/src/slang-nodes/FallbackFunctionDefinition.js +++ b/src/slang-nodes/FallbackFunctionDefinition.js @@ -13,10 +13,10 @@ export class FallbackFunctionDefinition extends SlangNode { body; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); + super(); + this.initialize(ast, offset, comments, parse); + this.cleanModifierInvocationArguments(); - this.finalize(ast); } cleanModifierInvocationArguments() { diff --git a/src/slang-nodes/ForStatement.js b/src/slang-nodes/ForStatement.js index 0ac35f4af..98eb2ab51 100644 --- a/src/slang-nodes/ForStatement.js +++ b/src/slang-nodes/ForStatement.js @@ -20,9 +20,8 @@ export class ForStatement extends SlangNode { body; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/ForStatementCondition.js b/src/slang-nodes/ForStatementCondition.js index bfe9a8b62..a5201b6d9 100644 --- a/src/slang-nodes/ForStatementCondition.js +++ b/src/slang-nodes/ForStatementCondition.js @@ -4,9 +4,8 @@ export class ForStatementCondition extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/ForStatementInitialization.js b/src/slang-nodes/ForStatementInitialization.js index 5ce7e38ef..6c1754874 100644 --- a/src/slang-nodes/ForStatementInitialization.js +++ b/src/slang-nodes/ForStatementInitialization.js @@ -4,9 +4,8 @@ export class ForStatementInitialization extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/FunctionAttribute.js b/src/slang-nodes/FunctionAttribute.js index f1759bfa1..b972d5e48 100644 --- a/src/slang-nodes/FunctionAttribute.js +++ b/src/slang-nodes/FunctionAttribute.js @@ -4,9 +4,8 @@ export class FunctionAttribute extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/FunctionAttributes.js b/src/slang-nodes/FunctionAttributes.js index 5f7f63820..2d17cdf3b 100644 --- a/src/slang-nodes/FunctionAttributes.js +++ b/src/slang-nodes/FunctionAttributes.js @@ -8,10 +8,10 @@ export class FunctionAttributes extends SlangNode { items; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); + super(); + this.initialize(ast, offset, comments, parse); + this.items = this.items.sort(sortFunctionAttributes); - this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/FunctionBody.js b/src/slang-nodes/FunctionBody.js index f41ae0666..6efb4c18d 100644 --- a/src/slang-nodes/FunctionBody.js +++ b/src/slang-nodes/FunctionBody.js @@ -4,9 +4,8 @@ export class FunctionBody extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/FunctionCallExpression.js b/src/slang-nodes/FunctionCallExpression.js index 7c2be86e9..ae5305a48 100644 --- a/src/slang-nodes/FunctionCallExpression.js +++ b/src/slang-nodes/FunctionCallExpression.js @@ -10,9 +10,8 @@ export class FunctionCallExpression extends SlangNode { arguments; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/FunctionDefinition.js b/src/slang-nodes/FunctionDefinition.js index dfd60e243..0a6aea103 100644 --- a/src/slang-nodes/FunctionDefinition.js +++ b/src/slang-nodes/FunctionDefinition.js @@ -17,8 +17,8 @@ export class FunctionDefinition extends SlangNode { body; constructor(ast, offset, comments, parse, options) { - super(ast, offset, comments); - this.initialize(ast, parse); + super(); + this.initialize(ast, offset, comments, parse); // Older versions of Solidity defined a constructor as a function having // the same name as the contract. @@ -26,8 +26,6 @@ export class FunctionDefinition extends SlangNode { if (compiler && satisfies(compiler, '>=0.5.0')) { this.cleanModifierInvocationArguments(); } - - this.finalize(ast); } cleanModifierInvocationArguments() { diff --git a/src/slang-nodes/FunctionName.js b/src/slang-nodes/FunctionName.js index c12099bf3..9bc0fea02 100644 --- a/src/slang-nodes/FunctionName.js +++ b/src/slang-nodes/FunctionName.js @@ -4,9 +4,8 @@ export class FunctionName extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print() { diff --git a/src/slang-nodes/FunctionType.js b/src/slang-nodes/FunctionType.js index 69aef20c4..f49539ea2 100644 --- a/src/slang-nodes/FunctionType.js +++ b/src/slang-nodes/FunctionType.js @@ -11,9 +11,8 @@ export class FunctionType extends SlangNode { returns; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/FunctionTypeAttribute.js b/src/slang-nodes/FunctionTypeAttribute.js index 4d69e5e19..6865ea7f7 100644 --- a/src/slang-nodes/FunctionTypeAttribute.js +++ b/src/slang-nodes/FunctionTypeAttribute.js @@ -4,9 +4,8 @@ export class FunctionTypeAttribute extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print() { diff --git a/src/slang-nodes/FunctionTypeAttributes.js b/src/slang-nodes/FunctionTypeAttributes.js index 08b3dfb6a..926525d48 100644 --- a/src/slang-nodes/FunctionTypeAttributes.js +++ b/src/slang-nodes/FunctionTypeAttributes.js @@ -8,10 +8,10 @@ export class FunctionTypeAttributes extends SlangNode { items; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); + super(); + this.initialize(ast, offset, comments, parse); + this.items = this.items.sort(sortFunctionAttributes); - this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/HexNumberExpression.js b/src/slang-nodes/HexNumberExpression.js index dfc81497f..9063eb044 100644 --- a/src/slang-nodes/HexNumberExpression.js +++ b/src/slang-nodes/HexNumberExpression.js @@ -6,9 +6,8 @@ export class HexNumberExpression extends SlangNode { unit; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/HexStringLiteral.js b/src/slang-nodes/HexStringLiteral.js index f6456cf42..4b58a3c43 100644 --- a/src/slang-nodes/HexStringLiteral.js +++ b/src/slang-nodes/HexStringLiteral.js @@ -5,10 +5,10 @@ export class HexStringLiteral extends SlangNode { variant; constructor(ast, offset, comments, parse, options) { - super(ast, offset, comments); - this.initialize(ast, parse); + super(); + this.initialize(ast, offset, comments, parse); + this.variant = `hex${printString(this.variant.slice(4, -1), options)}`; - this.finalize(ast); } print() { diff --git a/src/slang-nodes/HexStringLiterals.js b/src/slang-nodes/HexStringLiterals.js index a6bb2462b..1c0301138 100644 --- a/src/slang-nodes/HexStringLiterals.js +++ b/src/slang-nodes/HexStringLiterals.js @@ -7,9 +7,8 @@ export class HexStringLiterals extends SlangNode { items; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/IdentifierPath.js b/src/slang-nodes/IdentifierPath.js index 35ca3af46..a77bbfac7 100644 --- a/src/slang-nodes/IdentifierPath.js +++ b/src/slang-nodes/IdentifierPath.js @@ -6,9 +6,8 @@ export class IdentifierPath extends SlangNode { separators; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print() { diff --git a/src/slang-nodes/IfStatement.js b/src/slang-nodes/IfStatement.js index 507d39fd3..1e93f53ca 100644 --- a/src/slang-nodes/IfStatement.js +++ b/src/slang-nodes/IfStatement.js @@ -18,9 +18,8 @@ export class IfStatement extends SlangNode { elseBranch; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/ImportAlias.js b/src/slang-nodes/ImportAlias.js index 495dcd487..883a33c48 100644 --- a/src/slang-nodes/ImportAlias.js +++ b/src/slang-nodes/ImportAlias.js @@ -6,9 +6,8 @@ export class ImportAlias extends SlangNode { identifier; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print() { diff --git a/src/slang-nodes/ImportClause.js b/src/slang-nodes/ImportClause.js index e18b2ba25..50d72b8a6 100644 --- a/src/slang-nodes/ImportClause.js +++ b/src/slang-nodes/ImportClause.js @@ -4,9 +4,8 @@ export class ImportClause extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/ImportDeconstruction.js b/src/slang-nodes/ImportDeconstruction.js index e87e7edb2..72b3fced7 100644 --- a/src/slang-nodes/ImportDeconstruction.js +++ b/src/slang-nodes/ImportDeconstruction.js @@ -12,9 +12,8 @@ export class ImportDeconstruction extends SlangNode { path; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/ImportDeconstructionSymbol.js b/src/slang-nodes/ImportDeconstructionSymbol.js index 3d587130a..99b8308df 100644 --- a/src/slang-nodes/ImportDeconstructionSymbol.js +++ b/src/slang-nodes/ImportDeconstructionSymbol.js @@ -6,9 +6,8 @@ export class ImportDeconstructionSymbol extends SlangNode { alias; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/ImportDeconstructionSymbols.js b/src/slang-nodes/ImportDeconstructionSymbols.js index d0dd60005..5081581c5 100644 --- a/src/slang-nodes/ImportDeconstructionSymbols.js +++ b/src/slang-nodes/ImportDeconstructionSymbols.js @@ -12,9 +12,8 @@ export class ImportDeconstructionSymbols extends SlangNode { separators; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print, options) { diff --git a/src/slang-nodes/ImportDirective.js b/src/slang-nodes/ImportDirective.js index a321315e0..5f4de1cd9 100644 --- a/src/slang-nodes/ImportDirective.js +++ b/src/slang-nodes/ImportDirective.js @@ -8,9 +8,8 @@ export class ImportDirective extends SlangNode { semicolon; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/IndexAccessEnd.js b/src/slang-nodes/IndexAccessEnd.js index eeec3e5cd..8af57c2e2 100644 --- a/src/slang-nodes/IndexAccessEnd.js +++ b/src/slang-nodes/IndexAccessEnd.js @@ -6,9 +6,8 @@ export class IndexAccessEnd extends SlangNode { end; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/IndexAccessExpression.js b/src/slang-nodes/IndexAccessExpression.js index 9e0245b06..8ef80852c 100644 --- a/src/slang-nodes/IndexAccessExpression.js +++ b/src/slang-nodes/IndexAccessExpression.js @@ -16,10 +16,8 @@ export class IndexAccessExpression extends SlangNode { closeBracket; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.closeBracket = ast.closeBracket.text; - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/InheritanceSpecifier.js b/src/slang-nodes/InheritanceSpecifier.js index 426c3ff80..f1ed8873b 100644 --- a/src/slang-nodes/InheritanceSpecifier.js +++ b/src/slang-nodes/InheritanceSpecifier.js @@ -6,9 +6,8 @@ export class InheritanceSpecifier extends SlangNode { types; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/InheritanceType.js b/src/slang-nodes/InheritanceType.js index 93783322c..437265306 100644 --- a/src/slang-nodes/InheritanceType.js +++ b/src/slang-nodes/InheritanceType.js @@ -6,9 +6,8 @@ export class InheritanceType extends SlangNode { arguments; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/InheritanceTypes.js b/src/slang-nodes/InheritanceTypes.js index 9c18b2d76..7a0d15c7b 100644 --- a/src/slang-nodes/InheritanceTypes.js +++ b/src/slang-nodes/InheritanceTypes.js @@ -10,9 +10,8 @@ export class InheritanceTypes extends SlangNode { separators; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/InterfaceDefinition.js b/src/slang-nodes/InterfaceDefinition.js index e0b158e33..f6f7610ea 100644 --- a/src/slang-nodes/InterfaceDefinition.js +++ b/src/slang-nodes/InterfaceDefinition.js @@ -17,9 +17,8 @@ export class InterfaceDefinition extends SlangNode { closeBrace; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/InterfaceMembers.js b/src/slang-nodes/InterfaceMembers.js index 94a69b09b..50bdf1600 100644 --- a/src/slang-nodes/InterfaceMembers.js +++ b/src/slang-nodes/InterfaceMembers.js @@ -9,9 +9,8 @@ export class InterfaceMembers extends SlangNode { items; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print, options) { diff --git a/src/slang-nodes/LibraryDefinition.js b/src/slang-nodes/LibraryDefinition.js index 4c38f9b58..4d791d55a 100644 --- a/src/slang-nodes/LibraryDefinition.js +++ b/src/slang-nodes/LibraryDefinition.js @@ -15,9 +15,8 @@ export class LibraryDefinition extends SlangNode { closeBrace; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/LibraryMembers.js b/src/slang-nodes/LibraryMembers.js index d03ac295c..58ab1cad0 100644 --- a/src/slang-nodes/LibraryMembers.js +++ b/src/slang-nodes/LibraryMembers.js @@ -9,9 +9,8 @@ export class LibraryMembers extends SlangNode { items; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print, options) { diff --git a/src/slang-nodes/MappingKey.js b/src/slang-nodes/MappingKey.js index 2e0e0403e..442851eb2 100644 --- a/src/slang-nodes/MappingKey.js +++ b/src/slang-nodes/MappingKey.js @@ -6,9 +6,8 @@ export class MappingKey extends SlangNode { name; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/MappingKeyType.js b/src/slang-nodes/MappingKeyType.js index 2c9d3127c..641dad5eb 100644 --- a/src/slang-nodes/MappingKeyType.js +++ b/src/slang-nodes/MappingKeyType.js @@ -4,9 +4,8 @@ export class MappingKeyType extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/MappingType.js b/src/slang-nodes/MappingType.js index fda7c3de4..39c85a206 100644 --- a/src/slang-nodes/MappingType.js +++ b/src/slang-nodes/MappingType.js @@ -14,9 +14,8 @@ export class MappingType extends SlangNode { closeParen; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/MappingValue.js b/src/slang-nodes/MappingValue.js index dd1e19114..d49420137 100644 --- a/src/slang-nodes/MappingValue.js +++ b/src/slang-nodes/MappingValue.js @@ -6,9 +6,8 @@ export class MappingValue extends SlangNode { name; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/MemberAccess.js b/src/slang-nodes/MemberAccess.js index 3616fc5d4..554e017c1 100644 --- a/src/slang-nodes/MemberAccess.js +++ b/src/slang-nodes/MemberAccess.js @@ -4,9 +4,8 @@ export class MemberAccess extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print() { diff --git a/src/slang-nodes/MemberAccessExpression.js b/src/slang-nodes/MemberAccessExpression.js index 6c63ca0b1..54acbb998 100644 --- a/src/slang-nodes/MemberAccessExpression.js +++ b/src/slang-nodes/MemberAccessExpression.js @@ -113,9 +113,8 @@ export class MemberAccessExpression extends SlangNode { member; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/ModifierAttribute.js b/src/slang-nodes/ModifierAttribute.js index 92f4f8b96..4f5328f12 100644 --- a/src/slang-nodes/ModifierAttribute.js +++ b/src/slang-nodes/ModifierAttribute.js @@ -4,9 +4,8 @@ export class ModifierAttribute extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/ModifierAttributes.js b/src/slang-nodes/ModifierAttributes.js index c1761ad2c..89456183e 100644 --- a/src/slang-nodes/ModifierAttributes.js +++ b/src/slang-nodes/ModifierAttributes.js @@ -8,10 +8,10 @@ export class ModifierAttributes extends SlangNode { items; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); + super(); + this.initialize(ast, offset, comments, parse); + this.items = this.items.sort(sortFunctionAttributes); - this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/ModifierDefinition.js b/src/slang-nodes/ModifierDefinition.js index 3e947769b..c2622ab76 100644 --- a/src/slang-nodes/ModifierDefinition.js +++ b/src/slang-nodes/ModifierDefinition.js @@ -16,8 +16,9 @@ export class ModifierDefinition extends SlangNode { body; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); + super(); + this.initialize(ast, offset, comments, parse); + if (typeof this.parameters === 'undefined') { const parametersLoc = { startWithTrivia: this.attributes.loc.startWithTrivia, @@ -36,7 +37,6 @@ export class ModifierDefinition extends SlangNode { closeParen: ')' }); } - this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/ModifierInvocation.js b/src/slang-nodes/ModifierInvocation.js index c08ecbeeb..1c0d56ede 100644 --- a/src/slang-nodes/ModifierInvocation.js +++ b/src/slang-nodes/ModifierInvocation.js @@ -9,10 +9,10 @@ export class ModifierInvocation extends SlangNode { arguments; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); + super(); + this.initialize(ast, offset, comments, parse); + this.#ast = ast; - this.initialize(ast, parse); - this.finalize(ast); } cleanModifierInvocationArguments() { diff --git a/src/slang-nodes/MultiplicativeExpression.js b/src/slang-nodes/MultiplicativeExpression.js index dcc04417e..56e53261e 100644 --- a/src/slang-nodes/MultiplicativeExpression.js +++ b/src/slang-nodes/MultiplicativeExpression.js @@ -14,8 +14,8 @@ export class MultiplicativeExpression extends SlangNode { rightOperand; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); + super(); + this.initialize(ast, offset, comments, parse); switch (this.operator) { case '*': @@ -30,8 +30,6 @@ export class MultiplicativeExpression extends SlangNode { default: break; } - - this.finalize(ast); } print(path, print, options) { diff --git a/src/slang-nodes/NamedArgument.js b/src/slang-nodes/NamedArgument.js index 6006df72a..af7633f2c 100644 --- a/src/slang-nodes/NamedArgument.js +++ b/src/slang-nodes/NamedArgument.js @@ -8,9 +8,8 @@ export class NamedArgument extends SlangNode { value; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/NamedArgumentGroup.js b/src/slang-nodes/NamedArgumentGroup.js index 0d8241006..efca86324 100644 --- a/src/slang-nodes/NamedArgumentGroup.js +++ b/src/slang-nodes/NamedArgumentGroup.js @@ -8,9 +8,8 @@ export class NamedArgumentGroup extends SlangNode { closeBrace; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/NamedArguments.js b/src/slang-nodes/NamedArguments.js index 38e1a2c42..a40410865 100644 --- a/src/slang-nodes/NamedArguments.js +++ b/src/slang-nodes/NamedArguments.js @@ -10,9 +10,8 @@ export class NamedArguments extends SlangNode { separators; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print, options) { diff --git a/src/slang-nodes/NamedArgumentsDeclaration.js b/src/slang-nodes/NamedArgumentsDeclaration.js index b09d6ae84..23de0eee0 100644 --- a/src/slang-nodes/NamedArgumentsDeclaration.js +++ b/src/slang-nodes/NamedArgumentsDeclaration.js @@ -8,9 +8,8 @@ export class NamedArgumentsDeclaration extends SlangNode { closeParen; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/NamedImport.js b/src/slang-nodes/NamedImport.js index a24b7176e..beefd4f3b 100644 --- a/src/slang-nodes/NamedImport.js +++ b/src/slang-nodes/NamedImport.js @@ -10,9 +10,8 @@ export class NamedImport extends SlangNode { path; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/NewExpression.js b/src/slang-nodes/NewExpression.js index 860cec90d..5e785c3fa 100644 --- a/src/slang-nodes/NewExpression.js +++ b/src/slang-nodes/NewExpression.js @@ -6,9 +6,8 @@ export class NewExpression extends SlangNode { typeName; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/NumberUnit.js b/src/slang-nodes/NumberUnit.js index fdce5827c..b259c96b7 100644 --- a/src/slang-nodes/NumberUnit.js +++ b/src/slang-nodes/NumberUnit.js @@ -4,9 +4,8 @@ export class NumberUnit extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print() { diff --git a/src/slang-nodes/OrExpression.js b/src/slang-nodes/OrExpression.js index 85f2e4276..65fff7951 100644 --- a/src/slang-nodes/OrExpression.js +++ b/src/slang-nodes/OrExpression.js @@ -12,11 +12,11 @@ export class OrExpression extends SlangNode { rightOperand; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); + super(); + this.initialize(ast, offset, comments, parse); + this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); - this.finalize(ast); } print(path, print, options) { diff --git a/src/slang-nodes/OverridePaths.js b/src/slang-nodes/OverridePaths.js index de25a5afe..db8e79273 100644 --- a/src/slang-nodes/OverridePaths.js +++ b/src/slang-nodes/OverridePaths.js @@ -6,9 +6,8 @@ export class OverridePaths extends SlangNode { separators; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } // TODO: implement print diff --git a/src/slang-nodes/OverridePathsDeclaration.js b/src/slang-nodes/OverridePathsDeclaration.js index a70cea509..b21102951 100644 --- a/src/slang-nodes/OverridePathsDeclaration.js +++ b/src/slang-nodes/OverridePathsDeclaration.js @@ -8,9 +8,8 @@ export class OverridePathsDeclaration extends SlangNode { closeParen; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } // TODO: implement print diff --git a/src/slang-nodes/OverrideSpecifier.js b/src/slang-nodes/OverrideSpecifier.js index cab6269e8..e29bb2add 100644 --- a/src/slang-nodes/OverrideSpecifier.js +++ b/src/slang-nodes/OverrideSpecifier.js @@ -6,9 +6,8 @@ export class OverrideSpecifier extends SlangNode { overridden; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/Parameter.js b/src/slang-nodes/Parameter.js index 4ddcea0ac..eee33795b 100644 --- a/src/slang-nodes/Parameter.js +++ b/src/slang-nodes/Parameter.js @@ -11,9 +11,8 @@ export class Parameter extends SlangNode { name; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/Parameters.js b/src/slang-nodes/Parameters.js index e48db64c3..d0de61a7f 100644 --- a/src/slang-nodes/Parameters.js +++ b/src/slang-nodes/Parameters.js @@ -11,10 +11,9 @@ export class Parameters extends SlangNode { separators; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); + super(); if (offset) { - this.initialize(ast, parse); - this.finalize(ast); + this.initialize(ast, offset, comments, parse); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/ParametersDeclaration.js b/src/slang-nodes/ParametersDeclaration.js index c8642ce24..67bf81f7a 100644 --- a/src/slang-nodes/ParametersDeclaration.js +++ b/src/slang-nodes/ParametersDeclaration.js @@ -8,10 +8,9 @@ export class ParametersDeclaration extends SlangNode { closeParen; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); + super(); if (offset) { - this.initialize(ast, parse); - this.finalize(ast); + this.initialize(ast, offset, comments, parse); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/PathImport.js b/src/slang-nodes/PathImport.js index 69f19d5e5..547abdae5 100644 --- a/src/slang-nodes/PathImport.js +++ b/src/slang-nodes/PathImport.js @@ -6,9 +6,8 @@ export class PathImport extends SlangNode { alias; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/PositionalArguments.js b/src/slang-nodes/PositionalArguments.js index f65e1c73a..00d3c672d 100644 --- a/src/slang-nodes/PositionalArguments.js +++ b/src/slang-nodes/PositionalArguments.js @@ -7,9 +7,8 @@ export class PositionalArguments extends SlangNode { separators; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/PositionalArgumentsDeclaration.js b/src/slang-nodes/PositionalArgumentsDeclaration.js index 159430d58..ccaca1317 100644 --- a/src/slang-nodes/PositionalArgumentsDeclaration.js +++ b/src/slang-nodes/PositionalArgumentsDeclaration.js @@ -8,9 +8,8 @@ export class PositionalArgumentsDeclaration extends SlangNode { closeParen; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/PostfixExpression.js b/src/slang-nodes/PostfixExpression.js index 9675de7c2..8c06dddc3 100644 --- a/src/slang-nodes/PostfixExpression.js +++ b/src/slang-nodes/PostfixExpression.js @@ -6,9 +6,8 @@ export class PostfixExpression extends SlangNode { operator; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/Pragma.js b/src/slang-nodes/Pragma.js index 178d65c0a..50ce5045a 100644 --- a/src/slang-nodes/Pragma.js +++ b/src/slang-nodes/Pragma.js @@ -4,9 +4,8 @@ export class Pragma extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/PragmaDirective.js b/src/slang-nodes/PragmaDirective.js index dac4aa233..0cb8b4d30 100644 --- a/src/slang-nodes/PragmaDirective.js +++ b/src/slang-nodes/PragmaDirective.js @@ -8,9 +8,8 @@ export class PragmaDirective extends SlangNode { semicolon; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/PrefixExpression.js b/src/slang-nodes/PrefixExpression.js index 51d11cba2..f6fc27baa 100644 --- a/src/slang-nodes/PrefixExpression.js +++ b/src/slang-nodes/PrefixExpression.js @@ -6,9 +6,8 @@ export class PrefixExpression extends SlangNode { operand; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/ReceiveFunctionAttribute.js b/src/slang-nodes/ReceiveFunctionAttribute.js index 95f01249b..72cdd80f2 100644 --- a/src/slang-nodes/ReceiveFunctionAttribute.js +++ b/src/slang-nodes/ReceiveFunctionAttribute.js @@ -4,9 +4,8 @@ export class ReceiveFunctionAttribute extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/ReceiveFunctionAttributes.js b/src/slang-nodes/ReceiveFunctionAttributes.js index a12aa3d29..d3e084433 100644 --- a/src/slang-nodes/ReceiveFunctionAttributes.js +++ b/src/slang-nodes/ReceiveFunctionAttributes.js @@ -8,10 +8,10 @@ export class ReceiveFunctionAttributes extends SlangNode { items; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); + super(); + this.initialize(ast, offset, comments, parse); + this.items = this.items.sort(sortFunctionAttributes); - this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/ReceiveFunctionDefinition.js b/src/slang-nodes/ReceiveFunctionDefinition.js index 6b2d4238b..0e1fccf0e 100644 --- a/src/slang-nodes/ReceiveFunctionDefinition.js +++ b/src/slang-nodes/ReceiveFunctionDefinition.js @@ -11,10 +11,10 @@ export class ReceiveFunctionDefinition extends SlangNode { body; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); + super(); + this.initialize(ast, offset, comments, parse); + this.cleanModifierInvocationArguments(); - this.finalize(ast); } cleanModifierInvocationArguments() { diff --git a/src/slang-nodes/ReturnStatement.js b/src/slang-nodes/ReturnStatement.js index e0b47f4b4..af66d16a7 100644 --- a/src/slang-nodes/ReturnStatement.js +++ b/src/slang-nodes/ReturnStatement.js @@ -22,9 +22,8 @@ export class ReturnStatement extends SlangNode { semicolon; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print, options) { diff --git a/src/slang-nodes/ReturnsDeclaration.js b/src/slang-nodes/ReturnsDeclaration.js index 4de594069..617d6f7da 100644 --- a/src/slang-nodes/ReturnsDeclaration.js +++ b/src/slang-nodes/ReturnsDeclaration.js @@ -9,9 +9,8 @@ export class ReturnsDeclaration extends SlangNode { variables; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/RevertStatement.js b/src/slang-nodes/RevertStatement.js index 3b0426877..30f3c43ff 100644 --- a/src/slang-nodes/RevertStatement.js +++ b/src/slang-nodes/RevertStatement.js @@ -10,9 +10,8 @@ export class RevertStatement extends SlangNode { semicolon; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/ShiftExpression.js b/src/slang-nodes/ShiftExpression.js index 92cff0f8d..55e9d18b9 100644 --- a/src/slang-nodes/ShiftExpression.js +++ b/src/slang-nodes/ShiftExpression.js @@ -21,11 +21,11 @@ export class ShiftExpression extends SlangNode { rightOperand; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); + super(); + this.initialize(ast, offset, comments, parse); + this.leftOperand = tryToHugLeftOperand(this.leftOperand); this.rightOperand = tryToHugRightOperand(this.rightOperand); - this.finalize(ast); } print(path, print, options) { diff --git a/src/slang-nodes/SlangNode.js b/src/slang-nodes/SlangNode.js index bca37e5f1..e7d09d261 100644 --- a/src/slang-nodes/SlangNode.js +++ b/src/slang-nodes/SlangNode.js @@ -1,61 +1,9 @@ -import { isComment } from '../slang-utils/is-comment.js'; import { Loc } from '../slang-utils/loc.js'; - -function getOffsets(children, initialOffset, comments) { - let offset = initialOffset; - - const offsets = children.reduce((offsetsArray, child) => { - if (child.type === 'Nonterminal') { - offsetsArray.push(offset); - } - if (child.type === 'Terminal' && isComment(child)) { - // Since the fetching the comments and calculating offsets are both done - // as we iterate over the children and the comment also depends on the - // offset, it's hard to separate these responsibilities into different - // functions. - comments.push({ - kind: child.kind, - value: child.text, - loc: new Loc({ - startWithTrivia: offset, - endWithTrivia: offset + child.textLength.utf8 - }) - }); - } - - offset += child.textLength.utf8; - return offsetsArray; - }, []); - return offsets; -} - -function getLeadingOffset(children) { - let offset = 0; - for (let i = 0; i < children.length; i += 1) { - const child = children[i]; - if (child.type === 'Nonterminal') { - // The node's content starts when we find the first non-terminal, - // non-comment, non-whitespace token. - return offset; - } - if ( - child.type === 'Terminal' && - !isComment(child) && - child.kind !== 'EndOfLine' && - child.kind !== 'Whitespace' - ) { - // The content of the node started if we find a non-comment, - // non-whitespace token. - return offset; - } - offset += child.textLength.utf8; - } - return offset; -} - -function getTrailingOffset(children) { - return getLeadingOffset(children.reverse()); -} +import { + getChildrenOffsets, + getLeadingOffset, + getTrailingOffset +} from '../slang-utils/get-offsets.js'; export class SlangNode { kind; @@ -64,82 +12,61 @@ export class SlangNode { comments = []; - constructor(ast, offset, comments) { - if (typeof offset === 'undefined') return; + initialize(ast, offset, comments, parse) { const children = ast.cst.children(); + this.kind = ast.cst.kind; - this.loc = new Loc({ - startWithTrivia: offset, - endWithTrivia: offset + ast.cst.textLength.utf8, - childrenOffsets: getOffsets(children, offset, comments) - }); - } - initialize(ast, parse) { + const childrenOffsets = getChildrenOffsets(children, offset, comments); + const getValue = (astChild) => astChild.type === 'Terminal' ? astChild.text - : parse(astChild, this.loc.childrenOffsets.shift()); + : parse(astChild, childrenOffsets.shift()); - Object.keys(this) - .slice(3) - .forEach((childKey) => { - const astChild = ast[childKey]; - if (astChild) { - this[childKey] = Array.isArray(astChild) - ? astChild.map(getValue) - : getValue(astChild); - } - }); - } + const childrenKeys = Object.keys(this).slice(3); - /** - * Leading and trailing Comments are considered by the parser as part of the - * innermost possible node. For example if there is a comment just before a - * variable assignment, the parser will consider the comment belongs to the - * variable name instead of the whole statement. - * - * This behaviour creates erratic outcomes when the new line of a - * SingleLineComment can trigger a group break or a prettier-ignore will - * apply to a subset of the intended nodes. - * - * ```Solidity - * // prettier-ignore - * matrix = [ - * 0, 1, 2, - * 3, 4, 5, - * 6, 7, 8 - * ]; - * ``` - */ - finalize(ast) { - const children = ast.cst.children(); + childrenKeys.forEach((childKey) => { + const astChild = ast[childKey]; + if (astChild) { + this[childKey] = Array.isArray(astChild) + ? astChild.map(getValue) + : getValue(astChild); + } + }); + + const startWithTrivia = offset; + const endWithTrivia = offset + ast.cst.textLength.utf8; let leadingOffset = getLeadingOffset(children); let trailingOffset = getTrailingOffset(children); if (leadingOffset === 0 || trailingOffset === 0) { - const childrenKeys = Object.keys(this).slice(3); for (let i = 0; i < childrenKeys.length; i += 1) { const childLoc = this[childrenKeys[i]]?.loc; if (childLoc) { if ( leadingOffset === 0 && - childLoc.startWithTrivia === this.loc.startWithTrivia + childLoc.startWithTrivia === startWithTrivia ) { - leadingOffset = childLoc.start - childLoc.startWithTrivia; + leadingOffset = childLoc.start - startWithTrivia; } if ( trailingOffset === 0 && - childLoc.endWithTrivia === this.loc.endWithTrivia + childLoc.endWithTrivia === endWithTrivia ) { - trailingOffset = childLoc.endWithTrivia - childLoc.end; + trailingOffset = endWithTrivia - childLoc.end; } } } } - this.loc.start = this.loc.startWithTrivia + leadingOffset; - this.loc.end = this.loc.endWithTrivia - trailingOffset; + + this.loc = new Loc({ + startWithTrivia, + start: startWithTrivia + leadingOffset, + endWithTrivia, + end: endWithTrivia - trailingOffset + }); } } diff --git a/src/slang-nodes/SourceUnit.js b/src/slang-nodes/SourceUnit.js index e059c0eec..1f84aea32 100644 --- a/src/slang-nodes/SourceUnit.js +++ b/src/slang-nodes/SourceUnit.js @@ -7,9 +7,8 @@ export class SourceUnit extends SlangNode { members; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print, options) { diff --git a/src/slang-nodes/SourceUnitMember.js b/src/slang-nodes/SourceUnitMember.js index bd582b0e3..e937cb6cc 100644 --- a/src/slang-nodes/SourceUnitMember.js +++ b/src/slang-nodes/SourceUnitMember.js @@ -4,9 +4,8 @@ export class SourceUnitMember extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/SourceUnitMembers.js b/src/slang-nodes/SourceUnitMembers.js index 6c4b75103..90196de37 100644 --- a/src/slang-nodes/SourceUnitMembers.js +++ b/src/slang-nodes/SourceUnitMembers.js @@ -5,9 +5,8 @@ export class SourceUnitMembers extends SlangNode { items; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print, options) { diff --git a/src/slang-nodes/StateVariableAttribute.js b/src/slang-nodes/StateVariableAttribute.js index 94b375c1c..aa59afcac 100644 --- a/src/slang-nodes/StateVariableAttribute.js +++ b/src/slang-nodes/StateVariableAttribute.js @@ -4,9 +4,8 @@ export class StateVariableAttribute extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/StateVariableAttributes.js b/src/slang-nodes/StateVariableAttributes.js index e06371fcf..3713f8fc8 100644 --- a/src/slang-nodes/StateVariableAttributes.js +++ b/src/slang-nodes/StateVariableAttributes.js @@ -4,9 +4,8 @@ export class StateVariableAttributes extends SlangNode { items; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/StateVariableDefinition.js b/src/slang-nodes/StateVariableDefinition.js index 1499bc94c..612a079c1 100644 --- a/src/slang-nodes/StateVariableDefinition.js +++ b/src/slang-nodes/StateVariableDefinition.js @@ -12,9 +12,8 @@ export class StateVariableDefinition extends SlangNode { semicolon; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/StateVariableDefinitionValue.js b/src/slang-nodes/StateVariableDefinitionValue.js index 9c75dab87..8b3c574b6 100644 --- a/src/slang-nodes/StateVariableDefinitionValue.js +++ b/src/slang-nodes/StateVariableDefinitionValue.js @@ -9,9 +9,8 @@ export class StateVariableDefinitionValue extends SlangNode { value; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/Statement.js b/src/slang-nodes/Statement.js index d8d4d06dd..9a04d5ab6 100644 --- a/src/slang-nodes/Statement.js +++ b/src/slang-nodes/Statement.js @@ -4,9 +4,8 @@ export class Statement extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/Statements.js b/src/slang-nodes/Statements.js index 79938d886..4ab041c2e 100644 --- a/src/slang-nodes/Statements.js +++ b/src/slang-nodes/Statements.js @@ -2,7 +2,6 @@ import { doc } from 'prettier'; import { printSeparatedItem } from '../common/printer-helpers.js'; import { printComments } from '../slang-printers/print-comments.js'; import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; - import { SlangNode } from './SlangNode.js'; const { hardline } = doc.builders; @@ -11,9 +10,8 @@ export class Statements extends SlangNode { items; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print, options) { diff --git a/src/slang-nodes/StorageLocation.js b/src/slang-nodes/StorageLocation.js index 33d3c065f..2bc69fab3 100644 --- a/src/slang-nodes/StorageLocation.js +++ b/src/slang-nodes/StorageLocation.js @@ -4,9 +4,8 @@ export class StorageLocation extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print() { diff --git a/src/slang-nodes/StringExpression.js b/src/slang-nodes/StringExpression.js index afa078b78..54a76af65 100644 --- a/src/slang-nodes/StringExpression.js +++ b/src/slang-nodes/StringExpression.js @@ -4,9 +4,8 @@ export class StringExpression extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/StringLiteral.js b/src/slang-nodes/StringLiteral.js index e22904666..d82ff39ba 100644 --- a/src/slang-nodes/StringLiteral.js +++ b/src/slang-nodes/StringLiteral.js @@ -5,10 +5,10 @@ export class StringLiteral extends SlangNode { variant; constructor(ast, offset, comments, parse, options) { - super(ast, offset, comments); - this.initialize(ast, parse); + super(); + this.initialize(ast, offset, comments, parse); + this.variant = printString(this.variant.slice(1, -1), options); - this.finalize(ast); } print() { diff --git a/src/slang-nodes/StringLiterals.js b/src/slang-nodes/StringLiterals.js index c1b08b789..d7e6e472a 100644 --- a/src/slang-nodes/StringLiterals.js +++ b/src/slang-nodes/StringLiterals.js @@ -7,9 +7,8 @@ export class StringLiterals extends SlangNode { items; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/StructDefinition.js b/src/slang-nodes/StructDefinition.js index a7d1294a1..43143335f 100644 --- a/src/slang-nodes/StructDefinition.js +++ b/src/slang-nodes/StructDefinition.js @@ -12,9 +12,8 @@ export class StructDefinition extends SlangNode { closeBrace; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/StructMember.js b/src/slang-nodes/StructMember.js index 9ec9984d9..029fe9ef4 100644 --- a/src/slang-nodes/StructMember.js +++ b/src/slang-nodes/StructMember.js @@ -8,9 +8,8 @@ export class StructMember extends SlangNode { semicolon; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/StructMembers.js b/src/slang-nodes/StructMembers.js index 784ef3029..660ad5123 100644 --- a/src/slang-nodes/StructMembers.js +++ b/src/slang-nodes/StructMembers.js @@ -8,9 +8,8 @@ export class StructMembers extends SlangNode { items; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/ThrowStatement.js b/src/slang-nodes/ThrowStatement.js index 7238bcb39..2667cb5b3 100644 --- a/src/slang-nodes/ThrowStatement.js +++ b/src/slang-nodes/ThrowStatement.js @@ -6,9 +6,8 @@ export class ThrowStatement extends SlangNode { semicolon; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } // TODO: implement print diff --git a/src/slang-nodes/TryStatement.js b/src/slang-nodes/TryStatement.js index 772f2bf27..065fcc904 100644 --- a/src/slang-nodes/TryStatement.js +++ b/src/slang-nodes/TryStatement.js @@ -16,9 +16,8 @@ export class TryStatement extends SlangNode { catchClauses; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/TupleDeconstructionElement.js b/src/slang-nodes/TupleDeconstructionElement.js index 1060086d5..3d5934886 100644 --- a/src/slang-nodes/TupleDeconstructionElement.js +++ b/src/slang-nodes/TupleDeconstructionElement.js @@ -4,9 +4,8 @@ export class TupleDeconstructionElement extends SlangNode { member; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/TupleDeconstructionElements.js b/src/slang-nodes/TupleDeconstructionElements.js index 22eeeffd1..bafe24dab 100644 --- a/src/slang-nodes/TupleDeconstructionElements.js +++ b/src/slang-nodes/TupleDeconstructionElements.js @@ -7,9 +7,8 @@ export class TupleDeconstructionElements extends SlangNode { separators; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/TupleDeconstructionStatement.js b/src/slang-nodes/TupleDeconstructionStatement.js index ce9abecf4..d490ae457 100644 --- a/src/slang-nodes/TupleDeconstructionStatement.js +++ b/src/slang-nodes/TupleDeconstructionStatement.js @@ -19,9 +19,8 @@ export class TupleDeconstructionStatement extends SlangNode { semicolon; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/TupleExpression.js b/src/slang-nodes/TupleExpression.js index 7f2a59ce3..409c98e3f 100644 --- a/src/slang-nodes/TupleExpression.js +++ b/src/slang-nodes/TupleExpression.js @@ -8,10 +8,9 @@ export class TupleExpression extends SlangNode { closeParen; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); + super(); if (offset) { - this.initialize(ast, parse); - this.finalize(ast); + this.initialize(ast, offset, comments, parse); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/TupleMember.js b/src/slang-nodes/TupleMember.js index ad3766748..d17866789 100644 --- a/src/slang-nodes/TupleMember.js +++ b/src/slang-nodes/TupleMember.js @@ -4,9 +4,8 @@ export class TupleMember extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/TupleValue.js b/src/slang-nodes/TupleValue.js index 9d6bed418..7bdb24927 100644 --- a/src/slang-nodes/TupleValue.js +++ b/src/slang-nodes/TupleValue.js @@ -4,10 +4,9 @@ export class TupleValue extends SlangNode { expression; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); + super(); if (offset) { - this.initialize(ast, parse); - this.finalize(ast); + this.initialize(ast, offset, comments, parse); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/TupleValues.js b/src/slang-nodes/TupleValues.js index bfeaab9ac..12fa102dd 100644 --- a/src/slang-nodes/TupleValues.js +++ b/src/slang-nodes/TupleValues.js @@ -8,10 +8,9 @@ export class TupleValues extends SlangNode { separators; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); + super(); if (offset) { - this.initialize(ast, parse); - this.finalize(ast); + this.initialize(ast, offset, comments, parse); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/TypeExpression.js b/src/slang-nodes/TypeExpression.js index 6962deb28..3b3c04950 100644 --- a/src/slang-nodes/TypeExpression.js +++ b/src/slang-nodes/TypeExpression.js @@ -10,9 +10,8 @@ export class TypeExpression extends SlangNode { closeParen; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } // TODO: implement print diff --git a/src/slang-nodes/TypeName.js b/src/slang-nodes/TypeName.js index 25e756b7d..6bcdad1c8 100644 --- a/src/slang-nodes/TypeName.js +++ b/src/slang-nodes/TypeName.js @@ -4,9 +4,8 @@ export class TypeName extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/TypedTupleMember.js b/src/slang-nodes/TypedTupleMember.js index 37c44a1b7..908c572b0 100644 --- a/src/slang-nodes/TypedTupleMember.js +++ b/src/slang-nodes/TypedTupleMember.js @@ -8,9 +8,8 @@ export class TypedTupleMember extends SlangNode { name; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/UncheckedBlock.js b/src/slang-nodes/UncheckedBlock.js index ce81a00bc..a1ad01812 100644 --- a/src/slang-nodes/UncheckedBlock.js +++ b/src/slang-nodes/UncheckedBlock.js @@ -6,9 +6,8 @@ export class UncheckedBlock extends SlangNode { block; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/UnicodeStringLiteral.js b/src/slang-nodes/UnicodeStringLiteral.js index d93ab3fea..3a4030afe 100644 --- a/src/slang-nodes/UnicodeStringLiteral.js +++ b/src/slang-nodes/UnicodeStringLiteral.js @@ -5,10 +5,10 @@ export class UnicodeStringLiteral extends SlangNode { variant; constructor(ast, offset, comments, parse, options) { - super(ast, offset, comments); - this.initialize(ast, parse); + super(); + this.initialize(ast, offset, comments, parse); + this.variant = `unicode${printString(this.variant.slice(8, -1), options)}`; - this.finalize(ast); } print() { diff --git a/src/slang-nodes/UnicodeStringLiterals.js b/src/slang-nodes/UnicodeStringLiterals.js index 06768ba8c..01c0fdf43 100644 --- a/src/slang-nodes/UnicodeStringLiterals.js +++ b/src/slang-nodes/UnicodeStringLiterals.js @@ -7,9 +7,8 @@ export class UnicodeStringLiterals extends SlangNode { items; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/UnnamedFunctionAttribute.js b/src/slang-nodes/UnnamedFunctionAttribute.js index cdfc8ed85..872d67165 100644 --- a/src/slang-nodes/UnnamedFunctionAttribute.js +++ b/src/slang-nodes/UnnamedFunctionAttribute.js @@ -4,9 +4,8 @@ export class UnnamedFunctionAttribute extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/UnnamedFunctionAttributes.js b/src/slang-nodes/UnnamedFunctionAttributes.js index fb223e789..855953dc0 100644 --- a/src/slang-nodes/UnnamedFunctionAttributes.js +++ b/src/slang-nodes/UnnamedFunctionAttributes.js @@ -8,10 +8,10 @@ export class UnnamedFunctionAttributes extends SlangNode { items; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); + super(); + this.initialize(ast, offset, comments, parse); + this.items = this.items.sort(sortFunctionAttributes); - this.finalize(ast); } print(path, print) { diff --git a/src/slang-nodes/UnnamedFunctionDefinition.js b/src/slang-nodes/UnnamedFunctionDefinition.js index c2345b1c6..2a41d04a7 100644 --- a/src/slang-nodes/UnnamedFunctionDefinition.js +++ b/src/slang-nodes/UnnamedFunctionDefinition.js @@ -11,10 +11,10 @@ export class UnnamedFunctionDefinition extends SlangNode { body; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); + super(); + this.initialize(ast, offset, comments, parse); + this.cleanModifierInvocationArguments(); - this.finalize(ast); } cleanModifierInvocationArguments() { diff --git a/src/slang-nodes/UntypedTupleMember.js b/src/slang-nodes/UntypedTupleMember.js index 279dea115..0b7c198de 100644 --- a/src/slang-nodes/UntypedTupleMember.js +++ b/src/slang-nodes/UntypedTupleMember.js @@ -6,9 +6,8 @@ export class UntypedTupleMember extends SlangNode { name; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } // TODO: implement print diff --git a/src/slang-nodes/UserDefinedValueTypeDefinition.js b/src/slang-nodes/UserDefinedValueTypeDefinition.js index da83770a8..dbbf7243c 100644 --- a/src/slang-nodes/UserDefinedValueTypeDefinition.js +++ b/src/slang-nodes/UserDefinedValueTypeDefinition.js @@ -12,9 +12,8 @@ export class UserDefinedValueTypeDefinition extends SlangNode { semicolon; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/UsingAlias.js b/src/slang-nodes/UsingAlias.js index c7765a3ad..5086e7b08 100644 --- a/src/slang-nodes/UsingAlias.js +++ b/src/slang-nodes/UsingAlias.js @@ -6,9 +6,8 @@ export class UsingAlias extends SlangNode { operator; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/UsingClause.js b/src/slang-nodes/UsingClause.js index bf36909ce..433fffddc 100644 --- a/src/slang-nodes/UsingClause.js +++ b/src/slang-nodes/UsingClause.js @@ -4,9 +4,8 @@ export class UsingClause extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/UsingDeconstruction.js b/src/slang-nodes/UsingDeconstruction.js index 67520bf00..eb9958229 100644 --- a/src/slang-nodes/UsingDeconstruction.js +++ b/src/slang-nodes/UsingDeconstruction.js @@ -8,9 +8,8 @@ export class UsingDeconstruction extends SlangNode { closeBrace; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/UsingDeconstructionSymbol.js b/src/slang-nodes/UsingDeconstructionSymbol.js index 3f5c5244b..b3f43e2b0 100644 --- a/src/slang-nodes/UsingDeconstructionSymbol.js +++ b/src/slang-nodes/UsingDeconstructionSymbol.js @@ -6,9 +6,8 @@ export class UsingDeconstructionSymbol extends SlangNode { alias; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/UsingDeconstructionSymbols.js b/src/slang-nodes/UsingDeconstructionSymbols.js index 2f7363a9b..91f025864 100644 --- a/src/slang-nodes/UsingDeconstructionSymbols.js +++ b/src/slang-nodes/UsingDeconstructionSymbols.js @@ -10,9 +10,8 @@ export class UsingDeconstructionSymbols extends SlangNode { separators; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print, options) { diff --git a/src/slang-nodes/UsingDirective.js b/src/slang-nodes/UsingDirective.js index 635b7e527..6a1542f72 100644 --- a/src/slang-nodes/UsingDirective.js +++ b/src/slang-nodes/UsingDirective.js @@ -14,9 +14,8 @@ export class UsingDirective extends SlangNode { semicolon; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/UsingOperator.js b/src/slang-nodes/UsingOperator.js index 5dba403be..836af03ab 100644 --- a/src/slang-nodes/UsingOperator.js +++ b/src/slang-nodes/UsingOperator.js @@ -4,9 +4,8 @@ export class UsingOperator extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print() { diff --git a/src/slang-nodes/UsingTarget.js b/src/slang-nodes/UsingTarget.js index 314665114..59b17120c 100644 --- a/src/slang-nodes/UsingTarget.js +++ b/src/slang-nodes/UsingTarget.js @@ -4,9 +4,8 @@ export class UsingTarget extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/VariableDeclarationStatement.js b/src/slang-nodes/VariableDeclarationStatement.js index 01b943b4f..4d145bc89 100644 --- a/src/slang-nodes/VariableDeclarationStatement.js +++ b/src/slang-nodes/VariableDeclarationStatement.js @@ -15,9 +15,8 @@ export class VariableDeclarationStatement extends SlangNode { semicolon; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/VariableDeclarationType.js b/src/slang-nodes/VariableDeclarationType.js index c2c6f09ac..f57c5f5de 100644 --- a/src/slang-nodes/VariableDeclarationType.js +++ b/src/slang-nodes/VariableDeclarationType.js @@ -4,9 +4,8 @@ export class VariableDeclarationType extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/VariableDeclarationValue.js b/src/slang-nodes/VariableDeclarationValue.js index 0c068324f..97adb1459 100644 --- a/src/slang-nodes/VariableDeclarationValue.js +++ b/src/slang-nodes/VariableDeclarationValue.js @@ -6,9 +6,8 @@ export class VariableDeclarationValue extends SlangNode { expression; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/VersionComparator.js b/src/slang-nodes/VersionComparator.js index 1ae2e9d5b..918ba836d 100644 --- a/src/slang-nodes/VersionComparator.js +++ b/src/slang-nodes/VersionComparator.js @@ -6,9 +6,8 @@ export class VersionComparator extends SlangNode { operand; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/VersionExpression.js b/src/slang-nodes/VersionExpression.js index dac6a5679..d546ba0c8 100644 --- a/src/slang-nodes/VersionExpression.js +++ b/src/slang-nodes/VersionExpression.js @@ -4,9 +4,8 @@ export class VersionExpression extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/VersionExpressionSet.js b/src/slang-nodes/VersionExpressionSet.js index c49fe2b2a..c5974e17e 100644 --- a/src/slang-nodes/VersionExpressionSet.js +++ b/src/slang-nodes/VersionExpressionSet.js @@ -7,9 +7,8 @@ export class VersionExpressionSet extends SlangNode { items; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/VersionExpressionSets.js b/src/slang-nodes/VersionExpressionSets.js index 669386ddf..e55c6a6dd 100644 --- a/src/slang-nodes/VersionExpressionSets.js +++ b/src/slang-nodes/VersionExpressionSets.js @@ -6,9 +6,8 @@ export class VersionExpressionSets extends SlangNode { separators; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/VersionPragma.js b/src/slang-nodes/VersionPragma.js index 46b98267e..3e0c497c5 100644 --- a/src/slang-nodes/VersionPragma.js +++ b/src/slang-nodes/VersionPragma.js @@ -6,9 +6,8 @@ export class VersionPragma extends SlangNode { sets; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/VersionRange.js b/src/slang-nodes/VersionRange.js index c00505113..b2404a765 100644 --- a/src/slang-nodes/VersionRange.js +++ b/src/slang-nodes/VersionRange.js @@ -8,9 +8,8 @@ export class VersionRange extends SlangNode { rightOperand; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } // TODO: implement print diff --git a/src/slang-nodes/VersionSpecifiers.js b/src/slang-nodes/VersionSpecifiers.js index c6d2b0bbe..efc2a3c5a 100644 --- a/src/slang-nodes/VersionSpecifiers.js +++ b/src/slang-nodes/VersionSpecifiers.js @@ -6,9 +6,8 @@ export class VersionSpecifiers extends SlangNode { separators; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print() { diff --git a/src/slang-nodes/WhileStatement.js b/src/slang-nodes/WhileStatement.js index 2d604aaaf..cb50acc67 100644 --- a/src/slang-nodes/WhileStatement.js +++ b/src/slang-nodes/WhileStatement.js @@ -16,9 +16,8 @@ export class WhileStatement extends SlangNode { body; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/YulArguments.js b/src/slang-nodes/YulArguments.js index 890b15f08..70d0025cd 100644 --- a/src/slang-nodes/YulArguments.js +++ b/src/slang-nodes/YulArguments.js @@ -7,9 +7,8 @@ export class YulArguments extends SlangNode { separators; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/YulAssignmentOperator.js b/src/slang-nodes/YulAssignmentOperator.js index 917ca3cef..f50a58c8b 100644 --- a/src/slang-nodes/YulAssignmentOperator.js +++ b/src/slang-nodes/YulAssignmentOperator.js @@ -4,9 +4,8 @@ export class YulAssignmentOperator extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/YulAssignmentStatement.js b/src/slang-nodes/YulAssignmentStatement.js index 4ec4dc499..7a7e02ad3 100644 --- a/src/slang-nodes/YulAssignmentStatement.js +++ b/src/slang-nodes/YulAssignmentStatement.js @@ -8,9 +8,8 @@ export class YulAssignmentStatement extends SlangNode { expression; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/YulBlock.js b/src/slang-nodes/YulBlock.js index b34774fb3..710aae7c6 100644 --- a/src/slang-nodes/YulBlock.js +++ b/src/slang-nodes/YulBlock.js @@ -8,9 +8,8 @@ export class YulBlock extends SlangNode { closeBrace; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/YulBreakStatement.js b/src/slang-nodes/YulBreakStatement.js index 830155439..c2dd43d33 100644 --- a/src/slang-nodes/YulBreakStatement.js +++ b/src/slang-nodes/YulBreakStatement.js @@ -4,9 +4,8 @@ export class YulBreakStatement extends SlangNode { breakKeyword; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print() { diff --git a/src/slang-nodes/YulBuiltInFunction.js b/src/slang-nodes/YulBuiltInFunction.js index af0212b9d..4c9dce649 100644 --- a/src/slang-nodes/YulBuiltInFunction.js +++ b/src/slang-nodes/YulBuiltInFunction.js @@ -4,9 +4,8 @@ export class YulBuiltInFunction extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print() { diff --git a/src/slang-nodes/YulColonAndEqual.js b/src/slang-nodes/YulColonAndEqual.js index e900e2d1c..68db3af28 100644 --- a/src/slang-nodes/YulColonAndEqual.js +++ b/src/slang-nodes/YulColonAndEqual.js @@ -6,9 +6,8 @@ export class YulColonAndEqual extends SlangNode { equal; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } // TODO: implement print diff --git a/src/slang-nodes/YulContinueStatement.js b/src/slang-nodes/YulContinueStatement.js index 5fe979ee3..b73020a1e 100644 --- a/src/slang-nodes/YulContinueStatement.js +++ b/src/slang-nodes/YulContinueStatement.js @@ -4,9 +4,8 @@ export class YulContinueStatement extends SlangNode { continueKeyword; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print() { diff --git a/src/slang-nodes/YulDefaultCase.js b/src/slang-nodes/YulDefaultCase.js index 1e856f068..a09625c4c 100644 --- a/src/slang-nodes/YulDefaultCase.js +++ b/src/slang-nodes/YulDefaultCase.js @@ -6,9 +6,8 @@ export class YulDefaultCase extends SlangNode { body; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/YulExpression.js b/src/slang-nodes/YulExpression.js index 361750fd2..e591f414d 100644 --- a/src/slang-nodes/YulExpression.js +++ b/src/slang-nodes/YulExpression.js @@ -4,9 +4,8 @@ export class YulExpression extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/YulForStatement.js b/src/slang-nodes/YulForStatement.js index 3d723b017..575cbad49 100644 --- a/src/slang-nodes/YulForStatement.js +++ b/src/slang-nodes/YulForStatement.js @@ -12,9 +12,8 @@ export class YulForStatement extends SlangNode { body; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/YulFunctionCallExpression.js b/src/slang-nodes/YulFunctionCallExpression.js index 196802886..856d61c34 100644 --- a/src/slang-nodes/YulFunctionCallExpression.js +++ b/src/slang-nodes/YulFunctionCallExpression.js @@ -10,9 +10,8 @@ export class YulFunctionCallExpression extends SlangNode { closeParen; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/YulFunctionDefinition.js b/src/slang-nodes/YulFunctionDefinition.js index 41d2c89e9..9eaa1f7fb 100644 --- a/src/slang-nodes/YulFunctionDefinition.js +++ b/src/slang-nodes/YulFunctionDefinition.js @@ -12,9 +12,8 @@ export class YulFunctionDefinition extends SlangNode { body; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/YulIfStatement.js b/src/slang-nodes/YulIfStatement.js index 9a952ec01..cc9b60dc5 100644 --- a/src/slang-nodes/YulIfStatement.js +++ b/src/slang-nodes/YulIfStatement.js @@ -8,9 +8,8 @@ export class YulIfStatement extends SlangNode { body; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/YulLabel.js b/src/slang-nodes/YulLabel.js index ed4d71e9f..2f2bb9dbb 100644 --- a/src/slang-nodes/YulLabel.js +++ b/src/slang-nodes/YulLabel.js @@ -2,15 +2,15 @@ import { doc } from 'prettier'; import { SlangNode } from './SlangNode.js'; const { dedent, line } = doc.builders; + export class YulLabel extends SlangNode { label; colon; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print() { diff --git a/src/slang-nodes/YulLeaveStatement.js b/src/slang-nodes/YulLeaveStatement.js index 527d0ac3d..dac0d01ff 100644 --- a/src/slang-nodes/YulLeaveStatement.js +++ b/src/slang-nodes/YulLeaveStatement.js @@ -4,9 +4,8 @@ export class YulLeaveStatement extends SlangNode { leaveKeyword; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } // TODO: implement print diff --git a/src/slang-nodes/YulLiteral.js b/src/slang-nodes/YulLiteral.js index f2beb34a8..0a455bd39 100644 --- a/src/slang-nodes/YulLiteral.js +++ b/src/slang-nodes/YulLiteral.js @@ -4,9 +4,8 @@ export class YulLiteral extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/YulParameters.js b/src/slang-nodes/YulParameters.js index 7d73cf157..861b29021 100644 --- a/src/slang-nodes/YulParameters.js +++ b/src/slang-nodes/YulParameters.js @@ -7,9 +7,8 @@ export class YulParameters extends SlangNode { separators; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print() { diff --git a/src/slang-nodes/YulParametersDeclaration.js b/src/slang-nodes/YulParametersDeclaration.js index 80430319b..6601c4169 100644 --- a/src/slang-nodes/YulParametersDeclaration.js +++ b/src/slang-nodes/YulParametersDeclaration.js @@ -8,9 +8,8 @@ export class YulParametersDeclaration extends SlangNode { closeParen; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/YulPath.js b/src/slang-nodes/YulPath.js index 72cfacd46..3058a68cc 100644 --- a/src/slang-nodes/YulPath.js +++ b/src/slang-nodes/YulPath.js @@ -6,9 +6,8 @@ export class YulPath extends SlangNode { separators; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/YulPathComponent.js b/src/slang-nodes/YulPathComponent.js index 3fc421293..d359c4d26 100644 --- a/src/slang-nodes/YulPathComponent.js +++ b/src/slang-nodes/YulPathComponent.js @@ -4,9 +4,8 @@ export class YulPathComponent extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print() { diff --git a/src/slang-nodes/YulPaths.js b/src/slang-nodes/YulPaths.js index f81f3e617..983a9f30b 100644 --- a/src/slang-nodes/YulPaths.js +++ b/src/slang-nodes/YulPaths.js @@ -6,9 +6,8 @@ export class YulPaths extends SlangNode { separators; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/YulReturnVariables.js b/src/slang-nodes/YulReturnVariables.js index 740aab75f..39ab38c3c 100644 --- a/src/slang-nodes/YulReturnVariables.js +++ b/src/slang-nodes/YulReturnVariables.js @@ -10,9 +10,8 @@ export class YulReturnVariables extends SlangNode { separators; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print() { diff --git a/src/slang-nodes/YulReturnsDeclaration.js b/src/slang-nodes/YulReturnsDeclaration.js index c815952fa..83a3be111 100644 --- a/src/slang-nodes/YulReturnsDeclaration.js +++ b/src/slang-nodes/YulReturnsDeclaration.js @@ -10,9 +10,8 @@ export class YulReturnsDeclaration extends SlangNode { variables; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/YulStatement.js b/src/slang-nodes/YulStatement.js index 26b7c7043..6403f4f15 100644 --- a/src/slang-nodes/YulStatement.js +++ b/src/slang-nodes/YulStatement.js @@ -4,9 +4,8 @@ export class YulStatement extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/YulStatements.js b/src/slang-nodes/YulStatements.js index 5ca85781e..a9ae8bd88 100644 --- a/src/slang-nodes/YulStatements.js +++ b/src/slang-nodes/YulStatements.js @@ -10,9 +10,8 @@ export class YulStatements extends SlangNode { items; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print, options) { diff --git a/src/slang-nodes/YulSwitchCase.js b/src/slang-nodes/YulSwitchCase.js index ac4edf7ce..6475ce2bb 100644 --- a/src/slang-nodes/YulSwitchCase.js +++ b/src/slang-nodes/YulSwitchCase.js @@ -4,9 +4,8 @@ export class YulSwitchCase extends SlangNode { variant; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/YulSwitchCases.js b/src/slang-nodes/YulSwitchCases.js index 60f65c6dc..2a3a25a90 100644 --- a/src/slang-nodes/YulSwitchCases.js +++ b/src/slang-nodes/YulSwitchCases.js @@ -7,9 +7,8 @@ export class YulSwitchCases extends SlangNode { items; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/YulSwitchStatement.js b/src/slang-nodes/YulSwitchStatement.js index 88cf5bd0c..123f07f3b 100644 --- a/src/slang-nodes/YulSwitchStatement.js +++ b/src/slang-nodes/YulSwitchStatement.js @@ -11,9 +11,8 @@ export class YulSwitchStatement extends SlangNode { cases; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/YulValueCase.js b/src/slang-nodes/YulValueCase.js index 0d1aacee9..78bd727d7 100644 --- a/src/slang-nodes/YulValueCase.js +++ b/src/slang-nodes/YulValueCase.js @@ -8,9 +8,8 @@ export class YulValueCase extends SlangNode { body; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/YulVariableAssignmentStatement.js b/src/slang-nodes/YulVariableAssignmentStatement.js index a74c721c1..cff1ebc6f 100644 --- a/src/slang-nodes/YulVariableAssignmentStatement.js +++ b/src/slang-nodes/YulVariableAssignmentStatement.js @@ -8,9 +8,8 @@ export class YulVariableAssignmentStatement extends SlangNode { expression; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/YulVariableDeclarationStatement.js b/src/slang-nodes/YulVariableDeclarationStatement.js index e117964e5..f0b5dbcb9 100644 --- a/src/slang-nodes/YulVariableDeclarationStatement.js +++ b/src/slang-nodes/YulVariableDeclarationStatement.js @@ -8,9 +8,8 @@ export class YulVariableDeclarationStatement extends SlangNode { value; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-nodes/YulVariableDeclarationValue.js b/src/slang-nodes/YulVariableDeclarationValue.js index 231920228..f21807719 100644 --- a/src/slang-nodes/YulVariableDeclarationValue.js +++ b/src/slang-nodes/YulVariableDeclarationValue.js @@ -6,9 +6,8 @@ export class YulVariableDeclarationValue extends SlangNode { expression; constructor(ast, offset, comments, parse) { - super(ast, offset, comments); - this.initialize(ast, parse); - this.finalize(ast); + super(); + this.initialize(ast, offset, comments, parse); } print(path, print) { diff --git a/src/slang-utils/get-offsets.js b/src/slang-utils/get-offsets.js new file mode 100644 index 000000000..98482bea9 --- /dev/null +++ b/src/slang-utils/get-offsets.js @@ -0,0 +1,58 @@ +import { isComment } from './is-comment.js'; +import { Loc } from './loc.js'; + +export function getChildrenOffsets(children, initialOffset, comments) { + let offset = initialOffset; + + const offsets = children.reduce((offsetsArray, child) => { + if (child.type === 'Nonterminal') { + offsetsArray.push(offset); + } + if (child.type === 'Terminal' && isComment(child)) { + // Since the fetching the comments and calculating offsets are both done + // as we iterate over the children and the comment also depends on the + // offset, it's hard to separate these responsibilities into different + // functions. + comments.push({ + kind: child.kind, + value: child.text, + loc: new Loc({ + startWithTrivia: offset, + endWithTrivia: offset + child.textLength.utf8 + }) + }); + } + + offset += child.textLength.utf8; + return offsetsArray; + }, []); + return offsets; +} + +export function getLeadingOffset(children) { + let offset = 0; + for (let i = 0; i < children.length; i += 1) { + const child = children[i]; + if (child.type === 'Nonterminal') { + // The node's content starts when we find the first non-terminal, + // non-comment, non-whitespace token. + return offset; + } + if ( + child.type === 'Terminal' && + !isComment(child) && + child.kind !== 'EndOfLine' && + child.kind !== 'Whitespace' + ) { + // The content of the node started if we find a non-comment, + // non-whitespace token. + return offset; + } + offset += child.textLength.utf8; + } + return offset; +} + +export function getTrailingOffset(children) { + return getLeadingOffset(children.reverse()); +} diff --git a/src/slang-utils/loc.js b/src/slang-utils/loc.js index 508212fd3..e0aeba954 100644 --- a/src/slang-utils/loc.js +++ b/src/slang-utils/loc.js @@ -1,6 +1,4 @@ export class Loc { - childrenOffsets = []; - startWithTrivia; start; @@ -9,11 +7,7 @@ export class Loc { end; - constructor({ startWithTrivia, endWithTrivia, start, end, childrenOffsets }) { - if (typeof childrenOffsets !== 'undefined') { - this.childrenOffsets = childrenOffsets; - } - + constructor({ startWithTrivia, endWithTrivia, start, end }) { this.startWithTrivia = startWithTrivia; this.endWithTrivia = endWithTrivia; From 24daa2b08281e9b67adbb338aafc36062be55fb8 Mon Sep 17 00:00:00 2001 From: Klaus Date: Tue, 16 Jul 2024 12:28:33 +1200 Subject: [PATCH 082/160] no need for Loc to be a class --- src/slang-nodes/ExponentiationExpression.js | 13 ++++++------- src/slang-nodes/ModifierDefinition.js | 12 +++++++----- src/slang-nodes/SlangNode.js | 5 ++--- src/slang-utils/create-hug-function.js | 9 ++++----- src/slang-utils/get-offsets.js | 9 ++++----- src/slang-utils/loc.js | 18 ------------------ 6 files changed, 23 insertions(+), 43 deletions(-) diff --git a/src/slang-nodes/ExponentiationExpression.js b/src/slang-nodes/ExponentiationExpression.js index 6b4aaaca8..800c3098e 100644 --- a/src/slang-nodes/ExponentiationExpression.js +++ b/src/slang-nodes/ExponentiationExpression.js @@ -3,7 +3,6 @@ import coerce from 'semver/functions/coerce.js'; import satisfies from 'semver/functions/satisfies.js'; import { createBinaryOperationPrinter } from '../slang-printers/create-binary-operation-printer.js'; import { createHugFunction } from '../slang-utils/create-hug-function.js'; -import { Loc } from '../slang-utils/loc.js'; import { SlangNode } from './SlangNode.js'; import { Expression } from './Expression.js'; import { TupleExpression } from './TupleExpression.js'; @@ -51,24 +50,24 @@ export class ExponentiationExpression extends SlangNode { }; this.leftOperand = new Expression({ kind: 'Expression', - loc: new Loc(leftLoc), + loc: { ...leftLoc }, variant: new TupleExpression({ kind: 'TupleExpression', - loc: new Loc(leftLoc), + loc: { ...leftLoc }, openParen: '(', items: new TupleValues({ kind: 'TupleValues', - loc: new Loc(leftLoc), + loc: { ...leftLoc }, items: [ new TupleValue({ kind: 'TupleValue', - loc: new Loc(leftLoc), + loc: { ...leftLoc }, expression: new Expression({ kind: 'Expression', - loc: new Loc(leftLoc), + loc: { ...leftLoc }, variant: new ExponentiationExpression({ kind: 'ExponentiationExpression', - loc: new Loc(leftLoc), + loc: { ...leftLoc }, leftOperand: this.leftOperand, operator: '**', rightOperand: this.rightOperand.variant.leftOperand diff --git a/src/slang-nodes/ModifierDefinition.js b/src/slang-nodes/ModifierDefinition.js index c2622ab76..bc983115a 100644 --- a/src/slang-nodes/ModifierDefinition.js +++ b/src/slang-nodes/ModifierDefinition.js @@ -2,7 +2,6 @@ import { printFunction } from '../slang-printers/print-function.js'; import { SlangNode } from './SlangNode.js'; import { ParametersDeclaration } from './ParametersDeclaration.js'; import { Parameters } from './Parameters.js'; -import { Loc } from '../slang-utils/loc.js'; export class ModifierDefinition extends SlangNode { modifierKeyword; @@ -20,17 +19,20 @@ export class ModifierDefinition extends SlangNode { this.initialize(ast, offset, comments, parse); if (typeof this.parameters === 'undefined') { + const parametersOffset = this.attributes.loc.startWithTrivia; const parametersLoc = { - startWithTrivia: this.attributes.loc.startWithTrivia, - endWithTrivia: this.attributes.loc.startWithTrivia + startWithTrivia: parametersOffset, + start: parametersOffset, + endWithTrivia: parametersOffset, + end: parametersOffset }; this.parameters = new ParametersDeclaration({ kind: 'ParametersDeclaration', - loc: new Loc(parametersLoc), + loc: { ...parametersLoc }, openParen: '(', parameters: new Parameters({ kind: 'Parameters', - loc: new Loc(parametersLoc), + loc: { ...parametersLoc }, items: [], separators: [] }), diff --git a/src/slang-nodes/SlangNode.js b/src/slang-nodes/SlangNode.js index e7d09d261..cdbdfbb3b 100644 --- a/src/slang-nodes/SlangNode.js +++ b/src/slang-nodes/SlangNode.js @@ -1,4 +1,3 @@ -import { Loc } from '../slang-utils/loc.js'; import { getChildrenOffsets, getLeadingOffset, @@ -62,11 +61,11 @@ export class SlangNode { } } - this.loc = new Loc({ + this.loc = { startWithTrivia, start: startWithTrivia + leadingOffset, endWithTrivia, end: endWithTrivia - trailingOffset - }); + }; } } diff --git a/src/slang-utils/create-hug-function.js b/src/slang-utils/create-hug-function.js index 35160f8ef..c86ab8ee3 100644 --- a/src/slang-utils/create-hug-function.js +++ b/src/slang-utils/create-hug-function.js @@ -3,7 +3,6 @@ import { TupleExpression } from '../slang-nodes/TupleExpression.js'; import { TupleValues } from '../slang-nodes/TupleValues.js'; import { TupleValue } from '../slang-nodes/TupleValue.js'; import { isBinaryOperation } from './is-binary-operation.js'; -import { Loc } from './loc.js'; export function createHugFunction(huggableOperators) { const operators = new Set(huggableOperators); @@ -21,18 +20,18 @@ export function createHugFunction(huggableOperators) { return new Expression({ kind: 'Expression', - loc: new Loc(loc), + loc: { ...loc }, variant: new TupleExpression({ kind: 'TupleExpression', - loc: new Loc(loc), + loc: { ...loc }, openParen: '(', items: new TupleValues({ kind: 'TupleValues', - loc: new Loc(loc), + loc: { ...loc }, items: [ new TupleValue({ kind: 'TupleValue', - loc: new Loc(loc), + loc: { ...loc }, expression: node }) ], diff --git a/src/slang-utils/get-offsets.js b/src/slang-utils/get-offsets.js index 98482bea9..975faa3c8 100644 --- a/src/slang-utils/get-offsets.js +++ b/src/slang-utils/get-offsets.js @@ -1,5 +1,4 @@ import { isComment } from './is-comment.js'; -import { Loc } from './loc.js'; export function getChildrenOffsets(children, initialOffset, comments) { let offset = initialOffset; @@ -16,10 +15,10 @@ export function getChildrenOffsets(children, initialOffset, comments) { comments.push({ kind: child.kind, value: child.text, - loc: new Loc({ - startWithTrivia: offset, - endWithTrivia: offset + child.textLength.utf8 - }) + loc: { + start: offset, + end: offset + child.textLength.utf8 + } }); } diff --git a/src/slang-utils/loc.js b/src/slang-utils/loc.js index e0aeba954..4d4cdec6b 100644 --- a/src/slang-utils/loc.js +++ b/src/slang-utils/loc.js @@ -1,21 +1,3 @@ -export class Loc { - startWithTrivia; - - start; - - endWithTrivia; - - end; - - constructor({ startWithTrivia, endWithTrivia, start, end }) { - this.startWithTrivia = startWithTrivia; - this.endWithTrivia = endWithTrivia; - - this.start = typeof start === 'undefined' ? startWithTrivia : start; - this.end = typeof end === 'undefined' ? endWithTrivia : end; - } -} - export function locStart(node) { return node.loc.start; } From ba49760fd77f07917ad42e5b99c9bf34c8e30383 Mon Sep 17 00:00:00 2001 From: Klaus Date: Tue, 16 Jul 2024 13:09:35 +1200 Subject: [PATCH 083/160] adding comments and renaming variables --- src/slang-nodes/SlangNode.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/slang-nodes/SlangNode.js b/src/slang-nodes/SlangNode.js index cdbdfbb3b..37ee148c5 100644 --- a/src/slang-nodes/SlangNode.js +++ b/src/slang-nodes/SlangNode.js @@ -12,16 +12,20 @@ export class SlangNode { comments = []; initialize(ast, offset, comments, parse) { - const children = ast.cst.children(); - this.kind = ast.cst.kind; - const childrenOffsets = getChildrenOffsets(children, offset, comments); + // Collect comments and get children offsets. + const cstChildren = ast.cst.children(); + const childrenOffsets = getChildrenOffsets(cstChildren, offset, comments); - const getValue = (astChild) => - astChild.type === 'Terminal' + // populate all children nodes + // TODO: before moving to typescript, this should be moved to a fetch + // function that returns static typed classes. + function getValue(astChild) { + return astChild.type === 'Terminal' ? astChild.text : parse(astChild, childrenOffsets.shift()); + } const childrenKeys = Object.keys(this).slice(3); @@ -34,10 +38,11 @@ export class SlangNode { } }); + // calculate correct loc object const startWithTrivia = offset; const endWithTrivia = offset + ast.cst.textLength.utf8; - let leadingOffset = getLeadingOffset(children); - let trailingOffset = getTrailingOffset(children); + let leadingOffset = getLeadingOffset(cstChildren); + let trailingOffset = getTrailingOffset(cstChildren); if (leadingOffset === 0 || trailingOffset === 0) { for (let i = 0; i < childrenKeys.length; i += 1) { From 64a3558c265c755770a388c0910980248806dac5 Mon Sep 17 00:00:00 2001 From: Klaus Date: Tue, 16 Jul 2024 15:18:26 +1200 Subject: [PATCH 084/160] cleaning up ugly code --- src/slang-nodes/ModifierInvocation.js | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/slang-nodes/ModifierInvocation.js b/src/slang-nodes/ModifierInvocation.js index 1c0d56ede..71e9a02eb 100644 --- a/src/slang-nodes/ModifierInvocation.js +++ b/src/slang-nodes/ModifierInvocation.js @@ -2,8 +2,6 @@ import { isComment } from '../slang-utils/is-comment.js'; import { SlangNode } from './SlangNode.js'; export class ModifierInvocation extends SlangNode { - #ast; - name; arguments; @@ -12,20 +10,16 @@ export class ModifierInvocation extends SlangNode { super(); this.initialize(ast, offset, comments, parse); - this.#ast = ast; - } - - cleanModifierInvocationArguments() { - if ( - this.arguments && - this.arguments.variant.kind === 'PositionalArgumentsDeclaration' && - this.arguments.variant.arguments.items.length === 0 && // no arguments - !this.#ast.arguments.variant.cst - .children() - .some((child) => isComment(child)) // no comments - ) { - this.arguments = undefined; - } + this.cleanModifierInvocationArguments = () => { + if ( + this.arguments && + this.arguments.variant.kind === 'PositionalArgumentsDeclaration' && + this.arguments.variant.arguments.items.length === 0 && // no arguments + !ast.arguments.variant.cst.children().some((child) => isComment(child)) // no comments + ) { + this.arguments = undefined; + } + }; } print(path, print) { From 6015067a697ed19ad5a75da19209f443d2b37608 Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 17 Jul 2024 15:13:19 +1200 Subject: [PATCH 085/160] so the move to typescript is easier, the parse function is replaced by a specialised fetch function --- src/slang-nodes/ABICoderPragma.js | 9 ++- src/slang-nodes/AdditiveExpression.js | 25 ++++++- src/slang-nodes/AddressType.js | 9 ++- src/slang-nodes/AndExpression.js | 25 ++++++- src/slang-nodes/ArgumentsDeclaration.js | 20 ++++- src/slang-nodes/ArrayExpression.js | 19 ++++- src/slang-nodes/ArrayTypeName.js | 29 ++++++- src/slang-nodes/ArrayValues.js | 21 +++++- src/slang-nodes/AssemblyFlags.js | 21 +++++- src/slang-nodes/AssemblyFlagsDeclaration.js | 19 ++++- src/slang-nodes/AssemblyStatement.js | 38 +++++++++- src/slang-nodes/AssignmentExpression.js | 25 ++++++- src/slang-nodes/BitwiseAndExpression.js | 25 ++++++- src/slang-nodes/BitwiseOrExpression.js | 25 ++++++- src/slang-nodes/BitwiseXorExpression.js | 25 ++++++- src/slang-nodes/Block.js | 19 ++++- src/slang-nodes/BreakStatement.js | 9 ++- src/slang-nodes/CallOptions.js | 21 +++++- src/slang-nodes/CallOptionsExpression.js | 27 ++++++- src/slang-nodes/CatchClause.js | 28 ++++++- src/slang-nodes/CatchClauseError.js | 18 ++++- src/slang-nodes/CatchClauses.js | 20 ++++- src/slang-nodes/ComparisonExpression.js | 25 ++++++- src/slang-nodes/ConditionalExpression.js | 32 +++++++- src/slang-nodes/ConstantDefinition.js | 29 ++++++- src/slang-nodes/ConstructorAttribute.js | 20 ++++- src/slang-nodes/ConstructorAttributes.js | 20 ++++- src/slang-nodes/ConstructorDefinition.js | 34 ++++++++- src/slang-nodes/ContinueStatement.js | 9 ++- src/slang-nodes/ContractDefinition.js | 38 +++++++++- src/slang-nodes/ContractMember.js | 45 ++++++++++- src/slang-nodes/ContractMembers.js | 20 ++++- src/slang-nodes/DecimalNumberExpression.js | 20 ++++- src/slang-nodes/DoWhileStatement.js | 38 +++++++++- src/slang-nodes/ElementaryType.js | 19 ++++- src/slang-nodes/ElseBranch.js | 20 ++++- src/slang-nodes/EmitStatement.js | 27 ++++++- src/slang-nodes/EnumDefinition.js | 21 +++++- src/slang-nodes/EnumMembers.js | 9 ++- src/slang-nodes/EqualityExpression.js | 25 ++++++- src/slang-nodes/ErrorDefinition.js | 20 ++++- src/slang-nodes/ErrorParameter.js | 18 ++++- src/slang-nodes/ErrorParameters.js | 21 +++++- src/slang-nodes/ErrorParametersDeclaration.js | 19 ++++- src/slang-nodes/EventDefinition.js | 22 +++++- src/slang-nodes/EventParameter.js | 19 ++++- src/slang-nodes/EventParameters.js | 21 +++++- src/slang-nodes/EventParametersDeclaration.js | 19 ++++- src/slang-nodes/ExperimentalFeature.js | 20 ++++- src/slang-nodes/ExperimentalPragma.js | 18 ++++- src/slang-nodes/ExponentiationExpression.js | 21 +++++- src/slang-nodes/Expression.js | 75 ++++++++++++++++++- src/slang-nodes/ExpressionStatement.js | 18 ++++- src/slang-nodes/FallbackFunctionAttribute.js | 23 +++++- src/slang-nodes/FallbackFunctionAttributes.js | 20 ++++- src/slang-nodes/FallbackFunctionDefinition.js | 44 ++++++++++- src/slang-nodes/ForStatement.js | 54 ++++++++++++- src/slang-nodes/ForStatementCondition.js | 20 ++++- src/slang-nodes/ForStatementInitialization.js | 28 ++++++- src/slang-nodes/FunctionAttribute.js | 23 +++++- src/slang-nodes/FunctionAttributes.js | 20 ++++- src/slang-nodes/FunctionBody.js | 20 ++++- src/slang-nodes/FunctionCallExpression.js | 25 ++++++- src/slang-nodes/FunctionDefinition.js | 51 ++++++++++++- src/slang-nodes/FunctionName.js | 8 +- src/slang-nodes/FunctionType.js | 36 ++++++++- src/slang-nodes/FunctionTypeAttribute.js | 8 +- src/slang-nodes/FunctionTypeAttributes.js | 20 ++++- src/slang-nodes/HexNumberExpression.js | 20 ++++- src/slang-nodes/HexStringLiteral.js | 8 +- src/slang-nodes/HexStringLiterals.js | 20 ++++- src/slang-nodes/IdentifierPath.js | 9 ++- src/slang-nodes/IfStatement.js | 39 +++++++++- src/slang-nodes/ImportAlias.js | 9 ++- src/slang-nodes/ImportClause.js | 21 +++++- src/slang-nodes/ImportDeconstruction.js | 28 ++++++- src/slang-nodes/ImportDeconstructionSymbol.js | 21 +++++- .../ImportDeconstructionSymbols.js | 21 +++++- src/slang-nodes/ImportDirective.js | 19 ++++- src/slang-nodes/IndexAccessEnd.js | 20 ++++- src/slang-nodes/IndexAccessExpression.js | 38 +++++++++- src/slang-nodes/InheritanceSpecifier.js | 18 ++++- src/slang-nodes/InheritanceType.js | 27 ++++++- src/slang-nodes/InheritanceTypes.js | 21 +++++- src/slang-nodes/InterfaceDefinition.js | 38 +++++++++- src/slang-nodes/InterfaceMembers.js | 20 ++++- src/slang-nodes/LibraryDefinition.js | 21 +++++- src/slang-nodes/LibraryMembers.js | 20 ++++- src/slang-nodes/MappingKey.js | 18 ++++- src/slang-nodes/MappingKeyType.js | 19 ++++- src/slang-nodes/MappingType.js | 36 ++++++++- src/slang-nodes/MappingValue.js | 18 ++++- src/slang-nodes/MemberAccess.js | 8 +- src/slang-nodes/MemberAccessExpression.js | 26 ++++++- src/slang-nodes/ModifierAttribute.js | 20 ++++- src/slang-nodes/ModifierAttributes.js | 20 ++++- src/slang-nodes/ModifierDefinition.js | 36 ++++++++- src/slang-nodes/ModifierInvocation.js | 27 ++++++- src/slang-nodes/MultiplicativeExpression.js | 25 ++++++- src/slang-nodes/NamedArgument.js | 19 ++++- src/slang-nodes/NamedArgumentGroup.js | 20 ++++- src/slang-nodes/NamedArguments.js | 21 +++++- src/slang-nodes/NamedArgumentsDeclaration.js | 21 +++++- src/slang-nodes/NamedImport.js | 27 ++++++- src/slang-nodes/NewExpression.js | 18 ++++- src/slang-nodes/NumberUnit.js | 8 +- src/slang-nodes/OrExpression.js | 25 ++++++- src/slang-nodes/OverridePaths.js | 21 +++++- src/slang-nodes/OverridePathsDeclaration.js | 19 ++++- src/slang-nodes/OverrideSpecifier.js | 20 ++++- src/slang-nodes/Parameter.js | 28 ++++++- src/slang-nodes/Parameters.js | 20 ++++- src/slang-nodes/ParametersDeclaration.js | 18 ++++- src/slang-nodes/PathImport.js | 28 ++++++- src/slang-nodes/PositionalArguments.js | 21 +++++- .../PositionalArgumentsDeclaration.js | 20 ++++- src/slang-nodes/PostfixExpression.js | 18 ++++- src/slang-nodes/Pragma.js | 20 ++++- src/slang-nodes/PragmaDirective.js | 19 ++++- src/slang-nodes/PrefixExpression.js | 18 ++++- src/slang-nodes/ReceiveFunctionAttribute.js | 23 +++++- src/slang-nodes/ReceiveFunctionAttributes.js | 20 ++++- src/slang-nodes/ReceiveFunctionDefinition.js | 34 ++++++++- src/slang-nodes/ReturnStatement.js | 25 ++++++- src/slang-nodes/ReturnsDeclaration.js | 18 ++++- src/slang-nodes/RevertStatement.js | 29 ++++++- src/slang-nodes/ShiftExpression.js | 25 ++++++- src/slang-nodes/SlangNode.js | 23 +----- src/slang-nodes/SourceUnit.js | 29 ++++++- src/slang-nodes/SourceUnitMember.js | 44 ++++++++++- src/slang-nodes/SourceUnitMembers.js | 20 ++++- src/slang-nodes/StateVariableAttribute.js | 20 ++++- src/slang-nodes/StateVariableAttributes.js | 20 ++++- src/slang-nodes/StateVariableDefinition.js | 37 ++++++++- .../StateVariableDefinitionValue.js | 18 ++++- src/slang-nodes/Statement.js | 53 ++++++++++++- src/slang-nodes/Statements.js | 14 +++- src/slang-nodes/StorageLocation.js | 8 +- src/slang-nodes/StringExpression.js | 28 ++++++- src/slang-nodes/StringLiteral.js | 8 +- src/slang-nodes/StringLiterals.js | 20 ++++- src/slang-nodes/StructDefinition.js | 21 +++++- src/slang-nodes/StructMember.js | 19 ++++- src/slang-nodes/StructMembers.js | 20 ++++- src/slang-nodes/ThrowStatement.js | 9 ++- src/slang-nodes/TryStatement.js | 44 ++++++++++- src/slang-nodes/TupleDeconstructionElement.js | 19 ++++- .../TupleDeconstructionElements.js | 21 +++++- .../TupleDeconstructionStatement.js | 38 +++++++++- src/slang-nodes/TupleExpression.js | 18 ++++- src/slang-nodes/TupleMember.js | 20 ++++- src/slang-nodes/TupleValue.js | 18 ++++- src/slang-nodes/TupleValues.js | 20 ++++- src/slang-nodes/TypeExpression.js | 20 ++++- src/slang-nodes/TypeName.js | 28 ++++++- src/slang-nodes/TypedTupleMember.js | 28 ++++++- src/slang-nodes/UncheckedBlock.js | 18 ++++- src/slang-nodes/UnicodeStringLiteral.js | 8 +- src/slang-nodes/UnicodeStringLiterals.js | 20 ++++- src/slang-nodes/UnnamedFunctionAttribute.js | 20 ++++- src/slang-nodes/UnnamedFunctionAttributes.js | 20 ++++- src/slang-nodes/UnnamedFunctionDefinition.js | 34 ++++++++- src/slang-nodes/UntypedTupleMember.js | 21 +++++- .../UserDefinedValueTypeDefinition.js | 21 +++++- src/slang-nodes/UsingAlias.js | 18 ++++- src/slang-nodes/UsingClause.js | 20 ++++- src/slang-nodes/UsingDeconstruction.js | 19 ++++- src/slang-nodes/UsingDeconstructionSymbol.js | 27 ++++++- src/slang-nodes/UsingDeconstructionSymbols.js | 21 +++++- src/slang-nodes/UsingDirective.js | 36 ++++++++- src/slang-nodes/UsingOperator.js | 8 +- src/slang-nodes/UsingTarget.js | 20 ++++- .../VariableDeclarationStatement.js | 39 +++++++++- src/slang-nodes/VariableDeclarationType.js | 20 ++++- src/slang-nodes/VariableDeclarationValue.js | 18 ++++- src/slang-nodes/VersionComparator.js | 19 ++++- src/slang-nodes/VersionExpression.js | 28 ++++++- src/slang-nodes/VersionExpressionSet.js | 20 ++++- src/slang-nodes/VersionExpressionSets.js | 21 +++++- src/slang-nodes/VersionPragma.js | 18 ++++- src/slang-nodes/VersionRange.js | 25 ++++++- src/slang-nodes/VersionSpecifiers.js | 9 ++- src/slang-nodes/WhileStatement.js | 28 ++++++- src/slang-nodes/YulArguments.js | 21 +++++- src/slang-nodes/YulAssignmentOperator.js | 20 ++++- src/slang-nodes/YulAssignmentStatement.js | 24 ------ src/slang-nodes/YulBlock.js | 19 ++++- src/slang-nodes/YulBreakStatement.js | 8 +- src/slang-nodes/YulBuiltInFunction.js | 8 +- src/slang-nodes/YulColonAndEqual.js | 17 ----- src/slang-nodes/YulColonEqual.js | 24 ++++++ src/slang-nodes/YulContinueStatement.js | 8 +- src/slang-nodes/YulDefaultCase.js | 18 ++++- src/slang-nodes/YulExpression.js | 27 ++++++- src/slang-nodes/YulForStatement.js | 40 +++++++++- src/slang-nodes/YulFunctionCallExpression.js | 27 ++++++- src/slang-nodes/YulFunctionDefinition.js | 37 ++++++++- src/slang-nodes/YulIfStatement.js | 26 ++++++- src/slang-nodes/YulLabel.js | 9 ++- src/slang-nodes/YulLeaveStatement.js | 8 +- src/slang-nodes/YulLiteral.js | 23 +++++- src/slang-nodes/YulParameters.js | 9 ++- src/slang-nodes/YulParametersDeclaration.js | 19 ++++- src/slang-nodes/YulPath.js | 21 +++++- src/slang-nodes/YulPathComponent.js | 8 +- src/slang-nodes/YulPaths.js | 15 +++- src/slang-nodes/YulReturnVariables.js | 9 ++- src/slang-nodes/YulReturnsDeclaration.js | 18 ++++- .../YulStackAssignmentStatement.js | 38 ++++++++++ src/slang-nodes/YulStatement.js | 45 ++++++++++- src/slang-nodes/YulStatements.js | 20 ++++- src/slang-nodes/YulSwitchCase.js | 19 ++++- src/slang-nodes/YulSwitchCases.js | 20 ++++- src/slang-nodes/YulSwitchStatement.js | 26 ++++++- src/slang-nodes/YulValueCase.js | 26 ++++++- .../YulVariableAssignmentStatement.js | 33 +++++++- .../YulVariableDeclarationStatement.js | 21 +++++- .../YulVariableDeclarationValue.js | 25 ++++++- src/slang-nodes/index.js | 11 +-- 219 files changed, 4476 insertions(+), 465 deletions(-) delete mode 100644 src/slang-nodes/YulAssignmentStatement.js delete mode 100644 src/slang-nodes/YulColonAndEqual.js create mode 100644 src/slang-nodes/YulColonEqual.js create mode 100644 src/slang-nodes/YulStackAssignmentStatement.js diff --git a/src/slang-nodes/ABICoderPragma.js b/src/slang-nodes/ABICoderPragma.js index 65def6c35..807054da6 100644 --- a/src/slang-nodes/ABICoderPragma.js +++ b/src/slang-nodes/ABICoderPragma.js @@ -7,7 +7,14 @@ export class ABICoderPragma extends SlangNode { constructor(ast, offset, comments, parse) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = () => { + const { abicoderKeyword, version } = ast; + this.abicoderKeyword = abicoderKeyword.text; + this.version = version.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print() { diff --git a/src/slang-nodes/AdditiveExpression.js b/src/slang-nodes/AdditiveExpression.js index ef447c583..77da1a1f4 100644 --- a/src/slang-nodes/AdditiveExpression.js +++ b/src/slang-nodes/AdditiveExpression.js @@ -1,6 +1,7 @@ import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; import { createHugFunction } from '../slang-utils/create-hug-function.js'; import { SlangNode } from './SlangNode.js'; +import { Expression } from './Expression.js'; const tryToHug = createHugFunction(['%']); @@ -11,9 +12,29 @@ export class AdditiveExpression extends SlangNode { rightOperand; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { leftOperand, operator, rightOperand } = ast; + this.leftOperand = new Expression( + leftOperand, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.operator = operator.text; + this.rightOperand = new Expression( + rightOperand, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); diff --git a/src/slang-nodes/AddressType.js b/src/slang-nodes/AddressType.js index 067f8282e..271cfbf95 100644 --- a/src/slang-nodes/AddressType.js +++ b/src/slang-nodes/AddressType.js @@ -7,7 +7,14 @@ export class AddressType extends SlangNode { constructor(ast, offset, comments, parse) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = () => { + const { addressKeyword, payableKeyword } = ast; + this.addressKeyword = addressKeyword.text; + this.payableKeyword = payableKeyword?.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print() { diff --git a/src/slang-nodes/AndExpression.js b/src/slang-nodes/AndExpression.js index 160f10486..bb49f218c 100644 --- a/src/slang-nodes/AndExpression.js +++ b/src/slang-nodes/AndExpression.js @@ -1,5 +1,6 @@ import { printLogicalOperation } from '../slang-printers/print-logical-operation.js'; import { SlangNode } from './SlangNode.js'; +import { Expression } from './Expression.js'; export class AndExpression extends SlangNode { leftOperand; @@ -8,9 +9,29 @@ export class AndExpression extends SlangNode { rightOperand; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { leftOperand, operator, rightOperand } = ast; + this.leftOperand = new Expression( + leftOperand, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.operator = operator.text; + this.rightOperand = new Expression( + rightOperand, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print, options) { diff --git a/src/slang-nodes/ArgumentsDeclaration.js b/src/slang-nodes/ArgumentsDeclaration.js index 03ab626ca..f819122ac 100644 --- a/src/slang-nodes/ArgumentsDeclaration.js +++ b/src/slang-nodes/ArgumentsDeclaration.js @@ -1,11 +1,27 @@ import { SlangNode } from './SlangNode.js'; +import { PositionalArgumentsDeclaration } from './PositionalArgumentsDeclaration.js'; +import { NamedArgumentsDeclaration } from './NamedArgumentsDeclaration.js'; + +const variants = { PositionalArgumentsDeclaration, NamedArgumentsDeclaration }; export class ArgumentsDeclaration extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { variant } = ast; + this.variant = new variants[variant.cst.kind]( + variant, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/ArrayExpression.js b/src/slang-nodes/ArrayExpression.js index c38adc90a..87a33a10e 100644 --- a/src/slang-nodes/ArrayExpression.js +++ b/src/slang-nodes/ArrayExpression.js @@ -1,5 +1,6 @@ import { doc } from 'prettier'; import { SlangNode } from './SlangNode.js'; +import { ArrayValues } from './ArrayValues.js'; const { group } = doc.builders; @@ -10,9 +11,23 @@ export class ArrayExpression extends SlangNode { closeBracket; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { openBracket, items, closeBracket } = ast; + this.openBracket = openBracket.text; + this.items = new ArrayValues( + items, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.closeBracket = closeBracket.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/ArrayTypeName.js b/src/slang-nodes/ArrayTypeName.js index 64b98d963..62bdb3478 100644 --- a/src/slang-nodes/ArrayTypeName.js +++ b/src/slang-nodes/ArrayTypeName.js @@ -1,4 +1,6 @@ import { SlangNode } from './SlangNode.js'; +import { TypeName } from './TypeName.js'; +import { Expression } from './Expression.js'; export class ArrayTypeName extends SlangNode { operand; @@ -9,9 +11,32 @@ export class ArrayTypeName extends SlangNode { closeBracket; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { operand, openBracket, index, closeBracket } = ast; + this.operand = new TypeName( + operand, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.openBracket = openBracket.text; + if (index) { + this.index = new Expression( + index, + childrenOffsets.shift(), + comments, + parse, + options + ); + } + this.closeBracket = closeBracket.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/ArrayValues.js b/src/slang-nodes/ArrayValues.js index b0a16aa8a..0a6fd8808 100644 --- a/src/slang-nodes/ArrayValues.js +++ b/src/slang-nodes/ArrayValues.js @@ -1,14 +1,31 @@ import { printSeparatedList } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; +import { Expression } from './Expression.js'; export class ArrayValues extends SlangNode { items; separators; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items, separators } = ast; + this.items = items.map( + (item) => + new Expression( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + this.separators = separators.map((separator) => separator.text); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/AssemblyFlags.js b/src/slang-nodes/AssemblyFlags.js index f8b6df147..4e410f77e 100644 --- a/src/slang-nodes/AssemblyFlags.js +++ b/src/slang-nodes/AssemblyFlags.js @@ -1,14 +1,31 @@ import { printSeparatedList } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; +import { StringLiteral } from './StringLiteral.js'; export class AssemblyFlags extends SlangNode { items; separators; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items, separators } = ast; + this.items = items.map( + (item) => + new StringLiteral( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + this.separators = separators.map((separator) => separator.text); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/AssemblyFlagsDeclaration.js b/src/slang-nodes/AssemblyFlagsDeclaration.js index e37d2c003..a07a9fc38 100644 --- a/src/slang-nodes/AssemblyFlagsDeclaration.js +++ b/src/slang-nodes/AssemblyFlagsDeclaration.js @@ -1,4 +1,5 @@ import { SlangNode } from './SlangNode.js'; +import { AssemblyFlags } from './AssemblyFlags.js'; export class AssemblyFlagsDeclaration extends SlangNode { openParen; @@ -7,9 +8,23 @@ export class AssemblyFlagsDeclaration extends SlangNode { closeParen; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { openParen, flags, closeParen } = ast; + this.openParen = openParen.text; + this.flags = new AssemblyFlags( + flags, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.closeParen = closeParen.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/AssemblyStatement.js b/src/slang-nodes/AssemblyStatement.js index 6e0eb5a0c..0ea3121ec 100644 --- a/src/slang-nodes/AssemblyStatement.js +++ b/src/slang-nodes/AssemblyStatement.js @@ -1,4 +1,7 @@ import { SlangNode } from './SlangNode.js'; +import { StringLiteral } from './StringLiteral.js'; +import { AssemblyFlagsDeclaration } from './AssemblyFlagsDeclaration.js'; +import { YulBlock } from './YulBlock.js'; export class AssemblyStatement extends SlangNode { assemblyKeyword; @@ -9,9 +12,40 @@ export class AssemblyStatement extends SlangNode { body; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { assemblyKeyword, label, flags, body } = ast; + this.assemblyKeyword = assemblyKeyword.text; + if (label) { + this.label = new StringLiteral( + label, + childrenOffsets.shift(), + comments, + parse, + options + ); + } + if (flags) { + this.flags = new AssemblyFlagsDeclaration( + flags, + childrenOffsets.shift(), + comments, + parse, + options + ); + } + this.body = new YulBlock( + body, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/AssignmentExpression.js b/src/slang-nodes/AssignmentExpression.js index c7afc7046..9b85a0519 100644 --- a/src/slang-nodes/AssignmentExpression.js +++ b/src/slang-nodes/AssignmentExpression.js @@ -1,6 +1,7 @@ import { doc } from 'prettier'; import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; import { SlangNode } from './SlangNode.js'; +import { Expression } from './Expression.js'; const { group, indent, line } = doc.builders; @@ -11,9 +12,29 @@ export class AssignmentExpression extends SlangNode { rightOperand; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { leftOperand, operator, rightOperand } = ast; + this.leftOperand = new Expression( + leftOperand, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.operator = operator.text; + this.rightOperand = new Expression( + rightOperand, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/BitwiseAndExpression.js b/src/slang-nodes/BitwiseAndExpression.js index c3f2de493..2ae8e66fc 100644 --- a/src/slang-nodes/BitwiseAndExpression.js +++ b/src/slang-nodes/BitwiseAndExpression.js @@ -1,6 +1,7 @@ import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; import { createHugFunction } from '../slang-utils/create-hug-function.js'; import { SlangNode } from './SlangNode.js'; +import { Expression } from './Expression.js'; const tryToHug = createHugFunction(['+', '-', '*', '/', '**', '<<', '>>']); @@ -11,9 +12,29 @@ export class BitwiseAndExpression extends SlangNode { rightOperand; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { leftOperand, operator, rightOperand } = ast; + this.leftOperand = new Expression( + leftOperand, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.operator = operator.text; + this.rightOperand = new Expression( + rightOperand, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); diff --git a/src/slang-nodes/BitwiseOrExpression.js b/src/slang-nodes/BitwiseOrExpression.js index 277ba1dfa..313402f1a 100644 --- a/src/slang-nodes/BitwiseOrExpression.js +++ b/src/slang-nodes/BitwiseOrExpression.js @@ -1,6 +1,7 @@ import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; import { createHugFunction } from '../slang-utils/create-hug-function.js'; import { SlangNode } from './SlangNode.js'; +import { Expression } from './Expression.js'; const tryToHug = createHugFunction([ '+', @@ -21,9 +22,29 @@ export class BitwiseOrExpression extends SlangNode { rightOperand; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { leftOperand, operator, rightOperand } = ast; + this.leftOperand = new Expression( + leftOperand, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.operator = operator.text; + this.rightOperand = new Expression( + rightOperand, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); diff --git a/src/slang-nodes/BitwiseXorExpression.js b/src/slang-nodes/BitwiseXorExpression.js index 18085126e..3c52d5fb2 100644 --- a/src/slang-nodes/BitwiseXorExpression.js +++ b/src/slang-nodes/BitwiseXorExpression.js @@ -1,6 +1,7 @@ import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; import { createHugFunction } from '../slang-utils/create-hug-function.js'; import { SlangNode } from './SlangNode.js'; +import { Expression } from './Expression.js'; const tryToHug = createHugFunction(['+', '-', '*', '/', '**', '<<', '>>', '&']); @@ -11,9 +12,29 @@ export class BitwiseXorExpression extends SlangNode { rightOperand; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { leftOperand, operator, rightOperand } = ast; + this.leftOperand = new Expression( + leftOperand, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.operator = operator.text; + this.rightOperand = new Expression( + rightOperand, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); diff --git a/src/slang-nodes/Block.js b/src/slang-nodes/Block.js index 9facac25e..9e78688b0 100644 --- a/src/slang-nodes/Block.js +++ b/src/slang-nodes/Block.js @@ -1,4 +1,5 @@ import { SlangNode } from './SlangNode.js'; +import { Statements } from './Statements.js'; export class Block extends SlangNode { openBrace; @@ -7,9 +8,23 @@ export class Block extends SlangNode { closeBrace; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { openBrace, statements, closeBrace } = ast; + this.openBrace = openBrace.text; + this.statements = new Statements( + statements, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.closeBrace = closeBrace.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/BreakStatement.js b/src/slang-nodes/BreakStatement.js index 4d99ecdea..6b8b5bd3b 100644 --- a/src/slang-nodes/BreakStatement.js +++ b/src/slang-nodes/BreakStatement.js @@ -7,7 +7,14 @@ export class BreakStatement extends SlangNode { constructor(ast, offset, comments, parse) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = () => { + const { breakKeyword, semicolon } = ast; + this.breakKeyword = breakKeyword.text; + this.semicolon = semicolon.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print() { diff --git a/src/slang-nodes/CallOptions.js b/src/slang-nodes/CallOptions.js index b6c96129b..783cc6733 100644 --- a/src/slang-nodes/CallOptions.js +++ b/src/slang-nodes/CallOptions.js @@ -1,6 +1,7 @@ import { doc } from 'prettier'; import { printSeparatedList } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; +import { NamedArgument } from './NamedArgument.js'; const { line, softline } = doc.builders; @@ -9,9 +10,25 @@ export class CallOptions extends SlangNode { separators; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items, separators } = ast; + this.items = items.map( + (item) => + new NamedArgument( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + this.separators = separators.map((separator) => separator.text); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print, options) { diff --git a/src/slang-nodes/CallOptionsExpression.js b/src/slang-nodes/CallOptionsExpression.js index 91c07ead0..8d9ef0e8b 100644 --- a/src/slang-nodes/CallOptionsExpression.js +++ b/src/slang-nodes/CallOptionsExpression.js @@ -1,4 +1,6 @@ import { SlangNode } from './SlangNode.js'; +import { Expression } from './Expression.js'; +import { CallOptions } from './CallOptions.js'; export class CallOptionsExpression extends SlangNode { operand; @@ -9,9 +11,30 @@ export class CallOptionsExpression extends SlangNode { closeBrace; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { operand, openBrace, closeBrace } = ast; + this.operand = new Expression( + operand, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.openBrace = openBrace.text; + this.options = new CallOptions( + ast.options, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.closeBrace = closeBrace.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/CatchClause.js b/src/slang-nodes/CatchClause.js index d09c56d6c..9af710e01 100644 --- a/src/slang-nodes/CatchClause.js +++ b/src/slang-nodes/CatchClause.js @@ -1,4 +1,6 @@ import { SlangNode } from './SlangNode.js'; +import { CatchClauseError } from './CatchClauseError.js'; +import { Block } from './Block.js'; export class CatchClause extends SlangNode { catchKeyword; @@ -7,9 +9,31 @@ export class CatchClause extends SlangNode { body; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { catchKeyword, error, body } = ast; + this.catchKeyword = catchKeyword.text; + if (error) { + this.error = new CatchClauseError( + error, + childrenOffsets.shift(), + comments, + parse, + options + ); + } + this.body = new Block( + body, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/CatchClauseError.js b/src/slang-nodes/CatchClauseError.js index 0f68da221..5dbac6d44 100644 --- a/src/slang-nodes/CatchClauseError.js +++ b/src/slang-nodes/CatchClauseError.js @@ -1,5 +1,6 @@ import { doc } from 'prettier'; import { SlangNode } from './SlangNode.js'; +import { ParametersDeclaration } from './ParametersDeclaration.js'; const { group } = doc.builders; @@ -8,9 +9,22 @@ export class CatchClauseError extends SlangNode { parameters; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { name, parameters } = ast; + this.name = name?.text; + this.parameters = new ParametersDeclaration( + parameters, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/CatchClauses.js b/src/slang-nodes/CatchClauses.js index 8f3cdba39..c7924ad2f 100644 --- a/src/slang-nodes/CatchClauses.js +++ b/src/slang-nodes/CatchClauses.js @@ -1,14 +1,30 @@ import { doc } from 'prettier'; import { SlangNode } from './SlangNode.js'; +import { CatchClause } from './CatchClause.js'; const { join } = doc.builders; export class CatchClauses extends SlangNode { items; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items } = ast; + this.items = items.map( + (item) => + new CatchClause( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/ComparisonExpression.js b/src/slang-nodes/ComparisonExpression.js index ad42086f2..dba33f3f5 100644 --- a/src/slang-nodes/ComparisonExpression.js +++ b/src/slang-nodes/ComparisonExpression.js @@ -1,5 +1,6 @@ import { printComparisonOperation } from '../slang-printers/print-comparison-operation.js'; import { SlangNode } from './SlangNode.js'; +import { Expression } from './Expression.js'; export class ComparisonExpression extends SlangNode { leftOperand; @@ -8,9 +9,29 @@ export class ComparisonExpression extends SlangNode { rightOperand; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { leftOperand, operator, rightOperand } = ast; + this.leftOperand = new Expression( + leftOperand, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.operator = operator.text; + this.rightOperand = new Expression( + rightOperand, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print, options) { diff --git a/src/slang-nodes/ConditionalExpression.js b/src/slang-nodes/ConditionalExpression.js index dfabbe743..d02687c03 100644 --- a/src/slang-nodes/ConditionalExpression.js +++ b/src/slang-nodes/ConditionalExpression.js @@ -2,6 +2,7 @@ import { doc } from 'prettier'; import { printSeparatedItem } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; +import { Expression } from './Expression.js'; const { group, hardline, ifBreak, indent, line, softline } = doc.builders; @@ -97,7 +98,36 @@ export class ConditionalExpression extends SlangNode { constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { operand, questionMark, trueExpression, colon, falseExpression } = + ast; + this.operand = new Expression( + operand, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.questionMark = questionMark.text; + this.trueExpression = new Expression( + trueExpression, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.colon = colon.text; + this.falseExpression = new Expression( + falseExpression, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); // TODO: while the behaviour is not stable, it should be behind the // experimentalTernaries flag. diff --git a/src/slang-nodes/ConstantDefinition.js b/src/slang-nodes/ConstantDefinition.js index 55adc3f7b..00ddb8303 100644 --- a/src/slang-nodes/ConstantDefinition.js +++ b/src/slang-nodes/ConstantDefinition.js @@ -1,4 +1,6 @@ import { SlangNode } from './SlangNode.js'; +import { TypeName } from './TypeName.js'; +import { Expression } from './Expression.js'; export class ConstantDefinition extends SlangNode { typeName; @@ -13,9 +15,32 @@ export class ConstantDefinition extends SlangNode { semicolon; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { typeName, constantKeyword, name, equal, value, semicolon } = ast; + this.typeName = new TypeName( + typeName, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.constantKeyword = constantKeyword.text; + this.name = name.text; + this.equal = equal.text; + this.value = new Expression( + value, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.semicolon = semicolon.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } // TODO: implement print diff --git a/src/slang-nodes/ConstructorAttribute.js b/src/slang-nodes/ConstructorAttribute.js index 04394f671..7f98e3477 100644 --- a/src/slang-nodes/ConstructorAttribute.js +++ b/src/slang-nodes/ConstructorAttribute.js @@ -1,11 +1,27 @@ import { SlangNode } from './SlangNode.js'; +import { ModifierInvocation } from './ModifierInvocation.js'; export class ConstructorAttribute extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { variant } = ast; + this.variant = + variant.type === 'Terminal' + ? variant.text + : new ModifierInvocation( + variant, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/ConstructorAttributes.js b/src/slang-nodes/ConstructorAttributes.js index b06d64988..29800f5a4 100644 --- a/src/slang-nodes/ConstructorAttributes.js +++ b/src/slang-nodes/ConstructorAttributes.js @@ -1,15 +1,31 @@ import { doc } from 'prettier'; import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; import { SlangNode } from './SlangNode.js'; +import { ConstructorAttribute } from './ConstructorAttribute.js'; const { line } = doc.builders; export class ConstructorAttributes extends SlangNode { items; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items } = ast; + this.items = items.map( + (item) => + new ConstructorAttribute( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); this.items = this.items.sort(sortFunctionAttributes); } diff --git a/src/slang-nodes/ConstructorDefinition.js b/src/slang-nodes/ConstructorDefinition.js index 400378ce3..bb21763d2 100644 --- a/src/slang-nodes/ConstructorDefinition.js +++ b/src/slang-nodes/ConstructorDefinition.js @@ -1,5 +1,8 @@ import { printFunction } from '../slang-printers/print-function.js'; import { SlangNode } from './SlangNode.js'; +import { ParametersDeclaration } from './ParametersDeclaration.js'; +import { ConstructorAttributes } from './ConstructorAttributes.js'; +import { Block } from './Block.js'; export class ConstructorDefinition extends SlangNode { constructorKeyword; @@ -10,9 +13,36 @@ export class ConstructorDefinition extends SlangNode { body; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { constructorKeyword, parameters, attributes, body } = ast; + this.constructorKeyword = constructorKeyword.text; + this.parameters = new ParametersDeclaration( + parameters, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.attributes = new ConstructorAttributes( + attributes, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.body = new Block( + body, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/ContinueStatement.js b/src/slang-nodes/ContinueStatement.js index f8a54bcb3..ed1c2bb78 100644 --- a/src/slang-nodes/ContinueStatement.js +++ b/src/slang-nodes/ContinueStatement.js @@ -7,7 +7,14 @@ export class ContinueStatement extends SlangNode { constructor(ast, offset, comments, parse) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = () => { + const { continueKeyword, semicolon } = ast; + this.continueKeyword = continueKeyword.text; + this.semicolon = semicolon.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print() { diff --git a/src/slang-nodes/ContractDefinition.js b/src/slang-nodes/ContractDefinition.js index 28f4986cb..32001db57 100644 --- a/src/slang-nodes/ContractDefinition.js +++ b/src/slang-nodes/ContractDefinition.js @@ -2,6 +2,8 @@ import { doc } from 'prettier'; import coerce from 'semver/functions/coerce.js'; import satisfies from 'semver/functions/satisfies.js'; import { SlangNode } from './SlangNode.js'; +import { InheritanceSpecifier } from './InheritanceSpecifier.js'; +import { ContractMembers } from './ContractMembers.js'; const { group, line } = doc.builders; @@ -22,7 +24,41 @@ export class ContractDefinition extends SlangNode { constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { + abstractKeyword, + contractKeyword, + name, + inheritance, + openBrace, + members, + closeBrace + } = ast; + this.abstractKeyword = abstractKeyword?.text; + this.contractKeyword = contractKeyword.text; + this.name = name.text; + if (inheritance) { + this.inheritance = new InheritanceSpecifier( + inheritance, + childrenOffsets.shift(), + comments, + parse, + options + ); + } + this.openBrace = openBrace.text; + this.members = new ContractMembers( + members, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.closeBrace = closeBrace.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); this.cleanModifierInvocationArguments(options); } diff --git a/src/slang-nodes/ContractMember.js b/src/slang-nodes/ContractMember.js index 92b5beac7..0496e5e4e 100644 --- a/src/slang-nodes/ContractMember.js +++ b/src/slang-nodes/ContractMember.js @@ -1,11 +1,52 @@ import { SlangNode } from './SlangNode.js'; +import { UsingDirective } from './UsingDirective.js'; +import { FunctionDefinition } from './FunctionDefinition.js'; +import { ConstructorDefinition } from './ConstructorDefinition.js'; +import { ReceiveFunctionDefinition } from './ReceiveFunctionDefinition.js'; +import { FallbackFunctionDefinition } from './FallbackFunctionDefinition.js'; +import { UnnamedFunctionDefinition } from './UnnamedFunctionDefinition.js'; +import { ModifierDefinition } from './ModifierDefinition.js'; +import { StructDefinition } from './StructDefinition.js'; +import { EnumDefinition } from './EnumDefinition.js'; +import { EventDefinition } from './EventDefinition.js'; +import { StateVariableDefinition } from './StateVariableDefinition.js'; +import { ErrorDefinition } from './ErrorDefinition.js'; +import { UserDefinedValueTypeDefinition } from './UserDefinedValueTypeDefinition.js'; + +const variants = { + UsingDirective, + FunctionDefinition, + ConstructorDefinition, + ReceiveFunctionDefinition, + FallbackFunctionDefinition, + UnnamedFunctionDefinition, + ModifierDefinition, + StructDefinition, + EnumDefinition, + EventDefinition, + StateVariableDefinition, + ErrorDefinition, + UserDefinedValueTypeDefinition +}; export class ContractMember extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { variant } = ast; + this.variant = new variants[variant.cst.kind]( + variant, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/ContractMembers.js b/src/slang-nodes/ContractMembers.js index 53520a7fa..a42948a69 100644 --- a/src/slang-nodes/ContractMembers.js +++ b/src/slang-nodes/ContractMembers.js @@ -3,15 +3,31 @@ import { printSeparatedItem } from '../common/printer-helpers.js'; import { printComments } from '../slang-printers/print-comments.js'; import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; import { SlangNode } from './SlangNode.js'; +import { ContractMember } from './ContractMember.js'; const { hardline } = doc.builders; export class ContractMembers extends SlangNode { items; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items } = ast; + this.items = items.map( + (item) => + new ContractMember( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print, options) { diff --git a/src/slang-nodes/DecimalNumberExpression.js b/src/slang-nodes/DecimalNumberExpression.js index 2038b898e..91003a54b 100644 --- a/src/slang-nodes/DecimalNumberExpression.js +++ b/src/slang-nodes/DecimalNumberExpression.js @@ -1,13 +1,29 @@ import { SlangNode } from './SlangNode.js'; +import { NumberUnit } from './NumberUnit.js'; export class DecimalNumberExpression extends SlangNode { literal; unit; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { literal, unit } = ast; + this.literal = literal.text; + if (unit) { + this.unit = new NumberUnit( + unit, + childrenOffsets.shift(), + comments, + parse, + options + ); + } + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/DoWhileStatement.js b/src/slang-nodes/DoWhileStatement.js index f04479069..76f3be50b 100644 --- a/src/slang-nodes/DoWhileStatement.js +++ b/src/slang-nodes/DoWhileStatement.js @@ -1,6 +1,8 @@ import { doc } from 'prettier'; import { printSeparatedItem } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; +import { Statement } from './Statement.js'; +import { Expression } from './Expression.js'; const { group, indent, line } = doc.builders; @@ -19,9 +21,41 @@ export class DoWhileStatement extends SlangNode { semicolon; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { + doKeyword, + body, + whileKeyword, + openParen, + condition, + closeParen, + semicolon + } = ast; + this.doKeyword = doKeyword.text; + this.body = new Statement( + body, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.whileKeyword = whileKeyword.text; + this.openParen = openParen.text; + this.condition = new Expression( + condition, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.closeParen = closeParen.text; + this.semicolon = semicolon.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/ElementaryType.js b/src/slang-nodes/ElementaryType.js index 1e0e0ab95..f41ddfeb3 100644 --- a/src/slang-nodes/ElementaryType.js +++ b/src/slang-nodes/ElementaryType.js @@ -1,11 +1,26 @@ import { SlangNode } from './SlangNode.js'; +import { AddressType } from './AddressType.js'; export class ElementaryType extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + const fetch = (childrenOffsets) => { + const { variant } = ast; + this.variant = + variant.type === 'Terminal' + ? variant.text + : new AddressType( + variant, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/ElseBranch.js b/src/slang-nodes/ElseBranch.js index 239762ff7..23cb45f0a 100644 --- a/src/slang-nodes/ElseBranch.js +++ b/src/slang-nodes/ElseBranch.js @@ -1,6 +1,7 @@ import { doc } from 'prettier'; -import { SlangNode } from './SlangNode.js'; import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js'; +import { SlangNode } from './SlangNode.js'; +import { Statement } from './Statement.js'; const { group, indent, line } = doc.builders; @@ -11,9 +12,22 @@ export class ElseBranch extends SlangNode { body; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { elseKeyword, body } = ast; + this.elseKeyword = elseKeyword.text; + this.body = new Statement( + body, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/EmitStatement.js b/src/slang-nodes/EmitStatement.js index bd97bbbb2..865193888 100644 --- a/src/slang-nodes/EmitStatement.js +++ b/src/slang-nodes/EmitStatement.js @@ -1,4 +1,6 @@ import { SlangNode } from './SlangNode.js'; +import { IdentifierPath } from './IdentifierPath.js'; +import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; export class EmitStatement extends SlangNode { emitKeyword; @@ -9,9 +11,30 @@ export class EmitStatement extends SlangNode { semicolon; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { emitKeyword, event, semicolon } = ast; + this.emitKeyword = emitKeyword.text; + this.event = new IdentifierPath( + event, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.arguments = new ArgumentsDeclaration( + ast.arguments, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.semicolon = semicolon.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/EnumDefinition.js b/src/slang-nodes/EnumDefinition.js index 355c9aa95..f277fc277 100644 --- a/src/slang-nodes/EnumDefinition.js +++ b/src/slang-nodes/EnumDefinition.js @@ -1,4 +1,5 @@ import { SlangNode } from './SlangNode.js'; +import { EnumMembers } from './EnumMembers.js'; export class EnumDefinition extends SlangNode { enumKeyword; @@ -11,9 +12,25 @@ export class EnumDefinition extends SlangNode { closeBrace; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { enumKeyword, name, openBrace, members, closeBrace } = ast; + this.enumKeyword = enumKeyword.text; + this.name = name.text; + this.openBrace = openBrace.text; + this.members = new EnumMembers( + members, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.closeBrace = closeBrace.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/EnumMembers.js b/src/slang-nodes/EnumMembers.js index eaa3c71e6..c1704eea3 100644 --- a/src/slang-nodes/EnumMembers.js +++ b/src/slang-nodes/EnumMembers.js @@ -11,7 +11,14 @@ export class EnumMembers extends SlangNode { constructor(ast, offset, comments, parse) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = () => { + const { items, separators } = ast; + this.items = items.map((item) => item.text); + this.separators = separators.map((separator) => separator.text); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print() { diff --git a/src/slang-nodes/EqualityExpression.js b/src/slang-nodes/EqualityExpression.js index e695b93ed..a29c40213 100644 --- a/src/slang-nodes/EqualityExpression.js +++ b/src/slang-nodes/EqualityExpression.js @@ -1,5 +1,6 @@ import { printComparisonOperation } from '../slang-printers/print-comparison-operation.js'; import { SlangNode } from './SlangNode.js'; +import { Expression } from './Expression.js'; export class EqualityExpression extends SlangNode { leftOperand; @@ -8,9 +9,29 @@ export class EqualityExpression extends SlangNode { rightOperand; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { leftOperand, operator, rightOperand } = ast; + this.leftOperand = new Expression( + leftOperand, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.operator = operator.text; + this.rightOperand = new Expression( + rightOperand, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print, options) { diff --git a/src/slang-nodes/ErrorDefinition.js b/src/slang-nodes/ErrorDefinition.js index 768b164b8..ae8c34d0a 100644 --- a/src/slang-nodes/ErrorDefinition.js +++ b/src/slang-nodes/ErrorDefinition.js @@ -1,4 +1,5 @@ import { SlangNode } from './SlangNode.js'; +import { ErrorParametersDeclaration } from './ErrorParametersDeclaration.js'; export class ErrorDefinition extends SlangNode { errorKeyword; @@ -9,9 +10,24 @@ export class ErrorDefinition extends SlangNode { semicolon; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { errorKeyword, name, members, semicolon } = ast; + this.errorKeyword = errorKeyword.text; + this.name = name.text; + this.members = new ErrorParametersDeclaration( + members, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.semicolon = semicolon.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/ErrorParameter.js b/src/slang-nodes/ErrorParameter.js index 850fe7815..e5697f672 100644 --- a/src/slang-nodes/ErrorParameter.js +++ b/src/slang-nodes/ErrorParameter.js @@ -1,13 +1,27 @@ import { SlangNode } from './SlangNode.js'; +import { TypeName } from './TypeName.js'; export class ErrorParameter extends SlangNode { typeName; name; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { typeName, name } = ast; + this.typeName = new TypeName( + typeName, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.name = name?.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/ErrorParameters.js b/src/slang-nodes/ErrorParameters.js index de1939126..bea65d1c3 100644 --- a/src/slang-nodes/ErrorParameters.js +++ b/src/slang-nodes/ErrorParameters.js @@ -1,14 +1,31 @@ import { printSeparatedList } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; +import { ErrorParameter } from './ErrorParameter.js'; export class ErrorParameters extends SlangNode { items; separators; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items, separators } = ast; + this.items = items.map( + (item) => + new ErrorParameter( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + this.separators = separators.map((separator) => separator.text); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/ErrorParametersDeclaration.js b/src/slang-nodes/ErrorParametersDeclaration.js index 178287cb2..51e1c2f90 100644 --- a/src/slang-nodes/ErrorParametersDeclaration.js +++ b/src/slang-nodes/ErrorParametersDeclaration.js @@ -1,4 +1,5 @@ import { SlangNode } from './SlangNode.js'; +import { ErrorParameters } from './ErrorParameters.js'; export class ErrorParametersDeclaration extends SlangNode { openParen; @@ -7,9 +8,23 @@ export class ErrorParametersDeclaration extends SlangNode { closeParen; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { openParen, parameters, closeParen } = ast; + this.openParen = openParen.text; + this.parameters = new ErrorParameters( + parameters, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.closeParen = closeParen.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/EventDefinition.js b/src/slang-nodes/EventDefinition.js index 0ab1c7fc2..628ab3fd1 100644 --- a/src/slang-nodes/EventDefinition.js +++ b/src/slang-nodes/EventDefinition.js @@ -1,4 +1,5 @@ import { SlangNode } from './SlangNode.js'; +import { EventParametersDeclaration } from './EventParametersDeclaration.js'; export class EventDefinition extends SlangNode { eventKeyword; @@ -11,9 +12,26 @@ export class EventDefinition extends SlangNode { semicolon; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { eventKeyword, name, parameters, anonymousKeyword, semicolon } = + ast; + this.eventKeyword = eventKeyword.text; + this.name = name.text; + this.parameters = new EventParametersDeclaration( + parameters, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.anonymousKeyword = anonymousKeyword?.text; + this.semicolon = semicolon.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/EventParameter.js b/src/slang-nodes/EventParameter.js index 5324c704b..3144bf523 100644 --- a/src/slang-nodes/EventParameter.js +++ b/src/slang-nodes/EventParameter.js @@ -1,4 +1,5 @@ import { SlangNode } from './SlangNode.js'; +import { TypeName } from './TypeName.js'; export class EventParameter extends SlangNode { typeName; @@ -7,9 +8,23 @@ export class EventParameter extends SlangNode { name; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { typeName, indexedKeyword, name } = ast; + this.typeName = new TypeName( + typeName, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.indexedKeyword = indexedKeyword?.text; + this.name = name?.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/EventParameters.js b/src/slang-nodes/EventParameters.js index 60ab7a430..02e66fbd6 100644 --- a/src/slang-nodes/EventParameters.js +++ b/src/slang-nodes/EventParameters.js @@ -1,14 +1,31 @@ import { printSeparatedList } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; +import { EventParameter } from './EventParameter.js'; export class EventParameters extends SlangNode { items; separators; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items, separators } = ast; + this.items = items.map( + (item) => + new EventParameter( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + this.separators = separators.map((separator) => separator.text); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/EventParametersDeclaration.js b/src/slang-nodes/EventParametersDeclaration.js index abab19091..c4ff8e860 100644 --- a/src/slang-nodes/EventParametersDeclaration.js +++ b/src/slang-nodes/EventParametersDeclaration.js @@ -1,4 +1,5 @@ import { SlangNode } from './SlangNode.js'; +import { EventParameters } from './EventParameters.js'; export class EventParametersDeclaration extends SlangNode { openParen; @@ -7,9 +8,23 @@ export class EventParametersDeclaration extends SlangNode { closeParen; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { openParen, parameters, closeParen } = ast; + this.openParen = openParen.text; + this.parameters = new EventParameters( + parameters, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.closeParen = closeParen.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/ExperimentalFeature.js b/src/slang-nodes/ExperimentalFeature.js index 9c9b93880..31540f354 100644 --- a/src/slang-nodes/ExperimentalFeature.js +++ b/src/slang-nodes/ExperimentalFeature.js @@ -1,11 +1,27 @@ import { SlangNode } from './SlangNode.js'; +import { StringLiteral } from './StringLiteral.js'; export class ExperimentalFeature extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { variant } = ast; + this.variant = + variant.type === 'Terminal' + ? variant.text + : new StringLiteral( + variant, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/ExperimentalPragma.js b/src/slang-nodes/ExperimentalPragma.js index 269e6b9eb..1b88c52e3 100644 --- a/src/slang-nodes/ExperimentalPragma.js +++ b/src/slang-nodes/ExperimentalPragma.js @@ -1,13 +1,27 @@ import { SlangNode } from './SlangNode.js'; +import { ExperimentalFeature } from './ExperimentalFeature.js'; export class ExperimentalPragma extends SlangNode { experimentalKeyword; feature; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { experimentalKeyword, feature } = ast; + this.experimentalKeyword = experimentalKeyword.text; + this.feature = new ExperimentalFeature( + feature, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/ExponentiationExpression.js b/src/slang-nodes/ExponentiationExpression.js index 800c3098e..ddf5b99ef 100644 --- a/src/slang-nodes/ExponentiationExpression.js +++ b/src/slang-nodes/ExponentiationExpression.js @@ -28,7 +28,26 @@ export class ExponentiationExpression extends SlangNode { constructor(ast, offset, comments, parse, options) { super(); if (offset) { - this.initialize(ast, offset, comments, parse); + const fetch = (childrenOffsets) => { + const { leftOperand, operator, rightOperand } = ast; + this.leftOperand = new Expression( + leftOperand, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.operator = operator.text; + this.rightOperand = new Expression( + rightOperand, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); const compiler = coerce(options.compiler); if (compiler) { diff --git a/src/slang-nodes/Expression.js b/src/slang-nodes/Expression.js index 72e79365f..16cd9599d 100644 --- a/src/slang-nodes/Expression.js +++ b/src/slang-nodes/Expression.js @@ -1,12 +1,83 @@ import { SlangNode } from './SlangNode.js'; +import { AssignmentExpression } from './AssignmentExpression.js'; +import { ConditionalExpression } from './ConditionalExpression.js'; +import { OrExpression } from './OrExpression.js'; +import { AndExpression } from './AndExpression.js'; +import { EqualityExpression } from './EqualityExpression.js'; +import { ComparisonExpression } from './ComparisonExpression.js'; +import { BitwiseOrExpression } from './BitwiseOrExpression.js'; +import { BitwiseXorExpression } from './BitwiseXorExpression.js'; +import { BitwiseAndExpression } from './BitwiseAndExpression.js'; +import { ShiftExpression } from './ShiftExpression.js'; +import { AdditiveExpression } from './AdditiveExpression.js'; +import { MultiplicativeExpression } from './MultiplicativeExpression.js'; +import { ExponentiationExpression } from './ExponentiationExpression.js'; +import { PostfixExpression } from './PostfixExpression.js'; +import { PrefixExpression } from './PrefixExpression.js'; +import { FunctionCallExpression } from './FunctionCallExpression.js'; +import { CallOptionsExpression } from './CallOptionsExpression.js'; +import { MemberAccessExpression } from './MemberAccessExpression.js'; +import { IndexAccessExpression } from './IndexAccessExpression.js'; +import { NewExpression } from './NewExpression.js'; +import { TupleExpression } from './TupleExpression.js'; +import { TypeExpression } from './TypeExpression.js'; +import { ArrayExpression } from './ArrayExpression.js'; +import { HexNumberExpression } from './HexNumberExpression.js'; +import { DecimalNumberExpression } from './DecimalNumberExpression.js'; +import { StringExpression } from './StringExpression.js'; +import { ElementaryType } from './ElementaryType.js'; + +const variants = { + AssignmentExpression, + ConditionalExpression, + OrExpression, + AndExpression, + EqualityExpression, + ComparisonExpression, + BitwiseOrExpression, + BitwiseXorExpression, + BitwiseAndExpression, + ShiftExpression, + AdditiveExpression, + MultiplicativeExpression, + ExponentiationExpression, + PostfixExpression, + PrefixExpression, + FunctionCallExpression, + CallOptionsExpression, + MemberAccessExpression, + IndexAccessExpression, + NewExpression, + TupleExpression, + TypeExpression, + ArrayExpression, + HexNumberExpression, + DecimalNumberExpression, + StringExpression, + ElementaryType +}; export class Expression extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); if (offset) { - this.initialize(ast, offset, comments, parse); + const fetch = (childrenOffsets) => { + const { variant } = ast; + this.variant = + variant.type === 'Terminal' + ? variant.text + : new variants[variant.cst.kind]( + variant, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/ExpressionStatement.js b/src/slang-nodes/ExpressionStatement.js index 0d409cde4..1f8d9a10e 100644 --- a/src/slang-nodes/ExpressionStatement.js +++ b/src/slang-nodes/ExpressionStatement.js @@ -1,13 +1,27 @@ import { SlangNode } from './SlangNode.js'; +import { Expression } from './Expression.js'; export class ExpressionStatement extends SlangNode { expression; semicolon; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { expression, semicolon } = ast; + this.expression = new Expression( + expression, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.semicolon = semicolon.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/FallbackFunctionAttribute.js b/src/slang-nodes/FallbackFunctionAttribute.js index f0c8cb89f..7231fdd73 100644 --- a/src/slang-nodes/FallbackFunctionAttribute.js +++ b/src/slang-nodes/FallbackFunctionAttribute.js @@ -1,11 +1,30 @@ import { SlangNode } from './SlangNode.js'; +import { ModifierInvocation } from './ModifierInvocation.js'; +import { OverrideSpecifier } from './OverrideSpecifier.js'; + +const variants = { ModifierInvocation, OverrideSpecifier }; export class FallbackFunctionAttribute extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { variant } = ast; + this.variant = + variant.type === 'Terminal' + ? variant.text + : new variants[variant.cst.kind]( + variant, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/FallbackFunctionAttributes.js b/src/slang-nodes/FallbackFunctionAttributes.js index 9b6d623b3..a664939a4 100644 --- a/src/slang-nodes/FallbackFunctionAttributes.js +++ b/src/slang-nodes/FallbackFunctionAttributes.js @@ -1,15 +1,31 @@ import { doc } from 'prettier'; import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; import { SlangNode } from './SlangNode.js'; +import { FallbackFunctionAttribute } from './FallbackFunctionAttribute.js'; const { line } = doc.builders; export class FallbackFunctionAttributes extends SlangNode { items; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items } = ast; + this.items = items.map( + (item) => + new FallbackFunctionAttribute( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); this.items = this.items.sort(sortFunctionAttributes); } diff --git a/src/slang-nodes/FallbackFunctionDefinition.js b/src/slang-nodes/FallbackFunctionDefinition.js index d21245791..02bc644c5 100644 --- a/src/slang-nodes/FallbackFunctionDefinition.js +++ b/src/slang-nodes/FallbackFunctionDefinition.js @@ -1,5 +1,9 @@ import { printFunction } from '../slang-printers/print-function.js'; import { SlangNode } from './SlangNode.js'; +import { ParametersDeclaration } from './ParametersDeclaration.js'; +import { FallbackFunctionAttributes } from './FallbackFunctionAttributes.js'; +import { ReturnsDeclaration } from './ReturnsDeclaration.js'; +import { FunctionBody } from './FunctionBody.js'; export class FallbackFunctionDefinition extends SlangNode { fallbackKeyword; @@ -12,9 +16,45 @@ export class FallbackFunctionDefinition extends SlangNode { body; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { fallbackKeyword, parameters, attributes, returns, body } = ast; + this.fallbackKeyword = fallbackKeyword.text; + this.parameters = new ParametersDeclaration( + parameters, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.attributes = new FallbackFunctionAttributes( + attributes, + childrenOffsets.shift(), + comments, + parse, + options + ); + if (returns) { + this.returns = new ReturnsDeclaration( + returns, + childrenOffsets.shift(), + comments, + parse, + options + ); + } + this.body = new FunctionBody( + body, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); this.cleanModifierInvocationArguments(); } diff --git a/src/slang-nodes/ForStatement.js b/src/slang-nodes/ForStatement.js index 98eb2ab51..515057092 100644 --- a/src/slang-nodes/ForStatement.js +++ b/src/slang-nodes/ForStatement.js @@ -1,6 +1,10 @@ import { doc } from 'prettier'; import { printSeparatedList } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; +import { ForStatementInitialization } from './ForStatementInitialization.js'; +import { ForStatementCondition } from './ForStatementCondition.js'; +import { Expression } from './Expression.js'; +import { Statement } from './Statement.js'; const { group, indent, line } = doc.builders; @@ -19,9 +23,55 @@ export class ForStatement extends SlangNode { body; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { + forKeyword, + openParen, + initialization, + condition, + iterator, + closeParen, + body + } = ast; + this.forKeyword = forKeyword.text; + this.openParen = openParen.text; + this.initialization = new ForStatementInitialization( + initialization, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.condition = new ForStatementCondition( + condition, + childrenOffsets.shift(), + comments, + parse, + options + ); + if (iterator) { + this.iterator = new Expression( + iterator, + childrenOffsets.shift(), + comments, + parse, + options + ); + } + this.closeParen = closeParen.text; + this.body = new Statement( + body, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/ForStatementCondition.js b/src/slang-nodes/ForStatementCondition.js index a5201b6d9..34f2c224f 100644 --- a/src/slang-nodes/ForStatementCondition.js +++ b/src/slang-nodes/ForStatementCondition.js @@ -1,11 +1,27 @@ import { SlangNode } from './SlangNode.js'; +import { ExpressionStatement } from './ExpressionStatement.js'; export class ForStatementCondition extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { variant } = ast; + this.variant = + variant.type === 'Terminal' + ? variant.text + : new ExpressionStatement( + variant, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/ForStatementInitialization.js b/src/slang-nodes/ForStatementInitialization.js index 6c1754874..fa4197b33 100644 --- a/src/slang-nodes/ForStatementInitialization.js +++ b/src/slang-nodes/ForStatementInitialization.js @@ -1,11 +1,35 @@ import { SlangNode } from './SlangNode.js'; +import { ExpressionStatement } from './ExpressionStatement.js'; +import { VariableDeclarationStatement } from './VariableDeclarationStatement.js'; +import { TupleDeconstructionStatement } from './TupleDeconstructionStatement.js'; + +const variants = { + ExpressionStatement, + VariableDeclarationStatement, + TupleDeconstructionStatement +}; export class ForStatementInitialization extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { variant } = ast; + this.variant = + variant.type === 'Terminal' + ? variant.text + : new variants[variant.cst.kind]( + variant, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/FunctionAttribute.js b/src/slang-nodes/FunctionAttribute.js index b972d5e48..0b0ac2db2 100644 --- a/src/slang-nodes/FunctionAttribute.js +++ b/src/slang-nodes/FunctionAttribute.js @@ -1,11 +1,30 @@ import { SlangNode } from './SlangNode.js'; +import { ModifierInvocation } from './ModifierInvocation.js'; +import { OverrideSpecifier } from './OverrideSpecifier.js'; + +const variants = { ModifierInvocation, OverrideSpecifier }; export class FunctionAttribute extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { variant } = ast; + this.variant = + variant.type === 'Terminal' + ? variant.text + : new variants[variant.cst.kind]( + variant, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/FunctionAttributes.js b/src/slang-nodes/FunctionAttributes.js index 2d17cdf3b..8ea3f114c 100644 --- a/src/slang-nodes/FunctionAttributes.js +++ b/src/slang-nodes/FunctionAttributes.js @@ -1,15 +1,31 @@ import { doc } from 'prettier'; import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; import { SlangNode } from './SlangNode.js'; +import { FunctionAttribute } from './FunctionAttribute.js'; const { line } = doc.builders; export class FunctionAttributes extends SlangNode { items; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items } = ast; + this.items = items.map( + (item) => + new FunctionAttribute( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); this.items = this.items.sort(sortFunctionAttributes); } diff --git a/src/slang-nodes/FunctionBody.js b/src/slang-nodes/FunctionBody.js index 6efb4c18d..8f038a5b9 100644 --- a/src/slang-nodes/FunctionBody.js +++ b/src/slang-nodes/FunctionBody.js @@ -1,11 +1,27 @@ import { SlangNode } from './SlangNode.js'; +import { Block } from './Block.js'; export class FunctionBody extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { variant } = ast; + this.variant = + variant.type === 'Terminal' + ? variant.text + : new Block( + variant, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/FunctionCallExpression.js b/src/slang-nodes/FunctionCallExpression.js index ae5305a48..9956e0d29 100644 --- a/src/slang-nodes/FunctionCallExpression.js +++ b/src/slang-nodes/FunctionCallExpression.js @@ -1,6 +1,8 @@ import { doc } from 'prettier'; import { isLabel } from '../common/util.js'; import { SlangNode } from './SlangNode.js'; +import { Expression } from './Expression.js'; +import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; const { group, indentIfBreak, label } = doc.builders; @@ -9,9 +11,28 @@ export class FunctionCallExpression extends SlangNode { arguments; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { operand } = ast; + this.operand = new Expression( + operand, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.arguments = new ArgumentsDeclaration( + ast.arguments, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/FunctionDefinition.js b/src/slang-nodes/FunctionDefinition.js index 0a6aea103..cf384a610 100644 --- a/src/slang-nodes/FunctionDefinition.js +++ b/src/slang-nodes/FunctionDefinition.js @@ -2,6 +2,11 @@ import coerce from 'semver/functions/coerce.js'; import satisfies from 'semver/functions/satisfies.js'; import { printFunction } from '../slang-printers/print-function.js'; import { SlangNode } from './SlangNode.js'; +import { FunctionName } from './FunctionName.js'; +import { ParametersDeclaration } from './ParametersDeclaration.js'; +import { FunctionAttributes } from './FunctionAttributes.js'; +import { ReturnsDeclaration } from './ReturnsDeclaration.js'; +import { FunctionBody } from './FunctionBody.js'; export class FunctionDefinition extends SlangNode { functionKeyword; @@ -18,7 +23,51 @@ export class FunctionDefinition extends SlangNode { constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { functionKeyword, name, parameters, attributes, returns, body } = + ast; + this.functionKeyword = functionKeyword.text; + this.name = new FunctionName( + name, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.parameters = new ParametersDeclaration( + parameters, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.attributes = new FunctionAttributes( + attributes, + childrenOffsets.shift(), + comments, + parse, + options + ); + if (returns) { + this.returns = new ReturnsDeclaration( + returns, + childrenOffsets.shift(), + comments, + parse, + options + ); + } + this.body = new FunctionBody( + body, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); // Older versions of Solidity defined a constructor as a function having // the same name as the contract. diff --git a/src/slang-nodes/FunctionName.js b/src/slang-nodes/FunctionName.js index 9bc0fea02..497240f59 100644 --- a/src/slang-nodes/FunctionName.js +++ b/src/slang-nodes/FunctionName.js @@ -5,7 +5,13 @@ export class FunctionName extends SlangNode { constructor(ast, offset, comments, parse) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = () => { + const { variant } = ast; + this.variant = variant.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print() { diff --git a/src/slang-nodes/FunctionType.js b/src/slang-nodes/FunctionType.js index f49539ea2..ced112e0c 100644 --- a/src/slang-nodes/FunctionType.js +++ b/src/slang-nodes/FunctionType.js @@ -1,5 +1,8 @@ import { printFunction } from '../slang-printers/print-function.js'; import { SlangNode } from './SlangNode.js'; +import { ParametersDeclaration } from './ParametersDeclaration.js'; +import { FunctionTypeAttributes } from './FunctionTypeAttributes.js'; +import { ReturnsDeclaration } from './ReturnsDeclaration.js'; export class FunctionType extends SlangNode { functionKeyword; @@ -10,9 +13,38 @@ export class FunctionType extends SlangNode { returns; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { functionKeyword, parameters, attributes, returns } = ast; + this.functionKeyword = functionKeyword.text; + this.parameters = new ParametersDeclaration( + parameters, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.attributes = new FunctionTypeAttributes( + attributes, + childrenOffsets.shift(), + comments, + parse, + options + ); + if (returns) { + this.returns = new ReturnsDeclaration( + returns, + childrenOffsets.shift(), + comments, + parse, + options + ); + } + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/FunctionTypeAttribute.js b/src/slang-nodes/FunctionTypeAttribute.js index 6865ea7f7..5846f025e 100644 --- a/src/slang-nodes/FunctionTypeAttribute.js +++ b/src/slang-nodes/FunctionTypeAttribute.js @@ -5,7 +5,13 @@ export class FunctionTypeAttribute extends SlangNode { constructor(ast, offset, comments, parse) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = () => { + const { variant } = ast; + this.variant = variant.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print() { diff --git a/src/slang-nodes/FunctionTypeAttributes.js b/src/slang-nodes/FunctionTypeAttributes.js index 926525d48..1e9009ee1 100644 --- a/src/slang-nodes/FunctionTypeAttributes.js +++ b/src/slang-nodes/FunctionTypeAttributes.js @@ -1,15 +1,31 @@ import { doc } from 'prettier'; import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; import { SlangNode } from './SlangNode.js'; +import { FunctionTypeAttribute } from './FunctionTypeAttribute.js'; const { line } = doc.builders; export class FunctionTypeAttributes extends SlangNode { items; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items } = ast; + this.items = items.map( + (item) => + new FunctionTypeAttribute( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); this.items = this.items.sort(sortFunctionAttributes); } diff --git a/src/slang-nodes/HexNumberExpression.js b/src/slang-nodes/HexNumberExpression.js index 9063eb044..ed6d79cff 100644 --- a/src/slang-nodes/HexNumberExpression.js +++ b/src/slang-nodes/HexNumberExpression.js @@ -1,13 +1,29 @@ import { SlangNode } from './SlangNode.js'; +import { NumberUnit } from './NumberUnit.js'; export class HexNumberExpression extends SlangNode { literal; unit; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { literal, unit } = ast; + this.literal = literal.text; + if (unit) { + this.unit = new NumberUnit( + unit, + childrenOffsets.shift(), + comments, + parse, + options + ); + } + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/HexStringLiteral.js b/src/slang-nodes/HexStringLiteral.js index 4b58a3c43..ec063c4b3 100644 --- a/src/slang-nodes/HexStringLiteral.js +++ b/src/slang-nodes/HexStringLiteral.js @@ -6,7 +6,13 @@ export class HexStringLiteral extends SlangNode { constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = () => { + const { variant } = ast; + this.variant = variant.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); this.variant = `hex${printString(this.variant.slice(4, -1), options)}`; } diff --git a/src/slang-nodes/HexStringLiterals.js b/src/slang-nodes/HexStringLiterals.js index 1c0301138..b470ec12a 100644 --- a/src/slang-nodes/HexStringLiterals.js +++ b/src/slang-nodes/HexStringLiterals.js @@ -1,14 +1,30 @@ import { doc } from 'prettier'; import { SlangNode } from './SlangNode.js'; +import { HexStringLiteral } from './HexStringLiteral.js'; const { join, hardline } = doc.builders; export class HexStringLiterals extends SlangNode { items; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items } = ast; + this.items = items.map( + (item) => + new HexStringLiteral( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/IdentifierPath.js b/src/slang-nodes/IdentifierPath.js index a77bbfac7..cdc69e5ac 100644 --- a/src/slang-nodes/IdentifierPath.js +++ b/src/slang-nodes/IdentifierPath.js @@ -7,7 +7,14 @@ export class IdentifierPath extends SlangNode { constructor(ast, offset, comments, parse) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = () => { + const { items, separators } = ast; + this.items = items.map((item) => item.text); + this.separators = separators.map((separator) => separator.text); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print() { diff --git a/src/slang-nodes/IfStatement.js b/src/slang-nodes/IfStatement.js index 1e93f53ca..0f41ac5c9 100644 --- a/src/slang-nodes/IfStatement.js +++ b/src/slang-nodes/IfStatement.js @@ -1,6 +1,9 @@ import { doc } from 'prettier'; import { printSeparatedItem } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; +import { Expression } from './Expression.js'; +import { Statement } from './Statement.js'; +import { ElseBranch } from './ElseBranch.js'; const { group, hardline, indent, line } = doc.builders; @@ -17,9 +20,41 @@ export class IfStatement extends SlangNode { elseBranch; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { ifKeyword, openParen, condition, closeParen, body, elseBranch } = + ast; + this.ifKeyword = ifKeyword.text; + this.openParen = openParen.text; + this.condition = new Expression( + condition, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.closeParen = closeParen.text; + this.body = new Statement( + body, + childrenOffsets.shift(), + comments, + parse, + options + ); + if (elseBranch) { + this.elseBranch = new ElseBranch( + elseBranch, + childrenOffsets.shift(), + comments, + parse, + options + ); + } + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/ImportAlias.js b/src/slang-nodes/ImportAlias.js index 883a33c48..51e36222d 100644 --- a/src/slang-nodes/ImportAlias.js +++ b/src/slang-nodes/ImportAlias.js @@ -7,7 +7,14 @@ export class ImportAlias extends SlangNode { constructor(ast, offset, comments, parse) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = () => { + const { asKeyword, identifier } = ast; + this.asKeyword = asKeyword.text; + this.identifier = identifier.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print() { diff --git a/src/slang-nodes/ImportClause.js b/src/slang-nodes/ImportClause.js index 50d72b8a6..1fc60f3af 100644 --- a/src/slang-nodes/ImportClause.js +++ b/src/slang-nodes/ImportClause.js @@ -1,11 +1,28 @@ import { SlangNode } from './SlangNode.js'; +import { PathImport } from './PathImport.js'; +import { NamedImport } from './NamedImport.js'; +import { ImportDeconstruction } from './ImportDeconstruction.js'; + +const variants = { PathImport, NamedImport, ImportDeconstruction }; export class ImportClause extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { variant } = ast; + this.variant = new variants[variant.cst.kind]( + variant, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/ImportDeconstruction.js b/src/slang-nodes/ImportDeconstruction.js index 72b3fced7..4ceefac91 100644 --- a/src/slang-nodes/ImportDeconstruction.js +++ b/src/slang-nodes/ImportDeconstruction.js @@ -1,4 +1,6 @@ import { SlangNode } from './SlangNode.js'; +import { ImportDeconstructionSymbols } from './ImportDeconstructionSymbols.js'; +import { StringLiteral } from './StringLiteral.js'; export class ImportDeconstruction extends SlangNode { openBrace; @@ -11,9 +13,31 @@ export class ImportDeconstruction extends SlangNode { path; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { openBrace, symbols, closeBrace, fromKeyword, path } = ast; + this.openBrace = openBrace.text; + this.symbols = new ImportDeconstructionSymbols( + symbols, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.closeBrace = closeBrace.text; + this.fromKeyword = fromKeyword.text; + this.path = new StringLiteral( + path, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/ImportDeconstructionSymbol.js b/src/slang-nodes/ImportDeconstructionSymbol.js index 99b8308df..73b92f017 100644 --- a/src/slang-nodes/ImportDeconstructionSymbol.js +++ b/src/slang-nodes/ImportDeconstructionSymbol.js @@ -1,13 +1,30 @@ import { SlangNode } from './SlangNode.js'; +import { ImportAlias } from './ImportAlias.js'; export class ImportDeconstructionSymbol extends SlangNode { name; alias; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { name, alias } = ast; + this.name = name.text; + this.alias = + typeof alias === 'undefined' + ? undefined + : new ImportAlias( + alias, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/ImportDeconstructionSymbols.js b/src/slang-nodes/ImportDeconstructionSymbols.js index 5081581c5..ec4e9b518 100644 --- a/src/slang-nodes/ImportDeconstructionSymbols.js +++ b/src/slang-nodes/ImportDeconstructionSymbols.js @@ -3,6 +3,7 @@ import coerce from 'semver/functions/coerce.js'; import satisfies from 'semver/functions/satisfies.js'; import { printSeparatedList } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; +import { ImportDeconstructionSymbol } from './ImportDeconstructionSymbol.js'; const { line, softline } = doc.builders; @@ -11,9 +12,25 @@ export class ImportDeconstructionSymbols extends SlangNode { separators; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items, separators } = ast; + this.items = items.map( + (item) => + new ImportDeconstructionSymbol( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + this.separators = separators.map((separator) => separator.text); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print, options) { diff --git a/src/slang-nodes/ImportDirective.js b/src/slang-nodes/ImportDirective.js index 5f4de1cd9..376020ea8 100644 --- a/src/slang-nodes/ImportDirective.js +++ b/src/slang-nodes/ImportDirective.js @@ -1,4 +1,5 @@ import { SlangNode } from './SlangNode.js'; +import { ImportClause } from './ImportClause.js'; export class ImportDirective extends SlangNode { importKeyword; @@ -7,9 +8,23 @@ export class ImportDirective extends SlangNode { semicolon; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { importKeyword, clause, semicolon } = ast; + this.importKeyword = importKeyword.text; + this.clause = new ImportClause( + clause, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.semicolon = semicolon.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/IndexAccessEnd.js b/src/slang-nodes/IndexAccessEnd.js index 8af57c2e2..5b66ea461 100644 --- a/src/slang-nodes/IndexAccessEnd.js +++ b/src/slang-nodes/IndexAccessEnd.js @@ -1,13 +1,29 @@ import { SlangNode } from './SlangNode.js'; +import { Expression } from './Expression.js'; export class IndexAccessEnd extends SlangNode { colon; end; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { colon, end } = ast; + this.colon = colon.text; + if (end) { + this.end = new Expression( + end, + childrenOffsets.shift(), + comments, + parse, + options + ); + } + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/IndexAccessExpression.js b/src/slang-nodes/IndexAccessExpression.js index 8ef80852c..3442725fd 100644 --- a/src/slang-nodes/IndexAccessExpression.js +++ b/src/slang-nodes/IndexAccessExpression.js @@ -1,6 +1,8 @@ import { doc } from 'prettier'; import { isLabel } from '../common/util.js'; import { SlangNode } from './SlangNode.js'; +import { Expression } from './Expression.js'; +import { IndexAccessEnd } from './IndexAccessEnd.js'; const { group, indent, indentIfBreak, label, softline } = doc.builders; @@ -15,9 +17,41 @@ export class IndexAccessExpression extends SlangNode { closeBracket; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { operand, openBracket, start, end, closeBracket } = ast; + this.operand = new Expression( + operand, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.openBracket = openBracket.text; + if (start) { + this.start = new Expression( + start, + childrenOffsets.shift(), + comments, + parse, + options + ); + } + if (end) { + this.end = new IndexAccessEnd( + end, + childrenOffsets.shift(), + comments, + parse, + options + ); + } + this.closeBracket = closeBracket.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/InheritanceSpecifier.js b/src/slang-nodes/InheritanceSpecifier.js index f1ed8873b..8f3383646 100644 --- a/src/slang-nodes/InheritanceSpecifier.js +++ b/src/slang-nodes/InheritanceSpecifier.js @@ -1,13 +1,27 @@ import { SlangNode } from './SlangNode.js'; +import { InheritanceTypes } from './InheritanceTypes.js'; export class InheritanceSpecifier extends SlangNode { isKeyword; types; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { isKeyword, types } = ast; + this.isKeyword = isKeyword?.text; + this.types = new InheritanceTypes( + types, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/InheritanceType.js b/src/slang-nodes/InheritanceType.js index 437265306..ab67b97a0 100644 --- a/src/slang-nodes/InheritanceType.js +++ b/src/slang-nodes/InheritanceType.js @@ -1,13 +1,36 @@ import { SlangNode } from './SlangNode.js'; +import { IdentifierPath } from './IdentifierPath.js'; +import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; export class InheritanceType extends SlangNode { typeName; arguments; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { typeName } = ast; + this.typeName = new IdentifierPath( + typeName, + childrenOffsets.shift(), + comments, + parse, + options + ); + if (ast.arguments) { + this.arguments = new ArgumentsDeclaration( + ast.arguments, + childrenOffsets.shift(), + comments, + parse, + options + ); + } + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/InheritanceTypes.js b/src/slang-nodes/InheritanceTypes.js index 7a0d15c7b..dd9fb97bd 100644 --- a/src/slang-nodes/InheritanceTypes.js +++ b/src/slang-nodes/InheritanceTypes.js @@ -1,6 +1,7 @@ import { doc } from 'prettier'; import { printSeparatedList } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; +import { InheritanceType } from './InheritanceType.js'; const { line } = doc.builders; @@ -9,9 +10,25 @@ export class InheritanceTypes extends SlangNode { separators; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items, separators } = ast; + this.items = items.map( + (item) => + new InheritanceType( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + this.separators = separators.map((separator) => separator.text); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/InterfaceDefinition.js b/src/slang-nodes/InterfaceDefinition.js index f6f7610ea..7cec2f838 100644 --- a/src/slang-nodes/InterfaceDefinition.js +++ b/src/slang-nodes/InterfaceDefinition.js @@ -1,5 +1,7 @@ import { doc } from 'prettier'; import { SlangNode } from './SlangNode.js'; +import { InheritanceSpecifier } from './InheritanceSpecifier.js'; +import { InterfaceMembers } from './InterfaceMembers.js'; const { group, line } = doc.builders; @@ -16,9 +18,41 @@ export class InterfaceDefinition extends SlangNode { closeBrace; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { + interfaceKeyword, + name, + inheritance, + openBrace, + members, + closeBrace + } = ast; + this.interfaceKeyword = interfaceKeyword.text; + this.name = name.text; + if (inheritance) { + this.inheritance = new InheritanceSpecifier( + inheritance, + childrenOffsets.shift(), + comments, + parse, + options + ); + } + this.openBrace = openBrace.text; + this.members = new InterfaceMembers( + members, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.closeBrace = closeBrace.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/InterfaceMembers.js b/src/slang-nodes/InterfaceMembers.js index 50bdf1600..40b8e8d24 100644 --- a/src/slang-nodes/InterfaceMembers.js +++ b/src/slang-nodes/InterfaceMembers.js @@ -2,15 +2,31 @@ import { doc } from 'prettier'; import { printSeparatedItem } from '../common/printer-helpers.js'; import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; import { SlangNode } from './SlangNode.js'; +import { ContractMember } from './ContractMember.js'; const { hardline } = doc.builders; export class InterfaceMembers extends SlangNode { items; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items } = ast; + this.items = items.map( + (item) => + new ContractMember( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print, options) { diff --git a/src/slang-nodes/LibraryDefinition.js b/src/slang-nodes/LibraryDefinition.js index 4d791d55a..1a5e76aee 100644 --- a/src/slang-nodes/LibraryDefinition.js +++ b/src/slang-nodes/LibraryDefinition.js @@ -1,5 +1,6 @@ import { doc } from 'prettier'; import { SlangNode } from './SlangNode.js'; +import { LibraryMembers } from './LibraryMembers.js'; const { group, line } = doc.builders; @@ -14,9 +15,25 @@ export class LibraryDefinition extends SlangNode { closeBrace; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { libraryKeyword, name, openBrace, members, closeBrace } = ast; + this.libraryKeyword = libraryKeyword.text; + this.name = name.text; + this.openBrace = openBrace.text; + this.members = new LibraryMembers( + members, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.closeBrace = closeBrace.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/LibraryMembers.js b/src/slang-nodes/LibraryMembers.js index 58ab1cad0..df17ed33a 100644 --- a/src/slang-nodes/LibraryMembers.js +++ b/src/slang-nodes/LibraryMembers.js @@ -2,15 +2,31 @@ import { doc } from 'prettier'; import { printSeparatedItem } from '../common/printer-helpers.js'; import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; import { SlangNode } from './SlangNode.js'; +import { ContractMember } from './ContractMember.js'; const { hardline } = doc.builders; export class LibraryMembers extends SlangNode { items; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items } = ast; + this.items = items.map( + (item) => + new ContractMember( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print, options) { diff --git a/src/slang-nodes/MappingKey.js b/src/slang-nodes/MappingKey.js index 442851eb2..9ac5220f6 100644 --- a/src/slang-nodes/MappingKey.js +++ b/src/slang-nodes/MappingKey.js @@ -1,13 +1,27 @@ import { SlangNode } from './SlangNode.js'; +import { MappingKeyType } from './MappingKeyType.js'; export class MappingKey extends SlangNode { keyType; name; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { keyType, name } = ast; + this.keyType = new MappingKeyType( + keyType, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.name = name?.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/MappingKeyType.js b/src/slang-nodes/MappingKeyType.js index 641dad5eb..17a6083e5 100644 --- a/src/slang-nodes/MappingKeyType.js +++ b/src/slang-nodes/MappingKeyType.js @@ -1,11 +1,26 @@ import { SlangNode } from './SlangNode.js'; +import { ElementaryType } from './ElementaryType.js'; +import { IdentifierPath } from './IdentifierPath.js'; + +const variants = { ElementaryType, IdentifierPath }; export class MappingKeyType extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + const fetch = (childrenOffsets) => { + const { variant } = ast; + this.variant = new variants[variant.cst.kind]( + variant, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/MappingType.js b/src/slang-nodes/MappingType.js index 39c85a206..1b2642fb9 100644 --- a/src/slang-nodes/MappingType.js +++ b/src/slang-nodes/MappingType.js @@ -1,4 +1,6 @@ import { SlangNode } from './SlangNode.js'; +import { MappingKey } from './MappingKey.js'; +import { MappingValue } from './MappingValue.js'; export class MappingType extends SlangNode { mappingKeyword; @@ -13,9 +15,39 @@ export class MappingType extends SlangNode { closeParen; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { + mappingKeyword, + openParen, + keyType, + equalGreaterThan, + valueType, + closeParen + } = ast; + this.mappingKeyword = mappingKeyword.text; + this.openParen = openParen.text; + this.keyType = new MappingKey( + keyType, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.equalGreaterThan = equalGreaterThan.text; + this.valueType = new MappingValue( + valueType, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.closeParen = closeParen.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/MappingValue.js b/src/slang-nodes/MappingValue.js index d49420137..3b2888fad 100644 --- a/src/slang-nodes/MappingValue.js +++ b/src/slang-nodes/MappingValue.js @@ -1,13 +1,27 @@ import { SlangNode } from './SlangNode.js'; +import { TypeName } from './TypeName.js'; export class MappingValue extends SlangNode { typeName; name; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { typeName, name } = ast; + this.typeName = new TypeName( + typeName, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.name = name?.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/MemberAccess.js b/src/slang-nodes/MemberAccess.js index 554e017c1..3a3606ddc 100644 --- a/src/slang-nodes/MemberAccess.js +++ b/src/slang-nodes/MemberAccess.js @@ -5,7 +5,13 @@ export class MemberAccess extends SlangNode { constructor(ast, offset, comments, parse) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = () => { + const { variant } = ast; + this.variant = variant.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print() { diff --git a/src/slang-nodes/MemberAccessExpression.js b/src/slang-nodes/MemberAccessExpression.js index 54acbb998..fd1a2ded9 100644 --- a/src/slang-nodes/MemberAccessExpression.js +++ b/src/slang-nodes/MemberAccessExpression.js @@ -2,6 +2,8 @@ import { doc } from 'prettier'; import { isLabel } from '../common/util.js'; import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js'; import { SlangNode } from './SlangNode.js'; +import { Expression } from './Expression.js'; +import { MemberAccess } from './MemberAccess.js'; const { group, indent, label, softline } = doc.builders; @@ -112,9 +114,29 @@ export class MemberAccessExpression extends SlangNode { member; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { operand, period, member } = ast; + this.operand = new Expression( + operand, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.period = period.text; + this.member = new MemberAccess( + member, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/ModifierAttribute.js b/src/slang-nodes/ModifierAttribute.js index 4f5328f12..ca3bd6aa0 100644 --- a/src/slang-nodes/ModifierAttribute.js +++ b/src/slang-nodes/ModifierAttribute.js @@ -1,11 +1,27 @@ import { SlangNode } from './SlangNode.js'; +import { OverrideSpecifier } from './OverrideSpecifier.js'; export class ModifierAttribute extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { variant } = ast; + this.variant = + variant.type === 'Terminal' + ? variant.text + : new OverrideSpecifier( + variant, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/ModifierAttributes.js b/src/slang-nodes/ModifierAttributes.js index 89456183e..6a3e3f25b 100644 --- a/src/slang-nodes/ModifierAttributes.js +++ b/src/slang-nodes/ModifierAttributes.js @@ -1,15 +1,31 @@ import { doc } from 'prettier'; import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; import { SlangNode } from './SlangNode.js'; +import { ModifierAttribute } from './ModifierAttribute.js'; const { line } = doc.builders; export class ModifierAttributes extends SlangNode { items; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items } = ast; + this.items = items.map( + (item) => + new ModifierAttribute( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); this.items = this.items.sort(sortFunctionAttributes); } diff --git a/src/slang-nodes/ModifierDefinition.js b/src/slang-nodes/ModifierDefinition.js index bc983115a..db18e8302 100644 --- a/src/slang-nodes/ModifierDefinition.js +++ b/src/slang-nodes/ModifierDefinition.js @@ -2,6 +2,8 @@ import { printFunction } from '../slang-printers/print-function.js'; import { SlangNode } from './SlangNode.js'; import { ParametersDeclaration } from './ParametersDeclaration.js'; import { Parameters } from './Parameters.js'; +import { ModifierAttributes } from './ModifierAttributes.js'; +import { FunctionBody } from './FunctionBody.js'; export class ModifierDefinition extends SlangNode { modifierKeyword; @@ -14,9 +16,39 @@ export class ModifierDefinition extends SlangNode { body; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { modifierKeyword, name, parameters, attributes, body } = ast; + this.modifierKeyword = modifierKeyword.text; + this.name = name.text; + if (parameters) { + this.parameters = new ParametersDeclaration( + parameters, + childrenOffsets.shift(), + comments, + parse, + options + ); + } + this.attributes = new ModifierAttributes( + attributes, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.body = new FunctionBody( + body, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); if (typeof this.parameters === 'undefined') { const parametersOffset = this.attributes.loc.startWithTrivia; diff --git a/src/slang-nodes/ModifierInvocation.js b/src/slang-nodes/ModifierInvocation.js index 71e9a02eb..133efc73c 100644 --- a/src/slang-nodes/ModifierInvocation.js +++ b/src/slang-nodes/ModifierInvocation.js @@ -1,14 +1,37 @@ import { isComment } from '../slang-utils/is-comment.js'; import { SlangNode } from './SlangNode.js'; +import { IdentifierPath } from './IdentifierPath.js'; +import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; export class ModifierInvocation extends SlangNode { name; arguments; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { name } = ast; + this.name = new IdentifierPath( + name, + childrenOffsets.shift(), + comments, + parse, + options + ); + if (ast.arguments) { + this.arguments = new ArgumentsDeclaration( + ast.arguments, + childrenOffsets.shift(), + comments, + parse, + options + ); + } + }; + + this.initialize(ast, offset, comments, fetch, parse); this.cleanModifierInvocationArguments = () => { if ( diff --git a/src/slang-nodes/MultiplicativeExpression.js b/src/slang-nodes/MultiplicativeExpression.js index 56e53261e..4524e5c3d 100644 --- a/src/slang-nodes/MultiplicativeExpression.js +++ b/src/slang-nodes/MultiplicativeExpression.js @@ -1,6 +1,7 @@ import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; import { createHugFunction } from '../slang-utils/create-hug-function.js'; import { SlangNode } from './SlangNode.js'; +import { Expression } from './Expression.js'; const multiplicationTryToHug = createHugFunction(['/', '%']); const divisionTryToHug = createHugFunction(['*', '%']); @@ -13,9 +14,29 @@ export class MultiplicativeExpression extends SlangNode { rightOperand; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { leftOperand, operator, rightOperand } = ast; + this.leftOperand = new Expression( + leftOperand, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.operator = operator.text; + this.rightOperand = new Expression( + rightOperand, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); switch (this.operator) { case '*': diff --git a/src/slang-nodes/NamedArgument.js b/src/slang-nodes/NamedArgument.js index af7633f2c..703d03807 100644 --- a/src/slang-nodes/NamedArgument.js +++ b/src/slang-nodes/NamedArgument.js @@ -1,4 +1,5 @@ import { SlangNode } from './SlangNode.js'; +import { Expression } from './Expression.js'; export class NamedArgument extends SlangNode { name; @@ -7,9 +8,23 @@ export class NamedArgument extends SlangNode { value; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { name, colon, value } = ast; + this.name = name.text; + this.colon = colon.text; + this.value = new Expression( + value, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/NamedArgumentGroup.js b/src/slang-nodes/NamedArgumentGroup.js index efca86324..a3eb71b92 100644 --- a/src/slang-nodes/NamedArgumentGroup.js +++ b/src/slang-nodes/NamedArgumentGroup.js @@ -1,4 +1,5 @@ import { SlangNode } from './SlangNode.js'; +import { NamedArguments } from './NamedArguments.js'; export class NamedArgumentGroup extends SlangNode { openBrace; @@ -7,9 +8,24 @@ export class NamedArgumentGroup extends SlangNode { closeBrace; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { openBrace, closeBrace } = ast; + this.openBrace = openBrace.text; + this.arguments = new NamedArguments( + ast.arguments, + childrenOffsets.shift(), + comments, + parse, + options + ); + + this.closeBrace = closeBrace.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/NamedArguments.js b/src/slang-nodes/NamedArguments.js index a40410865..8b312f2fd 100644 --- a/src/slang-nodes/NamedArguments.js +++ b/src/slang-nodes/NamedArguments.js @@ -1,6 +1,7 @@ import { doc } from 'prettier'; import { printSeparatedList } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; +import { NamedArgument } from './NamedArgument.js'; const { line, softline } = doc.builders; @@ -9,9 +10,25 @@ export class NamedArguments extends SlangNode { separators; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items, separators } = ast; + this.items = items.map( + (item) => + new NamedArgument( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + this.separators = separators.map((separator) => separator.text); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print, options) { diff --git a/src/slang-nodes/NamedArgumentsDeclaration.js b/src/slang-nodes/NamedArgumentsDeclaration.js index 23de0eee0..74184c01b 100644 --- a/src/slang-nodes/NamedArgumentsDeclaration.js +++ b/src/slang-nodes/NamedArgumentsDeclaration.js @@ -1,4 +1,5 @@ import { SlangNode } from './SlangNode.js'; +import { NamedArgumentGroup } from './NamedArgumentGroup.js'; export class NamedArgumentsDeclaration extends SlangNode { openParen; @@ -7,9 +8,25 @@ export class NamedArgumentsDeclaration extends SlangNode { closeParen; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { openParen, closeParen } = ast; + this.openParen = openParen.text; + if (ast.arguments) { + this.arguments = new NamedArgumentGroup( + ast.arguments, + childrenOffsets.shift(), + comments, + parse, + options + ); + } + this.closeParen = closeParen.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/NamedImport.js b/src/slang-nodes/NamedImport.js index beefd4f3b..41a11b19c 100644 --- a/src/slang-nodes/NamedImport.js +++ b/src/slang-nodes/NamedImport.js @@ -1,4 +1,6 @@ import { SlangNode } from './SlangNode.js'; +import { ImportAlias } from './ImportAlias.js'; +import { StringLiteral } from './StringLiteral.js'; export class NamedImport extends SlangNode { asterisk; @@ -9,9 +11,30 @@ export class NamedImport extends SlangNode { path; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { asterisk, alias, fromKeyword, path } = ast; + this.asterisk = asterisk.text; + this.alias = new ImportAlias( + alias, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.fromKeyword = fromKeyword.text; + this.path = new StringLiteral( + path, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/NewExpression.js b/src/slang-nodes/NewExpression.js index 5e785c3fa..5c0163f59 100644 --- a/src/slang-nodes/NewExpression.js +++ b/src/slang-nodes/NewExpression.js @@ -1,13 +1,27 @@ import { SlangNode } from './SlangNode.js'; +import { TypeName } from './TypeName.js'; export class NewExpression extends SlangNode { newKeyword; typeName; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { newKeyword, typeName } = ast; + this.newKeyword = newKeyword.text; + this.typeName = new TypeName( + typeName, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/NumberUnit.js b/src/slang-nodes/NumberUnit.js index b259c96b7..682142edc 100644 --- a/src/slang-nodes/NumberUnit.js +++ b/src/slang-nodes/NumberUnit.js @@ -5,7 +5,13 @@ export class NumberUnit extends SlangNode { constructor(ast, offset, comments, parse) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = () => { + const { variant } = ast; + this.variant = variant.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print() { diff --git a/src/slang-nodes/OrExpression.js b/src/slang-nodes/OrExpression.js index 65fff7951..1b0b5785e 100644 --- a/src/slang-nodes/OrExpression.js +++ b/src/slang-nodes/OrExpression.js @@ -1,6 +1,7 @@ import { printLogicalOperation } from '../slang-printers/print-logical-operation.js'; import { createHugFunction } from '../slang-utils/create-hug-function.js'; import { SlangNode } from './SlangNode.js'; +import { Expression } from './Expression.js'; const tryToHug = createHugFunction(['&&']); @@ -11,9 +12,29 @@ export class OrExpression extends SlangNode { rightOperand; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { leftOperand, operator, rightOperand } = ast; + this.leftOperand = new Expression( + leftOperand, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.operator = operator.text; + this.rightOperand = new Expression( + rightOperand, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); diff --git a/src/slang-nodes/OverridePaths.js b/src/slang-nodes/OverridePaths.js index db8e79273..271b36103 100644 --- a/src/slang-nodes/OverridePaths.js +++ b/src/slang-nodes/OverridePaths.js @@ -1,13 +1,30 @@ import { SlangNode } from './SlangNode.js'; +import { IdentifierPath } from './IdentifierPath.js'; export class OverridePaths extends SlangNode { items; separators; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items, separators } = ast; + this.items = items.map( + (item) => + new IdentifierPath( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + this.separators = separators.map((separator) => separator.text); + }; + + this.initialize(ast, offset, comments, fetch, parse); } // TODO: implement print diff --git a/src/slang-nodes/OverridePathsDeclaration.js b/src/slang-nodes/OverridePathsDeclaration.js index b21102951..acf7fa3af 100644 --- a/src/slang-nodes/OverridePathsDeclaration.js +++ b/src/slang-nodes/OverridePathsDeclaration.js @@ -1,4 +1,5 @@ import { SlangNode } from './SlangNode.js'; +import { OverridePaths } from './OverridePaths.js'; export class OverridePathsDeclaration extends SlangNode { openParen; @@ -7,9 +8,23 @@ export class OverridePathsDeclaration extends SlangNode { closeParen; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { openParen, paths, closeParen } = ast; + this.openParen = openParen.text; + this.paths = new OverridePaths( + paths, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.closeParen = closeParen.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } // TODO: implement print diff --git a/src/slang-nodes/OverrideSpecifier.js b/src/slang-nodes/OverrideSpecifier.js index e29bb2add..d36135c48 100644 --- a/src/slang-nodes/OverrideSpecifier.js +++ b/src/slang-nodes/OverrideSpecifier.js @@ -1,13 +1,29 @@ import { SlangNode } from './SlangNode.js'; +import { OverridePathsDeclaration } from './OverridePathsDeclaration.js'; export class OverrideSpecifier extends SlangNode { overrideKeyword; overridden; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { overrideKeyword, overridden } = ast; + this.overrideKeyword = overrideKeyword.text; + if (overridden) { + this.overridden = new OverridePathsDeclaration( + overridden, + childrenOffsets.shift(), + comments, + parse, + options + ); + } + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/Parameter.js b/src/slang-nodes/Parameter.js index eee33795b..3d13e6996 100644 --- a/src/slang-nodes/Parameter.js +++ b/src/slang-nodes/Parameter.js @@ -1,5 +1,7 @@ import { doc } from 'prettier'; import { SlangNode } from './SlangNode.js'; +import { TypeName } from './TypeName.js'; +import { StorageLocation } from './StorageLocation.js'; const { group } = doc.builders; @@ -10,9 +12,31 @@ export class Parameter extends SlangNode { name; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { typeName, storageLocation, name } = ast; + this.typeName = new TypeName( + typeName, + childrenOffsets.shift(), + comments, + parse, + options + ); + if (storageLocation) { + this.storageLocation = new StorageLocation( + storageLocation, + childrenOffsets.shift(), + comments, + parse, + options + ); + } + this.name = name?.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/Parameters.js b/src/slang-nodes/Parameters.js index d0de61a7f..e5338fd54 100644 --- a/src/slang-nodes/Parameters.js +++ b/src/slang-nodes/Parameters.js @@ -4,16 +4,32 @@ import { } from '../common/printer-helpers.js'; import { printComments } from '../slang-printers/print-comments.js'; import { SlangNode } from './SlangNode.js'; +import { Parameter } from './Parameter.js'; export class Parameters extends SlangNode { items; separators; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); if (offset) { - this.initialize(ast, offset, comments, parse); + const fetch = (childrenOffsets) => { + const { items, separators } = ast; + this.items = items.map( + (item) => + new Parameter( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + this.separators = separators.map((separator) => separator.text); + }; + + this.initialize(ast, offset, comments, fetch, parse); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/ParametersDeclaration.js b/src/slang-nodes/ParametersDeclaration.js index 67bf81f7a..f6ce312b7 100644 --- a/src/slang-nodes/ParametersDeclaration.js +++ b/src/slang-nodes/ParametersDeclaration.js @@ -1,4 +1,5 @@ import { SlangNode } from './SlangNode.js'; +import { Parameters } from './Parameters.js'; export class ParametersDeclaration extends SlangNode { openParen; @@ -7,10 +8,23 @@ export class ParametersDeclaration extends SlangNode { closeParen; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); if (offset) { - this.initialize(ast, offset, comments, parse); + const fetch = (childrenOffsets) => { + const { openParen, parameters, closeParen } = ast; + this.openParen = openParen.text; + this.parameters = new Parameters( + parameters, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.closeParen = closeParen.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/PathImport.js b/src/slang-nodes/PathImport.js index 547abdae5..2b0c91fe3 100644 --- a/src/slang-nodes/PathImport.js +++ b/src/slang-nodes/PathImport.js @@ -1,13 +1,37 @@ import { SlangNode } from './SlangNode.js'; +import { StringLiteral } from './StringLiteral.js'; +import { ImportAlias } from './ImportAlias.js'; export class PathImport extends SlangNode { path; alias; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { path, alias } = ast; + this.path = new StringLiteral( + path, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.alias = + typeof alias === 'undefined' + ? undefined + : new ImportAlias( + alias, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/PositionalArguments.js b/src/slang-nodes/PositionalArguments.js index 00d3c672d..946ee156e 100644 --- a/src/slang-nodes/PositionalArguments.js +++ b/src/slang-nodes/PositionalArguments.js @@ -1,14 +1,31 @@ import { printSeparatedList } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; +import { Expression } from './Expression.js'; export class PositionalArguments extends SlangNode { items; separators; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items, separators } = ast; + this.items = items.map( + (item) => + new Expression( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + this.separators = separators.map((separator) => separator.text); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/PositionalArgumentsDeclaration.js b/src/slang-nodes/PositionalArgumentsDeclaration.js index ccaca1317..a83300221 100644 --- a/src/slang-nodes/PositionalArgumentsDeclaration.js +++ b/src/slang-nodes/PositionalArgumentsDeclaration.js @@ -1,4 +1,5 @@ import { SlangNode } from './SlangNode.js'; +import { PositionalArguments } from './PositionalArguments.js'; export class PositionalArgumentsDeclaration extends SlangNode { openParen; @@ -7,9 +8,24 @@ export class PositionalArgumentsDeclaration extends SlangNode { closeParen; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { openParen, closeParen } = ast; + const $arguments = ast.arguments; + this.openParen = openParen.text; + this.arguments = new PositionalArguments( + $arguments, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.closeParen = closeParen.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/PostfixExpression.js b/src/slang-nodes/PostfixExpression.js index 8c06dddc3..d094bd3f0 100644 --- a/src/slang-nodes/PostfixExpression.js +++ b/src/slang-nodes/PostfixExpression.js @@ -1,13 +1,27 @@ import { SlangNode } from './SlangNode.js'; +import { Expression } from './Expression.js'; export class PostfixExpression extends SlangNode { operand; operator; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { operand, operator } = ast; + this.operand = new Expression( + operand, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.operator = operator.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/Pragma.js b/src/slang-nodes/Pragma.js index 50ce5045a..5e9c9d8f1 100644 --- a/src/slang-nodes/Pragma.js +++ b/src/slang-nodes/Pragma.js @@ -1,11 +1,27 @@ import { SlangNode } from './SlangNode.js'; +import { ABICoderPragma } from './ABICoderPragma.js'; +import { ExperimentalPragma } from './ExperimentalPragma.js'; +import { VersionPragma } from './VersionPragma.js'; +const variants = { ABICoderPragma, ExperimentalPragma, VersionPragma }; export class Pragma extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { variant } = ast; + this.variant = new variants[variant.cst.kind]( + variant, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/PragmaDirective.js b/src/slang-nodes/PragmaDirective.js index 0cb8b4d30..6b078dffa 100644 --- a/src/slang-nodes/PragmaDirective.js +++ b/src/slang-nodes/PragmaDirective.js @@ -1,4 +1,5 @@ import { SlangNode } from './SlangNode.js'; +import { Pragma } from './Pragma.js'; export class PragmaDirective extends SlangNode { pragmaKeyword; @@ -7,9 +8,23 @@ export class PragmaDirective extends SlangNode { semicolon; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { pragmaKeyword, pragma, semicolon } = ast; + this.pragmaKeyword = pragmaKeyword.text; + this.pragma = new Pragma( + pragma, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.semicolon = semicolon.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/PrefixExpression.js b/src/slang-nodes/PrefixExpression.js index f6fc27baa..3cc85b63b 100644 --- a/src/slang-nodes/PrefixExpression.js +++ b/src/slang-nodes/PrefixExpression.js @@ -1,13 +1,27 @@ import { SlangNode } from './SlangNode.js'; +import { Expression } from './Expression.js'; export class PrefixExpression extends SlangNode { operator; operand; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { operator, operand } = ast; + this.operator = operator.text; + this.operand = new Expression( + operand, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/ReceiveFunctionAttribute.js b/src/slang-nodes/ReceiveFunctionAttribute.js index 72cdd80f2..a7655da16 100644 --- a/src/slang-nodes/ReceiveFunctionAttribute.js +++ b/src/slang-nodes/ReceiveFunctionAttribute.js @@ -1,11 +1,30 @@ import { SlangNode } from './SlangNode.js'; +import { ModifierInvocation } from './ModifierInvocation.js'; +import { OverrideSpecifier } from './OverrideSpecifier.js'; + +const variants = { ModifierInvocation, OverrideSpecifier }; export class ReceiveFunctionAttribute extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { variant } = ast; + this.variant = + variant.type === 'Terminal' + ? variant.text + : new variants[variant.cst.kind]( + variant, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/ReceiveFunctionAttributes.js b/src/slang-nodes/ReceiveFunctionAttributes.js index d3e084433..91038ec89 100644 --- a/src/slang-nodes/ReceiveFunctionAttributes.js +++ b/src/slang-nodes/ReceiveFunctionAttributes.js @@ -1,15 +1,31 @@ import { doc } from 'prettier'; import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; import { SlangNode } from './SlangNode.js'; +import { ReceiveFunctionAttribute } from './ReceiveFunctionAttribute.js'; const { line } = doc.builders; export class ReceiveFunctionAttributes extends SlangNode { items; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items } = ast; + this.items = items.map( + (item) => + new ReceiveFunctionAttribute( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); this.items = this.items.sort(sortFunctionAttributes); } diff --git a/src/slang-nodes/ReceiveFunctionDefinition.js b/src/slang-nodes/ReceiveFunctionDefinition.js index 0e1fccf0e..337ce2529 100644 --- a/src/slang-nodes/ReceiveFunctionDefinition.js +++ b/src/slang-nodes/ReceiveFunctionDefinition.js @@ -1,5 +1,8 @@ import { printFunction } from '../slang-printers/print-function.js'; import { SlangNode } from './SlangNode.js'; +import { ParametersDeclaration } from './ParametersDeclaration.js'; +import { ReceiveFunctionAttributes } from './ReceiveFunctionAttributes.js'; +import { FunctionBody } from './FunctionBody.js'; export class ReceiveFunctionDefinition extends SlangNode { receiveKeyword; @@ -10,9 +13,36 @@ export class ReceiveFunctionDefinition extends SlangNode { body; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { receiveKeyword, parameters, attributes, body } = ast; + this.receiveKeyword = receiveKeyword.text; + this.parameters = new ParametersDeclaration( + parameters, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.attributes = new ReceiveFunctionAttributes( + attributes, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.body = new FunctionBody( + body, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); this.cleanModifierInvocationArguments(); } diff --git a/src/slang-nodes/ReturnStatement.js b/src/slang-nodes/ReturnStatement.js index af66d16a7..eade4595a 100644 --- a/src/slang-nodes/ReturnStatement.js +++ b/src/slang-nodes/ReturnStatement.js @@ -1,9 +1,10 @@ import { doc } from 'prettier'; import { SlangNode } from './SlangNode.js'; +import { Expression } from './Expression.js'; const { group, indent, line } = doc.builders; -function expression(node, path, print, options) { +function printExpression(node, path, print, options) { if (node.expression) { return node.expression.variant.kind === 'TupleExpression' || (options.experimentalTernaries && @@ -21,15 +22,31 @@ export class ReturnStatement extends SlangNode { semicolon; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { returnKeyword, expression, semicolon } = ast; + this.returnKeyword = returnKeyword.text; + if (expression) { + this.expression = new Expression( + expression, + childrenOffsets.shift(), + comments, + parse, + options + ); + } + this.semicolon = semicolon.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print, options) { return [ this.returnKeyword, - expression(this, path, print, options), + printExpression(this, path, print, options), this.semicolon ]; } diff --git a/src/slang-nodes/ReturnsDeclaration.js b/src/slang-nodes/ReturnsDeclaration.js index 617d6f7da..198c7e502 100644 --- a/src/slang-nodes/ReturnsDeclaration.js +++ b/src/slang-nodes/ReturnsDeclaration.js @@ -1,5 +1,6 @@ import { doc } from 'prettier'; import { SlangNode } from './SlangNode.js'; +import { ParametersDeclaration } from './ParametersDeclaration.js'; const { group } = doc.builders; @@ -8,9 +9,22 @@ export class ReturnsDeclaration extends SlangNode { variables; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { returnsKeyword, variables } = ast; + this.returnsKeyword = returnsKeyword.text; + this.variables = new ParametersDeclaration( + variables, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/RevertStatement.js b/src/slang-nodes/RevertStatement.js index 30f3c43ff..8279649b2 100644 --- a/src/slang-nodes/RevertStatement.js +++ b/src/slang-nodes/RevertStatement.js @@ -1,4 +1,6 @@ import { SlangNode } from './SlangNode.js'; +import { IdentifierPath } from './IdentifierPath.js'; +import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; export class RevertStatement extends SlangNode { revertKeyword; @@ -9,9 +11,32 @@ export class RevertStatement extends SlangNode { semicolon; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { revertKeyword, error, semicolon } = ast; + this.revertKeyword = revertKeyword.text; + if (error) { + this.error = new IdentifierPath( + error, + childrenOffsets.shift(), + comments, + parse, + options + ); + } + this.arguments = new ArgumentsDeclaration( + ast.arguments, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.semicolon = semicolon.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/ShiftExpression.js b/src/slang-nodes/ShiftExpression.js index 55e9d18b9..1a6db46f7 100644 --- a/src/slang-nodes/ShiftExpression.js +++ b/src/slang-nodes/ShiftExpression.js @@ -1,6 +1,7 @@ import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; import { createHugFunction } from '../slang-utils/create-hug-function.js'; import { SlangNode } from './SlangNode.js'; +import { Expression } from './Expression.js'; const tryToHugLeftOperand = createHugFunction([ '+', @@ -20,9 +21,29 @@ export class ShiftExpression extends SlangNode { rightOperand; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { leftOperand, operator, rightOperand } = ast; + this.leftOperand = new Expression( + leftOperand, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.operator = operator.text; + this.rightOperand = new Expression( + rightOperand, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); this.leftOperand = tryToHugLeftOperand(this.leftOperand); this.rightOperand = tryToHugRightOperand(this.rightOperand); diff --git a/src/slang-nodes/SlangNode.js b/src/slang-nodes/SlangNode.js index 37ee148c5..e9285d943 100644 --- a/src/slang-nodes/SlangNode.js +++ b/src/slang-nodes/SlangNode.js @@ -11,7 +11,7 @@ export class SlangNode { comments = []; - initialize(ast, offset, comments, parse) { + initialize(ast, offset, comments, fetch) { this.kind = ast.cst.kind; // Collect comments and get children offsets. @@ -19,24 +19,7 @@ export class SlangNode { const childrenOffsets = getChildrenOffsets(cstChildren, offset, comments); // populate all children nodes - // TODO: before moving to typescript, this should be moved to a fetch - // function that returns static typed classes. - function getValue(astChild) { - return astChild.type === 'Terminal' - ? astChild.text - : parse(astChild, childrenOffsets.shift()); - } - - const childrenKeys = Object.keys(this).slice(3); - - childrenKeys.forEach((childKey) => { - const astChild = ast[childKey]; - if (astChild) { - this[childKey] = Array.isArray(astChild) - ? astChild.map(getValue) - : getValue(astChild); - } - }); + fetch(childrenOffsets); // calculate correct loc object const startWithTrivia = offset; @@ -45,6 +28,8 @@ export class SlangNode { let trailingOffset = getTrailingOffset(cstChildren); if (leadingOffset === 0 || trailingOffset === 0) { + const childrenKeys = Object.keys(this).slice(3); + for (let i = 0; i < childrenKeys.length; i += 1) { const childLoc = this[childrenKeys[i]]?.loc; diff --git a/src/slang-nodes/SourceUnit.js b/src/slang-nodes/SourceUnit.js index 1f84aea32..f2f6625ec 100644 --- a/src/slang-nodes/SourceUnit.js +++ b/src/slang-nodes/SourceUnit.js @@ -1,14 +1,39 @@ import { doc } from 'prettier'; import { SlangNode } from './SlangNode.js'; +import { SourceUnitMembers } from './SourceUnitMembers.js'; const { line } = doc.builders; export class SourceUnit extends SlangNode { members; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { members } = ast; + this.members = new SourceUnitMembers( + members, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); + } + + fetch(ast, childrenOffsets, comments) { + const { members } = ast; + return { + members: new SourceUnitMembers( + members, + childrenOffsets.shift(), + comments, + parse + ) + }; } print(path, print, options) { diff --git a/src/slang-nodes/SourceUnitMember.js b/src/slang-nodes/SourceUnitMember.js index e937cb6cc..531a072fb 100644 --- a/src/slang-nodes/SourceUnitMember.js +++ b/src/slang-nodes/SourceUnitMember.js @@ -1,11 +1,51 @@ import { SlangNode } from './SlangNode.js'; +import { PragmaDirective } from './PragmaDirective.js'; +import { ImportDirective } from './ImportDirective.js'; +import { ContractDefinition } from './ContractDefinition.js'; +import { InterfaceDefinition } from './InterfaceDefinition.js'; +import { LibraryDefinition } from './LibraryDefinition.js'; +import { StructDefinition } from './StructDefinition.js'; +import { EnumDefinition } from './EnumDefinition.js'; +import { FunctionDefinition } from './FunctionDefinition.js'; +import { ConstantDefinition } from './ConstantDefinition.js'; +import { ErrorDefinition } from './ErrorDefinition.js'; +import { UserDefinedValueTypeDefinition } from './UserDefinedValueTypeDefinition.js'; +import { UsingDirective } from './UsingDirective.js'; +import { EventDefinition } from './EventDefinition.js'; +const variants = { + PragmaDirective, + ImportDirective, + ContractDefinition, + InterfaceDefinition, + LibraryDefinition, + StructDefinition, + EnumDefinition, + FunctionDefinition, + ConstantDefinition, + ErrorDefinition, + UserDefinedValueTypeDefinition, + UsingDirective, + EventDefinition +}; export class SourceUnitMember extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { variant } = ast; + this.variant = new variants[variant.cst.kind]( + variant, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/SourceUnitMembers.js b/src/slang-nodes/SourceUnitMembers.js index 90196de37..6099e8638 100644 --- a/src/slang-nodes/SourceUnitMembers.js +++ b/src/slang-nodes/SourceUnitMembers.js @@ -1,12 +1,28 @@ import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; import { SlangNode } from './SlangNode.js'; +import { SourceUnitMember } from './SourceUnitMember.js'; export class SourceUnitMembers extends SlangNode { items; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items } = ast; + this.items = items.map( + (item) => + new SourceUnitMember( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print, options) { diff --git a/src/slang-nodes/StateVariableAttribute.js b/src/slang-nodes/StateVariableAttribute.js index aa59afcac..72ba00ff6 100644 --- a/src/slang-nodes/StateVariableAttribute.js +++ b/src/slang-nodes/StateVariableAttribute.js @@ -1,11 +1,27 @@ import { SlangNode } from './SlangNode.js'; +import { OverrideSpecifier } from './OverrideSpecifier.js'; export class StateVariableAttribute extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { variant } = ast; + this.variant = + variant.type === 'Terminal' + ? variant.text + : new OverrideSpecifier( + variant, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/StateVariableAttributes.js b/src/slang-nodes/StateVariableAttributes.js index 3713f8fc8..b2d8c2710 100644 --- a/src/slang-nodes/StateVariableAttributes.js +++ b/src/slang-nodes/StateVariableAttributes.js @@ -1,11 +1,27 @@ import { SlangNode } from './SlangNode.js'; +import { StateVariableAttribute } from './StateVariableAttribute.js'; export class StateVariableAttributes extends SlangNode { items; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items } = ast; + this.items = items.map( + (item) => + new StateVariableAttribute( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/StateVariableDefinition.js b/src/slang-nodes/StateVariableDefinition.js index 612a079c1..7607602db 100644 --- a/src/slang-nodes/StateVariableDefinition.js +++ b/src/slang-nodes/StateVariableDefinition.js @@ -1,4 +1,7 @@ import { SlangNode } from './SlangNode.js'; +import { TypeName } from './TypeName.js'; +import { StateVariableAttributes } from './StateVariableAttributes.js'; +import { StateVariableDefinitionValue } from './StateVariableDefinitionValue.js'; export class StateVariableDefinition extends SlangNode { typeName; @@ -11,9 +14,39 @@ export class StateVariableDefinition extends SlangNode { semicolon; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { typeName, attributes, name, value, semicolon } = ast; + this.typeName = new TypeName( + typeName, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.attributes = new StateVariableAttributes( + attributes, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.name = name.text; + if (value) { + this.value = new StateVariableDefinitionValue( + value, + childrenOffsets.shift(), + comments, + parse, + options + ); + } + this.semicolon = semicolon.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/StateVariableDefinitionValue.js b/src/slang-nodes/StateVariableDefinitionValue.js index 8b3c574b6..f03828196 100644 --- a/src/slang-nodes/StateVariableDefinitionValue.js +++ b/src/slang-nodes/StateVariableDefinitionValue.js @@ -1,5 +1,6 @@ import { doc } from 'prettier'; import { SlangNode } from './SlangNode.js'; +import { Expression } from './Expression.js'; const { group, indent, line } = doc.builders; @@ -8,9 +9,22 @@ export class StateVariableDefinitionValue extends SlangNode { value; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { equal, value } = ast; + this.equal = equal.text; + this.value = new Expression( + value, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/Statement.js b/src/slang-nodes/Statement.js index 9a04d5ab6..a8be293bc 100644 --- a/src/slang-nodes/Statement.js +++ b/src/slang-nodes/Statement.js @@ -1,11 +1,60 @@ import { SlangNode } from './SlangNode.js'; +import { ExpressionStatement } from './ExpressionStatement.js'; +import { VariableDeclarationStatement } from './VariableDeclarationStatement.js'; +import { TupleDeconstructionStatement } from './TupleDeconstructionStatement.js'; +import { IfStatement } from './IfStatement.js'; +import { ForStatement } from './ForStatement.js'; +import { WhileStatement } from './WhileStatement.js'; +import { DoWhileStatement } from './DoWhileStatement.js'; +import { ContinueStatement } from './ContinueStatement.js'; +import { BreakStatement } from './BreakStatement.js'; +import { ReturnStatement } from './ReturnStatement.js'; +import { ThrowStatement } from './ThrowStatement.js'; +import { EmitStatement } from './EmitStatement.js'; +import { TryStatement } from './TryStatement.js'; +import { RevertStatement } from './RevertStatement.js'; +import { AssemblyStatement } from './AssemblyStatement.js'; +import { Block } from './Block.js'; +import { UncheckedBlock } from './UncheckedBlock.js'; + +const variants = { + ExpressionStatement, + VariableDeclarationStatement, + TupleDeconstructionStatement, + IfStatement, + ForStatement, + WhileStatement, + DoWhileStatement, + ContinueStatement, + BreakStatement, + ReturnStatement, + ThrowStatement, + EmitStatement, + TryStatement, + RevertStatement, + AssemblyStatement, + Block, + UncheckedBlock +}; export class Statement extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { variant } = ast; + this.variant = new variants[variant.cst.kind]( + variant, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/Statements.js b/src/slang-nodes/Statements.js index 4ab041c2e..8611c7543 100644 --- a/src/slang-nodes/Statements.js +++ b/src/slang-nodes/Statements.js @@ -3,15 +3,25 @@ import { printSeparatedItem } from '../common/printer-helpers.js'; import { printComments } from '../slang-printers/print-comments.js'; import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; import { SlangNode } from './SlangNode.js'; +import { Statement } from './Statement.js'; const { hardline } = doc.builders; export class Statements extends SlangNode { items; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items } = ast; + this.items = items.map( + (item) => + new Statement(item, childrenOffsets.shift(), comments, parse, options) + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print, options) { diff --git a/src/slang-nodes/StorageLocation.js b/src/slang-nodes/StorageLocation.js index 2bc69fab3..663ccbdd2 100644 --- a/src/slang-nodes/StorageLocation.js +++ b/src/slang-nodes/StorageLocation.js @@ -5,7 +5,13 @@ export class StorageLocation extends SlangNode { constructor(ast, offset, comments, parse) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = () => { + const { variant } = ast; + this.variant = variant.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print() { diff --git a/src/slang-nodes/StringExpression.js b/src/slang-nodes/StringExpression.js index 54a76af65..cf7614d65 100644 --- a/src/slang-nodes/StringExpression.js +++ b/src/slang-nodes/StringExpression.js @@ -1,11 +1,35 @@ import { SlangNode } from './SlangNode.js'; +import { StringLiteral } from './StringLiteral.js'; +import { StringLiterals } from './StringLiterals.js'; +import { HexStringLiteral } from './HexStringLiteral.js'; +import { HexStringLiterals } from './HexStringLiterals.js'; +import { UnicodeStringLiterals } from './UnicodeStringLiterals.js'; + +const variants = { + StringLiteral, + StringLiterals, + HexStringLiteral, + HexStringLiterals, + UnicodeStringLiterals +}; export class StringExpression extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + const fetch = (childrenOffsets) => { + const { variant } = ast; + this.variant = new variants[variant.cst.kind]( + variant, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/StringLiteral.js b/src/slang-nodes/StringLiteral.js index d82ff39ba..c7b752495 100644 --- a/src/slang-nodes/StringLiteral.js +++ b/src/slang-nodes/StringLiteral.js @@ -6,7 +6,13 @@ export class StringLiteral extends SlangNode { constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = () => { + const { variant } = ast; + this.variant = variant.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); this.variant = printString(this.variant.slice(1, -1), options); } diff --git a/src/slang-nodes/StringLiterals.js b/src/slang-nodes/StringLiterals.js index d7e6e472a..58e0e16f8 100644 --- a/src/slang-nodes/StringLiterals.js +++ b/src/slang-nodes/StringLiterals.js @@ -1,14 +1,30 @@ import { doc } from 'prettier'; import { SlangNode } from './SlangNode.js'; +import { StringLiteral } from './StringLiteral.js'; const { join, hardline } = doc.builders; export class StringLiterals extends SlangNode { items; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items } = ast; + this.items = items.map( + (item) => + new StringLiteral( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/StructDefinition.js b/src/slang-nodes/StructDefinition.js index 43143335f..b55c4556c 100644 --- a/src/slang-nodes/StructDefinition.js +++ b/src/slang-nodes/StructDefinition.js @@ -1,4 +1,5 @@ import { SlangNode } from './SlangNode.js'; +import { StructMembers } from './StructMembers.js'; export class StructDefinition extends SlangNode { structKeyword; @@ -11,9 +12,25 @@ export class StructDefinition extends SlangNode { closeBrace; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { structKeyword, name, openBrace, members, closeBrace } = ast; + this.structKeyword = structKeyword.text; + this.name = name.text; + this.openBrace = openBrace.text; + this.members = new StructMembers( + members, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.closeBrace = closeBrace.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/StructMember.js b/src/slang-nodes/StructMember.js index 029fe9ef4..dda090219 100644 --- a/src/slang-nodes/StructMember.js +++ b/src/slang-nodes/StructMember.js @@ -1,4 +1,5 @@ import { SlangNode } from './SlangNode.js'; +import { TypeName } from './TypeName.js'; export class StructMember extends SlangNode { typeName; @@ -7,9 +8,23 @@ export class StructMember extends SlangNode { semicolon; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { typeName, name, semicolon } = ast; + this.typeName = new TypeName( + typeName, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.name = name.text; + this.semicolon = semicolon.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/StructMembers.js b/src/slang-nodes/StructMembers.js index 660ad5123..4e9f5e0f1 100644 --- a/src/slang-nodes/StructMembers.js +++ b/src/slang-nodes/StructMembers.js @@ -1,15 +1,31 @@ import { doc } from 'prettier'; import { printSeparatedList } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; +import { StructMember } from './StructMember.js'; const { hardline } = doc.builders; export class StructMembers extends SlangNode { items; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items } = ast; + this.items = items.map( + (item) => + new StructMember( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/ThrowStatement.js b/src/slang-nodes/ThrowStatement.js index 2667cb5b3..dba210e5b 100644 --- a/src/slang-nodes/ThrowStatement.js +++ b/src/slang-nodes/ThrowStatement.js @@ -7,7 +7,14 @@ export class ThrowStatement extends SlangNode { constructor(ast, offset, comments, parse) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = () => { + const { throwKeyword, semicolon } = ast; + this.throwKeyword = throwKeyword.text; + this.semicolon = semicolon.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } // TODO: implement print diff --git a/src/slang-nodes/TryStatement.js b/src/slang-nodes/TryStatement.js index 065fcc904..828ba9add 100644 --- a/src/slang-nodes/TryStatement.js +++ b/src/slang-nodes/TryStatement.js @@ -1,6 +1,10 @@ import { doc } from 'prettier'; import { printSeparatedItem } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; +import { Expression } from './Expression.js'; +import { ReturnsDeclaration } from './ReturnsDeclaration.js'; +import { Block } from './Block.js'; +import { CatchClauses } from './CatchClauses.js'; const { line } = doc.builders; @@ -15,9 +19,45 @@ export class TryStatement extends SlangNode { catchClauses; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { tryKeyword, expression, returns, body, catchClauses } = ast; + this.tryKeyword = tryKeyword.text; + this.expression = new Expression( + expression, + childrenOffsets.shift(), + comments, + parse, + options + ); + if (returns) { + this.returns = new ReturnsDeclaration( + returns, + childrenOffsets.shift(), + comments, + parse, + options + ); + } + this.body = new Block( + body, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.catchClauses = new CatchClauses( + catchClauses, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/TupleDeconstructionElement.js b/src/slang-nodes/TupleDeconstructionElement.js index 3d5934886..6ed2774f9 100644 --- a/src/slang-nodes/TupleDeconstructionElement.js +++ b/src/slang-nodes/TupleDeconstructionElement.js @@ -1,11 +1,26 @@ import { SlangNode } from './SlangNode.js'; +import { TupleMember } from './TupleMember.js'; export class TupleDeconstructionElement extends SlangNode { member; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { member } = ast; + if (member) { + this.member = new TupleMember( + member, + childrenOffsets.shift(), + comments, + parse, + options + ); + } + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/TupleDeconstructionElements.js b/src/slang-nodes/TupleDeconstructionElements.js index bafe24dab..f88072e48 100644 --- a/src/slang-nodes/TupleDeconstructionElements.js +++ b/src/slang-nodes/TupleDeconstructionElements.js @@ -1,14 +1,31 @@ import { printSeparatedList } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; +import { TupleDeconstructionElement } from './TupleDeconstructionElement.js'; export class TupleDeconstructionElements extends SlangNode { items; separators; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items, separators } = ast; + this.items = items.map( + (item) => + new TupleDeconstructionElement( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + this.separators = separators.map((separator) => separator.text); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/TupleDeconstructionStatement.js b/src/slang-nodes/TupleDeconstructionStatement.js index d490ae457..a733d6b91 100644 --- a/src/slang-nodes/TupleDeconstructionStatement.js +++ b/src/slang-nodes/TupleDeconstructionStatement.js @@ -1,5 +1,7 @@ import { doc } from 'prettier'; import { SlangNode } from './SlangNode.js'; +import { TupleDeconstructionElements } from './TupleDeconstructionElements.js'; +import { Expression } from './Expression.js'; const { group, indent, line } = doc.builders; @@ -18,9 +20,41 @@ export class TupleDeconstructionStatement extends SlangNode { semicolon; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { + varKeyword, + openParen, + elements, + closeParen, + equal, + expression, + semicolon + } = ast; + this.varKeyword = varKeyword?.text; + this.openParen = openParen.text; + this.elements = new TupleDeconstructionElements( + elements, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.closeParen = closeParen.text; + this.equal = equal.text; + this.expression = new Expression( + expression, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.semicolon = semicolon.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/TupleExpression.js b/src/slang-nodes/TupleExpression.js index 409c98e3f..1a6102aac 100644 --- a/src/slang-nodes/TupleExpression.js +++ b/src/slang-nodes/TupleExpression.js @@ -1,4 +1,5 @@ import { SlangNode } from './SlangNode.js'; +import { TupleValues } from './TupleValues.js'; export class TupleExpression extends SlangNode { openParen; @@ -7,10 +8,23 @@ export class TupleExpression extends SlangNode { closeParen; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); if (offset) { - this.initialize(ast, offset, comments, parse); + const fetch = (childrenOffsets) => { + const { openParen, items, closeParen } = ast; + this.openParen = openParen.text; + this.items = new TupleValues( + items, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.closeParen = closeParen.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/TupleMember.js b/src/slang-nodes/TupleMember.js index d17866789..3637bac76 100644 --- a/src/slang-nodes/TupleMember.js +++ b/src/slang-nodes/TupleMember.js @@ -1,11 +1,27 @@ import { SlangNode } from './SlangNode.js'; +import { TypedTupleMember } from './TypedTupleMember.js'; +import { UntypedTupleMember } from './UntypedTupleMember.js'; + +const variants = { TypedTupleMember, UntypedTupleMember }; export class TupleMember extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { variant } = ast; + this.variant = new variants[variant.cst.kind]( + variant, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/TupleValue.js b/src/slang-nodes/TupleValue.js index 7bdb24927..ad5f3f3c9 100644 --- a/src/slang-nodes/TupleValue.js +++ b/src/slang-nodes/TupleValue.js @@ -1,12 +1,26 @@ import { SlangNode } from './SlangNode.js'; +import { Expression } from './Expression.js'; export class TupleValue extends SlangNode { expression; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); if (offset) { - this.initialize(ast, offset, comments, parse); + const fetch = (childrenOffsets) => { + const { expression } = ast; + if (expression) { + this.expression = new Expression( + expression, + childrenOffsets.shift(), + comments, + parse, + options + ); + } + }; + + this.initialize(ast, offset, comments, fetch, parse); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/TupleValues.js b/src/slang-nodes/TupleValues.js index 12fa102dd..6ca0eb961 100644 --- a/src/slang-nodes/TupleValues.js +++ b/src/slang-nodes/TupleValues.js @@ -1,16 +1,32 @@ import { printSeparatedList } from '../common/printer-helpers.js'; import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; import { SlangNode } from './SlangNode.js'; +import { TupleValue } from './TupleValue.js'; export class TupleValues extends SlangNode { items; separators; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); if (offset) { - this.initialize(ast, offset, comments, parse); + const fetch = (childrenOffsets) => { + const { items, separators } = ast; + this.items = items.map( + (item) => + new TupleValue( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + this.separators = separators.map((separator) => separator.text); + }; + + this.initialize(ast, offset, comments, fetch, parse); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/TypeExpression.js b/src/slang-nodes/TypeExpression.js index 3b3c04950..0f8594228 100644 --- a/src/slang-nodes/TypeExpression.js +++ b/src/slang-nodes/TypeExpression.js @@ -1,4 +1,5 @@ import { SlangNode } from './SlangNode.js'; +import { TypeName } from './TypeName.js'; export class TypeExpression extends SlangNode { typeKeyword; @@ -9,9 +10,24 @@ export class TypeExpression extends SlangNode { closeParen; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { typeKeyword, openParen, typeName, closeParen } = ast; + this.typeKeyword = typeKeyword.text; + this.openParen = openParen.text; + this.typeName = new TypeName( + typeName, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.closeParen = closeParen.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } // TODO: implement print diff --git a/src/slang-nodes/TypeName.js b/src/slang-nodes/TypeName.js index 6bcdad1c8..cb165e18e 100644 --- a/src/slang-nodes/TypeName.js +++ b/src/slang-nodes/TypeName.js @@ -1,11 +1,35 @@ import { SlangNode } from './SlangNode.js'; +import { ArrayTypeName } from './ArrayTypeName.js'; +import { FunctionType } from './FunctionType.js'; +import { MappingType } from './MappingType.js'; +import { ElementaryType } from './ElementaryType.js'; +import { IdentifierPath } from './IdentifierPath.js'; + +const variants = { + ArrayTypeName, + FunctionType, + MappingType, + ElementaryType, + IdentifierPath +}; export class TypeName extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + const fetch = (childrenOffsets) => { + const { variant } = ast; + this.variant = new variants[variant.cst.kind]( + variant, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/TypedTupleMember.js b/src/slang-nodes/TypedTupleMember.js index 908c572b0..44c4725e9 100644 --- a/src/slang-nodes/TypedTupleMember.js +++ b/src/slang-nodes/TypedTupleMember.js @@ -1,4 +1,6 @@ import { SlangNode } from './SlangNode.js'; +import { TypeName } from './TypeName.js'; +import { StorageLocation } from './StorageLocation.js'; export class TypedTupleMember extends SlangNode { typeName; @@ -7,9 +9,31 @@ export class TypedTupleMember extends SlangNode { name; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { typeName, storageLocation, name } = ast; + this.typeName = new TypeName( + typeName, + childrenOffsets.shift(), + comments, + parse, + options + ); + if (storageLocation) { + this.storageLocation = new StorageLocation( + storageLocation, + childrenOffsets.shift(), + comments, + parse, + options + ); + } + this.name = name.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/UncheckedBlock.js b/src/slang-nodes/UncheckedBlock.js index a1ad01812..a65588972 100644 --- a/src/slang-nodes/UncheckedBlock.js +++ b/src/slang-nodes/UncheckedBlock.js @@ -1,13 +1,27 @@ import { SlangNode } from './SlangNode.js'; +import { Block } from './Block.js'; export class UncheckedBlock extends SlangNode { uncheckedKeyword; block; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { uncheckedKeyword, block } = ast; + this.uncheckedKeyword = uncheckedKeyword.text; + this.block = new Block( + block, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/UnicodeStringLiteral.js b/src/slang-nodes/UnicodeStringLiteral.js index 3a4030afe..ac6f04f51 100644 --- a/src/slang-nodes/UnicodeStringLiteral.js +++ b/src/slang-nodes/UnicodeStringLiteral.js @@ -6,7 +6,13 @@ export class UnicodeStringLiteral extends SlangNode { constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = () => { + const { variant } = ast; + this.variant = variant.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); this.variant = `unicode${printString(this.variant.slice(8, -1), options)}`; } diff --git a/src/slang-nodes/UnicodeStringLiterals.js b/src/slang-nodes/UnicodeStringLiterals.js index 01c0fdf43..3ccdabcf1 100644 --- a/src/slang-nodes/UnicodeStringLiterals.js +++ b/src/slang-nodes/UnicodeStringLiterals.js @@ -1,14 +1,30 @@ import { doc } from 'prettier'; import { SlangNode } from './SlangNode.js'; +import { UnicodeStringLiteral } from './UnicodeStringLiteral.js'; const { join, hardline } = doc.builders; export class UnicodeStringLiterals extends SlangNode { items; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items } = ast; + this.items = items.map( + (item) => + new UnicodeStringLiteral( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/UnnamedFunctionAttribute.js b/src/slang-nodes/UnnamedFunctionAttribute.js index 872d67165..31061358b 100644 --- a/src/slang-nodes/UnnamedFunctionAttribute.js +++ b/src/slang-nodes/UnnamedFunctionAttribute.js @@ -1,11 +1,27 @@ import { SlangNode } from './SlangNode.js'; +import { ModifierInvocation } from './ModifierInvocation.js'; export class UnnamedFunctionAttribute extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { variant } = ast; + this.variant = + variant.type === 'Terminal' + ? variant.text + : new ModifierInvocation( + variant, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/UnnamedFunctionAttributes.js b/src/slang-nodes/UnnamedFunctionAttributes.js index 855953dc0..58e3bff5a 100644 --- a/src/slang-nodes/UnnamedFunctionAttributes.js +++ b/src/slang-nodes/UnnamedFunctionAttributes.js @@ -1,15 +1,31 @@ import { doc } from 'prettier'; import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; import { SlangNode } from './SlangNode.js'; +import { UnnamedFunctionAttribute } from './UnnamedFunctionAttribute.js'; const { line } = doc.builders; export class UnnamedFunctionAttributes extends SlangNode { items; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items } = ast; + this.items = items.map( + (item) => + new UnnamedFunctionAttribute( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); this.items = this.items.sort(sortFunctionAttributes); } diff --git a/src/slang-nodes/UnnamedFunctionDefinition.js b/src/slang-nodes/UnnamedFunctionDefinition.js index 2a41d04a7..04278f6cf 100644 --- a/src/slang-nodes/UnnamedFunctionDefinition.js +++ b/src/slang-nodes/UnnamedFunctionDefinition.js @@ -1,5 +1,8 @@ import { printFunction } from '../slang-printers/print-function.js'; import { SlangNode } from './SlangNode.js'; +import { ParametersDeclaration } from './ParametersDeclaration.js'; +import { UnnamedFunctionAttributes } from './UnnamedFunctionAttributes.js'; +import { FunctionBody } from './FunctionBody.js'; export class UnnamedFunctionDefinition extends SlangNode { functionKeyword; @@ -10,9 +13,36 @@ export class UnnamedFunctionDefinition extends SlangNode { body; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { functionKeyword, parameters, attributes, body } = ast; + this.functionKeyword = functionKeyword.text; + this.parameters = new ParametersDeclaration( + parameters, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.attributes = new UnnamedFunctionAttributes( + attributes, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.body = new FunctionBody( + body, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); this.cleanModifierInvocationArguments(); } diff --git a/src/slang-nodes/UntypedTupleMember.js b/src/slang-nodes/UntypedTupleMember.js index 0b7c198de..8538904fd 100644 --- a/src/slang-nodes/UntypedTupleMember.js +++ b/src/slang-nodes/UntypedTupleMember.js @@ -1,13 +1,30 @@ import { SlangNode } from './SlangNode.js'; +import { StorageLocation } from './StorageLocation.js'; export class UntypedTupleMember extends SlangNode { storageLocation; name; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { storageLocation, name } = ast; + + if (storageLocation) { + this.storageLocation = new StorageLocation( + storageLocation, + childrenOffsets.shift(), + comments, + parse, + options + ); + } + this.name = name.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } // TODO: implement print diff --git a/src/slang-nodes/UserDefinedValueTypeDefinition.js b/src/slang-nodes/UserDefinedValueTypeDefinition.js index dbbf7243c..e8bcf830d 100644 --- a/src/slang-nodes/UserDefinedValueTypeDefinition.js +++ b/src/slang-nodes/UserDefinedValueTypeDefinition.js @@ -1,4 +1,5 @@ import { SlangNode } from './SlangNode.js'; +import { ElementaryType } from './ElementaryType.js'; export class UserDefinedValueTypeDefinition extends SlangNode { typeKeyword; @@ -11,9 +12,25 @@ export class UserDefinedValueTypeDefinition extends SlangNode { semicolon; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { typeKeyword, name, isKeyword, valueType, semicolon } = ast; + this.typeKeyword = typeKeyword.text; + this.name = name.text; + this.isKeyword = isKeyword.text; + this.valueType = new ElementaryType( + valueType, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.semicolon = semicolon.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/UsingAlias.js b/src/slang-nodes/UsingAlias.js index 5086e7b08..4b7dc354d 100644 --- a/src/slang-nodes/UsingAlias.js +++ b/src/slang-nodes/UsingAlias.js @@ -1,13 +1,27 @@ import { SlangNode } from './SlangNode.js'; +import { UsingOperator } from './UsingOperator.js'; export class UsingAlias extends SlangNode { asKeyword; operator; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { asKeyword, operator } = ast; + this.asKeyword = asKeyword.text; + this.operator = new UsingOperator( + operator, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/UsingClause.js b/src/slang-nodes/UsingClause.js index 433fffddc..2206b1d22 100644 --- a/src/slang-nodes/UsingClause.js +++ b/src/slang-nodes/UsingClause.js @@ -1,11 +1,27 @@ import { SlangNode } from './SlangNode.js'; +import { IdentifierPath } from './IdentifierPath.js'; +import { UsingDeconstruction } from './UsingDeconstruction.js'; + +const variants = { IdentifierPath, UsingDeconstruction }; export class UsingClause extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { variant } = ast; + this.variant = new variants[variant.cst.kind]( + variant, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/UsingDeconstruction.js b/src/slang-nodes/UsingDeconstruction.js index eb9958229..20f5dd2cb 100644 --- a/src/slang-nodes/UsingDeconstruction.js +++ b/src/slang-nodes/UsingDeconstruction.js @@ -1,4 +1,5 @@ import { SlangNode } from './SlangNode.js'; +import { UsingDeconstructionSymbols } from './UsingDeconstructionSymbols.js'; export class UsingDeconstruction extends SlangNode { openBrace; @@ -7,9 +8,23 @@ export class UsingDeconstruction extends SlangNode { closeBrace; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { openBrace, symbols, closeBrace } = ast; + this.openBrace = openBrace.text; + this.symbols = new UsingDeconstructionSymbols( + symbols, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.closeBrace = closeBrace.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/UsingDeconstructionSymbol.js b/src/slang-nodes/UsingDeconstructionSymbol.js index b3f43e2b0..22232c054 100644 --- a/src/slang-nodes/UsingDeconstructionSymbol.js +++ b/src/slang-nodes/UsingDeconstructionSymbol.js @@ -1,13 +1,36 @@ import { SlangNode } from './SlangNode.js'; +import { IdentifierPath } from './IdentifierPath.js'; +import { UsingAlias } from './UsingAlias.js'; export class UsingDeconstructionSymbol extends SlangNode { name; alias; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { name, alias } = ast; + this.name = new IdentifierPath( + name, + childrenOffsets.shift(), + comments, + parse, + options + ); + if (alias) { + this.alias = new UsingAlias( + alias, + childrenOffsets.shift(), + comments, + parse, + options + ); + } + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/UsingDeconstructionSymbols.js b/src/slang-nodes/UsingDeconstructionSymbols.js index 91f025864..b9d99fcc2 100644 --- a/src/slang-nodes/UsingDeconstructionSymbols.js +++ b/src/slang-nodes/UsingDeconstructionSymbols.js @@ -1,6 +1,7 @@ import { doc } from 'prettier'; import { printSeparatedList } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; +import { UsingDeconstructionSymbol } from './UsingDeconstructionSymbol.js'; const { line, softline } = doc.builders; @@ -9,9 +10,25 @@ export class UsingDeconstructionSymbols extends SlangNode { separators; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items, separators } = ast; + this.items = items.map( + (item) => + new UsingDeconstructionSymbol( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + this.separators = separators.map((separator) => separator.text); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print, options) { diff --git a/src/slang-nodes/UsingDirective.js b/src/slang-nodes/UsingDirective.js index 6a1542f72..60154fa8a 100644 --- a/src/slang-nodes/UsingDirective.js +++ b/src/slang-nodes/UsingDirective.js @@ -1,4 +1,6 @@ import { SlangNode } from './SlangNode.js'; +import { UsingClause } from './UsingClause.js'; +import { UsingTarget } from './UsingTarget.js'; export class UsingDirective extends SlangNode { usingKeyword; @@ -13,9 +15,39 @@ export class UsingDirective extends SlangNode { semicolon; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { + usingKeyword, + clause, + forKeyword, + target, + globalKeyword, + semicolon + } = ast; + this.usingKeyword = usingKeyword.text; + this.clause = new UsingClause( + clause, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.forKeyword = forKeyword.text; + this.target = new UsingTarget( + target, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.globalKeyword = globalKeyword?.text; + this.semicolon = semicolon.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/UsingOperator.js b/src/slang-nodes/UsingOperator.js index 836af03ab..cac11fbfc 100644 --- a/src/slang-nodes/UsingOperator.js +++ b/src/slang-nodes/UsingOperator.js @@ -5,7 +5,13 @@ export class UsingOperator extends SlangNode { constructor(ast, offset, comments, parse) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = () => { + const { variant } = ast; + this.variant = variant.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print() { diff --git a/src/slang-nodes/UsingTarget.js b/src/slang-nodes/UsingTarget.js index 59b17120c..2a8eaaa55 100644 --- a/src/slang-nodes/UsingTarget.js +++ b/src/slang-nodes/UsingTarget.js @@ -1,11 +1,27 @@ import { SlangNode } from './SlangNode.js'; +import { TypeName } from './TypeName.js'; export class UsingTarget extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { variant } = ast; + this.variant = + variant.type === 'Terminal' + ? variant.text + : new TypeName( + variant, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/VariableDeclarationStatement.js b/src/slang-nodes/VariableDeclarationStatement.js index 4d145bc89..32e8a8c7f 100644 --- a/src/slang-nodes/VariableDeclarationStatement.js +++ b/src/slang-nodes/VariableDeclarationStatement.js @@ -1,5 +1,8 @@ import { doc } from 'prettier'; import { SlangNode } from './SlangNode.js'; +import { VariableDeclarationType } from './VariableDeclarationType.js'; +import { StorageLocation } from './StorageLocation.js'; +import { VariableDeclarationValue } from './VariableDeclarationValue.js'; const { group, indent, indentIfBreak, line } = doc.builders; @@ -14,9 +17,41 @@ export class VariableDeclarationStatement extends SlangNode { semicolon; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { variableType, storageLocation, name, value, semicolon } = ast; + this.variableType = new VariableDeclarationType( + variableType, + childrenOffsets.shift(), + comments, + parse, + options + ); + if (storageLocation) { + this.storageLocation = new StorageLocation( + storageLocation, + childrenOffsets.shift(), + comments, + parse, + options + ); + } + this.name = name.text; + if (value) { + this.value = new VariableDeclarationValue( + value, + childrenOffsets.shift(), + comments, + parse, + options + ); + } + this.semicolon = semicolon.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/VariableDeclarationType.js b/src/slang-nodes/VariableDeclarationType.js index f57c5f5de..859963ea0 100644 --- a/src/slang-nodes/VariableDeclarationType.js +++ b/src/slang-nodes/VariableDeclarationType.js @@ -1,11 +1,27 @@ import { SlangNode } from './SlangNode.js'; +import { TypeName } from './TypeName.js'; export class VariableDeclarationType extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { variant } = ast; + this.variant = + variant.type === 'Terminal' + ? variant.type + : new TypeName( + variant, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/VariableDeclarationValue.js b/src/slang-nodes/VariableDeclarationValue.js index 97adb1459..8ce1751c9 100644 --- a/src/slang-nodes/VariableDeclarationValue.js +++ b/src/slang-nodes/VariableDeclarationValue.js @@ -1,13 +1,27 @@ import { SlangNode } from './SlangNode.js'; +import { Expression } from './Expression.js'; export class VariableDeclarationValue extends SlangNode { equal; expression; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { equal, expression } = ast; + this.equal = equal.text; + this.expression = new Expression( + expression, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/VersionComparator.js b/src/slang-nodes/VersionComparator.js index 918ba836d..77b6a998f 100644 --- a/src/slang-nodes/VersionComparator.js +++ b/src/slang-nodes/VersionComparator.js @@ -1,13 +1,26 @@ import { SlangNode } from './SlangNode.js'; - +import { VersionExpression } from './VersionExpression.js'; export class VersionComparator extends SlangNode { operator; operand; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { operator, operand } = ast; + this.operator = operator.text; + this.operand = new VersionExpression( + operand, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/VersionExpression.js b/src/slang-nodes/VersionExpression.js index d546ba0c8..7dee4efe4 100644 --- a/src/slang-nodes/VersionExpression.js +++ b/src/slang-nodes/VersionExpression.js @@ -1,11 +1,35 @@ import { SlangNode } from './SlangNode.js'; +import { VersionRange } from './VersionRange.js'; +import { VersionComparator } from './VersionComparator.js'; +import { VersionSpecifiers } from './VersionSpecifiers.js'; + +const variants = { + VersionRange, + VersionComparator, + VersionSpecifiers +}; export class VersionExpression extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { variant } = ast; + this.variant = + variant.type === 'Terminal' + ? variant.text + : new variants[variant.cst.kind]( + variant, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/VersionExpressionSet.js b/src/slang-nodes/VersionExpressionSet.js index c5974e17e..c7767dac2 100644 --- a/src/slang-nodes/VersionExpressionSet.js +++ b/src/slang-nodes/VersionExpressionSet.js @@ -1,14 +1,30 @@ import { doc } from 'prettier'; import { SlangNode } from './SlangNode.js'; +import { VersionExpression } from './VersionExpression.js'; const { join } = doc.builders; export class VersionExpressionSet extends SlangNode { items; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items } = ast; + this.items = items.map( + (item) => + new VersionExpression( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/VersionExpressionSets.js b/src/slang-nodes/VersionExpressionSets.js index e55c6a6dd..7dc7faaad 100644 --- a/src/slang-nodes/VersionExpressionSets.js +++ b/src/slang-nodes/VersionExpressionSets.js @@ -1,13 +1,30 @@ import { SlangNode } from './SlangNode.js'; +import { VersionExpressionSet } from './VersionExpressionSet.js'; export class VersionExpressionSets extends SlangNode { items; separators; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items, separators } = ast; + this.items = items.map( + (item) => + new VersionExpressionSet( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + this.separators = separators.map((separator) => separator.text); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/VersionPragma.js b/src/slang-nodes/VersionPragma.js index 3e0c497c5..b6036431a 100644 --- a/src/slang-nodes/VersionPragma.js +++ b/src/slang-nodes/VersionPragma.js @@ -1,13 +1,27 @@ import { SlangNode } from './SlangNode.js'; +import { VersionExpressionSets } from './VersionExpressionSets.js'; export class VersionPragma extends SlangNode { solidityKeyword; sets; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { solidityKeyword, sets } = ast; + this.solidityKeyword = solidityKeyword.text; + this.sets = new VersionExpressionSets( + sets, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/VersionRange.js b/src/slang-nodes/VersionRange.js index b2404a765..d083318e1 100644 --- a/src/slang-nodes/VersionRange.js +++ b/src/slang-nodes/VersionRange.js @@ -1,4 +1,5 @@ import { SlangNode } from './SlangNode.js'; +import { VersionExpression } from './VersionExpression.js'; export class VersionRange extends SlangNode { leftOperand; @@ -7,9 +8,29 @@ export class VersionRange extends SlangNode { rightOperand; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { leftOperand, operator, rightOperand } = ast; + this.leftOperand = new VersionExpression( + leftOperand, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.operator = operator.text; + this.rightOperand = new VersionExpression( + rightOperand, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } // TODO: implement print diff --git a/src/slang-nodes/VersionSpecifiers.js b/src/slang-nodes/VersionSpecifiers.js index efc2a3c5a..275863137 100644 --- a/src/slang-nodes/VersionSpecifiers.js +++ b/src/slang-nodes/VersionSpecifiers.js @@ -7,7 +7,14 @@ export class VersionSpecifiers extends SlangNode { constructor(ast, offset, comments, parse) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = () => { + const { items, separators } = ast; + this.items = items.map((item) => item.text); + this.separators = separators.map((separator) => separator.text); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print() { diff --git a/src/slang-nodes/WhileStatement.js b/src/slang-nodes/WhileStatement.js index cb50acc67..8856a83cd 100644 --- a/src/slang-nodes/WhileStatement.js +++ b/src/slang-nodes/WhileStatement.js @@ -1,6 +1,8 @@ import { doc } from 'prettier'; import { printSeparatedItem } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; +import { Expression } from './Expression.js'; +import { Statement } from './Statement.js'; const { group, indent, line } = doc.builders; @@ -15,9 +17,31 @@ export class WhileStatement extends SlangNode { body; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { whileKeyword, openParen, condition, closeParen, body } = ast; + this.whileKeyword = whileKeyword.text; + this.openParen = openParen.text; + this.condition = new Expression( + condition, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.closeParen = closeParen.text; + this.body = new Statement( + body, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/YulArguments.js b/src/slang-nodes/YulArguments.js index 70d0025cd..c9494516d 100644 --- a/src/slang-nodes/YulArguments.js +++ b/src/slang-nodes/YulArguments.js @@ -1,14 +1,31 @@ import { printSeparatedList } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; +import { YulExpression } from './YulExpression.js'; export class YulArguments extends SlangNode { items; separators; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items, separators } = ast; + this.items = items.map( + (item) => + new YulExpression( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + this.separators = separators.map((separator) => separator.text); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/YulAssignmentOperator.js b/src/slang-nodes/YulAssignmentOperator.js index f50a58c8b..6401d984a 100644 --- a/src/slang-nodes/YulAssignmentOperator.js +++ b/src/slang-nodes/YulAssignmentOperator.js @@ -1,11 +1,27 @@ import { SlangNode } from './SlangNode.js'; +import { YulColonEqual } from './YulColonEqual.js'; export class YulAssignmentOperator extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { variant } = ast; + this.variant = + variant.type === 'Terminal' + ? variant.text + : new YulColonEqual( + variant, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/YulAssignmentStatement.js b/src/slang-nodes/YulAssignmentStatement.js deleted file mode 100644 index 7a7e02ad3..000000000 --- a/src/slang-nodes/YulAssignmentStatement.js +++ /dev/null @@ -1,24 +0,0 @@ -import { SlangNode } from './SlangNode.js'; - -export class YulAssignmentStatement extends SlangNode { - names; - - assignment; - - expression; - - constructor(ast, offset, comments, parse) { - super(); - this.initialize(ast, offset, comments, parse); - } - - print(path, print) { - return [ - path.call(print, 'names'), - ' ', - path.call(print, 'assignment'), - ' ', - path.call(print, 'expression') - ]; - } -} diff --git a/src/slang-nodes/YulBlock.js b/src/slang-nodes/YulBlock.js index 710aae7c6..eb89e2346 100644 --- a/src/slang-nodes/YulBlock.js +++ b/src/slang-nodes/YulBlock.js @@ -1,4 +1,5 @@ import { SlangNode } from './SlangNode.js'; +import { YulStatements } from './YulStatements.js'; export class YulBlock extends SlangNode { openBrace; @@ -7,9 +8,23 @@ export class YulBlock extends SlangNode { closeBrace; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { openBrace, statements, closeBrace } = ast; + this.openBrace = openBrace.text; + this.statements = new YulStatements( + statements, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.closeBrace = closeBrace.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/YulBreakStatement.js b/src/slang-nodes/YulBreakStatement.js index c2dd43d33..fd29172bf 100644 --- a/src/slang-nodes/YulBreakStatement.js +++ b/src/slang-nodes/YulBreakStatement.js @@ -5,7 +5,13 @@ export class YulBreakStatement extends SlangNode { constructor(ast, offset, comments, parse) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = () => { + const { breakKeyword } = ast; + this.breakKeyword = breakKeyword.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print() { diff --git a/src/slang-nodes/YulBuiltInFunction.js b/src/slang-nodes/YulBuiltInFunction.js index 4c9dce649..93071e372 100644 --- a/src/slang-nodes/YulBuiltInFunction.js +++ b/src/slang-nodes/YulBuiltInFunction.js @@ -5,7 +5,13 @@ export class YulBuiltInFunction extends SlangNode { constructor(ast, offset, comments, parse) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = () => { + const { variant } = ast; + this.variant = variant.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print() { diff --git a/src/slang-nodes/YulColonAndEqual.js b/src/slang-nodes/YulColonAndEqual.js deleted file mode 100644 index 68db3af28..000000000 --- a/src/slang-nodes/YulColonAndEqual.js +++ /dev/null @@ -1,17 +0,0 @@ -import { SlangNode } from './SlangNode.js'; - -export class YulColonAndEqual extends SlangNode { - colon; - - equal; - - constructor(ast, offset, comments, parse) { - super(); - this.initialize(ast, offset, comments, parse); - } - - // TODO: implement print - print(path, print, options) { - return ['TODO: YulColonAndEqual']; - } -} diff --git a/src/slang-nodes/YulColonEqual.js b/src/slang-nodes/YulColonEqual.js new file mode 100644 index 000000000..308cdd3d7 --- /dev/null +++ b/src/slang-nodes/YulColonEqual.js @@ -0,0 +1,24 @@ +import { SlangNode } from './SlangNode.js'; + +export class YulColonEqual extends SlangNode { + colon; + + equal; + + constructor(ast, offset, comments, parse) { + super(); + + const fetch = () => { + const { colon, equal } = ast; + this.colon = colon.text; + this.equal = equal.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); + } + + // TODO: implement print + print(path, print, options) { + return ['TODO: YulColonEqual']; + } +} diff --git a/src/slang-nodes/YulContinueStatement.js b/src/slang-nodes/YulContinueStatement.js index b73020a1e..2200767fa 100644 --- a/src/slang-nodes/YulContinueStatement.js +++ b/src/slang-nodes/YulContinueStatement.js @@ -5,7 +5,13 @@ export class YulContinueStatement extends SlangNode { constructor(ast, offset, comments, parse) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = () => { + const { continueKeyword } = ast; + this.continueKeyword = continueKeyword.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print() { diff --git a/src/slang-nodes/YulDefaultCase.js b/src/slang-nodes/YulDefaultCase.js index a09625c4c..d3c076d71 100644 --- a/src/slang-nodes/YulDefaultCase.js +++ b/src/slang-nodes/YulDefaultCase.js @@ -1,13 +1,27 @@ import { SlangNode } from './SlangNode.js'; +import { YulBlock } from './YulBlock.js'; export class YulDefaultCase extends SlangNode { defaultKeyword; body; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { defaultKeyword, body } = ast; + this.defaultKeyword = defaultKeyword.text; + this.body = new YulBlock( + body, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/YulExpression.js b/src/slang-nodes/YulExpression.js index e591f414d..e7701ebb5 100644 --- a/src/slang-nodes/YulExpression.js +++ b/src/slang-nodes/YulExpression.js @@ -1,11 +1,34 @@ import { SlangNode } from './SlangNode.js'; +import { YulFunctionCallExpression } from './YulFunctionCallExpression.js'; +import { YulLiteral } from './YulLiteral.js'; +import { YulBuiltInFunction } from './YulBuiltInFunction.js'; +import { YulPath } from './YulPath.js'; + +const variants = { + YulFunctionCallExpression, + YulLiteral, + YulBuiltInFunction, + YulPath +}; export class YulExpression extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { variant } = ast; + this.variant = new variants[variant.cst.kind]( + variant, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/YulForStatement.js b/src/slang-nodes/YulForStatement.js index 575cbad49..7adb010b6 100644 --- a/src/slang-nodes/YulForStatement.js +++ b/src/slang-nodes/YulForStatement.js @@ -1,4 +1,6 @@ import { SlangNode } from './SlangNode.js'; +import { YulBlock } from './YulBlock.js'; +import { YulExpression } from './YulExpression.js'; export class YulForStatement extends SlangNode { forKeyword; @@ -11,9 +13,43 @@ export class YulForStatement extends SlangNode { body; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { forKeyword, initialization, condition, iterator, body } = ast; + this.forKeyword = forKeyword.text; + this.initialization = new YulBlock( + initialization, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.condition = new YulExpression( + condition, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.iterator = new YulBlock( + iterator, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.body = new YulBlock( + body, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/YulFunctionCallExpression.js b/src/slang-nodes/YulFunctionCallExpression.js index 856d61c34..2ec41d788 100644 --- a/src/slang-nodes/YulFunctionCallExpression.js +++ b/src/slang-nodes/YulFunctionCallExpression.js @@ -1,4 +1,6 @@ import { SlangNode } from './SlangNode.js'; +import { YulExpression } from './YulExpression.js'; +import { YulArguments } from './YulArguments.js'; export class YulFunctionCallExpression extends SlangNode { operand; @@ -9,9 +11,30 @@ export class YulFunctionCallExpression extends SlangNode { closeParen; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { operand, openParen, closeParen } = ast; + this.operand = new YulExpression( + operand, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.openParen = openParen.text; + this.arguments = new YulArguments( + ast.arguments, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.closeParen = closeParen.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/YulFunctionDefinition.js b/src/slang-nodes/YulFunctionDefinition.js index 9eaa1f7fb..872cea5cc 100644 --- a/src/slang-nodes/YulFunctionDefinition.js +++ b/src/slang-nodes/YulFunctionDefinition.js @@ -1,4 +1,7 @@ import { SlangNode } from './SlangNode.js'; +import { YulParametersDeclaration } from './YulParametersDeclaration.js'; +import { YulReturnsDeclaration } from './YulReturnsDeclaration.js'; +import { YulBlock } from './YulBlock.js'; export class YulFunctionDefinition extends SlangNode { functionKeyword; @@ -11,9 +14,39 @@ export class YulFunctionDefinition extends SlangNode { body; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { functionKeyword, name, parameters, returns, body } = ast; + this.functionKeyword = functionKeyword.text; + this.name = name.text; + this.parameters = new YulParametersDeclaration( + parameters, + childrenOffsets.shift(), + comments, + parse, + options + ); + if (returns) { + this.returns = new YulReturnsDeclaration( + returns, + childrenOffsets.shift(), + comments, + parse, + options + ); + } + this.body = new YulBlock( + body, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/YulIfStatement.js b/src/slang-nodes/YulIfStatement.js index cc9b60dc5..cadc0ad7b 100644 --- a/src/slang-nodes/YulIfStatement.js +++ b/src/slang-nodes/YulIfStatement.js @@ -1,4 +1,6 @@ import { SlangNode } from './SlangNode.js'; +import { YulExpression } from './YulExpression.js'; +import { YulBlock } from './YulBlock.js'; export class YulIfStatement extends SlangNode { ifKeyword; @@ -7,9 +9,29 @@ export class YulIfStatement extends SlangNode { body; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { ifKeyword, condition, body } = ast; + this.ifKeyword = ifKeyword.text; + this.condition = new YulExpression( + condition, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.body = new YulBlock( + body, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/YulLabel.js b/src/slang-nodes/YulLabel.js index 2f2bb9dbb..2cade36fe 100644 --- a/src/slang-nodes/YulLabel.js +++ b/src/slang-nodes/YulLabel.js @@ -10,7 +10,14 @@ export class YulLabel extends SlangNode { constructor(ast, offset, comments, parse) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = () => { + const { label, colon } = ast; + this.label = label.text; + this.colon = colon.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print() { diff --git a/src/slang-nodes/YulLeaveStatement.js b/src/slang-nodes/YulLeaveStatement.js index dac0d01ff..3e614ed9a 100644 --- a/src/slang-nodes/YulLeaveStatement.js +++ b/src/slang-nodes/YulLeaveStatement.js @@ -5,7 +5,13 @@ export class YulLeaveStatement extends SlangNode { constructor(ast, offset, comments, parse) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = () => { + const { leaveKeyword } = ast; + this.leaveKeyword = leaveKeyword.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } // TODO: implement print diff --git a/src/slang-nodes/YulLiteral.js b/src/slang-nodes/YulLiteral.js index 0a455bd39..eb8bbc2c5 100644 --- a/src/slang-nodes/YulLiteral.js +++ b/src/slang-nodes/YulLiteral.js @@ -1,11 +1,30 @@ import { SlangNode } from './SlangNode.js'; +import { HexStringLiteral } from './HexStringLiteral.js'; +import { StringLiteral } from './StringLiteral.js'; + +const variants = { HexStringLiteral, StringLiteral }; export class YulLiteral extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { variant } = ast; + this.variant = + variant.type === 'Terminal' + ? variant.text + : new variants[variant.cst.kind]( + variant, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/YulParameters.js b/src/slang-nodes/YulParameters.js index 861b29021..fb19e39c1 100644 --- a/src/slang-nodes/YulParameters.js +++ b/src/slang-nodes/YulParameters.js @@ -8,7 +8,14 @@ export class YulParameters extends SlangNode { constructor(ast, offset, comments, parse) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = () => { + const { items, separators } = ast; + this.items = items.map((item) => item.text); + this.separators = separators.map((separator) => separator.text); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print() { diff --git a/src/slang-nodes/YulParametersDeclaration.js b/src/slang-nodes/YulParametersDeclaration.js index 6601c4169..a78f1b5a4 100644 --- a/src/slang-nodes/YulParametersDeclaration.js +++ b/src/slang-nodes/YulParametersDeclaration.js @@ -1,4 +1,5 @@ import { SlangNode } from './SlangNode.js'; +import { YulParameters } from './YulParameters.js'; export class YulParametersDeclaration extends SlangNode { openParen; @@ -7,9 +8,23 @@ export class YulParametersDeclaration extends SlangNode { closeParen; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { openParen, parameters, closeParen } = ast; + this.openParen = openParen.text; + this.parameters = new YulParameters( + parameters, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.closeParen = closeParen.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/YulPath.js b/src/slang-nodes/YulPath.js index 3058a68cc..f5d5a97b7 100644 --- a/src/slang-nodes/YulPath.js +++ b/src/slang-nodes/YulPath.js @@ -1,13 +1,30 @@ import { SlangNode } from './SlangNode.js'; +import { YulPathComponent } from './YulPathComponent.js'; export class YulPath extends SlangNode { items; separators; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items, separators } = ast; + this.items = items.map( + (item) => + new YulPathComponent( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + this.separators = separators.map((separator) => separator.text); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/YulPathComponent.js b/src/slang-nodes/YulPathComponent.js index d359c4d26..a7018c23e 100644 --- a/src/slang-nodes/YulPathComponent.js +++ b/src/slang-nodes/YulPathComponent.js @@ -5,7 +5,13 @@ export class YulPathComponent extends SlangNode { constructor(ast, offset, comments, parse) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = () => { + const { variant } = ast; + this.variant = variant.text; + }; + + this.initialize(ast, offset, comments, fetch, parse); } print() { diff --git a/src/slang-nodes/YulPaths.js b/src/slang-nodes/YulPaths.js index 983a9f30b..34175c6c2 100644 --- a/src/slang-nodes/YulPaths.js +++ b/src/slang-nodes/YulPaths.js @@ -1,13 +1,24 @@ import { SlangNode } from './SlangNode.js'; +import { YulPath } from './YulPath.js'; export class YulPaths extends SlangNode { items; separators; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items, separators } = ast; + this.items = items.map( + (item) => + new YulPath(item, childrenOffsets.shift(), comments, parse, options) + ); + this.separators = separators.map((separator) => separator.text); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/YulReturnVariables.js b/src/slang-nodes/YulReturnVariables.js index 39ab38c3c..90fc5393b 100644 --- a/src/slang-nodes/YulReturnVariables.js +++ b/src/slang-nodes/YulReturnVariables.js @@ -11,7 +11,14 @@ export class YulReturnVariables extends SlangNode { constructor(ast, offset, comments, parse) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = () => { + const { items, separators } = ast; + this.items = items.map((item) => item.text); + this.separators = separators.map((separator) => separator.text); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print() { diff --git a/src/slang-nodes/YulReturnsDeclaration.js b/src/slang-nodes/YulReturnsDeclaration.js index 83a3be111..be674879e 100644 --- a/src/slang-nodes/YulReturnsDeclaration.js +++ b/src/slang-nodes/YulReturnsDeclaration.js @@ -1,6 +1,7 @@ import { doc } from 'prettier'; import { printSeparatedItem } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; +import { YulReturnVariables } from './YulReturnVariables.js'; const { line } = doc.builders; @@ -9,9 +10,22 @@ export class YulReturnsDeclaration extends SlangNode { variables; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { minusGreaterThan, variables } = ast; + this.minusGreaterThan = minusGreaterThan.text; + this.variables = new YulReturnVariables( + variables, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/YulStackAssignmentStatement.js b/src/slang-nodes/YulStackAssignmentStatement.js new file mode 100644 index 000000000..34805ee9a --- /dev/null +++ b/src/slang-nodes/YulStackAssignmentStatement.js @@ -0,0 +1,38 @@ +import { SlangNode } from './SlangNode.js'; +import { YulAssignmentOperator } from './YulAssignmentOperator.js'; +import { YulExpression } from './YulExpression.js'; + +export class YulStackAssignmentStatement extends SlangNode { + assignment; + + expression; + + constructor(ast, offset, comments, parse, options) { + super(); + + const fetch = (childrenOffsets) => { + const { assignment, expression } = ast; + this.assignment = new YulAssignmentOperator( + assignment, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.expression = new YulExpression( + expression, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); + } + + // TODO: implement print + print(path, print, options) { + return ['TODO: YulStackAssignmentStatement']; + } +} diff --git a/src/slang-nodes/YulStatement.js b/src/slang-nodes/YulStatement.js index 6403f4f15..7ceafb49a 100644 --- a/src/slang-nodes/YulStatement.js +++ b/src/slang-nodes/YulStatement.js @@ -1,11 +1,52 @@ import { SlangNode } from './SlangNode.js'; +import { YulBlock } from './YulBlock.js'; +import { YulFunctionDefinition } from './YulFunctionDefinition.js'; +import { YulVariableDeclarationStatement } from './YulVariableDeclarationStatement.js'; +import { YulVariableAssignmentStatement } from './YulVariableAssignmentStatement.js'; +import { YulStackAssignmentStatement } from './YulStackAssignmentStatement.js'; +import { YulIfStatement } from './YulIfStatement.js'; +import { YulForStatement } from './YulForStatement.js'; +import { YulSwitchStatement } from './YulSwitchStatement.js'; +import { YulLeaveStatement } from './YulLeaveStatement.js'; +import { YulBreakStatement } from './YulBreakStatement.js'; +import { YulContinueStatement } from './YulContinueStatement.js'; +import { YulLabel } from './YulLabel.js'; +import { YulExpression } from './YulExpression.js'; + +const variants = { + YulBlock, + YulFunctionDefinition, + YulVariableDeclarationStatement, + YulVariableAssignmentStatement, + YulStackAssignmentStatement, + YulIfStatement, + YulForStatement, + YulSwitchStatement, + YulLeaveStatement, + YulBreakStatement, + YulContinueStatement, + YulLabel, + YulExpression +}; export class YulStatement extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { variant } = ast; + this.variant = new variants[variant.cst.kind]( + variant, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/YulStatements.js b/src/slang-nodes/YulStatements.js index a9ae8bd88..b4dab32f4 100644 --- a/src/slang-nodes/YulStatements.js +++ b/src/slang-nodes/YulStatements.js @@ -3,15 +3,31 @@ import { printSeparatedItem } from '../common/printer-helpers.js'; import { printComments } from '../slang-printers/print-comments.js'; import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; import { SlangNode } from './SlangNode.js'; +import { YulStatement } from './YulStatement.js'; const { hardline } = doc.builders; export class YulStatements extends SlangNode { items; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items } = ast; + this.items = items.map( + (item) => + new YulStatement( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print, options) { diff --git a/src/slang-nodes/YulSwitchCase.js b/src/slang-nodes/YulSwitchCase.js index 6475ce2bb..7e38cceee 100644 --- a/src/slang-nodes/YulSwitchCase.js +++ b/src/slang-nodes/YulSwitchCase.js @@ -1,11 +1,26 @@ import { SlangNode } from './SlangNode.js'; +import { YulDefaultCase } from './YulDefaultCase.js'; +import { YulValueCase } from './YulValueCase.js'; +const variants = { YulDefaultCase, YulValueCase }; export class YulSwitchCase extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { variant } = ast; + this.variant = new variants[variant.cst.kind]( + variant, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/YulSwitchCases.js b/src/slang-nodes/YulSwitchCases.js index 2a3a25a90..6e8ff986a 100644 --- a/src/slang-nodes/YulSwitchCases.js +++ b/src/slang-nodes/YulSwitchCases.js @@ -1,14 +1,30 @@ import { doc } from 'prettier'; import { SlangNode } from './SlangNode.js'; +import { YulSwitchCase } from './YulSwitchCase.js'; const { hardline, join } = doc.builders; export class YulSwitchCases extends SlangNode { items; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { items } = ast; + this.items = items.map( + (item) => + new YulSwitchCase( + item, + childrenOffsets.shift(), + comments, + parse, + options + ) + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/YulSwitchStatement.js b/src/slang-nodes/YulSwitchStatement.js index 123f07f3b..075e57b6e 100644 --- a/src/slang-nodes/YulSwitchStatement.js +++ b/src/slang-nodes/YulSwitchStatement.js @@ -1,5 +1,7 @@ import { doc } from 'prettier'; import { SlangNode } from './SlangNode.js'; +import { YulExpression } from './YulExpression.js'; +import { YulSwitchCases } from './YulSwitchCases.js'; const { hardline } = doc.builders; @@ -10,9 +12,29 @@ export class YulSwitchStatement extends SlangNode { cases; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { switchKeyword, expression, cases } = ast; + this.switchKeyword = switchKeyword.text; + this.expression = new YulExpression( + expression, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.cases = new YulSwitchCases( + cases, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/YulValueCase.js b/src/slang-nodes/YulValueCase.js index 78bd727d7..6afc3880a 100644 --- a/src/slang-nodes/YulValueCase.js +++ b/src/slang-nodes/YulValueCase.js @@ -1,4 +1,6 @@ import { SlangNode } from './SlangNode.js'; +import { YulLiteral } from './YulLiteral.js'; +import { YulBlock } from './YulBlock.js'; export class YulValueCase extends SlangNode { caseKeyword; @@ -7,9 +9,29 @@ export class YulValueCase extends SlangNode { body; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { caseKeyword, value, body } = ast; + this.caseKeyword = caseKeyword.text; + this.value = new YulLiteral( + value, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.body = new YulBlock( + body, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/YulVariableAssignmentStatement.js b/src/slang-nodes/YulVariableAssignmentStatement.js index cff1ebc6f..73dc76d11 100644 --- a/src/slang-nodes/YulVariableAssignmentStatement.js +++ b/src/slang-nodes/YulVariableAssignmentStatement.js @@ -1,4 +1,7 @@ import { SlangNode } from './SlangNode.js'; +import { YulPaths } from './YulPaths.js'; +import { YulAssignmentOperator } from './YulAssignmentOperator.js'; +import { YulExpression } from './YulExpression.js'; export class YulVariableAssignmentStatement extends SlangNode { names; @@ -7,9 +10,35 @@ export class YulVariableAssignmentStatement extends SlangNode { expression; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { names, assignment, expression } = ast; + this.names = new YulPaths( + names, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.assignment = new YulAssignmentOperator( + assignment, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.expression = new YulExpression( + expression, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/YulVariableDeclarationStatement.js b/src/slang-nodes/YulVariableDeclarationStatement.js index f0b5dbcb9..ef06a2c9f 100644 --- a/src/slang-nodes/YulVariableDeclarationStatement.js +++ b/src/slang-nodes/YulVariableDeclarationStatement.js @@ -1,4 +1,5 @@ import { SlangNode } from './SlangNode.js'; +import { YulVariableDeclarationValue } from './YulVariableDeclarationValue.js'; export class YulVariableDeclarationStatement extends SlangNode { letKeyword; @@ -7,9 +8,25 @@ export class YulVariableDeclarationStatement extends SlangNode { value; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { letKeyword, names, value } = ast; + this.letKeyword = letKeyword.text; + this.names = names.text; + if (value) { + this.value = new YulVariableDeclarationValue( + value, + childrenOffsets.shift(), + comments, + parse, + options + ); + } + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/YulVariableDeclarationValue.js b/src/slang-nodes/YulVariableDeclarationValue.js index f21807719..91c8b11cb 100644 --- a/src/slang-nodes/YulVariableDeclarationValue.js +++ b/src/slang-nodes/YulVariableDeclarationValue.js @@ -1,13 +1,34 @@ import { SlangNode } from './SlangNode.js'; +import { YulAssignmentOperator } from './YulAssignmentOperator.js'; +import { YulExpression } from './YulExpression.js'; export class YulVariableDeclarationValue extends SlangNode { assignment; expression; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments, parse, options) { super(); - this.initialize(ast, offset, comments, parse); + + const fetch = (childrenOffsets) => { + const { assignment, expression } = ast; + this.assignment = new YulAssignmentOperator( + assignment, + childrenOffsets.shift(), + comments, + parse, + options + ); + this.expression = new YulExpression( + expression, + childrenOffsets.shift(), + comments, + parse, + options + ); + }; + + this.initialize(ast, offset, comments, fetch, parse); } print(path, print) { diff --git a/src/slang-nodes/index.js b/src/slang-nodes/index.js index d5d9083ae..f25097c65 100644 --- a/src/slang-nodes/index.js +++ b/src/slang-nodes/index.js @@ -1,3 +1,7 @@ +export * from './YulStatement.js'; +export * from './Expression.js'; +export * from './Statement.js'; + export * from './ABICoderPragma.js'; export * from './AdditiveExpression.js'; export * from './AddressType.js'; @@ -49,7 +53,6 @@ export * from './EventParametersDeclaration.js'; export * from './ExperimentalFeature.js'; export * from './ExperimentalPragma.js'; export * from './ExponentiationExpression.js'; -export * from './Expression.js'; export * from './ExpressionStatement.js'; export * from './FallbackFunctionAttribute.js'; export * from './FallbackFunctionAttributes.js'; @@ -128,7 +131,6 @@ export * from './ShiftExpression.js'; export * from './SourceUnit.js'; export * from './SourceUnitMember.js'; export * from './SourceUnitMembers.js'; -export * from './Statement.js'; export * from './Statements.js'; export * from './StateVariableAttribute.js'; export * from './StateVariableAttributes.js'; @@ -182,11 +184,10 @@ export * from './VersionSpecifiers.js'; export * from './WhileStatement.js'; export * from './YulArguments.js'; export * from './YulAssignmentOperator.js'; -export * from './YulAssignmentStatement.js'; export * from './YulBlock.js'; export * from './YulBreakStatement.js'; export * from './YulBuiltInFunction.js'; -export * from './YulColonAndEqual.js'; +export * from './YulColonEqual.js'; export * from './YulContinueStatement.js'; export * from './YulDefaultCase.js'; export * from './YulExpression.js'; @@ -204,7 +205,7 @@ export * from './YulPathComponent.js'; export * from './YulPaths.js'; export * from './YulReturnsDeclaration.js'; export * from './YulReturnVariables.js'; -export * from './YulStatement.js'; +export * from './YulStackAssignmentStatement.js'; export * from './YulStatements.js'; export * from './YulSwitchCase.js'; export * from './YulSwitchCases.js'; From 5629e5153662907af4f91b84f4a97762815e9ff8 Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 17 Jul 2024 17:04:40 +1200 Subject: [PATCH 086/160] cleaning up parse function --- src/slang-nodes/ABICoderPragma.js | 4 ++-- src/slang-nodes/AdditiveExpression.js | 6 ++---- src/slang-nodes/AddressType.js | 4 ++-- src/slang-nodes/AndExpression.js | 6 ++---- src/slang-nodes/ArgumentsDeclaration.js | 5 ++--- src/slang-nodes/ArrayExpression.js | 5 ++--- src/slang-nodes/ArrayTypeName.js | 6 ++---- src/slang-nodes/ArrayValues.js | 12 +++--------- src/slang-nodes/AssemblyFlags.js | 12 +++--------- src/slang-nodes/AssemblyFlagsDeclaration.js | 5 ++--- src/slang-nodes/AssemblyStatement.js | 7 ++----- src/slang-nodes/AssignmentExpression.js | 6 ++---- src/slang-nodes/BitwiseAndExpression.js | 6 ++---- src/slang-nodes/BitwiseOrExpression.js | 6 ++---- src/slang-nodes/BitwiseXorExpression.js | 6 ++---- src/slang-nodes/Block.js | 5 ++--- src/slang-nodes/BreakStatement.js | 4 ++-- src/slang-nodes/CallOptions.js | 12 +++--------- src/slang-nodes/CallOptionsExpression.js | 6 ++---- src/slang-nodes/CatchClause.js | 13 +++---------- src/slang-nodes/CatchClauseError.js | 5 ++--- src/slang-nodes/CatchClauses.js | 12 +++--------- src/slang-nodes/ComparisonExpression.js | 6 ++---- src/slang-nodes/ConditionalExpression.js | 7 ++----- src/slang-nodes/ConstantDefinition.js | 6 ++---- src/slang-nodes/ConstructorAttribute.js | 5 ++--- src/slang-nodes/ConstructorAttributes.js | 5 ++--- src/slang-nodes/ConstructorDefinition.js | 14 +++----------- src/slang-nodes/ContinueStatement.js | 4 ++-- src/slang-nodes/ContractDefinition.js | 6 ++---- src/slang-nodes/ContractMember.js | 5 ++--- src/slang-nodes/ContractMembers.js | 12 +++--------- src/slang-nodes/DecimalNumberExpression.js | 5 ++--- src/slang-nodes/DoWhileStatement.js | 6 ++---- src/slang-nodes/ElementaryType.js | 5 ++--- src/slang-nodes/ElseBranch.js | 5 ++--- src/slang-nodes/EmitStatement.js | 6 ++---- src/slang-nodes/EnumDefinition.js | 5 ++--- src/slang-nodes/EnumMembers.js | 4 ++-- src/slang-nodes/EqualityExpression.js | 6 ++---- src/slang-nodes/ErrorDefinition.js | 5 ++--- src/slang-nodes/ErrorParameter.js | 5 ++--- src/slang-nodes/ErrorParameters.js | 12 +++--------- src/slang-nodes/ErrorParametersDeclaration.js | 5 ++--- src/slang-nodes/EventDefinition.js | 5 ++--- src/slang-nodes/EventParameter.js | 5 ++--- src/slang-nodes/EventParameters.js | 12 +++--------- src/slang-nodes/EventParametersDeclaration.js | 5 ++--- src/slang-nodes/ExperimentalFeature.js | 5 ++--- src/slang-nodes/ExperimentalPragma.js | 5 ++--- src/slang-nodes/ExponentiationExpression.js | 6 ++---- src/slang-nodes/Expression.js | 5 ++--- src/slang-nodes/ExpressionStatement.js | 5 ++--- src/slang-nodes/FallbackFunctionAttribute.js | 5 ++--- src/slang-nodes/FallbackFunctionAttributes.js | 5 ++--- src/slang-nodes/FallbackFunctionDefinition.js | 8 ++------ src/slang-nodes/ForStatement.js | 8 ++------ src/slang-nodes/ForStatementCondition.js | 5 ++--- src/slang-nodes/ForStatementInitialization.js | 5 ++--- src/slang-nodes/FunctionAttribute.js | 5 ++--- src/slang-nodes/FunctionAttributes.js | 5 ++--- src/slang-nodes/FunctionBody.js | 12 +++--------- src/slang-nodes/FunctionCallExpression.js | 6 ++---- src/slang-nodes/FunctionDefinition.js | 9 ++------- src/slang-nodes/FunctionName.js | 4 ++-- src/slang-nodes/FunctionType.js | 7 ++----- src/slang-nodes/FunctionTypeAttribute.js | 4 ++-- src/slang-nodes/FunctionTypeAttributes.js | 5 ++--- src/slang-nodes/HexNumberExpression.js | 5 ++--- src/slang-nodes/HexStringLiteral.js | 4 ++-- src/slang-nodes/HexStringLiterals.js | 12 +++--------- src/slang-nodes/IdentifierPath.js | 4 ++-- src/slang-nodes/IfStatement.js | 7 ++----- src/slang-nodes/ImportAlias.js | 4 ++-- src/slang-nodes/ImportClause.js | 5 ++--- src/slang-nodes/ImportDeconstruction.js | 6 ++---- src/slang-nodes/ImportDeconstructionSymbol.js | 12 +++--------- src/slang-nodes/ImportDeconstructionSymbols.js | 5 ++--- src/slang-nodes/ImportDirective.js | 5 ++--- src/slang-nodes/IndexAccessEnd.js | 5 ++--- src/slang-nodes/IndexAccessExpression.js | 7 ++----- src/slang-nodes/InheritanceSpecifier.js | 5 ++--- src/slang-nodes/InheritanceType.js | 6 ++---- src/slang-nodes/InheritanceTypes.js | 12 +++--------- src/slang-nodes/InterfaceDefinition.js | 6 ++---- src/slang-nodes/InterfaceMembers.js | 12 +++--------- src/slang-nodes/LibraryDefinition.js | 5 ++--- src/slang-nodes/LibraryMembers.js | 12 +++--------- src/slang-nodes/MappingKey.js | 5 ++--- src/slang-nodes/MappingKeyType.js | 5 ++--- src/slang-nodes/MappingType.js | 6 ++---- src/slang-nodes/MappingValue.js | 5 ++--- src/slang-nodes/MemberAccess.js | 4 ++-- src/slang-nodes/MemberAccessExpression.js | 6 ++---- src/slang-nodes/ModifierAttribute.js | 5 ++--- src/slang-nodes/ModifierAttributes.js | 5 ++--- src/slang-nodes/ModifierDefinition.js | 7 ++----- src/slang-nodes/ModifierInvocation.js | 6 ++---- src/slang-nodes/MultiplicativeExpression.js | 6 ++---- src/slang-nodes/NamedArgument.js | 5 ++--- src/slang-nodes/NamedArgumentGroup.js | 5 ++--- src/slang-nodes/NamedArguments.js | 12 +++--------- src/slang-nodes/NamedArgumentsDeclaration.js | 5 ++--- src/slang-nodes/NamedImport.js | 6 ++---- src/slang-nodes/NewExpression.js | 5 ++--- src/slang-nodes/NumberUnit.js | 4 ++-- src/slang-nodes/OrExpression.js | 6 ++---- src/slang-nodes/OverridePaths.js | 12 +++--------- src/slang-nodes/OverridePathsDeclaration.js | 5 ++--- src/slang-nodes/OverrideSpecifier.js | 5 ++--- src/slang-nodes/Parameter.js | 6 ++---- src/slang-nodes/Parameters.js | 12 +++--------- src/slang-nodes/ParametersDeclaration.js | 5 ++--- src/slang-nodes/PathImport.js | 13 +++---------- src/slang-nodes/PositionalArguments.js | 12 +++--------- .../PositionalArgumentsDeclaration.js | 5 ++--- src/slang-nodes/PostfixExpression.js | 5 ++--- src/slang-nodes/Pragma.js | 5 ++--- src/slang-nodes/PragmaDirective.js | 5 ++--- src/slang-nodes/PrefixExpression.js | 5 ++--- src/slang-nodes/ReceiveFunctionAttribute.js | 5 ++--- src/slang-nodes/ReceiveFunctionAttributes.js | 5 ++--- src/slang-nodes/ReceiveFunctionDefinition.js | 7 ++----- src/slang-nodes/ReturnStatement.js | 5 ++--- src/slang-nodes/ReturnsDeclaration.js | 5 ++--- src/slang-nodes/RevertStatement.js | 6 ++---- src/slang-nodes/ShiftExpression.js | 6 ++---- src/slang-nodes/SourceUnit.js | 17 ++--------------- src/slang-nodes/SourceUnitMember.js | 5 ++--- src/slang-nodes/SourceUnitMembers.js | 12 +++--------- src/slang-nodes/StateVariableAttribute.js | 5 ++--- src/slang-nodes/StateVariableAttributes.js | 5 ++--- src/slang-nodes/StateVariableDefinition.js | 7 ++----- src/slang-nodes/StateVariableDefinitionValue.js | 5 ++--- src/slang-nodes/Statement.js | 5 ++--- src/slang-nodes/Statements.js | 6 +++--- src/slang-nodes/StorageLocation.js | 4 ++-- src/slang-nodes/StringExpression.js | 5 ++--- src/slang-nodes/StringLiteral.js | 4 ++-- src/slang-nodes/StringLiterals.js | 12 +++--------- src/slang-nodes/StructDefinition.js | 5 ++--- src/slang-nodes/StructMember.js | 5 ++--- src/slang-nodes/StructMembers.js | 12 +++--------- src/slang-nodes/ThrowStatement.js | 4 ++-- src/slang-nodes/TryStatement.js | 15 +++------------ src/slang-nodes/TupleDeconstructionElement.js | 5 ++--- src/slang-nodes/TupleDeconstructionElements.js | 5 ++--- src/slang-nodes/TupleDeconstructionStatement.js | 6 ++---- src/slang-nodes/TupleExpression.js | 5 ++--- src/slang-nodes/TupleMember.js | 5 ++--- src/slang-nodes/TupleValue.js | 5 ++--- src/slang-nodes/TupleValues.js | 12 +++--------- src/slang-nodes/TypeExpression.js | 5 ++--- src/slang-nodes/TypeName.js | 5 ++--- src/slang-nodes/TypedTupleMember.js | 6 ++---- src/slang-nodes/UncheckedBlock.js | 12 +++--------- src/slang-nodes/UnicodeStringLiteral.js | 4 ++-- src/slang-nodes/UnicodeStringLiterals.js | 5 ++--- src/slang-nodes/UnnamedFunctionAttribute.js | 5 ++--- src/slang-nodes/UnnamedFunctionAttributes.js | 5 ++--- src/slang-nodes/UnnamedFunctionDefinition.js | 7 ++----- src/slang-nodes/UntypedTupleMember.js | 5 ++--- .../UserDefinedValueTypeDefinition.js | 5 ++--- src/slang-nodes/UsingAlias.js | 5 ++--- src/slang-nodes/UsingClause.js | 5 ++--- src/slang-nodes/UsingDeconstruction.js | 5 ++--- src/slang-nodes/UsingDeconstructionSymbol.js | 6 ++---- src/slang-nodes/UsingDeconstructionSymbols.js | 5 ++--- src/slang-nodes/UsingDirective.js | 6 ++---- src/slang-nodes/UsingOperator.js | 4 ++-- src/slang-nodes/UsingTarget.js | 12 +++--------- src/slang-nodes/VariableDeclarationStatement.js | 7 ++----- src/slang-nodes/VariableDeclarationType.js | 12 +++--------- src/slang-nodes/VariableDeclarationValue.js | 5 ++--- src/slang-nodes/VersionComparator.js | 5 ++--- src/slang-nodes/VersionExpression.js | 5 ++--- src/slang-nodes/VersionExpressionSet.js | 5 ++--- src/slang-nodes/VersionExpressionSets.js | 5 ++--- src/slang-nodes/VersionPragma.js | 5 ++--- src/slang-nodes/VersionRange.js | 6 ++---- src/slang-nodes/VersionSpecifiers.js | 4 ++-- src/slang-nodes/WhileStatement.js | 6 ++---- src/slang-nodes/YulArguments.js | 12 +++--------- src/slang-nodes/YulAssignmentOperator.js | 5 ++--- src/slang-nodes/YulBlock.js | 5 ++--- src/slang-nodes/YulBreakStatement.js | 4 ++-- src/slang-nodes/YulBuiltInFunction.js | 4 ++-- src/slang-nodes/YulColonEqual.js | 4 ++-- src/slang-nodes/YulContinueStatement.js | 4 ++-- src/slang-nodes/YulDefaultCase.js | 5 ++--- src/slang-nodes/YulExpression.js | 5 ++--- src/slang-nodes/YulForStatement.js | 8 ++------ src/slang-nodes/YulFunctionCallExpression.js | 6 ++---- src/slangParser.js | 8 +------- 194 files changed, 417 insertions(+), 825 deletions(-) diff --git a/src/slang-nodes/ABICoderPragma.js b/src/slang-nodes/ABICoderPragma.js index 807054da6..979bd0b59 100644 --- a/src/slang-nodes/ABICoderPragma.js +++ b/src/slang-nodes/ABICoderPragma.js @@ -5,7 +5,7 @@ export class ABICoderPragma extends SlangNode { version; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments) { super(); const fetch = () => { @@ -14,7 +14,7 @@ export class ABICoderPragma extends SlangNode { this.version = version.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print() { diff --git a/src/slang-nodes/AdditiveExpression.js b/src/slang-nodes/AdditiveExpression.js index 77da1a1f4..5ff2f77f5 100644 --- a/src/slang-nodes/AdditiveExpression.js +++ b/src/slang-nodes/AdditiveExpression.js @@ -12,7 +12,7 @@ export class AdditiveExpression extends SlangNode { rightOperand; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -21,7 +21,6 @@ export class AdditiveExpression extends SlangNode { leftOperand, childrenOffsets.shift(), comments, - parse, options ); this.operator = operator.text; @@ -29,12 +28,11 @@ export class AdditiveExpression extends SlangNode { rightOperand, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); diff --git a/src/slang-nodes/AddressType.js b/src/slang-nodes/AddressType.js index 271cfbf95..f57d58307 100644 --- a/src/slang-nodes/AddressType.js +++ b/src/slang-nodes/AddressType.js @@ -5,7 +5,7 @@ export class AddressType extends SlangNode { payableKeyword; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments) { super(); const fetch = () => { @@ -14,7 +14,7 @@ export class AddressType extends SlangNode { this.payableKeyword = payableKeyword?.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print() { diff --git a/src/slang-nodes/AndExpression.js b/src/slang-nodes/AndExpression.js index bb49f218c..1d4b4f0d6 100644 --- a/src/slang-nodes/AndExpression.js +++ b/src/slang-nodes/AndExpression.js @@ -9,7 +9,7 @@ export class AndExpression extends SlangNode { rightOperand; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -18,7 +18,6 @@ export class AndExpression extends SlangNode { leftOperand, childrenOffsets.shift(), comments, - parse, options ); this.operator = operator.text; @@ -26,12 +25,11 @@ export class AndExpression extends SlangNode { rightOperand, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print, options) { diff --git a/src/slang-nodes/ArgumentsDeclaration.js b/src/slang-nodes/ArgumentsDeclaration.js index f819122ac..6b1ff756e 100644 --- a/src/slang-nodes/ArgumentsDeclaration.js +++ b/src/slang-nodes/ArgumentsDeclaration.js @@ -7,7 +7,7 @@ const variants = { PositionalArgumentsDeclaration, NamedArgumentsDeclaration }; export class ArgumentsDeclaration extends SlangNode { variant; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -16,12 +16,11 @@ export class ArgumentsDeclaration extends SlangNode { variant, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/ArrayExpression.js b/src/slang-nodes/ArrayExpression.js index 87a33a10e..da43c177d 100644 --- a/src/slang-nodes/ArrayExpression.js +++ b/src/slang-nodes/ArrayExpression.js @@ -11,7 +11,7 @@ export class ArrayExpression extends SlangNode { closeBracket; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -21,13 +21,12 @@ export class ArrayExpression extends SlangNode { items, childrenOffsets.shift(), comments, - parse, options ); this.closeBracket = closeBracket.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/ArrayTypeName.js b/src/slang-nodes/ArrayTypeName.js index 62bdb3478..6d4b4a5c7 100644 --- a/src/slang-nodes/ArrayTypeName.js +++ b/src/slang-nodes/ArrayTypeName.js @@ -11,7 +11,7 @@ export class ArrayTypeName extends SlangNode { closeBracket; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -20,7 +20,6 @@ export class ArrayTypeName extends SlangNode { operand, childrenOffsets.shift(), comments, - parse, options ); this.openBracket = openBracket.text; @@ -29,14 +28,13 @@ export class ArrayTypeName extends SlangNode { index, childrenOffsets.shift(), comments, - parse, options ); } this.closeBracket = closeBracket.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/ArrayValues.js b/src/slang-nodes/ArrayValues.js index 0a6fd8808..2ac3946b5 100644 --- a/src/slang-nodes/ArrayValues.js +++ b/src/slang-nodes/ArrayValues.js @@ -7,25 +7,19 @@ export class ArrayValues extends SlangNode { separators; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { const { items, separators } = ast; this.items = items.map( (item) => - new Expression( - item, - childrenOffsets.shift(), - comments, - parse, - options - ) + new Expression(item, childrenOffsets.shift(), comments, options) ); this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/AssemblyFlags.js b/src/slang-nodes/AssemblyFlags.js index 4e410f77e..352a3e409 100644 --- a/src/slang-nodes/AssemblyFlags.js +++ b/src/slang-nodes/AssemblyFlags.js @@ -7,25 +7,19 @@ export class AssemblyFlags extends SlangNode { separators; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { const { items, separators } = ast; this.items = items.map( (item) => - new StringLiteral( - item, - childrenOffsets.shift(), - comments, - parse, - options - ) + new StringLiteral(item, childrenOffsets.shift(), comments, options) ); this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/AssemblyFlagsDeclaration.js b/src/slang-nodes/AssemblyFlagsDeclaration.js index a07a9fc38..de18d53e7 100644 --- a/src/slang-nodes/AssemblyFlagsDeclaration.js +++ b/src/slang-nodes/AssemblyFlagsDeclaration.js @@ -8,7 +8,7 @@ export class AssemblyFlagsDeclaration extends SlangNode { closeParen; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -18,13 +18,12 @@ export class AssemblyFlagsDeclaration extends SlangNode { flags, childrenOffsets.shift(), comments, - parse, options ); this.closeParen = closeParen.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/AssemblyStatement.js b/src/slang-nodes/AssemblyStatement.js index 0ea3121ec..2a33a39d3 100644 --- a/src/slang-nodes/AssemblyStatement.js +++ b/src/slang-nodes/AssemblyStatement.js @@ -12,7 +12,7 @@ export class AssemblyStatement extends SlangNode { body; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -23,7 +23,6 @@ export class AssemblyStatement extends SlangNode { label, childrenOffsets.shift(), comments, - parse, options ); } @@ -32,7 +31,6 @@ export class AssemblyStatement extends SlangNode { flags, childrenOffsets.shift(), comments, - parse, options ); } @@ -40,12 +38,11 @@ export class AssemblyStatement extends SlangNode { body, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/AssignmentExpression.js b/src/slang-nodes/AssignmentExpression.js index 9b85a0519..212c41135 100644 --- a/src/slang-nodes/AssignmentExpression.js +++ b/src/slang-nodes/AssignmentExpression.js @@ -12,7 +12,7 @@ export class AssignmentExpression extends SlangNode { rightOperand; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -21,7 +21,6 @@ export class AssignmentExpression extends SlangNode { leftOperand, childrenOffsets.shift(), comments, - parse, options ); this.operator = operator.text; @@ -29,12 +28,11 @@ export class AssignmentExpression extends SlangNode { rightOperand, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/BitwiseAndExpression.js b/src/slang-nodes/BitwiseAndExpression.js index 2ae8e66fc..906ef00bd 100644 --- a/src/slang-nodes/BitwiseAndExpression.js +++ b/src/slang-nodes/BitwiseAndExpression.js @@ -12,7 +12,7 @@ export class BitwiseAndExpression extends SlangNode { rightOperand; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -21,7 +21,6 @@ export class BitwiseAndExpression extends SlangNode { leftOperand, childrenOffsets.shift(), comments, - parse, options ); this.operator = operator.text; @@ -29,12 +28,11 @@ export class BitwiseAndExpression extends SlangNode { rightOperand, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); diff --git a/src/slang-nodes/BitwiseOrExpression.js b/src/slang-nodes/BitwiseOrExpression.js index 313402f1a..2bae6059d 100644 --- a/src/slang-nodes/BitwiseOrExpression.js +++ b/src/slang-nodes/BitwiseOrExpression.js @@ -22,7 +22,7 @@ export class BitwiseOrExpression extends SlangNode { rightOperand; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -31,7 +31,6 @@ export class BitwiseOrExpression extends SlangNode { leftOperand, childrenOffsets.shift(), comments, - parse, options ); this.operator = operator.text; @@ -39,12 +38,11 @@ export class BitwiseOrExpression extends SlangNode { rightOperand, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); diff --git a/src/slang-nodes/BitwiseXorExpression.js b/src/slang-nodes/BitwiseXorExpression.js index 3c52d5fb2..5c7348d4b 100644 --- a/src/slang-nodes/BitwiseXorExpression.js +++ b/src/slang-nodes/BitwiseXorExpression.js @@ -12,7 +12,7 @@ export class BitwiseXorExpression extends SlangNode { rightOperand; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -21,7 +21,6 @@ export class BitwiseXorExpression extends SlangNode { leftOperand, childrenOffsets.shift(), comments, - parse, options ); this.operator = operator.text; @@ -29,12 +28,11 @@ export class BitwiseXorExpression extends SlangNode { rightOperand, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); diff --git a/src/slang-nodes/Block.js b/src/slang-nodes/Block.js index 9e78688b0..f51e278e9 100644 --- a/src/slang-nodes/Block.js +++ b/src/slang-nodes/Block.js @@ -8,7 +8,7 @@ export class Block extends SlangNode { closeBrace; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -18,13 +18,12 @@ export class Block extends SlangNode { statements, childrenOffsets.shift(), comments, - parse, options ); this.closeBrace = closeBrace.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/BreakStatement.js b/src/slang-nodes/BreakStatement.js index 6b8b5bd3b..a61474474 100644 --- a/src/slang-nodes/BreakStatement.js +++ b/src/slang-nodes/BreakStatement.js @@ -5,7 +5,7 @@ export class BreakStatement extends SlangNode { semicolon; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments) { super(); const fetch = () => { @@ -14,7 +14,7 @@ export class BreakStatement extends SlangNode { this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print() { diff --git a/src/slang-nodes/CallOptions.js b/src/slang-nodes/CallOptions.js index 783cc6733..7b00a341d 100644 --- a/src/slang-nodes/CallOptions.js +++ b/src/slang-nodes/CallOptions.js @@ -10,25 +10,19 @@ export class CallOptions extends SlangNode { separators; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { const { items, separators } = ast; this.items = items.map( (item) => - new NamedArgument( - item, - childrenOffsets.shift(), - comments, - parse, - options - ) + new NamedArgument(item, childrenOffsets.shift(), comments, options) ); this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print, options) { diff --git a/src/slang-nodes/CallOptionsExpression.js b/src/slang-nodes/CallOptionsExpression.js index 8d9ef0e8b..f257190f1 100644 --- a/src/slang-nodes/CallOptionsExpression.js +++ b/src/slang-nodes/CallOptionsExpression.js @@ -11,7 +11,7 @@ export class CallOptionsExpression extends SlangNode { closeBrace; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -20,7 +20,6 @@ export class CallOptionsExpression extends SlangNode { operand, childrenOffsets.shift(), comments, - parse, options ); this.openBrace = openBrace.text; @@ -28,13 +27,12 @@ export class CallOptionsExpression extends SlangNode { ast.options, childrenOffsets.shift(), comments, - parse, options ); this.closeBrace = closeBrace.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/CatchClause.js b/src/slang-nodes/CatchClause.js index 9af710e01..9ed9a1f24 100644 --- a/src/slang-nodes/CatchClause.js +++ b/src/slang-nodes/CatchClause.js @@ -9,7 +9,7 @@ export class CatchClause extends SlangNode { body; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -20,20 +20,13 @@ export class CatchClause extends SlangNode { error, childrenOffsets.shift(), comments, - parse, options ); } - this.body = new Block( - body, - childrenOffsets.shift(), - comments, - parse, - options - ); + this.body = new Block(body, childrenOffsets.shift(), comments, options); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/CatchClauseError.js b/src/slang-nodes/CatchClauseError.js index 5dbac6d44..f1c8640cc 100644 --- a/src/slang-nodes/CatchClauseError.js +++ b/src/slang-nodes/CatchClauseError.js @@ -9,7 +9,7 @@ export class CatchClauseError extends SlangNode { parameters; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -19,12 +19,11 @@ export class CatchClauseError extends SlangNode { parameters, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/CatchClauses.js b/src/slang-nodes/CatchClauses.js index c7924ad2f..6f3faa4df 100644 --- a/src/slang-nodes/CatchClauses.js +++ b/src/slang-nodes/CatchClauses.js @@ -7,24 +7,18 @@ const { join } = doc.builders; export class CatchClauses extends SlangNode { items; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { const { items } = ast; this.items = items.map( (item) => - new CatchClause( - item, - childrenOffsets.shift(), - comments, - parse, - options - ) + new CatchClause(item, childrenOffsets.shift(), comments, options) ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/ComparisonExpression.js b/src/slang-nodes/ComparisonExpression.js index dba33f3f5..cdc0949b6 100644 --- a/src/slang-nodes/ComparisonExpression.js +++ b/src/slang-nodes/ComparisonExpression.js @@ -9,7 +9,7 @@ export class ComparisonExpression extends SlangNode { rightOperand; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -18,7 +18,6 @@ export class ComparisonExpression extends SlangNode { leftOperand, childrenOffsets.shift(), comments, - parse, options ); this.operator = operator.text; @@ -26,12 +25,11 @@ export class ComparisonExpression extends SlangNode { rightOperand, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print, options) { diff --git a/src/slang-nodes/ConditionalExpression.js b/src/slang-nodes/ConditionalExpression.js index d02687c03..2b9924758 100644 --- a/src/slang-nodes/ConditionalExpression.js +++ b/src/slang-nodes/ConditionalExpression.js @@ -96,7 +96,7 @@ export class ConditionalExpression extends SlangNode { falseExpression; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -106,7 +106,6 @@ export class ConditionalExpression extends SlangNode { operand, childrenOffsets.shift(), comments, - parse, options ); this.questionMark = questionMark.text; @@ -114,7 +113,6 @@ export class ConditionalExpression extends SlangNode { trueExpression, childrenOffsets.shift(), comments, - parse, options ); this.colon = colon.text; @@ -122,12 +120,11 @@ export class ConditionalExpression extends SlangNode { falseExpression, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); // TODO: while the behaviour is not stable, it should be behind the // experimentalTernaries flag. diff --git a/src/slang-nodes/ConstantDefinition.js b/src/slang-nodes/ConstantDefinition.js index 00ddb8303..cc33ca75e 100644 --- a/src/slang-nodes/ConstantDefinition.js +++ b/src/slang-nodes/ConstantDefinition.js @@ -15,7 +15,7 @@ export class ConstantDefinition extends SlangNode { semicolon; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -24,7 +24,6 @@ export class ConstantDefinition extends SlangNode { typeName, childrenOffsets.shift(), comments, - parse, options ); this.constantKeyword = constantKeyword.text; @@ -34,13 +33,12 @@ export class ConstantDefinition extends SlangNode { value, childrenOffsets.shift(), comments, - parse, options ); this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } // TODO: implement print diff --git a/src/slang-nodes/ConstructorAttribute.js b/src/slang-nodes/ConstructorAttribute.js index 7f98e3477..0647398a4 100644 --- a/src/slang-nodes/ConstructorAttribute.js +++ b/src/slang-nodes/ConstructorAttribute.js @@ -4,7 +4,7 @@ import { ModifierInvocation } from './ModifierInvocation.js'; export class ConstructorAttribute extends SlangNode { variant; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -16,12 +16,11 @@ export class ConstructorAttribute extends SlangNode { variant, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/ConstructorAttributes.js b/src/slang-nodes/ConstructorAttributes.js index 29800f5a4..2f8429c9b 100644 --- a/src/slang-nodes/ConstructorAttributes.js +++ b/src/slang-nodes/ConstructorAttributes.js @@ -8,7 +8,7 @@ const { line } = doc.builders; export class ConstructorAttributes extends SlangNode { items; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -19,13 +19,12 @@ export class ConstructorAttributes extends SlangNode { item, childrenOffsets.shift(), comments, - parse, options ) ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); this.items = this.items.sort(sortFunctionAttributes); } diff --git a/src/slang-nodes/ConstructorDefinition.js b/src/slang-nodes/ConstructorDefinition.js index bb21763d2..c14e7240f 100644 --- a/src/slang-nodes/ConstructorDefinition.js +++ b/src/slang-nodes/ConstructorDefinition.js @@ -13,7 +13,7 @@ export class ConstructorDefinition extends SlangNode { body; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -23,26 +23,18 @@ export class ConstructorDefinition extends SlangNode { parameters, childrenOffsets.shift(), comments, - parse, options ); this.attributes = new ConstructorAttributes( attributes, childrenOffsets.shift(), comments, - parse, - options - ); - this.body = new Block( - body, - childrenOffsets.shift(), - comments, - parse, options ); + this.body = new Block(body, childrenOffsets.shift(), comments, options); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/ContinueStatement.js b/src/slang-nodes/ContinueStatement.js index ed1c2bb78..7ade5cfea 100644 --- a/src/slang-nodes/ContinueStatement.js +++ b/src/slang-nodes/ContinueStatement.js @@ -5,7 +5,7 @@ export class ContinueStatement extends SlangNode { semicolon; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments) { super(); const fetch = () => { @@ -14,7 +14,7 @@ export class ContinueStatement extends SlangNode { this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print() { diff --git a/src/slang-nodes/ContractDefinition.js b/src/slang-nodes/ContractDefinition.js index 32001db57..d40107d22 100644 --- a/src/slang-nodes/ContractDefinition.js +++ b/src/slang-nodes/ContractDefinition.js @@ -22,7 +22,7 @@ export class ContractDefinition extends SlangNode { closeBrace; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -43,7 +43,6 @@ export class ContractDefinition extends SlangNode { inheritance, childrenOffsets.shift(), comments, - parse, options ); } @@ -52,13 +51,12 @@ export class ContractDefinition extends SlangNode { members, childrenOffsets.shift(), comments, - parse, options ); this.closeBrace = closeBrace.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); this.cleanModifierInvocationArguments(options); } diff --git a/src/slang-nodes/ContractMember.js b/src/slang-nodes/ContractMember.js index 0496e5e4e..a5f248c53 100644 --- a/src/slang-nodes/ContractMember.js +++ b/src/slang-nodes/ContractMember.js @@ -32,7 +32,7 @@ const variants = { export class ContractMember extends SlangNode { variant; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -41,12 +41,11 @@ export class ContractMember extends SlangNode { variant, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/ContractMembers.js b/src/slang-nodes/ContractMembers.js index a42948a69..7b7cfb662 100644 --- a/src/slang-nodes/ContractMembers.js +++ b/src/slang-nodes/ContractMembers.js @@ -10,24 +10,18 @@ const { hardline } = doc.builders; export class ContractMembers extends SlangNode { items; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { const { items } = ast; this.items = items.map( (item) => - new ContractMember( - item, - childrenOffsets.shift(), - comments, - parse, - options - ) + new ContractMember(item, childrenOffsets.shift(), comments, options) ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print, options) { diff --git a/src/slang-nodes/DecimalNumberExpression.js b/src/slang-nodes/DecimalNumberExpression.js index 91003a54b..7a2935945 100644 --- a/src/slang-nodes/DecimalNumberExpression.js +++ b/src/slang-nodes/DecimalNumberExpression.js @@ -6,7 +6,7 @@ export class DecimalNumberExpression extends SlangNode { unit; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -17,13 +17,12 @@ export class DecimalNumberExpression extends SlangNode { unit, childrenOffsets.shift(), comments, - parse, options ); } }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/DoWhileStatement.js b/src/slang-nodes/DoWhileStatement.js index 76f3be50b..5dffc1315 100644 --- a/src/slang-nodes/DoWhileStatement.js +++ b/src/slang-nodes/DoWhileStatement.js @@ -21,7 +21,7 @@ export class DoWhileStatement extends SlangNode { semicolon; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -39,7 +39,6 @@ export class DoWhileStatement extends SlangNode { body, childrenOffsets.shift(), comments, - parse, options ); this.whileKeyword = whileKeyword.text; @@ -48,14 +47,13 @@ export class DoWhileStatement extends SlangNode { condition, childrenOffsets.shift(), comments, - parse, options ); this.closeParen = closeParen.text; this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/ElementaryType.js b/src/slang-nodes/ElementaryType.js index f41ddfeb3..88155c60b 100644 --- a/src/slang-nodes/ElementaryType.js +++ b/src/slang-nodes/ElementaryType.js @@ -4,7 +4,7 @@ import { AddressType } from './AddressType.js'; export class ElementaryType extends SlangNode { variant; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { const { variant } = ast; @@ -15,12 +15,11 @@ export class ElementaryType extends SlangNode { variant, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/ElseBranch.js b/src/slang-nodes/ElseBranch.js index 23cb45f0a..44eb1c68a 100644 --- a/src/slang-nodes/ElseBranch.js +++ b/src/slang-nodes/ElseBranch.js @@ -12,7 +12,7 @@ export class ElseBranch extends SlangNode { body; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -22,12 +22,11 @@ export class ElseBranch extends SlangNode { body, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/EmitStatement.js b/src/slang-nodes/EmitStatement.js index 865193888..f27e1fa05 100644 --- a/src/slang-nodes/EmitStatement.js +++ b/src/slang-nodes/EmitStatement.js @@ -11,7 +11,7 @@ export class EmitStatement extends SlangNode { semicolon; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -21,20 +21,18 @@ export class EmitStatement extends SlangNode { event, childrenOffsets.shift(), comments, - parse, options ); this.arguments = new ArgumentsDeclaration( ast.arguments, childrenOffsets.shift(), comments, - parse, options ); this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/EnumDefinition.js b/src/slang-nodes/EnumDefinition.js index f277fc277..0782f26a1 100644 --- a/src/slang-nodes/EnumDefinition.js +++ b/src/slang-nodes/EnumDefinition.js @@ -12,7 +12,7 @@ export class EnumDefinition extends SlangNode { closeBrace; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -24,13 +24,12 @@ export class EnumDefinition extends SlangNode { members, childrenOffsets.shift(), comments, - parse, options ); this.closeBrace = closeBrace.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/EnumMembers.js b/src/slang-nodes/EnumMembers.js index c1704eea3..dbc18839b 100644 --- a/src/slang-nodes/EnumMembers.js +++ b/src/slang-nodes/EnumMembers.js @@ -9,7 +9,7 @@ export class EnumMembers extends SlangNode { separators; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments) { super(); const fetch = () => { @@ -18,7 +18,7 @@ export class EnumMembers extends SlangNode { this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print() { diff --git a/src/slang-nodes/EqualityExpression.js b/src/slang-nodes/EqualityExpression.js index a29c40213..72658ffa9 100644 --- a/src/slang-nodes/EqualityExpression.js +++ b/src/slang-nodes/EqualityExpression.js @@ -9,7 +9,7 @@ export class EqualityExpression extends SlangNode { rightOperand; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -18,7 +18,6 @@ export class EqualityExpression extends SlangNode { leftOperand, childrenOffsets.shift(), comments, - parse, options ); this.operator = operator.text; @@ -26,12 +25,11 @@ export class EqualityExpression extends SlangNode { rightOperand, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print, options) { diff --git a/src/slang-nodes/ErrorDefinition.js b/src/slang-nodes/ErrorDefinition.js index ae8c34d0a..f97b43efd 100644 --- a/src/slang-nodes/ErrorDefinition.js +++ b/src/slang-nodes/ErrorDefinition.js @@ -10,7 +10,7 @@ export class ErrorDefinition extends SlangNode { semicolon; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -21,13 +21,12 @@ export class ErrorDefinition extends SlangNode { members, childrenOffsets.shift(), comments, - parse, options ); this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/ErrorParameter.js b/src/slang-nodes/ErrorParameter.js index e5697f672..52e817a06 100644 --- a/src/slang-nodes/ErrorParameter.js +++ b/src/slang-nodes/ErrorParameter.js @@ -6,7 +6,7 @@ export class ErrorParameter extends SlangNode { name; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -15,13 +15,12 @@ export class ErrorParameter extends SlangNode { typeName, childrenOffsets.shift(), comments, - parse, options ); this.name = name?.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/ErrorParameters.js b/src/slang-nodes/ErrorParameters.js index bea65d1c3..eabe55663 100644 --- a/src/slang-nodes/ErrorParameters.js +++ b/src/slang-nodes/ErrorParameters.js @@ -7,25 +7,19 @@ export class ErrorParameters extends SlangNode { separators; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { const { items, separators } = ast; this.items = items.map( (item) => - new ErrorParameter( - item, - childrenOffsets.shift(), - comments, - parse, - options - ) + new ErrorParameter(item, childrenOffsets.shift(), comments, options) ); this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/ErrorParametersDeclaration.js b/src/slang-nodes/ErrorParametersDeclaration.js index 51e1c2f90..66e155347 100644 --- a/src/slang-nodes/ErrorParametersDeclaration.js +++ b/src/slang-nodes/ErrorParametersDeclaration.js @@ -8,7 +8,7 @@ export class ErrorParametersDeclaration extends SlangNode { closeParen; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -18,13 +18,12 @@ export class ErrorParametersDeclaration extends SlangNode { parameters, childrenOffsets.shift(), comments, - parse, options ); this.closeParen = closeParen.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/EventDefinition.js b/src/slang-nodes/EventDefinition.js index 628ab3fd1..cab073f6a 100644 --- a/src/slang-nodes/EventDefinition.js +++ b/src/slang-nodes/EventDefinition.js @@ -12,7 +12,7 @@ export class EventDefinition extends SlangNode { semicolon; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -24,14 +24,13 @@ export class EventDefinition extends SlangNode { parameters, childrenOffsets.shift(), comments, - parse, options ); this.anonymousKeyword = anonymousKeyword?.text; this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/EventParameter.js b/src/slang-nodes/EventParameter.js index 3144bf523..41b76261c 100644 --- a/src/slang-nodes/EventParameter.js +++ b/src/slang-nodes/EventParameter.js @@ -8,7 +8,7 @@ export class EventParameter extends SlangNode { name; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -17,14 +17,13 @@ export class EventParameter extends SlangNode { typeName, childrenOffsets.shift(), comments, - parse, options ); this.indexedKeyword = indexedKeyword?.text; this.name = name?.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/EventParameters.js b/src/slang-nodes/EventParameters.js index 02e66fbd6..b586cb1d8 100644 --- a/src/slang-nodes/EventParameters.js +++ b/src/slang-nodes/EventParameters.js @@ -7,25 +7,19 @@ export class EventParameters extends SlangNode { separators; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { const { items, separators } = ast; this.items = items.map( (item) => - new EventParameter( - item, - childrenOffsets.shift(), - comments, - parse, - options - ) + new EventParameter(item, childrenOffsets.shift(), comments, options) ); this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/EventParametersDeclaration.js b/src/slang-nodes/EventParametersDeclaration.js index c4ff8e860..6bdafcda3 100644 --- a/src/slang-nodes/EventParametersDeclaration.js +++ b/src/slang-nodes/EventParametersDeclaration.js @@ -8,7 +8,7 @@ export class EventParametersDeclaration extends SlangNode { closeParen; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -18,13 +18,12 @@ export class EventParametersDeclaration extends SlangNode { parameters, childrenOffsets.shift(), comments, - parse, options ); this.closeParen = closeParen.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/ExperimentalFeature.js b/src/slang-nodes/ExperimentalFeature.js index 31540f354..57967b07e 100644 --- a/src/slang-nodes/ExperimentalFeature.js +++ b/src/slang-nodes/ExperimentalFeature.js @@ -4,7 +4,7 @@ import { StringLiteral } from './StringLiteral.js'; export class ExperimentalFeature extends SlangNode { variant; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -16,12 +16,11 @@ export class ExperimentalFeature extends SlangNode { variant, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/ExperimentalPragma.js b/src/slang-nodes/ExperimentalPragma.js index 1b88c52e3..bbf626c36 100644 --- a/src/slang-nodes/ExperimentalPragma.js +++ b/src/slang-nodes/ExperimentalPragma.js @@ -6,7 +6,7 @@ export class ExperimentalPragma extends SlangNode { feature; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -16,12 +16,11 @@ export class ExperimentalPragma extends SlangNode { feature, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/ExponentiationExpression.js b/src/slang-nodes/ExponentiationExpression.js index ddf5b99ef..d69d05dff 100644 --- a/src/slang-nodes/ExponentiationExpression.js +++ b/src/slang-nodes/ExponentiationExpression.js @@ -25,7 +25,7 @@ export class ExponentiationExpression extends SlangNode { rightOperand; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); if (offset) { const fetch = (childrenOffsets) => { @@ -34,7 +34,6 @@ export class ExponentiationExpression extends SlangNode { leftOperand, childrenOffsets.shift(), comments, - parse, options ); this.operator = operator.text; @@ -42,12 +41,11 @@ export class ExponentiationExpression extends SlangNode { rightOperand, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); const compiler = coerce(options.compiler); if (compiler) { diff --git a/src/slang-nodes/Expression.js b/src/slang-nodes/Expression.js index 16cd9599d..04abeba72 100644 --- a/src/slang-nodes/Expression.js +++ b/src/slang-nodes/Expression.js @@ -60,7 +60,7 @@ const variants = { export class Expression extends SlangNode { variant; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); if (offset) { const fetch = (childrenOffsets) => { @@ -72,12 +72,11 @@ export class Expression extends SlangNode { variant, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/ExpressionStatement.js b/src/slang-nodes/ExpressionStatement.js index 1f8d9a10e..bd2ea5c30 100644 --- a/src/slang-nodes/ExpressionStatement.js +++ b/src/slang-nodes/ExpressionStatement.js @@ -6,7 +6,7 @@ export class ExpressionStatement extends SlangNode { semicolon; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -15,13 +15,12 @@ export class ExpressionStatement extends SlangNode { expression, childrenOffsets.shift(), comments, - parse, options ); this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/FallbackFunctionAttribute.js b/src/slang-nodes/FallbackFunctionAttribute.js index 7231fdd73..21d89cbfc 100644 --- a/src/slang-nodes/FallbackFunctionAttribute.js +++ b/src/slang-nodes/FallbackFunctionAttribute.js @@ -7,7 +7,7 @@ const variants = { ModifierInvocation, OverrideSpecifier }; export class FallbackFunctionAttribute extends SlangNode { variant; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -19,12 +19,11 @@ export class FallbackFunctionAttribute extends SlangNode { variant, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/FallbackFunctionAttributes.js b/src/slang-nodes/FallbackFunctionAttributes.js index a664939a4..e0b39a619 100644 --- a/src/slang-nodes/FallbackFunctionAttributes.js +++ b/src/slang-nodes/FallbackFunctionAttributes.js @@ -8,7 +8,7 @@ const { line } = doc.builders; export class FallbackFunctionAttributes extends SlangNode { items; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -19,13 +19,12 @@ export class FallbackFunctionAttributes extends SlangNode { item, childrenOffsets.shift(), comments, - parse, options ) ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); this.items = this.items.sort(sortFunctionAttributes); } diff --git a/src/slang-nodes/FallbackFunctionDefinition.js b/src/slang-nodes/FallbackFunctionDefinition.js index 02bc644c5..c15b62054 100644 --- a/src/slang-nodes/FallbackFunctionDefinition.js +++ b/src/slang-nodes/FallbackFunctionDefinition.js @@ -16,7 +16,7 @@ export class FallbackFunctionDefinition extends SlangNode { body; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -26,14 +26,12 @@ export class FallbackFunctionDefinition extends SlangNode { parameters, childrenOffsets.shift(), comments, - parse, options ); this.attributes = new FallbackFunctionAttributes( attributes, childrenOffsets.shift(), comments, - parse, options ); if (returns) { @@ -41,7 +39,6 @@ export class FallbackFunctionDefinition extends SlangNode { returns, childrenOffsets.shift(), comments, - parse, options ); } @@ -49,12 +46,11 @@ export class FallbackFunctionDefinition extends SlangNode { body, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); this.cleanModifierInvocationArguments(); } diff --git a/src/slang-nodes/ForStatement.js b/src/slang-nodes/ForStatement.js index 515057092..4deec3022 100644 --- a/src/slang-nodes/ForStatement.js +++ b/src/slang-nodes/ForStatement.js @@ -23,7 +23,7 @@ export class ForStatement extends SlangNode { body; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -42,14 +42,12 @@ export class ForStatement extends SlangNode { initialization, childrenOffsets.shift(), comments, - parse, options ); this.condition = new ForStatementCondition( condition, childrenOffsets.shift(), comments, - parse, options ); if (iterator) { @@ -57,7 +55,6 @@ export class ForStatement extends SlangNode { iterator, childrenOffsets.shift(), comments, - parse, options ); } @@ -66,12 +63,11 @@ export class ForStatement extends SlangNode { body, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/ForStatementCondition.js b/src/slang-nodes/ForStatementCondition.js index 34f2c224f..5bf5ee324 100644 --- a/src/slang-nodes/ForStatementCondition.js +++ b/src/slang-nodes/ForStatementCondition.js @@ -4,7 +4,7 @@ import { ExpressionStatement } from './ExpressionStatement.js'; export class ForStatementCondition extends SlangNode { variant; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -16,12 +16,11 @@ export class ForStatementCondition extends SlangNode { variant, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/ForStatementInitialization.js b/src/slang-nodes/ForStatementInitialization.js index fa4197b33..d15d9780a 100644 --- a/src/slang-nodes/ForStatementInitialization.js +++ b/src/slang-nodes/ForStatementInitialization.js @@ -12,7 +12,7 @@ const variants = { export class ForStatementInitialization extends SlangNode { variant; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -24,12 +24,11 @@ export class ForStatementInitialization extends SlangNode { variant, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/FunctionAttribute.js b/src/slang-nodes/FunctionAttribute.js index 0b0ac2db2..954dc87d7 100644 --- a/src/slang-nodes/FunctionAttribute.js +++ b/src/slang-nodes/FunctionAttribute.js @@ -7,7 +7,7 @@ const variants = { ModifierInvocation, OverrideSpecifier }; export class FunctionAttribute extends SlangNode { variant; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -19,12 +19,11 @@ export class FunctionAttribute extends SlangNode { variant, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/FunctionAttributes.js b/src/slang-nodes/FunctionAttributes.js index 8ea3f114c..8295fb2ad 100644 --- a/src/slang-nodes/FunctionAttributes.js +++ b/src/slang-nodes/FunctionAttributes.js @@ -8,7 +8,7 @@ const { line } = doc.builders; export class FunctionAttributes extends SlangNode { items; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -19,13 +19,12 @@ export class FunctionAttributes extends SlangNode { item, childrenOffsets.shift(), comments, - parse, options ) ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); this.items = this.items.sort(sortFunctionAttributes); } diff --git a/src/slang-nodes/FunctionBody.js b/src/slang-nodes/FunctionBody.js index 8f038a5b9..3c7767cc9 100644 --- a/src/slang-nodes/FunctionBody.js +++ b/src/slang-nodes/FunctionBody.js @@ -4,7 +4,7 @@ import { Block } from './Block.js'; export class FunctionBody extends SlangNode { variant; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -12,16 +12,10 @@ export class FunctionBody extends SlangNode { this.variant = variant.type === 'Terminal' ? variant.text - : new Block( - variant, - childrenOffsets.shift(), - comments, - parse, - options - ); + : new Block(variant, childrenOffsets.shift(), comments, options); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/FunctionCallExpression.js b/src/slang-nodes/FunctionCallExpression.js index 9956e0d29..bbe4468bf 100644 --- a/src/slang-nodes/FunctionCallExpression.js +++ b/src/slang-nodes/FunctionCallExpression.js @@ -11,7 +11,7 @@ export class FunctionCallExpression extends SlangNode { arguments; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -20,19 +20,17 @@ export class FunctionCallExpression extends SlangNode { operand, childrenOffsets.shift(), comments, - parse, options ); this.arguments = new ArgumentsDeclaration( ast.arguments, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/FunctionDefinition.js b/src/slang-nodes/FunctionDefinition.js index cf384a610..d7a6345ee 100644 --- a/src/slang-nodes/FunctionDefinition.js +++ b/src/slang-nodes/FunctionDefinition.js @@ -21,7 +21,7 @@ export class FunctionDefinition extends SlangNode { body; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -32,21 +32,18 @@ export class FunctionDefinition extends SlangNode { name, childrenOffsets.shift(), comments, - parse, options ); this.parameters = new ParametersDeclaration( parameters, childrenOffsets.shift(), comments, - parse, options ); this.attributes = new FunctionAttributes( attributes, childrenOffsets.shift(), comments, - parse, options ); if (returns) { @@ -54,7 +51,6 @@ export class FunctionDefinition extends SlangNode { returns, childrenOffsets.shift(), comments, - parse, options ); } @@ -62,12 +58,11 @@ export class FunctionDefinition extends SlangNode { body, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); // Older versions of Solidity defined a constructor as a function having // the same name as the contract. diff --git a/src/slang-nodes/FunctionName.js b/src/slang-nodes/FunctionName.js index 497240f59..42f1abbd8 100644 --- a/src/slang-nodes/FunctionName.js +++ b/src/slang-nodes/FunctionName.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class FunctionName extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments) { super(); const fetch = () => { @@ -11,7 +11,7 @@ export class FunctionName extends SlangNode { this.variant = variant.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print() { diff --git a/src/slang-nodes/FunctionType.js b/src/slang-nodes/FunctionType.js index ced112e0c..b1dbe19e1 100644 --- a/src/slang-nodes/FunctionType.js +++ b/src/slang-nodes/FunctionType.js @@ -13,7 +13,7 @@ export class FunctionType extends SlangNode { returns; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -23,14 +23,12 @@ export class FunctionType extends SlangNode { parameters, childrenOffsets.shift(), comments, - parse, options ); this.attributes = new FunctionTypeAttributes( attributes, childrenOffsets.shift(), comments, - parse, options ); if (returns) { @@ -38,13 +36,12 @@ export class FunctionType extends SlangNode { returns, childrenOffsets.shift(), comments, - parse, options ); } }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/FunctionTypeAttribute.js b/src/slang-nodes/FunctionTypeAttribute.js index 5846f025e..6cb2c6cc7 100644 --- a/src/slang-nodes/FunctionTypeAttribute.js +++ b/src/slang-nodes/FunctionTypeAttribute.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class FunctionTypeAttribute extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments) { super(); const fetch = () => { @@ -11,7 +11,7 @@ export class FunctionTypeAttribute extends SlangNode { this.variant = variant.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print() { diff --git a/src/slang-nodes/FunctionTypeAttributes.js b/src/slang-nodes/FunctionTypeAttributes.js index 1e9009ee1..bd6e71a95 100644 --- a/src/slang-nodes/FunctionTypeAttributes.js +++ b/src/slang-nodes/FunctionTypeAttributes.js @@ -8,7 +8,7 @@ const { line } = doc.builders; export class FunctionTypeAttributes extends SlangNode { items; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -19,13 +19,12 @@ export class FunctionTypeAttributes extends SlangNode { item, childrenOffsets.shift(), comments, - parse, options ) ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); this.items = this.items.sort(sortFunctionAttributes); } diff --git a/src/slang-nodes/HexNumberExpression.js b/src/slang-nodes/HexNumberExpression.js index ed6d79cff..0f60b02ce 100644 --- a/src/slang-nodes/HexNumberExpression.js +++ b/src/slang-nodes/HexNumberExpression.js @@ -6,7 +6,7 @@ export class HexNumberExpression extends SlangNode { unit; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -17,13 +17,12 @@ export class HexNumberExpression extends SlangNode { unit, childrenOffsets.shift(), comments, - parse, options ); } }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/HexStringLiteral.js b/src/slang-nodes/HexStringLiteral.js index ec063c4b3..dca9478ff 100644 --- a/src/slang-nodes/HexStringLiteral.js +++ b/src/slang-nodes/HexStringLiteral.js @@ -4,7 +4,7 @@ import { SlangNode } from './SlangNode.js'; export class HexStringLiteral extends SlangNode { variant; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = () => { @@ -12,7 +12,7 @@ export class HexStringLiteral extends SlangNode { this.variant = variant.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); this.variant = `hex${printString(this.variant.slice(4, -1), options)}`; } diff --git a/src/slang-nodes/HexStringLiterals.js b/src/slang-nodes/HexStringLiterals.js index b470ec12a..df64ebc49 100644 --- a/src/slang-nodes/HexStringLiterals.js +++ b/src/slang-nodes/HexStringLiterals.js @@ -7,24 +7,18 @@ const { join, hardline } = doc.builders; export class HexStringLiterals extends SlangNode { items; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { const { items } = ast; this.items = items.map( (item) => - new HexStringLiteral( - item, - childrenOffsets.shift(), - comments, - parse, - options - ) + new HexStringLiteral(item, childrenOffsets.shift(), comments, options) ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/IdentifierPath.js b/src/slang-nodes/IdentifierPath.js index cdc69e5ac..6c092a178 100644 --- a/src/slang-nodes/IdentifierPath.js +++ b/src/slang-nodes/IdentifierPath.js @@ -5,7 +5,7 @@ export class IdentifierPath extends SlangNode { separators; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments) { super(); const fetch = () => { @@ -14,7 +14,7 @@ export class IdentifierPath extends SlangNode { this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print() { diff --git a/src/slang-nodes/IfStatement.js b/src/slang-nodes/IfStatement.js index 0f41ac5c9..b1fbab601 100644 --- a/src/slang-nodes/IfStatement.js +++ b/src/slang-nodes/IfStatement.js @@ -20,7 +20,7 @@ export class IfStatement extends SlangNode { elseBranch; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -32,7 +32,6 @@ export class IfStatement extends SlangNode { condition, childrenOffsets.shift(), comments, - parse, options ); this.closeParen = closeParen.text; @@ -40,7 +39,6 @@ export class IfStatement extends SlangNode { body, childrenOffsets.shift(), comments, - parse, options ); if (elseBranch) { @@ -48,13 +46,12 @@ export class IfStatement extends SlangNode { elseBranch, childrenOffsets.shift(), comments, - parse, options ); } }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/ImportAlias.js b/src/slang-nodes/ImportAlias.js index 51e36222d..a05f67129 100644 --- a/src/slang-nodes/ImportAlias.js +++ b/src/slang-nodes/ImportAlias.js @@ -5,7 +5,7 @@ export class ImportAlias extends SlangNode { identifier; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments) { super(); const fetch = () => { @@ -14,7 +14,7 @@ export class ImportAlias extends SlangNode { this.identifier = identifier.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print() { diff --git a/src/slang-nodes/ImportClause.js b/src/slang-nodes/ImportClause.js index 1fc60f3af..881c0b4ab 100644 --- a/src/slang-nodes/ImportClause.js +++ b/src/slang-nodes/ImportClause.js @@ -8,7 +8,7 @@ const variants = { PathImport, NamedImport, ImportDeconstruction }; export class ImportClause extends SlangNode { variant; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -17,12 +17,11 @@ export class ImportClause extends SlangNode { variant, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/ImportDeconstruction.js b/src/slang-nodes/ImportDeconstruction.js index 4ceefac91..26ce1b7f2 100644 --- a/src/slang-nodes/ImportDeconstruction.js +++ b/src/slang-nodes/ImportDeconstruction.js @@ -13,7 +13,7 @@ export class ImportDeconstruction extends SlangNode { path; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -23,7 +23,6 @@ export class ImportDeconstruction extends SlangNode { symbols, childrenOffsets.shift(), comments, - parse, options ); this.closeBrace = closeBrace.text; @@ -32,12 +31,11 @@ export class ImportDeconstruction extends SlangNode { path, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/ImportDeconstructionSymbol.js b/src/slang-nodes/ImportDeconstructionSymbol.js index 73b92f017..ac5f0fa03 100644 --- a/src/slang-nodes/ImportDeconstructionSymbol.js +++ b/src/slang-nodes/ImportDeconstructionSymbol.js @@ -6,7 +6,7 @@ export class ImportDeconstructionSymbol extends SlangNode { alias; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -15,16 +15,10 @@ export class ImportDeconstructionSymbol extends SlangNode { this.alias = typeof alias === 'undefined' ? undefined - : new ImportAlias( - alias, - childrenOffsets.shift(), - comments, - parse, - options - ); + : new ImportAlias(alias, childrenOffsets.shift(), comments, options); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/ImportDeconstructionSymbols.js b/src/slang-nodes/ImportDeconstructionSymbols.js index ec4e9b518..dfb758ce5 100644 --- a/src/slang-nodes/ImportDeconstructionSymbols.js +++ b/src/slang-nodes/ImportDeconstructionSymbols.js @@ -12,7 +12,7 @@ export class ImportDeconstructionSymbols extends SlangNode { separators; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -23,14 +23,13 @@ export class ImportDeconstructionSymbols extends SlangNode { item, childrenOffsets.shift(), comments, - parse, options ) ); this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print, options) { diff --git a/src/slang-nodes/ImportDirective.js b/src/slang-nodes/ImportDirective.js index 376020ea8..6d206100c 100644 --- a/src/slang-nodes/ImportDirective.js +++ b/src/slang-nodes/ImportDirective.js @@ -8,7 +8,7 @@ export class ImportDirective extends SlangNode { semicolon; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -18,13 +18,12 @@ export class ImportDirective extends SlangNode { clause, childrenOffsets.shift(), comments, - parse, options ); this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/IndexAccessEnd.js b/src/slang-nodes/IndexAccessEnd.js index 5b66ea461..9ce59c0aa 100644 --- a/src/slang-nodes/IndexAccessEnd.js +++ b/src/slang-nodes/IndexAccessEnd.js @@ -6,7 +6,7 @@ export class IndexAccessEnd extends SlangNode { end; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -17,13 +17,12 @@ export class IndexAccessEnd extends SlangNode { end, childrenOffsets.shift(), comments, - parse, options ); } }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/IndexAccessExpression.js b/src/slang-nodes/IndexAccessExpression.js index 3442725fd..6d632f700 100644 --- a/src/slang-nodes/IndexAccessExpression.js +++ b/src/slang-nodes/IndexAccessExpression.js @@ -17,7 +17,7 @@ export class IndexAccessExpression extends SlangNode { closeBracket; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -26,7 +26,6 @@ export class IndexAccessExpression extends SlangNode { operand, childrenOffsets.shift(), comments, - parse, options ); this.openBracket = openBracket.text; @@ -35,7 +34,6 @@ export class IndexAccessExpression extends SlangNode { start, childrenOffsets.shift(), comments, - parse, options ); } @@ -44,14 +42,13 @@ export class IndexAccessExpression extends SlangNode { end, childrenOffsets.shift(), comments, - parse, options ); } this.closeBracket = closeBracket.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/InheritanceSpecifier.js b/src/slang-nodes/InheritanceSpecifier.js index 8f3383646..988c94c49 100644 --- a/src/slang-nodes/InheritanceSpecifier.js +++ b/src/slang-nodes/InheritanceSpecifier.js @@ -6,7 +6,7 @@ export class InheritanceSpecifier extends SlangNode { types; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -16,12 +16,11 @@ export class InheritanceSpecifier extends SlangNode { types, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/InheritanceType.js b/src/slang-nodes/InheritanceType.js index ab67b97a0..f00268011 100644 --- a/src/slang-nodes/InheritanceType.js +++ b/src/slang-nodes/InheritanceType.js @@ -7,7 +7,7 @@ export class InheritanceType extends SlangNode { arguments; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -16,7 +16,6 @@ export class InheritanceType extends SlangNode { typeName, childrenOffsets.shift(), comments, - parse, options ); if (ast.arguments) { @@ -24,13 +23,12 @@ export class InheritanceType extends SlangNode { ast.arguments, childrenOffsets.shift(), comments, - parse, options ); } }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/InheritanceTypes.js b/src/slang-nodes/InheritanceTypes.js index dd9fb97bd..ea895d924 100644 --- a/src/slang-nodes/InheritanceTypes.js +++ b/src/slang-nodes/InheritanceTypes.js @@ -10,25 +10,19 @@ export class InheritanceTypes extends SlangNode { separators; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { const { items, separators } = ast; this.items = items.map( (item) => - new InheritanceType( - item, - childrenOffsets.shift(), - comments, - parse, - options - ) + new InheritanceType(item, childrenOffsets.shift(), comments, options) ); this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/InterfaceDefinition.js b/src/slang-nodes/InterfaceDefinition.js index 7cec2f838..53c0efe2f 100644 --- a/src/slang-nodes/InterfaceDefinition.js +++ b/src/slang-nodes/InterfaceDefinition.js @@ -18,7 +18,7 @@ export class InterfaceDefinition extends SlangNode { closeBrace; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -37,7 +37,6 @@ export class InterfaceDefinition extends SlangNode { inheritance, childrenOffsets.shift(), comments, - parse, options ); } @@ -46,13 +45,12 @@ export class InterfaceDefinition extends SlangNode { members, childrenOffsets.shift(), comments, - parse, options ); this.closeBrace = closeBrace.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/InterfaceMembers.js b/src/slang-nodes/InterfaceMembers.js index 40b8e8d24..7a803baaa 100644 --- a/src/slang-nodes/InterfaceMembers.js +++ b/src/slang-nodes/InterfaceMembers.js @@ -9,24 +9,18 @@ const { hardline } = doc.builders; export class InterfaceMembers extends SlangNode { items; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { const { items } = ast; this.items = items.map( (item) => - new ContractMember( - item, - childrenOffsets.shift(), - comments, - parse, - options - ) + new ContractMember(item, childrenOffsets.shift(), comments, options) ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print, options) { diff --git a/src/slang-nodes/LibraryDefinition.js b/src/slang-nodes/LibraryDefinition.js index 1a5e76aee..19a0ee7dc 100644 --- a/src/slang-nodes/LibraryDefinition.js +++ b/src/slang-nodes/LibraryDefinition.js @@ -15,7 +15,7 @@ export class LibraryDefinition extends SlangNode { closeBrace; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -27,13 +27,12 @@ export class LibraryDefinition extends SlangNode { members, childrenOffsets.shift(), comments, - parse, options ); this.closeBrace = closeBrace.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/LibraryMembers.js b/src/slang-nodes/LibraryMembers.js index df17ed33a..d751a7efc 100644 --- a/src/slang-nodes/LibraryMembers.js +++ b/src/slang-nodes/LibraryMembers.js @@ -9,24 +9,18 @@ const { hardline } = doc.builders; export class LibraryMembers extends SlangNode { items; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { const { items } = ast; this.items = items.map( (item) => - new ContractMember( - item, - childrenOffsets.shift(), - comments, - parse, - options - ) + new ContractMember(item, childrenOffsets.shift(), comments, options) ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print, options) { diff --git a/src/slang-nodes/MappingKey.js b/src/slang-nodes/MappingKey.js index 9ac5220f6..fb29c873c 100644 --- a/src/slang-nodes/MappingKey.js +++ b/src/slang-nodes/MappingKey.js @@ -6,7 +6,7 @@ export class MappingKey extends SlangNode { name; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -15,13 +15,12 @@ export class MappingKey extends SlangNode { keyType, childrenOffsets.shift(), comments, - parse, options ); this.name = name?.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/MappingKeyType.js b/src/slang-nodes/MappingKeyType.js index 17a6083e5..e78cc3432 100644 --- a/src/slang-nodes/MappingKeyType.js +++ b/src/slang-nodes/MappingKeyType.js @@ -7,7 +7,7 @@ const variants = { ElementaryType, IdentifierPath }; export class MappingKeyType extends SlangNode { variant; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { const { variant } = ast; @@ -15,12 +15,11 @@ export class MappingKeyType extends SlangNode { variant, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/MappingType.js b/src/slang-nodes/MappingType.js index 1b2642fb9..99967941f 100644 --- a/src/slang-nodes/MappingType.js +++ b/src/slang-nodes/MappingType.js @@ -15,7 +15,7 @@ export class MappingType extends SlangNode { closeParen; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -33,7 +33,6 @@ export class MappingType extends SlangNode { keyType, childrenOffsets.shift(), comments, - parse, options ); this.equalGreaterThan = equalGreaterThan.text; @@ -41,13 +40,12 @@ export class MappingType extends SlangNode { valueType, childrenOffsets.shift(), comments, - parse, options ); this.closeParen = closeParen.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/MappingValue.js b/src/slang-nodes/MappingValue.js index 3b2888fad..3634e3341 100644 --- a/src/slang-nodes/MappingValue.js +++ b/src/slang-nodes/MappingValue.js @@ -6,7 +6,7 @@ export class MappingValue extends SlangNode { name; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -15,13 +15,12 @@ export class MappingValue extends SlangNode { typeName, childrenOffsets.shift(), comments, - parse, options ); this.name = name?.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/MemberAccess.js b/src/slang-nodes/MemberAccess.js index 3a3606ddc..3e87cd07a 100644 --- a/src/slang-nodes/MemberAccess.js +++ b/src/slang-nodes/MemberAccess.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class MemberAccess extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments) { super(); const fetch = () => { @@ -11,7 +11,7 @@ export class MemberAccess extends SlangNode { this.variant = variant.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print() { diff --git a/src/slang-nodes/MemberAccessExpression.js b/src/slang-nodes/MemberAccessExpression.js index fd1a2ded9..d16540184 100644 --- a/src/slang-nodes/MemberAccessExpression.js +++ b/src/slang-nodes/MemberAccessExpression.js @@ -114,7 +114,7 @@ export class MemberAccessExpression extends SlangNode { member; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -123,7 +123,6 @@ export class MemberAccessExpression extends SlangNode { operand, childrenOffsets.shift(), comments, - parse, options ); this.period = period.text; @@ -131,12 +130,11 @@ export class MemberAccessExpression extends SlangNode { member, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/ModifierAttribute.js b/src/slang-nodes/ModifierAttribute.js index ca3bd6aa0..8f60bea6a 100644 --- a/src/slang-nodes/ModifierAttribute.js +++ b/src/slang-nodes/ModifierAttribute.js @@ -4,7 +4,7 @@ import { OverrideSpecifier } from './OverrideSpecifier.js'; export class ModifierAttribute extends SlangNode { variant; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -16,12 +16,11 @@ export class ModifierAttribute extends SlangNode { variant, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/ModifierAttributes.js b/src/slang-nodes/ModifierAttributes.js index 6a3e3f25b..c8325dae8 100644 --- a/src/slang-nodes/ModifierAttributes.js +++ b/src/slang-nodes/ModifierAttributes.js @@ -8,7 +8,7 @@ const { line } = doc.builders; export class ModifierAttributes extends SlangNode { items; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -19,13 +19,12 @@ export class ModifierAttributes extends SlangNode { item, childrenOffsets.shift(), comments, - parse, options ) ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); this.items = this.items.sort(sortFunctionAttributes); } diff --git a/src/slang-nodes/ModifierDefinition.js b/src/slang-nodes/ModifierDefinition.js index db18e8302..854a563b1 100644 --- a/src/slang-nodes/ModifierDefinition.js +++ b/src/slang-nodes/ModifierDefinition.js @@ -16,7 +16,7 @@ export class ModifierDefinition extends SlangNode { body; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -28,7 +28,6 @@ export class ModifierDefinition extends SlangNode { parameters, childrenOffsets.shift(), comments, - parse, options ); } @@ -36,19 +35,17 @@ export class ModifierDefinition extends SlangNode { attributes, childrenOffsets.shift(), comments, - parse, options ); this.body = new FunctionBody( body, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); if (typeof this.parameters === 'undefined') { const parametersOffset = this.attributes.loc.startWithTrivia; diff --git a/src/slang-nodes/ModifierInvocation.js b/src/slang-nodes/ModifierInvocation.js index 133efc73c..d9c344db3 100644 --- a/src/slang-nodes/ModifierInvocation.js +++ b/src/slang-nodes/ModifierInvocation.js @@ -8,7 +8,7 @@ export class ModifierInvocation extends SlangNode { arguments; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -17,7 +17,6 @@ export class ModifierInvocation extends SlangNode { name, childrenOffsets.shift(), comments, - parse, options ); if (ast.arguments) { @@ -25,13 +24,12 @@ export class ModifierInvocation extends SlangNode { ast.arguments, childrenOffsets.shift(), comments, - parse, options ); } }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); this.cleanModifierInvocationArguments = () => { if ( diff --git a/src/slang-nodes/MultiplicativeExpression.js b/src/slang-nodes/MultiplicativeExpression.js index 4524e5c3d..d986ddaed 100644 --- a/src/slang-nodes/MultiplicativeExpression.js +++ b/src/slang-nodes/MultiplicativeExpression.js @@ -14,7 +14,7 @@ export class MultiplicativeExpression extends SlangNode { rightOperand; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -23,7 +23,6 @@ export class MultiplicativeExpression extends SlangNode { leftOperand, childrenOffsets.shift(), comments, - parse, options ); this.operator = operator.text; @@ -31,12 +30,11 @@ export class MultiplicativeExpression extends SlangNode { rightOperand, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); switch (this.operator) { case '*': diff --git a/src/slang-nodes/NamedArgument.js b/src/slang-nodes/NamedArgument.js index 703d03807..d90498a74 100644 --- a/src/slang-nodes/NamedArgument.js +++ b/src/slang-nodes/NamedArgument.js @@ -8,7 +8,7 @@ export class NamedArgument extends SlangNode { value; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -19,12 +19,11 @@ export class NamedArgument extends SlangNode { value, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/NamedArgumentGroup.js b/src/slang-nodes/NamedArgumentGroup.js index a3eb71b92..51337a289 100644 --- a/src/slang-nodes/NamedArgumentGroup.js +++ b/src/slang-nodes/NamedArgumentGroup.js @@ -8,7 +8,7 @@ export class NamedArgumentGroup extends SlangNode { closeBrace; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -18,14 +18,13 @@ export class NamedArgumentGroup extends SlangNode { ast.arguments, childrenOffsets.shift(), comments, - parse, options ); this.closeBrace = closeBrace.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/NamedArguments.js b/src/slang-nodes/NamedArguments.js index 8b312f2fd..3674083cf 100644 --- a/src/slang-nodes/NamedArguments.js +++ b/src/slang-nodes/NamedArguments.js @@ -10,25 +10,19 @@ export class NamedArguments extends SlangNode { separators; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { const { items, separators } = ast; this.items = items.map( (item) => - new NamedArgument( - item, - childrenOffsets.shift(), - comments, - parse, - options - ) + new NamedArgument(item, childrenOffsets.shift(), comments, options) ); this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print, options) { diff --git a/src/slang-nodes/NamedArgumentsDeclaration.js b/src/slang-nodes/NamedArgumentsDeclaration.js index 74184c01b..811217b11 100644 --- a/src/slang-nodes/NamedArgumentsDeclaration.js +++ b/src/slang-nodes/NamedArgumentsDeclaration.js @@ -8,7 +8,7 @@ export class NamedArgumentsDeclaration extends SlangNode { closeParen; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -19,14 +19,13 @@ export class NamedArgumentsDeclaration extends SlangNode { ast.arguments, childrenOffsets.shift(), comments, - parse, options ); } this.closeParen = closeParen.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/NamedImport.js b/src/slang-nodes/NamedImport.js index 41a11b19c..5082e411e 100644 --- a/src/slang-nodes/NamedImport.js +++ b/src/slang-nodes/NamedImport.js @@ -11,7 +11,7 @@ export class NamedImport extends SlangNode { path; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -21,7 +21,6 @@ export class NamedImport extends SlangNode { alias, childrenOffsets.shift(), comments, - parse, options ); this.fromKeyword = fromKeyword.text; @@ -29,12 +28,11 @@ export class NamedImport extends SlangNode { path, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/NewExpression.js b/src/slang-nodes/NewExpression.js index 5c0163f59..edb3e7bf9 100644 --- a/src/slang-nodes/NewExpression.js +++ b/src/slang-nodes/NewExpression.js @@ -6,7 +6,7 @@ export class NewExpression extends SlangNode { typeName; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -16,12 +16,11 @@ export class NewExpression extends SlangNode { typeName, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/NumberUnit.js b/src/slang-nodes/NumberUnit.js index 682142edc..e24997a03 100644 --- a/src/slang-nodes/NumberUnit.js +++ b/src/slang-nodes/NumberUnit.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class NumberUnit extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments) { super(); const fetch = () => { @@ -11,7 +11,7 @@ export class NumberUnit extends SlangNode { this.variant = variant.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print() { diff --git a/src/slang-nodes/OrExpression.js b/src/slang-nodes/OrExpression.js index 1b0b5785e..120df61a9 100644 --- a/src/slang-nodes/OrExpression.js +++ b/src/slang-nodes/OrExpression.js @@ -12,7 +12,7 @@ export class OrExpression extends SlangNode { rightOperand; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -21,7 +21,6 @@ export class OrExpression extends SlangNode { leftOperand, childrenOffsets.shift(), comments, - parse, options ); this.operator = operator.text; @@ -29,12 +28,11 @@ export class OrExpression extends SlangNode { rightOperand, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); diff --git a/src/slang-nodes/OverridePaths.js b/src/slang-nodes/OverridePaths.js index 271b36103..48e6e263d 100644 --- a/src/slang-nodes/OverridePaths.js +++ b/src/slang-nodes/OverridePaths.js @@ -6,25 +6,19 @@ export class OverridePaths extends SlangNode { separators; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { const { items, separators } = ast; this.items = items.map( (item) => - new IdentifierPath( - item, - childrenOffsets.shift(), - comments, - parse, - options - ) + new IdentifierPath(item, childrenOffsets.shift(), comments, options) ); this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } // TODO: implement print diff --git a/src/slang-nodes/OverridePathsDeclaration.js b/src/slang-nodes/OverridePathsDeclaration.js index acf7fa3af..29779f690 100644 --- a/src/slang-nodes/OverridePathsDeclaration.js +++ b/src/slang-nodes/OverridePathsDeclaration.js @@ -8,7 +8,7 @@ export class OverridePathsDeclaration extends SlangNode { closeParen; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -18,13 +18,12 @@ export class OverridePathsDeclaration extends SlangNode { paths, childrenOffsets.shift(), comments, - parse, options ); this.closeParen = closeParen.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } // TODO: implement print diff --git a/src/slang-nodes/OverrideSpecifier.js b/src/slang-nodes/OverrideSpecifier.js index d36135c48..47f346934 100644 --- a/src/slang-nodes/OverrideSpecifier.js +++ b/src/slang-nodes/OverrideSpecifier.js @@ -6,7 +6,7 @@ export class OverrideSpecifier extends SlangNode { overridden; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -17,13 +17,12 @@ export class OverrideSpecifier extends SlangNode { overridden, childrenOffsets.shift(), comments, - parse, options ); } }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/Parameter.js b/src/slang-nodes/Parameter.js index 3d13e6996..b6c752c61 100644 --- a/src/slang-nodes/Parameter.js +++ b/src/slang-nodes/Parameter.js @@ -12,7 +12,7 @@ export class Parameter extends SlangNode { name; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -21,7 +21,6 @@ export class Parameter extends SlangNode { typeName, childrenOffsets.shift(), comments, - parse, options ); if (storageLocation) { @@ -29,14 +28,13 @@ export class Parameter extends SlangNode { storageLocation, childrenOffsets.shift(), comments, - parse, options ); } this.name = name?.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/Parameters.js b/src/slang-nodes/Parameters.js index e5338fd54..0f03e8cb5 100644 --- a/src/slang-nodes/Parameters.js +++ b/src/slang-nodes/Parameters.js @@ -11,25 +11,19 @@ export class Parameters extends SlangNode { separators; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); if (offset) { const fetch = (childrenOffsets) => { const { items, separators } = ast; this.items = items.map( (item) => - new Parameter( - item, - childrenOffsets.shift(), - comments, - parse, - options - ) + new Parameter(item, childrenOffsets.shift(), comments, options) ); this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/ParametersDeclaration.js b/src/slang-nodes/ParametersDeclaration.js index f6ce312b7..8dada44ae 100644 --- a/src/slang-nodes/ParametersDeclaration.js +++ b/src/slang-nodes/ParametersDeclaration.js @@ -8,7 +8,7 @@ export class ParametersDeclaration extends SlangNode { closeParen; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); if (offset) { const fetch = (childrenOffsets) => { @@ -18,13 +18,12 @@ export class ParametersDeclaration extends SlangNode { parameters, childrenOffsets.shift(), comments, - parse, options ); this.closeParen = closeParen.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/PathImport.js b/src/slang-nodes/PathImport.js index 2b0c91fe3..6402d9f0b 100644 --- a/src/slang-nodes/PathImport.js +++ b/src/slang-nodes/PathImport.js @@ -7,7 +7,7 @@ export class PathImport extends SlangNode { alias; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -16,22 +16,15 @@ export class PathImport extends SlangNode { path, childrenOffsets.shift(), comments, - parse, options ); this.alias = typeof alias === 'undefined' ? undefined - : new ImportAlias( - alias, - childrenOffsets.shift(), - comments, - parse, - options - ); + : new ImportAlias(alias, childrenOffsets.shift(), comments, options); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/PositionalArguments.js b/src/slang-nodes/PositionalArguments.js index 946ee156e..d98a87c41 100644 --- a/src/slang-nodes/PositionalArguments.js +++ b/src/slang-nodes/PositionalArguments.js @@ -7,25 +7,19 @@ export class PositionalArguments extends SlangNode { separators; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { const { items, separators } = ast; this.items = items.map( (item) => - new Expression( - item, - childrenOffsets.shift(), - comments, - parse, - options - ) + new Expression(item, childrenOffsets.shift(), comments, options) ); this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/PositionalArgumentsDeclaration.js b/src/slang-nodes/PositionalArgumentsDeclaration.js index a83300221..dba8142e2 100644 --- a/src/slang-nodes/PositionalArgumentsDeclaration.js +++ b/src/slang-nodes/PositionalArgumentsDeclaration.js @@ -8,7 +8,7 @@ export class PositionalArgumentsDeclaration extends SlangNode { closeParen; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -19,13 +19,12 @@ export class PositionalArgumentsDeclaration extends SlangNode { $arguments, childrenOffsets.shift(), comments, - parse, options ); this.closeParen = closeParen.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/PostfixExpression.js b/src/slang-nodes/PostfixExpression.js index d094bd3f0..59f35aac3 100644 --- a/src/slang-nodes/PostfixExpression.js +++ b/src/slang-nodes/PostfixExpression.js @@ -6,7 +6,7 @@ export class PostfixExpression extends SlangNode { operator; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -15,13 +15,12 @@ export class PostfixExpression extends SlangNode { operand, childrenOffsets.shift(), comments, - parse, options ); this.operator = operator.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/Pragma.js b/src/slang-nodes/Pragma.js index 5e9c9d8f1..37a038e29 100644 --- a/src/slang-nodes/Pragma.js +++ b/src/slang-nodes/Pragma.js @@ -7,7 +7,7 @@ const variants = { ABICoderPragma, ExperimentalPragma, VersionPragma }; export class Pragma extends SlangNode { variant; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -16,12 +16,11 @@ export class Pragma extends SlangNode { variant, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/PragmaDirective.js b/src/slang-nodes/PragmaDirective.js index 6b078dffa..9573cd360 100644 --- a/src/slang-nodes/PragmaDirective.js +++ b/src/slang-nodes/PragmaDirective.js @@ -8,7 +8,7 @@ export class PragmaDirective extends SlangNode { semicolon; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -18,13 +18,12 @@ export class PragmaDirective extends SlangNode { pragma, childrenOffsets.shift(), comments, - parse, options ); this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/PrefixExpression.js b/src/slang-nodes/PrefixExpression.js index 3cc85b63b..44cc6a9d5 100644 --- a/src/slang-nodes/PrefixExpression.js +++ b/src/slang-nodes/PrefixExpression.js @@ -6,7 +6,7 @@ export class PrefixExpression extends SlangNode { operand; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -16,12 +16,11 @@ export class PrefixExpression extends SlangNode { operand, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/ReceiveFunctionAttribute.js b/src/slang-nodes/ReceiveFunctionAttribute.js index a7655da16..7f9bceb8c 100644 --- a/src/slang-nodes/ReceiveFunctionAttribute.js +++ b/src/slang-nodes/ReceiveFunctionAttribute.js @@ -7,7 +7,7 @@ const variants = { ModifierInvocation, OverrideSpecifier }; export class ReceiveFunctionAttribute extends SlangNode { variant; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -19,12 +19,11 @@ export class ReceiveFunctionAttribute extends SlangNode { variant, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/ReceiveFunctionAttributes.js b/src/slang-nodes/ReceiveFunctionAttributes.js index 91038ec89..1e6a02c47 100644 --- a/src/slang-nodes/ReceiveFunctionAttributes.js +++ b/src/slang-nodes/ReceiveFunctionAttributes.js @@ -8,7 +8,7 @@ const { line } = doc.builders; export class ReceiveFunctionAttributes extends SlangNode { items; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -19,13 +19,12 @@ export class ReceiveFunctionAttributes extends SlangNode { item, childrenOffsets.shift(), comments, - parse, options ) ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); this.items = this.items.sort(sortFunctionAttributes); } diff --git a/src/slang-nodes/ReceiveFunctionDefinition.js b/src/slang-nodes/ReceiveFunctionDefinition.js index 337ce2529..18b73270c 100644 --- a/src/slang-nodes/ReceiveFunctionDefinition.js +++ b/src/slang-nodes/ReceiveFunctionDefinition.js @@ -13,7 +13,7 @@ export class ReceiveFunctionDefinition extends SlangNode { body; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -23,26 +23,23 @@ export class ReceiveFunctionDefinition extends SlangNode { parameters, childrenOffsets.shift(), comments, - parse, options ); this.attributes = new ReceiveFunctionAttributes( attributes, childrenOffsets.shift(), comments, - parse, options ); this.body = new FunctionBody( body, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); this.cleanModifierInvocationArguments(); } diff --git a/src/slang-nodes/ReturnStatement.js b/src/slang-nodes/ReturnStatement.js index eade4595a..12d378ea0 100644 --- a/src/slang-nodes/ReturnStatement.js +++ b/src/slang-nodes/ReturnStatement.js @@ -22,7 +22,7 @@ export class ReturnStatement extends SlangNode { semicolon; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -33,14 +33,13 @@ export class ReturnStatement extends SlangNode { expression, childrenOffsets.shift(), comments, - parse, options ); } this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print, options) { diff --git a/src/slang-nodes/ReturnsDeclaration.js b/src/slang-nodes/ReturnsDeclaration.js index 198c7e502..853884729 100644 --- a/src/slang-nodes/ReturnsDeclaration.js +++ b/src/slang-nodes/ReturnsDeclaration.js @@ -9,7 +9,7 @@ export class ReturnsDeclaration extends SlangNode { variables; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -19,12 +19,11 @@ export class ReturnsDeclaration extends SlangNode { variables, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/RevertStatement.js b/src/slang-nodes/RevertStatement.js index 8279649b2..2b9da0808 100644 --- a/src/slang-nodes/RevertStatement.js +++ b/src/slang-nodes/RevertStatement.js @@ -11,7 +11,7 @@ export class RevertStatement extends SlangNode { semicolon; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -22,7 +22,6 @@ export class RevertStatement extends SlangNode { error, childrenOffsets.shift(), comments, - parse, options ); } @@ -30,13 +29,12 @@ export class RevertStatement extends SlangNode { ast.arguments, childrenOffsets.shift(), comments, - parse, options ); this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/ShiftExpression.js b/src/slang-nodes/ShiftExpression.js index 1a6db46f7..3289eb104 100644 --- a/src/slang-nodes/ShiftExpression.js +++ b/src/slang-nodes/ShiftExpression.js @@ -21,7 +21,7 @@ export class ShiftExpression extends SlangNode { rightOperand; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -30,7 +30,6 @@ export class ShiftExpression extends SlangNode { leftOperand, childrenOffsets.shift(), comments, - parse, options ); this.operator = operator.text; @@ -38,12 +37,11 @@ export class ShiftExpression extends SlangNode { rightOperand, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); this.leftOperand = tryToHugLeftOperand(this.leftOperand); this.rightOperand = tryToHugRightOperand(this.rightOperand); diff --git a/src/slang-nodes/SourceUnit.js b/src/slang-nodes/SourceUnit.js index f2f6625ec..89f1c8dc2 100644 --- a/src/slang-nodes/SourceUnit.js +++ b/src/slang-nodes/SourceUnit.js @@ -7,7 +7,7 @@ const { line } = doc.builders; export class SourceUnit extends SlangNode { members; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -16,24 +16,11 @@ export class SourceUnit extends SlangNode { members, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); - } - - fetch(ast, childrenOffsets, comments) { - const { members } = ast; - return { - members: new SourceUnitMembers( - members, - childrenOffsets.shift(), - comments, - parse - ) - }; + this.initialize(ast, offset, comments, fetch); } print(path, print, options) { diff --git a/src/slang-nodes/SourceUnitMember.js b/src/slang-nodes/SourceUnitMember.js index 531a072fb..623e1ef8d 100644 --- a/src/slang-nodes/SourceUnitMember.js +++ b/src/slang-nodes/SourceUnitMember.js @@ -31,7 +31,7 @@ const variants = { export class SourceUnitMember extends SlangNode { variant; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -40,12 +40,11 @@ export class SourceUnitMember extends SlangNode { variant, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/SourceUnitMembers.js b/src/slang-nodes/SourceUnitMembers.js index 6099e8638..cc6472960 100644 --- a/src/slang-nodes/SourceUnitMembers.js +++ b/src/slang-nodes/SourceUnitMembers.js @@ -5,24 +5,18 @@ import { SourceUnitMember } from './SourceUnitMember.js'; export class SourceUnitMembers extends SlangNode { items; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { const { items } = ast; this.items = items.map( (item) => - new SourceUnitMember( - item, - childrenOffsets.shift(), - comments, - parse, - options - ) + new SourceUnitMember(item, childrenOffsets.shift(), comments, options) ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print, options) { diff --git a/src/slang-nodes/StateVariableAttribute.js b/src/slang-nodes/StateVariableAttribute.js index 72ba00ff6..ffba839b4 100644 --- a/src/slang-nodes/StateVariableAttribute.js +++ b/src/slang-nodes/StateVariableAttribute.js @@ -4,7 +4,7 @@ import { OverrideSpecifier } from './OverrideSpecifier.js'; export class StateVariableAttribute extends SlangNode { variant; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -16,12 +16,11 @@ export class StateVariableAttribute extends SlangNode { variant, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/StateVariableAttributes.js b/src/slang-nodes/StateVariableAttributes.js index b2d8c2710..a80c78e51 100644 --- a/src/slang-nodes/StateVariableAttributes.js +++ b/src/slang-nodes/StateVariableAttributes.js @@ -4,7 +4,7 @@ import { StateVariableAttribute } from './StateVariableAttribute.js'; export class StateVariableAttributes extends SlangNode { items; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -15,13 +15,12 @@ export class StateVariableAttributes extends SlangNode { item, childrenOffsets.shift(), comments, - parse, options ) ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/StateVariableDefinition.js b/src/slang-nodes/StateVariableDefinition.js index 7607602db..4a9534bcc 100644 --- a/src/slang-nodes/StateVariableDefinition.js +++ b/src/slang-nodes/StateVariableDefinition.js @@ -14,7 +14,7 @@ export class StateVariableDefinition extends SlangNode { semicolon; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -23,14 +23,12 @@ export class StateVariableDefinition extends SlangNode { typeName, childrenOffsets.shift(), comments, - parse, options ); this.attributes = new StateVariableAttributes( attributes, childrenOffsets.shift(), comments, - parse, options ); this.name = name.text; @@ -39,14 +37,13 @@ export class StateVariableDefinition extends SlangNode { value, childrenOffsets.shift(), comments, - parse, options ); } this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/StateVariableDefinitionValue.js b/src/slang-nodes/StateVariableDefinitionValue.js index f03828196..07e6e2b57 100644 --- a/src/slang-nodes/StateVariableDefinitionValue.js +++ b/src/slang-nodes/StateVariableDefinitionValue.js @@ -9,7 +9,7 @@ export class StateVariableDefinitionValue extends SlangNode { value; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -19,12 +19,11 @@ export class StateVariableDefinitionValue extends SlangNode { value, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/Statement.js b/src/slang-nodes/Statement.js index a8be293bc..808eecf06 100644 --- a/src/slang-nodes/Statement.js +++ b/src/slang-nodes/Statement.js @@ -40,7 +40,7 @@ const variants = { export class Statement extends SlangNode { variant; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -49,12 +49,11 @@ export class Statement extends SlangNode { variant, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/Statements.js b/src/slang-nodes/Statements.js index 8611c7543..e2080908f 100644 --- a/src/slang-nodes/Statements.js +++ b/src/slang-nodes/Statements.js @@ -10,18 +10,18 @@ const { hardline } = doc.builders; export class Statements extends SlangNode { items; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { const { items } = ast; this.items = items.map( (item) => - new Statement(item, childrenOffsets.shift(), comments, parse, options) + new Statement(item, childrenOffsets.shift(), comments, options) ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print, options) { diff --git a/src/slang-nodes/StorageLocation.js b/src/slang-nodes/StorageLocation.js index 663ccbdd2..66d8cc52f 100644 --- a/src/slang-nodes/StorageLocation.js +++ b/src/slang-nodes/StorageLocation.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class StorageLocation extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments) { super(); const fetch = () => { @@ -11,7 +11,7 @@ export class StorageLocation extends SlangNode { this.variant = variant.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print() { diff --git a/src/slang-nodes/StringExpression.js b/src/slang-nodes/StringExpression.js index cf7614d65..61cc067b2 100644 --- a/src/slang-nodes/StringExpression.js +++ b/src/slang-nodes/StringExpression.js @@ -16,7 +16,7 @@ const variants = { export class StringExpression extends SlangNode { variant; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { const { variant } = ast; @@ -24,12 +24,11 @@ export class StringExpression extends SlangNode { variant, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/StringLiteral.js b/src/slang-nodes/StringLiteral.js index c7b752495..b8b604511 100644 --- a/src/slang-nodes/StringLiteral.js +++ b/src/slang-nodes/StringLiteral.js @@ -4,7 +4,7 @@ import { SlangNode } from './SlangNode.js'; export class StringLiteral extends SlangNode { variant; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = () => { @@ -12,7 +12,7 @@ export class StringLiteral extends SlangNode { this.variant = variant.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); this.variant = printString(this.variant.slice(1, -1), options); } diff --git a/src/slang-nodes/StringLiterals.js b/src/slang-nodes/StringLiterals.js index 58e0e16f8..3f30f26ec 100644 --- a/src/slang-nodes/StringLiterals.js +++ b/src/slang-nodes/StringLiterals.js @@ -7,24 +7,18 @@ const { join, hardline } = doc.builders; export class StringLiterals extends SlangNode { items; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { const { items } = ast; this.items = items.map( (item) => - new StringLiteral( - item, - childrenOffsets.shift(), - comments, - parse, - options - ) + new StringLiteral(item, childrenOffsets.shift(), comments, options) ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/StructDefinition.js b/src/slang-nodes/StructDefinition.js index b55c4556c..1a9b7031d 100644 --- a/src/slang-nodes/StructDefinition.js +++ b/src/slang-nodes/StructDefinition.js @@ -12,7 +12,7 @@ export class StructDefinition extends SlangNode { closeBrace; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -24,13 +24,12 @@ export class StructDefinition extends SlangNode { members, childrenOffsets.shift(), comments, - parse, options ); this.closeBrace = closeBrace.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/StructMember.js b/src/slang-nodes/StructMember.js index dda090219..8268226a0 100644 --- a/src/slang-nodes/StructMember.js +++ b/src/slang-nodes/StructMember.js @@ -8,7 +8,7 @@ export class StructMember extends SlangNode { semicolon; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -17,14 +17,13 @@ export class StructMember extends SlangNode { typeName, childrenOffsets.shift(), comments, - parse, options ); this.name = name.text; this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/StructMembers.js b/src/slang-nodes/StructMembers.js index 4e9f5e0f1..cc3d8d19b 100644 --- a/src/slang-nodes/StructMembers.js +++ b/src/slang-nodes/StructMembers.js @@ -8,24 +8,18 @@ const { hardline } = doc.builders; export class StructMembers extends SlangNode { items; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { const { items } = ast; this.items = items.map( (item) => - new StructMember( - item, - childrenOffsets.shift(), - comments, - parse, - options - ) + new StructMember(item, childrenOffsets.shift(), comments, options) ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/ThrowStatement.js b/src/slang-nodes/ThrowStatement.js index dba210e5b..7dfbf153a 100644 --- a/src/slang-nodes/ThrowStatement.js +++ b/src/slang-nodes/ThrowStatement.js @@ -5,7 +5,7 @@ export class ThrowStatement extends SlangNode { semicolon; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments) { super(); const fetch = () => { @@ -14,7 +14,7 @@ export class ThrowStatement extends SlangNode { this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } // TODO: implement print diff --git a/src/slang-nodes/TryStatement.js b/src/slang-nodes/TryStatement.js index 828ba9add..9b5e7e87f 100644 --- a/src/slang-nodes/TryStatement.js +++ b/src/slang-nodes/TryStatement.js @@ -19,7 +19,7 @@ export class TryStatement extends SlangNode { catchClauses; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -29,7 +29,6 @@ export class TryStatement extends SlangNode { expression, childrenOffsets.shift(), comments, - parse, options ); if (returns) { @@ -37,27 +36,19 @@ export class TryStatement extends SlangNode { returns, childrenOffsets.shift(), comments, - parse, options ); } - this.body = new Block( - body, - childrenOffsets.shift(), - comments, - parse, - options - ); + this.body = new Block(body, childrenOffsets.shift(), comments, options); this.catchClauses = new CatchClauses( catchClauses, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/TupleDeconstructionElement.js b/src/slang-nodes/TupleDeconstructionElement.js index 6ed2774f9..d2f99ecbf 100644 --- a/src/slang-nodes/TupleDeconstructionElement.js +++ b/src/slang-nodes/TupleDeconstructionElement.js @@ -4,7 +4,7 @@ import { TupleMember } from './TupleMember.js'; export class TupleDeconstructionElement extends SlangNode { member; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -14,13 +14,12 @@ export class TupleDeconstructionElement extends SlangNode { member, childrenOffsets.shift(), comments, - parse, options ); } }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/TupleDeconstructionElements.js b/src/slang-nodes/TupleDeconstructionElements.js index f88072e48..a6e0e1785 100644 --- a/src/slang-nodes/TupleDeconstructionElements.js +++ b/src/slang-nodes/TupleDeconstructionElements.js @@ -7,7 +7,7 @@ export class TupleDeconstructionElements extends SlangNode { separators; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -18,14 +18,13 @@ export class TupleDeconstructionElements extends SlangNode { item, childrenOffsets.shift(), comments, - parse, options ) ); this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/TupleDeconstructionStatement.js b/src/slang-nodes/TupleDeconstructionStatement.js index a733d6b91..be09888cf 100644 --- a/src/slang-nodes/TupleDeconstructionStatement.js +++ b/src/slang-nodes/TupleDeconstructionStatement.js @@ -20,7 +20,7 @@ export class TupleDeconstructionStatement extends SlangNode { semicolon; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -39,7 +39,6 @@ export class TupleDeconstructionStatement extends SlangNode { elements, childrenOffsets.shift(), comments, - parse, options ); this.closeParen = closeParen.text; @@ -48,13 +47,12 @@ export class TupleDeconstructionStatement extends SlangNode { expression, childrenOffsets.shift(), comments, - parse, options ); this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/TupleExpression.js b/src/slang-nodes/TupleExpression.js index 1a6102aac..40c778c7e 100644 --- a/src/slang-nodes/TupleExpression.js +++ b/src/slang-nodes/TupleExpression.js @@ -8,7 +8,7 @@ export class TupleExpression extends SlangNode { closeParen; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); if (offset) { const fetch = (childrenOffsets) => { @@ -18,13 +18,12 @@ export class TupleExpression extends SlangNode { items, childrenOffsets.shift(), comments, - parse, options ); this.closeParen = closeParen.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/TupleMember.js b/src/slang-nodes/TupleMember.js index 3637bac76..2d92996a6 100644 --- a/src/slang-nodes/TupleMember.js +++ b/src/slang-nodes/TupleMember.js @@ -7,7 +7,7 @@ const variants = { TypedTupleMember, UntypedTupleMember }; export class TupleMember extends SlangNode { variant; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -16,12 +16,11 @@ export class TupleMember extends SlangNode { variant, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/TupleValue.js b/src/slang-nodes/TupleValue.js index ad5f3f3c9..8d0eda37f 100644 --- a/src/slang-nodes/TupleValue.js +++ b/src/slang-nodes/TupleValue.js @@ -4,7 +4,7 @@ import { Expression } from './Expression.js'; export class TupleValue extends SlangNode { expression; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); if (offset) { const fetch = (childrenOffsets) => { @@ -14,13 +14,12 @@ export class TupleValue extends SlangNode { expression, childrenOffsets.shift(), comments, - parse, options ); } }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/TupleValues.js b/src/slang-nodes/TupleValues.js index 6ca0eb961..690b4b9e0 100644 --- a/src/slang-nodes/TupleValues.js +++ b/src/slang-nodes/TupleValues.js @@ -8,25 +8,19 @@ export class TupleValues extends SlangNode { separators; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); if (offset) { const fetch = (childrenOffsets) => { const { items, separators } = ast; this.items = items.map( (item) => - new TupleValue( - item, - childrenOffsets.shift(), - comments, - parse, - options - ) + new TupleValue(item, childrenOffsets.shift(), comments, options) ); this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/TypeExpression.js b/src/slang-nodes/TypeExpression.js index 0f8594228..ba0e019c0 100644 --- a/src/slang-nodes/TypeExpression.js +++ b/src/slang-nodes/TypeExpression.js @@ -10,7 +10,7 @@ export class TypeExpression extends SlangNode { closeParen; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -21,13 +21,12 @@ export class TypeExpression extends SlangNode { typeName, childrenOffsets.shift(), comments, - parse, options ); this.closeParen = closeParen.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } // TODO: implement print diff --git a/src/slang-nodes/TypeName.js b/src/slang-nodes/TypeName.js index cb165e18e..78d0ce6d6 100644 --- a/src/slang-nodes/TypeName.js +++ b/src/slang-nodes/TypeName.js @@ -16,7 +16,7 @@ const variants = { export class TypeName extends SlangNode { variant; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { const { variant } = ast; @@ -24,12 +24,11 @@ export class TypeName extends SlangNode { variant, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/TypedTupleMember.js b/src/slang-nodes/TypedTupleMember.js index 44c4725e9..99a2bcc19 100644 --- a/src/slang-nodes/TypedTupleMember.js +++ b/src/slang-nodes/TypedTupleMember.js @@ -9,7 +9,7 @@ export class TypedTupleMember extends SlangNode { name; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -18,7 +18,6 @@ export class TypedTupleMember extends SlangNode { typeName, childrenOffsets.shift(), comments, - parse, options ); if (storageLocation) { @@ -26,14 +25,13 @@ export class TypedTupleMember extends SlangNode { storageLocation, childrenOffsets.shift(), comments, - parse, options ); } this.name = name.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/UncheckedBlock.js b/src/slang-nodes/UncheckedBlock.js index a65588972..b7635bffb 100644 --- a/src/slang-nodes/UncheckedBlock.js +++ b/src/slang-nodes/UncheckedBlock.js @@ -6,22 +6,16 @@ export class UncheckedBlock extends SlangNode { block; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { const { uncheckedKeyword, block } = ast; this.uncheckedKeyword = uncheckedKeyword.text; - this.block = new Block( - block, - childrenOffsets.shift(), - comments, - parse, - options - ); + this.block = new Block(block, childrenOffsets.shift(), comments, options); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/UnicodeStringLiteral.js b/src/slang-nodes/UnicodeStringLiteral.js index ac6f04f51..c5e4e3046 100644 --- a/src/slang-nodes/UnicodeStringLiteral.js +++ b/src/slang-nodes/UnicodeStringLiteral.js @@ -4,7 +4,7 @@ import { SlangNode } from './SlangNode.js'; export class UnicodeStringLiteral extends SlangNode { variant; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = () => { @@ -12,7 +12,7 @@ export class UnicodeStringLiteral extends SlangNode { this.variant = variant.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); this.variant = `unicode${printString(this.variant.slice(8, -1), options)}`; } diff --git a/src/slang-nodes/UnicodeStringLiterals.js b/src/slang-nodes/UnicodeStringLiterals.js index 3ccdabcf1..18752f9e2 100644 --- a/src/slang-nodes/UnicodeStringLiterals.js +++ b/src/slang-nodes/UnicodeStringLiterals.js @@ -7,7 +7,7 @@ const { join, hardline } = doc.builders; export class UnicodeStringLiterals extends SlangNode { items; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -18,13 +18,12 @@ export class UnicodeStringLiterals extends SlangNode { item, childrenOffsets.shift(), comments, - parse, options ) ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/UnnamedFunctionAttribute.js b/src/slang-nodes/UnnamedFunctionAttribute.js index 31061358b..ed19f9eed 100644 --- a/src/slang-nodes/UnnamedFunctionAttribute.js +++ b/src/slang-nodes/UnnamedFunctionAttribute.js @@ -4,7 +4,7 @@ import { ModifierInvocation } from './ModifierInvocation.js'; export class UnnamedFunctionAttribute extends SlangNode { variant; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -16,12 +16,11 @@ export class UnnamedFunctionAttribute extends SlangNode { variant, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/UnnamedFunctionAttributes.js b/src/slang-nodes/UnnamedFunctionAttributes.js index 58e3bff5a..a2f8243cf 100644 --- a/src/slang-nodes/UnnamedFunctionAttributes.js +++ b/src/slang-nodes/UnnamedFunctionAttributes.js @@ -8,7 +8,7 @@ const { line } = doc.builders; export class UnnamedFunctionAttributes extends SlangNode { items; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -19,13 +19,12 @@ export class UnnamedFunctionAttributes extends SlangNode { item, childrenOffsets.shift(), comments, - parse, options ) ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); this.items = this.items.sort(sortFunctionAttributes); } diff --git a/src/slang-nodes/UnnamedFunctionDefinition.js b/src/slang-nodes/UnnamedFunctionDefinition.js index 04278f6cf..60487a13d 100644 --- a/src/slang-nodes/UnnamedFunctionDefinition.js +++ b/src/slang-nodes/UnnamedFunctionDefinition.js @@ -13,7 +13,7 @@ export class UnnamedFunctionDefinition extends SlangNode { body; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -23,26 +23,23 @@ export class UnnamedFunctionDefinition extends SlangNode { parameters, childrenOffsets.shift(), comments, - parse, options ); this.attributes = new UnnamedFunctionAttributes( attributes, childrenOffsets.shift(), comments, - parse, options ); this.body = new FunctionBody( body, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); this.cleanModifierInvocationArguments(); } diff --git a/src/slang-nodes/UntypedTupleMember.js b/src/slang-nodes/UntypedTupleMember.js index 8538904fd..4cfc7f9f9 100644 --- a/src/slang-nodes/UntypedTupleMember.js +++ b/src/slang-nodes/UntypedTupleMember.js @@ -6,7 +6,7 @@ export class UntypedTupleMember extends SlangNode { name; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -17,14 +17,13 @@ export class UntypedTupleMember extends SlangNode { storageLocation, childrenOffsets.shift(), comments, - parse, options ); } this.name = name.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } // TODO: implement print diff --git a/src/slang-nodes/UserDefinedValueTypeDefinition.js b/src/slang-nodes/UserDefinedValueTypeDefinition.js index e8bcf830d..5d06f096d 100644 --- a/src/slang-nodes/UserDefinedValueTypeDefinition.js +++ b/src/slang-nodes/UserDefinedValueTypeDefinition.js @@ -12,7 +12,7 @@ export class UserDefinedValueTypeDefinition extends SlangNode { semicolon; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -24,13 +24,12 @@ export class UserDefinedValueTypeDefinition extends SlangNode { valueType, childrenOffsets.shift(), comments, - parse, options ); this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/UsingAlias.js b/src/slang-nodes/UsingAlias.js index 4b7dc354d..82b7bae99 100644 --- a/src/slang-nodes/UsingAlias.js +++ b/src/slang-nodes/UsingAlias.js @@ -6,7 +6,7 @@ export class UsingAlias extends SlangNode { operator; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -16,12 +16,11 @@ export class UsingAlias extends SlangNode { operator, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/UsingClause.js b/src/slang-nodes/UsingClause.js index 2206b1d22..2dac1dea0 100644 --- a/src/slang-nodes/UsingClause.js +++ b/src/slang-nodes/UsingClause.js @@ -7,7 +7,7 @@ const variants = { IdentifierPath, UsingDeconstruction }; export class UsingClause extends SlangNode { variant; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -16,12 +16,11 @@ export class UsingClause extends SlangNode { variant, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/UsingDeconstruction.js b/src/slang-nodes/UsingDeconstruction.js index 20f5dd2cb..aa5e76299 100644 --- a/src/slang-nodes/UsingDeconstruction.js +++ b/src/slang-nodes/UsingDeconstruction.js @@ -8,7 +8,7 @@ export class UsingDeconstruction extends SlangNode { closeBrace; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -18,13 +18,12 @@ export class UsingDeconstruction extends SlangNode { symbols, childrenOffsets.shift(), comments, - parse, options ); this.closeBrace = closeBrace.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/UsingDeconstructionSymbol.js b/src/slang-nodes/UsingDeconstructionSymbol.js index 22232c054..cb6c93402 100644 --- a/src/slang-nodes/UsingDeconstructionSymbol.js +++ b/src/slang-nodes/UsingDeconstructionSymbol.js @@ -7,7 +7,7 @@ export class UsingDeconstructionSymbol extends SlangNode { alias; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -16,7 +16,6 @@ export class UsingDeconstructionSymbol extends SlangNode { name, childrenOffsets.shift(), comments, - parse, options ); if (alias) { @@ -24,13 +23,12 @@ export class UsingDeconstructionSymbol extends SlangNode { alias, childrenOffsets.shift(), comments, - parse, options ); } }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/UsingDeconstructionSymbols.js b/src/slang-nodes/UsingDeconstructionSymbols.js index b9d99fcc2..70a47dc8c 100644 --- a/src/slang-nodes/UsingDeconstructionSymbols.js +++ b/src/slang-nodes/UsingDeconstructionSymbols.js @@ -10,7 +10,7 @@ export class UsingDeconstructionSymbols extends SlangNode { separators; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -21,14 +21,13 @@ export class UsingDeconstructionSymbols extends SlangNode { item, childrenOffsets.shift(), comments, - parse, options ) ); this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print, options) { diff --git a/src/slang-nodes/UsingDirective.js b/src/slang-nodes/UsingDirective.js index 60154fa8a..3b8e5d404 100644 --- a/src/slang-nodes/UsingDirective.js +++ b/src/slang-nodes/UsingDirective.js @@ -15,7 +15,7 @@ export class UsingDirective extends SlangNode { semicolon; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -32,7 +32,6 @@ export class UsingDirective extends SlangNode { clause, childrenOffsets.shift(), comments, - parse, options ); this.forKeyword = forKeyword.text; @@ -40,14 +39,13 @@ export class UsingDirective extends SlangNode { target, childrenOffsets.shift(), comments, - parse, options ); this.globalKeyword = globalKeyword?.text; this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/UsingOperator.js b/src/slang-nodes/UsingOperator.js index cac11fbfc..3af8bb3ac 100644 --- a/src/slang-nodes/UsingOperator.js +++ b/src/slang-nodes/UsingOperator.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class UsingOperator extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments) { super(); const fetch = () => { @@ -11,7 +11,7 @@ export class UsingOperator extends SlangNode { this.variant = variant.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print() { diff --git a/src/slang-nodes/UsingTarget.js b/src/slang-nodes/UsingTarget.js index 2a8eaaa55..2c16c2bf7 100644 --- a/src/slang-nodes/UsingTarget.js +++ b/src/slang-nodes/UsingTarget.js @@ -4,7 +4,7 @@ import { TypeName } from './TypeName.js'; export class UsingTarget extends SlangNode { variant; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -12,16 +12,10 @@ export class UsingTarget extends SlangNode { this.variant = variant.type === 'Terminal' ? variant.text - : new TypeName( - variant, - childrenOffsets.shift(), - comments, - parse, - options - ); + : new TypeName(variant, childrenOffsets.shift(), comments, options); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/VariableDeclarationStatement.js b/src/slang-nodes/VariableDeclarationStatement.js index 32e8a8c7f..c8567f9af 100644 --- a/src/slang-nodes/VariableDeclarationStatement.js +++ b/src/slang-nodes/VariableDeclarationStatement.js @@ -17,7 +17,7 @@ export class VariableDeclarationStatement extends SlangNode { semicolon; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -26,7 +26,6 @@ export class VariableDeclarationStatement extends SlangNode { variableType, childrenOffsets.shift(), comments, - parse, options ); if (storageLocation) { @@ -34,7 +33,6 @@ export class VariableDeclarationStatement extends SlangNode { storageLocation, childrenOffsets.shift(), comments, - parse, options ); } @@ -44,14 +42,13 @@ export class VariableDeclarationStatement extends SlangNode { value, childrenOffsets.shift(), comments, - parse, options ); } this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/VariableDeclarationType.js b/src/slang-nodes/VariableDeclarationType.js index 859963ea0..36e6c67b6 100644 --- a/src/slang-nodes/VariableDeclarationType.js +++ b/src/slang-nodes/VariableDeclarationType.js @@ -4,7 +4,7 @@ import { TypeName } from './TypeName.js'; export class VariableDeclarationType extends SlangNode { variant; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -12,16 +12,10 @@ export class VariableDeclarationType extends SlangNode { this.variant = variant.type === 'Terminal' ? variant.type - : new TypeName( - variant, - childrenOffsets.shift(), - comments, - parse, - options - ); + : new TypeName(variant, childrenOffsets.shift(), comments, options); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/VariableDeclarationValue.js b/src/slang-nodes/VariableDeclarationValue.js index 8ce1751c9..0d5dd151f 100644 --- a/src/slang-nodes/VariableDeclarationValue.js +++ b/src/slang-nodes/VariableDeclarationValue.js @@ -6,7 +6,7 @@ export class VariableDeclarationValue extends SlangNode { expression; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -16,12 +16,11 @@ export class VariableDeclarationValue extends SlangNode { expression, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/VersionComparator.js b/src/slang-nodes/VersionComparator.js index 77b6a998f..d2e235c69 100644 --- a/src/slang-nodes/VersionComparator.js +++ b/src/slang-nodes/VersionComparator.js @@ -5,7 +5,7 @@ export class VersionComparator extends SlangNode { operand; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -15,12 +15,11 @@ export class VersionComparator extends SlangNode { operand, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/VersionExpression.js b/src/slang-nodes/VersionExpression.js index 7dee4efe4..4a3a9fa6a 100644 --- a/src/slang-nodes/VersionExpression.js +++ b/src/slang-nodes/VersionExpression.js @@ -12,7 +12,7 @@ const variants = { export class VersionExpression extends SlangNode { variant; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -24,12 +24,11 @@ export class VersionExpression extends SlangNode { variant, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/VersionExpressionSet.js b/src/slang-nodes/VersionExpressionSet.js index c7767dac2..6e75f8e13 100644 --- a/src/slang-nodes/VersionExpressionSet.js +++ b/src/slang-nodes/VersionExpressionSet.js @@ -7,7 +7,7 @@ const { join } = doc.builders; export class VersionExpressionSet extends SlangNode { items; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -18,13 +18,12 @@ export class VersionExpressionSet extends SlangNode { item, childrenOffsets.shift(), comments, - parse, options ) ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/VersionExpressionSets.js b/src/slang-nodes/VersionExpressionSets.js index 7dc7faaad..406b3b458 100644 --- a/src/slang-nodes/VersionExpressionSets.js +++ b/src/slang-nodes/VersionExpressionSets.js @@ -6,7 +6,7 @@ export class VersionExpressionSets extends SlangNode { separators; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -17,14 +17,13 @@ export class VersionExpressionSets extends SlangNode { item, childrenOffsets.shift(), comments, - parse, options ) ); this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/VersionPragma.js b/src/slang-nodes/VersionPragma.js index b6036431a..5f55b4c61 100644 --- a/src/slang-nodes/VersionPragma.js +++ b/src/slang-nodes/VersionPragma.js @@ -6,7 +6,7 @@ export class VersionPragma extends SlangNode { sets; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -16,12 +16,11 @@ export class VersionPragma extends SlangNode { sets, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/VersionRange.js b/src/slang-nodes/VersionRange.js index d083318e1..2f3c020d8 100644 --- a/src/slang-nodes/VersionRange.js +++ b/src/slang-nodes/VersionRange.js @@ -8,7 +8,7 @@ export class VersionRange extends SlangNode { rightOperand; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -17,7 +17,6 @@ export class VersionRange extends SlangNode { leftOperand, childrenOffsets.shift(), comments, - parse, options ); this.operator = operator.text; @@ -25,12 +24,11 @@ export class VersionRange extends SlangNode { rightOperand, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } // TODO: implement print diff --git a/src/slang-nodes/VersionSpecifiers.js b/src/slang-nodes/VersionSpecifiers.js index 275863137..669bf06f0 100644 --- a/src/slang-nodes/VersionSpecifiers.js +++ b/src/slang-nodes/VersionSpecifiers.js @@ -5,7 +5,7 @@ export class VersionSpecifiers extends SlangNode { separators; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments) { super(); const fetch = () => { @@ -14,7 +14,7 @@ export class VersionSpecifiers extends SlangNode { this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print() { diff --git a/src/slang-nodes/WhileStatement.js b/src/slang-nodes/WhileStatement.js index 8856a83cd..95bb596b2 100644 --- a/src/slang-nodes/WhileStatement.js +++ b/src/slang-nodes/WhileStatement.js @@ -17,7 +17,7 @@ export class WhileStatement extends SlangNode { body; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -28,7 +28,6 @@ export class WhileStatement extends SlangNode { condition, childrenOffsets.shift(), comments, - parse, options ); this.closeParen = closeParen.text; @@ -36,12 +35,11 @@ export class WhileStatement extends SlangNode { body, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/YulArguments.js b/src/slang-nodes/YulArguments.js index c9494516d..ba6f96a44 100644 --- a/src/slang-nodes/YulArguments.js +++ b/src/slang-nodes/YulArguments.js @@ -7,25 +7,19 @@ export class YulArguments extends SlangNode { separators; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { const { items, separators } = ast; this.items = items.map( (item) => - new YulExpression( - item, - childrenOffsets.shift(), - comments, - parse, - options - ) + new YulExpression(item, childrenOffsets.shift(), comments, options) ); this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/YulAssignmentOperator.js b/src/slang-nodes/YulAssignmentOperator.js index 6401d984a..45edfee70 100644 --- a/src/slang-nodes/YulAssignmentOperator.js +++ b/src/slang-nodes/YulAssignmentOperator.js @@ -4,7 +4,7 @@ import { YulColonEqual } from './YulColonEqual.js'; export class YulAssignmentOperator extends SlangNode { variant; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -16,12 +16,11 @@ export class YulAssignmentOperator extends SlangNode { variant, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/YulBlock.js b/src/slang-nodes/YulBlock.js index eb89e2346..96bd6bac0 100644 --- a/src/slang-nodes/YulBlock.js +++ b/src/slang-nodes/YulBlock.js @@ -8,7 +8,7 @@ export class YulBlock extends SlangNode { closeBrace; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -18,13 +18,12 @@ export class YulBlock extends SlangNode { statements, childrenOffsets.shift(), comments, - parse, options ); this.closeBrace = closeBrace.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/YulBreakStatement.js b/src/slang-nodes/YulBreakStatement.js index fd29172bf..f18d841c6 100644 --- a/src/slang-nodes/YulBreakStatement.js +++ b/src/slang-nodes/YulBreakStatement.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class YulBreakStatement extends SlangNode { breakKeyword; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments) { super(); const fetch = () => { @@ -11,7 +11,7 @@ export class YulBreakStatement extends SlangNode { this.breakKeyword = breakKeyword.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print() { diff --git a/src/slang-nodes/YulBuiltInFunction.js b/src/slang-nodes/YulBuiltInFunction.js index 93071e372..932fe7b6e 100644 --- a/src/slang-nodes/YulBuiltInFunction.js +++ b/src/slang-nodes/YulBuiltInFunction.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class YulBuiltInFunction extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments) { super(); const fetch = () => { @@ -11,7 +11,7 @@ export class YulBuiltInFunction extends SlangNode { this.variant = variant.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print() { diff --git a/src/slang-nodes/YulColonEqual.js b/src/slang-nodes/YulColonEqual.js index 308cdd3d7..cdc8eb881 100644 --- a/src/slang-nodes/YulColonEqual.js +++ b/src/slang-nodes/YulColonEqual.js @@ -5,7 +5,7 @@ export class YulColonEqual extends SlangNode { equal; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments) { super(); const fetch = () => { @@ -14,7 +14,7 @@ export class YulColonEqual extends SlangNode { this.equal = equal.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } // TODO: implement print diff --git a/src/slang-nodes/YulContinueStatement.js b/src/slang-nodes/YulContinueStatement.js index 2200767fa..153991ea7 100644 --- a/src/slang-nodes/YulContinueStatement.js +++ b/src/slang-nodes/YulContinueStatement.js @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js'; export class YulContinueStatement extends SlangNode { continueKeyword; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments) { super(); const fetch = () => { @@ -11,7 +11,7 @@ export class YulContinueStatement extends SlangNode { this.continueKeyword = continueKeyword.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print() { diff --git a/src/slang-nodes/YulDefaultCase.js b/src/slang-nodes/YulDefaultCase.js index d3c076d71..df3acbac1 100644 --- a/src/slang-nodes/YulDefaultCase.js +++ b/src/slang-nodes/YulDefaultCase.js @@ -6,7 +6,7 @@ export class YulDefaultCase extends SlangNode { body; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -16,12 +16,11 @@ export class YulDefaultCase extends SlangNode { body, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/YulExpression.js b/src/slang-nodes/YulExpression.js index e7701ebb5..c1ef9361e 100644 --- a/src/slang-nodes/YulExpression.js +++ b/src/slang-nodes/YulExpression.js @@ -14,7 +14,7 @@ const variants = { export class YulExpression extends SlangNode { variant; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -23,12 +23,11 @@ export class YulExpression extends SlangNode { variant, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/YulForStatement.js b/src/slang-nodes/YulForStatement.js index 7adb010b6..97ae86254 100644 --- a/src/slang-nodes/YulForStatement.js +++ b/src/slang-nodes/YulForStatement.js @@ -13,7 +13,7 @@ export class YulForStatement extends SlangNode { body; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -23,33 +23,29 @@ export class YulForStatement extends SlangNode { initialization, childrenOffsets.shift(), comments, - parse, options ); this.condition = new YulExpression( condition, childrenOffsets.shift(), comments, - parse, options ); this.iterator = new YulBlock( iterator, childrenOffsets.shift(), comments, - parse, options ); this.body = new YulBlock( body, childrenOffsets.shift(), comments, - parse, options ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slang-nodes/YulFunctionCallExpression.js b/src/slang-nodes/YulFunctionCallExpression.js index 2ec41d788..40ac7237c 100644 --- a/src/slang-nodes/YulFunctionCallExpression.js +++ b/src/slang-nodes/YulFunctionCallExpression.js @@ -11,7 +11,7 @@ export class YulFunctionCallExpression extends SlangNode { closeParen; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => { @@ -20,7 +20,6 @@ export class YulFunctionCallExpression extends SlangNode { operand, childrenOffsets.shift(), comments, - parse, options ); this.openParen = openParen.text; @@ -28,13 +27,12 @@ export class YulFunctionCallExpression extends SlangNode { ast.arguments, childrenOffsets.shift(), comments, - parse, options ); this.closeParen = closeParen.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, comments, fetch); } print(path, print) { diff --git a/src/slangParser.js b/src/slangParser.js index 364198db3..0d17ecad8 100644 --- a/src/slangParser.js +++ b/src/slangParser.js @@ -8,13 +8,7 @@ import * as parsers from './slang-nodes/index.js'; function createGenericParse(options, comments) { return function genericParse(ast, offset = 0) { - return new parsers[ast.cst.kind]( - ast, - offset, - comments, - genericParse, - options - ); + return new parsers[ast.cst.kind](ast, offset, comments, options); }; } From c4b1072cee9aa296ea2b46e99de96891fcd864c8 Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 17 Jul 2024 17:14:07 +1200 Subject: [PATCH 087/160] reordering initialise parameters --- src/slang-nodes/ABICoderPragma.js | 2 +- src/slang-nodes/AdditiveExpression.js | 2 +- src/slang-nodes/AddressType.js | 2 +- src/slang-nodes/AndExpression.js | 2 +- src/slang-nodes/ArgumentsDeclaration.js | 2 +- src/slang-nodes/ArrayExpression.js | 2 +- src/slang-nodes/ArrayTypeName.js | 2 +- src/slang-nodes/ArrayValues.js | 2 +- src/slang-nodes/AssemblyFlags.js | 2 +- src/slang-nodes/AssemblyFlagsDeclaration.js | 2 +- src/slang-nodes/AssemblyStatement.js | 2 +- src/slang-nodes/AssignmentExpression.js | 2 +- src/slang-nodes/BitwiseAndExpression.js | 2 +- src/slang-nodes/BitwiseOrExpression.js | 2 +- src/slang-nodes/BitwiseXorExpression.js | 2 +- src/slang-nodes/Block.js | 2 +- src/slang-nodes/BreakStatement.js | 2 +- src/slang-nodes/CallOptions.js | 2 +- src/slang-nodes/CallOptionsExpression.js | 2 +- src/slang-nodes/CatchClause.js | 2 +- src/slang-nodes/CatchClauseError.js | 2 +- src/slang-nodes/CatchClauses.js | 2 +- src/slang-nodes/ComparisonExpression.js | 2 +- src/slang-nodes/ConditionalExpression.js | 2 +- src/slang-nodes/ConstantDefinition.js | 2 +- src/slang-nodes/ConstructorAttribute.js | 2 +- src/slang-nodes/ConstructorAttributes.js | 2 +- src/slang-nodes/ConstructorDefinition.js | 2 +- src/slang-nodes/ContinueStatement.js | 2 +- src/slang-nodes/ContractDefinition.js | 2 +- src/slang-nodes/ContractMember.js | 2 +- src/slang-nodes/ContractMembers.js | 2 +- src/slang-nodes/DecimalNumberExpression.js | 2 +- src/slang-nodes/DoWhileStatement.js | 2 +- src/slang-nodes/ElementaryType.js | 2 +- src/slang-nodes/ElseBranch.js | 2 +- src/slang-nodes/EmitStatement.js | 2 +- src/slang-nodes/EnumDefinition.js | 2 +- src/slang-nodes/EnumMembers.js | 2 +- src/slang-nodes/EqualityExpression.js | 2 +- src/slang-nodes/ErrorDefinition.js | 2 +- src/slang-nodes/ErrorParameter.js | 2 +- src/slang-nodes/ErrorParameters.js | 2 +- src/slang-nodes/ErrorParametersDeclaration.js | 2 +- src/slang-nodes/EventDefinition.js | 2 +- src/slang-nodes/EventParameter.js | 2 +- src/slang-nodes/EventParameters.js | 2 +- src/slang-nodes/EventParametersDeclaration.js | 2 +- src/slang-nodes/ExperimentalFeature.js | 2 +- src/slang-nodes/ExperimentalPragma.js | 2 +- src/slang-nodes/ExponentiationExpression.js | 2 +- src/slang-nodes/Expression.js | 2 +- src/slang-nodes/ExpressionStatement.js | 2 +- src/slang-nodes/FallbackFunctionAttribute.js | 2 +- src/slang-nodes/FallbackFunctionAttributes.js | 2 +- src/slang-nodes/FallbackFunctionDefinition.js | 2 +- src/slang-nodes/ForStatement.js | 2 +- src/slang-nodes/ForStatementCondition.js | 2 +- src/slang-nodes/ForStatementInitialization.js | 2 +- src/slang-nodes/FunctionAttribute.js | 2 +- src/slang-nodes/FunctionAttributes.js | 2 +- src/slang-nodes/FunctionBody.js | 2 +- src/slang-nodes/FunctionCallExpression.js | 2 +- src/slang-nodes/FunctionDefinition.js | 2 +- src/slang-nodes/FunctionName.js | 2 +- src/slang-nodes/FunctionType.js | 2 +- src/slang-nodes/FunctionTypeAttribute.js | 2 +- src/slang-nodes/FunctionTypeAttributes.js | 2 +- src/slang-nodes/HexNumberExpression.js | 2 +- src/slang-nodes/HexStringLiteral.js | 2 +- src/slang-nodes/HexStringLiterals.js | 2 +- src/slang-nodes/IdentifierPath.js | 2 +- src/slang-nodes/IfStatement.js | 2 +- src/slang-nodes/ImportAlias.js | 2 +- src/slang-nodes/ImportClause.js | 2 +- src/slang-nodes/ImportDeconstruction.js | 2 +- src/slang-nodes/ImportDeconstructionSymbol.js | 2 +- src/slang-nodes/ImportDeconstructionSymbols.js | 2 +- src/slang-nodes/ImportDirective.js | 2 +- src/slang-nodes/IndexAccessEnd.js | 2 +- src/slang-nodes/IndexAccessExpression.js | 2 +- src/slang-nodes/InheritanceSpecifier.js | 2 +- src/slang-nodes/InheritanceType.js | 2 +- src/slang-nodes/InheritanceTypes.js | 2 +- src/slang-nodes/InterfaceDefinition.js | 2 +- src/slang-nodes/InterfaceMembers.js | 2 +- src/slang-nodes/LibraryDefinition.js | 2 +- src/slang-nodes/LibraryMembers.js | 2 +- src/slang-nodes/MappingKey.js | 2 +- src/slang-nodes/MappingKeyType.js | 2 +- src/slang-nodes/MappingType.js | 2 +- src/slang-nodes/MappingValue.js | 2 +- src/slang-nodes/MemberAccess.js | 2 +- src/slang-nodes/MemberAccessExpression.js | 2 +- src/slang-nodes/ModifierAttribute.js | 2 +- src/slang-nodes/ModifierAttributes.js | 2 +- src/slang-nodes/ModifierDefinition.js | 2 +- src/slang-nodes/ModifierInvocation.js | 2 +- src/slang-nodes/MultiplicativeExpression.js | 2 +- src/slang-nodes/NamedArgument.js | 2 +- src/slang-nodes/NamedArgumentGroup.js | 2 +- src/slang-nodes/NamedArguments.js | 2 +- src/slang-nodes/NamedArgumentsDeclaration.js | 2 +- src/slang-nodes/NamedImport.js | 2 +- src/slang-nodes/NewExpression.js | 2 +- src/slang-nodes/NumberUnit.js | 2 +- src/slang-nodes/OrExpression.js | 2 +- src/slang-nodes/OverridePaths.js | 2 +- src/slang-nodes/OverridePathsDeclaration.js | 2 +- src/slang-nodes/OverrideSpecifier.js | 2 +- src/slang-nodes/Parameter.js | 2 +- src/slang-nodes/Parameters.js | 2 +- src/slang-nodes/ParametersDeclaration.js | 2 +- src/slang-nodes/PathImport.js | 2 +- src/slang-nodes/PositionalArguments.js | 2 +- src/slang-nodes/PositionalArgumentsDeclaration.js | 2 +- src/slang-nodes/PostfixExpression.js | 2 +- src/slang-nodes/Pragma.js | 2 +- src/slang-nodes/PragmaDirective.js | 2 +- src/slang-nodes/PrefixExpression.js | 2 +- src/slang-nodes/ReceiveFunctionAttribute.js | 2 +- src/slang-nodes/ReceiveFunctionAttributes.js | 2 +- src/slang-nodes/ReceiveFunctionDefinition.js | 2 +- src/slang-nodes/ReturnStatement.js | 2 +- src/slang-nodes/ReturnsDeclaration.js | 2 +- src/slang-nodes/RevertStatement.js | 2 +- src/slang-nodes/ShiftExpression.js | 2 +- src/slang-nodes/SlangNode.js | 2 +- src/slang-nodes/SourceUnit.js | 2 +- src/slang-nodes/SourceUnitMember.js | 2 +- src/slang-nodes/SourceUnitMembers.js | 2 +- src/slang-nodes/StateVariableAttribute.js | 2 +- src/slang-nodes/StateVariableAttributes.js | 2 +- src/slang-nodes/StateVariableDefinition.js | 2 +- src/slang-nodes/StateVariableDefinitionValue.js | 2 +- src/slang-nodes/Statement.js | 2 +- src/slang-nodes/Statements.js | 2 +- src/slang-nodes/StorageLocation.js | 2 +- src/slang-nodes/StringExpression.js | 2 +- src/slang-nodes/StringLiteral.js | 2 +- src/slang-nodes/StringLiterals.js | 2 +- src/slang-nodes/StructDefinition.js | 2 +- src/slang-nodes/StructMember.js | 2 +- src/slang-nodes/StructMembers.js | 2 +- src/slang-nodes/ThrowStatement.js | 2 +- src/slang-nodes/TryStatement.js | 2 +- src/slang-nodes/TupleDeconstructionElement.js | 2 +- src/slang-nodes/TupleDeconstructionElements.js | 2 +- src/slang-nodes/TupleDeconstructionStatement.js | 2 +- src/slang-nodes/TupleExpression.js | 2 +- src/slang-nodes/TupleMember.js | 2 +- src/slang-nodes/TupleValue.js | 2 +- src/slang-nodes/TupleValues.js | 2 +- src/slang-nodes/TypeExpression.js | 2 +- src/slang-nodes/TypeName.js | 2 +- src/slang-nodes/TypedTupleMember.js | 2 +- src/slang-nodes/UncheckedBlock.js | 2 +- src/slang-nodes/UnicodeStringLiteral.js | 2 +- src/slang-nodes/UnicodeStringLiterals.js | 2 +- src/slang-nodes/UnnamedFunctionAttribute.js | 2 +- src/slang-nodes/UnnamedFunctionAttributes.js | 2 +- src/slang-nodes/UnnamedFunctionDefinition.js | 2 +- src/slang-nodes/UntypedTupleMember.js | 2 +- src/slang-nodes/UserDefinedValueTypeDefinition.js | 2 +- src/slang-nodes/UsingAlias.js | 2 +- src/slang-nodes/UsingClause.js | 2 +- src/slang-nodes/UsingDeconstruction.js | 2 +- src/slang-nodes/UsingDeconstructionSymbol.js | 2 +- src/slang-nodes/UsingDeconstructionSymbols.js | 2 +- src/slang-nodes/UsingDirective.js | 2 +- src/slang-nodes/UsingOperator.js | 2 +- src/slang-nodes/UsingTarget.js | 2 +- src/slang-nodes/VariableDeclarationStatement.js | 2 +- src/slang-nodes/VariableDeclarationType.js | 2 +- src/slang-nodes/VariableDeclarationValue.js | 2 +- src/slang-nodes/VersionComparator.js | 2 +- src/slang-nodes/VersionExpression.js | 2 +- src/slang-nodes/VersionExpressionSet.js | 2 +- src/slang-nodes/VersionExpressionSets.js | 2 +- src/slang-nodes/VersionPragma.js | 2 +- src/slang-nodes/VersionRange.js | 2 +- src/slang-nodes/VersionSpecifiers.js | 2 +- src/slang-nodes/WhileStatement.js | 2 +- src/slang-nodes/YulArguments.js | 2 +- src/slang-nodes/YulAssignmentOperator.js | 2 +- src/slang-nodes/YulBlock.js | 2 +- src/slang-nodes/YulBreakStatement.js | 2 +- src/slang-nodes/YulBuiltInFunction.js | 2 +- src/slang-nodes/YulColonEqual.js | 2 +- src/slang-nodes/YulContinueStatement.js | 2 +- src/slang-nodes/YulDefaultCase.js | 2 +- src/slang-nodes/YulExpression.js | 2 +- src/slang-nodes/YulForStatement.js | 2 +- src/slang-nodes/YulFunctionCallExpression.js | 2 +- src/slang-nodes/YulFunctionDefinition.js | 2 +- src/slang-nodes/YulIfStatement.js | 2 +- src/slang-nodes/YulLabel.js | 2 +- src/slang-nodes/YulLeaveStatement.js | 2 +- src/slang-nodes/YulLiteral.js | 2 +- src/slang-nodes/YulParameters.js | 2 +- src/slang-nodes/YulParametersDeclaration.js | 2 +- src/slang-nodes/YulPath.js | 2 +- src/slang-nodes/YulPathComponent.js | 2 +- src/slang-nodes/YulPaths.js | 2 +- src/slang-nodes/YulReturnVariables.js | 2 +- src/slang-nodes/YulReturnsDeclaration.js | 2 +- src/slang-nodes/YulStackAssignmentStatement.js | 2 +- src/slang-nodes/YulStatement.js | 2 +- src/slang-nodes/YulStatements.js | 2 +- src/slang-nodes/YulSwitchCase.js | 2 +- src/slang-nodes/YulSwitchCases.js | 2 +- src/slang-nodes/YulSwitchStatement.js | 2 +- src/slang-nodes/YulValueCase.js | 2 +- src/slang-nodes/YulVariableAssignmentStatement.js | 2 +- src/slang-nodes/YulVariableDeclarationStatement.js | 2 +- src/slang-nodes/YulVariableDeclarationValue.js | 2 +- src/slangParser.js | 2 +- 217 files changed, 217 insertions(+), 217 deletions(-) diff --git a/src/slang-nodes/ABICoderPragma.js b/src/slang-nodes/ABICoderPragma.js index 979bd0b59..8a898a2ff 100644 --- a/src/slang-nodes/ABICoderPragma.js +++ b/src/slang-nodes/ABICoderPragma.js @@ -14,7 +14,7 @@ export class ABICoderPragma extends SlangNode { this.version = version.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print() { diff --git a/src/slang-nodes/AdditiveExpression.js b/src/slang-nodes/AdditiveExpression.js index 5ff2f77f5..3030af42c 100644 --- a/src/slang-nodes/AdditiveExpression.js +++ b/src/slang-nodes/AdditiveExpression.js @@ -32,7 +32,7 @@ export class AdditiveExpression extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); diff --git a/src/slang-nodes/AddressType.js b/src/slang-nodes/AddressType.js index f57d58307..5d80d6dda 100644 --- a/src/slang-nodes/AddressType.js +++ b/src/slang-nodes/AddressType.js @@ -14,7 +14,7 @@ export class AddressType extends SlangNode { this.payableKeyword = payableKeyword?.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print() { diff --git a/src/slang-nodes/AndExpression.js b/src/slang-nodes/AndExpression.js index 1d4b4f0d6..50ed7c6d4 100644 --- a/src/slang-nodes/AndExpression.js +++ b/src/slang-nodes/AndExpression.js @@ -29,7 +29,7 @@ export class AndExpression extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print, options) { diff --git a/src/slang-nodes/ArgumentsDeclaration.js b/src/slang-nodes/ArgumentsDeclaration.js index 6b1ff756e..83ac08bbf 100644 --- a/src/slang-nodes/ArgumentsDeclaration.js +++ b/src/slang-nodes/ArgumentsDeclaration.js @@ -20,7 +20,7 @@ export class ArgumentsDeclaration extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/ArrayExpression.js b/src/slang-nodes/ArrayExpression.js index da43c177d..0c55f4f58 100644 --- a/src/slang-nodes/ArrayExpression.js +++ b/src/slang-nodes/ArrayExpression.js @@ -26,7 +26,7 @@ export class ArrayExpression extends SlangNode { this.closeBracket = closeBracket.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/ArrayTypeName.js b/src/slang-nodes/ArrayTypeName.js index 6d4b4a5c7..754f3eab1 100644 --- a/src/slang-nodes/ArrayTypeName.js +++ b/src/slang-nodes/ArrayTypeName.js @@ -34,7 +34,7 @@ export class ArrayTypeName extends SlangNode { this.closeBracket = closeBracket.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/ArrayValues.js b/src/slang-nodes/ArrayValues.js index 2ac3946b5..4f9d2333a 100644 --- a/src/slang-nodes/ArrayValues.js +++ b/src/slang-nodes/ArrayValues.js @@ -19,7 +19,7 @@ export class ArrayValues extends SlangNode { this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/AssemblyFlags.js b/src/slang-nodes/AssemblyFlags.js index 352a3e409..fe81efc91 100644 --- a/src/slang-nodes/AssemblyFlags.js +++ b/src/slang-nodes/AssemblyFlags.js @@ -19,7 +19,7 @@ export class AssemblyFlags extends SlangNode { this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/AssemblyFlagsDeclaration.js b/src/slang-nodes/AssemblyFlagsDeclaration.js index de18d53e7..1be70c137 100644 --- a/src/slang-nodes/AssemblyFlagsDeclaration.js +++ b/src/slang-nodes/AssemblyFlagsDeclaration.js @@ -23,7 +23,7 @@ export class AssemblyFlagsDeclaration extends SlangNode { this.closeParen = closeParen.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/AssemblyStatement.js b/src/slang-nodes/AssemblyStatement.js index 2a33a39d3..d440ccf8a 100644 --- a/src/slang-nodes/AssemblyStatement.js +++ b/src/slang-nodes/AssemblyStatement.js @@ -42,7 +42,7 @@ export class AssemblyStatement extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/AssignmentExpression.js b/src/slang-nodes/AssignmentExpression.js index 212c41135..60a014f57 100644 --- a/src/slang-nodes/AssignmentExpression.js +++ b/src/slang-nodes/AssignmentExpression.js @@ -32,7 +32,7 @@ export class AssignmentExpression extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/BitwiseAndExpression.js b/src/slang-nodes/BitwiseAndExpression.js index 906ef00bd..b68a55d42 100644 --- a/src/slang-nodes/BitwiseAndExpression.js +++ b/src/slang-nodes/BitwiseAndExpression.js @@ -32,7 +32,7 @@ export class BitwiseAndExpression extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); diff --git a/src/slang-nodes/BitwiseOrExpression.js b/src/slang-nodes/BitwiseOrExpression.js index 2bae6059d..9b2f6ff7e 100644 --- a/src/slang-nodes/BitwiseOrExpression.js +++ b/src/slang-nodes/BitwiseOrExpression.js @@ -42,7 +42,7 @@ export class BitwiseOrExpression extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); diff --git a/src/slang-nodes/BitwiseXorExpression.js b/src/slang-nodes/BitwiseXorExpression.js index 5c7348d4b..f28d84aa9 100644 --- a/src/slang-nodes/BitwiseXorExpression.js +++ b/src/slang-nodes/BitwiseXorExpression.js @@ -32,7 +32,7 @@ export class BitwiseXorExpression extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); diff --git a/src/slang-nodes/Block.js b/src/slang-nodes/Block.js index f51e278e9..a0962d90f 100644 --- a/src/slang-nodes/Block.js +++ b/src/slang-nodes/Block.js @@ -23,7 +23,7 @@ export class Block extends SlangNode { this.closeBrace = closeBrace.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/BreakStatement.js b/src/slang-nodes/BreakStatement.js index a61474474..90cd52fcb 100644 --- a/src/slang-nodes/BreakStatement.js +++ b/src/slang-nodes/BreakStatement.js @@ -14,7 +14,7 @@ export class BreakStatement extends SlangNode { this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print() { diff --git a/src/slang-nodes/CallOptions.js b/src/slang-nodes/CallOptions.js index 7b00a341d..2758b35d1 100644 --- a/src/slang-nodes/CallOptions.js +++ b/src/slang-nodes/CallOptions.js @@ -22,7 +22,7 @@ export class CallOptions extends SlangNode { this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print, options) { diff --git a/src/slang-nodes/CallOptionsExpression.js b/src/slang-nodes/CallOptionsExpression.js index f257190f1..6783232fe 100644 --- a/src/slang-nodes/CallOptionsExpression.js +++ b/src/slang-nodes/CallOptionsExpression.js @@ -32,7 +32,7 @@ export class CallOptionsExpression extends SlangNode { this.closeBrace = closeBrace.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/CatchClause.js b/src/slang-nodes/CatchClause.js index 9ed9a1f24..263b21263 100644 --- a/src/slang-nodes/CatchClause.js +++ b/src/slang-nodes/CatchClause.js @@ -26,7 +26,7 @@ export class CatchClause extends SlangNode { this.body = new Block(body, childrenOffsets.shift(), comments, options); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/CatchClauseError.js b/src/slang-nodes/CatchClauseError.js index f1c8640cc..4822df75e 100644 --- a/src/slang-nodes/CatchClauseError.js +++ b/src/slang-nodes/CatchClauseError.js @@ -23,7 +23,7 @@ export class CatchClauseError extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/CatchClauses.js b/src/slang-nodes/CatchClauses.js index 6f3faa4df..f33c635c0 100644 --- a/src/slang-nodes/CatchClauses.js +++ b/src/slang-nodes/CatchClauses.js @@ -18,7 +18,7 @@ export class CatchClauses extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/ComparisonExpression.js b/src/slang-nodes/ComparisonExpression.js index cdc0949b6..0f398fa68 100644 --- a/src/slang-nodes/ComparisonExpression.js +++ b/src/slang-nodes/ComparisonExpression.js @@ -29,7 +29,7 @@ export class ComparisonExpression extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print, options) { diff --git a/src/slang-nodes/ConditionalExpression.js b/src/slang-nodes/ConditionalExpression.js index 2b9924758..c6fcfba75 100644 --- a/src/slang-nodes/ConditionalExpression.js +++ b/src/slang-nodes/ConditionalExpression.js @@ -124,7 +124,7 @@ export class ConditionalExpression extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); // TODO: while the behaviour is not stable, it should be behind the // experimentalTernaries flag. diff --git a/src/slang-nodes/ConstantDefinition.js b/src/slang-nodes/ConstantDefinition.js index cc33ca75e..48e0b6298 100644 --- a/src/slang-nodes/ConstantDefinition.js +++ b/src/slang-nodes/ConstantDefinition.js @@ -38,7 +38,7 @@ export class ConstantDefinition extends SlangNode { this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } // TODO: implement print diff --git a/src/slang-nodes/ConstructorAttribute.js b/src/slang-nodes/ConstructorAttribute.js index 0647398a4..535a85557 100644 --- a/src/slang-nodes/ConstructorAttribute.js +++ b/src/slang-nodes/ConstructorAttribute.js @@ -20,7 +20,7 @@ export class ConstructorAttribute extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/ConstructorAttributes.js b/src/slang-nodes/ConstructorAttributes.js index 2f8429c9b..a73928cb7 100644 --- a/src/slang-nodes/ConstructorAttributes.js +++ b/src/slang-nodes/ConstructorAttributes.js @@ -24,7 +24,7 @@ export class ConstructorAttributes extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); this.items = this.items.sort(sortFunctionAttributes); } diff --git a/src/slang-nodes/ConstructorDefinition.js b/src/slang-nodes/ConstructorDefinition.js index c14e7240f..3d4f06e01 100644 --- a/src/slang-nodes/ConstructorDefinition.js +++ b/src/slang-nodes/ConstructorDefinition.js @@ -34,7 +34,7 @@ export class ConstructorDefinition extends SlangNode { this.body = new Block(body, childrenOffsets.shift(), comments, options); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/ContinueStatement.js b/src/slang-nodes/ContinueStatement.js index 7ade5cfea..1cf5351d7 100644 --- a/src/slang-nodes/ContinueStatement.js +++ b/src/slang-nodes/ContinueStatement.js @@ -14,7 +14,7 @@ export class ContinueStatement extends SlangNode { this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print() { diff --git a/src/slang-nodes/ContractDefinition.js b/src/slang-nodes/ContractDefinition.js index d40107d22..6e32dda14 100644 --- a/src/slang-nodes/ContractDefinition.js +++ b/src/slang-nodes/ContractDefinition.js @@ -56,7 +56,7 @@ export class ContractDefinition extends SlangNode { this.closeBrace = closeBrace.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); this.cleanModifierInvocationArguments(options); } diff --git a/src/slang-nodes/ContractMember.js b/src/slang-nodes/ContractMember.js index a5f248c53..e78375f38 100644 --- a/src/slang-nodes/ContractMember.js +++ b/src/slang-nodes/ContractMember.js @@ -45,7 +45,7 @@ export class ContractMember extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/ContractMembers.js b/src/slang-nodes/ContractMembers.js index 7b7cfb662..17bdd4acf 100644 --- a/src/slang-nodes/ContractMembers.js +++ b/src/slang-nodes/ContractMembers.js @@ -21,7 +21,7 @@ export class ContractMembers extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print, options) { diff --git a/src/slang-nodes/DecimalNumberExpression.js b/src/slang-nodes/DecimalNumberExpression.js index 7a2935945..454010a9e 100644 --- a/src/slang-nodes/DecimalNumberExpression.js +++ b/src/slang-nodes/DecimalNumberExpression.js @@ -22,7 +22,7 @@ export class DecimalNumberExpression extends SlangNode { } }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/DoWhileStatement.js b/src/slang-nodes/DoWhileStatement.js index 5dffc1315..d91b89df2 100644 --- a/src/slang-nodes/DoWhileStatement.js +++ b/src/slang-nodes/DoWhileStatement.js @@ -53,7 +53,7 @@ export class DoWhileStatement extends SlangNode { this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/ElementaryType.js b/src/slang-nodes/ElementaryType.js index 88155c60b..8096e8aa6 100644 --- a/src/slang-nodes/ElementaryType.js +++ b/src/slang-nodes/ElementaryType.js @@ -19,7 +19,7 @@ export class ElementaryType extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/ElseBranch.js b/src/slang-nodes/ElseBranch.js index 44eb1c68a..fa2b1e9c6 100644 --- a/src/slang-nodes/ElseBranch.js +++ b/src/slang-nodes/ElseBranch.js @@ -26,7 +26,7 @@ export class ElseBranch extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/EmitStatement.js b/src/slang-nodes/EmitStatement.js index f27e1fa05..c3458ee1c 100644 --- a/src/slang-nodes/EmitStatement.js +++ b/src/slang-nodes/EmitStatement.js @@ -32,7 +32,7 @@ export class EmitStatement extends SlangNode { this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/EnumDefinition.js b/src/slang-nodes/EnumDefinition.js index 0782f26a1..907d86afb 100644 --- a/src/slang-nodes/EnumDefinition.js +++ b/src/slang-nodes/EnumDefinition.js @@ -29,7 +29,7 @@ export class EnumDefinition extends SlangNode { this.closeBrace = closeBrace.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/EnumMembers.js b/src/slang-nodes/EnumMembers.js index dbc18839b..2b99bf15b 100644 --- a/src/slang-nodes/EnumMembers.js +++ b/src/slang-nodes/EnumMembers.js @@ -18,7 +18,7 @@ export class EnumMembers extends SlangNode { this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print() { diff --git a/src/slang-nodes/EqualityExpression.js b/src/slang-nodes/EqualityExpression.js index 72658ffa9..f8dcfbcd8 100644 --- a/src/slang-nodes/EqualityExpression.js +++ b/src/slang-nodes/EqualityExpression.js @@ -29,7 +29,7 @@ export class EqualityExpression extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print, options) { diff --git a/src/slang-nodes/ErrorDefinition.js b/src/slang-nodes/ErrorDefinition.js index f97b43efd..ce45fb762 100644 --- a/src/slang-nodes/ErrorDefinition.js +++ b/src/slang-nodes/ErrorDefinition.js @@ -26,7 +26,7 @@ export class ErrorDefinition extends SlangNode { this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/ErrorParameter.js b/src/slang-nodes/ErrorParameter.js index 52e817a06..deb60d444 100644 --- a/src/slang-nodes/ErrorParameter.js +++ b/src/slang-nodes/ErrorParameter.js @@ -20,7 +20,7 @@ export class ErrorParameter extends SlangNode { this.name = name?.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/ErrorParameters.js b/src/slang-nodes/ErrorParameters.js index eabe55663..1a50749c9 100644 --- a/src/slang-nodes/ErrorParameters.js +++ b/src/slang-nodes/ErrorParameters.js @@ -19,7 +19,7 @@ export class ErrorParameters extends SlangNode { this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/ErrorParametersDeclaration.js b/src/slang-nodes/ErrorParametersDeclaration.js index 66e155347..42dc1048f 100644 --- a/src/slang-nodes/ErrorParametersDeclaration.js +++ b/src/slang-nodes/ErrorParametersDeclaration.js @@ -23,7 +23,7 @@ export class ErrorParametersDeclaration extends SlangNode { this.closeParen = closeParen.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/EventDefinition.js b/src/slang-nodes/EventDefinition.js index cab073f6a..a5d8b9b10 100644 --- a/src/slang-nodes/EventDefinition.js +++ b/src/slang-nodes/EventDefinition.js @@ -30,7 +30,7 @@ export class EventDefinition extends SlangNode { this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/EventParameter.js b/src/slang-nodes/EventParameter.js index 41b76261c..74da729bd 100644 --- a/src/slang-nodes/EventParameter.js +++ b/src/slang-nodes/EventParameter.js @@ -23,7 +23,7 @@ export class EventParameter extends SlangNode { this.name = name?.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/EventParameters.js b/src/slang-nodes/EventParameters.js index b586cb1d8..a866d0e6f 100644 --- a/src/slang-nodes/EventParameters.js +++ b/src/slang-nodes/EventParameters.js @@ -19,7 +19,7 @@ export class EventParameters extends SlangNode { this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/EventParametersDeclaration.js b/src/slang-nodes/EventParametersDeclaration.js index 6bdafcda3..662eac083 100644 --- a/src/slang-nodes/EventParametersDeclaration.js +++ b/src/slang-nodes/EventParametersDeclaration.js @@ -23,7 +23,7 @@ export class EventParametersDeclaration extends SlangNode { this.closeParen = closeParen.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/ExperimentalFeature.js b/src/slang-nodes/ExperimentalFeature.js index 57967b07e..cd9ca772d 100644 --- a/src/slang-nodes/ExperimentalFeature.js +++ b/src/slang-nodes/ExperimentalFeature.js @@ -20,7 +20,7 @@ export class ExperimentalFeature extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/ExperimentalPragma.js b/src/slang-nodes/ExperimentalPragma.js index bbf626c36..f7ad76e52 100644 --- a/src/slang-nodes/ExperimentalPragma.js +++ b/src/slang-nodes/ExperimentalPragma.js @@ -20,7 +20,7 @@ export class ExperimentalPragma extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/ExponentiationExpression.js b/src/slang-nodes/ExponentiationExpression.js index d69d05dff..954fdf4b0 100644 --- a/src/slang-nodes/ExponentiationExpression.js +++ b/src/slang-nodes/ExponentiationExpression.js @@ -45,7 +45,7 @@ export class ExponentiationExpression extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); const compiler = coerce(options.compiler); if (compiler) { diff --git a/src/slang-nodes/Expression.js b/src/slang-nodes/Expression.js index 04abeba72..986115c66 100644 --- a/src/slang-nodes/Expression.js +++ b/src/slang-nodes/Expression.js @@ -76,7 +76,7 @@ export class Expression extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/ExpressionStatement.js b/src/slang-nodes/ExpressionStatement.js index bd2ea5c30..9a367bf9d 100644 --- a/src/slang-nodes/ExpressionStatement.js +++ b/src/slang-nodes/ExpressionStatement.js @@ -20,7 +20,7 @@ export class ExpressionStatement extends SlangNode { this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/FallbackFunctionAttribute.js b/src/slang-nodes/FallbackFunctionAttribute.js index 21d89cbfc..d3ad9dd9a 100644 --- a/src/slang-nodes/FallbackFunctionAttribute.js +++ b/src/slang-nodes/FallbackFunctionAttribute.js @@ -23,7 +23,7 @@ export class FallbackFunctionAttribute extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/FallbackFunctionAttributes.js b/src/slang-nodes/FallbackFunctionAttributes.js index e0b39a619..c9774d453 100644 --- a/src/slang-nodes/FallbackFunctionAttributes.js +++ b/src/slang-nodes/FallbackFunctionAttributes.js @@ -24,7 +24,7 @@ export class FallbackFunctionAttributes extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); this.items = this.items.sort(sortFunctionAttributes); } diff --git a/src/slang-nodes/FallbackFunctionDefinition.js b/src/slang-nodes/FallbackFunctionDefinition.js index c15b62054..20417534d 100644 --- a/src/slang-nodes/FallbackFunctionDefinition.js +++ b/src/slang-nodes/FallbackFunctionDefinition.js @@ -50,7 +50,7 @@ export class FallbackFunctionDefinition extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); this.cleanModifierInvocationArguments(); } diff --git a/src/slang-nodes/ForStatement.js b/src/slang-nodes/ForStatement.js index 4deec3022..91f6bfb6d 100644 --- a/src/slang-nodes/ForStatement.js +++ b/src/slang-nodes/ForStatement.js @@ -67,7 +67,7 @@ export class ForStatement extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/ForStatementCondition.js b/src/slang-nodes/ForStatementCondition.js index 5bf5ee324..8d66108e1 100644 --- a/src/slang-nodes/ForStatementCondition.js +++ b/src/slang-nodes/ForStatementCondition.js @@ -20,7 +20,7 @@ export class ForStatementCondition extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/ForStatementInitialization.js b/src/slang-nodes/ForStatementInitialization.js index d15d9780a..9ed7f9336 100644 --- a/src/slang-nodes/ForStatementInitialization.js +++ b/src/slang-nodes/ForStatementInitialization.js @@ -28,7 +28,7 @@ export class ForStatementInitialization extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/FunctionAttribute.js b/src/slang-nodes/FunctionAttribute.js index 954dc87d7..549c0089b 100644 --- a/src/slang-nodes/FunctionAttribute.js +++ b/src/slang-nodes/FunctionAttribute.js @@ -23,7 +23,7 @@ export class FunctionAttribute extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/FunctionAttributes.js b/src/slang-nodes/FunctionAttributes.js index 8295fb2ad..6428378b6 100644 --- a/src/slang-nodes/FunctionAttributes.js +++ b/src/slang-nodes/FunctionAttributes.js @@ -24,7 +24,7 @@ export class FunctionAttributes extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); this.items = this.items.sort(sortFunctionAttributes); } diff --git a/src/slang-nodes/FunctionBody.js b/src/slang-nodes/FunctionBody.js index 3c7767cc9..95f18948a 100644 --- a/src/slang-nodes/FunctionBody.js +++ b/src/slang-nodes/FunctionBody.js @@ -15,7 +15,7 @@ export class FunctionBody extends SlangNode { : new Block(variant, childrenOffsets.shift(), comments, options); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/FunctionCallExpression.js b/src/slang-nodes/FunctionCallExpression.js index bbe4468bf..502282f89 100644 --- a/src/slang-nodes/FunctionCallExpression.js +++ b/src/slang-nodes/FunctionCallExpression.js @@ -30,7 +30,7 @@ export class FunctionCallExpression extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/FunctionDefinition.js b/src/slang-nodes/FunctionDefinition.js index d7a6345ee..57f1b0c9a 100644 --- a/src/slang-nodes/FunctionDefinition.js +++ b/src/slang-nodes/FunctionDefinition.js @@ -62,7 +62,7 @@ export class FunctionDefinition extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); // Older versions of Solidity defined a constructor as a function having // the same name as the contract. diff --git a/src/slang-nodes/FunctionName.js b/src/slang-nodes/FunctionName.js index 42f1abbd8..a10100dfa 100644 --- a/src/slang-nodes/FunctionName.js +++ b/src/slang-nodes/FunctionName.js @@ -11,7 +11,7 @@ export class FunctionName extends SlangNode { this.variant = variant.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print() { diff --git a/src/slang-nodes/FunctionType.js b/src/slang-nodes/FunctionType.js index b1dbe19e1..1896680d2 100644 --- a/src/slang-nodes/FunctionType.js +++ b/src/slang-nodes/FunctionType.js @@ -41,7 +41,7 @@ export class FunctionType extends SlangNode { } }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/FunctionTypeAttribute.js b/src/slang-nodes/FunctionTypeAttribute.js index 6cb2c6cc7..c047b725b 100644 --- a/src/slang-nodes/FunctionTypeAttribute.js +++ b/src/slang-nodes/FunctionTypeAttribute.js @@ -11,7 +11,7 @@ export class FunctionTypeAttribute extends SlangNode { this.variant = variant.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print() { diff --git a/src/slang-nodes/FunctionTypeAttributes.js b/src/slang-nodes/FunctionTypeAttributes.js index bd6e71a95..749bde3ab 100644 --- a/src/slang-nodes/FunctionTypeAttributes.js +++ b/src/slang-nodes/FunctionTypeAttributes.js @@ -24,7 +24,7 @@ export class FunctionTypeAttributes extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); this.items = this.items.sort(sortFunctionAttributes); } diff --git a/src/slang-nodes/HexNumberExpression.js b/src/slang-nodes/HexNumberExpression.js index 0f60b02ce..f52c5c7ce 100644 --- a/src/slang-nodes/HexNumberExpression.js +++ b/src/slang-nodes/HexNumberExpression.js @@ -22,7 +22,7 @@ export class HexNumberExpression extends SlangNode { } }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/HexStringLiteral.js b/src/slang-nodes/HexStringLiteral.js index dca9478ff..1459775e5 100644 --- a/src/slang-nodes/HexStringLiteral.js +++ b/src/slang-nodes/HexStringLiteral.js @@ -12,7 +12,7 @@ export class HexStringLiteral extends SlangNode { this.variant = variant.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); this.variant = `hex${printString(this.variant.slice(4, -1), options)}`; } diff --git a/src/slang-nodes/HexStringLiterals.js b/src/slang-nodes/HexStringLiterals.js index df64ebc49..8ef097a62 100644 --- a/src/slang-nodes/HexStringLiterals.js +++ b/src/slang-nodes/HexStringLiterals.js @@ -18,7 +18,7 @@ export class HexStringLiterals extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/IdentifierPath.js b/src/slang-nodes/IdentifierPath.js index 6c092a178..4ec8c98e6 100644 --- a/src/slang-nodes/IdentifierPath.js +++ b/src/slang-nodes/IdentifierPath.js @@ -14,7 +14,7 @@ export class IdentifierPath extends SlangNode { this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print() { diff --git a/src/slang-nodes/IfStatement.js b/src/slang-nodes/IfStatement.js index b1fbab601..643ae472b 100644 --- a/src/slang-nodes/IfStatement.js +++ b/src/slang-nodes/IfStatement.js @@ -51,7 +51,7 @@ export class IfStatement extends SlangNode { } }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/ImportAlias.js b/src/slang-nodes/ImportAlias.js index a05f67129..44849e3d6 100644 --- a/src/slang-nodes/ImportAlias.js +++ b/src/slang-nodes/ImportAlias.js @@ -14,7 +14,7 @@ export class ImportAlias extends SlangNode { this.identifier = identifier.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print() { diff --git a/src/slang-nodes/ImportClause.js b/src/slang-nodes/ImportClause.js index 881c0b4ab..4373cdd48 100644 --- a/src/slang-nodes/ImportClause.js +++ b/src/slang-nodes/ImportClause.js @@ -21,7 +21,7 @@ export class ImportClause extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/ImportDeconstruction.js b/src/slang-nodes/ImportDeconstruction.js index 26ce1b7f2..8cb5f3c25 100644 --- a/src/slang-nodes/ImportDeconstruction.js +++ b/src/slang-nodes/ImportDeconstruction.js @@ -35,7 +35,7 @@ export class ImportDeconstruction extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/ImportDeconstructionSymbol.js b/src/slang-nodes/ImportDeconstructionSymbol.js index ac5f0fa03..5d34d2ff9 100644 --- a/src/slang-nodes/ImportDeconstructionSymbol.js +++ b/src/slang-nodes/ImportDeconstructionSymbol.js @@ -18,7 +18,7 @@ export class ImportDeconstructionSymbol extends SlangNode { : new ImportAlias(alias, childrenOffsets.shift(), comments, options); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/ImportDeconstructionSymbols.js b/src/slang-nodes/ImportDeconstructionSymbols.js index dfb758ce5..80d0301b8 100644 --- a/src/slang-nodes/ImportDeconstructionSymbols.js +++ b/src/slang-nodes/ImportDeconstructionSymbols.js @@ -29,7 +29,7 @@ export class ImportDeconstructionSymbols extends SlangNode { this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print, options) { diff --git a/src/slang-nodes/ImportDirective.js b/src/slang-nodes/ImportDirective.js index 6d206100c..9457d0a76 100644 --- a/src/slang-nodes/ImportDirective.js +++ b/src/slang-nodes/ImportDirective.js @@ -23,7 +23,7 @@ export class ImportDirective extends SlangNode { this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/IndexAccessEnd.js b/src/slang-nodes/IndexAccessEnd.js index 9ce59c0aa..64e0238b5 100644 --- a/src/slang-nodes/IndexAccessEnd.js +++ b/src/slang-nodes/IndexAccessEnd.js @@ -22,7 +22,7 @@ export class IndexAccessEnd extends SlangNode { } }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/IndexAccessExpression.js b/src/slang-nodes/IndexAccessExpression.js index 6d632f700..f71fbdf47 100644 --- a/src/slang-nodes/IndexAccessExpression.js +++ b/src/slang-nodes/IndexAccessExpression.js @@ -48,7 +48,7 @@ export class IndexAccessExpression extends SlangNode { this.closeBracket = closeBracket.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/InheritanceSpecifier.js b/src/slang-nodes/InheritanceSpecifier.js index 988c94c49..20305c8ee 100644 --- a/src/slang-nodes/InheritanceSpecifier.js +++ b/src/slang-nodes/InheritanceSpecifier.js @@ -20,7 +20,7 @@ export class InheritanceSpecifier extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/InheritanceType.js b/src/slang-nodes/InheritanceType.js index f00268011..b9296c5c4 100644 --- a/src/slang-nodes/InheritanceType.js +++ b/src/slang-nodes/InheritanceType.js @@ -28,7 +28,7 @@ export class InheritanceType extends SlangNode { } }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/InheritanceTypes.js b/src/slang-nodes/InheritanceTypes.js index ea895d924..505ee45da 100644 --- a/src/slang-nodes/InheritanceTypes.js +++ b/src/slang-nodes/InheritanceTypes.js @@ -22,7 +22,7 @@ export class InheritanceTypes extends SlangNode { this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/InterfaceDefinition.js b/src/slang-nodes/InterfaceDefinition.js index 53c0efe2f..99129fc86 100644 --- a/src/slang-nodes/InterfaceDefinition.js +++ b/src/slang-nodes/InterfaceDefinition.js @@ -50,7 +50,7 @@ export class InterfaceDefinition extends SlangNode { this.closeBrace = closeBrace.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/InterfaceMembers.js b/src/slang-nodes/InterfaceMembers.js index 7a803baaa..07b38cad6 100644 --- a/src/slang-nodes/InterfaceMembers.js +++ b/src/slang-nodes/InterfaceMembers.js @@ -20,7 +20,7 @@ export class InterfaceMembers extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print, options) { diff --git a/src/slang-nodes/LibraryDefinition.js b/src/slang-nodes/LibraryDefinition.js index 19a0ee7dc..9b29138ed 100644 --- a/src/slang-nodes/LibraryDefinition.js +++ b/src/slang-nodes/LibraryDefinition.js @@ -32,7 +32,7 @@ export class LibraryDefinition extends SlangNode { this.closeBrace = closeBrace.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/LibraryMembers.js b/src/slang-nodes/LibraryMembers.js index d751a7efc..35ba6b298 100644 --- a/src/slang-nodes/LibraryMembers.js +++ b/src/slang-nodes/LibraryMembers.js @@ -20,7 +20,7 @@ export class LibraryMembers extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print, options) { diff --git a/src/slang-nodes/MappingKey.js b/src/slang-nodes/MappingKey.js index fb29c873c..6682cb7c4 100644 --- a/src/slang-nodes/MappingKey.js +++ b/src/slang-nodes/MappingKey.js @@ -20,7 +20,7 @@ export class MappingKey extends SlangNode { this.name = name?.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/MappingKeyType.js b/src/slang-nodes/MappingKeyType.js index e78cc3432..aa1c6ce59 100644 --- a/src/slang-nodes/MappingKeyType.js +++ b/src/slang-nodes/MappingKeyType.js @@ -19,7 +19,7 @@ export class MappingKeyType extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/MappingType.js b/src/slang-nodes/MappingType.js index 99967941f..0a117e266 100644 --- a/src/slang-nodes/MappingType.js +++ b/src/slang-nodes/MappingType.js @@ -45,7 +45,7 @@ export class MappingType extends SlangNode { this.closeParen = closeParen.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/MappingValue.js b/src/slang-nodes/MappingValue.js index 3634e3341..0dc72b0a6 100644 --- a/src/slang-nodes/MappingValue.js +++ b/src/slang-nodes/MappingValue.js @@ -20,7 +20,7 @@ export class MappingValue extends SlangNode { this.name = name?.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/MemberAccess.js b/src/slang-nodes/MemberAccess.js index 3e87cd07a..a8f542a4f 100644 --- a/src/slang-nodes/MemberAccess.js +++ b/src/slang-nodes/MemberAccess.js @@ -11,7 +11,7 @@ export class MemberAccess extends SlangNode { this.variant = variant.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print() { diff --git a/src/slang-nodes/MemberAccessExpression.js b/src/slang-nodes/MemberAccessExpression.js index d16540184..76914142a 100644 --- a/src/slang-nodes/MemberAccessExpression.js +++ b/src/slang-nodes/MemberAccessExpression.js @@ -134,7 +134,7 @@ export class MemberAccessExpression extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/ModifierAttribute.js b/src/slang-nodes/ModifierAttribute.js index 8f60bea6a..f630055ee 100644 --- a/src/slang-nodes/ModifierAttribute.js +++ b/src/slang-nodes/ModifierAttribute.js @@ -20,7 +20,7 @@ export class ModifierAttribute extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/ModifierAttributes.js b/src/slang-nodes/ModifierAttributes.js index c8325dae8..ea137d4c6 100644 --- a/src/slang-nodes/ModifierAttributes.js +++ b/src/slang-nodes/ModifierAttributes.js @@ -24,7 +24,7 @@ export class ModifierAttributes extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); this.items = this.items.sort(sortFunctionAttributes); } diff --git a/src/slang-nodes/ModifierDefinition.js b/src/slang-nodes/ModifierDefinition.js index 854a563b1..a98093241 100644 --- a/src/slang-nodes/ModifierDefinition.js +++ b/src/slang-nodes/ModifierDefinition.js @@ -45,7 +45,7 @@ export class ModifierDefinition extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); if (typeof this.parameters === 'undefined') { const parametersOffset = this.attributes.loc.startWithTrivia; diff --git a/src/slang-nodes/ModifierInvocation.js b/src/slang-nodes/ModifierInvocation.js index d9c344db3..d711d87d4 100644 --- a/src/slang-nodes/ModifierInvocation.js +++ b/src/slang-nodes/ModifierInvocation.js @@ -29,7 +29,7 @@ export class ModifierInvocation extends SlangNode { } }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); this.cleanModifierInvocationArguments = () => { if ( diff --git a/src/slang-nodes/MultiplicativeExpression.js b/src/slang-nodes/MultiplicativeExpression.js index d986ddaed..8f8f51824 100644 --- a/src/slang-nodes/MultiplicativeExpression.js +++ b/src/slang-nodes/MultiplicativeExpression.js @@ -34,7 +34,7 @@ export class MultiplicativeExpression extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); switch (this.operator) { case '*': diff --git a/src/slang-nodes/NamedArgument.js b/src/slang-nodes/NamedArgument.js index d90498a74..e031a9b14 100644 --- a/src/slang-nodes/NamedArgument.js +++ b/src/slang-nodes/NamedArgument.js @@ -23,7 +23,7 @@ export class NamedArgument extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/NamedArgumentGroup.js b/src/slang-nodes/NamedArgumentGroup.js index 51337a289..e7d42196b 100644 --- a/src/slang-nodes/NamedArgumentGroup.js +++ b/src/slang-nodes/NamedArgumentGroup.js @@ -24,7 +24,7 @@ export class NamedArgumentGroup extends SlangNode { this.closeBrace = closeBrace.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/NamedArguments.js b/src/slang-nodes/NamedArguments.js index 3674083cf..d736a0cf4 100644 --- a/src/slang-nodes/NamedArguments.js +++ b/src/slang-nodes/NamedArguments.js @@ -22,7 +22,7 @@ export class NamedArguments extends SlangNode { this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print, options) { diff --git a/src/slang-nodes/NamedArgumentsDeclaration.js b/src/slang-nodes/NamedArgumentsDeclaration.js index 811217b11..75abe930a 100644 --- a/src/slang-nodes/NamedArgumentsDeclaration.js +++ b/src/slang-nodes/NamedArgumentsDeclaration.js @@ -25,7 +25,7 @@ export class NamedArgumentsDeclaration extends SlangNode { this.closeParen = closeParen.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/NamedImport.js b/src/slang-nodes/NamedImport.js index 5082e411e..565bfa4d0 100644 --- a/src/slang-nodes/NamedImport.js +++ b/src/slang-nodes/NamedImport.js @@ -32,7 +32,7 @@ export class NamedImport extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/NewExpression.js b/src/slang-nodes/NewExpression.js index edb3e7bf9..b1e137531 100644 --- a/src/slang-nodes/NewExpression.js +++ b/src/slang-nodes/NewExpression.js @@ -20,7 +20,7 @@ export class NewExpression extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/NumberUnit.js b/src/slang-nodes/NumberUnit.js index e24997a03..54113607e 100644 --- a/src/slang-nodes/NumberUnit.js +++ b/src/slang-nodes/NumberUnit.js @@ -11,7 +11,7 @@ export class NumberUnit extends SlangNode { this.variant = variant.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print() { diff --git a/src/slang-nodes/OrExpression.js b/src/slang-nodes/OrExpression.js index 120df61a9..df774befa 100644 --- a/src/slang-nodes/OrExpression.js +++ b/src/slang-nodes/OrExpression.js @@ -32,7 +32,7 @@ export class OrExpression extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); diff --git a/src/slang-nodes/OverridePaths.js b/src/slang-nodes/OverridePaths.js index 48e6e263d..d1f674dde 100644 --- a/src/slang-nodes/OverridePaths.js +++ b/src/slang-nodes/OverridePaths.js @@ -18,7 +18,7 @@ export class OverridePaths extends SlangNode { this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } // TODO: implement print diff --git a/src/slang-nodes/OverridePathsDeclaration.js b/src/slang-nodes/OverridePathsDeclaration.js index 29779f690..9589fe86f 100644 --- a/src/slang-nodes/OverridePathsDeclaration.js +++ b/src/slang-nodes/OverridePathsDeclaration.js @@ -23,7 +23,7 @@ export class OverridePathsDeclaration extends SlangNode { this.closeParen = closeParen.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } // TODO: implement print diff --git a/src/slang-nodes/OverrideSpecifier.js b/src/slang-nodes/OverrideSpecifier.js index 47f346934..d2ea338bf 100644 --- a/src/slang-nodes/OverrideSpecifier.js +++ b/src/slang-nodes/OverrideSpecifier.js @@ -22,7 +22,7 @@ export class OverrideSpecifier extends SlangNode { } }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/Parameter.js b/src/slang-nodes/Parameter.js index b6c752c61..c7b9f29bb 100644 --- a/src/slang-nodes/Parameter.js +++ b/src/slang-nodes/Parameter.js @@ -34,7 +34,7 @@ export class Parameter extends SlangNode { this.name = name?.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/Parameters.js b/src/slang-nodes/Parameters.js index 0f03e8cb5..bdedb267f 100644 --- a/src/slang-nodes/Parameters.js +++ b/src/slang-nodes/Parameters.js @@ -23,7 +23,7 @@ export class Parameters extends SlangNode { this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/ParametersDeclaration.js b/src/slang-nodes/ParametersDeclaration.js index 8dada44ae..26fcf225f 100644 --- a/src/slang-nodes/ParametersDeclaration.js +++ b/src/slang-nodes/ParametersDeclaration.js @@ -23,7 +23,7 @@ export class ParametersDeclaration extends SlangNode { this.closeParen = closeParen.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/PathImport.js b/src/slang-nodes/PathImport.js index 6402d9f0b..974690b90 100644 --- a/src/slang-nodes/PathImport.js +++ b/src/slang-nodes/PathImport.js @@ -24,7 +24,7 @@ export class PathImport extends SlangNode { : new ImportAlias(alias, childrenOffsets.shift(), comments, options); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/PositionalArguments.js b/src/slang-nodes/PositionalArguments.js index d98a87c41..da84e739e 100644 --- a/src/slang-nodes/PositionalArguments.js +++ b/src/slang-nodes/PositionalArguments.js @@ -19,7 +19,7 @@ export class PositionalArguments extends SlangNode { this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/PositionalArgumentsDeclaration.js b/src/slang-nodes/PositionalArgumentsDeclaration.js index dba8142e2..73fa4c6a6 100644 --- a/src/slang-nodes/PositionalArgumentsDeclaration.js +++ b/src/slang-nodes/PositionalArgumentsDeclaration.js @@ -24,7 +24,7 @@ export class PositionalArgumentsDeclaration extends SlangNode { this.closeParen = closeParen.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/PostfixExpression.js b/src/slang-nodes/PostfixExpression.js index 59f35aac3..c8ffcec36 100644 --- a/src/slang-nodes/PostfixExpression.js +++ b/src/slang-nodes/PostfixExpression.js @@ -20,7 +20,7 @@ export class PostfixExpression extends SlangNode { this.operator = operator.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/Pragma.js b/src/slang-nodes/Pragma.js index 37a038e29..8e579fc28 100644 --- a/src/slang-nodes/Pragma.js +++ b/src/slang-nodes/Pragma.js @@ -20,7 +20,7 @@ export class Pragma extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/PragmaDirective.js b/src/slang-nodes/PragmaDirective.js index 9573cd360..cc0bbdc2f 100644 --- a/src/slang-nodes/PragmaDirective.js +++ b/src/slang-nodes/PragmaDirective.js @@ -23,7 +23,7 @@ export class PragmaDirective extends SlangNode { this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/PrefixExpression.js b/src/slang-nodes/PrefixExpression.js index 44cc6a9d5..5e2386cef 100644 --- a/src/slang-nodes/PrefixExpression.js +++ b/src/slang-nodes/PrefixExpression.js @@ -20,7 +20,7 @@ export class PrefixExpression extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/ReceiveFunctionAttribute.js b/src/slang-nodes/ReceiveFunctionAttribute.js index 7f9bceb8c..9e7b011f9 100644 --- a/src/slang-nodes/ReceiveFunctionAttribute.js +++ b/src/slang-nodes/ReceiveFunctionAttribute.js @@ -23,7 +23,7 @@ export class ReceiveFunctionAttribute extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/ReceiveFunctionAttributes.js b/src/slang-nodes/ReceiveFunctionAttributes.js index 1e6a02c47..560efe20b 100644 --- a/src/slang-nodes/ReceiveFunctionAttributes.js +++ b/src/slang-nodes/ReceiveFunctionAttributes.js @@ -24,7 +24,7 @@ export class ReceiveFunctionAttributes extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); this.items = this.items.sort(sortFunctionAttributes); } diff --git a/src/slang-nodes/ReceiveFunctionDefinition.js b/src/slang-nodes/ReceiveFunctionDefinition.js index 18b73270c..7cbd36468 100644 --- a/src/slang-nodes/ReceiveFunctionDefinition.js +++ b/src/slang-nodes/ReceiveFunctionDefinition.js @@ -39,7 +39,7 @@ export class ReceiveFunctionDefinition extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); this.cleanModifierInvocationArguments(); } diff --git a/src/slang-nodes/ReturnStatement.js b/src/slang-nodes/ReturnStatement.js index 12d378ea0..05f3ed149 100644 --- a/src/slang-nodes/ReturnStatement.js +++ b/src/slang-nodes/ReturnStatement.js @@ -39,7 +39,7 @@ export class ReturnStatement extends SlangNode { this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print, options) { diff --git a/src/slang-nodes/ReturnsDeclaration.js b/src/slang-nodes/ReturnsDeclaration.js index 853884729..34481d64a 100644 --- a/src/slang-nodes/ReturnsDeclaration.js +++ b/src/slang-nodes/ReturnsDeclaration.js @@ -23,7 +23,7 @@ export class ReturnsDeclaration extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/RevertStatement.js b/src/slang-nodes/RevertStatement.js index 2b9da0808..156025ea8 100644 --- a/src/slang-nodes/RevertStatement.js +++ b/src/slang-nodes/RevertStatement.js @@ -34,7 +34,7 @@ export class RevertStatement extends SlangNode { this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/ShiftExpression.js b/src/slang-nodes/ShiftExpression.js index 3289eb104..145d714d1 100644 --- a/src/slang-nodes/ShiftExpression.js +++ b/src/slang-nodes/ShiftExpression.js @@ -41,7 +41,7 @@ export class ShiftExpression extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); this.leftOperand = tryToHugLeftOperand(this.leftOperand); this.rightOperand = tryToHugRightOperand(this.rightOperand); diff --git a/src/slang-nodes/SlangNode.js b/src/slang-nodes/SlangNode.js index e9285d943..0285eb821 100644 --- a/src/slang-nodes/SlangNode.js +++ b/src/slang-nodes/SlangNode.js @@ -11,7 +11,7 @@ export class SlangNode { comments = []; - initialize(ast, offset, comments, fetch) { + initialize(ast, offset, fetch, comments) { this.kind = ast.cst.kind; // Collect comments and get children offsets. diff --git a/src/slang-nodes/SourceUnit.js b/src/slang-nodes/SourceUnit.js index 89f1c8dc2..5062a8587 100644 --- a/src/slang-nodes/SourceUnit.js +++ b/src/slang-nodes/SourceUnit.js @@ -20,7 +20,7 @@ export class SourceUnit extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print, options) { diff --git a/src/slang-nodes/SourceUnitMember.js b/src/slang-nodes/SourceUnitMember.js index 623e1ef8d..dc5e4d2b5 100644 --- a/src/slang-nodes/SourceUnitMember.js +++ b/src/slang-nodes/SourceUnitMember.js @@ -44,7 +44,7 @@ export class SourceUnitMember extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/SourceUnitMembers.js b/src/slang-nodes/SourceUnitMembers.js index cc6472960..58f7e5056 100644 --- a/src/slang-nodes/SourceUnitMembers.js +++ b/src/slang-nodes/SourceUnitMembers.js @@ -16,7 +16,7 @@ export class SourceUnitMembers extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print, options) { diff --git a/src/slang-nodes/StateVariableAttribute.js b/src/slang-nodes/StateVariableAttribute.js index ffba839b4..60929403f 100644 --- a/src/slang-nodes/StateVariableAttribute.js +++ b/src/slang-nodes/StateVariableAttribute.js @@ -20,7 +20,7 @@ export class StateVariableAttribute extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/StateVariableAttributes.js b/src/slang-nodes/StateVariableAttributes.js index a80c78e51..b23e62d78 100644 --- a/src/slang-nodes/StateVariableAttributes.js +++ b/src/slang-nodes/StateVariableAttributes.js @@ -20,7 +20,7 @@ export class StateVariableAttributes extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/StateVariableDefinition.js b/src/slang-nodes/StateVariableDefinition.js index 4a9534bcc..fef44605b 100644 --- a/src/slang-nodes/StateVariableDefinition.js +++ b/src/slang-nodes/StateVariableDefinition.js @@ -43,7 +43,7 @@ export class StateVariableDefinition extends SlangNode { this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/StateVariableDefinitionValue.js b/src/slang-nodes/StateVariableDefinitionValue.js index 07e6e2b57..775d6008a 100644 --- a/src/slang-nodes/StateVariableDefinitionValue.js +++ b/src/slang-nodes/StateVariableDefinitionValue.js @@ -23,7 +23,7 @@ export class StateVariableDefinitionValue extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/Statement.js b/src/slang-nodes/Statement.js index 808eecf06..f42223c4f 100644 --- a/src/slang-nodes/Statement.js +++ b/src/slang-nodes/Statement.js @@ -53,7 +53,7 @@ export class Statement extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/Statements.js b/src/slang-nodes/Statements.js index e2080908f..f940b2990 100644 --- a/src/slang-nodes/Statements.js +++ b/src/slang-nodes/Statements.js @@ -21,7 +21,7 @@ export class Statements extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print, options) { diff --git a/src/slang-nodes/StorageLocation.js b/src/slang-nodes/StorageLocation.js index 66d8cc52f..a06543a56 100644 --- a/src/slang-nodes/StorageLocation.js +++ b/src/slang-nodes/StorageLocation.js @@ -11,7 +11,7 @@ export class StorageLocation extends SlangNode { this.variant = variant.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print() { diff --git a/src/slang-nodes/StringExpression.js b/src/slang-nodes/StringExpression.js index 61cc067b2..16b5d858a 100644 --- a/src/slang-nodes/StringExpression.js +++ b/src/slang-nodes/StringExpression.js @@ -28,7 +28,7 @@ export class StringExpression extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/StringLiteral.js b/src/slang-nodes/StringLiteral.js index b8b604511..759f6b9ee 100644 --- a/src/slang-nodes/StringLiteral.js +++ b/src/slang-nodes/StringLiteral.js @@ -12,7 +12,7 @@ export class StringLiteral extends SlangNode { this.variant = variant.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); this.variant = printString(this.variant.slice(1, -1), options); } diff --git a/src/slang-nodes/StringLiterals.js b/src/slang-nodes/StringLiterals.js index 3f30f26ec..edd342ce2 100644 --- a/src/slang-nodes/StringLiterals.js +++ b/src/slang-nodes/StringLiterals.js @@ -18,7 +18,7 @@ export class StringLiterals extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/StructDefinition.js b/src/slang-nodes/StructDefinition.js index 1a9b7031d..80a2d1eca 100644 --- a/src/slang-nodes/StructDefinition.js +++ b/src/slang-nodes/StructDefinition.js @@ -29,7 +29,7 @@ export class StructDefinition extends SlangNode { this.closeBrace = closeBrace.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/StructMember.js b/src/slang-nodes/StructMember.js index 8268226a0..8f4e39fe3 100644 --- a/src/slang-nodes/StructMember.js +++ b/src/slang-nodes/StructMember.js @@ -23,7 +23,7 @@ export class StructMember extends SlangNode { this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/StructMembers.js b/src/slang-nodes/StructMembers.js index cc3d8d19b..4545130a0 100644 --- a/src/slang-nodes/StructMembers.js +++ b/src/slang-nodes/StructMembers.js @@ -19,7 +19,7 @@ export class StructMembers extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/ThrowStatement.js b/src/slang-nodes/ThrowStatement.js index 7dfbf153a..08940070f 100644 --- a/src/slang-nodes/ThrowStatement.js +++ b/src/slang-nodes/ThrowStatement.js @@ -14,7 +14,7 @@ export class ThrowStatement extends SlangNode { this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } // TODO: implement print diff --git a/src/slang-nodes/TryStatement.js b/src/slang-nodes/TryStatement.js index 9b5e7e87f..b0cac937c 100644 --- a/src/slang-nodes/TryStatement.js +++ b/src/slang-nodes/TryStatement.js @@ -48,7 +48,7 @@ export class TryStatement extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/TupleDeconstructionElement.js b/src/slang-nodes/TupleDeconstructionElement.js index d2f99ecbf..bb2ba178f 100644 --- a/src/slang-nodes/TupleDeconstructionElement.js +++ b/src/slang-nodes/TupleDeconstructionElement.js @@ -19,7 +19,7 @@ export class TupleDeconstructionElement extends SlangNode { } }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/TupleDeconstructionElements.js b/src/slang-nodes/TupleDeconstructionElements.js index a6e0e1785..d329f1a0d 100644 --- a/src/slang-nodes/TupleDeconstructionElements.js +++ b/src/slang-nodes/TupleDeconstructionElements.js @@ -24,7 +24,7 @@ export class TupleDeconstructionElements extends SlangNode { this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/TupleDeconstructionStatement.js b/src/slang-nodes/TupleDeconstructionStatement.js index be09888cf..5075f782b 100644 --- a/src/slang-nodes/TupleDeconstructionStatement.js +++ b/src/slang-nodes/TupleDeconstructionStatement.js @@ -52,7 +52,7 @@ export class TupleDeconstructionStatement extends SlangNode { this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/TupleExpression.js b/src/slang-nodes/TupleExpression.js index 40c778c7e..907d49f2e 100644 --- a/src/slang-nodes/TupleExpression.js +++ b/src/slang-nodes/TupleExpression.js @@ -23,7 +23,7 @@ export class TupleExpression extends SlangNode { this.closeParen = closeParen.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/TupleMember.js b/src/slang-nodes/TupleMember.js index 2d92996a6..1e5f6bebe 100644 --- a/src/slang-nodes/TupleMember.js +++ b/src/slang-nodes/TupleMember.js @@ -20,7 +20,7 @@ export class TupleMember extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/TupleValue.js b/src/slang-nodes/TupleValue.js index 8d0eda37f..d21f7e811 100644 --- a/src/slang-nodes/TupleValue.js +++ b/src/slang-nodes/TupleValue.js @@ -19,7 +19,7 @@ export class TupleValue extends SlangNode { } }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/TupleValues.js b/src/slang-nodes/TupleValues.js index 690b4b9e0..1897095d9 100644 --- a/src/slang-nodes/TupleValues.js +++ b/src/slang-nodes/TupleValues.js @@ -20,7 +20,7 @@ export class TupleValues extends SlangNode { this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/TypeExpression.js b/src/slang-nodes/TypeExpression.js index ba0e019c0..b9084e5ef 100644 --- a/src/slang-nodes/TypeExpression.js +++ b/src/slang-nodes/TypeExpression.js @@ -26,7 +26,7 @@ export class TypeExpression extends SlangNode { this.closeParen = closeParen.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } // TODO: implement print diff --git a/src/slang-nodes/TypeName.js b/src/slang-nodes/TypeName.js index 78d0ce6d6..5289b7803 100644 --- a/src/slang-nodes/TypeName.js +++ b/src/slang-nodes/TypeName.js @@ -28,7 +28,7 @@ export class TypeName extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/TypedTupleMember.js b/src/slang-nodes/TypedTupleMember.js index 99a2bcc19..66e2c7db3 100644 --- a/src/slang-nodes/TypedTupleMember.js +++ b/src/slang-nodes/TypedTupleMember.js @@ -31,7 +31,7 @@ export class TypedTupleMember extends SlangNode { this.name = name.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/UncheckedBlock.js b/src/slang-nodes/UncheckedBlock.js index b7635bffb..01752bab3 100644 --- a/src/slang-nodes/UncheckedBlock.js +++ b/src/slang-nodes/UncheckedBlock.js @@ -15,7 +15,7 @@ export class UncheckedBlock extends SlangNode { this.block = new Block(block, childrenOffsets.shift(), comments, options); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/UnicodeStringLiteral.js b/src/slang-nodes/UnicodeStringLiteral.js index c5e4e3046..f2475b8a5 100644 --- a/src/slang-nodes/UnicodeStringLiteral.js +++ b/src/slang-nodes/UnicodeStringLiteral.js @@ -12,7 +12,7 @@ export class UnicodeStringLiteral extends SlangNode { this.variant = variant.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); this.variant = `unicode${printString(this.variant.slice(8, -1), options)}`; } diff --git a/src/slang-nodes/UnicodeStringLiterals.js b/src/slang-nodes/UnicodeStringLiterals.js index 18752f9e2..defececf5 100644 --- a/src/slang-nodes/UnicodeStringLiterals.js +++ b/src/slang-nodes/UnicodeStringLiterals.js @@ -23,7 +23,7 @@ export class UnicodeStringLiterals extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/UnnamedFunctionAttribute.js b/src/slang-nodes/UnnamedFunctionAttribute.js index ed19f9eed..6cd5c0c5d 100644 --- a/src/slang-nodes/UnnamedFunctionAttribute.js +++ b/src/slang-nodes/UnnamedFunctionAttribute.js @@ -20,7 +20,7 @@ export class UnnamedFunctionAttribute extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/UnnamedFunctionAttributes.js b/src/slang-nodes/UnnamedFunctionAttributes.js index a2f8243cf..7f19e08d2 100644 --- a/src/slang-nodes/UnnamedFunctionAttributes.js +++ b/src/slang-nodes/UnnamedFunctionAttributes.js @@ -24,7 +24,7 @@ export class UnnamedFunctionAttributes extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); this.items = this.items.sort(sortFunctionAttributes); } diff --git a/src/slang-nodes/UnnamedFunctionDefinition.js b/src/slang-nodes/UnnamedFunctionDefinition.js index 60487a13d..96910b015 100644 --- a/src/slang-nodes/UnnamedFunctionDefinition.js +++ b/src/slang-nodes/UnnamedFunctionDefinition.js @@ -39,7 +39,7 @@ export class UnnamedFunctionDefinition extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); this.cleanModifierInvocationArguments(); } diff --git a/src/slang-nodes/UntypedTupleMember.js b/src/slang-nodes/UntypedTupleMember.js index 4cfc7f9f9..a8e6917da 100644 --- a/src/slang-nodes/UntypedTupleMember.js +++ b/src/slang-nodes/UntypedTupleMember.js @@ -23,7 +23,7 @@ export class UntypedTupleMember extends SlangNode { this.name = name.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } // TODO: implement print diff --git a/src/slang-nodes/UserDefinedValueTypeDefinition.js b/src/slang-nodes/UserDefinedValueTypeDefinition.js index 5d06f096d..dc2654a19 100644 --- a/src/slang-nodes/UserDefinedValueTypeDefinition.js +++ b/src/slang-nodes/UserDefinedValueTypeDefinition.js @@ -29,7 +29,7 @@ export class UserDefinedValueTypeDefinition extends SlangNode { this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/UsingAlias.js b/src/slang-nodes/UsingAlias.js index 82b7bae99..0ae0004b3 100644 --- a/src/slang-nodes/UsingAlias.js +++ b/src/slang-nodes/UsingAlias.js @@ -20,7 +20,7 @@ export class UsingAlias extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/UsingClause.js b/src/slang-nodes/UsingClause.js index 2dac1dea0..61b4194ea 100644 --- a/src/slang-nodes/UsingClause.js +++ b/src/slang-nodes/UsingClause.js @@ -20,7 +20,7 @@ export class UsingClause extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/UsingDeconstruction.js b/src/slang-nodes/UsingDeconstruction.js index aa5e76299..034b101cc 100644 --- a/src/slang-nodes/UsingDeconstruction.js +++ b/src/slang-nodes/UsingDeconstruction.js @@ -23,7 +23,7 @@ export class UsingDeconstruction extends SlangNode { this.closeBrace = closeBrace.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/UsingDeconstructionSymbol.js b/src/slang-nodes/UsingDeconstructionSymbol.js index cb6c93402..013537a5c 100644 --- a/src/slang-nodes/UsingDeconstructionSymbol.js +++ b/src/slang-nodes/UsingDeconstructionSymbol.js @@ -28,7 +28,7 @@ export class UsingDeconstructionSymbol extends SlangNode { } }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/UsingDeconstructionSymbols.js b/src/slang-nodes/UsingDeconstructionSymbols.js index 70a47dc8c..602e976ae 100644 --- a/src/slang-nodes/UsingDeconstructionSymbols.js +++ b/src/slang-nodes/UsingDeconstructionSymbols.js @@ -27,7 +27,7 @@ export class UsingDeconstructionSymbols extends SlangNode { this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print, options) { diff --git a/src/slang-nodes/UsingDirective.js b/src/slang-nodes/UsingDirective.js index 3b8e5d404..dd7e0a67b 100644 --- a/src/slang-nodes/UsingDirective.js +++ b/src/slang-nodes/UsingDirective.js @@ -45,7 +45,7 @@ export class UsingDirective extends SlangNode { this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/UsingOperator.js b/src/slang-nodes/UsingOperator.js index 3af8bb3ac..44f5f68a8 100644 --- a/src/slang-nodes/UsingOperator.js +++ b/src/slang-nodes/UsingOperator.js @@ -11,7 +11,7 @@ export class UsingOperator extends SlangNode { this.variant = variant.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print() { diff --git a/src/slang-nodes/UsingTarget.js b/src/slang-nodes/UsingTarget.js index 2c16c2bf7..5381113b5 100644 --- a/src/slang-nodes/UsingTarget.js +++ b/src/slang-nodes/UsingTarget.js @@ -15,7 +15,7 @@ export class UsingTarget extends SlangNode { : new TypeName(variant, childrenOffsets.shift(), comments, options); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/VariableDeclarationStatement.js b/src/slang-nodes/VariableDeclarationStatement.js index c8567f9af..c04d9fc21 100644 --- a/src/slang-nodes/VariableDeclarationStatement.js +++ b/src/slang-nodes/VariableDeclarationStatement.js @@ -48,7 +48,7 @@ export class VariableDeclarationStatement extends SlangNode { this.semicolon = semicolon.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/VariableDeclarationType.js b/src/slang-nodes/VariableDeclarationType.js index 36e6c67b6..637d91e91 100644 --- a/src/slang-nodes/VariableDeclarationType.js +++ b/src/slang-nodes/VariableDeclarationType.js @@ -15,7 +15,7 @@ export class VariableDeclarationType extends SlangNode { : new TypeName(variant, childrenOffsets.shift(), comments, options); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/VariableDeclarationValue.js b/src/slang-nodes/VariableDeclarationValue.js index 0d5dd151f..327cd65af 100644 --- a/src/slang-nodes/VariableDeclarationValue.js +++ b/src/slang-nodes/VariableDeclarationValue.js @@ -20,7 +20,7 @@ export class VariableDeclarationValue extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/VersionComparator.js b/src/slang-nodes/VersionComparator.js index d2e235c69..b80af22f8 100644 --- a/src/slang-nodes/VersionComparator.js +++ b/src/slang-nodes/VersionComparator.js @@ -19,7 +19,7 @@ export class VersionComparator extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/VersionExpression.js b/src/slang-nodes/VersionExpression.js index 4a3a9fa6a..fa1a25cde 100644 --- a/src/slang-nodes/VersionExpression.js +++ b/src/slang-nodes/VersionExpression.js @@ -28,7 +28,7 @@ export class VersionExpression extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/VersionExpressionSet.js b/src/slang-nodes/VersionExpressionSet.js index 6e75f8e13..d50ef36a5 100644 --- a/src/slang-nodes/VersionExpressionSet.js +++ b/src/slang-nodes/VersionExpressionSet.js @@ -23,7 +23,7 @@ export class VersionExpressionSet extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/VersionExpressionSets.js b/src/slang-nodes/VersionExpressionSets.js index 406b3b458..a492568ff 100644 --- a/src/slang-nodes/VersionExpressionSets.js +++ b/src/slang-nodes/VersionExpressionSets.js @@ -23,7 +23,7 @@ export class VersionExpressionSets extends SlangNode { this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/VersionPragma.js b/src/slang-nodes/VersionPragma.js index 5f55b4c61..cbeb98490 100644 --- a/src/slang-nodes/VersionPragma.js +++ b/src/slang-nodes/VersionPragma.js @@ -20,7 +20,7 @@ export class VersionPragma extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/VersionRange.js b/src/slang-nodes/VersionRange.js index 2f3c020d8..a3af3fb22 100644 --- a/src/slang-nodes/VersionRange.js +++ b/src/slang-nodes/VersionRange.js @@ -28,7 +28,7 @@ export class VersionRange extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } // TODO: implement print diff --git a/src/slang-nodes/VersionSpecifiers.js b/src/slang-nodes/VersionSpecifiers.js index 669bf06f0..a1f7eb81b 100644 --- a/src/slang-nodes/VersionSpecifiers.js +++ b/src/slang-nodes/VersionSpecifiers.js @@ -14,7 +14,7 @@ export class VersionSpecifiers extends SlangNode { this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print() { diff --git a/src/slang-nodes/WhileStatement.js b/src/slang-nodes/WhileStatement.js index 95bb596b2..ee4a4daba 100644 --- a/src/slang-nodes/WhileStatement.js +++ b/src/slang-nodes/WhileStatement.js @@ -39,7 +39,7 @@ export class WhileStatement extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/YulArguments.js b/src/slang-nodes/YulArguments.js index ba6f96a44..60d79936e 100644 --- a/src/slang-nodes/YulArguments.js +++ b/src/slang-nodes/YulArguments.js @@ -19,7 +19,7 @@ export class YulArguments extends SlangNode { this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/YulAssignmentOperator.js b/src/slang-nodes/YulAssignmentOperator.js index 45edfee70..a38d2798f 100644 --- a/src/slang-nodes/YulAssignmentOperator.js +++ b/src/slang-nodes/YulAssignmentOperator.js @@ -20,7 +20,7 @@ export class YulAssignmentOperator extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/YulBlock.js b/src/slang-nodes/YulBlock.js index 96bd6bac0..695ab12b5 100644 --- a/src/slang-nodes/YulBlock.js +++ b/src/slang-nodes/YulBlock.js @@ -23,7 +23,7 @@ export class YulBlock extends SlangNode { this.closeBrace = closeBrace.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/YulBreakStatement.js b/src/slang-nodes/YulBreakStatement.js index f18d841c6..b6c00f2f9 100644 --- a/src/slang-nodes/YulBreakStatement.js +++ b/src/slang-nodes/YulBreakStatement.js @@ -11,7 +11,7 @@ export class YulBreakStatement extends SlangNode { this.breakKeyword = breakKeyword.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print() { diff --git a/src/slang-nodes/YulBuiltInFunction.js b/src/slang-nodes/YulBuiltInFunction.js index 932fe7b6e..a52ddebae 100644 --- a/src/slang-nodes/YulBuiltInFunction.js +++ b/src/slang-nodes/YulBuiltInFunction.js @@ -11,7 +11,7 @@ export class YulBuiltInFunction extends SlangNode { this.variant = variant.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print() { diff --git a/src/slang-nodes/YulColonEqual.js b/src/slang-nodes/YulColonEqual.js index cdc8eb881..e05ba07e5 100644 --- a/src/slang-nodes/YulColonEqual.js +++ b/src/slang-nodes/YulColonEqual.js @@ -14,7 +14,7 @@ export class YulColonEqual extends SlangNode { this.equal = equal.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } // TODO: implement print diff --git a/src/slang-nodes/YulContinueStatement.js b/src/slang-nodes/YulContinueStatement.js index 153991ea7..421313f80 100644 --- a/src/slang-nodes/YulContinueStatement.js +++ b/src/slang-nodes/YulContinueStatement.js @@ -11,7 +11,7 @@ export class YulContinueStatement extends SlangNode { this.continueKeyword = continueKeyword.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print() { diff --git a/src/slang-nodes/YulDefaultCase.js b/src/slang-nodes/YulDefaultCase.js index df3acbac1..e5b95b056 100644 --- a/src/slang-nodes/YulDefaultCase.js +++ b/src/slang-nodes/YulDefaultCase.js @@ -20,7 +20,7 @@ export class YulDefaultCase extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/YulExpression.js b/src/slang-nodes/YulExpression.js index c1ef9361e..27d96860b 100644 --- a/src/slang-nodes/YulExpression.js +++ b/src/slang-nodes/YulExpression.js @@ -27,7 +27,7 @@ export class YulExpression extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/YulForStatement.js b/src/slang-nodes/YulForStatement.js index 97ae86254..1b1748b5f 100644 --- a/src/slang-nodes/YulForStatement.js +++ b/src/slang-nodes/YulForStatement.js @@ -45,7 +45,7 @@ export class YulForStatement extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/YulFunctionCallExpression.js b/src/slang-nodes/YulFunctionCallExpression.js index 40ac7237c..ad9fe3385 100644 --- a/src/slang-nodes/YulFunctionCallExpression.js +++ b/src/slang-nodes/YulFunctionCallExpression.js @@ -32,7 +32,7 @@ export class YulFunctionCallExpression extends SlangNode { this.closeParen = closeParen.text; }; - this.initialize(ast, offset, comments, fetch); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/YulFunctionDefinition.js b/src/slang-nodes/YulFunctionDefinition.js index 872cea5cc..4c70f0d63 100644 --- a/src/slang-nodes/YulFunctionDefinition.js +++ b/src/slang-nodes/YulFunctionDefinition.js @@ -46,7 +46,7 @@ export class YulFunctionDefinition extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/YulIfStatement.js b/src/slang-nodes/YulIfStatement.js index cadc0ad7b..0e08895c1 100644 --- a/src/slang-nodes/YulIfStatement.js +++ b/src/slang-nodes/YulIfStatement.js @@ -31,7 +31,7 @@ export class YulIfStatement extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/YulLabel.js b/src/slang-nodes/YulLabel.js index 2cade36fe..486214ca8 100644 --- a/src/slang-nodes/YulLabel.js +++ b/src/slang-nodes/YulLabel.js @@ -17,7 +17,7 @@ export class YulLabel extends SlangNode { this.colon = colon.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, fetch, comments); } print() { diff --git a/src/slang-nodes/YulLeaveStatement.js b/src/slang-nodes/YulLeaveStatement.js index 3e614ed9a..aacec23aa 100644 --- a/src/slang-nodes/YulLeaveStatement.js +++ b/src/slang-nodes/YulLeaveStatement.js @@ -11,7 +11,7 @@ export class YulLeaveStatement extends SlangNode { this.leaveKeyword = leaveKeyword.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, fetch, comments); } // TODO: implement print diff --git a/src/slang-nodes/YulLiteral.js b/src/slang-nodes/YulLiteral.js index eb8bbc2c5..1b83f6563 100644 --- a/src/slang-nodes/YulLiteral.js +++ b/src/slang-nodes/YulLiteral.js @@ -24,7 +24,7 @@ export class YulLiteral extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/YulParameters.js b/src/slang-nodes/YulParameters.js index fb19e39c1..d6040a88a 100644 --- a/src/slang-nodes/YulParameters.js +++ b/src/slang-nodes/YulParameters.js @@ -15,7 +15,7 @@ export class YulParameters extends SlangNode { this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, fetch, comments); } print() { diff --git a/src/slang-nodes/YulParametersDeclaration.js b/src/slang-nodes/YulParametersDeclaration.js index a78f1b5a4..11f259fe9 100644 --- a/src/slang-nodes/YulParametersDeclaration.js +++ b/src/slang-nodes/YulParametersDeclaration.js @@ -24,7 +24,7 @@ export class YulParametersDeclaration extends SlangNode { this.closeParen = closeParen.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/YulPath.js b/src/slang-nodes/YulPath.js index f5d5a97b7..0f3568450 100644 --- a/src/slang-nodes/YulPath.js +++ b/src/slang-nodes/YulPath.js @@ -24,7 +24,7 @@ export class YulPath extends SlangNode { this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/YulPathComponent.js b/src/slang-nodes/YulPathComponent.js index a7018c23e..3cda1366b 100644 --- a/src/slang-nodes/YulPathComponent.js +++ b/src/slang-nodes/YulPathComponent.js @@ -11,7 +11,7 @@ export class YulPathComponent extends SlangNode { this.variant = variant.text; }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, fetch, comments); } print() { diff --git a/src/slang-nodes/YulPaths.js b/src/slang-nodes/YulPaths.js index 34175c6c2..f5dd154a6 100644 --- a/src/slang-nodes/YulPaths.js +++ b/src/slang-nodes/YulPaths.js @@ -18,7 +18,7 @@ export class YulPaths extends SlangNode { this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/YulReturnVariables.js b/src/slang-nodes/YulReturnVariables.js index 90fc5393b..f86e94a5b 100644 --- a/src/slang-nodes/YulReturnVariables.js +++ b/src/slang-nodes/YulReturnVariables.js @@ -18,7 +18,7 @@ export class YulReturnVariables extends SlangNode { this.separators = separators.map((separator) => separator.text); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, fetch, comments); } print() { diff --git a/src/slang-nodes/YulReturnsDeclaration.js b/src/slang-nodes/YulReturnsDeclaration.js index be674879e..78be93031 100644 --- a/src/slang-nodes/YulReturnsDeclaration.js +++ b/src/slang-nodes/YulReturnsDeclaration.js @@ -25,7 +25,7 @@ export class YulReturnsDeclaration extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/YulStackAssignmentStatement.js b/src/slang-nodes/YulStackAssignmentStatement.js index 34805ee9a..d638e4a69 100644 --- a/src/slang-nodes/YulStackAssignmentStatement.js +++ b/src/slang-nodes/YulStackAssignmentStatement.js @@ -28,7 +28,7 @@ export class YulStackAssignmentStatement extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, fetch, comments); } // TODO: implement print diff --git a/src/slang-nodes/YulStatement.js b/src/slang-nodes/YulStatement.js index 7ceafb49a..045426dac 100644 --- a/src/slang-nodes/YulStatement.js +++ b/src/slang-nodes/YulStatement.js @@ -46,7 +46,7 @@ export class YulStatement extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/YulStatements.js b/src/slang-nodes/YulStatements.js index b4dab32f4..f4be230cd 100644 --- a/src/slang-nodes/YulStatements.js +++ b/src/slang-nodes/YulStatements.js @@ -27,7 +27,7 @@ export class YulStatements extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, fetch, comments); } print(path, print, options) { diff --git a/src/slang-nodes/YulSwitchCase.js b/src/slang-nodes/YulSwitchCase.js index 7e38cceee..31e5c5d73 100644 --- a/src/slang-nodes/YulSwitchCase.js +++ b/src/slang-nodes/YulSwitchCase.js @@ -20,7 +20,7 @@ export class YulSwitchCase extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/YulSwitchCases.js b/src/slang-nodes/YulSwitchCases.js index 6e8ff986a..013d2d65d 100644 --- a/src/slang-nodes/YulSwitchCases.js +++ b/src/slang-nodes/YulSwitchCases.js @@ -24,7 +24,7 @@ export class YulSwitchCases extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/YulSwitchStatement.js b/src/slang-nodes/YulSwitchStatement.js index 075e57b6e..6c5bb5888 100644 --- a/src/slang-nodes/YulSwitchStatement.js +++ b/src/slang-nodes/YulSwitchStatement.js @@ -34,7 +34,7 @@ export class YulSwitchStatement extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/YulValueCase.js b/src/slang-nodes/YulValueCase.js index 6afc3880a..625eb89bd 100644 --- a/src/slang-nodes/YulValueCase.js +++ b/src/slang-nodes/YulValueCase.js @@ -31,7 +31,7 @@ export class YulValueCase extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/YulVariableAssignmentStatement.js b/src/slang-nodes/YulVariableAssignmentStatement.js index 73dc76d11..ce39ab3d1 100644 --- a/src/slang-nodes/YulVariableAssignmentStatement.js +++ b/src/slang-nodes/YulVariableAssignmentStatement.js @@ -38,7 +38,7 @@ export class YulVariableAssignmentStatement extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/YulVariableDeclarationStatement.js b/src/slang-nodes/YulVariableDeclarationStatement.js index ef06a2c9f..9f5b324f4 100644 --- a/src/slang-nodes/YulVariableDeclarationStatement.js +++ b/src/slang-nodes/YulVariableDeclarationStatement.js @@ -26,7 +26,7 @@ export class YulVariableDeclarationStatement extends SlangNode { } }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slang-nodes/YulVariableDeclarationValue.js b/src/slang-nodes/YulVariableDeclarationValue.js index 91c8b11cb..72e149981 100644 --- a/src/slang-nodes/YulVariableDeclarationValue.js +++ b/src/slang-nodes/YulVariableDeclarationValue.js @@ -28,7 +28,7 @@ export class YulVariableDeclarationValue extends SlangNode { ); }; - this.initialize(ast, offset, comments, fetch, parse); + this.initialize(ast, offset, fetch, comments); } print(path, print) { diff --git a/src/slangParser.js b/src/slangParser.js index 0d17ecad8..04e70387e 100644 --- a/src/slangParser.js +++ b/src/slangParser.js @@ -15,7 +15,7 @@ function createGenericParse(options, comments) { function parse(text, _parsers, options = _parsers) { const compiler = coerce(options.compiler); - const language = new Language(compiler?.version || '0.8.25'); + const language = new Language(compiler?.version || '0.8.26'); const ast = new SourceUnit( language.parse(NonterminalKind.SourceUnit, text).tree() ); From 9b2238779ed5602d3d406fbe8ba1ade13ebf8241 Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 17 Jul 2024 22:47:20 +1200 Subject: [PATCH 088/160] fetch function doesn't rely on `this` --- src/slang-nodes/ABICoderPragma.js | 9 ++-- src/slang-nodes/AdditiveExpression.js | 19 ++++--- src/slang-nodes/AddressType.js | 9 ++-- src/slang-nodes/AndExpression.js | 19 ++++--- src/slang-nodes/ArgumentsDeclaration.js | 11 ++-- src/slang-nodes/ArrayExpression.js | 15 +++--- src/slang-nodes/ArrayTypeName.js | 26 ++++----- src/slang-nodes/ArrayValues.js | 11 ++-- src/slang-nodes/AssemblyFlags.js | 11 ++-- src/slang-nodes/AssemblyFlagsDeclaration.js | 15 +++--- src/slang-nodes/AssemblyStatement.js | 46 +++++++--------- src/slang-nodes/AssignmentExpression.js | 19 ++++--- src/slang-nodes/BitwiseAndExpression.js | 19 ++++--- src/slang-nodes/BitwiseOrExpression.js | 19 ++++--- src/slang-nodes/BitwiseXorExpression.js | 19 ++++--- src/slang-nodes/Block.js | 15 +++--- src/slang-nodes/BreakStatement.js | 9 ++-- src/slang-nodes/CallOptions.js | 11 ++-- src/slang-nodes/CallOptionsExpression.js | 19 ++++--- src/slang-nodes/CatchClause.js | 25 +++++---- src/slang-nodes/CatchClauseError.js | 13 +++-- src/slang-nodes/CatchClauses.js | 9 ++-- src/slang-nodes/ComparisonExpression.js | 19 ++++--- src/slang-nodes/ConditionalExpression.js | 28 +++++----- src/slang-nodes/ConstantDefinition.js | 25 +++++---- src/slang-nodes/ConstructorAttribute.js | 15 +++--- src/slang-nodes/ConstructorAttributes.js | 9 ++-- src/slang-nodes/ConstructorDefinition.js | 21 ++++---- src/slang-nodes/ContinueStatement.js | 9 ++-- src/slang-nodes/ContractDefinition.js | 45 +++++++--------- src/slang-nodes/ContractMember.js | 11 ++-- src/slang-nodes/ContractMembers.js | 9 ++-- src/slang-nodes/DecimalNumberExpression.js | 18 +++---- src/slang-nodes/DoWhileStatement.js | 36 ++++--------- src/slang-nodes/ElementaryType.js | 15 +++--- src/slang-nodes/ElseBranch.js | 14 ++--- src/slang-nodes/EmitStatement.js | 19 ++++--- src/slang-nodes/EnumDefinition.js | 19 ++++--- src/slang-nodes/EnumMembers.js | 9 ++-- src/slang-nodes/EqualityExpression.js | 19 ++++--- src/slang-nodes/ErrorDefinition.js | 17 +++--- src/slang-nodes/ErrorParameter.js | 13 +++-- src/slang-nodes/ErrorParameters.js | 11 ++-- src/slang-nodes/ErrorParametersDeclaration.js | 15 +++--- src/slang-nodes/EventDefinition.js | 20 ++++--- src/slang-nodes/EventParameter.js | 15 +++--- src/slang-nodes/EventParameters.js | 11 ++-- src/slang-nodes/EventParametersDeclaration.js | 15 +++--- src/slang-nodes/ExperimentalFeature.js | 15 +++--- src/slang-nodes/ExperimentalPragma.js | 13 +++-- src/slang-nodes/ExponentiationExpression.js | 19 ++++--- src/slang-nodes/Expression.js | 17 +++--- src/slang-nodes/ExpressionStatement.js | 13 +++-- src/slang-nodes/FallbackFunctionAttribute.js | 17 +++--- src/slang-nodes/FallbackFunctionAttributes.js | 9 ++-- src/slang-nodes/FallbackFunctionDefinition.js | 41 +++++++------- src/slang-nodes/ForStatement.js | 54 +++++++------------ src/slang-nodes/ForStatementCondition.js | 15 +++--- src/slang-nodes/ForStatementInitialization.js | 17 +++--- src/slang-nodes/FunctionAttribute.js | 17 +++--- src/slang-nodes/FunctionAttributes.js | 9 ++-- src/slang-nodes/FunctionBody.js | 13 +++-- src/slang-nodes/FunctionCallExpression.js | 15 +++--- src/slang-nodes/FunctionDefinition.js | 48 ++++++++--------- src/slang-nodes/FunctionName.js | 7 ++- src/slang-nodes/FunctionType.js | 35 ++++++------ src/slang-nodes/FunctionTypeAttribute.js | 7 ++- src/slang-nodes/FunctionTypeAttributes.js | 9 ++-- src/slang-nodes/HexNumberExpression.js | 18 +++---- src/slang-nodes/HexStringLiteral.js | 7 ++- src/slang-nodes/HexStringLiterals.js | 9 ++-- src/slang-nodes/IdentifierPath.js | 9 ++-- src/slang-nodes/IfStatement.js | 41 ++++++-------- src/slang-nodes/ImportAlias.js | 9 ++-- src/slang-nodes/ImportClause.js | 11 ++-- src/slang-nodes/ImportDeconstruction.js | 23 ++++---- src/slang-nodes/ImportDeconstructionSymbol.js | 14 +++-- .../ImportDeconstructionSymbols.js | 11 ++-- src/slang-nodes/ImportDirective.js | 15 +++--- src/slang-nodes/IndexAccessEnd.js | 18 +++---- src/slang-nodes/IndexAccessExpression.js | 42 +++++++-------- src/slang-nodes/InheritanceSpecifier.js | 13 +++-- src/slang-nodes/InheritanceType.js | 27 +++++----- src/slang-nodes/InheritanceTypes.js | 11 ++-- src/slang-nodes/InterfaceDefinition.js | 42 ++++++--------- src/slang-nodes/InterfaceMembers.js | 9 ++-- src/slang-nodes/LibraryDefinition.js | 19 ++++--- src/slang-nodes/LibraryMembers.js | 9 ++-- src/slang-nodes/MappingKey.js | 13 +++-- src/slang-nodes/MappingKeyType.js | 11 ++-- src/slang-nodes/MappingType.js | 32 +++++------ src/slang-nodes/MappingValue.js | 13 +++-- src/slang-nodes/MemberAccess.js | 7 ++- src/slang-nodes/MemberAccessExpression.js | 19 ++++--- src/slang-nodes/ModifierAttribute.js | 15 +++--- src/slang-nodes/ModifierAttributes.js | 9 ++-- src/slang-nodes/ModifierDefinition.js | 37 +++++++------ src/slang-nodes/ModifierInvocation.js | 27 +++++----- src/slang-nodes/MultiplicativeExpression.js | 19 ++++--- src/slang-nodes/NamedArgument.js | 15 +++--- src/slang-nodes/NamedArgumentGroup.js | 14 +++-- src/slang-nodes/NamedArguments.js | 11 ++-- src/slang-nodes/NamedArgumentsDeclaration.js | 25 +++++---- src/slang-nodes/NamedImport.js | 21 ++++---- src/slang-nodes/NewExpression.js | 13 +++-- src/slang-nodes/NumberUnit.js | 7 ++- src/slang-nodes/OrExpression.js | 19 ++++--- src/slang-nodes/OverridePaths.js | 11 ++-- src/slang-nodes/OverridePathsDeclaration.js | 15 +++--- src/slang-nodes/OverrideSpecifier.js | 23 ++++---- src/slang-nodes/Parameter.js | 29 +++++----- src/slang-nodes/Parameters.js | 11 ++-- src/slang-nodes/ParametersDeclaration.js | 15 +++--- src/slang-nodes/PathImport.js | 18 +++---- src/slang-nodes/PositionalArguments.js | 11 ++-- .../PositionalArgumentsDeclaration.js | 16 +++--- src/slang-nodes/PostfixExpression.js | 13 +++-- src/slang-nodes/Pragma.js | 11 ++-- src/slang-nodes/PragmaDirective.js | 15 +++--- src/slang-nodes/PrefixExpression.js | 13 +++-- src/slang-nodes/ReceiveFunctionAttribute.js | 17 +++--- src/slang-nodes/ReceiveFunctionAttributes.js | 9 ++-- src/slang-nodes/ReceiveFunctionDefinition.js | 25 +++++---- src/slang-nodes/ReturnStatement.js | 26 ++++----- src/slang-nodes/ReturnsDeclaration.js | 13 +++-- src/slang-nodes/RevertStatement.js | 29 +++++----- src/slang-nodes/ShiftExpression.js | 19 ++++--- src/slang-nodes/SlangNode.js | 15 +++++- src/slang-nodes/SourceUnit.js | 11 ++-- src/slang-nodes/SourceUnitMember.js | 11 ++-- src/slang-nodes/SourceUnitMembers.js | 9 ++-- src/slang-nodes/StateVariableAttribute.js | 15 +++--- src/slang-nodes/StateVariableAttributes.js | 9 ++-- src/slang-nodes/StateVariableDefinition.js | 37 +++++++------ .../StateVariableDefinitionValue.js | 13 +++-- src/slang-nodes/Statement.js | 11 ++-- src/slang-nodes/Statements.js | 9 ++-- src/slang-nodes/StorageLocation.js | 7 ++- src/slang-nodes/StringExpression.js | 11 ++-- src/slang-nodes/StringLiteral.js | 7 ++- src/slang-nodes/StringLiterals.js | 9 ++-- src/slang-nodes/StructDefinition.js | 19 ++++--- src/slang-nodes/StructMember.js | 15 +++--- src/slang-nodes/StructMembers.js | 9 ++-- src/slang-nodes/ThrowStatement.js | 9 ++-- src/slang-nodes/TryStatement.js | 37 +++++++------ src/slang-nodes/TupleDeconstructionElement.js | 21 ++++---- .../TupleDeconstructionElements.js | 11 ++-- .../TupleDeconstructionStatement.js | 35 +++++------- src/slang-nodes/TupleExpression.js | 15 +++--- src/slang-nodes/TupleMember.js | 11 ++-- src/slang-nodes/TupleValue.js | 21 ++++---- src/slang-nodes/TupleValues.js | 11 ++-- src/slang-nodes/TypeExpression.js | 17 +++--- src/slang-nodes/TypeName.js | 11 ++-- src/slang-nodes/TypedTupleMember.js | 29 +++++----- src/slang-nodes/UncheckedBlock.js | 9 ++-- src/slang-nodes/UnicodeStringLiteral.js | 7 ++- src/slang-nodes/UnicodeStringLiterals.js | 9 ++-- src/slang-nodes/UnnamedFunctionAttribute.js | 15 +++--- src/slang-nodes/UnnamedFunctionAttributes.js | 9 ++-- src/slang-nodes/UnnamedFunctionDefinition.js | 25 +++++---- src/slang-nodes/UntypedTupleMember.js | 24 ++++----- .../UserDefinedValueTypeDefinition.js | 19 ++++--- src/slang-nodes/UsingAlias.js | 13 +++-- src/slang-nodes/UsingClause.js | 11 ++-- src/slang-nodes/UsingDeconstruction.js | 15 +++--- src/slang-nodes/UsingDeconstructionSymbol.js | 22 +++----- src/slang-nodes/UsingDeconstructionSymbols.js | 11 ++-- src/slang-nodes/UsingDirective.js | 32 +++++------ src/slang-nodes/UsingOperator.js | 7 ++- src/slang-nodes/UsingTarget.js | 18 ++++--- .../VariableDeclarationStatement.js | 47 ++++++++-------- src/slang-nodes/VariableDeclarationType.js | 18 ++++--- src/slang-nodes/VariableDeclarationValue.js | 13 +++-- src/slang-nodes/VersionComparator.js | 13 +++-- src/slang-nodes/VersionExpression.js | 17 +++--- src/slang-nodes/VersionExpressionSet.js | 9 ++-- src/slang-nodes/VersionExpressionSets.js | 11 ++-- src/slang-nodes/VersionPragma.js | 13 +++-- src/slang-nodes/VersionRange.js | 19 ++++--- src/slang-nodes/VersionSpecifiers.js | 9 ++-- src/slang-nodes/WhileStatement.js | 24 ++++----- src/slang-nodes/YulArguments.js | 11 ++-- src/slang-nodes/YulAssignmentOperator.js | 15 +++--- src/slang-nodes/YulBlock.js | 15 +++--- src/slang-nodes/YulBreakStatement.js | 7 ++- src/slang-nodes/YulBuiltInFunction.js | 7 ++- src/slang-nodes/YulColonEqual.js | 9 ++-- src/slang-nodes/YulContinueStatement.js | 7 ++- src/slang-nodes/YulDefaultCase.js | 14 ++--- src/slang-nodes/YulExpression.js | 11 ++-- src/slang-nodes/YulForStatement.js | 32 +++++------ src/slang-nodes/YulFunctionCallExpression.js | 19 ++++--- src/slang-nodes/YulFunctionDefinition.js | 39 +++++++------- src/slang-nodes/YulIfStatement.js | 19 ++++--- src/slang-nodes/YulLabel.js | 11 ++-- src/slang-nodes/YulLeaveStatement.js | 9 ++-- src/slang-nodes/YulLiteral.js | 17 +++--- src/slang-nodes/YulParameters.js | 11 ++-- src/slang-nodes/YulParametersDeclaration.js | 15 +++--- src/slang-nodes/YulPath.js | 11 ++-- src/slang-nodes/YulPathComponent.js | 9 ++-- src/slang-nodes/YulPaths.js | 11 ++-- src/slang-nodes/YulReturnVariables.js | 11 ++-- src/slang-nodes/YulReturnsDeclaration.js | 13 +++-- .../YulStackAssignmentStatement.js | 17 +++--- src/slang-nodes/YulStatement.js | 11 ++-- src/slang-nodes/YulStatements.js | 9 ++-- src/slang-nodes/YulSwitchCase.js | 11 ++-- src/slang-nodes/YulSwitchCases.js | 9 ++-- src/slang-nodes/YulSwitchStatement.js | 19 ++++--- src/slang-nodes/YulValueCase.js | 19 ++++--- .../YulVariableAssignmentStatement.js | 23 ++++---- .../YulVariableDeclarationStatement.js | 27 +++++----- .../YulVariableDeclarationValue.js | 17 +++--- 216 files changed, 1642 insertions(+), 1965 deletions(-) diff --git a/src/slang-nodes/ABICoderPragma.js b/src/slang-nodes/ABICoderPragma.js index 8a898a2ff..8ace89941 100644 --- a/src/slang-nodes/ABICoderPragma.js +++ b/src/slang-nodes/ABICoderPragma.js @@ -8,11 +8,10 @@ export class ABICoderPragma extends SlangNode { constructor(ast, offset, comments) { super(); - const fetch = () => { - const { abicoderKeyword, version } = ast; - this.abicoderKeyword = abicoderKeyword.text; - this.version = version.text; - }; + const fetch = () => ({ + abicoderKeyword: ast.abicoderKeyword.text, + version: ast.version.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/AdditiveExpression.js b/src/slang-nodes/AdditiveExpression.js index 3030af42c..9a903d125 100644 --- a/src/slang-nodes/AdditiveExpression.js +++ b/src/slang-nodes/AdditiveExpression.js @@ -15,22 +15,21 @@ export class AdditiveExpression extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { leftOperand, operator, rightOperand } = ast; - this.leftOperand = new Expression( - leftOperand, + const fetch = (childrenOffsets) => ({ + leftOperand: new Expression( + ast.leftOperand, childrenOffsets.shift(), comments, options - ); - this.operator = operator.text; - this.rightOperand = new Expression( - rightOperand, + ), + operator: ast.operator.text, + rightOperand: new Expression( + ast.rightOperand, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); diff --git a/src/slang-nodes/AddressType.js b/src/slang-nodes/AddressType.js index 5d80d6dda..e4a1a1b26 100644 --- a/src/slang-nodes/AddressType.js +++ b/src/slang-nodes/AddressType.js @@ -8,11 +8,10 @@ export class AddressType extends SlangNode { constructor(ast, offset, comments) { super(); - const fetch = () => { - const { addressKeyword, payableKeyword } = ast; - this.addressKeyword = addressKeyword.text; - this.payableKeyword = payableKeyword?.text; - }; + const fetch = () => ({ + addressKeyword: ast.addressKeyword.text, + payableKeyword: ast.payableKeyword?.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/AndExpression.js b/src/slang-nodes/AndExpression.js index 50ed7c6d4..464269848 100644 --- a/src/slang-nodes/AndExpression.js +++ b/src/slang-nodes/AndExpression.js @@ -12,22 +12,21 @@ export class AndExpression extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { leftOperand, operator, rightOperand } = ast; - this.leftOperand = new Expression( - leftOperand, + const fetch = (childrenOffsets) => ({ + leftOperand: new Expression( + ast.leftOperand, childrenOffsets.shift(), comments, options - ); - this.operator = operator.text; - this.rightOperand = new Expression( - rightOperand, + ), + operator: ast.operator.text, + rightOperand: new Expression( + ast.rightOperand, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/ArgumentsDeclaration.js b/src/slang-nodes/ArgumentsDeclaration.js index 83ac08bbf..764add460 100644 --- a/src/slang-nodes/ArgumentsDeclaration.js +++ b/src/slang-nodes/ArgumentsDeclaration.js @@ -10,15 +10,14 @@ export class ArgumentsDeclaration extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { variant } = ast; - this.variant = new variants[variant.cst.kind]( - variant, + const fetch = (childrenOffsets) => ({ + variant: new variants[ast.variant.cst.kind]( + ast.variant, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/ArrayExpression.js b/src/slang-nodes/ArrayExpression.js index 0c55f4f58..d20ee9d5b 100644 --- a/src/slang-nodes/ArrayExpression.js +++ b/src/slang-nodes/ArrayExpression.js @@ -14,17 +14,16 @@ export class ArrayExpression extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { openBracket, items, closeBracket } = ast; - this.openBracket = openBracket.text; - this.items = new ArrayValues( - items, + const fetch = (childrenOffsets) => ({ + openBracket: ast.openBracket.text, + items: new ArrayValues( + ast.items, childrenOffsets.shift(), comments, options - ); - this.closeBracket = closeBracket.text; - }; + ), + closeBracket: ast.closeBracket.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/ArrayTypeName.js b/src/slang-nodes/ArrayTypeName.js index 754f3eab1..fe00fd955 100644 --- a/src/slang-nodes/ArrayTypeName.js +++ b/src/slang-nodes/ArrayTypeName.js @@ -14,25 +14,19 @@ export class ArrayTypeName extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { operand, openBracket, index, closeBracket } = ast; - this.operand = new TypeName( - operand, + const fetch = (childrenOffsets) => ({ + operand: new TypeName( + ast.operand, childrenOffsets.shift(), comments, options - ); - this.openBracket = openBracket.text; - if (index) { - this.index = new Expression( - index, - childrenOffsets.shift(), - comments, - options - ); - } - this.closeBracket = closeBracket.text; - }; + ), + openBracket: ast.openBracket.text, + index: ast.index + ? new Expression(ast.index, childrenOffsets.shift(), comments, options) + : undefined, + closeBracket: ast.closeBracket.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/ArrayValues.js b/src/slang-nodes/ArrayValues.js index 4f9d2333a..378d74ab3 100644 --- a/src/slang-nodes/ArrayValues.js +++ b/src/slang-nodes/ArrayValues.js @@ -10,14 +10,13 @@ export class ArrayValues extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { items, separators } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new Expression(item, childrenOffsets.shift(), comments, options) - ); - this.separators = separators.map((separator) => separator.text); - }; + ), + separators: ast.separators.map((separator) => separator.text) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/AssemblyFlags.js b/src/slang-nodes/AssemblyFlags.js index fe81efc91..4e9c6c099 100644 --- a/src/slang-nodes/AssemblyFlags.js +++ b/src/slang-nodes/AssemblyFlags.js @@ -10,14 +10,13 @@ export class AssemblyFlags extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { items, separators } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new StringLiteral(item, childrenOffsets.shift(), comments, options) - ); - this.separators = separators.map((separator) => separator.text); - }; + ), + separators: ast.separators.map((separator) => separator.text) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/AssemblyFlagsDeclaration.js b/src/slang-nodes/AssemblyFlagsDeclaration.js index 1be70c137..974969dcd 100644 --- a/src/slang-nodes/AssemblyFlagsDeclaration.js +++ b/src/slang-nodes/AssemblyFlagsDeclaration.js @@ -11,17 +11,16 @@ export class AssemblyFlagsDeclaration extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { openParen, flags, closeParen } = ast; - this.openParen = openParen.text; - this.flags = new AssemblyFlags( - flags, + const fetch = (childrenOffsets) => ({ + openParen: ast.openParen.text, + flags: new AssemblyFlags( + ast.flags, childrenOffsets.shift(), comments, options - ); - this.closeParen = closeParen.text; - }; + ), + closeParen: ast.closeParen.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/AssemblyStatement.js b/src/slang-nodes/AssemblyStatement.js index d440ccf8a..66db62aa8 100644 --- a/src/slang-nodes/AssemblyStatement.js +++ b/src/slang-nodes/AssemblyStatement.js @@ -15,32 +15,26 @@ export class AssemblyStatement extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { assemblyKeyword, label, flags, body } = ast; - this.assemblyKeyword = assemblyKeyword.text; - if (label) { - this.label = new StringLiteral( - label, - childrenOffsets.shift(), - comments, - options - ); - } - if (flags) { - this.flags = new AssemblyFlagsDeclaration( - flags, - childrenOffsets.shift(), - comments, - options - ); - } - this.body = new YulBlock( - body, - childrenOffsets.shift(), - comments, - options - ); - }; + const fetch = (childrenOffsets) => ({ + assemblyKeyword: ast.assemblyKeyword.text, + label: ast.label + ? new StringLiteral( + ast.label, + childrenOffsets.shift(), + comments, + options + ) + : undefined, + flags: ast.flags + ? new AssemblyFlagsDeclaration( + ast.flags, + childrenOffsets.shift(), + comments, + options + ) + : undefined, + body: new YulBlock(ast.body, childrenOffsets.shift(), comments, options) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/AssignmentExpression.js b/src/slang-nodes/AssignmentExpression.js index 60a014f57..749db4fb4 100644 --- a/src/slang-nodes/AssignmentExpression.js +++ b/src/slang-nodes/AssignmentExpression.js @@ -15,22 +15,21 @@ export class AssignmentExpression extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { leftOperand, operator, rightOperand } = ast; - this.leftOperand = new Expression( - leftOperand, + const fetch = (childrenOffsets) => ({ + leftOperand: new Expression( + ast.leftOperand, childrenOffsets.shift(), comments, options - ); - this.operator = operator.text; - this.rightOperand = new Expression( - rightOperand, + ), + operator: ast.operator.text, + rightOperand: new Expression( + ast.rightOperand, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/BitwiseAndExpression.js b/src/slang-nodes/BitwiseAndExpression.js index b68a55d42..e0e19efb2 100644 --- a/src/slang-nodes/BitwiseAndExpression.js +++ b/src/slang-nodes/BitwiseAndExpression.js @@ -15,22 +15,21 @@ export class BitwiseAndExpression extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { leftOperand, operator, rightOperand } = ast; - this.leftOperand = new Expression( - leftOperand, + const fetch = (childrenOffsets) => ({ + leftOperand: new Expression( + ast.leftOperand, childrenOffsets.shift(), comments, options - ); - this.operator = operator.text; - this.rightOperand = new Expression( - rightOperand, + ), + operator: ast.operator.text, + rightOperand: new Expression( + ast.rightOperand, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); diff --git a/src/slang-nodes/BitwiseOrExpression.js b/src/slang-nodes/BitwiseOrExpression.js index 9b2f6ff7e..25edd7856 100644 --- a/src/slang-nodes/BitwiseOrExpression.js +++ b/src/slang-nodes/BitwiseOrExpression.js @@ -25,22 +25,21 @@ export class BitwiseOrExpression extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { leftOperand, operator, rightOperand } = ast; - this.leftOperand = new Expression( - leftOperand, + const fetch = (childrenOffsets) => ({ + leftOperand: new Expression( + ast.leftOperand, childrenOffsets.shift(), comments, options - ); - this.operator = operator.text; - this.rightOperand = new Expression( - rightOperand, + ), + operator: ast.operator.text, + rightOperand: new Expression( + ast.rightOperand, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); diff --git a/src/slang-nodes/BitwiseXorExpression.js b/src/slang-nodes/BitwiseXorExpression.js index f28d84aa9..032d423ef 100644 --- a/src/slang-nodes/BitwiseXorExpression.js +++ b/src/slang-nodes/BitwiseXorExpression.js @@ -15,22 +15,21 @@ export class BitwiseXorExpression extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { leftOperand, operator, rightOperand } = ast; - this.leftOperand = new Expression( - leftOperand, + const fetch = (childrenOffsets) => ({ + leftOperand: new Expression( + ast.leftOperand, childrenOffsets.shift(), comments, options - ); - this.operator = operator.text; - this.rightOperand = new Expression( - rightOperand, + ), + operator: ast.operator.text, + rightOperand: new Expression( + ast.rightOperand, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); diff --git a/src/slang-nodes/Block.js b/src/slang-nodes/Block.js index a0962d90f..a8f76ee65 100644 --- a/src/slang-nodes/Block.js +++ b/src/slang-nodes/Block.js @@ -11,17 +11,16 @@ export class Block extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { openBrace, statements, closeBrace } = ast; - this.openBrace = openBrace.text; - this.statements = new Statements( - statements, + const fetch = (childrenOffsets) => ({ + openBrace: ast.openBrace.text, + statements: new Statements( + ast.statements, childrenOffsets.shift(), comments, options - ); - this.closeBrace = closeBrace.text; - }; + ), + closeBrace: ast.closeBrace.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/BreakStatement.js b/src/slang-nodes/BreakStatement.js index 90cd52fcb..922cb6d1d 100644 --- a/src/slang-nodes/BreakStatement.js +++ b/src/slang-nodes/BreakStatement.js @@ -8,11 +8,10 @@ export class BreakStatement extends SlangNode { constructor(ast, offset, comments) { super(); - const fetch = () => { - const { breakKeyword, semicolon } = ast; - this.breakKeyword = breakKeyword.text; - this.semicolon = semicolon.text; - }; + const fetch = () => ({ + breakKeyword: ast.breakKeyword.text, + semicolon: ast.semicolon.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/CallOptions.js b/src/slang-nodes/CallOptions.js index 2758b35d1..b16ed6ea0 100644 --- a/src/slang-nodes/CallOptions.js +++ b/src/slang-nodes/CallOptions.js @@ -13,14 +13,13 @@ export class CallOptions extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { items, separators } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new NamedArgument(item, childrenOffsets.shift(), comments, options) - ); - this.separators = separators.map((separator) => separator.text); - }; + ), + separators: ast.separators.map((separator) => separator.text) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/CallOptionsExpression.js b/src/slang-nodes/CallOptionsExpression.js index 6783232fe..6c46308cf 100644 --- a/src/slang-nodes/CallOptionsExpression.js +++ b/src/slang-nodes/CallOptionsExpression.js @@ -14,23 +14,22 @@ export class CallOptionsExpression extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { operand, openBrace, closeBrace } = ast; - this.operand = new Expression( - operand, + const fetch = (childrenOffsets) => ({ + operand: new Expression( + ast.operand, childrenOffsets.shift(), comments, options - ); - this.openBrace = openBrace.text; - this.options = new CallOptions( + ), + openBrace: ast.openBrace.text, + options: new CallOptions( ast.options, childrenOffsets.shift(), comments, options - ); - this.closeBrace = closeBrace.text; - }; + ), + closeBrace: ast.closeBrace.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/CatchClause.js b/src/slang-nodes/CatchClause.js index 263b21263..3c2a3f2f1 100644 --- a/src/slang-nodes/CatchClause.js +++ b/src/slang-nodes/CatchClause.js @@ -12,19 +12,18 @@ export class CatchClause extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { catchKeyword, error, body } = ast; - this.catchKeyword = catchKeyword.text; - if (error) { - this.error = new CatchClauseError( - error, - childrenOffsets.shift(), - comments, - options - ); - } - this.body = new Block(body, childrenOffsets.shift(), comments, options); - }; + const fetch = (childrenOffsets) => ({ + catchKeyword: ast.catchKeyword.text, + error: ast.error + ? new CatchClauseError( + ast.error, + childrenOffsets.shift(), + comments, + options + ) + : undefined, + body: new Block(ast.body, childrenOffsets.shift(), comments, options) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/CatchClauseError.js b/src/slang-nodes/CatchClauseError.js index 4822df75e..02d22e18c 100644 --- a/src/slang-nodes/CatchClauseError.js +++ b/src/slang-nodes/CatchClauseError.js @@ -12,16 +12,15 @@ export class CatchClauseError extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { name, parameters } = ast; - this.name = name?.text; - this.parameters = new ParametersDeclaration( - parameters, + const fetch = (childrenOffsets) => ({ + name: ast.name?.text, + parameters: new ParametersDeclaration( + ast.parameters, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/CatchClauses.js b/src/slang-nodes/CatchClauses.js index f33c635c0..e6dc738a2 100644 --- a/src/slang-nodes/CatchClauses.js +++ b/src/slang-nodes/CatchClauses.js @@ -10,13 +10,12 @@ export class CatchClauses extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { items } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new CatchClause(item, childrenOffsets.shift(), comments, options) - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/ComparisonExpression.js b/src/slang-nodes/ComparisonExpression.js index 0f398fa68..dd8154fc7 100644 --- a/src/slang-nodes/ComparisonExpression.js +++ b/src/slang-nodes/ComparisonExpression.js @@ -12,22 +12,21 @@ export class ComparisonExpression extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { leftOperand, operator, rightOperand } = ast; - this.leftOperand = new Expression( - leftOperand, + const fetch = (childrenOffsets) => ({ + leftOperand: new Expression( + ast.leftOperand, childrenOffsets.shift(), comments, options - ); - this.operator = operator.text; - this.rightOperand = new Expression( - rightOperand, + ), + operator: ast.operator.text, + rightOperand: new Expression( + ast.rightOperand, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/ConditionalExpression.js b/src/slang-nodes/ConditionalExpression.js index c6fcfba75..bcf92bbb3 100644 --- a/src/slang-nodes/ConditionalExpression.js +++ b/src/slang-nodes/ConditionalExpression.js @@ -99,30 +99,28 @@ export class ConditionalExpression extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { operand, questionMark, trueExpression, colon, falseExpression } = - ast; - this.operand = new Expression( - operand, + const fetch = (childrenOffsets) => ({ + operand: new Expression( + ast.operand, childrenOffsets.shift(), comments, options - ); - this.questionMark = questionMark.text; - this.trueExpression = new Expression( - trueExpression, + ), + questionMark: ast.questionMark.text, + trueExpression: new Expression( + ast.trueExpression, childrenOffsets.shift(), comments, options - ); - this.colon = colon.text; - this.falseExpression = new Expression( - falseExpression, + ), + colon: ast.colon.text, + falseExpression: new Expression( + ast.falseExpression, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); diff --git a/src/slang-nodes/ConstantDefinition.js b/src/slang-nodes/ConstantDefinition.js index 48e0b6298..29b53baf4 100644 --- a/src/slang-nodes/ConstantDefinition.js +++ b/src/slang-nodes/ConstantDefinition.js @@ -18,25 +18,24 @@ export class ConstantDefinition extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { typeName, constantKeyword, name, equal, value, semicolon } = ast; - this.typeName = new TypeName( - typeName, + const fetch = (childrenOffsets) => ({ + typeName: new TypeName( + ast.typeName, childrenOffsets.shift(), comments, options - ); - this.constantKeyword = constantKeyword.text; - this.name = name.text; - this.equal = equal.text; - this.value = new Expression( - value, + ), + constantKeyword: ast.constantKeyword.text, + name: ast.name.text, + equal: ast.equal.text, + value: new Expression( + ast.value, childrenOffsets.shift(), comments, options - ); - this.semicolon = semicolon.text; - }; + ), + semicolon: ast.semicolon.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/ConstructorAttribute.js b/src/slang-nodes/ConstructorAttribute.js index 535a85557..51947a219 100644 --- a/src/slang-nodes/ConstructorAttribute.js +++ b/src/slang-nodes/ConstructorAttribute.js @@ -7,18 +7,17 @@ export class ConstructorAttribute extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { variant } = ast; - this.variant = - variant.type === 'Terminal' - ? variant.text + const fetch = (childrenOffsets) => ({ + variant: + ast.variant.type === 'Terminal' + ? ast.variant.text : new ModifierInvocation( - variant, + ast.variant, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/ConstructorAttributes.js b/src/slang-nodes/ConstructorAttributes.js index a73928cb7..edbff177c 100644 --- a/src/slang-nodes/ConstructorAttributes.js +++ b/src/slang-nodes/ConstructorAttributes.js @@ -11,9 +11,8 @@ export class ConstructorAttributes extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { items } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new ConstructorAttribute( item, @@ -21,8 +20,8 @@ export class ConstructorAttributes extends SlangNode { comments, options ) - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); diff --git a/src/slang-nodes/ConstructorDefinition.js b/src/slang-nodes/ConstructorDefinition.js index 3d4f06e01..76391ec13 100644 --- a/src/slang-nodes/ConstructorDefinition.js +++ b/src/slang-nodes/ConstructorDefinition.js @@ -16,23 +16,22 @@ export class ConstructorDefinition extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { constructorKeyword, parameters, attributes, body } = ast; - this.constructorKeyword = constructorKeyword.text; - this.parameters = new ParametersDeclaration( - parameters, + const fetch = (childrenOffsets) => ({ + constructorKeyword: ast.constructorKeyword.text, + parameters: new ParametersDeclaration( + ast.parameters, childrenOffsets.shift(), comments, options - ); - this.attributes = new ConstructorAttributes( - attributes, + ), + attributes: new ConstructorAttributes( + ast.attributes, childrenOffsets.shift(), comments, options - ); - this.body = new Block(body, childrenOffsets.shift(), comments, options); - }; + ), + body: new Block(ast.body, childrenOffsets.shift(), comments, options) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/ContinueStatement.js b/src/slang-nodes/ContinueStatement.js index 1cf5351d7..3e94e2085 100644 --- a/src/slang-nodes/ContinueStatement.js +++ b/src/slang-nodes/ContinueStatement.js @@ -8,11 +8,10 @@ export class ContinueStatement extends SlangNode { constructor(ast, offset, comments) { super(); - const fetch = () => { - const { continueKeyword, semicolon } = ast; - this.continueKeyword = continueKeyword.text; - this.semicolon = semicolon.text; - }; + const fetch = () => ({ + continueKeyword: ast.continueKeyword.text, + semicolon: ast.semicolon.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/ContractDefinition.js b/src/slang-nodes/ContractDefinition.js index 6e32dda14..e577a7fa5 100644 --- a/src/slang-nodes/ContractDefinition.js +++ b/src/slang-nodes/ContractDefinition.js @@ -25,36 +25,27 @@ export class ContractDefinition extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { - abstractKeyword, - contractKeyword, - name, - inheritance, - openBrace, - members, - closeBrace - } = ast; - this.abstractKeyword = abstractKeyword?.text; - this.contractKeyword = contractKeyword.text; - this.name = name.text; - if (inheritance) { - this.inheritance = new InheritanceSpecifier( - inheritance, - childrenOffsets.shift(), - comments, - options - ); - } - this.openBrace = openBrace.text; - this.members = new ContractMembers( - members, + const fetch = (childrenOffsets) => ({ + abstractKeyword: ast.abstractKeyword?.text, + contractKeyword: ast.contractKeyword.text, + name: ast.name.text, + inheritance: ast.inheritance + ? new InheritanceSpecifier( + ast.inheritance, + childrenOffsets.shift(), + comments, + options + ) + : undefined, + openBrace: ast.openBrace.text, + members: new ContractMembers( + ast.members, childrenOffsets.shift(), comments, options - ); - this.closeBrace = closeBrace.text; - }; + ), + closeBrace: ast.closeBrace.text + }); this.initialize(ast, offset, fetch, comments); diff --git a/src/slang-nodes/ContractMember.js b/src/slang-nodes/ContractMember.js index e78375f38..01a05eea1 100644 --- a/src/slang-nodes/ContractMember.js +++ b/src/slang-nodes/ContractMember.js @@ -35,15 +35,14 @@ export class ContractMember extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { variant } = ast; - this.variant = new variants[variant.cst.kind]( - variant, + const fetch = (childrenOffsets) => ({ + variant: new variants[ast.variant.cst.kind]( + ast.variant, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/ContractMembers.js b/src/slang-nodes/ContractMembers.js index 17bdd4acf..369582ebf 100644 --- a/src/slang-nodes/ContractMembers.js +++ b/src/slang-nodes/ContractMembers.js @@ -13,13 +13,12 @@ export class ContractMembers extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { items } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new ContractMember(item, childrenOffsets.shift(), comments, options) - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/DecimalNumberExpression.js b/src/slang-nodes/DecimalNumberExpression.js index 454010a9e..9cc9d8370 100644 --- a/src/slang-nodes/DecimalNumberExpression.js +++ b/src/slang-nodes/DecimalNumberExpression.js @@ -9,18 +9,12 @@ export class DecimalNumberExpression extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { literal, unit } = ast; - this.literal = literal.text; - if (unit) { - this.unit = new NumberUnit( - unit, - childrenOffsets.shift(), - comments, - options - ); - } - }; + const fetch = (childrenOffsets) => ({ + literal: ast.literal.text, + unit: ast.unit + ? new NumberUnit(ast.unit, childrenOffsets.shift(), comments, options) + : undefined + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/DoWhileStatement.js b/src/slang-nodes/DoWhileStatement.js index d91b89df2..baec56ee6 100644 --- a/src/slang-nodes/DoWhileStatement.js +++ b/src/slang-nodes/DoWhileStatement.js @@ -24,34 +24,20 @@ export class DoWhileStatement extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { - doKeyword, - body, - whileKeyword, - openParen, - condition, - closeParen, - semicolon - } = ast; - this.doKeyword = doKeyword.text; - this.body = new Statement( - body, + const fetch = (childrenOffsets) => ({ + doKeyword: ast.doKeyword.text, + body: new Statement(ast.body, childrenOffsets.shift(), comments, options), + whileKeyword: ast.whileKeyword.text, + openParen: ast.openParen.text, + condition: new Expression( + ast.condition, childrenOffsets.shift(), comments, options - ); - this.whileKeyword = whileKeyword.text; - this.openParen = openParen.text; - this.condition = new Expression( - condition, - childrenOffsets.shift(), - comments, - options - ); - this.closeParen = closeParen.text; - this.semicolon = semicolon.text; - }; + ), + closeParen: ast.closeParen.text, + semicolon: ast.semicolon.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/ElementaryType.js b/src/slang-nodes/ElementaryType.js index 8096e8aa6..4d13e5074 100644 --- a/src/slang-nodes/ElementaryType.js +++ b/src/slang-nodes/ElementaryType.js @@ -6,18 +6,17 @@ export class ElementaryType extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { variant } = ast; - this.variant = - variant.type === 'Terminal' - ? variant.text + const fetch = (childrenOffsets) => ({ + variant: + ast.variant.type === 'Terminal' + ? ast.variant.text : new AddressType( - variant, + ast.variant, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/ElseBranch.js b/src/slang-nodes/ElseBranch.js index fa2b1e9c6..a7ad13871 100644 --- a/src/slang-nodes/ElseBranch.js +++ b/src/slang-nodes/ElseBranch.js @@ -15,16 +15,10 @@ export class ElseBranch extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { elseKeyword, body } = ast; - this.elseKeyword = elseKeyword.text; - this.body = new Statement( - body, - childrenOffsets.shift(), - comments, - options - ); - }; + const fetch = (childrenOffsets) => ({ + elseKeyword: ast.elseKeyword.text, + body: new Statement(ast.body, childrenOffsets.shift(), comments, options) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/EmitStatement.js b/src/slang-nodes/EmitStatement.js index c3458ee1c..b42ddccba 100644 --- a/src/slang-nodes/EmitStatement.js +++ b/src/slang-nodes/EmitStatement.js @@ -14,23 +14,22 @@ export class EmitStatement extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { emitKeyword, event, semicolon } = ast; - this.emitKeyword = emitKeyword.text; - this.event = new IdentifierPath( - event, + const fetch = (childrenOffsets) => ({ + emitKeyword: ast.emitKeyword.text, + event: new IdentifierPath( + ast.event, childrenOffsets.shift(), comments, options - ); - this.arguments = new ArgumentsDeclaration( + ), + arguments: new ArgumentsDeclaration( ast.arguments, childrenOffsets.shift(), comments, options - ); - this.semicolon = semicolon.text; - }; + ), + semicolon: ast.semicolon.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/EnumDefinition.js b/src/slang-nodes/EnumDefinition.js index 907d86afb..ce69ce3f6 100644 --- a/src/slang-nodes/EnumDefinition.js +++ b/src/slang-nodes/EnumDefinition.js @@ -15,19 +15,18 @@ export class EnumDefinition extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { enumKeyword, name, openBrace, members, closeBrace } = ast; - this.enumKeyword = enumKeyword.text; - this.name = name.text; - this.openBrace = openBrace.text; - this.members = new EnumMembers( - members, + const fetch = (childrenOffsets) => ({ + enumKeyword: ast.enumKeyword.text, + name: ast.name.text, + openBrace: ast.openBrace.text, + members: new EnumMembers( + ast.members, childrenOffsets.shift(), comments, options - ); - this.closeBrace = closeBrace.text; - }; + ), + closeBrace: ast.closeBrace.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/EnumMembers.js b/src/slang-nodes/EnumMembers.js index 2b99bf15b..bd679a857 100644 --- a/src/slang-nodes/EnumMembers.js +++ b/src/slang-nodes/EnumMembers.js @@ -12,11 +12,10 @@ export class EnumMembers extends SlangNode { constructor(ast, offset, comments) { super(); - const fetch = () => { - const { items, separators } = ast; - this.items = items.map((item) => item.text); - this.separators = separators.map((separator) => separator.text); - }; + const fetch = () => ({ + items: ast.items.map((item) => item.text), + separators: ast.separators.map((separator) => separator.text) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/EqualityExpression.js b/src/slang-nodes/EqualityExpression.js index f8dcfbcd8..e03ca39bb 100644 --- a/src/slang-nodes/EqualityExpression.js +++ b/src/slang-nodes/EqualityExpression.js @@ -12,22 +12,21 @@ export class EqualityExpression extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { leftOperand, operator, rightOperand } = ast; - this.leftOperand = new Expression( - leftOperand, + const fetch = (childrenOffsets) => ({ + leftOperand: new Expression( + ast.leftOperand, childrenOffsets.shift(), comments, options - ); - this.operator = operator.text; - this.rightOperand = new Expression( - rightOperand, + ), + operator: ast.operator.text, + rightOperand: new Expression( + ast.rightOperand, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/ErrorDefinition.js b/src/slang-nodes/ErrorDefinition.js index ce45fb762..27a9ee616 100644 --- a/src/slang-nodes/ErrorDefinition.js +++ b/src/slang-nodes/ErrorDefinition.js @@ -13,18 +13,17 @@ export class ErrorDefinition extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { errorKeyword, name, members, semicolon } = ast; - this.errorKeyword = errorKeyword.text; - this.name = name.text; - this.members = new ErrorParametersDeclaration( - members, + const fetch = (childrenOffsets) => ({ + errorKeyword: ast.errorKeyword.text, + name: ast.name.text, + members: new ErrorParametersDeclaration( + ast.members, childrenOffsets.shift(), comments, options - ); - this.semicolon = semicolon.text; - }; + ), + semicolon: ast.semicolon.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/ErrorParameter.js b/src/slang-nodes/ErrorParameter.js index deb60d444..8d920effb 100644 --- a/src/slang-nodes/ErrorParameter.js +++ b/src/slang-nodes/ErrorParameter.js @@ -9,16 +9,15 @@ export class ErrorParameter extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { typeName, name } = ast; - this.typeName = new TypeName( - typeName, + const fetch = (childrenOffsets) => ({ + typeName: new TypeName( + ast.typeName, childrenOffsets.shift(), comments, options - ); - this.name = name?.text; - }; + ), + name: ast.name?.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/ErrorParameters.js b/src/slang-nodes/ErrorParameters.js index 1a50749c9..9f266ebd4 100644 --- a/src/slang-nodes/ErrorParameters.js +++ b/src/slang-nodes/ErrorParameters.js @@ -10,14 +10,13 @@ export class ErrorParameters extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { items, separators } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new ErrorParameter(item, childrenOffsets.shift(), comments, options) - ); - this.separators = separators.map((separator) => separator.text); - }; + ), + separators: ast.separators.map((separator) => separator.text) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/ErrorParametersDeclaration.js b/src/slang-nodes/ErrorParametersDeclaration.js index 42dc1048f..35bed0b09 100644 --- a/src/slang-nodes/ErrorParametersDeclaration.js +++ b/src/slang-nodes/ErrorParametersDeclaration.js @@ -11,17 +11,16 @@ export class ErrorParametersDeclaration extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { openParen, parameters, closeParen } = ast; - this.openParen = openParen.text; - this.parameters = new ErrorParameters( - parameters, + const fetch = (childrenOffsets) => ({ + openParen: ast.openParen.text, + parameters: new ErrorParameters( + ast.parameters, childrenOffsets.shift(), comments, options - ); - this.closeParen = closeParen.text; - }; + ), + closeParen: ast.closeParen.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/EventDefinition.js b/src/slang-nodes/EventDefinition.js index a5d8b9b10..80883853c 100644 --- a/src/slang-nodes/EventDefinition.js +++ b/src/slang-nodes/EventDefinition.js @@ -15,20 +15,18 @@ export class EventDefinition extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { eventKeyword, name, parameters, anonymousKeyword, semicolon } = - ast; - this.eventKeyword = eventKeyword.text; - this.name = name.text; - this.parameters = new EventParametersDeclaration( - parameters, + const fetch = (childrenOffsets) => ({ + eventKeyword: ast.eventKeyword.text, + name: ast.name.text, + parameters: new EventParametersDeclaration( + ast.parameters, childrenOffsets.shift(), comments, options - ); - this.anonymousKeyword = anonymousKeyword?.text; - this.semicolon = semicolon.text; - }; + ), + anonymousKeyword: ast.anonymousKeyword?.text, + semicolon: ast.semicolon.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/EventParameter.js b/src/slang-nodes/EventParameter.js index 74da729bd..4ea5ba194 100644 --- a/src/slang-nodes/EventParameter.js +++ b/src/slang-nodes/EventParameter.js @@ -11,17 +11,16 @@ export class EventParameter extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { typeName, indexedKeyword, name } = ast; - this.typeName = new TypeName( - typeName, + const fetch = (childrenOffsets) => ({ + typeName: new TypeName( + ast.typeName, childrenOffsets.shift(), comments, options - ); - this.indexedKeyword = indexedKeyword?.text; - this.name = name?.text; - }; + ), + indexedKeyword: ast.indexedKeyword?.text, + name: ast.name?.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/EventParameters.js b/src/slang-nodes/EventParameters.js index a866d0e6f..360656c22 100644 --- a/src/slang-nodes/EventParameters.js +++ b/src/slang-nodes/EventParameters.js @@ -10,14 +10,13 @@ export class EventParameters extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { items, separators } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new EventParameter(item, childrenOffsets.shift(), comments, options) - ); - this.separators = separators.map((separator) => separator.text); - }; + ), + separators: ast.separators.map((separator) => separator.text) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/EventParametersDeclaration.js b/src/slang-nodes/EventParametersDeclaration.js index 662eac083..6305b170f 100644 --- a/src/slang-nodes/EventParametersDeclaration.js +++ b/src/slang-nodes/EventParametersDeclaration.js @@ -11,17 +11,16 @@ export class EventParametersDeclaration extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { openParen, parameters, closeParen } = ast; - this.openParen = openParen.text; - this.parameters = new EventParameters( - parameters, + const fetch = (childrenOffsets) => ({ + openParen: ast.openParen.text, + parameters: new EventParameters( + ast.parameters, childrenOffsets.shift(), comments, options - ); - this.closeParen = closeParen.text; - }; + ), + closeParen: ast.closeParen.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/ExperimentalFeature.js b/src/slang-nodes/ExperimentalFeature.js index cd9ca772d..ce7002f67 100644 --- a/src/slang-nodes/ExperimentalFeature.js +++ b/src/slang-nodes/ExperimentalFeature.js @@ -7,18 +7,17 @@ export class ExperimentalFeature extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { variant } = ast; - this.variant = - variant.type === 'Terminal' - ? variant.text + const fetch = (childrenOffsets) => ({ + variant: + ast.variant.type === 'Terminal' + ? ast.variant.text : new StringLiteral( - variant, + ast.variant, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/ExperimentalPragma.js b/src/slang-nodes/ExperimentalPragma.js index f7ad76e52..e38a64410 100644 --- a/src/slang-nodes/ExperimentalPragma.js +++ b/src/slang-nodes/ExperimentalPragma.js @@ -9,16 +9,15 @@ export class ExperimentalPragma extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { experimentalKeyword, feature } = ast; - this.experimentalKeyword = experimentalKeyword.text; - this.feature = new ExperimentalFeature( - feature, + const fetch = (childrenOffsets) => ({ + experimentalKeyword: ast.experimentalKeyword.text, + feature: new ExperimentalFeature( + ast.feature, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/ExponentiationExpression.js b/src/slang-nodes/ExponentiationExpression.js index 954fdf4b0..18fb883df 100644 --- a/src/slang-nodes/ExponentiationExpression.js +++ b/src/slang-nodes/ExponentiationExpression.js @@ -28,22 +28,21 @@ export class ExponentiationExpression extends SlangNode { constructor(ast, offset, comments, options) { super(); if (offset) { - const fetch = (childrenOffsets) => { - const { leftOperand, operator, rightOperand } = ast; - this.leftOperand = new Expression( - leftOperand, + const fetch = (childrenOffsets) => ({ + leftOperand: new Expression( + ast.leftOperand, childrenOffsets.shift(), comments, options - ); - this.operator = operator.text; - this.rightOperand = new Expression( - rightOperand, + ), + operator: ast.operator.text, + rightOperand: new Expression( + ast.rightOperand, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); diff --git a/src/slang-nodes/Expression.js b/src/slang-nodes/Expression.js index 986115c66..88b606c60 100644 --- a/src/slang-nodes/Expression.js +++ b/src/slang-nodes/Expression.js @@ -63,18 +63,17 @@ export class Expression extends SlangNode { constructor(ast, offset, comments, options) { super(); if (offset) { - const fetch = (childrenOffsets) => { - const { variant } = ast; - this.variant = - variant.type === 'Terminal' - ? variant.text - : new variants[variant.cst.kind]( - variant, + const fetch = (childrenOffsets) => ({ + variant: + ast.variant.type === 'Terminal' + ? ast.variant.text + : new variants[ast.variant.cst.kind]( + ast.variant, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } else { diff --git a/src/slang-nodes/ExpressionStatement.js b/src/slang-nodes/ExpressionStatement.js index 9a367bf9d..23e7b9cb6 100644 --- a/src/slang-nodes/ExpressionStatement.js +++ b/src/slang-nodes/ExpressionStatement.js @@ -9,16 +9,15 @@ export class ExpressionStatement extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { expression, semicolon } = ast; - this.expression = new Expression( - expression, + const fetch = (childrenOffsets) => ({ + expression: new Expression( + ast.expression, childrenOffsets.shift(), comments, options - ); - this.semicolon = semicolon.text; - }; + ), + semicolon: ast.semicolon.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/FallbackFunctionAttribute.js b/src/slang-nodes/FallbackFunctionAttribute.js index d3ad9dd9a..4182eed82 100644 --- a/src/slang-nodes/FallbackFunctionAttribute.js +++ b/src/slang-nodes/FallbackFunctionAttribute.js @@ -10,18 +10,17 @@ export class FallbackFunctionAttribute extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { variant } = ast; - this.variant = - variant.type === 'Terminal' - ? variant.text - : new variants[variant.cst.kind]( - variant, + const fetch = (childrenOffsets) => ({ + variant: + ast.variant.type === 'Terminal' + ? ast.variant.text + : new variants[ast.variant.cst.kind]( + ast.variant, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/FallbackFunctionAttributes.js b/src/slang-nodes/FallbackFunctionAttributes.js index c9774d453..13825a896 100644 --- a/src/slang-nodes/FallbackFunctionAttributes.js +++ b/src/slang-nodes/FallbackFunctionAttributes.js @@ -11,9 +11,8 @@ export class FallbackFunctionAttributes extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { items } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new FallbackFunctionAttribute( item, @@ -21,8 +20,8 @@ export class FallbackFunctionAttributes extends SlangNode { comments, options ) - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); diff --git a/src/slang-nodes/FallbackFunctionDefinition.js b/src/slang-nodes/FallbackFunctionDefinition.js index 20417534d..9d2724ac1 100644 --- a/src/slang-nodes/FallbackFunctionDefinition.js +++ b/src/slang-nodes/FallbackFunctionDefinition.js @@ -19,36 +19,35 @@ export class FallbackFunctionDefinition extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { fallbackKeyword, parameters, attributes, returns, body } = ast; - this.fallbackKeyword = fallbackKeyword.text; - this.parameters = new ParametersDeclaration( - parameters, + const fetch = (childrenOffsets) => ({ + fallbackKeyword: ast.fallbackKeyword.text, + parameters: new ParametersDeclaration( + ast.parameters, childrenOffsets.shift(), comments, options - ); - this.attributes = new FallbackFunctionAttributes( - attributes, + ), + attributes: new FallbackFunctionAttributes( + ast.attributes, childrenOffsets.shift(), comments, options - ); - if (returns) { - this.returns = new ReturnsDeclaration( - returns, - childrenOffsets.shift(), - comments, - options - ); - } - this.body = new FunctionBody( - body, + ), + returns: ast.returns + ? new ReturnsDeclaration( + ast.returns, + childrenOffsets.shift(), + comments, + options + ) + : undefined, + body: new FunctionBody( + ast.body, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); diff --git a/src/slang-nodes/ForStatement.js b/src/slang-nodes/ForStatement.js index 91f6bfb6d..43d76877e 100644 --- a/src/slang-nodes/ForStatement.js +++ b/src/slang-nodes/ForStatement.js @@ -26,46 +26,32 @@ export class ForStatement extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { - forKeyword, - openParen, - initialization, - condition, - iterator, - closeParen, - body - } = ast; - this.forKeyword = forKeyword.text; - this.openParen = openParen.text; - this.initialization = new ForStatementInitialization( - initialization, + const fetch = (childrenOffsets) => ({ + forKeyword: ast.forKeyword.text, + openParen: ast.openParen.text, + initialization: new ForStatementInitialization( + ast.initialization, childrenOffsets.shift(), comments, options - ); - this.condition = new ForStatementCondition( - condition, + ), + condition: new ForStatementCondition( + ast.condition, childrenOffsets.shift(), comments, options - ); - if (iterator) { - this.iterator = new Expression( - iterator, - childrenOffsets.shift(), - comments, - options - ); - } - this.closeParen = closeParen.text; - this.body = new Statement( - body, - childrenOffsets.shift(), - comments, - options - ); - }; + ), + iterator: ast.iterator + ? new Expression( + ast.iterator, + childrenOffsets.shift(), + comments, + options + ) + : undefined, + closeParen: ast.closeParen.text, + body: new Statement(ast.body, childrenOffsets.shift(), comments, options) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/ForStatementCondition.js b/src/slang-nodes/ForStatementCondition.js index 8d66108e1..46ab1fd5c 100644 --- a/src/slang-nodes/ForStatementCondition.js +++ b/src/slang-nodes/ForStatementCondition.js @@ -7,18 +7,17 @@ export class ForStatementCondition extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { variant } = ast; - this.variant = - variant.type === 'Terminal' - ? variant.text + const fetch = (childrenOffsets) => ({ + variant: + ast.variant.type === 'Terminal' + ? ast.variant.text : new ExpressionStatement( - variant, + ast.variant, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/ForStatementInitialization.js b/src/slang-nodes/ForStatementInitialization.js index 9ed7f9336..5c8b14816 100644 --- a/src/slang-nodes/ForStatementInitialization.js +++ b/src/slang-nodes/ForStatementInitialization.js @@ -15,18 +15,17 @@ export class ForStatementInitialization extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { variant } = ast; - this.variant = - variant.type === 'Terminal' - ? variant.text - : new variants[variant.cst.kind]( - variant, + const fetch = (childrenOffsets) => ({ + variant: + ast.variant.type === 'Terminal' + ? ast.variant.text + : new variants[ast.variant.cst.kind]( + ast.variant, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/FunctionAttribute.js b/src/slang-nodes/FunctionAttribute.js index 549c0089b..2dd3dbdc3 100644 --- a/src/slang-nodes/FunctionAttribute.js +++ b/src/slang-nodes/FunctionAttribute.js @@ -10,18 +10,17 @@ export class FunctionAttribute extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { variant } = ast; - this.variant = - variant.type === 'Terminal' - ? variant.text - : new variants[variant.cst.kind]( - variant, + const fetch = (childrenOffsets) => ({ + variant: + ast.variant.type === 'Terminal' + ? ast.variant.text + : new variants[ast.variant.cst.kind]( + ast.variant, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/FunctionAttributes.js b/src/slang-nodes/FunctionAttributes.js index 6428378b6..ebc3edb40 100644 --- a/src/slang-nodes/FunctionAttributes.js +++ b/src/slang-nodes/FunctionAttributes.js @@ -11,9 +11,8 @@ export class FunctionAttributes extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { items } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new FunctionAttribute( item, @@ -21,8 +20,8 @@ export class FunctionAttributes extends SlangNode { comments, options ) - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); diff --git a/src/slang-nodes/FunctionBody.js b/src/slang-nodes/FunctionBody.js index 95f18948a..3159438d3 100644 --- a/src/slang-nodes/FunctionBody.js +++ b/src/slang-nodes/FunctionBody.js @@ -7,13 +7,12 @@ export class FunctionBody extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { variant } = ast; - this.variant = - variant.type === 'Terminal' - ? variant.text - : new Block(variant, childrenOffsets.shift(), comments, options); - }; + const fetch = (childrenOffsets) => ({ + variant: + ast.variant.type === 'Terminal' + ? ast.variant.text + : new Block(ast.variant, childrenOffsets.shift(), comments, options) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/FunctionCallExpression.js b/src/slang-nodes/FunctionCallExpression.js index 502282f89..4a8b6c86f 100644 --- a/src/slang-nodes/FunctionCallExpression.js +++ b/src/slang-nodes/FunctionCallExpression.js @@ -14,21 +14,20 @@ export class FunctionCallExpression extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { operand } = ast; - this.operand = new Expression( - operand, + const fetch = (childrenOffsets) => ({ + operand: new Expression( + ast.operand, childrenOffsets.shift(), comments, options - ); - this.arguments = new ArgumentsDeclaration( + ), + arguments: new ArgumentsDeclaration( ast.arguments, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/FunctionDefinition.js b/src/slang-nodes/FunctionDefinition.js index 57f1b0c9a..72fe91249 100644 --- a/src/slang-nodes/FunctionDefinition.js +++ b/src/slang-nodes/FunctionDefinition.js @@ -24,43 +24,41 @@ export class FunctionDefinition extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { functionKeyword, name, parameters, attributes, returns, body } = - ast; - this.functionKeyword = functionKeyword.text; - this.name = new FunctionName( - name, + const fetch = (childrenOffsets) => ({ + functionKeyword: ast.functionKeyword.text, + name: new FunctionName( + ast.name, childrenOffsets.shift(), comments, options - ); - this.parameters = new ParametersDeclaration( - parameters, + ), + parameters: new ParametersDeclaration( + ast.parameters, childrenOffsets.shift(), comments, options - ); - this.attributes = new FunctionAttributes( - attributes, + ), + attributes: new FunctionAttributes( + ast.attributes, childrenOffsets.shift(), comments, options - ); - if (returns) { - this.returns = new ReturnsDeclaration( - returns, - childrenOffsets.shift(), - comments, - options - ); - } - this.body = new FunctionBody( - body, + ), + returns: ast.returns + ? new ReturnsDeclaration( + ast.returns, + childrenOffsets.shift(), + comments, + options + ) + : undefined, + body: new FunctionBody( + ast.body, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); diff --git a/src/slang-nodes/FunctionName.js b/src/slang-nodes/FunctionName.js index a10100dfa..5543a0f43 100644 --- a/src/slang-nodes/FunctionName.js +++ b/src/slang-nodes/FunctionName.js @@ -6,10 +6,9 @@ export class FunctionName extends SlangNode { constructor(ast, offset, comments) { super(); - const fetch = () => { - const { variant } = ast; - this.variant = variant.text; - }; + const fetch = () => ({ + variant: ast.variant.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/FunctionType.js b/src/slang-nodes/FunctionType.js index 1896680d2..d83384410 100644 --- a/src/slang-nodes/FunctionType.js +++ b/src/slang-nodes/FunctionType.js @@ -16,30 +16,29 @@ export class FunctionType extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { functionKeyword, parameters, attributes, returns } = ast; - this.functionKeyword = functionKeyword.text; - this.parameters = new ParametersDeclaration( - parameters, + const fetch = (childrenOffsets) => ({ + functionKeyword: ast.functionKeyword.text, + parameters: new ParametersDeclaration( + ast.parameters, childrenOffsets.shift(), comments, options - ); - this.attributes = new FunctionTypeAttributes( - attributes, + ), + attributes: new FunctionTypeAttributes( + ast.attributes, childrenOffsets.shift(), comments, options - ); - if (returns) { - this.returns = new ReturnsDeclaration( - returns, - childrenOffsets.shift(), - comments, - options - ); - } - }; + ), + returns: ast.returns + ? new ReturnsDeclaration( + ast.returns, + childrenOffsets.shift(), + comments, + options + ) + : undefined + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/FunctionTypeAttribute.js b/src/slang-nodes/FunctionTypeAttribute.js index c047b725b..accc8923a 100644 --- a/src/slang-nodes/FunctionTypeAttribute.js +++ b/src/slang-nodes/FunctionTypeAttribute.js @@ -6,10 +6,9 @@ export class FunctionTypeAttribute extends SlangNode { constructor(ast, offset, comments) { super(); - const fetch = () => { - const { variant } = ast; - this.variant = variant.text; - }; + const fetch = () => ({ + variant: ast.variant.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/FunctionTypeAttributes.js b/src/slang-nodes/FunctionTypeAttributes.js index 749bde3ab..ab55fdda9 100644 --- a/src/slang-nodes/FunctionTypeAttributes.js +++ b/src/slang-nodes/FunctionTypeAttributes.js @@ -11,9 +11,8 @@ export class FunctionTypeAttributes extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { items } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new FunctionTypeAttribute( item, @@ -21,8 +20,8 @@ export class FunctionTypeAttributes extends SlangNode { comments, options ) - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); diff --git a/src/slang-nodes/HexNumberExpression.js b/src/slang-nodes/HexNumberExpression.js index f52c5c7ce..c99e12989 100644 --- a/src/slang-nodes/HexNumberExpression.js +++ b/src/slang-nodes/HexNumberExpression.js @@ -9,18 +9,12 @@ export class HexNumberExpression extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { literal, unit } = ast; - this.literal = literal.text; - if (unit) { - this.unit = new NumberUnit( - unit, - childrenOffsets.shift(), - comments, - options - ); - } - }; + const fetch = (childrenOffsets) => ({ + literal: ast.literal.text, + unit: ast.unit + ? new NumberUnit(ast.unit, childrenOffsets.shift(), comments, options) + : undefined + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/HexStringLiteral.js b/src/slang-nodes/HexStringLiteral.js index 1459775e5..9c6c13881 100644 --- a/src/slang-nodes/HexStringLiteral.js +++ b/src/slang-nodes/HexStringLiteral.js @@ -7,10 +7,9 @@ export class HexStringLiteral extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = () => { - const { variant } = ast; - this.variant = variant.text; - }; + const fetch = () => ({ + variant: ast.variant.text + }); this.initialize(ast, offset, fetch, comments); diff --git a/src/slang-nodes/HexStringLiterals.js b/src/slang-nodes/HexStringLiterals.js index 8ef097a62..a9fe0a462 100644 --- a/src/slang-nodes/HexStringLiterals.js +++ b/src/slang-nodes/HexStringLiterals.js @@ -10,13 +10,12 @@ export class HexStringLiterals extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { items } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new HexStringLiteral(item, childrenOffsets.shift(), comments, options) - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/IdentifierPath.js b/src/slang-nodes/IdentifierPath.js index 4ec8c98e6..a777cc51f 100644 --- a/src/slang-nodes/IdentifierPath.js +++ b/src/slang-nodes/IdentifierPath.js @@ -8,11 +8,10 @@ export class IdentifierPath extends SlangNode { constructor(ast, offset, comments) { super(); - const fetch = () => { - const { items, separators } = ast; - this.items = items.map((item) => item.text); - this.separators = separators.map((separator) => separator.text); - }; + const fetch = () => ({ + items: ast.items.map((item) => item.text), + separators: ast.separators.map((separator) => separator.text) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/IfStatement.js b/src/slang-nodes/IfStatement.js index 643ae472b..e56c235e0 100644 --- a/src/slang-nodes/IfStatement.js +++ b/src/slang-nodes/IfStatement.js @@ -23,33 +23,26 @@ export class IfStatement extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { ifKeyword, openParen, condition, closeParen, body, elseBranch } = - ast; - this.ifKeyword = ifKeyword.text; - this.openParen = openParen.text; - this.condition = new Expression( - condition, + const fetch = (childrenOffsets) => ({ + ifKeyword: ast.ifKeyword.text, + openParen: ast.openParen.text, + condition: new Expression( + ast.condition, childrenOffsets.shift(), comments, options - ); - this.closeParen = closeParen.text; - this.body = new Statement( - body, - childrenOffsets.shift(), - comments, - options - ); - if (elseBranch) { - this.elseBranch = new ElseBranch( - elseBranch, - childrenOffsets.shift(), - comments, - options - ); - } - }; + ), + closeParen: ast.closeParen.text, + body: new Statement(ast.body, childrenOffsets.shift(), comments, options), + elseBranch: ast.elseBranch + ? new ElseBranch( + ast.elseBranch, + childrenOffsets.shift(), + comments, + options + ) + : undefined + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/ImportAlias.js b/src/slang-nodes/ImportAlias.js index 44849e3d6..b0adca786 100644 --- a/src/slang-nodes/ImportAlias.js +++ b/src/slang-nodes/ImportAlias.js @@ -8,11 +8,10 @@ export class ImportAlias extends SlangNode { constructor(ast, offset, comments) { super(); - const fetch = () => { - const { asKeyword, identifier } = ast; - this.asKeyword = asKeyword.text; - this.identifier = identifier.text; - }; + const fetch = () => ({ + asKeyword: ast.asKeyword.text, + identifier: ast.identifier.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/ImportClause.js b/src/slang-nodes/ImportClause.js index 4373cdd48..067166e92 100644 --- a/src/slang-nodes/ImportClause.js +++ b/src/slang-nodes/ImportClause.js @@ -11,15 +11,14 @@ export class ImportClause extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { variant } = ast; - this.variant = new variants[variant.cst.kind]( - variant, + const fetch = (childrenOffsets) => ({ + variant: new variants[ast.variant.cst.kind]( + ast.variant, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/ImportDeconstruction.js b/src/slang-nodes/ImportDeconstruction.js index 8cb5f3c25..93aa845b2 100644 --- a/src/slang-nodes/ImportDeconstruction.js +++ b/src/slang-nodes/ImportDeconstruction.js @@ -16,24 +16,23 @@ export class ImportDeconstruction extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { openBrace, symbols, closeBrace, fromKeyword, path } = ast; - this.openBrace = openBrace.text; - this.symbols = new ImportDeconstructionSymbols( - symbols, + const fetch = (childrenOffsets) => ({ + openBrace: ast.openBrace.text, + symbols: new ImportDeconstructionSymbols( + ast.symbols, childrenOffsets.shift(), comments, options - ); - this.closeBrace = closeBrace.text; - this.fromKeyword = fromKeyword.text; - this.path = new StringLiteral( - path, + ), + closeBrace: ast.closeBrace.text, + fromKeyword: ast.fromKeyword.text, + path: new StringLiteral( + ast.path, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/ImportDeconstructionSymbol.js b/src/slang-nodes/ImportDeconstructionSymbol.js index 5d34d2ff9..90b9005e3 100644 --- a/src/slang-nodes/ImportDeconstructionSymbol.js +++ b/src/slang-nodes/ImportDeconstructionSymbol.js @@ -9,14 +9,12 @@ export class ImportDeconstructionSymbol extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { name, alias } = ast; - this.name = name.text; - this.alias = - typeof alias === 'undefined' - ? undefined - : new ImportAlias(alias, childrenOffsets.shift(), comments, options); - }; + const fetch = (childrenOffsets) => ({ + name: ast.name.text, + alias: ast.alias + ? new ImportAlias(ast.alias, childrenOffsets.shift(), comments, options) + : undefined + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/ImportDeconstructionSymbols.js b/src/slang-nodes/ImportDeconstructionSymbols.js index 80d0301b8..f6b2be335 100644 --- a/src/slang-nodes/ImportDeconstructionSymbols.js +++ b/src/slang-nodes/ImportDeconstructionSymbols.js @@ -15,9 +15,8 @@ export class ImportDeconstructionSymbols extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { items, separators } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new ImportDeconstructionSymbol( item, @@ -25,9 +24,9 @@ export class ImportDeconstructionSymbols extends SlangNode { comments, options ) - ); - this.separators = separators.map((separator) => separator.text); - }; + ), + separators: ast.separators.map((separator) => separator.text) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/ImportDirective.js b/src/slang-nodes/ImportDirective.js index 9457d0a76..0c9ff7acd 100644 --- a/src/slang-nodes/ImportDirective.js +++ b/src/slang-nodes/ImportDirective.js @@ -11,17 +11,16 @@ export class ImportDirective extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { importKeyword, clause, semicolon } = ast; - this.importKeyword = importKeyword.text; - this.clause = new ImportClause( - clause, + const fetch = (childrenOffsets) => ({ + importKeyword: ast.importKeyword.text, + clause: new ImportClause( + ast.clause, childrenOffsets.shift(), comments, options - ); - this.semicolon = semicolon.text; - }; + ), + semicolon: ast.semicolon.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/IndexAccessEnd.js b/src/slang-nodes/IndexAccessEnd.js index 64e0238b5..155bcdcf9 100644 --- a/src/slang-nodes/IndexAccessEnd.js +++ b/src/slang-nodes/IndexAccessEnd.js @@ -9,18 +9,12 @@ export class IndexAccessEnd extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { colon, end } = ast; - this.colon = colon.text; - if (end) { - this.end = new Expression( - end, - childrenOffsets.shift(), - comments, - options - ); - } - }; + const fetch = (childrenOffsets) => ({ + colon: ast.colon.text, + end: ast.end + ? new Expression(ast.end, childrenOffsets.shift(), comments, options) + : undefined + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/IndexAccessExpression.js b/src/slang-nodes/IndexAccessExpression.js index f71fbdf47..89bd3249d 100644 --- a/src/slang-nodes/IndexAccessExpression.js +++ b/src/slang-nodes/IndexAccessExpression.js @@ -20,33 +20,27 @@ export class IndexAccessExpression extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { operand, openBracket, start, end, closeBracket } = ast; - this.operand = new Expression( - operand, + const fetch = (childrenOffsets) => ({ + operand: new Expression( + ast.operand, childrenOffsets.shift(), comments, options - ); - this.openBracket = openBracket.text; - if (start) { - this.start = new Expression( - start, - childrenOffsets.shift(), - comments, - options - ); - } - if (end) { - this.end = new IndexAccessEnd( - end, - childrenOffsets.shift(), - comments, - options - ); - } - this.closeBracket = closeBracket.text; - }; + ), + openBracket: ast.openBracket.text, + start: ast.start + ? new Expression(ast.start, childrenOffsets.shift(), comments, options) + : undefined, + end: ast.end + ? new IndexAccessEnd( + ast.end, + childrenOffsets.shift(), + comments, + options + ) + : undefined, + closeBracket: ast.closeBracket.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/InheritanceSpecifier.js b/src/slang-nodes/InheritanceSpecifier.js index 20305c8ee..3b18a0c70 100644 --- a/src/slang-nodes/InheritanceSpecifier.js +++ b/src/slang-nodes/InheritanceSpecifier.js @@ -9,16 +9,15 @@ export class InheritanceSpecifier extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { isKeyword, types } = ast; - this.isKeyword = isKeyword?.text; - this.types = new InheritanceTypes( - types, + const fetch = (childrenOffsets) => ({ + isKeyword: ast.isKeyword?.text, + types: new InheritanceTypes( + ast.types, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/InheritanceType.js b/src/slang-nodes/InheritanceType.js index b9296c5c4..6de9ae678 100644 --- a/src/slang-nodes/InheritanceType.js +++ b/src/slang-nodes/InheritanceType.js @@ -10,23 +10,22 @@ export class InheritanceType extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { typeName } = ast; - this.typeName = new IdentifierPath( - typeName, + const fetch = (childrenOffsets) => ({ + typeName: new IdentifierPath( + ast.typeName, childrenOffsets.shift(), comments, options - ); - if (ast.arguments) { - this.arguments = new ArgumentsDeclaration( - ast.arguments, - childrenOffsets.shift(), - comments, - options - ); - } - }; + ), + arguments: ast.arguments + ? new ArgumentsDeclaration( + ast.arguments, + childrenOffsets.shift(), + comments, + options + ) + : undefined + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/InheritanceTypes.js b/src/slang-nodes/InheritanceTypes.js index 505ee45da..f6330a1bf 100644 --- a/src/slang-nodes/InheritanceTypes.js +++ b/src/slang-nodes/InheritanceTypes.js @@ -13,14 +13,13 @@ export class InheritanceTypes extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { items, separators } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new InheritanceType(item, childrenOffsets.shift(), comments, options) - ); - this.separators = separators.map((separator) => separator.text); - }; + ), + separators: ast.separators.map((separator) => separator.text) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/InterfaceDefinition.js b/src/slang-nodes/InterfaceDefinition.js index 99129fc86..86b83f35d 100644 --- a/src/slang-nodes/InterfaceDefinition.js +++ b/src/slang-nodes/InterfaceDefinition.js @@ -21,34 +21,26 @@ export class InterfaceDefinition extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { - interfaceKeyword, - name, - inheritance, - openBrace, - members, - closeBrace - } = ast; - this.interfaceKeyword = interfaceKeyword.text; - this.name = name.text; - if (inheritance) { - this.inheritance = new InheritanceSpecifier( - inheritance, - childrenOffsets.shift(), - comments, - options - ); - } - this.openBrace = openBrace.text; - this.members = new InterfaceMembers( - members, + const fetch = (childrenOffsets) => ({ + interfaceKeyword: ast.interfaceKeyword.text, + name: ast.name.text, + inheritance: ast.inheritance + ? new InheritanceSpecifier( + ast.inheritance, + childrenOffsets.shift(), + comments, + options + ) + : undefined, + openBrace: ast.openBrace.text, + members: new InterfaceMembers( + ast.members, childrenOffsets.shift(), comments, options - ); - this.closeBrace = closeBrace.text; - }; + ), + closeBrace: ast.closeBrace.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/InterfaceMembers.js b/src/slang-nodes/InterfaceMembers.js index 07b38cad6..158426714 100644 --- a/src/slang-nodes/InterfaceMembers.js +++ b/src/slang-nodes/InterfaceMembers.js @@ -12,13 +12,12 @@ export class InterfaceMembers extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { items } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new ContractMember(item, childrenOffsets.shift(), comments, options) - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/LibraryDefinition.js b/src/slang-nodes/LibraryDefinition.js index 9b29138ed..965b50e1a 100644 --- a/src/slang-nodes/LibraryDefinition.js +++ b/src/slang-nodes/LibraryDefinition.js @@ -18,19 +18,18 @@ export class LibraryDefinition extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { libraryKeyword, name, openBrace, members, closeBrace } = ast; - this.libraryKeyword = libraryKeyword.text; - this.name = name.text; - this.openBrace = openBrace.text; - this.members = new LibraryMembers( - members, + const fetch = (childrenOffsets) => ({ + libraryKeyword: ast.libraryKeyword.text, + name: ast.name.text, + openBrace: ast.openBrace.text, + members: new LibraryMembers( + ast.members, childrenOffsets.shift(), comments, options - ); - this.closeBrace = closeBrace.text; - }; + ), + closeBrace: ast.closeBrace.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/LibraryMembers.js b/src/slang-nodes/LibraryMembers.js index 35ba6b298..b9ade2e7d 100644 --- a/src/slang-nodes/LibraryMembers.js +++ b/src/slang-nodes/LibraryMembers.js @@ -12,13 +12,12 @@ export class LibraryMembers extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { items } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new ContractMember(item, childrenOffsets.shift(), comments, options) - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/MappingKey.js b/src/slang-nodes/MappingKey.js index 6682cb7c4..124490e84 100644 --- a/src/slang-nodes/MappingKey.js +++ b/src/slang-nodes/MappingKey.js @@ -9,16 +9,15 @@ export class MappingKey extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { keyType, name } = ast; - this.keyType = new MappingKeyType( - keyType, + const fetch = (childrenOffsets) => ({ + keyType: new MappingKeyType( + ast.keyType, childrenOffsets.shift(), comments, options - ); - this.name = name?.text; - }; + ), + name: ast.name?.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/MappingKeyType.js b/src/slang-nodes/MappingKeyType.js index aa1c6ce59..677a75515 100644 --- a/src/slang-nodes/MappingKeyType.js +++ b/src/slang-nodes/MappingKeyType.js @@ -9,15 +9,14 @@ export class MappingKeyType extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { variant } = ast; - this.variant = new variants[variant.cst.kind]( - variant, + const fetch = (childrenOffsets) => ({ + variant: new variants[ast.variant.cst.kind]( + ast.variant, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/MappingType.js b/src/slang-nodes/MappingType.js index 0a117e266..de0864fce 100644 --- a/src/slang-nodes/MappingType.js +++ b/src/slang-nodes/MappingType.js @@ -18,32 +18,24 @@ export class MappingType extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { - mappingKeyword, - openParen, - keyType, - equalGreaterThan, - valueType, - closeParen - } = ast; - this.mappingKeyword = mappingKeyword.text; - this.openParen = openParen.text; - this.keyType = new MappingKey( - keyType, + const fetch = (childrenOffsets) => ({ + mappingKeyword: ast.mappingKeyword.text, + openParen: ast.openParen.text, + keyType: new MappingKey( + ast.keyType, childrenOffsets.shift(), comments, options - ); - this.equalGreaterThan = equalGreaterThan.text; - this.valueType = new MappingValue( - valueType, + ), + equalGreaterThan: ast.equalGreaterThan.text, + valueType: new MappingValue( + ast.valueType, childrenOffsets.shift(), comments, options - ); - this.closeParen = closeParen.text; - }; + ), + closeParen: ast.closeParen.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/MappingValue.js b/src/slang-nodes/MappingValue.js index 0dc72b0a6..e3420ac15 100644 --- a/src/slang-nodes/MappingValue.js +++ b/src/slang-nodes/MappingValue.js @@ -9,16 +9,15 @@ export class MappingValue extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { typeName, name } = ast; - this.typeName = new TypeName( - typeName, + const fetch = (childrenOffsets) => ({ + typeName: new TypeName( + ast.typeName, childrenOffsets.shift(), comments, options - ); - this.name = name?.text; - }; + ), + name: ast.name?.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/MemberAccess.js b/src/slang-nodes/MemberAccess.js index a8f542a4f..d2cf5aff2 100644 --- a/src/slang-nodes/MemberAccess.js +++ b/src/slang-nodes/MemberAccess.js @@ -6,10 +6,9 @@ export class MemberAccess extends SlangNode { constructor(ast, offset, comments) { super(); - const fetch = () => { - const { variant } = ast; - this.variant = variant.text; - }; + const fetch = () => ({ + variant: ast.variant.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/MemberAccessExpression.js b/src/slang-nodes/MemberAccessExpression.js index 76914142a..3e8ed1eeb 100644 --- a/src/slang-nodes/MemberAccessExpression.js +++ b/src/slang-nodes/MemberAccessExpression.js @@ -117,22 +117,21 @@ export class MemberAccessExpression extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { operand, period, member } = ast; - this.operand = new Expression( - operand, + const fetch = (childrenOffsets) => ({ + operand: new Expression( + ast.operand, childrenOffsets.shift(), comments, options - ); - this.period = period.text; - this.member = new MemberAccess( - member, + ), + period: ast.period.text, + member: new MemberAccess( + ast.member, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/ModifierAttribute.js b/src/slang-nodes/ModifierAttribute.js index f630055ee..76adbdcc4 100644 --- a/src/slang-nodes/ModifierAttribute.js +++ b/src/slang-nodes/ModifierAttribute.js @@ -7,18 +7,17 @@ export class ModifierAttribute extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { variant } = ast; - this.variant = - variant.type === 'Terminal' - ? variant.text + const fetch = (childrenOffsets) => ({ + variant: + ast.variant.type === 'Terminal' + ? ast.variant.text : new OverrideSpecifier( - variant, + ast.variant, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/ModifierAttributes.js b/src/slang-nodes/ModifierAttributes.js index ea137d4c6..d144c4c15 100644 --- a/src/slang-nodes/ModifierAttributes.js +++ b/src/slang-nodes/ModifierAttributes.js @@ -11,9 +11,8 @@ export class ModifierAttributes extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { items } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new ModifierAttribute( item, @@ -21,8 +20,8 @@ export class ModifierAttributes extends SlangNode { comments, options ) - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); diff --git a/src/slang-nodes/ModifierDefinition.js b/src/slang-nodes/ModifierDefinition.js index a98093241..30a07ce86 100644 --- a/src/slang-nodes/ModifierDefinition.js +++ b/src/slang-nodes/ModifierDefinition.js @@ -19,31 +19,30 @@ export class ModifierDefinition extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { modifierKeyword, name, parameters, attributes, body } = ast; - this.modifierKeyword = modifierKeyword.text; - this.name = name.text; - if (parameters) { - this.parameters = new ParametersDeclaration( - parameters, - childrenOffsets.shift(), - comments, - options - ); - } - this.attributes = new ModifierAttributes( - attributes, + const fetch = (childrenOffsets) => ({ + modifierKeyword: ast.modifierKeyword.text, + name: ast.name.text, + parameters: ast.parameters + ? new ParametersDeclaration( + ast.parameters, + childrenOffsets.shift(), + comments, + options + ) + : undefined, + attributes: new ModifierAttributes( + ast.attributes, childrenOffsets.shift(), comments, options - ); - this.body = new FunctionBody( - body, + ), + body: new FunctionBody( + ast.body, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); diff --git a/src/slang-nodes/ModifierInvocation.js b/src/slang-nodes/ModifierInvocation.js index d711d87d4..ad93014cc 100644 --- a/src/slang-nodes/ModifierInvocation.js +++ b/src/slang-nodes/ModifierInvocation.js @@ -11,23 +11,22 @@ export class ModifierInvocation extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { name } = ast; - this.name = new IdentifierPath( - name, + const fetch = (childrenOffsets) => ({ + name: new IdentifierPath( + ast.name, childrenOffsets.shift(), comments, options - ); - if (ast.arguments) { - this.arguments = new ArgumentsDeclaration( - ast.arguments, - childrenOffsets.shift(), - comments, - options - ); - } - }; + ), + arguments: ast.arguments + ? new ArgumentsDeclaration( + ast.arguments, + childrenOffsets.shift(), + comments, + options + ) + : undefined + }); this.initialize(ast, offset, fetch, comments); diff --git a/src/slang-nodes/MultiplicativeExpression.js b/src/slang-nodes/MultiplicativeExpression.js index 8f8f51824..6d126f010 100644 --- a/src/slang-nodes/MultiplicativeExpression.js +++ b/src/slang-nodes/MultiplicativeExpression.js @@ -17,22 +17,21 @@ export class MultiplicativeExpression extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { leftOperand, operator, rightOperand } = ast; - this.leftOperand = new Expression( - leftOperand, + const fetch = (childrenOffsets) => ({ + leftOperand: new Expression( + ast.leftOperand, childrenOffsets.shift(), comments, options - ); - this.operator = operator.text; - this.rightOperand = new Expression( - rightOperand, + ), + operator: ast.operator.text, + rightOperand: new Expression( + ast.rightOperand, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); diff --git a/src/slang-nodes/NamedArgument.js b/src/slang-nodes/NamedArgument.js index e031a9b14..c683b7d38 100644 --- a/src/slang-nodes/NamedArgument.js +++ b/src/slang-nodes/NamedArgument.js @@ -11,17 +11,16 @@ export class NamedArgument extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { name, colon, value } = ast; - this.name = name.text; - this.colon = colon.text; - this.value = new Expression( - value, + const fetch = (childrenOffsets) => ({ + name: ast.name.text, + colon: ast.colon.text, + value: new Expression( + ast.value, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/NamedArgumentGroup.js b/src/slang-nodes/NamedArgumentGroup.js index e7d42196b..8eb161a2d 100644 --- a/src/slang-nodes/NamedArgumentGroup.js +++ b/src/slang-nodes/NamedArgumentGroup.js @@ -11,18 +11,16 @@ export class NamedArgumentGroup extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { openBrace, closeBrace } = ast; - this.openBrace = openBrace.text; - this.arguments = new NamedArguments( + const fetch = (childrenOffsets) => ({ + openBrace: ast.openBrace.text, + arguments: new NamedArguments( ast.arguments, childrenOffsets.shift(), comments, options - ); - - this.closeBrace = closeBrace.text; - }; + ), + closeBrace: ast.closeBrace.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/NamedArguments.js b/src/slang-nodes/NamedArguments.js index d736a0cf4..a3a3e0cd6 100644 --- a/src/slang-nodes/NamedArguments.js +++ b/src/slang-nodes/NamedArguments.js @@ -13,14 +13,13 @@ export class NamedArguments extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { items, separators } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new NamedArgument(item, childrenOffsets.shift(), comments, options) - ); - this.separators = separators.map((separator) => separator.text); - }; + ), + separators: ast.separators.map((separator) => separator.text) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/NamedArgumentsDeclaration.js b/src/slang-nodes/NamedArgumentsDeclaration.js index 75abe930a..d855f3528 100644 --- a/src/slang-nodes/NamedArgumentsDeclaration.js +++ b/src/slang-nodes/NamedArgumentsDeclaration.js @@ -11,19 +11,18 @@ export class NamedArgumentsDeclaration extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { openParen, closeParen } = ast; - this.openParen = openParen.text; - if (ast.arguments) { - this.arguments = new NamedArgumentGroup( - ast.arguments, - childrenOffsets.shift(), - comments, - options - ); - } - this.closeParen = closeParen.text; - }; + const fetch = (childrenOffsets) => ({ + openParen: ast.openParen.text, + arguments: ast.arguments + ? new NamedArgumentGroup( + ast.arguments, + childrenOffsets.shift(), + comments, + options + ) + : undefined, + closeParen: ast.closeParen.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/NamedImport.js b/src/slang-nodes/NamedImport.js index 565bfa4d0..c6c7d1287 100644 --- a/src/slang-nodes/NamedImport.js +++ b/src/slang-nodes/NamedImport.js @@ -14,23 +14,22 @@ export class NamedImport extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { asterisk, alias, fromKeyword, path } = ast; - this.asterisk = asterisk.text; - this.alias = new ImportAlias( - alias, + const fetch = (childrenOffsets) => ({ + asterisk: ast.asterisk.text, + alias: new ImportAlias( + ast.alias, childrenOffsets.shift(), comments, options - ); - this.fromKeyword = fromKeyword.text; - this.path = new StringLiteral( - path, + ), + fromKeyword: ast.fromKeyword.text, + path: new StringLiteral( + ast.path, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/NewExpression.js b/src/slang-nodes/NewExpression.js index b1e137531..e68d0f313 100644 --- a/src/slang-nodes/NewExpression.js +++ b/src/slang-nodes/NewExpression.js @@ -9,16 +9,15 @@ export class NewExpression extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { newKeyword, typeName } = ast; - this.newKeyword = newKeyword.text; - this.typeName = new TypeName( - typeName, + const fetch = (childrenOffsets) => ({ + newKeyword: ast.newKeyword.text, + typeName: new TypeName( + ast.typeName, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/NumberUnit.js b/src/slang-nodes/NumberUnit.js index 54113607e..f5a0a4358 100644 --- a/src/slang-nodes/NumberUnit.js +++ b/src/slang-nodes/NumberUnit.js @@ -6,10 +6,9 @@ export class NumberUnit extends SlangNode { constructor(ast, offset, comments) { super(); - const fetch = () => { - const { variant } = ast; - this.variant = variant.text; - }; + const fetch = () => ({ + variant: ast.variant.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/OrExpression.js b/src/slang-nodes/OrExpression.js index df774befa..52605297e 100644 --- a/src/slang-nodes/OrExpression.js +++ b/src/slang-nodes/OrExpression.js @@ -15,22 +15,21 @@ export class OrExpression extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { leftOperand, operator, rightOperand } = ast; - this.leftOperand = new Expression( - leftOperand, + const fetch = (childrenOffsets) => ({ + leftOperand: new Expression( + ast.leftOperand, childrenOffsets.shift(), comments, options - ); - this.operator = operator.text; - this.rightOperand = new Expression( - rightOperand, + ), + operator: ast.operator.text, + rightOperand: new Expression( + ast.rightOperand, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); diff --git a/src/slang-nodes/OverridePaths.js b/src/slang-nodes/OverridePaths.js index d1f674dde..99f006860 100644 --- a/src/slang-nodes/OverridePaths.js +++ b/src/slang-nodes/OverridePaths.js @@ -9,14 +9,13 @@ export class OverridePaths extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { items, separators } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new IdentifierPath(item, childrenOffsets.shift(), comments, options) - ); - this.separators = separators.map((separator) => separator.text); - }; + ), + separators: ast.separators.map((separator) => separator.text) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/OverridePathsDeclaration.js b/src/slang-nodes/OverridePathsDeclaration.js index 9589fe86f..32e320edd 100644 --- a/src/slang-nodes/OverridePathsDeclaration.js +++ b/src/slang-nodes/OverridePathsDeclaration.js @@ -11,17 +11,16 @@ export class OverridePathsDeclaration extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { openParen, paths, closeParen } = ast; - this.openParen = openParen.text; - this.paths = new OverridePaths( - paths, + const fetch = (childrenOffsets) => ({ + openParen: ast.openParen.text, + paths: new OverridePaths( + ast.paths, childrenOffsets.shift(), comments, options - ); - this.closeParen = closeParen.text; - }; + ), + closeParen: ast.closeParen.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/OverrideSpecifier.js b/src/slang-nodes/OverrideSpecifier.js index d2ea338bf..4788efdbd 100644 --- a/src/slang-nodes/OverrideSpecifier.js +++ b/src/slang-nodes/OverrideSpecifier.js @@ -9,18 +9,17 @@ export class OverrideSpecifier extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { overrideKeyword, overridden } = ast; - this.overrideKeyword = overrideKeyword.text; - if (overridden) { - this.overridden = new OverridePathsDeclaration( - overridden, - childrenOffsets.shift(), - comments, - options - ); - } - }; + const fetch = (childrenOffsets) => ({ + overrideKeyword: ast.overrideKeyword.text, + overridden: ast.overridden + ? new OverridePathsDeclaration( + ast.overridden, + childrenOffsets.shift(), + comments, + options + ) + : undefined + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/Parameter.js b/src/slang-nodes/Parameter.js index c7b9f29bb..4f07f5ad7 100644 --- a/src/slang-nodes/Parameter.js +++ b/src/slang-nodes/Parameter.js @@ -15,24 +15,23 @@ export class Parameter extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { typeName, storageLocation, name } = ast; - this.typeName = new TypeName( - typeName, + const fetch = (childrenOffsets) => ({ + typeName: new TypeName( + ast.typeName, childrenOffsets.shift(), comments, options - ); - if (storageLocation) { - this.storageLocation = new StorageLocation( - storageLocation, - childrenOffsets.shift(), - comments, - options - ); - } - this.name = name?.text; - }; + ), + storageLocation: ast.storageLocation + ? new StorageLocation( + ast.storageLocation, + childrenOffsets.shift(), + comments, + options + ) + : undefined, + name: ast.name?.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/Parameters.js b/src/slang-nodes/Parameters.js index bdedb267f..38f349825 100644 --- a/src/slang-nodes/Parameters.js +++ b/src/slang-nodes/Parameters.js @@ -14,14 +14,13 @@ export class Parameters extends SlangNode { constructor(ast, offset, comments, options) { super(); if (offset) { - const fetch = (childrenOffsets) => { - const { items, separators } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new Parameter(item, childrenOffsets.shift(), comments, options) - ); - this.separators = separators.map((separator) => separator.text); - }; + ), + separators: ast.separators.map((separator) => separator.text) + }); this.initialize(ast, offset, fetch, comments); } else { diff --git a/src/slang-nodes/ParametersDeclaration.js b/src/slang-nodes/ParametersDeclaration.js index 26fcf225f..6ea0cc089 100644 --- a/src/slang-nodes/ParametersDeclaration.js +++ b/src/slang-nodes/ParametersDeclaration.js @@ -11,17 +11,16 @@ export class ParametersDeclaration extends SlangNode { constructor(ast, offset, comments, options) { super(); if (offset) { - const fetch = (childrenOffsets) => { - const { openParen, parameters, closeParen } = ast; - this.openParen = openParen.text; - this.parameters = new Parameters( - parameters, + const fetch = (childrenOffsets) => ({ + openParen: ast.openParen.text, + parameters: new Parameters( + ast.parameters, childrenOffsets.shift(), comments, options - ); - this.closeParen = closeParen.text; - }; + ), + closeParen: ast.closeParen.text + }); this.initialize(ast, offset, fetch, comments); } else { diff --git a/src/slang-nodes/PathImport.js b/src/slang-nodes/PathImport.js index 974690b90..c6a4f6881 100644 --- a/src/slang-nodes/PathImport.js +++ b/src/slang-nodes/PathImport.js @@ -10,19 +10,17 @@ export class PathImport extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { path, alias } = ast; - this.path = new StringLiteral( - path, + const fetch = (childrenOffsets) => ({ + path: new StringLiteral( + ast.path, childrenOffsets.shift(), comments, options - ); - this.alias = - typeof alias === 'undefined' - ? undefined - : new ImportAlias(alias, childrenOffsets.shift(), comments, options); - }; + ), + alias: ast.alias + ? new ImportAlias(ast.alias, childrenOffsets.shift(), comments, options) + : undefined + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/PositionalArguments.js b/src/slang-nodes/PositionalArguments.js index da84e739e..97d0def06 100644 --- a/src/slang-nodes/PositionalArguments.js +++ b/src/slang-nodes/PositionalArguments.js @@ -10,14 +10,13 @@ export class PositionalArguments extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { items, separators } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new Expression(item, childrenOffsets.shift(), comments, options) - ); - this.separators = separators.map((separator) => separator.text); - }; + ), + separators: ast.separators.map((separator) => separator.text) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/PositionalArgumentsDeclaration.js b/src/slang-nodes/PositionalArgumentsDeclaration.js index 73fa4c6a6..e324b9e6a 100644 --- a/src/slang-nodes/PositionalArgumentsDeclaration.js +++ b/src/slang-nodes/PositionalArgumentsDeclaration.js @@ -11,18 +11,16 @@ export class PositionalArgumentsDeclaration extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { openParen, closeParen } = ast; - const $arguments = ast.arguments; - this.openParen = openParen.text; - this.arguments = new PositionalArguments( - $arguments, + const fetch = (childrenOffsets) => ({ + openParen: ast.openParen.text, + arguments: new PositionalArguments( + ast.arguments, childrenOffsets.shift(), comments, options - ); - this.closeParen = closeParen.text; - }; + ), + closeParen: ast.closeParen.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/PostfixExpression.js b/src/slang-nodes/PostfixExpression.js index c8ffcec36..9fe0093bf 100644 --- a/src/slang-nodes/PostfixExpression.js +++ b/src/slang-nodes/PostfixExpression.js @@ -9,16 +9,15 @@ export class PostfixExpression extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { operand, operator } = ast; - this.operand = new Expression( - operand, + const fetch = (childrenOffsets) => ({ + operand: new Expression( + ast.operand, childrenOffsets.shift(), comments, options - ); - this.operator = operator.text; - }; + ), + operator: ast.operator.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/Pragma.js b/src/slang-nodes/Pragma.js index 8e579fc28..66dbaffce 100644 --- a/src/slang-nodes/Pragma.js +++ b/src/slang-nodes/Pragma.js @@ -10,15 +10,14 @@ export class Pragma extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { variant } = ast; - this.variant = new variants[variant.cst.kind]( - variant, + const fetch = (childrenOffsets) => ({ + variant: new variants[ast.variant.cst.kind]( + ast.variant, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/PragmaDirective.js b/src/slang-nodes/PragmaDirective.js index cc0bbdc2f..c0e86fe31 100644 --- a/src/slang-nodes/PragmaDirective.js +++ b/src/slang-nodes/PragmaDirective.js @@ -11,17 +11,16 @@ export class PragmaDirective extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { pragmaKeyword, pragma, semicolon } = ast; - this.pragmaKeyword = pragmaKeyword.text; - this.pragma = new Pragma( - pragma, + const fetch = (childrenOffsets) => ({ + pragmaKeyword: ast.pragmaKeyword.text, + pragma: new Pragma( + ast.pragma, childrenOffsets.shift(), comments, options - ); - this.semicolon = semicolon.text; - }; + ), + semicolon: ast.semicolon.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/PrefixExpression.js b/src/slang-nodes/PrefixExpression.js index 5e2386cef..09fdda17c 100644 --- a/src/slang-nodes/PrefixExpression.js +++ b/src/slang-nodes/PrefixExpression.js @@ -9,16 +9,15 @@ export class PrefixExpression extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { operator, operand } = ast; - this.operator = operator.text; - this.operand = new Expression( - operand, + const fetch = (childrenOffsets) => ({ + operator: ast.operator.text, + operand: new Expression( + ast.operand, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/ReceiveFunctionAttribute.js b/src/slang-nodes/ReceiveFunctionAttribute.js index 9e7b011f9..a0d369455 100644 --- a/src/slang-nodes/ReceiveFunctionAttribute.js +++ b/src/slang-nodes/ReceiveFunctionAttribute.js @@ -10,18 +10,17 @@ export class ReceiveFunctionAttribute extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { variant } = ast; - this.variant = - variant.type === 'Terminal' - ? variant.text - : new variants[variant.cst.kind]( - variant, + const fetch = (childrenOffsets) => ({ + variant: + ast.variant.type === 'Terminal' + ? ast.variant.text + : new variants[ast.variant.cst.kind]( + ast.variant, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/ReceiveFunctionAttributes.js b/src/slang-nodes/ReceiveFunctionAttributes.js index 560efe20b..f47377fc1 100644 --- a/src/slang-nodes/ReceiveFunctionAttributes.js +++ b/src/slang-nodes/ReceiveFunctionAttributes.js @@ -11,9 +11,8 @@ export class ReceiveFunctionAttributes extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { items } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new ReceiveFunctionAttribute( item, @@ -21,8 +20,8 @@ export class ReceiveFunctionAttributes extends SlangNode { comments, options ) - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); diff --git a/src/slang-nodes/ReceiveFunctionDefinition.js b/src/slang-nodes/ReceiveFunctionDefinition.js index 7cbd36468..a95f97af1 100644 --- a/src/slang-nodes/ReceiveFunctionDefinition.js +++ b/src/slang-nodes/ReceiveFunctionDefinition.js @@ -16,28 +16,27 @@ export class ReceiveFunctionDefinition extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { receiveKeyword, parameters, attributes, body } = ast; - this.receiveKeyword = receiveKeyword.text; - this.parameters = new ParametersDeclaration( - parameters, + const fetch = (childrenOffsets) => ({ + receiveKeyword: ast.receiveKeyword.text, + parameters: new ParametersDeclaration( + ast.parameters, childrenOffsets.shift(), comments, options - ); - this.attributes = new ReceiveFunctionAttributes( - attributes, + ), + attributes: new ReceiveFunctionAttributes( + ast.attributes, childrenOffsets.shift(), comments, options - ); - this.body = new FunctionBody( - body, + ), + body: new FunctionBody( + ast.body, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); diff --git a/src/slang-nodes/ReturnStatement.js b/src/slang-nodes/ReturnStatement.js index 05f3ed149..49f5c20f5 100644 --- a/src/slang-nodes/ReturnStatement.js +++ b/src/slang-nodes/ReturnStatement.js @@ -25,19 +25,19 @@ export class ReturnStatement extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { returnKeyword, expression, semicolon } = ast; - this.returnKeyword = returnKeyword.text; - if (expression) { - this.expression = new Expression( - expression, - childrenOffsets.shift(), - comments, - options - ); - } - this.semicolon = semicolon.text; - }; + const fetch = (childrenOffsets) => ({ + returnKeyword: ast.returnKeyword.text, + expression: ast.expression + ? new Expression( + ast.expression, + childrenOffsets.shift(), + comments, + options + ) + : undefined, + + semicolon: ast.semicolon.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/ReturnsDeclaration.js b/src/slang-nodes/ReturnsDeclaration.js index 34481d64a..d58bfae95 100644 --- a/src/slang-nodes/ReturnsDeclaration.js +++ b/src/slang-nodes/ReturnsDeclaration.js @@ -12,16 +12,15 @@ export class ReturnsDeclaration extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { returnsKeyword, variables } = ast; - this.returnsKeyword = returnsKeyword.text; - this.variables = new ParametersDeclaration( - variables, + const fetch = (childrenOffsets) => ({ + returnsKeyword: ast.returnsKeyword.text, + variables: new ParametersDeclaration( + ast.variables, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/RevertStatement.js b/src/slang-nodes/RevertStatement.js index 156025ea8..f2ab1670e 100644 --- a/src/slang-nodes/RevertStatement.js +++ b/src/slang-nodes/RevertStatement.js @@ -14,25 +14,24 @@ export class RevertStatement extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { revertKeyword, error, semicolon } = ast; - this.revertKeyword = revertKeyword.text; - if (error) { - this.error = new IdentifierPath( - error, - childrenOffsets.shift(), - comments, - options - ); - } - this.arguments = new ArgumentsDeclaration( + const fetch = (childrenOffsets) => ({ + revertKeyword: ast.revertKeyword.text, + error: ast.error + ? new IdentifierPath( + ast.error, + childrenOffsets.shift(), + comments, + options + ) + : undefined, + arguments: new ArgumentsDeclaration( ast.arguments, childrenOffsets.shift(), comments, options - ); - this.semicolon = semicolon.text; - }; + ), + semicolon: ast.semicolon.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/ShiftExpression.js b/src/slang-nodes/ShiftExpression.js index 145d714d1..66eba3b56 100644 --- a/src/slang-nodes/ShiftExpression.js +++ b/src/slang-nodes/ShiftExpression.js @@ -24,22 +24,21 @@ export class ShiftExpression extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { leftOperand, operator, rightOperand } = ast; - this.leftOperand = new Expression( - leftOperand, + const fetch = (childrenOffsets) => ({ + leftOperand: new Expression( + ast.leftOperand, childrenOffsets.shift(), comments, options - ); - this.operator = operator.text; - this.rightOperand = new Expression( - rightOperand, + ), + operator: ast.operator.text, + rightOperand: new Expression( + ast.rightOperand, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); diff --git a/src/slang-nodes/SlangNode.js b/src/slang-nodes/SlangNode.js index 0285eb821..14fcb6d86 100644 --- a/src/slang-nodes/SlangNode.js +++ b/src/slang-nodes/SlangNode.js @@ -19,7 +19,20 @@ export class SlangNode { const childrenOffsets = getChildrenOffsets(cstChildren, offset, comments); // populate all children nodes - fetch(childrenOffsets); + let children; + + this.fetch = () => { + if (children === undefined) { + children = fetch(childrenOffsets); + } + return children; + }; + + this.fetch(); + + Object.keys(children).forEach((childKey) => { + this[childKey] = children[childKey]; + }); // calculate correct loc object const startWithTrivia = offset; diff --git a/src/slang-nodes/SourceUnit.js b/src/slang-nodes/SourceUnit.js index 5062a8587..439c87065 100644 --- a/src/slang-nodes/SourceUnit.js +++ b/src/slang-nodes/SourceUnit.js @@ -10,15 +10,14 @@ export class SourceUnit extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { members } = ast; - this.members = new SourceUnitMembers( - members, + const fetch = (childrenOffsets) => ({ + members: new SourceUnitMembers( + ast.members, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/SourceUnitMember.js b/src/slang-nodes/SourceUnitMember.js index dc5e4d2b5..37f53fd37 100644 --- a/src/slang-nodes/SourceUnitMember.js +++ b/src/slang-nodes/SourceUnitMember.js @@ -34,15 +34,14 @@ export class SourceUnitMember extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { variant } = ast; - this.variant = new variants[variant.cst.kind]( - variant, + const fetch = (childrenOffsets) => ({ + variant: new variants[ast.variant.cst.kind]( + ast.variant, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/SourceUnitMembers.js b/src/slang-nodes/SourceUnitMembers.js index 58f7e5056..ed907f69a 100644 --- a/src/slang-nodes/SourceUnitMembers.js +++ b/src/slang-nodes/SourceUnitMembers.js @@ -8,13 +8,12 @@ export class SourceUnitMembers extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { items } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new SourceUnitMember(item, childrenOffsets.shift(), comments, options) - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/StateVariableAttribute.js b/src/slang-nodes/StateVariableAttribute.js index 60929403f..419eca76d 100644 --- a/src/slang-nodes/StateVariableAttribute.js +++ b/src/slang-nodes/StateVariableAttribute.js @@ -7,18 +7,17 @@ export class StateVariableAttribute extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { variant } = ast; - this.variant = - variant.type === 'Terminal' - ? variant.text + const fetch = (childrenOffsets) => ({ + variant: + ast.variant.type === 'Terminal' + ? ast.variant.text : new OverrideSpecifier( - variant, + ast.variant, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/StateVariableAttributes.js b/src/slang-nodes/StateVariableAttributes.js index b23e62d78..bb739d53f 100644 --- a/src/slang-nodes/StateVariableAttributes.js +++ b/src/slang-nodes/StateVariableAttributes.js @@ -7,9 +7,8 @@ export class StateVariableAttributes extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { items } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new StateVariableAttribute( item, @@ -17,8 +16,8 @@ export class StateVariableAttributes extends SlangNode { comments, options ) - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/StateVariableDefinition.js b/src/slang-nodes/StateVariableDefinition.js index fef44605b..21b374d8b 100644 --- a/src/slang-nodes/StateVariableDefinition.js +++ b/src/slang-nodes/StateVariableDefinition.js @@ -17,31 +17,30 @@ export class StateVariableDefinition extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { typeName, attributes, name, value, semicolon } = ast; - this.typeName = new TypeName( - typeName, + const fetch = (childrenOffsets) => ({ + typeName: new TypeName( + ast.typeName, childrenOffsets.shift(), comments, options - ); - this.attributes = new StateVariableAttributes( - attributes, + ), + attributes: new StateVariableAttributes( + ast.attributes, childrenOffsets.shift(), comments, options - ); - this.name = name.text; - if (value) { - this.value = new StateVariableDefinitionValue( - value, - childrenOffsets.shift(), - comments, - options - ); - } - this.semicolon = semicolon.text; - }; + ), + name: ast.name.text, + value: ast.value + ? new StateVariableDefinitionValue( + ast.value, + childrenOffsets.shift(), + comments, + options + ) + : undefined, + semicolon: ast.semicolon.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/StateVariableDefinitionValue.js b/src/slang-nodes/StateVariableDefinitionValue.js index 775d6008a..b116794b3 100644 --- a/src/slang-nodes/StateVariableDefinitionValue.js +++ b/src/slang-nodes/StateVariableDefinitionValue.js @@ -12,16 +12,15 @@ export class StateVariableDefinitionValue extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { equal, value } = ast; - this.equal = equal.text; - this.value = new Expression( - value, + const fetch = (childrenOffsets) => ({ + equal: ast.equal.text, + value: new Expression( + ast.value, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/Statement.js b/src/slang-nodes/Statement.js index f42223c4f..2e7550c1c 100644 --- a/src/slang-nodes/Statement.js +++ b/src/slang-nodes/Statement.js @@ -43,15 +43,14 @@ export class Statement extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { variant } = ast; - this.variant = new variants[variant.cst.kind]( - variant, + const fetch = (childrenOffsets) => ({ + variant: new variants[ast.variant.cst.kind]( + ast.variant, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/Statements.js b/src/slang-nodes/Statements.js index f940b2990..dba7a63ba 100644 --- a/src/slang-nodes/Statements.js +++ b/src/slang-nodes/Statements.js @@ -13,13 +13,12 @@ export class Statements extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { items } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new Statement(item, childrenOffsets.shift(), comments, options) - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/StorageLocation.js b/src/slang-nodes/StorageLocation.js index a06543a56..fb8a72ec0 100644 --- a/src/slang-nodes/StorageLocation.js +++ b/src/slang-nodes/StorageLocation.js @@ -6,10 +6,9 @@ export class StorageLocation extends SlangNode { constructor(ast, offset, comments) { super(); - const fetch = () => { - const { variant } = ast; - this.variant = variant.text; - }; + const fetch = () => ({ + variant: ast.variant.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/StringExpression.js b/src/slang-nodes/StringExpression.js index 16b5d858a..7c5526bef 100644 --- a/src/slang-nodes/StringExpression.js +++ b/src/slang-nodes/StringExpression.js @@ -18,15 +18,14 @@ export class StringExpression extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { variant } = ast; - this.variant = new variants[variant.cst.kind]( - variant, + const fetch = (childrenOffsets) => ({ + variant: new variants[ast.variant.cst.kind]( + ast.variant, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/StringLiteral.js b/src/slang-nodes/StringLiteral.js index 759f6b9ee..576bc76ea 100644 --- a/src/slang-nodes/StringLiteral.js +++ b/src/slang-nodes/StringLiteral.js @@ -7,10 +7,9 @@ export class StringLiteral extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = () => { - const { variant } = ast; - this.variant = variant.text; - }; + const fetch = () => ({ + variant: ast.variant.text + }); this.initialize(ast, offset, fetch, comments); diff --git a/src/slang-nodes/StringLiterals.js b/src/slang-nodes/StringLiterals.js index edd342ce2..103c6606a 100644 --- a/src/slang-nodes/StringLiterals.js +++ b/src/slang-nodes/StringLiterals.js @@ -10,13 +10,12 @@ export class StringLiterals extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { items } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new StringLiteral(item, childrenOffsets.shift(), comments, options) - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/StructDefinition.js b/src/slang-nodes/StructDefinition.js index 80a2d1eca..3caac54ea 100644 --- a/src/slang-nodes/StructDefinition.js +++ b/src/slang-nodes/StructDefinition.js @@ -15,19 +15,18 @@ export class StructDefinition extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { structKeyword, name, openBrace, members, closeBrace } = ast; - this.structKeyword = structKeyword.text; - this.name = name.text; - this.openBrace = openBrace.text; - this.members = new StructMembers( - members, + const fetch = (childrenOffsets) => ({ + structKeyword: ast.structKeyword.text, + name: ast.name.text, + openBrace: ast.openBrace.text, + members: new StructMembers( + ast.members, childrenOffsets.shift(), comments, options - ); - this.closeBrace = closeBrace.text; - }; + ), + closeBrace: ast.closeBrace.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/StructMember.js b/src/slang-nodes/StructMember.js index 8f4e39fe3..fed939a28 100644 --- a/src/slang-nodes/StructMember.js +++ b/src/slang-nodes/StructMember.js @@ -11,17 +11,16 @@ export class StructMember extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { typeName, name, semicolon } = ast; - this.typeName = new TypeName( - typeName, + const fetch = (childrenOffsets) => ({ + typeName: new TypeName( + ast.typeName, childrenOffsets.shift(), comments, options - ); - this.name = name.text; - this.semicolon = semicolon.text; - }; + ), + name: ast.name.text, + semicolon: ast.semicolon.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/StructMembers.js b/src/slang-nodes/StructMembers.js index 4545130a0..edca9e054 100644 --- a/src/slang-nodes/StructMembers.js +++ b/src/slang-nodes/StructMembers.js @@ -11,13 +11,12 @@ export class StructMembers extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { items } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new StructMember(item, childrenOffsets.shift(), comments, options) - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/ThrowStatement.js b/src/slang-nodes/ThrowStatement.js index 08940070f..2bc2c38bb 100644 --- a/src/slang-nodes/ThrowStatement.js +++ b/src/slang-nodes/ThrowStatement.js @@ -8,11 +8,10 @@ export class ThrowStatement extends SlangNode { constructor(ast, offset, comments) { super(); - const fetch = () => { - const { throwKeyword, semicolon } = ast; - this.throwKeyword = throwKeyword.text; - this.semicolon = semicolon.text; - }; + const fetch = () => ({ + throwKeyword: ast.throwKeyword.text, + semicolon: ast.semicolon.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/TryStatement.js b/src/slang-nodes/TryStatement.js index b0cac937c..2321c50eb 100644 --- a/src/slang-nodes/TryStatement.js +++ b/src/slang-nodes/TryStatement.js @@ -22,31 +22,30 @@ export class TryStatement extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { tryKeyword, expression, returns, body, catchClauses } = ast; - this.tryKeyword = tryKeyword.text; - this.expression = new Expression( - expression, + const fetch = (childrenOffsets) => ({ + tryKeyword: ast.tryKeyword.text, + expression: new Expression( + ast.expression, childrenOffsets.shift(), comments, options - ); - if (returns) { - this.returns = new ReturnsDeclaration( - returns, - childrenOffsets.shift(), - comments, - options - ); - } - this.body = new Block(body, childrenOffsets.shift(), comments, options); - this.catchClauses = new CatchClauses( - catchClauses, + ), + returns: ast.returns + ? new ReturnsDeclaration( + ast.returns, + childrenOffsets.shift(), + comments, + options + ) + : undefined, + body: new Block(ast.body, childrenOffsets.shift(), comments, options), + catchClauses: new CatchClauses( + ast.catchClauses, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/TupleDeconstructionElement.js b/src/slang-nodes/TupleDeconstructionElement.js index bb2ba178f..acc030793 100644 --- a/src/slang-nodes/TupleDeconstructionElement.js +++ b/src/slang-nodes/TupleDeconstructionElement.js @@ -7,17 +7,16 @@ export class TupleDeconstructionElement extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { member } = ast; - if (member) { - this.member = new TupleMember( - member, - childrenOffsets.shift(), - comments, - options - ); - } - }; + const fetch = (childrenOffsets) => ({ + member: ast.member + ? new TupleMember( + ast.member, + childrenOffsets.shift(), + comments, + options + ) + : undefined + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/TupleDeconstructionElements.js b/src/slang-nodes/TupleDeconstructionElements.js index d329f1a0d..1fc5f63f2 100644 --- a/src/slang-nodes/TupleDeconstructionElements.js +++ b/src/slang-nodes/TupleDeconstructionElements.js @@ -10,9 +10,8 @@ export class TupleDeconstructionElements extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { items, separators } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new TupleDeconstructionElement( item, @@ -20,9 +19,9 @@ export class TupleDeconstructionElements extends SlangNode { comments, options ) - ); - this.separators = separators.map((separator) => separator.text); - }; + ), + separators: ast.separators.map((separator) => separator.text) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/TupleDeconstructionStatement.js b/src/slang-nodes/TupleDeconstructionStatement.js index 5075f782b..78c72691b 100644 --- a/src/slang-nodes/TupleDeconstructionStatement.js +++ b/src/slang-nodes/TupleDeconstructionStatement.js @@ -23,34 +23,25 @@ export class TupleDeconstructionStatement extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { - varKeyword, - openParen, - elements, - closeParen, - equal, - expression, - semicolon - } = ast; - this.varKeyword = varKeyword?.text; - this.openParen = openParen.text; - this.elements = new TupleDeconstructionElements( - elements, + const fetch = (childrenOffsets) => ({ + varKeyword: ast.varKeyword?.text, + openParen: ast.openParen.text, + elements: new TupleDeconstructionElements( + ast.elements, childrenOffsets.shift(), comments, options - ); - this.closeParen = closeParen.text; - this.equal = equal.text; - this.expression = new Expression( - expression, + ), + closeParen: ast.closeParen.text, + equal: ast.equal.text, + expression: new Expression( + ast.expression, childrenOffsets.shift(), comments, options - ); - this.semicolon = semicolon.text; - }; + ), + semicolon: ast.semicolon.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/TupleExpression.js b/src/slang-nodes/TupleExpression.js index 907d49f2e..7235cad75 100644 --- a/src/slang-nodes/TupleExpression.js +++ b/src/slang-nodes/TupleExpression.js @@ -11,17 +11,16 @@ export class TupleExpression extends SlangNode { constructor(ast, offset, comments, options) { super(); if (offset) { - const fetch = (childrenOffsets) => { - const { openParen, items, closeParen } = ast; - this.openParen = openParen.text; - this.items = new TupleValues( - items, + const fetch = (childrenOffsets) => ({ + openParen: ast.openParen.text, + items: new TupleValues( + ast.items, childrenOffsets.shift(), comments, options - ); - this.closeParen = closeParen.text; - }; + ), + closeParen: ast.closeParen.text + }); this.initialize(ast, offset, fetch, comments); } else { diff --git a/src/slang-nodes/TupleMember.js b/src/slang-nodes/TupleMember.js index 1e5f6bebe..3e00e7d14 100644 --- a/src/slang-nodes/TupleMember.js +++ b/src/slang-nodes/TupleMember.js @@ -10,15 +10,14 @@ export class TupleMember extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { variant } = ast; - this.variant = new variants[variant.cst.kind]( - variant, + const fetch = (childrenOffsets) => ({ + variant: new variants[ast.variant.cst.kind]( + ast.variant, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/TupleValue.js b/src/slang-nodes/TupleValue.js index d21f7e811..73a5cd47e 100644 --- a/src/slang-nodes/TupleValue.js +++ b/src/slang-nodes/TupleValue.js @@ -7,17 +7,16 @@ export class TupleValue extends SlangNode { constructor(ast, offset, comments, options) { super(); if (offset) { - const fetch = (childrenOffsets) => { - const { expression } = ast; - if (expression) { - this.expression = new Expression( - expression, - childrenOffsets.shift(), - comments, - options - ); - } - }; + const fetch = (childrenOffsets) => ({ + expression: ast.expression + ? new Expression( + ast.expression, + childrenOffsets.shift(), + comments, + options + ) + : undefined + }); this.initialize(ast, offset, fetch, comments); } else { diff --git a/src/slang-nodes/TupleValues.js b/src/slang-nodes/TupleValues.js index 1897095d9..4258f6024 100644 --- a/src/slang-nodes/TupleValues.js +++ b/src/slang-nodes/TupleValues.js @@ -11,14 +11,13 @@ export class TupleValues extends SlangNode { constructor(ast, offset, comments, options) { super(); if (offset) { - const fetch = (childrenOffsets) => { - const { items, separators } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new TupleValue(item, childrenOffsets.shift(), comments, options) - ); - this.separators = separators.map((separator) => separator.text); - }; + ), + separators: ast.separators.map((separator) => separator.text) + }); this.initialize(ast, offset, fetch, comments); } else { diff --git a/src/slang-nodes/TypeExpression.js b/src/slang-nodes/TypeExpression.js index b9084e5ef..b0ca29497 100644 --- a/src/slang-nodes/TypeExpression.js +++ b/src/slang-nodes/TypeExpression.js @@ -13,18 +13,17 @@ export class TypeExpression extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { typeKeyword, openParen, typeName, closeParen } = ast; - this.typeKeyword = typeKeyword.text; - this.openParen = openParen.text; - this.typeName = new TypeName( - typeName, + const fetch = (childrenOffsets) => ({ + typeKeyword: ast.typeKeyword.text, + openParen: ast.openParen.text, + typeName: new TypeName( + ast.typeName, childrenOffsets.shift(), comments, options - ); - this.closeParen = closeParen.text; - }; + ), + closeParen: ast.closeParen.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/TypeName.js b/src/slang-nodes/TypeName.js index 5289b7803..94171b6a3 100644 --- a/src/slang-nodes/TypeName.js +++ b/src/slang-nodes/TypeName.js @@ -18,15 +18,14 @@ export class TypeName extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { variant } = ast; - this.variant = new variants[variant.cst.kind]( - variant, + const fetch = (childrenOffsets) => ({ + variant: new variants[ast.variant.cst.kind]( + ast.variant, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/TypedTupleMember.js b/src/slang-nodes/TypedTupleMember.js index 66e2c7db3..787c9fb2e 100644 --- a/src/slang-nodes/TypedTupleMember.js +++ b/src/slang-nodes/TypedTupleMember.js @@ -12,24 +12,23 @@ export class TypedTupleMember extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { typeName, storageLocation, name } = ast; - this.typeName = new TypeName( - typeName, + const fetch = (childrenOffsets) => ({ + typeName: new TypeName( + ast.typeName, childrenOffsets.shift(), comments, options - ); - if (storageLocation) { - this.storageLocation = new StorageLocation( - storageLocation, - childrenOffsets.shift(), - comments, - options - ); - } - this.name = name.text; - }; + ), + storageLocation: ast.storageLocation + ? new StorageLocation( + ast.storageLocation, + childrenOffsets.shift(), + comments, + options + ) + : undefined, + name: ast.name.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/UncheckedBlock.js b/src/slang-nodes/UncheckedBlock.js index 01752bab3..dbd24c0f8 100644 --- a/src/slang-nodes/UncheckedBlock.js +++ b/src/slang-nodes/UncheckedBlock.js @@ -9,11 +9,10 @@ export class UncheckedBlock extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { uncheckedKeyword, block } = ast; - this.uncheckedKeyword = uncheckedKeyword.text; - this.block = new Block(block, childrenOffsets.shift(), comments, options); - }; + const fetch = (childrenOffsets) => ({ + uncheckedKeyword: ast.uncheckedKeyword.text, + block: new Block(ast.block, childrenOffsets.shift(), comments, options) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/UnicodeStringLiteral.js b/src/slang-nodes/UnicodeStringLiteral.js index f2475b8a5..805bda477 100644 --- a/src/slang-nodes/UnicodeStringLiteral.js +++ b/src/slang-nodes/UnicodeStringLiteral.js @@ -7,10 +7,9 @@ export class UnicodeStringLiteral extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = () => { - const { variant } = ast; - this.variant = variant.text; - }; + const fetch = () => ({ + variant: ast.variant.text + }); this.initialize(ast, offset, fetch, comments); diff --git a/src/slang-nodes/UnicodeStringLiterals.js b/src/slang-nodes/UnicodeStringLiterals.js index defececf5..88224653d 100644 --- a/src/slang-nodes/UnicodeStringLiterals.js +++ b/src/slang-nodes/UnicodeStringLiterals.js @@ -10,9 +10,8 @@ export class UnicodeStringLiterals extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { items } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new UnicodeStringLiteral( item, @@ -20,8 +19,8 @@ export class UnicodeStringLiterals extends SlangNode { comments, options ) - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/UnnamedFunctionAttribute.js b/src/slang-nodes/UnnamedFunctionAttribute.js index 6cd5c0c5d..b03f7d97e 100644 --- a/src/slang-nodes/UnnamedFunctionAttribute.js +++ b/src/slang-nodes/UnnamedFunctionAttribute.js @@ -7,18 +7,17 @@ export class UnnamedFunctionAttribute extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { variant } = ast; - this.variant = - variant.type === 'Terminal' - ? variant.text + const fetch = (childrenOffsets) => ({ + variant: + ast.variant.type === 'Terminal' + ? ast.variant.text : new ModifierInvocation( - variant, + ast.variant, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/UnnamedFunctionAttributes.js b/src/slang-nodes/UnnamedFunctionAttributes.js index 7f19e08d2..add642cb5 100644 --- a/src/slang-nodes/UnnamedFunctionAttributes.js +++ b/src/slang-nodes/UnnamedFunctionAttributes.js @@ -11,9 +11,8 @@ export class UnnamedFunctionAttributes extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { items } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new UnnamedFunctionAttribute( item, @@ -21,8 +20,8 @@ export class UnnamedFunctionAttributes extends SlangNode { comments, options ) - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); diff --git a/src/slang-nodes/UnnamedFunctionDefinition.js b/src/slang-nodes/UnnamedFunctionDefinition.js index 96910b015..f27ed185c 100644 --- a/src/slang-nodes/UnnamedFunctionDefinition.js +++ b/src/slang-nodes/UnnamedFunctionDefinition.js @@ -16,28 +16,27 @@ export class UnnamedFunctionDefinition extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { functionKeyword, parameters, attributes, body } = ast; - this.functionKeyword = functionKeyword.text; - this.parameters = new ParametersDeclaration( - parameters, + const fetch = (childrenOffsets) => ({ + functionKeyword: ast.functionKeyword.text, + parameters: new ParametersDeclaration( + ast.parameters, childrenOffsets.shift(), comments, options - ); - this.attributes = new UnnamedFunctionAttributes( - attributes, + ), + attributes: new UnnamedFunctionAttributes( + ast.attributes, childrenOffsets.shift(), comments, options - ); - this.body = new FunctionBody( - body, + ), + body: new FunctionBody( + ast.body, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); diff --git a/src/slang-nodes/UntypedTupleMember.js b/src/slang-nodes/UntypedTupleMember.js index a8e6917da..ef13cb927 100644 --- a/src/slang-nodes/UntypedTupleMember.js +++ b/src/slang-nodes/UntypedTupleMember.js @@ -9,19 +9,17 @@ export class UntypedTupleMember extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { storageLocation, name } = ast; - - if (storageLocation) { - this.storageLocation = new StorageLocation( - storageLocation, - childrenOffsets.shift(), - comments, - options - ); - } - this.name = name.text; - }; + const fetch = (childrenOffsets) => ({ + storageLocation: ast.storageLocation + ? new StorageLocation( + ast.storageLocation, + childrenOffsets.shift(), + comments, + options + ) + : undefined, + name: ast.name.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/UserDefinedValueTypeDefinition.js b/src/slang-nodes/UserDefinedValueTypeDefinition.js index dc2654a19..94728b7d9 100644 --- a/src/slang-nodes/UserDefinedValueTypeDefinition.js +++ b/src/slang-nodes/UserDefinedValueTypeDefinition.js @@ -15,19 +15,18 @@ export class UserDefinedValueTypeDefinition extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { typeKeyword, name, isKeyword, valueType, semicolon } = ast; - this.typeKeyword = typeKeyword.text; - this.name = name.text; - this.isKeyword = isKeyword.text; - this.valueType = new ElementaryType( - valueType, + const fetch = (childrenOffsets) => ({ + typeKeyword: ast.typeKeyword.text, + name: ast.name.text, + isKeyword: ast.isKeyword.text, + valueType: new ElementaryType( + ast.valueType, childrenOffsets.shift(), comments, options - ); - this.semicolon = semicolon.text; - }; + ), + semicolon: ast.semicolon.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/UsingAlias.js b/src/slang-nodes/UsingAlias.js index 0ae0004b3..70efc19aa 100644 --- a/src/slang-nodes/UsingAlias.js +++ b/src/slang-nodes/UsingAlias.js @@ -9,16 +9,15 @@ export class UsingAlias extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { asKeyword, operator } = ast; - this.asKeyword = asKeyword.text; - this.operator = new UsingOperator( - operator, + const fetch = (childrenOffsets) => ({ + asKeyword: ast.asKeyword.text, + operator: new UsingOperator( + ast.operator, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/UsingClause.js b/src/slang-nodes/UsingClause.js index 61b4194ea..c36efc18e 100644 --- a/src/slang-nodes/UsingClause.js +++ b/src/slang-nodes/UsingClause.js @@ -10,15 +10,14 @@ export class UsingClause extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { variant } = ast; - this.variant = new variants[variant.cst.kind]( - variant, + const fetch = (childrenOffsets) => ({ + variant: new variants[ast.variant.cst.kind]( + ast.variant, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/UsingDeconstruction.js b/src/slang-nodes/UsingDeconstruction.js index 034b101cc..48c6618b6 100644 --- a/src/slang-nodes/UsingDeconstruction.js +++ b/src/slang-nodes/UsingDeconstruction.js @@ -11,17 +11,16 @@ export class UsingDeconstruction extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { openBrace, symbols, closeBrace } = ast; - this.openBrace = openBrace.text; - this.symbols = new UsingDeconstructionSymbols( - symbols, + const fetch = (childrenOffsets) => ({ + openBrace: ast.openBrace.text, + symbols: new UsingDeconstructionSymbols( + ast.symbols, childrenOffsets.shift(), comments, options - ); - this.closeBrace = closeBrace.text; - }; + ), + closeBrace: ast.closeBrace.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/UsingDeconstructionSymbol.js b/src/slang-nodes/UsingDeconstructionSymbol.js index 013537a5c..7149d0628 100644 --- a/src/slang-nodes/UsingDeconstructionSymbol.js +++ b/src/slang-nodes/UsingDeconstructionSymbol.js @@ -10,23 +10,17 @@ export class UsingDeconstructionSymbol extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { name, alias } = ast; - this.name = new IdentifierPath( - name, + const fetch = (childrenOffsets) => ({ + name: new IdentifierPath( + ast.name, childrenOffsets.shift(), comments, options - ); - if (alias) { - this.alias = new UsingAlias( - alias, - childrenOffsets.shift(), - comments, - options - ); - } - }; + ), + alias: ast.alias + ? new UsingAlias(ast.alias, childrenOffsets.shift(), comments, options) + : undefined + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/UsingDeconstructionSymbols.js b/src/slang-nodes/UsingDeconstructionSymbols.js index 602e976ae..3e23d813c 100644 --- a/src/slang-nodes/UsingDeconstructionSymbols.js +++ b/src/slang-nodes/UsingDeconstructionSymbols.js @@ -13,9 +13,8 @@ export class UsingDeconstructionSymbols extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { items, separators } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new UsingDeconstructionSymbol( item, @@ -23,9 +22,9 @@ export class UsingDeconstructionSymbols extends SlangNode { comments, options ) - ); - this.separators = separators.map((separator) => separator.text); - }; + ), + separators: ast.separators.map((separator) => separator.text) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/UsingDirective.js b/src/slang-nodes/UsingDirective.js index dd7e0a67b..a394fe75d 100644 --- a/src/slang-nodes/UsingDirective.js +++ b/src/slang-nodes/UsingDirective.js @@ -18,32 +18,24 @@ export class UsingDirective extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { - usingKeyword, - clause, - forKeyword, - target, - globalKeyword, - semicolon - } = ast; - this.usingKeyword = usingKeyword.text; - this.clause = new UsingClause( - clause, + const fetch = (childrenOffsets) => ({ + usingKeyword: ast.usingKeyword.text, + clause: new UsingClause( + ast.clause, childrenOffsets.shift(), comments, options - ); - this.forKeyword = forKeyword.text; - this.target = new UsingTarget( - target, + ), + forKeyword: ast.forKeyword.text, + target: new UsingTarget( + ast.target, childrenOffsets.shift(), comments, options - ); - this.globalKeyword = globalKeyword?.text; - this.semicolon = semicolon.text; - }; + ), + globalKeyword: ast.globalKeyword?.text, + semicolon: ast.semicolon.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/UsingOperator.js b/src/slang-nodes/UsingOperator.js index 44f5f68a8..7dae62ae4 100644 --- a/src/slang-nodes/UsingOperator.js +++ b/src/slang-nodes/UsingOperator.js @@ -6,10 +6,9 @@ export class UsingOperator extends SlangNode { constructor(ast, offset, comments) { super(); - const fetch = () => { - const { variant } = ast; - this.variant = variant.text; - }; + const fetch = () => ({ + variant: ast.variant.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/UsingTarget.js b/src/slang-nodes/UsingTarget.js index 5381113b5..f01fcfeaa 100644 --- a/src/slang-nodes/UsingTarget.js +++ b/src/slang-nodes/UsingTarget.js @@ -7,13 +7,17 @@ export class UsingTarget extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { variant } = ast; - this.variant = - variant.type === 'Terminal' - ? variant.text - : new TypeName(variant, childrenOffsets.shift(), comments, options); - }; + const fetch = (childrenOffsets) => ({ + variant: + ast.variant.type === 'Terminal' + ? ast.variant.text + : new TypeName( + ast.variant, + childrenOffsets.shift(), + comments, + options + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/VariableDeclarationStatement.js b/src/slang-nodes/VariableDeclarationStatement.js index c04d9fc21..05974c764 100644 --- a/src/slang-nodes/VariableDeclarationStatement.js +++ b/src/slang-nodes/VariableDeclarationStatement.js @@ -20,33 +20,32 @@ export class VariableDeclarationStatement extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { variableType, storageLocation, name, value, semicolon } = ast; - this.variableType = new VariableDeclarationType( - variableType, + const fetch = (childrenOffsets) => ({ + variableType: new VariableDeclarationType( + ast.variableType, childrenOffsets.shift(), comments, options - ); - if (storageLocation) { - this.storageLocation = new StorageLocation( - storageLocation, - childrenOffsets.shift(), - comments, - options - ); - } - this.name = name.text; - if (value) { - this.value = new VariableDeclarationValue( - value, - childrenOffsets.shift(), - comments, - options - ); - } - this.semicolon = semicolon.text; - }; + ), + storageLocation: ast.storageLocation + ? new StorageLocation( + ast.storageLocation, + childrenOffsets.shift(), + comments, + options + ) + : undefined, + name: ast.name.text, + value: ast.value + ? new VariableDeclarationValue( + ast.value, + childrenOffsets.shift(), + comments, + options + ) + : undefined, + semicolon: ast.semicolon.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/VariableDeclarationType.js b/src/slang-nodes/VariableDeclarationType.js index 637d91e91..1601f54e7 100644 --- a/src/slang-nodes/VariableDeclarationType.js +++ b/src/slang-nodes/VariableDeclarationType.js @@ -7,13 +7,17 @@ export class VariableDeclarationType extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { variant } = ast; - this.variant = - variant.type === 'Terminal' - ? variant.type - : new TypeName(variant, childrenOffsets.shift(), comments, options); - }; + const fetch = (childrenOffsets) => ({ + variant: + ast.variant.type === 'Terminal' + ? ast.variant.type + : new TypeName( + ast.variant, + childrenOffsets.shift(), + comments, + options + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/VariableDeclarationValue.js b/src/slang-nodes/VariableDeclarationValue.js index 327cd65af..7cd8e1c0e 100644 --- a/src/slang-nodes/VariableDeclarationValue.js +++ b/src/slang-nodes/VariableDeclarationValue.js @@ -9,16 +9,15 @@ export class VariableDeclarationValue extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { equal, expression } = ast; - this.equal = equal.text; - this.expression = new Expression( - expression, + const fetch = (childrenOffsets) => ({ + equal: ast.equal.text, + expression: new Expression( + ast.expression, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/VersionComparator.js b/src/slang-nodes/VersionComparator.js index b80af22f8..b20957361 100644 --- a/src/slang-nodes/VersionComparator.js +++ b/src/slang-nodes/VersionComparator.js @@ -8,16 +8,15 @@ export class VersionComparator extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { operator, operand } = ast; - this.operator = operator.text; - this.operand = new VersionExpression( - operand, + const fetch = (childrenOffsets) => ({ + operator: ast.operator.text, + operand: new VersionExpression( + ast.operand, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/VersionExpression.js b/src/slang-nodes/VersionExpression.js index fa1a25cde..65b46b746 100644 --- a/src/slang-nodes/VersionExpression.js +++ b/src/slang-nodes/VersionExpression.js @@ -15,18 +15,17 @@ export class VersionExpression extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { variant } = ast; - this.variant = - variant.type === 'Terminal' - ? variant.text - : new variants[variant.cst.kind]( - variant, + const fetch = (childrenOffsets) => ({ + variant: + ast.variant.type === 'Terminal' + ? ast.variant.text + : new variants[ast.variant.cst.kind]( + ast.variant, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/VersionExpressionSet.js b/src/slang-nodes/VersionExpressionSet.js index d50ef36a5..9c81b422f 100644 --- a/src/slang-nodes/VersionExpressionSet.js +++ b/src/slang-nodes/VersionExpressionSet.js @@ -10,9 +10,8 @@ export class VersionExpressionSet extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { items } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new VersionExpression( item, @@ -20,8 +19,8 @@ export class VersionExpressionSet extends SlangNode { comments, options ) - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/VersionExpressionSets.js b/src/slang-nodes/VersionExpressionSets.js index a492568ff..e6bcb3202 100644 --- a/src/slang-nodes/VersionExpressionSets.js +++ b/src/slang-nodes/VersionExpressionSets.js @@ -9,9 +9,8 @@ export class VersionExpressionSets extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { items, separators } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new VersionExpressionSet( item, @@ -19,9 +18,9 @@ export class VersionExpressionSets extends SlangNode { comments, options ) - ); - this.separators = separators.map((separator) => separator.text); - }; + ), + separators: ast.separators.map((separator) => separator.text) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/VersionPragma.js b/src/slang-nodes/VersionPragma.js index cbeb98490..bf2d9c226 100644 --- a/src/slang-nodes/VersionPragma.js +++ b/src/slang-nodes/VersionPragma.js @@ -9,16 +9,15 @@ export class VersionPragma extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { solidityKeyword, sets } = ast; - this.solidityKeyword = solidityKeyword.text; - this.sets = new VersionExpressionSets( - sets, + const fetch = (childrenOffsets) => ({ + solidityKeyword: ast.solidityKeyword.text, + sets: new VersionExpressionSets( + ast.sets, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/VersionRange.js b/src/slang-nodes/VersionRange.js index a3af3fb22..d31db446c 100644 --- a/src/slang-nodes/VersionRange.js +++ b/src/slang-nodes/VersionRange.js @@ -11,22 +11,21 @@ export class VersionRange extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { leftOperand, operator, rightOperand } = ast; - this.leftOperand = new VersionExpression( - leftOperand, + const fetch = (childrenOffsets) => ({ + leftOperand: new VersionExpression( + ast.leftOperand, childrenOffsets.shift(), comments, options - ); - this.operator = operator.text; - this.rightOperand = new VersionExpression( - rightOperand, + ), + operator: ast.operator.text, + rightOperand: new VersionExpression( + ast.rightOperand, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/VersionSpecifiers.js b/src/slang-nodes/VersionSpecifiers.js index a1f7eb81b..4e37a1a83 100644 --- a/src/slang-nodes/VersionSpecifiers.js +++ b/src/slang-nodes/VersionSpecifiers.js @@ -8,11 +8,10 @@ export class VersionSpecifiers extends SlangNode { constructor(ast, offset, comments) { super(); - const fetch = () => { - const { items, separators } = ast; - this.items = items.map((item) => item.text); - this.separators = separators.map((separator) => separator.text); - }; + const fetch = () => ({ + items: ast.items.map((item) => item.text), + separators: ast.separators.map((separator) => separator.text) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/WhileStatement.js b/src/slang-nodes/WhileStatement.js index ee4a4daba..fc2f385d2 100644 --- a/src/slang-nodes/WhileStatement.js +++ b/src/slang-nodes/WhileStatement.js @@ -20,24 +20,18 @@ export class WhileStatement extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { whileKeyword, openParen, condition, closeParen, body } = ast; - this.whileKeyword = whileKeyword.text; - this.openParen = openParen.text; - this.condition = new Expression( - condition, + const fetch = (childrenOffsets) => ({ + whileKeyword: ast.whileKeyword.text, + openParen: ast.openParen.text, + condition: new Expression( + ast.condition, childrenOffsets.shift(), comments, options - ); - this.closeParen = closeParen.text; - this.body = new Statement( - body, - childrenOffsets.shift(), - comments, - options - ); - }; + ), + closeParen: ast.closeParen.text, + body: new Statement(ast.body, childrenOffsets.shift(), comments, options) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/YulArguments.js b/src/slang-nodes/YulArguments.js index 60d79936e..bce4daa01 100644 --- a/src/slang-nodes/YulArguments.js +++ b/src/slang-nodes/YulArguments.js @@ -10,14 +10,13 @@ export class YulArguments extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { items, separators } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new YulExpression(item, childrenOffsets.shift(), comments, options) - ); - this.separators = separators.map((separator) => separator.text); - }; + ), + separators: ast.separators.map((separator) => separator.text) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/YulAssignmentOperator.js b/src/slang-nodes/YulAssignmentOperator.js index a38d2798f..bda7c4b5d 100644 --- a/src/slang-nodes/YulAssignmentOperator.js +++ b/src/slang-nodes/YulAssignmentOperator.js @@ -7,18 +7,17 @@ export class YulAssignmentOperator extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { variant } = ast; - this.variant = - variant.type === 'Terminal' - ? variant.text + const fetch = (childrenOffsets) => ({ + variant: + ast.variant.type === 'Terminal' + ? ast.variant.text : new YulColonEqual( - variant, + ast.variant, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/YulBlock.js b/src/slang-nodes/YulBlock.js index 695ab12b5..da922c2bb 100644 --- a/src/slang-nodes/YulBlock.js +++ b/src/slang-nodes/YulBlock.js @@ -11,17 +11,16 @@ export class YulBlock extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { openBrace, statements, closeBrace } = ast; - this.openBrace = openBrace.text; - this.statements = new YulStatements( - statements, + const fetch = (childrenOffsets) => ({ + openBrace: ast.openBrace.text, + statements: new YulStatements( + ast.statements, childrenOffsets.shift(), comments, options - ); - this.closeBrace = closeBrace.text; - }; + ), + closeBrace: ast.closeBrace.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/YulBreakStatement.js b/src/slang-nodes/YulBreakStatement.js index b6c00f2f9..1299e8a80 100644 --- a/src/slang-nodes/YulBreakStatement.js +++ b/src/slang-nodes/YulBreakStatement.js @@ -6,10 +6,9 @@ export class YulBreakStatement extends SlangNode { constructor(ast, offset, comments) { super(); - const fetch = () => { - const { breakKeyword } = ast; - this.breakKeyword = breakKeyword.text; - }; + const fetch = () => ({ + breakKeyword: ast.breakKeyword.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/YulBuiltInFunction.js b/src/slang-nodes/YulBuiltInFunction.js index a52ddebae..e6c45cfc1 100644 --- a/src/slang-nodes/YulBuiltInFunction.js +++ b/src/slang-nodes/YulBuiltInFunction.js @@ -6,10 +6,9 @@ export class YulBuiltInFunction extends SlangNode { constructor(ast, offset, comments) { super(); - const fetch = () => { - const { variant } = ast; - this.variant = variant.text; - }; + const fetch = () => ({ + variant: ast.variant.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/YulColonEqual.js b/src/slang-nodes/YulColonEqual.js index e05ba07e5..cb8b0f9a0 100644 --- a/src/slang-nodes/YulColonEqual.js +++ b/src/slang-nodes/YulColonEqual.js @@ -8,11 +8,10 @@ export class YulColonEqual extends SlangNode { constructor(ast, offset, comments) { super(); - const fetch = () => { - const { colon, equal } = ast; - this.colon = colon.text; - this.equal = equal.text; - }; + const fetch = () => ({ + colon: ast.colon.text, + equal: ast.equal.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/YulContinueStatement.js b/src/slang-nodes/YulContinueStatement.js index 421313f80..af040d583 100644 --- a/src/slang-nodes/YulContinueStatement.js +++ b/src/slang-nodes/YulContinueStatement.js @@ -6,10 +6,9 @@ export class YulContinueStatement extends SlangNode { constructor(ast, offset, comments) { super(); - const fetch = () => { - const { continueKeyword } = ast; - this.continueKeyword = continueKeyword.text; - }; + const fetch = () => ({ + continueKeyword: ast.continueKeyword.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/YulDefaultCase.js b/src/slang-nodes/YulDefaultCase.js index e5b95b056..d93b18cb9 100644 --- a/src/slang-nodes/YulDefaultCase.js +++ b/src/slang-nodes/YulDefaultCase.js @@ -9,16 +9,10 @@ export class YulDefaultCase extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { defaultKeyword, body } = ast; - this.defaultKeyword = defaultKeyword.text; - this.body = new YulBlock( - body, - childrenOffsets.shift(), - comments, - options - ); - }; + const fetch = (childrenOffsets) => ({ + defaultKeyword: ast.defaultKeyword.text, + body: new YulBlock(ast.body, childrenOffsets.shift(), comments, options) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/YulExpression.js b/src/slang-nodes/YulExpression.js index 27d96860b..13020a599 100644 --- a/src/slang-nodes/YulExpression.js +++ b/src/slang-nodes/YulExpression.js @@ -17,15 +17,14 @@ export class YulExpression extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { variant } = ast; - this.variant = new variants[variant.cst.kind]( - variant, + const fetch = (childrenOffsets) => ({ + variant: new variants[ast.variant.cst.kind]( + ast.variant, childrenOffsets.shift(), comments, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/YulForStatement.js b/src/slang-nodes/YulForStatement.js index 1b1748b5f..c2770ca00 100644 --- a/src/slang-nodes/YulForStatement.js +++ b/src/slang-nodes/YulForStatement.js @@ -16,34 +16,28 @@ export class YulForStatement extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { forKeyword, initialization, condition, iterator, body } = ast; - this.forKeyword = forKeyword.text; - this.initialization = new YulBlock( - initialization, + const fetch = (childrenOffsets) => ({ + forKeyword: ast.forKeyword.text, + initialization: new YulBlock( + ast.initialization, childrenOffsets.shift(), comments, options - ); - this.condition = new YulExpression( - condition, + ), + condition: new YulExpression( + ast.condition, childrenOffsets.shift(), comments, options - ); - this.iterator = new YulBlock( - iterator, + ), + iterator: new YulBlock( + ast.iterator, childrenOffsets.shift(), comments, options - ); - this.body = new YulBlock( - body, - childrenOffsets.shift(), - comments, - options - ); - }; + ), + body: new YulBlock(ast.body, childrenOffsets.shift(), comments, options) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/YulFunctionCallExpression.js b/src/slang-nodes/YulFunctionCallExpression.js index ad9fe3385..75c7f4c6b 100644 --- a/src/slang-nodes/YulFunctionCallExpression.js +++ b/src/slang-nodes/YulFunctionCallExpression.js @@ -14,23 +14,22 @@ export class YulFunctionCallExpression extends SlangNode { constructor(ast, offset, comments, options) { super(); - const fetch = (childrenOffsets) => { - const { operand, openParen, closeParen } = ast; - this.operand = new YulExpression( - operand, + const fetch = (childrenOffsets) => ({ + operand: new YulExpression( + ast.operand, childrenOffsets.shift(), comments, options - ); - this.openParen = openParen.text; - this.arguments = new YulArguments( + ), + openParen: ast.openParen.text, + arguments: new YulArguments( ast.arguments, childrenOffsets.shift(), comments, options - ); - this.closeParen = closeParen.text; - }; + ), + closeParen: ast.closeParen.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/YulFunctionDefinition.js b/src/slang-nodes/YulFunctionDefinition.js index 4c70f0d63..f05a31034 100644 --- a/src/slang-nodes/YulFunctionDefinition.js +++ b/src/slang-nodes/YulFunctionDefinition.js @@ -17,34 +17,33 @@ export class YulFunctionDefinition extends SlangNode { constructor(ast, offset, comments, parse, options) { super(); - const fetch = (childrenOffsets) => { - const { functionKeyword, name, parameters, returns, body } = ast; - this.functionKeyword = functionKeyword.text; - this.name = name.text; - this.parameters = new YulParametersDeclaration( - parameters, + const fetch = (childrenOffsets) => ({ + functionKeyword: ast.functionKeyword.text, + name: ast.name.text, + parameters: new YulParametersDeclaration( + ast.parameters, childrenOffsets.shift(), comments, parse, options - ); - if (returns) { - this.returns = new YulReturnsDeclaration( - returns, - childrenOffsets.shift(), - comments, - parse, - options - ); - } - this.body = new YulBlock( - body, + ), + returns: ast.returns + ? new YulReturnsDeclaration( + ast.returns, + childrenOffsets.shift(), + comments, + parse, + options + ) + : undefined, + body: new YulBlock( + ast.body, childrenOffsets.shift(), comments, parse, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/YulIfStatement.js b/src/slang-nodes/YulIfStatement.js index 0e08895c1..49465b6f1 100644 --- a/src/slang-nodes/YulIfStatement.js +++ b/src/slang-nodes/YulIfStatement.js @@ -12,24 +12,23 @@ export class YulIfStatement extends SlangNode { constructor(ast, offset, comments, parse, options) { super(); - const fetch = (childrenOffsets) => { - const { ifKeyword, condition, body } = ast; - this.ifKeyword = ifKeyword.text; - this.condition = new YulExpression( - condition, + const fetch = (childrenOffsets) => ({ + ifKeyword: ast.ifKeyword.text, + condition: new YulExpression( + ast.condition, childrenOffsets.shift(), comments, parse, options - ); - this.body = new YulBlock( - body, + ), + body: new YulBlock( + ast.body, childrenOffsets.shift(), comments, parse, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/YulLabel.js b/src/slang-nodes/YulLabel.js index 486214ca8..a36fa7076 100644 --- a/src/slang-nodes/YulLabel.js +++ b/src/slang-nodes/YulLabel.js @@ -8,14 +8,13 @@ export class YulLabel extends SlangNode { colon; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments) { super(); - const fetch = () => { - const { label, colon } = ast; - this.label = label.text; - this.colon = colon.text; - }; + const fetch = () => ({ + label: ast.label.text, + colon: ast.colon.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/YulLeaveStatement.js b/src/slang-nodes/YulLeaveStatement.js index aacec23aa..be7f39d64 100644 --- a/src/slang-nodes/YulLeaveStatement.js +++ b/src/slang-nodes/YulLeaveStatement.js @@ -3,13 +3,12 @@ import { SlangNode } from './SlangNode.js'; export class YulLeaveStatement extends SlangNode { leaveKeyword; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments) { super(); - const fetch = () => { - const { leaveKeyword } = ast; - this.leaveKeyword = leaveKeyword.text; - }; + const fetch = () => ({ + leaveKeyword: ast.leaveKeyword.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/YulLiteral.js b/src/slang-nodes/YulLiteral.js index 1b83f6563..ab20b0ab3 100644 --- a/src/slang-nodes/YulLiteral.js +++ b/src/slang-nodes/YulLiteral.js @@ -10,19 +10,18 @@ export class YulLiteral extends SlangNode { constructor(ast, offset, comments, parse, options) { super(); - const fetch = (childrenOffsets) => { - const { variant } = ast; - this.variant = - variant.type === 'Terminal' - ? variant.text - : new variants[variant.cst.kind]( - variant, + const fetch = (childrenOffsets) => ({ + variant: + ast.variant.type === 'Terminal' + ? ast.variant.text + : new variants[ast.variant.cst.kind]( + ast.variant, childrenOffsets.shift(), comments, parse, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/YulParameters.js b/src/slang-nodes/YulParameters.js index d6040a88a..1200f80ea 100644 --- a/src/slang-nodes/YulParameters.js +++ b/src/slang-nodes/YulParameters.js @@ -6,14 +6,13 @@ export class YulParameters extends SlangNode { separators; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments) { super(); - const fetch = () => { - const { items, separators } = ast; - this.items = items.map((item) => item.text); - this.separators = separators.map((separator) => separator.text); - }; + const fetch = () => ({ + items: ast.items.map((item) => item.text), + separators: ast.separators.map((separator) => separator.text) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/YulParametersDeclaration.js b/src/slang-nodes/YulParametersDeclaration.js index 11f259fe9..2e1590570 100644 --- a/src/slang-nodes/YulParametersDeclaration.js +++ b/src/slang-nodes/YulParametersDeclaration.js @@ -11,18 +11,17 @@ export class YulParametersDeclaration extends SlangNode { constructor(ast, offset, comments, parse, options) { super(); - const fetch = (childrenOffsets) => { - const { openParen, parameters, closeParen } = ast; - this.openParen = openParen.text; - this.parameters = new YulParameters( - parameters, + const fetch = (childrenOffsets) => ({ + openParen: ast.openParen.text, + parameters: new YulParameters( + ast.parameters, childrenOffsets.shift(), comments, parse, options - ); - this.closeParen = closeParen.text; - }; + ), + closeParen: ast.closeParen.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/YulPath.js b/src/slang-nodes/YulPath.js index 0f3568450..79416db26 100644 --- a/src/slang-nodes/YulPath.js +++ b/src/slang-nodes/YulPath.js @@ -9,9 +9,8 @@ export class YulPath extends SlangNode { constructor(ast, offset, comments, parse, options) { super(); - const fetch = (childrenOffsets) => { - const { items, separators } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new YulPathComponent( item, @@ -20,9 +19,9 @@ export class YulPath extends SlangNode { parse, options ) - ); - this.separators = separators.map((separator) => separator.text); - }; + ), + separators: ast.separators.map((separator) => separator.text) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/YulPathComponent.js b/src/slang-nodes/YulPathComponent.js index 3cda1366b..0abbcf2cf 100644 --- a/src/slang-nodes/YulPathComponent.js +++ b/src/slang-nodes/YulPathComponent.js @@ -3,13 +3,12 @@ import { SlangNode } from './SlangNode.js'; export class YulPathComponent extends SlangNode { variant; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments) { super(); - const fetch = () => { - const { variant } = ast; - this.variant = variant.text; - }; + const fetch = () => ({ + variant: ast.variant.text + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/YulPaths.js b/src/slang-nodes/YulPaths.js index f5dd154a6..8ee99bdc3 100644 --- a/src/slang-nodes/YulPaths.js +++ b/src/slang-nodes/YulPaths.js @@ -9,14 +9,13 @@ export class YulPaths extends SlangNode { constructor(ast, offset, comments, parse, options) { super(); - const fetch = (childrenOffsets) => { - const { items, separators } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new YulPath(item, childrenOffsets.shift(), comments, parse, options) - ); - this.separators = separators.map((separator) => separator.text); - }; + ), + separators: ast.separators.map((separator) => separator.text) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/YulReturnVariables.js b/src/slang-nodes/YulReturnVariables.js index f86e94a5b..eacbabf36 100644 --- a/src/slang-nodes/YulReturnVariables.js +++ b/src/slang-nodes/YulReturnVariables.js @@ -9,14 +9,13 @@ export class YulReturnVariables extends SlangNode { separators; - constructor(ast, offset, comments, parse) { + constructor(ast, offset, comments) { super(); - const fetch = () => { - const { items, separators } = ast; - this.items = items.map((item) => item.text); - this.separators = separators.map((separator) => separator.text); - }; + const fetch = () => ({ + items: ast.items.map((item) => item.text), + separators: ast.separators.map((separator) => separator.text) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/YulReturnsDeclaration.js b/src/slang-nodes/YulReturnsDeclaration.js index 78be93031..1da845df8 100644 --- a/src/slang-nodes/YulReturnsDeclaration.js +++ b/src/slang-nodes/YulReturnsDeclaration.js @@ -13,17 +13,16 @@ export class YulReturnsDeclaration extends SlangNode { constructor(ast, offset, comments, parse, options) { super(); - const fetch = (childrenOffsets) => { - const { minusGreaterThan, variables } = ast; - this.minusGreaterThan = minusGreaterThan.text; - this.variables = new YulReturnVariables( - variables, + const fetch = (childrenOffsets) => ({ + minusGreaterThan: ast.minusGreaterThan.text, + variables: new YulReturnVariables( + ast.variables, childrenOffsets.shift(), comments, parse, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/YulStackAssignmentStatement.js b/src/slang-nodes/YulStackAssignmentStatement.js index d638e4a69..10360fcab 100644 --- a/src/slang-nodes/YulStackAssignmentStatement.js +++ b/src/slang-nodes/YulStackAssignmentStatement.js @@ -10,23 +10,22 @@ export class YulStackAssignmentStatement extends SlangNode { constructor(ast, offset, comments, parse, options) { super(); - const fetch = (childrenOffsets) => { - const { assignment, expression } = ast; - this.assignment = new YulAssignmentOperator( - assignment, + const fetch = (childrenOffsets) => ({ + assignment: new YulAssignmentOperator( + ast.assignment, childrenOffsets.shift(), comments, parse, options - ); - this.expression = new YulExpression( - expression, + ), + expression: new YulExpression( + ast.expression, childrenOffsets.shift(), comments, parse, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/YulStatement.js b/src/slang-nodes/YulStatement.js index 045426dac..e14339cf8 100644 --- a/src/slang-nodes/YulStatement.js +++ b/src/slang-nodes/YulStatement.js @@ -35,16 +35,15 @@ export class YulStatement extends SlangNode { constructor(ast, offset, comments, parse, options) { super(); - const fetch = (childrenOffsets) => { - const { variant } = ast; - this.variant = new variants[variant.cst.kind]( - variant, + const fetch = (childrenOffsets) => ({ + variant: new variants[ast.variant.cst.kind]( + ast.variant, childrenOffsets.shift(), comments, parse, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/YulStatements.js b/src/slang-nodes/YulStatements.js index f4be230cd..8166b407b 100644 --- a/src/slang-nodes/YulStatements.js +++ b/src/slang-nodes/YulStatements.js @@ -13,9 +13,8 @@ export class YulStatements extends SlangNode { constructor(ast, offset, comments, parse, options) { super(); - const fetch = (childrenOffsets) => { - const { items } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new YulStatement( item, @@ -24,8 +23,8 @@ export class YulStatements extends SlangNode { parse, options ) - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/YulSwitchCase.js b/src/slang-nodes/YulSwitchCase.js index 31e5c5d73..c69533519 100644 --- a/src/slang-nodes/YulSwitchCase.js +++ b/src/slang-nodes/YulSwitchCase.js @@ -9,16 +9,15 @@ export class YulSwitchCase extends SlangNode { constructor(ast, offset, comments, parse, options) { super(); - const fetch = (childrenOffsets) => { - const { variant } = ast; - this.variant = new variants[variant.cst.kind]( - variant, + const fetch = (childrenOffsets) => ({ + variant: new variants[ast.variant.cst.kind]( + ast.variant, childrenOffsets.shift(), comments, parse, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/YulSwitchCases.js b/src/slang-nodes/YulSwitchCases.js index 013d2d65d..882f0c43a 100644 --- a/src/slang-nodes/YulSwitchCases.js +++ b/src/slang-nodes/YulSwitchCases.js @@ -10,9 +10,8 @@ export class YulSwitchCases extends SlangNode { constructor(ast, offset, comments, parse, options) { super(); - const fetch = (childrenOffsets) => { - const { items } = ast; - this.items = items.map( + const fetch = (childrenOffsets) => ({ + items: ast.items.map( (item) => new YulSwitchCase( item, @@ -21,8 +20,8 @@ export class YulSwitchCases extends SlangNode { parse, options ) - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/YulSwitchStatement.js b/src/slang-nodes/YulSwitchStatement.js index 6c5bb5888..1dce38fcc 100644 --- a/src/slang-nodes/YulSwitchStatement.js +++ b/src/slang-nodes/YulSwitchStatement.js @@ -15,24 +15,23 @@ export class YulSwitchStatement extends SlangNode { constructor(ast, offset, comments, parse, options) { super(); - const fetch = (childrenOffsets) => { - const { switchKeyword, expression, cases } = ast; - this.switchKeyword = switchKeyword.text; - this.expression = new YulExpression( - expression, + const fetch = (childrenOffsets) => ({ + switchKeyword: ast.switchKeyword.text, + expression: new YulExpression( + ast.expression, childrenOffsets.shift(), comments, parse, options - ); - this.cases = new YulSwitchCases( - cases, + ), + cases: new YulSwitchCases( + ast.cases, childrenOffsets.shift(), comments, parse, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/YulValueCase.js b/src/slang-nodes/YulValueCase.js index 625eb89bd..719e955ed 100644 --- a/src/slang-nodes/YulValueCase.js +++ b/src/slang-nodes/YulValueCase.js @@ -12,24 +12,23 @@ export class YulValueCase extends SlangNode { constructor(ast, offset, comments, parse, options) { super(); - const fetch = (childrenOffsets) => { - const { caseKeyword, value, body } = ast; - this.caseKeyword = caseKeyword.text; - this.value = new YulLiteral( - value, + const fetch = (childrenOffsets) => ({ + caseKeyword: ast.caseKeyword.text, + value: new YulLiteral( + ast.value, childrenOffsets.shift(), comments, parse, options - ); - this.body = new YulBlock( - body, + ), + body: new YulBlock( + ast.body, childrenOffsets.shift(), comments, parse, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/YulVariableAssignmentStatement.js b/src/slang-nodes/YulVariableAssignmentStatement.js index ce39ab3d1..2ad079e1c 100644 --- a/src/slang-nodes/YulVariableAssignmentStatement.js +++ b/src/slang-nodes/YulVariableAssignmentStatement.js @@ -13,30 +13,29 @@ export class YulVariableAssignmentStatement extends SlangNode { constructor(ast, offset, comments, parse, options) { super(); - const fetch = (childrenOffsets) => { - const { names, assignment, expression } = ast; - this.names = new YulPaths( - names, + const fetch = (childrenOffsets) => ({ + names: new YulPaths( + ast.names, childrenOffsets.shift(), comments, parse, options - ); - this.assignment = new YulAssignmentOperator( - assignment, + ), + assignment: new YulAssignmentOperator( + ast.assignment, childrenOffsets.shift(), comments, parse, options - ); - this.expression = new YulExpression( - expression, + ), + expression: new YulExpression( + ast.expression, childrenOffsets.shift(), comments, parse, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/YulVariableDeclarationStatement.js b/src/slang-nodes/YulVariableDeclarationStatement.js index 9f5b324f4..b4d0a23d9 100644 --- a/src/slang-nodes/YulVariableDeclarationStatement.js +++ b/src/slang-nodes/YulVariableDeclarationStatement.js @@ -11,20 +11,19 @@ export class YulVariableDeclarationStatement extends SlangNode { constructor(ast, offset, comments, parse, options) { super(); - const fetch = (childrenOffsets) => { - const { letKeyword, names, value } = ast; - this.letKeyword = letKeyword.text; - this.names = names.text; - if (value) { - this.value = new YulVariableDeclarationValue( - value, - childrenOffsets.shift(), - comments, - parse, - options - ); - } - }; + const fetch = (childrenOffsets) => ({ + letKeyword: ast.letKeyword.text, + names: ast.names.text, + value: ast.value + ? new YulVariableDeclarationValue( + ast.value, + childrenOffsets.shift(), + comments, + parse, + options + ) + : undefined + }); this.initialize(ast, offset, fetch, comments); } diff --git a/src/slang-nodes/YulVariableDeclarationValue.js b/src/slang-nodes/YulVariableDeclarationValue.js index 72e149981..d16f0fa5c 100644 --- a/src/slang-nodes/YulVariableDeclarationValue.js +++ b/src/slang-nodes/YulVariableDeclarationValue.js @@ -10,23 +10,22 @@ export class YulVariableDeclarationValue extends SlangNode { constructor(ast, offset, comments, parse, options) { super(); - const fetch = (childrenOffsets) => { - const { assignment, expression } = ast; - this.assignment = new YulAssignmentOperator( - assignment, + const fetch = (childrenOffsets) => ({ + assignment: new YulAssignmentOperator( + ast.assignment, childrenOffsets.shift(), comments, parse, options - ); - this.expression = new YulExpression( - expression, + ), + expression: new YulExpression( + ast.expression, childrenOffsets.shift(), comments, parse, options - ); - }; + ) + }); this.initialize(ast, offset, fetch, comments); } From 6ebb694d31be5e93d93ac1138afce5bb1c4a32d0 Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 17 Jul 2024 23:49:56 +1200 Subject: [PATCH 089/160] cleanup --- src/slang-nodes/ElementaryType.js | 1 + src/slang-nodes/ExponentiationExpression.js | 1 + src/slang-nodes/Expression.js | 1 + src/slang-nodes/MappingKeyType.js | 1 + src/slang-nodes/Parameters.js | 1 + src/slang-nodes/ParametersDeclaration.js | 1 + src/slang-nodes/SlangNode.js | 5 ++--- src/slang-nodes/StringExpression.js | 1 + src/slang-nodes/TupleExpression.js | 1 + src/slang-nodes/TupleValue.js | 1 + src/slang-nodes/TupleValues.js | 1 + src/slang-nodes/TypeName.js | 1 + src/slang-nodes/YulFunctionDefinition.js | 12 ++---------- src/slang-nodes/YulIfStatement.js | 11 ++--------- src/slang-nodes/YulLiteral.js | 3 +-- src/slang-nodes/YulParametersDeclaration.js | 3 +-- src/slang-nodes/YulPath.js | 10 ++-------- src/slang-nodes/YulPaths.js | 5 ++--- src/slang-nodes/YulReturnsDeclaration.js | 3 +-- src/slang-nodes/YulStackAssignmentStatement.js | 4 +--- src/slang-nodes/YulStatement.js | 3 +-- src/slang-nodes/YulStatements.js | 10 ++-------- src/slang-nodes/YulSwitchCase.js | 3 +-- src/slang-nodes/YulSwitchCases.js | 10 ++-------- src/slang-nodes/YulSwitchStatement.js | 4 +--- src/slang-nodes/YulValueCase.js | 11 ++--------- src/slang-nodes/YulVariableAssignmentStatement.js | 5 +---- src/slang-nodes/YulVariableDeclarationStatement.js | 3 +-- src/slang-nodes/YulVariableDeclarationValue.js | 4 +--- 29 files changed, 37 insertions(+), 83 deletions(-) diff --git a/src/slang-nodes/ElementaryType.js b/src/slang-nodes/ElementaryType.js index 4d13e5074..008f89235 100644 --- a/src/slang-nodes/ElementaryType.js +++ b/src/slang-nodes/ElementaryType.js @@ -6,6 +6,7 @@ export class ElementaryType extends SlangNode { constructor(ast, offset, comments, options) { super(); + const fetch = (childrenOffsets) => ({ variant: ast.variant.type === 'Terminal' diff --git a/src/slang-nodes/ExponentiationExpression.js b/src/slang-nodes/ExponentiationExpression.js index 18fb883df..6e33a6cbc 100644 --- a/src/slang-nodes/ExponentiationExpression.js +++ b/src/slang-nodes/ExponentiationExpression.js @@ -27,6 +27,7 @@ export class ExponentiationExpression extends SlangNode { constructor(ast, offset, comments, options) { super(); + if (offset) { const fetch = (childrenOffsets) => ({ leftOperand: new Expression( diff --git a/src/slang-nodes/Expression.js b/src/slang-nodes/Expression.js index 88b606c60..fcc898e18 100644 --- a/src/slang-nodes/Expression.js +++ b/src/slang-nodes/Expression.js @@ -62,6 +62,7 @@ export class Expression extends SlangNode { constructor(ast, offset, comments, options) { super(); + if (offset) { const fetch = (childrenOffsets) => ({ variant: diff --git a/src/slang-nodes/MappingKeyType.js b/src/slang-nodes/MappingKeyType.js index 677a75515..ba7508d1f 100644 --- a/src/slang-nodes/MappingKeyType.js +++ b/src/slang-nodes/MappingKeyType.js @@ -9,6 +9,7 @@ export class MappingKeyType extends SlangNode { constructor(ast, offset, comments, options) { super(); + const fetch = (childrenOffsets) => ({ variant: new variants[ast.variant.cst.kind]( ast.variant, diff --git a/src/slang-nodes/Parameters.js b/src/slang-nodes/Parameters.js index 38f349825..15bf3d8f9 100644 --- a/src/slang-nodes/Parameters.js +++ b/src/slang-nodes/Parameters.js @@ -13,6 +13,7 @@ export class Parameters extends SlangNode { constructor(ast, offset, comments, options) { super(); + if (offset) { const fetch = (childrenOffsets) => ({ items: ast.items.map( diff --git a/src/slang-nodes/ParametersDeclaration.js b/src/slang-nodes/ParametersDeclaration.js index 6ea0cc089..98073d0f8 100644 --- a/src/slang-nodes/ParametersDeclaration.js +++ b/src/slang-nodes/ParametersDeclaration.js @@ -10,6 +10,7 @@ export class ParametersDeclaration extends SlangNode { constructor(ast, offset, comments, options) { super(); + if (offset) { const fetch = (childrenOffsets) => ({ openParen: ast.openParen.text, diff --git a/src/slang-nodes/SlangNode.js b/src/slang-nodes/SlangNode.js index 14fcb6d86..fc5b9bd11 100644 --- a/src/slang-nodes/SlangNode.js +++ b/src/slang-nodes/SlangNode.js @@ -30,7 +30,8 @@ export class SlangNode { this.fetch(); - Object.keys(children).forEach((childKey) => { + const childrenKeys = Object.keys(children); + childrenKeys.forEach((childKey) => { this[childKey] = children[childKey]; }); @@ -41,8 +42,6 @@ export class SlangNode { let trailingOffset = getTrailingOffset(cstChildren); if (leadingOffset === 0 || trailingOffset === 0) { - const childrenKeys = Object.keys(this).slice(3); - for (let i = 0; i < childrenKeys.length; i += 1) { const childLoc = this[childrenKeys[i]]?.loc; diff --git a/src/slang-nodes/StringExpression.js b/src/slang-nodes/StringExpression.js index 7c5526bef..49c97fceb 100644 --- a/src/slang-nodes/StringExpression.js +++ b/src/slang-nodes/StringExpression.js @@ -18,6 +18,7 @@ export class StringExpression extends SlangNode { constructor(ast, offset, comments, options) { super(); + const fetch = (childrenOffsets) => ({ variant: new variants[ast.variant.cst.kind]( ast.variant, diff --git a/src/slang-nodes/TupleExpression.js b/src/slang-nodes/TupleExpression.js index 7235cad75..8e997d695 100644 --- a/src/slang-nodes/TupleExpression.js +++ b/src/slang-nodes/TupleExpression.js @@ -10,6 +10,7 @@ export class TupleExpression extends SlangNode { constructor(ast, offset, comments, options) { super(); + if (offset) { const fetch = (childrenOffsets) => ({ openParen: ast.openParen.text, diff --git a/src/slang-nodes/TupleValue.js b/src/slang-nodes/TupleValue.js index 73a5cd47e..796294f5f 100644 --- a/src/slang-nodes/TupleValue.js +++ b/src/slang-nodes/TupleValue.js @@ -6,6 +6,7 @@ export class TupleValue extends SlangNode { constructor(ast, offset, comments, options) { super(); + if (offset) { const fetch = (childrenOffsets) => ({ expression: ast.expression diff --git a/src/slang-nodes/TupleValues.js b/src/slang-nodes/TupleValues.js index 4258f6024..a46d4efff 100644 --- a/src/slang-nodes/TupleValues.js +++ b/src/slang-nodes/TupleValues.js @@ -10,6 +10,7 @@ export class TupleValues extends SlangNode { constructor(ast, offset, comments, options) { super(); + if (offset) { const fetch = (childrenOffsets) => ({ items: ast.items.map( diff --git a/src/slang-nodes/TypeName.js b/src/slang-nodes/TypeName.js index 94171b6a3..9383644fc 100644 --- a/src/slang-nodes/TypeName.js +++ b/src/slang-nodes/TypeName.js @@ -18,6 +18,7 @@ export class TypeName extends SlangNode { constructor(ast, offset, comments, options) { super(); + const fetch = (childrenOffsets) => ({ variant: new variants[ast.variant.cst.kind]( ast.variant, diff --git a/src/slang-nodes/YulFunctionDefinition.js b/src/slang-nodes/YulFunctionDefinition.js index f05a31034..3af6c4f17 100644 --- a/src/slang-nodes/YulFunctionDefinition.js +++ b/src/slang-nodes/YulFunctionDefinition.js @@ -14,7 +14,7 @@ export class YulFunctionDefinition extends SlangNode { body; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => ({ @@ -24,7 +24,6 @@ export class YulFunctionDefinition extends SlangNode { ast.parameters, childrenOffsets.shift(), comments, - parse, options ), returns: ast.returns @@ -32,17 +31,10 @@ export class YulFunctionDefinition extends SlangNode { ast.returns, childrenOffsets.shift(), comments, - parse, options ) : undefined, - body: new YulBlock( - ast.body, - childrenOffsets.shift(), - comments, - parse, - options - ) + body: new YulBlock(ast.body, childrenOffsets.shift(), comments, options) }); this.initialize(ast, offset, fetch, comments); diff --git a/src/slang-nodes/YulIfStatement.js b/src/slang-nodes/YulIfStatement.js index 49465b6f1..35a4df355 100644 --- a/src/slang-nodes/YulIfStatement.js +++ b/src/slang-nodes/YulIfStatement.js @@ -9,7 +9,7 @@ export class YulIfStatement extends SlangNode { body; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => ({ @@ -18,16 +18,9 @@ export class YulIfStatement extends SlangNode { ast.condition, childrenOffsets.shift(), comments, - parse, options ), - body: new YulBlock( - ast.body, - childrenOffsets.shift(), - comments, - parse, - options - ) + body: new YulBlock(ast.body, childrenOffsets.shift(), comments, options) }); this.initialize(ast, offset, fetch, comments); diff --git a/src/slang-nodes/YulLiteral.js b/src/slang-nodes/YulLiteral.js index ab20b0ab3..774cc0db1 100644 --- a/src/slang-nodes/YulLiteral.js +++ b/src/slang-nodes/YulLiteral.js @@ -7,7 +7,7 @@ const variants = { HexStringLiteral, StringLiteral }; export class YulLiteral extends SlangNode { variant; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => ({ @@ -18,7 +18,6 @@ export class YulLiteral extends SlangNode { ast.variant, childrenOffsets.shift(), comments, - parse, options ) }); diff --git a/src/slang-nodes/YulParametersDeclaration.js b/src/slang-nodes/YulParametersDeclaration.js index 2e1590570..91350e309 100644 --- a/src/slang-nodes/YulParametersDeclaration.js +++ b/src/slang-nodes/YulParametersDeclaration.js @@ -8,7 +8,7 @@ export class YulParametersDeclaration extends SlangNode { closeParen; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => ({ @@ -17,7 +17,6 @@ export class YulParametersDeclaration extends SlangNode { ast.parameters, childrenOffsets.shift(), comments, - parse, options ), closeParen: ast.closeParen.text diff --git a/src/slang-nodes/YulPath.js b/src/slang-nodes/YulPath.js index 79416db26..2856c17c5 100644 --- a/src/slang-nodes/YulPath.js +++ b/src/slang-nodes/YulPath.js @@ -6,19 +6,13 @@ export class YulPath extends SlangNode { separators; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( (item) => - new YulPathComponent( - item, - childrenOffsets.shift(), - comments, - parse, - options - ) + new YulPathComponent(item, childrenOffsets.shift(), comments, options) ), separators: ast.separators.map((separator) => separator.text) }); diff --git a/src/slang-nodes/YulPaths.js b/src/slang-nodes/YulPaths.js index 8ee99bdc3..26c3ad20b 100644 --- a/src/slang-nodes/YulPaths.js +++ b/src/slang-nodes/YulPaths.js @@ -6,13 +6,12 @@ export class YulPaths extends SlangNode { separators; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( - (item) => - new YulPath(item, childrenOffsets.shift(), comments, parse, options) + (item) => new YulPath(item, childrenOffsets.shift(), comments, options) ), separators: ast.separators.map((separator) => separator.text) }); diff --git a/src/slang-nodes/YulReturnsDeclaration.js b/src/slang-nodes/YulReturnsDeclaration.js index 1da845df8..759252a5b 100644 --- a/src/slang-nodes/YulReturnsDeclaration.js +++ b/src/slang-nodes/YulReturnsDeclaration.js @@ -10,7 +10,7 @@ export class YulReturnsDeclaration extends SlangNode { variables; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => ({ @@ -19,7 +19,6 @@ export class YulReturnsDeclaration extends SlangNode { ast.variables, childrenOffsets.shift(), comments, - parse, options ) }); diff --git a/src/slang-nodes/YulStackAssignmentStatement.js b/src/slang-nodes/YulStackAssignmentStatement.js index 10360fcab..19f49b975 100644 --- a/src/slang-nodes/YulStackAssignmentStatement.js +++ b/src/slang-nodes/YulStackAssignmentStatement.js @@ -7,7 +7,7 @@ export class YulStackAssignmentStatement extends SlangNode { expression; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => ({ @@ -15,14 +15,12 @@ export class YulStackAssignmentStatement extends SlangNode { ast.assignment, childrenOffsets.shift(), comments, - parse, options ), expression: new YulExpression( ast.expression, childrenOffsets.shift(), comments, - parse, options ) }); diff --git a/src/slang-nodes/YulStatement.js b/src/slang-nodes/YulStatement.js index e14339cf8..a3a22b9ea 100644 --- a/src/slang-nodes/YulStatement.js +++ b/src/slang-nodes/YulStatement.js @@ -32,7 +32,7 @@ const variants = { export class YulStatement extends SlangNode { variant; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => ({ @@ -40,7 +40,6 @@ export class YulStatement extends SlangNode { ast.variant, childrenOffsets.shift(), comments, - parse, options ) }); diff --git a/src/slang-nodes/YulStatements.js b/src/slang-nodes/YulStatements.js index 8166b407b..66a8e974e 100644 --- a/src/slang-nodes/YulStatements.js +++ b/src/slang-nodes/YulStatements.js @@ -10,19 +10,13 @@ const { hardline } = doc.builders; export class YulStatements extends SlangNode { items; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( (item) => - new YulStatement( - item, - childrenOffsets.shift(), - comments, - parse, - options - ) + new YulStatement(item, childrenOffsets.shift(), comments, options) ) }); diff --git a/src/slang-nodes/YulSwitchCase.js b/src/slang-nodes/YulSwitchCase.js index c69533519..f54792dcf 100644 --- a/src/slang-nodes/YulSwitchCase.js +++ b/src/slang-nodes/YulSwitchCase.js @@ -6,7 +6,7 @@ const variants = { YulDefaultCase, YulValueCase }; export class YulSwitchCase extends SlangNode { variant; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => ({ @@ -14,7 +14,6 @@ export class YulSwitchCase extends SlangNode { ast.variant, childrenOffsets.shift(), comments, - parse, options ) }); diff --git a/src/slang-nodes/YulSwitchCases.js b/src/slang-nodes/YulSwitchCases.js index 882f0c43a..4315f9fd1 100644 --- a/src/slang-nodes/YulSwitchCases.js +++ b/src/slang-nodes/YulSwitchCases.js @@ -7,19 +7,13 @@ const { hardline, join } = doc.builders; export class YulSwitchCases extends SlangNode { items; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( (item) => - new YulSwitchCase( - item, - childrenOffsets.shift(), - comments, - parse, - options - ) + new YulSwitchCase(item, childrenOffsets.shift(), comments, options) ) }); diff --git a/src/slang-nodes/YulSwitchStatement.js b/src/slang-nodes/YulSwitchStatement.js index 1dce38fcc..6ac0ebc42 100644 --- a/src/slang-nodes/YulSwitchStatement.js +++ b/src/slang-nodes/YulSwitchStatement.js @@ -12,7 +12,7 @@ export class YulSwitchStatement extends SlangNode { cases; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => ({ @@ -21,14 +21,12 @@ export class YulSwitchStatement extends SlangNode { ast.expression, childrenOffsets.shift(), comments, - parse, options ), cases: new YulSwitchCases( ast.cases, childrenOffsets.shift(), comments, - parse, options ) }); diff --git a/src/slang-nodes/YulValueCase.js b/src/slang-nodes/YulValueCase.js index 719e955ed..4f4f4de62 100644 --- a/src/slang-nodes/YulValueCase.js +++ b/src/slang-nodes/YulValueCase.js @@ -9,7 +9,7 @@ export class YulValueCase extends SlangNode { body; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => ({ @@ -18,16 +18,9 @@ export class YulValueCase extends SlangNode { ast.value, childrenOffsets.shift(), comments, - parse, options ), - body: new YulBlock( - ast.body, - childrenOffsets.shift(), - comments, - parse, - options - ) + body: new YulBlock(ast.body, childrenOffsets.shift(), comments, options) }); this.initialize(ast, offset, fetch, comments); diff --git a/src/slang-nodes/YulVariableAssignmentStatement.js b/src/slang-nodes/YulVariableAssignmentStatement.js index 2ad079e1c..9ec7112bd 100644 --- a/src/slang-nodes/YulVariableAssignmentStatement.js +++ b/src/slang-nodes/YulVariableAssignmentStatement.js @@ -10,7 +10,7 @@ export class YulVariableAssignmentStatement extends SlangNode { expression; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => ({ @@ -18,21 +18,18 @@ export class YulVariableAssignmentStatement extends SlangNode { ast.names, childrenOffsets.shift(), comments, - parse, options ), assignment: new YulAssignmentOperator( ast.assignment, childrenOffsets.shift(), comments, - parse, options ), expression: new YulExpression( ast.expression, childrenOffsets.shift(), comments, - parse, options ) }); diff --git a/src/slang-nodes/YulVariableDeclarationStatement.js b/src/slang-nodes/YulVariableDeclarationStatement.js index b4d0a23d9..5c8bb8767 100644 --- a/src/slang-nodes/YulVariableDeclarationStatement.js +++ b/src/slang-nodes/YulVariableDeclarationStatement.js @@ -8,7 +8,7 @@ export class YulVariableDeclarationStatement extends SlangNode { value; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => ({ @@ -19,7 +19,6 @@ export class YulVariableDeclarationStatement extends SlangNode { ast.value, childrenOffsets.shift(), comments, - parse, options ) : undefined diff --git a/src/slang-nodes/YulVariableDeclarationValue.js b/src/slang-nodes/YulVariableDeclarationValue.js index d16f0fa5c..72061dc34 100644 --- a/src/slang-nodes/YulVariableDeclarationValue.js +++ b/src/slang-nodes/YulVariableDeclarationValue.js @@ -7,7 +7,7 @@ export class YulVariableDeclarationValue extends SlangNode { expression; - constructor(ast, offset, comments, parse, options) { + constructor(ast, offset, comments, options) { super(); const fetch = (childrenOffsets) => ({ @@ -15,14 +15,12 @@ export class YulVariableDeclarationValue extends SlangNode { ast.assignment, childrenOffsets.shift(), comments, - parse, options ), expression: new YulExpression( ast.expression, childrenOffsets.shift(), comments, - parse, options ) }); From 564edfe077d8a108db0bde123237da99f5d3175c Mon Sep 17 00:00:00 2001 From: Klaus Date: Thu, 18 Jul 2024 01:00:56 +1200 Subject: [PATCH 090/160] collecting comments internally --- src/slang-nodes/ABICoderPragma.js | 4 +- src/slang-nodes/AdditiveExpression.js | 6 +-- src/slang-nodes/AddressType.js | 4 +- src/slang-nodes/AndExpression.js | 6 +-- src/slang-nodes/ArgumentsDeclaration.js | 5 +-- src/slang-nodes/ArrayExpression.js | 11 ++--- src/slang-nodes/ArrayTypeName.js | 13 ++---- src/slang-nodes/ArrayValues.js | 7 ++- src/slang-nodes/AssemblyFlags.js | 7 ++- src/slang-nodes/AssemblyFlagsDeclaration.js | 11 ++--- src/slang-nodes/AssemblyStatement.js | 14 ++---- src/slang-nodes/AssignmentExpression.js | 6 +-- src/slang-nodes/BitwiseAndExpression.js | 6 +-- src/slang-nodes/BitwiseOrExpression.js | 6 +-- src/slang-nodes/BitwiseXorExpression.js | 6 +-- src/slang-nodes/Block.js | 5 +-- src/slang-nodes/BreakStatement.js | 4 +- src/slang-nodes/CallOptions.js | 7 ++- src/slang-nodes/CallOptionsExpression.js | 18 ++------ src/slang-nodes/CatchClause.js | 13 ++---- src/slang-nodes/CatchClauseError.js | 5 +-- src/slang-nodes/CatchClauses.js | 7 ++- src/slang-nodes/ComparisonExpression.js | 6 +-- src/slang-nodes/ConditionalExpression.js | 13 ++---- src/slang-nodes/ConstantDefinition.js | 18 ++------ src/slang-nodes/ConstructorAttribute.js | 5 +-- src/slang-nodes/ConstructorAttributes.js | 11 ++--- src/slang-nodes/ConstructorDefinition.js | 8 ++-- src/slang-nodes/ContinueStatement.js | 4 +- src/slang-nodes/ContractDefinition.js | 6 +-- src/slang-nodes/ContractMember.js | 5 +-- src/slang-nodes/ContractMembers.js | 7 ++- src/slang-nodes/DecimalNumberExpression.js | 6 +-- src/slang-nodes/DoWhileStatement.js | 7 ++- src/slang-nodes/ElementaryType.js | 11 ++--- src/slang-nodes/ElseBranch.js | 6 +-- src/slang-nodes/EmitStatement.js | 12 ++---- src/slang-nodes/EnumDefinition.js | 11 ++--- src/slang-nodes/EnumMembers.js | 4 +- src/slang-nodes/EqualityExpression.js | 6 +-- src/slang-nodes/ErrorDefinition.js | 5 +-- src/slang-nodes/ErrorParameter.js | 11 ++--- src/slang-nodes/ErrorParameters.js | 7 ++- src/slang-nodes/ErrorParametersDeclaration.js | 5 +-- src/slang-nodes/EventDefinition.js | 5 +-- src/slang-nodes/EventParameter.js | 11 ++--- src/slang-nodes/EventParameters.js | 7 ++- src/slang-nodes/EventParametersDeclaration.js | 5 +-- src/slang-nodes/ExperimentalFeature.js | 11 ++--- src/slang-nodes/ExperimentalPragma.js | 5 +-- src/slang-nodes/ExponentiationExpression.js | 6 +-- src/slang-nodes/Expression.js | 5 +-- src/slang-nodes/ExpressionStatement.js | 5 +-- src/slang-nodes/FallbackFunctionAttribute.js | 5 +-- src/slang-nodes/FallbackFunctionAttributes.js | 11 ++--- src/slang-nodes/FallbackFunctionDefinition.js | 20 ++------- src/slang-nodes/ForStatement.js | 15 ++----- src/slang-nodes/ForStatementCondition.js | 5 +-- src/slang-nodes/ForStatementInitialization.js | 5 +-- src/slang-nodes/FunctionAttribute.js | 5 +-- src/slang-nodes/FunctionAttributes.js | 12 ++---- src/slang-nodes/FunctionBody.js | 6 +-- src/slang-nodes/FunctionCallExpression.js | 12 ++---- src/slang-nodes/FunctionDefinition.js | 27 +++--------- src/slang-nodes/FunctionName.js | 4 +- src/slang-nodes/FunctionType.js | 13 ++---- src/slang-nodes/FunctionTypeAttribute.js | 4 +- src/slang-nodes/FunctionTypeAttributes.js | 11 ++--- src/slang-nodes/HexNumberExpression.js | 6 +-- src/slang-nodes/HexStringLiteral.js | 4 +- src/slang-nodes/HexStringLiterals.js | 7 ++- src/slang-nodes/IdentifierPath.js | 4 +- src/slang-nodes/IfStatement.js | 14 ++---- src/slang-nodes/ImportAlias.js | 4 +- src/slang-nodes/ImportClause.js | 5 +-- src/slang-nodes/ImportDeconstruction.js | 12 ++---- src/slang-nodes/ImportDeconstructionSymbol.js | 6 +-- .../ImportDeconstructionSymbols.js | 11 ++--- src/slang-nodes/ImportDirective.js | 11 ++--- src/slang-nodes/IndexAccessEnd.js | 6 +-- src/slang-nodes/IndexAccessExpression.js | 20 +++------ src/slang-nodes/InheritanceSpecifier.js | 11 ++--- src/slang-nodes/InheritanceType.js | 6 +-- src/slang-nodes/InheritanceTypes.js | 7 ++- src/slang-nodes/InterfaceDefinition.js | 6 +-- src/slang-nodes/InterfaceMembers.js | 7 ++- src/slang-nodes/LibraryDefinition.js | 5 +-- src/slang-nodes/LibraryMembers.js | 7 ++- src/slang-nodes/MappingKey.js | 5 +-- src/slang-nodes/MappingKeyType.js | 5 +-- src/slang-nodes/MappingType.js | 12 ++---- src/slang-nodes/MappingValue.js | 11 ++--- src/slang-nodes/MemberAccess.js | 4 +- src/slang-nodes/MemberAccessExpression.js | 18 ++------ src/slang-nodes/ModifierAttribute.js | 11 ++--- src/slang-nodes/ModifierAttributes.js | 12 ++---- src/slang-nodes/ModifierDefinition.js | 13 ++---- src/slang-nodes/ModifierInvocation.js | 12 ++---- src/slang-nodes/MultiplicativeExpression.js | 6 +-- src/slang-nodes/NamedArgument.js | 11 ++--- src/slang-nodes/NamedArgumentGroup.js | 5 +-- src/slang-nodes/NamedArguments.js | 7 ++- src/slang-nodes/NamedArgumentsDeclaration.js | 5 +-- src/slang-nodes/NamedImport.js | 18 ++------ src/slang-nodes/NewExpression.js | 11 ++--- src/slang-nodes/NumberUnit.js | 4 +- src/slang-nodes/OrExpression.js | 6 +-- src/slang-nodes/OverridePaths.js | 7 ++- src/slang-nodes/OverridePathsDeclaration.js | 11 ++--- src/slang-nodes/OverrideSpecifier.js | 5 +-- src/slang-nodes/Parameter.js | 12 ++---- src/slang-nodes/Parameters.js | 7 ++- src/slang-nodes/ParametersDeclaration.js | 5 +-- src/slang-nodes/PathImport.js | 13 ++---- src/slang-nodes/PositionalArguments.js | 7 ++- .../PositionalArgumentsDeclaration.js | 5 +-- src/slang-nodes/PostfixExpression.js | 11 ++--- src/slang-nodes/Pragma.js | 5 +-- src/slang-nodes/PragmaDirective.js | 11 ++--- src/slang-nodes/PrefixExpression.js | 11 ++--- src/slang-nodes/ReceiveFunctionAttribute.js | 5 +-- src/slang-nodes/ReceiveFunctionAttributes.js | 11 ++--- src/slang-nodes/ReceiveFunctionDefinition.js | 13 ++---- src/slang-nodes/ReturnStatement.js | 11 ++--- src/slang-nodes/ReturnsDeclaration.js | 5 +-- src/slang-nodes/RevertStatement.js | 12 ++---- src/slang-nodes/ShiftExpression.js | 6 +-- src/slang-nodes/SlangNode.js | 43 ++++++++++++++----- src/slang-nodes/SourceUnit.js | 5 +-- src/slang-nodes/SourceUnitMember.js | 5 +-- src/slang-nodes/SourceUnitMembers.js | 7 ++- src/slang-nodes/StateVariableAttribute.js | 11 ++--- src/slang-nodes/StateVariableAttributes.js | 11 ++--- src/slang-nodes/StateVariableDefinition.js | 13 ++---- .../StateVariableDefinitionValue.js | 11 ++--- src/slang-nodes/Statement.js | 5 +-- src/slang-nodes/Statements.js | 7 ++- src/slang-nodes/StorageLocation.js | 4 +- src/slang-nodes/StringExpression.js | 5 +-- src/slang-nodes/StringLiteral.js | 4 +- src/slang-nodes/StringLiterals.js | 7 ++- src/slang-nodes/StructDefinition.js | 11 ++--- src/slang-nodes/StructMember.js | 11 ++--- src/slang-nodes/StructMembers.js | 7 ++- src/slang-nodes/ThrowStatement.js | 4 +- src/slang-nodes/TryStatement.js | 15 ++----- src/slang-nodes/TupleDeconstructionElement.js | 11 ++--- .../TupleDeconstructionElements.js | 11 ++--- .../TupleDeconstructionStatement.js | 6 +-- src/slang-nodes/TupleExpression.js | 11 ++--- src/slang-nodes/TupleMember.js | 5 +-- src/slang-nodes/TupleValue.js | 11 ++--- src/slang-nodes/TupleValues.js | 7 ++- src/slang-nodes/TypeExpression.js | 11 ++--- src/slang-nodes/TypeName.js | 5 +-- src/slang-nodes/TypedTupleMember.js | 12 ++---- src/slang-nodes/UncheckedBlock.js | 6 +-- src/slang-nodes/UnicodeStringLiteral.js | 4 +- src/slang-nodes/UnicodeStringLiterals.js | 11 ++--- src/slang-nodes/UnnamedFunctionAttribute.js | 5 +-- src/slang-nodes/UnnamedFunctionAttributes.js | 11 ++--- src/slang-nodes/UnnamedFunctionDefinition.js | 13 ++---- src/slang-nodes/UntypedTupleMember.js | 5 +-- .../UserDefinedValueTypeDefinition.js | 5 +-- src/slang-nodes/UsingAlias.js | 5 +-- src/slang-nodes/UsingClause.js | 5 +-- src/slang-nodes/UsingDeconstruction.js | 5 +-- src/slang-nodes/UsingDeconstructionSymbol.js | 13 ++---- src/slang-nodes/UsingDeconstructionSymbols.js | 11 ++--- src/slang-nodes/UsingDirective.js | 18 ++------ src/slang-nodes/UsingOperator.js | 4 +- src/slang-nodes/UsingTarget.js | 11 ++--- .../VariableDeclarationStatement.js | 7 +-- src/slang-nodes/VariableDeclarationType.js | 11 ++--- src/slang-nodes/VariableDeclarationValue.js | 5 +-- src/slang-nodes/VersionComparator.js | 5 +-- src/slang-nodes/VersionExpression.js | 5 +-- src/slang-nodes/VersionExpressionSet.js | 12 ++---- src/slang-nodes/VersionExpressionSets.js | 11 ++--- src/slang-nodes/VersionPragma.js | 5 +-- src/slang-nodes/VersionRange.js | 6 +-- src/slang-nodes/VersionSpecifiers.js | 4 +- src/slang-nodes/WhileStatement.js | 7 ++- src/slang-nodes/YulArguments.js | 7 ++- src/slang-nodes/YulAssignmentOperator.js | 11 ++--- src/slang-nodes/YulBlock.js | 5 +-- src/slang-nodes/YulBreakStatement.js | 4 +- src/slang-nodes/YulBuiltInFunction.js | 4 +- src/slang-nodes/YulColonEqual.js | 4 +- src/slang-nodes/YulContinueStatement.js | 4 +- src/slang-nodes/YulDefaultCase.js | 6 +-- src/slang-nodes/YulExpression.js | 5 +-- src/slang-nodes/YulForStatement.js | 15 ++----- src/slang-nodes/YulFunctionCallExpression.js | 12 ++---- src/slang-nodes/YulFunctionDefinition.js | 8 ++-- src/slang-nodes/YulIfStatement.js | 7 ++- src/slang-nodes/YulLabel.js | 4 +- src/slang-nodes/YulLeaveStatement.js | 4 +- src/slang-nodes/YulLiteral.js | 5 +-- src/slang-nodes/YulParameters.js | 4 +- src/slang-nodes/YulParametersDeclaration.js | 5 +-- src/slang-nodes/YulPath.js | 7 ++- src/slang-nodes/YulPathComponent.js | 4 +- src/slang-nodes/YulPaths.js | 6 +-- src/slang-nodes/YulReturnVariables.js | 4 +- src/slang-nodes/YulReturnsDeclaration.js | 5 +-- .../YulStackAssignmentStatement.js | 6 +-- src/slang-nodes/YulStatement.js | 5 +-- src/slang-nodes/YulStatements.js | 7 ++- src/slang-nodes/YulSwitchCase.js | 5 +-- src/slang-nodes/YulSwitchCases.js | 7 ++- src/slang-nodes/YulSwitchStatement.js | 12 ++---- src/slang-nodes/YulValueCase.js | 13 ++---- .../YulVariableAssignmentStatement.js | 13 ++---- .../YulVariableDeclarationStatement.js | 5 +-- .../YulVariableDeclarationValue.js | 6 +-- src/slangParser.js | 13 ++---- 217 files changed, 601 insertions(+), 1185 deletions(-) diff --git a/src/slang-nodes/ABICoderPragma.js b/src/slang-nodes/ABICoderPragma.js index 8ace89941..3dd6c6d84 100644 --- a/src/slang-nodes/ABICoderPragma.js +++ b/src/slang-nodes/ABICoderPragma.js @@ -5,7 +5,7 @@ export class ABICoderPragma extends SlangNode { version; - constructor(ast, offset, comments) { + constructor(ast, offset) { super(); const fetch = () => ({ @@ -13,7 +13,7 @@ export class ABICoderPragma extends SlangNode { version: ast.version.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print() { diff --git a/src/slang-nodes/AdditiveExpression.js b/src/slang-nodes/AdditiveExpression.js index 9a903d125..4934db97a 100644 --- a/src/slang-nodes/AdditiveExpression.js +++ b/src/slang-nodes/AdditiveExpression.js @@ -12,26 +12,24 @@ export class AdditiveExpression extends SlangNode { rightOperand; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ leftOperand: new Expression( ast.leftOperand, childrenOffsets.shift(), - comments, options ), operator: ast.operator.text, rightOperand: new Expression( ast.rightOperand, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); diff --git a/src/slang-nodes/AddressType.js b/src/slang-nodes/AddressType.js index e4a1a1b26..ef1f5465d 100644 --- a/src/slang-nodes/AddressType.js +++ b/src/slang-nodes/AddressType.js @@ -5,7 +5,7 @@ export class AddressType extends SlangNode { payableKeyword; - constructor(ast, offset, comments) { + constructor(ast, offset) { super(); const fetch = () => ({ @@ -13,7 +13,7 @@ export class AddressType extends SlangNode { payableKeyword: ast.payableKeyword?.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print() { diff --git a/src/slang-nodes/AndExpression.js b/src/slang-nodes/AndExpression.js index 464269848..7128c9c56 100644 --- a/src/slang-nodes/AndExpression.js +++ b/src/slang-nodes/AndExpression.js @@ -9,26 +9,24 @@ export class AndExpression extends SlangNode { rightOperand; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ leftOperand: new Expression( ast.leftOperand, childrenOffsets.shift(), - comments, options ), operator: ast.operator.text, rightOperand: new Expression( ast.rightOperand, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print, options) { diff --git a/src/slang-nodes/ArgumentsDeclaration.js b/src/slang-nodes/ArgumentsDeclaration.js index 764add460..a53956c8d 100644 --- a/src/slang-nodes/ArgumentsDeclaration.js +++ b/src/slang-nodes/ArgumentsDeclaration.js @@ -7,19 +7,18 @@ const variants = { PositionalArgumentsDeclaration, NamedArgumentsDeclaration }; export class ArgumentsDeclaration extends SlangNode { variant; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ variant: new variants[ast.variant.cst.kind]( ast.variant, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/ArrayExpression.js b/src/slang-nodes/ArrayExpression.js index d20ee9d5b..04f35e925 100644 --- a/src/slang-nodes/ArrayExpression.js +++ b/src/slang-nodes/ArrayExpression.js @@ -11,21 +11,16 @@ export class ArrayExpression extends SlangNode { closeBracket; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ openBracket: ast.openBracket.text, - items: new ArrayValues( - ast.items, - childrenOffsets.shift(), - comments, - options - ), + items: new ArrayValues(ast.items, childrenOffsets.shift(), options), closeBracket: ast.closeBracket.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/ArrayTypeName.js b/src/slang-nodes/ArrayTypeName.js index fe00fd955..5abedecc6 100644 --- a/src/slang-nodes/ArrayTypeName.js +++ b/src/slang-nodes/ArrayTypeName.js @@ -11,24 +11,19 @@ export class ArrayTypeName extends SlangNode { closeBracket; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ - operand: new TypeName( - ast.operand, - childrenOffsets.shift(), - comments, - options - ), + operand: new TypeName(ast.operand, childrenOffsets.shift(), options), openBracket: ast.openBracket.text, index: ast.index - ? new Expression(ast.index, childrenOffsets.shift(), comments, options) + ? new Expression(ast.index, childrenOffsets.shift(), options) : undefined, closeBracket: ast.closeBracket.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/ArrayValues.js b/src/slang-nodes/ArrayValues.js index 378d74ab3..2898bc3db 100644 --- a/src/slang-nodes/ArrayValues.js +++ b/src/slang-nodes/ArrayValues.js @@ -7,18 +7,17 @@ export class ArrayValues extends SlangNode { separators; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( - (item) => - new Expression(item, childrenOffsets.shift(), comments, options) + (item) => new Expression(item, childrenOffsets.shift(), options) ), separators: ast.separators.map((separator) => separator.text) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/AssemblyFlags.js b/src/slang-nodes/AssemblyFlags.js index 4e9c6c099..808c1ae32 100644 --- a/src/slang-nodes/AssemblyFlags.js +++ b/src/slang-nodes/AssemblyFlags.js @@ -7,18 +7,17 @@ export class AssemblyFlags extends SlangNode { separators; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( - (item) => - new StringLiteral(item, childrenOffsets.shift(), comments, options) + (item) => new StringLiteral(item, childrenOffsets.shift(), options) ), separators: ast.separators.map((separator) => separator.text) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/AssemblyFlagsDeclaration.js b/src/slang-nodes/AssemblyFlagsDeclaration.js index 974969dcd..02f73aeca 100644 --- a/src/slang-nodes/AssemblyFlagsDeclaration.js +++ b/src/slang-nodes/AssemblyFlagsDeclaration.js @@ -8,21 +8,16 @@ export class AssemblyFlagsDeclaration extends SlangNode { closeParen; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ openParen: ast.openParen.text, - flags: new AssemblyFlags( - ast.flags, - childrenOffsets.shift(), - comments, - options - ), + flags: new AssemblyFlags(ast.flags, childrenOffsets.shift(), options), closeParen: ast.closeParen.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/AssemblyStatement.js b/src/slang-nodes/AssemblyStatement.js index 66db62aa8..19d210c03 100644 --- a/src/slang-nodes/AssemblyStatement.js +++ b/src/slang-nodes/AssemblyStatement.js @@ -12,31 +12,25 @@ export class AssemblyStatement extends SlangNode { body; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ assemblyKeyword: ast.assemblyKeyword.text, label: ast.label - ? new StringLiteral( - ast.label, - childrenOffsets.shift(), - comments, - options - ) + ? new StringLiteral(ast.label, childrenOffsets.shift(), options) : undefined, flags: ast.flags ? new AssemblyFlagsDeclaration( ast.flags, childrenOffsets.shift(), - comments, options ) : undefined, - body: new YulBlock(ast.body, childrenOffsets.shift(), comments, options) + body: new YulBlock(ast.body, childrenOffsets.shift(), options) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/AssignmentExpression.js b/src/slang-nodes/AssignmentExpression.js index 749db4fb4..7fc48dcda 100644 --- a/src/slang-nodes/AssignmentExpression.js +++ b/src/slang-nodes/AssignmentExpression.js @@ -12,26 +12,24 @@ export class AssignmentExpression extends SlangNode { rightOperand; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ leftOperand: new Expression( ast.leftOperand, childrenOffsets.shift(), - comments, options ), operator: ast.operator.text, rightOperand: new Expression( ast.rightOperand, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/BitwiseAndExpression.js b/src/slang-nodes/BitwiseAndExpression.js index e0e19efb2..b3221be9a 100644 --- a/src/slang-nodes/BitwiseAndExpression.js +++ b/src/slang-nodes/BitwiseAndExpression.js @@ -12,26 +12,24 @@ export class BitwiseAndExpression extends SlangNode { rightOperand; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ leftOperand: new Expression( ast.leftOperand, childrenOffsets.shift(), - comments, options ), operator: ast.operator.text, rightOperand: new Expression( ast.rightOperand, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); diff --git a/src/slang-nodes/BitwiseOrExpression.js b/src/slang-nodes/BitwiseOrExpression.js index 25edd7856..698c598ec 100644 --- a/src/slang-nodes/BitwiseOrExpression.js +++ b/src/slang-nodes/BitwiseOrExpression.js @@ -22,26 +22,24 @@ export class BitwiseOrExpression extends SlangNode { rightOperand; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ leftOperand: new Expression( ast.leftOperand, childrenOffsets.shift(), - comments, options ), operator: ast.operator.text, rightOperand: new Expression( ast.rightOperand, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); diff --git a/src/slang-nodes/BitwiseXorExpression.js b/src/slang-nodes/BitwiseXorExpression.js index 032d423ef..78b38bed1 100644 --- a/src/slang-nodes/BitwiseXorExpression.js +++ b/src/slang-nodes/BitwiseXorExpression.js @@ -12,26 +12,24 @@ export class BitwiseXorExpression extends SlangNode { rightOperand; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ leftOperand: new Expression( ast.leftOperand, childrenOffsets.shift(), - comments, options ), operator: ast.operator.text, rightOperand: new Expression( ast.rightOperand, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); diff --git a/src/slang-nodes/Block.js b/src/slang-nodes/Block.js index a8f76ee65..52375ffc2 100644 --- a/src/slang-nodes/Block.js +++ b/src/slang-nodes/Block.js @@ -8,7 +8,7 @@ export class Block extends SlangNode { closeBrace; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -16,13 +16,12 @@ export class Block extends SlangNode { statements: new Statements( ast.statements, childrenOffsets.shift(), - comments, options ), closeBrace: ast.closeBrace.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/BreakStatement.js b/src/slang-nodes/BreakStatement.js index 922cb6d1d..913427db9 100644 --- a/src/slang-nodes/BreakStatement.js +++ b/src/slang-nodes/BreakStatement.js @@ -5,7 +5,7 @@ export class BreakStatement extends SlangNode { semicolon; - constructor(ast, offset, comments) { + constructor(ast, offset) { super(); const fetch = () => ({ @@ -13,7 +13,7 @@ export class BreakStatement extends SlangNode { semicolon: ast.semicolon.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print() { diff --git a/src/slang-nodes/CallOptions.js b/src/slang-nodes/CallOptions.js index b16ed6ea0..7b210514b 100644 --- a/src/slang-nodes/CallOptions.js +++ b/src/slang-nodes/CallOptions.js @@ -10,18 +10,17 @@ export class CallOptions extends SlangNode { separators; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( - (item) => - new NamedArgument(item, childrenOffsets.shift(), comments, options) + (item) => new NamedArgument(item, childrenOffsets.shift(), options) ), separators: ast.separators.map((separator) => separator.text) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print, options) { diff --git a/src/slang-nodes/CallOptionsExpression.js b/src/slang-nodes/CallOptionsExpression.js index 6c46308cf..2e052b258 100644 --- a/src/slang-nodes/CallOptionsExpression.js +++ b/src/slang-nodes/CallOptionsExpression.js @@ -11,27 +11,17 @@ export class CallOptionsExpression extends SlangNode { closeBrace; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ - operand: new Expression( - ast.operand, - childrenOffsets.shift(), - comments, - options - ), + operand: new Expression(ast.operand, childrenOffsets.shift(), options), openBrace: ast.openBrace.text, - options: new CallOptions( - ast.options, - childrenOffsets.shift(), - comments, - options - ), + options: new CallOptions(ast.options, childrenOffsets.shift(), options), closeBrace: ast.closeBrace.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/CatchClause.js b/src/slang-nodes/CatchClause.js index 3c2a3f2f1..e643af0e0 100644 --- a/src/slang-nodes/CatchClause.js +++ b/src/slang-nodes/CatchClause.js @@ -9,23 +9,18 @@ export class CatchClause extends SlangNode { body; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ catchKeyword: ast.catchKeyword.text, error: ast.error - ? new CatchClauseError( - ast.error, - childrenOffsets.shift(), - comments, - options - ) + ? new CatchClauseError(ast.error, childrenOffsets.shift(), options) : undefined, - body: new Block(ast.body, childrenOffsets.shift(), comments, options) + body: new Block(ast.body, childrenOffsets.shift(), options) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/CatchClauseError.js b/src/slang-nodes/CatchClauseError.js index 02d22e18c..c508e631e 100644 --- a/src/slang-nodes/CatchClauseError.js +++ b/src/slang-nodes/CatchClauseError.js @@ -9,7 +9,7 @@ export class CatchClauseError extends SlangNode { parameters; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -17,12 +17,11 @@ export class CatchClauseError extends SlangNode { parameters: new ParametersDeclaration( ast.parameters, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/CatchClauses.js b/src/slang-nodes/CatchClauses.js index e6dc738a2..a17f79eb7 100644 --- a/src/slang-nodes/CatchClauses.js +++ b/src/slang-nodes/CatchClauses.js @@ -7,17 +7,16 @@ const { join } = doc.builders; export class CatchClauses extends SlangNode { items; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( - (item) => - new CatchClause(item, childrenOffsets.shift(), comments, options) + (item) => new CatchClause(item, childrenOffsets.shift(), options) ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/ComparisonExpression.js b/src/slang-nodes/ComparisonExpression.js index dd8154fc7..49b9897b6 100644 --- a/src/slang-nodes/ComparisonExpression.js +++ b/src/slang-nodes/ComparisonExpression.js @@ -9,26 +9,24 @@ export class ComparisonExpression extends SlangNode { rightOperand; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ leftOperand: new Expression( ast.leftOperand, childrenOffsets.shift(), - comments, options ), operator: ast.operator.text, rightOperand: new Expression( ast.rightOperand, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print, options) { diff --git a/src/slang-nodes/ConditionalExpression.js b/src/slang-nodes/ConditionalExpression.js index bcf92bbb3..b25f5a436 100644 --- a/src/slang-nodes/ConditionalExpression.js +++ b/src/slang-nodes/ConditionalExpression.js @@ -96,33 +96,26 @@ export class ConditionalExpression extends SlangNode { falseExpression; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ - operand: new Expression( - ast.operand, - childrenOffsets.shift(), - comments, - options - ), + operand: new Expression(ast.operand, childrenOffsets.shift(), options), questionMark: ast.questionMark.text, trueExpression: new Expression( ast.trueExpression, childrenOffsets.shift(), - comments, options ), colon: ast.colon.text, falseExpression: new Expression( ast.falseExpression, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); // TODO: while the behaviour is not stable, it should be behind the // experimentalTernaries flag. diff --git a/src/slang-nodes/ConstantDefinition.js b/src/slang-nodes/ConstantDefinition.js index 29b53baf4..ff7b76f3d 100644 --- a/src/slang-nodes/ConstantDefinition.js +++ b/src/slang-nodes/ConstantDefinition.js @@ -15,29 +15,19 @@ export class ConstantDefinition extends SlangNode { semicolon; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ - typeName: new TypeName( - ast.typeName, - childrenOffsets.shift(), - comments, - options - ), + typeName: new TypeName(ast.typeName, childrenOffsets.shift(), options), constantKeyword: ast.constantKeyword.text, name: ast.name.text, equal: ast.equal.text, - value: new Expression( - ast.value, - childrenOffsets.shift(), - comments, - options - ), + value: new Expression(ast.value, childrenOffsets.shift(), options), semicolon: ast.semicolon.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } // TODO: implement print diff --git a/src/slang-nodes/ConstructorAttribute.js b/src/slang-nodes/ConstructorAttribute.js index 51947a219..128606210 100644 --- a/src/slang-nodes/ConstructorAttribute.js +++ b/src/slang-nodes/ConstructorAttribute.js @@ -4,7 +4,7 @@ import { ModifierInvocation } from './ModifierInvocation.js'; export class ConstructorAttribute extends SlangNode { variant; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -14,12 +14,11 @@ export class ConstructorAttribute extends SlangNode { : new ModifierInvocation( ast.variant, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/ConstructorAttributes.js b/src/slang-nodes/ConstructorAttributes.js index edbff177c..5c943629b 100644 --- a/src/slang-nodes/ConstructorAttributes.js +++ b/src/slang-nodes/ConstructorAttributes.js @@ -8,22 +8,17 @@ const { line } = doc.builders; export class ConstructorAttributes extends SlangNode { items; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( (item) => - new ConstructorAttribute( - item, - childrenOffsets.shift(), - comments, - options - ) + new ConstructorAttribute(item, childrenOffsets.shift(), options) ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); this.items = this.items.sort(sortFunctionAttributes); } diff --git a/src/slang-nodes/ConstructorDefinition.js b/src/slang-nodes/ConstructorDefinition.js index 76391ec13..a5380ae64 100644 --- a/src/slang-nodes/ConstructorDefinition.js +++ b/src/slang-nodes/ConstructorDefinition.js @@ -13,7 +13,7 @@ export class ConstructorDefinition extends SlangNode { body; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -21,19 +21,17 @@ export class ConstructorDefinition extends SlangNode { parameters: new ParametersDeclaration( ast.parameters, childrenOffsets.shift(), - comments, options ), attributes: new ConstructorAttributes( ast.attributes, childrenOffsets.shift(), - comments, options ), - body: new Block(ast.body, childrenOffsets.shift(), comments, options) + body: new Block(ast.body, childrenOffsets.shift(), options) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/ContinueStatement.js b/src/slang-nodes/ContinueStatement.js index 3e94e2085..53276339b 100644 --- a/src/slang-nodes/ContinueStatement.js +++ b/src/slang-nodes/ContinueStatement.js @@ -5,7 +5,7 @@ export class ContinueStatement extends SlangNode { semicolon; - constructor(ast, offset, comments) { + constructor(ast, offset) { super(); const fetch = () => ({ @@ -13,7 +13,7 @@ export class ContinueStatement extends SlangNode { semicolon: ast.semicolon.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print() { diff --git a/src/slang-nodes/ContractDefinition.js b/src/slang-nodes/ContractDefinition.js index e577a7fa5..56361dd19 100644 --- a/src/slang-nodes/ContractDefinition.js +++ b/src/slang-nodes/ContractDefinition.js @@ -22,7 +22,7 @@ export class ContractDefinition extends SlangNode { closeBrace; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -33,7 +33,6 @@ export class ContractDefinition extends SlangNode { ? new InheritanceSpecifier( ast.inheritance, childrenOffsets.shift(), - comments, options ) : undefined, @@ -41,13 +40,12 @@ export class ContractDefinition extends SlangNode { members: new ContractMembers( ast.members, childrenOffsets.shift(), - comments, options ), closeBrace: ast.closeBrace.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); this.cleanModifierInvocationArguments(options); } diff --git a/src/slang-nodes/ContractMember.js b/src/slang-nodes/ContractMember.js index 01a05eea1..2bb7f7f9f 100644 --- a/src/slang-nodes/ContractMember.js +++ b/src/slang-nodes/ContractMember.js @@ -32,19 +32,18 @@ const variants = { export class ContractMember extends SlangNode { variant; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ variant: new variants[ast.variant.cst.kind]( ast.variant, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/ContractMembers.js b/src/slang-nodes/ContractMembers.js index 369582ebf..1f7b481aa 100644 --- a/src/slang-nodes/ContractMembers.js +++ b/src/slang-nodes/ContractMembers.js @@ -10,17 +10,16 @@ const { hardline } = doc.builders; export class ContractMembers extends SlangNode { items; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( - (item) => - new ContractMember(item, childrenOffsets.shift(), comments, options) + (item) => new ContractMember(item, childrenOffsets.shift(), options) ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print, options) { diff --git a/src/slang-nodes/DecimalNumberExpression.js b/src/slang-nodes/DecimalNumberExpression.js index 9cc9d8370..990820cd3 100644 --- a/src/slang-nodes/DecimalNumberExpression.js +++ b/src/slang-nodes/DecimalNumberExpression.js @@ -6,17 +6,17 @@ export class DecimalNumberExpression extends SlangNode { unit; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ literal: ast.literal.text, unit: ast.unit - ? new NumberUnit(ast.unit, childrenOffsets.shift(), comments, options) + ? new NumberUnit(ast.unit, childrenOffsets.shift(), options) : undefined }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/DoWhileStatement.js b/src/slang-nodes/DoWhileStatement.js index baec56ee6..63881d85c 100644 --- a/src/slang-nodes/DoWhileStatement.js +++ b/src/slang-nodes/DoWhileStatement.js @@ -21,25 +21,24 @@ export class DoWhileStatement extends SlangNode { semicolon; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ doKeyword: ast.doKeyword.text, - body: new Statement(ast.body, childrenOffsets.shift(), comments, options), + body: new Statement(ast.body, childrenOffsets.shift(), options), whileKeyword: ast.whileKeyword.text, openParen: ast.openParen.text, condition: new Expression( ast.condition, childrenOffsets.shift(), - comments, options ), closeParen: ast.closeParen.text, semicolon: ast.semicolon.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/ElementaryType.js b/src/slang-nodes/ElementaryType.js index 008f89235..0ed9b9d9f 100644 --- a/src/slang-nodes/ElementaryType.js +++ b/src/slang-nodes/ElementaryType.js @@ -4,22 +4,17 @@ import { AddressType } from './AddressType.js'; export class ElementaryType extends SlangNode { variant; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text - : new AddressType( - ast.variant, - childrenOffsets.shift(), - comments, - options - ) + : new AddressType(ast.variant, childrenOffsets.shift(), options) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/ElseBranch.js b/src/slang-nodes/ElseBranch.js index a7ad13871..94febb337 100644 --- a/src/slang-nodes/ElseBranch.js +++ b/src/slang-nodes/ElseBranch.js @@ -12,15 +12,15 @@ export class ElseBranch extends SlangNode { body; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ elseKeyword: ast.elseKeyword.text, - body: new Statement(ast.body, childrenOffsets.shift(), comments, options) + body: new Statement(ast.body, childrenOffsets.shift(), options) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/EmitStatement.js b/src/slang-nodes/EmitStatement.js index b42ddccba..bf30cca5d 100644 --- a/src/slang-nodes/EmitStatement.js +++ b/src/slang-nodes/EmitStatement.js @@ -11,27 +11,21 @@ export class EmitStatement extends SlangNode { semicolon; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ emitKeyword: ast.emitKeyword.text, - event: new IdentifierPath( - ast.event, - childrenOffsets.shift(), - comments, - options - ), + event: new IdentifierPath(ast.event, childrenOffsets.shift(), options), arguments: new ArgumentsDeclaration( ast.arguments, childrenOffsets.shift(), - comments, options ), semicolon: ast.semicolon.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/EnumDefinition.js b/src/slang-nodes/EnumDefinition.js index ce69ce3f6..8be32762e 100644 --- a/src/slang-nodes/EnumDefinition.js +++ b/src/slang-nodes/EnumDefinition.js @@ -12,23 +12,18 @@ export class EnumDefinition extends SlangNode { closeBrace; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ enumKeyword: ast.enumKeyword.text, name: ast.name.text, openBrace: ast.openBrace.text, - members: new EnumMembers( - ast.members, - childrenOffsets.shift(), - comments, - options - ), + members: new EnumMembers(ast.members, childrenOffsets.shift(), options), closeBrace: ast.closeBrace.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/EnumMembers.js b/src/slang-nodes/EnumMembers.js index bd679a857..aa33ccf9f 100644 --- a/src/slang-nodes/EnumMembers.js +++ b/src/slang-nodes/EnumMembers.js @@ -9,7 +9,7 @@ export class EnumMembers extends SlangNode { separators; - constructor(ast, offset, comments) { + constructor(ast, offset) { super(); const fetch = () => ({ @@ -17,7 +17,7 @@ export class EnumMembers extends SlangNode { separators: ast.separators.map((separator) => separator.text) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print() { diff --git a/src/slang-nodes/EqualityExpression.js b/src/slang-nodes/EqualityExpression.js index e03ca39bb..2333a6629 100644 --- a/src/slang-nodes/EqualityExpression.js +++ b/src/slang-nodes/EqualityExpression.js @@ -9,26 +9,24 @@ export class EqualityExpression extends SlangNode { rightOperand; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ leftOperand: new Expression( ast.leftOperand, childrenOffsets.shift(), - comments, options ), operator: ast.operator.text, rightOperand: new Expression( ast.rightOperand, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print, options) { diff --git a/src/slang-nodes/ErrorDefinition.js b/src/slang-nodes/ErrorDefinition.js index 27a9ee616..b107d21a1 100644 --- a/src/slang-nodes/ErrorDefinition.js +++ b/src/slang-nodes/ErrorDefinition.js @@ -10,7 +10,7 @@ export class ErrorDefinition extends SlangNode { semicolon; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -19,13 +19,12 @@ export class ErrorDefinition extends SlangNode { members: new ErrorParametersDeclaration( ast.members, childrenOffsets.shift(), - comments, options ), semicolon: ast.semicolon.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/ErrorParameter.js b/src/slang-nodes/ErrorParameter.js index 8d920effb..fcb703de9 100644 --- a/src/slang-nodes/ErrorParameter.js +++ b/src/slang-nodes/ErrorParameter.js @@ -6,20 +6,15 @@ export class ErrorParameter extends SlangNode { name; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ - typeName: new TypeName( - ast.typeName, - childrenOffsets.shift(), - comments, - options - ), + typeName: new TypeName(ast.typeName, childrenOffsets.shift(), options), name: ast.name?.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/ErrorParameters.js b/src/slang-nodes/ErrorParameters.js index 9f266ebd4..f85cbf69e 100644 --- a/src/slang-nodes/ErrorParameters.js +++ b/src/slang-nodes/ErrorParameters.js @@ -7,18 +7,17 @@ export class ErrorParameters extends SlangNode { separators; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( - (item) => - new ErrorParameter(item, childrenOffsets.shift(), comments, options) + (item) => new ErrorParameter(item, childrenOffsets.shift(), options) ), separators: ast.separators.map((separator) => separator.text) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/ErrorParametersDeclaration.js b/src/slang-nodes/ErrorParametersDeclaration.js index 35bed0b09..2a19d2c49 100644 --- a/src/slang-nodes/ErrorParametersDeclaration.js +++ b/src/slang-nodes/ErrorParametersDeclaration.js @@ -8,7 +8,7 @@ export class ErrorParametersDeclaration extends SlangNode { closeParen; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -16,13 +16,12 @@ export class ErrorParametersDeclaration extends SlangNode { parameters: new ErrorParameters( ast.parameters, childrenOffsets.shift(), - comments, options ), closeParen: ast.closeParen.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/EventDefinition.js b/src/slang-nodes/EventDefinition.js index 80883853c..900fb6abd 100644 --- a/src/slang-nodes/EventDefinition.js +++ b/src/slang-nodes/EventDefinition.js @@ -12,7 +12,7 @@ export class EventDefinition extends SlangNode { semicolon; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -21,14 +21,13 @@ export class EventDefinition extends SlangNode { parameters: new EventParametersDeclaration( ast.parameters, childrenOffsets.shift(), - comments, options ), anonymousKeyword: ast.anonymousKeyword?.text, semicolon: ast.semicolon.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/EventParameter.js b/src/slang-nodes/EventParameter.js index 4ea5ba194..c465adbdf 100644 --- a/src/slang-nodes/EventParameter.js +++ b/src/slang-nodes/EventParameter.js @@ -8,21 +8,16 @@ export class EventParameter extends SlangNode { name; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ - typeName: new TypeName( - ast.typeName, - childrenOffsets.shift(), - comments, - options - ), + typeName: new TypeName(ast.typeName, childrenOffsets.shift(), options), indexedKeyword: ast.indexedKeyword?.text, name: ast.name?.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/EventParameters.js b/src/slang-nodes/EventParameters.js index 360656c22..381159d3c 100644 --- a/src/slang-nodes/EventParameters.js +++ b/src/slang-nodes/EventParameters.js @@ -7,18 +7,17 @@ export class EventParameters extends SlangNode { separators; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( - (item) => - new EventParameter(item, childrenOffsets.shift(), comments, options) + (item) => new EventParameter(item, childrenOffsets.shift(), options) ), separators: ast.separators.map((separator) => separator.text) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/EventParametersDeclaration.js b/src/slang-nodes/EventParametersDeclaration.js index 6305b170f..967045df2 100644 --- a/src/slang-nodes/EventParametersDeclaration.js +++ b/src/slang-nodes/EventParametersDeclaration.js @@ -8,7 +8,7 @@ export class EventParametersDeclaration extends SlangNode { closeParen; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -16,13 +16,12 @@ export class EventParametersDeclaration extends SlangNode { parameters: new EventParameters( ast.parameters, childrenOffsets.shift(), - comments, options ), closeParen: ast.closeParen.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/ExperimentalFeature.js b/src/slang-nodes/ExperimentalFeature.js index ce7002f67..7ce26c51d 100644 --- a/src/slang-nodes/ExperimentalFeature.js +++ b/src/slang-nodes/ExperimentalFeature.js @@ -4,22 +4,17 @@ import { StringLiteral } from './StringLiteral.js'; export class ExperimentalFeature extends SlangNode { variant; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text - : new StringLiteral( - ast.variant, - childrenOffsets.shift(), - comments, - options - ) + : new StringLiteral(ast.variant, childrenOffsets.shift(), options) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/ExperimentalPragma.js b/src/slang-nodes/ExperimentalPragma.js index e38a64410..d8a6c4723 100644 --- a/src/slang-nodes/ExperimentalPragma.js +++ b/src/slang-nodes/ExperimentalPragma.js @@ -6,7 +6,7 @@ export class ExperimentalPragma extends SlangNode { feature; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -14,12 +14,11 @@ export class ExperimentalPragma extends SlangNode { feature: new ExperimentalFeature( ast.feature, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/ExponentiationExpression.js b/src/slang-nodes/ExponentiationExpression.js index 6e33a6cbc..5f6585e99 100644 --- a/src/slang-nodes/ExponentiationExpression.js +++ b/src/slang-nodes/ExponentiationExpression.js @@ -25,7 +25,7 @@ export class ExponentiationExpression extends SlangNode { rightOperand; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); if (offset) { @@ -33,19 +33,17 @@ export class ExponentiationExpression extends SlangNode { leftOperand: new Expression( ast.leftOperand, childrenOffsets.shift(), - comments, options ), operator: ast.operator.text, rightOperand: new Expression( ast.rightOperand, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); const compiler = coerce(options.compiler); if (compiler) { diff --git a/src/slang-nodes/Expression.js b/src/slang-nodes/Expression.js index fcc898e18..bbdd555d4 100644 --- a/src/slang-nodes/Expression.js +++ b/src/slang-nodes/Expression.js @@ -60,7 +60,7 @@ const variants = { export class Expression extends SlangNode { variant; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); if (offset) { @@ -71,12 +71,11 @@ export class Expression extends SlangNode { : new variants[ast.variant.cst.kind]( ast.variant, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/ExpressionStatement.js b/src/slang-nodes/ExpressionStatement.js index 23e7b9cb6..75a6cacd1 100644 --- a/src/slang-nodes/ExpressionStatement.js +++ b/src/slang-nodes/ExpressionStatement.js @@ -6,20 +6,19 @@ export class ExpressionStatement extends SlangNode { semicolon; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ expression: new Expression( ast.expression, childrenOffsets.shift(), - comments, options ), semicolon: ast.semicolon.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/FallbackFunctionAttribute.js b/src/slang-nodes/FallbackFunctionAttribute.js index 4182eed82..80a06f453 100644 --- a/src/slang-nodes/FallbackFunctionAttribute.js +++ b/src/slang-nodes/FallbackFunctionAttribute.js @@ -7,7 +7,7 @@ const variants = { ModifierInvocation, OverrideSpecifier }; export class FallbackFunctionAttribute extends SlangNode { variant; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -17,12 +17,11 @@ export class FallbackFunctionAttribute extends SlangNode { : new variants[ast.variant.cst.kind]( ast.variant, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/FallbackFunctionAttributes.js b/src/slang-nodes/FallbackFunctionAttributes.js index 13825a896..4282f2a66 100644 --- a/src/slang-nodes/FallbackFunctionAttributes.js +++ b/src/slang-nodes/FallbackFunctionAttributes.js @@ -8,22 +8,17 @@ const { line } = doc.builders; export class FallbackFunctionAttributes extends SlangNode { items; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( (item) => - new FallbackFunctionAttribute( - item, - childrenOffsets.shift(), - comments, - options - ) + new FallbackFunctionAttribute(item, childrenOffsets.shift(), options) ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); this.items = this.items.sort(sortFunctionAttributes); } diff --git a/src/slang-nodes/FallbackFunctionDefinition.js b/src/slang-nodes/FallbackFunctionDefinition.js index 9d2724ac1..8c508ed10 100644 --- a/src/slang-nodes/FallbackFunctionDefinition.js +++ b/src/slang-nodes/FallbackFunctionDefinition.js @@ -16,7 +16,7 @@ export class FallbackFunctionDefinition extends SlangNode { body; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -24,32 +24,20 @@ export class FallbackFunctionDefinition extends SlangNode { parameters: new ParametersDeclaration( ast.parameters, childrenOffsets.shift(), - comments, options ), attributes: new FallbackFunctionAttributes( ast.attributes, childrenOffsets.shift(), - comments, options ), returns: ast.returns - ? new ReturnsDeclaration( - ast.returns, - childrenOffsets.shift(), - comments, - options - ) + ? new ReturnsDeclaration(ast.returns, childrenOffsets.shift(), options) : undefined, - body: new FunctionBody( - ast.body, - childrenOffsets.shift(), - comments, - options - ) + body: new FunctionBody(ast.body, childrenOffsets.shift(), options) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); this.cleanModifierInvocationArguments(); } diff --git a/src/slang-nodes/ForStatement.js b/src/slang-nodes/ForStatement.js index 43d76877e..ffa1d3404 100644 --- a/src/slang-nodes/ForStatement.js +++ b/src/slang-nodes/ForStatement.js @@ -23,7 +23,7 @@ export class ForStatement extends SlangNode { body; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -32,28 +32,21 @@ export class ForStatement extends SlangNode { initialization: new ForStatementInitialization( ast.initialization, childrenOffsets.shift(), - comments, options ), condition: new ForStatementCondition( ast.condition, childrenOffsets.shift(), - comments, options ), iterator: ast.iterator - ? new Expression( - ast.iterator, - childrenOffsets.shift(), - comments, - options - ) + ? new Expression(ast.iterator, childrenOffsets.shift(), options) : undefined, closeParen: ast.closeParen.text, - body: new Statement(ast.body, childrenOffsets.shift(), comments, options) + body: new Statement(ast.body, childrenOffsets.shift(), options) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/ForStatementCondition.js b/src/slang-nodes/ForStatementCondition.js index 46ab1fd5c..ec1e29f47 100644 --- a/src/slang-nodes/ForStatementCondition.js +++ b/src/slang-nodes/ForStatementCondition.js @@ -4,7 +4,7 @@ import { ExpressionStatement } from './ExpressionStatement.js'; export class ForStatementCondition extends SlangNode { variant; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -14,12 +14,11 @@ export class ForStatementCondition extends SlangNode { : new ExpressionStatement( ast.variant, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/ForStatementInitialization.js b/src/slang-nodes/ForStatementInitialization.js index 5c8b14816..af56c8f0f 100644 --- a/src/slang-nodes/ForStatementInitialization.js +++ b/src/slang-nodes/ForStatementInitialization.js @@ -12,7 +12,7 @@ const variants = { export class ForStatementInitialization extends SlangNode { variant; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -22,12 +22,11 @@ export class ForStatementInitialization extends SlangNode { : new variants[ast.variant.cst.kind]( ast.variant, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/FunctionAttribute.js b/src/slang-nodes/FunctionAttribute.js index 2dd3dbdc3..08a467082 100644 --- a/src/slang-nodes/FunctionAttribute.js +++ b/src/slang-nodes/FunctionAttribute.js @@ -7,7 +7,7 @@ const variants = { ModifierInvocation, OverrideSpecifier }; export class FunctionAttribute extends SlangNode { variant; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -17,12 +17,11 @@ export class FunctionAttribute extends SlangNode { : new variants[ast.variant.cst.kind]( ast.variant, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/FunctionAttributes.js b/src/slang-nodes/FunctionAttributes.js index ebc3edb40..c16c71962 100644 --- a/src/slang-nodes/FunctionAttributes.js +++ b/src/slang-nodes/FunctionAttributes.js @@ -8,22 +8,16 @@ const { line } = doc.builders; export class FunctionAttributes extends SlangNode { items; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( - (item) => - new FunctionAttribute( - item, - childrenOffsets.shift(), - comments, - options - ) + (item) => new FunctionAttribute(item, childrenOffsets.shift(), options) ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); this.items = this.items.sort(sortFunctionAttributes); } diff --git a/src/slang-nodes/FunctionBody.js b/src/slang-nodes/FunctionBody.js index 3159438d3..2076651f0 100644 --- a/src/slang-nodes/FunctionBody.js +++ b/src/slang-nodes/FunctionBody.js @@ -4,17 +4,17 @@ import { Block } from './Block.js'; export class FunctionBody extends SlangNode { variant; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text - : new Block(ast.variant, childrenOffsets.shift(), comments, options) + : new Block(ast.variant, childrenOffsets.shift(), options) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/FunctionCallExpression.js b/src/slang-nodes/FunctionCallExpression.js index 4a8b6c86f..69e35f1f2 100644 --- a/src/slang-nodes/FunctionCallExpression.js +++ b/src/slang-nodes/FunctionCallExpression.js @@ -11,25 +11,19 @@ export class FunctionCallExpression extends SlangNode { arguments; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ - operand: new Expression( - ast.operand, - childrenOffsets.shift(), - comments, - options - ), + operand: new Expression(ast.operand, childrenOffsets.shift(), options), arguments: new ArgumentsDeclaration( ast.arguments, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/FunctionDefinition.js b/src/slang-nodes/FunctionDefinition.js index 72fe91249..64a05aab3 100644 --- a/src/slang-nodes/FunctionDefinition.js +++ b/src/slang-nodes/FunctionDefinition.js @@ -21,46 +21,29 @@ export class FunctionDefinition extends SlangNode { body; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ functionKeyword: ast.functionKeyword.text, - name: new FunctionName( - ast.name, - childrenOffsets.shift(), - comments, - options - ), + name: new FunctionName(ast.name, childrenOffsets.shift(), options), parameters: new ParametersDeclaration( ast.parameters, childrenOffsets.shift(), - comments, options ), attributes: new FunctionAttributes( ast.attributes, childrenOffsets.shift(), - comments, options ), returns: ast.returns - ? new ReturnsDeclaration( - ast.returns, - childrenOffsets.shift(), - comments, - options - ) + ? new ReturnsDeclaration(ast.returns, childrenOffsets.shift(), options) : undefined, - body: new FunctionBody( - ast.body, - childrenOffsets.shift(), - comments, - options - ) + body: new FunctionBody(ast.body, childrenOffsets.shift(), options) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); // Older versions of Solidity defined a constructor as a function having // the same name as the contract. diff --git a/src/slang-nodes/FunctionName.js b/src/slang-nodes/FunctionName.js index 5543a0f43..b3fa12e8c 100644 --- a/src/slang-nodes/FunctionName.js +++ b/src/slang-nodes/FunctionName.js @@ -3,14 +3,14 @@ import { SlangNode } from './SlangNode.js'; export class FunctionName extends SlangNode { variant; - constructor(ast, offset, comments) { + constructor(ast, offset) { super(); const fetch = () => ({ variant: ast.variant.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print() { diff --git a/src/slang-nodes/FunctionType.js b/src/slang-nodes/FunctionType.js index d83384410..4bd226f41 100644 --- a/src/slang-nodes/FunctionType.js +++ b/src/slang-nodes/FunctionType.js @@ -13,7 +13,7 @@ export class FunctionType extends SlangNode { returns; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -21,26 +21,19 @@ export class FunctionType extends SlangNode { parameters: new ParametersDeclaration( ast.parameters, childrenOffsets.shift(), - comments, options ), attributes: new FunctionTypeAttributes( ast.attributes, childrenOffsets.shift(), - comments, options ), returns: ast.returns - ? new ReturnsDeclaration( - ast.returns, - childrenOffsets.shift(), - comments, - options - ) + ? new ReturnsDeclaration(ast.returns, childrenOffsets.shift(), options) : undefined }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/FunctionTypeAttribute.js b/src/slang-nodes/FunctionTypeAttribute.js index accc8923a..f4f300f40 100644 --- a/src/slang-nodes/FunctionTypeAttribute.js +++ b/src/slang-nodes/FunctionTypeAttribute.js @@ -3,14 +3,14 @@ import { SlangNode } from './SlangNode.js'; export class FunctionTypeAttribute extends SlangNode { variant; - constructor(ast, offset, comments) { + constructor(ast, offset) { super(); const fetch = () => ({ variant: ast.variant.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print() { diff --git a/src/slang-nodes/FunctionTypeAttributes.js b/src/slang-nodes/FunctionTypeAttributes.js index ab55fdda9..28a3515bb 100644 --- a/src/slang-nodes/FunctionTypeAttributes.js +++ b/src/slang-nodes/FunctionTypeAttributes.js @@ -8,22 +8,17 @@ const { line } = doc.builders; export class FunctionTypeAttributes extends SlangNode { items; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( (item) => - new FunctionTypeAttribute( - item, - childrenOffsets.shift(), - comments, - options - ) + new FunctionTypeAttribute(item, childrenOffsets.shift(), options) ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); this.items = this.items.sort(sortFunctionAttributes); } diff --git a/src/slang-nodes/HexNumberExpression.js b/src/slang-nodes/HexNumberExpression.js index c99e12989..715498b41 100644 --- a/src/slang-nodes/HexNumberExpression.js +++ b/src/slang-nodes/HexNumberExpression.js @@ -6,17 +6,17 @@ export class HexNumberExpression extends SlangNode { unit; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ literal: ast.literal.text, unit: ast.unit - ? new NumberUnit(ast.unit, childrenOffsets.shift(), comments, options) + ? new NumberUnit(ast.unit, childrenOffsets.shift(), options) : undefined }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/HexStringLiteral.js b/src/slang-nodes/HexStringLiteral.js index 9c6c13881..45fedf0d3 100644 --- a/src/slang-nodes/HexStringLiteral.js +++ b/src/slang-nodes/HexStringLiteral.js @@ -4,14 +4,14 @@ import { SlangNode } from './SlangNode.js'; export class HexStringLiteral extends SlangNode { variant; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = () => ({ variant: ast.variant.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); this.variant = `hex${printString(this.variant.slice(4, -1), options)}`; } diff --git a/src/slang-nodes/HexStringLiterals.js b/src/slang-nodes/HexStringLiterals.js index a9fe0a462..c06e74a51 100644 --- a/src/slang-nodes/HexStringLiterals.js +++ b/src/slang-nodes/HexStringLiterals.js @@ -7,17 +7,16 @@ const { join, hardline } = doc.builders; export class HexStringLiterals extends SlangNode { items; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( - (item) => - new HexStringLiteral(item, childrenOffsets.shift(), comments, options) + (item) => new HexStringLiteral(item, childrenOffsets.shift(), options) ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/IdentifierPath.js b/src/slang-nodes/IdentifierPath.js index a777cc51f..a4855ea54 100644 --- a/src/slang-nodes/IdentifierPath.js +++ b/src/slang-nodes/IdentifierPath.js @@ -5,7 +5,7 @@ export class IdentifierPath extends SlangNode { separators; - constructor(ast, offset, comments) { + constructor(ast, offset) { super(); const fetch = () => ({ @@ -13,7 +13,7 @@ export class IdentifierPath extends SlangNode { separators: ast.separators.map((separator) => separator.text) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print() { diff --git a/src/slang-nodes/IfStatement.js b/src/slang-nodes/IfStatement.js index e56c235e0..07b616f97 100644 --- a/src/slang-nodes/IfStatement.js +++ b/src/slang-nodes/IfStatement.js @@ -20,7 +20,7 @@ export class IfStatement extends SlangNode { elseBranch; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -29,22 +29,16 @@ export class IfStatement extends SlangNode { condition: new Expression( ast.condition, childrenOffsets.shift(), - comments, options ), closeParen: ast.closeParen.text, - body: new Statement(ast.body, childrenOffsets.shift(), comments, options), + body: new Statement(ast.body, childrenOffsets.shift(), options), elseBranch: ast.elseBranch - ? new ElseBranch( - ast.elseBranch, - childrenOffsets.shift(), - comments, - options - ) + ? new ElseBranch(ast.elseBranch, childrenOffsets.shift(), options) : undefined }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/ImportAlias.js b/src/slang-nodes/ImportAlias.js index b0adca786..3a05b6641 100644 --- a/src/slang-nodes/ImportAlias.js +++ b/src/slang-nodes/ImportAlias.js @@ -5,7 +5,7 @@ export class ImportAlias extends SlangNode { identifier; - constructor(ast, offset, comments) { + constructor(ast, offset) { super(); const fetch = () => ({ @@ -13,7 +13,7 @@ export class ImportAlias extends SlangNode { identifier: ast.identifier.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print() { diff --git a/src/slang-nodes/ImportClause.js b/src/slang-nodes/ImportClause.js index 067166e92..2ca06a45e 100644 --- a/src/slang-nodes/ImportClause.js +++ b/src/slang-nodes/ImportClause.js @@ -8,19 +8,18 @@ const variants = { PathImport, NamedImport, ImportDeconstruction }; export class ImportClause extends SlangNode { variant; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ variant: new variants[ast.variant.cst.kind]( ast.variant, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/ImportDeconstruction.js b/src/slang-nodes/ImportDeconstruction.js index 93aa845b2..cabb99abc 100644 --- a/src/slang-nodes/ImportDeconstruction.js +++ b/src/slang-nodes/ImportDeconstruction.js @@ -13,7 +13,7 @@ export class ImportDeconstruction extends SlangNode { path; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -21,20 +21,14 @@ export class ImportDeconstruction extends SlangNode { symbols: new ImportDeconstructionSymbols( ast.symbols, childrenOffsets.shift(), - comments, options ), closeBrace: ast.closeBrace.text, fromKeyword: ast.fromKeyword.text, - path: new StringLiteral( - ast.path, - childrenOffsets.shift(), - comments, - options - ) + path: new StringLiteral(ast.path, childrenOffsets.shift(), options) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/ImportDeconstructionSymbol.js b/src/slang-nodes/ImportDeconstructionSymbol.js index 90b9005e3..4fb4e604e 100644 --- a/src/slang-nodes/ImportDeconstructionSymbol.js +++ b/src/slang-nodes/ImportDeconstructionSymbol.js @@ -6,17 +6,17 @@ export class ImportDeconstructionSymbol extends SlangNode { alias; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ name: ast.name.text, alias: ast.alias - ? new ImportAlias(ast.alias, childrenOffsets.shift(), comments, options) + ? new ImportAlias(ast.alias, childrenOffsets.shift(), options) : undefined }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/ImportDeconstructionSymbols.js b/src/slang-nodes/ImportDeconstructionSymbols.js index f6b2be335..b369b20a1 100644 --- a/src/slang-nodes/ImportDeconstructionSymbols.js +++ b/src/slang-nodes/ImportDeconstructionSymbols.js @@ -12,23 +12,18 @@ export class ImportDeconstructionSymbols extends SlangNode { separators; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( (item) => - new ImportDeconstructionSymbol( - item, - childrenOffsets.shift(), - comments, - options - ) + new ImportDeconstructionSymbol(item, childrenOffsets.shift(), options) ), separators: ast.separators.map((separator) => separator.text) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print, options) { diff --git a/src/slang-nodes/ImportDirective.js b/src/slang-nodes/ImportDirective.js index 0c9ff7acd..5640ecdbb 100644 --- a/src/slang-nodes/ImportDirective.js +++ b/src/slang-nodes/ImportDirective.js @@ -8,21 +8,16 @@ export class ImportDirective extends SlangNode { semicolon; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ importKeyword: ast.importKeyword.text, - clause: new ImportClause( - ast.clause, - childrenOffsets.shift(), - comments, - options - ), + clause: new ImportClause(ast.clause, childrenOffsets.shift(), options), semicolon: ast.semicolon.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/IndexAccessEnd.js b/src/slang-nodes/IndexAccessEnd.js index 155bcdcf9..090e9081d 100644 --- a/src/slang-nodes/IndexAccessEnd.js +++ b/src/slang-nodes/IndexAccessEnd.js @@ -6,17 +6,17 @@ export class IndexAccessEnd extends SlangNode { end; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ colon: ast.colon.text, end: ast.end - ? new Expression(ast.end, childrenOffsets.shift(), comments, options) + ? new Expression(ast.end, childrenOffsets.shift(), options) : undefined }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/IndexAccessExpression.js b/src/slang-nodes/IndexAccessExpression.js index 89bd3249d..46e44c8e9 100644 --- a/src/slang-nodes/IndexAccessExpression.js +++ b/src/slang-nodes/IndexAccessExpression.js @@ -17,32 +17,22 @@ export class IndexAccessExpression extends SlangNode { closeBracket; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ - operand: new Expression( - ast.operand, - childrenOffsets.shift(), - comments, - options - ), + operand: new Expression(ast.operand, childrenOffsets.shift(), options), openBracket: ast.openBracket.text, start: ast.start - ? new Expression(ast.start, childrenOffsets.shift(), comments, options) + ? new Expression(ast.start, childrenOffsets.shift(), options) : undefined, end: ast.end - ? new IndexAccessEnd( - ast.end, - childrenOffsets.shift(), - comments, - options - ) + ? new IndexAccessEnd(ast.end, childrenOffsets.shift(), options) : undefined, closeBracket: ast.closeBracket.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/InheritanceSpecifier.js b/src/slang-nodes/InheritanceSpecifier.js index 3b18a0c70..58c8f5d51 100644 --- a/src/slang-nodes/InheritanceSpecifier.js +++ b/src/slang-nodes/InheritanceSpecifier.js @@ -6,20 +6,15 @@ export class InheritanceSpecifier extends SlangNode { types; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ isKeyword: ast.isKeyword?.text, - types: new InheritanceTypes( - ast.types, - childrenOffsets.shift(), - comments, - options - ) + types: new InheritanceTypes(ast.types, childrenOffsets.shift(), options) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/InheritanceType.js b/src/slang-nodes/InheritanceType.js index 6de9ae678..b8089b9d7 100644 --- a/src/slang-nodes/InheritanceType.js +++ b/src/slang-nodes/InheritanceType.js @@ -7,27 +7,25 @@ export class InheritanceType extends SlangNode { arguments; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ typeName: new IdentifierPath( ast.typeName, childrenOffsets.shift(), - comments, options ), arguments: ast.arguments ? new ArgumentsDeclaration( ast.arguments, childrenOffsets.shift(), - comments, options ) : undefined }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/InheritanceTypes.js b/src/slang-nodes/InheritanceTypes.js index f6330a1bf..4548738eb 100644 --- a/src/slang-nodes/InheritanceTypes.js +++ b/src/slang-nodes/InheritanceTypes.js @@ -10,18 +10,17 @@ export class InheritanceTypes extends SlangNode { separators; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( - (item) => - new InheritanceType(item, childrenOffsets.shift(), comments, options) + (item) => new InheritanceType(item, childrenOffsets.shift(), options) ), separators: ast.separators.map((separator) => separator.text) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/InterfaceDefinition.js b/src/slang-nodes/InterfaceDefinition.js index 86b83f35d..13ab049ff 100644 --- a/src/slang-nodes/InterfaceDefinition.js +++ b/src/slang-nodes/InterfaceDefinition.js @@ -18,7 +18,7 @@ export class InterfaceDefinition extends SlangNode { closeBrace; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -28,7 +28,6 @@ export class InterfaceDefinition extends SlangNode { ? new InheritanceSpecifier( ast.inheritance, childrenOffsets.shift(), - comments, options ) : undefined, @@ -36,13 +35,12 @@ export class InterfaceDefinition extends SlangNode { members: new InterfaceMembers( ast.members, childrenOffsets.shift(), - comments, options ), closeBrace: ast.closeBrace.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/InterfaceMembers.js b/src/slang-nodes/InterfaceMembers.js index 158426714..43008feb6 100644 --- a/src/slang-nodes/InterfaceMembers.js +++ b/src/slang-nodes/InterfaceMembers.js @@ -9,17 +9,16 @@ const { hardline } = doc.builders; export class InterfaceMembers extends SlangNode { items; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( - (item) => - new ContractMember(item, childrenOffsets.shift(), comments, options) + (item) => new ContractMember(item, childrenOffsets.shift(), options) ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print, options) { diff --git a/src/slang-nodes/LibraryDefinition.js b/src/slang-nodes/LibraryDefinition.js index 965b50e1a..7a64348ee 100644 --- a/src/slang-nodes/LibraryDefinition.js +++ b/src/slang-nodes/LibraryDefinition.js @@ -15,7 +15,7 @@ export class LibraryDefinition extends SlangNode { closeBrace; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -25,13 +25,12 @@ export class LibraryDefinition extends SlangNode { members: new LibraryMembers( ast.members, childrenOffsets.shift(), - comments, options ), closeBrace: ast.closeBrace.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/LibraryMembers.js b/src/slang-nodes/LibraryMembers.js index b9ade2e7d..c3bec6cdf 100644 --- a/src/slang-nodes/LibraryMembers.js +++ b/src/slang-nodes/LibraryMembers.js @@ -9,17 +9,16 @@ const { hardline } = doc.builders; export class LibraryMembers extends SlangNode { items; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( - (item) => - new ContractMember(item, childrenOffsets.shift(), comments, options) + (item) => new ContractMember(item, childrenOffsets.shift(), options) ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print, options) { diff --git a/src/slang-nodes/MappingKey.js b/src/slang-nodes/MappingKey.js index 124490e84..232619307 100644 --- a/src/slang-nodes/MappingKey.js +++ b/src/slang-nodes/MappingKey.js @@ -6,20 +6,19 @@ export class MappingKey extends SlangNode { name; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ keyType: new MappingKeyType( ast.keyType, childrenOffsets.shift(), - comments, options ), name: ast.name?.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/MappingKeyType.js b/src/slang-nodes/MappingKeyType.js index ba7508d1f..312c306a1 100644 --- a/src/slang-nodes/MappingKeyType.js +++ b/src/slang-nodes/MappingKeyType.js @@ -7,19 +7,18 @@ const variants = { ElementaryType, IdentifierPath }; export class MappingKeyType extends SlangNode { variant; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ variant: new variants[ast.variant.cst.kind]( ast.variant, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/MappingType.js b/src/slang-nodes/MappingType.js index de0864fce..9fa0cd532 100644 --- a/src/slang-nodes/MappingType.js +++ b/src/slang-nodes/MappingType.js @@ -15,29 +15,23 @@ export class MappingType extends SlangNode { closeParen; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ mappingKeyword: ast.mappingKeyword.text, openParen: ast.openParen.text, - keyType: new MappingKey( - ast.keyType, - childrenOffsets.shift(), - comments, - options - ), + keyType: new MappingKey(ast.keyType, childrenOffsets.shift(), options), equalGreaterThan: ast.equalGreaterThan.text, valueType: new MappingValue( ast.valueType, childrenOffsets.shift(), - comments, options ), closeParen: ast.closeParen.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/MappingValue.js b/src/slang-nodes/MappingValue.js index e3420ac15..d97d93548 100644 --- a/src/slang-nodes/MappingValue.js +++ b/src/slang-nodes/MappingValue.js @@ -6,20 +6,15 @@ export class MappingValue extends SlangNode { name; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ - typeName: new TypeName( - ast.typeName, - childrenOffsets.shift(), - comments, - options - ), + typeName: new TypeName(ast.typeName, childrenOffsets.shift(), options), name: ast.name?.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/MemberAccess.js b/src/slang-nodes/MemberAccess.js index d2cf5aff2..e82019923 100644 --- a/src/slang-nodes/MemberAccess.js +++ b/src/slang-nodes/MemberAccess.js @@ -3,14 +3,14 @@ import { SlangNode } from './SlangNode.js'; export class MemberAccess extends SlangNode { variant; - constructor(ast, offset, comments) { + constructor(ast, offset) { super(); const fetch = () => ({ variant: ast.variant.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print() { diff --git a/src/slang-nodes/MemberAccessExpression.js b/src/slang-nodes/MemberAccessExpression.js index 3e8ed1eeb..618a183bd 100644 --- a/src/slang-nodes/MemberAccessExpression.js +++ b/src/slang-nodes/MemberAccessExpression.js @@ -114,26 +114,16 @@ export class MemberAccessExpression extends SlangNode { member; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ - operand: new Expression( - ast.operand, - childrenOffsets.shift(), - comments, - options - ), + operand: new Expression(ast.operand, childrenOffsets.shift(), options), period: ast.period.text, - member: new MemberAccess( - ast.member, - childrenOffsets.shift(), - comments, - options - ) + member: new MemberAccess(ast.member, childrenOffsets.shift(), options) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/ModifierAttribute.js b/src/slang-nodes/ModifierAttribute.js index 76adbdcc4..7827437d6 100644 --- a/src/slang-nodes/ModifierAttribute.js +++ b/src/slang-nodes/ModifierAttribute.js @@ -4,22 +4,17 @@ import { OverrideSpecifier } from './OverrideSpecifier.js'; export class ModifierAttribute extends SlangNode { variant; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text - : new OverrideSpecifier( - ast.variant, - childrenOffsets.shift(), - comments, - options - ) + : new OverrideSpecifier(ast.variant, childrenOffsets.shift(), options) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/ModifierAttributes.js b/src/slang-nodes/ModifierAttributes.js index d144c4c15..7a2a82e07 100644 --- a/src/slang-nodes/ModifierAttributes.js +++ b/src/slang-nodes/ModifierAttributes.js @@ -8,22 +8,16 @@ const { line } = doc.builders; export class ModifierAttributes extends SlangNode { items; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( - (item) => - new ModifierAttribute( - item, - childrenOffsets.shift(), - comments, - options - ) + (item) => new ModifierAttribute(item, childrenOffsets.shift(), options) ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); this.items = this.items.sort(sortFunctionAttributes); } diff --git a/src/slang-nodes/ModifierDefinition.js b/src/slang-nodes/ModifierDefinition.js index 30a07ce86..b15fae81d 100644 --- a/src/slang-nodes/ModifierDefinition.js +++ b/src/slang-nodes/ModifierDefinition.js @@ -16,7 +16,7 @@ export class ModifierDefinition extends SlangNode { body; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -26,25 +26,18 @@ export class ModifierDefinition extends SlangNode { ? new ParametersDeclaration( ast.parameters, childrenOffsets.shift(), - comments, options ) : undefined, attributes: new ModifierAttributes( ast.attributes, childrenOffsets.shift(), - comments, options ), - body: new FunctionBody( - ast.body, - childrenOffsets.shift(), - comments, - options - ) + body: new FunctionBody(ast.body, childrenOffsets.shift(), options) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); if (typeof this.parameters === 'undefined') { const parametersOffset = this.attributes.loc.startWithTrivia; diff --git a/src/slang-nodes/ModifierInvocation.js b/src/slang-nodes/ModifierInvocation.js index ad93014cc..f1fd46063 100644 --- a/src/slang-nodes/ModifierInvocation.js +++ b/src/slang-nodes/ModifierInvocation.js @@ -8,27 +8,21 @@ export class ModifierInvocation extends SlangNode { arguments; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ - name: new IdentifierPath( - ast.name, - childrenOffsets.shift(), - comments, - options - ), + name: new IdentifierPath(ast.name, childrenOffsets.shift(), options), arguments: ast.arguments ? new ArgumentsDeclaration( ast.arguments, childrenOffsets.shift(), - comments, options ) : undefined }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); this.cleanModifierInvocationArguments = () => { if ( diff --git a/src/slang-nodes/MultiplicativeExpression.js b/src/slang-nodes/MultiplicativeExpression.js index 6d126f010..fa3d65cd3 100644 --- a/src/slang-nodes/MultiplicativeExpression.js +++ b/src/slang-nodes/MultiplicativeExpression.js @@ -14,26 +14,24 @@ export class MultiplicativeExpression extends SlangNode { rightOperand; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ leftOperand: new Expression( ast.leftOperand, childrenOffsets.shift(), - comments, options ), operator: ast.operator.text, rightOperand: new Expression( ast.rightOperand, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); switch (this.operator) { case '*': diff --git a/src/slang-nodes/NamedArgument.js b/src/slang-nodes/NamedArgument.js index c683b7d38..fb0a93308 100644 --- a/src/slang-nodes/NamedArgument.js +++ b/src/slang-nodes/NamedArgument.js @@ -8,21 +8,16 @@ export class NamedArgument extends SlangNode { value; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ name: ast.name.text, colon: ast.colon.text, - value: new Expression( - ast.value, - childrenOffsets.shift(), - comments, - options - ) + value: new Expression(ast.value, childrenOffsets.shift(), options) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/NamedArgumentGroup.js b/src/slang-nodes/NamedArgumentGroup.js index 8eb161a2d..a2a769da7 100644 --- a/src/slang-nodes/NamedArgumentGroup.js +++ b/src/slang-nodes/NamedArgumentGroup.js @@ -8,7 +8,7 @@ export class NamedArgumentGroup extends SlangNode { closeBrace; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -16,13 +16,12 @@ export class NamedArgumentGroup extends SlangNode { arguments: new NamedArguments( ast.arguments, childrenOffsets.shift(), - comments, options ), closeBrace: ast.closeBrace.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/NamedArguments.js b/src/slang-nodes/NamedArguments.js index a3a3e0cd6..c72590b13 100644 --- a/src/slang-nodes/NamedArguments.js +++ b/src/slang-nodes/NamedArguments.js @@ -10,18 +10,17 @@ export class NamedArguments extends SlangNode { separators; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( - (item) => - new NamedArgument(item, childrenOffsets.shift(), comments, options) + (item) => new NamedArgument(item, childrenOffsets.shift(), options) ), separators: ast.separators.map((separator) => separator.text) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print, options) { diff --git a/src/slang-nodes/NamedArgumentsDeclaration.js b/src/slang-nodes/NamedArgumentsDeclaration.js index d855f3528..68348903a 100644 --- a/src/slang-nodes/NamedArgumentsDeclaration.js +++ b/src/slang-nodes/NamedArgumentsDeclaration.js @@ -8,7 +8,7 @@ export class NamedArgumentsDeclaration extends SlangNode { closeParen; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -17,14 +17,13 @@ export class NamedArgumentsDeclaration extends SlangNode { ? new NamedArgumentGroup( ast.arguments, childrenOffsets.shift(), - comments, options ) : undefined, closeParen: ast.closeParen.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/NamedImport.js b/src/slang-nodes/NamedImport.js index c6c7d1287..f8086f0c6 100644 --- a/src/slang-nodes/NamedImport.js +++ b/src/slang-nodes/NamedImport.js @@ -11,27 +11,17 @@ export class NamedImport extends SlangNode { path; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ asterisk: ast.asterisk.text, - alias: new ImportAlias( - ast.alias, - childrenOffsets.shift(), - comments, - options - ), + alias: new ImportAlias(ast.alias, childrenOffsets.shift(), options), fromKeyword: ast.fromKeyword.text, - path: new StringLiteral( - ast.path, - childrenOffsets.shift(), - comments, - options - ) + path: new StringLiteral(ast.path, childrenOffsets.shift(), options) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/NewExpression.js b/src/slang-nodes/NewExpression.js index e68d0f313..9d047712b 100644 --- a/src/slang-nodes/NewExpression.js +++ b/src/slang-nodes/NewExpression.js @@ -6,20 +6,15 @@ export class NewExpression extends SlangNode { typeName; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ newKeyword: ast.newKeyword.text, - typeName: new TypeName( - ast.typeName, - childrenOffsets.shift(), - comments, - options - ) + typeName: new TypeName(ast.typeName, childrenOffsets.shift(), options) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/NumberUnit.js b/src/slang-nodes/NumberUnit.js index f5a0a4358..fa7b0b488 100644 --- a/src/slang-nodes/NumberUnit.js +++ b/src/slang-nodes/NumberUnit.js @@ -3,14 +3,14 @@ import { SlangNode } from './SlangNode.js'; export class NumberUnit extends SlangNode { variant; - constructor(ast, offset, comments) { + constructor(ast, offset) { super(); const fetch = () => ({ variant: ast.variant.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print() { diff --git a/src/slang-nodes/OrExpression.js b/src/slang-nodes/OrExpression.js index 52605297e..cc9f3396c 100644 --- a/src/slang-nodes/OrExpression.js +++ b/src/slang-nodes/OrExpression.js @@ -12,26 +12,24 @@ export class OrExpression extends SlangNode { rightOperand; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ leftOperand: new Expression( ast.leftOperand, childrenOffsets.shift(), - comments, options ), operator: ast.operator.text, rightOperand: new Expression( ast.rightOperand, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); this.leftOperand = tryToHug(this.leftOperand); this.rightOperand = tryToHug(this.rightOperand); diff --git a/src/slang-nodes/OverridePaths.js b/src/slang-nodes/OverridePaths.js index 99f006860..b552dca0c 100644 --- a/src/slang-nodes/OverridePaths.js +++ b/src/slang-nodes/OverridePaths.js @@ -6,18 +6,17 @@ export class OverridePaths extends SlangNode { separators; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( - (item) => - new IdentifierPath(item, childrenOffsets.shift(), comments, options) + (item) => new IdentifierPath(item, childrenOffsets.shift(), options) ), separators: ast.separators.map((separator) => separator.text) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } // TODO: implement print diff --git a/src/slang-nodes/OverridePathsDeclaration.js b/src/slang-nodes/OverridePathsDeclaration.js index 32e320edd..9e99e6bee 100644 --- a/src/slang-nodes/OverridePathsDeclaration.js +++ b/src/slang-nodes/OverridePathsDeclaration.js @@ -8,21 +8,16 @@ export class OverridePathsDeclaration extends SlangNode { closeParen; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ openParen: ast.openParen.text, - paths: new OverridePaths( - ast.paths, - childrenOffsets.shift(), - comments, - options - ), + paths: new OverridePaths(ast.paths, childrenOffsets.shift(), options), closeParen: ast.closeParen.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } // TODO: implement print diff --git a/src/slang-nodes/OverrideSpecifier.js b/src/slang-nodes/OverrideSpecifier.js index 4788efdbd..840937f73 100644 --- a/src/slang-nodes/OverrideSpecifier.js +++ b/src/slang-nodes/OverrideSpecifier.js @@ -6,7 +6,7 @@ export class OverrideSpecifier extends SlangNode { overridden; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -15,13 +15,12 @@ export class OverrideSpecifier extends SlangNode { ? new OverridePathsDeclaration( ast.overridden, childrenOffsets.shift(), - comments, options ) : undefined }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/Parameter.js b/src/slang-nodes/Parameter.js index 4f07f5ad7..6cb6401c7 100644 --- a/src/slang-nodes/Parameter.js +++ b/src/slang-nodes/Parameter.js @@ -12,28 +12,22 @@ export class Parameter extends SlangNode { name; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ - typeName: new TypeName( - ast.typeName, - childrenOffsets.shift(), - comments, - options - ), + typeName: new TypeName(ast.typeName, childrenOffsets.shift(), options), storageLocation: ast.storageLocation ? new StorageLocation( ast.storageLocation, childrenOffsets.shift(), - comments, options ) : undefined, name: ast.name?.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/Parameters.js b/src/slang-nodes/Parameters.js index 15bf3d8f9..24563b802 100644 --- a/src/slang-nodes/Parameters.js +++ b/src/slang-nodes/Parameters.js @@ -11,19 +11,18 @@ export class Parameters extends SlangNode { separators; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); if (offset) { const fetch = (childrenOffsets) => ({ items: ast.items.map( - (item) => - new Parameter(item, childrenOffsets.shift(), comments, options) + (item) => new Parameter(item, childrenOffsets.shift(), options) ), separators: ast.separators.map((separator) => separator.text) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/ParametersDeclaration.js b/src/slang-nodes/ParametersDeclaration.js index 98073d0f8..81f0ae436 100644 --- a/src/slang-nodes/ParametersDeclaration.js +++ b/src/slang-nodes/ParametersDeclaration.js @@ -8,7 +8,7 @@ export class ParametersDeclaration extends SlangNode { closeParen; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); if (offset) { @@ -17,13 +17,12 @@ export class ParametersDeclaration extends SlangNode { parameters: new Parameters( ast.parameters, childrenOffsets.shift(), - comments, options ), closeParen: ast.closeParen.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/PathImport.js b/src/slang-nodes/PathImport.js index c6a4f6881..f6dffa20d 100644 --- a/src/slang-nodes/PathImport.js +++ b/src/slang-nodes/PathImport.js @@ -7,22 +7,17 @@ export class PathImport extends SlangNode { alias; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ - path: new StringLiteral( - ast.path, - childrenOffsets.shift(), - comments, - options - ), + path: new StringLiteral(ast.path, childrenOffsets.shift(), options), alias: ast.alias - ? new ImportAlias(ast.alias, childrenOffsets.shift(), comments, options) + ? new ImportAlias(ast.alias, childrenOffsets.shift(), options) : undefined }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/PositionalArguments.js b/src/slang-nodes/PositionalArguments.js index 97d0def06..9e025a2d6 100644 --- a/src/slang-nodes/PositionalArguments.js +++ b/src/slang-nodes/PositionalArguments.js @@ -7,18 +7,17 @@ export class PositionalArguments extends SlangNode { separators; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( - (item) => - new Expression(item, childrenOffsets.shift(), comments, options) + (item) => new Expression(item, childrenOffsets.shift(), options) ), separators: ast.separators.map((separator) => separator.text) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/PositionalArgumentsDeclaration.js b/src/slang-nodes/PositionalArgumentsDeclaration.js index e324b9e6a..be1c6aaeb 100644 --- a/src/slang-nodes/PositionalArgumentsDeclaration.js +++ b/src/slang-nodes/PositionalArgumentsDeclaration.js @@ -8,7 +8,7 @@ export class PositionalArgumentsDeclaration extends SlangNode { closeParen; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -16,13 +16,12 @@ export class PositionalArgumentsDeclaration extends SlangNode { arguments: new PositionalArguments( ast.arguments, childrenOffsets.shift(), - comments, options ), closeParen: ast.closeParen.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/PostfixExpression.js b/src/slang-nodes/PostfixExpression.js index 9fe0093bf..222299eb9 100644 --- a/src/slang-nodes/PostfixExpression.js +++ b/src/slang-nodes/PostfixExpression.js @@ -6,20 +6,15 @@ export class PostfixExpression extends SlangNode { operator; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ - operand: new Expression( - ast.operand, - childrenOffsets.shift(), - comments, - options - ), + operand: new Expression(ast.operand, childrenOffsets.shift(), options), operator: ast.operator.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/Pragma.js b/src/slang-nodes/Pragma.js index 66dbaffce..2e36431ad 100644 --- a/src/slang-nodes/Pragma.js +++ b/src/slang-nodes/Pragma.js @@ -7,19 +7,18 @@ const variants = { ABICoderPragma, ExperimentalPragma, VersionPragma }; export class Pragma extends SlangNode { variant; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ variant: new variants[ast.variant.cst.kind]( ast.variant, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/PragmaDirective.js b/src/slang-nodes/PragmaDirective.js index c0e86fe31..85867e8ed 100644 --- a/src/slang-nodes/PragmaDirective.js +++ b/src/slang-nodes/PragmaDirective.js @@ -8,21 +8,16 @@ export class PragmaDirective extends SlangNode { semicolon; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ pragmaKeyword: ast.pragmaKeyword.text, - pragma: new Pragma( - ast.pragma, - childrenOffsets.shift(), - comments, - options - ), + pragma: new Pragma(ast.pragma, childrenOffsets.shift(), options), semicolon: ast.semicolon.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/PrefixExpression.js b/src/slang-nodes/PrefixExpression.js index 09fdda17c..7aacd75bd 100644 --- a/src/slang-nodes/PrefixExpression.js +++ b/src/slang-nodes/PrefixExpression.js @@ -6,20 +6,15 @@ export class PrefixExpression extends SlangNode { operand; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ operator: ast.operator.text, - operand: new Expression( - ast.operand, - childrenOffsets.shift(), - comments, - options - ) + operand: new Expression(ast.operand, childrenOffsets.shift(), options) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/ReceiveFunctionAttribute.js b/src/slang-nodes/ReceiveFunctionAttribute.js index a0d369455..c5a42d7e4 100644 --- a/src/slang-nodes/ReceiveFunctionAttribute.js +++ b/src/slang-nodes/ReceiveFunctionAttribute.js @@ -7,7 +7,7 @@ const variants = { ModifierInvocation, OverrideSpecifier }; export class ReceiveFunctionAttribute extends SlangNode { variant; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -17,12 +17,11 @@ export class ReceiveFunctionAttribute extends SlangNode { : new variants[ast.variant.cst.kind]( ast.variant, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/ReceiveFunctionAttributes.js b/src/slang-nodes/ReceiveFunctionAttributes.js index f47377fc1..ba86c04c6 100644 --- a/src/slang-nodes/ReceiveFunctionAttributes.js +++ b/src/slang-nodes/ReceiveFunctionAttributes.js @@ -8,22 +8,17 @@ const { line } = doc.builders; export class ReceiveFunctionAttributes extends SlangNode { items; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( (item) => - new ReceiveFunctionAttribute( - item, - childrenOffsets.shift(), - comments, - options - ) + new ReceiveFunctionAttribute(item, childrenOffsets.shift(), options) ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); this.items = this.items.sort(sortFunctionAttributes); } diff --git a/src/slang-nodes/ReceiveFunctionDefinition.js b/src/slang-nodes/ReceiveFunctionDefinition.js index a95f97af1..93fa18098 100644 --- a/src/slang-nodes/ReceiveFunctionDefinition.js +++ b/src/slang-nodes/ReceiveFunctionDefinition.js @@ -13,7 +13,7 @@ export class ReceiveFunctionDefinition extends SlangNode { body; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -21,24 +21,17 @@ export class ReceiveFunctionDefinition extends SlangNode { parameters: new ParametersDeclaration( ast.parameters, childrenOffsets.shift(), - comments, options ), attributes: new ReceiveFunctionAttributes( ast.attributes, childrenOffsets.shift(), - comments, options ), - body: new FunctionBody( - ast.body, - childrenOffsets.shift(), - comments, - options - ) + body: new FunctionBody(ast.body, childrenOffsets.shift(), options) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); this.cleanModifierInvocationArguments(); } diff --git a/src/slang-nodes/ReturnStatement.js b/src/slang-nodes/ReturnStatement.js index 49f5c20f5..e3dfb7559 100644 --- a/src/slang-nodes/ReturnStatement.js +++ b/src/slang-nodes/ReturnStatement.js @@ -22,24 +22,19 @@ export class ReturnStatement extends SlangNode { semicolon; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ returnKeyword: ast.returnKeyword.text, expression: ast.expression - ? new Expression( - ast.expression, - childrenOffsets.shift(), - comments, - options - ) + ? new Expression(ast.expression, childrenOffsets.shift(), options) : undefined, semicolon: ast.semicolon.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print, options) { diff --git a/src/slang-nodes/ReturnsDeclaration.js b/src/slang-nodes/ReturnsDeclaration.js index d58bfae95..a90318671 100644 --- a/src/slang-nodes/ReturnsDeclaration.js +++ b/src/slang-nodes/ReturnsDeclaration.js @@ -9,7 +9,7 @@ export class ReturnsDeclaration extends SlangNode { variables; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -17,12 +17,11 @@ export class ReturnsDeclaration extends SlangNode { variables: new ParametersDeclaration( ast.variables, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/RevertStatement.js b/src/slang-nodes/RevertStatement.js index f2ab1670e..4333ffb28 100644 --- a/src/slang-nodes/RevertStatement.js +++ b/src/slang-nodes/RevertStatement.js @@ -11,29 +11,23 @@ export class RevertStatement extends SlangNode { semicolon; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ revertKeyword: ast.revertKeyword.text, error: ast.error - ? new IdentifierPath( - ast.error, - childrenOffsets.shift(), - comments, - options - ) + ? new IdentifierPath(ast.error, childrenOffsets.shift(), options) : undefined, arguments: new ArgumentsDeclaration( ast.arguments, childrenOffsets.shift(), - comments, options ), semicolon: ast.semicolon.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/ShiftExpression.js b/src/slang-nodes/ShiftExpression.js index 66eba3b56..9919274b5 100644 --- a/src/slang-nodes/ShiftExpression.js +++ b/src/slang-nodes/ShiftExpression.js @@ -21,26 +21,24 @@ export class ShiftExpression extends SlangNode { rightOperand; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ leftOperand: new Expression( ast.leftOperand, childrenOffsets.shift(), - comments, options ), operator: ast.operator.text, rightOperand: new Expression( ast.rightOperand, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); this.leftOperand = tryToHugLeftOperand(this.leftOperand); this.rightOperand = tryToHugRightOperand(this.rightOperand); diff --git a/src/slang-nodes/SlangNode.js b/src/slang-nodes/SlangNode.js index fc5b9bd11..bba9a6e4d 100644 --- a/src/slang-nodes/SlangNode.js +++ b/src/slang-nodes/SlangNode.js @@ -4,6 +4,8 @@ import { getTrailingOffset } from '../slang-utils/get-offsets.js'; +const isNotStringOrUndefined = (node) => + typeof node !== 'string' && typeof node !== 'undefined'; export class SlangNode { kind; @@ -11,28 +13,47 @@ export class SlangNode { comments = []; - initialize(ast, offset, fetch, comments) { + initialize(ast, offset, fetch) { this.kind = ast.cst.kind; // Collect comments and get children offsets. const cstChildren = ast.cst.children(); - const childrenOffsets = getChildrenOffsets(cstChildren, offset, comments); + const childrenOffsets = getChildrenOffsets( + cstChildren, + offset, + this.comments + ); // populate all children nodes - let children; + let properties; this.fetch = () => { - if (children === undefined) { - children = fetch(childrenOffsets); + if (properties === undefined) { + properties = fetch(childrenOffsets); } - return children; + return properties; }; this.fetch(); - const childrenKeys = Object.keys(children); - childrenKeys.forEach((childKey) => { - this[childKey] = children[childKey]; + const propertyKeys = Object.keys(properties); + const propertyValues = Object.values(properties); + propertyKeys.forEach((propertyKey) => { + this[propertyKey] = properties[propertyKey]; + }); + + // Collect comments + const childrenNodes = propertyValues.reduce((slangNodes, property) => { + if (Array.isArray(property)) { + slangNodes.push(...property.filter(isNotStringOrUndefined)); + } else if (isNotStringOrUndefined(property)) { + slangNodes.push(property); + } + return slangNodes; + }, []); + + childrenNodes.forEach((child) => { + this.comments.push(...child.comments.splice(0)); }); // calculate correct loc object @@ -42,8 +63,8 @@ export class SlangNode { let trailingOffset = getTrailingOffset(cstChildren); if (leadingOffset === 0 || trailingOffset === 0) { - for (let i = 0; i < childrenKeys.length; i += 1) { - const childLoc = this[childrenKeys[i]]?.loc; + for (let i = 0; i < propertyKeys.length; i += 1) { + const childLoc = this[propertyKeys[i]]?.loc; if (childLoc) { if ( diff --git a/src/slang-nodes/SourceUnit.js b/src/slang-nodes/SourceUnit.js index 439c87065..0b01d3927 100644 --- a/src/slang-nodes/SourceUnit.js +++ b/src/slang-nodes/SourceUnit.js @@ -7,19 +7,18 @@ const { line } = doc.builders; export class SourceUnit extends SlangNode { members; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ members: new SourceUnitMembers( ast.members, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print, options) { diff --git a/src/slang-nodes/SourceUnitMember.js b/src/slang-nodes/SourceUnitMember.js index 37f53fd37..398bd9487 100644 --- a/src/slang-nodes/SourceUnitMember.js +++ b/src/slang-nodes/SourceUnitMember.js @@ -31,19 +31,18 @@ const variants = { export class SourceUnitMember extends SlangNode { variant; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ variant: new variants[ast.variant.cst.kind]( ast.variant, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/SourceUnitMembers.js b/src/slang-nodes/SourceUnitMembers.js index ed907f69a..5fc4ad9be 100644 --- a/src/slang-nodes/SourceUnitMembers.js +++ b/src/slang-nodes/SourceUnitMembers.js @@ -5,17 +5,16 @@ import { SourceUnitMember } from './SourceUnitMember.js'; export class SourceUnitMembers extends SlangNode { items; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( - (item) => - new SourceUnitMember(item, childrenOffsets.shift(), comments, options) + (item) => new SourceUnitMember(item, childrenOffsets.shift(), options) ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print, options) { diff --git a/src/slang-nodes/StateVariableAttribute.js b/src/slang-nodes/StateVariableAttribute.js index 419eca76d..1afc7cbb5 100644 --- a/src/slang-nodes/StateVariableAttribute.js +++ b/src/slang-nodes/StateVariableAttribute.js @@ -4,22 +4,17 @@ import { OverrideSpecifier } from './OverrideSpecifier.js'; export class StateVariableAttribute extends SlangNode { variant; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text - : new OverrideSpecifier( - ast.variant, - childrenOffsets.shift(), - comments, - options - ) + : new OverrideSpecifier(ast.variant, childrenOffsets.shift(), options) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/StateVariableAttributes.js b/src/slang-nodes/StateVariableAttributes.js index bb739d53f..143ea13c6 100644 --- a/src/slang-nodes/StateVariableAttributes.js +++ b/src/slang-nodes/StateVariableAttributes.js @@ -4,22 +4,17 @@ import { StateVariableAttribute } from './StateVariableAttribute.js'; export class StateVariableAttributes extends SlangNode { items; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( (item) => - new StateVariableAttribute( - item, - childrenOffsets.shift(), - comments, - options - ) + new StateVariableAttribute(item, childrenOffsets.shift(), options) ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/StateVariableDefinition.js b/src/slang-nodes/StateVariableDefinition.js index 21b374d8b..ac80bbefb 100644 --- a/src/slang-nodes/StateVariableDefinition.js +++ b/src/slang-nodes/StateVariableDefinition.js @@ -14,20 +14,14 @@ export class StateVariableDefinition extends SlangNode { semicolon; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ - typeName: new TypeName( - ast.typeName, - childrenOffsets.shift(), - comments, - options - ), + typeName: new TypeName(ast.typeName, childrenOffsets.shift(), options), attributes: new StateVariableAttributes( ast.attributes, childrenOffsets.shift(), - comments, options ), name: ast.name.text, @@ -35,14 +29,13 @@ export class StateVariableDefinition extends SlangNode { ? new StateVariableDefinitionValue( ast.value, childrenOffsets.shift(), - comments, options ) : undefined, semicolon: ast.semicolon.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/StateVariableDefinitionValue.js b/src/slang-nodes/StateVariableDefinitionValue.js index b116794b3..17775252f 100644 --- a/src/slang-nodes/StateVariableDefinitionValue.js +++ b/src/slang-nodes/StateVariableDefinitionValue.js @@ -9,20 +9,15 @@ export class StateVariableDefinitionValue extends SlangNode { value; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ equal: ast.equal.text, - value: new Expression( - ast.value, - childrenOffsets.shift(), - comments, - options - ) + value: new Expression(ast.value, childrenOffsets.shift(), options) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/Statement.js b/src/slang-nodes/Statement.js index 2e7550c1c..851be5398 100644 --- a/src/slang-nodes/Statement.js +++ b/src/slang-nodes/Statement.js @@ -40,19 +40,18 @@ const variants = { export class Statement extends SlangNode { variant; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ variant: new variants[ast.variant.cst.kind]( ast.variant, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/Statements.js b/src/slang-nodes/Statements.js index dba7a63ba..b8c6e04d5 100644 --- a/src/slang-nodes/Statements.js +++ b/src/slang-nodes/Statements.js @@ -10,17 +10,16 @@ const { hardline } = doc.builders; export class Statements extends SlangNode { items; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( - (item) => - new Statement(item, childrenOffsets.shift(), comments, options) + (item) => new Statement(item, childrenOffsets.shift(), options) ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print, options) { diff --git a/src/slang-nodes/StorageLocation.js b/src/slang-nodes/StorageLocation.js index fb8a72ec0..bc6127007 100644 --- a/src/slang-nodes/StorageLocation.js +++ b/src/slang-nodes/StorageLocation.js @@ -3,14 +3,14 @@ import { SlangNode } from './SlangNode.js'; export class StorageLocation extends SlangNode { variant; - constructor(ast, offset, comments) { + constructor(ast, offset) { super(); const fetch = () => ({ variant: ast.variant.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print() { diff --git a/src/slang-nodes/StringExpression.js b/src/slang-nodes/StringExpression.js index 49c97fceb..cabeaa2fe 100644 --- a/src/slang-nodes/StringExpression.js +++ b/src/slang-nodes/StringExpression.js @@ -16,19 +16,18 @@ const variants = { export class StringExpression extends SlangNode { variant; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ variant: new variants[ast.variant.cst.kind]( ast.variant, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/StringLiteral.js b/src/slang-nodes/StringLiteral.js index 576bc76ea..fad052768 100644 --- a/src/slang-nodes/StringLiteral.js +++ b/src/slang-nodes/StringLiteral.js @@ -4,14 +4,14 @@ import { SlangNode } from './SlangNode.js'; export class StringLiteral extends SlangNode { variant; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = () => ({ variant: ast.variant.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); this.variant = printString(this.variant.slice(1, -1), options); } diff --git a/src/slang-nodes/StringLiterals.js b/src/slang-nodes/StringLiterals.js index 103c6606a..3c15732f8 100644 --- a/src/slang-nodes/StringLiterals.js +++ b/src/slang-nodes/StringLiterals.js @@ -7,17 +7,16 @@ const { join, hardline } = doc.builders; export class StringLiterals extends SlangNode { items; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( - (item) => - new StringLiteral(item, childrenOffsets.shift(), comments, options) + (item) => new StringLiteral(item, childrenOffsets.shift(), options) ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/StructDefinition.js b/src/slang-nodes/StructDefinition.js index 3caac54ea..be744d0bd 100644 --- a/src/slang-nodes/StructDefinition.js +++ b/src/slang-nodes/StructDefinition.js @@ -12,23 +12,18 @@ export class StructDefinition extends SlangNode { closeBrace; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ structKeyword: ast.structKeyword.text, name: ast.name.text, openBrace: ast.openBrace.text, - members: new StructMembers( - ast.members, - childrenOffsets.shift(), - comments, - options - ), + members: new StructMembers(ast.members, childrenOffsets.shift(), options), closeBrace: ast.closeBrace.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/StructMember.js b/src/slang-nodes/StructMember.js index fed939a28..d7e26d654 100644 --- a/src/slang-nodes/StructMember.js +++ b/src/slang-nodes/StructMember.js @@ -8,21 +8,16 @@ export class StructMember extends SlangNode { semicolon; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ - typeName: new TypeName( - ast.typeName, - childrenOffsets.shift(), - comments, - options - ), + typeName: new TypeName(ast.typeName, childrenOffsets.shift(), options), name: ast.name.text, semicolon: ast.semicolon.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/StructMembers.js b/src/slang-nodes/StructMembers.js index edca9e054..1b5c34acb 100644 --- a/src/slang-nodes/StructMembers.js +++ b/src/slang-nodes/StructMembers.js @@ -8,17 +8,16 @@ const { hardline } = doc.builders; export class StructMembers extends SlangNode { items; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( - (item) => - new StructMember(item, childrenOffsets.shift(), comments, options) + (item) => new StructMember(item, childrenOffsets.shift(), options) ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/ThrowStatement.js b/src/slang-nodes/ThrowStatement.js index 2bc2c38bb..b5bd19574 100644 --- a/src/slang-nodes/ThrowStatement.js +++ b/src/slang-nodes/ThrowStatement.js @@ -5,7 +5,7 @@ export class ThrowStatement extends SlangNode { semicolon; - constructor(ast, offset, comments) { + constructor(ast, offset) { super(); const fetch = () => ({ @@ -13,7 +13,7 @@ export class ThrowStatement extends SlangNode { semicolon: ast.semicolon.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } // TODO: implement print diff --git a/src/slang-nodes/TryStatement.js b/src/slang-nodes/TryStatement.js index 2321c50eb..7e6c74394 100644 --- a/src/slang-nodes/TryStatement.js +++ b/src/slang-nodes/TryStatement.js @@ -19,7 +19,7 @@ export class TryStatement extends SlangNode { catchClauses; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -27,27 +27,20 @@ export class TryStatement extends SlangNode { expression: new Expression( ast.expression, childrenOffsets.shift(), - comments, options ), returns: ast.returns - ? new ReturnsDeclaration( - ast.returns, - childrenOffsets.shift(), - comments, - options - ) + ? new ReturnsDeclaration(ast.returns, childrenOffsets.shift(), options) : undefined, - body: new Block(ast.body, childrenOffsets.shift(), comments, options), + body: new Block(ast.body, childrenOffsets.shift(), options), catchClauses: new CatchClauses( ast.catchClauses, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/TupleDeconstructionElement.js b/src/slang-nodes/TupleDeconstructionElement.js index acc030793..a2a3318ac 100644 --- a/src/slang-nodes/TupleDeconstructionElement.js +++ b/src/slang-nodes/TupleDeconstructionElement.js @@ -4,21 +4,16 @@ import { TupleMember } from './TupleMember.js'; export class TupleDeconstructionElement extends SlangNode { member; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ member: ast.member - ? new TupleMember( - ast.member, - childrenOffsets.shift(), - comments, - options - ) + ? new TupleMember(ast.member, childrenOffsets.shift(), options) : undefined }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/TupleDeconstructionElements.js b/src/slang-nodes/TupleDeconstructionElements.js index 1fc5f63f2..dbd47e62a 100644 --- a/src/slang-nodes/TupleDeconstructionElements.js +++ b/src/slang-nodes/TupleDeconstructionElements.js @@ -7,23 +7,18 @@ export class TupleDeconstructionElements extends SlangNode { separators; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( (item) => - new TupleDeconstructionElement( - item, - childrenOffsets.shift(), - comments, - options - ) + new TupleDeconstructionElement(item, childrenOffsets.shift(), options) ), separators: ast.separators.map((separator) => separator.text) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/TupleDeconstructionStatement.js b/src/slang-nodes/TupleDeconstructionStatement.js index 78c72691b..7260b6243 100644 --- a/src/slang-nodes/TupleDeconstructionStatement.js +++ b/src/slang-nodes/TupleDeconstructionStatement.js @@ -20,7 +20,7 @@ export class TupleDeconstructionStatement extends SlangNode { semicolon; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -29,7 +29,6 @@ export class TupleDeconstructionStatement extends SlangNode { elements: new TupleDeconstructionElements( ast.elements, childrenOffsets.shift(), - comments, options ), closeParen: ast.closeParen.text, @@ -37,13 +36,12 @@ export class TupleDeconstructionStatement extends SlangNode { expression: new Expression( ast.expression, childrenOffsets.shift(), - comments, options ), semicolon: ast.semicolon.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/TupleExpression.js b/src/slang-nodes/TupleExpression.js index 8e997d695..79802e46c 100644 --- a/src/slang-nodes/TupleExpression.js +++ b/src/slang-nodes/TupleExpression.js @@ -8,22 +8,17 @@ export class TupleExpression extends SlangNode { closeParen; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); if (offset) { const fetch = (childrenOffsets) => ({ openParen: ast.openParen.text, - items: new TupleValues( - ast.items, - childrenOffsets.shift(), - comments, - options - ), + items: new TupleValues(ast.items, childrenOffsets.shift(), options), closeParen: ast.closeParen.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/TupleMember.js b/src/slang-nodes/TupleMember.js index 3e00e7d14..f9809a73d 100644 --- a/src/slang-nodes/TupleMember.js +++ b/src/slang-nodes/TupleMember.js @@ -7,19 +7,18 @@ const variants = { TypedTupleMember, UntypedTupleMember }; export class TupleMember extends SlangNode { variant; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ variant: new variants[ast.variant.cst.kind]( ast.variant, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/TupleValue.js b/src/slang-nodes/TupleValue.js index 796294f5f..7cc940e17 100644 --- a/src/slang-nodes/TupleValue.js +++ b/src/slang-nodes/TupleValue.js @@ -4,22 +4,17 @@ import { Expression } from './Expression.js'; export class TupleValue extends SlangNode { expression; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); if (offset) { const fetch = (childrenOffsets) => ({ expression: ast.expression - ? new Expression( - ast.expression, - childrenOffsets.shift(), - comments, - options - ) + ? new Expression(ast.expression, childrenOffsets.shift(), options) : undefined }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/TupleValues.js b/src/slang-nodes/TupleValues.js index a46d4efff..7d44ba530 100644 --- a/src/slang-nodes/TupleValues.js +++ b/src/slang-nodes/TupleValues.js @@ -8,19 +8,18 @@ export class TupleValues extends SlangNode { separators; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); if (offset) { const fetch = (childrenOffsets) => ({ items: ast.items.map( - (item) => - new TupleValue(item, childrenOffsets.shift(), comments, options) + (item) => new TupleValue(item, childrenOffsets.shift(), options) ), separators: ast.separators.map((separator) => separator.text) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } else { this.kind = ast.kind; this.loc = ast.loc; diff --git a/src/slang-nodes/TypeExpression.js b/src/slang-nodes/TypeExpression.js index b0ca29497..b4ff06556 100644 --- a/src/slang-nodes/TypeExpression.js +++ b/src/slang-nodes/TypeExpression.js @@ -10,22 +10,17 @@ export class TypeExpression extends SlangNode { closeParen; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ typeKeyword: ast.typeKeyword.text, openParen: ast.openParen.text, - typeName: new TypeName( - ast.typeName, - childrenOffsets.shift(), - comments, - options - ), + typeName: new TypeName(ast.typeName, childrenOffsets.shift(), options), closeParen: ast.closeParen.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } // TODO: implement print diff --git a/src/slang-nodes/TypeName.js b/src/slang-nodes/TypeName.js index 9383644fc..19ae954b0 100644 --- a/src/slang-nodes/TypeName.js +++ b/src/slang-nodes/TypeName.js @@ -16,19 +16,18 @@ const variants = { export class TypeName extends SlangNode { variant; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ variant: new variants[ast.variant.cst.kind]( ast.variant, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/TypedTupleMember.js b/src/slang-nodes/TypedTupleMember.js index 787c9fb2e..f154ea2b3 100644 --- a/src/slang-nodes/TypedTupleMember.js +++ b/src/slang-nodes/TypedTupleMember.js @@ -9,28 +9,22 @@ export class TypedTupleMember extends SlangNode { name; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ - typeName: new TypeName( - ast.typeName, - childrenOffsets.shift(), - comments, - options - ), + typeName: new TypeName(ast.typeName, childrenOffsets.shift(), options), storageLocation: ast.storageLocation ? new StorageLocation( ast.storageLocation, childrenOffsets.shift(), - comments, options ) : undefined, name: ast.name.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/UncheckedBlock.js b/src/slang-nodes/UncheckedBlock.js index dbd24c0f8..43e564a0e 100644 --- a/src/slang-nodes/UncheckedBlock.js +++ b/src/slang-nodes/UncheckedBlock.js @@ -6,15 +6,15 @@ export class UncheckedBlock extends SlangNode { block; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ uncheckedKeyword: ast.uncheckedKeyword.text, - block: new Block(ast.block, childrenOffsets.shift(), comments, options) + block: new Block(ast.block, childrenOffsets.shift(), options) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/UnicodeStringLiteral.js b/src/slang-nodes/UnicodeStringLiteral.js index 805bda477..d982b33e5 100644 --- a/src/slang-nodes/UnicodeStringLiteral.js +++ b/src/slang-nodes/UnicodeStringLiteral.js @@ -4,14 +4,14 @@ import { SlangNode } from './SlangNode.js'; export class UnicodeStringLiteral extends SlangNode { variant; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = () => ({ variant: ast.variant.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); this.variant = `unicode${printString(this.variant.slice(8, -1), options)}`; } diff --git a/src/slang-nodes/UnicodeStringLiterals.js b/src/slang-nodes/UnicodeStringLiterals.js index 88224653d..8e002e111 100644 --- a/src/slang-nodes/UnicodeStringLiterals.js +++ b/src/slang-nodes/UnicodeStringLiterals.js @@ -7,22 +7,17 @@ const { join, hardline } = doc.builders; export class UnicodeStringLiterals extends SlangNode { items; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( (item) => - new UnicodeStringLiteral( - item, - childrenOffsets.shift(), - comments, - options - ) + new UnicodeStringLiteral(item, childrenOffsets.shift(), options) ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/UnnamedFunctionAttribute.js b/src/slang-nodes/UnnamedFunctionAttribute.js index b03f7d97e..0c507759d 100644 --- a/src/slang-nodes/UnnamedFunctionAttribute.js +++ b/src/slang-nodes/UnnamedFunctionAttribute.js @@ -4,7 +4,7 @@ import { ModifierInvocation } from './ModifierInvocation.js'; export class UnnamedFunctionAttribute extends SlangNode { variant; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -14,12 +14,11 @@ export class UnnamedFunctionAttribute extends SlangNode { : new ModifierInvocation( ast.variant, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/UnnamedFunctionAttributes.js b/src/slang-nodes/UnnamedFunctionAttributes.js index add642cb5..85ab2a953 100644 --- a/src/slang-nodes/UnnamedFunctionAttributes.js +++ b/src/slang-nodes/UnnamedFunctionAttributes.js @@ -8,22 +8,17 @@ const { line } = doc.builders; export class UnnamedFunctionAttributes extends SlangNode { items; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( (item) => - new UnnamedFunctionAttribute( - item, - childrenOffsets.shift(), - comments, - options - ) + new UnnamedFunctionAttribute(item, childrenOffsets.shift(), options) ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); this.items = this.items.sort(sortFunctionAttributes); } diff --git a/src/slang-nodes/UnnamedFunctionDefinition.js b/src/slang-nodes/UnnamedFunctionDefinition.js index f27ed185c..c84dbc863 100644 --- a/src/slang-nodes/UnnamedFunctionDefinition.js +++ b/src/slang-nodes/UnnamedFunctionDefinition.js @@ -13,7 +13,7 @@ export class UnnamedFunctionDefinition extends SlangNode { body; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -21,24 +21,17 @@ export class UnnamedFunctionDefinition extends SlangNode { parameters: new ParametersDeclaration( ast.parameters, childrenOffsets.shift(), - comments, options ), attributes: new UnnamedFunctionAttributes( ast.attributes, childrenOffsets.shift(), - comments, options ), - body: new FunctionBody( - ast.body, - childrenOffsets.shift(), - comments, - options - ) + body: new FunctionBody(ast.body, childrenOffsets.shift(), options) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); this.cleanModifierInvocationArguments(); } diff --git a/src/slang-nodes/UntypedTupleMember.js b/src/slang-nodes/UntypedTupleMember.js index ef13cb927..819e86307 100644 --- a/src/slang-nodes/UntypedTupleMember.js +++ b/src/slang-nodes/UntypedTupleMember.js @@ -6,7 +6,7 @@ export class UntypedTupleMember extends SlangNode { name; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -14,14 +14,13 @@ export class UntypedTupleMember extends SlangNode { ? new StorageLocation( ast.storageLocation, childrenOffsets.shift(), - comments, options ) : undefined, name: ast.name.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } // TODO: implement print diff --git a/src/slang-nodes/UserDefinedValueTypeDefinition.js b/src/slang-nodes/UserDefinedValueTypeDefinition.js index 94728b7d9..faf503832 100644 --- a/src/slang-nodes/UserDefinedValueTypeDefinition.js +++ b/src/slang-nodes/UserDefinedValueTypeDefinition.js @@ -12,7 +12,7 @@ export class UserDefinedValueTypeDefinition extends SlangNode { semicolon; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -22,13 +22,12 @@ export class UserDefinedValueTypeDefinition extends SlangNode { valueType: new ElementaryType( ast.valueType, childrenOffsets.shift(), - comments, options ), semicolon: ast.semicolon.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/UsingAlias.js b/src/slang-nodes/UsingAlias.js index 70efc19aa..298f427ec 100644 --- a/src/slang-nodes/UsingAlias.js +++ b/src/slang-nodes/UsingAlias.js @@ -6,7 +6,7 @@ export class UsingAlias extends SlangNode { operator; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -14,12 +14,11 @@ export class UsingAlias extends SlangNode { operator: new UsingOperator( ast.operator, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/UsingClause.js b/src/slang-nodes/UsingClause.js index c36efc18e..5c661ad5e 100644 --- a/src/slang-nodes/UsingClause.js +++ b/src/slang-nodes/UsingClause.js @@ -7,19 +7,18 @@ const variants = { IdentifierPath, UsingDeconstruction }; export class UsingClause extends SlangNode { variant; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ variant: new variants[ast.variant.cst.kind]( ast.variant, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/UsingDeconstruction.js b/src/slang-nodes/UsingDeconstruction.js index 48c6618b6..78ab079fa 100644 --- a/src/slang-nodes/UsingDeconstruction.js +++ b/src/slang-nodes/UsingDeconstruction.js @@ -8,7 +8,7 @@ export class UsingDeconstruction extends SlangNode { closeBrace; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -16,13 +16,12 @@ export class UsingDeconstruction extends SlangNode { symbols: new UsingDeconstructionSymbols( ast.symbols, childrenOffsets.shift(), - comments, options ), closeBrace: ast.closeBrace.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/UsingDeconstructionSymbol.js b/src/slang-nodes/UsingDeconstructionSymbol.js index 7149d0628..00f745c15 100644 --- a/src/slang-nodes/UsingDeconstructionSymbol.js +++ b/src/slang-nodes/UsingDeconstructionSymbol.js @@ -7,22 +7,17 @@ export class UsingDeconstructionSymbol extends SlangNode { alias; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ - name: new IdentifierPath( - ast.name, - childrenOffsets.shift(), - comments, - options - ), + name: new IdentifierPath(ast.name, childrenOffsets.shift(), options), alias: ast.alias - ? new UsingAlias(ast.alias, childrenOffsets.shift(), comments, options) + ? new UsingAlias(ast.alias, childrenOffsets.shift(), options) : undefined }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/UsingDeconstructionSymbols.js b/src/slang-nodes/UsingDeconstructionSymbols.js index 3e23d813c..88f4a792b 100644 --- a/src/slang-nodes/UsingDeconstructionSymbols.js +++ b/src/slang-nodes/UsingDeconstructionSymbols.js @@ -10,23 +10,18 @@ export class UsingDeconstructionSymbols extends SlangNode { separators; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( (item) => - new UsingDeconstructionSymbol( - item, - childrenOffsets.shift(), - comments, - options - ) + new UsingDeconstructionSymbol(item, childrenOffsets.shift(), options) ), separators: ast.separators.map((separator) => separator.text) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print, options) { diff --git a/src/slang-nodes/UsingDirective.js b/src/slang-nodes/UsingDirective.js index a394fe75d..d98d952bb 100644 --- a/src/slang-nodes/UsingDirective.js +++ b/src/slang-nodes/UsingDirective.js @@ -15,29 +15,19 @@ export class UsingDirective extends SlangNode { semicolon; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ usingKeyword: ast.usingKeyword.text, - clause: new UsingClause( - ast.clause, - childrenOffsets.shift(), - comments, - options - ), + clause: new UsingClause(ast.clause, childrenOffsets.shift(), options), forKeyword: ast.forKeyword.text, - target: new UsingTarget( - ast.target, - childrenOffsets.shift(), - comments, - options - ), + target: new UsingTarget(ast.target, childrenOffsets.shift(), options), globalKeyword: ast.globalKeyword?.text, semicolon: ast.semicolon.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/UsingOperator.js b/src/slang-nodes/UsingOperator.js index 7dae62ae4..f6c4b30bf 100644 --- a/src/slang-nodes/UsingOperator.js +++ b/src/slang-nodes/UsingOperator.js @@ -3,14 +3,14 @@ import { SlangNode } from './SlangNode.js'; export class UsingOperator extends SlangNode { variant; - constructor(ast, offset, comments) { + constructor(ast, offset) { super(); const fetch = () => ({ variant: ast.variant.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print() { diff --git a/src/slang-nodes/UsingTarget.js b/src/slang-nodes/UsingTarget.js index f01fcfeaa..9862fcfed 100644 --- a/src/slang-nodes/UsingTarget.js +++ b/src/slang-nodes/UsingTarget.js @@ -4,22 +4,17 @@ import { TypeName } from './TypeName.js'; export class UsingTarget extends SlangNode { variant; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text - : new TypeName( - ast.variant, - childrenOffsets.shift(), - comments, - options - ) + : new TypeName(ast.variant, childrenOffsets.shift(), options) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/VariableDeclarationStatement.js b/src/slang-nodes/VariableDeclarationStatement.js index 05974c764..68f71741f 100644 --- a/src/slang-nodes/VariableDeclarationStatement.js +++ b/src/slang-nodes/VariableDeclarationStatement.js @@ -17,21 +17,19 @@ export class VariableDeclarationStatement extends SlangNode { semicolon; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ variableType: new VariableDeclarationType( ast.variableType, childrenOffsets.shift(), - comments, options ), storageLocation: ast.storageLocation ? new StorageLocation( ast.storageLocation, childrenOffsets.shift(), - comments, options ) : undefined, @@ -40,14 +38,13 @@ export class VariableDeclarationStatement extends SlangNode { ? new VariableDeclarationValue( ast.value, childrenOffsets.shift(), - comments, options ) : undefined, semicolon: ast.semicolon.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/VariableDeclarationType.js b/src/slang-nodes/VariableDeclarationType.js index 1601f54e7..4fd4695f4 100644 --- a/src/slang-nodes/VariableDeclarationType.js +++ b/src/slang-nodes/VariableDeclarationType.js @@ -4,22 +4,17 @@ import { TypeName } from './TypeName.js'; export class VariableDeclarationType extends SlangNode { variant; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.type - : new TypeName( - ast.variant, - childrenOffsets.shift(), - comments, - options - ) + : new TypeName(ast.variant, childrenOffsets.shift(), options) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/VariableDeclarationValue.js b/src/slang-nodes/VariableDeclarationValue.js index 7cd8e1c0e..31c72b987 100644 --- a/src/slang-nodes/VariableDeclarationValue.js +++ b/src/slang-nodes/VariableDeclarationValue.js @@ -6,7 +6,7 @@ export class VariableDeclarationValue extends SlangNode { expression; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -14,12 +14,11 @@ export class VariableDeclarationValue extends SlangNode { expression: new Expression( ast.expression, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/VersionComparator.js b/src/slang-nodes/VersionComparator.js index b20957361..ee79c5961 100644 --- a/src/slang-nodes/VersionComparator.js +++ b/src/slang-nodes/VersionComparator.js @@ -5,7 +5,7 @@ export class VersionComparator extends SlangNode { operand; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -13,12 +13,11 @@ export class VersionComparator extends SlangNode { operand: new VersionExpression( ast.operand, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/VersionExpression.js b/src/slang-nodes/VersionExpression.js index 65b46b746..505764cc7 100644 --- a/src/slang-nodes/VersionExpression.js +++ b/src/slang-nodes/VersionExpression.js @@ -12,7 +12,7 @@ const variants = { export class VersionExpression extends SlangNode { variant; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -22,12 +22,11 @@ export class VersionExpression extends SlangNode { : new variants[ast.variant.cst.kind]( ast.variant, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/VersionExpressionSet.js b/src/slang-nodes/VersionExpressionSet.js index 9c81b422f..85d457ca8 100644 --- a/src/slang-nodes/VersionExpressionSet.js +++ b/src/slang-nodes/VersionExpressionSet.js @@ -7,22 +7,16 @@ const { join } = doc.builders; export class VersionExpressionSet extends SlangNode { items; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( - (item) => - new VersionExpression( - item, - childrenOffsets.shift(), - comments, - options - ) + (item) => new VersionExpression(item, childrenOffsets.shift(), options) ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/VersionExpressionSets.js b/src/slang-nodes/VersionExpressionSets.js index e6bcb3202..f592b9dc9 100644 --- a/src/slang-nodes/VersionExpressionSets.js +++ b/src/slang-nodes/VersionExpressionSets.js @@ -6,23 +6,18 @@ export class VersionExpressionSets extends SlangNode { separators; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( (item) => - new VersionExpressionSet( - item, - childrenOffsets.shift(), - comments, - options - ) + new VersionExpressionSet(item, childrenOffsets.shift(), options) ), separators: ast.separators.map((separator) => separator.text) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/VersionPragma.js b/src/slang-nodes/VersionPragma.js index bf2d9c226..d7421b94c 100644 --- a/src/slang-nodes/VersionPragma.js +++ b/src/slang-nodes/VersionPragma.js @@ -6,7 +6,7 @@ export class VersionPragma extends SlangNode { sets; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -14,12 +14,11 @@ export class VersionPragma extends SlangNode { sets: new VersionExpressionSets( ast.sets, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/VersionRange.js b/src/slang-nodes/VersionRange.js index d31db446c..21206d98f 100644 --- a/src/slang-nodes/VersionRange.js +++ b/src/slang-nodes/VersionRange.js @@ -8,26 +8,24 @@ export class VersionRange extends SlangNode { rightOperand; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ leftOperand: new VersionExpression( ast.leftOperand, childrenOffsets.shift(), - comments, options ), operator: ast.operator.text, rightOperand: new VersionExpression( ast.rightOperand, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } // TODO: implement print diff --git a/src/slang-nodes/VersionSpecifiers.js b/src/slang-nodes/VersionSpecifiers.js index 4e37a1a83..9bf722dc2 100644 --- a/src/slang-nodes/VersionSpecifiers.js +++ b/src/slang-nodes/VersionSpecifiers.js @@ -5,7 +5,7 @@ export class VersionSpecifiers extends SlangNode { separators; - constructor(ast, offset, comments) { + constructor(ast, offset) { super(); const fetch = () => ({ @@ -13,7 +13,7 @@ export class VersionSpecifiers extends SlangNode { separators: ast.separators.map((separator) => separator.text) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print() { diff --git a/src/slang-nodes/WhileStatement.js b/src/slang-nodes/WhileStatement.js index fc2f385d2..886ece0e1 100644 --- a/src/slang-nodes/WhileStatement.js +++ b/src/slang-nodes/WhileStatement.js @@ -17,7 +17,7 @@ export class WhileStatement extends SlangNode { body; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -26,14 +26,13 @@ export class WhileStatement extends SlangNode { condition: new Expression( ast.condition, childrenOffsets.shift(), - comments, options ), closeParen: ast.closeParen.text, - body: new Statement(ast.body, childrenOffsets.shift(), comments, options) + body: new Statement(ast.body, childrenOffsets.shift(), options) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/YulArguments.js b/src/slang-nodes/YulArguments.js index bce4daa01..06324d639 100644 --- a/src/slang-nodes/YulArguments.js +++ b/src/slang-nodes/YulArguments.js @@ -7,18 +7,17 @@ export class YulArguments extends SlangNode { separators; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( - (item) => - new YulExpression(item, childrenOffsets.shift(), comments, options) + (item) => new YulExpression(item, childrenOffsets.shift(), options) ), separators: ast.separators.map((separator) => separator.text) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/YulAssignmentOperator.js b/src/slang-nodes/YulAssignmentOperator.js index bda7c4b5d..07a47e364 100644 --- a/src/slang-nodes/YulAssignmentOperator.js +++ b/src/slang-nodes/YulAssignmentOperator.js @@ -4,22 +4,17 @@ import { YulColonEqual } from './YulColonEqual.js'; export class YulAssignmentOperator extends SlangNode { variant; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text - : new YulColonEqual( - ast.variant, - childrenOffsets.shift(), - comments, - options - ) + : new YulColonEqual(ast.variant, childrenOffsets.shift(), options) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/YulBlock.js b/src/slang-nodes/YulBlock.js index da922c2bb..81f13fff2 100644 --- a/src/slang-nodes/YulBlock.js +++ b/src/slang-nodes/YulBlock.js @@ -8,7 +8,7 @@ export class YulBlock extends SlangNode { closeBrace; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -16,13 +16,12 @@ export class YulBlock extends SlangNode { statements: new YulStatements( ast.statements, childrenOffsets.shift(), - comments, options ), closeBrace: ast.closeBrace.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/YulBreakStatement.js b/src/slang-nodes/YulBreakStatement.js index 1299e8a80..728633a52 100644 --- a/src/slang-nodes/YulBreakStatement.js +++ b/src/slang-nodes/YulBreakStatement.js @@ -3,14 +3,14 @@ import { SlangNode } from './SlangNode.js'; export class YulBreakStatement extends SlangNode { breakKeyword; - constructor(ast, offset, comments) { + constructor(ast, offset) { super(); const fetch = () => ({ breakKeyword: ast.breakKeyword.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print() { diff --git a/src/slang-nodes/YulBuiltInFunction.js b/src/slang-nodes/YulBuiltInFunction.js index e6c45cfc1..0f664d4d0 100644 --- a/src/slang-nodes/YulBuiltInFunction.js +++ b/src/slang-nodes/YulBuiltInFunction.js @@ -3,14 +3,14 @@ import { SlangNode } from './SlangNode.js'; export class YulBuiltInFunction extends SlangNode { variant; - constructor(ast, offset, comments) { + constructor(ast, offset) { super(); const fetch = () => ({ variant: ast.variant.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print() { diff --git a/src/slang-nodes/YulColonEqual.js b/src/slang-nodes/YulColonEqual.js index cb8b0f9a0..ab21f8265 100644 --- a/src/slang-nodes/YulColonEqual.js +++ b/src/slang-nodes/YulColonEqual.js @@ -5,7 +5,7 @@ export class YulColonEqual extends SlangNode { equal; - constructor(ast, offset, comments) { + constructor(ast, offset) { super(); const fetch = () => ({ @@ -13,7 +13,7 @@ export class YulColonEqual extends SlangNode { equal: ast.equal.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } // TODO: implement print diff --git a/src/slang-nodes/YulContinueStatement.js b/src/slang-nodes/YulContinueStatement.js index af040d583..81b46bc3b 100644 --- a/src/slang-nodes/YulContinueStatement.js +++ b/src/slang-nodes/YulContinueStatement.js @@ -3,14 +3,14 @@ import { SlangNode } from './SlangNode.js'; export class YulContinueStatement extends SlangNode { continueKeyword; - constructor(ast, offset, comments) { + constructor(ast, offset) { super(); const fetch = () => ({ continueKeyword: ast.continueKeyword.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print() { diff --git a/src/slang-nodes/YulDefaultCase.js b/src/slang-nodes/YulDefaultCase.js index d93b18cb9..0a8fdf35e 100644 --- a/src/slang-nodes/YulDefaultCase.js +++ b/src/slang-nodes/YulDefaultCase.js @@ -6,15 +6,15 @@ export class YulDefaultCase extends SlangNode { body; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ defaultKeyword: ast.defaultKeyword.text, - body: new YulBlock(ast.body, childrenOffsets.shift(), comments, options) + body: new YulBlock(ast.body, childrenOffsets.shift(), options) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/YulExpression.js b/src/slang-nodes/YulExpression.js index 13020a599..1b833594f 100644 --- a/src/slang-nodes/YulExpression.js +++ b/src/slang-nodes/YulExpression.js @@ -14,19 +14,18 @@ const variants = { export class YulExpression extends SlangNode { variant; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ variant: new variants[ast.variant.cst.kind]( ast.variant, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/YulForStatement.js b/src/slang-nodes/YulForStatement.js index c2770ca00..2855317c1 100644 --- a/src/slang-nodes/YulForStatement.js +++ b/src/slang-nodes/YulForStatement.js @@ -13,7 +13,7 @@ export class YulForStatement extends SlangNode { body; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -21,25 +21,18 @@ export class YulForStatement extends SlangNode { initialization: new YulBlock( ast.initialization, childrenOffsets.shift(), - comments, options ), condition: new YulExpression( ast.condition, childrenOffsets.shift(), - comments, options ), - iterator: new YulBlock( - ast.iterator, - childrenOffsets.shift(), - comments, - options - ), - body: new YulBlock(ast.body, childrenOffsets.shift(), comments, options) + iterator: new YulBlock(ast.iterator, childrenOffsets.shift(), options), + body: new YulBlock(ast.body, childrenOffsets.shift(), options) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/YulFunctionCallExpression.js b/src/slang-nodes/YulFunctionCallExpression.js index 75c7f4c6b..220a84d95 100644 --- a/src/slang-nodes/YulFunctionCallExpression.js +++ b/src/slang-nodes/YulFunctionCallExpression.js @@ -11,27 +11,21 @@ export class YulFunctionCallExpression extends SlangNode { closeParen; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ - operand: new YulExpression( - ast.operand, - childrenOffsets.shift(), - comments, - options - ), + operand: new YulExpression(ast.operand, childrenOffsets.shift(), options), openParen: ast.openParen.text, arguments: new YulArguments( ast.arguments, childrenOffsets.shift(), - comments, options ), closeParen: ast.closeParen.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/YulFunctionDefinition.js b/src/slang-nodes/YulFunctionDefinition.js index 3af6c4f17..769c13a77 100644 --- a/src/slang-nodes/YulFunctionDefinition.js +++ b/src/slang-nodes/YulFunctionDefinition.js @@ -14,7 +14,7 @@ export class YulFunctionDefinition extends SlangNode { body; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -23,21 +23,19 @@ export class YulFunctionDefinition extends SlangNode { parameters: new YulParametersDeclaration( ast.parameters, childrenOffsets.shift(), - comments, options ), returns: ast.returns ? new YulReturnsDeclaration( ast.returns, childrenOffsets.shift(), - comments, options ) : undefined, - body: new YulBlock(ast.body, childrenOffsets.shift(), comments, options) + body: new YulBlock(ast.body, childrenOffsets.shift(), options) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/YulIfStatement.js b/src/slang-nodes/YulIfStatement.js index 35a4df355..457db9cfc 100644 --- a/src/slang-nodes/YulIfStatement.js +++ b/src/slang-nodes/YulIfStatement.js @@ -9,7 +9,7 @@ export class YulIfStatement extends SlangNode { body; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -17,13 +17,12 @@ export class YulIfStatement extends SlangNode { condition: new YulExpression( ast.condition, childrenOffsets.shift(), - comments, options ), - body: new YulBlock(ast.body, childrenOffsets.shift(), comments, options) + body: new YulBlock(ast.body, childrenOffsets.shift(), options) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/YulLabel.js b/src/slang-nodes/YulLabel.js index a36fa7076..70253f246 100644 --- a/src/slang-nodes/YulLabel.js +++ b/src/slang-nodes/YulLabel.js @@ -8,7 +8,7 @@ export class YulLabel extends SlangNode { colon; - constructor(ast, offset, comments) { + constructor(ast, offset) { super(); const fetch = () => ({ @@ -16,7 +16,7 @@ export class YulLabel extends SlangNode { colon: ast.colon.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print() { diff --git a/src/slang-nodes/YulLeaveStatement.js b/src/slang-nodes/YulLeaveStatement.js index be7f39d64..a19615afb 100644 --- a/src/slang-nodes/YulLeaveStatement.js +++ b/src/slang-nodes/YulLeaveStatement.js @@ -3,14 +3,14 @@ import { SlangNode } from './SlangNode.js'; export class YulLeaveStatement extends SlangNode { leaveKeyword; - constructor(ast, offset, comments) { + constructor(ast, offset) { super(); const fetch = () => ({ leaveKeyword: ast.leaveKeyword.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } // TODO: implement print diff --git a/src/slang-nodes/YulLiteral.js b/src/slang-nodes/YulLiteral.js index 774cc0db1..58e8164d9 100644 --- a/src/slang-nodes/YulLiteral.js +++ b/src/slang-nodes/YulLiteral.js @@ -7,7 +7,7 @@ const variants = { HexStringLiteral, StringLiteral }; export class YulLiteral extends SlangNode { variant; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -17,12 +17,11 @@ export class YulLiteral extends SlangNode { : new variants[ast.variant.cst.kind]( ast.variant, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/YulParameters.js b/src/slang-nodes/YulParameters.js index 1200f80ea..67984b1a0 100644 --- a/src/slang-nodes/YulParameters.js +++ b/src/slang-nodes/YulParameters.js @@ -6,7 +6,7 @@ export class YulParameters extends SlangNode { separators; - constructor(ast, offset, comments) { + constructor(ast, offset) { super(); const fetch = () => ({ @@ -14,7 +14,7 @@ export class YulParameters extends SlangNode { separators: ast.separators.map((separator) => separator.text) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print() { diff --git a/src/slang-nodes/YulParametersDeclaration.js b/src/slang-nodes/YulParametersDeclaration.js index 91350e309..8f3cbd320 100644 --- a/src/slang-nodes/YulParametersDeclaration.js +++ b/src/slang-nodes/YulParametersDeclaration.js @@ -8,7 +8,7 @@ export class YulParametersDeclaration extends SlangNode { closeParen; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -16,13 +16,12 @@ export class YulParametersDeclaration extends SlangNode { parameters: new YulParameters( ast.parameters, childrenOffsets.shift(), - comments, options ), closeParen: ast.closeParen.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/YulPath.js b/src/slang-nodes/YulPath.js index 2856c17c5..72358e8d1 100644 --- a/src/slang-nodes/YulPath.js +++ b/src/slang-nodes/YulPath.js @@ -6,18 +6,17 @@ export class YulPath extends SlangNode { separators; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( - (item) => - new YulPathComponent(item, childrenOffsets.shift(), comments, options) + (item) => new YulPathComponent(item, childrenOffsets.shift(), options) ), separators: ast.separators.map((separator) => separator.text) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/YulPathComponent.js b/src/slang-nodes/YulPathComponent.js index 0abbcf2cf..034dafa4f 100644 --- a/src/slang-nodes/YulPathComponent.js +++ b/src/slang-nodes/YulPathComponent.js @@ -3,14 +3,14 @@ import { SlangNode } from './SlangNode.js'; export class YulPathComponent extends SlangNode { variant; - constructor(ast, offset, comments) { + constructor(ast, offset) { super(); const fetch = () => ({ variant: ast.variant.text }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print() { diff --git a/src/slang-nodes/YulPaths.js b/src/slang-nodes/YulPaths.js index 26c3ad20b..577b6a7a1 100644 --- a/src/slang-nodes/YulPaths.js +++ b/src/slang-nodes/YulPaths.js @@ -6,17 +6,17 @@ export class YulPaths extends SlangNode { separators; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( - (item) => new YulPath(item, childrenOffsets.shift(), comments, options) + (item) => new YulPath(item, childrenOffsets.shift(), options) ), separators: ast.separators.map((separator) => separator.text) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/YulReturnVariables.js b/src/slang-nodes/YulReturnVariables.js index eacbabf36..43f434cdf 100644 --- a/src/slang-nodes/YulReturnVariables.js +++ b/src/slang-nodes/YulReturnVariables.js @@ -9,7 +9,7 @@ export class YulReturnVariables extends SlangNode { separators; - constructor(ast, offset, comments) { + constructor(ast, offset) { super(); const fetch = () => ({ @@ -17,7 +17,7 @@ export class YulReturnVariables extends SlangNode { separators: ast.separators.map((separator) => separator.text) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print() { diff --git a/src/slang-nodes/YulReturnsDeclaration.js b/src/slang-nodes/YulReturnsDeclaration.js index 759252a5b..72128459a 100644 --- a/src/slang-nodes/YulReturnsDeclaration.js +++ b/src/slang-nodes/YulReturnsDeclaration.js @@ -10,7 +10,7 @@ export class YulReturnsDeclaration extends SlangNode { variables; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -18,12 +18,11 @@ export class YulReturnsDeclaration extends SlangNode { variables: new YulReturnVariables( ast.variables, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/YulStackAssignmentStatement.js b/src/slang-nodes/YulStackAssignmentStatement.js index 19f49b975..4ce38b671 100644 --- a/src/slang-nodes/YulStackAssignmentStatement.js +++ b/src/slang-nodes/YulStackAssignmentStatement.js @@ -7,25 +7,23 @@ export class YulStackAssignmentStatement extends SlangNode { expression; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ assignment: new YulAssignmentOperator( ast.assignment, childrenOffsets.shift(), - comments, options ), expression: new YulExpression( ast.expression, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } // TODO: implement print diff --git a/src/slang-nodes/YulStatement.js b/src/slang-nodes/YulStatement.js index a3a22b9ea..c04034713 100644 --- a/src/slang-nodes/YulStatement.js +++ b/src/slang-nodes/YulStatement.js @@ -32,19 +32,18 @@ const variants = { export class YulStatement extends SlangNode { variant; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ variant: new variants[ast.variant.cst.kind]( ast.variant, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/YulStatements.js b/src/slang-nodes/YulStatements.js index 66a8e974e..456400fe5 100644 --- a/src/slang-nodes/YulStatements.js +++ b/src/slang-nodes/YulStatements.js @@ -10,17 +10,16 @@ const { hardline } = doc.builders; export class YulStatements extends SlangNode { items; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( - (item) => - new YulStatement(item, childrenOffsets.shift(), comments, options) + (item) => new YulStatement(item, childrenOffsets.shift(), options) ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print, options) { diff --git a/src/slang-nodes/YulSwitchCase.js b/src/slang-nodes/YulSwitchCase.js index f54792dcf..cc3f40c82 100644 --- a/src/slang-nodes/YulSwitchCase.js +++ b/src/slang-nodes/YulSwitchCase.js @@ -6,19 +6,18 @@ const variants = { YulDefaultCase, YulValueCase }; export class YulSwitchCase extends SlangNode { variant; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ variant: new variants[ast.variant.cst.kind]( ast.variant, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/YulSwitchCases.js b/src/slang-nodes/YulSwitchCases.js index 4315f9fd1..b0e73f39f 100644 --- a/src/slang-nodes/YulSwitchCases.js +++ b/src/slang-nodes/YulSwitchCases.js @@ -7,17 +7,16 @@ const { hardline, join } = doc.builders; export class YulSwitchCases extends SlangNode { items; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ items: ast.items.map( - (item) => - new YulSwitchCase(item, childrenOffsets.shift(), comments, options) + (item) => new YulSwitchCase(item, childrenOffsets.shift(), options) ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/YulSwitchStatement.js b/src/slang-nodes/YulSwitchStatement.js index 6ac0ebc42..fbb7c0bc9 100644 --- a/src/slang-nodes/YulSwitchStatement.js +++ b/src/slang-nodes/YulSwitchStatement.js @@ -12,7 +12,7 @@ export class YulSwitchStatement extends SlangNode { cases; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -20,18 +20,12 @@ export class YulSwitchStatement extends SlangNode { expression: new YulExpression( ast.expression, childrenOffsets.shift(), - comments, options ), - cases: new YulSwitchCases( - ast.cases, - childrenOffsets.shift(), - comments, - options - ) + cases: new YulSwitchCases(ast.cases, childrenOffsets.shift(), options) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/YulValueCase.js b/src/slang-nodes/YulValueCase.js index 4f4f4de62..ec23a43db 100644 --- a/src/slang-nodes/YulValueCase.js +++ b/src/slang-nodes/YulValueCase.js @@ -9,21 +9,16 @@ export class YulValueCase extends SlangNode { body; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ caseKeyword: ast.caseKeyword.text, - value: new YulLiteral( - ast.value, - childrenOffsets.shift(), - comments, - options - ), - body: new YulBlock(ast.body, childrenOffsets.shift(), comments, options) + value: new YulLiteral(ast.value, childrenOffsets.shift(), options), + body: new YulBlock(ast.body, childrenOffsets.shift(), options) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/YulVariableAssignmentStatement.js b/src/slang-nodes/YulVariableAssignmentStatement.js index 9ec7112bd..edc44b40c 100644 --- a/src/slang-nodes/YulVariableAssignmentStatement.js +++ b/src/slang-nodes/YulVariableAssignmentStatement.js @@ -10,31 +10,24 @@ export class YulVariableAssignmentStatement extends SlangNode { expression; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ - names: new YulPaths( - ast.names, - childrenOffsets.shift(), - comments, - options - ), + names: new YulPaths(ast.names, childrenOffsets.shift(), options), assignment: new YulAssignmentOperator( ast.assignment, childrenOffsets.shift(), - comments, options ), expression: new YulExpression( ast.expression, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/YulVariableDeclarationStatement.js b/src/slang-nodes/YulVariableDeclarationStatement.js index 5c8bb8767..8a236c2f3 100644 --- a/src/slang-nodes/YulVariableDeclarationStatement.js +++ b/src/slang-nodes/YulVariableDeclarationStatement.js @@ -8,7 +8,7 @@ export class YulVariableDeclarationStatement extends SlangNode { value; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ @@ -18,13 +18,12 @@ export class YulVariableDeclarationStatement extends SlangNode { ? new YulVariableDeclarationValue( ast.value, childrenOffsets.shift(), - comments, options ) : undefined }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/YulVariableDeclarationValue.js b/src/slang-nodes/YulVariableDeclarationValue.js index 72061dc34..cd1f365ca 100644 --- a/src/slang-nodes/YulVariableDeclarationValue.js +++ b/src/slang-nodes/YulVariableDeclarationValue.js @@ -7,25 +7,23 @@ export class YulVariableDeclarationValue extends SlangNode { expression; - constructor(ast, offset, comments, options) { + constructor(ast, offset, options) { super(); const fetch = (childrenOffsets) => ({ assignment: new YulAssignmentOperator( ast.assignment, childrenOffsets.shift(), - comments, options ), expression: new YulExpression( ast.expression, childrenOffsets.shift(), - comments, options ) }); - this.initialize(ast, offset, fetch, comments); + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slangParser.js b/src/slangParser.js index 04e70387e..55a7cb8c4 100644 --- a/src/slangParser.js +++ b/src/slangParser.js @@ -6,10 +6,8 @@ import { SourceUnit } from '@nomicfoundation/slang/ast/index.js'; import coerce from 'semver/functions/coerce.js'; import * as parsers from './slang-nodes/index.js'; -function createGenericParse(options, comments) { - return function genericParse(ast, offset = 0) { - return new parsers[ast.cst.kind](ast, offset, comments, options); - }; +function genericParse(ast, offset, options) { + return new parsers[ast.cst.kind](ast, offset, options); } function parse(text, _parsers, options = _parsers) { @@ -20,12 +18,7 @@ function parse(text, _parsers, options = _parsers) { language.parse(NonterminalKind.SourceUnit, text).tree() ); - const comments = []; - - const genericParse = createGenericParse(options, comments); - const parsed = genericParse(ast); - - parsed.comments = comments; + const parsed = genericParse(ast, 0, options); return parsed; } From 56c99c13cf091a66857d044eb20cee5b74e5ec41 Mon Sep 17 00:00:00 2001 From: Klaus Date: Thu, 18 Jul 2024 14:13:45 +1200 Subject: [PATCH 091/160] moving ast changes in postProcess function --- src/slang-nodes/AdditiveExpression.js | 11 ++-- src/slang-nodes/BitwiseAndExpression.js | 11 ++-- src/slang-nodes/BitwiseOrExpression.js | 11 ++-- src/slang-nodes/BitwiseXorExpression.js | 11 ++-- src/slang-nodes/ConditionalExpression.js | 48 ++++++++++------- src/slang-nodes/ConstructorAttributes.js | 6 +-- src/slang-nodes/FallbackFunctionAttributes.js | 6 +-- src/slang-nodes/FunctionAttributes.js | 6 +-- src/slang-nodes/FunctionTypeAttributes.js | 6 +-- src/slang-nodes/HexStringLiteral.js | 8 +-- src/slang-nodes/ModifierAttributes.js | 6 +-- src/slang-nodes/ModifierDefinition.js | 52 +++++++++++-------- src/slang-nodes/MultiplicativeExpression.js | 39 ++++++++------ src/slang-nodes/OrExpression.js | 11 ++-- src/slang-nodes/ReceiveFunctionAttributes.js | 6 +-- src/slang-nodes/ShiftExpression.js | 11 ++-- src/slang-nodes/SlangNode.js | 16 ++++-- src/slang-nodes/StringLiteral.js | 8 +-- src/slang-nodes/UnicodeStringLiteral.js | 8 +-- src/slang-nodes/UnnamedFunctionAttributes.js | 6 +-- src/slang-nodes/VersionComparator.js | 1 + src/slang-utils/sort-function-attributes.js | 7 ++- 22 files changed, 171 insertions(+), 124 deletions(-) diff --git a/src/slang-nodes/AdditiveExpression.js b/src/slang-nodes/AdditiveExpression.js index 4934db97a..48980fc37 100644 --- a/src/slang-nodes/AdditiveExpression.js +++ b/src/slang-nodes/AdditiveExpression.js @@ -5,6 +5,12 @@ import { Expression } from './Expression.js'; const tryToHug = createHugFunction(['%']); +const postProcess = (properties) => ({ + ...properties, + leftOperand: tryToHug(properties.leftOperand), + rightOperand: tryToHug(properties.rightOperand) +}); + export class AdditiveExpression extends SlangNode { leftOperand; @@ -29,10 +35,7 @@ export class AdditiveExpression extends SlangNode { ) }); - this.initialize(ast, offset, fetch); - - this.leftOperand = tryToHug(this.leftOperand); - this.rightOperand = tryToHug(this.rightOperand); + this.initialize(ast, offset, fetch, postProcess); } print(path, print, options) { diff --git a/src/slang-nodes/BitwiseAndExpression.js b/src/slang-nodes/BitwiseAndExpression.js index b3221be9a..0a6842a31 100644 --- a/src/slang-nodes/BitwiseAndExpression.js +++ b/src/slang-nodes/BitwiseAndExpression.js @@ -5,6 +5,12 @@ import { Expression } from './Expression.js'; const tryToHug = createHugFunction(['+', '-', '*', '/', '**', '<<', '>>']); +const postProcess = (properties) => ({ + ...properties, + leftOperand: tryToHug(properties.leftOperand), + rightOperand: tryToHug(properties.rightOperand) +}); + export class BitwiseAndExpression extends SlangNode { leftOperand; @@ -29,10 +35,7 @@ export class BitwiseAndExpression extends SlangNode { ) }); - this.initialize(ast, offset, fetch); - - this.leftOperand = tryToHug(this.leftOperand); - this.rightOperand = tryToHug(this.rightOperand); + this.initialize(ast, offset, fetch, postProcess); } print(path, print, options) { diff --git a/src/slang-nodes/BitwiseOrExpression.js b/src/slang-nodes/BitwiseOrExpression.js index 698c598ec..c903d4fa5 100644 --- a/src/slang-nodes/BitwiseOrExpression.js +++ b/src/slang-nodes/BitwiseOrExpression.js @@ -15,6 +15,12 @@ const tryToHug = createHugFunction([ '^' ]); +const postProcess = (properties) => ({ + ...properties, + leftOperand: tryToHug(properties.leftOperand), + rightOperand: tryToHug(properties.rightOperand) +}); + export class BitwiseOrExpression extends SlangNode { leftOperand; @@ -39,10 +45,7 @@ export class BitwiseOrExpression extends SlangNode { ) }); - this.initialize(ast, offset, fetch); - - this.leftOperand = tryToHug(this.leftOperand); - this.rightOperand = tryToHug(this.rightOperand); + this.initialize(ast, offset, fetch, postProcess); } print(path, print, options) { diff --git a/src/slang-nodes/BitwiseXorExpression.js b/src/slang-nodes/BitwiseXorExpression.js index 78b38bed1..84c58efd4 100644 --- a/src/slang-nodes/BitwiseXorExpression.js +++ b/src/slang-nodes/BitwiseXorExpression.js @@ -5,6 +5,12 @@ import { Expression } from './Expression.js'; const tryToHug = createHugFunction(['+', '-', '*', '/', '**', '<<', '>>', '&']); +const postProcess = (properties) => ({ + ...properties, + leftOperand: tryToHug(properties.leftOperand), + rightOperand: tryToHug(properties.rightOperand) +}); + export class BitwiseXorExpression extends SlangNode { leftOperand; @@ -29,10 +35,7 @@ export class BitwiseXorExpression extends SlangNode { ) }); - this.initialize(ast, offset, fetch); - - this.leftOperand = tryToHug(this.leftOperand); - this.rightOperand = tryToHug(this.rightOperand); + this.initialize(ast, offset, fetch, postProcess); } print(path, print, options) { diff --git a/src/slang-nodes/ConditionalExpression.js b/src/slang-nodes/ConditionalExpression.js index b25f5a436..492429a40 100644 --- a/src/slang-nodes/ConditionalExpression.js +++ b/src/slang-nodes/ConditionalExpression.js @@ -6,6 +6,27 @@ import { Expression } from './Expression.js'; const { group, hardline, ifBreak, indent, line, softline } = doc.builders; +const postProcess = (properties) => { + // We can remove parentheses only because we are sure that the + // `condition` must be a single `bool` value. + let { operand } = properties; + const operandLoc = operand.loc; + while ( + operand.variant.kind === 'TupleExpression' && + operand.variant.items.items.length === 1 && + operand.variant.items.items[0].expression.variant.kind !== + 'ConditionalExpression' + ) { + operand = operand.variant.items.items[0].expression; + } + operand.loc = operandLoc; + + return { + ...properties, + operand + }; +}; + function experimentalTernaries(node, path, print, options) { const grandparent = path.getNode(2); const isNested = grandparent.kind === 'ConditionalExpression'; @@ -115,25 +136,14 @@ export class ConditionalExpression extends SlangNode { ) }); - this.initialize(ast, offset, fetch); - - // TODO: while the behaviour is not stable, it should be behind the - // experimentalTernaries flag. - if (options.experimentalTernaries) { - // We can remove parentheses only because we are sure that the - // `condition` must be a single `bool` value. - const operandLoc = this.operand.loc; - while ( - this.operand.variant.kind === 'TupleExpression' && - this.operand.variant.items.items.length === 1 && - this.operand.variant.items.items[0].expression.variant.kind !== - 'ConditionalExpression' - ) { - this.operand = this.operand.variant.items.items[0].expression; - } - - this.operand.loc = operandLoc; - } + this.initialize( + ast, + offset, + fetch, + // TODO: while the behaviour is not stable, it should be behind the + // experimentalTernaries flag. + options.experimentalTernaries ? postProcess : undefined + ); } print(path, print, options) { diff --git a/src/slang-nodes/ConstructorAttributes.js b/src/slang-nodes/ConstructorAttributes.js index 5c943629b..f442e9505 100644 --- a/src/slang-nodes/ConstructorAttributes.js +++ b/src/slang-nodes/ConstructorAttributes.js @@ -1,5 +1,5 @@ import { doc } from 'prettier'; -import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; +import { postProcessFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; import { SlangNode } from './SlangNode.js'; import { ConstructorAttribute } from './ConstructorAttribute.js'; @@ -18,9 +18,7 @@ export class ConstructorAttributes extends SlangNode { ) }); - this.initialize(ast, offset, fetch); - - this.items = this.items.sort(sortFunctionAttributes); + this.initialize(ast, offset, fetch, postProcessFunctionAttributes); } print(path, print) { diff --git a/src/slang-nodes/FallbackFunctionAttributes.js b/src/slang-nodes/FallbackFunctionAttributes.js index 4282f2a66..9935a88f2 100644 --- a/src/slang-nodes/FallbackFunctionAttributes.js +++ b/src/slang-nodes/FallbackFunctionAttributes.js @@ -1,5 +1,5 @@ import { doc } from 'prettier'; -import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; +import { postProcessFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; import { SlangNode } from './SlangNode.js'; import { FallbackFunctionAttribute } from './FallbackFunctionAttribute.js'; @@ -18,9 +18,7 @@ export class FallbackFunctionAttributes extends SlangNode { ) }); - this.initialize(ast, offset, fetch); - - this.items = this.items.sort(sortFunctionAttributes); + this.initialize(ast, offset, fetch, postProcessFunctionAttributes); } print(path, print) { diff --git a/src/slang-nodes/FunctionAttributes.js b/src/slang-nodes/FunctionAttributes.js index c16c71962..c8a4e93be 100644 --- a/src/slang-nodes/FunctionAttributes.js +++ b/src/slang-nodes/FunctionAttributes.js @@ -1,5 +1,5 @@ import { doc } from 'prettier'; -import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; +import { postProcessFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; import { SlangNode } from './SlangNode.js'; import { FunctionAttribute } from './FunctionAttribute.js'; @@ -17,9 +17,7 @@ export class FunctionAttributes extends SlangNode { ) }); - this.initialize(ast, offset, fetch); - - this.items = this.items.sort(sortFunctionAttributes); + this.initialize(ast, offset, fetch, postProcessFunctionAttributes); } print(path, print) { diff --git a/src/slang-nodes/FunctionTypeAttributes.js b/src/slang-nodes/FunctionTypeAttributes.js index 28a3515bb..6b91fb3a7 100644 --- a/src/slang-nodes/FunctionTypeAttributes.js +++ b/src/slang-nodes/FunctionTypeAttributes.js @@ -1,5 +1,5 @@ import { doc } from 'prettier'; -import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; +import { postProcessFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; import { SlangNode } from './SlangNode.js'; import { FunctionTypeAttribute } from './FunctionTypeAttribute.js'; @@ -18,9 +18,7 @@ export class FunctionTypeAttributes extends SlangNode { ) }); - this.initialize(ast, offset, fetch); - - this.items = this.items.sort(sortFunctionAttributes); + this.initialize(ast, offset, fetch, postProcessFunctionAttributes); } print(path, print) { diff --git a/src/slang-nodes/HexStringLiteral.js b/src/slang-nodes/HexStringLiteral.js index 45fedf0d3..e49edef68 100644 --- a/src/slang-nodes/HexStringLiteral.js +++ b/src/slang-nodes/HexStringLiteral.js @@ -1,6 +1,10 @@ import { printString } from '../slang-printers/print-string.js'; import { SlangNode } from './SlangNode.js'; +const postProcess = (options) => (properties) => ({ + variant: `hex${printString(properties.variant.slice(4, -1), options)}` +}); + export class HexStringLiteral extends SlangNode { variant; @@ -11,9 +15,7 @@ export class HexStringLiteral extends SlangNode { variant: ast.variant.text }); - this.initialize(ast, offset, fetch); - - this.variant = `hex${printString(this.variant.slice(4, -1), options)}`; + this.initialize(ast, offset, fetch, postProcess(options)); } print() { diff --git a/src/slang-nodes/ModifierAttributes.js b/src/slang-nodes/ModifierAttributes.js index 7a2a82e07..daa80813c 100644 --- a/src/slang-nodes/ModifierAttributes.js +++ b/src/slang-nodes/ModifierAttributes.js @@ -1,5 +1,5 @@ import { doc } from 'prettier'; -import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; +import { postProcessFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; import { SlangNode } from './SlangNode.js'; import { ModifierAttribute } from './ModifierAttribute.js'; @@ -17,9 +17,7 @@ export class ModifierAttributes extends SlangNode { ) }); - this.initialize(ast, offset, fetch); - - this.items = this.items.sort(sortFunctionAttributes); + this.initialize(ast, offset, fetch, postProcessFunctionAttributes); } print(path, print) { diff --git a/src/slang-nodes/ModifierDefinition.js b/src/slang-nodes/ModifierDefinition.js index b15fae81d..07a3aa4bc 100644 --- a/src/slang-nodes/ModifierDefinition.js +++ b/src/slang-nodes/ModifierDefinition.js @@ -5,6 +5,34 @@ import { Parameters } from './Parameters.js'; import { ModifierAttributes } from './ModifierAttributes.js'; import { FunctionBody } from './FunctionBody.js'; +const postProcess = (properties) => { + if (typeof properties.parameters !== 'undefined') return properties; + + const parametersOffset = properties.attributes.loc.startWithTrivia; + const parametersLoc = { + startWithTrivia: parametersOffset, + start: parametersOffset, + endWithTrivia: parametersOffset, + end: parametersOffset + }; + + return { + ...properties, + parameters: new ParametersDeclaration({ + kind: 'ParametersDeclaration', + loc: { ...parametersLoc }, + openParen: '(', + parameters: new Parameters({ + kind: 'Parameters', + loc: { ...parametersLoc }, + items: [], + separators: [] + }), + closeParen: ')' + }) + }; +}; + export class ModifierDefinition extends SlangNode { modifierKeyword; @@ -37,29 +65,7 @@ export class ModifierDefinition extends SlangNode { body: new FunctionBody(ast.body, childrenOffsets.shift(), options) }); - this.initialize(ast, offset, fetch); - - if (typeof this.parameters === 'undefined') { - const parametersOffset = this.attributes.loc.startWithTrivia; - const parametersLoc = { - startWithTrivia: parametersOffset, - start: parametersOffset, - endWithTrivia: parametersOffset, - end: parametersOffset - }; - this.parameters = new ParametersDeclaration({ - kind: 'ParametersDeclaration', - loc: { ...parametersLoc }, - openParen: '(', - parameters: new Parameters({ - kind: 'Parameters', - loc: { ...parametersLoc }, - items: [], - separators: [] - }), - closeParen: ')' - }); - } + this.initialize(ast, offset, fetch, postProcess); } print(path, print) { diff --git a/src/slang-nodes/MultiplicativeExpression.js b/src/slang-nodes/MultiplicativeExpression.js index fa3d65cd3..210438a61 100644 --- a/src/slang-nodes/MultiplicativeExpression.js +++ b/src/slang-nodes/MultiplicativeExpression.js @@ -7,6 +7,29 @@ const multiplicationTryToHug = createHugFunction(['/', '%']); const divisionTryToHug = createHugFunction(['*', '%']); const moduloTryToHug = createHugFunction(['*', '/', '%']); +const postProcess = (properties) => { + let { leftOperand } = properties; + + switch (properties.operator) { + case '*': + leftOperand = multiplicationTryToHug(leftOperand); + break; + case '/': + leftOperand = divisionTryToHug(leftOperand); + break; + case '%': + leftOperand = moduloTryToHug(leftOperand); + break; + default: + break; + } + + return { + ...properties, + leftOperand + }; +}; + export class MultiplicativeExpression extends SlangNode { leftOperand; @@ -31,21 +54,7 @@ export class MultiplicativeExpression extends SlangNode { ) }); - this.initialize(ast, offset, fetch); - - switch (this.operator) { - case '*': - this.leftOperand = multiplicationTryToHug(this.leftOperand); - break; - case '/': - this.leftOperand = divisionTryToHug(this.leftOperand); - break; - case '%': - this.leftOperand = moduloTryToHug(this.leftOperand); - break; - default: - break; - } + this.initialize(ast, offset, fetch, postProcess); } print(path, print, options) { diff --git a/src/slang-nodes/OrExpression.js b/src/slang-nodes/OrExpression.js index cc9f3396c..40d68d971 100644 --- a/src/slang-nodes/OrExpression.js +++ b/src/slang-nodes/OrExpression.js @@ -5,6 +5,12 @@ import { Expression } from './Expression.js'; const tryToHug = createHugFunction(['&&']); +const postProcess = (properties) => ({ + ...properties, + leftOperand: tryToHug(properties.leftOperand), + rightOperand: tryToHug(properties.rightOperand) +}); + export class OrExpression extends SlangNode { leftOperand; @@ -29,10 +35,7 @@ export class OrExpression extends SlangNode { ) }); - this.initialize(ast, offset, fetch); - - this.leftOperand = tryToHug(this.leftOperand); - this.rightOperand = tryToHug(this.rightOperand); + this.initialize(ast, offset, fetch, postProcess); } print(path, print, options) { diff --git a/src/slang-nodes/ReceiveFunctionAttributes.js b/src/slang-nodes/ReceiveFunctionAttributes.js index ba86c04c6..1cf1bae83 100644 --- a/src/slang-nodes/ReceiveFunctionAttributes.js +++ b/src/slang-nodes/ReceiveFunctionAttributes.js @@ -1,5 +1,5 @@ import { doc } from 'prettier'; -import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; +import { postProcessFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; import { SlangNode } from './SlangNode.js'; import { ReceiveFunctionAttribute } from './ReceiveFunctionAttribute.js'; @@ -18,9 +18,7 @@ export class ReceiveFunctionAttributes extends SlangNode { ) }); - this.initialize(ast, offset, fetch); - - this.items = this.items.sort(sortFunctionAttributes); + this.initialize(ast, offset, fetch, postProcessFunctionAttributes); } print(path, print) { diff --git a/src/slang-nodes/ShiftExpression.js b/src/slang-nodes/ShiftExpression.js index 9919274b5..a45d70349 100644 --- a/src/slang-nodes/ShiftExpression.js +++ b/src/slang-nodes/ShiftExpression.js @@ -14,6 +14,12 @@ const tryToHugLeftOperand = createHugFunction([ ]); const tryToHugRightOperand = createHugFunction(['+', '-', '*', '/', '**']); +const postProcess = (properties) => ({ + ...properties, + leftOperand: tryToHugLeftOperand(properties.leftOperand), + rightOperand: tryToHugRightOperand(properties.rightOperand) +}); + export class ShiftExpression extends SlangNode { leftOperand; @@ -38,10 +44,7 @@ export class ShiftExpression extends SlangNode { ) }); - this.initialize(ast, offset, fetch); - - this.leftOperand = tryToHugLeftOperand(this.leftOperand); - this.rightOperand = tryToHugRightOperand(this.rightOperand); + this.initialize(ast, offset, fetch, postProcess); } print(path, print, options) { diff --git a/src/slang-nodes/SlangNode.js b/src/slang-nodes/SlangNode.js index bba9a6e4d..fde4216b7 100644 --- a/src/slang-nodes/SlangNode.js +++ b/src/slang-nodes/SlangNode.js @@ -6,6 +6,7 @@ import { const isNotStringOrUndefined = (node) => typeof node !== 'string' && typeof node !== 'undefined'; + export class SlangNode { kind; @@ -13,7 +14,7 @@ export class SlangNode { comments = []; - initialize(ast, offset, fetch) { + initialize(ast, offset, fetch, postProcess) { this.kind = ast.cst.kind; // Collect comments and get children offsets. @@ -38,9 +39,6 @@ export class SlangNode { const propertyKeys = Object.keys(properties); const propertyValues = Object.values(properties); - propertyKeys.forEach((propertyKey) => { - this[propertyKey] = properties[propertyKey]; - }); // Collect comments const childrenNodes = propertyValues.reduce((slangNodes, property) => { @@ -64,7 +62,7 @@ export class SlangNode { if (leadingOffset === 0 || trailingOffset === 0) { for (let i = 0; i < propertyKeys.length; i += 1) { - const childLoc = this[propertyKeys[i]]?.loc; + const childLoc = properties[propertyKeys[i]]?.loc; if (childLoc) { if ( @@ -90,5 +88,13 @@ export class SlangNode { endWithTrivia, end: endWithTrivia - trailingOffset }; + + if (typeof postProcess === 'function') { + properties = postProcess(properties); + } + + propertyKeys.forEach((propertyKey) => { + this[propertyKey] = properties[propertyKey]; + }); } } diff --git a/src/slang-nodes/StringLiteral.js b/src/slang-nodes/StringLiteral.js index fad052768..b0b4414b7 100644 --- a/src/slang-nodes/StringLiteral.js +++ b/src/slang-nodes/StringLiteral.js @@ -1,6 +1,10 @@ import { printString } from '../slang-printers/print-string.js'; import { SlangNode } from './SlangNode.js'; +const postProcess = (options) => (properties) => ({ + variant: printString(properties.variant.slice(1, -1), options) +}); + export class StringLiteral extends SlangNode { variant; @@ -11,9 +15,7 @@ export class StringLiteral extends SlangNode { variant: ast.variant.text }); - this.initialize(ast, offset, fetch); - - this.variant = printString(this.variant.slice(1, -1), options); + this.initialize(ast, offset, fetch, postProcess(options)); } print() { diff --git a/src/slang-nodes/UnicodeStringLiteral.js b/src/slang-nodes/UnicodeStringLiteral.js index d982b33e5..b46dd611e 100644 --- a/src/slang-nodes/UnicodeStringLiteral.js +++ b/src/slang-nodes/UnicodeStringLiteral.js @@ -1,6 +1,10 @@ import { printString } from '../slang-printers/print-string.js'; import { SlangNode } from './SlangNode.js'; +const postProcess = (options) => (properties) => ({ + variant: `unicode${printString(properties.variant.slice(8, -1), options)}` +}); + export class UnicodeStringLiteral extends SlangNode { variant; @@ -11,9 +15,7 @@ export class UnicodeStringLiteral extends SlangNode { variant: ast.variant.text }); - this.initialize(ast, offset, fetch); - - this.variant = `unicode${printString(this.variant.slice(8, -1), options)}`; + this.initialize(ast, offset, fetch, postProcess(options)); } print() { diff --git a/src/slang-nodes/UnnamedFunctionAttributes.js b/src/slang-nodes/UnnamedFunctionAttributes.js index 85ab2a953..55dc76b43 100644 --- a/src/slang-nodes/UnnamedFunctionAttributes.js +++ b/src/slang-nodes/UnnamedFunctionAttributes.js @@ -1,5 +1,5 @@ import { doc } from 'prettier'; -import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; +import { postProcessFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; import { SlangNode } from './SlangNode.js'; import { UnnamedFunctionAttribute } from './UnnamedFunctionAttribute.js'; @@ -18,9 +18,7 @@ export class UnnamedFunctionAttributes extends SlangNode { ) }); - this.initialize(ast, offset, fetch); - - this.items = this.items.sort(sortFunctionAttributes); + this.initialize(ast, offset, fetch, postProcessFunctionAttributes); } print(path, print) { diff --git a/src/slang-nodes/VersionComparator.js b/src/slang-nodes/VersionComparator.js index ee79c5961..775653a03 100644 --- a/src/slang-nodes/VersionComparator.js +++ b/src/slang-nodes/VersionComparator.js @@ -1,5 +1,6 @@ import { SlangNode } from './SlangNode.js'; import { VersionExpression } from './VersionExpression.js'; + export class VersionComparator extends SlangNode { operator; diff --git a/src/slang-utils/sort-function-attributes.js b/src/slang-utils/sort-function-attributes.js index fd1eee9b0..84ee20f51 100644 --- a/src/slang-utils/sort-function-attributes.js +++ b/src/slang-utils/sort-function-attributes.js @@ -7,7 +7,7 @@ const visibilityKeyWords = new Set([ const mutabilityKeyWords = new Set(['pure', 'constant', 'payable', 'view']); -export function sortFunctionAttributes(a, b) { +function sortFunctionAttributes(a, b) { const aIsString = typeof a.variant === 'string'; const bIsString = typeof b.variant === 'string'; @@ -38,3 +38,8 @@ export function sortFunctionAttributes(a, b) { } return 0; } + +export const postProcessFunctionAttributes = (properties) => ({ + ...properties, + items: properties.items.sort(sortFunctionAttributes) +}); From 8dc931389016c5527d119db01186872f55d0e1e5 Mon Sep 17 00:00:00 2001 From: Klaus Date: Thu, 18 Jul 2024 15:18:53 +1200 Subject: [PATCH 092/160] cleaning up create-hug-function.js --- src/slang-utils/create-hug-function.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/slang-utils/create-hug-function.js b/src/slang-utils/create-hug-function.js index c86ab8ee3..fd6189658 100644 --- a/src/slang-utils/create-hug-function.js +++ b/src/slang-utils/create-hug-function.js @@ -11,12 +11,7 @@ export function createHugFunction(huggableOperators) { isBinaryOperation(node.variant) && operators.has(node.variant.operator) ) { - const loc = { - startWithTrivia: node.loc.startWithTrivia, - start: node.loc.start, - endWithTrivia: node.loc.endWithTrivia, - end: node.loc.end - }; + const { loc } = node; return new Expression({ kind: 'Expression', From 39ab0071fdecbccd85ea2c17b68725e42dc6f488 Mon Sep 17 00:00:00 2001 From: Klaus Date: Thu, 18 Jul 2024 15:50:08 +1200 Subject: [PATCH 093/160] `kind` is a static getter now --- src/slang-nodes/ABICoderPragma.js | 5 +++++ src/slang-nodes/AdditiveExpression.js | 5 +++++ src/slang-nodes/AddressType.js | 5 +++++ src/slang-nodes/AndExpression.js | 5 +++++ src/slang-nodes/ArgumentsDeclaration.js | 5 +++++ src/slang-nodes/ArrayExpression.js | 5 +++++ src/slang-nodes/ArrayTypeName.js | 5 +++++ src/slang-nodes/ArrayValues.js | 5 +++++ src/slang-nodes/AssemblyFlags.js | 5 +++++ src/slang-nodes/AssemblyFlagsDeclaration.js | 5 +++++ src/slang-nodes/AssemblyStatement.js | 5 +++++ src/slang-nodes/AssignmentExpression.js | 5 +++++ src/slang-nodes/BitwiseAndExpression.js | 5 +++++ src/slang-nodes/BitwiseOrExpression.js | 5 +++++ src/slang-nodes/BitwiseXorExpression.js | 5 +++++ src/slang-nodes/Block.js | 5 +++++ src/slang-nodes/BreakStatement.js | 5 +++++ src/slang-nodes/CallOptions.js | 5 +++++ src/slang-nodes/CallOptionsExpression.js | 5 +++++ src/slang-nodes/CatchClause.js | 5 +++++ src/slang-nodes/CatchClauseError.js | 5 +++++ src/slang-nodes/CatchClauses.js | 5 +++++ src/slang-nodes/ComparisonExpression.js | 5 +++++ src/slang-nodes/ConditionalExpression.js | 5 +++++ src/slang-nodes/ConstantDefinition.js | 5 +++++ src/slang-nodes/ConstructorAttribute.js | 5 +++++ src/slang-nodes/ConstructorAttributes.js | 5 +++++ src/slang-nodes/ConstructorDefinition.js | 5 +++++ src/slang-nodes/ContinueStatement.js | 5 +++++ src/slang-nodes/ContractDefinition.js | 5 +++++ src/slang-nodes/ContractMember.js | 5 +++++ src/slang-nodes/ContractMembers.js | 5 +++++ src/slang-nodes/DecimalNumberExpression.js | 5 +++++ src/slang-nodes/DoWhileStatement.js | 5 +++++ src/slang-nodes/ElementaryType.js | 5 +++++ src/slang-nodes/ElseBranch.js | 5 +++++ src/slang-nodes/EmitStatement.js | 5 +++++ src/slang-nodes/EnumDefinition.js | 5 +++++ src/slang-nodes/EnumMembers.js | 5 +++++ src/slang-nodes/EqualityExpression.js | 5 +++++ src/slang-nodes/ErrorDefinition.js | 5 +++++ src/slang-nodes/ErrorParameter.js | 5 +++++ src/slang-nodes/ErrorParameters.js | 5 +++++ src/slang-nodes/ErrorParametersDeclaration.js | 5 +++++ src/slang-nodes/EventDefinition.js | 5 +++++ src/slang-nodes/EventParameter.js | 5 +++++ src/slang-nodes/EventParameters.js | 5 +++++ src/slang-nodes/EventParametersDeclaration.js | 5 +++++ src/slang-nodes/ExperimentalFeature.js | 5 +++++ src/slang-nodes/ExperimentalPragma.js | 5 +++++ src/slang-nodes/ExponentiationExpression.js | 12 +++++------- src/slang-nodes/Expression.js | 6 +++++- src/slang-nodes/ExpressionStatement.js | 5 +++++ src/slang-nodes/FallbackFunctionAttribute.js | 5 +++++ src/slang-nodes/FallbackFunctionAttributes.js | 5 +++++ src/slang-nodes/FallbackFunctionDefinition.js | 5 +++++ src/slang-nodes/ForStatement.js | 5 +++++ src/slang-nodes/ForStatementCondition.js | 5 +++++ src/slang-nodes/ForStatementInitialization.js | 5 +++++ src/slang-nodes/FunctionAttribute.js | 5 +++++ src/slang-nodes/FunctionAttributes.js | 5 +++++ src/slang-nodes/FunctionBody.js | 5 +++++ src/slang-nodes/FunctionCallExpression.js | 5 +++++ src/slang-nodes/FunctionDefinition.js | 5 +++++ src/slang-nodes/FunctionName.js | 5 +++++ src/slang-nodes/FunctionType.js | 5 +++++ src/slang-nodes/FunctionTypeAttribute.js | 5 +++++ src/slang-nodes/FunctionTypeAttributes.js | 5 +++++ src/slang-nodes/HexNumberExpression.js | 5 +++++ src/slang-nodes/HexStringLiteral.js | 5 +++++ src/slang-nodes/HexStringLiterals.js | 5 +++++ src/slang-nodes/IdentifierPath.js | 5 +++++ src/slang-nodes/IfStatement.js | 5 +++++ src/slang-nodes/ImportAlias.js | 5 +++++ src/slang-nodes/ImportClause.js | 5 +++++ src/slang-nodes/ImportDeconstruction.js | 5 +++++ src/slang-nodes/ImportDeconstructionSymbol.js | 5 +++++ src/slang-nodes/ImportDeconstructionSymbols.js | 5 +++++ src/slang-nodes/ImportDirective.js | 5 +++++ src/slang-nodes/IndexAccessEnd.js | 5 +++++ src/slang-nodes/IndexAccessExpression.js | 5 +++++ src/slang-nodes/InheritanceSpecifier.js | 5 +++++ src/slang-nodes/InheritanceType.js | 5 +++++ src/slang-nodes/InheritanceTypes.js | 5 +++++ src/slang-nodes/InterfaceDefinition.js | 5 +++++ src/slang-nodes/InterfaceMembers.js | 5 +++++ src/slang-nodes/LibraryDefinition.js | 5 +++++ src/slang-nodes/LibraryMembers.js | 5 +++++ src/slang-nodes/MappingKey.js | 5 +++++ src/slang-nodes/MappingKeyType.js | 5 +++++ src/slang-nodes/MappingType.js | 5 +++++ src/slang-nodes/MappingValue.js | 5 +++++ src/slang-nodes/MemberAccess.js | 5 +++++ src/slang-nodes/MemberAccessExpression.js | 5 +++++ src/slang-nodes/ModifierAttribute.js | 5 +++++ src/slang-nodes/ModifierAttributes.js | 5 +++++ src/slang-nodes/ModifierDefinition.js | 7 +++++-- src/slang-nodes/ModifierInvocation.js | 5 +++++ src/slang-nodes/MultiplicativeExpression.js | 5 +++++ src/slang-nodes/NamedArgument.js | 5 +++++ src/slang-nodes/NamedArgumentGroup.js | 5 +++++ src/slang-nodes/NamedArguments.js | 5 +++++ src/slang-nodes/NamedArgumentsDeclaration.js | 5 +++++ src/slang-nodes/NamedImport.js | 5 +++++ src/slang-nodes/NewExpression.js | 5 +++++ src/slang-nodes/NumberUnit.js | 5 +++++ src/slang-nodes/OrExpression.js | 5 +++++ src/slang-nodes/OverridePaths.js | 5 +++++ src/slang-nodes/OverridePathsDeclaration.js | 5 +++++ src/slang-nodes/OverrideSpecifier.js | 5 +++++ src/slang-nodes/Parameter.js | 5 +++++ src/slang-nodes/Parameters.js | 6 +++++- src/slang-nodes/ParametersDeclaration.js | 6 +++++- src/slang-nodes/PathImport.js | 5 +++++ src/slang-nodes/PositionalArguments.js | 5 +++++ src/slang-nodes/PositionalArgumentsDeclaration.js | 5 +++++ src/slang-nodes/PostfixExpression.js | 5 +++++ src/slang-nodes/Pragma.js | 5 +++++ src/slang-nodes/PragmaDirective.js | 5 +++++ src/slang-nodes/PrefixExpression.js | 5 +++++ src/slang-nodes/ReceiveFunctionAttribute.js | 5 +++++ src/slang-nodes/ReceiveFunctionAttributes.js | 5 +++++ src/slang-nodes/ReceiveFunctionDefinition.js | 5 +++++ src/slang-nodes/ReturnStatement.js | 5 +++++ src/slang-nodes/ReturnsDeclaration.js | 5 +++++ src/slang-nodes/RevertStatement.js | 5 +++++ src/slang-nodes/ShiftExpression.js | 5 +++++ src/slang-nodes/SlangNode.js | 8 ++++---- src/slang-nodes/SourceUnit.js | 5 ++++- src/slang-nodes/SourceUnitMember.js | 5 +++++ src/slang-nodes/SourceUnitMembers.js | 5 +++++ src/slang-nodes/StateVariableAttribute.js | 5 +++++ src/slang-nodes/StateVariableAttributes.js | 5 +++++ src/slang-nodes/StateVariableDefinition.js | 5 +++++ src/slang-nodes/StateVariableDefinitionValue.js | 5 +++++ src/slang-nodes/Statement.js | 5 +++++ src/slang-nodes/Statements.js | 5 +++++ src/slang-nodes/StorageLocation.js | 5 +++++ src/slang-nodes/StringExpression.js | 5 +++++ src/slang-nodes/StringLiteral.js | 5 +++++ src/slang-nodes/StringLiterals.js | 5 +++++ src/slang-nodes/StructDefinition.js | 5 +++++ src/slang-nodes/StructMember.js | 5 +++++ src/slang-nodes/StructMembers.js | 5 +++++ src/slang-nodes/ThrowStatement.js | 5 +++++ src/slang-nodes/TryStatement.js | 5 +++++ src/slang-nodes/TupleDeconstructionElement.js | 5 +++++ src/slang-nodes/TupleDeconstructionElements.js | 5 +++++ src/slang-nodes/TupleDeconstructionStatement.js | 5 +++++ src/slang-nodes/TupleExpression.js | 6 +++++- src/slang-nodes/TupleMember.js | 5 +++++ src/slang-nodes/TupleValue.js | 6 +++++- src/slang-nodes/TupleValues.js | 6 +++++- src/slang-nodes/TypeExpression.js | 5 +++++ src/slang-nodes/TypeName.js | 5 +++++ src/slang-nodes/TypedTupleMember.js | 5 +++++ src/slang-nodes/UncheckedBlock.js | 5 +++++ src/slang-nodes/UnicodeStringLiteral.js | 5 +++++ src/slang-nodes/UnicodeStringLiterals.js | 5 +++++ src/slang-nodes/UnnamedFunctionAttribute.js | 5 +++++ src/slang-nodes/UnnamedFunctionAttributes.js | 5 +++++ src/slang-nodes/UnnamedFunctionDefinition.js | 5 +++++ src/slang-nodes/UntypedTupleMember.js | 5 +++++ src/slang-nodes/UserDefinedValueTypeDefinition.js | 5 +++++ src/slang-nodes/UsingAlias.js | 5 +++++ src/slang-nodes/UsingClause.js | 5 +++++ src/slang-nodes/UsingDeconstruction.js | 5 +++++ src/slang-nodes/UsingDeconstructionSymbol.js | 5 +++++ src/slang-nodes/UsingDeconstructionSymbols.js | 5 +++++ src/slang-nodes/UsingDirective.js | 5 +++++ src/slang-nodes/UsingOperator.js | 5 +++++ src/slang-nodes/UsingTarget.js | 5 +++++ src/slang-nodes/VariableDeclarationStatement.js | 5 +++++ src/slang-nodes/VariableDeclarationType.js | 5 +++++ src/slang-nodes/VariableDeclarationValue.js | 5 +++++ src/slang-nodes/VersionComparator.js | 5 +++++ src/slang-nodes/VersionExpression.js | 5 +++++ src/slang-nodes/VersionExpressionSet.js | 5 +++++ src/slang-nodes/VersionExpressionSets.js | 5 +++++ src/slang-nodes/VersionPragma.js | 5 +++++ src/slang-nodes/VersionRange.js | 5 +++++ src/slang-nodes/VersionSpecifiers.js | 5 +++++ src/slang-nodes/WhileStatement.js | 5 +++++ src/slang-nodes/YulArguments.js | 5 +++++ src/slang-nodes/YulAssignmentOperator.js | 5 +++++ src/slang-nodes/YulBlock.js | 5 +++++ src/slang-nodes/YulBreakStatement.js | 5 +++++ src/slang-nodes/YulBuiltInFunction.js | 5 +++++ src/slang-nodes/YulColonEqual.js | 5 +++++ src/slang-nodes/YulContinueStatement.js | 5 +++++ src/slang-nodes/YulDefaultCase.js | 5 +++++ src/slang-nodes/YulExpression.js | 5 +++++ src/slang-nodes/YulForStatement.js | 5 +++++ src/slang-nodes/YulFunctionCallExpression.js | 5 +++++ src/slang-nodes/YulFunctionDefinition.js | 5 +++++ src/slang-nodes/YulIfStatement.js | 5 +++++ src/slang-nodes/YulLabel.js | 5 +++++ src/slang-nodes/YulLeaveStatement.js | 5 +++++ src/slang-nodes/YulLiteral.js | 5 +++++ src/slang-nodes/YulParameters.js | 5 +++++ src/slang-nodes/YulParametersDeclaration.js | 5 +++++ src/slang-nodes/YulPath.js | 5 +++++ src/slang-nodes/YulPathComponent.js | 5 +++++ src/slang-nodes/YulPaths.js | 5 +++++ src/slang-nodes/YulReturnVariables.js | 5 +++++ src/slang-nodes/YulReturnsDeclaration.js | 5 +++++ src/slang-nodes/YulStackAssignmentStatement.js | 5 +++++ src/slang-nodes/YulStatement.js | 5 +++++ src/slang-nodes/YulStatements.js | 5 +++++ src/slang-nodes/YulSwitchCase.js | 5 +++++ src/slang-nodes/YulSwitchCases.js | 5 +++++ src/slang-nodes/YulSwitchStatement.js | 5 +++++ src/slang-nodes/YulValueCase.js | 5 +++++ src/slang-nodes/YulVariableAssignmentStatement.js | 5 +++++ src/slang-nodes/YulVariableDeclarationStatement.js | 5 +++++ src/slang-nodes/YulVariableDeclarationValue.js | 5 +++++ src/slang-utils/create-hug-function.js | 4 ---- 217 files changed, 1078 insertions(+), 24 deletions(-) diff --git a/src/slang-nodes/ABICoderPragma.js b/src/slang-nodes/ABICoderPragma.js index 3dd6c6d84..38d4a95e4 100644 --- a/src/slang-nodes/ABICoderPragma.js +++ b/src/slang-nodes/ABICoderPragma.js @@ -1,6 +1,11 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; export class ABICoderPragma extends SlangNode { + get kind() { + return NonterminalKind.ABICoderPragma; + } + abicoderKeyword; version; diff --git a/src/slang-nodes/AdditiveExpression.js b/src/slang-nodes/AdditiveExpression.js index 48980fc37..33debc5bc 100644 --- a/src/slang-nodes/AdditiveExpression.js +++ b/src/slang-nodes/AdditiveExpression.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; import { createHugFunction } from '../slang-utils/create-hug-function.js'; import { SlangNode } from './SlangNode.js'; @@ -12,6 +13,10 @@ const postProcess = (properties) => ({ }); export class AdditiveExpression extends SlangNode { + get kind() { + return NonterminalKind.AdditiveExpression; + } + leftOperand; operator; diff --git a/src/slang-nodes/AddressType.js b/src/slang-nodes/AddressType.js index ef1f5465d..596a31c43 100644 --- a/src/slang-nodes/AddressType.js +++ b/src/slang-nodes/AddressType.js @@ -1,6 +1,11 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; export class AddressType extends SlangNode { + get kind() { + return NonterminalKind.AddressType; + } + addressKeyword; payableKeyword; diff --git a/src/slang-nodes/AndExpression.js b/src/slang-nodes/AndExpression.js index 7128c9c56..8f33bca10 100644 --- a/src/slang-nodes/AndExpression.js +++ b/src/slang-nodes/AndExpression.js @@ -1,8 +1,13 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printLogicalOperation } from '../slang-printers/print-logical-operation.js'; import { SlangNode } from './SlangNode.js'; import { Expression } from './Expression.js'; export class AndExpression extends SlangNode { + get kind() { + return NonterminalKind.AndExpression; + } + leftOperand; operator; diff --git a/src/slang-nodes/ArgumentsDeclaration.js b/src/slang-nodes/ArgumentsDeclaration.js index a53956c8d..4069ec46f 100644 --- a/src/slang-nodes/ArgumentsDeclaration.js +++ b/src/slang-nodes/ArgumentsDeclaration.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { PositionalArgumentsDeclaration } from './PositionalArgumentsDeclaration.js'; import { NamedArgumentsDeclaration } from './NamedArgumentsDeclaration.js'; @@ -5,6 +6,10 @@ import { NamedArgumentsDeclaration } from './NamedArgumentsDeclaration.js'; const variants = { PositionalArgumentsDeclaration, NamedArgumentsDeclaration }; export class ArgumentsDeclaration extends SlangNode { + get kind() { + return NonterminalKind.ArgumentsDeclaration; + } + variant; constructor(ast, offset, options) { diff --git a/src/slang-nodes/ArrayExpression.js b/src/slang-nodes/ArrayExpression.js index 04f35e925..fbde98c9c 100644 --- a/src/slang-nodes/ArrayExpression.js +++ b/src/slang-nodes/ArrayExpression.js @@ -1,10 +1,15 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { ArrayValues } from './ArrayValues.js'; const { group } = doc.builders; export class ArrayExpression extends SlangNode { + get kind() { + return NonterminalKind.ArrayExpression; + } + openBracket; items; diff --git a/src/slang-nodes/ArrayTypeName.js b/src/slang-nodes/ArrayTypeName.js index 5abedecc6..ed10d2ee1 100644 --- a/src/slang-nodes/ArrayTypeName.js +++ b/src/slang-nodes/ArrayTypeName.js @@ -1,8 +1,13 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { TypeName } from './TypeName.js'; import { Expression } from './Expression.js'; export class ArrayTypeName extends SlangNode { + get kind() { + return NonterminalKind.ArrayTypeName; + } + operand; openBracket; diff --git a/src/slang-nodes/ArrayValues.js b/src/slang-nodes/ArrayValues.js index 2898bc3db..66d074cb4 100644 --- a/src/slang-nodes/ArrayValues.js +++ b/src/slang-nodes/ArrayValues.js @@ -1,8 +1,13 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; import { Expression } from './Expression.js'; export class ArrayValues extends SlangNode { + get kind() { + return NonterminalKind.ArrayValues; + } + items; separators; diff --git a/src/slang-nodes/AssemblyFlags.js b/src/slang-nodes/AssemblyFlags.js index 808c1ae32..6fc5b13ca 100644 --- a/src/slang-nodes/AssemblyFlags.js +++ b/src/slang-nodes/AssemblyFlags.js @@ -1,8 +1,13 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; import { StringLiteral } from './StringLiteral.js'; export class AssemblyFlags extends SlangNode { + get kind() { + return NonterminalKind.AssemblyFlags; + } + items; separators; diff --git a/src/slang-nodes/AssemblyFlagsDeclaration.js b/src/slang-nodes/AssemblyFlagsDeclaration.js index 02f73aeca..e4aec3e5c 100644 --- a/src/slang-nodes/AssemblyFlagsDeclaration.js +++ b/src/slang-nodes/AssemblyFlagsDeclaration.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { AssemblyFlags } from './AssemblyFlags.js'; export class AssemblyFlagsDeclaration extends SlangNode { + get kind() { + return NonterminalKind.AssemblyFlagsDeclaration; + } + openParen; flags; diff --git a/src/slang-nodes/AssemblyStatement.js b/src/slang-nodes/AssemblyStatement.js index 19d210c03..307e2505e 100644 --- a/src/slang-nodes/AssemblyStatement.js +++ b/src/slang-nodes/AssemblyStatement.js @@ -1,9 +1,14 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { StringLiteral } from './StringLiteral.js'; import { AssemblyFlagsDeclaration } from './AssemblyFlagsDeclaration.js'; import { YulBlock } from './YulBlock.js'; export class AssemblyStatement extends SlangNode { + get kind() { + return NonterminalKind.AssemblyStatement; + } + assemblyKeyword; label; diff --git a/src/slang-nodes/AssignmentExpression.js b/src/slang-nodes/AssignmentExpression.js index 7fc48dcda..9364e17a7 100644 --- a/src/slang-nodes/AssignmentExpression.js +++ b/src/slang-nodes/AssignmentExpression.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; import { SlangNode } from './SlangNode.js'; import { Expression } from './Expression.js'; @@ -6,6 +7,10 @@ import { Expression } from './Expression.js'; const { group, indent, line } = doc.builders; export class AssignmentExpression extends SlangNode { + get kind() { + return NonterminalKind.AssignmentExpression; + } + leftOperand; operator; diff --git a/src/slang-nodes/BitwiseAndExpression.js b/src/slang-nodes/BitwiseAndExpression.js index 0a6842a31..9f6e2488b 100644 --- a/src/slang-nodes/BitwiseAndExpression.js +++ b/src/slang-nodes/BitwiseAndExpression.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; import { createHugFunction } from '../slang-utils/create-hug-function.js'; import { SlangNode } from './SlangNode.js'; @@ -12,6 +13,10 @@ const postProcess = (properties) => ({ }); export class BitwiseAndExpression extends SlangNode { + get kind() { + return NonterminalKind.BitwiseAndExpression; + } + leftOperand; operator; diff --git a/src/slang-nodes/BitwiseOrExpression.js b/src/slang-nodes/BitwiseOrExpression.js index c903d4fa5..b444b941a 100644 --- a/src/slang-nodes/BitwiseOrExpression.js +++ b/src/slang-nodes/BitwiseOrExpression.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; import { createHugFunction } from '../slang-utils/create-hug-function.js'; import { SlangNode } from './SlangNode.js'; @@ -22,6 +23,10 @@ const postProcess = (properties) => ({ }); export class BitwiseOrExpression extends SlangNode { + get kind() { + return NonterminalKind.BitwiseOrExpression; + } + leftOperand; operator; diff --git a/src/slang-nodes/BitwiseXorExpression.js b/src/slang-nodes/BitwiseXorExpression.js index 84c58efd4..e78469935 100644 --- a/src/slang-nodes/BitwiseXorExpression.js +++ b/src/slang-nodes/BitwiseXorExpression.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; import { createHugFunction } from '../slang-utils/create-hug-function.js'; import { SlangNode } from './SlangNode.js'; @@ -12,6 +13,10 @@ const postProcess = (properties) => ({ }); export class BitwiseXorExpression extends SlangNode { + get kind() { + return NonterminalKind.BitwiseXorExpression; + } + leftOperand; operator; diff --git a/src/slang-nodes/Block.js b/src/slang-nodes/Block.js index 52375ffc2..287cb3520 100644 --- a/src/slang-nodes/Block.js +++ b/src/slang-nodes/Block.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { Statements } from './Statements.js'; export class Block extends SlangNode { + get kind() { + return NonterminalKind.Block; + } + openBrace; statements; diff --git a/src/slang-nodes/BreakStatement.js b/src/slang-nodes/BreakStatement.js index 913427db9..05b621a75 100644 --- a/src/slang-nodes/BreakStatement.js +++ b/src/slang-nodes/BreakStatement.js @@ -1,6 +1,11 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; export class BreakStatement extends SlangNode { + get kind() { + return NonterminalKind.BreakStatement; + } + breakKeyword; semicolon; diff --git a/src/slang-nodes/CallOptions.js b/src/slang-nodes/CallOptions.js index 7b210514b..f671fa8e8 100644 --- a/src/slang-nodes/CallOptions.js +++ b/src/slang-nodes/CallOptions.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; import { NamedArgument } from './NamedArgument.js'; @@ -6,6 +7,10 @@ import { NamedArgument } from './NamedArgument.js'; const { line, softline } = doc.builders; export class CallOptions extends SlangNode { + get kind() { + return NonterminalKind.CallOptions; + } + items; separators; diff --git a/src/slang-nodes/CallOptionsExpression.js b/src/slang-nodes/CallOptionsExpression.js index 2e052b258..8388ba8cf 100644 --- a/src/slang-nodes/CallOptionsExpression.js +++ b/src/slang-nodes/CallOptionsExpression.js @@ -1,8 +1,13 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { Expression } from './Expression.js'; import { CallOptions } from './CallOptions.js'; export class CallOptionsExpression extends SlangNode { + get kind() { + return NonterminalKind.CallOptionsExpression; + } + operand; openBrace; diff --git a/src/slang-nodes/CatchClause.js b/src/slang-nodes/CatchClause.js index e643af0e0..e062b2f77 100644 --- a/src/slang-nodes/CatchClause.js +++ b/src/slang-nodes/CatchClause.js @@ -1,8 +1,13 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { CatchClauseError } from './CatchClauseError.js'; import { Block } from './Block.js'; export class CatchClause extends SlangNode { + get kind() { + return NonterminalKind.CatchClause; + } + catchKeyword; error; diff --git a/src/slang-nodes/CatchClauseError.js b/src/slang-nodes/CatchClauseError.js index c508e631e..084867770 100644 --- a/src/slang-nodes/CatchClauseError.js +++ b/src/slang-nodes/CatchClauseError.js @@ -1,10 +1,15 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { ParametersDeclaration } from './ParametersDeclaration.js'; const { group } = doc.builders; export class CatchClauseError extends SlangNode { + get kind() { + return NonterminalKind.CatchClauseError; + } + name; parameters; diff --git a/src/slang-nodes/CatchClauses.js b/src/slang-nodes/CatchClauses.js index a17f79eb7..5e122ccb9 100644 --- a/src/slang-nodes/CatchClauses.js +++ b/src/slang-nodes/CatchClauses.js @@ -1,10 +1,15 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { CatchClause } from './CatchClause.js'; const { join } = doc.builders; export class CatchClauses extends SlangNode { + get kind() { + return NonterminalKind.CatchClauses; + } + items; constructor(ast, offset, options) { diff --git a/src/slang-nodes/ComparisonExpression.js b/src/slang-nodes/ComparisonExpression.js index 49b9897b6..ff61a6c64 100644 --- a/src/slang-nodes/ComparisonExpression.js +++ b/src/slang-nodes/ComparisonExpression.js @@ -1,8 +1,13 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printComparisonOperation } from '../slang-printers/print-comparison-operation.js'; import { SlangNode } from './SlangNode.js'; import { Expression } from './Expression.js'; export class ComparisonExpression extends SlangNode { + get kind() { + return NonterminalKind.ComparisonExpression; + } + leftOperand; operator; diff --git a/src/slang-nodes/ConditionalExpression.js b/src/slang-nodes/ConditionalExpression.js index 492429a40..ff63ea0cd 100644 --- a/src/slang-nodes/ConditionalExpression.js +++ b/src/slang-nodes/ConditionalExpression.js @@ -1,5 +1,6 @@ /* eslint-disable no-nested-ternary */ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedItem } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; import { Expression } from './Expression.js'; @@ -107,6 +108,10 @@ function traditionalTernaries(node, path, print) { } export class ConditionalExpression extends SlangNode { + get kind() { + return NonterminalKind.ConditionalExpression; + } + operand; questionMark; diff --git a/src/slang-nodes/ConstantDefinition.js b/src/slang-nodes/ConstantDefinition.js index ff7b76f3d..72410d01b 100644 --- a/src/slang-nodes/ConstantDefinition.js +++ b/src/slang-nodes/ConstantDefinition.js @@ -1,8 +1,13 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { TypeName } from './TypeName.js'; import { Expression } from './Expression.js'; export class ConstantDefinition extends SlangNode { + get kind() { + return NonterminalKind.ConstantDefinition; + } + typeName; constantKeyword; diff --git a/src/slang-nodes/ConstructorAttribute.js b/src/slang-nodes/ConstructorAttribute.js index 128606210..d0e66a1ed 100644 --- a/src/slang-nodes/ConstructorAttribute.js +++ b/src/slang-nodes/ConstructorAttribute.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { ModifierInvocation } from './ModifierInvocation.js'; export class ConstructorAttribute extends SlangNode { + get kind() { + return NonterminalKind.ConstructorAttribute; + } + variant; constructor(ast, offset, options) { diff --git a/src/slang-nodes/ConstructorAttributes.js b/src/slang-nodes/ConstructorAttributes.js index f442e9505..55ff380c8 100644 --- a/src/slang-nodes/ConstructorAttributes.js +++ b/src/slang-nodes/ConstructorAttributes.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { postProcessFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; import { SlangNode } from './SlangNode.js'; import { ConstructorAttribute } from './ConstructorAttribute.js'; @@ -6,6 +7,10 @@ import { ConstructorAttribute } from './ConstructorAttribute.js'; const { line } = doc.builders; export class ConstructorAttributes extends SlangNode { + get kind() { + return NonterminalKind.ConstructorAttributes; + } + items; constructor(ast, offset, options) { diff --git a/src/slang-nodes/ConstructorDefinition.js b/src/slang-nodes/ConstructorDefinition.js index a5380ae64..e5a33ec06 100644 --- a/src/slang-nodes/ConstructorDefinition.js +++ b/src/slang-nodes/ConstructorDefinition.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printFunction } from '../slang-printers/print-function.js'; import { SlangNode } from './SlangNode.js'; import { ParametersDeclaration } from './ParametersDeclaration.js'; @@ -5,6 +6,10 @@ import { ConstructorAttributes } from './ConstructorAttributes.js'; import { Block } from './Block.js'; export class ConstructorDefinition extends SlangNode { + get kind() { + return NonterminalKind.ConstructorDefinition; + } + constructorKeyword; parameters; diff --git a/src/slang-nodes/ContinueStatement.js b/src/slang-nodes/ContinueStatement.js index 53276339b..6bd7d0753 100644 --- a/src/slang-nodes/ContinueStatement.js +++ b/src/slang-nodes/ContinueStatement.js @@ -1,6 +1,11 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; export class ContinueStatement extends SlangNode { + get kind() { + return NonterminalKind.ContinueStatement; + } + continueKeyword; semicolon; diff --git a/src/slang-nodes/ContractDefinition.js b/src/slang-nodes/ContractDefinition.js index 56361dd19..88884fc41 100644 --- a/src/slang-nodes/ContractDefinition.js +++ b/src/slang-nodes/ContractDefinition.js @@ -1,6 +1,7 @@ import { doc } from 'prettier'; import coerce from 'semver/functions/coerce.js'; import satisfies from 'semver/functions/satisfies.js'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { InheritanceSpecifier } from './InheritanceSpecifier.js'; import { ContractMembers } from './ContractMembers.js'; @@ -8,6 +9,10 @@ import { ContractMembers } from './ContractMembers.js'; const { group, line } = doc.builders; export class ContractDefinition extends SlangNode { + get kind() { + return NonterminalKind.ContractDefinition; + } + abstractKeyword; contractKeyword; diff --git a/src/slang-nodes/ContractMember.js b/src/slang-nodes/ContractMember.js index 2bb7f7f9f..4be15338b 100644 --- a/src/slang-nodes/ContractMember.js +++ b/src/slang-nodes/ContractMember.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { UsingDirective } from './UsingDirective.js'; import { FunctionDefinition } from './FunctionDefinition.js'; @@ -30,6 +31,10 @@ const variants = { }; export class ContractMember extends SlangNode { + get kind() { + return NonterminalKind.ContractMember; + } + variant; constructor(ast, offset, options) { diff --git a/src/slang-nodes/ContractMembers.js b/src/slang-nodes/ContractMembers.js index 1f7b481aa..68a067371 100644 --- a/src/slang-nodes/ContractMembers.js +++ b/src/slang-nodes/ContractMembers.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedItem } from '../common/printer-helpers.js'; import { printComments } from '../slang-printers/print-comments.js'; import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; @@ -8,6 +9,10 @@ import { ContractMember } from './ContractMember.js'; const { hardline } = doc.builders; export class ContractMembers extends SlangNode { + get kind() { + return NonterminalKind.ContractMembers; + } + items; constructor(ast, offset, options) { diff --git a/src/slang-nodes/DecimalNumberExpression.js b/src/slang-nodes/DecimalNumberExpression.js index 990820cd3..e0966de9f 100644 --- a/src/slang-nodes/DecimalNumberExpression.js +++ b/src/slang-nodes/DecimalNumberExpression.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { NumberUnit } from './NumberUnit.js'; export class DecimalNumberExpression extends SlangNode { + get kind() { + return NonterminalKind.DecimalNumberExpression; + } + literal; unit; diff --git a/src/slang-nodes/DoWhileStatement.js b/src/slang-nodes/DoWhileStatement.js index 63881d85c..3593f5ef5 100644 --- a/src/slang-nodes/DoWhileStatement.js +++ b/src/slang-nodes/DoWhileStatement.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedItem } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; import { Statement } from './Statement.js'; @@ -7,6 +8,10 @@ import { Expression } from './Expression.js'; const { group, indent, line } = doc.builders; export class DoWhileStatement extends SlangNode { + get kind() { + return NonterminalKind.DoWhileStatement; + } + doKeyword; body; diff --git a/src/slang-nodes/ElementaryType.js b/src/slang-nodes/ElementaryType.js index 0ed9b9d9f..ce958effc 100644 --- a/src/slang-nodes/ElementaryType.js +++ b/src/slang-nodes/ElementaryType.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { AddressType } from './AddressType.js'; export class ElementaryType extends SlangNode { + get kind() { + return NonterminalKind.ElementaryType; + } + variant; constructor(ast, offset, options) { diff --git a/src/slang-nodes/ElseBranch.js b/src/slang-nodes/ElseBranch.js index 94febb337..59d2ae8dc 100644 --- a/src/slang-nodes/ElseBranch.js +++ b/src/slang-nodes/ElseBranch.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js'; import { SlangNode } from './SlangNode.js'; import { Statement } from './Statement.js'; @@ -8,6 +9,10 @@ const { group, indent, line } = doc.builders; const isIfStatementOrBlock = createKindCheckFunction(['Block', 'IfStatement']); export class ElseBranch extends SlangNode { + get kind() { + return NonterminalKind.ElseBranch; + } + elseKeyword; body; diff --git a/src/slang-nodes/EmitStatement.js b/src/slang-nodes/EmitStatement.js index bf30cca5d..68e13f1ad 100644 --- a/src/slang-nodes/EmitStatement.js +++ b/src/slang-nodes/EmitStatement.js @@ -1,8 +1,13 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { IdentifierPath } from './IdentifierPath.js'; import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; export class EmitStatement extends SlangNode { + get kind() { + return NonterminalKind.EmitStatement; + } + emitKeyword; event; diff --git a/src/slang-nodes/EnumDefinition.js b/src/slang-nodes/EnumDefinition.js index 8be32762e..28b1092a5 100644 --- a/src/slang-nodes/EnumDefinition.js +++ b/src/slang-nodes/EnumDefinition.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { EnumMembers } from './EnumMembers.js'; export class EnumDefinition extends SlangNode { + get kind() { + return NonterminalKind.EnumDefinition; + } + enumKeyword; name; diff --git a/src/slang-nodes/EnumMembers.js b/src/slang-nodes/EnumMembers.js index aa33ccf9f..973046a4f 100644 --- a/src/slang-nodes/EnumMembers.js +++ b/src/slang-nodes/EnumMembers.js @@ -1,10 +1,15 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; const { hardline } = doc.builders; export class EnumMembers extends SlangNode { + get kind() { + return NonterminalKind.EnumMembers; + } + items; separators; diff --git a/src/slang-nodes/EqualityExpression.js b/src/slang-nodes/EqualityExpression.js index 2333a6629..30a2bf9c1 100644 --- a/src/slang-nodes/EqualityExpression.js +++ b/src/slang-nodes/EqualityExpression.js @@ -1,8 +1,13 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printComparisonOperation } from '../slang-printers/print-comparison-operation.js'; import { SlangNode } from './SlangNode.js'; import { Expression } from './Expression.js'; export class EqualityExpression extends SlangNode { + get kind() { + return NonterminalKind.EqualityExpression; + } + leftOperand; operator; diff --git a/src/slang-nodes/ErrorDefinition.js b/src/slang-nodes/ErrorDefinition.js index b107d21a1..6fc8c98c2 100644 --- a/src/slang-nodes/ErrorDefinition.js +++ b/src/slang-nodes/ErrorDefinition.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { ErrorParametersDeclaration } from './ErrorParametersDeclaration.js'; export class ErrorDefinition extends SlangNode { + get kind() { + return NonterminalKind.ErrorDefinition; + } + errorKeyword; name; diff --git a/src/slang-nodes/ErrorParameter.js b/src/slang-nodes/ErrorParameter.js index fcb703de9..12655e716 100644 --- a/src/slang-nodes/ErrorParameter.js +++ b/src/slang-nodes/ErrorParameter.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { TypeName } from './TypeName.js'; export class ErrorParameter extends SlangNode { + get kind() { + return NonterminalKind.ErrorParameter; + } + typeName; name; diff --git a/src/slang-nodes/ErrorParameters.js b/src/slang-nodes/ErrorParameters.js index f85cbf69e..249ec978e 100644 --- a/src/slang-nodes/ErrorParameters.js +++ b/src/slang-nodes/ErrorParameters.js @@ -1,8 +1,13 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; import { ErrorParameter } from './ErrorParameter.js'; export class ErrorParameters extends SlangNode { + get kind() { + return NonterminalKind.ErrorParameters; + } + items; separators; diff --git a/src/slang-nodes/ErrorParametersDeclaration.js b/src/slang-nodes/ErrorParametersDeclaration.js index 2a19d2c49..85722e2e4 100644 --- a/src/slang-nodes/ErrorParametersDeclaration.js +++ b/src/slang-nodes/ErrorParametersDeclaration.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { ErrorParameters } from './ErrorParameters.js'; export class ErrorParametersDeclaration extends SlangNode { + get kind() { + return NonterminalKind.ErrorParametersDeclaration; + } + openParen; parameters; diff --git a/src/slang-nodes/EventDefinition.js b/src/slang-nodes/EventDefinition.js index 900fb6abd..ae85a1b41 100644 --- a/src/slang-nodes/EventDefinition.js +++ b/src/slang-nodes/EventDefinition.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { EventParametersDeclaration } from './EventParametersDeclaration.js'; export class EventDefinition extends SlangNode { + get kind() { + return NonterminalKind.EventDefinition; + } + eventKeyword; name; diff --git a/src/slang-nodes/EventParameter.js b/src/slang-nodes/EventParameter.js index c465adbdf..36b679f5e 100644 --- a/src/slang-nodes/EventParameter.js +++ b/src/slang-nodes/EventParameter.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { TypeName } from './TypeName.js'; export class EventParameter extends SlangNode { + get kind() { + return NonterminalKind.EventParameter; + } + typeName; indexedKeyword; diff --git a/src/slang-nodes/EventParameters.js b/src/slang-nodes/EventParameters.js index 381159d3c..34602fd45 100644 --- a/src/slang-nodes/EventParameters.js +++ b/src/slang-nodes/EventParameters.js @@ -1,8 +1,13 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; import { EventParameter } from './EventParameter.js'; export class EventParameters extends SlangNode { + get kind() { + return NonterminalKind.EventParameters; + } + items; separators; diff --git a/src/slang-nodes/EventParametersDeclaration.js b/src/slang-nodes/EventParametersDeclaration.js index 967045df2..c720ef946 100644 --- a/src/slang-nodes/EventParametersDeclaration.js +++ b/src/slang-nodes/EventParametersDeclaration.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { EventParameters } from './EventParameters.js'; export class EventParametersDeclaration extends SlangNode { + get kind() { + return NonterminalKind.EventParametersDeclaration; + } + openParen; parameters; diff --git a/src/slang-nodes/ExperimentalFeature.js b/src/slang-nodes/ExperimentalFeature.js index 7ce26c51d..c4b7e0fa0 100644 --- a/src/slang-nodes/ExperimentalFeature.js +++ b/src/slang-nodes/ExperimentalFeature.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { StringLiteral } from './StringLiteral.js'; export class ExperimentalFeature extends SlangNode { + get kind() { + return NonterminalKind.ExperimentalFeature; + } + variant; constructor(ast, offset, options) { diff --git a/src/slang-nodes/ExperimentalPragma.js b/src/slang-nodes/ExperimentalPragma.js index d8a6c4723..3ec9aae36 100644 --- a/src/slang-nodes/ExperimentalPragma.js +++ b/src/slang-nodes/ExperimentalPragma.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { ExperimentalFeature } from './ExperimentalFeature.js'; export class ExperimentalPragma extends SlangNode { + get kind() { + return NonterminalKind.ExperimentalPragma; + } + experimentalKeyword; feature; diff --git a/src/slang-nodes/ExponentiationExpression.js b/src/slang-nodes/ExponentiationExpression.js index 5f6585e99..05c67ede9 100644 --- a/src/slang-nodes/ExponentiationExpression.js +++ b/src/slang-nodes/ExponentiationExpression.js @@ -1,6 +1,7 @@ import { doc } from 'prettier'; import coerce from 'semver/functions/coerce.js'; import satisfies from 'semver/functions/satisfies.js'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { createBinaryOperationPrinter } from '../slang-printers/create-binary-operation-printer.js'; import { createHugFunction } from '../slang-utils/create-hug-function.js'; import { SlangNode } from './SlangNode.js'; @@ -19,6 +20,10 @@ const printExponentiationExpression = createBinaryOperationPrinter( ); export class ExponentiationExpression extends SlangNode { + get kind() { + return NonterminalKind.ExponentiationExpression; + } + leftOperand; operator; @@ -64,24 +69,18 @@ export class ExponentiationExpression extends SlangNode { end: this.rightOperand.variant.leftOperand.loc.end }; this.leftOperand = new Expression({ - kind: 'Expression', loc: { ...leftLoc }, variant: new TupleExpression({ - kind: 'TupleExpression', loc: { ...leftLoc }, openParen: '(', items: new TupleValues({ - kind: 'TupleValues', loc: { ...leftLoc }, items: [ new TupleValue({ - kind: 'TupleValue', loc: { ...leftLoc }, expression: new Expression({ - kind: 'Expression', loc: { ...leftLoc }, variant: new ExponentiationExpression({ - kind: 'ExponentiationExpression', loc: { ...leftLoc }, leftOperand: this.leftOperand, operator: '**', @@ -101,7 +100,6 @@ export class ExponentiationExpression extends SlangNode { } } } else { - this.kind = ast.kind; this.loc = ast.loc; this.leftOperand = ast.leftOperand; this.operator = ast.operator; diff --git a/src/slang-nodes/Expression.js b/src/slang-nodes/Expression.js index bbdd555d4..74322359e 100644 --- a/src/slang-nodes/Expression.js +++ b/src/slang-nodes/Expression.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { AssignmentExpression } from './AssignmentExpression.js'; import { ConditionalExpression } from './ConditionalExpression.js'; @@ -58,6 +59,10 @@ const variants = { }; export class Expression extends SlangNode { + get kind() { + return NonterminalKind.Expression; + } + variant; constructor(ast, offset, options) { @@ -77,7 +82,6 @@ export class Expression extends SlangNode { this.initialize(ast, offset, fetch); } else { - this.kind = ast.kind; this.loc = ast.loc; this.variant = ast.variant; } diff --git a/src/slang-nodes/ExpressionStatement.js b/src/slang-nodes/ExpressionStatement.js index 75a6cacd1..950fe4265 100644 --- a/src/slang-nodes/ExpressionStatement.js +++ b/src/slang-nodes/ExpressionStatement.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { Expression } from './Expression.js'; export class ExpressionStatement extends SlangNode { + get kind() { + return NonterminalKind.ExpressionStatement; + } + expression; semicolon; diff --git a/src/slang-nodes/FallbackFunctionAttribute.js b/src/slang-nodes/FallbackFunctionAttribute.js index 80a06f453..14ab0490c 100644 --- a/src/slang-nodes/FallbackFunctionAttribute.js +++ b/src/slang-nodes/FallbackFunctionAttribute.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { ModifierInvocation } from './ModifierInvocation.js'; import { OverrideSpecifier } from './OverrideSpecifier.js'; @@ -5,6 +6,10 @@ import { OverrideSpecifier } from './OverrideSpecifier.js'; const variants = { ModifierInvocation, OverrideSpecifier }; export class FallbackFunctionAttribute extends SlangNode { + get kind() { + return NonterminalKind.FallbackFunctionAttribute; + } + variant; constructor(ast, offset, options) { diff --git a/src/slang-nodes/FallbackFunctionAttributes.js b/src/slang-nodes/FallbackFunctionAttributes.js index 9935a88f2..74c3e5a70 100644 --- a/src/slang-nodes/FallbackFunctionAttributes.js +++ b/src/slang-nodes/FallbackFunctionAttributes.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { postProcessFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; import { SlangNode } from './SlangNode.js'; import { FallbackFunctionAttribute } from './FallbackFunctionAttribute.js'; @@ -6,6 +7,10 @@ import { FallbackFunctionAttribute } from './FallbackFunctionAttribute.js'; const { line } = doc.builders; export class FallbackFunctionAttributes extends SlangNode { + get kind() { + return NonterminalKind.FallbackFunctionAttributes; + } + items; constructor(ast, offset, options) { diff --git a/src/slang-nodes/FallbackFunctionDefinition.js b/src/slang-nodes/FallbackFunctionDefinition.js index 8c508ed10..d3626018a 100644 --- a/src/slang-nodes/FallbackFunctionDefinition.js +++ b/src/slang-nodes/FallbackFunctionDefinition.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printFunction } from '../slang-printers/print-function.js'; import { SlangNode } from './SlangNode.js'; import { ParametersDeclaration } from './ParametersDeclaration.js'; @@ -6,6 +7,10 @@ import { ReturnsDeclaration } from './ReturnsDeclaration.js'; import { FunctionBody } from './FunctionBody.js'; export class FallbackFunctionDefinition extends SlangNode { + get kind() { + return NonterminalKind.FallbackFunctionDefinition; + } + fallbackKeyword; parameters; diff --git a/src/slang-nodes/ForStatement.js b/src/slang-nodes/ForStatement.js index ffa1d3404..37d189fc6 100644 --- a/src/slang-nodes/ForStatement.js +++ b/src/slang-nodes/ForStatement.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; import { ForStatementInitialization } from './ForStatementInitialization.js'; @@ -9,6 +10,10 @@ import { Statement } from './Statement.js'; const { group, indent, line } = doc.builders; export class ForStatement extends SlangNode { + get kind() { + return NonterminalKind.ForStatement; + } + forKeyword; openParen; diff --git a/src/slang-nodes/ForStatementCondition.js b/src/slang-nodes/ForStatementCondition.js index ec1e29f47..1df9ce7e1 100644 --- a/src/slang-nodes/ForStatementCondition.js +++ b/src/slang-nodes/ForStatementCondition.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { ExpressionStatement } from './ExpressionStatement.js'; export class ForStatementCondition extends SlangNode { + get kind() { + return NonterminalKind.ForStatementCondition; + } + variant; constructor(ast, offset, options) { diff --git a/src/slang-nodes/ForStatementInitialization.js b/src/slang-nodes/ForStatementInitialization.js index af56c8f0f..7db2281b1 100644 --- a/src/slang-nodes/ForStatementInitialization.js +++ b/src/slang-nodes/ForStatementInitialization.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { ExpressionStatement } from './ExpressionStatement.js'; import { VariableDeclarationStatement } from './VariableDeclarationStatement.js'; @@ -10,6 +11,10 @@ const variants = { }; export class ForStatementInitialization extends SlangNode { + get kind() { + return NonterminalKind.ForStatementInitialization; + } + variant; constructor(ast, offset, options) { diff --git a/src/slang-nodes/FunctionAttribute.js b/src/slang-nodes/FunctionAttribute.js index 08a467082..a98e75043 100644 --- a/src/slang-nodes/FunctionAttribute.js +++ b/src/slang-nodes/FunctionAttribute.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { ModifierInvocation } from './ModifierInvocation.js'; import { OverrideSpecifier } from './OverrideSpecifier.js'; @@ -5,6 +6,10 @@ import { OverrideSpecifier } from './OverrideSpecifier.js'; const variants = { ModifierInvocation, OverrideSpecifier }; export class FunctionAttribute extends SlangNode { + get kind() { + return NonterminalKind.FunctionAttribute; + } + variant; constructor(ast, offset, options) { diff --git a/src/slang-nodes/FunctionAttributes.js b/src/slang-nodes/FunctionAttributes.js index c8a4e93be..912285e93 100644 --- a/src/slang-nodes/FunctionAttributes.js +++ b/src/slang-nodes/FunctionAttributes.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { postProcessFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; import { SlangNode } from './SlangNode.js'; import { FunctionAttribute } from './FunctionAttribute.js'; @@ -6,6 +7,10 @@ import { FunctionAttribute } from './FunctionAttribute.js'; const { line } = doc.builders; export class FunctionAttributes extends SlangNode { + get kind() { + return NonterminalKind.FunctionAttributes; + } + items; constructor(ast, offset, options) { diff --git a/src/slang-nodes/FunctionBody.js b/src/slang-nodes/FunctionBody.js index 2076651f0..d09f45ae4 100644 --- a/src/slang-nodes/FunctionBody.js +++ b/src/slang-nodes/FunctionBody.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { Block } from './Block.js'; export class FunctionBody extends SlangNode { + get kind() { + return NonterminalKind.FunctionBody; + } + variant; constructor(ast, offset, options) { diff --git a/src/slang-nodes/FunctionCallExpression.js b/src/slang-nodes/FunctionCallExpression.js index 69e35f1f2..b3402679c 100644 --- a/src/slang-nodes/FunctionCallExpression.js +++ b/src/slang-nodes/FunctionCallExpression.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { isLabel } from '../common/util.js'; import { SlangNode } from './SlangNode.js'; import { Expression } from './Expression.js'; @@ -7,6 +8,10 @@ import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; const { group, indentIfBreak, label } = doc.builders; export class FunctionCallExpression extends SlangNode { + get kind() { + return NonterminalKind.FunctionCallExpression; + } + operand; arguments; diff --git a/src/slang-nodes/FunctionDefinition.js b/src/slang-nodes/FunctionDefinition.js index 64a05aab3..fda12c7ed 100644 --- a/src/slang-nodes/FunctionDefinition.js +++ b/src/slang-nodes/FunctionDefinition.js @@ -1,5 +1,6 @@ import coerce from 'semver/functions/coerce.js'; import satisfies from 'semver/functions/satisfies.js'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printFunction } from '../slang-printers/print-function.js'; import { SlangNode } from './SlangNode.js'; import { FunctionName } from './FunctionName.js'; @@ -9,6 +10,10 @@ import { ReturnsDeclaration } from './ReturnsDeclaration.js'; import { FunctionBody } from './FunctionBody.js'; export class FunctionDefinition extends SlangNode { + get kind() { + return NonterminalKind.FunctionDefinition; + } + functionKeyword; name; diff --git a/src/slang-nodes/FunctionName.js b/src/slang-nodes/FunctionName.js index b3fa12e8c..18efe98dc 100644 --- a/src/slang-nodes/FunctionName.js +++ b/src/slang-nodes/FunctionName.js @@ -1,6 +1,11 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; export class FunctionName extends SlangNode { + get kind() { + return NonterminalKind.FunctionName; + } + variant; constructor(ast, offset) { diff --git a/src/slang-nodes/FunctionType.js b/src/slang-nodes/FunctionType.js index 4bd226f41..afa3ae47d 100644 --- a/src/slang-nodes/FunctionType.js +++ b/src/slang-nodes/FunctionType.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printFunction } from '../slang-printers/print-function.js'; import { SlangNode } from './SlangNode.js'; import { ParametersDeclaration } from './ParametersDeclaration.js'; @@ -5,6 +6,10 @@ import { FunctionTypeAttributes } from './FunctionTypeAttributes.js'; import { ReturnsDeclaration } from './ReturnsDeclaration.js'; export class FunctionType extends SlangNode { + get kind() { + return NonterminalKind.FunctionType; + } + functionKeyword; parameters; diff --git a/src/slang-nodes/FunctionTypeAttribute.js b/src/slang-nodes/FunctionTypeAttribute.js index f4f300f40..ee5ae8309 100644 --- a/src/slang-nodes/FunctionTypeAttribute.js +++ b/src/slang-nodes/FunctionTypeAttribute.js @@ -1,6 +1,11 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; export class FunctionTypeAttribute extends SlangNode { + get kind() { + return NonterminalKind.FunctionTypeAttribute; + } + variant; constructor(ast, offset) { diff --git a/src/slang-nodes/FunctionTypeAttributes.js b/src/slang-nodes/FunctionTypeAttributes.js index 6b91fb3a7..dec445ebf 100644 --- a/src/slang-nodes/FunctionTypeAttributes.js +++ b/src/slang-nodes/FunctionTypeAttributes.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { postProcessFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; import { SlangNode } from './SlangNode.js'; import { FunctionTypeAttribute } from './FunctionTypeAttribute.js'; @@ -6,6 +7,10 @@ import { FunctionTypeAttribute } from './FunctionTypeAttribute.js'; const { line } = doc.builders; export class FunctionTypeAttributes extends SlangNode { + get kind() { + return NonterminalKind.FunctionTypeAttributes; + } + items; constructor(ast, offset, options) { diff --git a/src/slang-nodes/HexNumberExpression.js b/src/slang-nodes/HexNumberExpression.js index 715498b41..580da158a 100644 --- a/src/slang-nodes/HexNumberExpression.js +++ b/src/slang-nodes/HexNumberExpression.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { NumberUnit } from './NumberUnit.js'; export class HexNumberExpression extends SlangNode { + get kind() { + return NonterminalKind.HexNumberExpression; + } + literal; unit; diff --git a/src/slang-nodes/HexStringLiteral.js b/src/slang-nodes/HexStringLiteral.js index e49edef68..9c15cf596 100644 --- a/src/slang-nodes/HexStringLiteral.js +++ b/src/slang-nodes/HexStringLiteral.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printString } from '../slang-printers/print-string.js'; import { SlangNode } from './SlangNode.js'; @@ -6,6 +7,10 @@ const postProcess = (options) => (properties) => ({ }); export class HexStringLiteral extends SlangNode { + get kind() { + return NonterminalKind.HexStringLiteral; + } + variant; constructor(ast, offset, options) { diff --git a/src/slang-nodes/HexStringLiterals.js b/src/slang-nodes/HexStringLiterals.js index c06e74a51..2a3e63e99 100644 --- a/src/slang-nodes/HexStringLiterals.js +++ b/src/slang-nodes/HexStringLiterals.js @@ -1,10 +1,15 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { HexStringLiteral } from './HexStringLiteral.js'; const { join, hardline } = doc.builders; export class HexStringLiterals extends SlangNode { + get kind() { + return NonterminalKind.HexStringLiterals; + } + items; constructor(ast, offset, options) { diff --git a/src/slang-nodes/IdentifierPath.js b/src/slang-nodes/IdentifierPath.js index a4855ea54..684393c7a 100644 --- a/src/slang-nodes/IdentifierPath.js +++ b/src/slang-nodes/IdentifierPath.js @@ -1,6 +1,11 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; export class IdentifierPath extends SlangNode { + get kind() { + return NonterminalKind.IdentifierPath; + } + items; separators; diff --git a/src/slang-nodes/IfStatement.js b/src/slang-nodes/IfStatement.js index 07b616f97..c5b7ea3d4 100644 --- a/src/slang-nodes/IfStatement.js +++ b/src/slang-nodes/IfStatement.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedItem } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; import { Expression } from './Expression.js'; @@ -8,6 +9,10 @@ import { ElseBranch } from './ElseBranch.js'; const { group, hardline, indent, line } = doc.builders; export class IfStatement extends SlangNode { + get kind() { + return NonterminalKind.IfStatement; + } + ifKeyword; openParen; diff --git a/src/slang-nodes/ImportAlias.js b/src/slang-nodes/ImportAlias.js index 3a05b6641..cecdfdb6d 100644 --- a/src/slang-nodes/ImportAlias.js +++ b/src/slang-nodes/ImportAlias.js @@ -1,6 +1,11 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; export class ImportAlias extends SlangNode { + get kind() { + return NonterminalKind.ImportAlias; + } + asKeyword; identifier; diff --git a/src/slang-nodes/ImportClause.js b/src/slang-nodes/ImportClause.js index 2ca06a45e..b722afb8b 100644 --- a/src/slang-nodes/ImportClause.js +++ b/src/slang-nodes/ImportClause.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { PathImport } from './PathImport.js'; import { NamedImport } from './NamedImport.js'; @@ -6,6 +7,10 @@ import { ImportDeconstruction } from './ImportDeconstruction.js'; const variants = { PathImport, NamedImport, ImportDeconstruction }; export class ImportClause extends SlangNode { + get kind() { + return NonterminalKind.ImportClause; + } + variant; constructor(ast, offset, options) { diff --git a/src/slang-nodes/ImportDeconstruction.js b/src/slang-nodes/ImportDeconstruction.js index cabb99abc..1634ff1ec 100644 --- a/src/slang-nodes/ImportDeconstruction.js +++ b/src/slang-nodes/ImportDeconstruction.js @@ -1,8 +1,13 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { ImportDeconstructionSymbols } from './ImportDeconstructionSymbols.js'; import { StringLiteral } from './StringLiteral.js'; export class ImportDeconstruction extends SlangNode { + get kind() { + return NonterminalKind.ImportDeconstruction; + } + openBrace; symbols; diff --git a/src/slang-nodes/ImportDeconstructionSymbol.js b/src/slang-nodes/ImportDeconstructionSymbol.js index 4fb4e604e..7f6f66668 100644 --- a/src/slang-nodes/ImportDeconstructionSymbol.js +++ b/src/slang-nodes/ImportDeconstructionSymbol.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { ImportAlias } from './ImportAlias.js'; export class ImportDeconstructionSymbol extends SlangNode { + get kind() { + return NonterminalKind.ImportDeconstructionSymbol; + } + name; alias; diff --git a/src/slang-nodes/ImportDeconstructionSymbols.js b/src/slang-nodes/ImportDeconstructionSymbols.js index b369b20a1..16ca65570 100644 --- a/src/slang-nodes/ImportDeconstructionSymbols.js +++ b/src/slang-nodes/ImportDeconstructionSymbols.js @@ -1,6 +1,7 @@ import { doc } from 'prettier'; import coerce from 'semver/functions/coerce.js'; import satisfies from 'semver/functions/satisfies.js'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; import { ImportDeconstructionSymbol } from './ImportDeconstructionSymbol.js'; @@ -8,6 +9,10 @@ import { ImportDeconstructionSymbol } from './ImportDeconstructionSymbol.js'; const { line, softline } = doc.builders; export class ImportDeconstructionSymbols extends SlangNode { + get kind() { + return NonterminalKind.ImportDeconstructionSymbols; + } + items; separators; diff --git a/src/slang-nodes/ImportDirective.js b/src/slang-nodes/ImportDirective.js index 5640ecdbb..ca606aaaf 100644 --- a/src/slang-nodes/ImportDirective.js +++ b/src/slang-nodes/ImportDirective.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { ImportClause } from './ImportClause.js'; export class ImportDirective extends SlangNode { + get kind() { + return NonterminalKind.ImportDirective; + } + importKeyword; clause; diff --git a/src/slang-nodes/IndexAccessEnd.js b/src/slang-nodes/IndexAccessEnd.js index 090e9081d..dd0ed128e 100644 --- a/src/slang-nodes/IndexAccessEnd.js +++ b/src/slang-nodes/IndexAccessEnd.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { Expression } from './Expression.js'; export class IndexAccessEnd extends SlangNode { + get kind() { + return NonterminalKind.IndexAccessEnd; + } + colon; end; diff --git a/src/slang-nodes/IndexAccessExpression.js b/src/slang-nodes/IndexAccessExpression.js index 46e44c8e9..699f17594 100644 --- a/src/slang-nodes/IndexAccessExpression.js +++ b/src/slang-nodes/IndexAccessExpression.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { isLabel } from '../common/util.js'; import { SlangNode } from './SlangNode.js'; import { Expression } from './Expression.js'; @@ -7,6 +8,10 @@ import { IndexAccessEnd } from './IndexAccessEnd.js'; const { group, indent, indentIfBreak, label, softline } = doc.builders; export class IndexAccessExpression extends SlangNode { + get kind() { + return NonterminalKind.IndexAccessExpression; + } + operand; openBracket; diff --git a/src/slang-nodes/InheritanceSpecifier.js b/src/slang-nodes/InheritanceSpecifier.js index 58c8f5d51..95f3f3633 100644 --- a/src/slang-nodes/InheritanceSpecifier.js +++ b/src/slang-nodes/InheritanceSpecifier.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { InheritanceTypes } from './InheritanceTypes.js'; export class InheritanceSpecifier extends SlangNode { + get kind() { + return NonterminalKind.InheritanceSpecifier; + } + isKeyword; types; diff --git a/src/slang-nodes/InheritanceType.js b/src/slang-nodes/InheritanceType.js index b8089b9d7..9b4ac5e1d 100644 --- a/src/slang-nodes/InheritanceType.js +++ b/src/slang-nodes/InheritanceType.js @@ -1,8 +1,13 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { IdentifierPath } from './IdentifierPath.js'; import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; export class InheritanceType extends SlangNode { + get kind() { + return NonterminalKind.InheritanceType; + } + typeName; arguments; diff --git a/src/slang-nodes/InheritanceTypes.js b/src/slang-nodes/InheritanceTypes.js index 4548738eb..bfd5c392d 100644 --- a/src/slang-nodes/InheritanceTypes.js +++ b/src/slang-nodes/InheritanceTypes.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; import { InheritanceType } from './InheritanceType.js'; @@ -6,6 +7,10 @@ import { InheritanceType } from './InheritanceType.js'; const { line } = doc.builders; export class InheritanceTypes extends SlangNode { + get kind() { + return NonterminalKind.InheritanceTypes; + } + items; separators; diff --git a/src/slang-nodes/InterfaceDefinition.js b/src/slang-nodes/InterfaceDefinition.js index 13ab049ff..ab3874eee 100644 --- a/src/slang-nodes/InterfaceDefinition.js +++ b/src/slang-nodes/InterfaceDefinition.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { InheritanceSpecifier } from './InheritanceSpecifier.js'; import { InterfaceMembers } from './InterfaceMembers.js'; @@ -6,6 +7,10 @@ import { InterfaceMembers } from './InterfaceMembers.js'; const { group, line } = doc.builders; export class InterfaceDefinition extends SlangNode { + get kind() { + return NonterminalKind.InterfaceDefinition; + } + interfaceKeyword; name; diff --git a/src/slang-nodes/InterfaceMembers.js b/src/slang-nodes/InterfaceMembers.js index 43008feb6..3a27f05a4 100644 --- a/src/slang-nodes/InterfaceMembers.js +++ b/src/slang-nodes/InterfaceMembers.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedItem } from '../common/printer-helpers.js'; import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; import { SlangNode } from './SlangNode.js'; @@ -7,6 +8,10 @@ import { ContractMember } from './ContractMember.js'; const { hardline } = doc.builders; export class InterfaceMembers extends SlangNode { + get kind() { + return NonterminalKind.InterfaceMembers; + } + items; constructor(ast, offset, options) { diff --git a/src/slang-nodes/LibraryDefinition.js b/src/slang-nodes/LibraryDefinition.js index 7a64348ee..3f876f732 100644 --- a/src/slang-nodes/LibraryDefinition.js +++ b/src/slang-nodes/LibraryDefinition.js @@ -1,10 +1,15 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { LibraryMembers } from './LibraryMembers.js'; const { group, line } = doc.builders; export class LibraryDefinition extends SlangNode { + get kind() { + return NonterminalKind.LibraryDefinition; + } + libraryKeyword; name; diff --git a/src/slang-nodes/LibraryMembers.js b/src/slang-nodes/LibraryMembers.js index c3bec6cdf..289e3b798 100644 --- a/src/slang-nodes/LibraryMembers.js +++ b/src/slang-nodes/LibraryMembers.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedItem } from '../common/printer-helpers.js'; import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; import { SlangNode } from './SlangNode.js'; @@ -7,6 +8,10 @@ import { ContractMember } from './ContractMember.js'; const { hardline } = doc.builders; export class LibraryMembers extends SlangNode { + get kind() { + return NonterminalKind.LibraryMembers; + } + items; constructor(ast, offset, options) { diff --git a/src/slang-nodes/MappingKey.js b/src/slang-nodes/MappingKey.js index 232619307..7a2e63751 100644 --- a/src/slang-nodes/MappingKey.js +++ b/src/slang-nodes/MappingKey.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { MappingKeyType } from './MappingKeyType.js'; export class MappingKey extends SlangNode { + get kind() { + return NonterminalKind.MappingKey; + } + keyType; name; diff --git a/src/slang-nodes/MappingKeyType.js b/src/slang-nodes/MappingKeyType.js index 312c306a1..c8d1568d8 100644 --- a/src/slang-nodes/MappingKeyType.js +++ b/src/slang-nodes/MappingKeyType.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { ElementaryType } from './ElementaryType.js'; import { IdentifierPath } from './IdentifierPath.js'; @@ -5,6 +6,10 @@ import { IdentifierPath } from './IdentifierPath.js'; const variants = { ElementaryType, IdentifierPath }; export class MappingKeyType extends SlangNode { + get kind() { + return NonterminalKind.MappingKeyType; + } + variant; constructor(ast, offset, options) { diff --git a/src/slang-nodes/MappingType.js b/src/slang-nodes/MappingType.js index 9fa0cd532..355601703 100644 --- a/src/slang-nodes/MappingType.js +++ b/src/slang-nodes/MappingType.js @@ -1,8 +1,13 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { MappingKey } from './MappingKey.js'; import { MappingValue } from './MappingValue.js'; export class MappingType extends SlangNode { + get kind() { + return NonterminalKind.MappingType; + } + mappingKeyword; openParen; diff --git a/src/slang-nodes/MappingValue.js b/src/slang-nodes/MappingValue.js index d97d93548..4a70c451b 100644 --- a/src/slang-nodes/MappingValue.js +++ b/src/slang-nodes/MappingValue.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { TypeName } from './TypeName.js'; export class MappingValue extends SlangNode { + get kind() { + return NonterminalKind.MappingValue; + } + typeName; name; diff --git a/src/slang-nodes/MemberAccess.js b/src/slang-nodes/MemberAccess.js index e82019923..5bb50cd87 100644 --- a/src/slang-nodes/MemberAccess.js +++ b/src/slang-nodes/MemberAccess.js @@ -1,6 +1,11 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; export class MemberAccess extends SlangNode { + get kind() { + return NonterminalKind.MemberAccess; + } + variant; constructor(ast, offset) { diff --git a/src/slang-nodes/MemberAccessExpression.js b/src/slang-nodes/MemberAccessExpression.js index 618a183bd..b2e1f96a0 100644 --- a/src/slang-nodes/MemberAccessExpression.js +++ b/src/slang-nodes/MemberAccessExpression.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { isLabel } from '../common/util.js'; import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js'; import { SlangNode } from './SlangNode.js'; @@ -108,6 +109,10 @@ function processChain(chain) { } export class MemberAccessExpression extends SlangNode { + get kind() { + return NonterminalKind.MemberAccessExpression; + } + operand; period; diff --git a/src/slang-nodes/ModifierAttribute.js b/src/slang-nodes/ModifierAttribute.js index 7827437d6..4ada7785b 100644 --- a/src/slang-nodes/ModifierAttribute.js +++ b/src/slang-nodes/ModifierAttribute.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { OverrideSpecifier } from './OverrideSpecifier.js'; export class ModifierAttribute extends SlangNode { + get kind() { + return NonterminalKind.ModifierAttribute; + } + variant; constructor(ast, offset, options) { diff --git a/src/slang-nodes/ModifierAttributes.js b/src/slang-nodes/ModifierAttributes.js index daa80813c..53daa7cf5 100644 --- a/src/slang-nodes/ModifierAttributes.js +++ b/src/slang-nodes/ModifierAttributes.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { postProcessFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; import { SlangNode } from './SlangNode.js'; import { ModifierAttribute } from './ModifierAttribute.js'; @@ -6,6 +7,10 @@ import { ModifierAttribute } from './ModifierAttribute.js'; const { line } = doc.builders; export class ModifierAttributes extends SlangNode { + get kind() { + return NonterminalKind.ModifierAttributes; + } + items; constructor(ast, offset, options) { diff --git a/src/slang-nodes/ModifierDefinition.js b/src/slang-nodes/ModifierDefinition.js index 07a3aa4bc..20b588264 100644 --- a/src/slang-nodes/ModifierDefinition.js +++ b/src/slang-nodes/ModifierDefinition.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printFunction } from '../slang-printers/print-function.js'; import { SlangNode } from './SlangNode.js'; import { ParametersDeclaration } from './ParametersDeclaration.js'; @@ -19,11 +20,9 @@ const postProcess = (properties) => { return { ...properties, parameters: new ParametersDeclaration({ - kind: 'ParametersDeclaration', loc: { ...parametersLoc }, openParen: '(', parameters: new Parameters({ - kind: 'Parameters', loc: { ...parametersLoc }, items: [], separators: [] @@ -34,6 +33,10 @@ const postProcess = (properties) => { }; export class ModifierDefinition extends SlangNode { + get kind() { + return NonterminalKind.ModifierDefinition; + } + modifierKeyword; name; diff --git a/src/slang-nodes/ModifierInvocation.js b/src/slang-nodes/ModifierInvocation.js index f1fd46063..89d8d209d 100644 --- a/src/slang-nodes/ModifierInvocation.js +++ b/src/slang-nodes/ModifierInvocation.js @@ -1,9 +1,14 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { isComment } from '../slang-utils/is-comment.js'; import { SlangNode } from './SlangNode.js'; import { IdentifierPath } from './IdentifierPath.js'; import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; export class ModifierInvocation extends SlangNode { + get kind() { + return NonterminalKind.ModifierInvocation; + } + name; arguments; diff --git a/src/slang-nodes/MultiplicativeExpression.js b/src/slang-nodes/MultiplicativeExpression.js index 210438a61..33b1d09b6 100644 --- a/src/slang-nodes/MultiplicativeExpression.js +++ b/src/slang-nodes/MultiplicativeExpression.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; import { createHugFunction } from '../slang-utils/create-hug-function.js'; import { SlangNode } from './SlangNode.js'; @@ -31,6 +32,10 @@ const postProcess = (properties) => { }; export class MultiplicativeExpression extends SlangNode { + get kind() { + return NonterminalKind.MultiplicativeExpression; + } + leftOperand; operator; diff --git a/src/slang-nodes/NamedArgument.js b/src/slang-nodes/NamedArgument.js index fb0a93308..cc1b535c8 100644 --- a/src/slang-nodes/NamedArgument.js +++ b/src/slang-nodes/NamedArgument.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { Expression } from './Expression.js'; export class NamedArgument extends SlangNode { + get kind() { + return NonterminalKind.NamedArgument; + } + name; colon; diff --git a/src/slang-nodes/NamedArgumentGroup.js b/src/slang-nodes/NamedArgumentGroup.js index a2a769da7..917e116c9 100644 --- a/src/slang-nodes/NamedArgumentGroup.js +++ b/src/slang-nodes/NamedArgumentGroup.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { NamedArguments } from './NamedArguments.js'; export class NamedArgumentGroup extends SlangNode { + get kind() { + return NonterminalKind.NamedArgumentGroup; + } + openBrace; arguments; diff --git a/src/slang-nodes/NamedArguments.js b/src/slang-nodes/NamedArguments.js index c72590b13..fcfb49f06 100644 --- a/src/slang-nodes/NamedArguments.js +++ b/src/slang-nodes/NamedArguments.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; import { NamedArgument } from './NamedArgument.js'; @@ -6,6 +7,10 @@ import { NamedArgument } from './NamedArgument.js'; const { line, softline } = doc.builders; export class NamedArguments extends SlangNode { + get kind() { + return NonterminalKind.NamedArguments; + } + items; separators; diff --git a/src/slang-nodes/NamedArgumentsDeclaration.js b/src/slang-nodes/NamedArgumentsDeclaration.js index 68348903a..baedffbd2 100644 --- a/src/slang-nodes/NamedArgumentsDeclaration.js +++ b/src/slang-nodes/NamedArgumentsDeclaration.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { NamedArgumentGroup } from './NamedArgumentGroup.js'; export class NamedArgumentsDeclaration extends SlangNode { + get kind() { + return NonterminalKind.NamedArgumentsDeclaration; + } + openParen; arguments; diff --git a/src/slang-nodes/NamedImport.js b/src/slang-nodes/NamedImport.js index f8086f0c6..9f976bc1a 100644 --- a/src/slang-nodes/NamedImport.js +++ b/src/slang-nodes/NamedImport.js @@ -1,8 +1,13 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { ImportAlias } from './ImportAlias.js'; import { StringLiteral } from './StringLiteral.js'; export class NamedImport extends SlangNode { + get kind() { + return NonterminalKind.NamedImport; + } + asterisk; alias; diff --git a/src/slang-nodes/NewExpression.js b/src/slang-nodes/NewExpression.js index 9d047712b..f57a82295 100644 --- a/src/slang-nodes/NewExpression.js +++ b/src/slang-nodes/NewExpression.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { TypeName } from './TypeName.js'; export class NewExpression extends SlangNode { + get kind() { + return NonterminalKind.NewExpression; + } + newKeyword; typeName; diff --git a/src/slang-nodes/NumberUnit.js b/src/slang-nodes/NumberUnit.js index fa7b0b488..4fac5b43a 100644 --- a/src/slang-nodes/NumberUnit.js +++ b/src/slang-nodes/NumberUnit.js @@ -1,6 +1,11 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; export class NumberUnit extends SlangNode { + get kind() { + return NonterminalKind.NumberUnit; + } + variant; constructor(ast, offset) { diff --git a/src/slang-nodes/OrExpression.js b/src/slang-nodes/OrExpression.js index 40d68d971..897b4e1ad 100644 --- a/src/slang-nodes/OrExpression.js +++ b/src/slang-nodes/OrExpression.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printLogicalOperation } from '../slang-printers/print-logical-operation.js'; import { createHugFunction } from '../slang-utils/create-hug-function.js'; import { SlangNode } from './SlangNode.js'; @@ -12,6 +13,10 @@ const postProcess = (properties) => ({ }); export class OrExpression extends SlangNode { + get kind() { + return NonterminalKind.OrExpression; + } + leftOperand; operator; diff --git a/src/slang-nodes/OverridePaths.js b/src/slang-nodes/OverridePaths.js index b552dca0c..e4491033e 100644 --- a/src/slang-nodes/OverridePaths.js +++ b/src/slang-nodes/OverridePaths.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { IdentifierPath } from './IdentifierPath.js'; export class OverridePaths extends SlangNode { + get kind() { + return NonterminalKind.OverridePaths; + } + items; separators; diff --git a/src/slang-nodes/OverridePathsDeclaration.js b/src/slang-nodes/OverridePathsDeclaration.js index 9e99e6bee..a3ecf42c1 100644 --- a/src/slang-nodes/OverridePathsDeclaration.js +++ b/src/slang-nodes/OverridePathsDeclaration.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { OverridePaths } from './OverridePaths.js'; export class OverridePathsDeclaration extends SlangNode { + get kind() { + return NonterminalKind.OverridePathsDeclaration; + } + openParen; paths; diff --git a/src/slang-nodes/OverrideSpecifier.js b/src/slang-nodes/OverrideSpecifier.js index 840937f73..ba8c25486 100644 --- a/src/slang-nodes/OverrideSpecifier.js +++ b/src/slang-nodes/OverrideSpecifier.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { OverridePathsDeclaration } from './OverridePathsDeclaration.js'; export class OverrideSpecifier extends SlangNode { + get kind() { + return NonterminalKind.OverrideSpecifier; + } + overrideKeyword; overridden; diff --git a/src/slang-nodes/Parameter.js b/src/slang-nodes/Parameter.js index 6cb6401c7..8d71f60e9 100644 --- a/src/slang-nodes/Parameter.js +++ b/src/slang-nodes/Parameter.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { TypeName } from './TypeName.js'; import { StorageLocation } from './StorageLocation.js'; @@ -6,6 +7,10 @@ import { StorageLocation } from './StorageLocation.js'; const { group } = doc.builders; export class Parameter extends SlangNode { + get kind() { + return NonterminalKind.Parameter; + } + typeName; storageLocation; diff --git a/src/slang-nodes/Parameters.js b/src/slang-nodes/Parameters.js index 24563b802..0de32977c 100644 --- a/src/slang-nodes/Parameters.js +++ b/src/slang-nodes/Parameters.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedItem, printSeparatedList @@ -7,6 +8,10 @@ import { SlangNode } from './SlangNode.js'; import { Parameter } from './Parameter.js'; export class Parameters extends SlangNode { + get kind() { + return NonterminalKind.Parameters; + } + items; separators; @@ -24,7 +29,6 @@ export class Parameters extends SlangNode { this.initialize(ast, offset, fetch); } else { - this.kind = ast.kind; this.loc = ast.loc; this.items = ast.items; this.separators = ast.separators; diff --git a/src/slang-nodes/ParametersDeclaration.js b/src/slang-nodes/ParametersDeclaration.js index 81f0ae436..f82073374 100644 --- a/src/slang-nodes/ParametersDeclaration.js +++ b/src/slang-nodes/ParametersDeclaration.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { Parameters } from './Parameters.js'; export class ParametersDeclaration extends SlangNode { + get kind() { + return NonterminalKind.ParametersDeclaration; + } + openParen; parameters; @@ -24,7 +29,6 @@ export class ParametersDeclaration extends SlangNode { this.initialize(ast, offset, fetch); } else { - this.kind = ast.kind; this.loc = ast.loc; this.openParen = ast.openParen; this.parameters = ast.parameters; diff --git a/src/slang-nodes/PathImport.js b/src/slang-nodes/PathImport.js index f6dffa20d..228fe9575 100644 --- a/src/slang-nodes/PathImport.js +++ b/src/slang-nodes/PathImport.js @@ -1,8 +1,13 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { StringLiteral } from './StringLiteral.js'; import { ImportAlias } from './ImportAlias.js'; export class PathImport extends SlangNode { + get kind() { + return NonterminalKind.PathImport; + } + path; alias; diff --git a/src/slang-nodes/PositionalArguments.js b/src/slang-nodes/PositionalArguments.js index 9e025a2d6..8cf97523e 100644 --- a/src/slang-nodes/PositionalArguments.js +++ b/src/slang-nodes/PositionalArguments.js @@ -1,8 +1,13 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; import { Expression } from './Expression.js'; export class PositionalArguments extends SlangNode { + get kind() { + return NonterminalKind.PositionalArguments; + } + items; separators; diff --git a/src/slang-nodes/PositionalArgumentsDeclaration.js b/src/slang-nodes/PositionalArgumentsDeclaration.js index be1c6aaeb..b829d2228 100644 --- a/src/slang-nodes/PositionalArgumentsDeclaration.js +++ b/src/slang-nodes/PositionalArgumentsDeclaration.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { PositionalArguments } from './PositionalArguments.js'; export class PositionalArgumentsDeclaration extends SlangNode { + get kind() { + return NonterminalKind.PositionalArgumentsDeclaration; + } + openParen; arguments; diff --git a/src/slang-nodes/PostfixExpression.js b/src/slang-nodes/PostfixExpression.js index 222299eb9..637dd2140 100644 --- a/src/slang-nodes/PostfixExpression.js +++ b/src/slang-nodes/PostfixExpression.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { Expression } from './Expression.js'; export class PostfixExpression extends SlangNode { + get kind() { + return NonterminalKind.PostfixExpression; + } + operand; operator; diff --git a/src/slang-nodes/Pragma.js b/src/slang-nodes/Pragma.js index 2e36431ad..ff696c66a 100644 --- a/src/slang-nodes/Pragma.js +++ b/src/slang-nodes/Pragma.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { ABICoderPragma } from './ABICoderPragma.js'; import { ExperimentalPragma } from './ExperimentalPragma.js'; @@ -5,6 +6,10 @@ import { VersionPragma } from './VersionPragma.js'; const variants = { ABICoderPragma, ExperimentalPragma, VersionPragma }; export class Pragma extends SlangNode { + get kind() { + return NonterminalKind.Pragma; + } + variant; constructor(ast, offset, options) { diff --git a/src/slang-nodes/PragmaDirective.js b/src/slang-nodes/PragmaDirective.js index 85867e8ed..ab8e83861 100644 --- a/src/slang-nodes/PragmaDirective.js +++ b/src/slang-nodes/PragmaDirective.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { Pragma } from './Pragma.js'; export class PragmaDirective extends SlangNode { + get kind() { + return NonterminalKind.PragmaDirective; + } + pragmaKeyword; pragma; diff --git a/src/slang-nodes/PrefixExpression.js b/src/slang-nodes/PrefixExpression.js index 7aacd75bd..e72a0274d 100644 --- a/src/slang-nodes/PrefixExpression.js +++ b/src/slang-nodes/PrefixExpression.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { Expression } from './Expression.js'; export class PrefixExpression extends SlangNode { + get kind() { + return NonterminalKind.PrefixExpression; + } + operator; operand; diff --git a/src/slang-nodes/ReceiveFunctionAttribute.js b/src/slang-nodes/ReceiveFunctionAttribute.js index c5a42d7e4..c46e34359 100644 --- a/src/slang-nodes/ReceiveFunctionAttribute.js +++ b/src/slang-nodes/ReceiveFunctionAttribute.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { ModifierInvocation } from './ModifierInvocation.js'; import { OverrideSpecifier } from './OverrideSpecifier.js'; @@ -5,6 +6,10 @@ import { OverrideSpecifier } from './OverrideSpecifier.js'; const variants = { ModifierInvocation, OverrideSpecifier }; export class ReceiveFunctionAttribute extends SlangNode { + get kind() { + return NonterminalKind.ReceiveFunctionAttribute; + } + variant; constructor(ast, offset, options) { diff --git a/src/slang-nodes/ReceiveFunctionAttributes.js b/src/slang-nodes/ReceiveFunctionAttributes.js index 1cf1bae83..99dc1d2bc 100644 --- a/src/slang-nodes/ReceiveFunctionAttributes.js +++ b/src/slang-nodes/ReceiveFunctionAttributes.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { postProcessFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; import { SlangNode } from './SlangNode.js'; import { ReceiveFunctionAttribute } from './ReceiveFunctionAttribute.js'; @@ -6,6 +7,10 @@ import { ReceiveFunctionAttribute } from './ReceiveFunctionAttribute.js'; const { line } = doc.builders; export class ReceiveFunctionAttributes extends SlangNode { + get kind() { + return NonterminalKind.ReceiveFunctionAttributes; + } + items; constructor(ast, offset, options) { diff --git a/src/slang-nodes/ReceiveFunctionDefinition.js b/src/slang-nodes/ReceiveFunctionDefinition.js index 93fa18098..169214063 100644 --- a/src/slang-nodes/ReceiveFunctionDefinition.js +++ b/src/slang-nodes/ReceiveFunctionDefinition.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printFunction } from '../slang-printers/print-function.js'; import { SlangNode } from './SlangNode.js'; import { ParametersDeclaration } from './ParametersDeclaration.js'; @@ -5,6 +6,10 @@ import { ReceiveFunctionAttributes } from './ReceiveFunctionAttributes.js'; import { FunctionBody } from './FunctionBody.js'; export class ReceiveFunctionDefinition extends SlangNode { + get kind() { + return NonterminalKind.ReceiveFunctionDefinition; + } + receiveKeyword; parameters; diff --git a/src/slang-nodes/ReturnStatement.js b/src/slang-nodes/ReturnStatement.js index e3dfb7559..fb8b1cef6 100644 --- a/src/slang-nodes/ReturnStatement.js +++ b/src/slang-nodes/ReturnStatement.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { Expression } from './Expression.js'; @@ -16,6 +17,10 @@ function printExpression(node, path, print, options) { } export class ReturnStatement extends SlangNode { + get kind() { + return NonterminalKind.ReturnStatement; + } + returnKeyword; expression; diff --git a/src/slang-nodes/ReturnsDeclaration.js b/src/slang-nodes/ReturnsDeclaration.js index a90318671..861f0bb37 100644 --- a/src/slang-nodes/ReturnsDeclaration.js +++ b/src/slang-nodes/ReturnsDeclaration.js @@ -1,10 +1,15 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { ParametersDeclaration } from './ParametersDeclaration.js'; const { group } = doc.builders; export class ReturnsDeclaration extends SlangNode { + get kind() { + return NonterminalKind.ReturnsDeclaration; + } + returnsKeyword; variables; diff --git a/src/slang-nodes/RevertStatement.js b/src/slang-nodes/RevertStatement.js index 4333ffb28..e21bba5a1 100644 --- a/src/slang-nodes/RevertStatement.js +++ b/src/slang-nodes/RevertStatement.js @@ -1,8 +1,13 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { IdentifierPath } from './IdentifierPath.js'; import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; export class RevertStatement extends SlangNode { + get kind() { + return NonterminalKind.RevertStatement; + } + revertKeyword; error; diff --git a/src/slang-nodes/ShiftExpression.js b/src/slang-nodes/ShiftExpression.js index a45d70349..625289ca9 100644 --- a/src/slang-nodes/ShiftExpression.js +++ b/src/slang-nodes/ShiftExpression.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; import { createHugFunction } from '../slang-utils/create-hug-function.js'; import { SlangNode } from './SlangNode.js'; @@ -21,6 +22,10 @@ const postProcess = (properties) => ({ }); export class ShiftExpression extends SlangNode { + get kind() { + return NonterminalKind.ShiftExpression; + } + leftOperand; operator; diff --git a/src/slang-nodes/SlangNode.js b/src/slang-nodes/SlangNode.js index fde4216b7..0d308f3d1 100644 --- a/src/slang-nodes/SlangNode.js +++ b/src/slang-nodes/SlangNode.js @@ -8,15 +8,15 @@ const isNotStringOrUndefined = (node) => typeof node !== 'string' && typeof node !== 'undefined'; export class SlangNode { - kind; - loc; comments = []; initialize(ast, offset, fetch, postProcess) { - this.kind = ast.cst.kind; - + if (this.kind !== ast.cst.kind) + throw new Error( + `${this.kind} can only be initialized with an AST node of the same kind.` + ); // Collect comments and get children offsets. const cstChildren = ast.cst.children(); const childrenOffsets = getChildrenOffsets( diff --git a/src/slang-nodes/SourceUnit.js b/src/slang-nodes/SourceUnit.js index 0b01d3927..c6f912999 100644 --- a/src/slang-nodes/SourceUnit.js +++ b/src/slang-nodes/SourceUnit.js @@ -1,11 +1,14 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { SourceUnitMembers } from './SourceUnitMembers.js'; const { line } = doc.builders; export class SourceUnit extends SlangNode { - members; + get kind() { + return NonterminalKind.SourceUnit; + } constructor(ast, offset, options) { super(); diff --git a/src/slang-nodes/SourceUnitMember.js b/src/slang-nodes/SourceUnitMember.js index 398bd9487..2947222cc 100644 --- a/src/slang-nodes/SourceUnitMember.js +++ b/src/slang-nodes/SourceUnitMember.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { PragmaDirective } from './PragmaDirective.js'; import { ImportDirective } from './ImportDirective.js'; @@ -29,6 +30,10 @@ const variants = { EventDefinition }; export class SourceUnitMember extends SlangNode { + get kind() { + return NonterminalKind.SourceUnitMember; + } + variant; constructor(ast, offset, options) { diff --git a/src/slang-nodes/SourceUnitMembers.js b/src/slang-nodes/SourceUnitMembers.js index 5fc4ad9be..b49ab1885 100644 --- a/src/slang-nodes/SourceUnitMembers.js +++ b/src/slang-nodes/SourceUnitMembers.js @@ -1,8 +1,13 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; import { SlangNode } from './SlangNode.js'; import { SourceUnitMember } from './SourceUnitMember.js'; export class SourceUnitMembers extends SlangNode { + get kind() { + return NonterminalKind.SourceUnitMembers; + } + items; constructor(ast, offset, options) { diff --git a/src/slang-nodes/StateVariableAttribute.js b/src/slang-nodes/StateVariableAttribute.js index 1afc7cbb5..011020f5a 100644 --- a/src/slang-nodes/StateVariableAttribute.js +++ b/src/slang-nodes/StateVariableAttribute.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { OverrideSpecifier } from './OverrideSpecifier.js'; export class StateVariableAttribute extends SlangNode { + get kind() { + return NonterminalKind.StateVariableAttribute; + } + variant; constructor(ast, offset, options) { diff --git a/src/slang-nodes/StateVariableAttributes.js b/src/slang-nodes/StateVariableAttributes.js index 143ea13c6..4cc6b090a 100644 --- a/src/slang-nodes/StateVariableAttributes.js +++ b/src/slang-nodes/StateVariableAttributes.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { StateVariableAttribute } from './StateVariableAttribute.js'; export class StateVariableAttributes extends SlangNode { + get kind() { + return NonterminalKind.StateVariableAttributes; + } + items; constructor(ast, offset, options) { diff --git a/src/slang-nodes/StateVariableDefinition.js b/src/slang-nodes/StateVariableDefinition.js index ac80bbefb..44b5796fa 100644 --- a/src/slang-nodes/StateVariableDefinition.js +++ b/src/slang-nodes/StateVariableDefinition.js @@ -1,9 +1,14 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { TypeName } from './TypeName.js'; import { StateVariableAttributes } from './StateVariableAttributes.js'; import { StateVariableDefinitionValue } from './StateVariableDefinitionValue.js'; export class StateVariableDefinition extends SlangNode { + get kind() { + return NonterminalKind.StateVariableDefinition; + } + typeName; attributes; diff --git a/src/slang-nodes/StateVariableDefinitionValue.js b/src/slang-nodes/StateVariableDefinitionValue.js index 17775252f..f868c91ad 100644 --- a/src/slang-nodes/StateVariableDefinitionValue.js +++ b/src/slang-nodes/StateVariableDefinitionValue.js @@ -1,10 +1,15 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { Expression } from './Expression.js'; const { group, indent, line } = doc.builders; export class StateVariableDefinitionValue extends SlangNode { + get kind() { + return NonterminalKind.StateVariableDefinitionValue; + } + equal; value; diff --git a/src/slang-nodes/Statement.js b/src/slang-nodes/Statement.js index 851be5398..d436efed0 100644 --- a/src/slang-nodes/Statement.js +++ b/src/slang-nodes/Statement.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { ExpressionStatement } from './ExpressionStatement.js'; import { VariableDeclarationStatement } from './VariableDeclarationStatement.js'; @@ -38,6 +39,10 @@ const variants = { }; export class Statement extends SlangNode { + get kind() { + return NonterminalKind.Statement; + } + variant; constructor(ast, offset, options) { diff --git a/src/slang-nodes/Statements.js b/src/slang-nodes/Statements.js index b8c6e04d5..a095e5a9c 100644 --- a/src/slang-nodes/Statements.js +++ b/src/slang-nodes/Statements.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedItem } from '../common/printer-helpers.js'; import { printComments } from '../slang-printers/print-comments.js'; import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; @@ -8,6 +9,10 @@ import { Statement } from './Statement.js'; const { hardline } = doc.builders; export class Statements extends SlangNode { + get kind() { + return NonterminalKind.Statements; + } + items; constructor(ast, offset, options) { diff --git a/src/slang-nodes/StorageLocation.js b/src/slang-nodes/StorageLocation.js index bc6127007..6af01f246 100644 --- a/src/slang-nodes/StorageLocation.js +++ b/src/slang-nodes/StorageLocation.js @@ -1,6 +1,11 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; export class StorageLocation extends SlangNode { + get kind() { + return NonterminalKind.StorageLocation; + } + variant; constructor(ast, offset) { diff --git a/src/slang-nodes/StringExpression.js b/src/slang-nodes/StringExpression.js index cabeaa2fe..91deaddc2 100644 --- a/src/slang-nodes/StringExpression.js +++ b/src/slang-nodes/StringExpression.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { StringLiteral } from './StringLiteral.js'; import { StringLiterals } from './StringLiterals.js'; @@ -14,6 +15,10 @@ const variants = { }; export class StringExpression extends SlangNode { + get kind() { + return NonterminalKind.StringExpression; + } + variant; constructor(ast, offset, options) { diff --git a/src/slang-nodes/StringLiteral.js b/src/slang-nodes/StringLiteral.js index b0b4414b7..5509e9c05 100644 --- a/src/slang-nodes/StringLiteral.js +++ b/src/slang-nodes/StringLiteral.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printString } from '../slang-printers/print-string.js'; import { SlangNode } from './SlangNode.js'; @@ -6,6 +7,10 @@ const postProcess = (options) => (properties) => ({ }); export class StringLiteral extends SlangNode { + get kind() { + return NonterminalKind.StringLiteral; + } + variant; constructor(ast, offset, options) { diff --git a/src/slang-nodes/StringLiterals.js b/src/slang-nodes/StringLiterals.js index 3c15732f8..3f952d542 100644 --- a/src/slang-nodes/StringLiterals.js +++ b/src/slang-nodes/StringLiterals.js @@ -1,10 +1,15 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { StringLiteral } from './StringLiteral.js'; const { join, hardline } = doc.builders; export class StringLiterals extends SlangNode { + get kind() { + return NonterminalKind.StringLiterals; + } + items; constructor(ast, offset, options) { diff --git a/src/slang-nodes/StructDefinition.js b/src/slang-nodes/StructDefinition.js index be744d0bd..c9c1ebf1b 100644 --- a/src/slang-nodes/StructDefinition.js +++ b/src/slang-nodes/StructDefinition.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { StructMembers } from './StructMembers.js'; export class StructDefinition extends SlangNode { + get kind() { + return NonterminalKind.StructDefinition; + } + structKeyword; name; diff --git a/src/slang-nodes/StructMember.js b/src/slang-nodes/StructMember.js index d7e26d654..32e32eab8 100644 --- a/src/slang-nodes/StructMember.js +++ b/src/slang-nodes/StructMember.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { TypeName } from './TypeName.js'; export class StructMember extends SlangNode { + get kind() { + return NonterminalKind.StructMember; + } + typeName; name; diff --git a/src/slang-nodes/StructMembers.js b/src/slang-nodes/StructMembers.js index 1b5c34acb..8af5c6365 100644 --- a/src/slang-nodes/StructMembers.js +++ b/src/slang-nodes/StructMembers.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; import { StructMember } from './StructMember.js'; @@ -6,6 +7,10 @@ import { StructMember } from './StructMember.js'; const { hardline } = doc.builders; export class StructMembers extends SlangNode { + get kind() { + return NonterminalKind.StructMembers; + } + items; constructor(ast, offset, options) { diff --git a/src/slang-nodes/ThrowStatement.js b/src/slang-nodes/ThrowStatement.js index b5bd19574..db7af101a 100644 --- a/src/slang-nodes/ThrowStatement.js +++ b/src/slang-nodes/ThrowStatement.js @@ -1,6 +1,11 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; export class ThrowStatement extends SlangNode { + get kind() { + return NonterminalKind.ThrowStatement; + } + throwKeyword; semicolon; diff --git a/src/slang-nodes/TryStatement.js b/src/slang-nodes/TryStatement.js index 7e6c74394..188e244f9 100644 --- a/src/slang-nodes/TryStatement.js +++ b/src/slang-nodes/TryStatement.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedItem } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; import { Expression } from './Expression.js'; @@ -9,6 +10,10 @@ import { CatchClauses } from './CatchClauses.js'; const { line } = doc.builders; export class TryStatement extends SlangNode { + get kind() { + return NonterminalKind.TryStatement; + } + tryKeyword; expression; diff --git a/src/slang-nodes/TupleDeconstructionElement.js b/src/slang-nodes/TupleDeconstructionElement.js index a2a3318ac..3a3c452b5 100644 --- a/src/slang-nodes/TupleDeconstructionElement.js +++ b/src/slang-nodes/TupleDeconstructionElement.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { TupleMember } from './TupleMember.js'; export class TupleDeconstructionElement extends SlangNode { + get kind() { + return NonterminalKind.TupleDeconstructionElement; + } + member; constructor(ast, offset, options) { diff --git a/src/slang-nodes/TupleDeconstructionElements.js b/src/slang-nodes/TupleDeconstructionElements.js index dbd47e62a..3fa3738f7 100644 --- a/src/slang-nodes/TupleDeconstructionElements.js +++ b/src/slang-nodes/TupleDeconstructionElements.js @@ -1,8 +1,13 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; import { TupleDeconstructionElement } from './TupleDeconstructionElement.js'; export class TupleDeconstructionElements extends SlangNode { + get kind() { + return NonterminalKind.TupleDeconstructionElements; + } + items; separators; diff --git a/src/slang-nodes/TupleDeconstructionStatement.js b/src/slang-nodes/TupleDeconstructionStatement.js index 7260b6243..393f2b4af 100644 --- a/src/slang-nodes/TupleDeconstructionStatement.js +++ b/src/slang-nodes/TupleDeconstructionStatement.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { TupleDeconstructionElements } from './TupleDeconstructionElements.js'; import { Expression } from './Expression.js'; @@ -6,6 +7,10 @@ import { Expression } from './Expression.js'; const { group, indent, line } = doc.builders; export class TupleDeconstructionStatement extends SlangNode { + get kind() { + return NonterminalKind.TupleDeconstructionStatement; + } + varKeyword; openParen; diff --git a/src/slang-nodes/TupleExpression.js b/src/slang-nodes/TupleExpression.js index 79802e46c..424ed29bc 100644 --- a/src/slang-nodes/TupleExpression.js +++ b/src/slang-nodes/TupleExpression.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { TupleValues } from './TupleValues.js'; export class TupleExpression extends SlangNode { + get kind() { + return NonterminalKind.TupleExpression; + } + openParen; items; @@ -20,7 +25,6 @@ export class TupleExpression extends SlangNode { this.initialize(ast, offset, fetch); } else { - this.kind = ast.kind; this.loc = ast.loc; this.openParen = ast.openParen; this.items = ast.items; diff --git a/src/slang-nodes/TupleMember.js b/src/slang-nodes/TupleMember.js index f9809a73d..ca51176e1 100644 --- a/src/slang-nodes/TupleMember.js +++ b/src/slang-nodes/TupleMember.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { TypedTupleMember } from './TypedTupleMember.js'; import { UntypedTupleMember } from './UntypedTupleMember.js'; @@ -5,6 +6,10 @@ import { UntypedTupleMember } from './UntypedTupleMember.js'; const variants = { TypedTupleMember, UntypedTupleMember }; export class TupleMember extends SlangNode { + get kind() { + return NonterminalKind.TupleMember; + } + variant; constructor(ast, offset, options) { diff --git a/src/slang-nodes/TupleValue.js b/src/slang-nodes/TupleValue.js index 7cc940e17..ee65d32c3 100644 --- a/src/slang-nodes/TupleValue.js +++ b/src/slang-nodes/TupleValue.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { Expression } from './Expression.js'; export class TupleValue extends SlangNode { + get kind() { + return NonterminalKind.TupleValue; + } + expression; constructor(ast, offset, options) { @@ -16,7 +21,6 @@ export class TupleValue extends SlangNode { this.initialize(ast, offset, fetch); } else { - this.kind = ast.kind; this.loc = ast.loc; this.expression = ast.expression; } diff --git a/src/slang-nodes/TupleValues.js b/src/slang-nodes/TupleValues.js index 7d44ba530..12f226116 100644 --- a/src/slang-nodes/TupleValues.js +++ b/src/slang-nodes/TupleValues.js @@ -1,9 +1,14 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../common/printer-helpers.js'; import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; import { SlangNode } from './SlangNode.js'; import { TupleValue } from './TupleValue.js'; export class TupleValues extends SlangNode { + get kind() { + return NonterminalKind.TupleValues; + } + items; separators; @@ -21,7 +26,6 @@ export class TupleValues extends SlangNode { this.initialize(ast, offset, fetch); } else { - this.kind = ast.kind; this.loc = ast.loc; this.items = ast.items; this.separators = ast.separators; diff --git a/src/slang-nodes/TypeExpression.js b/src/slang-nodes/TypeExpression.js index b4ff06556..f75989296 100644 --- a/src/slang-nodes/TypeExpression.js +++ b/src/slang-nodes/TypeExpression.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { TypeName } from './TypeName.js'; export class TypeExpression extends SlangNode { + get kind() { + return NonterminalKind.TypeExpression; + } + typeKeyword; openParen; diff --git a/src/slang-nodes/TypeName.js b/src/slang-nodes/TypeName.js index 19ae954b0..f759fbb6a 100644 --- a/src/slang-nodes/TypeName.js +++ b/src/slang-nodes/TypeName.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { ArrayTypeName } from './ArrayTypeName.js'; import { FunctionType } from './FunctionType.js'; @@ -14,6 +15,10 @@ const variants = { }; export class TypeName extends SlangNode { + get kind() { + return NonterminalKind.TypeName; + } + variant; constructor(ast, offset, options) { diff --git a/src/slang-nodes/TypedTupleMember.js b/src/slang-nodes/TypedTupleMember.js index f154ea2b3..6d905a1b4 100644 --- a/src/slang-nodes/TypedTupleMember.js +++ b/src/slang-nodes/TypedTupleMember.js @@ -1,8 +1,13 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { TypeName } from './TypeName.js'; import { StorageLocation } from './StorageLocation.js'; export class TypedTupleMember extends SlangNode { + get kind() { + return NonterminalKind.TypedTupleMember; + } + typeName; storageLocation; diff --git a/src/slang-nodes/UncheckedBlock.js b/src/slang-nodes/UncheckedBlock.js index 43e564a0e..4c456740d 100644 --- a/src/slang-nodes/UncheckedBlock.js +++ b/src/slang-nodes/UncheckedBlock.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { Block } from './Block.js'; export class UncheckedBlock extends SlangNode { + get kind() { + return NonterminalKind.UncheckedBlock; + } + uncheckedKeyword; block; diff --git a/src/slang-nodes/UnicodeStringLiteral.js b/src/slang-nodes/UnicodeStringLiteral.js index b46dd611e..d0154e608 100644 --- a/src/slang-nodes/UnicodeStringLiteral.js +++ b/src/slang-nodes/UnicodeStringLiteral.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printString } from '../slang-printers/print-string.js'; import { SlangNode } from './SlangNode.js'; @@ -6,6 +7,10 @@ const postProcess = (options) => (properties) => ({ }); export class UnicodeStringLiteral extends SlangNode { + get kind() { + return NonterminalKind.UnicodeStringLiteral; + } + variant; constructor(ast, offset, options) { diff --git a/src/slang-nodes/UnicodeStringLiterals.js b/src/slang-nodes/UnicodeStringLiterals.js index 8e002e111..cf04be1e5 100644 --- a/src/slang-nodes/UnicodeStringLiterals.js +++ b/src/slang-nodes/UnicodeStringLiterals.js @@ -1,10 +1,15 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { UnicodeStringLiteral } from './UnicodeStringLiteral.js'; const { join, hardline } = doc.builders; export class UnicodeStringLiterals extends SlangNode { + get kind() { + return NonterminalKind.UnicodeStringLiterals; + } + items; constructor(ast, offset, options) { diff --git a/src/slang-nodes/UnnamedFunctionAttribute.js b/src/slang-nodes/UnnamedFunctionAttribute.js index 0c507759d..d0dd3bfbb 100644 --- a/src/slang-nodes/UnnamedFunctionAttribute.js +++ b/src/slang-nodes/UnnamedFunctionAttribute.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { ModifierInvocation } from './ModifierInvocation.js'; export class UnnamedFunctionAttribute extends SlangNode { + get kind() { + return NonterminalKind.UnnamedFunctionAttribute; + } + variant; constructor(ast, offset, options) { diff --git a/src/slang-nodes/UnnamedFunctionAttributes.js b/src/slang-nodes/UnnamedFunctionAttributes.js index 55dc76b43..eb1d57a52 100644 --- a/src/slang-nodes/UnnamedFunctionAttributes.js +++ b/src/slang-nodes/UnnamedFunctionAttributes.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { postProcessFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; import { SlangNode } from './SlangNode.js'; import { UnnamedFunctionAttribute } from './UnnamedFunctionAttribute.js'; @@ -6,6 +7,10 @@ import { UnnamedFunctionAttribute } from './UnnamedFunctionAttribute.js'; const { line } = doc.builders; export class UnnamedFunctionAttributes extends SlangNode { + get kind() { + return NonterminalKind.UnnamedFunctionAttributes; + } + items; constructor(ast, offset, options) { diff --git a/src/slang-nodes/UnnamedFunctionDefinition.js b/src/slang-nodes/UnnamedFunctionDefinition.js index c84dbc863..2f934b291 100644 --- a/src/slang-nodes/UnnamedFunctionDefinition.js +++ b/src/slang-nodes/UnnamedFunctionDefinition.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printFunction } from '../slang-printers/print-function.js'; import { SlangNode } from './SlangNode.js'; import { ParametersDeclaration } from './ParametersDeclaration.js'; @@ -5,6 +6,10 @@ import { UnnamedFunctionAttributes } from './UnnamedFunctionAttributes.js'; import { FunctionBody } from './FunctionBody.js'; export class UnnamedFunctionDefinition extends SlangNode { + get kind() { + return NonterminalKind.UnnamedFunctionDefinition; + } + functionKeyword; parameters; diff --git a/src/slang-nodes/UntypedTupleMember.js b/src/slang-nodes/UntypedTupleMember.js index 819e86307..f952cc2d9 100644 --- a/src/slang-nodes/UntypedTupleMember.js +++ b/src/slang-nodes/UntypedTupleMember.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { StorageLocation } from './StorageLocation.js'; export class UntypedTupleMember extends SlangNode { + get kind() { + return NonterminalKind.UntypedTupleMember; + } + storageLocation; name; diff --git a/src/slang-nodes/UserDefinedValueTypeDefinition.js b/src/slang-nodes/UserDefinedValueTypeDefinition.js index faf503832..3f8fe4b30 100644 --- a/src/slang-nodes/UserDefinedValueTypeDefinition.js +++ b/src/slang-nodes/UserDefinedValueTypeDefinition.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { ElementaryType } from './ElementaryType.js'; export class UserDefinedValueTypeDefinition extends SlangNode { + get kind() { + return NonterminalKind.UserDefinedValueTypeDefinition; + } + typeKeyword; name; diff --git a/src/slang-nodes/UsingAlias.js b/src/slang-nodes/UsingAlias.js index 298f427ec..02a3c7ab4 100644 --- a/src/slang-nodes/UsingAlias.js +++ b/src/slang-nodes/UsingAlias.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { UsingOperator } from './UsingOperator.js'; export class UsingAlias extends SlangNode { + get kind() { + return NonterminalKind.UsingAlias; + } + asKeyword; operator; diff --git a/src/slang-nodes/UsingClause.js b/src/slang-nodes/UsingClause.js index 5c661ad5e..7b5fe7adf 100644 --- a/src/slang-nodes/UsingClause.js +++ b/src/slang-nodes/UsingClause.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { IdentifierPath } from './IdentifierPath.js'; import { UsingDeconstruction } from './UsingDeconstruction.js'; @@ -5,6 +6,10 @@ import { UsingDeconstruction } from './UsingDeconstruction.js'; const variants = { IdentifierPath, UsingDeconstruction }; export class UsingClause extends SlangNode { + get kind() { + return NonterminalKind.UsingClause; + } + variant; constructor(ast, offset, options) { diff --git a/src/slang-nodes/UsingDeconstruction.js b/src/slang-nodes/UsingDeconstruction.js index 78ab079fa..44503799a 100644 --- a/src/slang-nodes/UsingDeconstruction.js +++ b/src/slang-nodes/UsingDeconstruction.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { UsingDeconstructionSymbols } from './UsingDeconstructionSymbols.js'; export class UsingDeconstruction extends SlangNode { + get kind() { + return NonterminalKind.UsingDeconstruction; + } + openBrace; symbols; diff --git a/src/slang-nodes/UsingDeconstructionSymbol.js b/src/slang-nodes/UsingDeconstructionSymbol.js index 00f745c15..c2cccb109 100644 --- a/src/slang-nodes/UsingDeconstructionSymbol.js +++ b/src/slang-nodes/UsingDeconstructionSymbol.js @@ -1,8 +1,13 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { IdentifierPath } from './IdentifierPath.js'; import { UsingAlias } from './UsingAlias.js'; export class UsingDeconstructionSymbol extends SlangNode { + get kind() { + return NonterminalKind.UsingDeconstructionSymbol; + } + name; alias; diff --git a/src/slang-nodes/UsingDeconstructionSymbols.js b/src/slang-nodes/UsingDeconstructionSymbols.js index 88f4a792b..4dd0bf206 100644 --- a/src/slang-nodes/UsingDeconstructionSymbols.js +++ b/src/slang-nodes/UsingDeconstructionSymbols.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; import { UsingDeconstructionSymbol } from './UsingDeconstructionSymbol.js'; @@ -6,6 +7,10 @@ import { UsingDeconstructionSymbol } from './UsingDeconstructionSymbol.js'; const { line, softline } = doc.builders; export class UsingDeconstructionSymbols extends SlangNode { + get kind() { + return NonterminalKind.UsingDeconstructionSymbols; + } + items; separators; diff --git a/src/slang-nodes/UsingDirective.js b/src/slang-nodes/UsingDirective.js index d98d952bb..de067adfd 100644 --- a/src/slang-nodes/UsingDirective.js +++ b/src/slang-nodes/UsingDirective.js @@ -1,8 +1,13 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { UsingClause } from './UsingClause.js'; import { UsingTarget } from './UsingTarget.js'; export class UsingDirective extends SlangNode { + get kind() { + return NonterminalKind.UsingDirective; + } + usingKeyword; clause; diff --git a/src/slang-nodes/UsingOperator.js b/src/slang-nodes/UsingOperator.js index f6c4b30bf..eee3758c2 100644 --- a/src/slang-nodes/UsingOperator.js +++ b/src/slang-nodes/UsingOperator.js @@ -1,6 +1,11 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; export class UsingOperator extends SlangNode { + get kind() { + return NonterminalKind.UsingOperator; + } + variant; constructor(ast, offset) { diff --git a/src/slang-nodes/UsingTarget.js b/src/slang-nodes/UsingTarget.js index 9862fcfed..50b813931 100644 --- a/src/slang-nodes/UsingTarget.js +++ b/src/slang-nodes/UsingTarget.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { TypeName } from './TypeName.js'; export class UsingTarget extends SlangNode { + get kind() { + return NonterminalKind.UsingTarget; + } + variant; constructor(ast, offset, options) { diff --git a/src/slang-nodes/VariableDeclarationStatement.js b/src/slang-nodes/VariableDeclarationStatement.js index 68f71741f..f6050dd1a 100644 --- a/src/slang-nodes/VariableDeclarationStatement.js +++ b/src/slang-nodes/VariableDeclarationStatement.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { VariableDeclarationType } from './VariableDeclarationType.js'; import { StorageLocation } from './StorageLocation.js'; @@ -7,6 +8,10 @@ import { VariableDeclarationValue } from './VariableDeclarationValue.js'; const { group, indent, indentIfBreak, line } = doc.builders; export class VariableDeclarationStatement extends SlangNode { + get kind() { + return NonterminalKind.VariableDeclarationStatement; + } + variableType; storageLocation; diff --git a/src/slang-nodes/VariableDeclarationType.js b/src/slang-nodes/VariableDeclarationType.js index 4fd4695f4..3fe26270c 100644 --- a/src/slang-nodes/VariableDeclarationType.js +++ b/src/slang-nodes/VariableDeclarationType.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { TypeName } from './TypeName.js'; export class VariableDeclarationType extends SlangNode { + get kind() { + return NonterminalKind.VariableDeclarationType; + } + variant; constructor(ast, offset, options) { diff --git a/src/slang-nodes/VariableDeclarationValue.js b/src/slang-nodes/VariableDeclarationValue.js index 31c72b987..042097b37 100644 --- a/src/slang-nodes/VariableDeclarationValue.js +++ b/src/slang-nodes/VariableDeclarationValue.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { Expression } from './Expression.js'; export class VariableDeclarationValue extends SlangNode { + get kind() { + return NonterminalKind.VariableDeclarationValue; + } + equal; expression; diff --git a/src/slang-nodes/VersionComparator.js b/src/slang-nodes/VersionComparator.js index 775653a03..c6c4f6282 100644 --- a/src/slang-nodes/VersionComparator.js +++ b/src/slang-nodes/VersionComparator.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { VersionExpression } from './VersionExpression.js'; export class VersionComparator extends SlangNode { + get kind() { + return NonterminalKind.VersionComparator; + } + operator; operand; diff --git a/src/slang-nodes/VersionExpression.js b/src/slang-nodes/VersionExpression.js index 505764cc7..2c6b41abe 100644 --- a/src/slang-nodes/VersionExpression.js +++ b/src/slang-nodes/VersionExpression.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { VersionRange } from './VersionRange.js'; import { VersionComparator } from './VersionComparator.js'; @@ -10,6 +11,10 @@ const variants = { }; export class VersionExpression extends SlangNode { + get kind() { + return NonterminalKind.VersionExpression; + } + variant; constructor(ast, offset, options) { diff --git a/src/slang-nodes/VersionExpressionSet.js b/src/slang-nodes/VersionExpressionSet.js index 85d457ca8..2b00454ee 100644 --- a/src/slang-nodes/VersionExpressionSet.js +++ b/src/slang-nodes/VersionExpressionSet.js @@ -1,10 +1,15 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { VersionExpression } from './VersionExpression.js'; const { join } = doc.builders; export class VersionExpressionSet extends SlangNode { + get kind() { + return NonterminalKind.VersionExpressionSet; + } + items; constructor(ast, offset, options) { diff --git a/src/slang-nodes/VersionExpressionSets.js b/src/slang-nodes/VersionExpressionSets.js index f592b9dc9..7fef37b6c 100644 --- a/src/slang-nodes/VersionExpressionSets.js +++ b/src/slang-nodes/VersionExpressionSets.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { VersionExpressionSet } from './VersionExpressionSet.js'; export class VersionExpressionSets extends SlangNode { + get kind() { + return NonterminalKind.VersionExpressionSets; + } + items; separators; diff --git a/src/slang-nodes/VersionPragma.js b/src/slang-nodes/VersionPragma.js index d7421b94c..0ad676056 100644 --- a/src/slang-nodes/VersionPragma.js +++ b/src/slang-nodes/VersionPragma.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { VersionExpressionSets } from './VersionExpressionSets.js'; export class VersionPragma extends SlangNode { + get kind() { + return NonterminalKind.VersionPragma; + } + solidityKeyword; sets; diff --git a/src/slang-nodes/VersionRange.js b/src/slang-nodes/VersionRange.js index 21206d98f..56916d9cd 100644 --- a/src/slang-nodes/VersionRange.js +++ b/src/slang-nodes/VersionRange.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { VersionExpression } from './VersionExpression.js'; export class VersionRange extends SlangNode { + get kind() { + return NonterminalKind.VersionRange; + } + leftOperand; operator; diff --git a/src/slang-nodes/VersionSpecifiers.js b/src/slang-nodes/VersionSpecifiers.js index 9bf722dc2..11512198f 100644 --- a/src/slang-nodes/VersionSpecifiers.js +++ b/src/slang-nodes/VersionSpecifiers.js @@ -1,6 +1,11 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; export class VersionSpecifiers extends SlangNode { + get kind() { + return NonterminalKind.VersionSpecifiers; + } + items; separators; diff --git a/src/slang-nodes/WhileStatement.js b/src/slang-nodes/WhileStatement.js index 886ece0e1..17607df55 100644 --- a/src/slang-nodes/WhileStatement.js +++ b/src/slang-nodes/WhileStatement.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedItem } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; import { Expression } from './Expression.js'; @@ -7,6 +8,10 @@ import { Statement } from './Statement.js'; const { group, indent, line } = doc.builders; export class WhileStatement extends SlangNode { + get kind() { + return NonterminalKind.WhileStatement; + } + whileKeyword; openParen; diff --git a/src/slang-nodes/YulArguments.js b/src/slang-nodes/YulArguments.js index 06324d639..67db7ace3 100644 --- a/src/slang-nodes/YulArguments.js +++ b/src/slang-nodes/YulArguments.js @@ -1,8 +1,13 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; import { YulExpression } from './YulExpression.js'; export class YulArguments extends SlangNode { + get kind() { + return NonterminalKind.YulArguments; + } + items; separators; diff --git a/src/slang-nodes/YulAssignmentOperator.js b/src/slang-nodes/YulAssignmentOperator.js index 07a47e364..7b6bfc67d 100644 --- a/src/slang-nodes/YulAssignmentOperator.js +++ b/src/slang-nodes/YulAssignmentOperator.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { YulColonEqual } from './YulColonEqual.js'; export class YulAssignmentOperator extends SlangNode { + get kind() { + return NonterminalKind.YulAssignmentOperator; + } + variant; constructor(ast, offset, options) { diff --git a/src/slang-nodes/YulBlock.js b/src/slang-nodes/YulBlock.js index 81f13fff2..ac9a5dc59 100644 --- a/src/slang-nodes/YulBlock.js +++ b/src/slang-nodes/YulBlock.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { YulStatements } from './YulStatements.js'; export class YulBlock extends SlangNode { + get kind() { + return NonterminalKind.YulBlock; + } + openBrace; statements; diff --git a/src/slang-nodes/YulBreakStatement.js b/src/slang-nodes/YulBreakStatement.js index 728633a52..33dc4b82c 100644 --- a/src/slang-nodes/YulBreakStatement.js +++ b/src/slang-nodes/YulBreakStatement.js @@ -1,6 +1,11 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; export class YulBreakStatement extends SlangNode { + get kind() { + return NonterminalKind.YulBreakStatement; + } + breakKeyword; constructor(ast, offset) { diff --git a/src/slang-nodes/YulBuiltInFunction.js b/src/slang-nodes/YulBuiltInFunction.js index 0f664d4d0..f57e8c412 100644 --- a/src/slang-nodes/YulBuiltInFunction.js +++ b/src/slang-nodes/YulBuiltInFunction.js @@ -1,6 +1,11 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; export class YulBuiltInFunction extends SlangNode { + get kind() { + return NonterminalKind.YulBuiltInFunction; + } + variant; constructor(ast, offset) { diff --git a/src/slang-nodes/YulColonEqual.js b/src/slang-nodes/YulColonEqual.js index ab21f8265..b840c82c8 100644 --- a/src/slang-nodes/YulColonEqual.js +++ b/src/slang-nodes/YulColonEqual.js @@ -1,6 +1,11 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; export class YulColonEqual extends SlangNode { + get kind() { + return NonterminalKind.YulColonEqual; + } + colon; equal; diff --git a/src/slang-nodes/YulContinueStatement.js b/src/slang-nodes/YulContinueStatement.js index 81b46bc3b..2393319eb 100644 --- a/src/slang-nodes/YulContinueStatement.js +++ b/src/slang-nodes/YulContinueStatement.js @@ -1,6 +1,11 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; export class YulContinueStatement extends SlangNode { + get kind() { + return NonterminalKind.YulContinueStatement; + } + continueKeyword; constructor(ast, offset) { diff --git a/src/slang-nodes/YulDefaultCase.js b/src/slang-nodes/YulDefaultCase.js index 0a8fdf35e..c656fabe8 100644 --- a/src/slang-nodes/YulDefaultCase.js +++ b/src/slang-nodes/YulDefaultCase.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { YulBlock } from './YulBlock.js'; export class YulDefaultCase extends SlangNode { + get kind() { + return NonterminalKind.YulDefaultCase; + } + defaultKeyword; body; diff --git a/src/slang-nodes/YulExpression.js b/src/slang-nodes/YulExpression.js index 1b833594f..fd751f9ae 100644 --- a/src/slang-nodes/YulExpression.js +++ b/src/slang-nodes/YulExpression.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { YulFunctionCallExpression } from './YulFunctionCallExpression.js'; import { YulLiteral } from './YulLiteral.js'; @@ -12,6 +13,10 @@ const variants = { }; export class YulExpression extends SlangNode { + get kind() { + return NonterminalKind.YulExpression; + } + variant; constructor(ast, offset, options) { diff --git a/src/slang-nodes/YulForStatement.js b/src/slang-nodes/YulForStatement.js index 2855317c1..d4e22fe59 100644 --- a/src/slang-nodes/YulForStatement.js +++ b/src/slang-nodes/YulForStatement.js @@ -1,8 +1,13 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { YulBlock } from './YulBlock.js'; import { YulExpression } from './YulExpression.js'; export class YulForStatement extends SlangNode { + get kind() { + return NonterminalKind.YulForStatement; + } + forKeyword; initialization; diff --git a/src/slang-nodes/YulFunctionCallExpression.js b/src/slang-nodes/YulFunctionCallExpression.js index 220a84d95..1a86b6485 100644 --- a/src/slang-nodes/YulFunctionCallExpression.js +++ b/src/slang-nodes/YulFunctionCallExpression.js @@ -1,8 +1,13 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { YulExpression } from './YulExpression.js'; import { YulArguments } from './YulArguments.js'; export class YulFunctionCallExpression extends SlangNode { + get kind() { + return NonterminalKind.YulFunctionCallExpression; + } + operand; openParen; diff --git a/src/slang-nodes/YulFunctionDefinition.js b/src/slang-nodes/YulFunctionDefinition.js index 769c13a77..933ca2391 100644 --- a/src/slang-nodes/YulFunctionDefinition.js +++ b/src/slang-nodes/YulFunctionDefinition.js @@ -1,9 +1,14 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { YulParametersDeclaration } from './YulParametersDeclaration.js'; import { YulReturnsDeclaration } from './YulReturnsDeclaration.js'; import { YulBlock } from './YulBlock.js'; export class YulFunctionDefinition extends SlangNode { + get kind() { + return NonterminalKind.YulFunctionDefinition; + } + functionKeyword; name; diff --git a/src/slang-nodes/YulIfStatement.js b/src/slang-nodes/YulIfStatement.js index 457db9cfc..ec51a849c 100644 --- a/src/slang-nodes/YulIfStatement.js +++ b/src/slang-nodes/YulIfStatement.js @@ -1,8 +1,13 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { YulExpression } from './YulExpression.js'; import { YulBlock } from './YulBlock.js'; export class YulIfStatement extends SlangNode { + get kind() { + return NonterminalKind.YulIfStatement; + } + ifKeyword; condition; diff --git a/src/slang-nodes/YulLabel.js b/src/slang-nodes/YulLabel.js index 70253f246..c9d08a0cd 100644 --- a/src/slang-nodes/YulLabel.js +++ b/src/slang-nodes/YulLabel.js @@ -1,9 +1,14 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; const { dedent, line } = doc.builders; export class YulLabel extends SlangNode { + get kind() { + return NonterminalKind.YulLabel; + } + label; colon; diff --git a/src/slang-nodes/YulLeaveStatement.js b/src/slang-nodes/YulLeaveStatement.js index a19615afb..f622c28a9 100644 --- a/src/slang-nodes/YulLeaveStatement.js +++ b/src/slang-nodes/YulLeaveStatement.js @@ -1,6 +1,11 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; export class YulLeaveStatement extends SlangNode { + get kind() { + return NonterminalKind.YulLeaveStatement; + } + leaveKeyword; constructor(ast, offset) { diff --git a/src/slang-nodes/YulLiteral.js b/src/slang-nodes/YulLiteral.js index 58e8164d9..efb3639b0 100644 --- a/src/slang-nodes/YulLiteral.js +++ b/src/slang-nodes/YulLiteral.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { HexStringLiteral } from './HexStringLiteral.js'; import { StringLiteral } from './StringLiteral.js'; @@ -5,6 +6,10 @@ import { StringLiteral } from './StringLiteral.js'; const variants = { HexStringLiteral, StringLiteral }; export class YulLiteral extends SlangNode { + get kind() { + return NonterminalKind.YulLiteral; + } + variant; constructor(ast, offset, options) { diff --git a/src/slang-nodes/YulParameters.js b/src/slang-nodes/YulParameters.js index 67984b1a0..fd2e86b76 100644 --- a/src/slang-nodes/YulParameters.js +++ b/src/slang-nodes/YulParameters.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; export class YulParameters extends SlangNode { + get kind() { + return NonterminalKind.YulParameters; + } + items; separators; diff --git a/src/slang-nodes/YulParametersDeclaration.js b/src/slang-nodes/YulParametersDeclaration.js index 8f3cbd320..6a7989712 100644 --- a/src/slang-nodes/YulParametersDeclaration.js +++ b/src/slang-nodes/YulParametersDeclaration.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { YulParameters } from './YulParameters.js'; export class YulParametersDeclaration extends SlangNode { + get kind() { + return NonterminalKind.YulParametersDeclaration; + } + openParen; parameters; diff --git a/src/slang-nodes/YulPath.js b/src/slang-nodes/YulPath.js index 72358e8d1..a6e010b1c 100644 --- a/src/slang-nodes/YulPath.js +++ b/src/slang-nodes/YulPath.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { YulPathComponent } from './YulPathComponent.js'; export class YulPath extends SlangNode { + get kind() { + return NonterminalKind.YulPath; + } + items; separators; diff --git a/src/slang-nodes/YulPathComponent.js b/src/slang-nodes/YulPathComponent.js index 034dafa4f..a55386a20 100644 --- a/src/slang-nodes/YulPathComponent.js +++ b/src/slang-nodes/YulPathComponent.js @@ -1,6 +1,11 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; export class YulPathComponent extends SlangNode { + get kind() { + return NonterminalKind.YulPathComponent; + } + variant; constructor(ast, offset) { diff --git a/src/slang-nodes/YulPaths.js b/src/slang-nodes/YulPaths.js index 577b6a7a1..c54221ad9 100644 --- a/src/slang-nodes/YulPaths.js +++ b/src/slang-nodes/YulPaths.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { YulPath } from './YulPath.js'; export class YulPaths extends SlangNode { + get kind() { + return NonterminalKind.YulPaths; + } + items; separators; diff --git a/src/slang-nodes/YulReturnVariables.js b/src/slang-nodes/YulReturnVariables.js index 43f434cdf..56366b85d 100644 --- a/src/slang-nodes/YulReturnVariables.js +++ b/src/slang-nodes/YulReturnVariables.js @@ -1,10 +1,15 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; const { line } = doc.builders; export class YulReturnVariables extends SlangNode { + get kind() { + return NonterminalKind.YulReturnVariables; + } + items; separators; diff --git a/src/slang-nodes/YulReturnsDeclaration.js b/src/slang-nodes/YulReturnsDeclaration.js index 72128459a..4b9c250a7 100644 --- a/src/slang-nodes/YulReturnsDeclaration.js +++ b/src/slang-nodes/YulReturnsDeclaration.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedItem } from '../common/printer-helpers.js'; import { SlangNode } from './SlangNode.js'; import { YulReturnVariables } from './YulReturnVariables.js'; @@ -6,6 +7,10 @@ import { YulReturnVariables } from './YulReturnVariables.js'; const { line } = doc.builders; export class YulReturnsDeclaration extends SlangNode { + get kind() { + return NonterminalKind.YulReturnsDeclaration; + } + minusGreaterThan; variables; diff --git a/src/slang-nodes/YulStackAssignmentStatement.js b/src/slang-nodes/YulStackAssignmentStatement.js index 4ce38b671..374e332ce 100644 --- a/src/slang-nodes/YulStackAssignmentStatement.js +++ b/src/slang-nodes/YulStackAssignmentStatement.js @@ -1,8 +1,13 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { YulAssignmentOperator } from './YulAssignmentOperator.js'; import { YulExpression } from './YulExpression.js'; export class YulStackAssignmentStatement extends SlangNode { + get kind() { + return NonterminalKind.YulStackAssignmentStatement; + } + assignment; expression; diff --git a/src/slang-nodes/YulStatement.js b/src/slang-nodes/YulStatement.js index c04034713..c17d4c224 100644 --- a/src/slang-nodes/YulStatement.js +++ b/src/slang-nodes/YulStatement.js @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { YulBlock } from './YulBlock.js'; import { YulFunctionDefinition } from './YulFunctionDefinition.js'; @@ -30,6 +31,10 @@ const variants = { }; export class YulStatement extends SlangNode { + get kind() { + return NonterminalKind.YulStatement; + } + variant; constructor(ast, offset, options) { diff --git a/src/slang-nodes/YulStatements.js b/src/slang-nodes/YulStatements.js index 456400fe5..a055d975c 100644 --- a/src/slang-nodes/YulStatements.js +++ b/src/slang-nodes/YulStatements.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedItem } from '../common/printer-helpers.js'; import { printComments } from '../slang-printers/print-comments.js'; import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; @@ -8,6 +9,10 @@ import { YulStatement } from './YulStatement.js'; const { hardline } = doc.builders; export class YulStatements extends SlangNode { + get kind() { + return NonterminalKind.YulStatements; + } + items; constructor(ast, offset, options) { diff --git a/src/slang-nodes/YulSwitchCase.js b/src/slang-nodes/YulSwitchCase.js index cc3f40c82..a381c8513 100644 --- a/src/slang-nodes/YulSwitchCase.js +++ b/src/slang-nodes/YulSwitchCase.js @@ -1,9 +1,14 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { YulDefaultCase } from './YulDefaultCase.js'; import { YulValueCase } from './YulValueCase.js'; const variants = { YulDefaultCase, YulValueCase }; export class YulSwitchCase extends SlangNode { + get kind() { + return NonterminalKind.YulSwitchCase; + } + variant; constructor(ast, offset, options) { diff --git a/src/slang-nodes/YulSwitchCases.js b/src/slang-nodes/YulSwitchCases.js index b0e73f39f..8d6670ec0 100644 --- a/src/slang-nodes/YulSwitchCases.js +++ b/src/slang-nodes/YulSwitchCases.js @@ -1,10 +1,15 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { YulSwitchCase } from './YulSwitchCase.js'; const { hardline, join } = doc.builders; export class YulSwitchCases extends SlangNode { + get kind() { + return NonterminalKind.YulSwitchCases; + } + items; constructor(ast, offset, options) { diff --git a/src/slang-nodes/YulSwitchStatement.js b/src/slang-nodes/YulSwitchStatement.js index fbb7c0bc9..880763944 100644 --- a/src/slang-nodes/YulSwitchStatement.js +++ b/src/slang-nodes/YulSwitchStatement.js @@ -1,4 +1,5 @@ import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { YulExpression } from './YulExpression.js'; import { YulSwitchCases } from './YulSwitchCases.js'; @@ -6,6 +7,10 @@ import { YulSwitchCases } from './YulSwitchCases.js'; const { hardline } = doc.builders; export class YulSwitchStatement extends SlangNode { + get kind() { + return NonterminalKind.YulSwitchStatement; + } + switchKeyword; expression; diff --git a/src/slang-nodes/YulValueCase.js b/src/slang-nodes/YulValueCase.js index ec23a43db..f3147874f 100644 --- a/src/slang-nodes/YulValueCase.js +++ b/src/slang-nodes/YulValueCase.js @@ -1,8 +1,13 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { YulLiteral } from './YulLiteral.js'; import { YulBlock } from './YulBlock.js'; export class YulValueCase extends SlangNode { + get kind() { + return NonterminalKind.YulValueCase; + } + caseKeyword; value; diff --git a/src/slang-nodes/YulVariableAssignmentStatement.js b/src/slang-nodes/YulVariableAssignmentStatement.js index edc44b40c..29d48b5c5 100644 --- a/src/slang-nodes/YulVariableAssignmentStatement.js +++ b/src/slang-nodes/YulVariableAssignmentStatement.js @@ -1,9 +1,14 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { YulPaths } from './YulPaths.js'; import { YulAssignmentOperator } from './YulAssignmentOperator.js'; import { YulExpression } from './YulExpression.js'; export class YulVariableAssignmentStatement extends SlangNode { + get kind() { + return NonterminalKind.YulVariableAssignmentStatement; + } + names; assignment; diff --git a/src/slang-nodes/YulVariableDeclarationStatement.js b/src/slang-nodes/YulVariableDeclarationStatement.js index 8a236c2f3..d6959afa4 100644 --- a/src/slang-nodes/YulVariableDeclarationStatement.js +++ b/src/slang-nodes/YulVariableDeclarationStatement.js @@ -1,7 +1,12 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { YulVariableDeclarationValue } from './YulVariableDeclarationValue.js'; export class YulVariableDeclarationStatement extends SlangNode { + get kind() { + return NonterminalKind.YulVariableDeclarationStatement; + } + letKeyword; names; diff --git a/src/slang-nodes/YulVariableDeclarationValue.js b/src/slang-nodes/YulVariableDeclarationValue.js index cd1f365ca..8345ec75b 100644 --- a/src/slang-nodes/YulVariableDeclarationValue.js +++ b/src/slang-nodes/YulVariableDeclarationValue.js @@ -1,8 +1,13 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { SlangNode } from './SlangNode.js'; import { YulAssignmentOperator } from './YulAssignmentOperator.js'; import { YulExpression } from './YulExpression.js'; export class YulVariableDeclarationValue extends SlangNode { + get kind() { + return NonterminalKind.YulVariableDeclarationValue; + } + assignment; expression; diff --git a/src/slang-utils/create-hug-function.js b/src/slang-utils/create-hug-function.js index fd6189658..ec79243ef 100644 --- a/src/slang-utils/create-hug-function.js +++ b/src/slang-utils/create-hug-function.js @@ -14,18 +14,14 @@ export function createHugFunction(huggableOperators) { const { loc } = node; return new Expression({ - kind: 'Expression', loc: { ...loc }, variant: new TupleExpression({ - kind: 'TupleExpression', loc: { ...loc }, openParen: '(', items: new TupleValues({ - kind: 'TupleValues', loc: { ...loc }, items: [ new TupleValue({ - kind: 'TupleValue', loc: { ...loc }, expression: node }) From cdf45994f3c39e8193bd1c2fff3d67639bed1566 Mon Sep 17 00:00:00 2001 From: Klaus Date: Thu, 18 Jul 2024 16:16:25 +1200 Subject: [PATCH 094/160] if offset is not defined, this is one of the few classes that can be initiated with a simple object. --- src/slang-nodes/ExponentiationExpression.js | 38 ++++++++++----------- src/slang-nodes/Expression.js | 30 ++++++++-------- src/slang-nodes/Parameters.js | 25 ++++++-------- src/slang-nodes/ParametersDeclaration.js | 32 ++++++++--------- src/slang-nodes/SlangNode.js | 11 ++++-- src/slang-nodes/TupleExpression.js | 24 ++++++------- src/slang-nodes/TupleValue.js | 20 +++++------ src/slang-nodes/TupleValues.js | 23 ++++++------- 8 files changed, 95 insertions(+), 108 deletions(-) diff --git a/src/slang-nodes/ExponentiationExpression.js b/src/slang-nodes/ExponentiationExpression.js index 05c67ede9..a1ed7cf19 100644 --- a/src/slang-nodes/ExponentiationExpression.js +++ b/src/slang-nodes/ExponentiationExpression.js @@ -33,23 +33,26 @@ export class ExponentiationExpression extends SlangNode { constructor(ast, offset, options) { super(); - if (offset) { - const fetch = (childrenOffsets) => ({ - leftOperand: new Expression( - ast.leftOperand, - childrenOffsets.shift(), - options - ), - operator: ast.operator.text, - rightOperand: new Expression( - ast.rightOperand, - childrenOffsets.shift(), - options - ) - }); + const fetch = + typeof offset !== 'undefined' + ? (childrenOffsets) => ({ + leftOperand: new Expression( + ast.leftOperand, + childrenOffsets.shift(), + options + ), + operator: ast.operator.text, + rightOperand: new Expression( + ast.rightOperand, + childrenOffsets.shift(), + options + ) + }) + : undefined; - this.initialize(ast, offset, fetch); + this.initialize(ast, offset, fetch); + if (offset) { const compiler = coerce(options.compiler); if (compiler) { if (satisfies(compiler, '>=0.8.0')) { @@ -99,11 +102,6 @@ export class ExponentiationExpression extends SlangNode { this.leftOperand = tryToHug(this.leftOperand); } } - } else { - this.loc = ast.loc; - this.leftOperand = ast.leftOperand; - this.operator = ast.operator; - this.rightOperand = ast.rightOperand; } } diff --git a/src/slang-nodes/Expression.js b/src/slang-nodes/Expression.js index 74322359e..495870019 100644 --- a/src/slang-nodes/Expression.js +++ b/src/slang-nodes/Expression.js @@ -68,23 +68,21 @@ export class Expression extends SlangNode { constructor(ast, offset, options) { super(); - if (offset) { - const fetch = (childrenOffsets) => ({ - variant: - ast.variant.type === 'Terminal' - ? ast.variant.text - : new variants[ast.variant.cst.kind]( - ast.variant, - childrenOffsets.shift(), - options - ) - }); + const fetch = + typeof offset !== 'undefined' + ? (childrenOffsets) => ({ + variant: + ast.variant.type === 'Terminal' + ? ast.variant.text + : new variants[ast.variant.cst.kind]( + ast.variant, + childrenOffsets.shift(), + options + ) + }) + : undefined; - this.initialize(ast, offset, fetch); - } else { - this.loc = ast.loc; - this.variant = ast.variant; - } + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/Parameters.js b/src/slang-nodes/Parameters.js index 0de32977c..b6b2c65cc 100644 --- a/src/slang-nodes/Parameters.js +++ b/src/slang-nodes/Parameters.js @@ -19,20 +19,17 @@ export class Parameters extends SlangNode { constructor(ast, offset, options) { super(); - if (offset) { - const fetch = (childrenOffsets) => ({ - items: ast.items.map( - (item) => new Parameter(item, childrenOffsets.shift(), options) - ), - separators: ast.separators.map((separator) => separator.text) - }); - - this.initialize(ast, offset, fetch); - } else { - this.loc = ast.loc; - this.items = ast.items; - this.separators = ast.separators; - } + const fetch = + typeof offset !== 'undefined' + ? (childrenOffsets) => ({ + items: ast.items.map( + (item) => new Parameter(item, childrenOffsets.shift(), options) + ), + separators: ast.separators.map((separator) => separator.text) + }) + : undefined; + + this.initialize(ast, offset, fetch); } print(path, print, options) { diff --git a/src/slang-nodes/ParametersDeclaration.js b/src/slang-nodes/ParametersDeclaration.js index f82073374..0574558c9 100644 --- a/src/slang-nodes/ParametersDeclaration.js +++ b/src/slang-nodes/ParametersDeclaration.js @@ -16,24 +16,20 @@ export class ParametersDeclaration extends SlangNode { constructor(ast, offset, options) { super(); - if (offset) { - const fetch = (childrenOffsets) => ({ - openParen: ast.openParen.text, - parameters: new Parameters( - ast.parameters, - childrenOffsets.shift(), - options - ), - closeParen: ast.closeParen.text - }); - - this.initialize(ast, offset, fetch); - } else { - this.loc = ast.loc; - this.openParen = ast.openParen; - this.parameters = ast.parameters; - this.closeParen = ast.closeParen; - } + const fetch = + typeof offset !== 'undefined' + ? (childrenOffsets) => ({ + openParen: ast.openParen.text, + parameters: new Parameters( + ast.parameters, + childrenOffsets.shift(), + options + ), + closeParen: ast.closeParen.text + }) + : undefined; + + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/SlangNode.js b/src/slang-nodes/SlangNode.js index 0d308f3d1..9d4b6f966 100644 --- a/src/slang-nodes/SlangNode.js +++ b/src/slang-nodes/SlangNode.js @@ -13,6 +13,15 @@ export class SlangNode { comments = []; initialize(ast, offset, fetch, postProcess) { + let properties; + if (typeof offset === 'undefined') { + properties = { ...ast }; + + Object.keys(properties).forEach((propertyKey) => { + this[propertyKey] = properties[propertyKey]; + }); + return; + } if (this.kind !== ast.cst.kind) throw new Error( `${this.kind} can only be initialized with an AST node of the same kind.` @@ -26,8 +35,6 @@ export class SlangNode { ); // populate all children nodes - let properties; - this.fetch = () => { if (properties === undefined) { properties = fetch(childrenOffsets); diff --git a/src/slang-nodes/TupleExpression.js b/src/slang-nodes/TupleExpression.js index 424ed29bc..7dde3f2a6 100644 --- a/src/slang-nodes/TupleExpression.js +++ b/src/slang-nodes/TupleExpression.js @@ -16,20 +16,16 @@ export class TupleExpression extends SlangNode { constructor(ast, offset, options) { super(); - if (offset) { - const fetch = (childrenOffsets) => ({ - openParen: ast.openParen.text, - items: new TupleValues(ast.items, childrenOffsets.shift(), options), - closeParen: ast.closeParen.text - }); - - this.initialize(ast, offset, fetch); - } else { - this.loc = ast.loc; - this.openParen = ast.openParen; - this.items = ast.items; - this.closeParen = ast.closeParen; - } + const fetch = + typeof offset !== 'undefined' + ? (childrenOffsets) => ({ + openParen: ast.openParen.text, + items: new TupleValues(ast.items, childrenOffsets.shift(), options), + closeParen: ast.closeParen.text + }) + : undefined; + + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/TupleValue.js b/src/slang-nodes/TupleValue.js index ee65d32c3..eeff8f7a4 100644 --- a/src/slang-nodes/TupleValue.js +++ b/src/slang-nodes/TupleValue.js @@ -12,18 +12,16 @@ export class TupleValue extends SlangNode { constructor(ast, offset, options) { super(); - if (offset) { - const fetch = (childrenOffsets) => ({ - expression: ast.expression - ? new Expression(ast.expression, childrenOffsets.shift(), options) - : undefined - }); + const fetch = + typeof offset !== 'undefined' + ? (childrenOffsets) => ({ + expression: ast.expression + ? new Expression(ast.expression, childrenOffsets.shift(), options) + : undefined + }) + : undefined; - this.initialize(ast, offset, fetch); - } else { - this.loc = ast.loc; - this.expression = ast.expression; - } + this.initialize(ast, offset, fetch); } print(path, print) { diff --git a/src/slang-nodes/TupleValues.js b/src/slang-nodes/TupleValues.js index 12f226116..36e3c20c3 100644 --- a/src/slang-nodes/TupleValues.js +++ b/src/slang-nodes/TupleValues.js @@ -16,20 +16,17 @@ export class TupleValues extends SlangNode { constructor(ast, offset, options) { super(); - if (offset) { - const fetch = (childrenOffsets) => ({ - items: ast.items.map( - (item) => new TupleValue(item, childrenOffsets.shift(), options) - ), - separators: ast.separators.map((separator) => separator.text) - }); + const fetch = + typeof offset !== 'undefined' + ? (childrenOffsets) => ({ + items: ast.items.map( + (item) => new TupleValue(item, childrenOffsets.shift(), options) + ), + separators: ast.separators.map((separator) => separator.text) + }) + : undefined; - this.initialize(ast, offset, fetch); - } else { - this.loc = ast.loc; - this.items = ast.items; - this.separators = ast.separators; - } + this.initialize(ast, offset, fetch); } print(path, print) { From 41c9b814b6be13c409f871a4aacce5daa335b2cb Mon Sep 17 00:00:00 2001 From: Klaus Date: Fri, 19 Jul 2024 22:31:05 +1200 Subject: [PATCH 095/160] using Object.create instead of having a special case in the constructor for instances created dynamically --- src/slang-nodes/ExponentiationExpression.js | 93 ++++++++++++--------- src/slang-nodes/Expression.js | 23 +++-- src/slang-nodes/ModifierDefinition.js | 20 +++-- src/slang-nodes/Parameters.js | 15 ++-- src/slang-nodes/ParametersDeclaration.js | 21 ++--- src/slang-nodes/SlangNode.js | 7 -- src/slang-nodes/TupleExpression.js | 13 ++- src/slang-nodes/TupleValue.js | 13 ++- src/slang-nodes/TupleValues.js | 15 ++-- src/slang-utils/create-hug-function.js | 38 +++++---- 10 files changed, 127 insertions(+), 131 deletions(-) diff --git a/src/slang-nodes/ExponentiationExpression.js b/src/slang-nodes/ExponentiationExpression.js index a1ed7cf19..3ab0f2298 100644 --- a/src/slang-nodes/ExponentiationExpression.js +++ b/src/slang-nodes/ExponentiationExpression.js @@ -33,22 +33,19 @@ export class ExponentiationExpression extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = - typeof offset !== 'undefined' - ? (childrenOffsets) => ({ - leftOperand: new Expression( - ast.leftOperand, - childrenOffsets.shift(), - options - ), - operator: ast.operator.text, - rightOperand: new Expression( - ast.rightOperand, - childrenOffsets.shift(), - options - ) - }) - : undefined; + const fetch = (childrenOffsets) => ({ + leftOperand: new Expression( + ast.leftOperand, + childrenOffsets.shift(), + options + ), + operator: ast.operator.text, + rightOperand: new Expression( + ast.rightOperand, + childrenOffsets.shift(), + options + ) + }); this.initialize(ast, offset, fetch); @@ -71,31 +68,47 @@ export class ExponentiationExpression extends SlangNode { this.rightOperand.variant.leftOperand.loc.endWithTrivia, end: this.rightOperand.variant.leftOperand.loc.end }; - this.leftOperand = new Expression({ - loc: { ...leftLoc }, - variant: new TupleExpression({ - loc: { ...leftLoc }, - openParen: '(', - items: new TupleValues({ - loc: { ...leftLoc }, - items: [ - new TupleValue({ - loc: { ...leftLoc }, - expression: new Expression({ - loc: { ...leftLoc }, - variant: new ExponentiationExpression({ - loc: { ...leftLoc }, - leftOperand: this.leftOperand, - operator: '**', - rightOperand: this.rightOperand.variant.leftOperand - }) - }) + this.leftOperand = Object.create(Expression.prototype, { + loc: { value: { ...leftLoc } }, + variant: { + value: Object.create(TupleExpression.prototype, { + loc: { value: { ...leftLoc } }, + openParen: { value: '(' }, + items: { + value: Object.create(TupleValues.prototype, { + loc: { value: { ...leftLoc } }, + items: { + value: [ + Object.create(TupleValue.prototype, { + loc: { value: { ...leftLoc } }, + expression: { + value: Object.create(Expression.prototype, { + loc: { value: { ...leftLoc } }, + variant: { + value: Object.create( + ExponentiationExpression.prototype, + { + loc: { value: { ...leftLoc } }, + leftOperand: { value: this.leftOperand }, + operator: { value: '**' }, + rightOperand: { + value: + this.rightOperand.variant.leftOperand + } + } + ) + } + }) + } + }) + ] + }, + separators: { value: [] } }) - ], - separators: [] - }), - closeParen: ')' - }) + }, + closeParen: { value: ')' } + }) + } }); this.rightOperand = this.rightOperand.variant.rightOperand; } diff --git a/src/slang-nodes/Expression.js b/src/slang-nodes/Expression.js index 495870019..d50ae8a31 100644 --- a/src/slang-nodes/Expression.js +++ b/src/slang-nodes/Expression.js @@ -68,19 +68,16 @@ export class Expression extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = - typeof offset !== 'undefined' - ? (childrenOffsets) => ({ - variant: - ast.variant.type === 'Terminal' - ? ast.variant.text - : new variants[ast.variant.cst.kind]( - ast.variant, - childrenOffsets.shift(), - options - ) - }) - : undefined; + const fetch = (childrenOffsets) => ({ + variant: + ast.variant.type === 'Terminal' + ? ast.variant.text + : new variants[ast.variant.cst.kind]( + ast.variant, + childrenOffsets.shift(), + options + ) + }); this.initialize(ast, offset, fetch); } diff --git a/src/slang-nodes/ModifierDefinition.js b/src/slang-nodes/ModifierDefinition.js index 20b588264..eff448b6f 100644 --- a/src/slang-nodes/ModifierDefinition.js +++ b/src/slang-nodes/ModifierDefinition.js @@ -19,15 +19,17 @@ const postProcess = (properties) => { return { ...properties, - parameters: new ParametersDeclaration({ - loc: { ...parametersLoc }, - openParen: '(', - parameters: new Parameters({ - loc: { ...parametersLoc }, - items: [], - separators: [] - }), - closeParen: ')' + parameters: Object.create(ParametersDeclaration.prototype, { + loc: { value: { ...parametersLoc } }, + openParen: { value: '(' }, + parameters: { + value: Object.create(Parameters.prototype, { + loc: { value: { ...parametersLoc } }, + items: { value: [] }, + separators: { value: [] } + }) + }, + closeParen: { value: ')' } }) }; }; diff --git a/src/slang-nodes/Parameters.js b/src/slang-nodes/Parameters.js index b6b2c65cc..cea7ba06b 100644 --- a/src/slang-nodes/Parameters.js +++ b/src/slang-nodes/Parameters.js @@ -19,15 +19,12 @@ export class Parameters extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = - typeof offset !== 'undefined' - ? (childrenOffsets) => ({ - items: ast.items.map( - (item) => new Parameter(item, childrenOffsets.shift(), options) - ), - separators: ast.separators.map((separator) => separator.text) - }) - : undefined; + const fetch = (childrenOffsets) => ({ + items: ast.items.map( + (item) => new Parameter(item, childrenOffsets.shift(), options) + ), + separators: ast.separators.map((separator) => separator.text) + }); this.initialize(ast, offset, fetch); } diff --git a/src/slang-nodes/ParametersDeclaration.js b/src/slang-nodes/ParametersDeclaration.js index 0574558c9..ffd4ebcc6 100644 --- a/src/slang-nodes/ParametersDeclaration.js +++ b/src/slang-nodes/ParametersDeclaration.js @@ -16,18 +16,15 @@ export class ParametersDeclaration extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = - typeof offset !== 'undefined' - ? (childrenOffsets) => ({ - openParen: ast.openParen.text, - parameters: new Parameters( - ast.parameters, - childrenOffsets.shift(), - options - ), - closeParen: ast.closeParen.text - }) - : undefined; + const fetch = (childrenOffsets) => ({ + openParen: ast.openParen.text, + parameters: new Parameters( + ast.parameters, + childrenOffsets.shift(), + options + ), + closeParen: ast.closeParen.text + }); this.initialize(ast, offset, fetch); } diff --git a/src/slang-nodes/SlangNode.js b/src/slang-nodes/SlangNode.js index 9d4b6f966..31576c7f0 100644 --- a/src/slang-nodes/SlangNode.js +++ b/src/slang-nodes/SlangNode.js @@ -14,14 +14,7 @@ export class SlangNode { initialize(ast, offset, fetch, postProcess) { let properties; - if (typeof offset === 'undefined') { - properties = { ...ast }; - Object.keys(properties).forEach((propertyKey) => { - this[propertyKey] = properties[propertyKey]; - }); - return; - } if (this.kind !== ast.cst.kind) throw new Error( `${this.kind} can only be initialized with an AST node of the same kind.` diff --git a/src/slang-nodes/TupleExpression.js b/src/slang-nodes/TupleExpression.js index 7dde3f2a6..ecb4e9476 100644 --- a/src/slang-nodes/TupleExpression.js +++ b/src/slang-nodes/TupleExpression.js @@ -16,14 +16,11 @@ export class TupleExpression extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = - typeof offset !== 'undefined' - ? (childrenOffsets) => ({ - openParen: ast.openParen.text, - items: new TupleValues(ast.items, childrenOffsets.shift(), options), - closeParen: ast.closeParen.text - }) - : undefined; + const fetch = (childrenOffsets) => ({ + openParen: ast.openParen.text, + items: new TupleValues(ast.items, childrenOffsets.shift(), options), + closeParen: ast.closeParen.text + }); this.initialize(ast, offset, fetch); } diff --git a/src/slang-nodes/TupleValue.js b/src/slang-nodes/TupleValue.js index eeff8f7a4..3811608eb 100644 --- a/src/slang-nodes/TupleValue.js +++ b/src/slang-nodes/TupleValue.js @@ -12,14 +12,11 @@ export class TupleValue extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = - typeof offset !== 'undefined' - ? (childrenOffsets) => ({ - expression: ast.expression - ? new Expression(ast.expression, childrenOffsets.shift(), options) - : undefined - }) - : undefined; + const fetch = (childrenOffsets) => ({ + expression: ast.expression + ? new Expression(ast.expression, childrenOffsets.shift(), options) + : undefined + }); this.initialize(ast, offset, fetch); } diff --git a/src/slang-nodes/TupleValues.js b/src/slang-nodes/TupleValues.js index 36e3c20c3..bffff2b9d 100644 --- a/src/slang-nodes/TupleValues.js +++ b/src/slang-nodes/TupleValues.js @@ -16,15 +16,12 @@ export class TupleValues extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = - typeof offset !== 'undefined' - ? (childrenOffsets) => ({ - items: ast.items.map( - (item) => new TupleValue(item, childrenOffsets.shift(), options) - ), - separators: ast.separators.map((separator) => separator.text) - }) - : undefined; + const fetch = (childrenOffsets) => ({ + items: ast.items.map( + (item) => new TupleValue(item, childrenOffsets.shift(), options) + ), + separators: ast.separators.map((separator) => separator.text) + }); this.initialize(ast, offset, fetch); } diff --git a/src/slang-utils/create-hug-function.js b/src/slang-utils/create-hug-function.js index ec79243ef..3c188f21f 100644 --- a/src/slang-utils/create-hug-function.js +++ b/src/slang-utils/create-hug-function.js @@ -13,23 +13,29 @@ export function createHugFunction(huggableOperators) { ) { const { loc } = node; - return new Expression({ - loc: { ...loc }, - variant: new TupleExpression({ - loc: { ...loc }, - openParen: '(', - items: new TupleValues({ - loc: { ...loc }, - items: [ - new TupleValue({ - loc: { ...loc }, - expression: node + return Object.create(Expression.prototype, { + loc: { value: { ...loc } }, + variant: { + value: Object.create(TupleExpression.prototype, { + loc: { value: { ...loc } }, + openParen: { value: '(' }, + items: { + value: Object.create(TupleValues.prototype, { + loc: { value: { ...loc } }, + items: { + value: [ + Object.create(TupleValue.prototype, { + loc: { value: { ...loc } }, + expression: { value: node } + }) + ] + }, + separators: { value: [] } }) - ], - separators: [] - }), - closeParen: ')' - }) + }, + closeParen: { value: ')' } + }) + } }); } From 64c8a16f27a26f7d79ce5d97608ddb246b02d640 Mon Sep 17 00:00:00 2001 From: Klaus Date: Tue, 23 Jul 2024 15:53:51 +1200 Subject: [PATCH 096/160] redefining loc so it can easily be reorganised --- src/slang-nodes/ExponentiationExpression.js | 6 +-- src/slang-nodes/ModifierDefinition.js | 9 +++-- src/slang-nodes/SlangNode.js | 43 +++++++++------------ 3 files changed, 26 insertions(+), 32 deletions(-) diff --git a/src/slang-nodes/ExponentiationExpression.js b/src/slang-nodes/ExponentiationExpression.js index 3ab0f2298..c55c69e27 100644 --- a/src/slang-nodes/ExponentiationExpression.js +++ b/src/slang-nodes/ExponentiationExpression.js @@ -62,10 +62,10 @@ export class ExponentiationExpression extends SlangNode { // https://github.com/NomicFoundation/slang/issues/1031 if (this.rightOperand.variant.kind === 'ExponentiationExpression') { const leftLoc = { - startWithTrivia: this.leftOperand.loc.startWithTrivia, + leadingOffset: this.leftOperand.loc.leadingOffset, start: this.leftOperand.loc.start, - endWithTrivia: - this.rightOperand.variant.leftOperand.loc.endWithTrivia, + trailingOffset: + this.rightOperand.variant.leftOperand.loc.trailingOffset, end: this.rightOperand.variant.leftOperand.loc.end }; this.leftOperand = Object.create(Expression.prototype, { diff --git a/src/slang-nodes/ModifierDefinition.js b/src/slang-nodes/ModifierDefinition.js index eff448b6f..c363c2d1c 100644 --- a/src/slang-nodes/ModifierDefinition.js +++ b/src/slang-nodes/ModifierDefinition.js @@ -9,12 +9,13 @@ import { FunctionBody } from './FunctionBody.js'; const postProcess = (properties) => { if (typeof properties.parameters !== 'undefined') return properties; - const parametersOffset = properties.attributes.loc.startWithTrivia; + const parametersOffset = + properties.attributes.loc.start - properties.attributes.loc.leadingOffset; const parametersLoc = { - startWithTrivia: parametersOffset, start: parametersOffset, - endWithTrivia: parametersOffset, - end: parametersOffset + end: parametersOffset, + leadingOffset: 0, + trailingOffset: 0 }; return { diff --git a/src/slang-nodes/SlangNode.js b/src/slang-nodes/SlangNode.js index 31576c7f0..e18878f68 100644 --- a/src/slang-nodes/SlangNode.js +++ b/src/slang-nodes/SlangNode.js @@ -28,14 +28,9 @@ export class SlangNode { ); // populate all children nodes - this.fetch = () => { - if (properties === undefined) { - properties = fetch(childrenOffsets); - } - return properties; - }; - - this.fetch(); + if (properties === undefined) { + properties = fetch(childrenOffsets); + } const propertyKeys = Object.keys(properties); const propertyValues = Object.values(properties); @@ -55,39 +50,37 @@ export class SlangNode { }); // calculate correct loc object - const startWithTrivia = offset; - const endWithTrivia = offset + ast.cst.textLength.utf8; - let leadingOffset = getLeadingOffset(cstChildren); - let trailingOffset = getTrailingOffset(cstChildren); + this.loc = { + start: offset, + end: offset + ast.cst.textLength.utf8, + leadingOffset: getLeadingOffset(cstChildren), + trailingOffset: getTrailingOffset(cstChildren) + }; - if (leadingOffset === 0 || trailingOffset === 0) { + if (this.loc.leadingOffset === 0 || this.loc.trailingOffset === 0) { for (let i = 0; i < propertyKeys.length; i += 1) { const childLoc = properties[propertyKeys[i]]?.loc; if (childLoc) { if ( - leadingOffset === 0 && - childLoc.startWithTrivia === startWithTrivia + this.loc.leadingOffset === 0 && + childLoc.start - childLoc.leadingOffset === this.loc.start ) { - leadingOffset = childLoc.start - startWithTrivia; + this.loc.leadingOffset = childLoc.leadingOffset; } if ( - trailingOffset === 0 && - childLoc.endWithTrivia === endWithTrivia + this.loc.trailingOffset === 0 && + childLoc.end + childLoc.trailingOffset === this.loc.end ) { - trailingOffset = endWithTrivia - childLoc.end; + this.loc.trailingOffset = childLoc.trailingOffset; } } } } - this.loc = { - startWithTrivia, - start: startWithTrivia + leadingOffset, - endWithTrivia, - end: endWithTrivia - trailingOffset - }; + this.loc.start += this.loc.leadingOffset; + this.loc.end -= this.loc.trailingOffset; if (typeof postProcess === 'function') { properties = postProcess(properties); From bd6a2ea35ed873930349f8d003026828db0f124c Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 24 Jul 2024 08:01:01 +1200 Subject: [PATCH 097/160] instead of using unshift, we access the offset by index. --- src/slang-nodes/AdditiveExpression.js | 14 +- src/slang-nodes/AndExpression.js | 14 +- src/slang-nodes/ArgumentsDeclaration.js | 4 +- src/slang-nodes/ArrayExpression.js | 4 +- src/slang-nodes/ArrayTypeName.js | 6 +- src/slang-nodes/ArrayValues.js | 4 +- src/slang-nodes/AssemblyFlags.js | 4 +- src/slang-nodes/AssemblyFlagsDeclaration.js | 4 +- src/slang-nodes/AssemblyStatement.js | 28 ++-- src/slang-nodes/AssignmentExpression.js | 14 +- src/slang-nodes/BitwiseAndExpression.js | 14 +- src/slang-nodes/BitwiseOrExpression.js | 14 +- src/slang-nodes/BitwiseXorExpression.js | 14 +- src/slang-nodes/Block.js | 8 +- src/slang-nodes/CallOptions.js | 4 +- src/slang-nodes/CallOptionsExpression.js | 6 +- src/slang-nodes/CatchClause.js | 18 ++- src/slang-nodes/CatchClauseError.js | 8 +- src/slang-nodes/CatchClauses.js | 4 +- src/slang-nodes/ComparisonExpression.js | 14 +- src/slang-nodes/ConditionalExpression.js | 16 +- src/slang-nodes/ConstantDefinition.js | 6 +- src/slang-nodes/ConstructorAttribute.js | 8 +- src/slang-nodes/ConstructorAttributes.js | 5 +- src/slang-nodes/ConstructorDefinition.js | 8 +- src/slang-nodes/ContractDefinition.js | 38 ++--- src/slang-nodes/ContractMember.js | 4 +- src/slang-nodes/ContractMembers.js | 4 +- src/slang-nodes/DecimalNumberExpression.js | 6 +- src/slang-nodes/DoWhileStatement.js | 10 +- src/slang-nodes/ElementaryType.js | 4 +- src/slang-nodes/ElseBranch.js | 4 +- src/slang-nodes/EmitStatement.js | 10 +- src/slang-nodes/EnumDefinition.js | 4 +- src/slang-nodes/EqualityExpression.js | 14 +- src/slang-nodes/ErrorDefinition.js | 8 +- src/slang-nodes/ErrorParameter.js | 4 +- src/slang-nodes/ErrorParameters.js | 4 +- src/slang-nodes/ErrorParametersDeclaration.js | 8 +- src/slang-nodes/EventDefinition.js | 4 +- src/slang-nodes/EventParameter.js | 4 +- src/slang-nodes/EventParameters.js | 4 +- src/slang-nodes/EventParametersDeclaration.js | 8 +- src/slang-nodes/ExperimentalFeature.js | 4 +- src/slang-nodes/ExperimentalPragma.js | 8 +- src/slang-nodes/ExponentiationExpression.js | 138 ++++++++---------- src/slang-nodes/Expression.js | 8 +- src/slang-nodes/ExpressionStatement.js | 8 +- src/slang-nodes/FallbackFunctionAttribute.js | 8 +- src/slang-nodes/FallbackFunctionAttributes.js | 6 +- src/slang-nodes/FallbackFunctionDefinition.js | 38 ++--- src/slang-nodes/ForStatement.js | 42 +++--- src/slang-nodes/ForStatementCondition.js | 8 +- src/slang-nodes/ForStatementInitialization.js | 8 +- src/slang-nodes/FunctionAttribute.js | 8 +- src/slang-nodes/FunctionAttributes.js | 4 +- src/slang-nodes/FunctionBody.js | 4 +- src/slang-nodes/FunctionCallExpression.js | 10 +- src/slang-nodes/FunctionDefinition.js | 36 ++--- src/slang-nodes/FunctionType.js | 8 +- src/slang-nodes/FunctionTypeAttributes.js | 6 +- src/slang-nodes/HexNumberExpression.js | 6 +- src/slang-nodes/HexStringLiterals.js | 4 +- src/slang-nodes/IfStatement.js | 12 +- src/slang-nodes/ImportClause.js | 4 +- src/slang-nodes/ImportDeconstruction.js | 6 +- src/slang-nodes/ImportDeconstructionSymbol.js | 4 +- .../ImportDeconstructionSymbols.js | 6 +- src/slang-nodes/ImportDirective.js | 4 +- src/slang-nodes/IndexAccessEnd.js | 6 +- src/slang-nodes/IndexAccessExpression.js | 26 ++-- src/slang-nodes/InheritanceSpecifier.js | 4 +- src/slang-nodes/InheritanceType.js | 14 +- src/slang-nodes/InheritanceTypes.js | 4 +- src/slang-nodes/InterfaceDefinition.js | 36 ++--- src/slang-nodes/InterfaceMembers.js | 4 +- src/slang-nodes/LibraryDefinition.js | 8 +- src/slang-nodes/LibraryMembers.js | 4 +- src/slang-nodes/MappingKey.js | 8 +- src/slang-nodes/MappingKeyType.js | 4 +- src/slang-nodes/MappingType.js | 10 +- src/slang-nodes/MappingValue.js | 4 +- src/slang-nodes/MemberAccessExpression.js | 6 +- src/slang-nodes/ModifierAttribute.js | 4 +- src/slang-nodes/ModifierAttributes.js | 4 +- src/slang-nodes/ModifierDefinition.js | 38 ++--- src/slang-nodes/ModifierInvocation.js | 10 +- src/slang-nodes/MultiplicativeExpression.js | 14 +- src/slang-nodes/NamedArgument.js | 4 +- src/slang-nodes/NamedArgumentGroup.js | 8 +- src/slang-nodes/NamedArguments.js | 4 +- src/slang-nodes/NamedArgumentsDeclaration.js | 8 +- src/slang-nodes/NamedImport.js | 6 +- src/slang-nodes/NewExpression.js | 4 +- src/slang-nodes/OrExpression.js | 14 +- src/slang-nodes/OverridePaths.js | 4 +- src/slang-nodes/OverridePathsDeclaration.js | 4 +- src/slang-nodes/OverrideSpecifier.js | 8 +- src/slang-nodes/Parameter.js | 10 +- src/slang-nodes/Parameters.js | 4 +- src/slang-nodes/ParametersDeclaration.js | 8 +- src/slang-nodes/PathImport.js | 6 +- src/slang-nodes/PositionalArguments.js | 4 +- .../PositionalArgumentsDeclaration.js | 8 +- src/slang-nodes/PostfixExpression.js | 4 +- src/slang-nodes/Pragma.js | 4 +- src/slang-nodes/PragmaDirective.js | 4 +- src/slang-nodes/PrefixExpression.js | 4 +- src/slang-nodes/ReceiveFunctionAttribute.js | 8 +- src/slang-nodes/ReceiveFunctionAttributes.js | 6 +- src/slang-nodes/ReceiveFunctionDefinition.js | 8 +- src/slang-nodes/ReturnStatement.js | 4 +- src/slang-nodes/ReturnsDeclaration.js | 8 +- src/slang-nodes/RevertStatement.js | 28 ++-- src/slang-nodes/ShiftExpression.js | 14 +- src/slang-nodes/SourceUnit.js | 8 +- src/slang-nodes/SourceUnitMember.js | 4 +- src/slang-nodes/SourceUnitMembers.js | 4 +- src/slang-nodes/StateVariableAttribute.js | 4 +- src/slang-nodes/StateVariableAttributes.js | 6 +- src/slang-nodes/StateVariableDefinition.js | 12 +- .../StateVariableDefinitionValue.js | 4 +- src/slang-nodes/Statement.js | 4 +- src/slang-nodes/Statements.js | 4 +- src/slang-nodes/StringExpression.js | 4 +- src/slang-nodes/StringLiterals.js | 4 +- src/slang-nodes/StructDefinition.js | 4 +- src/slang-nodes/StructMember.js | 4 +- src/slang-nodes/StructMembers.js | 4 +- src/slang-nodes/TryStatement.js | 34 ++--- src/slang-nodes/TupleDeconstructionElement.js | 4 +- .../TupleDeconstructionElements.js | 6 +- .../TupleDeconstructionStatement.js | 10 +- src/slang-nodes/TupleExpression.js | 4 +- src/slang-nodes/TupleMember.js | 4 +- src/slang-nodes/TupleValue.js | 4 +- src/slang-nodes/TupleValues.js | 4 +- src/slang-nodes/TypeExpression.js | 4 +- src/slang-nodes/TypeName.js | 4 +- src/slang-nodes/TypedTupleMember.js | 10 +- src/slang-nodes/UncheckedBlock.js | 4 +- src/slang-nodes/UnicodeStringLiterals.js | 5 +- src/slang-nodes/UnnamedFunctionAttribute.js | 8 +- src/slang-nodes/UnnamedFunctionAttributes.js | 6 +- src/slang-nodes/UnnamedFunctionDefinition.js | 8 +- src/slang-nodes/UntypedTupleMember.js | 8 +- .../UserDefinedValueTypeDefinition.js | 8 +- src/slang-nodes/UsingAlias.js | 8 +- src/slang-nodes/UsingClause.js | 4 +- src/slang-nodes/UsingDeconstruction.js | 8 +- src/slang-nodes/UsingDeconstructionSymbol.js | 6 +- src/slang-nodes/UsingDeconstructionSymbols.js | 6 +- src/slang-nodes/UsingDirective.js | 6 +- src/slang-nodes/UsingTarget.js | 4 +- .../VariableDeclarationStatement.js | 42 +++--- src/slang-nodes/VariableDeclarationType.js | 4 +- src/slang-nodes/VariableDeclarationValue.js | 8 +- src/slang-nodes/VersionComparator.js | 8 +- src/slang-nodes/VersionExpression.js | 8 +- src/slang-nodes/VersionExpressionSet.js | 4 +- src/slang-nodes/VersionExpressionSets.js | 5 +- src/slang-nodes/VersionPragma.js | 8 +- src/slang-nodes/VersionRange.js | 14 +- src/slang-nodes/WhileStatement.js | 10 +- src/slang-nodes/YulArguments.js | 4 +- src/slang-nodes/YulAssignmentOperator.js | 4 +- src/slang-nodes/YulBlock.js | 8 +- src/slang-nodes/YulDefaultCase.js | 4 +- src/slang-nodes/YulExpression.js | 4 +- src/slang-nodes/YulForStatement.js | 18 +-- src/slang-nodes/YulFunctionCallExpression.js | 10 +- src/slang-nodes/YulFunctionDefinition.js | 34 ++--- src/slang-nodes/YulIfStatement.js | 10 +- src/slang-nodes/YulLiteral.js | 8 +- src/slang-nodes/YulParametersDeclaration.js | 8 +- src/slang-nodes/YulPath.js | 4 +- src/slang-nodes/YulPaths.js | 4 +- src/slang-nodes/YulReturnsDeclaration.js | 8 +- .../YulStackAssignmentStatement.js | 10 +- src/slang-nodes/YulStatement.js | 4 +- src/slang-nodes/YulStatements.js | 4 +- src/slang-nodes/YulSwitchCase.js | 4 +- src/slang-nodes/YulSwitchCases.js | 4 +- src/slang-nodes/YulSwitchStatement.js | 10 +- src/slang-nodes/YulValueCase.js | 6 +- .../YulVariableAssignmentStatement.js | 12 +- .../YulVariableDeclarationStatement.js | 8 +- .../YulVariableDeclarationValue.js | 10 +- 188 files changed, 705 insertions(+), 1040 deletions(-) diff --git a/src/slang-nodes/AdditiveExpression.js b/src/slang-nodes/AdditiveExpression.js index 33debc5bc..adfc8cdbc 100644 --- a/src/slang-nodes/AdditiveExpression.js +++ b/src/slang-nodes/AdditiveExpression.js @@ -26,18 +26,10 @@ export class AdditiveExpression extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - leftOperand: new Expression( - ast.leftOperand, - childrenOffsets.shift(), - options - ), + const fetch = (offsets) => ({ + leftOperand: new Expression(ast.leftOperand, offsets[0], options), operator: ast.operator.text, - rightOperand: new Expression( - ast.rightOperand, - childrenOffsets.shift(), - options - ) + rightOperand: new Expression(ast.rightOperand, offsets[1], options) }); this.initialize(ast, offset, fetch, postProcess); diff --git a/src/slang-nodes/AndExpression.js b/src/slang-nodes/AndExpression.js index 8f33bca10..51a575b2b 100644 --- a/src/slang-nodes/AndExpression.js +++ b/src/slang-nodes/AndExpression.js @@ -17,18 +17,10 @@ export class AndExpression extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - leftOperand: new Expression( - ast.leftOperand, - childrenOffsets.shift(), - options - ), + const fetch = (offsets) => ({ + leftOperand: new Expression(ast.leftOperand, offsets[0], options), operator: ast.operator.text, - rightOperand: new Expression( - ast.rightOperand, - childrenOffsets.shift(), - options - ) + rightOperand: new Expression(ast.rightOperand, offsets[1], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/ArgumentsDeclaration.js b/src/slang-nodes/ArgumentsDeclaration.js index 4069ec46f..f689de349 100644 --- a/src/slang-nodes/ArgumentsDeclaration.js +++ b/src/slang-nodes/ArgumentsDeclaration.js @@ -15,10 +15,10 @@ export class ArgumentsDeclaration extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ variant: new variants[ast.variant.cst.kind]( ast.variant, - childrenOffsets.shift(), + offsets[0], options ) }); diff --git a/src/slang-nodes/ArrayExpression.js b/src/slang-nodes/ArrayExpression.js index fbde98c9c..417282166 100644 --- a/src/slang-nodes/ArrayExpression.js +++ b/src/slang-nodes/ArrayExpression.js @@ -19,9 +19,9 @@ export class ArrayExpression extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ openBracket: ast.openBracket.text, - items: new ArrayValues(ast.items, childrenOffsets.shift(), options), + items: new ArrayValues(ast.items, offsets[0], options), closeBracket: ast.closeBracket.text }); diff --git a/src/slang-nodes/ArrayTypeName.js b/src/slang-nodes/ArrayTypeName.js index ed10d2ee1..db13a1a66 100644 --- a/src/slang-nodes/ArrayTypeName.js +++ b/src/slang-nodes/ArrayTypeName.js @@ -19,11 +19,11 @@ export class ArrayTypeName extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - operand: new TypeName(ast.operand, childrenOffsets.shift(), options), + const fetch = (offsets) => ({ + operand: new TypeName(ast.operand, offsets[0], options), openBracket: ast.openBracket.text, index: ast.index - ? new Expression(ast.index, childrenOffsets.shift(), options) + ? new Expression(ast.index, offsets[1], options) : undefined, closeBracket: ast.closeBracket.text }); diff --git a/src/slang-nodes/ArrayValues.js b/src/slang-nodes/ArrayValues.js index 66d074cb4..39869858e 100644 --- a/src/slang-nodes/ArrayValues.js +++ b/src/slang-nodes/ArrayValues.js @@ -15,9 +15,9 @@ export class ArrayValues extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => new Expression(item, childrenOffsets.shift(), options) + (item, index) => new Expression(item, offsets[index], options) ), separators: ast.separators.map((separator) => separator.text) }); diff --git a/src/slang-nodes/AssemblyFlags.js b/src/slang-nodes/AssemblyFlags.js index 6fc5b13ca..08b366e45 100644 --- a/src/slang-nodes/AssemblyFlags.js +++ b/src/slang-nodes/AssemblyFlags.js @@ -15,9 +15,9 @@ export class AssemblyFlags extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => new StringLiteral(item, childrenOffsets.shift(), options) + (item, index) => new StringLiteral(item, offsets[index], options) ), separators: ast.separators.map((separator) => separator.text) }); diff --git a/src/slang-nodes/AssemblyFlagsDeclaration.js b/src/slang-nodes/AssemblyFlagsDeclaration.js index e4aec3e5c..52c4fa876 100644 --- a/src/slang-nodes/AssemblyFlagsDeclaration.js +++ b/src/slang-nodes/AssemblyFlagsDeclaration.js @@ -16,9 +16,9 @@ export class AssemblyFlagsDeclaration extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ openParen: ast.openParen.text, - flags: new AssemblyFlags(ast.flags, childrenOffsets.shift(), options), + flags: new AssemblyFlags(ast.flags, offsets[0], options), closeParen: ast.closeParen.text }); diff --git a/src/slang-nodes/AssemblyStatement.js b/src/slang-nodes/AssemblyStatement.js index 307e2505e..6afb98f13 100644 --- a/src/slang-nodes/AssemblyStatement.js +++ b/src/slang-nodes/AssemblyStatement.js @@ -20,20 +20,20 @@ export class AssemblyStatement extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - assemblyKeyword: ast.assemblyKeyword.text, - label: ast.label - ? new StringLiteral(ast.label, childrenOffsets.shift(), options) - : undefined, - flags: ast.flags - ? new AssemblyFlagsDeclaration( - ast.flags, - childrenOffsets.shift(), - options - ) - : undefined, - body: new YulBlock(ast.body, childrenOffsets.shift(), options) - }); + const fetch = (offsets) => { + let i = -1; + const children = { + assemblyKeyword: ast.assemblyKeyword.text, + label: ast.label + ? new StringLiteral(ast.label, offsets[(i += 1)], options) + : undefined, + flags: ast.flags + ? new AssemblyFlagsDeclaration(ast.flags, offsets[(i += 1)], options) + : undefined, + body: new YulBlock(ast.body, offsets[(i += 1)], options) + }; + return children; + }; this.initialize(ast, offset, fetch); } diff --git a/src/slang-nodes/AssignmentExpression.js b/src/slang-nodes/AssignmentExpression.js index 9364e17a7..39db0b40f 100644 --- a/src/slang-nodes/AssignmentExpression.js +++ b/src/slang-nodes/AssignmentExpression.js @@ -20,18 +20,10 @@ export class AssignmentExpression extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - leftOperand: new Expression( - ast.leftOperand, - childrenOffsets.shift(), - options - ), + const fetch = (offsets) => ({ + leftOperand: new Expression(ast.leftOperand, offsets[0], options), operator: ast.operator.text, - rightOperand: new Expression( - ast.rightOperand, - childrenOffsets.shift(), - options - ) + rightOperand: new Expression(ast.rightOperand, offsets[1], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/BitwiseAndExpression.js b/src/slang-nodes/BitwiseAndExpression.js index 9f6e2488b..dcbbf0677 100644 --- a/src/slang-nodes/BitwiseAndExpression.js +++ b/src/slang-nodes/BitwiseAndExpression.js @@ -26,18 +26,10 @@ export class BitwiseAndExpression extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - leftOperand: new Expression( - ast.leftOperand, - childrenOffsets.shift(), - options - ), + const fetch = (offsets) => ({ + leftOperand: new Expression(ast.leftOperand, offsets[0], options), operator: ast.operator.text, - rightOperand: new Expression( - ast.rightOperand, - childrenOffsets.shift(), - options - ) + rightOperand: new Expression(ast.rightOperand, offsets[1], options) }); this.initialize(ast, offset, fetch, postProcess); diff --git a/src/slang-nodes/BitwiseOrExpression.js b/src/slang-nodes/BitwiseOrExpression.js index b444b941a..1af3219cb 100644 --- a/src/slang-nodes/BitwiseOrExpression.js +++ b/src/slang-nodes/BitwiseOrExpression.js @@ -36,18 +36,10 @@ export class BitwiseOrExpression extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - leftOperand: new Expression( - ast.leftOperand, - childrenOffsets.shift(), - options - ), + const fetch = (offsets) => ({ + leftOperand: new Expression(ast.leftOperand, offsets[0], options), operator: ast.operator.text, - rightOperand: new Expression( - ast.rightOperand, - childrenOffsets.shift(), - options - ) + rightOperand: new Expression(ast.rightOperand, offsets[1], options) }); this.initialize(ast, offset, fetch, postProcess); diff --git a/src/slang-nodes/BitwiseXorExpression.js b/src/slang-nodes/BitwiseXorExpression.js index e78469935..4a5a66660 100644 --- a/src/slang-nodes/BitwiseXorExpression.js +++ b/src/slang-nodes/BitwiseXorExpression.js @@ -26,18 +26,10 @@ export class BitwiseXorExpression extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - leftOperand: new Expression( - ast.leftOperand, - childrenOffsets.shift(), - options - ), + const fetch = (offsets) => ({ + leftOperand: new Expression(ast.leftOperand, offsets[0], options), operator: ast.operator.text, - rightOperand: new Expression( - ast.rightOperand, - childrenOffsets.shift(), - options - ) + rightOperand: new Expression(ast.rightOperand, offsets[1], options) }); this.initialize(ast, offset, fetch, postProcess); diff --git a/src/slang-nodes/Block.js b/src/slang-nodes/Block.js index 287cb3520..85c6ead67 100644 --- a/src/slang-nodes/Block.js +++ b/src/slang-nodes/Block.js @@ -16,13 +16,9 @@ export class Block extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ openBrace: ast.openBrace.text, - statements: new Statements( - ast.statements, - childrenOffsets.shift(), - options - ), + statements: new Statements(ast.statements, offsets[0], options), closeBrace: ast.closeBrace.text }); diff --git a/src/slang-nodes/CallOptions.js b/src/slang-nodes/CallOptions.js index f671fa8e8..1810db343 100644 --- a/src/slang-nodes/CallOptions.js +++ b/src/slang-nodes/CallOptions.js @@ -18,9 +18,9 @@ export class CallOptions extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => new NamedArgument(item, childrenOffsets.shift(), options) + (item, index) => new NamedArgument(item, offsets[index], options) ), separators: ast.separators.map((separator) => separator.text) }); diff --git a/src/slang-nodes/CallOptionsExpression.js b/src/slang-nodes/CallOptionsExpression.js index 8388ba8cf..69c9e9267 100644 --- a/src/slang-nodes/CallOptionsExpression.js +++ b/src/slang-nodes/CallOptionsExpression.js @@ -19,10 +19,10 @@ export class CallOptionsExpression extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - operand: new Expression(ast.operand, childrenOffsets.shift(), options), + const fetch = (offsets) => ({ + operand: new Expression(ast.operand, offsets[0], options), openBrace: ast.openBrace.text, - options: new CallOptions(ast.options, childrenOffsets.shift(), options), + options: new CallOptions(ast.options, offsets[1], options), closeBrace: ast.closeBrace.text }); diff --git a/src/slang-nodes/CatchClause.js b/src/slang-nodes/CatchClause.js index e062b2f77..f00d369d0 100644 --- a/src/slang-nodes/CatchClause.js +++ b/src/slang-nodes/CatchClause.js @@ -17,13 +17,17 @@ export class CatchClause extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - catchKeyword: ast.catchKeyword.text, - error: ast.error - ? new CatchClauseError(ast.error, childrenOffsets.shift(), options) - : undefined, - body: new Block(ast.body, childrenOffsets.shift(), options) - }); + const fetch = (offsets) => { + let i = -1; + const children = { + catchKeyword: ast.catchKeyword.text, + error: ast.error + ? new CatchClauseError(ast.error, offsets[(i += 1)], options) + : undefined, + body: new Block(ast.body, offsets[(i += 1)], options) + }; + return children; + }; this.initialize(ast, offset, fetch); } diff --git a/src/slang-nodes/CatchClauseError.js b/src/slang-nodes/CatchClauseError.js index 084867770..5f35dfe30 100644 --- a/src/slang-nodes/CatchClauseError.js +++ b/src/slang-nodes/CatchClauseError.js @@ -17,13 +17,9 @@ export class CatchClauseError extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ name: ast.name?.text, - parameters: new ParametersDeclaration( - ast.parameters, - childrenOffsets.shift(), - options - ) + parameters: new ParametersDeclaration(ast.parameters, offsets[0], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/CatchClauses.js b/src/slang-nodes/CatchClauses.js index 5e122ccb9..c965f67fc 100644 --- a/src/slang-nodes/CatchClauses.js +++ b/src/slang-nodes/CatchClauses.js @@ -15,9 +15,9 @@ export class CatchClauses extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => new CatchClause(item, childrenOffsets.shift(), options) + (item, index) => new CatchClause(item, offsets[index], options) ) }); diff --git a/src/slang-nodes/ComparisonExpression.js b/src/slang-nodes/ComparisonExpression.js index ff61a6c64..68bd84df5 100644 --- a/src/slang-nodes/ComparisonExpression.js +++ b/src/slang-nodes/ComparisonExpression.js @@ -17,18 +17,10 @@ export class ComparisonExpression extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - leftOperand: new Expression( - ast.leftOperand, - childrenOffsets.shift(), - options - ), + const fetch = (offsets) => ({ + leftOperand: new Expression(ast.leftOperand, offsets[0], options), operator: ast.operator.text, - rightOperand: new Expression( - ast.rightOperand, - childrenOffsets.shift(), - options - ) + rightOperand: new Expression(ast.rightOperand, offsets[1], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/ConditionalExpression.js b/src/slang-nodes/ConditionalExpression.js index ff63ea0cd..9fcf78669 100644 --- a/src/slang-nodes/ConditionalExpression.js +++ b/src/slang-nodes/ConditionalExpression.js @@ -125,20 +125,12 @@ export class ConditionalExpression extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - operand: new Expression(ast.operand, childrenOffsets.shift(), options), + const fetch = (offsets) => ({ + operand: new Expression(ast.operand, offsets[0], options), questionMark: ast.questionMark.text, - trueExpression: new Expression( - ast.trueExpression, - childrenOffsets.shift(), - options - ), + trueExpression: new Expression(ast.trueExpression, offsets[1], options), colon: ast.colon.text, - falseExpression: new Expression( - ast.falseExpression, - childrenOffsets.shift(), - options - ) + falseExpression: new Expression(ast.falseExpression, offsets[2], options) }); this.initialize( diff --git a/src/slang-nodes/ConstantDefinition.js b/src/slang-nodes/ConstantDefinition.js index 72410d01b..39a1012e1 100644 --- a/src/slang-nodes/ConstantDefinition.js +++ b/src/slang-nodes/ConstantDefinition.js @@ -23,12 +23,12 @@ export class ConstantDefinition extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - typeName: new TypeName(ast.typeName, childrenOffsets.shift(), options), + const fetch = (offsets) => ({ + typeName: new TypeName(ast.typeName, offsets[0], options), constantKeyword: ast.constantKeyword.text, name: ast.name.text, equal: ast.equal.text, - value: new Expression(ast.value, childrenOffsets.shift(), options), + value: new Expression(ast.value, offsets[1], options), semicolon: ast.semicolon.text }); diff --git a/src/slang-nodes/ConstructorAttribute.js b/src/slang-nodes/ConstructorAttribute.js index d0e66a1ed..0d22b32bf 100644 --- a/src/slang-nodes/ConstructorAttribute.js +++ b/src/slang-nodes/ConstructorAttribute.js @@ -12,15 +12,11 @@ export class ConstructorAttribute extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text - : new ModifierInvocation( - ast.variant, - childrenOffsets.shift(), - options - ) + : new ModifierInvocation(ast.variant, offsets[0], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/ConstructorAttributes.js b/src/slang-nodes/ConstructorAttributes.js index 55ff380c8..5c6ce44ea 100644 --- a/src/slang-nodes/ConstructorAttributes.js +++ b/src/slang-nodes/ConstructorAttributes.js @@ -16,10 +16,9 @@ export class ConstructorAttributes extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => - new ConstructorAttribute(item, childrenOffsets.shift(), options) + (item, index) => new ConstructorAttribute(item, offsets[index], options) ) }); diff --git a/src/slang-nodes/ConstructorDefinition.js b/src/slang-nodes/ConstructorDefinition.js index e5a33ec06..eada91669 100644 --- a/src/slang-nodes/ConstructorDefinition.js +++ b/src/slang-nodes/ConstructorDefinition.js @@ -21,19 +21,19 @@ export class ConstructorDefinition extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ constructorKeyword: ast.constructorKeyword.text, parameters: new ParametersDeclaration( ast.parameters, - childrenOffsets.shift(), + offsets[0], options ), attributes: new ConstructorAttributes( ast.attributes, - childrenOffsets.shift(), + offsets[1], options ), - body: new Block(ast.body, childrenOffsets.shift(), options) + body: new Block(ast.body, offsets[2], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/ContractDefinition.js b/src/slang-nodes/ContractDefinition.js index 88884fc41..826089d88 100644 --- a/src/slang-nodes/ContractDefinition.js +++ b/src/slang-nodes/ContractDefinition.js @@ -30,25 +30,25 @@ export class ContractDefinition extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - abstractKeyword: ast.abstractKeyword?.text, - contractKeyword: ast.contractKeyword.text, - name: ast.name.text, - inheritance: ast.inheritance - ? new InheritanceSpecifier( - ast.inheritance, - childrenOffsets.shift(), - options - ) - : undefined, - openBrace: ast.openBrace.text, - members: new ContractMembers( - ast.members, - childrenOffsets.shift(), - options - ), - closeBrace: ast.closeBrace.text - }); + const fetch = (offsets) => { + let i = -1; + const children = { + abstractKeyword: ast.abstractKeyword?.text, + contractKeyword: ast.contractKeyword.text, + name: ast.name.text, + inheritance: ast.inheritance + ? new InheritanceSpecifier( + ast.inheritance, + offsets[(i += 1)], + options + ) + : undefined, + openBrace: ast.openBrace.text, + members: new ContractMembers(ast.members, offsets[(i += 1)], options), + closeBrace: ast.closeBrace.text + }; + return children; + }; this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/ContractMember.js b/src/slang-nodes/ContractMember.js index 4be15338b..156bb579a 100644 --- a/src/slang-nodes/ContractMember.js +++ b/src/slang-nodes/ContractMember.js @@ -40,10 +40,10 @@ export class ContractMember extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ variant: new variants[ast.variant.cst.kind]( ast.variant, - childrenOffsets.shift(), + offsets[0], options ) }); diff --git a/src/slang-nodes/ContractMembers.js b/src/slang-nodes/ContractMembers.js index 68a067371..84bee99a1 100644 --- a/src/slang-nodes/ContractMembers.js +++ b/src/slang-nodes/ContractMembers.js @@ -18,9 +18,9 @@ export class ContractMembers extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => new ContractMember(item, childrenOffsets.shift(), options) + (item, index) => new ContractMember(item, offsets[index], options) ) }); diff --git a/src/slang-nodes/DecimalNumberExpression.js b/src/slang-nodes/DecimalNumberExpression.js index e0966de9f..3ab9ba52d 100644 --- a/src/slang-nodes/DecimalNumberExpression.js +++ b/src/slang-nodes/DecimalNumberExpression.js @@ -14,11 +14,9 @@ export class DecimalNumberExpression extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ literal: ast.literal.text, - unit: ast.unit - ? new NumberUnit(ast.unit, childrenOffsets.shift(), options) - : undefined + unit: ast.unit ? new NumberUnit(ast.unit, offsets[0], options) : undefined }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/DoWhileStatement.js b/src/slang-nodes/DoWhileStatement.js index 3593f5ef5..7ab04ea25 100644 --- a/src/slang-nodes/DoWhileStatement.js +++ b/src/slang-nodes/DoWhileStatement.js @@ -29,16 +29,12 @@ export class DoWhileStatement extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ doKeyword: ast.doKeyword.text, - body: new Statement(ast.body, childrenOffsets.shift(), options), + body: new Statement(ast.body, offsets[0], options), whileKeyword: ast.whileKeyword.text, openParen: ast.openParen.text, - condition: new Expression( - ast.condition, - childrenOffsets.shift(), - options - ), + condition: new Expression(ast.condition, offsets[1], options), closeParen: ast.closeParen.text, semicolon: ast.semicolon.text }); diff --git a/src/slang-nodes/ElementaryType.js b/src/slang-nodes/ElementaryType.js index ce958effc..4a1b2fbd0 100644 --- a/src/slang-nodes/ElementaryType.js +++ b/src/slang-nodes/ElementaryType.js @@ -12,11 +12,11 @@ export class ElementaryType extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text - : new AddressType(ast.variant, childrenOffsets.shift(), options) + : new AddressType(ast.variant, offsets[0], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/ElseBranch.js b/src/slang-nodes/ElseBranch.js index 59d2ae8dc..e36f0f2c4 100644 --- a/src/slang-nodes/ElseBranch.js +++ b/src/slang-nodes/ElseBranch.js @@ -20,9 +20,9 @@ export class ElseBranch extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ elseKeyword: ast.elseKeyword.text, - body: new Statement(ast.body, childrenOffsets.shift(), options) + body: new Statement(ast.body, offsets[0], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/EmitStatement.js b/src/slang-nodes/EmitStatement.js index 68e13f1ad..7c0310acd 100644 --- a/src/slang-nodes/EmitStatement.js +++ b/src/slang-nodes/EmitStatement.js @@ -19,14 +19,10 @@ export class EmitStatement extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ emitKeyword: ast.emitKeyword.text, - event: new IdentifierPath(ast.event, childrenOffsets.shift(), options), - arguments: new ArgumentsDeclaration( - ast.arguments, - childrenOffsets.shift(), - options - ), + event: new IdentifierPath(ast.event, offsets[0], options), + arguments: new ArgumentsDeclaration(ast.arguments, offsets[1], options), semicolon: ast.semicolon.text }); diff --git a/src/slang-nodes/EnumDefinition.js b/src/slang-nodes/EnumDefinition.js index 28b1092a5..ec94628ee 100644 --- a/src/slang-nodes/EnumDefinition.js +++ b/src/slang-nodes/EnumDefinition.js @@ -20,11 +20,11 @@ export class EnumDefinition extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ enumKeyword: ast.enumKeyword.text, name: ast.name.text, openBrace: ast.openBrace.text, - members: new EnumMembers(ast.members, childrenOffsets.shift(), options), + members: new EnumMembers(ast.members, offsets[0], options), closeBrace: ast.closeBrace.text }); diff --git a/src/slang-nodes/EqualityExpression.js b/src/slang-nodes/EqualityExpression.js index 30a2bf9c1..ed11e76a6 100644 --- a/src/slang-nodes/EqualityExpression.js +++ b/src/slang-nodes/EqualityExpression.js @@ -17,18 +17,10 @@ export class EqualityExpression extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - leftOperand: new Expression( - ast.leftOperand, - childrenOffsets.shift(), - options - ), + const fetch = (offsets) => ({ + leftOperand: new Expression(ast.leftOperand, offsets[0], options), operator: ast.operator.text, - rightOperand: new Expression( - ast.rightOperand, - childrenOffsets.shift(), - options - ) + rightOperand: new Expression(ast.rightOperand, offsets[1], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/ErrorDefinition.js b/src/slang-nodes/ErrorDefinition.js index 6fc8c98c2..ff1015f58 100644 --- a/src/slang-nodes/ErrorDefinition.js +++ b/src/slang-nodes/ErrorDefinition.js @@ -18,14 +18,10 @@ export class ErrorDefinition extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ errorKeyword: ast.errorKeyword.text, name: ast.name.text, - members: new ErrorParametersDeclaration( - ast.members, - childrenOffsets.shift(), - options - ), + members: new ErrorParametersDeclaration(ast.members, offsets[0], options), semicolon: ast.semicolon.text }); diff --git a/src/slang-nodes/ErrorParameter.js b/src/slang-nodes/ErrorParameter.js index 12655e716..5121e9b8e 100644 --- a/src/slang-nodes/ErrorParameter.js +++ b/src/slang-nodes/ErrorParameter.js @@ -14,8 +14,8 @@ export class ErrorParameter extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - typeName: new TypeName(ast.typeName, childrenOffsets.shift(), options), + const fetch = (offsets) => ({ + typeName: new TypeName(ast.typeName, offsets[0], options), name: ast.name?.text }); diff --git a/src/slang-nodes/ErrorParameters.js b/src/slang-nodes/ErrorParameters.js index 249ec978e..d68208d73 100644 --- a/src/slang-nodes/ErrorParameters.js +++ b/src/slang-nodes/ErrorParameters.js @@ -15,9 +15,9 @@ export class ErrorParameters extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => new ErrorParameter(item, childrenOffsets.shift(), options) + (item, index) => new ErrorParameter(item, offsets[index], options) ), separators: ast.separators.map((separator) => separator.text) }); diff --git a/src/slang-nodes/ErrorParametersDeclaration.js b/src/slang-nodes/ErrorParametersDeclaration.js index 85722e2e4..e334e4417 100644 --- a/src/slang-nodes/ErrorParametersDeclaration.js +++ b/src/slang-nodes/ErrorParametersDeclaration.js @@ -16,13 +16,9 @@ export class ErrorParametersDeclaration extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ openParen: ast.openParen.text, - parameters: new ErrorParameters( - ast.parameters, - childrenOffsets.shift(), - options - ), + parameters: new ErrorParameters(ast.parameters, offsets[0], options), closeParen: ast.closeParen.text }); diff --git a/src/slang-nodes/EventDefinition.js b/src/slang-nodes/EventDefinition.js index ae85a1b41..217551aa1 100644 --- a/src/slang-nodes/EventDefinition.js +++ b/src/slang-nodes/EventDefinition.js @@ -20,12 +20,12 @@ export class EventDefinition extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ eventKeyword: ast.eventKeyword.text, name: ast.name.text, parameters: new EventParametersDeclaration( ast.parameters, - childrenOffsets.shift(), + offsets[0], options ), anonymousKeyword: ast.anonymousKeyword?.text, diff --git a/src/slang-nodes/EventParameter.js b/src/slang-nodes/EventParameter.js index 36b679f5e..22e2a70ca 100644 --- a/src/slang-nodes/EventParameter.js +++ b/src/slang-nodes/EventParameter.js @@ -16,8 +16,8 @@ export class EventParameter extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - typeName: new TypeName(ast.typeName, childrenOffsets.shift(), options), + const fetch = (offsets) => ({ + typeName: new TypeName(ast.typeName, offsets[0], options), indexedKeyword: ast.indexedKeyword?.text, name: ast.name?.text }); diff --git a/src/slang-nodes/EventParameters.js b/src/slang-nodes/EventParameters.js index 34602fd45..dbe98426b 100644 --- a/src/slang-nodes/EventParameters.js +++ b/src/slang-nodes/EventParameters.js @@ -15,9 +15,9 @@ export class EventParameters extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => new EventParameter(item, childrenOffsets.shift(), options) + (item, index) => new EventParameter(item, offsets[index], options) ), separators: ast.separators.map((separator) => separator.text) }); diff --git a/src/slang-nodes/EventParametersDeclaration.js b/src/slang-nodes/EventParametersDeclaration.js index c720ef946..bd3440edc 100644 --- a/src/slang-nodes/EventParametersDeclaration.js +++ b/src/slang-nodes/EventParametersDeclaration.js @@ -16,13 +16,9 @@ export class EventParametersDeclaration extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ openParen: ast.openParen.text, - parameters: new EventParameters( - ast.parameters, - childrenOffsets.shift(), - options - ), + parameters: new EventParameters(ast.parameters, offsets[0], options), closeParen: ast.closeParen.text }); diff --git a/src/slang-nodes/ExperimentalFeature.js b/src/slang-nodes/ExperimentalFeature.js index c4b7e0fa0..65aa84985 100644 --- a/src/slang-nodes/ExperimentalFeature.js +++ b/src/slang-nodes/ExperimentalFeature.js @@ -12,11 +12,11 @@ export class ExperimentalFeature extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text - : new StringLiteral(ast.variant, childrenOffsets.shift(), options) + : new StringLiteral(ast.variant, offsets[0], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/ExperimentalPragma.js b/src/slang-nodes/ExperimentalPragma.js index 3ec9aae36..c05e826a2 100644 --- a/src/slang-nodes/ExperimentalPragma.js +++ b/src/slang-nodes/ExperimentalPragma.js @@ -14,13 +14,9 @@ export class ExperimentalPragma extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ experimentalKeyword: ast.experimentalKeyword.text, - feature: new ExperimentalFeature( - ast.feature, - childrenOffsets.shift(), - options - ) + feature: new ExperimentalFeature(ast.feature, offsets[0], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/ExponentiationExpression.js b/src/slang-nodes/ExponentiationExpression.js index c55c69e27..98c41dc41 100644 --- a/src/slang-nodes/ExponentiationExpression.js +++ b/src/slang-nodes/ExponentiationExpression.js @@ -33,87 +33,77 @@ export class ExponentiationExpression extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - leftOperand: new Expression( - ast.leftOperand, - childrenOffsets.shift(), - options - ), + const fetch = (offsets) => ({ + leftOperand: new Expression(ast.leftOperand, offsets[0], options), operator: ast.operator.text, - rightOperand: new Expression( - ast.rightOperand, - childrenOffsets.shift(), - options - ) + rightOperand: new Expression(ast.rightOperand, offsets[1], options) }); this.initialize(ast, offset, fetch); - if (offset) { - const compiler = coerce(options.compiler); - if (compiler) { - if (satisfies(compiler, '>=0.8.0')) { - this.rightOperand = tryToHug(this.rightOperand); - } else { - // Currently the parser considers exponentiation as having left - // association from 0.6.0. - // in reality solidity fixed this from 0.8.0. - // TODO: remove this once the parser has fixed this. - // https://github.com/NomicFoundation/slang/issues/1031 - if (this.rightOperand.variant.kind === 'ExponentiationExpression') { - const leftLoc = { - leadingOffset: this.leftOperand.loc.leadingOffset, - start: this.leftOperand.loc.start, - trailingOffset: - this.rightOperand.variant.leftOperand.loc.trailingOffset, - end: this.rightOperand.variant.leftOperand.loc.end - }; - this.leftOperand = Object.create(Expression.prototype, { - loc: { value: { ...leftLoc } }, - variant: { - value: Object.create(TupleExpression.prototype, { - loc: { value: { ...leftLoc } }, - openParen: { value: '(' }, - items: { - value: Object.create(TupleValues.prototype, { - loc: { value: { ...leftLoc } }, - items: { - value: [ - Object.create(TupleValue.prototype, { - loc: { value: { ...leftLoc } }, - expression: { - value: Object.create(Expression.prototype, { - loc: { value: { ...leftLoc } }, - variant: { - value: Object.create( - ExponentiationExpression.prototype, - { - loc: { value: { ...leftLoc } }, - leftOperand: { value: this.leftOperand }, - operator: { value: '**' }, - rightOperand: { - value: - this.rightOperand.variant.leftOperand - } + const compiler = coerce(options.compiler); + if (compiler) { + if (satisfies(compiler, '>=0.8.0')) { + this.rightOperand = tryToHug(this.rightOperand); + } else { + // Currently the parser considers exponentiation as having left + // association from 0.6.0. + // in reality solidity fixed this from 0.8.0. + // TODO: remove this once the parser has fixed this. + // https://github.com/NomicFoundation/slang/issues/1031 + if (this.rightOperand.variant.kind === 'ExponentiationExpression') { + const leftLoc = { + leadingOffset: this.leftOperand.loc.leadingOffset, + start: this.leftOperand.loc.start, + trailingOffset: + this.rightOperand.variant.leftOperand.loc.trailingOffset, + end: this.rightOperand.variant.leftOperand.loc.end + }; + this.leftOperand = Object.create(Expression.prototype, { + loc: { value: { ...leftLoc } }, + variant: { + value: Object.create(TupleExpression.prototype, { + loc: { value: { ...leftLoc } }, + openParen: { value: '(' }, + items: { + value: Object.create(TupleValues.prototype, { + loc: { value: { ...leftLoc } }, + items: { + value: [ + Object.create(TupleValue.prototype, { + loc: { value: { ...leftLoc } }, + expression: { + value: Object.create(Expression.prototype, { + loc: { value: { ...leftLoc } }, + variant: { + value: Object.create( + ExponentiationExpression.prototype, + { + loc: { value: { ...leftLoc } }, + leftOperand: { value: this.leftOperand }, + operator: { value: '**' }, + rightOperand: { + value: + this.rightOperand.variant.leftOperand } - ) - } - }) - } - }) - ] - }, - separators: { value: [] } - }) - }, - closeParen: { value: ')' } - }) - } - }); - this.rightOperand = this.rightOperand.variant.rightOperand; - } - this.leftOperand = tryToHug(this.leftOperand); + } + ) + } + }) + } + }) + ] + }, + separators: { value: [] } + }) + }, + closeParen: { value: ')' } + }) + } + }); + this.rightOperand = this.rightOperand.variant.rightOperand; } + this.leftOperand = tryToHug(this.leftOperand); } } } diff --git a/src/slang-nodes/Expression.js b/src/slang-nodes/Expression.js index d50ae8a31..4cf69961e 100644 --- a/src/slang-nodes/Expression.js +++ b/src/slang-nodes/Expression.js @@ -68,15 +68,11 @@ export class Expression extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text - : new variants[ast.variant.cst.kind]( - ast.variant, - childrenOffsets.shift(), - options - ) + : new variants[ast.variant.cst.kind](ast.variant, offsets[0], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/ExpressionStatement.js b/src/slang-nodes/ExpressionStatement.js index 950fe4265..b50e3eeb3 100644 --- a/src/slang-nodes/ExpressionStatement.js +++ b/src/slang-nodes/ExpressionStatement.js @@ -14,12 +14,8 @@ export class ExpressionStatement extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - expression: new Expression( - ast.expression, - childrenOffsets.shift(), - options - ), + const fetch = (offsets) => ({ + expression: new Expression(ast.expression, offsets[0], options), semicolon: ast.semicolon.text }); diff --git a/src/slang-nodes/FallbackFunctionAttribute.js b/src/slang-nodes/FallbackFunctionAttribute.js index 14ab0490c..fd4cdd72c 100644 --- a/src/slang-nodes/FallbackFunctionAttribute.js +++ b/src/slang-nodes/FallbackFunctionAttribute.js @@ -15,15 +15,11 @@ export class FallbackFunctionAttribute extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text - : new variants[ast.variant.cst.kind]( - ast.variant, - childrenOffsets.shift(), - options - ) + : new variants[ast.variant.cst.kind](ast.variant, offsets[0], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/FallbackFunctionAttributes.js b/src/slang-nodes/FallbackFunctionAttributes.js index 74c3e5a70..d28f4505a 100644 --- a/src/slang-nodes/FallbackFunctionAttributes.js +++ b/src/slang-nodes/FallbackFunctionAttributes.js @@ -16,10 +16,10 @@ export class FallbackFunctionAttributes extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => - new FallbackFunctionAttribute(item, childrenOffsets.shift(), options) + (item, index) => + new FallbackFunctionAttribute(item, offsets[index], options) ) }); diff --git a/src/slang-nodes/FallbackFunctionDefinition.js b/src/slang-nodes/FallbackFunctionDefinition.js index d3626018a..873af970d 100644 --- a/src/slang-nodes/FallbackFunctionDefinition.js +++ b/src/slang-nodes/FallbackFunctionDefinition.js @@ -24,23 +24,27 @@ export class FallbackFunctionDefinition extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - fallbackKeyword: ast.fallbackKeyword.text, - parameters: new ParametersDeclaration( - ast.parameters, - childrenOffsets.shift(), - options - ), - attributes: new FallbackFunctionAttributes( - ast.attributes, - childrenOffsets.shift(), - options - ), - returns: ast.returns - ? new ReturnsDeclaration(ast.returns, childrenOffsets.shift(), options) - : undefined, - body: new FunctionBody(ast.body, childrenOffsets.shift(), options) - }); + const fetch = (offsets) => { + let i = 1; + const children = { + fallbackKeyword: ast.fallbackKeyword.text, + parameters: new ParametersDeclaration( + ast.parameters, + offsets[0], + options + ), + attributes: new FallbackFunctionAttributes( + ast.attributes, + offsets[1], + options + ), + returns: ast.returns + ? new ReturnsDeclaration(ast.returns, offsets[(i += 1)], options) + : undefined, + body: new FunctionBody(ast.body, offsets[(i += 1)], options) + }; + return children; + }; this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/ForStatement.js b/src/slang-nodes/ForStatement.js index 37d189fc6..67199451b 100644 --- a/src/slang-nodes/ForStatement.js +++ b/src/slang-nodes/ForStatement.js @@ -31,25 +31,29 @@ export class ForStatement extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - forKeyword: ast.forKeyword.text, - openParen: ast.openParen.text, - initialization: new ForStatementInitialization( - ast.initialization, - childrenOffsets.shift(), - options - ), - condition: new ForStatementCondition( - ast.condition, - childrenOffsets.shift(), - options - ), - iterator: ast.iterator - ? new Expression(ast.iterator, childrenOffsets.shift(), options) - : undefined, - closeParen: ast.closeParen.text, - body: new Statement(ast.body, childrenOffsets.shift(), options) - }); + const fetch = (offsets) => { + let i = 1; + const children = { + forKeyword: ast.forKeyword.text, + openParen: ast.openParen.text, + initialization: new ForStatementInitialization( + ast.initialization, + offsets[0], + options + ), + condition: new ForStatementCondition( + ast.condition, + offsets[1], + options + ), + iterator: ast.iterator + ? new Expression(ast.iterator, offsets[(i += 1)], options) + : undefined, + closeParen: ast.closeParen.text, + body: new Statement(ast.body, offsets[(i += 1)], options) + }; + return children; + }; this.initialize(ast, offset, fetch); } diff --git a/src/slang-nodes/ForStatementCondition.js b/src/slang-nodes/ForStatementCondition.js index 1df9ce7e1..1cd779b58 100644 --- a/src/slang-nodes/ForStatementCondition.js +++ b/src/slang-nodes/ForStatementCondition.js @@ -12,15 +12,11 @@ export class ForStatementCondition extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text - : new ExpressionStatement( - ast.variant, - childrenOffsets.shift(), - options - ) + : new ExpressionStatement(ast.variant, offsets[0], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/ForStatementInitialization.js b/src/slang-nodes/ForStatementInitialization.js index 7db2281b1..fe1749a07 100644 --- a/src/slang-nodes/ForStatementInitialization.js +++ b/src/slang-nodes/ForStatementInitialization.js @@ -20,15 +20,11 @@ export class ForStatementInitialization extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text - : new variants[ast.variant.cst.kind]( - ast.variant, - childrenOffsets.shift(), - options - ) + : new variants[ast.variant.cst.kind](ast.variant, offsets[0], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/FunctionAttribute.js b/src/slang-nodes/FunctionAttribute.js index a98e75043..b84703086 100644 --- a/src/slang-nodes/FunctionAttribute.js +++ b/src/slang-nodes/FunctionAttribute.js @@ -15,15 +15,11 @@ export class FunctionAttribute extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text - : new variants[ast.variant.cst.kind]( - ast.variant, - childrenOffsets.shift(), - options - ) + : new variants[ast.variant.cst.kind](ast.variant, offsets[0], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/FunctionAttributes.js b/src/slang-nodes/FunctionAttributes.js index 912285e93..891e1d212 100644 --- a/src/slang-nodes/FunctionAttributes.js +++ b/src/slang-nodes/FunctionAttributes.js @@ -16,9 +16,9 @@ export class FunctionAttributes extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => new FunctionAttribute(item, childrenOffsets.shift(), options) + (item, index) => new FunctionAttribute(item, offsets[index], options) ) }); diff --git a/src/slang-nodes/FunctionBody.js b/src/slang-nodes/FunctionBody.js index d09f45ae4..84c6b7138 100644 --- a/src/slang-nodes/FunctionBody.js +++ b/src/slang-nodes/FunctionBody.js @@ -12,11 +12,11 @@ export class FunctionBody extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text - : new Block(ast.variant, childrenOffsets.shift(), options) + : new Block(ast.variant, offsets[0], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/FunctionCallExpression.js b/src/slang-nodes/FunctionCallExpression.js index b3402679c..c8170194d 100644 --- a/src/slang-nodes/FunctionCallExpression.js +++ b/src/slang-nodes/FunctionCallExpression.js @@ -19,13 +19,9 @@ export class FunctionCallExpression extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - operand: new Expression(ast.operand, childrenOffsets.shift(), options), - arguments: new ArgumentsDeclaration( - ast.arguments, - childrenOffsets.shift(), - options - ) + const fetch = (offsets) => ({ + operand: new Expression(ast.operand, offsets[0], options), + arguments: new ArgumentsDeclaration(ast.arguments, offsets[1], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/FunctionDefinition.js b/src/slang-nodes/FunctionDefinition.js index fda12c7ed..e79a8e408 100644 --- a/src/slang-nodes/FunctionDefinition.js +++ b/src/slang-nodes/FunctionDefinition.js @@ -29,24 +29,24 @@ export class FunctionDefinition extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - functionKeyword: ast.functionKeyword.text, - name: new FunctionName(ast.name, childrenOffsets.shift(), options), - parameters: new ParametersDeclaration( - ast.parameters, - childrenOffsets.shift(), - options - ), - attributes: new FunctionAttributes( - ast.attributes, - childrenOffsets.shift(), - options - ), - returns: ast.returns - ? new ReturnsDeclaration(ast.returns, childrenOffsets.shift(), options) - : undefined, - body: new FunctionBody(ast.body, childrenOffsets.shift(), options) - }); + const fetch = (offsets) => { + let i = 2; + const children = { + functionKeyword: ast.functionKeyword.text, + name: new FunctionName(ast.name, offsets[0], options), + parameters: new ParametersDeclaration( + ast.parameters, + offsets[1], + options + ), + attributes: new FunctionAttributes(ast.attributes, offsets[2], options), + returns: ast.returns + ? new ReturnsDeclaration(ast.returns, offsets[(i += 1)], options) + : undefined, + body: new FunctionBody(ast.body, offsets[(i += 1)], options) + }; + return children; + }; this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/FunctionType.js b/src/slang-nodes/FunctionType.js index afa3ae47d..f6e2841d8 100644 --- a/src/slang-nodes/FunctionType.js +++ b/src/slang-nodes/FunctionType.js @@ -21,20 +21,20 @@ export class FunctionType extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ functionKeyword: ast.functionKeyword.text, parameters: new ParametersDeclaration( ast.parameters, - childrenOffsets.shift(), + offsets[0], options ), attributes: new FunctionTypeAttributes( ast.attributes, - childrenOffsets.shift(), + offsets[1], options ), returns: ast.returns - ? new ReturnsDeclaration(ast.returns, childrenOffsets.shift(), options) + ? new ReturnsDeclaration(ast.returns, offsets[2], options) : undefined }); diff --git a/src/slang-nodes/FunctionTypeAttributes.js b/src/slang-nodes/FunctionTypeAttributes.js index dec445ebf..970e88bc2 100644 --- a/src/slang-nodes/FunctionTypeAttributes.js +++ b/src/slang-nodes/FunctionTypeAttributes.js @@ -16,10 +16,10 @@ export class FunctionTypeAttributes extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => - new FunctionTypeAttribute(item, childrenOffsets.shift(), options) + (item, index) => + new FunctionTypeAttribute(item, offsets[index], options) ) }); diff --git a/src/slang-nodes/HexNumberExpression.js b/src/slang-nodes/HexNumberExpression.js index 580da158a..91a951e3e 100644 --- a/src/slang-nodes/HexNumberExpression.js +++ b/src/slang-nodes/HexNumberExpression.js @@ -14,11 +14,9 @@ export class HexNumberExpression extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ literal: ast.literal.text, - unit: ast.unit - ? new NumberUnit(ast.unit, childrenOffsets.shift(), options) - : undefined + unit: ast.unit ? new NumberUnit(ast.unit, offsets[0], options) : undefined }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/HexStringLiterals.js b/src/slang-nodes/HexStringLiterals.js index 2a3e63e99..7960b26a7 100644 --- a/src/slang-nodes/HexStringLiterals.js +++ b/src/slang-nodes/HexStringLiterals.js @@ -15,9 +15,9 @@ export class HexStringLiterals extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => new HexStringLiteral(item, childrenOffsets.shift(), options) + (item, index) => new HexStringLiteral(item, offsets[index], options) ) }); diff --git a/src/slang-nodes/IfStatement.js b/src/slang-nodes/IfStatement.js index c5b7ea3d4..c3936276c 100644 --- a/src/slang-nodes/IfStatement.js +++ b/src/slang-nodes/IfStatement.js @@ -28,18 +28,14 @@ export class IfStatement extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ ifKeyword: ast.ifKeyword.text, openParen: ast.openParen.text, - condition: new Expression( - ast.condition, - childrenOffsets.shift(), - options - ), + condition: new Expression(ast.condition, offsets[0], options), closeParen: ast.closeParen.text, - body: new Statement(ast.body, childrenOffsets.shift(), options), + body: new Statement(ast.body, offsets[1], options), elseBranch: ast.elseBranch - ? new ElseBranch(ast.elseBranch, childrenOffsets.shift(), options) + ? new ElseBranch(ast.elseBranch, offsets[2], options) : undefined }); diff --git a/src/slang-nodes/ImportClause.js b/src/slang-nodes/ImportClause.js index b722afb8b..9f7d87b10 100644 --- a/src/slang-nodes/ImportClause.js +++ b/src/slang-nodes/ImportClause.js @@ -16,10 +16,10 @@ export class ImportClause extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ variant: new variants[ast.variant.cst.kind]( ast.variant, - childrenOffsets.shift(), + offsets[0], options ) }); diff --git a/src/slang-nodes/ImportDeconstruction.js b/src/slang-nodes/ImportDeconstruction.js index 1634ff1ec..0f51a6328 100644 --- a/src/slang-nodes/ImportDeconstruction.js +++ b/src/slang-nodes/ImportDeconstruction.js @@ -21,16 +21,16 @@ export class ImportDeconstruction extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ openBrace: ast.openBrace.text, symbols: new ImportDeconstructionSymbols( ast.symbols, - childrenOffsets.shift(), + offsets[0], options ), closeBrace: ast.closeBrace.text, fromKeyword: ast.fromKeyword.text, - path: new StringLiteral(ast.path, childrenOffsets.shift(), options) + path: new StringLiteral(ast.path, offsets[1], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/ImportDeconstructionSymbol.js b/src/slang-nodes/ImportDeconstructionSymbol.js index 7f6f66668..99ce8eac8 100644 --- a/src/slang-nodes/ImportDeconstructionSymbol.js +++ b/src/slang-nodes/ImportDeconstructionSymbol.js @@ -14,10 +14,10 @@ export class ImportDeconstructionSymbol extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ name: ast.name.text, alias: ast.alias - ? new ImportAlias(ast.alias, childrenOffsets.shift(), options) + ? new ImportAlias(ast.alias, offsets[0], options) : undefined }); diff --git a/src/slang-nodes/ImportDeconstructionSymbols.js b/src/slang-nodes/ImportDeconstructionSymbols.js index 16ca65570..d3769cf70 100644 --- a/src/slang-nodes/ImportDeconstructionSymbols.js +++ b/src/slang-nodes/ImportDeconstructionSymbols.js @@ -20,10 +20,10 @@ export class ImportDeconstructionSymbols extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => - new ImportDeconstructionSymbol(item, childrenOffsets.shift(), options) + (item, index) => + new ImportDeconstructionSymbol(item, offsets[index], options) ), separators: ast.separators.map((separator) => separator.text) }); diff --git a/src/slang-nodes/ImportDirective.js b/src/slang-nodes/ImportDirective.js index ca606aaaf..6f2dd5f9e 100644 --- a/src/slang-nodes/ImportDirective.js +++ b/src/slang-nodes/ImportDirective.js @@ -16,9 +16,9 @@ export class ImportDirective extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ importKeyword: ast.importKeyword.text, - clause: new ImportClause(ast.clause, childrenOffsets.shift(), options), + clause: new ImportClause(ast.clause, offsets[0], options), semicolon: ast.semicolon.text }); diff --git a/src/slang-nodes/IndexAccessEnd.js b/src/slang-nodes/IndexAccessEnd.js index dd0ed128e..fecebf58e 100644 --- a/src/slang-nodes/IndexAccessEnd.js +++ b/src/slang-nodes/IndexAccessEnd.js @@ -14,11 +14,9 @@ export class IndexAccessEnd extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ colon: ast.colon.text, - end: ast.end - ? new Expression(ast.end, childrenOffsets.shift(), options) - : undefined + end: ast.end ? new Expression(ast.end, offsets[0], options) : undefined }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/IndexAccessExpression.js b/src/slang-nodes/IndexAccessExpression.js index 699f17594..a0f5b2783 100644 --- a/src/slang-nodes/IndexAccessExpression.js +++ b/src/slang-nodes/IndexAccessExpression.js @@ -25,17 +25,21 @@ export class IndexAccessExpression extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - operand: new Expression(ast.operand, childrenOffsets.shift(), options), - openBracket: ast.openBracket.text, - start: ast.start - ? new Expression(ast.start, childrenOffsets.shift(), options) - : undefined, - end: ast.end - ? new IndexAccessEnd(ast.end, childrenOffsets.shift(), options) - : undefined, - closeBracket: ast.closeBracket.text - }); + const fetch = (offsets) => { + let i = 0; + const children = { + operand: new Expression(ast.operand, offsets[0], options), + openBracket: ast.openBracket.text, + start: ast.start + ? new Expression(ast.start, offsets[(i += 1)], options) + : undefined, + end: ast.end + ? new IndexAccessEnd(ast.end, offsets[(i += 1)], options) + : undefined, + closeBracket: ast.closeBracket.text + }; + return children; + }; this.initialize(ast, offset, fetch); } diff --git a/src/slang-nodes/InheritanceSpecifier.js b/src/slang-nodes/InheritanceSpecifier.js index 95f3f3633..20cf43d71 100644 --- a/src/slang-nodes/InheritanceSpecifier.js +++ b/src/slang-nodes/InheritanceSpecifier.js @@ -14,9 +14,9 @@ export class InheritanceSpecifier extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ isKeyword: ast.isKeyword?.text, - types: new InheritanceTypes(ast.types, childrenOffsets.shift(), options) + types: new InheritanceTypes(ast.types, offsets[0], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/InheritanceType.js b/src/slang-nodes/InheritanceType.js index 9b4ac5e1d..43c925afe 100644 --- a/src/slang-nodes/InheritanceType.js +++ b/src/slang-nodes/InheritanceType.js @@ -15,18 +15,10 @@ export class InheritanceType extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - typeName: new IdentifierPath( - ast.typeName, - childrenOffsets.shift(), - options - ), + const fetch = (offsets) => ({ + typeName: new IdentifierPath(ast.typeName, offsets[0], options), arguments: ast.arguments - ? new ArgumentsDeclaration( - ast.arguments, - childrenOffsets.shift(), - options - ) + ? new ArgumentsDeclaration(ast.arguments, offsets[1], options) : undefined }); diff --git a/src/slang-nodes/InheritanceTypes.js b/src/slang-nodes/InheritanceTypes.js index bfd5c392d..50e1f2e31 100644 --- a/src/slang-nodes/InheritanceTypes.js +++ b/src/slang-nodes/InheritanceTypes.js @@ -18,9 +18,9 @@ export class InheritanceTypes extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => new InheritanceType(item, childrenOffsets.shift(), options) + (item, index) => new InheritanceType(item, offsets[index], options) ), separators: ast.separators.map((separator) => separator.text) }); diff --git a/src/slang-nodes/InterfaceDefinition.js b/src/slang-nodes/InterfaceDefinition.js index ab3874eee..b0d54631f 100644 --- a/src/slang-nodes/InterfaceDefinition.js +++ b/src/slang-nodes/InterfaceDefinition.js @@ -26,24 +26,24 @@ export class InterfaceDefinition extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - interfaceKeyword: ast.interfaceKeyword.text, - name: ast.name.text, - inheritance: ast.inheritance - ? new InheritanceSpecifier( - ast.inheritance, - childrenOffsets.shift(), - options - ) - : undefined, - openBrace: ast.openBrace.text, - members: new InterfaceMembers( - ast.members, - childrenOffsets.shift(), - options - ), - closeBrace: ast.closeBrace.text - }); + const fetch = (offsets) => { + let i = -1; + const children = { + interfaceKeyword: ast.interfaceKeyword.text, + name: ast.name.text, + inheritance: ast.inheritance + ? new InheritanceSpecifier( + ast.inheritance, + offsets[(i += 1)], + options + ) + : undefined, + openBrace: ast.openBrace.text, + members: new InterfaceMembers(ast.members, offsets[(i += 1)], options), + closeBrace: ast.closeBrace.text + }; + return children; + }; this.initialize(ast, offset, fetch); } diff --git a/src/slang-nodes/InterfaceMembers.js b/src/slang-nodes/InterfaceMembers.js index 3a27f05a4..b06a934b6 100644 --- a/src/slang-nodes/InterfaceMembers.js +++ b/src/slang-nodes/InterfaceMembers.js @@ -17,9 +17,9 @@ export class InterfaceMembers extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => new ContractMember(item, childrenOffsets.shift(), options) + (item, index) => new ContractMember(item, offsets[index], options) ) }); diff --git a/src/slang-nodes/LibraryDefinition.js b/src/slang-nodes/LibraryDefinition.js index 3f876f732..ee4cb0277 100644 --- a/src/slang-nodes/LibraryDefinition.js +++ b/src/slang-nodes/LibraryDefinition.js @@ -23,15 +23,11 @@ export class LibraryDefinition extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ libraryKeyword: ast.libraryKeyword.text, name: ast.name.text, openBrace: ast.openBrace.text, - members: new LibraryMembers( - ast.members, - childrenOffsets.shift(), - options - ), + members: new LibraryMembers(ast.members, offsets[0], options), closeBrace: ast.closeBrace.text }); diff --git a/src/slang-nodes/LibraryMembers.js b/src/slang-nodes/LibraryMembers.js index 289e3b798..8366eb76c 100644 --- a/src/slang-nodes/LibraryMembers.js +++ b/src/slang-nodes/LibraryMembers.js @@ -17,9 +17,9 @@ export class LibraryMembers extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => new ContractMember(item, childrenOffsets.shift(), options) + (item, index) => new ContractMember(item, offsets[index], options) ) }); diff --git a/src/slang-nodes/MappingKey.js b/src/slang-nodes/MappingKey.js index 7a2e63751..b63b80349 100644 --- a/src/slang-nodes/MappingKey.js +++ b/src/slang-nodes/MappingKey.js @@ -14,12 +14,8 @@ export class MappingKey extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - keyType: new MappingKeyType( - ast.keyType, - childrenOffsets.shift(), - options - ), + const fetch = (offsets) => ({ + keyType: new MappingKeyType(ast.keyType, offsets[0], options), name: ast.name?.text }); diff --git a/src/slang-nodes/MappingKeyType.js b/src/slang-nodes/MappingKeyType.js index c8d1568d8..74e49cdc6 100644 --- a/src/slang-nodes/MappingKeyType.js +++ b/src/slang-nodes/MappingKeyType.js @@ -15,10 +15,10 @@ export class MappingKeyType extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ variant: new variants[ast.variant.cst.kind]( ast.variant, - childrenOffsets.shift(), + offsets[0], options ) }); diff --git a/src/slang-nodes/MappingType.js b/src/slang-nodes/MappingType.js index 355601703..a7b53700c 100644 --- a/src/slang-nodes/MappingType.js +++ b/src/slang-nodes/MappingType.js @@ -23,16 +23,12 @@ export class MappingType extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ mappingKeyword: ast.mappingKeyword.text, openParen: ast.openParen.text, - keyType: new MappingKey(ast.keyType, childrenOffsets.shift(), options), + keyType: new MappingKey(ast.keyType, offsets[0], options), equalGreaterThan: ast.equalGreaterThan.text, - valueType: new MappingValue( - ast.valueType, - childrenOffsets.shift(), - options - ), + valueType: new MappingValue(ast.valueType, offsets[1], options), closeParen: ast.closeParen.text }); diff --git a/src/slang-nodes/MappingValue.js b/src/slang-nodes/MappingValue.js index 4a70c451b..7ed1e290c 100644 --- a/src/slang-nodes/MappingValue.js +++ b/src/slang-nodes/MappingValue.js @@ -14,8 +14,8 @@ export class MappingValue extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - typeName: new TypeName(ast.typeName, childrenOffsets.shift(), options), + const fetch = (offsets) => ({ + typeName: new TypeName(ast.typeName, offsets[0], options), name: ast.name?.text }); diff --git a/src/slang-nodes/MemberAccessExpression.js b/src/slang-nodes/MemberAccessExpression.js index b2e1f96a0..7c6678365 100644 --- a/src/slang-nodes/MemberAccessExpression.js +++ b/src/slang-nodes/MemberAccessExpression.js @@ -122,10 +122,10 @@ export class MemberAccessExpression extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - operand: new Expression(ast.operand, childrenOffsets.shift(), options), + const fetch = (offsets) => ({ + operand: new Expression(ast.operand, offsets[0], options), period: ast.period.text, - member: new MemberAccess(ast.member, childrenOffsets.shift(), options) + member: new MemberAccess(ast.member, offsets[1], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/ModifierAttribute.js b/src/slang-nodes/ModifierAttribute.js index 4ada7785b..9ea0f6bf5 100644 --- a/src/slang-nodes/ModifierAttribute.js +++ b/src/slang-nodes/ModifierAttribute.js @@ -12,11 +12,11 @@ export class ModifierAttribute extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text - : new OverrideSpecifier(ast.variant, childrenOffsets.shift(), options) + : new OverrideSpecifier(ast.variant, offsets[0], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/ModifierAttributes.js b/src/slang-nodes/ModifierAttributes.js index 53daa7cf5..d6018e971 100644 --- a/src/slang-nodes/ModifierAttributes.js +++ b/src/slang-nodes/ModifierAttributes.js @@ -16,9 +16,9 @@ export class ModifierAttributes extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => new ModifierAttribute(item, childrenOffsets.shift(), options) + (item, index) => new ModifierAttribute(item, offsets[index], options) ) }); diff --git a/src/slang-nodes/ModifierDefinition.js b/src/slang-nodes/ModifierDefinition.js index c363c2d1c..f42d4939d 100644 --- a/src/slang-nodes/ModifierDefinition.js +++ b/src/slang-nodes/ModifierDefinition.js @@ -53,23 +53,27 @@ export class ModifierDefinition extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - modifierKeyword: ast.modifierKeyword.text, - name: ast.name.text, - parameters: ast.parameters - ? new ParametersDeclaration( - ast.parameters, - childrenOffsets.shift(), - options - ) - : undefined, - attributes: new ModifierAttributes( - ast.attributes, - childrenOffsets.shift(), - options - ), - body: new FunctionBody(ast.body, childrenOffsets.shift(), options) - }); + const fetch = (offsets) => { + let i = -1; + const children = { + modifierKeyword: ast.modifierKeyword.text, + name: ast.name.text, + parameters: ast.parameters + ? new ParametersDeclaration( + ast.parameters, + offsets[(i += 1)], + options + ) + : undefined, + attributes: new ModifierAttributes( + ast.attributes, + offsets[(i += 1)], + options + ), + body: new FunctionBody(ast.body, offsets[(i += 1)], options) + }; + return children; + }; this.initialize(ast, offset, fetch, postProcess); } diff --git a/src/slang-nodes/ModifierInvocation.js b/src/slang-nodes/ModifierInvocation.js index 89d8d209d..9f6869b6d 100644 --- a/src/slang-nodes/ModifierInvocation.js +++ b/src/slang-nodes/ModifierInvocation.js @@ -16,14 +16,10 @@ export class ModifierInvocation extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - name: new IdentifierPath(ast.name, childrenOffsets.shift(), options), + const fetch = (offsets) => ({ + name: new IdentifierPath(ast.name, offsets[0], options), arguments: ast.arguments - ? new ArgumentsDeclaration( - ast.arguments, - childrenOffsets.shift(), - options - ) + ? new ArgumentsDeclaration(ast.arguments, offsets[1], options) : undefined }); diff --git a/src/slang-nodes/MultiplicativeExpression.js b/src/slang-nodes/MultiplicativeExpression.js index 33b1d09b6..f3fa02d35 100644 --- a/src/slang-nodes/MultiplicativeExpression.js +++ b/src/slang-nodes/MultiplicativeExpression.js @@ -45,18 +45,10 @@ export class MultiplicativeExpression extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - leftOperand: new Expression( - ast.leftOperand, - childrenOffsets.shift(), - options - ), + const fetch = (offsets) => ({ + leftOperand: new Expression(ast.leftOperand, offsets[0], options), operator: ast.operator.text, - rightOperand: new Expression( - ast.rightOperand, - childrenOffsets.shift(), - options - ) + rightOperand: new Expression(ast.rightOperand, offsets[1], options) }); this.initialize(ast, offset, fetch, postProcess); diff --git a/src/slang-nodes/NamedArgument.js b/src/slang-nodes/NamedArgument.js index cc1b535c8..6b58892c6 100644 --- a/src/slang-nodes/NamedArgument.js +++ b/src/slang-nodes/NamedArgument.js @@ -16,10 +16,10 @@ export class NamedArgument extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ name: ast.name.text, colon: ast.colon.text, - value: new Expression(ast.value, childrenOffsets.shift(), options) + value: new Expression(ast.value, offsets[0], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/NamedArgumentGroup.js b/src/slang-nodes/NamedArgumentGroup.js index 917e116c9..fc52a45d1 100644 --- a/src/slang-nodes/NamedArgumentGroup.js +++ b/src/slang-nodes/NamedArgumentGroup.js @@ -16,13 +16,9 @@ export class NamedArgumentGroup extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ openBrace: ast.openBrace.text, - arguments: new NamedArguments( - ast.arguments, - childrenOffsets.shift(), - options - ), + arguments: new NamedArguments(ast.arguments, offsets[0], options), closeBrace: ast.closeBrace.text }); diff --git a/src/slang-nodes/NamedArguments.js b/src/slang-nodes/NamedArguments.js index fcfb49f06..703cb4c95 100644 --- a/src/slang-nodes/NamedArguments.js +++ b/src/slang-nodes/NamedArguments.js @@ -18,9 +18,9 @@ export class NamedArguments extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => new NamedArgument(item, childrenOffsets.shift(), options) + (item, index) => new NamedArgument(item, offsets[index], options) ), separators: ast.separators.map((separator) => separator.text) }); diff --git a/src/slang-nodes/NamedArgumentsDeclaration.js b/src/slang-nodes/NamedArgumentsDeclaration.js index baedffbd2..efea82178 100644 --- a/src/slang-nodes/NamedArgumentsDeclaration.js +++ b/src/slang-nodes/NamedArgumentsDeclaration.js @@ -16,14 +16,10 @@ export class NamedArgumentsDeclaration extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ openParen: ast.openParen.text, arguments: ast.arguments - ? new NamedArgumentGroup( - ast.arguments, - childrenOffsets.shift(), - options - ) + ? new NamedArgumentGroup(ast.arguments, offsets[0], options) : undefined, closeParen: ast.closeParen.text }); diff --git a/src/slang-nodes/NamedImport.js b/src/slang-nodes/NamedImport.js index 9f976bc1a..c4ff99eae 100644 --- a/src/slang-nodes/NamedImport.js +++ b/src/slang-nodes/NamedImport.js @@ -19,11 +19,11 @@ export class NamedImport extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ asterisk: ast.asterisk.text, - alias: new ImportAlias(ast.alias, childrenOffsets.shift(), options), + alias: new ImportAlias(ast.alias, offsets[0], options), fromKeyword: ast.fromKeyword.text, - path: new StringLiteral(ast.path, childrenOffsets.shift(), options) + path: new StringLiteral(ast.path, offsets[1], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/NewExpression.js b/src/slang-nodes/NewExpression.js index f57a82295..f243e6e1b 100644 --- a/src/slang-nodes/NewExpression.js +++ b/src/slang-nodes/NewExpression.js @@ -14,9 +14,9 @@ export class NewExpression extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ newKeyword: ast.newKeyword.text, - typeName: new TypeName(ast.typeName, childrenOffsets.shift(), options) + typeName: new TypeName(ast.typeName, offsets[0], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/OrExpression.js b/src/slang-nodes/OrExpression.js index 897b4e1ad..915a12433 100644 --- a/src/slang-nodes/OrExpression.js +++ b/src/slang-nodes/OrExpression.js @@ -26,18 +26,10 @@ export class OrExpression extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - leftOperand: new Expression( - ast.leftOperand, - childrenOffsets.shift(), - options - ), + const fetch = (offsets) => ({ + leftOperand: new Expression(ast.leftOperand, offsets[0], options), operator: ast.operator.text, - rightOperand: new Expression( - ast.rightOperand, - childrenOffsets.shift(), - options - ) + rightOperand: new Expression(ast.rightOperand, offsets[1], options) }); this.initialize(ast, offset, fetch, postProcess); diff --git a/src/slang-nodes/OverridePaths.js b/src/slang-nodes/OverridePaths.js index e4491033e..e17aa6d32 100644 --- a/src/slang-nodes/OverridePaths.js +++ b/src/slang-nodes/OverridePaths.js @@ -14,9 +14,9 @@ export class OverridePaths extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => new IdentifierPath(item, childrenOffsets.shift(), options) + (item, index) => new IdentifierPath(item, offsets[index], options) ), separators: ast.separators.map((separator) => separator.text) }); diff --git a/src/slang-nodes/OverridePathsDeclaration.js b/src/slang-nodes/OverridePathsDeclaration.js index a3ecf42c1..d1bf8a72a 100644 --- a/src/slang-nodes/OverridePathsDeclaration.js +++ b/src/slang-nodes/OverridePathsDeclaration.js @@ -16,9 +16,9 @@ export class OverridePathsDeclaration extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ openParen: ast.openParen.text, - paths: new OverridePaths(ast.paths, childrenOffsets.shift(), options), + paths: new OverridePaths(ast.paths, offsets[0], options), closeParen: ast.closeParen.text }); diff --git a/src/slang-nodes/OverrideSpecifier.js b/src/slang-nodes/OverrideSpecifier.js index ba8c25486..93d73368f 100644 --- a/src/slang-nodes/OverrideSpecifier.js +++ b/src/slang-nodes/OverrideSpecifier.js @@ -14,14 +14,10 @@ export class OverrideSpecifier extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ overrideKeyword: ast.overrideKeyword.text, overridden: ast.overridden - ? new OverridePathsDeclaration( - ast.overridden, - childrenOffsets.shift(), - options - ) + ? new OverridePathsDeclaration(ast.overridden, offsets[0], options) : undefined }); diff --git a/src/slang-nodes/Parameter.js b/src/slang-nodes/Parameter.js index 8d71f60e9..f321c7bb9 100644 --- a/src/slang-nodes/Parameter.js +++ b/src/slang-nodes/Parameter.js @@ -20,14 +20,10 @@ export class Parameter extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - typeName: new TypeName(ast.typeName, childrenOffsets.shift(), options), + const fetch = (offsets) => ({ + typeName: new TypeName(ast.typeName, offsets[0], options), storageLocation: ast.storageLocation - ? new StorageLocation( - ast.storageLocation, - childrenOffsets.shift(), - options - ) + ? new StorageLocation(ast.storageLocation, offsets[1], options) : undefined, name: ast.name?.text }); diff --git a/src/slang-nodes/Parameters.js b/src/slang-nodes/Parameters.js index cea7ba06b..82b454e25 100644 --- a/src/slang-nodes/Parameters.js +++ b/src/slang-nodes/Parameters.js @@ -19,9 +19,9 @@ export class Parameters extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => new Parameter(item, childrenOffsets.shift(), options) + (item, index) => new Parameter(item, offsets[index], options) ), separators: ast.separators.map((separator) => separator.text) }); diff --git a/src/slang-nodes/ParametersDeclaration.js b/src/slang-nodes/ParametersDeclaration.js index ffd4ebcc6..9ae79a343 100644 --- a/src/slang-nodes/ParametersDeclaration.js +++ b/src/slang-nodes/ParametersDeclaration.js @@ -16,13 +16,9 @@ export class ParametersDeclaration extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ openParen: ast.openParen.text, - parameters: new Parameters( - ast.parameters, - childrenOffsets.shift(), - options - ), + parameters: new Parameters(ast.parameters, offsets[0], options), closeParen: ast.closeParen.text }); diff --git a/src/slang-nodes/PathImport.js b/src/slang-nodes/PathImport.js index 228fe9575..362292455 100644 --- a/src/slang-nodes/PathImport.js +++ b/src/slang-nodes/PathImport.js @@ -15,10 +15,10 @@ export class PathImport extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - path: new StringLiteral(ast.path, childrenOffsets.shift(), options), + const fetch = (offsets) => ({ + path: new StringLiteral(ast.path, offsets[0], options), alias: ast.alias - ? new ImportAlias(ast.alias, childrenOffsets.shift(), options) + ? new ImportAlias(ast.alias, offsets[1], options) : undefined }); diff --git a/src/slang-nodes/PositionalArguments.js b/src/slang-nodes/PositionalArguments.js index 8cf97523e..9c57f57e7 100644 --- a/src/slang-nodes/PositionalArguments.js +++ b/src/slang-nodes/PositionalArguments.js @@ -15,9 +15,9 @@ export class PositionalArguments extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => new Expression(item, childrenOffsets.shift(), options) + (item, index) => new Expression(item, offsets[index], options) ), separators: ast.separators.map((separator) => separator.text) }); diff --git a/src/slang-nodes/PositionalArgumentsDeclaration.js b/src/slang-nodes/PositionalArgumentsDeclaration.js index b829d2228..cf06a0356 100644 --- a/src/slang-nodes/PositionalArgumentsDeclaration.js +++ b/src/slang-nodes/PositionalArgumentsDeclaration.js @@ -16,13 +16,9 @@ export class PositionalArgumentsDeclaration extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ openParen: ast.openParen.text, - arguments: new PositionalArguments( - ast.arguments, - childrenOffsets.shift(), - options - ), + arguments: new PositionalArguments(ast.arguments, offsets[0], options), closeParen: ast.closeParen.text }); diff --git a/src/slang-nodes/PostfixExpression.js b/src/slang-nodes/PostfixExpression.js index 637dd2140..bf0592f8d 100644 --- a/src/slang-nodes/PostfixExpression.js +++ b/src/slang-nodes/PostfixExpression.js @@ -14,8 +14,8 @@ export class PostfixExpression extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - operand: new Expression(ast.operand, childrenOffsets.shift(), options), + const fetch = (offsets) => ({ + operand: new Expression(ast.operand, offsets[0], options), operator: ast.operator.text }); diff --git a/src/slang-nodes/Pragma.js b/src/slang-nodes/Pragma.js index ff696c66a..d8ef56cf7 100644 --- a/src/slang-nodes/Pragma.js +++ b/src/slang-nodes/Pragma.js @@ -15,10 +15,10 @@ export class Pragma extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ variant: new variants[ast.variant.cst.kind]( ast.variant, - childrenOffsets.shift(), + offsets[0], options ) }); diff --git a/src/slang-nodes/PragmaDirective.js b/src/slang-nodes/PragmaDirective.js index ab8e83861..bd5526bac 100644 --- a/src/slang-nodes/PragmaDirective.js +++ b/src/slang-nodes/PragmaDirective.js @@ -16,9 +16,9 @@ export class PragmaDirective extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ pragmaKeyword: ast.pragmaKeyword.text, - pragma: new Pragma(ast.pragma, childrenOffsets.shift(), options), + pragma: new Pragma(ast.pragma, offsets[0], options), semicolon: ast.semicolon.text }); diff --git a/src/slang-nodes/PrefixExpression.js b/src/slang-nodes/PrefixExpression.js index e72a0274d..945200c09 100644 --- a/src/slang-nodes/PrefixExpression.js +++ b/src/slang-nodes/PrefixExpression.js @@ -14,9 +14,9 @@ export class PrefixExpression extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ operator: ast.operator.text, - operand: new Expression(ast.operand, childrenOffsets.shift(), options) + operand: new Expression(ast.operand, offsets[0], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/ReceiveFunctionAttribute.js b/src/slang-nodes/ReceiveFunctionAttribute.js index c46e34359..0feed7c08 100644 --- a/src/slang-nodes/ReceiveFunctionAttribute.js +++ b/src/slang-nodes/ReceiveFunctionAttribute.js @@ -15,15 +15,11 @@ export class ReceiveFunctionAttribute extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text - : new variants[ast.variant.cst.kind]( - ast.variant, - childrenOffsets.shift(), - options - ) + : new variants[ast.variant.cst.kind](ast.variant, offsets[0], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/ReceiveFunctionAttributes.js b/src/slang-nodes/ReceiveFunctionAttributes.js index 99dc1d2bc..de0468889 100644 --- a/src/slang-nodes/ReceiveFunctionAttributes.js +++ b/src/slang-nodes/ReceiveFunctionAttributes.js @@ -16,10 +16,10 @@ export class ReceiveFunctionAttributes extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => - new ReceiveFunctionAttribute(item, childrenOffsets.shift(), options) + (item, index) => + new ReceiveFunctionAttribute(item, offsets[index], options) ) }); diff --git a/src/slang-nodes/ReceiveFunctionDefinition.js b/src/slang-nodes/ReceiveFunctionDefinition.js index 169214063..681b954cb 100644 --- a/src/slang-nodes/ReceiveFunctionDefinition.js +++ b/src/slang-nodes/ReceiveFunctionDefinition.js @@ -21,19 +21,19 @@ export class ReceiveFunctionDefinition extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ receiveKeyword: ast.receiveKeyword.text, parameters: new ParametersDeclaration( ast.parameters, - childrenOffsets.shift(), + offsets[0], options ), attributes: new ReceiveFunctionAttributes( ast.attributes, - childrenOffsets.shift(), + offsets[1], options ), - body: new FunctionBody(ast.body, childrenOffsets.shift(), options) + body: new FunctionBody(ast.body, offsets[2], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/ReturnStatement.js b/src/slang-nodes/ReturnStatement.js index fb8b1cef6..6bb07383d 100644 --- a/src/slang-nodes/ReturnStatement.js +++ b/src/slang-nodes/ReturnStatement.js @@ -30,10 +30,10 @@ export class ReturnStatement extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ returnKeyword: ast.returnKeyword.text, expression: ast.expression - ? new Expression(ast.expression, childrenOffsets.shift(), options) + ? new Expression(ast.expression, offsets[0], options) : undefined, semicolon: ast.semicolon.text diff --git a/src/slang-nodes/ReturnsDeclaration.js b/src/slang-nodes/ReturnsDeclaration.js index 861f0bb37..5045dc3d9 100644 --- a/src/slang-nodes/ReturnsDeclaration.js +++ b/src/slang-nodes/ReturnsDeclaration.js @@ -17,13 +17,9 @@ export class ReturnsDeclaration extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ returnsKeyword: ast.returnsKeyword.text, - variables: new ParametersDeclaration( - ast.variables, - childrenOffsets.shift(), - options - ) + variables: new ParametersDeclaration(ast.variables, offsets[0], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/RevertStatement.js b/src/slang-nodes/RevertStatement.js index e21bba5a1..cf90567ce 100644 --- a/src/slang-nodes/RevertStatement.js +++ b/src/slang-nodes/RevertStatement.js @@ -19,18 +19,22 @@ export class RevertStatement extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - revertKeyword: ast.revertKeyword.text, - error: ast.error - ? new IdentifierPath(ast.error, childrenOffsets.shift(), options) - : undefined, - arguments: new ArgumentsDeclaration( - ast.arguments, - childrenOffsets.shift(), - options - ), - semicolon: ast.semicolon.text - }); + const fetch = (offsets) => { + let i = -1; + const children = { + revertKeyword: ast.revertKeyword.text, + error: ast.error + ? new IdentifierPath(ast.error, offsets[(i += 1)], options) + : undefined, + arguments: new ArgumentsDeclaration( + ast.arguments, + offsets[(i += 1)], + options + ), + semicolon: ast.semicolon.text + }; + return children; + }; this.initialize(ast, offset, fetch); } diff --git a/src/slang-nodes/ShiftExpression.js b/src/slang-nodes/ShiftExpression.js index 625289ca9..7bbc626de 100644 --- a/src/slang-nodes/ShiftExpression.js +++ b/src/slang-nodes/ShiftExpression.js @@ -35,18 +35,10 @@ export class ShiftExpression extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - leftOperand: new Expression( - ast.leftOperand, - childrenOffsets.shift(), - options - ), + const fetch = (offsets) => ({ + leftOperand: new Expression(ast.leftOperand, offsets[0], options), operator: ast.operator.text, - rightOperand: new Expression( - ast.rightOperand, - childrenOffsets.shift(), - options - ) + rightOperand: new Expression(ast.rightOperand, offsets[1], options) }); this.initialize(ast, offset, fetch, postProcess); diff --git a/src/slang-nodes/SourceUnit.js b/src/slang-nodes/SourceUnit.js index c6f912999..124e54492 100644 --- a/src/slang-nodes/SourceUnit.js +++ b/src/slang-nodes/SourceUnit.js @@ -13,12 +13,8 @@ export class SourceUnit extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - members: new SourceUnitMembers( - ast.members, - childrenOffsets.shift(), - options - ) + const fetch = (offsets) => ({ + members: new SourceUnitMembers(ast.members, offsets[0], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/SourceUnitMember.js b/src/slang-nodes/SourceUnitMember.js index 2947222cc..34334ff67 100644 --- a/src/slang-nodes/SourceUnitMember.js +++ b/src/slang-nodes/SourceUnitMember.js @@ -39,10 +39,10 @@ export class SourceUnitMember extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ variant: new variants[ast.variant.cst.kind]( ast.variant, - childrenOffsets.shift(), + offsets[0], options ) }); diff --git a/src/slang-nodes/SourceUnitMembers.js b/src/slang-nodes/SourceUnitMembers.js index b49ab1885..467062732 100644 --- a/src/slang-nodes/SourceUnitMembers.js +++ b/src/slang-nodes/SourceUnitMembers.js @@ -13,9 +13,9 @@ export class SourceUnitMembers extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => new SourceUnitMember(item, childrenOffsets.shift(), options) + (item, index) => new SourceUnitMember(item, offsets[index], options) ) }); diff --git a/src/slang-nodes/StateVariableAttribute.js b/src/slang-nodes/StateVariableAttribute.js index 011020f5a..7d5101a8b 100644 --- a/src/slang-nodes/StateVariableAttribute.js +++ b/src/slang-nodes/StateVariableAttribute.js @@ -12,11 +12,11 @@ export class StateVariableAttribute extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text - : new OverrideSpecifier(ast.variant, childrenOffsets.shift(), options) + : new OverrideSpecifier(ast.variant, offsets[0], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/StateVariableAttributes.js b/src/slang-nodes/StateVariableAttributes.js index 4cc6b090a..c06da927d 100644 --- a/src/slang-nodes/StateVariableAttributes.js +++ b/src/slang-nodes/StateVariableAttributes.js @@ -12,10 +12,10 @@ export class StateVariableAttributes extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => - new StateVariableAttribute(item, childrenOffsets.shift(), options) + (item, index) => + new StateVariableAttribute(item, offsets[index], options) ) }); diff --git a/src/slang-nodes/StateVariableDefinition.js b/src/slang-nodes/StateVariableDefinition.js index 44b5796fa..65a262a1a 100644 --- a/src/slang-nodes/StateVariableDefinition.js +++ b/src/slang-nodes/StateVariableDefinition.js @@ -22,20 +22,16 @@ export class StateVariableDefinition extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - typeName: new TypeName(ast.typeName, childrenOffsets.shift(), options), + const fetch = (offsets) => ({ + typeName: new TypeName(ast.typeName, offsets[0], options), attributes: new StateVariableAttributes( ast.attributes, - childrenOffsets.shift(), + offsets[1], options ), name: ast.name.text, value: ast.value - ? new StateVariableDefinitionValue( - ast.value, - childrenOffsets.shift(), - options - ) + ? new StateVariableDefinitionValue(ast.value, offsets[2], options) : undefined, semicolon: ast.semicolon.text }); diff --git a/src/slang-nodes/StateVariableDefinitionValue.js b/src/slang-nodes/StateVariableDefinitionValue.js index f868c91ad..5a1358fa7 100644 --- a/src/slang-nodes/StateVariableDefinitionValue.js +++ b/src/slang-nodes/StateVariableDefinitionValue.js @@ -17,9 +17,9 @@ export class StateVariableDefinitionValue extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ equal: ast.equal.text, - value: new Expression(ast.value, childrenOffsets.shift(), options) + value: new Expression(ast.value, offsets[0], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/Statement.js b/src/slang-nodes/Statement.js index d436efed0..8172209d3 100644 --- a/src/slang-nodes/Statement.js +++ b/src/slang-nodes/Statement.js @@ -48,10 +48,10 @@ export class Statement extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ variant: new variants[ast.variant.cst.kind]( ast.variant, - childrenOffsets.shift(), + offsets[0], options ) }); diff --git a/src/slang-nodes/Statements.js b/src/slang-nodes/Statements.js index a095e5a9c..da5f1f14c 100644 --- a/src/slang-nodes/Statements.js +++ b/src/slang-nodes/Statements.js @@ -18,9 +18,9 @@ export class Statements extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => new Statement(item, childrenOffsets.shift(), options) + (item, index) => new Statement(item, offsets[index], options) ) }); diff --git a/src/slang-nodes/StringExpression.js b/src/slang-nodes/StringExpression.js index 91deaddc2..15b941035 100644 --- a/src/slang-nodes/StringExpression.js +++ b/src/slang-nodes/StringExpression.js @@ -24,10 +24,10 @@ export class StringExpression extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ variant: new variants[ast.variant.cst.kind]( ast.variant, - childrenOffsets.shift(), + offsets[0], options ) }); diff --git a/src/slang-nodes/StringLiterals.js b/src/slang-nodes/StringLiterals.js index 3f952d542..52a83c36a 100644 --- a/src/slang-nodes/StringLiterals.js +++ b/src/slang-nodes/StringLiterals.js @@ -15,9 +15,9 @@ export class StringLiterals extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => new StringLiteral(item, childrenOffsets.shift(), options) + (item, index) => new StringLiteral(item, offsets[index], options) ) }); diff --git a/src/slang-nodes/StructDefinition.js b/src/slang-nodes/StructDefinition.js index c9c1ebf1b..012f4f6e7 100644 --- a/src/slang-nodes/StructDefinition.js +++ b/src/slang-nodes/StructDefinition.js @@ -20,11 +20,11 @@ export class StructDefinition extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ structKeyword: ast.structKeyword.text, name: ast.name.text, openBrace: ast.openBrace.text, - members: new StructMembers(ast.members, childrenOffsets.shift(), options), + members: new StructMembers(ast.members, offsets[0], options), closeBrace: ast.closeBrace.text }); diff --git a/src/slang-nodes/StructMember.js b/src/slang-nodes/StructMember.js index 32e32eab8..32548e0c4 100644 --- a/src/slang-nodes/StructMember.js +++ b/src/slang-nodes/StructMember.js @@ -16,8 +16,8 @@ export class StructMember extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - typeName: new TypeName(ast.typeName, childrenOffsets.shift(), options), + const fetch = (offsets) => ({ + typeName: new TypeName(ast.typeName, offsets[0], options), name: ast.name.text, semicolon: ast.semicolon.text }); diff --git a/src/slang-nodes/StructMembers.js b/src/slang-nodes/StructMembers.js index 8af5c6365..019b47194 100644 --- a/src/slang-nodes/StructMembers.js +++ b/src/slang-nodes/StructMembers.js @@ -16,9 +16,9 @@ export class StructMembers extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => new StructMember(item, childrenOffsets.shift(), options) + (item, index) => new StructMember(item, offsets[index], options) ) }); diff --git a/src/slang-nodes/TryStatement.js b/src/slang-nodes/TryStatement.js index 188e244f9..3b26552a1 100644 --- a/src/slang-nodes/TryStatement.js +++ b/src/slang-nodes/TryStatement.js @@ -27,23 +27,23 @@ export class TryStatement extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - tryKeyword: ast.tryKeyword.text, - expression: new Expression( - ast.expression, - childrenOffsets.shift(), - options - ), - returns: ast.returns - ? new ReturnsDeclaration(ast.returns, childrenOffsets.shift(), options) - : undefined, - body: new Block(ast.body, childrenOffsets.shift(), options), - catchClauses: new CatchClauses( - ast.catchClauses, - childrenOffsets.shift(), - options - ) - }); + const fetch = (offsets) => { + let i = 0; + const children = { + tryKeyword: ast.tryKeyword.text, + expression: new Expression(ast.expression, offsets[0], options), + returns: ast.returns + ? new ReturnsDeclaration(ast.returns, offsets[(i += 1)], options) + : undefined, + body: new Block(ast.body, offsets[(i += 1)], options), + catchClauses: new CatchClauses( + ast.catchClauses, + offsets[(i += 1)], + options + ) + }; + return children; + }; this.initialize(ast, offset, fetch); } diff --git a/src/slang-nodes/TupleDeconstructionElement.js b/src/slang-nodes/TupleDeconstructionElement.js index 3a3c452b5..d173501d2 100644 --- a/src/slang-nodes/TupleDeconstructionElement.js +++ b/src/slang-nodes/TupleDeconstructionElement.js @@ -12,9 +12,9 @@ export class TupleDeconstructionElement extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ member: ast.member - ? new TupleMember(ast.member, childrenOffsets.shift(), options) + ? new TupleMember(ast.member, offsets[0], options) : undefined }); diff --git a/src/slang-nodes/TupleDeconstructionElements.js b/src/slang-nodes/TupleDeconstructionElements.js index 3fa3738f7..70ad8ebb6 100644 --- a/src/slang-nodes/TupleDeconstructionElements.js +++ b/src/slang-nodes/TupleDeconstructionElements.js @@ -15,10 +15,10 @@ export class TupleDeconstructionElements extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => - new TupleDeconstructionElement(item, childrenOffsets.shift(), options) + (item, index) => + new TupleDeconstructionElement(item, offsets[index], options) ), separators: ast.separators.map((separator) => separator.text) }); diff --git a/src/slang-nodes/TupleDeconstructionStatement.js b/src/slang-nodes/TupleDeconstructionStatement.js index 393f2b4af..eb36162ef 100644 --- a/src/slang-nodes/TupleDeconstructionStatement.js +++ b/src/slang-nodes/TupleDeconstructionStatement.js @@ -28,21 +28,17 @@ export class TupleDeconstructionStatement extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ varKeyword: ast.varKeyword?.text, openParen: ast.openParen.text, elements: new TupleDeconstructionElements( ast.elements, - childrenOffsets.shift(), + offsets[0], options ), closeParen: ast.closeParen.text, equal: ast.equal.text, - expression: new Expression( - ast.expression, - childrenOffsets.shift(), - options - ), + expression: new Expression(ast.expression, offsets[1], options), semicolon: ast.semicolon.text }); diff --git a/src/slang-nodes/TupleExpression.js b/src/slang-nodes/TupleExpression.js index ecb4e9476..a077f9b0b 100644 --- a/src/slang-nodes/TupleExpression.js +++ b/src/slang-nodes/TupleExpression.js @@ -16,9 +16,9 @@ export class TupleExpression extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ openParen: ast.openParen.text, - items: new TupleValues(ast.items, childrenOffsets.shift(), options), + items: new TupleValues(ast.items, offsets[0], options), closeParen: ast.closeParen.text }); diff --git a/src/slang-nodes/TupleMember.js b/src/slang-nodes/TupleMember.js index ca51176e1..75696f73d 100644 --- a/src/slang-nodes/TupleMember.js +++ b/src/slang-nodes/TupleMember.js @@ -15,10 +15,10 @@ export class TupleMember extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ variant: new variants[ast.variant.cst.kind]( ast.variant, - childrenOffsets.shift(), + offsets[0], options ) }); diff --git a/src/slang-nodes/TupleValue.js b/src/slang-nodes/TupleValue.js index 3811608eb..90e7d8353 100644 --- a/src/slang-nodes/TupleValue.js +++ b/src/slang-nodes/TupleValue.js @@ -12,9 +12,9 @@ export class TupleValue extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ expression: ast.expression - ? new Expression(ast.expression, childrenOffsets.shift(), options) + ? new Expression(ast.expression, offsets[0], options) : undefined }); diff --git a/src/slang-nodes/TupleValues.js b/src/slang-nodes/TupleValues.js index bffff2b9d..b0c2e49df 100644 --- a/src/slang-nodes/TupleValues.js +++ b/src/slang-nodes/TupleValues.js @@ -16,9 +16,9 @@ export class TupleValues extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => new TupleValue(item, childrenOffsets.shift(), options) + (item, index) => new TupleValue(item, offsets[index], options) ), separators: ast.separators.map((separator) => separator.text) }); diff --git a/src/slang-nodes/TypeExpression.js b/src/slang-nodes/TypeExpression.js index f75989296..fbeef0e9a 100644 --- a/src/slang-nodes/TypeExpression.js +++ b/src/slang-nodes/TypeExpression.js @@ -18,10 +18,10 @@ export class TypeExpression extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ typeKeyword: ast.typeKeyword.text, openParen: ast.openParen.text, - typeName: new TypeName(ast.typeName, childrenOffsets.shift(), options), + typeName: new TypeName(ast.typeName, offsets[0], options), closeParen: ast.closeParen.text }); diff --git a/src/slang-nodes/TypeName.js b/src/slang-nodes/TypeName.js index f759fbb6a..5f6a80529 100644 --- a/src/slang-nodes/TypeName.js +++ b/src/slang-nodes/TypeName.js @@ -24,10 +24,10 @@ export class TypeName extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ variant: new variants[ast.variant.cst.kind]( ast.variant, - childrenOffsets.shift(), + offsets[0], options ) }); diff --git a/src/slang-nodes/TypedTupleMember.js b/src/slang-nodes/TypedTupleMember.js index 6d905a1b4..cb6b98709 100644 --- a/src/slang-nodes/TypedTupleMember.js +++ b/src/slang-nodes/TypedTupleMember.js @@ -17,14 +17,10 @@ export class TypedTupleMember extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - typeName: new TypeName(ast.typeName, childrenOffsets.shift(), options), + const fetch = (offsets) => ({ + typeName: new TypeName(ast.typeName, offsets[0], options), storageLocation: ast.storageLocation - ? new StorageLocation( - ast.storageLocation, - childrenOffsets.shift(), - options - ) + ? new StorageLocation(ast.storageLocation, offsets[1], options) : undefined, name: ast.name.text }); diff --git a/src/slang-nodes/UncheckedBlock.js b/src/slang-nodes/UncheckedBlock.js index 4c456740d..dbcb24480 100644 --- a/src/slang-nodes/UncheckedBlock.js +++ b/src/slang-nodes/UncheckedBlock.js @@ -14,9 +14,9 @@ export class UncheckedBlock extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ uncheckedKeyword: ast.uncheckedKeyword.text, - block: new Block(ast.block, childrenOffsets.shift(), options) + block: new Block(ast.block, offsets[0], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/UnicodeStringLiterals.js b/src/slang-nodes/UnicodeStringLiterals.js index cf04be1e5..611be17c5 100644 --- a/src/slang-nodes/UnicodeStringLiterals.js +++ b/src/slang-nodes/UnicodeStringLiterals.js @@ -15,10 +15,9 @@ export class UnicodeStringLiterals extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => - new UnicodeStringLiteral(item, childrenOffsets.shift(), options) + (item, index) => new UnicodeStringLiteral(item, offsets[index], options) ) }); diff --git a/src/slang-nodes/UnnamedFunctionAttribute.js b/src/slang-nodes/UnnamedFunctionAttribute.js index d0dd3bfbb..f55d08087 100644 --- a/src/slang-nodes/UnnamedFunctionAttribute.js +++ b/src/slang-nodes/UnnamedFunctionAttribute.js @@ -12,15 +12,11 @@ export class UnnamedFunctionAttribute extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text - : new ModifierInvocation( - ast.variant, - childrenOffsets.shift(), - options - ) + : new ModifierInvocation(ast.variant, offsets[0], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/UnnamedFunctionAttributes.js b/src/slang-nodes/UnnamedFunctionAttributes.js index eb1d57a52..e47898429 100644 --- a/src/slang-nodes/UnnamedFunctionAttributes.js +++ b/src/slang-nodes/UnnamedFunctionAttributes.js @@ -16,10 +16,10 @@ export class UnnamedFunctionAttributes extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => - new UnnamedFunctionAttribute(item, childrenOffsets.shift(), options) + (item, index) => + new UnnamedFunctionAttribute(item, offsets[index], options) ) }); diff --git a/src/slang-nodes/UnnamedFunctionDefinition.js b/src/slang-nodes/UnnamedFunctionDefinition.js index 2f934b291..1346b5807 100644 --- a/src/slang-nodes/UnnamedFunctionDefinition.js +++ b/src/slang-nodes/UnnamedFunctionDefinition.js @@ -21,19 +21,19 @@ export class UnnamedFunctionDefinition extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ functionKeyword: ast.functionKeyword.text, parameters: new ParametersDeclaration( ast.parameters, - childrenOffsets.shift(), + offsets[0], options ), attributes: new UnnamedFunctionAttributes( ast.attributes, - childrenOffsets.shift(), + offsets[1], options ), - body: new FunctionBody(ast.body, childrenOffsets.shift(), options) + body: new FunctionBody(ast.body, offsets[2], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/UntypedTupleMember.js b/src/slang-nodes/UntypedTupleMember.js index f952cc2d9..b7e63d0b7 100644 --- a/src/slang-nodes/UntypedTupleMember.js +++ b/src/slang-nodes/UntypedTupleMember.js @@ -14,13 +14,9 @@ export class UntypedTupleMember extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ storageLocation: ast.storageLocation - ? new StorageLocation( - ast.storageLocation, - childrenOffsets.shift(), - options - ) + ? new StorageLocation(ast.storageLocation, offsets[0], options) : undefined, name: ast.name.text }); diff --git a/src/slang-nodes/UserDefinedValueTypeDefinition.js b/src/slang-nodes/UserDefinedValueTypeDefinition.js index 3f8fe4b30..e1933557d 100644 --- a/src/slang-nodes/UserDefinedValueTypeDefinition.js +++ b/src/slang-nodes/UserDefinedValueTypeDefinition.js @@ -20,15 +20,11 @@ export class UserDefinedValueTypeDefinition extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ typeKeyword: ast.typeKeyword.text, name: ast.name.text, isKeyword: ast.isKeyword.text, - valueType: new ElementaryType( - ast.valueType, - childrenOffsets.shift(), - options - ), + valueType: new ElementaryType(ast.valueType, offsets[0], options), semicolon: ast.semicolon.text }); diff --git a/src/slang-nodes/UsingAlias.js b/src/slang-nodes/UsingAlias.js index 02a3c7ab4..80b8ad215 100644 --- a/src/slang-nodes/UsingAlias.js +++ b/src/slang-nodes/UsingAlias.js @@ -14,13 +14,9 @@ export class UsingAlias extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ asKeyword: ast.asKeyword.text, - operator: new UsingOperator( - ast.operator, - childrenOffsets.shift(), - options - ) + operator: new UsingOperator(ast.operator, offsets[0], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/UsingClause.js b/src/slang-nodes/UsingClause.js index 7b5fe7adf..0e48a742d 100644 --- a/src/slang-nodes/UsingClause.js +++ b/src/slang-nodes/UsingClause.js @@ -15,10 +15,10 @@ export class UsingClause extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ variant: new variants[ast.variant.cst.kind]( ast.variant, - childrenOffsets.shift(), + offsets[0], options ) }); diff --git a/src/slang-nodes/UsingDeconstruction.js b/src/slang-nodes/UsingDeconstruction.js index 44503799a..56abbae9e 100644 --- a/src/slang-nodes/UsingDeconstruction.js +++ b/src/slang-nodes/UsingDeconstruction.js @@ -16,13 +16,9 @@ export class UsingDeconstruction extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ openBrace: ast.openBrace.text, - symbols: new UsingDeconstructionSymbols( - ast.symbols, - childrenOffsets.shift(), - options - ), + symbols: new UsingDeconstructionSymbols(ast.symbols, offsets[0], options), closeBrace: ast.closeBrace.text }); diff --git a/src/slang-nodes/UsingDeconstructionSymbol.js b/src/slang-nodes/UsingDeconstructionSymbol.js index c2cccb109..154737259 100644 --- a/src/slang-nodes/UsingDeconstructionSymbol.js +++ b/src/slang-nodes/UsingDeconstructionSymbol.js @@ -15,10 +15,10 @@ export class UsingDeconstructionSymbol extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - name: new IdentifierPath(ast.name, childrenOffsets.shift(), options), + const fetch = (offsets) => ({ + name: new IdentifierPath(ast.name, offsets[0], options), alias: ast.alias - ? new UsingAlias(ast.alias, childrenOffsets.shift(), options) + ? new UsingAlias(ast.alias, offsets[1], options) : undefined }); diff --git a/src/slang-nodes/UsingDeconstructionSymbols.js b/src/slang-nodes/UsingDeconstructionSymbols.js index 4dd0bf206..5f2d67287 100644 --- a/src/slang-nodes/UsingDeconstructionSymbols.js +++ b/src/slang-nodes/UsingDeconstructionSymbols.js @@ -18,10 +18,10 @@ export class UsingDeconstructionSymbols extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => - new UsingDeconstructionSymbol(item, childrenOffsets.shift(), options) + (item, index) => + new UsingDeconstructionSymbol(item, offsets[index], options) ), separators: ast.separators.map((separator) => separator.text) }); diff --git a/src/slang-nodes/UsingDirective.js b/src/slang-nodes/UsingDirective.js index de067adfd..76a9c38fd 100644 --- a/src/slang-nodes/UsingDirective.js +++ b/src/slang-nodes/UsingDirective.js @@ -23,11 +23,11 @@ export class UsingDirective extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ usingKeyword: ast.usingKeyword.text, - clause: new UsingClause(ast.clause, childrenOffsets.shift(), options), + clause: new UsingClause(ast.clause, offsets[0], options), forKeyword: ast.forKeyword.text, - target: new UsingTarget(ast.target, childrenOffsets.shift(), options), + target: new UsingTarget(ast.target, offsets[1], options), globalKeyword: ast.globalKeyword?.text, semicolon: ast.semicolon.text }); diff --git a/src/slang-nodes/UsingTarget.js b/src/slang-nodes/UsingTarget.js index 50b813931..d3751df38 100644 --- a/src/slang-nodes/UsingTarget.js +++ b/src/slang-nodes/UsingTarget.js @@ -12,11 +12,11 @@ export class UsingTarget extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text - : new TypeName(ast.variant, childrenOffsets.shift(), options) + : new TypeName(ast.variant, offsets[0], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/VariableDeclarationStatement.js b/src/slang-nodes/VariableDeclarationStatement.js index f6050dd1a..a4e57bc81 100644 --- a/src/slang-nodes/VariableDeclarationStatement.js +++ b/src/slang-nodes/VariableDeclarationStatement.js @@ -25,29 +25,25 @@ export class VariableDeclarationStatement extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - variableType: new VariableDeclarationType( - ast.variableType, - childrenOffsets.shift(), - options - ), - storageLocation: ast.storageLocation - ? new StorageLocation( - ast.storageLocation, - childrenOffsets.shift(), - options - ) - : undefined, - name: ast.name.text, - value: ast.value - ? new VariableDeclarationValue( - ast.value, - childrenOffsets.shift(), - options - ) - : undefined, - semicolon: ast.semicolon.text - }); + const fetch = (offsets) => { + let i = 0; + const children = { + variableType: new VariableDeclarationType( + ast.variableType, + offsets[0], + options + ), + storageLocation: ast.storageLocation + ? new StorageLocation(ast.storageLocation, offsets[(i += 1)], options) + : undefined, + name: ast.name.text, + value: ast.value + ? new VariableDeclarationValue(ast.value, offsets[(i += 1)], options) + : undefined, + semicolon: ast.semicolon.text + }; + return children; + }; this.initialize(ast, offset, fetch); } diff --git a/src/slang-nodes/VariableDeclarationType.js b/src/slang-nodes/VariableDeclarationType.js index 3fe26270c..ca4620f50 100644 --- a/src/slang-nodes/VariableDeclarationType.js +++ b/src/slang-nodes/VariableDeclarationType.js @@ -12,11 +12,11 @@ export class VariableDeclarationType extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.type - : new TypeName(ast.variant, childrenOffsets.shift(), options) + : new TypeName(ast.variant, offsets[0], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/VariableDeclarationValue.js b/src/slang-nodes/VariableDeclarationValue.js index 042097b37..03feaba50 100644 --- a/src/slang-nodes/VariableDeclarationValue.js +++ b/src/slang-nodes/VariableDeclarationValue.js @@ -14,13 +14,9 @@ export class VariableDeclarationValue extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ equal: ast.equal.text, - expression: new Expression( - ast.expression, - childrenOffsets.shift(), - options - ) + expression: new Expression(ast.expression, offsets[0], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/VersionComparator.js b/src/slang-nodes/VersionComparator.js index c6c4f6282..221648af3 100644 --- a/src/slang-nodes/VersionComparator.js +++ b/src/slang-nodes/VersionComparator.js @@ -14,13 +14,9 @@ export class VersionComparator extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ operator: ast.operator.text, - operand: new VersionExpression( - ast.operand, - childrenOffsets.shift(), - options - ) + operand: new VersionExpression(ast.operand, offsets[0], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/VersionExpression.js b/src/slang-nodes/VersionExpression.js index 2c6b41abe..0f6ccb4c6 100644 --- a/src/slang-nodes/VersionExpression.js +++ b/src/slang-nodes/VersionExpression.js @@ -20,15 +20,11 @@ export class VersionExpression extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text - : new variants[ast.variant.cst.kind]( - ast.variant, - childrenOffsets.shift(), - options - ) + : new variants[ast.variant.cst.kind](ast.variant, offsets[0], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/VersionExpressionSet.js b/src/slang-nodes/VersionExpressionSet.js index 2b00454ee..452ab8752 100644 --- a/src/slang-nodes/VersionExpressionSet.js +++ b/src/slang-nodes/VersionExpressionSet.js @@ -15,9 +15,9 @@ export class VersionExpressionSet extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => new VersionExpression(item, childrenOffsets.shift(), options) + (item, index) => new VersionExpression(item, offsets[index], options) ) }); diff --git a/src/slang-nodes/VersionExpressionSets.js b/src/slang-nodes/VersionExpressionSets.js index 7fef37b6c..2f3d1c467 100644 --- a/src/slang-nodes/VersionExpressionSets.js +++ b/src/slang-nodes/VersionExpressionSets.js @@ -14,10 +14,9 @@ export class VersionExpressionSets extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => - new VersionExpressionSet(item, childrenOffsets.shift(), options) + (item, index) => new VersionExpressionSet(item, offsets[index], options) ), separators: ast.separators.map((separator) => separator.text) }); diff --git a/src/slang-nodes/VersionPragma.js b/src/slang-nodes/VersionPragma.js index 0ad676056..a04306809 100644 --- a/src/slang-nodes/VersionPragma.js +++ b/src/slang-nodes/VersionPragma.js @@ -14,13 +14,9 @@ export class VersionPragma extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ solidityKeyword: ast.solidityKeyword.text, - sets: new VersionExpressionSets( - ast.sets, - childrenOffsets.shift(), - options - ) + sets: new VersionExpressionSets(ast.sets, offsets[0], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/VersionRange.js b/src/slang-nodes/VersionRange.js index 56916d9cd..d026d5505 100644 --- a/src/slang-nodes/VersionRange.js +++ b/src/slang-nodes/VersionRange.js @@ -16,18 +16,10 @@ export class VersionRange extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - leftOperand: new VersionExpression( - ast.leftOperand, - childrenOffsets.shift(), - options - ), + const fetch = (offsets) => ({ + leftOperand: new VersionExpression(ast.leftOperand, offsets[0], options), operator: ast.operator.text, - rightOperand: new VersionExpression( - ast.rightOperand, - childrenOffsets.shift(), - options - ) + rightOperand: new VersionExpression(ast.rightOperand, offsets[1], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/WhileStatement.js b/src/slang-nodes/WhileStatement.js index 17607df55..c24a22898 100644 --- a/src/slang-nodes/WhileStatement.js +++ b/src/slang-nodes/WhileStatement.js @@ -25,16 +25,12 @@ export class WhileStatement extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ whileKeyword: ast.whileKeyword.text, openParen: ast.openParen.text, - condition: new Expression( - ast.condition, - childrenOffsets.shift(), - options - ), + condition: new Expression(ast.condition, offsets[0], options), closeParen: ast.closeParen.text, - body: new Statement(ast.body, childrenOffsets.shift(), options) + body: new Statement(ast.body, offsets[1], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/YulArguments.js b/src/slang-nodes/YulArguments.js index 67db7ace3..81f6c3c0c 100644 --- a/src/slang-nodes/YulArguments.js +++ b/src/slang-nodes/YulArguments.js @@ -15,9 +15,9 @@ export class YulArguments extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => new YulExpression(item, childrenOffsets.shift(), options) + (item, index) => new YulExpression(item, offsets[index], options) ), separators: ast.separators.map((separator) => separator.text) }); diff --git a/src/slang-nodes/YulAssignmentOperator.js b/src/slang-nodes/YulAssignmentOperator.js index 7b6bfc67d..8a733d98b 100644 --- a/src/slang-nodes/YulAssignmentOperator.js +++ b/src/slang-nodes/YulAssignmentOperator.js @@ -12,11 +12,11 @@ export class YulAssignmentOperator extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text - : new YulColonEqual(ast.variant, childrenOffsets.shift(), options) + : new YulColonEqual(ast.variant, offsets[0], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/YulBlock.js b/src/slang-nodes/YulBlock.js index ac9a5dc59..2676329f2 100644 --- a/src/slang-nodes/YulBlock.js +++ b/src/slang-nodes/YulBlock.js @@ -16,13 +16,9 @@ export class YulBlock extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ openBrace: ast.openBrace.text, - statements: new YulStatements( - ast.statements, - childrenOffsets.shift(), - options - ), + statements: new YulStatements(ast.statements, offsets[0], options), closeBrace: ast.closeBrace.text }); diff --git a/src/slang-nodes/YulDefaultCase.js b/src/slang-nodes/YulDefaultCase.js index c656fabe8..990631e80 100644 --- a/src/slang-nodes/YulDefaultCase.js +++ b/src/slang-nodes/YulDefaultCase.js @@ -14,9 +14,9 @@ export class YulDefaultCase extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ defaultKeyword: ast.defaultKeyword.text, - body: new YulBlock(ast.body, childrenOffsets.shift(), options) + body: new YulBlock(ast.body, offsets[0], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/YulExpression.js b/src/slang-nodes/YulExpression.js index fd751f9ae..1c1d42cc8 100644 --- a/src/slang-nodes/YulExpression.js +++ b/src/slang-nodes/YulExpression.js @@ -22,10 +22,10 @@ export class YulExpression extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ variant: new variants[ast.variant.cst.kind]( ast.variant, - childrenOffsets.shift(), + offsets[0], options ) }); diff --git a/src/slang-nodes/YulForStatement.js b/src/slang-nodes/YulForStatement.js index d4e22fe59..7dba95860 100644 --- a/src/slang-nodes/YulForStatement.js +++ b/src/slang-nodes/YulForStatement.js @@ -21,20 +21,12 @@ export class YulForStatement extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ forKeyword: ast.forKeyword.text, - initialization: new YulBlock( - ast.initialization, - childrenOffsets.shift(), - options - ), - condition: new YulExpression( - ast.condition, - childrenOffsets.shift(), - options - ), - iterator: new YulBlock(ast.iterator, childrenOffsets.shift(), options), - body: new YulBlock(ast.body, childrenOffsets.shift(), options) + initialization: new YulBlock(ast.initialization, offsets[0], options), + condition: new YulExpression(ast.condition, offsets[1], options), + iterator: new YulBlock(ast.iterator, offsets[2], options), + body: new YulBlock(ast.body, offsets[3], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/YulFunctionCallExpression.js b/src/slang-nodes/YulFunctionCallExpression.js index 1a86b6485..752bc14bd 100644 --- a/src/slang-nodes/YulFunctionCallExpression.js +++ b/src/slang-nodes/YulFunctionCallExpression.js @@ -19,14 +19,10 @@ export class YulFunctionCallExpression extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - operand: new YulExpression(ast.operand, childrenOffsets.shift(), options), + const fetch = (offsets) => ({ + operand: new YulExpression(ast.operand, offsets[0], options), openParen: ast.openParen.text, - arguments: new YulArguments( - ast.arguments, - childrenOffsets.shift(), - options - ), + arguments: new YulArguments(ast.arguments, offsets[1], options), closeParen: ast.closeParen.text }); diff --git a/src/slang-nodes/YulFunctionDefinition.js b/src/slang-nodes/YulFunctionDefinition.js index 933ca2391..beebaf025 100644 --- a/src/slang-nodes/YulFunctionDefinition.js +++ b/src/slang-nodes/YulFunctionDefinition.js @@ -22,23 +22,23 @@ export class YulFunctionDefinition extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - functionKeyword: ast.functionKeyword.text, - name: ast.name.text, - parameters: new YulParametersDeclaration( - ast.parameters, - childrenOffsets.shift(), - options - ), - returns: ast.returns - ? new YulReturnsDeclaration( - ast.returns, - childrenOffsets.shift(), - options - ) - : undefined, - body: new YulBlock(ast.body, childrenOffsets.shift(), options) - }); + const fetch = (offsets) => { + let i = 0; + const children = { + functionKeyword: ast.functionKeyword.text, + name: ast.name.text, + parameters: new YulParametersDeclaration( + ast.parameters, + offsets[0], + options + ), + returns: ast.returns + ? new YulReturnsDeclaration(ast.returns, offsets[(i += 1)], options) + : undefined, + body: new YulBlock(ast.body, offsets[(i += 1)], options) + }; + return children; + }; this.initialize(ast, offset, fetch); } diff --git a/src/slang-nodes/YulIfStatement.js b/src/slang-nodes/YulIfStatement.js index ec51a849c..7d475c694 100644 --- a/src/slang-nodes/YulIfStatement.js +++ b/src/slang-nodes/YulIfStatement.js @@ -17,14 +17,10 @@ export class YulIfStatement extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ ifKeyword: ast.ifKeyword.text, - condition: new YulExpression( - ast.condition, - childrenOffsets.shift(), - options - ), - body: new YulBlock(ast.body, childrenOffsets.shift(), options) + condition: new YulExpression(ast.condition, offsets[0], options), + body: new YulBlock(ast.body, offsets[1], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/YulLiteral.js b/src/slang-nodes/YulLiteral.js index efb3639b0..c64e543c9 100644 --- a/src/slang-nodes/YulLiteral.js +++ b/src/slang-nodes/YulLiteral.js @@ -15,15 +15,11 @@ export class YulLiteral extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ variant: ast.variant.type === 'Terminal' ? ast.variant.text - : new variants[ast.variant.cst.kind]( - ast.variant, - childrenOffsets.shift(), - options - ) + : new variants[ast.variant.cst.kind](ast.variant, offsets[0], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/YulParametersDeclaration.js b/src/slang-nodes/YulParametersDeclaration.js index 6a7989712..1621cf327 100644 --- a/src/slang-nodes/YulParametersDeclaration.js +++ b/src/slang-nodes/YulParametersDeclaration.js @@ -16,13 +16,9 @@ export class YulParametersDeclaration extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ openParen: ast.openParen.text, - parameters: new YulParameters( - ast.parameters, - childrenOffsets.shift(), - options - ), + parameters: new YulParameters(ast.parameters, offsets[0], options), closeParen: ast.closeParen.text }); diff --git a/src/slang-nodes/YulPath.js b/src/slang-nodes/YulPath.js index a6e010b1c..425e62110 100644 --- a/src/slang-nodes/YulPath.js +++ b/src/slang-nodes/YulPath.js @@ -14,9 +14,9 @@ export class YulPath extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => new YulPathComponent(item, childrenOffsets.shift(), options) + (item, index) => new YulPathComponent(item, offsets[index], options) ), separators: ast.separators.map((separator) => separator.text) }); diff --git a/src/slang-nodes/YulPaths.js b/src/slang-nodes/YulPaths.js index c54221ad9..5581fbd29 100644 --- a/src/slang-nodes/YulPaths.js +++ b/src/slang-nodes/YulPaths.js @@ -14,9 +14,9 @@ export class YulPaths extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => new YulPath(item, childrenOffsets.shift(), options) + (item, index) => new YulPath(item, offsets[index], options) ), separators: ast.separators.map((separator) => separator.text) }); diff --git a/src/slang-nodes/YulReturnsDeclaration.js b/src/slang-nodes/YulReturnsDeclaration.js index 4b9c250a7..87b77e6e2 100644 --- a/src/slang-nodes/YulReturnsDeclaration.js +++ b/src/slang-nodes/YulReturnsDeclaration.js @@ -18,13 +18,9 @@ export class YulReturnsDeclaration extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ minusGreaterThan: ast.minusGreaterThan.text, - variables: new YulReturnVariables( - ast.variables, - childrenOffsets.shift(), - options - ) + variables: new YulReturnVariables(ast.variables, offsets[0], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/YulStackAssignmentStatement.js b/src/slang-nodes/YulStackAssignmentStatement.js index 374e332ce..a99a0db7e 100644 --- a/src/slang-nodes/YulStackAssignmentStatement.js +++ b/src/slang-nodes/YulStackAssignmentStatement.js @@ -15,17 +15,13 @@ export class YulStackAssignmentStatement extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ assignment: new YulAssignmentOperator( ast.assignment, - childrenOffsets.shift(), + offsets[0], options ), - expression: new YulExpression( - ast.expression, - childrenOffsets.shift(), - options - ) + expression: new YulExpression(ast.expression, offsets[1], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/YulStatement.js b/src/slang-nodes/YulStatement.js index c17d4c224..3204e58a0 100644 --- a/src/slang-nodes/YulStatement.js +++ b/src/slang-nodes/YulStatement.js @@ -40,10 +40,10 @@ export class YulStatement extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ variant: new variants[ast.variant.cst.kind]( ast.variant, - childrenOffsets.shift(), + offsets[0], options ) }); diff --git a/src/slang-nodes/YulStatements.js b/src/slang-nodes/YulStatements.js index a055d975c..d41c1ae10 100644 --- a/src/slang-nodes/YulStatements.js +++ b/src/slang-nodes/YulStatements.js @@ -18,9 +18,9 @@ export class YulStatements extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => new YulStatement(item, childrenOffsets.shift(), options) + (item, index) => new YulStatement(item, offsets[index], options) ) }); diff --git a/src/slang-nodes/YulSwitchCase.js b/src/slang-nodes/YulSwitchCase.js index a381c8513..f36bb16c4 100644 --- a/src/slang-nodes/YulSwitchCase.js +++ b/src/slang-nodes/YulSwitchCase.js @@ -14,10 +14,10 @@ export class YulSwitchCase extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ variant: new variants[ast.variant.cst.kind]( ast.variant, - childrenOffsets.shift(), + offsets[0], options ) }); diff --git a/src/slang-nodes/YulSwitchCases.js b/src/slang-nodes/YulSwitchCases.js index 8d6670ec0..d064fb7f6 100644 --- a/src/slang-nodes/YulSwitchCases.js +++ b/src/slang-nodes/YulSwitchCases.js @@ -15,9 +15,9 @@ export class YulSwitchCases extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ items: ast.items.map( - (item) => new YulSwitchCase(item, childrenOffsets.shift(), options) + (item, index) => new YulSwitchCase(item, offsets[index], options) ) }); diff --git a/src/slang-nodes/YulSwitchStatement.js b/src/slang-nodes/YulSwitchStatement.js index 880763944..4318599e7 100644 --- a/src/slang-nodes/YulSwitchStatement.js +++ b/src/slang-nodes/YulSwitchStatement.js @@ -20,14 +20,10 @@ export class YulSwitchStatement extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ switchKeyword: ast.switchKeyword.text, - expression: new YulExpression( - ast.expression, - childrenOffsets.shift(), - options - ), - cases: new YulSwitchCases(ast.cases, childrenOffsets.shift(), options) + expression: new YulExpression(ast.expression, offsets[0], options), + cases: new YulSwitchCases(ast.cases, offsets[1], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/YulValueCase.js b/src/slang-nodes/YulValueCase.js index f3147874f..e13d8a7b1 100644 --- a/src/slang-nodes/YulValueCase.js +++ b/src/slang-nodes/YulValueCase.js @@ -17,10 +17,10 @@ export class YulValueCase extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ caseKeyword: ast.caseKeyword.text, - value: new YulLiteral(ast.value, childrenOffsets.shift(), options), - body: new YulBlock(ast.body, childrenOffsets.shift(), options) + value: new YulLiteral(ast.value, offsets[0], options), + body: new YulBlock(ast.body, offsets[1], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/YulVariableAssignmentStatement.js b/src/slang-nodes/YulVariableAssignmentStatement.js index 29d48b5c5..38d9dcd75 100644 --- a/src/slang-nodes/YulVariableAssignmentStatement.js +++ b/src/slang-nodes/YulVariableAssignmentStatement.js @@ -18,18 +18,14 @@ export class YulVariableAssignmentStatement extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ - names: new YulPaths(ast.names, childrenOffsets.shift(), options), + const fetch = (offsets) => ({ + names: new YulPaths(ast.names, offsets[0], options), assignment: new YulAssignmentOperator( ast.assignment, - childrenOffsets.shift(), + offsets[1], options ), - expression: new YulExpression( - ast.expression, - childrenOffsets.shift(), - options - ) + expression: new YulExpression(ast.expression, offsets[2], options) }); this.initialize(ast, offset, fetch); diff --git a/src/slang-nodes/YulVariableDeclarationStatement.js b/src/slang-nodes/YulVariableDeclarationStatement.js index d6959afa4..7b83d0b57 100644 --- a/src/slang-nodes/YulVariableDeclarationStatement.js +++ b/src/slang-nodes/YulVariableDeclarationStatement.js @@ -16,15 +16,11 @@ export class YulVariableDeclarationStatement extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ letKeyword: ast.letKeyword.text, names: ast.names.text, value: ast.value - ? new YulVariableDeclarationValue( - ast.value, - childrenOffsets.shift(), - options - ) + ? new YulVariableDeclarationValue(ast.value, offsets[0], options) : undefined }); diff --git a/src/slang-nodes/YulVariableDeclarationValue.js b/src/slang-nodes/YulVariableDeclarationValue.js index 8345ec75b..3276caf03 100644 --- a/src/slang-nodes/YulVariableDeclarationValue.js +++ b/src/slang-nodes/YulVariableDeclarationValue.js @@ -15,17 +15,13 @@ export class YulVariableDeclarationValue extends SlangNode { constructor(ast, offset, options) { super(); - const fetch = (childrenOffsets) => ({ + const fetch = (offsets) => ({ assignment: new YulAssignmentOperator( ast.assignment, - childrenOffsets.shift(), + offsets[0], options ), - expression: new YulExpression( - ast.expression, - childrenOffsets.shift(), - options - ) + expression: new YulExpression(ast.expression, offsets[1], options) }); this.initialize(ast, offset, fetch); From 5877e753481a0e5f600aa4be3315bd7e8c412375 Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 24 Jul 2024 08:05:14 +1200 Subject: [PATCH 098/160] reorganise how we access the leading and trailing offsets --- src/slang-nodes/SlangNode.js | 24 ++++++++++++------------ src/slang-utils/get-offsets.js | 4 ---- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/slang-nodes/SlangNode.js b/src/slang-nodes/SlangNode.js index e18878f68..707c07219 100644 --- a/src/slang-nodes/SlangNode.js +++ b/src/slang-nodes/SlangNode.js @@ -1,7 +1,6 @@ import { getChildrenOffsets, - getLeadingOffset, - getTrailingOffset + getLeadingOffset } from '../slang-utils/get-offsets.js'; const isNotStringOrUndefined = (node) => @@ -50,38 +49,39 @@ export class SlangNode { }); // calculate correct loc object + const leadingOffset = getLeadingOffset(cstChildren); + const trailingOffset = getLeadingOffset(cstChildren.reverse()); this.loc = { - start: offset, - end: offset + ast.cst.textLength.utf8, - leadingOffset: getLeadingOffset(cstChildren), - trailingOffset: getTrailingOffset(cstChildren) + start: offset + leadingOffset, + end: offset + ast.cst.textLength.utf8 - trailingOffset, + leadingOffset, + trailingOffset }; - if (this.loc.leadingOffset === 0 || this.loc.trailingOffset === 0) { + if (leadingOffset === 0 || trailingOffset === 0) { for (let i = 0; i < propertyKeys.length; i += 1) { const childLoc = properties[propertyKeys[i]]?.loc; if (childLoc) { if ( - this.loc.leadingOffset === 0 && + leadingOffset === 0 && childLoc.start - childLoc.leadingOffset === this.loc.start ) { this.loc.leadingOffset = childLoc.leadingOffset; + this.loc.start += childLoc.leadingOffset; } if ( - this.loc.trailingOffset === 0 && + trailingOffset === 0 && childLoc.end + childLoc.trailingOffset === this.loc.end ) { this.loc.trailingOffset = childLoc.trailingOffset; + this.loc.end -= childLoc.trailingOffset; } } } } - this.loc.start += this.loc.leadingOffset; - this.loc.end -= this.loc.trailingOffset; - if (typeof postProcess === 'function') { properties = postProcess(properties); } diff --git a/src/slang-utils/get-offsets.js b/src/slang-utils/get-offsets.js index 975faa3c8..416082559 100644 --- a/src/slang-utils/get-offsets.js +++ b/src/slang-utils/get-offsets.js @@ -51,7 +51,3 @@ export function getLeadingOffset(children) { } return offset; } - -export function getTrailingOffset(children) { - return getLeadingOffset(children.reverse()); -} From c4262c65b20881212084abfa4a6700c2b223fc10 Mon Sep 17 00:00:00 2001 From: Klaus Date: Tue, 30 Jul 2024 09:33:00 +1200 Subject: [PATCH 099/160] moving to TS --- .eslintignore | 3 +- .eslintrc | 40 +- .github/workflows/CI.yml | 2 +- jest.config.js | 15 +- package-lock.json | 519 +++++++++++++++++- package.json | 15 +- src/slang-nodes/ABICoderPragma.js | 27 - src/slang-nodes/ABICoderPragma.ts | 32 ++ src/slang-nodes/AdditiveExpression.js | 41 -- src/slang-nodes/AdditiveExpression.ts | 54 ++ src/slang-nodes/AddressType.js | 27 - src/slang-nodes/AddressType.ts | 32 ++ src/slang-nodes/AndExpression.js | 32 -- src/slang-nodes/AndExpression.ts | 44 ++ src/slang-nodes/ArgumentsDeclaration.js | 32 -- src/slang-nodes/ArgumentsDeclaration.ts | 55 ++ src/slang-nodes/ArrayExpression.js | 38 -- src/slang-nodes/ArrayExpression.ts | 50 ++ src/slang-nodes/ArrayTypeName.js | 42 -- src/slang-nodes/ArrayTypeName.ts | 50 ++ src/slang-nodes/ArrayValues.js | 31 -- src/slang-nodes/ArrayValues.ts | 39 ++ src/slang-nodes/AssemblyFlags.js | 31 -- src/slang-nodes/AssemblyFlags.ts | 39 ++ src/slang-nodes/AssemblyFlagsDeclaration.js | 31 -- src/slang-nodes/AssemblyFlagsDeclaration.ts | 43 ++ src/slang-nodes/AssemblyStatement.js | 49 -- src/slang-nodes/AssemblyStatement.ts | 60 ++ src/slang-nodes/AssignmentExpression.js | 41 -- src/slang-nodes/AssignmentExpression.ts | 53 ++ src/slang-nodes/BitwiseAndExpression.js | 41 -- src/slang-nodes/BitwiseAndExpression.ts | 54 ++ src/slang-nodes/BitwiseOrExpression.js | 51 -- src/slang-nodes/BitwiseOrExpression.ts | 64 +++ src/slang-nodes/BitwiseXorExpression.js | 41 -- src/slang-nodes/BitwiseXorExpression.ts | 54 ++ src/slang-nodes/Block.js | 31 -- src/slang-nodes/Block.ts | 39 ++ src/slang-nodes/BreakStatement.js | 27 - src/slang-nodes/BreakStatement.ts | 32 ++ src/slang-nodes/CallOptions.js | 36 -- src/slang-nodes/CallOptions.ts | 48 ++ src/slang-nodes/CallOptionsExpression.js | 40 -- src/slang-nodes/CallOptionsExpression.ts | 52 ++ src/slang-nodes/CatchClause.js | 42 -- src/slang-nodes/CatchClause.ts | 48 ++ src/slang-nodes/CatchClauseError.js | 31 -- src/slang-nodes/CatchClauseError.ts | 47 ++ src/slang-nodes/CatchClauses.js | 30 - src/slang-nodes/CatchClauses.ts | 38 ++ src/slang-nodes/ComparisonExpression.js | 32 -- src/slang-nodes/ComparisonExpression.ts | 48 ++ ...Expression.js => ConditionalExpression.ts} | 144 +++-- src/slang-nodes/ConstantDefinition.js | 42 -- src/slang-nodes/ConstantDefinition.ts | 58 ++ src/slang-nodes/ConstructorAttribute.js | 30 - src/slang-nodes/ConstructorAttribute.ts | 46 ++ src/slang-nodes/ConstructorAttributes.js | 31 -- src/slang-nodes/ConstructorAttributes.ts | 45 ++ src/slang-nodes/ConstructorDefinition.js | 45 -- src/slang-nodes/ConstructorDefinition.ts | 61 ++ src/slang-nodes/ContinueStatement.js | 27 - src/slang-nodes/ContinueStatement.ts | 32 ++ src/slang-nodes/ContractDefinition.js | 85 --- src/slang-nodes/ContractDefinition.ts | 96 ++++ src/slang-nodes/ContractMember.js | 57 -- src/slang-nodes/ContractMember.ts | 150 +++++ src/slang-nodes/ContractMembers.js | 42 -- src/slang-nodes/ContractMembers.ts | 58 ++ src/slang-nodes/DecimalNumberExpression.js | 28 - src/slang-nodes/DecimalNumberExpression.ts | 38 ++ src/slang-nodes/DoWhileStatement.js | 56 -- src/slang-nodes/DoWhileStatement.ts | 68 +++ src/slang-nodes/ElementaryType.js | 30 - src/slang-nodes/ElementaryType.ts | 42 ++ src/slang-nodes/ElseBranch.js | 39 -- src/slang-nodes/ElseBranch.ts | 47 ++ src/slang-nodes/EmitStatement.js | 40 -- src/slang-nodes/EmitStatement.ts | 52 ++ src/slang-nodes/EnumDefinition.js | 41 -- src/slang-nodes/EnumDefinition.ts | 49 ++ src/slang-nodes/EnumMembers.js | 31 -- src/slang-nodes/EnumMembers.ts | 36 ++ src/slang-nodes/EqualityExpression.js | 32 -- src/slang-nodes/EqualityExpression.ts | 48 ++ src/slang-nodes/ErrorDefinition.js | 38 -- src/slang-nodes/ErrorDefinition.ts | 54 ++ src/slang-nodes/ErrorParameter.js | 28 - src/slang-nodes/ErrorParameter.ts | 36 ++ src/slang-nodes/ErrorParameters.js | 33 -- src/slang-nodes/ErrorParameters.ts | 45 ++ src/slang-nodes/ErrorParametersDeclaration.js | 31 -- src/slang-nodes/ErrorParametersDeclaration.ts | 43 ++ src/slang-nodes/EventDefinition.js | 46 -- src/slang-nodes/EventDefinition.ts | 58 ++ src/slang-nodes/EventParameter.js | 35 -- src/slang-nodes/EventParameter.ts | 43 ++ src/slang-nodes/EventParameters.js | 33 -- src/slang-nodes/EventParameters.ts | 45 ++ src/slang-nodes/EventParametersDeclaration.js | 31 -- src/slang-nodes/EventParametersDeclaration.ts | 43 ++ src/slang-nodes/ExperimentalFeature.js | 30 - src/slang-nodes/ExperimentalFeature.ts | 46 ++ src/slang-nodes/ExperimentalPragma.js | 28 - src/slang-nodes/ExperimentalPragma.ts | 40 ++ ...ression.js => ExponentiationExpression.ts} | 80 ++- src/slang-nodes/Expression.js | 86 --- src/slang-nodes/Expression.ts | 286 ++++++++++ src/slang-nodes/ExpressionStatement.js | 28 - src/slang-nodes/ExpressionStatement.ts | 40 ++ src/slang-nodes/FallbackFunctionAttribute.js | 33 -- src/slang-nodes/FallbackFunctionAttribute.ts | 64 +++ src/slang-nodes/FallbackFunctionAttributes.js | 32 -- src/slang-nodes/FallbackFunctionAttributes.ts | 46 ++ src/slang-nodes/FallbackFunctionDefinition.js | 65 --- src/slang-nodes/FallbackFunctionDefinition.ts | 83 +++ src/slang-nodes/ForStatement.js | 80 --- src/slang-nodes/ForStatement.ts | 91 +++ src/slang-nodes/ForStatementCondition.js | 30 - src/slang-nodes/ForStatementCondition.ts | 46 ++ src/slang-nodes/ForStatementInitialization.js | 38 -- src/slang-nodes/ForStatementInitialization.ts | 77 +++ src/slang-nodes/FunctionAttribute.js | 33 -- src/slang-nodes/FunctionAttribute.ts | 64 +++ src/slang-nodes/FunctionAttributes.js | 31 -- src/slang-nodes/FunctionAttributes.ts | 45 ++ src/slang-nodes/FunctionBody.js | 30 - src/slang-nodes/FunctionBody.ts | 42 ++ src/slang-nodes/FunctionCallExpression.js | 51 -- src/slang-nodes/FunctionCallExpression.ts | 67 +++ src/slang-nodes/FunctionDefinition.js | 77 --- src/slang-nodes/FunctionDefinition.ts | 100 ++++ src/slang-nodes/FunctionName.js | 24 - src/slang-nodes/FunctionName.ts | 29 + src/slang-nodes/FunctionType.js | 47 -- src/slang-nodes/FunctionType.ts | 55 ++ src/slang-nodes/FunctionTypeAttribute.js | 24 - src/slang-nodes/FunctionTypeAttribute.ts | 29 + src/slang-nodes/FunctionTypeAttributes.js | 32 -- src/slang-nodes/FunctionTypeAttributes.ts | 41 ++ src/slang-nodes/HexNumberExpression.js | 28 - src/slang-nodes/HexNumberExpression.ts | 38 ++ src/slang-nodes/HexStringLiteral.js | 29 - src/slang-nodes/HexStringLiteral.ts | 36 ++ src/slang-nodes/HexStringLiterals.js | 30 - src/slang-nodes/HexStringLiterals.ts | 42 ++ src/slang-nodes/IdentifierPath.js | 29 - src/slang-nodes/IdentifierPath.ts | 34 ++ src/slang-nodes/IfStatement.js | 65 --- src/slang-nodes/IfStatement.ts | 77 +++ src/slang-nodes/ImportAlias.js | 27 - src/slang-nodes/ImportAlias.ts | 32 ++ src/slang-nodes/ImportClause.js | 33 -- src/slang-nodes/ImportClause.ts | 60 ++ src/slang-nodes/ImportDeconstruction.js | 47 -- src/slang-nodes/ImportDeconstruction.ts | 55 ++ src/slang-nodes/ImportDeconstructionSymbol.js | 30 - src/slang-nodes/ImportDeconstructionSymbol.ts | 38 ++ .../ImportDeconstructionSymbols.js | 55 -- .../ImportDeconstructionSymbols.ts | 66 +++ src/slang-nodes/ImportDirective.js | 35 -- src/slang-nodes/ImportDirective.ts | 47 ++ src/slang-nodes/IndexAccessEnd.js | 28 - src/slang-nodes/IndexAccessEnd.ts | 38 ++ src/slang-nodes/IndexAccessExpression.js | 77 --- src/slang-nodes/IndexAccessExpression.ts | 87 +++ src/slang-nodes/InheritanceSpecifier.js | 28 - src/slang-nodes/InheritanceSpecifier.ts | 40 ++ src/slang-nodes/InheritanceType.js | 34 -- src/slang-nodes/InheritanceType.ts | 50 ++ src/slang-nodes/InheritanceTypes.js | 36 -- src/slang-nodes/InheritanceTypes.ts | 48 ++ src/slang-nodes/InterfaceDefinition.js | 62 --- src/slang-nodes/InterfaceDefinition.ts | 72 +++ src/slang-nodes/InterfaceMembers.js | 37 -- src/slang-nodes/InterfaceMembers.ts | 53 ++ src/slang-nodes/LibraryDefinition.js | 44 -- src/slang-nodes/LibraryDefinition.ts | 56 ++ src/slang-nodes/LibraryMembers.js | 37 -- src/slang-nodes/LibraryMembers.ts | 49 ++ src/slang-nodes/MappingKey.js | 28 - src/slang-nodes/MappingKey.ts | 36 ++ src/slang-nodes/MappingKeyType.js | 32 -- src/slang-nodes/MappingKeyType.ts | 49 ++ src/slang-nodes/MappingType.js | 47 -- src/slang-nodes/MappingType.ts | 55 ++ src/slang-nodes/MappingValue.js | 28 - src/slang-nodes/MappingValue.ts | 36 ++ src/slang-nodes/MemberAccess.js | 24 - src/slang-nodes/MemberAccess.ts | 29 + ...xpression.js => MemberAccessExpression.ts} | 52 +- src/slang-nodes/ModifierAttribute.js | 30 - src/slang-nodes/ModifierAttribute.ts | 42 ++ src/slang-nodes/ModifierAttributes.js | 31 -- src/slang-nodes/ModifierAttributes.ts | 41 ++ src/slang-nodes/ModifierDefinition.js | 89 --- src/slang-nodes/ModifierDefinition.ts | 99 ++++ src/slang-nodes/ModifierInvocation.js | 46 -- src/slang-nodes/ModifierInvocation.ts | 61 ++ src/slang-nodes/MultiplicativeExpression.js | 60 -- src/slang-nodes/MultiplicativeExpression.ts | 67 +++ src/slang-nodes/NamedArgument.js | 31 -- src/slang-nodes/NamedArgument.ts | 39 ++ src/slang-nodes/NamedArgumentGroup.js | 31 -- src/slang-nodes/NamedArgumentGroup.ts | 43 ++ src/slang-nodes/NamedArguments.js | 36 -- src/slang-nodes/NamedArguments.ts | 48 ++ src/slang-nodes/NamedArgumentsDeclaration.js | 37 -- src/slang-nodes/NamedArgumentsDeclaration.ts | 53 ++ src/slang-nodes/NamedImport.js | 40 -- src/slang-nodes/NamedImport.ts | 48 ++ src/slang-nodes/NewExpression.js | 28 - src/slang-nodes/NewExpression.ts | 36 ++ src/slang-nodes/NumberUnit.js | 24 - src/slang-nodes/NumberUnit.ts | 29 + src/slang-nodes/OrExpression.js | 41 -- src/slang-nodes/OrExpression.ts | 50 ++ src/slang-nodes/OverridePaths.js | 31 -- src/slang-nodes/OverridePaths.ts | 43 ++ src/slang-nodes/OverridePathsDeclaration.js | 32 -- src/slang-nodes/OverridePathsDeclaration.ts | 44 ++ src/slang-nodes/OverrideSpecifier.js | 33 -- src/slang-nodes/OverrideSpecifier.ts | 44 ++ src/slang-nodes/Parameter.js | 41 -- src/slang-nodes/Parameter.ts | 52 ++ src/slang-nodes/Parameters.js | 43 -- src/slang-nodes/Parameters.ts | 53 ++ src/slang-nodes/ParametersDeclaration.js | 31 -- src/slang-nodes/ParametersDeclaration.ts | 43 ++ src/slang-nodes/PathImport.js | 34 -- src/slang-nodes/PathImport.ts | 42 ++ src/slang-nodes/PositionalArguments.js | 33 -- src/slang-nodes/PositionalArguments.ts | 45 ++ .../PositionalArgumentsDeclaration.js | 31 -- .../PositionalArgumentsDeclaration.ts | 47 ++ src/slang-nodes/PostfixExpression.js | 28 - src/slang-nodes/PostfixExpression.ts | 40 ++ src/slang-nodes/Pragma.js | 32 -- src/slang-nodes/Pragma.ts | 58 ++ src/slang-nodes/PragmaDirective.js | 35 -- src/slang-nodes/PragmaDirective.ts | 47 ++ src/slang-nodes/PrefixExpression.js | 28 - src/slang-nodes/PrefixExpression.ts | 40 ++ src/slang-nodes/ReceiveFunctionAttribute.js | 33 -- src/slang-nodes/ReceiveFunctionAttribute.ts | 64 +++ src/slang-nodes/ReceiveFunctionAttributes.js | 32 -- src/slang-nodes/ReceiveFunctionAttributes.ts | 46 ++ src/slang-nodes/ReceiveFunctionDefinition.js | 55 -- src/slang-nodes/ReceiveFunctionDefinition.ts | 74 +++ src/slang-nodes/ReturnStatement.js | 52 -- src/slang-nodes/ReturnStatement.ts | 73 +++ src/slang-nodes/ReturnsDeclaration.js | 31 -- src/slang-nodes/ReturnsDeclaration.ts | 47 ++ src/slang-nodes/RevertStatement.js | 50 -- src/slang-nodes/RevertStatement.ts | 60 ++ src/slang-nodes/ShiftExpression.js | 50 -- src/slang-nodes/ShiftExpression.ts | 63 +++ src/slang-nodes/SlangNode.js | 93 ---- src/slang-nodes/SourceUnit.js | 26 - src/slang-nodes/SourceUnit.ts | 40 ++ src/slang-nodes/SourceUnitMember.js | 56 -- src/slang-nodes/SourceUnitMember.ts | 154 ++++++ src/slang-nodes/SourceUnitMembers.js | 28 - src/slang-nodes/SourceUnitMembers.ts | 44 ++ src/slang-nodes/StateVariableAttribute.js | 30 - src/slang-nodes/StateVariableAttribute.ts | 42 ++ src/slang-nodes/StateVariableAttributes.js | 30 - src/slang-nodes/StateVariableAttributes.ts | 37 ++ src/slang-nodes/StateVariableDefinition.js | 51 -- src/slang-nodes/StateVariableDefinition.ts | 63 +++ .../StateVariableDefinitionValue.js | 33 -- .../StateVariableDefinitionValue.ts | 46 ++ src/slang-nodes/Statement.js | 65 --- src/slang-nodes/Statement.ts | 181 ++++++ src/slang-nodes/Statements.js | 45 -- src/slang-nodes/Statements.ts | 57 ++ src/slang-nodes/StorageLocation.js | 24 - src/slang-nodes/StorageLocation.ts | 29 + src/slang-nodes/StringExpression.js | 41 -- src/slang-nodes/StringExpression.ts | 85 +++ src/slang-nodes/StringLiteral.js | 29 - src/slang-nodes/StringLiteral.ts | 32 ++ src/slang-nodes/StringLiterals.js | 30 - src/slang-nodes/StringLiterals.ts | 38 ++ src/slang-nodes/StructDefinition.js | 41 -- src/slang-nodes/StructDefinition.ts | 53 ++ src/slang-nodes/StructMember.js | 31 -- src/slang-nodes/StructMember.ts | 39 ++ src/slang-nodes/StructMembers.js | 36 -- src/slang-nodes/StructMembers.ts | 44 ++ src/slang-nodes/ThrowStatement.js | 28 - src/slang-nodes/ThrowStatement.ts | 32 ++ src/slang-nodes/TryStatement.js | 63 --- src/slang-nodes/TryStatement.ts | 71 +++ src/slang-nodes/TupleDeconstructionElement.js | 27 - src/slang-nodes/TupleDeconstructionElement.ts | 39 ++ .../TupleDeconstructionElements.js | 32 -- .../TupleDeconstructionElements.ts | 44 ++ .../TupleDeconstructionStatement.js | 61 -- .../TupleDeconstructionStatement.ts | 74 +++ src/slang-nodes/TupleExpression.js | 31 -- src/slang-nodes/TupleExpression.ts | 43 ++ src/slang-nodes/TupleMember.js | 32 -- src/slang-nodes/TupleMember.ts | 50 ++ src/slang-nodes/TupleValue.js | 27 - src/slang-nodes/TupleValue.ts | 35 ++ src/slang-nodes/TupleValues.js | 35 -- src/slang-nodes/TupleValues.ts | 43 ++ src/slang-nodes/TypeExpression.js | 35 -- src/slang-nodes/TypeExpression.ts | 47 ++ src/slang-nodes/TypeName.js | 41 -- src/slang-nodes/TypeName.ts | 81 +++ src/slang-nodes/TypedTupleMember.js | 38 -- src/slang-nodes/TypedTupleMember.ts | 53 ++ src/slang-nodes/UncheckedBlock.js | 28 - src/slang-nodes/UncheckedBlock.ts | 36 ++ src/slang-nodes/UnicodeStringLiteral.js | 29 - src/slang-nodes/UnicodeStringLiteral.ts | 36 ++ src/slang-nodes/UnicodeStringLiterals.js | 30 - src/slang-nodes/UnicodeStringLiterals.ts | 42 ++ src/slang-nodes/UnnamedFunctionAttribute.js | 30 - src/slang-nodes/UnnamedFunctionAttribute.ts | 46 ++ src/slang-nodes/UnnamedFunctionAttributes.js | 32 -- src/slang-nodes/UnnamedFunctionAttributes.ts | 46 ++ src/slang-nodes/UnnamedFunctionDefinition.js | 55 -- src/slang-nodes/UnnamedFunctionDefinition.ts | 71 +++ src/slang-nodes/UntypedTupleMember.js | 31 -- src/slang-nodes/UntypedTupleMember.ts | 46 ++ .../UserDefinedValueTypeDefinition.js | 41 -- .../UserDefinedValueTypeDefinition.ts | 49 ++ src/slang-nodes/UsingAlias.js | 28 - src/slang-nodes/UsingAlias.ts | 36 ++ src/slang-nodes/UsingClause.js | 32 -- src/slang-nodes/UsingClause.ts | 52 ++ src/slang-nodes/UsingDeconstruction.js | 31 -- src/slang-nodes/UsingDeconstruction.ts | 39 ++ src/slang-nodes/UsingDeconstructionSymbol.js | 34 -- src/slang-nodes/UsingDeconstructionSymbol.ts | 42 ++ src/slang-nodes/UsingDeconstructionSymbols.js | 37 -- src/slang-nodes/UsingDeconstructionSymbols.ts | 48 ++ src/slang-nodes/UsingDirective.js | 47 -- src/slang-nodes/UsingDirective.ts | 55 ++ src/slang-nodes/UsingOperator.js | 24 - src/slang-nodes/UsingOperator.ts | 29 + src/slang-nodes/UsingTarget.js | 30 - src/slang-nodes/UsingTarget.ts | 42 ++ .../VariableDeclarationStatement.js | 73 --- .../VariableDeclarationStatement.ts | 89 +++ src/slang-nodes/VariableDeclarationType.js | 30 - src/slang-nodes/VariableDeclarationType.ts | 46 ++ src/slang-nodes/VariableDeclarationValue.js | 28 - src/slang-nodes/VariableDeclarationValue.ts | 40 ++ src/slang-nodes/VersionComparator.js | 28 - src/slang-nodes/VersionComparator.ts | 40 ++ src/slang-nodes/VersionExpression.js | 38 -- src/slang-nodes/VersionExpression.ts | 72 +++ src/slang-nodes/VersionExpressionSet.js | 30 - src/slang-nodes/VersionExpressionSet.ts | 42 ++ src/slang-nodes/VersionExpressionSets.js | 34 -- src/slang-nodes/VersionExpressionSets.ts | 46 ++ src/slang-nodes/VersionPragma.js | 28 - src/slang-nodes/VersionPragma.ts | 36 ++ src/slang-nodes/VersionRange.js | 32 -- src/slang-nodes/VersionRange.ts | 52 ++ src/slang-nodes/VersionSpecifiers.js | 29 - src/slang-nodes/VersionSpecifiers.ts | 34 ++ src/slang-nodes/WhileStatement.js | 49 -- src/slang-nodes/WhileStatement.ts | 57 ++ src/slang-nodes/YulArguments.js | 31 -- src/slang-nodes/YulArguments.ts | 39 ++ src/slang-nodes/YulAssignmentOperator.js | 30 - src/slang-nodes/YulAssignmentOperator.ts | 42 ++ src/slang-nodes/YulBlock.js | 31 -- src/slang-nodes/YulBlock.ts | 39 ++ src/slang-nodes/YulBreakStatement.js | 24 - src/slang-nodes/YulBreakStatement.ts | 29 + src/slang-nodes/YulBuiltInFunction.js | 24 - src/slang-nodes/YulBuiltInFunction.ts | 29 + src/slang-nodes/YulColonEqual.js | 28 - src/slang-nodes/YulColonEqual.ts | 37 ++ src/slang-nodes/YulContinueStatement.js | 24 - src/slang-nodes/YulContinueStatement.ts | 29 + src/slang-nodes/YulDefaultCase.js | 28 - src/slang-nodes/YulDefaultCase.ts | 36 ++ src/slang-nodes/YulExpression.js | 39 -- src/slang-nodes/YulExpression.ts | 66 +++ src/slang-nodes/YulForStatement.js | 47 -- src/slang-nodes/YulForStatement.ts | 64 +++ src/slang-nodes/YulFunctionCallExpression.js | 40 -- src/slang-nodes/YulFunctionCallExpression.ts | 52 ++ src/slang-nodes/YulFunctionDefinition.js | 54 -- src/slang-nodes/YulFunctionDefinition.ts | 64 +++ src/slang-nodes/YulIfStatement.js | 37 -- src/slang-nodes/YulIfStatement.ts | 45 ++ src/slang-nodes/YulLabel.js | 30 - src/slang-nodes/YulLabel.ts | 35 ++ src/slang-nodes/YulLeaveStatement.js | 25 - src/slang-nodes/YulLeaveStatement.ts | 34 ++ src/slang-nodes/YulLiteral.js | 33 -- src/slang-nodes/YulLiteral.ts | 61 ++ src/slang-nodes/YulParameters.js | 28 - src/slang-nodes/YulParameters.ts | 33 ++ src/slang-nodes/YulParametersDeclaration.js | 31 -- src/slang-nodes/YulParametersDeclaration.ts | 39 ++ src/slang-nodes/YulPath.js | 34 -- src/slang-nodes/YulPath.ts | 42 ++ src/slang-nodes/YulPathComponent.js | 24 - src/slang-nodes/YulPathComponent.ts | 29 + src/slang-nodes/YulPaths.js | 34 -- src/slang-nodes/YulPaths.ts | 42 ++ src/slang-nodes/YulReturnVariables.js | 34 -- src/slang-nodes/YulReturnVariables.ts | 39 ++ src/slang-nodes/YulReturnsDeclaration.js | 37 -- src/slang-nodes/YulReturnsDeclaration.ts | 45 ++ .../YulStackAssignmentStatement.js | 34 -- .../YulStackAssignmentStatement.ts | 46 ++ src/slang-nodes/YulStatement.js | 57 -- src/slang-nodes/YulStatement.ts | 145 +++++ src/slang-nodes/YulStatements.js | 45 -- src/slang-nodes/YulStatements.ts | 57 ++ src/slang-nodes/YulSwitchCase.js | 31 -- src/slang-nodes/YulSwitchCase.ts | 51 ++ src/slang-nodes/YulSwitchCases.js | 30 - src/slang-nodes/YulSwitchCases.ts | 38 ++ src/slang-nodes/YulSwitchStatement.js | 40 -- src/slang-nodes/YulSwitchStatement.ts | 52 ++ src/slang-nodes/YulValueCase.js | 37 -- src/slang-nodes/YulValueCase.ts | 45 ++ .../YulVariableAssignmentStatement.js | 43 -- .../YulVariableAssignmentStatement.ts | 55 ++ .../YulVariableDeclarationStatement.js | 36 -- .../YulVariableDeclarationStatement.ts | 52 ++ .../YulVariableDeclarationValue.js | 37 -- .../YulVariableDeclarationValue.ts | 45 ++ src/slang-nodes/{index.js => index.ts} | 7 +- ....js => create-binary-operation-printer.ts} | 24 +- src/slang-printers/print-binary-operation.js | 45 -- src/slang-printers/print-binary-operation.ts | 51 ++ .../{print-comments.js => print-comments.ts} | 16 +- .../print-comparison-operation.js | 33 -- .../print-comparison-operation.ts | 39 ++ src/slang-printers/print-function.js | 20 - src/slang-printers/print-function.ts | 34 ++ src/slang-printers/print-logical-operation.js | 38 -- src/slang-printers/print-logical-operation.ts | 44 ++ ...nes.js => print-preserving-empty-lines.ts} | 12 +- src/slang-printers/print-separated-item.ts | 21 + src/slang-printers/print-separated-list.ts | 27 + .../{print-string.js => print-string.ts} | 12 +- src/slang-printers/types.d.ts | 15 + ...hug-function.js => create-hug-function.ts} | 19 +- src/slang-utils/get-offsets.js | 53 -- src/slang-utils/get-offsets.ts | 124 +++++ src/slang-utils/is-label.ts | 5 + src/slang-utils/loc.js | 7 - src/slang-utils/loc.ts | 9 + src/slang-utils/sort-function-attributes.js | 45 -- src/slang-utils/sort-function-attributes.ts | 46 ++ src/slang-utils/types.d.ts | 24 + src/slangPrinter.js | 7 +- src/types.d.ts | 518 +++++++++++++++++ tests/config/get-prettier.js | 2 +- tests/config/require-prettier.cjs | 5 - tsconfig.json | 17 + webpack.config.js | 17 + 465 files changed, 12783 insertions(+), 8384 deletions(-) delete mode 100644 src/slang-nodes/ABICoderPragma.js create mode 100644 src/slang-nodes/ABICoderPragma.ts delete mode 100644 src/slang-nodes/AdditiveExpression.js create mode 100644 src/slang-nodes/AdditiveExpression.ts delete mode 100644 src/slang-nodes/AddressType.js create mode 100644 src/slang-nodes/AddressType.ts delete mode 100644 src/slang-nodes/AndExpression.js create mode 100644 src/slang-nodes/AndExpression.ts delete mode 100644 src/slang-nodes/ArgumentsDeclaration.js create mode 100644 src/slang-nodes/ArgumentsDeclaration.ts delete mode 100644 src/slang-nodes/ArrayExpression.js create mode 100644 src/slang-nodes/ArrayExpression.ts delete mode 100644 src/slang-nodes/ArrayTypeName.js create mode 100644 src/slang-nodes/ArrayTypeName.ts delete mode 100644 src/slang-nodes/ArrayValues.js create mode 100644 src/slang-nodes/ArrayValues.ts delete mode 100644 src/slang-nodes/AssemblyFlags.js create mode 100644 src/slang-nodes/AssemblyFlags.ts delete mode 100644 src/slang-nodes/AssemblyFlagsDeclaration.js create mode 100644 src/slang-nodes/AssemblyFlagsDeclaration.ts delete mode 100644 src/slang-nodes/AssemblyStatement.js create mode 100644 src/slang-nodes/AssemblyStatement.ts delete mode 100644 src/slang-nodes/AssignmentExpression.js create mode 100644 src/slang-nodes/AssignmentExpression.ts delete mode 100644 src/slang-nodes/BitwiseAndExpression.js create mode 100644 src/slang-nodes/BitwiseAndExpression.ts delete mode 100644 src/slang-nodes/BitwiseOrExpression.js create mode 100644 src/slang-nodes/BitwiseOrExpression.ts delete mode 100644 src/slang-nodes/BitwiseXorExpression.js create mode 100644 src/slang-nodes/BitwiseXorExpression.ts delete mode 100644 src/slang-nodes/Block.js create mode 100644 src/slang-nodes/Block.ts delete mode 100644 src/slang-nodes/BreakStatement.js create mode 100644 src/slang-nodes/BreakStatement.ts delete mode 100644 src/slang-nodes/CallOptions.js create mode 100644 src/slang-nodes/CallOptions.ts delete mode 100644 src/slang-nodes/CallOptionsExpression.js create mode 100644 src/slang-nodes/CallOptionsExpression.ts delete mode 100644 src/slang-nodes/CatchClause.js create mode 100644 src/slang-nodes/CatchClause.ts delete mode 100644 src/slang-nodes/CatchClauseError.js create mode 100644 src/slang-nodes/CatchClauseError.ts delete mode 100644 src/slang-nodes/CatchClauses.js create mode 100644 src/slang-nodes/CatchClauses.ts delete mode 100644 src/slang-nodes/ComparisonExpression.js create mode 100644 src/slang-nodes/ComparisonExpression.ts rename src/slang-nodes/{ConditionalExpression.js => ConditionalExpression.ts} (50%) delete mode 100644 src/slang-nodes/ConstantDefinition.js create mode 100644 src/slang-nodes/ConstantDefinition.ts delete mode 100644 src/slang-nodes/ConstructorAttribute.js create mode 100644 src/slang-nodes/ConstructorAttribute.ts delete mode 100644 src/slang-nodes/ConstructorAttributes.js create mode 100644 src/slang-nodes/ConstructorAttributes.ts delete mode 100644 src/slang-nodes/ConstructorDefinition.js create mode 100644 src/slang-nodes/ConstructorDefinition.ts delete mode 100644 src/slang-nodes/ContinueStatement.js create mode 100644 src/slang-nodes/ContinueStatement.ts delete mode 100644 src/slang-nodes/ContractDefinition.js create mode 100644 src/slang-nodes/ContractDefinition.ts delete mode 100644 src/slang-nodes/ContractMember.js create mode 100644 src/slang-nodes/ContractMember.ts delete mode 100644 src/slang-nodes/ContractMembers.js create mode 100644 src/slang-nodes/ContractMembers.ts delete mode 100644 src/slang-nodes/DecimalNumberExpression.js create mode 100644 src/slang-nodes/DecimalNumberExpression.ts delete mode 100644 src/slang-nodes/DoWhileStatement.js create mode 100644 src/slang-nodes/DoWhileStatement.ts delete mode 100644 src/slang-nodes/ElementaryType.js create mode 100644 src/slang-nodes/ElementaryType.ts delete mode 100644 src/slang-nodes/ElseBranch.js create mode 100644 src/slang-nodes/ElseBranch.ts delete mode 100644 src/slang-nodes/EmitStatement.js create mode 100644 src/slang-nodes/EmitStatement.ts delete mode 100644 src/slang-nodes/EnumDefinition.js create mode 100644 src/slang-nodes/EnumDefinition.ts delete mode 100644 src/slang-nodes/EnumMembers.js create mode 100644 src/slang-nodes/EnumMembers.ts delete mode 100644 src/slang-nodes/EqualityExpression.js create mode 100644 src/slang-nodes/EqualityExpression.ts delete mode 100644 src/slang-nodes/ErrorDefinition.js create mode 100644 src/slang-nodes/ErrorDefinition.ts delete mode 100644 src/slang-nodes/ErrorParameter.js create mode 100644 src/slang-nodes/ErrorParameter.ts delete mode 100644 src/slang-nodes/ErrorParameters.js create mode 100644 src/slang-nodes/ErrorParameters.ts delete mode 100644 src/slang-nodes/ErrorParametersDeclaration.js create mode 100644 src/slang-nodes/ErrorParametersDeclaration.ts delete mode 100644 src/slang-nodes/EventDefinition.js create mode 100644 src/slang-nodes/EventDefinition.ts delete mode 100644 src/slang-nodes/EventParameter.js create mode 100644 src/slang-nodes/EventParameter.ts delete mode 100644 src/slang-nodes/EventParameters.js create mode 100644 src/slang-nodes/EventParameters.ts delete mode 100644 src/slang-nodes/EventParametersDeclaration.js create mode 100644 src/slang-nodes/EventParametersDeclaration.ts delete mode 100644 src/slang-nodes/ExperimentalFeature.js create mode 100644 src/slang-nodes/ExperimentalFeature.ts delete mode 100644 src/slang-nodes/ExperimentalPragma.js create mode 100644 src/slang-nodes/ExperimentalPragma.ts rename src/slang-nodes/{ExponentiationExpression.js => ExponentiationExpression.ts} (60%) delete mode 100644 src/slang-nodes/Expression.js create mode 100644 src/slang-nodes/Expression.ts delete mode 100644 src/slang-nodes/ExpressionStatement.js create mode 100644 src/slang-nodes/ExpressionStatement.ts delete mode 100644 src/slang-nodes/FallbackFunctionAttribute.js create mode 100644 src/slang-nodes/FallbackFunctionAttribute.ts delete mode 100644 src/slang-nodes/FallbackFunctionAttributes.js create mode 100644 src/slang-nodes/FallbackFunctionAttributes.ts delete mode 100644 src/slang-nodes/FallbackFunctionDefinition.js create mode 100644 src/slang-nodes/FallbackFunctionDefinition.ts delete mode 100644 src/slang-nodes/ForStatement.js create mode 100644 src/slang-nodes/ForStatement.ts delete mode 100644 src/slang-nodes/ForStatementCondition.js create mode 100644 src/slang-nodes/ForStatementCondition.ts delete mode 100644 src/slang-nodes/ForStatementInitialization.js create mode 100644 src/slang-nodes/ForStatementInitialization.ts delete mode 100644 src/slang-nodes/FunctionAttribute.js create mode 100644 src/slang-nodes/FunctionAttribute.ts delete mode 100644 src/slang-nodes/FunctionAttributes.js create mode 100644 src/slang-nodes/FunctionAttributes.ts delete mode 100644 src/slang-nodes/FunctionBody.js create mode 100644 src/slang-nodes/FunctionBody.ts delete mode 100644 src/slang-nodes/FunctionCallExpression.js create mode 100644 src/slang-nodes/FunctionCallExpression.ts delete mode 100644 src/slang-nodes/FunctionDefinition.js create mode 100644 src/slang-nodes/FunctionDefinition.ts delete mode 100644 src/slang-nodes/FunctionName.js create mode 100644 src/slang-nodes/FunctionName.ts delete mode 100644 src/slang-nodes/FunctionType.js create mode 100644 src/slang-nodes/FunctionType.ts delete mode 100644 src/slang-nodes/FunctionTypeAttribute.js create mode 100644 src/slang-nodes/FunctionTypeAttribute.ts delete mode 100644 src/slang-nodes/FunctionTypeAttributes.js create mode 100644 src/slang-nodes/FunctionTypeAttributes.ts delete mode 100644 src/slang-nodes/HexNumberExpression.js create mode 100644 src/slang-nodes/HexNumberExpression.ts delete mode 100644 src/slang-nodes/HexStringLiteral.js create mode 100644 src/slang-nodes/HexStringLiteral.ts delete mode 100644 src/slang-nodes/HexStringLiterals.js create mode 100644 src/slang-nodes/HexStringLiterals.ts delete mode 100644 src/slang-nodes/IdentifierPath.js create mode 100644 src/slang-nodes/IdentifierPath.ts delete mode 100644 src/slang-nodes/IfStatement.js create mode 100644 src/slang-nodes/IfStatement.ts delete mode 100644 src/slang-nodes/ImportAlias.js create mode 100644 src/slang-nodes/ImportAlias.ts delete mode 100644 src/slang-nodes/ImportClause.js create mode 100644 src/slang-nodes/ImportClause.ts delete mode 100644 src/slang-nodes/ImportDeconstruction.js create mode 100644 src/slang-nodes/ImportDeconstruction.ts delete mode 100644 src/slang-nodes/ImportDeconstructionSymbol.js create mode 100644 src/slang-nodes/ImportDeconstructionSymbol.ts delete mode 100644 src/slang-nodes/ImportDeconstructionSymbols.js create mode 100644 src/slang-nodes/ImportDeconstructionSymbols.ts delete mode 100644 src/slang-nodes/ImportDirective.js create mode 100644 src/slang-nodes/ImportDirective.ts delete mode 100644 src/slang-nodes/IndexAccessEnd.js create mode 100644 src/slang-nodes/IndexAccessEnd.ts delete mode 100644 src/slang-nodes/IndexAccessExpression.js create mode 100644 src/slang-nodes/IndexAccessExpression.ts delete mode 100644 src/slang-nodes/InheritanceSpecifier.js create mode 100644 src/slang-nodes/InheritanceSpecifier.ts delete mode 100644 src/slang-nodes/InheritanceType.js create mode 100644 src/slang-nodes/InheritanceType.ts delete mode 100644 src/slang-nodes/InheritanceTypes.js create mode 100644 src/slang-nodes/InheritanceTypes.ts delete mode 100644 src/slang-nodes/InterfaceDefinition.js create mode 100644 src/slang-nodes/InterfaceDefinition.ts delete mode 100644 src/slang-nodes/InterfaceMembers.js create mode 100644 src/slang-nodes/InterfaceMembers.ts delete mode 100644 src/slang-nodes/LibraryDefinition.js create mode 100644 src/slang-nodes/LibraryDefinition.ts delete mode 100644 src/slang-nodes/LibraryMembers.js create mode 100644 src/slang-nodes/LibraryMembers.ts delete mode 100644 src/slang-nodes/MappingKey.js create mode 100644 src/slang-nodes/MappingKey.ts delete mode 100644 src/slang-nodes/MappingKeyType.js create mode 100644 src/slang-nodes/MappingKeyType.ts delete mode 100644 src/slang-nodes/MappingType.js create mode 100644 src/slang-nodes/MappingType.ts delete mode 100644 src/slang-nodes/MappingValue.js create mode 100644 src/slang-nodes/MappingValue.ts delete mode 100644 src/slang-nodes/MemberAccess.js create mode 100644 src/slang-nodes/MemberAccess.ts rename src/slang-nodes/{MemberAccessExpression.js => MemberAccessExpression.ts} (75%) delete mode 100644 src/slang-nodes/ModifierAttribute.js create mode 100644 src/slang-nodes/ModifierAttribute.ts delete mode 100644 src/slang-nodes/ModifierAttributes.js create mode 100644 src/slang-nodes/ModifierAttributes.ts delete mode 100644 src/slang-nodes/ModifierDefinition.js create mode 100644 src/slang-nodes/ModifierDefinition.ts delete mode 100644 src/slang-nodes/ModifierInvocation.js create mode 100644 src/slang-nodes/ModifierInvocation.ts delete mode 100644 src/slang-nodes/MultiplicativeExpression.js create mode 100644 src/slang-nodes/MultiplicativeExpression.ts delete mode 100644 src/slang-nodes/NamedArgument.js create mode 100644 src/slang-nodes/NamedArgument.ts delete mode 100644 src/slang-nodes/NamedArgumentGroup.js create mode 100644 src/slang-nodes/NamedArgumentGroup.ts delete mode 100644 src/slang-nodes/NamedArguments.js create mode 100644 src/slang-nodes/NamedArguments.ts delete mode 100644 src/slang-nodes/NamedArgumentsDeclaration.js create mode 100644 src/slang-nodes/NamedArgumentsDeclaration.ts delete mode 100644 src/slang-nodes/NamedImport.js create mode 100644 src/slang-nodes/NamedImport.ts delete mode 100644 src/slang-nodes/NewExpression.js create mode 100644 src/slang-nodes/NewExpression.ts delete mode 100644 src/slang-nodes/NumberUnit.js create mode 100644 src/slang-nodes/NumberUnit.ts delete mode 100644 src/slang-nodes/OrExpression.js create mode 100644 src/slang-nodes/OrExpression.ts delete mode 100644 src/slang-nodes/OverridePaths.js create mode 100644 src/slang-nodes/OverridePaths.ts delete mode 100644 src/slang-nodes/OverridePathsDeclaration.js create mode 100644 src/slang-nodes/OverridePathsDeclaration.ts delete mode 100644 src/slang-nodes/OverrideSpecifier.js create mode 100644 src/slang-nodes/OverrideSpecifier.ts delete mode 100644 src/slang-nodes/Parameter.js create mode 100644 src/slang-nodes/Parameter.ts delete mode 100644 src/slang-nodes/Parameters.js create mode 100644 src/slang-nodes/Parameters.ts delete mode 100644 src/slang-nodes/ParametersDeclaration.js create mode 100644 src/slang-nodes/ParametersDeclaration.ts delete mode 100644 src/slang-nodes/PathImport.js create mode 100644 src/slang-nodes/PathImport.ts delete mode 100644 src/slang-nodes/PositionalArguments.js create mode 100644 src/slang-nodes/PositionalArguments.ts delete mode 100644 src/slang-nodes/PositionalArgumentsDeclaration.js create mode 100644 src/slang-nodes/PositionalArgumentsDeclaration.ts delete mode 100644 src/slang-nodes/PostfixExpression.js create mode 100644 src/slang-nodes/PostfixExpression.ts delete mode 100644 src/slang-nodes/Pragma.js create mode 100644 src/slang-nodes/Pragma.ts delete mode 100644 src/slang-nodes/PragmaDirective.js create mode 100644 src/slang-nodes/PragmaDirective.ts delete mode 100644 src/slang-nodes/PrefixExpression.js create mode 100644 src/slang-nodes/PrefixExpression.ts delete mode 100644 src/slang-nodes/ReceiveFunctionAttribute.js create mode 100644 src/slang-nodes/ReceiveFunctionAttribute.ts delete mode 100644 src/slang-nodes/ReceiveFunctionAttributes.js create mode 100644 src/slang-nodes/ReceiveFunctionAttributes.ts delete mode 100644 src/slang-nodes/ReceiveFunctionDefinition.js create mode 100644 src/slang-nodes/ReceiveFunctionDefinition.ts delete mode 100644 src/slang-nodes/ReturnStatement.js create mode 100644 src/slang-nodes/ReturnStatement.ts delete mode 100644 src/slang-nodes/ReturnsDeclaration.js create mode 100644 src/slang-nodes/ReturnsDeclaration.ts delete mode 100644 src/slang-nodes/RevertStatement.js create mode 100644 src/slang-nodes/RevertStatement.ts delete mode 100644 src/slang-nodes/ShiftExpression.js create mode 100644 src/slang-nodes/ShiftExpression.ts delete mode 100644 src/slang-nodes/SlangNode.js delete mode 100644 src/slang-nodes/SourceUnit.js create mode 100644 src/slang-nodes/SourceUnit.ts delete mode 100644 src/slang-nodes/SourceUnitMember.js create mode 100644 src/slang-nodes/SourceUnitMember.ts delete mode 100644 src/slang-nodes/SourceUnitMembers.js create mode 100644 src/slang-nodes/SourceUnitMembers.ts delete mode 100644 src/slang-nodes/StateVariableAttribute.js create mode 100644 src/slang-nodes/StateVariableAttribute.ts delete mode 100644 src/slang-nodes/StateVariableAttributes.js create mode 100644 src/slang-nodes/StateVariableAttributes.ts delete mode 100644 src/slang-nodes/StateVariableDefinition.js create mode 100644 src/slang-nodes/StateVariableDefinition.ts delete mode 100644 src/slang-nodes/StateVariableDefinitionValue.js create mode 100644 src/slang-nodes/StateVariableDefinitionValue.ts delete mode 100644 src/slang-nodes/Statement.js create mode 100644 src/slang-nodes/Statement.ts delete mode 100644 src/slang-nodes/Statements.js create mode 100644 src/slang-nodes/Statements.ts delete mode 100644 src/slang-nodes/StorageLocation.js create mode 100644 src/slang-nodes/StorageLocation.ts delete mode 100644 src/slang-nodes/StringExpression.js create mode 100644 src/slang-nodes/StringExpression.ts delete mode 100644 src/slang-nodes/StringLiteral.js create mode 100644 src/slang-nodes/StringLiteral.ts delete mode 100644 src/slang-nodes/StringLiterals.js create mode 100644 src/slang-nodes/StringLiterals.ts delete mode 100644 src/slang-nodes/StructDefinition.js create mode 100644 src/slang-nodes/StructDefinition.ts delete mode 100644 src/slang-nodes/StructMember.js create mode 100644 src/slang-nodes/StructMember.ts delete mode 100644 src/slang-nodes/StructMembers.js create mode 100644 src/slang-nodes/StructMembers.ts delete mode 100644 src/slang-nodes/ThrowStatement.js create mode 100644 src/slang-nodes/ThrowStatement.ts delete mode 100644 src/slang-nodes/TryStatement.js create mode 100644 src/slang-nodes/TryStatement.ts delete mode 100644 src/slang-nodes/TupleDeconstructionElement.js create mode 100644 src/slang-nodes/TupleDeconstructionElement.ts delete mode 100644 src/slang-nodes/TupleDeconstructionElements.js create mode 100644 src/slang-nodes/TupleDeconstructionElements.ts delete mode 100644 src/slang-nodes/TupleDeconstructionStatement.js create mode 100644 src/slang-nodes/TupleDeconstructionStatement.ts delete mode 100644 src/slang-nodes/TupleExpression.js create mode 100644 src/slang-nodes/TupleExpression.ts delete mode 100644 src/slang-nodes/TupleMember.js create mode 100644 src/slang-nodes/TupleMember.ts delete mode 100644 src/slang-nodes/TupleValue.js create mode 100644 src/slang-nodes/TupleValue.ts delete mode 100644 src/slang-nodes/TupleValues.js create mode 100644 src/slang-nodes/TupleValues.ts delete mode 100644 src/slang-nodes/TypeExpression.js create mode 100644 src/slang-nodes/TypeExpression.ts delete mode 100644 src/slang-nodes/TypeName.js create mode 100644 src/slang-nodes/TypeName.ts delete mode 100644 src/slang-nodes/TypedTupleMember.js create mode 100644 src/slang-nodes/TypedTupleMember.ts delete mode 100644 src/slang-nodes/UncheckedBlock.js create mode 100644 src/slang-nodes/UncheckedBlock.ts delete mode 100644 src/slang-nodes/UnicodeStringLiteral.js create mode 100644 src/slang-nodes/UnicodeStringLiteral.ts delete mode 100644 src/slang-nodes/UnicodeStringLiterals.js create mode 100644 src/slang-nodes/UnicodeStringLiterals.ts delete mode 100644 src/slang-nodes/UnnamedFunctionAttribute.js create mode 100644 src/slang-nodes/UnnamedFunctionAttribute.ts delete mode 100644 src/slang-nodes/UnnamedFunctionAttributes.js create mode 100644 src/slang-nodes/UnnamedFunctionAttributes.ts delete mode 100644 src/slang-nodes/UnnamedFunctionDefinition.js create mode 100644 src/slang-nodes/UnnamedFunctionDefinition.ts delete mode 100644 src/slang-nodes/UntypedTupleMember.js create mode 100644 src/slang-nodes/UntypedTupleMember.ts delete mode 100644 src/slang-nodes/UserDefinedValueTypeDefinition.js create mode 100644 src/slang-nodes/UserDefinedValueTypeDefinition.ts delete mode 100644 src/slang-nodes/UsingAlias.js create mode 100644 src/slang-nodes/UsingAlias.ts delete mode 100644 src/slang-nodes/UsingClause.js create mode 100644 src/slang-nodes/UsingClause.ts delete mode 100644 src/slang-nodes/UsingDeconstruction.js create mode 100644 src/slang-nodes/UsingDeconstruction.ts delete mode 100644 src/slang-nodes/UsingDeconstructionSymbol.js create mode 100644 src/slang-nodes/UsingDeconstructionSymbol.ts delete mode 100644 src/slang-nodes/UsingDeconstructionSymbols.js create mode 100644 src/slang-nodes/UsingDeconstructionSymbols.ts delete mode 100644 src/slang-nodes/UsingDirective.js create mode 100644 src/slang-nodes/UsingDirective.ts delete mode 100644 src/slang-nodes/UsingOperator.js create mode 100644 src/slang-nodes/UsingOperator.ts delete mode 100644 src/slang-nodes/UsingTarget.js create mode 100644 src/slang-nodes/UsingTarget.ts delete mode 100644 src/slang-nodes/VariableDeclarationStatement.js create mode 100644 src/slang-nodes/VariableDeclarationStatement.ts delete mode 100644 src/slang-nodes/VariableDeclarationType.js create mode 100644 src/slang-nodes/VariableDeclarationType.ts delete mode 100644 src/slang-nodes/VariableDeclarationValue.js create mode 100644 src/slang-nodes/VariableDeclarationValue.ts delete mode 100644 src/slang-nodes/VersionComparator.js create mode 100644 src/slang-nodes/VersionComparator.ts delete mode 100644 src/slang-nodes/VersionExpression.js create mode 100644 src/slang-nodes/VersionExpression.ts delete mode 100644 src/slang-nodes/VersionExpressionSet.js create mode 100644 src/slang-nodes/VersionExpressionSet.ts delete mode 100644 src/slang-nodes/VersionExpressionSets.js create mode 100644 src/slang-nodes/VersionExpressionSets.ts delete mode 100644 src/slang-nodes/VersionPragma.js create mode 100644 src/slang-nodes/VersionPragma.ts delete mode 100644 src/slang-nodes/VersionRange.js create mode 100644 src/slang-nodes/VersionRange.ts delete mode 100644 src/slang-nodes/VersionSpecifiers.js create mode 100644 src/slang-nodes/VersionSpecifiers.ts delete mode 100644 src/slang-nodes/WhileStatement.js create mode 100644 src/slang-nodes/WhileStatement.ts delete mode 100644 src/slang-nodes/YulArguments.js create mode 100644 src/slang-nodes/YulArguments.ts delete mode 100644 src/slang-nodes/YulAssignmentOperator.js create mode 100644 src/slang-nodes/YulAssignmentOperator.ts delete mode 100644 src/slang-nodes/YulBlock.js create mode 100644 src/slang-nodes/YulBlock.ts delete mode 100644 src/slang-nodes/YulBreakStatement.js create mode 100644 src/slang-nodes/YulBreakStatement.ts delete mode 100644 src/slang-nodes/YulBuiltInFunction.js create mode 100644 src/slang-nodes/YulBuiltInFunction.ts delete mode 100644 src/slang-nodes/YulColonEqual.js create mode 100644 src/slang-nodes/YulColonEqual.ts delete mode 100644 src/slang-nodes/YulContinueStatement.js create mode 100644 src/slang-nodes/YulContinueStatement.ts delete mode 100644 src/slang-nodes/YulDefaultCase.js create mode 100644 src/slang-nodes/YulDefaultCase.ts delete mode 100644 src/slang-nodes/YulExpression.js create mode 100644 src/slang-nodes/YulExpression.ts delete mode 100644 src/slang-nodes/YulForStatement.js create mode 100644 src/slang-nodes/YulForStatement.ts delete mode 100644 src/slang-nodes/YulFunctionCallExpression.js create mode 100644 src/slang-nodes/YulFunctionCallExpression.ts delete mode 100644 src/slang-nodes/YulFunctionDefinition.js create mode 100644 src/slang-nodes/YulFunctionDefinition.ts delete mode 100644 src/slang-nodes/YulIfStatement.js create mode 100644 src/slang-nodes/YulIfStatement.ts delete mode 100644 src/slang-nodes/YulLabel.js create mode 100644 src/slang-nodes/YulLabel.ts delete mode 100644 src/slang-nodes/YulLeaveStatement.js create mode 100644 src/slang-nodes/YulLeaveStatement.ts delete mode 100644 src/slang-nodes/YulLiteral.js create mode 100644 src/slang-nodes/YulLiteral.ts delete mode 100644 src/slang-nodes/YulParameters.js create mode 100644 src/slang-nodes/YulParameters.ts delete mode 100644 src/slang-nodes/YulParametersDeclaration.js create mode 100644 src/slang-nodes/YulParametersDeclaration.ts delete mode 100644 src/slang-nodes/YulPath.js create mode 100644 src/slang-nodes/YulPath.ts delete mode 100644 src/slang-nodes/YulPathComponent.js create mode 100644 src/slang-nodes/YulPathComponent.ts delete mode 100644 src/slang-nodes/YulPaths.js create mode 100644 src/slang-nodes/YulPaths.ts delete mode 100644 src/slang-nodes/YulReturnVariables.js create mode 100644 src/slang-nodes/YulReturnVariables.ts delete mode 100644 src/slang-nodes/YulReturnsDeclaration.js create mode 100644 src/slang-nodes/YulReturnsDeclaration.ts delete mode 100644 src/slang-nodes/YulStackAssignmentStatement.js create mode 100644 src/slang-nodes/YulStackAssignmentStatement.ts delete mode 100644 src/slang-nodes/YulStatement.js create mode 100644 src/slang-nodes/YulStatement.ts delete mode 100644 src/slang-nodes/YulStatements.js create mode 100644 src/slang-nodes/YulStatements.ts delete mode 100644 src/slang-nodes/YulSwitchCase.js create mode 100644 src/slang-nodes/YulSwitchCase.ts delete mode 100644 src/slang-nodes/YulSwitchCases.js create mode 100644 src/slang-nodes/YulSwitchCases.ts delete mode 100644 src/slang-nodes/YulSwitchStatement.js create mode 100644 src/slang-nodes/YulSwitchStatement.ts delete mode 100644 src/slang-nodes/YulValueCase.js create mode 100644 src/slang-nodes/YulValueCase.ts delete mode 100644 src/slang-nodes/YulVariableAssignmentStatement.js create mode 100644 src/slang-nodes/YulVariableAssignmentStatement.ts delete mode 100644 src/slang-nodes/YulVariableDeclarationStatement.js create mode 100644 src/slang-nodes/YulVariableDeclarationStatement.ts delete mode 100644 src/slang-nodes/YulVariableDeclarationValue.js create mode 100644 src/slang-nodes/YulVariableDeclarationValue.ts rename src/slang-nodes/{index.js => index.ts} (99%) rename src/slang-printers/{create-binary-operation-printer.js => create-binary-operation-printer.ts} (60%) delete mode 100644 src/slang-printers/print-binary-operation.js create mode 100644 src/slang-printers/print-binary-operation.ts rename src/slang-printers/{print-comments.js => print-comments.ts} (67%) delete mode 100644 src/slang-printers/print-comparison-operation.js create mode 100644 src/slang-printers/print-comparison-operation.ts delete mode 100644 src/slang-printers/print-function.js create mode 100644 src/slang-printers/print-function.ts delete mode 100644 src/slang-printers/print-logical-operation.js create mode 100644 src/slang-printers/print-logical-operation.ts rename src/slang-printers/{print-preserving-empty-lines.js => print-preserving-empty-lines.ts} (72%) create mode 100644 src/slang-printers/print-separated-item.ts create mode 100644 src/slang-printers/print-separated-list.ts rename src/slang-printers/{print-string.js => print-string.ts} (81%) create mode 100644 src/slang-printers/types.d.ts rename src/slang-utils/{create-hug-function.js => create-hug-function.ts} (63%) delete mode 100644 src/slang-utils/get-offsets.js create mode 100644 src/slang-utils/get-offsets.ts create mode 100644 src/slang-utils/is-label.ts delete mode 100644 src/slang-utils/loc.js create mode 100644 src/slang-utils/loc.ts delete mode 100644 src/slang-utils/sort-function-attributes.js create mode 100644 src/slang-utils/sort-function-attributes.ts create mode 100644 src/slang-utils/types.d.ts create mode 100644 src/types.d.ts delete mode 100644 tests/config/require-prettier.cjs create mode 100644 tsconfig.json diff --git a/.eslintignore b/.eslintignore index 77cd3b23c..d42818524 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,5 +1,6 @@ coverage/**/*.js -dist/**/*.js +dist/**/*.cjs +tests/**/*.snap tests/format/**/*.sol tests/format/Markdown/Markdown.md tests/format/RespectDefaultOptions/respect-default-options.js diff --git a/.eslintrc b/.eslintrc index 86187aaf2..d731dac9f 100644 --- a/.eslintrc +++ b/.eslintrc @@ -2,17 +2,35 @@ "env": { "jest": true }, - "extends": ["airbnb-base", "prettier"], "globals": { - "runFormatTest": false + "runFormatTest": "readonly" }, - "parserOptions": { - "ecmaVersion": "latest", - "sourceType": "module" - }, - "rules": { - "import/extensions": "off", - "import/prefer-default-export": "off", - "class-methods-use-this": "off" - } + "overrides": [ + { + "files": ["**/*.ts"], + "extends": ["prettier", "plugin:@typescript-eslint/recommended"], + "parser": "@typescript-eslint/parser", + "plugins": ["@typescript-eslint"], + "parserOptions": { + "project": ["tsconfig.json"] + }, + "rules": { + "@typescript-eslint/explicit-function-return-type": "error" + } + }, + { + "files": ["**/*.*js"], + "extends": ["airbnb-base", "prettier"], + "parserOptions": { + "ecmaVersion": "latest", + "sourceType": "module" + }, + "rules": { + "import/extensions": "off", + "import/prefer-default-export": "off", + "import/no-cycle": "off", + "class-methods-use-this": "off" + } + } + ] } diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index ecd108073..4d0d28fda 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -59,7 +59,7 @@ jobs: - name: Build test app run: npm run build:test - name: Run standalone tests - run: npm run test:standalone tests/format tests/integration tests/unit/prettier-version + run: npm run test:standalone test_linux: name: Test on Linux with Node ${{ matrix.node }} diff --git a/jest.config.js b/jest.config.js index 2feb5fb4a..27727ef91 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,12 +1,13 @@ const TEST_STANDALONE = Boolean(process.env.TEST_STANDALONE); -const testMatch = [ - '/tests/format/**/format.test.js', - - '/tests/unit/**/*.test.js' -]; +const testMatch = ['/tests/format/**/format.test.js']; if (TEST_STANDALONE) { - testMatch.push('/tests/integration/**/*.test.js'); + testMatch.push( + '/tests/integration/**/*.test.js', + '/tests/unit/prettier-version/**/*.test.js' + ); +} else { + testMatch.push('/tests/unit/**/*.test.js'); } export default { @@ -16,7 +17,6 @@ export default { 'jest-snapshot-serializer-raw', 'jest-snapshot-serializer-ansi' ], - testEnvironment: 'node', // ignore console warnings in TEST_STANDALONE silent: TEST_STANDALONE, testPathIgnorePatterns: TEST_STANDALONE @@ -27,7 +27,6 @@ export default { ] : [], testMatch, - transform: {}, watchPlugins: [ 'jest-watch-typeahead/filename', 'jest-watch-typeahead/testname' diff --git a/package-lock.json b/package-lock.json index 57f1d48b2..08de16551 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,9 @@ }, "devDependencies": { "@babel/code-frame": "^7.24.7", + "@types/semver": "^7.5.8", + "@typescript-eslint/eslint-plugin": "^8.1.0", + "@typescript-eslint/parser": "^8.1.0", "c8": "^9.1.0", "cross-env": "^7.0.3", "eslint": "^8.57.0", @@ -32,6 +35,9 @@ "prettier": "^3.3.3", "proxyquire": "^2.1.3", "solc": "^0.8.26", + "ts-loader": "^9.5.1", + "ts-node": "^10.9.2", + "typescript": "^5.5.4", "webpack": "^5.93.0", "webpack-cli": "^5.1.4" }, @@ -638,6 +644,30 @@ "integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==", "dev": true }, + "node_modules/@cspotcode/source-map-support": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", + "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/trace-mapping": "0.3.9" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@cspotcode/source-map-support/node_modules/@jridgewell/trace-mapping": { + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", + "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + }, "node_modules/@discoveryjs/json-ext": { "version": "0.5.7", "resolved": "https://registry.npmjs.org/@discoveryjs/json-ext/-/json-ext-0.5.7.tgz", @@ -663,10 +693,11 @@ } }, "node_modules/@eslint-community/regexpp": { - "version": "4.6.2", - "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.6.2.tgz", - "integrity": "sha512-pPTNuaAG3QMH+buKyBIGJs3g/S5y0caxw0ygM3YyE6yJFySwiGGSzA+mM3KJ8QQvzeLh3blwgSonkFjgQdxzMw==", + "version": "4.11.0", + "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.11.0.tgz", + "integrity": "sha512-G/M/tIiMrTAxEWRfLfQJMmGNX28IxBg4PBz8XqQhqUHLFI6TL2htpIB1iQCj144V5ee/JaKyT9/WZ0MGZWfA7A==", "dev": true, + "license": "MIT", "engines": { "node": "^12.0.0 || ^14.0.0 || >=16.0.0" } @@ -1396,6 +1427,34 @@ "resolved": "https://registry.npmjs.org/@solidity-parser/parser/-/parser-0.18.0.tgz", "integrity": "sha512-yfORGUIPgLck41qyN7nbwJRAx17/jAIXCTanHOJZhB6PJ1iAk/84b/xlsVKFSyNyLXIj0dhppoE0+CRws7wlzA==" }, + "node_modules/@tsconfig/node10": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.11.tgz", + "integrity": "sha512-DcRjDCujK/kCk/cUe8Xz8ZSpm8mS3mNNpta+jGCA6USEDfktlNvm1+IuZ9eTcDbNk41BHwpHHeW+N1lKCz4zOw==", + "dev": true, + "license": "MIT" + }, + "node_modules/@tsconfig/node12": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz", + "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==", + "dev": true, + "license": "MIT" + }, + "node_modules/@tsconfig/node14": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", + "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==", + "dev": true, + "license": "MIT" + }, + "node_modules/@tsconfig/node16": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz", + "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/babel__core": { "version": "7.20.1", "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.1.tgz", @@ -1514,6 +1573,13 @@ "integrity": "sha512-HJSUJmni4BeDHhfzn6nF0sVmd1SMezP7/4F0Lq+aXzmp2xm9O7WXrUtHW/CHlYVtZUbByEvWidHqRtcJXGF2Ng==", "dev": true }, + "node_modules/@types/semver": { + "version": "7.5.8", + "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.8.tgz", + "integrity": "sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/stack-utils": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.1.tgz", @@ -1535,6 +1601,222 @@ "integrity": "sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==", "dev": true }, + "node_modules/@typescript-eslint/eslint-plugin": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.1.0.tgz", + "integrity": "sha512-LlNBaHFCEBPHyD4pZXb35mzjGkuGKXU5eeCA1SxvHfiRES0E82dOounfVpL4DCqYvJEKab0bZIA0gCRpdLKkCw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@eslint-community/regexpp": "^4.10.0", + "@typescript-eslint/scope-manager": "8.1.0", + "@typescript-eslint/type-utils": "8.1.0", + "@typescript-eslint/utils": "8.1.0", + "@typescript-eslint/visitor-keys": "8.1.0", + "graphemer": "^1.4.0", + "ignore": "^5.3.1", + "natural-compare": "^1.4.0", + "ts-api-utils": "^1.3.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "@typescript-eslint/parser": "^8.0.0 || ^8.0.0-alpha.0", + "eslint": "^8.57.0 || ^9.0.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/@typescript-eslint/parser": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.1.0.tgz", + "integrity": "sha512-U7iTAtGgJk6DPX9wIWPPOlt1gO57097G06gIcl0N0EEnNw8RGD62c+2/DiP/zL7KrkqnnqF7gtFGR7YgzPllTA==", + "dev": true, + "license": "BSD-2-Clause", + "dependencies": { + "@typescript-eslint/scope-manager": "8.1.0", + "@typescript-eslint/types": "8.1.0", + "@typescript-eslint/typescript-estree": "8.1.0", + "@typescript-eslint/visitor-keys": "8.1.0", + "debug": "^4.3.4" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^8.57.0 || ^9.0.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/@typescript-eslint/scope-manager": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.1.0.tgz", + "integrity": "sha512-DsuOZQji687sQUjm4N6c9xABJa7fjvfIdjqpSIIVOgaENf2jFXiM9hIBZOL3hb6DHK9Nvd2d7zZnoMLf9e0OtQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/types": "8.1.0", + "@typescript-eslint/visitor-keys": "8.1.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@typescript-eslint/type-utils": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.1.0.tgz", + "integrity": "sha512-oLYvTxljVvsMnldfl6jIKxTaU7ok7km0KDrwOt1RHYu6nxlhN3TIx8k5Q52L6wR33nOwDgM7VwW1fT1qMNfFIA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/typescript-estree": "8.1.0", + "@typescript-eslint/utils": "8.1.0", + "debug": "^4.3.4", + "ts-api-utils": "^1.3.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/@typescript-eslint/types": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.1.0.tgz", + "integrity": "sha512-q2/Bxa0gMOu/2/AKALI0tCKbG2zppccnRIRCW6BaaTlRVaPKft4oVYPp7WOPpcnsgbr0qROAVCVKCvIQ0tbWog==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@typescript-eslint/typescript-estree": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.1.0.tgz", + "integrity": "sha512-NTHhmufocEkMiAord/g++gWKb0Fr34e9AExBRdqgWdVBaKoei2dIyYKD9Q0jBnvfbEA5zaf8plUFMUH6kQ0vGg==", + "dev": true, + "license": "BSD-2-Clause", + "dependencies": { + "@typescript-eslint/types": "8.1.0", + "@typescript-eslint/visitor-keys": "8.1.0", + "debug": "^4.3.4", + "globby": "^11.1.0", + "is-glob": "^4.0.3", + "minimatch": "^9.0.4", + "semver": "^7.6.0", + "ts-api-utils": "^1.3.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/@typescript-eslint/typescript-estree/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/@typescript-eslint/typescript-estree/node_modules/minimatch": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", + "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/@typescript-eslint/utils": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.1.0.tgz", + "integrity": "sha512-ypRueFNKTIFwqPeJBfeIpxZ895PQhNyH4YID6js0UoBImWYoSjBsahUn9KMiJXh94uOjVBgHD9AmkyPsPnFwJA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@eslint-community/eslint-utils": "^4.4.0", + "@typescript-eslint/scope-manager": "8.1.0", + "@typescript-eslint/types": "8.1.0", + "@typescript-eslint/typescript-estree": "8.1.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^8.57.0 || ^9.0.0" + } + }, + "node_modules/@typescript-eslint/visitor-keys": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.1.0.tgz", + "integrity": "sha512-ba0lNI19awqZ5ZNKh6wCModMwoZs457StTebQ0q1NP58zSi2F6MOZRXwfKZy+jB78JNJ/WH8GSh2IQNzXX8Nag==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/types": "8.1.0", + "eslint-visitor-keys": "^3.4.3" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, "node_modules/@ungap/structured-clone": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.2.0.tgz", @@ -1744,10 +2026,11 @@ "dev": true }, "node_modules/acorn": { - "version": "8.9.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.9.0.tgz", - "integrity": "sha512-jaVNAFBHNLXspO543WnNNPZFRtavh3skAkITqD0/2aeMkKZTN+254PyhwxFYrk3vQ1xfY+2wbesJMs/JC8/PwQ==", + "version": "8.12.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.1.tgz", + "integrity": "sha512-tcpGyI9zbizT9JbV6oYE477V6mTlXvvi0T0G3SNIYE2apm/G5huBa1+K89VGeovbg+jycCrfhl3ADxErOuO6Jg==", "dev": true, + "license": "MIT", "bin": { "acorn": "bin/acorn" }, @@ -1773,6 +2056,19 @@ "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, + "node_modules/acorn-walk": { + "version": "8.3.3", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.3.tgz", + "integrity": "sha512-MxXdReSRhGO7VlFe1bRG/oI7/mdLV9B9JJT0N8vZOhF7gFRR5l3M8W9G8JxmKV+JC5mGqJ0QvqfSOLsCPa4nUw==", + "dev": true, + "license": "MIT", + "dependencies": { + "acorn": "^8.11.0" + }, + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", @@ -1883,6 +2179,13 @@ "node": ">= 8" } }, + "node_modules/arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "dev": true, + "license": "MIT" + }, "node_modules/argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", @@ -1921,6 +2224,16 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/array-union": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz", + "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/array.prototype.findlastindex": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/array.prototype.findlastindex/-/array.prototype.findlastindex-1.2.3.tgz", @@ -2454,6 +2767,13 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/create-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", + "dev": true, + "license": "MIT" + }, "node_modules/cross-env": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz", @@ -2713,6 +3033,16 @@ "node": ">=8" } }, + "node_modules/diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "dev": true, + "license": "BSD-3-Clause", + "engines": { + "node": ">=0.3.1" + } + }, "node_modules/diff-sequences": { "version": "29.6.3", "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-29.6.3.tgz", @@ -2722,6 +3052,19 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/dir-glob": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", + "integrity": "sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==", + "dev": true, + "license": "MIT", + "dependencies": { + "path-type": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/doctrine": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", @@ -3683,6 +4026,27 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/globby": { + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz", + "integrity": "sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==", + "dev": true, + "license": "MIT", + "dependencies": { + "array-union": "^2.1.0", + "dir-glob": "^3.0.1", + "fast-glob": "^3.2.9", + "ignore": "^5.2.0", + "merge2": "^1.4.1", + "slash": "^3.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/gopd": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", @@ -3831,10 +4195,11 @@ } }, "node_modules/ignore": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.0.tgz", - "integrity": "sha512-g7dmpshy+gD7mh88OC9NwSGTKoc3kyLAZQRU1mt53Aw/vnvfXnbC+F/7F7QoYVKbV+KNvJx8wArewKy1vXMtlg==", + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", + "integrity": "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==", "dev": true, + "license": "MIT", "engines": { "node": ">= 4" } @@ -5929,6 +6294,13 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", + "dev": true, + "license": "ISC" + }, "node_modules/makeerror": { "version": "1.0.12", "resolved": "https://registry.npmjs.org/makeerror/-/makeerror-1.0.12.tgz", @@ -6361,6 +6733,16 @@ "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", "dev": true }, + "node_modules/path-type": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", + "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/picocolors": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", @@ -7324,6 +7706,94 @@ "node": ">=8.0" } }, + "node_modules/ts-api-utils": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-1.3.0.tgz", + "integrity": "sha512-UQMIo7pb8WRomKR1/+MFVLTroIvDVtMX3K6OUir8ynLyzB8Jeriont2bTAtmNPa1ekAgN7YPDyf6V+ygrdU+eQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=16" + }, + "peerDependencies": { + "typescript": ">=4.2.0" + } + }, + "node_modules/ts-loader": { + "version": "9.5.1", + "resolved": "https://registry.npmjs.org/ts-loader/-/ts-loader-9.5.1.tgz", + "integrity": "sha512-rNH3sK9kGZcH9dYzC7CewQm4NtxJTjSEVRJ2DyBZR7f8/wcta+iV44UPCXc5+nzDzivKtlzV6c9P4e+oFhDLYg==", + "dev": true, + "license": "MIT", + "dependencies": { + "chalk": "^4.1.0", + "enhanced-resolve": "^5.0.0", + "micromatch": "^4.0.0", + "semver": "^7.3.4", + "source-map": "^0.7.4" + }, + "engines": { + "node": ">=12.0.0" + }, + "peerDependencies": { + "typescript": "*", + "webpack": "^5.0.0" + } + }, + "node_modules/ts-loader/node_modules/source-map": { + "version": "0.7.4", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.4.tgz", + "integrity": "sha512-l3BikUxvPOcn5E74dZiq5BGsTb5yEwhaTSzccU6t4sDOH8NWJCstKO5QT2CvtFoK6F0saL7p9xHAqHOlCPJygA==", + "dev": true, + "license": "BSD-3-Clause", + "engines": { + "node": ">= 8" + } + }, + "node_modules/ts-node": { + "version": "10.9.2", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz", + "integrity": "sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@cspotcode/source-map-support": "^0.8.0", + "@tsconfig/node10": "^1.0.7", + "@tsconfig/node12": "^1.0.7", + "@tsconfig/node14": "^1.0.0", + "@tsconfig/node16": "^1.0.2", + "acorn": "^8.4.1", + "acorn-walk": "^8.1.1", + "arg": "^4.1.0", + "create-require": "^1.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "v8-compile-cache-lib": "^3.0.1", + "yn": "3.1.1" + }, + "bin": { + "ts-node": "dist/bin.js", + "ts-node-cwd": "dist/bin-cwd.js", + "ts-node-esm": "dist/bin-esm.js", + "ts-node-script": "dist/bin-script.js", + "ts-node-transpile-only": "dist/bin-transpile.js", + "ts-script": "dist/bin-script-deprecated.js" + }, + "peerDependencies": { + "@swc/core": ">=1.2.50", + "@swc/wasm": ">=1.2.50", + "@types/node": "*", + "typescript": ">=2.7" + }, + "peerDependenciesMeta": { + "@swc/core": { + "optional": true + }, + "@swc/wasm": { + "optional": true + } + } + }, "node_modules/tsconfig-paths": { "version": "3.15.0", "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.15.0.tgz", @@ -7440,6 +7910,20 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/typescript": { + "version": "5.5.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz", + "integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, "node_modules/unbox-primitive": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.2.tgz", @@ -7512,6 +7996,13 @@ "url": "https://github.com/fisker/url-or-path?sponsor=1" } }, + "node_modules/v8-compile-cache-lib": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", + "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", + "dev": true, + "license": "MIT" + }, "node_modules/v8-to-istanbul": { "version": "9.0.1", "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.0.1.tgz", @@ -7821,6 +8312,16 @@ "node": ">=12" } }, + "node_modules/yn": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, "node_modules/yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", diff --git a/package.json b/package.json index 28b75a3c6..a0740944f 100644 --- a/package.json +++ b/package.json @@ -23,9 +23,9 @@ "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}' '{src,tests}/**/*.js'", - "test": "NODE_OPTIONS=--loader=esmock jest", - "test:all": "cross-env FULL_TEST=1 NODE_OPTIONS=--loader=esmock c8 jest", + "prettier": "prettier './*.{ts,js,cjs,json,md,yml}' '{src,tests}/**/*.{ts,js,cjs}'", + "test": "NODE_OPTIONS=\"--loader=ts-node/esm --loader=esmock\" jest", + "test:all": "cross-env FULL_TEST=1 NODE_OPTIONS=\"--loader=ts-node/esm --loader=esmock\" c8 jest", "test:standalone": "cross-env TEST_STANDALONE=1 FULL_TEST=1 jest" }, "files": [ @@ -88,6 +88,9 @@ }, "devDependencies": { "@babel/code-frame": "^7.24.7", + "@types/semver": "^7.5.8", + "@typescript-eslint/eslint-plugin": "^8.1.0", + "@typescript-eslint/parser": "^8.1.0", "c8": "^9.1.0", "cross-env": "^7.0.3", "eslint": "^8.57.0", @@ -105,6 +108,9 @@ "prettier": "^3.3.3", "proxyquire": "^2.1.3", "solc": "^0.8.26", + "ts-loader": "^9.5.1", + "ts-node": "^10.9.2", + "typescript": "^5.5.4", "webpack": "^5.93.0", "webpack-cli": "^5.1.4" }, @@ -119,8 +125,7 @@ "browserslist": { "production": [ ">0.5%", - "not ie 11", - "not safari 5.1", + "not dead", "not op_mini all" ], "development": [ diff --git a/src/slang-nodes/ABICoderPragma.js b/src/slang-nodes/ABICoderPragma.js deleted file mode 100644 index 38d4a95e4..000000000 --- a/src/slang-nodes/ABICoderPragma.js +++ /dev/null @@ -1,27 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; - -export class ABICoderPragma extends SlangNode { - get kind() { - return NonterminalKind.ABICoderPragma; - } - - abicoderKeyword; - - version; - - constructor(ast, offset) { - super(); - - const fetch = () => ({ - abicoderKeyword: ast.abicoderKeyword.text, - version: ast.version.text - }); - - this.initialize(ast, offset, fetch); - } - - print() { - return `${this.abicoderKeyword} ${this.version}`; - } -} diff --git a/src/slang-nodes/ABICoderPragma.ts b/src/slang-nodes/ABICoderPragma.ts new file mode 100644 index 000000000..b2bef6398 --- /dev/null +++ b/src/slang-nodes/ABICoderPragma.ts @@ -0,0 +1,32 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata } from '../slang-utils/get-offsets.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class ABICoderPragma implements SlangNode { + readonly kind = NonterminalKind.ABICoderPragma; + + comments; + + loc; + + abicoderKeyword: string; + + version: string; + + constructor(ast: ast.ABICoderPragma, offset: number) { + const metadata = getNodeMetadata(ast, offset); + + this.abicoderKeyword = ast.abicoderKeyword.text; + this.version = ast.version.text; + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(): Doc { + return `${this.abicoderKeyword} ${this.version}`; + } +} diff --git a/src/slang-nodes/AdditiveExpression.js b/src/slang-nodes/AdditiveExpression.js deleted file mode 100644 index adfc8cdbc..000000000 --- a/src/slang-nodes/AdditiveExpression.js +++ /dev/null @@ -1,41 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; -import { createHugFunction } from '../slang-utils/create-hug-function.js'; -import { SlangNode } from './SlangNode.js'; -import { Expression } from './Expression.js'; - -const tryToHug = createHugFunction(['%']); - -const postProcess = (properties) => ({ - ...properties, - leftOperand: tryToHug(properties.leftOperand), - rightOperand: tryToHug(properties.rightOperand) -}); - -export class AdditiveExpression extends SlangNode { - get kind() { - return NonterminalKind.AdditiveExpression; - } - - leftOperand; - - operator; - - rightOperand; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - leftOperand: new Expression(ast.leftOperand, offsets[0], options), - operator: ast.operator.text, - rightOperand: new Expression(ast.rightOperand, offsets[1], options) - }); - - this.initialize(ast, offset, fetch, postProcess); - } - - print(path, print, options) { - return printBinaryOperation({ node: this, path, print, options }); - } -} diff --git a/src/slang-nodes/AdditiveExpression.ts b/src/slang-nodes/AdditiveExpression.ts new file mode 100644 index 000000000..0443f2810 --- /dev/null +++ b/src/slang-nodes/AdditiveExpression.ts @@ -0,0 +1,54 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; +import { createHugFunction } from '../slang-utils/create-hug-function.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Expression } from './Expression.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const tryToHug = createHugFunction(['%']); + +export class AdditiveExpression implements SlangNode { + readonly kind = NonterminalKind.AdditiveExpression; + + comments; + + loc; + + leftOperand: Expression; + + operator: string; + + rightOperand: Expression; + + constructor( + ast: ast.AdditiveExpression, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.leftOperand = new Expression(ast.leftOperand, offsets[0], options); + this.operator = ast.operator.text; + this.rightOperand = new Expression(ast.rightOperand, offsets[1], options); + + metadata = updateMetadata(metadata, [this.leftOperand, this.rightOperand]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + + this.leftOperand = tryToHug(this.leftOperand); + this.rightOperand = tryToHug(this.rightOperand); + } + + print( + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc { + return printBinaryOperation(this, path, print, options); + } +} diff --git a/src/slang-nodes/AddressType.js b/src/slang-nodes/AddressType.js deleted file mode 100644 index 596a31c43..000000000 --- a/src/slang-nodes/AddressType.js +++ /dev/null @@ -1,27 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; - -export class AddressType extends SlangNode { - get kind() { - return NonterminalKind.AddressType; - } - - addressKeyword; - - payableKeyword; - - constructor(ast, offset) { - super(); - - const fetch = () => ({ - addressKeyword: ast.addressKeyword.text, - payableKeyword: ast.payableKeyword?.text - }); - - this.initialize(ast, offset, fetch); - } - - print() { - return `${this.addressKeyword}${this.payableKeyword ? ` ${this.payableKeyword}` : ''}`; - } -} diff --git a/src/slang-nodes/AddressType.ts b/src/slang-nodes/AddressType.ts new file mode 100644 index 000000000..5640c5125 --- /dev/null +++ b/src/slang-nodes/AddressType.ts @@ -0,0 +1,32 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata } from '../slang-utils/get-offsets.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class AddressType implements SlangNode { + readonly kind = NonterminalKind.AddressType; + + comments; + + loc; + + addressKeyword: string; + + payableKeyword?: string; + + constructor(ast: ast.AddressType, offset: number) { + const metadata = getNodeMetadata(ast, offset); + + this.addressKeyword = ast.addressKeyword.text; + this.payableKeyword = ast.payableKeyword?.text; + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(): Doc { + return `${this.addressKeyword}${this.payableKeyword ? ` ${this.payableKeyword}` : ''}`; + } +} diff --git a/src/slang-nodes/AndExpression.js b/src/slang-nodes/AndExpression.js deleted file mode 100644 index 51a575b2b..000000000 --- a/src/slang-nodes/AndExpression.js +++ /dev/null @@ -1,32 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printLogicalOperation } from '../slang-printers/print-logical-operation.js'; -import { SlangNode } from './SlangNode.js'; -import { Expression } from './Expression.js'; - -export class AndExpression extends SlangNode { - get kind() { - return NonterminalKind.AndExpression; - } - - leftOperand; - - operator; - - rightOperand; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - leftOperand: new Expression(ast.leftOperand, offsets[0], options), - operator: ast.operator.text, - rightOperand: new Expression(ast.rightOperand, offsets[1], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print, options) { - return printLogicalOperation({ node: this, path, print, options }); - } -} diff --git a/src/slang-nodes/AndExpression.ts b/src/slang-nodes/AndExpression.ts new file mode 100644 index 000000000..dc9b2ef1e --- /dev/null +++ b/src/slang-nodes/AndExpression.ts @@ -0,0 +1,44 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printLogicalOperation } from '../slang-printers/print-logical-operation.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Expression } from './Expression.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class AndExpression implements SlangNode { + readonly kind = NonterminalKind.AndExpression; + + comments; + + loc; + + leftOperand: Expression; + + operator: string; + + rightOperand: Expression; + + constructor(ast: ast.AndExpression, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.leftOperand = new Expression(ast.leftOperand, offsets[0], options); + this.operator = ast.operator.text; + this.rightOperand = new Expression(ast.rightOperand, offsets[1], options); + + metadata = updateMetadata(metadata, [this.leftOperand, this.rightOperand]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print( + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc { + return printLogicalOperation(this, path, print, options); + } +} diff --git a/src/slang-nodes/ArgumentsDeclaration.js b/src/slang-nodes/ArgumentsDeclaration.js deleted file mode 100644 index f689de349..000000000 --- a/src/slang-nodes/ArgumentsDeclaration.js +++ /dev/null @@ -1,32 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { PositionalArgumentsDeclaration } from './PositionalArgumentsDeclaration.js'; -import { NamedArgumentsDeclaration } from './NamedArgumentsDeclaration.js'; - -const variants = { PositionalArgumentsDeclaration, NamedArgumentsDeclaration }; - -export class ArgumentsDeclaration extends SlangNode { - get kind() { - return NonterminalKind.ArgumentsDeclaration; - } - - variant; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - variant: new variants[ast.variant.cst.kind]( - ast.variant, - offsets[0], - options - ) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return path.call(print, 'variant'); - } -} diff --git a/src/slang-nodes/ArgumentsDeclaration.ts b/src/slang-nodes/ArgumentsDeclaration.ts new file mode 100644 index 000000000..bd538ac68 --- /dev/null +++ b/src/slang-nodes/ArgumentsDeclaration.ts @@ -0,0 +1,55 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { PositionalArgumentsDeclaration } from './PositionalArgumentsDeclaration.js'; +import { NamedArgumentsDeclaration } from './NamedArgumentsDeclaration.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class ArgumentsDeclaration implements SlangNode { + readonly kind = NonterminalKind.ArgumentsDeclaration; + + comments; + + loc; + + variant: PositionalArgumentsDeclaration | NamedArgumentsDeclaration; + + constructor( + ast: ast.ArgumentsDeclaration, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + switch (ast.variant.cst.kind) { + case 'PositionalArgumentsDeclaration': + this.variant = new PositionalArgumentsDeclaration( + ast.variant as ast.PositionalArgumentsDeclaration, + offsets[0], + options + ); + break; + case 'NamedArgumentsDeclaration': + this.variant = new NamedArgumentsDeclaration( + ast.variant as ast.NamedArgumentsDeclaration, + offsets[0], + options + ); + break; + default: + throw new Error(`Unexpected variant: ${ast.variant.cst.kind}`); + } + + metadata = updateMetadata(metadata, [this.variant]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/ArrayExpression.js b/src/slang-nodes/ArrayExpression.js deleted file mode 100644 index 417282166..000000000 --- a/src/slang-nodes/ArrayExpression.js +++ /dev/null @@ -1,38 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { ArrayValues } from './ArrayValues.js'; - -const { group } = doc.builders; - -export class ArrayExpression extends SlangNode { - get kind() { - return NonterminalKind.ArrayExpression; - } - - openBracket; - - items; - - closeBracket; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - openBracket: ast.openBracket.text, - items: new ArrayValues(ast.items, offsets[0], options), - closeBracket: ast.closeBracket.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return group([ - this.openBracket, - path.call(print, 'items'), - this.closeBracket - ]); - } -} diff --git a/src/slang-nodes/ArrayExpression.ts b/src/slang-nodes/ArrayExpression.ts new file mode 100644 index 000000000..d86c20528 --- /dev/null +++ b/src/slang-nodes/ArrayExpression.ts @@ -0,0 +1,50 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ArrayValues } from './ArrayValues.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { group } = doc.builders; + +export class ArrayExpression implements SlangNode { + readonly kind = NonterminalKind.ArrayExpression; + + comments; + + loc; + + openBracket: string; + + items: ArrayValues; + + closeBracket: string; + + constructor( + ast: ast.ArrayExpression, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.openBracket = ast.openBracket.text; + this.items = new ArrayValues(ast.items, offsets[0], options); + this.closeBracket = ast.closeBracket.text; + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return group([ + this.openBracket, + path.call(print, 'items'), + this.closeBracket + ]); + } +} diff --git a/src/slang-nodes/ArrayTypeName.js b/src/slang-nodes/ArrayTypeName.js deleted file mode 100644 index db13a1a66..000000000 --- a/src/slang-nodes/ArrayTypeName.js +++ /dev/null @@ -1,42 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { TypeName } from './TypeName.js'; -import { Expression } from './Expression.js'; - -export class ArrayTypeName extends SlangNode { - get kind() { - return NonterminalKind.ArrayTypeName; - } - - operand; - - openBracket; - - index; - - closeBracket; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - operand: new TypeName(ast.operand, offsets[0], options), - openBracket: ast.openBracket.text, - index: ast.index - ? new Expression(ast.index, offsets[1], options) - : undefined, - closeBracket: ast.closeBracket.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - path.call(print, 'operand'), - this.openBracket, - this.index ? path.call(print, 'index') : '', - this.closeBracket - ]; - } -} diff --git a/src/slang-nodes/ArrayTypeName.ts b/src/slang-nodes/ArrayTypeName.ts new file mode 100644 index 000000000..ab0f61473 --- /dev/null +++ b/src/slang-nodes/ArrayTypeName.ts @@ -0,0 +1,50 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { TypeName } from './TypeName.js'; +import { Expression } from './Expression.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class ArrayTypeName implements SlangNode { + readonly kind = NonterminalKind.ArrayTypeName; + + comments; + + loc; + + operand: TypeName; + + openBracket: string; + + index?: Expression; + + closeBracket: string; + + constructor(ast: ast.ArrayTypeName, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.operand = new TypeName(ast.operand, offsets[0], options); + this.openBracket = ast.openBracket.text; + if (ast.index) { + this.index = new Expression(ast.index, offsets[1], options); + } + this.closeBracket = ast.closeBracket.text; + + metadata = updateMetadata(metadata, [this.operand, this.index]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + path.call(print, 'operand'), + this.openBracket, + this.index ? path.call(print, 'index') : '', + this.closeBracket + ]; + } +} diff --git a/src/slang-nodes/ArrayValues.js b/src/slang-nodes/ArrayValues.js deleted file mode 100644 index 39869858e..000000000 --- a/src/slang-nodes/ArrayValues.js +++ /dev/null @@ -1,31 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printSeparatedList } from '../common/printer-helpers.js'; -import { SlangNode } from './SlangNode.js'; -import { Expression } from './Expression.js'; - -export class ArrayValues extends SlangNode { - get kind() { - return NonterminalKind.ArrayValues; - } - - items; - - separators; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => new Expression(item, offsets[index], options) - ), - separators: ast.separators.map((separator) => separator.text) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return printSeparatedList(path.map(print, 'items')); - } -} diff --git a/src/slang-nodes/ArrayValues.ts b/src/slang-nodes/ArrayValues.ts new file mode 100644 index 000000000..496fec72c --- /dev/null +++ b/src/slang-nodes/ArrayValues.ts @@ -0,0 +1,39 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printSeparatedList } from '../slang-printers/print-separated-list.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Expression } from './Expression.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class ArrayValues implements SlangNode { + readonly kind = NonterminalKind.ArrayValues; + + comments; + + loc; + + items: Expression[]; + + separators: string[]; + + constructor(ast: ast.ArrayValues, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => new Expression(item, offsets[index], options) + ); + this.separators = ast.separators.map((separator) => separator.text); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return printSeparatedList(path.map(print, 'items')); + } +} diff --git a/src/slang-nodes/AssemblyFlags.js b/src/slang-nodes/AssemblyFlags.js deleted file mode 100644 index 08b366e45..000000000 --- a/src/slang-nodes/AssemblyFlags.js +++ /dev/null @@ -1,31 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printSeparatedList } from '../common/printer-helpers.js'; -import { SlangNode } from './SlangNode.js'; -import { StringLiteral } from './StringLiteral.js'; - -export class AssemblyFlags extends SlangNode { - get kind() { - return NonterminalKind.AssemblyFlags; - } - - items; - - separators; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => new StringLiteral(item, offsets[index], options) - ), - separators: ast.separators.map((separator) => separator.text) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return printSeparatedList(path.map(print, 'items')); - } -} diff --git a/src/slang-nodes/AssemblyFlags.ts b/src/slang-nodes/AssemblyFlags.ts new file mode 100644 index 000000000..56daa21ba --- /dev/null +++ b/src/slang-nodes/AssemblyFlags.ts @@ -0,0 +1,39 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printSeparatedList } from '../slang-printers/print-separated-list.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { StringLiteral } from './StringLiteral.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class AssemblyFlags implements SlangNode { + readonly kind = NonterminalKind.AssemblyFlags; + + comments; + + loc; + + items: StringLiteral[]; + + separators: string[]; + + constructor(ast: ast.AssemblyFlags, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => new StringLiteral(item, offsets[index], options) + ); + this.separators = ast.separators.map((separator) => separator.text); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return printSeparatedList(path.map(print, 'items')); + } +} diff --git a/src/slang-nodes/AssemblyFlagsDeclaration.js b/src/slang-nodes/AssemblyFlagsDeclaration.js deleted file mode 100644 index 52c4fa876..000000000 --- a/src/slang-nodes/AssemblyFlagsDeclaration.js +++ /dev/null @@ -1,31 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { AssemblyFlags } from './AssemblyFlags.js'; - -export class AssemblyFlagsDeclaration extends SlangNode { - get kind() { - return NonterminalKind.AssemblyFlagsDeclaration; - } - - openParen; - - flags; - - closeParen; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - openParen: ast.openParen.text, - flags: new AssemblyFlags(ast.flags, offsets[0], options), - closeParen: ast.closeParen.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [this.openParen, path.call(print, 'flags'), this.closeParen]; - } -} diff --git a/src/slang-nodes/AssemblyFlagsDeclaration.ts b/src/slang-nodes/AssemblyFlagsDeclaration.ts new file mode 100644 index 000000000..80359c364 --- /dev/null +++ b/src/slang-nodes/AssemblyFlagsDeclaration.ts @@ -0,0 +1,43 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { AssemblyFlags } from './AssemblyFlags.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class AssemblyFlagsDeclaration implements SlangNode { + readonly kind = NonterminalKind.AssemblyFlagsDeclaration; + + comments; + + loc; + + openParen: string; + + flags: AssemblyFlags; + + closeParen: string; + + constructor( + ast: ast.AssemblyFlagsDeclaration, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.openParen = ast.openParen.text; + this.flags = new AssemblyFlags(ast.flags, offsets[0], options); + this.closeParen = ast.closeParen.text; + + metadata = updateMetadata(metadata, [this.flags]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [this.openParen, path.call(print, 'flags'), this.closeParen]; + } +} diff --git a/src/slang-nodes/AssemblyStatement.js b/src/slang-nodes/AssemblyStatement.js deleted file mode 100644 index 6afb98f13..000000000 --- a/src/slang-nodes/AssemblyStatement.js +++ /dev/null @@ -1,49 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { StringLiteral } from './StringLiteral.js'; -import { AssemblyFlagsDeclaration } from './AssemblyFlagsDeclaration.js'; -import { YulBlock } from './YulBlock.js'; - -export class AssemblyStatement extends SlangNode { - get kind() { - return NonterminalKind.AssemblyStatement; - } - - assemblyKeyword; - - label; - - flags; - - body; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => { - let i = -1; - const children = { - assemblyKeyword: ast.assemblyKeyword.text, - label: ast.label - ? new StringLiteral(ast.label, offsets[(i += 1)], options) - : undefined, - flags: ast.flags - ? new AssemblyFlagsDeclaration(ast.flags, offsets[(i += 1)], options) - : undefined, - body: new YulBlock(ast.body, offsets[(i += 1)], options) - }; - return children; - }; - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - `${this.assemblyKeyword} `, - this.label ? [path.call(print, 'label'), ' '] : '', - this.flags ? [path.call(print, 'flags'), ' '] : '', - path.call(print, 'body') - ]; - } -} diff --git a/src/slang-nodes/AssemblyStatement.ts b/src/slang-nodes/AssemblyStatement.ts new file mode 100644 index 000000000..c7644695f --- /dev/null +++ b/src/slang-nodes/AssemblyStatement.ts @@ -0,0 +1,60 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { StringLiteral } from './StringLiteral.js'; +import { AssemblyFlagsDeclaration } from './AssemblyFlagsDeclaration.js'; +import { YulBlock } from './YulBlock.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class AssemblyStatement implements SlangNode { + readonly kind = NonterminalKind.AssemblyStatement; + + comments; + + loc; + + assemblyKeyword: string; + + label?: StringLiteral; + + flags?: AssemblyFlagsDeclaration; + + body: YulBlock; + + constructor( + ast: ast.AssemblyStatement, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.assemblyKeyword = ast.assemblyKeyword.text; + let i = 0; + if (ast.label) { + this.label = new StringLiteral(ast.label, offsets[i], options); + i += 1; + } + if (ast.flags) { + this.flags = new AssemblyFlagsDeclaration(ast.flags, offsets[i], options); + i += 1; + } + this.body = new YulBlock(ast.body, offsets[i], options); + + metadata = updateMetadata(metadata, [this.label, this.flags, this.body]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + `${this.assemblyKeyword} `, + this.label ? [path.call(print, 'label'), ' '] : '', + this.flags ? [path.call(print, 'flags'), ' '] : '', + path.call(print, 'body') + ]; + } +} diff --git a/src/slang-nodes/AssignmentExpression.js b/src/slang-nodes/AssignmentExpression.js deleted file mode 100644 index 39db0b40f..000000000 --- a/src/slang-nodes/AssignmentExpression.js +++ /dev/null @@ -1,41 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; -import { SlangNode } from './SlangNode.js'; -import { Expression } from './Expression.js'; - -const { group, indent, line } = doc.builders; - -export class AssignmentExpression extends SlangNode { - get kind() { - return NonterminalKind.AssignmentExpression; - } - - leftOperand; - - operator; - - rightOperand; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - leftOperand: new Expression(ast.leftOperand, offsets[0], options), - operator: ast.operator.text, - rightOperand: new Expression(ast.rightOperand, offsets[1], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - path.call(print, 'leftOperand'), - ` ${this.operator}`, - isBinaryOperation(this.rightOperand.variant) - ? group(indent([line, path.call(print, 'rightOperand')])) - : [' ', path.call(print, 'rightOperand')] - ]; - } -} diff --git a/src/slang-nodes/AssignmentExpression.ts b/src/slang-nodes/AssignmentExpression.ts new file mode 100644 index 000000000..9f72a9d5e --- /dev/null +++ b/src/slang-nodes/AssignmentExpression.ts @@ -0,0 +1,53 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Expression } from './Expression.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { group, indent, line } = doc.builders; + +export class AssignmentExpression implements SlangNode { + readonly kind = NonterminalKind.AssignmentExpression; + + comments; + + loc; + + leftOperand: Expression; + + operator: string; + + rightOperand: Expression; + + constructor( + ast: ast.AssignmentExpression, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.leftOperand = new Expression(ast.leftOperand, offsets[0], options); + this.operator = ast.operator.text; + this.rightOperand = new Expression(ast.rightOperand, offsets[1], options); + + metadata = updateMetadata(metadata, [this.leftOperand, this.rightOperand]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + path.call(print, 'leftOperand'), + ` ${this.operator}`, + isBinaryOperation(this.rightOperand.variant) + ? group(indent([line, path.call(print, 'rightOperand')])) + : [' ', path.call(print, 'rightOperand')] + ]; + } +} diff --git a/src/slang-nodes/BitwiseAndExpression.js b/src/slang-nodes/BitwiseAndExpression.js deleted file mode 100644 index dcbbf0677..000000000 --- a/src/slang-nodes/BitwiseAndExpression.js +++ /dev/null @@ -1,41 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; -import { createHugFunction } from '../slang-utils/create-hug-function.js'; -import { SlangNode } from './SlangNode.js'; -import { Expression } from './Expression.js'; - -const tryToHug = createHugFunction(['+', '-', '*', '/', '**', '<<', '>>']); - -const postProcess = (properties) => ({ - ...properties, - leftOperand: tryToHug(properties.leftOperand), - rightOperand: tryToHug(properties.rightOperand) -}); - -export class BitwiseAndExpression extends SlangNode { - get kind() { - return NonterminalKind.BitwiseAndExpression; - } - - leftOperand; - - operator; - - rightOperand; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - leftOperand: new Expression(ast.leftOperand, offsets[0], options), - operator: ast.operator.text, - rightOperand: new Expression(ast.rightOperand, offsets[1], options) - }); - - this.initialize(ast, offset, fetch, postProcess); - } - - print(path, print, options) { - return printBinaryOperation({ node: this, path, print, options }); - } -} diff --git a/src/slang-nodes/BitwiseAndExpression.ts b/src/slang-nodes/BitwiseAndExpression.ts new file mode 100644 index 000000000..5ccba5bd8 --- /dev/null +++ b/src/slang-nodes/BitwiseAndExpression.ts @@ -0,0 +1,54 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; +import { createHugFunction } from '../slang-utils/create-hug-function.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Expression } from './Expression.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const tryToHug = createHugFunction(['+', '-', '*', '/', '**', '<<', '>>']); + +export class BitwiseAndExpression implements SlangNode { + readonly kind = NonterminalKind.BitwiseAndExpression; + + comments; + + loc; + + leftOperand: Expression; + + operator: string; + + rightOperand: Expression; + + constructor( + ast: ast.BitwiseAndExpression, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.leftOperand = new Expression(ast.leftOperand, offsets[0], options); + this.operator = ast.operator.text; + this.rightOperand = new Expression(ast.rightOperand, offsets[1], options); + + metadata = updateMetadata(metadata, [this.leftOperand, this.rightOperand]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + + this.leftOperand = tryToHug(this.leftOperand); + this.rightOperand = tryToHug(this.rightOperand); + } + + print( + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc { + return printBinaryOperation(this, path, print, options); + } +} diff --git a/src/slang-nodes/BitwiseOrExpression.js b/src/slang-nodes/BitwiseOrExpression.js deleted file mode 100644 index 1af3219cb..000000000 --- a/src/slang-nodes/BitwiseOrExpression.js +++ /dev/null @@ -1,51 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; -import { createHugFunction } from '../slang-utils/create-hug-function.js'; -import { SlangNode } from './SlangNode.js'; -import { Expression } from './Expression.js'; - -const tryToHug = createHugFunction([ - '+', - '-', - '*', - '/', - '**', - '<<', - '>>', - '&', - '^' -]); - -const postProcess = (properties) => ({ - ...properties, - leftOperand: tryToHug(properties.leftOperand), - rightOperand: tryToHug(properties.rightOperand) -}); - -export class BitwiseOrExpression extends SlangNode { - get kind() { - return NonterminalKind.BitwiseOrExpression; - } - - leftOperand; - - operator; - - rightOperand; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - leftOperand: new Expression(ast.leftOperand, offsets[0], options), - operator: ast.operator.text, - rightOperand: new Expression(ast.rightOperand, offsets[1], options) - }); - - this.initialize(ast, offset, fetch, postProcess); - } - - print(path, print, options) { - return printBinaryOperation({ node: this, path, print, options }); - } -} diff --git a/src/slang-nodes/BitwiseOrExpression.ts b/src/slang-nodes/BitwiseOrExpression.ts new file mode 100644 index 000000000..4faa4cf85 --- /dev/null +++ b/src/slang-nodes/BitwiseOrExpression.ts @@ -0,0 +1,64 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; +import { createHugFunction } from '../slang-utils/create-hug-function.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Expression } from './Expression.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const tryToHug = createHugFunction([ + '+', + '-', + '*', + '/', + '**', + '<<', + '>>', + '&', + '^' +]); + +export class BitwiseOrExpression implements SlangNode { + readonly kind = NonterminalKind.BitwiseOrExpression; + + comments; + + loc; + + leftOperand; + + operator; + + rightOperand; + + constructor( + ast: ast.BitwiseOrExpression, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.leftOperand = new Expression(ast.leftOperand, offsets[0], options); + this.operator = ast.operator.text; + this.rightOperand = new Expression(ast.rightOperand, offsets[1], options); + + metadata = updateMetadata(metadata, [this.leftOperand, this.rightOperand]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + + this.leftOperand = tryToHug(this.leftOperand); + this.rightOperand = tryToHug(this.rightOperand); + } + + print( + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc { + return printBinaryOperation(this, path, print, options); + } +} diff --git a/src/slang-nodes/BitwiseXorExpression.js b/src/slang-nodes/BitwiseXorExpression.js deleted file mode 100644 index 4a5a66660..000000000 --- a/src/slang-nodes/BitwiseXorExpression.js +++ /dev/null @@ -1,41 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; -import { createHugFunction } from '../slang-utils/create-hug-function.js'; -import { SlangNode } from './SlangNode.js'; -import { Expression } from './Expression.js'; - -const tryToHug = createHugFunction(['+', '-', '*', '/', '**', '<<', '>>', '&']); - -const postProcess = (properties) => ({ - ...properties, - leftOperand: tryToHug(properties.leftOperand), - rightOperand: tryToHug(properties.rightOperand) -}); - -export class BitwiseXorExpression extends SlangNode { - get kind() { - return NonterminalKind.BitwiseXorExpression; - } - - leftOperand; - - operator; - - rightOperand; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - leftOperand: new Expression(ast.leftOperand, offsets[0], options), - operator: ast.operator.text, - rightOperand: new Expression(ast.rightOperand, offsets[1], options) - }); - - this.initialize(ast, offset, fetch, postProcess); - } - - print(path, print, options) { - return printBinaryOperation({ node: this, path, print, options }); - } -} diff --git a/src/slang-nodes/BitwiseXorExpression.ts b/src/slang-nodes/BitwiseXorExpression.ts new file mode 100644 index 000000000..34231ee16 --- /dev/null +++ b/src/slang-nodes/BitwiseXorExpression.ts @@ -0,0 +1,54 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; +import { createHugFunction } from '../slang-utils/create-hug-function.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Expression } from './Expression.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const tryToHug = createHugFunction(['+', '-', '*', '/', '**', '<<', '>>', '&']); + +export class BitwiseXorExpression implements SlangNode { + readonly kind = NonterminalKind.BitwiseXorExpression; + + comments; + + loc; + + leftOperand: Expression; + + operator: string; + + rightOperand: Expression; + + constructor( + ast: ast.BitwiseXorExpression, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.leftOperand = new Expression(ast.leftOperand, offsets[0], options); + this.operator = ast.operator.text; + this.rightOperand = new Expression(ast.rightOperand, offsets[1], options); + + metadata = updateMetadata(metadata, [this.leftOperand, this.rightOperand]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + + this.leftOperand = tryToHug(this.leftOperand); + this.rightOperand = tryToHug(this.rightOperand); + } + + print( + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc { + return printBinaryOperation(this, path, print, options); + } +} diff --git a/src/slang-nodes/Block.js b/src/slang-nodes/Block.js deleted file mode 100644 index 85c6ead67..000000000 --- a/src/slang-nodes/Block.js +++ /dev/null @@ -1,31 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { Statements } from './Statements.js'; - -export class Block extends SlangNode { - get kind() { - return NonterminalKind.Block; - } - - openBrace; - - statements; - - closeBrace; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - openBrace: ast.openBrace.text, - statements: new Statements(ast.statements, offsets[0], options), - closeBrace: ast.closeBrace.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [this.openBrace, path.call(print, 'statements'), this.closeBrace]; - } -} diff --git a/src/slang-nodes/Block.ts b/src/slang-nodes/Block.ts new file mode 100644 index 000000000..48e304e91 --- /dev/null +++ b/src/slang-nodes/Block.ts @@ -0,0 +1,39 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Statements } from './Statements.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class Block implements SlangNode { + readonly kind = NonterminalKind.Block; + + comments; + + loc; + + openBrace: string; + + statements: Statements; + + closeBrace: string; + + constructor(ast: ast.Block, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.openBrace = ast.openBrace.text; + this.statements = new Statements(ast.statements, offsets[0], options); + this.closeBrace = ast.closeBrace.text; + + metadata = updateMetadata(metadata, [this.statements]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [this.openBrace, path.call(print, 'statements'), this.closeBrace]; + } +} diff --git a/src/slang-nodes/BreakStatement.js b/src/slang-nodes/BreakStatement.js deleted file mode 100644 index 05b621a75..000000000 --- a/src/slang-nodes/BreakStatement.js +++ /dev/null @@ -1,27 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; - -export class BreakStatement extends SlangNode { - get kind() { - return NonterminalKind.BreakStatement; - } - - breakKeyword; - - semicolon; - - constructor(ast, offset) { - super(); - - const fetch = () => ({ - breakKeyword: ast.breakKeyword.text, - semicolon: ast.semicolon.text - }); - - this.initialize(ast, offset, fetch); - } - - print() { - return `${this.breakKeyword}${this.semicolon}`; - } -} diff --git a/src/slang-nodes/BreakStatement.ts b/src/slang-nodes/BreakStatement.ts new file mode 100644 index 000000000..4d750d7a8 --- /dev/null +++ b/src/slang-nodes/BreakStatement.ts @@ -0,0 +1,32 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata } from '../slang-utils/get-offsets.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class BreakStatement implements SlangNode { + readonly kind = NonterminalKind.BreakStatement; + + comments; + + loc; + + breakKeyword: string; + + semicolon: string; + + constructor(ast: ast.BreakStatement, offset: number) { + const metadata = getNodeMetadata(ast, offset); + + this.breakKeyword = ast.breakKeyword.text; + this.semicolon = ast.semicolon.text; + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(): Doc { + return `${this.breakKeyword}${this.semicolon}`; + } +} diff --git a/src/slang-nodes/CallOptions.js b/src/slang-nodes/CallOptions.js deleted file mode 100644 index 1810db343..000000000 --- a/src/slang-nodes/CallOptions.js +++ /dev/null @@ -1,36 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printSeparatedList } from '../common/printer-helpers.js'; -import { SlangNode } from './SlangNode.js'; -import { NamedArgument } from './NamedArgument.js'; - -const { line, softline } = doc.builders; - -export class CallOptions extends SlangNode { - get kind() { - return NonterminalKind.CallOptions; - } - - items; - - separators; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => new NamedArgument(item, offsets[index], options) - ), - separators: ast.separators.map((separator) => separator.text) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print, options) { - return printSeparatedList(path.map(print, 'items'), { - firstSeparator: options.bracketSpacing ? line : softline - }); - } -} diff --git a/src/slang-nodes/CallOptions.ts b/src/slang-nodes/CallOptions.ts new file mode 100644 index 000000000..d2b5a63d9 --- /dev/null +++ b/src/slang-nodes/CallOptions.ts @@ -0,0 +1,48 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printSeparatedList } from '../slang-printers/print-separated-list.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { NamedArgument } from './NamedArgument.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { line, softline } = doc.builders; + +export class CallOptions implements SlangNode { + readonly kind = NonterminalKind.CallOptions; + + comments; + + loc; + + items: NamedArgument[]; + + separators: string[]; + + constructor(ast: ast.CallOptions, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => new NamedArgument(item, offsets[index], options) + ); + this.separators = ast.separators.map((separator) => separator.text); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print( + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc { + return printSeparatedList(path.map(print, 'items'), { + firstSeparator: options.bracketSpacing ? line : softline + }); + } +} diff --git a/src/slang-nodes/CallOptionsExpression.js b/src/slang-nodes/CallOptionsExpression.js deleted file mode 100644 index 69c9e9267..000000000 --- a/src/slang-nodes/CallOptionsExpression.js +++ /dev/null @@ -1,40 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { Expression } from './Expression.js'; -import { CallOptions } from './CallOptions.js'; - -export class CallOptionsExpression extends SlangNode { - get kind() { - return NonterminalKind.CallOptionsExpression; - } - - operand; - - openBrace; - - options; - - closeBrace; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - operand: new Expression(ast.operand, offsets[0], options), - openBrace: ast.openBrace.text, - options: new CallOptions(ast.options, offsets[1], options), - closeBrace: ast.closeBrace.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - path.call(print, 'operand'), - this.openBrace, - path.call(print, 'options'), - this.closeBrace - ]; - } -} diff --git a/src/slang-nodes/CallOptionsExpression.ts b/src/slang-nodes/CallOptionsExpression.ts new file mode 100644 index 000000000..b1a877ba3 --- /dev/null +++ b/src/slang-nodes/CallOptionsExpression.ts @@ -0,0 +1,52 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Expression } from './Expression.js'; +import { CallOptions } from './CallOptions.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class CallOptionsExpression implements SlangNode { + readonly kind = NonterminalKind.CallOptionsExpression; + + comments; + + loc; + + operand: Expression; + + openBrace: string; + + options: CallOptions; + + closeBrace: string; + + constructor( + ast: ast.CallOptionsExpression, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.operand = new Expression(ast.operand, offsets[0], options); + this.openBrace = ast.openBrace.text; + this.options = new CallOptions(ast.options, offsets[1], options); + this.closeBrace = ast.closeBrace.text; + + metadata = updateMetadata(metadata, [this.operand, this.options]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + path.call(print, 'operand'), + this.openBrace, + path.call(print, 'options'), + this.closeBrace + ]; + } +} diff --git a/src/slang-nodes/CatchClause.js b/src/slang-nodes/CatchClause.js deleted file mode 100644 index f00d369d0..000000000 --- a/src/slang-nodes/CatchClause.js +++ /dev/null @@ -1,42 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { CatchClauseError } from './CatchClauseError.js'; -import { Block } from './Block.js'; - -export class CatchClause extends SlangNode { - get kind() { - return NonterminalKind.CatchClause; - } - - catchKeyword; - - error; - - body; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => { - let i = -1; - const children = { - catchKeyword: ast.catchKeyword.text, - error: ast.error - ? new CatchClauseError(ast.error, offsets[(i += 1)], options) - : undefined, - body: new Block(ast.body, offsets[(i += 1)], options) - }; - return children; - }; - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - `${this.catchKeyword} `, - this.error ? path.call(print, 'error') : '', - path.call(print, 'body') - ]; - } -} diff --git a/src/slang-nodes/CatchClause.ts b/src/slang-nodes/CatchClause.ts new file mode 100644 index 000000000..a8c018b6d --- /dev/null +++ b/src/slang-nodes/CatchClause.ts @@ -0,0 +1,48 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { CatchClauseError } from './CatchClauseError.js'; +import { Block } from './Block.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class CatchClause implements SlangNode { + readonly kind = NonterminalKind.CatchClause; + + comments; + + loc; + + catchKeyword: string; + + error?: CatchClauseError; + + body: Block; + + constructor(ast: ast.CatchClause, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.catchKeyword = ast.catchKeyword.text; + let i = 0; + if (ast.error) { + this.error = new CatchClauseError(ast.error, offsets[i], options); + i += 1; + } + this.body = new Block(ast.body, offsets[i], options); + + metadata = updateMetadata(metadata, [this.error, this.body]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + `${this.catchKeyword} `, + this.error ? path.call(print, 'error') : '', + path.call(print, 'body') + ]; + } +} diff --git a/src/slang-nodes/CatchClauseError.js b/src/slang-nodes/CatchClauseError.js deleted file mode 100644 index 5f35dfe30..000000000 --- a/src/slang-nodes/CatchClauseError.js +++ /dev/null @@ -1,31 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { ParametersDeclaration } from './ParametersDeclaration.js'; - -const { group } = doc.builders; - -export class CatchClauseError extends SlangNode { - get kind() { - return NonterminalKind.CatchClauseError; - } - - name; - - parameters; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - name: ast.name?.text, - parameters: new ParametersDeclaration(ast.parameters, offsets[0], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [`${this.name ?? ''}`, group(path.call(print, 'parameters')), ' ']; - } -} diff --git a/src/slang-nodes/CatchClauseError.ts b/src/slang-nodes/CatchClauseError.ts new file mode 100644 index 000000000..844675140 --- /dev/null +++ b/src/slang-nodes/CatchClauseError.ts @@ -0,0 +1,47 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ParametersDeclaration } from './ParametersDeclaration.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { group } = doc.builders; + +export class CatchClauseError implements SlangNode { + readonly kind = NonterminalKind.CatchClauseError; + + comments; + + loc; + + name?: string; + + parameters: ParametersDeclaration; + + constructor( + ast: ast.CatchClauseError, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.name = ast.name?.text; + this.parameters = new ParametersDeclaration( + ast.parameters, + offsets[0], + options + ); + + metadata = updateMetadata(metadata, [this.parameters]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [`${this.name ?? ''}`, group(path.call(print, 'parameters')), ' ']; + } +} diff --git a/src/slang-nodes/CatchClauses.js b/src/slang-nodes/CatchClauses.js deleted file mode 100644 index c965f67fc..000000000 --- a/src/slang-nodes/CatchClauses.js +++ /dev/null @@ -1,30 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { CatchClause } from './CatchClause.js'; - -const { join } = doc.builders; - -export class CatchClauses extends SlangNode { - get kind() { - return NonterminalKind.CatchClauses; - } - - items; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => new CatchClause(item, offsets[index], options) - ) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return join(' ', path.map(print, 'items')); - } -} diff --git a/src/slang-nodes/CatchClauses.ts b/src/slang-nodes/CatchClauses.ts new file mode 100644 index 000000000..19e76209f --- /dev/null +++ b/src/slang-nodes/CatchClauses.ts @@ -0,0 +1,38 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { CatchClause } from './CatchClause.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { join } = doc.builders; + +export class CatchClauses implements SlangNode { + readonly kind = NonterminalKind.CatchClauses; + + comments; + + loc; + + items: CatchClause[]; + + constructor(ast: ast.CatchClauses, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => new CatchClause(item, offsets[index], options) + ); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return join(' ', path.map(print, 'items')); + } +} diff --git a/src/slang-nodes/ComparisonExpression.js b/src/slang-nodes/ComparisonExpression.js deleted file mode 100644 index 68bd84df5..000000000 --- a/src/slang-nodes/ComparisonExpression.js +++ /dev/null @@ -1,32 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printComparisonOperation } from '../slang-printers/print-comparison-operation.js'; -import { SlangNode } from './SlangNode.js'; -import { Expression } from './Expression.js'; - -export class ComparisonExpression extends SlangNode { - get kind() { - return NonterminalKind.ComparisonExpression; - } - - leftOperand; - - operator; - - rightOperand; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - leftOperand: new Expression(ast.leftOperand, offsets[0], options), - operator: ast.operator.text, - rightOperand: new Expression(ast.rightOperand, offsets[1], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print, options) { - return printComparisonOperation({ node: this, path, print, options }); - } -} diff --git a/src/slang-nodes/ComparisonExpression.ts b/src/slang-nodes/ComparisonExpression.ts new file mode 100644 index 000000000..86466f039 --- /dev/null +++ b/src/slang-nodes/ComparisonExpression.ts @@ -0,0 +1,48 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printComparisonOperation } from '../slang-printers/print-comparison-operation.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Expression } from './Expression.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class ComparisonExpression implements SlangNode { + readonly kind = NonterminalKind.ComparisonExpression; + + comments; + + loc; + + leftOperand: Expression; + + operator: string; + + rightOperand: Expression; + + constructor( + ast: ast.ComparisonExpression, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.leftOperand = new Expression(ast.leftOperand, offsets[0], options); + this.operator = ast.operator.text; + this.rightOperand = new Expression(ast.rightOperand, offsets[1], options); + + metadata = updateMetadata(metadata, [this.leftOperand, this.rightOperand]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print( + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc { + return printComparisonOperation(this, path, print, options); + } +} diff --git a/src/slang-nodes/ConditionalExpression.js b/src/slang-nodes/ConditionalExpression.ts similarity index 50% rename from src/slang-nodes/ConditionalExpression.js rename to src/slang-nodes/ConditionalExpression.ts index 9fcf78669..ffa80cb9a 100644 --- a/src/slang-nodes/ConditionalExpression.js +++ b/src/slang-nodes/ConditionalExpression.ts @@ -1,48 +1,41 @@ /* eslint-disable no-nested-ternary */ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printSeparatedItem } from '../common/printer-helpers.js'; -import { SlangNode } from './SlangNode.js'; +import { printSeparatedItem } from '../slang-printers/print-separated-item.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; import { Expression } from './Expression.js'; -const { group, hardline, ifBreak, indent, line, softline } = doc.builders; +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; -const postProcess = (properties) => { - // We can remove parentheses only because we are sure that the - // `condition` must be a single `bool` value. - let { operand } = properties; - const operandLoc = operand.loc; - while ( - operand.variant.kind === 'TupleExpression' && - operand.variant.items.items.length === 1 && - operand.variant.items.items[0].expression.variant.kind !== - 'ConditionalExpression' - ) { - operand = operand.variant.items.items[0].expression; - } - operand.loc = operandLoc; - - return { - ...properties, - operand - }; -}; +const { group, hardline, ifBreak, indent, line, softline } = doc.builders; -function experimentalTernaries(node, path, print, options) { +function experimentalTernaries( + node: ConditionalExpression, + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions +): Doc { const grandparent = path.getNode(2); const isNested = grandparent.kind === 'ConditionalExpression'; const isNestedAsTrueExpression = isNested && grandparent.trueExpression.variant === node; - const falseExpressionIsTuple = - node.falseExpression.variant.kind === 'TupleExpression'; - const falseExpressionInSameLine = - falseExpressionIsTuple || - node.falseExpression.variant.kind === 'ConditionalExpression'; + let falseExpressionIsTuple = false; + let falseExpressionInSameLine = false; + if (typeof node.falseExpression.variant !== 'string') { + falseExpressionIsTuple = + node.falseExpression.variant.kind === 'TupleExpression'; + falseExpressionInSameLine = + falseExpressionIsTuple || + node.falseExpression.variant.kind === 'ConditionalExpression'; + } // If the `condition` breaks into multiple lines, we add parentheses, // unless it already is a `TupleExpression`. const operand = path.call(print, 'operand'); const operandDoc = group([ + typeof node.operand.variant !== 'string' && node.operand.variant.kind === 'TupleExpression' ? operand : ifBreak(['(', printSeparatedItem(operand), ')'], operand), @@ -91,7 +84,11 @@ function experimentalTernaries(node, path, print, options) { : document; } -function traditionalTernaries(node, path, print) { +function traditionalTernaries( + node: ConditionalExpression, + path: AstPath, + print: (path: AstPath) => Doc +): Doc { return group([ path.call(print, 'operand'), indent([ @@ -107,43 +104,78 @@ function traditionalTernaries(node, path, print) { ]); } -export class ConditionalExpression extends SlangNode { - get kind() { - return NonterminalKind.ConditionalExpression; - } +export class ConditionalExpression implements SlangNode { + readonly kind = NonterminalKind.ConditionalExpression; - operand; + comments; - questionMark; + loc; - trueExpression; + operand: Expression; - colon; + questionMark: string; - falseExpression; + trueExpression: Expression; - constructor(ast, offset, options) { - super(); + colon: string; - const fetch = (offsets) => ({ - operand: new Expression(ast.operand, offsets[0], options), - questionMark: ast.questionMark.text, - trueExpression: new Expression(ast.trueExpression, offsets[1], options), - colon: ast.colon.text, - falseExpression: new Expression(ast.falseExpression, offsets[2], options) - }); + falseExpression: Expression; - this.initialize( - ast, - offset, - fetch, - // TODO: while the behaviour is not stable, it should be behind the - // experimentalTernaries flag. - options.experimentalTernaries ? postProcess : undefined + constructor( + ast: ast.ConditionalExpression, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.operand = new Expression(ast.operand, offsets[0], options); + this.questionMark = ast.questionMark.text; + this.trueExpression = new Expression( + ast.trueExpression, + offsets[1], + options ); + this.colon = ast.colon.text; + this.falseExpression = new Expression( + ast.falseExpression, + offsets[2], + options + ); + + metadata = updateMetadata(metadata, [ + this.operand, + this.trueExpression, + this.falseExpression + ]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + + if (options.experimentalTernaries) { + // We can remove parentheses only because we are sure that the + // `condition` must be a single `bool` value. + const operandLoc = this.operand.loc; + while ( + typeof this.operand.variant !== 'string' && + this.operand.variant.kind === 'TupleExpression' && + this.operand.variant.items.items.length === 1 && + (typeof this.operand.variant.items.items[0].expression!.variant === + 'string' || + this.operand.variant.items.items[0].expression!.variant.kind !== + 'ConditionalExpression') + ) { + this.operand = this.operand.variant.items.items[0].expression!; + } + this.operand.loc = operandLoc; + } } - print(path, print, options) { + print( + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc { return options.experimentalTernaries ? experimentalTernaries(this, path, print, options) : traditionalTernaries(this, path, print); diff --git a/src/slang-nodes/ConstantDefinition.js b/src/slang-nodes/ConstantDefinition.js deleted file mode 100644 index 39a1012e1..000000000 --- a/src/slang-nodes/ConstantDefinition.js +++ /dev/null @@ -1,42 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { TypeName } from './TypeName.js'; -import { Expression } from './Expression.js'; - -export class ConstantDefinition extends SlangNode { - get kind() { - return NonterminalKind.ConstantDefinition; - } - - typeName; - - constantKeyword; - - name; - - equal; - - value; - - semicolon; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - typeName: new TypeName(ast.typeName, offsets[0], options), - constantKeyword: ast.constantKeyword.text, - name: ast.name.text, - equal: ast.equal.text, - value: new Expression(ast.value, offsets[1], options), - semicolon: ast.semicolon.text - }); - - this.initialize(ast, offset, fetch); - } - - // TODO: implement print - print(path, print, options) { - return ['TODO: ConstantDefinition']; - } -} diff --git a/src/slang-nodes/ConstantDefinition.ts b/src/slang-nodes/ConstantDefinition.ts new file mode 100644 index 000000000..ab969c137 --- /dev/null +++ b/src/slang-nodes/ConstantDefinition.ts @@ -0,0 +1,58 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { TypeName } from './TypeName.js'; +import { Expression } from './Expression.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class ConstantDefinition implements SlangNode { + readonly kind = NonterminalKind.ConstantDefinition; + + comments; + + loc; + + typeName: TypeName; + + constantKeyword: string; + + name: string; + + equal: string; + + value: Expression; + + semicolon: string; + + constructor( + ast: ast.ConstantDefinition, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.typeName = new TypeName(ast.typeName, offsets[0], options); + this.constantKeyword = ast.constantKeyword.text; + this.name = ast.name.text; + this.equal = ast.equal.text; + this.value = new Expression(ast.value, offsets[1], options); + this.semicolon = ast.semicolon.text; + + metadata = updateMetadata(metadata, [this.typeName, this.value]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + // TODO: implement print + print( + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc { + return ['TODO: ConstantDefinition']; + } +} diff --git a/src/slang-nodes/ConstructorAttribute.js b/src/slang-nodes/ConstructorAttribute.js deleted file mode 100644 index 0d22b32bf..000000000 --- a/src/slang-nodes/ConstructorAttribute.js +++ /dev/null @@ -1,30 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { ModifierInvocation } from './ModifierInvocation.js'; - -export class ConstructorAttribute extends SlangNode { - get kind() { - return NonterminalKind.ConstructorAttribute; - } - - variant; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - variant: - ast.variant.type === 'Terminal' - ? ast.variant.text - : new ModifierInvocation(ast.variant, offsets[0], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return typeof this.variant === 'string' - ? this.variant - : path.call(print, 'variant'); - } -} diff --git a/src/slang-nodes/ConstructorAttribute.ts b/src/slang-nodes/ConstructorAttribute.ts new file mode 100644 index 000000000..87b349d62 --- /dev/null +++ b/src/slang-nodes/ConstructorAttribute.ts @@ -0,0 +1,46 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ModifierInvocation } from './ModifierInvocation.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class ConstructorAttribute implements SlangNode { + readonly kind = NonterminalKind.ConstructorAttribute; + + comments; + + loc; + + variant: ModifierInvocation | string; + + constructor( + ast: ast.ConstructorAttribute, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.variant = + ast.variant instanceof TerminalNode + ? ast.variant.text + : new ModifierInvocation(ast.variant, offsets[0], options); + + metadata = updateMetadata( + metadata, + typeof this.variant === 'string' ? [] : [this.variant] + ); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/ConstructorAttributes.js b/src/slang-nodes/ConstructorAttributes.js deleted file mode 100644 index 5c6ce44ea..000000000 --- a/src/slang-nodes/ConstructorAttributes.js +++ /dev/null @@ -1,31 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { postProcessFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; -import { SlangNode } from './SlangNode.js'; -import { ConstructorAttribute } from './ConstructorAttribute.js'; - -const { line } = doc.builders; - -export class ConstructorAttributes extends SlangNode { - get kind() { - return NonterminalKind.ConstructorAttributes; - } - - items; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => new ConstructorAttribute(item, offsets[index], options) - ) - }); - - this.initialize(ast, offset, fetch, postProcessFunctionAttributes); - } - - print(path, print) { - return path.map(print, 'items').map((item) => [line, item]); - } -} diff --git a/src/slang-nodes/ConstructorAttributes.ts b/src/slang-nodes/ConstructorAttributes.ts new file mode 100644 index 000000000..08e773564 --- /dev/null +++ b/src/slang-nodes/ConstructorAttributes.ts @@ -0,0 +1,45 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ConstructorAttribute } from './ConstructorAttribute.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { line } = doc.builders; + +export class ConstructorAttributes implements SlangNode { + readonly kind = NonterminalKind.ConstructorAttributes; + + comments; + + loc; + + items: ConstructorAttribute[]; + + constructor( + ast: ast.ConstructorAttributes, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => new ConstructorAttribute(item, offsets[index], options) + ); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + + this.items = this.items.sort(sortFunctionAttributes); + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return path.map(print, 'items').map((item) => [line, item]); + } +} diff --git a/src/slang-nodes/ConstructorDefinition.js b/src/slang-nodes/ConstructorDefinition.js deleted file mode 100644 index eada91669..000000000 --- a/src/slang-nodes/ConstructorDefinition.js +++ /dev/null @@ -1,45 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printFunction } from '../slang-printers/print-function.js'; -import { SlangNode } from './SlangNode.js'; -import { ParametersDeclaration } from './ParametersDeclaration.js'; -import { ConstructorAttributes } from './ConstructorAttributes.js'; -import { Block } from './Block.js'; - -export class ConstructorDefinition extends SlangNode { - get kind() { - return NonterminalKind.ConstructorDefinition; - } - - constructorKeyword; - - parameters; - - attributes; - - body; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - constructorKeyword: ast.constructorKeyword.text, - parameters: new ParametersDeclaration( - ast.parameters, - offsets[0], - options - ), - attributes: new ConstructorAttributes( - ast.attributes, - offsets[1], - options - ), - body: new Block(ast.body, offsets[2], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return printFunction(this.constructorKeyword, this, path, print); - } -} diff --git a/src/slang-nodes/ConstructorDefinition.ts b/src/slang-nodes/ConstructorDefinition.ts new file mode 100644 index 000000000..5235e74f9 --- /dev/null +++ b/src/slang-nodes/ConstructorDefinition.ts @@ -0,0 +1,61 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printFunction } from '../slang-printers/print-function.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ParametersDeclaration } from './ParametersDeclaration.js'; +import { ConstructorAttributes } from './ConstructorAttributes.js'; +import { Block } from './Block.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class ConstructorDefinition implements SlangNode { + readonly kind = NonterminalKind.ConstructorDefinition; + + comments; + + loc; + + constructorKeyword: string; + + parameters: ParametersDeclaration; + + attributes: ConstructorAttributes; + + body: Block; + + constructor( + ast: ast.ConstructorDefinition, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.constructorKeyword = ast.constructorKeyword.text; + this.parameters = new ParametersDeclaration( + ast.parameters, + offsets[0], + options + ); + this.attributes = new ConstructorAttributes( + ast.attributes, + offsets[1], + options + ); + this.body = new Block(ast.body, offsets[2], options); + + metadata = updateMetadata(metadata, [ + this.parameters, + this.attributes, + this.body + ]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return printFunction(this.constructorKeyword, this, path, print); + } +} diff --git a/src/slang-nodes/ContinueStatement.js b/src/slang-nodes/ContinueStatement.js deleted file mode 100644 index 6bd7d0753..000000000 --- a/src/slang-nodes/ContinueStatement.js +++ /dev/null @@ -1,27 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; - -export class ContinueStatement extends SlangNode { - get kind() { - return NonterminalKind.ContinueStatement; - } - - continueKeyword; - - semicolon; - - constructor(ast, offset) { - super(); - - const fetch = () => ({ - continueKeyword: ast.continueKeyword.text, - semicolon: ast.semicolon.text - }); - - this.initialize(ast, offset, fetch); - } - - print() { - return `${this.continueKeyword}${this.semicolon}`; - } -} diff --git a/src/slang-nodes/ContinueStatement.ts b/src/slang-nodes/ContinueStatement.ts new file mode 100644 index 000000000..66b831055 --- /dev/null +++ b/src/slang-nodes/ContinueStatement.ts @@ -0,0 +1,32 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata } from '../slang-utils/get-offsets.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class ContinueStatement implements SlangNode { + readonly kind = NonterminalKind.ContinueStatement; + + comments; + + loc; + + continueKeyword: string; + + semicolon: string; + + constructor(ast: ast.ContinueStatement, offset: number) { + const metadata = getNodeMetadata(ast, offset); + + this.continueKeyword = ast.continueKeyword.text; + this.semicolon = ast.semicolon.text; + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(): Doc { + return `${this.continueKeyword}${this.semicolon}`; + } +} diff --git a/src/slang-nodes/ContractDefinition.js b/src/slang-nodes/ContractDefinition.js deleted file mode 100644 index 826089d88..000000000 --- a/src/slang-nodes/ContractDefinition.js +++ /dev/null @@ -1,85 +0,0 @@ -import { doc } from 'prettier'; -import coerce from 'semver/functions/coerce.js'; -import satisfies from 'semver/functions/satisfies.js'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { InheritanceSpecifier } from './InheritanceSpecifier.js'; -import { ContractMembers } from './ContractMembers.js'; - -const { group, line } = doc.builders; - -export class ContractDefinition extends SlangNode { - get kind() { - return NonterminalKind.ContractDefinition; - } - - abstractKeyword; - - contractKeyword; - - name; - - inheritance; - - openBrace; - - members; - - closeBrace; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => { - let i = -1; - const children = { - abstractKeyword: ast.abstractKeyword?.text, - contractKeyword: ast.contractKeyword.text, - name: ast.name.text, - inheritance: ast.inheritance - ? new InheritanceSpecifier( - ast.inheritance, - offsets[(i += 1)], - options - ) - : undefined, - openBrace: ast.openBrace.text, - members: new ContractMembers(ast.members, offsets[(i += 1)], options), - closeBrace: ast.closeBrace.text - }; - return children; - }; - - this.initialize(ast, offset, fetch); - - this.cleanModifierInvocationArguments(options); - } - - cleanModifierInvocationArguments(options) { - // Older versions of Solidity defined a constructor as a function having - // the same name as the contract. - const compiler = coerce(options.compiler); - if (compiler && !satisfies(compiler, '>=0.5.0')) { - this.members.items.forEach((member) => { - if ( - member.variant.kind === 'FunctionDefinition' && - member.variant.name.variant !== this.name - ) { - member.variant.cleanModifierInvocationArguments(); - } - }); - } - } - - print(path, print) { - return [ - group([ - `${this.abstractKeyword ? `${this.abstractKeyword} ` : ''}${this.contractKeyword} ${this.name}`, - this.inheritance ? [' ', path.call(print, 'inheritance')] : line, - this.openBrace - ]), - path.call(print, 'members'), - this.closeBrace - ]; - } -} diff --git a/src/slang-nodes/ContractDefinition.ts b/src/slang-nodes/ContractDefinition.ts new file mode 100644 index 000000000..7fd0dc57a --- /dev/null +++ b/src/slang-nodes/ContractDefinition.ts @@ -0,0 +1,96 @@ +import { doc } from 'prettier'; +import coerce from 'semver/functions/coerce.js'; +import satisfies from 'semver/functions/satisfies.js'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { InheritanceSpecifier } from './InheritanceSpecifier.js'; +import { ContractMembers } from './ContractMembers.js'; +import { FunctionDefinition } from './FunctionDefinition.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { group, line } = doc.builders; + +export class ContractDefinition implements SlangNode { + readonly kind = NonterminalKind.ContractDefinition; + + comments; + + loc; + + abstractKeyword?: string; + + contractKeyword: string; + + name: string; + + inheritance?: InheritanceSpecifier; + + openBrace: string; + + members: ContractMembers; + + closeBrace: string; + + constructor( + ast: ast.ContractDefinition, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.abstractKeyword = ast.abstractKeyword?.text; + this.contractKeyword = ast.contractKeyword.text; + this.name = ast.name.text; + let i = 0; + if (ast.inheritance) { + this.inheritance = new InheritanceSpecifier( + ast.inheritance, + offsets[i], + options + ); + i += 1; + } + this.openBrace = ast.openBrace.text; + this.members = new ContractMembers(ast.members, offsets[i], options); + this.closeBrace = ast.closeBrace.text; + + metadata = updateMetadata(metadata, [this.inheritance, this.members]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + + this.cleanModifierInvocationArguments(options); + } + + cleanModifierInvocationArguments(options: ParserOptions): void { + // Older versions of Solidity defined a constructor as a function having + // the same name as the contract. + const compiler = coerce(options.compiler); + if (compiler && !satisfies(compiler, '>=0.5.0')) { + this.members.items.forEach((member) => { + if ( + member.variant.kind === 'FunctionDefinition' && + member.variant.name.variant !== this.name + ) { + member.variant.cleanModifierInvocationArguments(); + } + }); + } + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + group([ + `${this.abstractKeyword ? `${this.abstractKeyword} ` : ''}${this.contractKeyword} ${this.name}`, + this.inheritance ? [' ', path.call(print, 'inheritance')] : line, + this.openBrace + ]), + path.call(print, 'members'), + this.closeBrace + ]; + } +} diff --git a/src/slang-nodes/ContractMember.js b/src/slang-nodes/ContractMember.js deleted file mode 100644 index 156bb579a..000000000 --- a/src/slang-nodes/ContractMember.js +++ /dev/null @@ -1,57 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { UsingDirective } from './UsingDirective.js'; -import { FunctionDefinition } from './FunctionDefinition.js'; -import { ConstructorDefinition } from './ConstructorDefinition.js'; -import { ReceiveFunctionDefinition } from './ReceiveFunctionDefinition.js'; -import { FallbackFunctionDefinition } from './FallbackFunctionDefinition.js'; -import { UnnamedFunctionDefinition } from './UnnamedFunctionDefinition.js'; -import { ModifierDefinition } from './ModifierDefinition.js'; -import { StructDefinition } from './StructDefinition.js'; -import { EnumDefinition } from './EnumDefinition.js'; -import { EventDefinition } from './EventDefinition.js'; -import { StateVariableDefinition } from './StateVariableDefinition.js'; -import { ErrorDefinition } from './ErrorDefinition.js'; -import { UserDefinedValueTypeDefinition } from './UserDefinedValueTypeDefinition.js'; - -const variants = { - UsingDirective, - FunctionDefinition, - ConstructorDefinition, - ReceiveFunctionDefinition, - FallbackFunctionDefinition, - UnnamedFunctionDefinition, - ModifierDefinition, - StructDefinition, - EnumDefinition, - EventDefinition, - StateVariableDefinition, - ErrorDefinition, - UserDefinedValueTypeDefinition -}; - -export class ContractMember extends SlangNode { - get kind() { - return NonterminalKind.ContractMember; - } - - variant; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - variant: new variants[ast.variant.cst.kind]( - ast.variant, - offsets[0], - options - ) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return path.call(print, 'variant'); - } -} diff --git a/src/slang-nodes/ContractMember.ts b/src/slang-nodes/ContractMember.ts new file mode 100644 index 000000000..004ca416b --- /dev/null +++ b/src/slang-nodes/ContractMember.ts @@ -0,0 +1,150 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { UsingDirective } from './UsingDirective.js'; +import { FunctionDefinition } from './FunctionDefinition.js'; +import { ConstructorDefinition } from './ConstructorDefinition.js'; +import { ReceiveFunctionDefinition } from './ReceiveFunctionDefinition.js'; +import { FallbackFunctionDefinition } from './FallbackFunctionDefinition.js'; +import { UnnamedFunctionDefinition } from './UnnamedFunctionDefinition.js'; +import { ModifierDefinition } from './ModifierDefinition.js'; +import { StructDefinition } from './StructDefinition.js'; +import { EnumDefinition } from './EnumDefinition.js'; +import { EventDefinition } from './EventDefinition.js'; +import { StateVariableDefinition } from './StateVariableDefinition.js'; +import { ErrorDefinition } from './ErrorDefinition.js'; +import { UserDefinedValueTypeDefinition } from './UserDefinedValueTypeDefinition.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class ContractMember implements SlangNode { + readonly kind = NonterminalKind.ContractMember; + + comments; + + loc; + + variant: + | UsingDirective + | FunctionDefinition + | ConstructorDefinition + | ReceiveFunctionDefinition + | FallbackFunctionDefinition + | UnnamedFunctionDefinition + | ModifierDefinition + | StructDefinition + | EnumDefinition + | EventDefinition + | StateVariableDefinition + | ErrorDefinition + | UserDefinedValueTypeDefinition; + + constructor(ast: ast.ContractMember, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + switch (ast.variant.cst.kind) { + case 'UsingDirective': + this.variant = new UsingDirective( + ast.variant as ast.UsingDirective, + offsets[0], + options + ); + break; + case 'FunctionDefinition': + this.variant = new FunctionDefinition( + ast.variant as ast.FunctionDefinition, + offsets[0], + options + ); + break; + case 'ConstructorDefinition': + this.variant = new ConstructorDefinition( + ast.variant as ast.ConstructorDefinition, + offsets[0], + options + ); + break; + case 'ReceiveFunctionDefinition': + this.variant = new ReceiveFunctionDefinition( + ast.variant as ast.ReceiveFunctionDefinition, + offsets[0], + options + ); + break; + case 'FallbackFunctionDefinition': + this.variant = new FallbackFunctionDefinition( + ast.variant as ast.FallbackFunctionDefinition, + offsets[0], + options + ); + break; + case 'UnnamedFunctionDefinition': + this.variant = new UnnamedFunctionDefinition( + ast.variant as ast.UnnamedFunctionDefinition, + offsets[0], + options + ); + break; + case 'ModifierDefinition': + this.variant = new ModifierDefinition( + ast.variant as ast.ModifierDefinition, + offsets[0], + options + ); + break; + case 'StructDefinition': + this.variant = new StructDefinition( + ast.variant as ast.StructDefinition, + offsets[0], + options + ); + break; + case 'EnumDefinition': + this.variant = new EnumDefinition( + ast.variant as ast.EnumDefinition, + offsets[0] + ); + break; + case 'EventDefinition': + this.variant = new EventDefinition( + ast.variant as ast.EventDefinition, + offsets[0], + options + ); + break; + case 'StateVariableDefinition': + this.variant = new StateVariableDefinition( + ast.variant as ast.StateVariableDefinition, + offsets[0], + options + ); + break; + case 'ErrorDefinition': + this.variant = new ErrorDefinition( + ast.variant as ast.ErrorDefinition, + offsets[0], + options + ); + break; + case 'UserDefinedValueTypeDefinition': + this.variant = new UserDefinedValueTypeDefinition( + ast.variant as ast.UserDefinedValueTypeDefinition, + offsets[0] + ); + break; + default: + throw new Error(`Unexpected variant: ${ast.variant.cst.kind}`); + } + + metadata = updateMetadata(metadata, [this.variant]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/ContractMembers.js b/src/slang-nodes/ContractMembers.js deleted file mode 100644 index 84bee99a1..000000000 --- a/src/slang-nodes/ContractMembers.js +++ /dev/null @@ -1,42 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printSeparatedItem } from '../common/printer-helpers.js'; -import { printComments } from '../slang-printers/print-comments.js'; -import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; -import { SlangNode } from './SlangNode.js'; -import { ContractMember } from './ContractMember.js'; - -const { hardline } = doc.builders; - -export class ContractMembers extends SlangNode { - get kind() { - return NonterminalKind.ContractMembers; - } - - items; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => new ContractMember(item, offsets[index], options) - ) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print, options) { - return this.items.length === 0 && - (!this.comments || this.comments.length === 0) - ? '' - : printSeparatedItem( - [ - printPreservingEmptyLines(path, 'items', options, print), - printComments(this, path, options) - ], - { firstSeparator: hardline, grouped: false } - ); - } -} diff --git a/src/slang-nodes/ContractMembers.ts b/src/slang-nodes/ContractMembers.ts new file mode 100644 index 000000000..c85455a16 --- /dev/null +++ b/src/slang-nodes/ContractMembers.ts @@ -0,0 +1,58 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printSeparatedItem } from '../slang-printers/print-separated-item.js'; +import { printComments } from '../slang-printers/print-comments.js'; +import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ContractMember } from './ContractMember.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { hardline } = doc.builders; + +export class ContractMembers implements SlangNode { + readonly kind = NonterminalKind.ContractMembers; + + comments; + + loc; + + items: ContractMember[]; + + constructor( + ast: ast.ContractMembers, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => new ContractMember(item, offsets[index], options) + ); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print( + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc { + return this.items.length === 0 && + (!this.comments || this.comments.length === 0) + ? '' + : printSeparatedItem( + [ + printPreservingEmptyLines(path, 'items', print, options), + printComments(this, path) + ], + { firstSeparator: hardline, grouped: false } + ); + } +} diff --git a/src/slang-nodes/DecimalNumberExpression.js b/src/slang-nodes/DecimalNumberExpression.js deleted file mode 100644 index 3ab9ba52d..000000000 --- a/src/slang-nodes/DecimalNumberExpression.js +++ /dev/null @@ -1,28 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { NumberUnit } from './NumberUnit.js'; - -export class DecimalNumberExpression extends SlangNode { - get kind() { - return NonterminalKind.DecimalNumberExpression; - } - - literal; - - unit; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - literal: ast.literal.text, - unit: ast.unit ? new NumberUnit(ast.unit, offsets[0], options) : undefined - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [this.literal, this.unit ? [' ', path.call(print, 'unit')] : '']; - } -} diff --git a/src/slang-nodes/DecimalNumberExpression.ts b/src/slang-nodes/DecimalNumberExpression.ts new file mode 100644 index 000000000..46d3df7b8 --- /dev/null +++ b/src/slang-nodes/DecimalNumberExpression.ts @@ -0,0 +1,38 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { NumberUnit } from './NumberUnit.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class DecimalNumberExpression implements SlangNode { + readonly kind = NonterminalKind.DecimalNumberExpression; + + comments; + + loc; + + literal: string; + + unit?: NumberUnit; + + constructor(ast: ast.DecimalNumberExpression, offset: number) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.literal = ast.literal.text; + if (ast.unit) { + this.unit = new NumberUnit(ast.unit, offsets[0]); + } + + metadata = updateMetadata(metadata, [this.unit]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [this.literal, this.unit ? [' ', path.call(print, 'unit')] : '']; + } +} diff --git a/src/slang-nodes/DoWhileStatement.js b/src/slang-nodes/DoWhileStatement.js deleted file mode 100644 index 7ab04ea25..000000000 --- a/src/slang-nodes/DoWhileStatement.js +++ /dev/null @@ -1,56 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printSeparatedItem } from '../common/printer-helpers.js'; -import { SlangNode } from './SlangNode.js'; -import { Statement } from './Statement.js'; -import { Expression } from './Expression.js'; - -const { group, indent, line } = doc.builders; - -export class DoWhileStatement extends SlangNode { - get kind() { - return NonterminalKind.DoWhileStatement; - } - - doKeyword; - - body; - - whileKeyword; - - openParen; - - condition; - - closeParen; - - semicolon; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - doKeyword: ast.doKeyword.text, - body: new Statement(ast.body, offsets[0], options), - whileKeyword: ast.whileKeyword.text, - openParen: ast.openParen.text, - condition: new Expression(ast.condition, offsets[1], options), - closeParen: ast.closeParen.text, - semicolon: ast.semicolon.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - this.doKeyword, - this.body.variant.kind === 'Block' - ? [' ', path.call(print, 'body'), ' '] - : group([indent([line, path.call(print, 'body')]), line]), - `${this.whileKeyword} ${this.openParen}`, - printSeparatedItem(path.call(print, 'condition')), - `${this.closeParen}${this.semicolon}` - ]; - } -} diff --git a/src/slang-nodes/DoWhileStatement.ts b/src/slang-nodes/DoWhileStatement.ts new file mode 100644 index 000000000..3be3253b3 --- /dev/null +++ b/src/slang-nodes/DoWhileStatement.ts @@ -0,0 +1,68 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printSeparatedItem } from '../slang-printers/print-separated-item.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Statement } from './Statement.js'; +import { Expression } from './Expression.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { group, indent, line } = doc.builders; + +export class DoWhileStatement implements SlangNode { + readonly kind = NonterminalKind.DoWhileStatement; + + comments; + + loc; + + doKeyword: string; + + body: Statement; + + whileKeyword: string; + + openParen: string; + + condition: Expression; + + closeParen: string; + + semicolon: string; + + constructor( + ast: ast.DoWhileStatement, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.doKeyword = ast.doKeyword.text; + this.body = new Statement(ast.body, offsets[0], options); + this.whileKeyword = ast.whileKeyword.text; + this.openParen = ast.openParen.text; + this.condition = new Expression(ast.condition, offsets[1], options); + this.closeParen = ast.closeParen.text; + this.semicolon = ast.semicolon.text; + + metadata = updateMetadata(metadata, [this.body, this.condition]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + this.doKeyword, + this.body.variant.kind === 'Block' + ? [' ', path.call(print, 'body'), ' '] + : group([indent([line, path.call(print, 'body')]), line]), + `${this.whileKeyword} ${this.openParen}`, + printSeparatedItem(path.call(print, 'condition')), + `${this.closeParen}${this.semicolon}` + ]; + } +} diff --git a/src/slang-nodes/ElementaryType.js b/src/slang-nodes/ElementaryType.js deleted file mode 100644 index 4a1b2fbd0..000000000 --- a/src/slang-nodes/ElementaryType.js +++ /dev/null @@ -1,30 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { AddressType } from './AddressType.js'; - -export class ElementaryType extends SlangNode { - get kind() { - return NonterminalKind.ElementaryType; - } - - variant; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - variant: - ast.variant.type === 'Terminal' - ? ast.variant.text - : new AddressType(ast.variant, offsets[0], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return typeof this.variant === 'string' - ? this.variant - : path.call(print, 'variant'); - } -} diff --git a/src/slang-nodes/ElementaryType.ts b/src/slang-nodes/ElementaryType.ts new file mode 100644 index 000000000..929bcf060 --- /dev/null +++ b/src/slang-nodes/ElementaryType.ts @@ -0,0 +1,42 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { AddressType } from './AddressType.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class ElementaryType implements SlangNode { + readonly kind = NonterminalKind.ElementaryType; + + comments; + + loc; + + variant: AddressType | string; + + constructor(ast: ast.ElementaryType, offset: number) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.variant = + ast.variant instanceof TerminalNode + ? ast.variant.text + : new AddressType(ast.variant, offsets[0]); + + metadata = updateMetadata( + metadata, + typeof this.variant === 'string' ? [] : [this.variant] + ); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/ElseBranch.js b/src/slang-nodes/ElseBranch.js deleted file mode 100644 index e36f0f2c4..000000000 --- a/src/slang-nodes/ElseBranch.js +++ /dev/null @@ -1,39 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js'; -import { SlangNode } from './SlangNode.js'; -import { Statement } from './Statement.js'; - -const { group, indent, line } = doc.builders; - -const isIfStatementOrBlock = createKindCheckFunction(['Block', 'IfStatement']); - -export class ElseBranch extends SlangNode { - get kind() { - return NonterminalKind.ElseBranch; - } - - elseKeyword; - - body; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - elseKeyword: ast.elseKeyword.text, - body: new Statement(ast.body, offsets[0], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - this.elseKeyword, - isIfStatementOrBlock(this.body.variant) - ? [' ', path.call(print, 'body')] - : group(indent([line, path.call(print, 'body')])) - ]; - } -} diff --git a/src/slang-nodes/ElseBranch.ts b/src/slang-nodes/ElseBranch.ts new file mode 100644 index 000000000..68139eba4 --- /dev/null +++ b/src/slang-nodes/ElseBranch.ts @@ -0,0 +1,47 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Statement } from './Statement.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { group, indent, line } = doc.builders; + +const isIfStatementOrBlock = createKindCheckFunction(['Block', 'IfStatement']); + +export class ElseBranch implements SlangNode { + readonly kind = NonterminalKind.ElseBranch; + + comments; + + loc; + + elseKeyword: string; + + body: Statement; + + constructor(ast: ast.ElseBranch, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.elseKeyword = ast.elseKeyword.text; + this.body = new Statement(ast.body, offsets[0], options); + + metadata = updateMetadata(metadata, [this.body]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + this.elseKeyword, + isIfStatementOrBlock(this.body.variant) + ? [' ', path.call(print, 'body')] + : group(indent([line, path.call(print, 'body')])) + ]; + } +} diff --git a/src/slang-nodes/EmitStatement.js b/src/slang-nodes/EmitStatement.js deleted file mode 100644 index 7c0310acd..000000000 --- a/src/slang-nodes/EmitStatement.js +++ /dev/null @@ -1,40 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { IdentifierPath } from './IdentifierPath.js'; -import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; - -export class EmitStatement extends SlangNode { - get kind() { - return NonterminalKind.EmitStatement; - } - - emitKeyword; - - event; - - arguments; - - semicolon; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - emitKeyword: ast.emitKeyword.text, - event: new IdentifierPath(ast.event, offsets[0], options), - arguments: new ArgumentsDeclaration(ast.arguments, offsets[1], options), - semicolon: ast.semicolon.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - `${this.emitKeyword} `, - path.call(print, 'event'), - path.call(print, 'arguments'), - this.semicolon - ]; - } -} diff --git a/src/slang-nodes/EmitStatement.ts b/src/slang-nodes/EmitStatement.ts new file mode 100644 index 000000000..ae7c3fac6 --- /dev/null +++ b/src/slang-nodes/EmitStatement.ts @@ -0,0 +1,52 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { IdentifierPath } from './IdentifierPath.js'; +import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class EmitStatement implements SlangNode { + readonly kind = NonterminalKind.EmitStatement; + + comments; + + loc; + + emitKeyword: string; + + event: IdentifierPath; + + arguments: ArgumentsDeclaration; + + semicolon: string; + + constructor(ast: ast.EmitStatement, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.emitKeyword = ast.emitKeyword.text; + this.event = new IdentifierPath(ast.event, offsets[0]); + this.arguments = new ArgumentsDeclaration( + ast.arguments, + offsets[1], + options + ); + this.semicolon = ast.semicolon.text; + + metadata = updateMetadata(metadata, [this.event, this.arguments]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + `${this.emitKeyword} `, + path.call(print, 'event'), + path.call(print, 'arguments'), + this.semicolon + ]; + } +} diff --git a/src/slang-nodes/EnumDefinition.js b/src/slang-nodes/EnumDefinition.js deleted file mode 100644 index ec94628ee..000000000 --- a/src/slang-nodes/EnumDefinition.js +++ /dev/null @@ -1,41 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { EnumMembers } from './EnumMembers.js'; - -export class EnumDefinition extends SlangNode { - get kind() { - return NonterminalKind.EnumDefinition; - } - - enumKeyword; - - name; - - openBrace; - - members; - - closeBrace; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - enumKeyword: ast.enumKeyword.text, - name: ast.name.text, - openBrace: ast.openBrace.text, - members: new EnumMembers(ast.members, offsets[0], options), - closeBrace: ast.closeBrace.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - `${this.enumKeyword} ${this.name} ${this.openBrace}`, - path.call(print, 'members'), - this.closeBrace - ]; - } -} diff --git a/src/slang-nodes/EnumDefinition.ts b/src/slang-nodes/EnumDefinition.ts new file mode 100644 index 000000000..390833fd3 --- /dev/null +++ b/src/slang-nodes/EnumDefinition.ts @@ -0,0 +1,49 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { EnumMembers } from './EnumMembers.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class EnumDefinition implements SlangNode { + readonly kind = NonterminalKind.EnumDefinition; + + comments; + + loc; + + enumKeyword: string; + + name: string; + + openBrace: string; + + members: EnumMembers; + + closeBrace: string; + + constructor(ast: ast.EnumDefinition, offset: number) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.enumKeyword = ast.enumKeyword.text; + this.name = ast.name.text; + this.openBrace = ast.openBrace.text; + this.members = new EnumMembers(ast.members, offsets[0]); + this.closeBrace = ast.closeBrace.text; + + metadata = updateMetadata(metadata, [this.members]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + `${this.enumKeyword} ${this.name} ${this.openBrace}`, + path.call(print, 'members'), + this.closeBrace + ]; + } +} diff --git a/src/slang-nodes/EnumMembers.js b/src/slang-nodes/EnumMembers.js deleted file mode 100644 index 973046a4f..000000000 --- a/src/slang-nodes/EnumMembers.js +++ /dev/null @@ -1,31 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printSeparatedList } from '../common/printer-helpers.js'; -import { SlangNode } from './SlangNode.js'; - -const { hardline } = doc.builders; - -export class EnumMembers extends SlangNode { - get kind() { - return NonterminalKind.EnumMembers; - } - - items; - - separators; - - constructor(ast, offset) { - super(); - - const fetch = () => ({ - items: ast.items.map((item) => item.text), - separators: ast.separators.map((separator) => separator.text) - }); - - this.initialize(ast, offset, fetch); - } - - print() { - return printSeparatedList(this.items, { firstSeparator: hardline }); - } -} diff --git a/src/slang-nodes/EnumMembers.ts b/src/slang-nodes/EnumMembers.ts new file mode 100644 index 000000000..bbbb96b91 --- /dev/null +++ b/src/slang-nodes/EnumMembers.ts @@ -0,0 +1,36 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printSeparatedList } from '../slang-printers/print-separated-list.js'; +import { getNodeMetadata } from '../slang-utils/get-offsets.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { hardline } = doc.builders; + +export class EnumMembers implements SlangNode { + readonly kind = NonterminalKind.EnumMembers; + + comments; + + loc; + + items: string[]; + + separators: string[]; + + constructor(ast: ast.EnumMembers, offset: number) { + const metadata = getNodeMetadata(ast, offset); + + this.items = ast.items.map((item) => item.text); + this.separators = ast.separators.map((separator) => separator.text); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(): Doc { + return printSeparatedList(this.items, { firstSeparator: hardline }); + } +} diff --git a/src/slang-nodes/EqualityExpression.js b/src/slang-nodes/EqualityExpression.js deleted file mode 100644 index ed11e76a6..000000000 --- a/src/slang-nodes/EqualityExpression.js +++ /dev/null @@ -1,32 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printComparisonOperation } from '../slang-printers/print-comparison-operation.js'; -import { SlangNode } from './SlangNode.js'; -import { Expression } from './Expression.js'; - -export class EqualityExpression extends SlangNode { - get kind() { - return NonterminalKind.EqualityExpression; - } - - leftOperand; - - operator; - - rightOperand; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - leftOperand: new Expression(ast.leftOperand, offsets[0], options), - operator: ast.operator.text, - rightOperand: new Expression(ast.rightOperand, offsets[1], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print, options) { - return printComparisonOperation({ node: this, path, print, options }); - } -} diff --git a/src/slang-nodes/EqualityExpression.ts b/src/slang-nodes/EqualityExpression.ts new file mode 100644 index 000000000..6d05a3a4d --- /dev/null +++ b/src/slang-nodes/EqualityExpression.ts @@ -0,0 +1,48 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printComparisonOperation } from '../slang-printers/print-comparison-operation.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Expression } from './Expression.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class EqualityExpression implements SlangNode { + readonly kind = NonterminalKind.EqualityExpression; + + comments; + + loc; + + leftOperand: Expression; + + operator: string; + + rightOperand: Expression; + + constructor( + ast: ast.EqualityExpression, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.leftOperand = new Expression(ast.leftOperand, offsets[0], options); + this.operator = ast.operator.text; + this.rightOperand = new Expression(ast.rightOperand, offsets[1], options); + + metadata = updateMetadata(metadata, [this.leftOperand, this.rightOperand]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print( + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc { + return printComparisonOperation(this, path, print, options); + } +} diff --git a/src/slang-nodes/ErrorDefinition.js b/src/slang-nodes/ErrorDefinition.js deleted file mode 100644 index ff1015f58..000000000 --- a/src/slang-nodes/ErrorDefinition.js +++ /dev/null @@ -1,38 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { ErrorParametersDeclaration } from './ErrorParametersDeclaration.js'; - -export class ErrorDefinition extends SlangNode { - get kind() { - return NonterminalKind.ErrorDefinition; - } - - errorKeyword; - - name; - - members; - - semicolon; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - errorKeyword: ast.errorKeyword.text, - name: ast.name.text, - members: new ErrorParametersDeclaration(ast.members, offsets[0], options), - semicolon: ast.semicolon.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - `${this.errorKeyword} ${this.name}`, - path.call(print, 'members'), - this.semicolon - ]; - } -} diff --git a/src/slang-nodes/ErrorDefinition.ts b/src/slang-nodes/ErrorDefinition.ts new file mode 100644 index 000000000..0c6a625ce --- /dev/null +++ b/src/slang-nodes/ErrorDefinition.ts @@ -0,0 +1,54 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ErrorParametersDeclaration } from './ErrorParametersDeclaration.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class ErrorDefinition implements SlangNode { + readonly kind = NonterminalKind.ErrorDefinition; + + comments; + + loc; + + errorKeyword: string; + + name: string; + + members: ErrorParametersDeclaration; + + semicolon: string; + + constructor( + ast: ast.ErrorDefinition, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.errorKeyword = ast.errorKeyword.text; + this.name = ast.name.text; + this.members = new ErrorParametersDeclaration( + ast.members, + offsets[0], + options + ); + this.semicolon = ast.semicolon.text; + + metadata = updateMetadata(metadata, [this.members]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + `${this.errorKeyword} ${this.name}`, + path.call(print, 'members'), + this.semicolon + ]; + } +} diff --git a/src/slang-nodes/ErrorParameter.js b/src/slang-nodes/ErrorParameter.js deleted file mode 100644 index 5121e9b8e..000000000 --- a/src/slang-nodes/ErrorParameter.js +++ /dev/null @@ -1,28 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { TypeName } from './TypeName.js'; - -export class ErrorParameter extends SlangNode { - get kind() { - return NonterminalKind.ErrorParameter; - } - - typeName; - - name; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - typeName: new TypeName(ast.typeName, offsets[0], options), - name: ast.name?.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [path.call(print, 'typeName'), this.name ? ` ${this.name}` : '']; - } -} diff --git a/src/slang-nodes/ErrorParameter.ts b/src/slang-nodes/ErrorParameter.ts new file mode 100644 index 000000000..49bf46ab4 --- /dev/null +++ b/src/slang-nodes/ErrorParameter.ts @@ -0,0 +1,36 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { TypeName } from './TypeName.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class ErrorParameter implements SlangNode { + readonly kind = NonterminalKind.ErrorParameter; + + comments; + + loc; + + typeName: TypeName; + + name?: string; + + constructor(ast: ast.ErrorParameter, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.typeName = new TypeName(ast.typeName, offsets[0], options); + this.name = ast.name?.text; + + metadata = updateMetadata(metadata, [this.typeName]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [path.call(print, 'typeName'), this.name ? ` ${this.name}` : '']; + } +} diff --git a/src/slang-nodes/ErrorParameters.js b/src/slang-nodes/ErrorParameters.js deleted file mode 100644 index d68208d73..000000000 --- a/src/slang-nodes/ErrorParameters.js +++ /dev/null @@ -1,33 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printSeparatedList } from '../common/printer-helpers.js'; -import { SlangNode } from './SlangNode.js'; -import { ErrorParameter } from './ErrorParameter.js'; - -export class ErrorParameters extends SlangNode { - get kind() { - return NonterminalKind.ErrorParameters; - } - - items; - - separators; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => new ErrorParameter(item, offsets[index], options) - ), - separators: ast.separators.map((separator) => separator.text) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return this.items.length > 0 - ? printSeparatedList(path.map(print, 'items')) - : ''; - } -} diff --git a/src/slang-nodes/ErrorParameters.ts b/src/slang-nodes/ErrorParameters.ts new file mode 100644 index 000000000..47a206e33 --- /dev/null +++ b/src/slang-nodes/ErrorParameters.ts @@ -0,0 +1,45 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printSeparatedList } from '../slang-printers/print-separated-list.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ErrorParameter } from './ErrorParameter.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class ErrorParameters implements SlangNode { + readonly kind = NonterminalKind.ErrorParameters; + + comments; + + loc; + + items: ErrorParameter[]; + + separators: string[]; + + constructor( + ast: ast.ErrorParameters, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => new ErrorParameter(item, offsets[index], options) + ); + this.separators = ast.separators.map((separator) => separator.text); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return this.items.length > 0 + ? printSeparatedList(path.map(print, 'items')) + : ''; + } +} diff --git a/src/slang-nodes/ErrorParametersDeclaration.js b/src/slang-nodes/ErrorParametersDeclaration.js deleted file mode 100644 index e334e4417..000000000 --- a/src/slang-nodes/ErrorParametersDeclaration.js +++ /dev/null @@ -1,31 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { ErrorParameters } from './ErrorParameters.js'; - -export class ErrorParametersDeclaration extends SlangNode { - get kind() { - return NonterminalKind.ErrorParametersDeclaration; - } - - openParen; - - parameters; - - closeParen; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - openParen: ast.openParen.text, - parameters: new ErrorParameters(ast.parameters, offsets[0], options), - closeParen: ast.closeParen.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [this.openParen, path.call(print, 'parameters'), this.closeParen]; - } -} diff --git a/src/slang-nodes/ErrorParametersDeclaration.ts b/src/slang-nodes/ErrorParametersDeclaration.ts new file mode 100644 index 000000000..085f05a96 --- /dev/null +++ b/src/slang-nodes/ErrorParametersDeclaration.ts @@ -0,0 +1,43 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ErrorParameters } from './ErrorParameters.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class ErrorParametersDeclaration implements SlangNode { + readonly kind = NonterminalKind.ErrorParametersDeclaration; + + comments; + + loc; + + openParen: string; + + parameters: ErrorParameters; + + closeParen: string; + + constructor( + ast: ast.ErrorParametersDeclaration, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.openParen = ast.openParen.text; + this.parameters = new ErrorParameters(ast.parameters, offsets[0], options); + this.closeParen = ast.closeParen.text; + + metadata = updateMetadata(metadata, [this.parameters]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [this.openParen, path.call(print, 'parameters'), this.closeParen]; + } +} diff --git a/src/slang-nodes/EventDefinition.js b/src/slang-nodes/EventDefinition.js deleted file mode 100644 index 217551aa1..000000000 --- a/src/slang-nodes/EventDefinition.js +++ /dev/null @@ -1,46 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { EventParametersDeclaration } from './EventParametersDeclaration.js'; - -export class EventDefinition extends SlangNode { - get kind() { - return NonterminalKind.EventDefinition; - } - - eventKeyword; - - name; - - parameters; - - anonymousKeyword; - - semicolon; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - eventKeyword: ast.eventKeyword.text, - name: ast.name.text, - parameters: new EventParametersDeclaration( - ast.parameters, - offsets[0], - options - ), - anonymousKeyword: ast.anonymousKeyword?.text, - semicolon: ast.semicolon.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - `${this.eventKeyword} ${this.name}`, - path.call(print, 'parameters'), - this.anonymousKeyword ? ` ${this.anonymousKeyword}` : '', - this.semicolon - ]; - } -} diff --git a/src/slang-nodes/EventDefinition.ts b/src/slang-nodes/EventDefinition.ts new file mode 100644 index 000000000..439d1cb13 --- /dev/null +++ b/src/slang-nodes/EventDefinition.ts @@ -0,0 +1,58 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { EventParametersDeclaration } from './EventParametersDeclaration.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class EventDefinition implements SlangNode { + readonly kind = NonterminalKind.EventDefinition; + + comments; + + loc; + + eventKeyword: string; + + name: string; + + parameters: EventParametersDeclaration; + + anonymousKeyword?: string; + + semicolon: string; + + constructor( + ast: ast.EventDefinition, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.eventKeyword = ast.eventKeyword.text; + this.name = ast.name.text; + this.parameters = new EventParametersDeclaration( + ast.parameters, + offsets[0], + options + ); + this.anonymousKeyword = ast.anonymousKeyword?.text; + this.semicolon = ast.semicolon.text; + + metadata = updateMetadata(metadata, [this.parameters]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + `${this.eventKeyword} ${this.name}`, + path.call(print, 'parameters'), + this.anonymousKeyword ? ` ${this.anonymousKeyword}` : '', + this.semicolon + ]; + } +} diff --git a/src/slang-nodes/EventParameter.js b/src/slang-nodes/EventParameter.js deleted file mode 100644 index 22e2a70ca..000000000 --- a/src/slang-nodes/EventParameter.js +++ /dev/null @@ -1,35 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { TypeName } from './TypeName.js'; - -export class EventParameter extends SlangNode { - get kind() { - return NonterminalKind.EventParameter; - } - - typeName; - - indexedKeyword; - - name; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - typeName: new TypeName(ast.typeName, offsets[0], options), - indexedKeyword: ast.indexedKeyword?.text, - name: ast.name?.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - path.call(print, 'typeName'), - this.indexedKeyword ? ` ${this.indexedKeyword}` : '', - this.name ? ` ${this.name}` : '' - ]; - } -} diff --git a/src/slang-nodes/EventParameter.ts b/src/slang-nodes/EventParameter.ts new file mode 100644 index 000000000..4096aeef7 --- /dev/null +++ b/src/slang-nodes/EventParameter.ts @@ -0,0 +1,43 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { TypeName } from './TypeName.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class EventParameter implements SlangNode { + readonly kind = NonterminalKind.EventParameter; + + comments; + + loc; + + typeName: TypeName; + + indexedKeyword?: string; + + name?: string; + + constructor(ast: ast.EventParameter, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.typeName = new TypeName(ast.typeName, offsets[0], options); + this.indexedKeyword = ast.indexedKeyword?.text; + this.name = ast.name?.text; + + metadata = updateMetadata(metadata, [this.typeName]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + path.call(print, 'typeName'), + this.indexedKeyword ? ` ${this.indexedKeyword}` : '', + this.name ? ` ${this.name}` : '' + ]; + } +} diff --git a/src/slang-nodes/EventParameters.js b/src/slang-nodes/EventParameters.js deleted file mode 100644 index dbe98426b..000000000 --- a/src/slang-nodes/EventParameters.js +++ /dev/null @@ -1,33 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printSeparatedList } from '../common/printer-helpers.js'; -import { SlangNode } from './SlangNode.js'; -import { EventParameter } from './EventParameter.js'; - -export class EventParameters extends SlangNode { - get kind() { - return NonterminalKind.EventParameters; - } - - items; - - separators; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => new EventParameter(item, offsets[index], options) - ), - separators: ast.separators.map((separator) => separator.text) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return this.items.length > 0 - ? printSeparatedList(path.map(print, 'items')) - : ''; - } -} diff --git a/src/slang-nodes/EventParameters.ts b/src/slang-nodes/EventParameters.ts new file mode 100644 index 000000000..105193e84 --- /dev/null +++ b/src/slang-nodes/EventParameters.ts @@ -0,0 +1,45 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printSeparatedList } from '../slang-printers/print-separated-list.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { EventParameter } from './EventParameter.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class EventParameters implements SlangNode { + readonly kind = NonterminalKind.EventParameters; + + comments; + + loc; + + items: EventParameter[]; + + separators: string[]; + + constructor( + ast: ast.EventParameters, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => new EventParameter(item, offsets[index], options) + ); + this.separators = ast.separators.map((separator) => separator.text); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return this.items.length > 0 + ? printSeparatedList(path.map(print, 'items')) + : ''; + } +} diff --git a/src/slang-nodes/EventParametersDeclaration.js b/src/slang-nodes/EventParametersDeclaration.js deleted file mode 100644 index bd3440edc..000000000 --- a/src/slang-nodes/EventParametersDeclaration.js +++ /dev/null @@ -1,31 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { EventParameters } from './EventParameters.js'; - -export class EventParametersDeclaration extends SlangNode { - get kind() { - return NonterminalKind.EventParametersDeclaration; - } - - openParen; - - parameters; - - closeParen; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - openParen: ast.openParen.text, - parameters: new EventParameters(ast.parameters, offsets[0], options), - closeParen: ast.closeParen.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [this.openParen, path.call(print, 'parameters'), this.closeParen]; - } -} diff --git a/src/slang-nodes/EventParametersDeclaration.ts b/src/slang-nodes/EventParametersDeclaration.ts new file mode 100644 index 000000000..9d5f148b4 --- /dev/null +++ b/src/slang-nodes/EventParametersDeclaration.ts @@ -0,0 +1,43 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { EventParameters } from './EventParameters.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class EventParametersDeclaration implements SlangNode { + readonly kind = NonterminalKind.EventParametersDeclaration; + + comments; + + loc; + + openParen: string; + + parameters: EventParameters; + + closeParen: string; + + constructor( + ast: ast.EventParametersDeclaration, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.openParen = ast.openParen.text; + this.parameters = new EventParameters(ast.parameters, offsets[0], options); + this.closeParen = ast.closeParen.text; + + metadata = updateMetadata(metadata, [this.parameters]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [this.openParen, path.call(print, 'parameters'), this.closeParen]; + } +} diff --git a/src/slang-nodes/ExperimentalFeature.js b/src/slang-nodes/ExperimentalFeature.js deleted file mode 100644 index 65aa84985..000000000 --- a/src/slang-nodes/ExperimentalFeature.js +++ /dev/null @@ -1,30 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { StringLiteral } from './StringLiteral.js'; - -export class ExperimentalFeature extends SlangNode { - get kind() { - return NonterminalKind.ExperimentalFeature; - } - - variant; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - variant: - ast.variant.type === 'Terminal' - ? ast.variant.text - : new StringLiteral(ast.variant, offsets[0], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return typeof this.variant === 'string' - ? this.variant - : path.call(print, 'variant'); - } -} diff --git a/src/slang-nodes/ExperimentalFeature.ts b/src/slang-nodes/ExperimentalFeature.ts new file mode 100644 index 000000000..d0031d85f --- /dev/null +++ b/src/slang-nodes/ExperimentalFeature.ts @@ -0,0 +1,46 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { StringLiteral } from './StringLiteral.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class ExperimentalFeature implements SlangNode { + readonly kind = NonterminalKind.ExperimentalFeature; + + comments; + + loc; + + variant: StringLiteral | string; + + constructor( + ast: ast.ExperimentalFeature, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.variant = + ast.variant instanceof TerminalNode + ? ast.variant.text + : new StringLiteral(ast.variant, offsets[0], options); + + metadata = updateMetadata( + metadata, + typeof this.variant === 'string' ? [] : [this.variant] + ); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/ExperimentalPragma.js b/src/slang-nodes/ExperimentalPragma.js deleted file mode 100644 index c05e826a2..000000000 --- a/src/slang-nodes/ExperimentalPragma.js +++ /dev/null @@ -1,28 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { ExperimentalFeature } from './ExperimentalFeature.js'; - -export class ExperimentalPragma extends SlangNode { - get kind() { - return NonterminalKind.ExperimentalPragma; - } - - experimentalKeyword; - - feature; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - experimentalKeyword: ast.experimentalKeyword.text, - feature: new ExperimentalFeature(ast.feature, offsets[0], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [`${this.experimentalKeyword} `, path.call(print, 'feature')]; - } -} diff --git a/src/slang-nodes/ExperimentalPragma.ts b/src/slang-nodes/ExperimentalPragma.ts new file mode 100644 index 000000000..72019f939 --- /dev/null +++ b/src/slang-nodes/ExperimentalPragma.ts @@ -0,0 +1,40 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ExperimentalFeature } from './ExperimentalFeature.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class ExperimentalPragma implements SlangNode { + readonly kind = NonterminalKind.ExperimentalPragma; + + comments; + + loc; + + experimentalKeyword: string; + + feature: ExperimentalFeature; + + constructor( + ast: ast.ExperimentalPragma, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.experimentalKeyword = ast.experimentalKeyword.text; + this.feature = new ExperimentalFeature(ast.feature, offsets[0], options); + + metadata = updateMetadata(metadata, [this.feature]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [`${this.experimentalKeyword} `, path.call(print, 'feature')]; + } +} diff --git a/src/slang-nodes/ExponentiationExpression.js b/src/slang-nodes/ExponentiationExpression.ts similarity index 60% rename from src/slang-nodes/ExponentiationExpression.js rename to src/slang-nodes/ExponentiationExpression.ts index 98c41dc41..32a333172 100644 --- a/src/slang-nodes/ExponentiationExpression.js +++ b/src/slang-nodes/ExponentiationExpression.ts @@ -4,42 +4,58 @@ import satisfies from 'semver/functions/satisfies.js'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { createBinaryOperationPrinter } from '../slang-printers/create-binary-operation-printer.js'; import { createHugFunction } from '../slang-utils/create-hug-function.js'; -import { SlangNode } from './SlangNode.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; import { Expression } from './Expression.js'; import { TupleExpression } from './TupleExpression.js'; import { TupleValues } from './TupleValues.js'; import { TupleValue } from './TupleValue.js'; +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + const { group, indent } = doc.builders; const tryToHug = createHugFunction(['**']); const printExponentiationExpression = createBinaryOperationPrinter( - () => (document) => group(document), // always group - () => (document) => indent(document) // always indent + () => + (document: Doc): Doc => + group(document), // always group + () => + (document: Doc): Doc => + indent(document) // always indent ); -export class ExponentiationExpression extends SlangNode { - get kind() { - return NonterminalKind.ExponentiationExpression; - } +export class ExponentiationExpression implements SlangNode { + readonly kind = NonterminalKind.ExponentiationExpression; + + comments; - leftOperand; + loc; - operator; + leftOperand: Expression; - rightOperand; + operator: string; - constructor(ast, offset, options) { - super(); + rightOperand: Expression; - const fetch = (offsets) => ({ - leftOperand: new Expression(ast.leftOperand, offsets[0], options), - operator: ast.operator.text, - rightOperand: new Expression(ast.rightOperand, offsets[1], options) - }); + constructor( + ast: ast.ExponentiationExpression, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; - this.initialize(ast, offset, fetch); + this.leftOperand = new Expression(ast.leftOperand, offsets[0], options); + this.operator = ast.operator.text; + this.rightOperand = new Expression(ast.rightOperand, offsets[1], options); + + metadata = updateMetadata(metadata, [this.leftOperand, this.rightOperand]); + + this.comments = metadata.comments; + this.loc = metadata.loc; const compiler = coerce(options.compiler); if (compiler) { @@ -51,7 +67,10 @@ export class ExponentiationExpression extends SlangNode { // in reality solidity fixed this from 0.8.0. // TODO: remove this once the parser has fixed this. // https://github.com/NomicFoundation/slang/issues/1031 - if (this.rightOperand.variant.kind === 'ExponentiationExpression') { + if ( + typeof this.rightOperand.variant !== 'string' && + this.rightOperand.variant.kind === 'ExponentiationExpression' + ) { const leftLoc = { leadingOffset: this.leftOperand.loc.leadingOffset, start: this.leftOperand.loc.start, @@ -60,26 +79,41 @@ export class ExponentiationExpression extends SlangNode { end: this.rightOperand.variant.leftOperand.loc.end }; this.leftOperand = Object.create(Expression.prototype, { + kind: { value: NonterminalKind.Expression }, loc: { value: { ...leftLoc } }, + comments: { value: [] }, variant: { value: Object.create(TupleExpression.prototype, { + kind: { value: NonterminalKind.TupleExpression }, loc: { value: { ...leftLoc } }, + comments: { value: [] }, openParen: { value: '(' }, items: { value: Object.create(TupleValues.prototype, { + kind: { value: NonterminalKind.TupleValues }, loc: { value: { ...leftLoc } }, + comments: { value: [] }, items: { value: [ Object.create(TupleValue.prototype, { + kind: { value: NonterminalKind.TupleValue }, loc: { value: { ...leftLoc } }, + comments: { value: [] }, expression: { value: Object.create(Expression.prototype, { + kind: { value: NonterminalKind.Expression }, loc: { value: { ...leftLoc } }, + comments: { value: [] }, variant: { value: Object.create( ExponentiationExpression.prototype, { + kind: { + value: + NonterminalKind.ExponentiationExpression + }, loc: { value: { ...leftLoc } }, + comments: { value: [] }, leftOperand: { value: this.leftOperand }, operator: { value: '**' }, rightOperand: { @@ -108,7 +142,11 @@ export class ExponentiationExpression extends SlangNode { } } - print(path, print, options) { - return printExponentiationExpression({ node: this, path, print, options }); + print( + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc { + return printExponentiationExpression(this, path, print, options); } } diff --git a/src/slang-nodes/Expression.js b/src/slang-nodes/Expression.js deleted file mode 100644 index 4cf69961e..000000000 --- a/src/slang-nodes/Expression.js +++ /dev/null @@ -1,86 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { AssignmentExpression } from './AssignmentExpression.js'; -import { ConditionalExpression } from './ConditionalExpression.js'; -import { OrExpression } from './OrExpression.js'; -import { AndExpression } from './AndExpression.js'; -import { EqualityExpression } from './EqualityExpression.js'; -import { ComparisonExpression } from './ComparisonExpression.js'; -import { BitwiseOrExpression } from './BitwiseOrExpression.js'; -import { BitwiseXorExpression } from './BitwiseXorExpression.js'; -import { BitwiseAndExpression } from './BitwiseAndExpression.js'; -import { ShiftExpression } from './ShiftExpression.js'; -import { AdditiveExpression } from './AdditiveExpression.js'; -import { MultiplicativeExpression } from './MultiplicativeExpression.js'; -import { ExponentiationExpression } from './ExponentiationExpression.js'; -import { PostfixExpression } from './PostfixExpression.js'; -import { PrefixExpression } from './PrefixExpression.js'; -import { FunctionCallExpression } from './FunctionCallExpression.js'; -import { CallOptionsExpression } from './CallOptionsExpression.js'; -import { MemberAccessExpression } from './MemberAccessExpression.js'; -import { IndexAccessExpression } from './IndexAccessExpression.js'; -import { NewExpression } from './NewExpression.js'; -import { TupleExpression } from './TupleExpression.js'; -import { TypeExpression } from './TypeExpression.js'; -import { ArrayExpression } from './ArrayExpression.js'; -import { HexNumberExpression } from './HexNumberExpression.js'; -import { DecimalNumberExpression } from './DecimalNumberExpression.js'; -import { StringExpression } from './StringExpression.js'; -import { ElementaryType } from './ElementaryType.js'; - -const variants = { - AssignmentExpression, - ConditionalExpression, - OrExpression, - AndExpression, - EqualityExpression, - ComparisonExpression, - BitwiseOrExpression, - BitwiseXorExpression, - BitwiseAndExpression, - ShiftExpression, - AdditiveExpression, - MultiplicativeExpression, - ExponentiationExpression, - PostfixExpression, - PrefixExpression, - FunctionCallExpression, - CallOptionsExpression, - MemberAccessExpression, - IndexAccessExpression, - NewExpression, - TupleExpression, - TypeExpression, - ArrayExpression, - HexNumberExpression, - DecimalNumberExpression, - StringExpression, - ElementaryType -}; - -export class Expression extends SlangNode { - get kind() { - return NonterminalKind.Expression; - } - - variant; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - variant: - ast.variant.type === 'Terminal' - ? ast.variant.text - : new variants[ast.variant.cst.kind](ast.variant, offsets[0], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return typeof this.variant === 'string' - ? this.variant - : path.call(print, 'variant'); - } -} diff --git a/src/slang-nodes/Expression.ts b/src/slang-nodes/Expression.ts new file mode 100644 index 000000000..cb403802b --- /dev/null +++ b/src/slang-nodes/Expression.ts @@ -0,0 +1,286 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { AssignmentExpression } from './AssignmentExpression.js'; +import { ConditionalExpression } from './ConditionalExpression.js'; +import { OrExpression } from './OrExpression.js'; +import { AndExpression } from './AndExpression.js'; +import { EqualityExpression } from './EqualityExpression.js'; +import { ComparisonExpression } from './ComparisonExpression.js'; +import { BitwiseOrExpression } from './BitwiseOrExpression.js'; +import { BitwiseXorExpression } from './BitwiseXorExpression.js'; +import { BitwiseAndExpression } from './BitwiseAndExpression.js'; +import { ShiftExpression } from './ShiftExpression.js'; +import { AdditiveExpression } from './AdditiveExpression.js'; +import { MultiplicativeExpression } from './MultiplicativeExpression.js'; +import { ExponentiationExpression } from './ExponentiationExpression.js'; +import { PostfixExpression } from './PostfixExpression.js'; +import { PrefixExpression } from './PrefixExpression.js'; +import { FunctionCallExpression } from './FunctionCallExpression.js'; +import { CallOptionsExpression } from './CallOptionsExpression.js'; +import { MemberAccessExpression } from './MemberAccessExpression.js'; +import { IndexAccessExpression } from './IndexAccessExpression.js'; +import { NewExpression } from './NewExpression.js'; +import { TupleExpression } from './TupleExpression.js'; +import { TypeExpression } from './TypeExpression.js'; +import { ArrayExpression } from './ArrayExpression.js'; +import { HexNumberExpression } from './HexNumberExpression.js'; +import { DecimalNumberExpression } from './DecimalNumberExpression.js'; +import { StringExpression } from './StringExpression.js'; +import { ElementaryType } from './ElementaryType.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class Expression implements SlangNode { + readonly kind = NonterminalKind.Expression; + + comments; + + loc; + + variant: + | AssignmentExpression + | ConditionalExpression + | OrExpression + | AndExpression + | EqualityExpression + | ComparisonExpression + | BitwiseOrExpression + | BitwiseXorExpression + | BitwiseAndExpression + | ShiftExpression + | AdditiveExpression + | MultiplicativeExpression + | ExponentiationExpression + | PostfixExpression + | PrefixExpression + | FunctionCallExpression + | CallOptionsExpression + | MemberAccessExpression + | IndexAccessExpression + | NewExpression + | TupleExpression + | TypeExpression + | ArrayExpression + | HexNumberExpression + | DecimalNumberExpression + | StringExpression + | ElementaryType + | string; + + constructor(ast: ast.Expression, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + if (ast.variant instanceof TerminalNode) { + this.variant = ast.variant.text; + } else { + switch (ast.variant.cst.kind) { + case 'AssignmentExpression': + this.variant = new AssignmentExpression( + ast.variant as ast.AssignmentExpression, + offsets[0], + options + ); + break; + case 'ConditionalExpression': + this.variant = new ConditionalExpression( + ast.variant as ast.ConditionalExpression, + offsets[0], + options + ); + break; + case 'OrExpression': + this.variant = new OrExpression( + ast.variant as ast.OrExpression, + offsets[0], + options + ); + break; + case 'AndExpression': + this.variant = new AndExpression( + ast.variant as ast.AndExpression, + offsets[0], + options + ); + break; + case 'EqualityExpression': + this.variant = new EqualityExpression( + ast.variant as ast.EqualityExpression, + offsets[0], + options + ); + break; + case 'ComparisonExpression': + this.variant = new ComparisonExpression( + ast.variant as ast.ComparisonExpression, + offsets[0], + options + ); + break; + case 'BitwiseOrExpression': + this.variant = new BitwiseOrExpression( + ast.variant as ast.BitwiseOrExpression, + offsets[0], + options + ); + break; + case 'BitwiseXorExpression': + this.variant = new BitwiseXorExpression( + ast.variant as ast.BitwiseXorExpression, + offsets[0], + options + ); + break; + case 'BitwiseAndExpression': + this.variant = new BitwiseAndExpression( + ast.variant as ast.BitwiseAndExpression, + offsets[0], + options + ); + break; + case 'ShiftExpression': + this.variant = new ShiftExpression( + ast.variant as ast.ShiftExpression, + offsets[0], + options + ); + break; + case 'AdditiveExpression': + this.variant = new AdditiveExpression( + ast.variant as ast.AdditiveExpression, + offsets[0], + options + ); + break; + case 'MultiplicativeExpression': + this.variant = new MultiplicativeExpression( + ast.variant as ast.MultiplicativeExpression, + offsets[0], + options + ); + break; + case 'ExponentiationExpression': + this.variant = new ExponentiationExpression( + ast.variant as ast.ExponentiationExpression, + offsets[0], + options + ); + break; + case 'PostfixExpression': + this.variant = new PostfixExpression( + ast.variant as ast.PostfixExpression, + offsets[0], + options + ); + break; + case 'PrefixExpression': + this.variant = new PrefixExpression( + ast.variant as ast.PrefixExpression, + offsets[0], + options + ); + break; + case 'FunctionCallExpression': + this.variant = new FunctionCallExpression( + ast.variant as ast.FunctionCallExpression, + offsets[0], + options + ); + break; + case 'CallOptionsExpression': + this.variant = new CallOptionsExpression( + ast.variant as ast.CallOptionsExpression, + offsets[0], + options + ); + break; + case 'MemberAccessExpression': + this.variant = new MemberAccessExpression( + ast.variant as ast.MemberAccessExpression, + offsets[0], + options + ); + break; + case 'IndexAccessExpression': + this.variant = new IndexAccessExpression( + ast.variant as ast.IndexAccessExpression, + offsets[0], + options + ); + break; + case 'NewExpression': + this.variant = new NewExpression( + ast.variant as ast.NewExpression, + offsets[0], + options + ); + break; + case 'TupleExpression': + this.variant = new TupleExpression( + ast.variant as ast.TupleExpression, + offsets[0], + options + ); + break; + case 'TypeExpression': + this.variant = new TypeExpression( + ast.variant as ast.TypeExpression, + offsets[0], + options + ); + break; + case 'ArrayExpression': + this.variant = new ArrayExpression( + ast.variant as ast.ArrayExpression, + offsets[0], + options + ); + break; + case 'HexNumberExpression': + this.variant = new HexNumberExpression( + ast.variant as ast.HexNumberExpression, + offsets[0] + ); + break; + case 'DecimalNumberExpression': + this.variant = new DecimalNumberExpression( + ast.variant as ast.DecimalNumberExpression, + offsets[0] + ); + break; + case 'StringExpression': + this.variant = new StringExpression( + ast.variant as ast.StringExpression, + offsets[0], + options + ); + break; + case 'ElementaryType': + this.variant = new ElementaryType( + ast.variant as ast.ElementaryType, + offsets[0] + ); + break; + default: + throw new Error(`Unexpected variant: ${ast.variant.cst.kind}`); + } + } + + metadata = updateMetadata( + metadata, + typeof this.variant === 'string' ? [] : [this.variant] + ); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/ExpressionStatement.js b/src/slang-nodes/ExpressionStatement.js deleted file mode 100644 index b50e3eeb3..000000000 --- a/src/slang-nodes/ExpressionStatement.js +++ /dev/null @@ -1,28 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { Expression } from './Expression.js'; - -export class ExpressionStatement extends SlangNode { - get kind() { - return NonterminalKind.ExpressionStatement; - } - - expression; - - semicolon; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - expression: new Expression(ast.expression, offsets[0], options), - semicolon: ast.semicolon.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [path.call(print, 'expression'), this.semicolon]; - } -} diff --git a/src/slang-nodes/ExpressionStatement.ts b/src/slang-nodes/ExpressionStatement.ts new file mode 100644 index 000000000..4cc452810 --- /dev/null +++ b/src/slang-nodes/ExpressionStatement.ts @@ -0,0 +1,40 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Expression } from './Expression.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class ExpressionStatement implements SlangNode { + readonly kind = NonterminalKind.ExpressionStatement; + + comments; + + loc; + + expression: Expression; + + semicolon: string; + + constructor( + ast: ast.ExpressionStatement, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.expression = new Expression(ast.expression, offsets[0], options); + this.semicolon = ast.semicolon.text; + + metadata = updateMetadata(metadata, [this.expression]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [path.call(print, 'expression'), this.semicolon]; + } +} diff --git a/src/slang-nodes/FallbackFunctionAttribute.js b/src/slang-nodes/FallbackFunctionAttribute.js deleted file mode 100644 index fd4cdd72c..000000000 --- a/src/slang-nodes/FallbackFunctionAttribute.js +++ /dev/null @@ -1,33 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { ModifierInvocation } from './ModifierInvocation.js'; -import { OverrideSpecifier } from './OverrideSpecifier.js'; - -const variants = { ModifierInvocation, OverrideSpecifier }; - -export class FallbackFunctionAttribute extends SlangNode { - get kind() { - return NonterminalKind.FallbackFunctionAttribute; - } - - variant; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - variant: - ast.variant.type === 'Terminal' - ? ast.variant.text - : new variants[ast.variant.cst.kind](ast.variant, offsets[0], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return typeof this.variant === 'string' - ? this.variant - : path.call(print, 'variant'); - } -} diff --git a/src/slang-nodes/FallbackFunctionAttribute.ts b/src/slang-nodes/FallbackFunctionAttribute.ts new file mode 100644 index 000000000..a28fb6ded --- /dev/null +++ b/src/slang-nodes/FallbackFunctionAttribute.ts @@ -0,0 +1,64 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ModifierInvocation } from './ModifierInvocation.js'; +import { OverrideSpecifier } from './OverrideSpecifier.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class FallbackFunctionAttribute implements SlangNode { + readonly kind = NonterminalKind.FallbackFunctionAttribute; + + comments; + + loc; + + variant: ModifierInvocation | OverrideSpecifier | string; + + constructor( + ast: ast.FallbackFunctionAttribute, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + if (ast.variant instanceof TerminalNode) { + this.variant = ast.variant.text; + } else { + switch (ast.variant.cst.kind) { + case 'ModifierInvocation': + this.variant = new ModifierInvocation( + ast.variant as ast.ModifierInvocation, + offsets[0], + options + ); + break; + case 'OverrideSpecifier': + this.variant = new OverrideSpecifier( + ast.variant as ast.OverrideSpecifier, + offsets[0] + ); + break; + default: + throw new Error(`Unexpected variant: ${ast.variant.cst.kind}`); + } + } + + metadata = updateMetadata( + metadata, + typeof this.variant === 'string' ? [] : [this.variant] + ); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/FallbackFunctionAttributes.js b/src/slang-nodes/FallbackFunctionAttributes.js deleted file mode 100644 index d28f4505a..000000000 --- a/src/slang-nodes/FallbackFunctionAttributes.js +++ /dev/null @@ -1,32 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { postProcessFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; -import { SlangNode } from './SlangNode.js'; -import { FallbackFunctionAttribute } from './FallbackFunctionAttribute.js'; - -const { line } = doc.builders; - -export class FallbackFunctionAttributes extends SlangNode { - get kind() { - return NonterminalKind.FallbackFunctionAttributes; - } - - items; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => - new FallbackFunctionAttribute(item, offsets[index], options) - ) - }); - - this.initialize(ast, offset, fetch, postProcessFunctionAttributes); - } - - print(path, print) { - return path.map(print, 'items').map((item) => [line, item]); - } -} diff --git a/src/slang-nodes/FallbackFunctionAttributes.ts b/src/slang-nodes/FallbackFunctionAttributes.ts new file mode 100644 index 000000000..76c9f4268 --- /dev/null +++ b/src/slang-nodes/FallbackFunctionAttributes.ts @@ -0,0 +1,46 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { FallbackFunctionAttribute } from './FallbackFunctionAttribute.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { line } = doc.builders; + +export class FallbackFunctionAttributes implements SlangNode { + readonly kind = NonterminalKind.FallbackFunctionAttributes; + + comments; + + loc; + + items: FallbackFunctionAttribute[]; + + constructor( + ast: ast.FallbackFunctionAttributes, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => + new FallbackFunctionAttribute(item, offsets[index], options) + ); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + + this.items = this.items.sort(sortFunctionAttributes); + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return path.map(print, 'items').map((item) => [line, item]); + } +} diff --git a/src/slang-nodes/FallbackFunctionDefinition.js b/src/slang-nodes/FallbackFunctionDefinition.js deleted file mode 100644 index 873af970d..000000000 --- a/src/slang-nodes/FallbackFunctionDefinition.js +++ /dev/null @@ -1,65 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printFunction } from '../slang-printers/print-function.js'; -import { SlangNode } from './SlangNode.js'; -import { ParametersDeclaration } from './ParametersDeclaration.js'; -import { FallbackFunctionAttributes } from './FallbackFunctionAttributes.js'; -import { ReturnsDeclaration } from './ReturnsDeclaration.js'; -import { FunctionBody } from './FunctionBody.js'; - -export class FallbackFunctionDefinition extends SlangNode { - get kind() { - return NonterminalKind.FallbackFunctionDefinition; - } - - fallbackKeyword; - - parameters; - - attributes; - - returns; - - body; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => { - let i = 1; - const children = { - fallbackKeyword: ast.fallbackKeyword.text, - parameters: new ParametersDeclaration( - ast.parameters, - offsets[0], - options - ), - attributes: new FallbackFunctionAttributes( - ast.attributes, - offsets[1], - options - ), - returns: ast.returns - ? new ReturnsDeclaration(ast.returns, offsets[(i += 1)], options) - : undefined, - body: new FunctionBody(ast.body, offsets[(i += 1)], options) - }; - return children; - }; - - this.initialize(ast, offset, fetch); - - this.cleanModifierInvocationArguments(); - } - - cleanModifierInvocationArguments() { - this.attributes.items.forEach((attribute) => { - if (attribute.variant.kind === 'ModifierInvocation') { - attribute.variant.cleanModifierInvocationArguments(); - } - }); - } - - print(path, print) { - return printFunction(this.fallbackKeyword, this, path, print); - } -} diff --git a/src/slang-nodes/FallbackFunctionDefinition.ts b/src/slang-nodes/FallbackFunctionDefinition.ts new file mode 100644 index 000000000..2a365df52 --- /dev/null +++ b/src/slang-nodes/FallbackFunctionDefinition.ts @@ -0,0 +1,83 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printFunction } from '../slang-printers/print-function.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ParametersDeclaration } from './ParametersDeclaration.js'; +import { FallbackFunctionAttributes } from './FallbackFunctionAttributes.js'; +import { ReturnsDeclaration } from './ReturnsDeclaration.js'; +import { FunctionBody } from './FunctionBody.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class FallbackFunctionDefinition implements SlangNode { + readonly kind = NonterminalKind.FallbackFunctionDefinition; + + comments; + + loc; + + fallbackKeyword: string; + + parameters: ParametersDeclaration; + + attributes: FallbackFunctionAttributes; + + returns?: ReturnsDeclaration; + + body: FunctionBody; + + constructor( + ast: ast.FallbackFunctionDefinition, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.fallbackKeyword = ast.fallbackKeyword.text; + this.parameters = new ParametersDeclaration( + ast.parameters, + offsets[0], + options + ); + this.attributes = new FallbackFunctionAttributes( + ast.attributes, + offsets[1], + options + ); + let i = 2; + if (ast.returns) { + this.returns = new ReturnsDeclaration(ast.returns, offsets[i], options); + i += 1; + } + this.body = new FunctionBody(ast.body, offsets[i], options); + + metadata = updateMetadata(metadata, [ + this.parameters, + this.attributes, + this.returns, + this.body + ]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + + this.cleanModifierInvocationArguments(); + } + + cleanModifierInvocationArguments(): void { + this.attributes.items.forEach((attribute) => { + if ( + typeof attribute.variant !== 'string' && + attribute.variant.kind === 'ModifierInvocation' + ) { + attribute.variant.cleanModifierInvocationArguments(); + } + }); + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return printFunction(this.fallbackKeyword, this, path, print); + } +} diff --git a/src/slang-nodes/ForStatement.js b/src/slang-nodes/ForStatement.js deleted file mode 100644 index 67199451b..000000000 --- a/src/slang-nodes/ForStatement.js +++ /dev/null @@ -1,80 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printSeparatedList } from '../common/printer-helpers.js'; -import { SlangNode } from './SlangNode.js'; -import { ForStatementInitialization } from './ForStatementInitialization.js'; -import { ForStatementCondition } from './ForStatementCondition.js'; -import { Expression } from './Expression.js'; -import { Statement } from './Statement.js'; - -const { group, indent, line } = doc.builders; - -export class ForStatement extends SlangNode { - get kind() { - return NonterminalKind.ForStatement; - } - - forKeyword; - - openParen; - - initialization; - - condition; - - iterator; - - closeParen; - - body; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => { - let i = 1; - const children = { - forKeyword: ast.forKeyword.text, - openParen: ast.openParen.text, - initialization: new ForStatementInitialization( - ast.initialization, - offsets[0], - options - ), - condition: new ForStatementCondition( - ast.condition, - offsets[1], - options - ), - iterator: ast.iterator - ? new Expression(ast.iterator, offsets[(i += 1)], options) - : undefined, - closeParen: ast.closeParen.text, - body: new Statement(ast.body, offsets[(i += 1)], options) - }; - return children; - }; - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - const initialization = path.call(print, 'initialization'); - const condition = path.call(print, 'condition'); - const iterator = this.iterator ? path.call(print, 'iterator') : ''; - - return [ - `${this.forKeyword} ${this.openParen}`, - printSeparatedList([initialization, condition, iterator], { - separator: - initialization !== ';' || condition !== ';' || iterator !== '' - ? line - : '' - }), - this.closeParen, - this.body.variant.kind === 'Block' - ? [' ', path.call(print, 'body')] - : group(indent([line, path.call(print, 'body')])) - ]; - } -} diff --git a/src/slang-nodes/ForStatement.ts b/src/slang-nodes/ForStatement.ts new file mode 100644 index 000000000..c62905566 --- /dev/null +++ b/src/slang-nodes/ForStatement.ts @@ -0,0 +1,91 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printSeparatedList } from '../slang-printers/print-separated-list.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ForStatementInitialization } from './ForStatementInitialization.js'; +import { ForStatementCondition } from './ForStatementCondition.js'; +import { Expression } from './Expression.js'; +import { Statement } from './Statement.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { group, indent, line } = doc.builders; + +export class ForStatement implements SlangNode { + readonly kind = NonterminalKind.ForStatement; + + comments; + + loc; + + forKeyword: string; + + openParen: string; + + initialization: ForStatementInitialization; + + condition: ForStatementCondition; + + iterator?: Expression; + + closeParen: string; + + body: Statement; + + constructor(ast: ast.ForStatement, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.forKeyword = ast.forKeyword.text; + this.openParen = ast.openParen.text; + this.initialization = new ForStatementInitialization( + ast.initialization, + offsets[0], + options + ); + this.condition = new ForStatementCondition( + ast.condition, + offsets[1], + options + ); + let i = 2; + if (ast.iterator) { + this.iterator = new Expression(ast.iterator, offsets[i], options); + i += 1; + } + this.closeParen = ast.closeParen.text; + this.body = new Statement(ast.body, offsets[i], options); + + metadata = updateMetadata(metadata, [ + this.initialization, + this.condition, + this.iterator, + this.body + ]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + const initialization = path.call(print, 'initialization'); + const condition = path.call(print, 'condition'); + const iterator = this.iterator ? path.call(print, 'iterator') : ''; + + return [ + `${this.forKeyword} ${this.openParen}`, + printSeparatedList([initialization, condition, iterator], { + separator: + initialization !== ';' || condition !== ';' || iterator !== '' + ? line + : '' + }), + this.closeParen, + this.body.variant.kind === 'Block' + ? [' ', path.call(print, 'body')] + : group(indent([line, path.call(print, 'body')])) + ]; + } +} diff --git a/src/slang-nodes/ForStatementCondition.js b/src/slang-nodes/ForStatementCondition.js deleted file mode 100644 index 1cd779b58..000000000 --- a/src/slang-nodes/ForStatementCondition.js +++ /dev/null @@ -1,30 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { ExpressionStatement } from './ExpressionStatement.js'; - -export class ForStatementCondition extends SlangNode { - get kind() { - return NonterminalKind.ForStatementCondition; - } - - variant; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - variant: - ast.variant.type === 'Terminal' - ? ast.variant.text - : new ExpressionStatement(ast.variant, offsets[0], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return typeof this.variant === 'string' - ? this.variant - : path.call(print, 'variant'); - } -} diff --git a/src/slang-nodes/ForStatementCondition.ts b/src/slang-nodes/ForStatementCondition.ts new file mode 100644 index 000000000..8e35c6710 --- /dev/null +++ b/src/slang-nodes/ForStatementCondition.ts @@ -0,0 +1,46 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ExpressionStatement } from './ExpressionStatement.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class ForStatementCondition implements SlangNode { + readonly kind = NonterminalKind.ForStatementCondition; + + comments; + + loc; + + variant: ExpressionStatement | string; + + constructor( + ast: ast.ForStatementCondition, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.variant = + ast.variant instanceof TerminalNode + ? ast.variant.text + : new ExpressionStatement(ast.variant, offsets[0], options); + + metadata = updateMetadata( + metadata, + typeof this.variant === 'string' ? [] : [this.variant] + ); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/ForStatementInitialization.js b/src/slang-nodes/ForStatementInitialization.js deleted file mode 100644 index fe1749a07..000000000 --- a/src/slang-nodes/ForStatementInitialization.js +++ /dev/null @@ -1,38 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { ExpressionStatement } from './ExpressionStatement.js'; -import { VariableDeclarationStatement } from './VariableDeclarationStatement.js'; -import { TupleDeconstructionStatement } from './TupleDeconstructionStatement.js'; - -const variants = { - ExpressionStatement, - VariableDeclarationStatement, - TupleDeconstructionStatement -}; - -export class ForStatementInitialization extends SlangNode { - get kind() { - return NonterminalKind.ForStatementInitialization; - } - - variant; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - variant: - ast.variant.type === 'Terminal' - ? ast.variant.text - : new variants[ast.variant.cst.kind](ast.variant, offsets[0], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return typeof this.variant === 'string' - ? this.variant - : path.call(print, 'variant'); - } -} diff --git a/src/slang-nodes/ForStatementInitialization.ts b/src/slang-nodes/ForStatementInitialization.ts new file mode 100644 index 000000000..689b97076 --- /dev/null +++ b/src/slang-nodes/ForStatementInitialization.ts @@ -0,0 +1,77 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ExpressionStatement } from './ExpressionStatement.js'; +import { VariableDeclarationStatement } from './VariableDeclarationStatement.js'; +import { TupleDeconstructionStatement } from './TupleDeconstructionStatement.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class ForStatementInitialization implements SlangNode { + readonly kind = NonterminalKind.ForStatementInitialization; + + comments; + + loc; + + variant: + | ExpressionStatement + | VariableDeclarationStatement + | TupleDeconstructionStatement + | string; + + constructor( + ast: ast.ForStatementInitialization, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + if (ast.variant instanceof TerminalNode) { + this.variant = ast.variant.text; + } else { + switch (ast.variant.cst.kind) { + case 'ExpressionStatement': + this.variant = new ExpressionStatement( + ast.variant as ast.ExpressionStatement, + offsets[0], + options + ); + break; + case 'VariableDeclarationStatement': + this.variant = new VariableDeclarationStatement( + ast.variant as ast.VariableDeclarationStatement, + offsets[0], + options + ); + break; + case 'TupleDeconstructionStatement': + this.variant = new TupleDeconstructionStatement( + ast.variant as ast.TupleDeconstructionStatement, + offsets[0], + options + ); + break; + default: + throw new Error(`Unexpected variant: ${ast.variant.cst.kind}`); + } + } + + metadata = updateMetadata( + metadata, + typeof this.variant === 'string' ? [] : [this.variant] + ); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/FunctionAttribute.js b/src/slang-nodes/FunctionAttribute.js deleted file mode 100644 index b84703086..000000000 --- a/src/slang-nodes/FunctionAttribute.js +++ /dev/null @@ -1,33 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { ModifierInvocation } from './ModifierInvocation.js'; -import { OverrideSpecifier } from './OverrideSpecifier.js'; - -const variants = { ModifierInvocation, OverrideSpecifier }; - -export class FunctionAttribute extends SlangNode { - get kind() { - return NonterminalKind.FunctionAttribute; - } - - variant; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - variant: - ast.variant.type === 'Terminal' - ? ast.variant.text - : new variants[ast.variant.cst.kind](ast.variant, offsets[0], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return typeof this.variant === 'string' - ? this.variant - : path.call(print, 'variant'); - } -} diff --git a/src/slang-nodes/FunctionAttribute.ts b/src/slang-nodes/FunctionAttribute.ts new file mode 100644 index 000000000..a3c056f59 --- /dev/null +++ b/src/slang-nodes/FunctionAttribute.ts @@ -0,0 +1,64 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ModifierInvocation } from './ModifierInvocation.js'; +import { OverrideSpecifier } from './OverrideSpecifier.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class FunctionAttribute implements SlangNode { + readonly kind = NonterminalKind.FunctionAttribute; + + comments; + + loc; + + variant: ModifierInvocation | OverrideSpecifier | string; + + constructor( + ast: ast.FunctionAttribute, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + if (ast.variant instanceof TerminalNode) { + this.variant = ast.variant.text; + } else { + switch (ast.variant.cst.kind) { + case 'ModifierInvocation': + this.variant = new ModifierInvocation( + ast.variant as ast.ModifierInvocation, + offsets[0], + options + ); + break; + case 'OverrideSpecifier': + this.variant = new OverrideSpecifier( + ast.variant as ast.OverrideSpecifier, + offsets[0] + ); + break; + default: + throw new Error(`Unexpected variant: ${ast.variant.cst.kind}`); + } + } + + metadata = updateMetadata( + metadata, + typeof this.variant === 'string' ? [] : [this.variant] + ); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/FunctionAttributes.js b/src/slang-nodes/FunctionAttributes.js deleted file mode 100644 index 891e1d212..000000000 --- a/src/slang-nodes/FunctionAttributes.js +++ /dev/null @@ -1,31 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { postProcessFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; -import { SlangNode } from './SlangNode.js'; -import { FunctionAttribute } from './FunctionAttribute.js'; - -const { line } = doc.builders; - -export class FunctionAttributes extends SlangNode { - get kind() { - return NonterminalKind.FunctionAttributes; - } - - items; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => new FunctionAttribute(item, offsets[index], options) - ) - }); - - this.initialize(ast, offset, fetch, postProcessFunctionAttributes); - } - - print(path, print) { - return path.map(print, 'items').map((item) => [line, item]); - } -} diff --git a/src/slang-nodes/FunctionAttributes.ts b/src/slang-nodes/FunctionAttributes.ts new file mode 100644 index 000000000..3dc786602 --- /dev/null +++ b/src/slang-nodes/FunctionAttributes.ts @@ -0,0 +1,45 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { FunctionAttribute } from './FunctionAttribute.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { line } = doc.builders; + +export class FunctionAttributes implements SlangNode { + readonly kind = NonterminalKind.FunctionAttributes; + + comments; + + loc; + + items: FunctionAttribute[]; + + constructor( + ast: ast.FunctionAttributes, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => new FunctionAttribute(item, offsets[index], options) + ); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + + this.items = this.items.sort(sortFunctionAttributes); + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return path.map(print, 'items').map((item) => [line, item]); + } +} diff --git a/src/slang-nodes/FunctionBody.js b/src/slang-nodes/FunctionBody.js deleted file mode 100644 index 84c6b7138..000000000 --- a/src/slang-nodes/FunctionBody.js +++ /dev/null @@ -1,30 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { Block } from './Block.js'; - -export class FunctionBody extends SlangNode { - get kind() { - return NonterminalKind.FunctionBody; - } - - variant; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - variant: - ast.variant.type === 'Terminal' - ? ast.variant.text - : new Block(ast.variant, offsets[0], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return typeof this.variant === 'string' - ? this.variant - : path.call(print, 'variant'); - } -} diff --git a/src/slang-nodes/FunctionBody.ts b/src/slang-nodes/FunctionBody.ts new file mode 100644 index 000000000..a678bf15e --- /dev/null +++ b/src/slang-nodes/FunctionBody.ts @@ -0,0 +1,42 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Block } from './Block.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class FunctionBody implements SlangNode { + readonly kind = NonterminalKind.FunctionBody; + + comments; + + loc; + + variant: Block | string; + + constructor(ast: ast.FunctionBody, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.variant = + ast.variant instanceof TerminalNode + ? ast.variant.text + : new Block(ast.variant, offsets[0], options); + + metadata = updateMetadata( + metadata, + typeof this.variant === 'string' ? [] : [this.variant] + ); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/FunctionCallExpression.js b/src/slang-nodes/FunctionCallExpression.js deleted file mode 100644 index c8170194d..000000000 --- a/src/slang-nodes/FunctionCallExpression.js +++ /dev/null @@ -1,51 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { isLabel } from '../common/util.js'; -import { SlangNode } from './SlangNode.js'; -import { Expression } from './Expression.js'; -import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; - -const { group, indentIfBreak, label } = doc.builders; - -export class FunctionCallExpression extends SlangNode { - get kind() { - return NonterminalKind.FunctionCallExpression; - } - - operand; - - arguments; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - operand: new Expression(ast.operand, offsets[0], options), - arguments: new ArgumentsDeclaration(ast.arguments, offsets[1], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - let operandDoc = path.call(print, 'operand'); - let argumentsDoc = path.call(print, 'arguments'); - - // If we are at the end of a MemberAccessChain we should indent the - // arguments accordingly. - if (isLabel(operandDoc) && operandDoc.label === 'MemberAccessChain') { - operandDoc = group(operandDoc.contents, { - id: Symbol('FunctionCallExpression.operand') - }); - - argumentsDoc = indentIfBreak(argumentsDoc, { - groupId: operandDoc.id - }); - // We wrap the expression in a label in case there is an IndexAccess or - // a FunctionCall following this IndexAccess. - return label('MemberAccessChain', [operandDoc, argumentsDoc]); - } - - return [operandDoc, argumentsDoc].flat(); - } -} diff --git a/src/slang-nodes/FunctionCallExpression.ts b/src/slang-nodes/FunctionCallExpression.ts new file mode 100644 index 000000000..f2698a2d7 --- /dev/null +++ b/src/slang-nodes/FunctionCallExpression.ts @@ -0,0 +1,67 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { isLabel } from '../slang-utils/is-label.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Expression } from './Expression.js'; +import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { group, indentIfBreak, label } = doc.builders; + +export class FunctionCallExpression implements SlangNode { + readonly kind = NonterminalKind.FunctionCallExpression; + + comments; + + loc; + + operand: Expression; + + arguments: ArgumentsDeclaration; + + constructor( + ast: ast.FunctionCallExpression, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.operand = new Expression(ast.operand, offsets[0], options); + this.arguments = new ArgumentsDeclaration( + ast.arguments, + offsets[1], + options + ); + + metadata = updateMetadata(metadata, [this.operand, this.arguments]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + let operandDoc = path.call(print, 'operand'); + let argumentsDoc = path.call(print, 'arguments'); + + // If we are at the end of a MemberAccessChain we should indent the + // arguments accordingly. + if (isLabel(operandDoc) && operandDoc.label === 'MemberAccessChain') { + operandDoc = group(operandDoc.contents, { + id: Symbol('FunctionCallExpression.operand') + }); + + argumentsDoc = indentIfBreak(argumentsDoc, { + groupId: operandDoc.id! + }); + // We wrap the expression in a label in case there is an IndexAccess or + // a FunctionCall following this IndexAccess. + return label('MemberAccessChain', [operandDoc, argumentsDoc]); + } + + return [operandDoc, argumentsDoc].flat(); + } +} diff --git a/src/slang-nodes/FunctionDefinition.js b/src/slang-nodes/FunctionDefinition.js deleted file mode 100644 index e79a8e408..000000000 --- a/src/slang-nodes/FunctionDefinition.js +++ /dev/null @@ -1,77 +0,0 @@ -import coerce from 'semver/functions/coerce.js'; -import satisfies from 'semver/functions/satisfies.js'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printFunction } from '../slang-printers/print-function.js'; -import { SlangNode } from './SlangNode.js'; -import { FunctionName } from './FunctionName.js'; -import { ParametersDeclaration } from './ParametersDeclaration.js'; -import { FunctionAttributes } from './FunctionAttributes.js'; -import { ReturnsDeclaration } from './ReturnsDeclaration.js'; -import { FunctionBody } from './FunctionBody.js'; - -export class FunctionDefinition extends SlangNode { - get kind() { - return NonterminalKind.FunctionDefinition; - } - - functionKeyword; - - name; - - parameters; - - attributes; - - returns; - - body; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => { - let i = 2; - const children = { - functionKeyword: ast.functionKeyword.text, - name: new FunctionName(ast.name, offsets[0], options), - parameters: new ParametersDeclaration( - ast.parameters, - offsets[1], - options - ), - attributes: new FunctionAttributes(ast.attributes, offsets[2], options), - returns: ast.returns - ? new ReturnsDeclaration(ast.returns, offsets[(i += 1)], options) - : undefined, - body: new FunctionBody(ast.body, offsets[(i += 1)], options) - }; - return children; - }; - - this.initialize(ast, offset, fetch); - - // Older versions of Solidity defined a constructor as a function having - // the same name as the contract. - const compiler = coerce(options.compiler); - if (compiler && satisfies(compiler, '>=0.5.0')) { - this.cleanModifierInvocationArguments(); - } - } - - cleanModifierInvocationArguments() { - this.attributes.items.forEach((attribute) => { - if (attribute.variant.kind === 'ModifierInvocation') { - attribute.variant.cleanModifierInvocationArguments(); - } - }); - } - - print(path, print) { - return printFunction( - [`${this.functionKeyword} `, path.call(print, 'name')], - this, - path, - print - ); - } -} diff --git a/src/slang-nodes/FunctionDefinition.ts b/src/slang-nodes/FunctionDefinition.ts new file mode 100644 index 000000000..73ddba8e9 --- /dev/null +++ b/src/slang-nodes/FunctionDefinition.ts @@ -0,0 +1,100 @@ +import coerce from 'semver/functions/coerce.js'; +import satisfies from 'semver/functions/satisfies.js'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printFunction } from '../slang-printers/print-function.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { FunctionName } from './FunctionName.js'; +import { ParametersDeclaration } from './ParametersDeclaration.js'; +import { FunctionAttributes } from './FunctionAttributes.js'; +import { ReturnsDeclaration } from './ReturnsDeclaration.js'; +import { FunctionBody } from './FunctionBody.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class FunctionDefinition implements SlangNode { + readonly kind = NonterminalKind.FunctionDefinition; + + comments; + + loc; + + functionKeyword: string; + + name: FunctionName; + + parameters: ParametersDeclaration; + + attributes: FunctionAttributes; + + returns?: ReturnsDeclaration; + + body: FunctionBody; + + constructor( + ast: ast.FunctionDefinition, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.functionKeyword = ast.functionKeyword.text; + this.name = new FunctionName(ast.name, offsets[0]); + this.parameters = new ParametersDeclaration( + ast.parameters, + offsets[1], + options + ); + this.attributes = new FunctionAttributes( + ast.attributes, + offsets[2], + options + ); + let i = 3; + if (ast.returns) { + this.returns = new ReturnsDeclaration(ast.returns, offsets[i], options); + i += 1; + } + this.body = new FunctionBody(ast.body, offsets[i], options); + + metadata = updateMetadata(metadata, [ + this.name, + this.parameters, + this.attributes, + this.returns, + this.body + ]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + + // Older versions of Solidity defined a constructor as a function having + // the same name as the contract. + const compiler = coerce(options.compiler); + if (compiler && satisfies(compiler, '>=0.5.0')) { + this.cleanModifierInvocationArguments(); + } + } + + cleanModifierInvocationArguments(): void { + this.attributes.items.forEach((attribute) => { + if ( + typeof attribute.variant !== 'string' && + attribute.variant.kind === 'ModifierInvocation' + ) { + attribute.variant.cleanModifierInvocationArguments(); + } + }); + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return printFunction( + [`${this.functionKeyword} `, path.call(print, 'name')], + this, + path, + print + ); + } +} diff --git a/src/slang-nodes/FunctionName.js b/src/slang-nodes/FunctionName.js deleted file mode 100644 index 18efe98dc..000000000 --- a/src/slang-nodes/FunctionName.js +++ /dev/null @@ -1,24 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; - -export class FunctionName extends SlangNode { - get kind() { - return NonterminalKind.FunctionName; - } - - variant; - - constructor(ast, offset) { - super(); - - const fetch = () => ({ - variant: ast.variant.text - }); - - this.initialize(ast, offset, fetch); - } - - print() { - return this.variant; - } -} diff --git a/src/slang-nodes/FunctionName.ts b/src/slang-nodes/FunctionName.ts new file mode 100644 index 000000000..4f2712287 --- /dev/null +++ b/src/slang-nodes/FunctionName.ts @@ -0,0 +1,29 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata } from '../slang-utils/get-offsets.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class FunctionName implements SlangNode { + readonly kind = NonterminalKind.FunctionName; + + comments; + + loc; + + variant: string; + + constructor(ast: ast.FunctionName, offset: number) { + const metadata = getNodeMetadata(ast, offset); + + this.variant = ast.variant.text; + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(): Doc { + return this.variant; + } +} diff --git a/src/slang-nodes/FunctionType.js b/src/slang-nodes/FunctionType.js deleted file mode 100644 index f6e2841d8..000000000 --- a/src/slang-nodes/FunctionType.js +++ /dev/null @@ -1,47 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printFunction } from '../slang-printers/print-function.js'; -import { SlangNode } from './SlangNode.js'; -import { ParametersDeclaration } from './ParametersDeclaration.js'; -import { FunctionTypeAttributes } from './FunctionTypeAttributes.js'; -import { ReturnsDeclaration } from './ReturnsDeclaration.js'; - -export class FunctionType extends SlangNode { - get kind() { - return NonterminalKind.FunctionType; - } - - functionKeyword; - - parameters; - - attributes; - - returns; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - functionKeyword: ast.functionKeyword.text, - parameters: new ParametersDeclaration( - ast.parameters, - offsets[0], - options - ), - attributes: new FunctionTypeAttributes( - ast.attributes, - offsets[1], - options - ), - returns: ast.returns - ? new ReturnsDeclaration(ast.returns, offsets[2], options) - : undefined - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return printFunction(this.functionKeyword, this, path, print); - } -} diff --git a/src/slang-nodes/FunctionType.ts b/src/slang-nodes/FunctionType.ts new file mode 100644 index 000000000..18caeeab3 --- /dev/null +++ b/src/slang-nodes/FunctionType.ts @@ -0,0 +1,55 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printFunction } from '../slang-printers/print-function.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ParametersDeclaration } from './ParametersDeclaration.js'; +import { FunctionTypeAttributes } from './FunctionTypeAttributes.js'; +import { ReturnsDeclaration } from './ReturnsDeclaration.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class FunctionType implements SlangNode { + readonly kind = NonterminalKind.FunctionType; + + comments; + + loc; + + functionKeyword: string; + + parameters: ParametersDeclaration; + + attributes: FunctionTypeAttributes; + + returns?: ReturnsDeclaration; + + constructor(ast: ast.FunctionType, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.functionKeyword = ast.functionKeyword.text; + this.parameters = new ParametersDeclaration( + ast.parameters, + offsets[0], + options + ); + this.attributes = new FunctionTypeAttributes(ast.attributes, offsets[1]); + if (ast.returns) { + this.returns = new ReturnsDeclaration(ast.returns, offsets[2], options); + } + + metadata = updateMetadata(metadata, [ + this.parameters, + this.attributes, + this.returns + ]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return printFunction(this.functionKeyword, this, path, print); + } +} diff --git a/src/slang-nodes/FunctionTypeAttribute.js b/src/slang-nodes/FunctionTypeAttribute.js deleted file mode 100644 index ee5ae8309..000000000 --- a/src/slang-nodes/FunctionTypeAttribute.js +++ /dev/null @@ -1,24 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; - -export class FunctionTypeAttribute extends SlangNode { - get kind() { - return NonterminalKind.FunctionTypeAttribute; - } - - variant; - - constructor(ast, offset) { - super(); - - const fetch = () => ({ - variant: ast.variant.text - }); - - this.initialize(ast, offset, fetch); - } - - print() { - return this.variant; - } -} diff --git a/src/slang-nodes/FunctionTypeAttribute.ts b/src/slang-nodes/FunctionTypeAttribute.ts new file mode 100644 index 000000000..3daf8190e --- /dev/null +++ b/src/slang-nodes/FunctionTypeAttribute.ts @@ -0,0 +1,29 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata } from '../slang-utils/get-offsets.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class FunctionTypeAttribute implements SlangNode { + readonly kind = NonterminalKind.FunctionTypeAttribute; + + comments; + + loc; + + variant: string; + + constructor(ast: ast.FunctionTypeAttribute, offset: number) { + const metadata = getNodeMetadata(ast, offset); + + this.variant = ast.variant.text; + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(): Doc { + return this.variant; + } +} diff --git a/src/slang-nodes/FunctionTypeAttributes.js b/src/slang-nodes/FunctionTypeAttributes.js deleted file mode 100644 index 970e88bc2..000000000 --- a/src/slang-nodes/FunctionTypeAttributes.js +++ /dev/null @@ -1,32 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { postProcessFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; -import { SlangNode } from './SlangNode.js'; -import { FunctionTypeAttribute } from './FunctionTypeAttribute.js'; - -const { line } = doc.builders; - -export class FunctionTypeAttributes extends SlangNode { - get kind() { - return NonterminalKind.FunctionTypeAttributes; - } - - items; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => - new FunctionTypeAttribute(item, offsets[index], options) - ) - }); - - this.initialize(ast, offset, fetch, postProcessFunctionAttributes); - } - - print(path, print) { - return path.map(print, 'items').map((item) => [line, item]); - } -} diff --git a/src/slang-nodes/FunctionTypeAttributes.ts b/src/slang-nodes/FunctionTypeAttributes.ts new file mode 100644 index 000000000..0148b2c76 --- /dev/null +++ b/src/slang-nodes/FunctionTypeAttributes.ts @@ -0,0 +1,41 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { FunctionTypeAttribute } from './FunctionTypeAttribute.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { line } = doc.builders; + +export class FunctionTypeAttributes implements SlangNode { + readonly kind = NonterminalKind.FunctionTypeAttributes; + + comments; + + loc; + + items: FunctionTypeAttribute[]; + + constructor(ast: ast.FunctionTypeAttributes, offset: number) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => new FunctionTypeAttribute(item, offsets[index]) + ); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + + this.items = this.items.sort(sortFunctionAttributes); + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return path.map(print, 'items').map((item) => [line, item]); + } +} diff --git a/src/slang-nodes/HexNumberExpression.js b/src/slang-nodes/HexNumberExpression.js deleted file mode 100644 index 91a951e3e..000000000 --- a/src/slang-nodes/HexNumberExpression.js +++ /dev/null @@ -1,28 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { NumberUnit } from './NumberUnit.js'; - -export class HexNumberExpression extends SlangNode { - get kind() { - return NonterminalKind.HexNumberExpression; - } - - literal; - - unit; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - literal: ast.literal.text, - unit: ast.unit ? new NumberUnit(ast.unit, offsets[0], options) : undefined - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [this.literal, this.unit ? [' ', path.call(print, 'unit')] : '']; - } -} diff --git a/src/slang-nodes/HexNumberExpression.ts b/src/slang-nodes/HexNumberExpression.ts new file mode 100644 index 000000000..5a2edc8ed --- /dev/null +++ b/src/slang-nodes/HexNumberExpression.ts @@ -0,0 +1,38 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { NumberUnit } from './NumberUnit.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class HexNumberExpression implements SlangNode { + readonly kind = NonterminalKind.HexNumberExpression; + + comments; + + loc; + + literal: string; + + unit?: NumberUnit; + + constructor(ast: ast.HexNumberExpression, offset: number) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.literal = ast.literal.text; + if (ast.unit) { + this.unit = new NumberUnit(ast.unit, offsets[0]); + } + + metadata = updateMetadata(metadata, [this.unit]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [this.literal, this.unit ? [' ', path.call(print, 'unit')] : '']; + } +} diff --git a/src/slang-nodes/HexStringLiteral.js b/src/slang-nodes/HexStringLiteral.js deleted file mode 100644 index 9c15cf596..000000000 --- a/src/slang-nodes/HexStringLiteral.js +++ /dev/null @@ -1,29 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printString } from '../slang-printers/print-string.js'; -import { SlangNode } from './SlangNode.js'; - -const postProcess = (options) => (properties) => ({ - variant: `hex${printString(properties.variant.slice(4, -1), options)}` -}); - -export class HexStringLiteral extends SlangNode { - get kind() { - return NonterminalKind.HexStringLiteral; - } - - variant; - - constructor(ast, offset, options) { - super(); - - const fetch = () => ({ - variant: ast.variant.text - }); - - this.initialize(ast, offset, fetch, postProcess(options)); - } - - print() { - return this.variant; - } -} diff --git a/src/slang-nodes/HexStringLiteral.ts b/src/slang-nodes/HexStringLiteral.ts new file mode 100644 index 000000000..a3baa7a7a --- /dev/null +++ b/src/slang-nodes/HexStringLiteral.ts @@ -0,0 +1,36 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printString } from '../slang-printers/print-string.js'; +import { getNodeMetadata } from '../slang-utils/get-offsets.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class HexStringLiteral implements SlangNode { + readonly kind = NonterminalKind.HexStringLiteral; + + comments; + + loc; + + variant: string; + + constructor( + ast: ast.HexStringLiteral, + offset: number, + options: ParserOptions + ) { + const metadata = getNodeMetadata(ast, offset); + + this.variant = ast.variant.text; + + this.comments = metadata.comments; + this.loc = metadata.loc; + + this.variant = `hex${printString(this.variant.slice(4, -1), options)}`; + } + + print(): Doc { + return this.variant; + } +} diff --git a/src/slang-nodes/HexStringLiterals.js b/src/slang-nodes/HexStringLiterals.js deleted file mode 100644 index 7960b26a7..000000000 --- a/src/slang-nodes/HexStringLiterals.js +++ /dev/null @@ -1,30 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { HexStringLiteral } from './HexStringLiteral.js'; - -const { join, hardline } = doc.builders; - -export class HexStringLiterals extends SlangNode { - get kind() { - return NonterminalKind.HexStringLiterals; - } - - items; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => new HexStringLiteral(item, offsets[index], options) - ) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return join(hardline, path.map(print, 'items')); - } -} diff --git a/src/slang-nodes/HexStringLiterals.ts b/src/slang-nodes/HexStringLiterals.ts new file mode 100644 index 000000000..d908ed385 --- /dev/null +++ b/src/slang-nodes/HexStringLiterals.ts @@ -0,0 +1,42 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { HexStringLiteral } from './HexStringLiteral.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { join, hardline } = doc.builders; + +export class HexStringLiterals implements SlangNode { + readonly kind = NonterminalKind.HexStringLiterals; + + comments; + + loc; + + items: HexStringLiteral[]; + + constructor( + ast: ast.HexStringLiterals, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => new HexStringLiteral(item, offsets[index], options) + ); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return join(hardline, path.map(print, 'items')); + } +} diff --git a/src/slang-nodes/IdentifierPath.js b/src/slang-nodes/IdentifierPath.js deleted file mode 100644 index 684393c7a..000000000 --- a/src/slang-nodes/IdentifierPath.js +++ /dev/null @@ -1,29 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; - -export class IdentifierPath extends SlangNode { - get kind() { - return NonterminalKind.IdentifierPath; - } - - items; - - separators; - - constructor(ast, offset) { - super(); - - const fetch = () => ({ - items: ast.items.map((item) => item.text), - separators: ast.separators.map((separator) => separator.text) - }); - - this.initialize(ast, offset, fetch); - } - - print() { - return this.items.map((item, index) => - index === 0 ? item : [this.separators[index - 1], item] - ); - } -} diff --git a/src/slang-nodes/IdentifierPath.ts b/src/slang-nodes/IdentifierPath.ts new file mode 100644 index 000000000..a971d2565 --- /dev/null +++ b/src/slang-nodes/IdentifierPath.ts @@ -0,0 +1,34 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata } from '../slang-utils/get-offsets.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class IdentifierPath implements SlangNode { + readonly kind = NonterminalKind.IdentifierPath; + + comments; + + loc; + + items: string[]; + + separators: string[]; + + constructor(ast: ast.IdentifierPath, offset: number) { + const metadata = getNodeMetadata(ast, offset); + + this.items = ast.items.map((item) => item.text); + this.separators = ast.separators.map((separator) => separator.text); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(): Doc { + return this.items.map((item, index) => + index === 0 ? item : [this.separators[index - 1], item] + ); + } +} diff --git a/src/slang-nodes/IfStatement.js b/src/slang-nodes/IfStatement.js deleted file mode 100644 index c3936276c..000000000 --- a/src/slang-nodes/IfStatement.js +++ /dev/null @@ -1,65 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printSeparatedItem } from '../common/printer-helpers.js'; -import { SlangNode } from './SlangNode.js'; -import { Expression } from './Expression.js'; -import { Statement } from './Statement.js'; -import { ElseBranch } from './ElseBranch.js'; - -const { group, hardline, indent, line } = doc.builders; - -export class IfStatement extends SlangNode { - get kind() { - return NonterminalKind.IfStatement; - } - - ifKeyword; - - openParen; - - condition; - - closeParen; - - body; - - elseBranch; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - ifKeyword: ast.ifKeyword.text, - openParen: ast.openParen.text, - condition: new Expression(ast.condition, offsets[0], options), - closeParen: ast.closeParen.text, - body: new Statement(ast.body, offsets[1], options), - elseBranch: ast.elseBranch - ? new ElseBranch(ast.elseBranch, offsets[2], options) - : undefined - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - `${this.ifKeyword} ${this.openParen}`, - printSeparatedItem(path.call(print, 'condition')), - this.closeParen, - this.body.variant.kind === 'Block' - ? [' ', path.call(print, 'body')] - : group(indent([line, path.call(print, 'body')]), { - shouldBreak: this.body.variant.kind === 'IfStatement' // `if` within `if` - }), - this.elseBranch - ? [ - this.body.variant.kind !== 'Block' - ? hardline // else on a new line if body is not a block - : ' ', - path.call(print, 'elseBranch') - ] - : '' - ]; - } -} diff --git a/src/slang-nodes/IfStatement.ts b/src/slang-nodes/IfStatement.ts new file mode 100644 index 000000000..7b509ca03 --- /dev/null +++ b/src/slang-nodes/IfStatement.ts @@ -0,0 +1,77 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printSeparatedItem } from '../slang-printers/print-separated-item.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Expression } from './Expression.js'; +import { Statement } from './Statement.js'; +import { ElseBranch } from './ElseBranch.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { group, hardline, indent, line } = doc.builders; + +export class IfStatement implements SlangNode { + readonly kind = NonterminalKind.IfStatement; + + comments; + + loc; + + ifKeyword: string; + + openParen: string; + + condition: Expression; + + closeParen: string; + + body: Statement; + + elseBranch?: ElseBranch; + + constructor(ast: ast.IfStatement, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.ifKeyword = ast.ifKeyword.text; + this.openParen = ast.openParen.text; + this.condition = new Expression(ast.condition, offsets[0], options); + this.closeParen = ast.closeParen.text; + this.body = new Statement(ast.body, offsets[1], options); + if (ast.elseBranch) { + this.elseBranch = new ElseBranch(ast.elseBranch, offsets[2], options); + } + + metadata = updateMetadata(metadata, [ + this.condition, + this.body, + this.elseBranch + ]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + `${this.ifKeyword} ${this.openParen}`, + printSeparatedItem(path.call(print, 'condition')), + this.closeParen, + this.body.variant.kind === 'Block' + ? [' ', path.call(print, 'body')] + : group(indent([line, path.call(print, 'body')]), { + shouldBreak: this.body.variant.kind === 'IfStatement' // `if` within `if` + }), + this.elseBranch + ? [ + this.body.variant.kind !== 'Block' + ? hardline // else on a new line if body is not a block + : ' ', + path.call(print, 'elseBranch') + ] + : '' + ]; + } +} diff --git a/src/slang-nodes/ImportAlias.js b/src/slang-nodes/ImportAlias.js deleted file mode 100644 index cecdfdb6d..000000000 --- a/src/slang-nodes/ImportAlias.js +++ /dev/null @@ -1,27 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; - -export class ImportAlias extends SlangNode { - get kind() { - return NonterminalKind.ImportAlias; - } - - asKeyword; - - identifier; - - constructor(ast, offset) { - super(); - - const fetch = () => ({ - asKeyword: ast.asKeyword.text, - identifier: ast.identifier.text - }); - - this.initialize(ast, offset, fetch); - } - - print() { - return ` ${this.asKeyword} ${this.identifier}`; - } -} diff --git a/src/slang-nodes/ImportAlias.ts b/src/slang-nodes/ImportAlias.ts new file mode 100644 index 000000000..ff74c9b0f --- /dev/null +++ b/src/slang-nodes/ImportAlias.ts @@ -0,0 +1,32 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata } from '../slang-utils/get-offsets.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class ImportAlias implements SlangNode { + readonly kind = NonterminalKind.ImportAlias; + + comments; + + loc; + + asKeyword: string; + + identifier: string; + + constructor(ast: ast.ImportAlias, offset: number) { + const metadata = getNodeMetadata(ast, offset); + + this.asKeyword = ast.asKeyword.text; + this.identifier = ast.identifier.text; + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(): Doc { + return ` ${this.asKeyword} ${this.identifier}`; + } +} diff --git a/src/slang-nodes/ImportClause.js b/src/slang-nodes/ImportClause.js deleted file mode 100644 index 9f7d87b10..000000000 --- a/src/slang-nodes/ImportClause.js +++ /dev/null @@ -1,33 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { PathImport } from './PathImport.js'; -import { NamedImport } from './NamedImport.js'; -import { ImportDeconstruction } from './ImportDeconstruction.js'; - -const variants = { PathImport, NamedImport, ImportDeconstruction }; - -export class ImportClause extends SlangNode { - get kind() { - return NonterminalKind.ImportClause; - } - - variant; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - variant: new variants[ast.variant.cst.kind]( - ast.variant, - offsets[0], - options - ) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return path.call(print, 'variant'); - } -} diff --git a/src/slang-nodes/ImportClause.ts b/src/slang-nodes/ImportClause.ts new file mode 100644 index 000000000..3c789b725 --- /dev/null +++ b/src/slang-nodes/ImportClause.ts @@ -0,0 +1,60 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { PathImport } from './PathImport.js'; +import { NamedImport } from './NamedImport.js'; +import { ImportDeconstruction } from './ImportDeconstruction.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class ImportClause implements SlangNode { + readonly kind = NonterminalKind.ImportClause; + + comments; + + loc; + + variant: PathImport | NamedImport | ImportDeconstruction; + + constructor(ast: ast.ImportClause, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + switch (ast.variant.cst.kind) { + case 'PathImport': + this.variant = new PathImport( + ast.variant as ast.PathImport, + offsets[0], + options + ); + break; + case 'NamedImport': + this.variant = new NamedImport( + ast.variant as ast.NamedImport, + offsets[0], + options + ); + break; + case 'ImportDeconstruction': + this.variant = new ImportDeconstruction( + ast.variant as ast.ImportDeconstruction, + offsets[0], + options + ); + break; + + default: + throw new Error(`Unexpected variant: ${ast.variant.cst.kind}`); + } + + metadata = updateMetadata(metadata, [this.variant]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/ImportDeconstruction.js b/src/slang-nodes/ImportDeconstruction.js deleted file mode 100644 index 0f51a6328..000000000 --- a/src/slang-nodes/ImportDeconstruction.js +++ /dev/null @@ -1,47 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { ImportDeconstructionSymbols } from './ImportDeconstructionSymbols.js'; -import { StringLiteral } from './StringLiteral.js'; - -export class ImportDeconstruction extends SlangNode { - get kind() { - return NonterminalKind.ImportDeconstruction; - } - - openBrace; - - symbols; - - closeBrace; - - fromKeyword; - - path; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - openBrace: ast.openBrace.text, - symbols: new ImportDeconstructionSymbols( - ast.symbols, - offsets[0], - options - ), - closeBrace: ast.closeBrace.text, - fromKeyword: ast.fromKeyword.text, - path: new StringLiteral(ast.path, offsets[1], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - this.openBrace, - path.call(print, 'symbols'), - `${this.closeBrace} ${this.fromKeyword} `, - path.call(print, 'path') - ]; - } -} diff --git a/src/slang-nodes/ImportDeconstruction.ts b/src/slang-nodes/ImportDeconstruction.ts new file mode 100644 index 000000000..5ab9e482f --- /dev/null +++ b/src/slang-nodes/ImportDeconstruction.ts @@ -0,0 +1,55 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ImportDeconstructionSymbols } from './ImportDeconstructionSymbols.js'; +import { StringLiteral } from './StringLiteral.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class ImportDeconstruction implements SlangNode { + readonly kind = NonterminalKind.ImportDeconstruction; + + comments; + + loc; + + openBrace: string; + + symbols: ImportDeconstructionSymbols; + + closeBrace: string; + + fromKeyword: string; + + path: StringLiteral; + + constructor( + ast: ast.ImportDeconstruction, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.openBrace = ast.openBrace.text; + this.symbols = new ImportDeconstructionSymbols(ast.symbols, offsets[0]); + this.closeBrace = ast.closeBrace.text; + this.fromKeyword = ast.fromKeyword.text; + this.path = new StringLiteral(ast.path, offsets[1], options); + + metadata = updateMetadata(metadata, [this.symbols, this.path]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + this.openBrace, + path.call(print, 'symbols'), + `${this.closeBrace} ${this.fromKeyword} `, + path.call(print, 'path') + ]; + } +} diff --git a/src/slang-nodes/ImportDeconstructionSymbol.js b/src/slang-nodes/ImportDeconstructionSymbol.js deleted file mode 100644 index 99ce8eac8..000000000 --- a/src/slang-nodes/ImportDeconstructionSymbol.js +++ /dev/null @@ -1,30 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { ImportAlias } from './ImportAlias.js'; - -export class ImportDeconstructionSymbol extends SlangNode { - get kind() { - return NonterminalKind.ImportDeconstructionSymbol; - } - - name; - - alias; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - name: ast.name.text, - alias: ast.alias - ? new ImportAlias(ast.alias, offsets[0], options) - : undefined - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [this.name, this.alias ? path.call(print, 'alias') : '']; - } -} diff --git a/src/slang-nodes/ImportDeconstructionSymbol.ts b/src/slang-nodes/ImportDeconstructionSymbol.ts new file mode 100644 index 000000000..8ffae8131 --- /dev/null +++ b/src/slang-nodes/ImportDeconstructionSymbol.ts @@ -0,0 +1,38 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ImportAlias } from './ImportAlias.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class ImportDeconstructionSymbol implements SlangNode { + readonly kind = NonterminalKind.ImportDeconstructionSymbol; + + comments; + + loc; + + name: string; + + alias?: ImportAlias; + + constructor(ast: ast.ImportDeconstructionSymbol, offset: number) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.name = ast.name.text; + if (ast.alias) { + this.alias = new ImportAlias(ast.alias, offsets[0]); + } + + metadata = updateMetadata(metadata, [this.alias]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [this.name, this.alias ? path.call(print, 'alias') : '']; + } +} diff --git a/src/slang-nodes/ImportDeconstructionSymbols.js b/src/slang-nodes/ImportDeconstructionSymbols.js deleted file mode 100644 index d3769cf70..000000000 --- a/src/slang-nodes/ImportDeconstructionSymbols.js +++ /dev/null @@ -1,55 +0,0 @@ -import { doc } from 'prettier'; -import coerce from 'semver/functions/coerce.js'; -import satisfies from 'semver/functions/satisfies.js'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printSeparatedList } from '../common/printer-helpers.js'; -import { SlangNode } from './SlangNode.js'; -import { ImportDeconstructionSymbol } from './ImportDeconstructionSymbol.js'; - -const { line, softline } = doc.builders; - -export class ImportDeconstructionSymbols extends SlangNode { - get kind() { - return NonterminalKind.ImportDeconstructionSymbols; - } - - items; - - separators; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => - new ImportDeconstructionSymbol(item, offsets[index], options) - ), - separators: ast.separators.map((separator) => separator.text) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print, options) { - const compiler = coerce(options.compiler); - let firstSeparator; - let separator; - - if (compiler && satisfies(compiler, '>=0.7.4')) { - // if the compiler exists and is greater than or equal to 0.7.4 we will - // split the ImportDirective. - firstSeparator = options.bracketSpacing ? line : softline; - separator = [',', line]; - } else { - // if the compiler is not given or is lower than 0.7.4 we will not - // split the ImportDirective. - firstSeparator = options.bracketSpacing ? ' ' : ''; - separator = ', '; - } - return printSeparatedList(path.map(print, 'items'), { - firstSeparator, - separator - }); - } -} diff --git a/src/slang-nodes/ImportDeconstructionSymbols.ts b/src/slang-nodes/ImportDeconstructionSymbols.ts new file mode 100644 index 000000000..85d12b4cf --- /dev/null +++ b/src/slang-nodes/ImportDeconstructionSymbols.ts @@ -0,0 +1,66 @@ +import { doc } from 'prettier'; +import coerce from 'semver/functions/coerce.js'; +import satisfies from 'semver/functions/satisfies.js'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printSeparatedList } from '../slang-printers/print-separated-list.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ImportDeconstructionSymbol } from './ImportDeconstructionSymbol.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { line, softline } = doc.builders; + +export class ImportDeconstructionSymbols implements SlangNode { + readonly kind = NonterminalKind.ImportDeconstructionSymbols; + + comments; + + loc; + + items: ImportDeconstructionSymbol[]; + + separators: string[]; + + constructor(ast: ast.ImportDeconstructionSymbols, offset: number) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => new ImportDeconstructionSymbol(item, offsets[index]) + ); + this.separators = ast.separators.map((separator) => separator.text); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print( + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc { + const compiler = coerce(options.compiler); + let firstSeparator; + let separator; + + if (compiler && satisfies(compiler, '>=0.7.4')) { + // if the compiler exists and is greater than or equal to 0.7.4 we will + // split the ImportDirective. + firstSeparator = options.bracketSpacing ? line : softline; + separator = [',', line]; + } else { + // if the compiler is not given or is lower than 0.7.4 we will not + // split the ImportDirective. + firstSeparator = options.bracketSpacing ? ' ' : ''; + separator = ', '; + } + return printSeparatedList(path.map(print, 'items'), { + firstSeparator, + separator + }); + } +} diff --git a/src/slang-nodes/ImportDirective.js b/src/slang-nodes/ImportDirective.js deleted file mode 100644 index 6f2dd5f9e..000000000 --- a/src/slang-nodes/ImportDirective.js +++ /dev/null @@ -1,35 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { ImportClause } from './ImportClause.js'; - -export class ImportDirective extends SlangNode { - get kind() { - return NonterminalKind.ImportDirective; - } - - importKeyword; - - clause; - - semicolon; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - importKeyword: ast.importKeyword.text, - clause: new ImportClause(ast.clause, offsets[0], options), - semicolon: ast.semicolon.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - `${this.importKeyword} `, - path.call(print, 'clause'), - this.semicolon - ]; - } -} diff --git a/src/slang-nodes/ImportDirective.ts b/src/slang-nodes/ImportDirective.ts new file mode 100644 index 000000000..d2c7c2538 --- /dev/null +++ b/src/slang-nodes/ImportDirective.ts @@ -0,0 +1,47 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ImportClause } from './ImportClause.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class ImportDirective implements SlangNode { + readonly kind = NonterminalKind.ImportDirective; + + comments; + + loc; + + importKeyword: string; + + clause: ImportClause; + + semicolon: string; + + constructor( + ast: ast.ImportDirective, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.importKeyword = ast.importKeyword.text; + this.clause = new ImportClause(ast.clause, offsets[0], options); + this.semicolon = ast.semicolon.text; + + metadata = updateMetadata(metadata, [this.clause]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + `${this.importKeyword} `, + path.call(print, 'clause'), + this.semicolon + ]; + } +} diff --git a/src/slang-nodes/IndexAccessEnd.js b/src/slang-nodes/IndexAccessEnd.js deleted file mode 100644 index fecebf58e..000000000 --- a/src/slang-nodes/IndexAccessEnd.js +++ /dev/null @@ -1,28 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { Expression } from './Expression.js'; - -export class IndexAccessEnd extends SlangNode { - get kind() { - return NonterminalKind.IndexAccessEnd; - } - - colon; - - end; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - colon: ast.colon.text, - end: ast.end ? new Expression(ast.end, offsets[0], options) : undefined - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [this.colon, this.end ? path.call(print, 'end') : '']; - } -} diff --git a/src/slang-nodes/IndexAccessEnd.ts b/src/slang-nodes/IndexAccessEnd.ts new file mode 100644 index 000000000..9ac9bcea0 --- /dev/null +++ b/src/slang-nodes/IndexAccessEnd.ts @@ -0,0 +1,38 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Expression } from './Expression.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class IndexAccessEnd implements SlangNode { + readonly kind = NonterminalKind.IndexAccessEnd; + + comments; + + loc; + + colon: string; + + end?: Expression; + + constructor(ast: ast.IndexAccessEnd, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.colon = ast.colon.text; + if (ast.end) { + this.end = new Expression(ast.end, offsets[0], options); + } + + metadata = updateMetadata(metadata, [this.end]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [this.colon, this.end ? path.call(print, 'end') : '']; + } +} diff --git a/src/slang-nodes/IndexAccessExpression.js b/src/slang-nodes/IndexAccessExpression.js deleted file mode 100644 index a0f5b2783..000000000 --- a/src/slang-nodes/IndexAccessExpression.js +++ /dev/null @@ -1,77 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { isLabel } from '../common/util.js'; -import { SlangNode } from './SlangNode.js'; -import { Expression } from './Expression.js'; -import { IndexAccessEnd } from './IndexAccessEnd.js'; - -const { group, indent, indentIfBreak, label, softline } = doc.builders; - -export class IndexAccessExpression extends SlangNode { - get kind() { - return NonterminalKind.IndexAccessExpression; - } - - operand; - - openBracket; - - start; - - end; - - closeBracket; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => { - let i = 0; - const children = { - operand: new Expression(ast.operand, offsets[0], options), - openBracket: ast.openBracket.text, - start: ast.start - ? new Expression(ast.start, offsets[(i += 1)], options) - : undefined, - end: ast.end - ? new IndexAccessEnd(ast.end, offsets[(i += 1)], options) - : undefined, - closeBracket: ast.closeBracket.text - }; - return children; - }; - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - let operandDoc = path.call(print, 'operand'); - let indexDoc = group([ - this.openBracket, - indent([ - softline, - this.start ? path.call(print, 'start') : '', - this.end ? path.call(print, 'end') : '' - ]), - softline, - this.closeBracket - ]); - - // If we are at the end of a MemberAccessChain we should indent the - // arguments accordingly. - if (isLabel(operandDoc) && operandDoc.label === 'MemberAccessChain') { - operandDoc = group(operandDoc.contents, { - id: Symbol('IndexAccessExpression.operand') - }); - - indexDoc = indentIfBreak(indexDoc, { - groupId: operandDoc.id - }); - // We wrap the expression in a label in case there is an IndexAccess or - // a FunctionCall following this IndexAccess. - return label('MemberAccessChain', [operandDoc, indexDoc]); - } - - return [operandDoc, indexDoc].flat(); - } -} diff --git a/src/slang-nodes/IndexAccessExpression.ts b/src/slang-nodes/IndexAccessExpression.ts new file mode 100644 index 000000000..0463d88d0 --- /dev/null +++ b/src/slang-nodes/IndexAccessExpression.ts @@ -0,0 +1,87 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { isLabel } from '../slang-utils/is-label.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Expression } from './Expression.js'; +import { IndexAccessEnd } from './IndexAccessEnd.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { group, indent, indentIfBreak, label, softline } = doc.builders; + +export class IndexAccessExpression implements SlangNode { + readonly kind = NonterminalKind.IndexAccessExpression; + + comments; + + loc; + + operand: Expression; + + openBracket: string; + + start?: Expression; + + end?: IndexAccessEnd; + + closeBracket: string; + + constructor( + ast: ast.IndexAccessExpression, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.operand = new Expression(ast.operand, offsets[0], options); + this.openBracket = ast.openBracket.text; + let i = 1; + if (ast.start) { + this.start = new Expression(ast.start, offsets[i], options); + i += 1; + } + if (ast.end) { + this.end = new IndexAccessEnd(ast.end, offsets[i], options); + } + this.closeBracket = ast.closeBracket.text; + + metadata = updateMetadata(metadata, [this.operand, this.start, this.end]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + let operandDoc: Doc = path.call(print, 'operand'); + let indexDoc: Doc = group([ + this.openBracket, + indent([ + softline, + this.start ? path.call(print, 'start') : '', + this.end ? path.call(print, 'end') : '' + ]), + softline, + this.closeBracket + ]); + + // If we are at the end of a MemberAccessChain we should indent the + // arguments accordingly. + if (isLabel(operandDoc) && operandDoc.label === 'MemberAccessChain') { + operandDoc = group(operandDoc.contents, { + id: Symbol('IndexAccessExpression.operand') + }); + + indexDoc = indentIfBreak(indexDoc, { + groupId: operandDoc.id! + }); + // We wrap the expression in a label in case there is an IndexAccess or + // a FunctionCall following this IndexAccess. + return label('MemberAccessChain', [operandDoc, indexDoc]); + } + + return [operandDoc, indexDoc].flat(); + } +} diff --git a/src/slang-nodes/InheritanceSpecifier.js b/src/slang-nodes/InheritanceSpecifier.js deleted file mode 100644 index 20cf43d71..000000000 --- a/src/slang-nodes/InheritanceSpecifier.js +++ /dev/null @@ -1,28 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { InheritanceTypes } from './InheritanceTypes.js'; - -export class InheritanceSpecifier extends SlangNode { - get kind() { - return NonterminalKind.InheritanceSpecifier; - } - - isKeyword; - - types; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - isKeyword: ast.isKeyword?.text, - types: new InheritanceTypes(ast.types, offsets[0], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [this.isKeyword, path.call(print, 'types')]; - } -} diff --git a/src/slang-nodes/InheritanceSpecifier.ts b/src/slang-nodes/InheritanceSpecifier.ts new file mode 100644 index 000000000..61f7fb3a0 --- /dev/null +++ b/src/slang-nodes/InheritanceSpecifier.ts @@ -0,0 +1,40 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { InheritanceTypes } from './InheritanceTypes.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class InheritanceSpecifier implements SlangNode { + readonly kind = NonterminalKind.InheritanceSpecifier; + + comments; + + loc; + + isKeyword: string; + + types: InheritanceTypes; + + constructor( + ast: ast.InheritanceSpecifier, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.isKeyword = ast.isKeyword?.text; + this.types = new InheritanceTypes(ast.types, offsets[0], options); + + metadata = updateMetadata(metadata, [this.types]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [this.isKeyword, path.call(print, 'types')]; + } +} diff --git a/src/slang-nodes/InheritanceType.js b/src/slang-nodes/InheritanceType.js deleted file mode 100644 index 43c925afe..000000000 --- a/src/slang-nodes/InheritanceType.js +++ /dev/null @@ -1,34 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { IdentifierPath } from './IdentifierPath.js'; -import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; - -export class InheritanceType extends SlangNode { - get kind() { - return NonterminalKind.InheritanceType; - } - - typeName; - - arguments; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - typeName: new IdentifierPath(ast.typeName, offsets[0], options), - arguments: ast.arguments - ? new ArgumentsDeclaration(ast.arguments, offsets[1], options) - : undefined - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - path.call(print, 'typeName'), - this.arguments ? path.call(print, 'arguments') : '' - ]; - } -} diff --git a/src/slang-nodes/InheritanceType.ts b/src/slang-nodes/InheritanceType.ts new file mode 100644 index 000000000..c1ba52b0e --- /dev/null +++ b/src/slang-nodes/InheritanceType.ts @@ -0,0 +1,50 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { IdentifierPath } from './IdentifierPath.js'; +import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class InheritanceType implements SlangNode { + readonly kind = NonterminalKind.InheritanceType; + + comments; + + loc; + + typeName: IdentifierPath; + + arguments?: ArgumentsDeclaration; + + constructor( + ast: ast.InheritanceType, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.typeName = new IdentifierPath(ast.typeName, offsets[0]); + if (ast.arguments) { + this.arguments = new ArgumentsDeclaration( + ast.arguments, + offsets[1], + options + ); + } + + metadata = updateMetadata(metadata, [this.typeName, this.arguments]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + path.call(print, 'typeName'), + this.arguments ? path.call(print, 'arguments') : '' + ]; + } +} diff --git a/src/slang-nodes/InheritanceTypes.js b/src/slang-nodes/InheritanceTypes.js deleted file mode 100644 index 50e1f2e31..000000000 --- a/src/slang-nodes/InheritanceTypes.js +++ /dev/null @@ -1,36 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printSeparatedList } from '../common/printer-helpers.js'; -import { SlangNode } from './SlangNode.js'; -import { InheritanceType } from './InheritanceType.js'; - -const { line } = doc.builders; - -export class InheritanceTypes extends SlangNode { - get kind() { - return NonterminalKind.InheritanceTypes; - } - - items; - - separators; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => new InheritanceType(item, offsets[index], options) - ), - separators: ast.separators.map((separator) => separator.text) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return printSeparatedList(path.map(print, 'items'), { - firstSeparator: line - }); - } -} diff --git a/src/slang-nodes/InheritanceTypes.ts b/src/slang-nodes/InheritanceTypes.ts new file mode 100644 index 000000000..3b811af29 --- /dev/null +++ b/src/slang-nodes/InheritanceTypes.ts @@ -0,0 +1,48 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printSeparatedList } from '../slang-printers/print-separated-list.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { InheritanceType } from './InheritanceType.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { line } = doc.builders; + +export class InheritanceTypes implements SlangNode { + readonly kind = NonterminalKind.InheritanceTypes; + + comments; + + loc; + + items: InheritanceType[]; + + separators: string[]; + + constructor( + ast: ast.InheritanceTypes, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => new InheritanceType(item, offsets[index], options) + ); + this.separators = ast.separators.map((separator) => separator.text); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return printSeparatedList(path.map(print, 'items'), { + firstSeparator: line + }); + } +} diff --git a/src/slang-nodes/InterfaceDefinition.js b/src/slang-nodes/InterfaceDefinition.js deleted file mode 100644 index b0d54631f..000000000 --- a/src/slang-nodes/InterfaceDefinition.js +++ /dev/null @@ -1,62 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { InheritanceSpecifier } from './InheritanceSpecifier.js'; -import { InterfaceMembers } from './InterfaceMembers.js'; - -const { group, line } = doc.builders; - -export class InterfaceDefinition extends SlangNode { - get kind() { - return NonterminalKind.InterfaceDefinition; - } - - interfaceKeyword; - - name; - - inheritance; - - openBrace; - - members; - - closeBrace; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => { - let i = -1; - const children = { - interfaceKeyword: ast.interfaceKeyword.text, - name: ast.name.text, - inheritance: ast.inheritance - ? new InheritanceSpecifier( - ast.inheritance, - offsets[(i += 1)], - options - ) - : undefined, - openBrace: ast.openBrace.text, - members: new InterfaceMembers(ast.members, offsets[(i += 1)], options), - closeBrace: ast.closeBrace.text - }; - return children; - }; - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - group([ - `${this.interfaceKeyword} ${this.name}`, - this.inheritance ? path.call(print, 'inheritance') : line, - this.openBrace - ]), - path.call(print, 'members'), - this.closeBrace - ]; - } -} diff --git a/src/slang-nodes/InterfaceDefinition.ts b/src/slang-nodes/InterfaceDefinition.ts new file mode 100644 index 000000000..c86b48542 --- /dev/null +++ b/src/slang-nodes/InterfaceDefinition.ts @@ -0,0 +1,72 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { InheritanceSpecifier } from './InheritanceSpecifier.js'; +import { InterfaceMembers } from './InterfaceMembers.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { group, line } = doc.builders; + +export class InterfaceDefinition implements SlangNode { + readonly kind = NonterminalKind.InterfaceDefinition; + + comments; + + loc; + + interfaceKeyword: string; + + name: string; + + inheritance?: InheritanceSpecifier; + + openBrace: string; + + members: InterfaceMembers; + + closeBrace: string; + + constructor( + ast: ast.InterfaceDefinition, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.interfaceKeyword = ast.interfaceKeyword.text; + this.name = ast.name.text; + let i = 0; + if (ast.inheritance) { + this.inheritance = new InheritanceSpecifier( + ast.inheritance, + offsets[i], + options + ); + i += 1; + } + this.openBrace = ast.openBrace.text; + this.members = new InterfaceMembers(ast.members, offsets[i], options); + this.closeBrace = ast.closeBrace.text; + + metadata = updateMetadata(metadata, [this.inheritance, this.members]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + group([ + `${this.interfaceKeyword} ${this.name}`, + this.inheritance ? path.call(print, 'inheritance') : line, + this.openBrace + ]), + path.call(print, 'members'), + this.closeBrace + ]; + } +} diff --git a/src/slang-nodes/InterfaceMembers.js b/src/slang-nodes/InterfaceMembers.js deleted file mode 100644 index b06a934b6..000000000 --- a/src/slang-nodes/InterfaceMembers.js +++ /dev/null @@ -1,37 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printSeparatedItem } from '../common/printer-helpers.js'; -import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; -import { SlangNode } from './SlangNode.js'; -import { ContractMember } from './ContractMember.js'; - -const { hardline } = doc.builders; - -export class InterfaceMembers extends SlangNode { - get kind() { - return NonterminalKind.InterfaceMembers; - } - - items; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => new ContractMember(item, offsets[index], options) - ) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print, options) { - return this.items.length > 0 - ? printSeparatedItem( - printPreservingEmptyLines(path, 'items', options, print), - { firstSeparator: hardline, grouped: false } - ) - : ''; - } -} diff --git a/src/slang-nodes/InterfaceMembers.ts b/src/slang-nodes/InterfaceMembers.ts new file mode 100644 index 000000000..9c42c7608 --- /dev/null +++ b/src/slang-nodes/InterfaceMembers.ts @@ -0,0 +1,53 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printSeparatedItem } from '../slang-printers/print-separated-item.js'; +import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ContractMember } from './ContractMember.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { hardline } = doc.builders; + +export class InterfaceMembers implements SlangNode { + readonly kind = NonterminalKind.InterfaceMembers; + + comments; + + loc; + + items: ContractMember[]; + + constructor( + ast: ast.InterfaceMembers, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => new ContractMember(item, offsets[index], options) + ); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print( + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc { + return this.items.length > 0 + ? printSeparatedItem( + printPreservingEmptyLines(path, 'items', print, options), + { firstSeparator: hardline, grouped: false } + ) + : ''; + } +} diff --git a/src/slang-nodes/LibraryDefinition.js b/src/slang-nodes/LibraryDefinition.js deleted file mode 100644 index ee4cb0277..000000000 --- a/src/slang-nodes/LibraryDefinition.js +++ /dev/null @@ -1,44 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { LibraryMembers } from './LibraryMembers.js'; - -const { group, line } = doc.builders; - -export class LibraryDefinition extends SlangNode { - get kind() { - return NonterminalKind.LibraryDefinition; - } - - libraryKeyword; - - name; - - openBrace; - - members; - - closeBrace; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - libraryKeyword: ast.libraryKeyword.text, - name: ast.name.text, - openBrace: ast.openBrace.text, - members: new LibraryMembers(ast.members, offsets[0], options), - closeBrace: ast.closeBrace.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - group([`${this.libraryKeyword} ${this.name}`, line, this.openBrace]), - path.call(print, 'members'), - this.closeBrace - ]; - } -} diff --git a/src/slang-nodes/LibraryDefinition.ts b/src/slang-nodes/LibraryDefinition.ts new file mode 100644 index 000000000..24cca7d1a --- /dev/null +++ b/src/slang-nodes/LibraryDefinition.ts @@ -0,0 +1,56 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { LibraryMembers } from './LibraryMembers.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { group, line } = doc.builders; + +export class LibraryDefinition implements SlangNode { + readonly kind = NonterminalKind.LibraryDefinition; + + comments; + + loc; + + libraryKeyword: string; + + name: string; + + openBrace: string; + + members: LibraryMembers; + + closeBrace: string; + + constructor( + ast: ast.LibraryDefinition, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.libraryKeyword = ast.libraryKeyword.text; + this.name = ast.name.text; + this.openBrace = ast.openBrace.text; + this.members = new LibraryMembers(ast.members, offsets[0], options); + this.closeBrace = ast.closeBrace.text; + + metadata = updateMetadata(metadata, [this.members]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + group([`${this.libraryKeyword} ${this.name}`, line, this.openBrace]), + path.call(print, 'members'), + this.closeBrace + ]; + } +} diff --git a/src/slang-nodes/LibraryMembers.js b/src/slang-nodes/LibraryMembers.js deleted file mode 100644 index 8366eb76c..000000000 --- a/src/slang-nodes/LibraryMembers.js +++ /dev/null @@ -1,37 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printSeparatedItem } from '../common/printer-helpers.js'; -import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; -import { SlangNode } from './SlangNode.js'; -import { ContractMember } from './ContractMember.js'; - -const { hardline } = doc.builders; - -export class LibraryMembers extends SlangNode { - get kind() { - return NonterminalKind.LibraryMembers; - } - - items; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => new ContractMember(item, offsets[index], options) - ) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print, options) { - return this.items.length > 0 - ? printSeparatedItem( - printPreservingEmptyLines(path, 'items', options, print), - { firstSeparator: hardline, grouped: false } - ) - : ''; - } -} diff --git a/src/slang-nodes/LibraryMembers.ts b/src/slang-nodes/LibraryMembers.ts new file mode 100644 index 000000000..3168dd4e3 --- /dev/null +++ b/src/slang-nodes/LibraryMembers.ts @@ -0,0 +1,49 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printSeparatedItem } from '../slang-printers/print-separated-item.js'; +import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ContractMember } from './ContractMember.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { hardline } = doc.builders; + +export class LibraryMembers implements SlangNode { + readonly kind = NonterminalKind.LibraryMembers; + + comments; + + loc; + + items: ContractMember[]; + + constructor(ast: ast.LibraryMembers, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => new ContractMember(item, offsets[index], options) + ); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print( + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc { + return this.items.length > 0 + ? printSeparatedItem( + printPreservingEmptyLines(path, 'items', print, options), + { firstSeparator: hardline, grouped: false } + ) + : ''; + } +} diff --git a/src/slang-nodes/MappingKey.js b/src/slang-nodes/MappingKey.js deleted file mode 100644 index b63b80349..000000000 --- a/src/slang-nodes/MappingKey.js +++ /dev/null @@ -1,28 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { MappingKeyType } from './MappingKeyType.js'; - -export class MappingKey extends SlangNode { - get kind() { - return NonterminalKind.MappingKey; - } - - keyType; - - name; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - keyType: new MappingKeyType(ast.keyType, offsets[0], options), - name: ast.name?.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [path.call(print, 'keyType'), this.name ? ` ${this.name}` : '']; - } -} diff --git a/src/slang-nodes/MappingKey.ts b/src/slang-nodes/MappingKey.ts new file mode 100644 index 000000000..ba5a76182 --- /dev/null +++ b/src/slang-nodes/MappingKey.ts @@ -0,0 +1,36 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { MappingKeyType } from './MappingKeyType.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class MappingKey implements SlangNode { + readonly kind = NonterminalKind.MappingKey; + + comments; + + loc; + + keyType: MappingKeyType; + + name?: string; + + constructor(ast: ast.MappingKey, offset: number) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.keyType = new MappingKeyType(ast.keyType, offsets[0]); + this.name = ast.name?.text; + + metadata = updateMetadata(metadata, [this.keyType]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [path.call(print, 'keyType'), this.name ? ` ${this.name}` : '']; + } +} diff --git a/src/slang-nodes/MappingKeyType.js b/src/slang-nodes/MappingKeyType.js deleted file mode 100644 index 74e49cdc6..000000000 --- a/src/slang-nodes/MappingKeyType.js +++ /dev/null @@ -1,32 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { ElementaryType } from './ElementaryType.js'; -import { IdentifierPath } from './IdentifierPath.js'; - -const variants = { ElementaryType, IdentifierPath }; - -export class MappingKeyType extends SlangNode { - get kind() { - return NonterminalKind.MappingKeyType; - } - - variant; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - variant: new variants[ast.variant.cst.kind]( - ast.variant, - offsets[0], - options - ) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return path.call(print, 'variant'); - } -} diff --git a/src/slang-nodes/MappingKeyType.ts b/src/slang-nodes/MappingKeyType.ts new file mode 100644 index 000000000..29dd9052c --- /dev/null +++ b/src/slang-nodes/MappingKeyType.ts @@ -0,0 +1,49 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ElementaryType } from './ElementaryType.js'; +import { IdentifierPath } from './IdentifierPath.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class MappingKeyType implements SlangNode { + readonly kind = NonterminalKind.MappingKeyType; + + comments; + + loc; + + variant: ElementaryType | IdentifierPath; + + constructor(ast: ast.MappingKeyType, offset: number) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + switch (ast.variant.cst.kind) { + case 'ElementaryType': + this.variant = new ElementaryType( + ast.variant as ast.ElementaryType, + offsets[0] + ); + break; + case 'IdentifierPath': + this.variant = new IdentifierPath( + ast.variant as ast.IdentifierPath, + offsets[0] + ); + break; + default: + throw new Error(`Unexpected variant: ${ast.variant.cst.kind}`); + } + + metadata = updateMetadata(metadata, [this.variant]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/MappingType.js b/src/slang-nodes/MappingType.js deleted file mode 100644 index a7b53700c..000000000 --- a/src/slang-nodes/MappingType.js +++ /dev/null @@ -1,47 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { MappingKey } from './MappingKey.js'; -import { MappingValue } from './MappingValue.js'; - -export class MappingType extends SlangNode { - get kind() { - return NonterminalKind.MappingType; - } - - mappingKeyword; - - openParen; - - keyType; - - equalGreaterThan; - - valueType; - - closeParen; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - mappingKeyword: ast.mappingKeyword.text, - openParen: ast.openParen.text, - keyType: new MappingKey(ast.keyType, offsets[0], options), - equalGreaterThan: ast.equalGreaterThan.text, - valueType: new MappingValue(ast.valueType, offsets[1], options), - closeParen: ast.closeParen.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - `${this.mappingKeyword}${this.openParen}`, - path.call(print, 'keyType'), - ` ${this.equalGreaterThan} `, - path.call(print, 'valueType'), - this.closeParen - ]; - } -} diff --git a/src/slang-nodes/MappingType.ts b/src/slang-nodes/MappingType.ts new file mode 100644 index 000000000..ee7403d27 --- /dev/null +++ b/src/slang-nodes/MappingType.ts @@ -0,0 +1,55 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { MappingKey } from './MappingKey.js'; +import { MappingValue } from './MappingValue.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class MappingType implements SlangNode { + readonly kind = NonterminalKind.MappingType; + + comments; + + loc; + + mappingKeyword: string; + + openParen: string; + + keyType: MappingKey; + + equalGreaterThan: string; + + valueType: MappingValue; + + closeParen: string; + + constructor(ast: ast.MappingType, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.mappingKeyword = ast.mappingKeyword.text; + this.openParen = ast.openParen.text; + this.keyType = new MappingKey(ast.keyType, offsets[0]); + this.equalGreaterThan = ast.equalGreaterThan.text; + this.valueType = new MappingValue(ast.valueType, offsets[1], options); + this.closeParen = ast.closeParen.text; + + metadata = updateMetadata(metadata, [this.keyType, this.valueType]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + `${this.mappingKeyword}${this.openParen}`, + path.call(print, 'keyType'), + ` ${this.equalGreaterThan} `, + path.call(print, 'valueType'), + this.closeParen + ]; + } +} diff --git a/src/slang-nodes/MappingValue.js b/src/slang-nodes/MappingValue.js deleted file mode 100644 index 7ed1e290c..000000000 --- a/src/slang-nodes/MappingValue.js +++ /dev/null @@ -1,28 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { TypeName } from './TypeName.js'; - -export class MappingValue extends SlangNode { - get kind() { - return NonterminalKind.MappingValue; - } - - typeName; - - name; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - typeName: new TypeName(ast.typeName, offsets[0], options), - name: ast.name?.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [path.call(print, 'typeName'), this.name ? ` ${this.name}` : '']; - } -} diff --git a/src/slang-nodes/MappingValue.ts b/src/slang-nodes/MappingValue.ts new file mode 100644 index 000000000..342853e42 --- /dev/null +++ b/src/slang-nodes/MappingValue.ts @@ -0,0 +1,36 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { TypeName } from './TypeName.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class MappingValue implements SlangNode { + readonly kind = NonterminalKind.MappingValue; + + comments; + + loc; + + typeName: TypeName; + + name?: string; + + constructor(ast: ast.MappingValue, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.typeName = new TypeName(ast.typeName, offsets[0], options); + this.name = ast.name?.text; + + metadata = updateMetadata(metadata, [this.typeName]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [path.call(print, 'typeName'), this.name ? ` ${this.name}` : '']; + } +} diff --git a/src/slang-nodes/MemberAccess.js b/src/slang-nodes/MemberAccess.js deleted file mode 100644 index 5bb50cd87..000000000 --- a/src/slang-nodes/MemberAccess.js +++ /dev/null @@ -1,24 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; - -export class MemberAccess extends SlangNode { - get kind() { - return NonterminalKind.MemberAccess; - } - - variant; - - constructor(ast, offset) { - super(); - - const fetch = () => ({ - variant: ast.variant.text - }); - - this.initialize(ast, offset, fetch); - } - - print() { - return this.variant; - } -} diff --git a/src/slang-nodes/MemberAccess.ts b/src/slang-nodes/MemberAccess.ts new file mode 100644 index 000000000..ae2534336 --- /dev/null +++ b/src/slang-nodes/MemberAccess.ts @@ -0,0 +1,29 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata } from '../slang-utils/get-offsets.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class MemberAccess implements SlangNode { + readonly kind = NonterminalKind.MemberAccess; + + comments; + + loc; + + variant: string; + + constructor(ast: ast.MemberAccess, offset: number) { + const metadata = getNodeMetadata(ast, offset); + + this.variant = ast.variant.text; + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(): Doc { + return this.variant; + } +} diff --git a/src/slang-nodes/MemberAccessExpression.js b/src/slang-nodes/MemberAccessExpression.ts similarity index 75% rename from src/slang-nodes/MemberAccessExpression.js rename to src/slang-nodes/MemberAccessExpression.ts index 7c6678365..431438204 100644 --- a/src/slang-nodes/MemberAccessExpression.js +++ b/src/slang-nodes/MemberAccessExpression.ts @@ -1,11 +1,15 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { isLabel } from '../common/util.js'; +import { isLabel } from '../slang-utils/is-label.js'; import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js'; -import { SlangNode } from './SlangNode.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; import { Expression } from './Expression.js'; import { MemberAccess } from './MemberAccess.js'; +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + const { group, indent, label, softline } = doc.builders; const isChainableExpression = createKindCheckFunction([ @@ -14,7 +18,7 @@ const isChainableExpression = createKindCheckFunction([ 'MemberAccessExpression' ]); -function isEndOfChain(node, path) { +function isEndOfChain(node: MemberAccessExpression, path: AstPath): boolean { for ( let i = 0, currentNode = node, grandparentNode = path.getNode(i + 2); isChainableExpression(grandparentNode); @@ -93,7 +97,7 @@ function isEndOfChain(node, path) { * @returns a processed doc[] with the proper grouping and indentation ready to * be printed. */ -function processChain(chain) { +function processChain(chain: Doc[]): Doc { const firstSeparatorIndex = chain.findIndex( (element) => isLabel(element) && element.label === 'separator' ); @@ -108,30 +112,38 @@ function processChain(chain) { ]); } -export class MemberAccessExpression extends SlangNode { - get kind() { - return NonterminalKind.MemberAccessExpression; - } +export class MemberAccessExpression implements SlangNode { + readonly kind = NonterminalKind.MemberAccessExpression; + + comments; - operand; + loc; - period; + operand: Expression; - member; + period: string; + + member: MemberAccess; + + constructor( + ast: ast.MemberAccessExpression, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; - constructor(ast, offset, options) { - super(); + this.operand = new Expression(ast.operand, offsets[0], options); + this.period = ast.period.text; + this.member = new MemberAccess(ast.member, offsets[1]); - const fetch = (offsets) => ({ - operand: new Expression(ast.operand, offsets[0], options), - period: ast.period.text, - member: new MemberAccess(ast.member, offsets[1], options) - }); + metadata = updateMetadata(metadata, [this.operand, this.member]); - this.initialize(ast, offset, fetch); + this.comments = metadata.comments; + this.loc = metadata.loc; } - print(path, print) { + print(path: AstPath, print: (path: AstPath) => Doc): Doc { let operandDoc = path.call(print, 'operand'); if (Array.isArray(operandDoc)) { operandDoc = operandDoc.flat(); diff --git a/src/slang-nodes/ModifierAttribute.js b/src/slang-nodes/ModifierAttribute.js deleted file mode 100644 index 9ea0f6bf5..000000000 --- a/src/slang-nodes/ModifierAttribute.js +++ /dev/null @@ -1,30 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { OverrideSpecifier } from './OverrideSpecifier.js'; - -export class ModifierAttribute extends SlangNode { - get kind() { - return NonterminalKind.ModifierAttribute; - } - - variant; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - variant: - ast.variant.type === 'Terminal' - ? ast.variant.text - : new OverrideSpecifier(ast.variant, offsets[0], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return typeof this.variant === 'string' - ? this.variant - : path.call(print, 'variant'); - } -} diff --git a/src/slang-nodes/ModifierAttribute.ts b/src/slang-nodes/ModifierAttribute.ts new file mode 100644 index 000000000..a5e46b080 --- /dev/null +++ b/src/slang-nodes/ModifierAttribute.ts @@ -0,0 +1,42 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { OverrideSpecifier } from './OverrideSpecifier.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class ModifierAttribute implements SlangNode { + readonly kind = NonterminalKind.ModifierAttribute; + + comments; + + loc; + + variant: OverrideSpecifier | string; + + constructor(ast: ast.ModifierAttribute, offset: number) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.variant = + ast.variant instanceof TerminalNode + ? ast.variant.text + : new OverrideSpecifier(ast.variant, offsets[0]); + + metadata = updateMetadata( + metadata, + typeof this.variant === 'string' ? [] : [this.variant] + ); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/ModifierAttributes.js b/src/slang-nodes/ModifierAttributes.js deleted file mode 100644 index d6018e971..000000000 --- a/src/slang-nodes/ModifierAttributes.js +++ /dev/null @@ -1,31 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { postProcessFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; -import { SlangNode } from './SlangNode.js'; -import { ModifierAttribute } from './ModifierAttribute.js'; - -const { line } = doc.builders; - -export class ModifierAttributes extends SlangNode { - get kind() { - return NonterminalKind.ModifierAttributes; - } - - items; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => new ModifierAttribute(item, offsets[index], options) - ) - }); - - this.initialize(ast, offset, fetch, postProcessFunctionAttributes); - } - - print(path, print) { - return path.map(print, 'items').map((item) => [line, item]); - } -} diff --git a/src/slang-nodes/ModifierAttributes.ts b/src/slang-nodes/ModifierAttributes.ts new file mode 100644 index 000000000..d77174e2b --- /dev/null +++ b/src/slang-nodes/ModifierAttributes.ts @@ -0,0 +1,41 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ModifierAttribute } from './ModifierAttribute.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { line } = doc.builders; + +export class ModifierAttributes implements SlangNode { + readonly kind = NonterminalKind.ModifierAttributes; + + comments; + + loc; + + items: ModifierAttribute[]; + + constructor(ast: ast.ModifierAttributes, offset: number) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => new ModifierAttribute(item, offsets[index]) + ); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + + this.items = this.items.sort(sortFunctionAttributes); + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return path.map(print, 'items').map((item) => [line, item]); + } +} diff --git a/src/slang-nodes/ModifierDefinition.js b/src/slang-nodes/ModifierDefinition.js deleted file mode 100644 index f42d4939d..000000000 --- a/src/slang-nodes/ModifierDefinition.js +++ /dev/null @@ -1,89 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printFunction } from '../slang-printers/print-function.js'; -import { SlangNode } from './SlangNode.js'; -import { ParametersDeclaration } from './ParametersDeclaration.js'; -import { Parameters } from './Parameters.js'; -import { ModifierAttributes } from './ModifierAttributes.js'; -import { FunctionBody } from './FunctionBody.js'; - -const postProcess = (properties) => { - if (typeof properties.parameters !== 'undefined') return properties; - - const parametersOffset = - properties.attributes.loc.start - properties.attributes.loc.leadingOffset; - const parametersLoc = { - start: parametersOffset, - end: parametersOffset, - leadingOffset: 0, - trailingOffset: 0 - }; - - return { - ...properties, - parameters: Object.create(ParametersDeclaration.prototype, { - loc: { value: { ...parametersLoc } }, - openParen: { value: '(' }, - parameters: { - value: Object.create(Parameters.prototype, { - loc: { value: { ...parametersLoc } }, - items: { value: [] }, - separators: { value: [] } - }) - }, - closeParen: { value: ')' } - }) - }; -}; - -export class ModifierDefinition extends SlangNode { - get kind() { - return NonterminalKind.ModifierDefinition; - } - - modifierKeyword; - - name; - - parameters; - - attributes; - - body; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => { - let i = -1; - const children = { - modifierKeyword: ast.modifierKeyword.text, - name: ast.name.text, - parameters: ast.parameters - ? new ParametersDeclaration( - ast.parameters, - offsets[(i += 1)], - options - ) - : undefined, - attributes: new ModifierAttributes( - ast.attributes, - offsets[(i += 1)], - options - ), - body: new FunctionBody(ast.body, offsets[(i += 1)], options) - }; - return children; - }; - - this.initialize(ast, offset, fetch, postProcess); - } - - print(path, print) { - return printFunction( - `${this.modifierKeyword} ${this.name}`, - this, - path, - print - ); - } -} diff --git a/src/slang-nodes/ModifierDefinition.ts b/src/slang-nodes/ModifierDefinition.ts new file mode 100644 index 000000000..bb0126fc2 --- /dev/null +++ b/src/slang-nodes/ModifierDefinition.ts @@ -0,0 +1,99 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printFunction } from '../slang-printers/print-function.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ParametersDeclaration } from './ParametersDeclaration.js'; +import { Parameters } from './Parameters.js'; +import { ModifierAttributes } from './ModifierAttributes.js'; +import { FunctionBody } from './FunctionBody.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class ModifierDefinition implements SlangNode { + readonly kind = NonterminalKind.ModifierDefinition; + + comments; + + loc; + + modifierKeyword; + + name; + + parameters?: ParametersDeclaration; + + attributes: ModifierAttributes; + + body: FunctionBody; + + constructor( + ast: ast.ModifierDefinition, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.modifierKeyword = ast.modifierKeyword.text; + this.name = ast.name.text; + let i = 0; + if (ast.parameters) { + this.parameters = new ParametersDeclaration( + ast.parameters, + offsets[i], + options + ); + i += 1; + } + this.attributes = new ModifierAttributes(ast.attributes, offsets[i]); + i += 1; + this.body = new FunctionBody(ast.body, offsets[i], options); + + metadata = updateMetadata(metadata, [ + this.parameters, + this.attributes, + this.body + ]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + + if (!this.parameters) { + const parametersOffset = + this.attributes.loc.start - this.attributes.loc.leadingOffset!; + const parametersLoc = { + start: parametersOffset, + end: parametersOffset, + leadingOffset: 0, + trailingOffset: 0 + }; + + this.parameters = Object.create(ParametersDeclaration.prototype, { + kind: { value: NonterminalKind.ParametersDeclaration }, + loc: { value: { ...parametersLoc } }, + comments: { value: [] }, + openParen: { value: '(' }, + parameters: { + value: Object.create(Parameters.prototype, { + kind: { value: NonterminalKind.Parameters }, + loc: { value: { ...parametersLoc } }, + comments: { value: [] }, + items: { value: [] }, + separators: { value: [] } + }) + }, + closeParen: { value: ')' } + }); + } + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return printFunction( + `${this.modifierKeyword} ${this.name}`, + this, + path, + print + ); + } +} diff --git a/src/slang-nodes/ModifierInvocation.js b/src/slang-nodes/ModifierInvocation.js deleted file mode 100644 index 9f6869b6d..000000000 --- a/src/slang-nodes/ModifierInvocation.js +++ /dev/null @@ -1,46 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { isComment } from '../slang-utils/is-comment.js'; -import { SlangNode } from './SlangNode.js'; -import { IdentifierPath } from './IdentifierPath.js'; -import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; - -export class ModifierInvocation extends SlangNode { - get kind() { - return NonterminalKind.ModifierInvocation; - } - - name; - - arguments; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - name: new IdentifierPath(ast.name, offsets[0], options), - arguments: ast.arguments - ? new ArgumentsDeclaration(ast.arguments, offsets[1], options) - : undefined - }); - - this.initialize(ast, offset, fetch); - - this.cleanModifierInvocationArguments = () => { - if ( - this.arguments && - this.arguments.variant.kind === 'PositionalArgumentsDeclaration' && - this.arguments.variant.arguments.items.length === 0 && // no arguments - !ast.arguments.variant.cst.children().some((child) => isComment(child)) // no comments - ) { - this.arguments = undefined; - } - }; - } - - print(path, print) { - return [ - path.call(print, 'name'), - this.arguments ? path.call(print, 'arguments') : '' - ]; - } -} diff --git a/src/slang-nodes/ModifierInvocation.ts b/src/slang-nodes/ModifierInvocation.ts new file mode 100644 index 000000000..04c9d000f --- /dev/null +++ b/src/slang-nodes/ModifierInvocation.ts @@ -0,0 +1,61 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { isComment } from '../slang-utils/is-comment.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { IdentifierPath } from './IdentifierPath.js'; +import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; +import type { PositionalArgumentsDeclaration } from './PositionalArgumentsDeclaration.js'; + +export class ModifierInvocation implements SlangNode { + readonly kind = NonterminalKind.ModifierInvocation; + + comments; + + loc; + + cleanModifierInvocationArguments; + + name: IdentifierPath; + + arguments?: ArgumentsDeclaration; + + constructor( + ast: ast.ModifierInvocation, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.name = new IdentifierPath(ast.name, offsets[0]); + this.arguments = ast.arguments + ? new ArgumentsDeclaration(ast.arguments, offsets[1], options) + : undefined; + + metadata = updateMetadata(metadata, [this.name, this.arguments]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + + this.cleanModifierInvocationArguments = (): void => { + if ( + this.arguments && + this.arguments.variant.kind === 'PositionalArgumentsDeclaration' && + this.arguments.variant.arguments.items.length === 0 && // no arguments + !ast.arguments!.variant.cst.children().some((child) => isComment(child)) // no comments + ) { + this.arguments = undefined; + } + }; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + path.call(print, 'name'), + this.arguments ? path.call(print, 'arguments') : '' + ]; + } +} diff --git a/src/slang-nodes/MultiplicativeExpression.js b/src/slang-nodes/MultiplicativeExpression.js deleted file mode 100644 index f3fa02d35..000000000 --- a/src/slang-nodes/MultiplicativeExpression.js +++ /dev/null @@ -1,60 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; -import { createHugFunction } from '../slang-utils/create-hug-function.js'; -import { SlangNode } from './SlangNode.js'; -import { Expression } from './Expression.js'; - -const multiplicationTryToHug = createHugFunction(['/', '%']); -const divisionTryToHug = createHugFunction(['*', '%']); -const moduloTryToHug = createHugFunction(['*', '/', '%']); - -const postProcess = (properties) => { - let { leftOperand } = properties; - - switch (properties.operator) { - case '*': - leftOperand = multiplicationTryToHug(leftOperand); - break; - case '/': - leftOperand = divisionTryToHug(leftOperand); - break; - case '%': - leftOperand = moduloTryToHug(leftOperand); - break; - default: - break; - } - - return { - ...properties, - leftOperand - }; -}; - -export class MultiplicativeExpression extends SlangNode { - get kind() { - return NonterminalKind.MultiplicativeExpression; - } - - leftOperand; - - operator; - - rightOperand; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - leftOperand: new Expression(ast.leftOperand, offsets[0], options), - operator: ast.operator.text, - rightOperand: new Expression(ast.rightOperand, offsets[1], options) - }); - - this.initialize(ast, offset, fetch, postProcess); - } - - print(path, print, options) { - return printBinaryOperation({ node: this, path, print, options }); - } -} diff --git a/src/slang-nodes/MultiplicativeExpression.ts b/src/slang-nodes/MultiplicativeExpression.ts new file mode 100644 index 000000000..8a5a332a3 --- /dev/null +++ b/src/slang-nodes/MultiplicativeExpression.ts @@ -0,0 +1,67 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; +import { createHugFunction } from '../slang-utils/create-hug-function.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Expression } from './Expression.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const multiplicationTryToHug = createHugFunction(['/', '%']); +const divisionTryToHug = createHugFunction(['*', '%']); +const moduloTryToHug = createHugFunction(['*', '/', '%']); + +export class MultiplicativeExpression implements SlangNode { + readonly kind = NonterminalKind.MultiplicativeExpression; + + comments; + + loc; + + leftOperand: Expression; + + operator: string; + + rightOperand: Expression; + + constructor( + ast: ast.MultiplicativeExpression, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.leftOperand = new Expression(ast.leftOperand, offsets[0], options); + this.operator = ast.operator.text; + this.rightOperand = new Expression(ast.rightOperand, offsets[1], options); + + metadata = updateMetadata(metadata, [this.leftOperand, this.rightOperand]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + + switch (this.operator) { + case '*': + this.leftOperand = multiplicationTryToHug(this.leftOperand); + break; + case '/': + this.leftOperand = divisionTryToHug(this.leftOperand); + break; + case '%': + this.leftOperand = moduloTryToHug(this.leftOperand); + break; + default: + throw new Error(`Unexpected operator: ${this.operator}`); + } + } + + print( + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc { + return printBinaryOperation(this, path, print, options); + } +} diff --git a/src/slang-nodes/NamedArgument.js b/src/slang-nodes/NamedArgument.js deleted file mode 100644 index 6b58892c6..000000000 --- a/src/slang-nodes/NamedArgument.js +++ /dev/null @@ -1,31 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { Expression } from './Expression.js'; - -export class NamedArgument extends SlangNode { - get kind() { - return NonterminalKind.NamedArgument; - } - - name; - - colon; - - value; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - name: ast.name.text, - colon: ast.colon.text, - value: new Expression(ast.value, offsets[0], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [`${this.name}${this.colon} `, path.call(print, 'value')]; - } -} diff --git a/src/slang-nodes/NamedArgument.ts b/src/slang-nodes/NamedArgument.ts new file mode 100644 index 000000000..f64e34db1 --- /dev/null +++ b/src/slang-nodes/NamedArgument.ts @@ -0,0 +1,39 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Expression } from './Expression.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class NamedArgument implements SlangNode { + readonly kind = NonterminalKind.NamedArgument; + + comments; + + loc; + + name: string; + + colon: string; + + value: Expression; + + constructor(ast: ast.NamedArgument, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.name = ast.name.text; + this.colon = ast.colon.text; + this.value = new Expression(ast.value, offsets[0], options); + + metadata = updateMetadata(metadata, [this.value]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [`${this.name}${this.colon} `, path.call(print, 'value')]; + } +} diff --git a/src/slang-nodes/NamedArgumentGroup.js b/src/slang-nodes/NamedArgumentGroup.js deleted file mode 100644 index fc52a45d1..000000000 --- a/src/slang-nodes/NamedArgumentGroup.js +++ /dev/null @@ -1,31 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { NamedArguments } from './NamedArguments.js'; - -export class NamedArgumentGroup extends SlangNode { - get kind() { - return NonterminalKind.NamedArgumentGroup; - } - - openBrace; - - arguments; - - closeBrace; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - openBrace: ast.openBrace.text, - arguments: new NamedArguments(ast.arguments, offsets[0], options), - closeBrace: ast.closeBrace.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [this.openBrace, path.call(print, 'arguments'), this.closeBrace]; - } -} diff --git a/src/slang-nodes/NamedArgumentGroup.ts b/src/slang-nodes/NamedArgumentGroup.ts new file mode 100644 index 000000000..d9cd21eb9 --- /dev/null +++ b/src/slang-nodes/NamedArgumentGroup.ts @@ -0,0 +1,43 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { NamedArguments } from './NamedArguments.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class NamedArgumentGroup implements SlangNode { + readonly kind = NonterminalKind.NamedArgumentGroup; + + comments; + + loc; + + openBrace: string; + + arguments: NamedArguments; + + closeBrace: string; + + constructor( + ast: ast.NamedArgumentGroup, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.openBrace = ast.openBrace.text; + this.arguments = new NamedArguments(ast.arguments, offsets[0], options); + this.closeBrace = ast.closeBrace.text; + + metadata = updateMetadata(metadata, [this.arguments]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [this.openBrace, path.call(print, 'arguments'), this.closeBrace]; + } +} diff --git a/src/slang-nodes/NamedArguments.js b/src/slang-nodes/NamedArguments.js deleted file mode 100644 index 703cb4c95..000000000 --- a/src/slang-nodes/NamedArguments.js +++ /dev/null @@ -1,36 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printSeparatedList } from '../common/printer-helpers.js'; -import { SlangNode } from './SlangNode.js'; -import { NamedArgument } from './NamedArgument.js'; - -const { line, softline } = doc.builders; - -export class NamedArguments extends SlangNode { - get kind() { - return NonterminalKind.NamedArguments; - } - - items; - - separators; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => new NamedArgument(item, offsets[index], options) - ), - separators: ast.separators.map((separator) => separator.text) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print, options) { - return printSeparatedList(path.map(print, 'items'), { - firstSeparator: options.bracketSpacing ? line : softline - }); - } -} diff --git a/src/slang-nodes/NamedArguments.ts b/src/slang-nodes/NamedArguments.ts new file mode 100644 index 000000000..903f18805 --- /dev/null +++ b/src/slang-nodes/NamedArguments.ts @@ -0,0 +1,48 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printSeparatedList } from '../slang-printers/print-separated-list.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { NamedArgument } from './NamedArgument.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { line, softline } = doc.builders; + +export class NamedArguments implements SlangNode { + readonly kind = NonterminalKind.NamedArguments; + + comments; + + loc; + + items: NamedArgument[]; + + separators: string[]; + + constructor(ast: ast.NamedArguments, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => new NamedArgument(item, offsets[index], options) + ); + this.separators = ast.separators.map((separator) => separator.text); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print( + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc { + return printSeparatedList(path.map(print, 'items'), { + firstSeparator: options.bracketSpacing ? line : softline + }); + } +} diff --git a/src/slang-nodes/NamedArgumentsDeclaration.js b/src/slang-nodes/NamedArgumentsDeclaration.js deleted file mode 100644 index efea82178..000000000 --- a/src/slang-nodes/NamedArgumentsDeclaration.js +++ /dev/null @@ -1,37 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { NamedArgumentGroup } from './NamedArgumentGroup.js'; - -export class NamedArgumentsDeclaration extends SlangNode { - get kind() { - return NonterminalKind.NamedArgumentsDeclaration; - } - - openParen; - - arguments; - - closeParen; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - openParen: ast.openParen.text, - arguments: ast.arguments - ? new NamedArgumentGroup(ast.arguments, offsets[0], options) - : undefined, - closeParen: ast.closeParen.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - this.openParen, - this.arguments ? path.call(print, 'arguments') : '', - this.closeParen - ]; - } -} diff --git a/src/slang-nodes/NamedArgumentsDeclaration.ts b/src/slang-nodes/NamedArgumentsDeclaration.ts new file mode 100644 index 000000000..62ccbf265 --- /dev/null +++ b/src/slang-nodes/NamedArgumentsDeclaration.ts @@ -0,0 +1,53 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { NamedArgumentGroup } from './NamedArgumentGroup.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class NamedArgumentsDeclaration implements SlangNode { + readonly kind = NonterminalKind.NamedArgumentsDeclaration; + + comments; + + loc; + + openParen: string; + + arguments?: NamedArgumentGroup; + + closeParen: string; + + constructor( + ast: ast.NamedArgumentsDeclaration, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.openParen = ast.openParen.text; + if (ast.arguments) { + this.arguments = new NamedArgumentGroup( + ast.arguments, + offsets[0], + options + ); + } + this.closeParen = ast.closeParen.text; + + metadata = updateMetadata(metadata, [this.arguments]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + this.openParen, + this.arguments ? path.call(print, 'arguments') : '', + this.closeParen + ]; + } +} diff --git a/src/slang-nodes/NamedImport.js b/src/slang-nodes/NamedImport.js deleted file mode 100644 index c4ff99eae..000000000 --- a/src/slang-nodes/NamedImport.js +++ /dev/null @@ -1,40 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { ImportAlias } from './ImportAlias.js'; -import { StringLiteral } from './StringLiteral.js'; - -export class NamedImport extends SlangNode { - get kind() { - return NonterminalKind.NamedImport; - } - - asterisk; - - alias; - - fromKeyword; - - path; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - asterisk: ast.asterisk.text, - alias: new ImportAlias(ast.alias, offsets[0], options), - fromKeyword: ast.fromKeyword.text, - path: new StringLiteral(ast.path, offsets[1], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - this.asterisk, - path.call(print, 'alias'), - ` ${this.fromKeyword} `, - path.call(print, 'path') - ]; - } -} diff --git a/src/slang-nodes/NamedImport.ts b/src/slang-nodes/NamedImport.ts new file mode 100644 index 000000000..dad172e6c --- /dev/null +++ b/src/slang-nodes/NamedImport.ts @@ -0,0 +1,48 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ImportAlias } from './ImportAlias.js'; +import { StringLiteral } from './StringLiteral.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class NamedImport implements SlangNode { + readonly kind = NonterminalKind.NamedImport; + + comments; + + loc; + + asterisk: string; + + alias: ImportAlias; + + fromKeyword: string; + + path: StringLiteral; + + constructor(ast: ast.NamedImport, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.asterisk = ast.asterisk.text; + this.alias = new ImportAlias(ast.alias, offsets[0]); + this.fromKeyword = ast.fromKeyword.text; + this.path = new StringLiteral(ast.path, offsets[1], options); + + metadata = updateMetadata(metadata, [this.alias, this.path]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + this.asterisk, + path.call(print, 'alias'), + ` ${this.fromKeyword} `, + path.call(print, 'path') + ]; + } +} diff --git a/src/slang-nodes/NewExpression.js b/src/slang-nodes/NewExpression.js deleted file mode 100644 index f243e6e1b..000000000 --- a/src/slang-nodes/NewExpression.js +++ /dev/null @@ -1,28 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { TypeName } from './TypeName.js'; - -export class NewExpression extends SlangNode { - get kind() { - return NonterminalKind.NewExpression; - } - - newKeyword; - - typeName; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - newKeyword: ast.newKeyword.text, - typeName: new TypeName(ast.typeName, offsets[0], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [`${this.newKeyword} `, path.call(print, 'typeName')]; - } -} diff --git a/src/slang-nodes/NewExpression.ts b/src/slang-nodes/NewExpression.ts new file mode 100644 index 000000000..0590b6067 --- /dev/null +++ b/src/slang-nodes/NewExpression.ts @@ -0,0 +1,36 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { TypeName } from './TypeName.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class NewExpression implements SlangNode { + readonly kind = NonterminalKind.NewExpression; + + comments; + + loc; + + newKeyword: string; + + typeName: TypeName; + + constructor(ast: ast.NewExpression, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.newKeyword = ast.newKeyword.text; + this.typeName = new TypeName(ast.typeName, offsets[0], options); + + metadata = updateMetadata(metadata, [this.typeName]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [`${this.newKeyword} `, path.call(print, 'typeName')]; + } +} diff --git a/src/slang-nodes/NumberUnit.js b/src/slang-nodes/NumberUnit.js deleted file mode 100644 index 4fac5b43a..000000000 --- a/src/slang-nodes/NumberUnit.js +++ /dev/null @@ -1,24 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; - -export class NumberUnit extends SlangNode { - get kind() { - return NonterminalKind.NumberUnit; - } - - variant; - - constructor(ast, offset) { - super(); - - const fetch = () => ({ - variant: ast.variant.text - }); - - this.initialize(ast, offset, fetch); - } - - print() { - return this.variant; - } -} diff --git a/src/slang-nodes/NumberUnit.ts b/src/slang-nodes/NumberUnit.ts new file mode 100644 index 000000000..14a3e4bf5 --- /dev/null +++ b/src/slang-nodes/NumberUnit.ts @@ -0,0 +1,29 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata } from '../slang-utils/get-offsets.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class NumberUnit implements SlangNode { + readonly kind = NonterminalKind.NumberUnit; + + comments; + + loc; + + variant: string; + + constructor(ast: ast.NumberUnit, offset: number) { + const metadata = getNodeMetadata(ast, offset); + + this.variant = ast.variant.text; + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(): Doc { + return this.variant; + } +} diff --git a/src/slang-nodes/OrExpression.js b/src/slang-nodes/OrExpression.js deleted file mode 100644 index 915a12433..000000000 --- a/src/slang-nodes/OrExpression.js +++ /dev/null @@ -1,41 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printLogicalOperation } from '../slang-printers/print-logical-operation.js'; -import { createHugFunction } from '../slang-utils/create-hug-function.js'; -import { SlangNode } from './SlangNode.js'; -import { Expression } from './Expression.js'; - -const tryToHug = createHugFunction(['&&']); - -const postProcess = (properties) => ({ - ...properties, - leftOperand: tryToHug(properties.leftOperand), - rightOperand: tryToHug(properties.rightOperand) -}); - -export class OrExpression extends SlangNode { - get kind() { - return NonterminalKind.OrExpression; - } - - leftOperand; - - operator; - - rightOperand; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - leftOperand: new Expression(ast.leftOperand, offsets[0], options), - operator: ast.operator.text, - rightOperand: new Expression(ast.rightOperand, offsets[1], options) - }); - - this.initialize(ast, offset, fetch, postProcess); - } - - print(path, print, options) { - return printLogicalOperation({ node: this, path, print, options }); - } -} diff --git a/src/slang-nodes/OrExpression.ts b/src/slang-nodes/OrExpression.ts new file mode 100644 index 000000000..d4feabde3 --- /dev/null +++ b/src/slang-nodes/OrExpression.ts @@ -0,0 +1,50 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printLogicalOperation } from '../slang-printers/print-logical-operation.js'; +import { createHugFunction } from '../slang-utils/create-hug-function.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Expression } from './Expression.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const tryToHug = createHugFunction(['&&']); + +export class OrExpression implements SlangNode { + readonly kind = NonterminalKind.OrExpression; + + comments; + + loc; + + leftOperand: Expression; + + operator: string; + + rightOperand: Expression; + + constructor(ast: ast.OrExpression, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.leftOperand = new Expression(ast.leftOperand, offsets[0], options); + this.operator = ast.operator.text; + this.rightOperand = new Expression(ast.rightOperand, offsets[1], options); + + metadata = updateMetadata(metadata, [this.leftOperand, this.rightOperand]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + + this.leftOperand = tryToHug(this.leftOperand); + this.rightOperand = tryToHug(this.rightOperand); + } + + print( + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc { + return printLogicalOperation(this, path, print, options); + } +} diff --git a/src/slang-nodes/OverridePaths.js b/src/slang-nodes/OverridePaths.js deleted file mode 100644 index e17aa6d32..000000000 --- a/src/slang-nodes/OverridePaths.js +++ /dev/null @@ -1,31 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { IdentifierPath } from './IdentifierPath.js'; - -export class OverridePaths extends SlangNode { - get kind() { - return NonterminalKind.OverridePaths; - } - - items; - - separators; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => new IdentifierPath(item, offsets[index], options) - ), - separators: ast.separators.map((separator) => separator.text) - }); - - this.initialize(ast, offset, fetch); - } - - // TODO: implement print - print(path, print, options) { - return ['TODO: OverridePaths']; - } -} diff --git a/src/slang-nodes/OverridePaths.ts b/src/slang-nodes/OverridePaths.ts new file mode 100644 index 000000000..81f3c4bc6 --- /dev/null +++ b/src/slang-nodes/OverridePaths.ts @@ -0,0 +1,43 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { IdentifierPath } from './IdentifierPath.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class OverridePaths implements SlangNode { + readonly kind = NonterminalKind.OverridePaths; + + comments; + + loc; + + items: IdentifierPath[]; + + separators: string[]; + + constructor(ast: ast.OverridePaths, offset: number) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => new IdentifierPath(item, offsets[index]) + ); + this.separators = ast.separators.map((separator) => separator.text); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + // TODO: implement print + print( + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc { + return ['TODO: OverridePaths']; + } +} diff --git a/src/slang-nodes/OverridePathsDeclaration.js b/src/slang-nodes/OverridePathsDeclaration.js deleted file mode 100644 index d1bf8a72a..000000000 --- a/src/slang-nodes/OverridePathsDeclaration.js +++ /dev/null @@ -1,32 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { OverridePaths } from './OverridePaths.js'; - -export class OverridePathsDeclaration extends SlangNode { - get kind() { - return NonterminalKind.OverridePathsDeclaration; - } - - openParen; - - paths; - - closeParen; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - openParen: ast.openParen.text, - paths: new OverridePaths(ast.paths, offsets[0], options), - closeParen: ast.closeParen.text - }); - - this.initialize(ast, offset, fetch); - } - - // TODO: implement print - print(path, print, options) { - return ['TODO: OverridePathsDeclaration']; - } -} diff --git a/src/slang-nodes/OverridePathsDeclaration.ts b/src/slang-nodes/OverridePathsDeclaration.ts new file mode 100644 index 000000000..341c8c4bf --- /dev/null +++ b/src/slang-nodes/OverridePathsDeclaration.ts @@ -0,0 +1,44 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { OverridePaths } from './OverridePaths.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class OverridePathsDeclaration implements SlangNode { + readonly kind = NonterminalKind.OverridePathsDeclaration; + + comments; + + loc; + + openParen: string; + + paths: OverridePaths; + + closeParen: string; + + constructor(ast: ast.OverridePathsDeclaration, offset: number) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.openParen = ast.openParen.text; + this.paths = new OverridePaths(ast.paths, offsets[0]); + this.closeParen = ast.closeParen.text; + + metadata = updateMetadata(metadata, [this.paths]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + // TODO: implement print + print( + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc { + return ['TODO: OverridePathsDeclaration']; + } +} diff --git a/src/slang-nodes/OverrideSpecifier.js b/src/slang-nodes/OverrideSpecifier.js deleted file mode 100644 index 93d73368f..000000000 --- a/src/slang-nodes/OverrideSpecifier.js +++ /dev/null @@ -1,33 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { OverridePathsDeclaration } from './OverridePathsDeclaration.js'; - -export class OverrideSpecifier extends SlangNode { - get kind() { - return NonterminalKind.OverrideSpecifier; - } - - overrideKeyword; - - overridden; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - overrideKeyword: ast.overrideKeyword.text, - overridden: ast.overridden - ? new OverridePathsDeclaration(ast.overridden, offsets[0], options) - : undefined - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - this.overrideKeyword, - this.overridden ? path.call(print, 'overridden') : '' - ]; - } -} diff --git a/src/slang-nodes/OverrideSpecifier.ts b/src/slang-nodes/OverrideSpecifier.ts new file mode 100644 index 000000000..67e202172 --- /dev/null +++ b/src/slang-nodes/OverrideSpecifier.ts @@ -0,0 +1,44 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { OverridePathsDeclaration } from './OverridePathsDeclaration.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class OverrideSpecifier implements SlangNode { + readonly kind = NonterminalKind.OverrideSpecifier; + + comments; + + loc; + + overrideKeyword: string; + + overridden?: OverridePathsDeclaration; + + constructor(ast: ast.OverrideSpecifier, offset: number) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.overrideKeyword = ast.overrideKeyword.text; + if (ast.overridden) { + this.overridden = new OverridePathsDeclaration( + ast.overridden, + offsets[0] + ); + } + + metadata = updateMetadata(metadata, [this.overridden]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + this.overrideKeyword, + this.overridden ? path.call(print, 'overridden') : '' + ]; + } +} diff --git a/src/slang-nodes/Parameter.js b/src/slang-nodes/Parameter.js deleted file mode 100644 index f321c7bb9..000000000 --- a/src/slang-nodes/Parameter.js +++ /dev/null @@ -1,41 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { TypeName } from './TypeName.js'; -import { StorageLocation } from './StorageLocation.js'; - -const { group } = doc.builders; - -export class Parameter extends SlangNode { - get kind() { - return NonterminalKind.Parameter; - } - - typeName; - - storageLocation; - - name; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - typeName: new TypeName(ast.typeName, offsets[0], options), - storageLocation: ast.storageLocation - ? new StorageLocation(ast.storageLocation, offsets[1], options) - : undefined, - name: ast.name?.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return group([ - path.call(print, 'typeName'), - this.storageLocation ? ` ${path.call(print, 'storageLocation')}` : '', - this.name ? ` ${this.name}` : '' - ]); - } -} diff --git a/src/slang-nodes/Parameter.ts b/src/slang-nodes/Parameter.ts new file mode 100644 index 000000000..ac2c88ced --- /dev/null +++ b/src/slang-nodes/Parameter.ts @@ -0,0 +1,52 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { TypeName } from './TypeName.js'; +import { StorageLocation } from './StorageLocation.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { group } = doc.builders; + +export class Parameter implements SlangNode { + readonly kind = NonterminalKind.Parameter; + + comments; + + loc; + + typeName: TypeName; + + storageLocation?: StorageLocation; + + name?: string; + + constructor(ast: ast.Parameter, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.typeName = new TypeName(ast.typeName, offsets[0], options); + if (ast.storageLocation) { + this.storageLocation = new StorageLocation( + ast.storageLocation, + offsets[1] + ); + } + this.name = ast.name?.text; + + metadata = updateMetadata(metadata, [this.typeName, this.storageLocation]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return group([ + path.call(print, 'typeName'), + this.storageLocation ? ` ${path.call(print, 'storageLocation')}` : '', + this.name ? ` ${this.name}` : '' + ]); + } +} diff --git a/src/slang-nodes/Parameters.js b/src/slang-nodes/Parameters.js deleted file mode 100644 index 82b454e25..000000000 --- a/src/slang-nodes/Parameters.js +++ /dev/null @@ -1,43 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { - printSeparatedItem, - printSeparatedList -} from '../common/printer-helpers.js'; -import { printComments } from '../slang-printers/print-comments.js'; -import { SlangNode } from './SlangNode.js'; -import { Parameter } from './Parameter.js'; - -export class Parameters extends SlangNode { - get kind() { - return NonterminalKind.Parameters; - } - - items; - - separators; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => new Parameter(item, offsets[index], options) - ), - separators: ast.separators.map((separator) => separator.text) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print, options) { - if (this.items.length > 0) { - return printSeparatedList(path.map(print, 'items'), { grouped: false }); - } - - const parameterComments = printComments(this, path, options); - - return parameterComments.length > 0 - ? printSeparatedItem(parameterComments) - : ''; - } -} diff --git a/src/slang-nodes/Parameters.ts b/src/slang-nodes/Parameters.ts new file mode 100644 index 000000000..0f3b6c424 --- /dev/null +++ b/src/slang-nodes/Parameters.ts @@ -0,0 +1,53 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printSeparatedList } from '../slang-printers/print-separated-list.js'; +import { printSeparatedItem } from '../slang-printers/print-separated-item.js'; +import { printComments } from '../slang-printers/print-comments.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Parameter } from './Parameter.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class Parameters implements SlangNode { + readonly kind = NonterminalKind.Parameters; + + comments; + + loc; + + items: Parameter[]; + + separators: string[]; + + constructor(ast: ast.Parameters, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => new Parameter(item, offsets[index], options) + ); + this.separators = ast.separators.map((separator) => separator.text); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print( + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc { + if (this.items.length > 0) { + return printSeparatedList(path.map(print, 'items'), { grouped: false }); + } + + const parameterComments = printComments(this, path); + + return parameterComments.length > 0 + ? printSeparatedItem(parameterComments) + : ''; + } +} diff --git a/src/slang-nodes/ParametersDeclaration.js b/src/slang-nodes/ParametersDeclaration.js deleted file mode 100644 index 9ae79a343..000000000 --- a/src/slang-nodes/ParametersDeclaration.js +++ /dev/null @@ -1,31 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { Parameters } from './Parameters.js'; - -export class ParametersDeclaration extends SlangNode { - get kind() { - return NonterminalKind.ParametersDeclaration; - } - - openParen; - - parameters; - - closeParen; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - openParen: ast.openParen.text, - parameters: new Parameters(ast.parameters, offsets[0], options), - closeParen: ast.closeParen.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [this.openParen, path.call(print, 'parameters'), this.closeParen]; - } -} diff --git a/src/slang-nodes/ParametersDeclaration.ts b/src/slang-nodes/ParametersDeclaration.ts new file mode 100644 index 000000000..3b165b7ea --- /dev/null +++ b/src/slang-nodes/ParametersDeclaration.ts @@ -0,0 +1,43 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Parameters } from './Parameters.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class ParametersDeclaration implements SlangNode { + readonly kind = NonterminalKind.ParametersDeclaration; + + comments; + + loc; + + openParen: string; + + parameters: Parameters; + + closeParen: string; + + constructor( + ast: ast.ParametersDeclaration, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.openParen = ast.openParen.text; + this.parameters = new Parameters(ast.parameters, offsets[0], options); + this.closeParen = ast.closeParen.text; + + metadata = updateMetadata(metadata, [this.parameters]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [this.openParen, path.call(print, 'parameters'), this.closeParen]; + } +} diff --git a/src/slang-nodes/PathImport.js b/src/slang-nodes/PathImport.js deleted file mode 100644 index 362292455..000000000 --- a/src/slang-nodes/PathImport.js +++ /dev/null @@ -1,34 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { StringLiteral } from './StringLiteral.js'; -import { ImportAlias } from './ImportAlias.js'; - -export class PathImport extends SlangNode { - get kind() { - return NonterminalKind.PathImport; - } - - path; - - alias; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - path: new StringLiteral(ast.path, offsets[0], options), - alias: ast.alias - ? new ImportAlias(ast.alias, offsets[1], options) - : undefined - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - path.call(print, 'path'), - this.alias ? path.call(print, 'alias') : '' - ]; - } -} diff --git a/src/slang-nodes/PathImport.ts b/src/slang-nodes/PathImport.ts new file mode 100644 index 000000000..99cb695ca --- /dev/null +++ b/src/slang-nodes/PathImport.ts @@ -0,0 +1,42 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { StringLiteral } from './StringLiteral.js'; +import { ImportAlias } from './ImportAlias.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class PathImport implements SlangNode { + readonly kind = NonterminalKind.PathImport; + + comments; + + loc; + + path: StringLiteral; + + alias?: ImportAlias; + + constructor(ast: ast.PathImport, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.path = new StringLiteral(ast.path, offsets[0], options); + if (ast.alias) { + this.alias = new ImportAlias(ast.alias, offsets[1]); + } + + metadata = updateMetadata(metadata, [this.path, this.alias]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + path.call(print, 'path'), + this.alias ? path.call(print, 'alias') : '' + ]; + } +} diff --git a/src/slang-nodes/PositionalArguments.js b/src/slang-nodes/PositionalArguments.js deleted file mode 100644 index 9c57f57e7..000000000 --- a/src/slang-nodes/PositionalArguments.js +++ /dev/null @@ -1,33 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printSeparatedList } from '../common/printer-helpers.js'; -import { SlangNode } from './SlangNode.js'; -import { Expression } from './Expression.js'; - -export class PositionalArguments extends SlangNode { - get kind() { - return NonterminalKind.PositionalArguments; - } - - items; - - separators; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => new Expression(item, offsets[index], options) - ), - separators: ast.separators.map((separator) => separator.text) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return this.items.length > 0 - ? printSeparatedList(path.map(print, 'items')) - : ''; - } -} diff --git a/src/slang-nodes/PositionalArguments.ts b/src/slang-nodes/PositionalArguments.ts new file mode 100644 index 000000000..bdee513bc --- /dev/null +++ b/src/slang-nodes/PositionalArguments.ts @@ -0,0 +1,45 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printSeparatedList } from '../slang-printers/print-separated-list.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Expression } from './Expression.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class PositionalArguments implements SlangNode { + readonly kind = NonterminalKind.PositionalArguments; + + comments; + + loc; + + items; + + separators; + + constructor( + ast: ast.PositionalArguments, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => new Expression(item, offsets[index], options) + ); + this.separators = ast.separators.map((separator) => separator.text); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return this.items.length > 0 + ? printSeparatedList(path.map(print, 'items')) + : ''; + } +} diff --git a/src/slang-nodes/PositionalArgumentsDeclaration.js b/src/slang-nodes/PositionalArgumentsDeclaration.js deleted file mode 100644 index cf06a0356..000000000 --- a/src/slang-nodes/PositionalArgumentsDeclaration.js +++ /dev/null @@ -1,31 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { PositionalArguments } from './PositionalArguments.js'; - -export class PositionalArgumentsDeclaration extends SlangNode { - get kind() { - return NonterminalKind.PositionalArgumentsDeclaration; - } - - openParen; - - arguments; - - closeParen; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - openParen: ast.openParen.text, - arguments: new PositionalArguments(ast.arguments, offsets[0], options), - closeParen: ast.closeParen.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [this.openParen, path.call(print, 'arguments'), this.closeParen]; - } -} diff --git a/src/slang-nodes/PositionalArgumentsDeclaration.ts b/src/slang-nodes/PositionalArgumentsDeclaration.ts new file mode 100644 index 000000000..91565e3ca --- /dev/null +++ b/src/slang-nodes/PositionalArgumentsDeclaration.ts @@ -0,0 +1,47 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { PositionalArguments } from './PositionalArguments.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class PositionalArgumentsDeclaration implements SlangNode { + readonly kind = NonterminalKind.PositionalArgumentsDeclaration; + + comments; + + loc; + + openParen: string; + + arguments: PositionalArguments; + + closeParen: string; + + constructor( + ast: ast.PositionalArgumentsDeclaration, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.openParen = ast.openParen.text; + this.arguments = new PositionalArguments( + ast.arguments, + offsets[0], + options + ); + this.closeParen = ast.closeParen.text; + + metadata = updateMetadata(metadata, [this.arguments]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [this.openParen, path.call(print, 'arguments'), this.closeParen]; + } +} diff --git a/src/slang-nodes/PostfixExpression.js b/src/slang-nodes/PostfixExpression.js deleted file mode 100644 index bf0592f8d..000000000 --- a/src/slang-nodes/PostfixExpression.js +++ /dev/null @@ -1,28 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { Expression } from './Expression.js'; - -export class PostfixExpression extends SlangNode { - get kind() { - return NonterminalKind.PostfixExpression; - } - - operand; - - operator; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - operand: new Expression(ast.operand, offsets[0], options), - operator: ast.operator.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [path.call(print, 'operand'), this.operator]; - } -} diff --git a/src/slang-nodes/PostfixExpression.ts b/src/slang-nodes/PostfixExpression.ts new file mode 100644 index 000000000..4d75aa8cf --- /dev/null +++ b/src/slang-nodes/PostfixExpression.ts @@ -0,0 +1,40 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Expression } from './Expression.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class PostfixExpression implements SlangNode { + readonly kind = NonterminalKind.PostfixExpression; + + comments; + + loc; + + operand: Expression; + + operator: string; + + constructor( + ast: ast.PostfixExpression, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.operand = new Expression(ast.operand, offsets[0], options); + this.operator = ast.operator.text; + + metadata = updateMetadata(metadata, [this.operand]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [path.call(print, 'operand'), this.operator]; + } +} diff --git a/src/slang-nodes/Pragma.js b/src/slang-nodes/Pragma.js deleted file mode 100644 index d8ef56cf7..000000000 --- a/src/slang-nodes/Pragma.js +++ /dev/null @@ -1,32 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { ABICoderPragma } from './ABICoderPragma.js'; -import { ExperimentalPragma } from './ExperimentalPragma.js'; -import { VersionPragma } from './VersionPragma.js'; - -const variants = { ABICoderPragma, ExperimentalPragma, VersionPragma }; -export class Pragma extends SlangNode { - get kind() { - return NonterminalKind.Pragma; - } - - variant; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - variant: new variants[ast.variant.cst.kind]( - ast.variant, - offsets[0], - options - ) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return path.call(print, 'variant'); - } -} diff --git a/src/slang-nodes/Pragma.ts b/src/slang-nodes/Pragma.ts new file mode 100644 index 000000000..91dd34c2e --- /dev/null +++ b/src/slang-nodes/Pragma.ts @@ -0,0 +1,58 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ABICoderPragma } from './ABICoderPragma.js'; +import { ExperimentalPragma } from './ExperimentalPragma.js'; +import { VersionPragma } from './VersionPragma.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class Pragma implements SlangNode { + readonly kind = NonterminalKind.Pragma; + + comments; + + loc; + + variant: ABICoderPragma | ExperimentalPragma | VersionPragma; + + constructor(ast: ast.Pragma, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + switch (ast.variant.cst.kind) { + case 'ABICoderPragma': + this.variant = new ABICoderPragma( + ast.variant as ast.ABICoderPragma, + offsets[0] + ); + break; + case 'ExperimentalPragma': + this.variant = new ExperimentalPragma( + ast.variant as ast.ExperimentalPragma, + offsets[0], + options + ); + break; + case 'VersionPragma': + this.variant = new VersionPragma( + ast.variant as ast.VersionPragma, + offsets[0], + options + ); + break; + default: + throw new Error(`Unexpected variant: ${ast.variant.cst.kind}`); + } + + metadata = updateMetadata(metadata, [this.variant]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/PragmaDirective.js b/src/slang-nodes/PragmaDirective.js deleted file mode 100644 index bd5526bac..000000000 --- a/src/slang-nodes/PragmaDirective.js +++ /dev/null @@ -1,35 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { Pragma } from './Pragma.js'; - -export class PragmaDirective extends SlangNode { - get kind() { - return NonterminalKind.PragmaDirective; - } - - pragmaKeyword; - - pragma; - - semicolon; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - pragmaKeyword: ast.pragmaKeyword.text, - pragma: new Pragma(ast.pragma, offsets[0], options), - semicolon: ast.semicolon.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - `${this.pragmaKeyword} `, - path.call(print, 'pragma'), - this.semicolon - ]; - } -} diff --git a/src/slang-nodes/PragmaDirective.ts b/src/slang-nodes/PragmaDirective.ts new file mode 100644 index 000000000..11030d009 --- /dev/null +++ b/src/slang-nodes/PragmaDirective.ts @@ -0,0 +1,47 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Pragma } from './Pragma.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class PragmaDirective implements SlangNode { + readonly kind = NonterminalKind.PragmaDirective; + + comments; + + loc; + + pragmaKeyword: string; + + pragma: Pragma; + + semicolon: string; + + constructor( + ast: ast.PragmaDirective, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.pragmaKeyword = ast.pragmaKeyword.text; + this.pragma = new Pragma(ast.pragma, offsets[0], options); + this.semicolon = ast.semicolon.text; + + metadata = updateMetadata(metadata, [this.pragma]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + `${this.pragmaKeyword} `, + path.call(print, 'pragma'), + this.semicolon + ]; + } +} diff --git a/src/slang-nodes/PrefixExpression.js b/src/slang-nodes/PrefixExpression.js deleted file mode 100644 index 945200c09..000000000 --- a/src/slang-nodes/PrefixExpression.js +++ /dev/null @@ -1,28 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { Expression } from './Expression.js'; - -export class PrefixExpression extends SlangNode { - get kind() { - return NonterminalKind.PrefixExpression; - } - - operator; - - operand; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - operator: ast.operator.text, - operand: new Expression(ast.operand, offsets[0], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [this.operator, path.call(print, 'operand')]; - } -} diff --git a/src/slang-nodes/PrefixExpression.ts b/src/slang-nodes/PrefixExpression.ts new file mode 100644 index 000000000..dabf4152d --- /dev/null +++ b/src/slang-nodes/PrefixExpression.ts @@ -0,0 +1,40 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Expression } from './Expression.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class PrefixExpression implements SlangNode { + readonly kind = NonterminalKind.PrefixExpression; + + comments; + + loc; + + operator: string; + + operand: Expression; + + constructor( + ast: ast.PrefixExpression, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.operator = ast.operator.text; + this.operand = new Expression(ast.operand, offsets[0], options); + + metadata = updateMetadata(metadata, [this.operand]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [this.operator, path.call(print, 'operand')]; + } +} diff --git a/src/slang-nodes/ReceiveFunctionAttribute.js b/src/slang-nodes/ReceiveFunctionAttribute.js deleted file mode 100644 index 0feed7c08..000000000 --- a/src/slang-nodes/ReceiveFunctionAttribute.js +++ /dev/null @@ -1,33 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { ModifierInvocation } from './ModifierInvocation.js'; -import { OverrideSpecifier } from './OverrideSpecifier.js'; - -const variants = { ModifierInvocation, OverrideSpecifier }; - -export class ReceiveFunctionAttribute extends SlangNode { - get kind() { - return NonterminalKind.ReceiveFunctionAttribute; - } - - variant; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - variant: - ast.variant.type === 'Terminal' - ? ast.variant.text - : new variants[ast.variant.cst.kind](ast.variant, offsets[0], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return typeof this.variant === 'string' - ? this.variant - : path.call(print, 'variant'); - } -} diff --git a/src/slang-nodes/ReceiveFunctionAttribute.ts b/src/slang-nodes/ReceiveFunctionAttribute.ts new file mode 100644 index 000000000..250739d3d --- /dev/null +++ b/src/slang-nodes/ReceiveFunctionAttribute.ts @@ -0,0 +1,64 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ModifierInvocation } from './ModifierInvocation.js'; +import { OverrideSpecifier } from './OverrideSpecifier.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class ReceiveFunctionAttribute implements SlangNode { + readonly kind = NonterminalKind.ReceiveFunctionAttribute; + + comments; + + loc; + + variant: ModifierInvocation | OverrideSpecifier | string; + + constructor( + ast: ast.ReceiveFunctionAttribute, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + if (ast.variant instanceof TerminalNode) { + this.variant = ast.variant.text; + } else { + switch (ast.variant.cst.kind) { + case 'ModifierInvocation': + this.variant = new ModifierInvocation( + ast.variant as ast.ModifierInvocation, + offsets[0], + options + ); + break; + case 'OverrideSpecifier': + this.variant = new OverrideSpecifier( + ast.variant as ast.OverrideSpecifier, + offsets[0] + ); + break; + default: + throw new Error(`Unexpected variant: ${ast.variant.cst.kind}`); + } + } + + metadata = updateMetadata( + metadata, + typeof this.variant === 'string' ? [] : [this.variant] + ); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/ReceiveFunctionAttributes.js b/src/slang-nodes/ReceiveFunctionAttributes.js deleted file mode 100644 index de0468889..000000000 --- a/src/slang-nodes/ReceiveFunctionAttributes.js +++ /dev/null @@ -1,32 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { postProcessFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; -import { SlangNode } from './SlangNode.js'; -import { ReceiveFunctionAttribute } from './ReceiveFunctionAttribute.js'; - -const { line } = doc.builders; - -export class ReceiveFunctionAttributes extends SlangNode { - get kind() { - return NonterminalKind.ReceiveFunctionAttributes; - } - - items; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => - new ReceiveFunctionAttribute(item, offsets[index], options) - ) - }); - - this.initialize(ast, offset, fetch, postProcessFunctionAttributes); - } - - print(path, print) { - return path.map(print, 'items').map((item) => [line, item]); - } -} diff --git a/src/slang-nodes/ReceiveFunctionAttributes.ts b/src/slang-nodes/ReceiveFunctionAttributes.ts new file mode 100644 index 000000000..512ac7544 --- /dev/null +++ b/src/slang-nodes/ReceiveFunctionAttributes.ts @@ -0,0 +1,46 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ReceiveFunctionAttribute } from './ReceiveFunctionAttribute.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { line } = doc.builders; + +export class ReceiveFunctionAttributes implements SlangNode { + readonly kind = NonterminalKind.ReceiveFunctionAttributes; + + comments; + + loc; + + items: ReceiveFunctionAttribute[]; + + constructor( + ast: ast.ReceiveFunctionAttributes, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => + new ReceiveFunctionAttribute(item, offsets[index], options) + ); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + + this.items = this.items.sort(sortFunctionAttributes); + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return path.map(print, 'items').map((item) => [line, item]); + } +} diff --git a/src/slang-nodes/ReceiveFunctionDefinition.js b/src/slang-nodes/ReceiveFunctionDefinition.js deleted file mode 100644 index 681b954cb..000000000 --- a/src/slang-nodes/ReceiveFunctionDefinition.js +++ /dev/null @@ -1,55 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printFunction } from '../slang-printers/print-function.js'; -import { SlangNode } from './SlangNode.js'; -import { ParametersDeclaration } from './ParametersDeclaration.js'; -import { ReceiveFunctionAttributes } from './ReceiveFunctionAttributes.js'; -import { FunctionBody } from './FunctionBody.js'; - -export class ReceiveFunctionDefinition extends SlangNode { - get kind() { - return NonterminalKind.ReceiveFunctionDefinition; - } - - receiveKeyword; - - parameters; - - attributes; - - body; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - receiveKeyword: ast.receiveKeyword.text, - parameters: new ParametersDeclaration( - ast.parameters, - offsets[0], - options - ), - attributes: new ReceiveFunctionAttributes( - ast.attributes, - offsets[1], - options - ), - body: new FunctionBody(ast.body, offsets[2], options) - }); - - this.initialize(ast, offset, fetch); - - this.cleanModifierInvocationArguments(); - } - - cleanModifierInvocationArguments() { - this.attributes.items.forEach((attribute) => { - if (attribute.variant.kind === 'ModifierInvocation') { - attribute.variant.cleanModifierInvocationArguments(); - } - }); - } - - print(path, print) { - return printFunction(this.receiveKeyword, this, path, print); - } -} diff --git a/src/slang-nodes/ReceiveFunctionDefinition.ts b/src/slang-nodes/ReceiveFunctionDefinition.ts new file mode 100644 index 000000000..5078fb2a6 --- /dev/null +++ b/src/slang-nodes/ReceiveFunctionDefinition.ts @@ -0,0 +1,74 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printFunction } from '../slang-printers/print-function.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ParametersDeclaration } from './ParametersDeclaration.js'; +import { ReceiveFunctionAttributes } from './ReceiveFunctionAttributes.js'; +import { FunctionBody } from './FunctionBody.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class ReceiveFunctionDefinition implements SlangNode { + readonly kind = NonterminalKind.ReceiveFunctionDefinition; + + comments; + + loc; + + receiveKeyword: string; + + parameters: ParametersDeclaration; + + attributes: ReceiveFunctionAttributes; + + body: FunctionBody; + + constructor( + ast: ast.ReceiveFunctionDefinition, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.receiveKeyword = ast.receiveKeyword.text; + this.parameters = new ParametersDeclaration( + ast.parameters, + offsets[0], + options + ); + this.attributes = new ReceiveFunctionAttributes( + ast.attributes, + offsets[1], + options + ); + this.body = new FunctionBody(ast.body, offsets[2], options); + + metadata = updateMetadata(metadata, [ + this.parameters, + this.attributes, + this.body + ]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + + this.cleanModifierInvocationArguments(); + } + + cleanModifierInvocationArguments(): void { + this.attributes.items.forEach((attribute) => { + if ( + typeof attribute.variant !== 'string' && + attribute.variant.kind === 'ModifierInvocation' + ) { + attribute.variant.cleanModifierInvocationArguments(); + } + }); + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return printFunction(this.receiveKeyword, this, path, print); + } +} diff --git a/src/slang-nodes/ReturnStatement.js b/src/slang-nodes/ReturnStatement.js deleted file mode 100644 index 6bb07383d..000000000 --- a/src/slang-nodes/ReturnStatement.js +++ /dev/null @@ -1,52 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { Expression } from './Expression.js'; - -const { group, indent, line } = doc.builders; - -function printExpression(node, path, print, options) { - if (node.expression) { - return node.expression.variant.kind === 'TupleExpression' || - (options.experimentalTernaries && - node.expression.variant.kind === 'ConditionalExpression') - ? [' ', path.call(print, 'expression')] - : group(indent([line, path.call(print, 'expression')])); - } - return ''; -} - -export class ReturnStatement extends SlangNode { - get kind() { - return NonterminalKind.ReturnStatement; - } - - returnKeyword; - - expression; - - semicolon; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - returnKeyword: ast.returnKeyword.text, - expression: ast.expression - ? new Expression(ast.expression, offsets[0], options) - : undefined, - - semicolon: ast.semicolon.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print, options) { - return [ - this.returnKeyword, - printExpression(this, path, print, options), - this.semicolon - ]; - } -} diff --git a/src/slang-nodes/ReturnStatement.ts b/src/slang-nodes/ReturnStatement.ts new file mode 100644 index 000000000..ef2056b7b --- /dev/null +++ b/src/slang-nodes/ReturnStatement.ts @@ -0,0 +1,73 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Expression } from './Expression.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { group, indent, line } = doc.builders; + +function printExpression( + node: ReturnStatement, + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions +): Doc { + if (node.expression) { + return typeof node.expression.variant !== 'string' && + (node.expression.variant.kind === 'TupleExpression' || + (options.experimentalTernaries && + node.expression.variant.kind === 'ConditionalExpression')) + ? [' ', path.call(print, 'expression')] + : group(indent([line, path.call(print, 'expression')])); + } + return ''; +} + +export class ReturnStatement implements SlangNode { + readonly kind = NonterminalKind.ReturnStatement; + + comments; + + loc; + + returnKeyword: string; + + expression?: Expression; + + semicolon: string; + + constructor( + ast: ast.ReturnStatement, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.returnKeyword = ast.returnKeyword.text; + if (ast.expression) { + this.expression = new Expression(ast.expression, offsets[0], options); + } + this.semicolon = ast.semicolon.text; + + metadata = updateMetadata(metadata, [this.expression]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print( + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc { + return [ + this.returnKeyword, + printExpression(this, path, print, options), + this.semicolon + ]; + } +} diff --git a/src/slang-nodes/ReturnsDeclaration.js b/src/slang-nodes/ReturnsDeclaration.js deleted file mode 100644 index 5045dc3d9..000000000 --- a/src/slang-nodes/ReturnsDeclaration.js +++ /dev/null @@ -1,31 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { ParametersDeclaration } from './ParametersDeclaration.js'; - -const { group } = doc.builders; - -export class ReturnsDeclaration extends SlangNode { - get kind() { - return NonterminalKind.ReturnsDeclaration; - } - - returnsKeyword; - - variables; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - returnsKeyword: ast.returnsKeyword.text, - variables: new ParametersDeclaration(ast.variables, offsets[0], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [`${this.returnsKeyword} `, group(path.call(print, 'variables'))]; - } -} diff --git a/src/slang-nodes/ReturnsDeclaration.ts b/src/slang-nodes/ReturnsDeclaration.ts new file mode 100644 index 000000000..eaf0c5016 --- /dev/null +++ b/src/slang-nodes/ReturnsDeclaration.ts @@ -0,0 +1,47 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ParametersDeclaration } from './ParametersDeclaration.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { group } = doc.builders; + +export class ReturnsDeclaration implements SlangNode { + readonly kind = NonterminalKind.ReturnsDeclaration; + + comments; + + loc; + + returnsKeyword: string; + + variables: ParametersDeclaration; + + constructor( + ast: ast.ReturnsDeclaration, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.returnsKeyword = ast.returnsKeyword.text; + this.variables = new ParametersDeclaration( + ast.variables, + offsets[0], + options + ); + + metadata = updateMetadata(metadata, [this.variables]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [`${this.returnsKeyword} `, group(path.call(print, 'variables'))]; + } +} diff --git a/src/slang-nodes/RevertStatement.js b/src/slang-nodes/RevertStatement.js deleted file mode 100644 index cf90567ce..000000000 --- a/src/slang-nodes/RevertStatement.js +++ /dev/null @@ -1,50 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { IdentifierPath } from './IdentifierPath.js'; -import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; - -export class RevertStatement extends SlangNode { - get kind() { - return NonterminalKind.RevertStatement; - } - - revertKeyword; - - error; - - arguments; - - semicolon; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => { - let i = -1; - const children = { - revertKeyword: ast.revertKeyword.text, - error: ast.error - ? new IdentifierPath(ast.error, offsets[(i += 1)], options) - : undefined, - arguments: new ArgumentsDeclaration( - ast.arguments, - offsets[(i += 1)], - options - ), - semicolon: ast.semicolon.text - }; - return children; - }; - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - `${this.revertKeyword} `, - this.error ? path.call(print, 'error') : '', - path.call(print, 'arguments'), - this.semicolon - ]; - } -} diff --git a/src/slang-nodes/RevertStatement.ts b/src/slang-nodes/RevertStatement.ts new file mode 100644 index 000000000..453b1151e --- /dev/null +++ b/src/slang-nodes/RevertStatement.ts @@ -0,0 +1,60 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { IdentifierPath } from './IdentifierPath.js'; +import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class RevertStatement implements SlangNode { + readonly kind = NonterminalKind.RevertStatement; + + comments; + + loc; + + revertKeyword: string; + + error?: IdentifierPath; + + arguments: ArgumentsDeclaration; + + semicolon: string; + + constructor( + ast: ast.RevertStatement, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.revertKeyword = ast.revertKeyword.text; + let i = 0; + if (ast.error) { + this.error = new IdentifierPath(ast.error, offsets[i]); + i += 1; + } + this.arguments = new ArgumentsDeclaration( + ast.arguments, + offsets[i], + options + ); + this.semicolon = ast.semicolon.text; + + metadata = updateMetadata(metadata, [this.error, this.arguments]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + `${this.revertKeyword} `, + this.error ? path.call(print, 'error') : '', + path.call(print, 'arguments'), + this.semicolon + ]; + } +} diff --git a/src/slang-nodes/ShiftExpression.js b/src/slang-nodes/ShiftExpression.js deleted file mode 100644 index 7bbc626de..000000000 --- a/src/slang-nodes/ShiftExpression.js +++ /dev/null @@ -1,50 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; -import { createHugFunction } from '../slang-utils/create-hug-function.js'; -import { SlangNode } from './SlangNode.js'; -import { Expression } from './Expression.js'; - -const tryToHugLeftOperand = createHugFunction([ - '+', - '-', - '*', - '/', - '**', - '<<', - '>>' -]); -const tryToHugRightOperand = createHugFunction(['+', '-', '*', '/', '**']); - -const postProcess = (properties) => ({ - ...properties, - leftOperand: tryToHugLeftOperand(properties.leftOperand), - rightOperand: tryToHugRightOperand(properties.rightOperand) -}); - -export class ShiftExpression extends SlangNode { - get kind() { - return NonterminalKind.ShiftExpression; - } - - leftOperand; - - operator; - - rightOperand; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - leftOperand: new Expression(ast.leftOperand, offsets[0], options), - operator: ast.operator.text, - rightOperand: new Expression(ast.rightOperand, offsets[1], options) - }); - - this.initialize(ast, offset, fetch, postProcess); - } - - print(path, print, options) { - return printBinaryOperation({ node: this, path, print, options }); - } -} diff --git a/src/slang-nodes/ShiftExpression.ts b/src/slang-nodes/ShiftExpression.ts new file mode 100644 index 000000000..4c5ba7b59 --- /dev/null +++ b/src/slang-nodes/ShiftExpression.ts @@ -0,0 +1,63 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; +import { createHugFunction } from '../slang-utils/create-hug-function.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Expression } from './Expression.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const tryToHugLeftOperand = createHugFunction([ + '+', + '-', + '*', + '/', + '**', + '<<', + '>>' +]); +const tryToHugRightOperand = createHugFunction(['+', '-', '*', '/', '**']); + +export class ShiftExpression implements SlangNode { + readonly kind = NonterminalKind.ShiftExpression; + + comments; + + loc; + + leftOperand: Expression; + + operator: string; + + rightOperand: Expression; + + constructor( + ast: ast.ShiftExpression, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.leftOperand = new Expression(ast.leftOperand, offsets[0], options); + this.operator = ast.operator.text; + this.rightOperand = new Expression(ast.rightOperand, offsets[1], options); + + metadata = updateMetadata(metadata, [this.leftOperand, this.rightOperand]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + + this.leftOperand = tryToHugLeftOperand(this.leftOperand); + this.rightOperand = tryToHugRightOperand(this.rightOperand); + } + + print( + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc { + return printBinaryOperation(this, path, print, options); + } +} diff --git a/src/slang-nodes/SlangNode.js b/src/slang-nodes/SlangNode.js deleted file mode 100644 index 707c07219..000000000 --- a/src/slang-nodes/SlangNode.js +++ /dev/null @@ -1,93 +0,0 @@ -import { - getChildrenOffsets, - getLeadingOffset -} from '../slang-utils/get-offsets.js'; - -const isNotStringOrUndefined = (node) => - typeof node !== 'string' && typeof node !== 'undefined'; - -export class SlangNode { - loc; - - comments = []; - - initialize(ast, offset, fetch, postProcess) { - let properties; - - if (this.kind !== ast.cst.kind) - throw new Error( - `${this.kind} can only be initialized with an AST node of the same kind.` - ); - // Collect comments and get children offsets. - const cstChildren = ast.cst.children(); - const childrenOffsets = getChildrenOffsets( - cstChildren, - offset, - this.comments - ); - - // populate all children nodes - if (properties === undefined) { - properties = fetch(childrenOffsets); - } - - const propertyKeys = Object.keys(properties); - const propertyValues = Object.values(properties); - - // Collect comments - const childrenNodes = propertyValues.reduce((slangNodes, property) => { - if (Array.isArray(property)) { - slangNodes.push(...property.filter(isNotStringOrUndefined)); - } else if (isNotStringOrUndefined(property)) { - slangNodes.push(property); - } - return slangNodes; - }, []); - - childrenNodes.forEach((child) => { - this.comments.push(...child.comments.splice(0)); - }); - - // calculate correct loc object - const leadingOffset = getLeadingOffset(cstChildren); - const trailingOffset = getLeadingOffset(cstChildren.reverse()); - this.loc = { - start: offset + leadingOffset, - end: offset + ast.cst.textLength.utf8 - trailingOffset, - leadingOffset, - trailingOffset - }; - - if (leadingOffset === 0 || trailingOffset === 0) { - for (let i = 0; i < propertyKeys.length; i += 1) { - const childLoc = properties[propertyKeys[i]]?.loc; - - if (childLoc) { - if ( - leadingOffset === 0 && - childLoc.start - childLoc.leadingOffset === this.loc.start - ) { - this.loc.leadingOffset = childLoc.leadingOffset; - this.loc.start += childLoc.leadingOffset; - } - - if ( - trailingOffset === 0 && - childLoc.end + childLoc.trailingOffset === this.loc.end - ) { - this.loc.trailingOffset = childLoc.trailingOffset; - this.loc.end -= childLoc.trailingOffset; - } - } - } - } - - if (typeof postProcess === 'function') { - properties = postProcess(properties); - } - - propertyKeys.forEach((propertyKey) => { - this[propertyKey] = properties[propertyKey]; - }); - } -} diff --git a/src/slang-nodes/SourceUnit.js b/src/slang-nodes/SourceUnit.js deleted file mode 100644 index 124e54492..000000000 --- a/src/slang-nodes/SourceUnit.js +++ /dev/null @@ -1,26 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { SourceUnitMembers } from './SourceUnitMembers.js'; - -const { line } = doc.builders; - -export class SourceUnit extends SlangNode { - get kind() { - return NonterminalKind.SourceUnit; - } - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - members: new SourceUnitMembers(ast.members, offsets[0], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print, options) { - return [path.call(print, 'members'), options.parentParser ? '' : line]; - } -} diff --git a/src/slang-nodes/SourceUnit.ts b/src/slang-nodes/SourceUnit.ts new file mode 100644 index 000000000..772db108a --- /dev/null +++ b/src/slang-nodes/SourceUnit.ts @@ -0,0 +1,40 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { SourceUnitMembers } from './SourceUnitMembers.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { line } = doc.builders; + +export class SourceUnit implements SlangNode { + readonly kind = NonterminalKind.SourceUnit; + + comments; + + loc; + + members: SourceUnitMembers; + + constructor(ast: ast.SourceUnit, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.members = new SourceUnitMembers(ast.members, offsets[0], options); + + metadata = updateMetadata(metadata, [this.members]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print( + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc { + return [path.call(print, 'members'), options.parentParser ? '' : line]; + } +} diff --git a/src/slang-nodes/SourceUnitMember.js b/src/slang-nodes/SourceUnitMember.js deleted file mode 100644 index 34334ff67..000000000 --- a/src/slang-nodes/SourceUnitMember.js +++ /dev/null @@ -1,56 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { PragmaDirective } from './PragmaDirective.js'; -import { ImportDirective } from './ImportDirective.js'; -import { ContractDefinition } from './ContractDefinition.js'; -import { InterfaceDefinition } from './InterfaceDefinition.js'; -import { LibraryDefinition } from './LibraryDefinition.js'; -import { StructDefinition } from './StructDefinition.js'; -import { EnumDefinition } from './EnumDefinition.js'; -import { FunctionDefinition } from './FunctionDefinition.js'; -import { ConstantDefinition } from './ConstantDefinition.js'; -import { ErrorDefinition } from './ErrorDefinition.js'; -import { UserDefinedValueTypeDefinition } from './UserDefinedValueTypeDefinition.js'; -import { UsingDirective } from './UsingDirective.js'; -import { EventDefinition } from './EventDefinition.js'; - -const variants = { - PragmaDirective, - ImportDirective, - ContractDefinition, - InterfaceDefinition, - LibraryDefinition, - StructDefinition, - EnumDefinition, - FunctionDefinition, - ConstantDefinition, - ErrorDefinition, - UserDefinedValueTypeDefinition, - UsingDirective, - EventDefinition -}; -export class SourceUnitMember extends SlangNode { - get kind() { - return NonterminalKind.SourceUnitMember; - } - - variant; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - variant: new variants[ast.variant.cst.kind]( - ast.variant, - offsets[0], - options - ) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return path.call(print, 'variant'); - } -} diff --git a/src/slang-nodes/SourceUnitMember.ts b/src/slang-nodes/SourceUnitMember.ts new file mode 100644 index 000000000..bd38b619c --- /dev/null +++ b/src/slang-nodes/SourceUnitMember.ts @@ -0,0 +1,154 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { PragmaDirective } from './PragmaDirective.js'; +import { ImportDirective } from './ImportDirective.js'; +import { ContractDefinition } from './ContractDefinition.js'; +import { InterfaceDefinition } from './InterfaceDefinition.js'; +import { LibraryDefinition } from './LibraryDefinition.js'; +import { StructDefinition } from './StructDefinition.js'; +import { EnumDefinition } from './EnumDefinition.js'; +import { FunctionDefinition } from './FunctionDefinition.js'; +import { ConstantDefinition } from './ConstantDefinition.js'; +import { ErrorDefinition } from './ErrorDefinition.js'; +import { UserDefinedValueTypeDefinition } from './UserDefinedValueTypeDefinition.js'; +import { UsingDirective } from './UsingDirective.js'; +import { EventDefinition } from './EventDefinition.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class SourceUnitMember implements SlangNode { + readonly kind = NonterminalKind.SourceUnitMember; + + comments; + + loc; + + variant: + | PragmaDirective + | ImportDirective + | ContractDefinition + | InterfaceDefinition + | LibraryDefinition + | StructDefinition + | EnumDefinition + | FunctionDefinition + | ConstantDefinition + | ErrorDefinition + | UserDefinedValueTypeDefinition + | UsingDirective + | EventDefinition; + + constructor( + ast: ast.SourceUnitMember, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + switch (ast.variant.cst.kind) { + case 'PragmaDirective': + this.variant = new PragmaDirective( + ast.variant as ast.PragmaDirective, + offsets[0], + options + ); + break; + case 'ImportDirective': + this.variant = new ImportDirective( + ast.variant as ast.ImportDirective, + offsets[0], + options + ); + break; + case 'ContractDefinition': + this.variant = new ContractDefinition( + ast.variant as ast.ContractDefinition, + offsets[0], + options + ); + break; + case 'InterfaceDefinition': + this.variant = new InterfaceDefinition( + ast.variant as ast.InterfaceDefinition, + offsets[0], + options + ); + break; + case 'LibraryDefinition': + this.variant = new LibraryDefinition( + ast.variant as ast.LibraryDefinition, + offsets[0], + options + ); + break; + case 'StructDefinition': + this.variant = new StructDefinition( + ast.variant as ast.StructDefinition, + offsets[0], + options + ); + break; + case 'EnumDefinition': + this.variant = new EnumDefinition( + ast.variant as ast.EnumDefinition, + offsets[0] + ); + break; + case 'FunctionDefinition': + this.variant = new FunctionDefinition( + ast.variant as ast.FunctionDefinition, + offsets[0], + options + ); + break; + case 'ConstantDefinition': + this.variant = new ConstantDefinition( + ast.variant as ast.ConstantDefinition, + offsets[0], + options + ); + break; + case 'ErrorDefinition': + this.variant = new ErrorDefinition( + ast.variant as ast.ErrorDefinition, + offsets[0], + options + ); + break; + case 'UserDefinedValueTypeDefinition': + this.variant = new UserDefinedValueTypeDefinition( + ast.variant as ast.UserDefinedValueTypeDefinition, + offsets[0] + ); + break; + case 'UsingDirective': + this.variant = new UsingDirective( + ast.variant as ast.UsingDirective, + offsets[0], + options + ); + break; + case 'EventDefinition': + this.variant = new EventDefinition( + ast.variant as ast.EventDefinition, + offsets[0], + options + ); + break; + default: + throw new Error(`Unexpected variant: ${ast.variant.cst.kind}`); + } + + metadata = updateMetadata(metadata, [this.variant]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/SourceUnitMembers.js b/src/slang-nodes/SourceUnitMembers.js deleted file mode 100644 index 467062732..000000000 --- a/src/slang-nodes/SourceUnitMembers.js +++ /dev/null @@ -1,28 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; -import { SlangNode } from './SlangNode.js'; -import { SourceUnitMember } from './SourceUnitMember.js'; - -export class SourceUnitMembers extends SlangNode { - get kind() { - return NonterminalKind.SourceUnitMembers; - } - - items; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => new SourceUnitMember(item, offsets[index], options) - ) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print, options) { - return printPreservingEmptyLines(path, 'items', options, print); - } -} diff --git a/src/slang-nodes/SourceUnitMembers.ts b/src/slang-nodes/SourceUnitMembers.ts new file mode 100644 index 000000000..68c6b78cd --- /dev/null +++ b/src/slang-nodes/SourceUnitMembers.ts @@ -0,0 +1,44 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { SourceUnitMember } from './SourceUnitMember.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class SourceUnitMembers implements SlangNode { + readonly kind = NonterminalKind.SourceUnitMembers; + + comments; + + loc; + + items: SourceUnitMember[]; + + constructor( + ast: ast.SourceUnitMembers, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => new SourceUnitMember(item, offsets[index], options) + ); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print( + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc { + return printPreservingEmptyLines(path, 'items', print, options); + } +} diff --git a/src/slang-nodes/StateVariableAttribute.js b/src/slang-nodes/StateVariableAttribute.js deleted file mode 100644 index 7d5101a8b..000000000 --- a/src/slang-nodes/StateVariableAttribute.js +++ /dev/null @@ -1,30 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { OverrideSpecifier } from './OverrideSpecifier.js'; - -export class StateVariableAttribute extends SlangNode { - get kind() { - return NonterminalKind.StateVariableAttribute; - } - - variant; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - variant: - ast.variant.type === 'Terminal' - ? ast.variant.text - : new OverrideSpecifier(ast.variant, offsets[0], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return typeof this.variant === 'string' - ? this.variant - : path.call(print, 'variant'); - } -} diff --git a/src/slang-nodes/StateVariableAttribute.ts b/src/slang-nodes/StateVariableAttribute.ts new file mode 100644 index 000000000..e0d453e33 --- /dev/null +++ b/src/slang-nodes/StateVariableAttribute.ts @@ -0,0 +1,42 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { OverrideSpecifier } from './OverrideSpecifier.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class StateVariableAttribute implements SlangNode { + readonly kind = NonterminalKind.StateVariableAttribute; + + comments; + + loc; + + variant: OverrideSpecifier | string; + + constructor(ast: ast.StateVariableAttribute, offset: number) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.variant = + ast.variant instanceof TerminalNode + ? ast.variant.text + : new OverrideSpecifier(ast.variant, offsets[0]); + + metadata = updateMetadata( + metadata, + typeof this.variant === 'string' ? [] : [this.variant] + ); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/StateVariableAttributes.js b/src/slang-nodes/StateVariableAttributes.js deleted file mode 100644 index c06da927d..000000000 --- a/src/slang-nodes/StateVariableAttributes.js +++ /dev/null @@ -1,30 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { StateVariableAttribute } from './StateVariableAttribute.js'; - -export class StateVariableAttributes extends SlangNode { - get kind() { - return NonterminalKind.StateVariableAttributes; - } - - items; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => - new StateVariableAttribute(item, offsets[index], options) - ) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return this.items.length - ? path.map(print, 'items').map((item) => [' ', item]) - : ''; - } -} diff --git a/src/slang-nodes/StateVariableAttributes.ts b/src/slang-nodes/StateVariableAttributes.ts new file mode 100644 index 000000000..6a3029fe1 --- /dev/null +++ b/src/slang-nodes/StateVariableAttributes.ts @@ -0,0 +1,37 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { StateVariableAttribute } from './StateVariableAttribute.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class StateVariableAttributes implements SlangNode { + readonly kind = NonterminalKind.StateVariableAttributes; + + comments; + + loc; + + items: StateVariableAttribute[]; + + constructor(ast: ast.StateVariableAttributes, offset: number) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => new StateVariableAttribute(item, offsets[index]) + ); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return this.items.length + ? path.map(print, 'items').map((item) => [' ', item]) + : ''; + } +} diff --git a/src/slang-nodes/StateVariableDefinition.js b/src/slang-nodes/StateVariableDefinition.js deleted file mode 100644 index 65a262a1a..000000000 --- a/src/slang-nodes/StateVariableDefinition.js +++ /dev/null @@ -1,51 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { TypeName } from './TypeName.js'; -import { StateVariableAttributes } from './StateVariableAttributes.js'; -import { StateVariableDefinitionValue } from './StateVariableDefinitionValue.js'; - -export class StateVariableDefinition extends SlangNode { - get kind() { - return NonterminalKind.StateVariableDefinition; - } - - typeName; - - attributes; - - name; - - value; - - semicolon; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - typeName: new TypeName(ast.typeName, offsets[0], options), - attributes: new StateVariableAttributes( - ast.attributes, - offsets[1], - options - ), - name: ast.name.text, - value: ast.value - ? new StateVariableDefinitionValue(ast.value, offsets[2], options) - : undefined, - semicolon: ast.semicolon.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - path.call(print, 'typeName'), - path.call(print, 'attributes'), - ` ${this.name}`, - this.value ? path.call(print, 'value') : '', - this.semicolon - ]; - } -} diff --git a/src/slang-nodes/StateVariableDefinition.ts b/src/slang-nodes/StateVariableDefinition.ts new file mode 100644 index 000000000..d2f661813 --- /dev/null +++ b/src/slang-nodes/StateVariableDefinition.ts @@ -0,0 +1,63 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { TypeName } from './TypeName.js'; +import { StateVariableAttributes } from './StateVariableAttributes.js'; +import { StateVariableDefinitionValue } from './StateVariableDefinitionValue.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class StateVariableDefinition implements SlangNode { + readonly kind = NonterminalKind.StateVariableDefinition; + + comments; + + loc; + + typeName: TypeName; + + attributes: StateVariableAttributes; + + name: string; + + value?: StateVariableDefinitionValue; + + semicolon: string; + + constructor( + ast: ast.StateVariableDefinition, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.typeName = new TypeName(ast.typeName, offsets[0], options); + this.attributes = new StateVariableAttributes(ast.attributes, offsets[1]); + this.name = ast.name.text; + this.value = ast.value + ? new StateVariableDefinitionValue(ast.value, offsets[2], options) + : undefined; + this.semicolon = ast.semicolon.text; + + metadata = updateMetadata(metadata, [ + this.typeName, + this.attributes, + this.value + ]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + path.call(print, 'typeName'), + path.call(print, 'attributes'), + ` ${this.name}`, + this.value ? path.call(print, 'value') : '', + this.semicolon + ]; + } +} diff --git a/src/slang-nodes/StateVariableDefinitionValue.js b/src/slang-nodes/StateVariableDefinitionValue.js deleted file mode 100644 index 5a1358fa7..000000000 --- a/src/slang-nodes/StateVariableDefinitionValue.js +++ /dev/null @@ -1,33 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { Expression } from './Expression.js'; - -const { group, indent, line } = doc.builders; - -export class StateVariableDefinitionValue extends SlangNode { - get kind() { - return NonterminalKind.StateVariableDefinitionValue; - } - - equal; - - value; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - equal: ast.equal.text, - value: new Expression(ast.value, offsets[0], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return this.value.variant.kind === 'ArrayExpression' - ? [` ${this.equal} `, path.call(print, 'value')] - : group([` ${this.equal}`, indent([line, path.call(print, 'value')])]); - } -} diff --git a/src/slang-nodes/StateVariableDefinitionValue.ts b/src/slang-nodes/StateVariableDefinitionValue.ts new file mode 100644 index 000000000..0507ec8ff --- /dev/null +++ b/src/slang-nodes/StateVariableDefinitionValue.ts @@ -0,0 +1,46 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Expression } from './Expression.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { group, indent, line } = doc.builders; + +export class StateVariableDefinitionValue implements SlangNode { + readonly kind = NonterminalKind.StateVariableDefinitionValue; + + comments; + + loc; + + equal: string; + + value: Expression; + + constructor( + ast: ast.StateVariableDefinitionValue, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.equal = ast.equal.text; + this.value = new Expression(ast.value, offsets[0], options); + + metadata = updateMetadata(metadata, [this.value]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return typeof this.value.variant !== 'string' && + this.value.variant.kind === 'ArrayExpression' + ? [` ${this.equal} `, path.call(print, 'value')] + : group([` ${this.equal}`, indent([line, path.call(print, 'value')])]); + } +} diff --git a/src/slang-nodes/Statement.js b/src/slang-nodes/Statement.js deleted file mode 100644 index 8172209d3..000000000 --- a/src/slang-nodes/Statement.js +++ /dev/null @@ -1,65 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { ExpressionStatement } from './ExpressionStatement.js'; -import { VariableDeclarationStatement } from './VariableDeclarationStatement.js'; -import { TupleDeconstructionStatement } from './TupleDeconstructionStatement.js'; -import { IfStatement } from './IfStatement.js'; -import { ForStatement } from './ForStatement.js'; -import { WhileStatement } from './WhileStatement.js'; -import { DoWhileStatement } from './DoWhileStatement.js'; -import { ContinueStatement } from './ContinueStatement.js'; -import { BreakStatement } from './BreakStatement.js'; -import { ReturnStatement } from './ReturnStatement.js'; -import { ThrowStatement } from './ThrowStatement.js'; -import { EmitStatement } from './EmitStatement.js'; -import { TryStatement } from './TryStatement.js'; -import { RevertStatement } from './RevertStatement.js'; -import { AssemblyStatement } from './AssemblyStatement.js'; -import { Block } from './Block.js'; -import { UncheckedBlock } from './UncheckedBlock.js'; - -const variants = { - ExpressionStatement, - VariableDeclarationStatement, - TupleDeconstructionStatement, - IfStatement, - ForStatement, - WhileStatement, - DoWhileStatement, - ContinueStatement, - BreakStatement, - ReturnStatement, - ThrowStatement, - EmitStatement, - TryStatement, - RevertStatement, - AssemblyStatement, - Block, - UncheckedBlock -}; - -export class Statement extends SlangNode { - get kind() { - return NonterminalKind.Statement; - } - - variant; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - variant: new variants[ast.variant.cst.kind]( - ast.variant, - offsets[0], - options - ) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return path.call(print, 'variant'); - } -} diff --git a/src/slang-nodes/Statement.ts b/src/slang-nodes/Statement.ts new file mode 100644 index 000000000..13d92372f --- /dev/null +++ b/src/slang-nodes/Statement.ts @@ -0,0 +1,181 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ExpressionStatement } from './ExpressionStatement.js'; +import { VariableDeclarationStatement } from './VariableDeclarationStatement.js'; +import { TupleDeconstructionStatement } from './TupleDeconstructionStatement.js'; +import { IfStatement } from './IfStatement.js'; +import { ForStatement } from './ForStatement.js'; +import { WhileStatement } from './WhileStatement.js'; +import { DoWhileStatement } from './DoWhileStatement.js'; +import { ContinueStatement } from './ContinueStatement.js'; +import { BreakStatement } from './BreakStatement.js'; +import { ReturnStatement } from './ReturnStatement.js'; +import { ThrowStatement } from './ThrowStatement.js'; +import { EmitStatement } from './EmitStatement.js'; +import { TryStatement } from './TryStatement.js'; +import { RevertStatement } from './RevertStatement.js'; +import { AssemblyStatement } from './AssemblyStatement.js'; +import { Block } from './Block.js'; +import { UncheckedBlock } from './UncheckedBlock.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class Statement implements SlangNode { + readonly kind = NonterminalKind.Statement; + + comments; + + loc; + + variant: + | ExpressionStatement + | VariableDeclarationStatement + | TupleDeconstructionStatement + | IfStatement + | ForStatement + | WhileStatement + | DoWhileStatement + | ContinueStatement + | BreakStatement + | ReturnStatement + | ThrowStatement + | EmitStatement + | TryStatement + | RevertStatement + | AssemblyStatement + | Block + | UncheckedBlock; + + constructor(ast: ast.Statement, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + switch (ast.variant.cst.kind) { + case 'ExpressionStatement': + this.variant = new ExpressionStatement( + ast.variant as ast.ExpressionStatement, + offsets[0], + options + ); + break; + case 'VariableDeclarationStatement': + this.variant = new VariableDeclarationStatement( + ast.variant as ast.VariableDeclarationStatement, + offsets[0], + options + ); + break; + case 'TupleDeconstructionStatement': + this.variant = new TupleDeconstructionStatement( + ast.variant as ast.TupleDeconstructionStatement, + offsets[0], + options + ); + break; + case 'IfStatement': + this.variant = new IfStatement( + ast.variant as ast.IfStatement, + offsets[0], + options + ); + break; + case 'ForStatement': + this.variant = new ForStatement( + ast.variant as ast.ForStatement, + offsets[0], + options + ); + break; + case 'WhileStatement': + this.variant = new WhileStatement( + ast.variant as ast.WhileStatement, + offsets[0], + options + ); + break; + case 'DoWhileStatement': + this.variant = new DoWhileStatement( + ast.variant as ast.DoWhileStatement, + offsets[0], + options + ); + break; + case 'ContinueStatement': + this.variant = new ContinueStatement( + ast.variant as ast.ContinueStatement, + offsets[0] + ); + break; + case 'BreakStatement': + this.variant = new BreakStatement( + ast.variant as ast.BreakStatement, + offsets[0] + ); + break; + case 'ReturnStatement': + this.variant = new ReturnStatement( + ast.variant as ast.ReturnStatement, + offsets[0], + options + ); + break; + case 'ThrowStatement': + this.variant = new ThrowStatement( + ast.variant as ast.ThrowStatement, + offsets[0] + ); + break; + case 'EmitStatement': + this.variant = new EmitStatement( + ast.variant as ast.EmitStatement, + offsets[0], + options + ); + break; + case 'TryStatement': + this.variant = new TryStatement( + ast.variant as ast.TryStatement, + offsets[0], + options + ); + break; + case 'RevertStatement': + this.variant = new RevertStatement( + ast.variant as ast.RevertStatement, + offsets[0], + options + ); + break; + case 'AssemblyStatement': + this.variant = new AssemblyStatement( + ast.variant as ast.AssemblyStatement, + offsets[0], + options + ); + break; + case 'Block': + this.variant = new Block(ast.variant as ast.Block, offsets[0], options); + break; + case 'UncheckedBlock': + this.variant = new UncheckedBlock( + ast.variant as ast.UncheckedBlock, + offsets[0], + options + ); + break; + default: + throw new Error(`Unexpected variant: ${ast.variant.cst.kind}`); + } + + metadata = updateMetadata(metadata, [this.variant]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/Statements.js b/src/slang-nodes/Statements.js deleted file mode 100644 index da5f1f14c..000000000 --- a/src/slang-nodes/Statements.js +++ /dev/null @@ -1,45 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printSeparatedItem } from '../common/printer-helpers.js'; -import { printComments } from '../slang-printers/print-comments.js'; -import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; -import { SlangNode } from './SlangNode.js'; -import { Statement } from './Statement.js'; - -const { hardline } = doc.builders; - -export class Statements extends SlangNode { - get kind() { - return NonterminalKind.Statements; - } - - items; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => new Statement(item, offsets[index], options) - ) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print, options) { - return this.items.length === 0 && - (!this.comments || this.comments.length === 0) - ? '' - : printSeparatedItem( - [ - printPreservingEmptyLines(path, 'items', options, print), - printComments(this, path, options) - ], - { - firstSeparator: hardline, - grouped: false - } - ); - } -} diff --git a/src/slang-nodes/Statements.ts b/src/slang-nodes/Statements.ts new file mode 100644 index 000000000..2d0394d29 --- /dev/null +++ b/src/slang-nodes/Statements.ts @@ -0,0 +1,57 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printSeparatedItem } from '../slang-printers/print-separated-item.js'; +import { printComments } from '../slang-printers/print-comments.js'; +import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Statement } from './Statement.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { hardline } = doc.builders; + +export class Statements implements SlangNode { + readonly kind = NonterminalKind.Statements; + + comments; + + loc; + + items: Statement[]; + + constructor(ast: ast.Statements, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => new Statement(item, offsets[index], options) + ); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print( + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc { + return this.items.length === 0 && + (!this.comments || this.comments.length === 0) + ? '' + : printSeparatedItem( + [ + printPreservingEmptyLines(path, 'items', print, options), + printComments(this, path) + ], + { + firstSeparator: hardline, + grouped: false + } + ); + } +} diff --git a/src/slang-nodes/StorageLocation.js b/src/slang-nodes/StorageLocation.js deleted file mode 100644 index 6af01f246..000000000 --- a/src/slang-nodes/StorageLocation.js +++ /dev/null @@ -1,24 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; - -export class StorageLocation extends SlangNode { - get kind() { - return NonterminalKind.StorageLocation; - } - - variant; - - constructor(ast, offset) { - super(); - - const fetch = () => ({ - variant: ast.variant.text - }); - - this.initialize(ast, offset, fetch); - } - - print() { - return this.variant; - } -} diff --git a/src/slang-nodes/StorageLocation.ts b/src/slang-nodes/StorageLocation.ts new file mode 100644 index 000000000..b3596855d --- /dev/null +++ b/src/slang-nodes/StorageLocation.ts @@ -0,0 +1,29 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata } from '../slang-utils/get-offsets.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class StorageLocation implements SlangNode { + readonly kind = NonterminalKind.StorageLocation; + + comments; + + loc; + + variant: string; + + constructor(ast: ast.StorageLocation, offset: number) { + const metadata = getNodeMetadata(ast, offset); + + this.variant = ast.variant.text; + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(): Doc { + return this.variant; + } +} diff --git a/src/slang-nodes/StringExpression.js b/src/slang-nodes/StringExpression.js deleted file mode 100644 index 15b941035..000000000 --- a/src/slang-nodes/StringExpression.js +++ /dev/null @@ -1,41 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { StringLiteral } from './StringLiteral.js'; -import { StringLiterals } from './StringLiterals.js'; -import { HexStringLiteral } from './HexStringLiteral.js'; -import { HexStringLiterals } from './HexStringLiterals.js'; -import { UnicodeStringLiterals } from './UnicodeStringLiterals.js'; - -const variants = { - StringLiteral, - StringLiterals, - HexStringLiteral, - HexStringLiterals, - UnicodeStringLiterals -}; - -export class StringExpression extends SlangNode { - get kind() { - return NonterminalKind.StringExpression; - } - - variant; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - variant: new variants[ast.variant.cst.kind]( - ast.variant, - offsets[0], - options - ) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return path.call(print, 'variant'); - } -} diff --git a/src/slang-nodes/StringExpression.ts b/src/slang-nodes/StringExpression.ts new file mode 100644 index 000000000..e8f04e8d0 --- /dev/null +++ b/src/slang-nodes/StringExpression.ts @@ -0,0 +1,85 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { StringLiteral } from './StringLiteral.js'; +import { StringLiterals } from './StringLiterals.js'; +import { HexStringLiteral } from './HexStringLiteral.js'; +import { HexStringLiterals } from './HexStringLiterals.js'; +import { UnicodeStringLiterals } from './UnicodeStringLiterals.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class StringExpression implements SlangNode { + readonly kind = NonterminalKind.StringExpression; + + comments; + + loc; + + variant: + | StringLiteral + | StringLiterals + | HexStringLiteral + | HexStringLiterals + | UnicodeStringLiterals; + + constructor( + ast: ast.StringExpression, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + switch (ast.variant.cst.kind) { + case 'StringLiteral': + this.variant = new StringLiteral( + ast.variant as ast.StringLiteral, + offsets[0], + options + ); + break; + case 'StringLiterals': + this.variant = new StringLiterals( + ast.variant as ast.StringLiterals, + offsets[0], + options + ); + break; + case 'HexStringLiteral': + this.variant = new HexStringLiteral( + ast.variant as ast.HexStringLiteral, + offsets[0], + options + ); + break; + + case 'HexStringLiterals': + this.variant = new HexStringLiterals( + ast.variant as ast.HexStringLiterals, + offsets[0], + options + ); + break; + case 'UnicodeStringLiterals': + this.variant = new UnicodeStringLiterals( + ast.variant as ast.UnicodeStringLiterals, + offsets[0], + options + ); + break; + default: + throw new Error(`Unexpected variant: ${ast.variant.cst.kind}`); + } + + metadata = updateMetadata(metadata, [this.variant]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/StringLiteral.js b/src/slang-nodes/StringLiteral.js deleted file mode 100644 index 5509e9c05..000000000 --- a/src/slang-nodes/StringLiteral.js +++ /dev/null @@ -1,29 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printString } from '../slang-printers/print-string.js'; -import { SlangNode } from './SlangNode.js'; - -const postProcess = (options) => (properties) => ({ - variant: printString(properties.variant.slice(1, -1), options) -}); - -export class StringLiteral extends SlangNode { - get kind() { - return NonterminalKind.StringLiteral; - } - - variant; - - constructor(ast, offset, options) { - super(); - - const fetch = () => ({ - variant: ast.variant.text - }); - - this.initialize(ast, offset, fetch, postProcess(options)); - } - - print() { - return this.variant; - } -} diff --git a/src/slang-nodes/StringLiteral.ts b/src/slang-nodes/StringLiteral.ts new file mode 100644 index 000000000..738c703d6 --- /dev/null +++ b/src/slang-nodes/StringLiteral.ts @@ -0,0 +1,32 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printString } from '../slang-printers/print-string.js'; +import { getNodeMetadata } from '../slang-utils/get-offsets.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class StringLiteral implements SlangNode { + readonly kind = NonterminalKind.StringLiteral; + + comments; + + loc; + + variant; + + constructor(ast: ast.StringLiteral, offset: number, options: ParserOptions) { + const metadata = getNodeMetadata(ast, offset); + + this.variant = ast.variant.text; + + this.comments = metadata.comments; + this.loc = metadata.loc; + + this.variant = printString(this.variant.slice(1, -1), options); + } + + print(): Doc { + return this.variant; + } +} diff --git a/src/slang-nodes/StringLiterals.js b/src/slang-nodes/StringLiterals.js deleted file mode 100644 index 52a83c36a..000000000 --- a/src/slang-nodes/StringLiterals.js +++ /dev/null @@ -1,30 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { StringLiteral } from './StringLiteral.js'; - -const { join, hardline } = doc.builders; - -export class StringLiterals extends SlangNode { - get kind() { - return NonterminalKind.StringLiterals; - } - - items; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => new StringLiteral(item, offsets[index], options) - ) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return join(hardline, path.map(print, 'items')); - } -} diff --git a/src/slang-nodes/StringLiterals.ts b/src/slang-nodes/StringLiterals.ts new file mode 100644 index 000000000..791be0115 --- /dev/null +++ b/src/slang-nodes/StringLiterals.ts @@ -0,0 +1,38 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { StringLiteral } from './StringLiteral.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { join, hardline } = doc.builders; + +export class StringLiterals implements SlangNode { + readonly kind = NonterminalKind.StringLiterals; + + comments; + + loc; + + items: StringLiteral[]; + + constructor(ast: ast.StringLiterals, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => new StringLiteral(item, offsets[index], options) + ); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return join(hardline, path.map(print, 'items')); + } +} diff --git a/src/slang-nodes/StructDefinition.js b/src/slang-nodes/StructDefinition.js deleted file mode 100644 index 012f4f6e7..000000000 --- a/src/slang-nodes/StructDefinition.js +++ /dev/null @@ -1,41 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { StructMembers } from './StructMembers.js'; - -export class StructDefinition extends SlangNode { - get kind() { - return NonterminalKind.StructDefinition; - } - - structKeyword; - - name; - - openBrace; - - members; - - closeBrace; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - structKeyword: ast.structKeyword.text, - name: ast.name.text, - openBrace: ast.openBrace.text, - members: new StructMembers(ast.members, offsets[0], options), - closeBrace: ast.closeBrace.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - `${this.structKeyword} ${this.name} ${this.openBrace}`, - path.call(print, 'members'), - this.closeBrace - ]; - } -} diff --git a/src/slang-nodes/StructDefinition.ts b/src/slang-nodes/StructDefinition.ts new file mode 100644 index 000000000..38badeb00 --- /dev/null +++ b/src/slang-nodes/StructDefinition.ts @@ -0,0 +1,53 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { StructMembers } from './StructMembers.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class StructDefinition implements SlangNode { + readonly kind = NonterminalKind.StructDefinition; + + comments; + + loc; + + structKeyword: string; + + name: string; + + openBrace: string; + + members: StructMembers; + + closeBrace: string; + + constructor( + ast: ast.StructDefinition, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.structKeyword = ast.structKeyword.text; + this.name = ast.name.text; + this.openBrace = ast.openBrace.text; + this.members = new StructMembers(ast.members, offsets[0], options); + this.closeBrace = ast.closeBrace.text; + + metadata = updateMetadata(metadata, [this.members]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + `${this.structKeyword} ${this.name} ${this.openBrace}`, + path.call(print, 'members'), + this.closeBrace + ]; + } +} diff --git a/src/slang-nodes/StructMember.js b/src/slang-nodes/StructMember.js deleted file mode 100644 index 32548e0c4..000000000 --- a/src/slang-nodes/StructMember.js +++ /dev/null @@ -1,31 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { TypeName } from './TypeName.js'; - -export class StructMember extends SlangNode { - get kind() { - return NonterminalKind.StructMember; - } - - typeName; - - name; - - semicolon; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - typeName: new TypeName(ast.typeName, offsets[0], options), - name: ast.name.text, - semicolon: ast.semicolon.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [path.call(print, 'typeName'), ` ${this.name}${this.semicolon}`]; - } -} diff --git a/src/slang-nodes/StructMember.ts b/src/slang-nodes/StructMember.ts new file mode 100644 index 000000000..ea5ec43c0 --- /dev/null +++ b/src/slang-nodes/StructMember.ts @@ -0,0 +1,39 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { TypeName } from './TypeName.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class StructMember implements SlangNode { + readonly kind = NonterminalKind.StructMember; + + comments; + + loc; + + typeName: TypeName; + + name: string; + + semicolon: string; + + constructor(ast: ast.StructMember, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.typeName = new TypeName(ast.typeName, offsets[0], options); + this.name = ast.name.text; + this.semicolon = ast.semicolon.text; + + metadata = updateMetadata(metadata, [this.typeName]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [path.call(print, 'typeName'), ` ${this.name}${this.semicolon}`]; + } +} diff --git a/src/slang-nodes/StructMembers.js b/src/slang-nodes/StructMembers.js deleted file mode 100644 index 019b47194..000000000 --- a/src/slang-nodes/StructMembers.js +++ /dev/null @@ -1,36 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printSeparatedList } from '../common/printer-helpers.js'; -import { SlangNode } from './SlangNode.js'; -import { StructMember } from './StructMember.js'; - -const { hardline } = doc.builders; - -export class StructMembers extends SlangNode { - get kind() { - return NonterminalKind.StructMembers; - } - - items; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => new StructMember(item, offsets[index], options) - ) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return this.items.length > 0 - ? printSeparatedList(path.map(print, 'items'), { - firstSeparator: hardline, - separator: hardline - }) - : ''; - } -} diff --git a/src/slang-nodes/StructMembers.ts b/src/slang-nodes/StructMembers.ts new file mode 100644 index 000000000..d0f905223 --- /dev/null +++ b/src/slang-nodes/StructMembers.ts @@ -0,0 +1,44 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printSeparatedList } from '../slang-printers/print-separated-list.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { StructMember } from './StructMember.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { hardline } = doc.builders; + +export class StructMembers implements SlangNode { + readonly kind = NonterminalKind.StructMembers; + + comments; + + loc; + + items: StructMember[]; + + constructor(ast: ast.StructMembers, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => new StructMember(item, offsets[index], options) + ); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return this.items.length > 0 + ? printSeparatedList(path.map(print, 'items'), { + firstSeparator: hardline, + separator: hardline + }) + : ''; + } +} diff --git a/src/slang-nodes/ThrowStatement.js b/src/slang-nodes/ThrowStatement.js deleted file mode 100644 index db7af101a..000000000 --- a/src/slang-nodes/ThrowStatement.js +++ /dev/null @@ -1,28 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; - -export class ThrowStatement extends SlangNode { - get kind() { - return NonterminalKind.ThrowStatement; - } - - throwKeyword; - - semicolon; - - constructor(ast, offset) { - super(); - - const fetch = () => ({ - throwKeyword: ast.throwKeyword.text, - semicolon: ast.semicolon.text - }); - - this.initialize(ast, offset, fetch); - } - - // TODO: implement print - print(path, print, options) { - return ['TODO: ThrowStatement']; - } -} diff --git a/src/slang-nodes/ThrowStatement.ts b/src/slang-nodes/ThrowStatement.ts new file mode 100644 index 000000000..9c0fd861f --- /dev/null +++ b/src/slang-nodes/ThrowStatement.ts @@ -0,0 +1,32 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata } from '../slang-utils/get-offsets.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class ThrowStatement implements SlangNode { + readonly kind = NonterminalKind.ThrowStatement; + + comments; + + loc; + + throwKeyword: string; + + semicolon: string; + + constructor(ast: ast.ThrowStatement, offset: number) { + const metadata = getNodeMetadata(ast, offset); + + this.throwKeyword = ast.throwKeyword.text; + this.semicolon = ast.semicolon.text; + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(): Doc { + return `${this.throwKeyword}${this.semicolon}`; + } +} diff --git a/src/slang-nodes/TryStatement.js b/src/slang-nodes/TryStatement.js deleted file mode 100644 index 3b26552a1..000000000 --- a/src/slang-nodes/TryStatement.js +++ /dev/null @@ -1,63 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printSeparatedItem } from '../common/printer-helpers.js'; -import { SlangNode } from './SlangNode.js'; -import { Expression } from './Expression.js'; -import { ReturnsDeclaration } from './ReturnsDeclaration.js'; -import { Block } from './Block.js'; -import { CatchClauses } from './CatchClauses.js'; - -const { line } = doc.builders; - -export class TryStatement extends SlangNode { - get kind() { - return NonterminalKind.TryStatement; - } - - tryKeyword; - - expression; - - returns; - - body; - - catchClauses; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => { - let i = 0; - const children = { - tryKeyword: ast.tryKeyword.text, - expression: new Expression(ast.expression, offsets[0], options), - returns: ast.returns - ? new ReturnsDeclaration(ast.returns, offsets[(i += 1)], options) - : undefined, - body: new Block(ast.body, offsets[(i += 1)], options), - catchClauses: new CatchClauses( - ast.catchClauses, - offsets[(i += 1)], - options - ) - }; - return children; - }; - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - this.tryKeyword, - printSeparatedItem(path.call(print, 'expression'), { - firstSeparator: line - }), - this.returns ? [path.call(print, 'returns'), ' '] : '', - path.call(print, 'body'), - ' ', - path.call(print, 'catchClauses') - ]; - } -} diff --git a/src/slang-nodes/TryStatement.ts b/src/slang-nodes/TryStatement.ts new file mode 100644 index 000000000..c6705b12d --- /dev/null +++ b/src/slang-nodes/TryStatement.ts @@ -0,0 +1,71 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printSeparatedItem } from '../slang-printers/print-separated-item.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Expression } from './Expression.js'; +import { ReturnsDeclaration } from './ReturnsDeclaration.js'; +import { Block } from './Block.js'; +import { CatchClauses } from './CatchClauses.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { line } = doc.builders; + +export class TryStatement implements SlangNode { + readonly kind = NonterminalKind.TryStatement; + + comments; + + loc; + + tryKeyword; + + expression: Expression; + + returns?: ReturnsDeclaration; + + body: Block; + + catchClauses: CatchClauses; + + constructor(ast: ast.TryStatement, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.tryKeyword = ast.tryKeyword.text; + this.expression = new Expression(ast.expression, offsets[0], options); + let i = 1; + if (ast.returns) { + this.returns = new ReturnsDeclaration(ast.returns, offsets[i], options); + i += 1; + } + this.body = new Block(ast.body, offsets[i], options); + i += 1; + this.catchClauses = new CatchClauses(ast.catchClauses, offsets[i], options); + + metadata = updateMetadata(metadata, [ + this.expression, + this.returns, + this.body, + this.catchClauses + ]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + this.tryKeyword, + printSeparatedItem(path.call(print, 'expression'), { + firstSeparator: line + }), + this.returns ? [path.call(print, 'returns'), ' '] : '', + path.call(print, 'body'), + ' ', + path.call(print, 'catchClauses') + ]; + } +} diff --git a/src/slang-nodes/TupleDeconstructionElement.js b/src/slang-nodes/TupleDeconstructionElement.js deleted file mode 100644 index d173501d2..000000000 --- a/src/slang-nodes/TupleDeconstructionElement.js +++ /dev/null @@ -1,27 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { TupleMember } from './TupleMember.js'; - -export class TupleDeconstructionElement extends SlangNode { - get kind() { - return NonterminalKind.TupleDeconstructionElement; - } - - member; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - member: ast.member - ? new TupleMember(ast.member, offsets[0], options) - : undefined - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return this.member ? path.call(print, 'member') : ''; - } -} diff --git a/src/slang-nodes/TupleDeconstructionElement.ts b/src/slang-nodes/TupleDeconstructionElement.ts new file mode 100644 index 000000000..97217466d --- /dev/null +++ b/src/slang-nodes/TupleDeconstructionElement.ts @@ -0,0 +1,39 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { TupleMember } from './TupleMember.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class TupleDeconstructionElement implements SlangNode { + readonly kind = NonterminalKind.TupleDeconstructionElement; + + comments; + + loc; + + member?: TupleMember; + + constructor( + ast: ast.TupleDeconstructionElement, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + if (ast.member) { + this.member = new TupleMember(ast.member, offsets[0], options); + } + + metadata = updateMetadata(metadata, [this.member]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return this.member ? path.call(print, 'member') : ''; + } +} diff --git a/src/slang-nodes/TupleDeconstructionElements.js b/src/slang-nodes/TupleDeconstructionElements.js deleted file mode 100644 index 70ad8ebb6..000000000 --- a/src/slang-nodes/TupleDeconstructionElements.js +++ /dev/null @@ -1,32 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printSeparatedList } from '../common/printer-helpers.js'; -import { SlangNode } from './SlangNode.js'; -import { TupleDeconstructionElement } from './TupleDeconstructionElement.js'; - -export class TupleDeconstructionElements extends SlangNode { - get kind() { - return NonterminalKind.TupleDeconstructionElements; - } - - items; - - separators; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => - new TupleDeconstructionElement(item, offsets[index], options) - ), - separators: ast.separators.map((separator) => separator.text) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return printSeparatedList(path.map(print, 'items')); - } -} diff --git a/src/slang-nodes/TupleDeconstructionElements.ts b/src/slang-nodes/TupleDeconstructionElements.ts new file mode 100644 index 000000000..88b28fa77 --- /dev/null +++ b/src/slang-nodes/TupleDeconstructionElements.ts @@ -0,0 +1,44 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printSeparatedList } from '../slang-printers/print-separated-list.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { TupleDeconstructionElement } from './TupleDeconstructionElement.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class TupleDeconstructionElements implements SlangNode { + readonly kind = NonterminalKind.TupleDeconstructionElements; + + comments; + + loc; + + items: TupleDeconstructionElement[]; + + separators: string[]; + + constructor( + ast: ast.TupleDeconstructionElements, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => + new TupleDeconstructionElement(item, offsets[index], options) + ); + this.separators = ast.separators.map((separator) => separator.text); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return printSeparatedList(path.map(print, 'items')); + } +} diff --git a/src/slang-nodes/TupleDeconstructionStatement.js b/src/slang-nodes/TupleDeconstructionStatement.js deleted file mode 100644 index eb36162ef..000000000 --- a/src/slang-nodes/TupleDeconstructionStatement.js +++ /dev/null @@ -1,61 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { TupleDeconstructionElements } from './TupleDeconstructionElements.js'; -import { Expression } from './Expression.js'; - -const { group, indent, line } = doc.builders; - -export class TupleDeconstructionStatement extends SlangNode { - get kind() { - return NonterminalKind.TupleDeconstructionStatement; - } - - varKeyword; - - openParen; - - elements; - - closeParen; - - equal; - - expression; - - semicolon; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - varKeyword: ast.varKeyword?.text, - openParen: ast.openParen.text, - elements: new TupleDeconstructionElements( - ast.elements, - offsets[0], - options - ), - closeParen: ast.closeParen.text, - equal: ast.equal.text, - expression: new Expression(ast.expression, offsets[1], options), - semicolon: ast.semicolon.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - this.varKeyword ? this.varKeyword : '', - this.openParen, - path.call(print, 'elements'), - this.expression.variant.kind === 'TupleExpression' - ? [`${this.closeParen} ${this.equal} `, path.call(print, 'expression')] - : group([ - `${this.closeParen} ${this.equal}`, - indent([line, path.call(print, 'expression'), this.semicolon]) - ]) - ]; - } -} diff --git a/src/slang-nodes/TupleDeconstructionStatement.ts b/src/slang-nodes/TupleDeconstructionStatement.ts new file mode 100644 index 000000000..2f9b5be47 --- /dev/null +++ b/src/slang-nodes/TupleDeconstructionStatement.ts @@ -0,0 +1,74 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { TupleDeconstructionElements } from './TupleDeconstructionElements.js'; +import { Expression } from './Expression.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { group, indent, line } = doc.builders; + +export class TupleDeconstructionStatement implements SlangNode { + readonly kind = NonterminalKind.TupleDeconstructionStatement; + + comments; + + loc; + + varKeyword?: string; + + openParen: string; + + elements: TupleDeconstructionElements; + + closeParen: string; + + equal: string; + + expression: Expression; + + semicolon: string; + + constructor( + ast: ast.TupleDeconstructionStatement, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.varKeyword = ast.varKeyword?.text; + this.openParen = ast.openParen.text; + this.elements = new TupleDeconstructionElements( + ast.elements, + offsets[0], + options + ); + this.closeParen = ast.closeParen.text; + this.equal = ast.equal.text; + this.expression = new Expression(ast.expression, offsets[1], options); + this.semicolon = ast.semicolon.text; + + metadata = updateMetadata(metadata, [this.elements, this.expression]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + this.varKeyword ? this.varKeyword : '', + this.openParen, + path.call(print, 'elements'), + typeof this.expression.variant !== 'string' && + this.expression.variant.kind === 'TupleExpression' + ? [`${this.closeParen} ${this.equal} `, path.call(print, 'expression')] + : group([ + `${this.closeParen} ${this.equal}`, + indent([line, path.call(print, 'expression'), this.semicolon]) + ]) + ]; + } +} diff --git a/src/slang-nodes/TupleExpression.js b/src/slang-nodes/TupleExpression.js deleted file mode 100644 index a077f9b0b..000000000 --- a/src/slang-nodes/TupleExpression.js +++ /dev/null @@ -1,31 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { TupleValues } from './TupleValues.js'; - -export class TupleExpression extends SlangNode { - get kind() { - return NonterminalKind.TupleExpression; - } - - openParen; - - items; - - closeParen; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - openParen: ast.openParen.text, - items: new TupleValues(ast.items, offsets[0], options), - closeParen: ast.closeParen.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [this.openParen, path.call(print, 'items'), this.closeParen]; - } -} diff --git a/src/slang-nodes/TupleExpression.ts b/src/slang-nodes/TupleExpression.ts new file mode 100644 index 000000000..7ae3502c4 --- /dev/null +++ b/src/slang-nodes/TupleExpression.ts @@ -0,0 +1,43 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { TupleValues } from './TupleValues.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class TupleExpression implements SlangNode { + readonly kind = NonterminalKind.TupleExpression; + + comments; + + loc; + + openParen: string; + + items: TupleValues; + + closeParen: string; + + constructor( + ast: ast.TupleExpression, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.openParen = ast.openParen.text; + this.items = new TupleValues(ast.items, offsets[0], options); + this.closeParen = ast.closeParen.text; + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [this.openParen, path.call(print, 'items'), this.closeParen]; + } +} diff --git a/src/slang-nodes/TupleMember.js b/src/slang-nodes/TupleMember.js deleted file mode 100644 index 75696f73d..000000000 --- a/src/slang-nodes/TupleMember.js +++ /dev/null @@ -1,32 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { TypedTupleMember } from './TypedTupleMember.js'; -import { UntypedTupleMember } from './UntypedTupleMember.js'; - -const variants = { TypedTupleMember, UntypedTupleMember }; - -export class TupleMember extends SlangNode { - get kind() { - return NonterminalKind.TupleMember; - } - - variant; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - variant: new variants[ast.variant.cst.kind]( - ast.variant, - offsets[0], - options - ) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return path.call(print, 'variant'); - } -} diff --git a/src/slang-nodes/TupleMember.ts b/src/slang-nodes/TupleMember.ts new file mode 100644 index 000000000..e354d1376 --- /dev/null +++ b/src/slang-nodes/TupleMember.ts @@ -0,0 +1,50 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { TypedTupleMember } from './TypedTupleMember.js'; +import { UntypedTupleMember } from './UntypedTupleMember.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class TupleMember implements SlangNode { + readonly kind = NonterminalKind.TupleMember; + + comments; + + loc; + + variant: TypedTupleMember | UntypedTupleMember; + + constructor(ast: ast.TupleMember, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + switch (ast.variant.cst.kind) { + case 'TypedTupleMember': + this.variant = new TypedTupleMember( + ast.variant as ast.TypedTupleMember, + offsets[0], + options + ); + break; + case 'UntypedTupleMember': + this.variant = new UntypedTupleMember( + ast.variant as ast.UntypedTupleMember, + offsets[0] + ); + break; + default: + throw new Error(`Unexpected variant: ${ast.variant.cst.kind}`); + } + + metadata = updateMetadata(metadata, [this.variant]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/TupleValue.js b/src/slang-nodes/TupleValue.js deleted file mode 100644 index 90e7d8353..000000000 --- a/src/slang-nodes/TupleValue.js +++ /dev/null @@ -1,27 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { Expression } from './Expression.js'; - -export class TupleValue extends SlangNode { - get kind() { - return NonterminalKind.TupleValue; - } - - expression; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - expression: ast.expression - ? new Expression(ast.expression, offsets[0], options) - : undefined - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return this.expression ? path.call(print, 'expression') : ''; - } -} diff --git a/src/slang-nodes/TupleValue.ts b/src/slang-nodes/TupleValue.ts new file mode 100644 index 000000000..c1c23acf9 --- /dev/null +++ b/src/slang-nodes/TupleValue.ts @@ -0,0 +1,35 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Expression } from './Expression.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class TupleValue implements SlangNode { + readonly kind = NonterminalKind.TupleValue; + + comments; + + loc; + + expression?: Expression; + + constructor(ast: ast.TupleValue, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + if (ast.expression) { + this.expression = new Expression(ast.expression, offsets[0], options); + } + + metadata = updateMetadata(metadata, [this.expression]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return this.expression ? path.call(print, 'expression') : ''; + } +} diff --git a/src/slang-nodes/TupleValues.js b/src/slang-nodes/TupleValues.js deleted file mode 100644 index b0c2e49df..000000000 --- a/src/slang-nodes/TupleValues.js +++ /dev/null @@ -1,35 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printSeparatedList } from '../common/printer-helpers.js'; -import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; -import { SlangNode } from './SlangNode.js'; -import { TupleValue } from './TupleValue.js'; - -export class TupleValues extends SlangNode { - get kind() { - return NonterminalKind.TupleValues; - } - - items; - - separators; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => new TupleValue(item, offsets[index], options) - ), - separators: ast.separators.map((separator) => separator.text) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return this.items.length === 1 && - isBinaryOperation(this.items[0].expression.variant) - ? path.map(print, 'items') - : printSeparatedList(path.map(print, 'items')); - } -} diff --git a/src/slang-nodes/TupleValues.ts b/src/slang-nodes/TupleValues.ts new file mode 100644 index 000000000..f08fbf41a --- /dev/null +++ b/src/slang-nodes/TupleValues.ts @@ -0,0 +1,43 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printSeparatedList } from '../slang-printers/print-separated-list.js'; +import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { TupleValue } from './TupleValue.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class TupleValues implements SlangNode { + readonly kind = NonterminalKind.TupleValues; + + comments; + + loc; + + items: TupleValue[]; + + separators: string[]; + + constructor(ast: ast.TupleValues, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => new TupleValue(item, offsets[index], options) + ); + this.separators = ast.separators.map((separator) => separator.text); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return this.items.length === 1 && + isBinaryOperation(this.items[0].expression!.variant) + ? path.map(print, 'items') + : printSeparatedList(path.map(print, 'items')); + } +} diff --git a/src/slang-nodes/TypeExpression.js b/src/slang-nodes/TypeExpression.js deleted file mode 100644 index fbeef0e9a..000000000 --- a/src/slang-nodes/TypeExpression.js +++ /dev/null @@ -1,35 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { TypeName } from './TypeName.js'; - -export class TypeExpression extends SlangNode { - get kind() { - return NonterminalKind.TypeExpression; - } - - typeKeyword; - - openParen; - - typeName; - - closeParen; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - typeKeyword: ast.typeKeyword.text, - openParen: ast.openParen.text, - typeName: new TypeName(ast.typeName, offsets[0], options), - closeParen: ast.closeParen.text - }); - - this.initialize(ast, offset, fetch); - } - - // TODO: implement print - print(path, print, options) { - return ['TODO: TypeExpression']; - } -} diff --git a/src/slang-nodes/TypeExpression.ts b/src/slang-nodes/TypeExpression.ts new file mode 100644 index 000000000..e92f20c49 --- /dev/null +++ b/src/slang-nodes/TypeExpression.ts @@ -0,0 +1,47 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { TypeName } from './TypeName.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class TypeExpression implements SlangNode { + readonly kind = NonterminalKind.TypeExpression; + + comments; + + loc; + + typeKeyword: string; + + openParen: string; + + typeName: TypeName; + + closeParen: string; + + constructor(ast: ast.TypeExpression, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.typeKeyword = ast.typeKeyword.text; + this.openParen = ast.openParen.text; + this.typeName = new TypeName(ast.typeName, offsets[0], options); + this.closeParen = ast.closeParen.text; + + metadata = updateMetadata(metadata, [this.typeName]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + // TODO: implement print + print( + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc { + return ['TODO: TypeExpression']; + } +} diff --git a/src/slang-nodes/TypeName.js b/src/slang-nodes/TypeName.js deleted file mode 100644 index 5f6a80529..000000000 --- a/src/slang-nodes/TypeName.js +++ /dev/null @@ -1,41 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { ArrayTypeName } from './ArrayTypeName.js'; -import { FunctionType } from './FunctionType.js'; -import { MappingType } from './MappingType.js'; -import { ElementaryType } from './ElementaryType.js'; -import { IdentifierPath } from './IdentifierPath.js'; - -const variants = { - ArrayTypeName, - FunctionType, - MappingType, - ElementaryType, - IdentifierPath -}; - -export class TypeName extends SlangNode { - get kind() { - return NonterminalKind.TypeName; - } - - variant; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - variant: new variants[ast.variant.cst.kind]( - ast.variant, - offsets[0], - options - ) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return path.call(print, 'variant'); - } -} diff --git a/src/slang-nodes/TypeName.ts b/src/slang-nodes/TypeName.ts new file mode 100644 index 000000000..980277e6b --- /dev/null +++ b/src/slang-nodes/TypeName.ts @@ -0,0 +1,81 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ArrayTypeName } from './ArrayTypeName.js'; +import { FunctionType } from './FunctionType.js'; +import { MappingType } from './MappingType.js'; +import { ElementaryType } from './ElementaryType.js'; +import { IdentifierPath } from './IdentifierPath.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class TypeName implements SlangNode { + readonly kind = NonterminalKind.TypeName; + + comments; + + loc; + + variant: + | ArrayTypeName + | FunctionType + | MappingType + | ElementaryType + | IdentifierPath; + + constructor(ast: ast.TypeName, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + switch (ast.variant.cst.kind) { + case 'ArrayTypeName': + this.variant = new ArrayTypeName( + ast.variant as ast.ArrayTypeName, + offsets[0], + options + ); + break; + case 'FunctionType': + this.variant = new FunctionType( + ast.variant as ast.FunctionType, + offsets[0], + options + ); + break; + case 'MappingType': + this.variant = new MappingType( + ast.variant as ast.MappingType, + offsets[0], + options + ); + break; + case 'ElementaryType': + this.variant = new ElementaryType( + ast.variant as ast.ElementaryType, + offsets[0] + ); + break; + case 'IdentifierPath': + this.variant = new IdentifierPath( + ast.variant as ast.IdentifierPath, + offsets[0] + ); + break; + default: + throw new Error(`Unexpected variant: ${ast.variant.cst.kind}`); + } + + metadata = updateMetadata( + metadata, + typeof this.variant === 'string' ? [] : [this.variant] + ); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/TypedTupleMember.js b/src/slang-nodes/TypedTupleMember.js deleted file mode 100644 index cb6b98709..000000000 --- a/src/slang-nodes/TypedTupleMember.js +++ /dev/null @@ -1,38 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { TypeName } from './TypeName.js'; -import { StorageLocation } from './StorageLocation.js'; - -export class TypedTupleMember extends SlangNode { - get kind() { - return NonterminalKind.TypedTupleMember; - } - - typeName; - - storageLocation; - - name; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - typeName: new TypeName(ast.typeName, offsets[0], options), - storageLocation: ast.storageLocation - ? new StorageLocation(ast.storageLocation, offsets[1], options) - : undefined, - name: ast.name.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - path.call(print, 'typeName'), - this.storageLocation ? [' ', path.call(print, 'storageLocation')] : '', - ` ${this.name}` - ]; - } -} diff --git a/src/slang-nodes/TypedTupleMember.ts b/src/slang-nodes/TypedTupleMember.ts new file mode 100644 index 000000000..61d080d83 --- /dev/null +++ b/src/slang-nodes/TypedTupleMember.ts @@ -0,0 +1,53 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { TypeName } from './TypeName.js'; +import { StorageLocation } from './StorageLocation.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class TypedTupleMember implements SlangNode { + readonly kind = NonterminalKind.TypedTupleMember; + + comments; + + loc; + + typeName: TypeName; + + storageLocation?: StorageLocation; + + name: string; + + constructor( + ast: ast.TypedTupleMember, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.typeName = new TypeName(ast.typeName, offsets[0], options); + if (ast.storageLocation) { + this.storageLocation = new StorageLocation( + ast.storageLocation, + offsets[1] + ); + } + this.name = ast.name.text; + + metadata = updateMetadata(metadata, [this.typeName, this.storageLocation]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + path.call(print, 'typeName'), + this.storageLocation ? [' ', path.call(print, 'storageLocation')] : '', + ` ${this.name}` + ]; + } +} diff --git a/src/slang-nodes/UncheckedBlock.js b/src/slang-nodes/UncheckedBlock.js deleted file mode 100644 index dbcb24480..000000000 --- a/src/slang-nodes/UncheckedBlock.js +++ /dev/null @@ -1,28 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { Block } from './Block.js'; - -export class UncheckedBlock extends SlangNode { - get kind() { - return NonterminalKind.UncheckedBlock; - } - - uncheckedKeyword; - - block; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - uncheckedKeyword: ast.uncheckedKeyword.text, - block: new Block(ast.block, offsets[0], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [`${this.uncheckedKeyword} `, path.call(print, 'block')]; - } -} diff --git a/src/slang-nodes/UncheckedBlock.ts b/src/slang-nodes/UncheckedBlock.ts new file mode 100644 index 000000000..82d636c06 --- /dev/null +++ b/src/slang-nodes/UncheckedBlock.ts @@ -0,0 +1,36 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Block } from './Block.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class UncheckedBlock implements SlangNode { + readonly kind = NonterminalKind.UncheckedBlock; + + comments; + + loc; + + uncheckedKeyword: string; + + block: Block; + + constructor(ast: ast.UncheckedBlock, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.uncheckedKeyword = ast.uncheckedKeyword.text; + this.block = new Block(ast.block, offsets[0], options); + + metadata = updateMetadata(metadata, [this.block]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [`${this.uncheckedKeyword} `, path.call(print, 'block')]; + } +} diff --git a/src/slang-nodes/UnicodeStringLiteral.js b/src/slang-nodes/UnicodeStringLiteral.js deleted file mode 100644 index d0154e608..000000000 --- a/src/slang-nodes/UnicodeStringLiteral.js +++ /dev/null @@ -1,29 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printString } from '../slang-printers/print-string.js'; -import { SlangNode } from './SlangNode.js'; - -const postProcess = (options) => (properties) => ({ - variant: `unicode${printString(properties.variant.slice(8, -1), options)}` -}); - -export class UnicodeStringLiteral extends SlangNode { - get kind() { - return NonterminalKind.UnicodeStringLiteral; - } - - variant; - - constructor(ast, offset, options) { - super(); - - const fetch = () => ({ - variant: ast.variant.text - }); - - this.initialize(ast, offset, fetch, postProcess(options)); - } - - print() { - return this.variant; - } -} diff --git a/src/slang-nodes/UnicodeStringLiteral.ts b/src/slang-nodes/UnicodeStringLiteral.ts new file mode 100644 index 000000000..99c4400d9 --- /dev/null +++ b/src/slang-nodes/UnicodeStringLiteral.ts @@ -0,0 +1,36 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printString } from '../slang-printers/print-string.js'; +import { getNodeMetadata } from '../slang-utils/get-offsets.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class UnicodeStringLiteral implements SlangNode { + readonly kind = NonterminalKind.UnicodeStringLiteral; + + comments; + + loc; + + variant: string; + + constructor( + ast: ast.UnicodeStringLiteral, + offset: number, + options: ParserOptions + ) { + const metadata = getNodeMetadata(ast, offset); + + this.variant = ast.variant.text; + + this.comments = metadata.comments; + this.loc = metadata.loc; + + this.variant = `unicode${printString(this.variant.slice(8, -1), options)}`; + } + + print(): Doc { + return this.variant; + } +} diff --git a/src/slang-nodes/UnicodeStringLiterals.js b/src/slang-nodes/UnicodeStringLiterals.js deleted file mode 100644 index 611be17c5..000000000 --- a/src/slang-nodes/UnicodeStringLiterals.js +++ /dev/null @@ -1,30 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { UnicodeStringLiteral } from './UnicodeStringLiteral.js'; - -const { join, hardline } = doc.builders; - -export class UnicodeStringLiterals extends SlangNode { - get kind() { - return NonterminalKind.UnicodeStringLiterals; - } - - items; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => new UnicodeStringLiteral(item, offsets[index], options) - ) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return join(hardline, path.map(print, 'items')); - } -} diff --git a/src/slang-nodes/UnicodeStringLiterals.ts b/src/slang-nodes/UnicodeStringLiterals.ts new file mode 100644 index 000000000..b1f84e536 --- /dev/null +++ b/src/slang-nodes/UnicodeStringLiterals.ts @@ -0,0 +1,42 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { UnicodeStringLiteral } from './UnicodeStringLiteral.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { join, hardline } = doc.builders; + +export class UnicodeStringLiterals implements SlangNode { + readonly kind = NonterminalKind.UnicodeStringLiterals; + + comments; + + loc; + + items: UnicodeStringLiteral[]; + + constructor( + ast: ast.UnicodeStringLiterals, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => new UnicodeStringLiteral(item, offsets[index], options) + ); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return join(hardline, path.map(print, 'items')); + } +} diff --git a/src/slang-nodes/UnnamedFunctionAttribute.js b/src/slang-nodes/UnnamedFunctionAttribute.js deleted file mode 100644 index f55d08087..000000000 --- a/src/slang-nodes/UnnamedFunctionAttribute.js +++ /dev/null @@ -1,30 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { ModifierInvocation } from './ModifierInvocation.js'; - -export class UnnamedFunctionAttribute extends SlangNode { - get kind() { - return NonterminalKind.UnnamedFunctionAttribute; - } - - variant; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - variant: - ast.variant.type === 'Terminal' - ? ast.variant.text - : new ModifierInvocation(ast.variant, offsets[0], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return typeof this.variant === 'string' - ? this.variant - : path.call(print, 'variant'); - } -} diff --git a/src/slang-nodes/UnnamedFunctionAttribute.ts b/src/slang-nodes/UnnamedFunctionAttribute.ts new file mode 100644 index 000000000..4e19a4899 --- /dev/null +++ b/src/slang-nodes/UnnamedFunctionAttribute.ts @@ -0,0 +1,46 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ModifierInvocation } from './ModifierInvocation.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class UnnamedFunctionAttribute implements SlangNode { + readonly kind = NonterminalKind.UnnamedFunctionAttribute; + + comments; + + loc; + + variant: ModifierInvocation | string; + + constructor( + ast: ast.UnnamedFunctionAttribute, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.variant = + ast.variant instanceof TerminalNode + ? ast.variant.text + : new ModifierInvocation(ast.variant, offsets[0], options); + + metadata = updateMetadata( + metadata, + typeof this.variant === 'string' ? [] : [this.variant] + ); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/UnnamedFunctionAttributes.js b/src/slang-nodes/UnnamedFunctionAttributes.js deleted file mode 100644 index e47898429..000000000 --- a/src/slang-nodes/UnnamedFunctionAttributes.js +++ /dev/null @@ -1,32 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { postProcessFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; -import { SlangNode } from './SlangNode.js'; -import { UnnamedFunctionAttribute } from './UnnamedFunctionAttribute.js'; - -const { line } = doc.builders; - -export class UnnamedFunctionAttributes extends SlangNode { - get kind() { - return NonterminalKind.UnnamedFunctionAttributes; - } - - items; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => - new UnnamedFunctionAttribute(item, offsets[index], options) - ) - }); - - this.initialize(ast, offset, fetch, postProcessFunctionAttributes); - } - - print(path, print) { - return path.map(print, 'items').map((item) => [line, item]); - } -} diff --git a/src/slang-nodes/UnnamedFunctionAttributes.ts b/src/slang-nodes/UnnamedFunctionAttributes.ts new file mode 100644 index 000000000..68a85ad6b --- /dev/null +++ b/src/slang-nodes/UnnamedFunctionAttributes.ts @@ -0,0 +1,46 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { UnnamedFunctionAttribute } from './UnnamedFunctionAttribute.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { line } = doc.builders; + +export class UnnamedFunctionAttributes implements SlangNode { + readonly kind = NonterminalKind.UnnamedFunctionAttributes; + + comments; + + loc; + + items: UnnamedFunctionAttribute[]; + + constructor( + ast: ast.UnnamedFunctionAttributes, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => + new UnnamedFunctionAttribute(item, offsets[index], options) + ); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + + this.items = this.items.sort(sortFunctionAttributes); + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return path.map(print, 'items').map((item) => [line, item]); + } +} diff --git a/src/slang-nodes/UnnamedFunctionDefinition.js b/src/slang-nodes/UnnamedFunctionDefinition.js deleted file mode 100644 index 1346b5807..000000000 --- a/src/slang-nodes/UnnamedFunctionDefinition.js +++ /dev/null @@ -1,55 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printFunction } from '../slang-printers/print-function.js'; -import { SlangNode } from './SlangNode.js'; -import { ParametersDeclaration } from './ParametersDeclaration.js'; -import { UnnamedFunctionAttributes } from './UnnamedFunctionAttributes.js'; -import { FunctionBody } from './FunctionBody.js'; - -export class UnnamedFunctionDefinition extends SlangNode { - get kind() { - return NonterminalKind.UnnamedFunctionDefinition; - } - - functionKeyword; - - parameters; - - attributes; - - body; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - functionKeyword: ast.functionKeyword.text, - parameters: new ParametersDeclaration( - ast.parameters, - offsets[0], - options - ), - attributes: new UnnamedFunctionAttributes( - ast.attributes, - offsets[1], - options - ), - body: new FunctionBody(ast.body, offsets[2], options) - }); - - this.initialize(ast, offset, fetch); - - this.cleanModifierInvocationArguments(); - } - - cleanModifierInvocationArguments() { - this.attributes.items.forEach((attribute) => { - if (attribute.variant.kind === 'ModifierInvocation') { - attribute.variant.cleanModifierInvocationArguments(); - } - }); - } - - print(path, print) { - return printFunction(this.functionKeyword, this, path, print); - } -} diff --git a/src/slang-nodes/UnnamedFunctionDefinition.ts b/src/slang-nodes/UnnamedFunctionDefinition.ts new file mode 100644 index 000000000..5c40ce47a --- /dev/null +++ b/src/slang-nodes/UnnamedFunctionDefinition.ts @@ -0,0 +1,71 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printFunction } from '../slang-printers/print-function.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ParametersDeclaration } from './ParametersDeclaration.js'; +import { UnnamedFunctionAttributes } from './UnnamedFunctionAttributes.js'; +import { FunctionBody } from './FunctionBody.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class UnnamedFunctionDefinition implements SlangNode { + readonly kind = NonterminalKind.UnnamedFunctionDefinition; + + comments; + + loc; + + functionKeyword: string; + + parameters: ParametersDeclaration; + + attributes: UnnamedFunctionAttributes; + + body: FunctionBody; + + constructor( + ast: ast.UnnamedFunctionDefinition, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.functionKeyword = ast.functionKeyword.text; + this.parameters = new ParametersDeclaration( + ast.parameters, + offsets[0], + options + ); + this.attributes = new UnnamedFunctionAttributes( + ast.attributes, + offsets[1], + options + ); + this.body = new FunctionBody(ast.body, offsets[2], options); + + metadata = updateMetadata(metadata, [ + this.parameters, + this.attributes, + this.body + ]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + + this.cleanModifierInvocationArguments(); + } + + cleanModifierInvocationArguments(): void { + this.attributes.items.forEach((attribute) => { + if (typeof attribute.variant !== 'string') { + attribute.variant.cleanModifierInvocationArguments(); + } + }); + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return printFunction(this.functionKeyword, this, path, print); + } +} diff --git a/src/slang-nodes/UntypedTupleMember.js b/src/slang-nodes/UntypedTupleMember.js deleted file mode 100644 index b7e63d0b7..000000000 --- a/src/slang-nodes/UntypedTupleMember.js +++ /dev/null @@ -1,31 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { StorageLocation } from './StorageLocation.js'; - -export class UntypedTupleMember extends SlangNode { - get kind() { - return NonterminalKind.UntypedTupleMember; - } - - storageLocation; - - name; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - storageLocation: ast.storageLocation - ? new StorageLocation(ast.storageLocation, offsets[0], options) - : undefined, - name: ast.name.text - }); - - this.initialize(ast, offset, fetch); - } - - // TODO: implement print - print(path, print, options) { - return ['TODO: UntypedTupleMemberUntypedTupleMember']; - } -} diff --git a/src/slang-nodes/UntypedTupleMember.ts b/src/slang-nodes/UntypedTupleMember.ts new file mode 100644 index 000000000..dba658202 --- /dev/null +++ b/src/slang-nodes/UntypedTupleMember.ts @@ -0,0 +1,46 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { StorageLocation } from './StorageLocation.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class UntypedTupleMember implements SlangNode { + readonly kind = NonterminalKind.UntypedTupleMember; + + comments; + + loc; + + storageLocation?: StorageLocation; + + name: string; + + constructor(ast: ast.UntypedTupleMember, offset: number) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + if (ast.storageLocation) { + this.storageLocation = new StorageLocation( + ast.storageLocation, + offsets[0] + ); + } + this.name = ast.name.text; + + metadata = updateMetadata(metadata, [this.storageLocation]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + // TODO: implement print + print( + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc { + return ['TODO: UntypedTupleMemberUntypedTupleMember']; + } +} diff --git a/src/slang-nodes/UserDefinedValueTypeDefinition.js b/src/slang-nodes/UserDefinedValueTypeDefinition.js deleted file mode 100644 index e1933557d..000000000 --- a/src/slang-nodes/UserDefinedValueTypeDefinition.js +++ /dev/null @@ -1,41 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { ElementaryType } from './ElementaryType.js'; - -export class UserDefinedValueTypeDefinition extends SlangNode { - get kind() { - return NonterminalKind.UserDefinedValueTypeDefinition; - } - - typeKeyword; - - name; - - isKeyword; - - valueType; - - semicolon; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - typeKeyword: ast.typeKeyword.text, - name: ast.name.text, - isKeyword: ast.isKeyword.text, - valueType: new ElementaryType(ast.valueType, offsets[0], options), - semicolon: ast.semicolon.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - `${this.typeKeyword} ${this.name} ${this.isKeyword} `, - path.call(print, 'valueType'), - this.semicolon - ]; - } -} diff --git a/src/slang-nodes/UserDefinedValueTypeDefinition.ts b/src/slang-nodes/UserDefinedValueTypeDefinition.ts new file mode 100644 index 000000000..810a4cd80 --- /dev/null +++ b/src/slang-nodes/UserDefinedValueTypeDefinition.ts @@ -0,0 +1,49 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { ElementaryType } from './ElementaryType.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class UserDefinedValueTypeDefinition implements SlangNode { + readonly kind = NonterminalKind.UserDefinedValueTypeDefinition; + + comments; + + loc; + + typeKeyword: string; + + name: string; + + isKeyword: string; + + valueType: ElementaryType; + + semicolon: string; + + constructor(ast: ast.UserDefinedValueTypeDefinition, offset: number) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.typeKeyword = ast.typeKeyword.text; + this.name = ast.name.text; + this.isKeyword = ast.isKeyword.text; + this.valueType = new ElementaryType(ast.valueType, offsets[0]); + this.semicolon = ast.semicolon.text; + + metadata = updateMetadata(metadata, [this.valueType]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + `${this.typeKeyword} ${this.name} ${this.isKeyword} `, + path.call(print, 'valueType'), + this.semicolon + ]; + } +} diff --git a/src/slang-nodes/UsingAlias.js b/src/slang-nodes/UsingAlias.js deleted file mode 100644 index 80b8ad215..000000000 --- a/src/slang-nodes/UsingAlias.js +++ /dev/null @@ -1,28 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { UsingOperator } from './UsingOperator.js'; - -export class UsingAlias extends SlangNode { - get kind() { - return NonterminalKind.UsingAlias; - } - - asKeyword; - - operator; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - asKeyword: ast.asKeyword.text, - operator: new UsingOperator(ast.operator, offsets[0], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [` ${this.asKeyword} `, path.call(print, 'operator')]; - } -} diff --git a/src/slang-nodes/UsingAlias.ts b/src/slang-nodes/UsingAlias.ts new file mode 100644 index 000000000..18f47a0a3 --- /dev/null +++ b/src/slang-nodes/UsingAlias.ts @@ -0,0 +1,36 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { UsingOperator } from './UsingOperator.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class UsingAlias implements SlangNode { + readonly kind = NonterminalKind.UsingAlias; + + comments; + + loc; + + asKeyword: string; + + operator: UsingOperator; + + constructor(ast: ast.UsingAlias, offset: number) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.asKeyword = ast.asKeyword.text; + this.operator = new UsingOperator(ast.operator, offsets[0]); + + metadata = updateMetadata(metadata, [this.operator]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [` ${this.asKeyword} `, path.call(print, 'operator')]; + } +} diff --git a/src/slang-nodes/UsingClause.js b/src/slang-nodes/UsingClause.js deleted file mode 100644 index 0e48a742d..000000000 --- a/src/slang-nodes/UsingClause.js +++ /dev/null @@ -1,32 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { IdentifierPath } from './IdentifierPath.js'; -import { UsingDeconstruction } from './UsingDeconstruction.js'; - -const variants = { IdentifierPath, UsingDeconstruction }; - -export class UsingClause extends SlangNode { - get kind() { - return NonterminalKind.UsingClause; - } - - variant; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - variant: new variants[ast.variant.cst.kind]( - ast.variant, - offsets[0], - options - ) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return path.call(print, 'variant'); - } -} diff --git a/src/slang-nodes/UsingClause.ts b/src/slang-nodes/UsingClause.ts new file mode 100644 index 000000000..3f929f29d --- /dev/null +++ b/src/slang-nodes/UsingClause.ts @@ -0,0 +1,52 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { IdentifierPath } from './IdentifierPath.js'; +import { UsingDeconstruction } from './UsingDeconstruction.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class UsingClause implements SlangNode { + readonly kind = NonterminalKind.UsingClause; + + comments; + + loc; + + variant: IdentifierPath | UsingDeconstruction; + + constructor(ast: ast.UsingClause, offset: number) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + switch (ast.variant.cst.kind) { + case 'IdentifierPath': + this.variant = new IdentifierPath( + ast.variant as ast.IdentifierPath, + offsets[0] + ); + break; + case 'UsingDeconstruction': + this.variant = new UsingDeconstruction( + ast.variant as ast.UsingDeconstruction, + offsets[0] + ); + break; + default: + throw new Error(`Unexpected variant: ${ast.variant.cst.kind}`); + } + + metadata = updateMetadata( + metadata, + typeof this.variant === 'string' ? [] : [this.variant] + ); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/UsingDeconstruction.js b/src/slang-nodes/UsingDeconstruction.js deleted file mode 100644 index 56abbae9e..000000000 --- a/src/slang-nodes/UsingDeconstruction.js +++ /dev/null @@ -1,31 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { UsingDeconstructionSymbols } from './UsingDeconstructionSymbols.js'; - -export class UsingDeconstruction extends SlangNode { - get kind() { - return NonterminalKind.UsingDeconstruction; - } - - openBrace; - - symbols; - - closeBrace; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - openBrace: ast.openBrace.text, - symbols: new UsingDeconstructionSymbols(ast.symbols, offsets[0], options), - closeBrace: ast.closeBrace.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [this.openBrace, path.call(print, 'symbols'), this.closeBrace]; - } -} diff --git a/src/slang-nodes/UsingDeconstruction.ts b/src/slang-nodes/UsingDeconstruction.ts new file mode 100644 index 000000000..acfca21f7 --- /dev/null +++ b/src/slang-nodes/UsingDeconstruction.ts @@ -0,0 +1,39 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { UsingDeconstructionSymbols } from './UsingDeconstructionSymbols.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class UsingDeconstruction implements SlangNode { + readonly kind = NonterminalKind.UsingDeconstruction; + + comments; + + loc; + + openBrace: string; + + symbols: UsingDeconstructionSymbols; + + closeBrace: string; + + constructor(ast: ast.UsingDeconstruction, offset: number) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.openBrace = ast.openBrace.text; + this.symbols = new UsingDeconstructionSymbols(ast.symbols, offsets[0]); + this.closeBrace = ast.closeBrace.text; + + metadata = updateMetadata(metadata, [this.symbols]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [this.openBrace, path.call(print, 'symbols'), this.closeBrace]; + } +} diff --git a/src/slang-nodes/UsingDeconstructionSymbol.js b/src/slang-nodes/UsingDeconstructionSymbol.js deleted file mode 100644 index 154737259..000000000 --- a/src/slang-nodes/UsingDeconstructionSymbol.js +++ /dev/null @@ -1,34 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { IdentifierPath } from './IdentifierPath.js'; -import { UsingAlias } from './UsingAlias.js'; - -export class UsingDeconstructionSymbol extends SlangNode { - get kind() { - return NonterminalKind.UsingDeconstructionSymbol; - } - - name; - - alias; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - name: new IdentifierPath(ast.name, offsets[0], options), - alias: ast.alias - ? new UsingAlias(ast.alias, offsets[1], options) - : undefined - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - path.call(print, 'name'), - this.alias ? path.call(print, 'alias') : '' - ]; - } -} diff --git a/src/slang-nodes/UsingDeconstructionSymbol.ts b/src/slang-nodes/UsingDeconstructionSymbol.ts new file mode 100644 index 000000000..b77c77cb8 --- /dev/null +++ b/src/slang-nodes/UsingDeconstructionSymbol.ts @@ -0,0 +1,42 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { IdentifierPath } from './IdentifierPath.js'; +import { UsingAlias } from './UsingAlias.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class UsingDeconstructionSymbol implements SlangNode { + readonly kind = NonterminalKind.UsingDeconstructionSymbol; + + comments; + + loc; + + name: IdentifierPath; + + alias?: UsingAlias; + + constructor(ast: ast.UsingDeconstructionSymbol, offset: number) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.name = new IdentifierPath(ast.name, offsets[0]); + if (ast.alias) { + this.alias = new UsingAlias(ast.alias, offsets[1]); + } + + metadata = updateMetadata(metadata, [this.name, this.alias]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + path.call(print, 'name'), + this.alias ? path.call(print, 'alias') : '' + ]; + } +} diff --git a/src/slang-nodes/UsingDeconstructionSymbols.js b/src/slang-nodes/UsingDeconstructionSymbols.js deleted file mode 100644 index 5f2d67287..000000000 --- a/src/slang-nodes/UsingDeconstructionSymbols.js +++ /dev/null @@ -1,37 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printSeparatedList } from '../common/printer-helpers.js'; -import { SlangNode } from './SlangNode.js'; -import { UsingDeconstructionSymbol } from './UsingDeconstructionSymbol.js'; - -const { line, softline } = doc.builders; - -export class UsingDeconstructionSymbols extends SlangNode { - get kind() { - return NonterminalKind.UsingDeconstructionSymbols; - } - - items; - - separators; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => - new UsingDeconstructionSymbol(item, offsets[index], options) - ), - separators: ast.separators.map((separator) => separator.text) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print, options) { - return printSeparatedList(path.map(print, 'items'), { - firstSeparator: options.bracketSpacing ? line : softline - }); - } -} diff --git a/src/slang-nodes/UsingDeconstructionSymbols.ts b/src/slang-nodes/UsingDeconstructionSymbols.ts new file mode 100644 index 000000000..a89dfa577 --- /dev/null +++ b/src/slang-nodes/UsingDeconstructionSymbols.ts @@ -0,0 +1,48 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printSeparatedList } from '../slang-printers/print-separated-list.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { UsingDeconstructionSymbol } from './UsingDeconstructionSymbol.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { line, softline } = doc.builders; + +export class UsingDeconstructionSymbols implements SlangNode { + readonly kind = NonterminalKind.UsingDeconstructionSymbols; + + comments; + + loc; + + items: UsingDeconstructionSymbol[]; + + separators: string[]; + + constructor(ast: ast.UsingDeconstructionSymbols, offset: number) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => new UsingDeconstructionSymbol(item, offsets[index]) + ); + this.separators = ast.separators.map((separator) => separator.text); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print( + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc { + return printSeparatedList(path.map(print, 'items'), { + firstSeparator: options.bracketSpacing ? line : softline + }); + } +} diff --git a/src/slang-nodes/UsingDirective.js b/src/slang-nodes/UsingDirective.js deleted file mode 100644 index 76a9c38fd..000000000 --- a/src/slang-nodes/UsingDirective.js +++ /dev/null @@ -1,47 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { UsingClause } from './UsingClause.js'; -import { UsingTarget } from './UsingTarget.js'; - -export class UsingDirective extends SlangNode { - get kind() { - return NonterminalKind.UsingDirective; - } - - usingKeyword; - - clause; - - forKeyword; - - target; - - globalKeyword; - - semicolon; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - usingKeyword: ast.usingKeyword.text, - clause: new UsingClause(ast.clause, offsets[0], options), - forKeyword: ast.forKeyword.text, - target: new UsingTarget(ast.target, offsets[1], options), - globalKeyword: ast.globalKeyword?.text, - semicolon: ast.semicolon.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - `${this.usingKeyword} `, - path.call(print, 'clause'), - ` ${this.forKeyword} `, - path.call(print, 'target'), - `${this.globalKeyword ? ` ${this.globalKeyword}` : ''}${this.semicolon}` - ]; - } -} diff --git a/src/slang-nodes/UsingDirective.ts b/src/slang-nodes/UsingDirective.ts new file mode 100644 index 000000000..88ea96ea1 --- /dev/null +++ b/src/slang-nodes/UsingDirective.ts @@ -0,0 +1,55 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { UsingClause } from './UsingClause.js'; +import { UsingTarget } from './UsingTarget.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class UsingDirective implements SlangNode { + readonly kind = NonterminalKind.UsingDirective; + + comments; + + loc; + + usingKeyword: string; + + clause: UsingClause; + + forKeyword: string; + + target: UsingTarget; + + globalKeyword?: string; + + semicolon: string; + + constructor(ast: ast.UsingDirective, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.usingKeyword = ast.usingKeyword.text; + this.clause = new UsingClause(ast.clause, offsets[0]); + this.forKeyword = ast.forKeyword.text; + this.target = new UsingTarget(ast.target, offsets[1], options); + this.globalKeyword = ast.globalKeyword?.text; + this.semicolon = ast.semicolon.text; + + metadata = updateMetadata(metadata, [this.clause, this.target]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + `${this.usingKeyword} `, + path.call(print, 'clause'), + ` ${this.forKeyword} `, + path.call(print, 'target'), + `${this.globalKeyword ? ` ${this.globalKeyword}` : ''}${this.semicolon}` + ]; + } +} diff --git a/src/slang-nodes/UsingOperator.js b/src/slang-nodes/UsingOperator.js deleted file mode 100644 index eee3758c2..000000000 --- a/src/slang-nodes/UsingOperator.js +++ /dev/null @@ -1,24 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; - -export class UsingOperator extends SlangNode { - get kind() { - return NonterminalKind.UsingOperator; - } - - variant; - - constructor(ast, offset) { - super(); - - const fetch = () => ({ - variant: ast.variant.text - }); - - this.initialize(ast, offset, fetch); - } - - print() { - return this.variant; - } -} diff --git a/src/slang-nodes/UsingOperator.ts b/src/slang-nodes/UsingOperator.ts new file mode 100644 index 000000000..c50c1733a --- /dev/null +++ b/src/slang-nodes/UsingOperator.ts @@ -0,0 +1,29 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata } from '../slang-utils/get-offsets.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class UsingOperator implements SlangNode { + readonly kind = NonterminalKind.UsingOperator; + + comments; + + loc; + + variant: string; + + constructor(ast: ast.UsingOperator, offset: number) { + const metadata = getNodeMetadata(ast, offset); + + this.variant = ast.variant.text; + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(): Doc { + return this.variant; + } +} diff --git a/src/slang-nodes/UsingTarget.js b/src/slang-nodes/UsingTarget.js deleted file mode 100644 index d3751df38..000000000 --- a/src/slang-nodes/UsingTarget.js +++ /dev/null @@ -1,30 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { TypeName } from './TypeName.js'; - -export class UsingTarget extends SlangNode { - get kind() { - return NonterminalKind.UsingTarget; - } - - variant; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - variant: - ast.variant.type === 'Terminal' - ? ast.variant.text - : new TypeName(ast.variant, offsets[0], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return typeof this.variant === 'string' - ? this.variant - : path.call(print, 'variant'); - } -} diff --git a/src/slang-nodes/UsingTarget.ts b/src/slang-nodes/UsingTarget.ts new file mode 100644 index 000000000..565f1c33a --- /dev/null +++ b/src/slang-nodes/UsingTarget.ts @@ -0,0 +1,42 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { TypeName } from './TypeName.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class UsingTarget implements SlangNode { + readonly kind = NonterminalKind.UsingTarget; + + comments; + + loc; + + variant: TypeName | string; + + constructor(ast: ast.UsingTarget, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.variant = + ast.variant instanceof TerminalNode + ? ast.variant.text + : new TypeName(ast.variant, offsets[0], options); + + metadata = updateMetadata( + metadata, + typeof this.variant === 'string' ? [] : [this.variant] + ); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/VariableDeclarationStatement.js b/src/slang-nodes/VariableDeclarationStatement.js deleted file mode 100644 index a4e57bc81..000000000 --- a/src/slang-nodes/VariableDeclarationStatement.js +++ /dev/null @@ -1,73 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { VariableDeclarationType } from './VariableDeclarationType.js'; -import { StorageLocation } from './StorageLocation.js'; -import { VariableDeclarationValue } from './VariableDeclarationValue.js'; - -const { group, indent, indentIfBreak, line } = doc.builders; - -export class VariableDeclarationStatement extends SlangNode { - get kind() { - return NonterminalKind.VariableDeclarationStatement; - } - - variableType; - - storageLocation; - - name; - - value; - - semicolon; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => { - let i = 0; - const children = { - variableType: new VariableDeclarationType( - ast.variableType, - offsets[0], - options - ), - storageLocation: ast.storageLocation - ? new StorageLocation(ast.storageLocation, offsets[(i += 1)], options) - : undefined, - name: ast.name.text, - value: ast.value - ? new VariableDeclarationValue(ast.value, offsets[(i += 1)], options) - : undefined, - semicolon: ast.semicolon.text - }; - return children; - }; - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - const declarationDoc = group( - [ - path.call(print, 'variableType'), - indent([ - this.storageLocation - ? [line, path.call(print, 'storageLocation')] - : '', - ` ${this.name}` - ]) - ], - { id: 'VariableDeclarationStatement.variables' } - ); - - return [ - declarationDoc, - indentIfBreak(this.value ? path.call(print, 'value') : '', { - groupId: declarationDoc.id - }), - this.semicolon - ]; - } -} diff --git a/src/slang-nodes/VariableDeclarationStatement.ts b/src/slang-nodes/VariableDeclarationStatement.ts new file mode 100644 index 000000000..38d937660 --- /dev/null +++ b/src/slang-nodes/VariableDeclarationStatement.ts @@ -0,0 +1,89 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { VariableDeclarationType } from './VariableDeclarationType.js'; +import { StorageLocation } from './StorageLocation.js'; +import { VariableDeclarationValue } from './VariableDeclarationValue.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { group, indent, indentIfBreak, line } = doc.builders; + +export class VariableDeclarationStatement implements SlangNode { + readonly kind = NonterminalKind.VariableDeclarationStatement; + + comments; + + loc; + + variableType: VariableDeclarationType; + + storageLocation?: StorageLocation; + + name: string; + + value?: VariableDeclarationValue; + + semicolon: string; + + constructor( + ast: ast.VariableDeclarationStatement, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.variableType = new VariableDeclarationType( + ast.variableType, + offsets[0], + options + ); + let i = 1; + if (ast.storageLocation) { + this.storageLocation = ast.storageLocation + ? new StorageLocation(ast.storageLocation, offsets[i]) + : undefined; + i += 1; + } + this.name = ast.name.text; + if (ast.value) { + this.value = new VariableDeclarationValue(ast.value, offsets[i], options); + } + this.semicolon = ast.semicolon.text; + + metadata = updateMetadata(metadata, [ + this.variableType, + this.storageLocation, + this.value + ]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + const declarationDoc = group( + [ + path.call(print, 'variableType'), + indent([ + this.storageLocation + ? [line, path.call(print, 'storageLocation')] + : '', + ` ${this.name}` + ]) + ], + { id: Symbol('Slang.VariableDeclarationStatement.variables') } + ); + + return [ + declarationDoc, + indentIfBreak(this.value ? path.call(print, 'value') : '', { + groupId: declarationDoc.id! + }), + this.semicolon + ]; + } +} diff --git a/src/slang-nodes/VariableDeclarationType.js b/src/slang-nodes/VariableDeclarationType.js deleted file mode 100644 index ca4620f50..000000000 --- a/src/slang-nodes/VariableDeclarationType.js +++ /dev/null @@ -1,30 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { TypeName } from './TypeName.js'; - -export class VariableDeclarationType extends SlangNode { - get kind() { - return NonterminalKind.VariableDeclarationType; - } - - variant; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - variant: - ast.variant.type === 'Terminal' - ? ast.variant.type - : new TypeName(ast.variant, offsets[0], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return typeof this.variant === 'string' - ? this.variant - : path.call(print, 'variant'); - } -} diff --git a/src/slang-nodes/VariableDeclarationType.ts b/src/slang-nodes/VariableDeclarationType.ts new file mode 100644 index 000000000..c586565ee --- /dev/null +++ b/src/slang-nodes/VariableDeclarationType.ts @@ -0,0 +1,46 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { TypeName } from './TypeName.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class VariableDeclarationType implements SlangNode { + readonly kind = NonterminalKind.VariableDeclarationType; + + comments; + + loc; + + variant: TypeName | string; + + constructor( + ast: ast.VariableDeclarationType, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.variant = + ast.variant instanceof TerminalNode + ? ast.variant.type + : new TypeName(ast.variant, offsets[0], options); + + metadata = updateMetadata( + metadata, + typeof this.variant === 'string' ? [] : [this.variant] + ); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/VariableDeclarationValue.js b/src/slang-nodes/VariableDeclarationValue.js deleted file mode 100644 index 03feaba50..000000000 --- a/src/slang-nodes/VariableDeclarationValue.js +++ /dev/null @@ -1,28 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { Expression } from './Expression.js'; - -export class VariableDeclarationValue extends SlangNode { - get kind() { - return NonterminalKind.VariableDeclarationValue; - } - - equal; - - expression; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - equal: ast.equal.text, - expression: new Expression(ast.expression, offsets[0], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [` ${this.equal} `, path.call(print, 'expression')]; - } -} diff --git a/src/slang-nodes/VariableDeclarationValue.ts b/src/slang-nodes/VariableDeclarationValue.ts new file mode 100644 index 000000000..9b7adc36f --- /dev/null +++ b/src/slang-nodes/VariableDeclarationValue.ts @@ -0,0 +1,40 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Expression } from './Expression.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class VariableDeclarationValue implements SlangNode { + readonly kind = NonterminalKind.VariableDeclarationValue; + + comments; + + loc; + + equal: string; + + expression: Expression; + + constructor( + ast: ast.VariableDeclarationValue, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.equal = ast.equal.text; + this.expression = new Expression(ast.expression, offsets[0], options); + + metadata = updateMetadata(metadata, [this.expression]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [` ${this.equal} `, path.call(print, 'expression')]; + } +} diff --git a/src/slang-nodes/VersionComparator.js b/src/slang-nodes/VersionComparator.js deleted file mode 100644 index 221648af3..000000000 --- a/src/slang-nodes/VersionComparator.js +++ /dev/null @@ -1,28 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { VersionExpression } from './VersionExpression.js'; - -export class VersionComparator extends SlangNode { - get kind() { - return NonterminalKind.VersionComparator; - } - - operator; - - operand; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - operator: ast.operator.text, - operand: new VersionExpression(ast.operand, offsets[0], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [this.operator, path.call(print, 'operand')]; - } -} diff --git a/src/slang-nodes/VersionComparator.ts b/src/slang-nodes/VersionComparator.ts new file mode 100644 index 000000000..e9742da74 --- /dev/null +++ b/src/slang-nodes/VersionComparator.ts @@ -0,0 +1,40 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { VersionExpression } from './VersionExpression.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class VersionComparator implements SlangNode { + readonly kind = NonterminalKind.VersionComparator; + + comments; + + loc; + + operator: string; + + operand: VersionExpression; + + constructor( + ast: ast.VersionComparator, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.operator = ast.operator.text; + this.operand = new VersionExpression(ast.operand, offsets[0], options); + + metadata = updateMetadata(metadata, [this.operand]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [this.operator, path.call(print, 'operand')]; + } +} diff --git a/src/slang-nodes/VersionExpression.js b/src/slang-nodes/VersionExpression.js deleted file mode 100644 index 0f6ccb4c6..000000000 --- a/src/slang-nodes/VersionExpression.js +++ /dev/null @@ -1,38 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { VersionRange } from './VersionRange.js'; -import { VersionComparator } from './VersionComparator.js'; -import { VersionSpecifiers } from './VersionSpecifiers.js'; - -const variants = { - VersionRange, - VersionComparator, - VersionSpecifiers -}; - -export class VersionExpression extends SlangNode { - get kind() { - return NonterminalKind.VersionExpression; - } - - variant; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - variant: - ast.variant.type === 'Terminal' - ? ast.variant.text - : new variants[ast.variant.cst.kind](ast.variant, offsets[0], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return typeof this.variant === 'string' - ? this.variant - : path.call(print, 'variant'); - } -} diff --git a/src/slang-nodes/VersionExpression.ts b/src/slang-nodes/VersionExpression.ts new file mode 100644 index 000000000..85d21677b --- /dev/null +++ b/src/slang-nodes/VersionExpression.ts @@ -0,0 +1,72 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { VersionRange } from './VersionRange.js'; +import { VersionComparator } from './VersionComparator.js'; +import { VersionSpecifiers } from './VersionSpecifiers.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class VersionExpression implements SlangNode { + readonly kind = NonterminalKind.VersionExpression; + + comments; + + loc; + + variant: VersionRange | VersionComparator | VersionSpecifiers | string; + + constructor( + ast: ast.VersionExpression, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + if (ast.variant instanceof TerminalNode) { + this.variant = ast.variant.text; + } else { + switch (ast.variant.cst.kind) { + case 'VersionRange': + this.variant = new VersionRange( + ast.variant as ast.VersionRange, + offsets[0], + options + ); + break; + case 'VersionComparator': + this.variant = new VersionComparator( + ast.variant as ast.VersionComparator, + offsets[0], + options + ); + break; + case 'VersionSpecifiers': + this.variant = new VersionSpecifiers( + ast.variant as ast.VersionSpecifiers, + offsets[0] + ); + break; + default: + throw new Error(`Unexpected variant: ${ast.variant.cst.kind}`); + } + } + + metadata = updateMetadata( + metadata, + typeof this.variant === 'string' ? [] : [this.variant] + ); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/VersionExpressionSet.js b/src/slang-nodes/VersionExpressionSet.js deleted file mode 100644 index 452ab8752..000000000 --- a/src/slang-nodes/VersionExpressionSet.js +++ /dev/null @@ -1,30 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { VersionExpression } from './VersionExpression.js'; - -const { join } = doc.builders; - -export class VersionExpressionSet extends SlangNode { - get kind() { - return NonterminalKind.VersionExpressionSet; - } - - items; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => new VersionExpression(item, offsets[index], options) - ) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return join(' ', path.map(print, 'items')); - } -} diff --git a/src/slang-nodes/VersionExpressionSet.ts b/src/slang-nodes/VersionExpressionSet.ts new file mode 100644 index 000000000..821bcd0ef --- /dev/null +++ b/src/slang-nodes/VersionExpressionSet.ts @@ -0,0 +1,42 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { VersionExpression } from './VersionExpression.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { join } = doc.builders; + +export class VersionExpressionSet implements SlangNode { + readonly kind = NonterminalKind.VersionExpressionSet; + + comments; + + loc; + + items: VersionExpression[]; + + constructor( + ast: ast.VersionExpressionSet, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => new VersionExpression(item, offsets[index], options) + ); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return join(' ', path.map(print, 'items')); + } +} diff --git a/src/slang-nodes/VersionExpressionSets.js b/src/slang-nodes/VersionExpressionSets.js deleted file mode 100644 index 2f3d1c467..000000000 --- a/src/slang-nodes/VersionExpressionSets.js +++ /dev/null @@ -1,34 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { VersionExpressionSet } from './VersionExpressionSet.js'; - -export class VersionExpressionSets extends SlangNode { - get kind() { - return NonterminalKind.VersionExpressionSets; - } - - items; - - separators; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => new VersionExpressionSet(item, offsets[index], options) - ), - separators: ast.separators.map((separator) => separator.text) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return path - .map(print, 'items') - .map((item, index) => - index === 0 ? item : [` ${this.separators[index - 1]} `, item] - ); - } -} diff --git a/src/slang-nodes/VersionExpressionSets.ts b/src/slang-nodes/VersionExpressionSets.ts new file mode 100644 index 000000000..9d00704bc --- /dev/null +++ b/src/slang-nodes/VersionExpressionSets.ts @@ -0,0 +1,46 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { VersionExpressionSet } from './VersionExpressionSet.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class VersionExpressionSets implements SlangNode { + readonly kind = NonterminalKind.VersionExpressionSets; + + comments; + + loc; + + items: VersionExpressionSet[]; + + separators: string[]; + + constructor( + ast: ast.VersionExpressionSets, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => new VersionExpressionSet(item, offsets[index], options) + ); + this.separators = ast.separators.map((separator) => separator.text); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return path + .map(print, 'items') + .map((item, index) => + index === 0 ? item : [` ${this.separators[index - 1]} `, item] + ); + } +} diff --git a/src/slang-nodes/VersionPragma.js b/src/slang-nodes/VersionPragma.js deleted file mode 100644 index a04306809..000000000 --- a/src/slang-nodes/VersionPragma.js +++ /dev/null @@ -1,28 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { VersionExpressionSets } from './VersionExpressionSets.js'; - -export class VersionPragma extends SlangNode { - get kind() { - return NonterminalKind.VersionPragma; - } - - solidityKeyword; - - sets; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - solidityKeyword: ast.solidityKeyword.text, - sets: new VersionExpressionSets(ast.sets, offsets[0], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [`${this.solidityKeyword} `, path.call(print, 'sets')]; - } -} diff --git a/src/slang-nodes/VersionPragma.ts b/src/slang-nodes/VersionPragma.ts new file mode 100644 index 000000000..2943267ff --- /dev/null +++ b/src/slang-nodes/VersionPragma.ts @@ -0,0 +1,36 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { VersionExpressionSets } from './VersionExpressionSets.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class VersionPragma implements SlangNode { + readonly kind = NonterminalKind.VersionPragma; + + comments; + + loc; + + solidityKeyword: string; + + sets: VersionExpressionSets; + + constructor(ast: ast.VersionPragma, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.solidityKeyword = ast.solidityKeyword.text; + this.sets = new VersionExpressionSets(ast.sets, offsets[0], options); + + metadata = updateMetadata(metadata, [this.sets]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [`${this.solidityKeyword} `, path.call(print, 'sets')]; + } +} diff --git a/src/slang-nodes/VersionRange.js b/src/slang-nodes/VersionRange.js deleted file mode 100644 index d026d5505..000000000 --- a/src/slang-nodes/VersionRange.js +++ /dev/null @@ -1,32 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { VersionExpression } from './VersionExpression.js'; - -export class VersionRange extends SlangNode { - get kind() { - return NonterminalKind.VersionRange; - } - - leftOperand; - - operator; - - rightOperand; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - leftOperand: new VersionExpression(ast.leftOperand, offsets[0], options), - operator: ast.operator.text, - rightOperand: new VersionExpression(ast.rightOperand, offsets[1], options) - }); - - this.initialize(ast, offset, fetch); - } - - // TODO: implement print - print(path, print, options) { - return ['TODO: VersionRange']; - } -} diff --git a/src/slang-nodes/VersionRange.ts b/src/slang-nodes/VersionRange.ts new file mode 100644 index 000000000..9af6e24b0 --- /dev/null +++ b/src/slang-nodes/VersionRange.ts @@ -0,0 +1,52 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { VersionExpression } from './VersionExpression.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class VersionRange implements SlangNode { + readonly kind = NonterminalKind.VersionRange; + + comments; + + loc; + + leftOperand: VersionExpression; + + operator: string; + + rightOperand: VersionExpression; + + constructor(ast: ast.VersionRange, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.leftOperand = new VersionExpression( + ast.leftOperand, + offsets[0], + options + ); + this.operator = ast.operator.text; + this.rightOperand = new VersionExpression( + ast.rightOperand, + offsets[1], + options + ); + + metadata = updateMetadata(metadata, [this.leftOperand, this.rightOperand]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + // TODO: implement print + print( + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc { + return ['TODO: VersionRange']; + } +} diff --git a/src/slang-nodes/VersionSpecifiers.js b/src/slang-nodes/VersionSpecifiers.js deleted file mode 100644 index 11512198f..000000000 --- a/src/slang-nodes/VersionSpecifiers.js +++ /dev/null @@ -1,29 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; - -export class VersionSpecifiers extends SlangNode { - get kind() { - return NonterminalKind.VersionSpecifiers; - } - - items; - - separators; - - constructor(ast, offset) { - super(); - - const fetch = () => ({ - items: ast.items.map((item) => item.text), - separators: ast.separators.map((separator) => separator.text) - }); - - this.initialize(ast, offset, fetch); - } - - print() { - return this.items.map((item, index) => - index === 0 ? item : [this.separators[index - 1], item] - ); - } -} diff --git a/src/slang-nodes/VersionSpecifiers.ts b/src/slang-nodes/VersionSpecifiers.ts new file mode 100644 index 000000000..ffc93f7ed --- /dev/null +++ b/src/slang-nodes/VersionSpecifiers.ts @@ -0,0 +1,34 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata } from '../slang-utils/get-offsets.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class VersionSpecifiers implements SlangNode { + readonly kind = NonterminalKind.VersionSpecifiers; + + comments; + + loc; + + items: string[]; + + separators: string[]; + + constructor(ast: ast.VersionSpecifiers, offset: number) { + const metadata = getNodeMetadata(ast, offset); + + this.items = ast.items.map((item) => item.text); + this.separators = ast.separators.map((separator) => separator.text); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(): Doc { + return this.items.map((item, index) => + index === 0 ? item : [this.separators[index - 1], item] + ); + } +} diff --git a/src/slang-nodes/WhileStatement.js b/src/slang-nodes/WhileStatement.js deleted file mode 100644 index c24a22898..000000000 --- a/src/slang-nodes/WhileStatement.js +++ /dev/null @@ -1,49 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printSeparatedItem } from '../common/printer-helpers.js'; -import { SlangNode } from './SlangNode.js'; -import { Expression } from './Expression.js'; -import { Statement } from './Statement.js'; - -const { group, indent, line } = doc.builders; - -export class WhileStatement extends SlangNode { - get kind() { - return NonterminalKind.WhileStatement; - } - - whileKeyword; - - openParen; - - condition; - - closeParen; - - body; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - whileKeyword: ast.whileKeyword.text, - openParen: ast.openParen.text, - condition: new Expression(ast.condition, offsets[0], options), - closeParen: ast.closeParen.text, - body: new Statement(ast.body, offsets[1], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - `${this.whileKeyword} ${this.openParen}`, - printSeparatedItem(path.call(print, 'condition')), - this.closeParen, - this.body.variant.kind === 'Block' - ? [' ', path.call(print, 'body')] - : group(indent([line, path.call(print, 'body')])) - ]; - } -} diff --git a/src/slang-nodes/WhileStatement.ts b/src/slang-nodes/WhileStatement.ts new file mode 100644 index 000000000..fed356c05 --- /dev/null +++ b/src/slang-nodes/WhileStatement.ts @@ -0,0 +1,57 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printSeparatedItem } from '../slang-printers/print-separated-item.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { Expression } from './Expression.js'; +import { Statement } from './Statement.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { group, indent, line } = doc.builders; + +export class WhileStatement implements SlangNode { + readonly kind = NonterminalKind.WhileStatement; + + comments; + + loc; + + whileKeyword: string; + + openParen: string; + + condition: Expression; + + closeParen: string; + + body: Statement; + + constructor(ast: ast.WhileStatement, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.whileKeyword = ast.whileKeyword.text; + this.openParen = ast.openParen.text; + this.condition = new Expression(ast.condition, offsets[0], options); + this.closeParen = ast.closeParen.text; + this.body = new Statement(ast.body, offsets[1], options); + + metadata = updateMetadata(metadata, [this.condition, this.body]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + `${this.whileKeyword} ${this.openParen}`, + printSeparatedItem(path.call(print, 'condition')), + this.closeParen, + this.body.variant.kind === 'Block' + ? [' ', path.call(print, 'body')] + : group(indent([line, path.call(print, 'body')])) + ]; + } +} diff --git a/src/slang-nodes/YulArguments.js b/src/slang-nodes/YulArguments.js deleted file mode 100644 index 81f6c3c0c..000000000 --- a/src/slang-nodes/YulArguments.js +++ /dev/null @@ -1,31 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printSeparatedList } from '../common/printer-helpers.js'; -import { SlangNode } from './SlangNode.js'; -import { YulExpression } from './YulExpression.js'; - -export class YulArguments extends SlangNode { - get kind() { - return NonterminalKind.YulArguments; - } - - items; - - separators; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => new YulExpression(item, offsets[index], options) - ), - separators: ast.separators.map((separator) => separator.text) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return printSeparatedList(path.map(print, 'items')); - } -} diff --git a/src/slang-nodes/YulArguments.ts b/src/slang-nodes/YulArguments.ts new file mode 100644 index 000000000..622eec350 --- /dev/null +++ b/src/slang-nodes/YulArguments.ts @@ -0,0 +1,39 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printSeparatedList } from '../slang-printers/print-separated-list.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { YulExpression } from './YulExpression.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class YulArguments implements SlangNode { + readonly kind = NonterminalKind.YulArguments; + + comments; + + loc; + + items: YulExpression[]; + + separators: string[]; + + constructor(ast: ast.YulArguments, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => new YulExpression(item, offsets[index], options) + ); + this.separators = ast.separators.map((separator) => separator.text); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return printSeparatedList(path.map(print, 'items')); + } +} diff --git a/src/slang-nodes/YulAssignmentOperator.js b/src/slang-nodes/YulAssignmentOperator.js deleted file mode 100644 index 8a733d98b..000000000 --- a/src/slang-nodes/YulAssignmentOperator.js +++ /dev/null @@ -1,30 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { YulColonEqual } from './YulColonEqual.js'; - -export class YulAssignmentOperator extends SlangNode { - get kind() { - return NonterminalKind.YulAssignmentOperator; - } - - variant; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - variant: - ast.variant.type === 'Terminal' - ? ast.variant.text - : new YulColonEqual(ast.variant, offsets[0], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return typeof this.variant === 'string' - ? this.variant - : path.call(print, 'variant'); - } -} diff --git a/src/slang-nodes/YulAssignmentOperator.ts b/src/slang-nodes/YulAssignmentOperator.ts new file mode 100644 index 000000000..b80307a7c --- /dev/null +++ b/src/slang-nodes/YulAssignmentOperator.ts @@ -0,0 +1,42 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { YulColonEqual } from './YulColonEqual.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class YulAssignmentOperator implements SlangNode { + readonly kind = NonterminalKind.YulAssignmentOperator; + + comments; + + loc; + + variant: YulColonEqual | string; + + constructor(ast: ast.YulAssignmentOperator, offset: number) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.variant = + ast.variant instanceof TerminalNode + ? ast.variant.text + : new YulColonEqual(ast.variant, offsets[0]); + + metadata = updateMetadata( + metadata, + typeof this.variant === 'string' ? [] : [this.variant] + ); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/YulBlock.js b/src/slang-nodes/YulBlock.js deleted file mode 100644 index 2676329f2..000000000 --- a/src/slang-nodes/YulBlock.js +++ /dev/null @@ -1,31 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { YulStatements } from './YulStatements.js'; - -export class YulBlock extends SlangNode { - get kind() { - return NonterminalKind.YulBlock; - } - - openBrace; - - statements; - - closeBrace; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - openBrace: ast.openBrace.text, - statements: new YulStatements(ast.statements, offsets[0], options), - closeBrace: ast.closeBrace.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [this.openBrace, path.call(print, 'statements'), this.closeBrace]; - } -} diff --git a/src/slang-nodes/YulBlock.ts b/src/slang-nodes/YulBlock.ts new file mode 100644 index 000000000..396a1f610 --- /dev/null +++ b/src/slang-nodes/YulBlock.ts @@ -0,0 +1,39 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { YulStatements } from './YulStatements.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class YulBlock implements SlangNode { + readonly kind = NonterminalKind.YulBlock; + + comments; + + loc; + + openBrace: string; + + statements: YulStatements; + + closeBrace: string; + + constructor(ast: ast.YulBlock, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.openBrace = ast.openBrace.text; + this.statements = new YulStatements(ast.statements, offsets[0], options); + this.closeBrace = ast.closeBrace.text; + + metadata = updateMetadata(metadata, [this.statements]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [this.openBrace, path.call(print, 'statements'), this.closeBrace]; + } +} diff --git a/src/slang-nodes/YulBreakStatement.js b/src/slang-nodes/YulBreakStatement.js deleted file mode 100644 index 33dc4b82c..000000000 --- a/src/slang-nodes/YulBreakStatement.js +++ /dev/null @@ -1,24 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; - -export class YulBreakStatement extends SlangNode { - get kind() { - return NonterminalKind.YulBreakStatement; - } - - breakKeyword; - - constructor(ast, offset) { - super(); - - const fetch = () => ({ - breakKeyword: ast.breakKeyword.text - }); - - this.initialize(ast, offset, fetch); - } - - print() { - return this.breakKeyword; - } -} diff --git a/src/slang-nodes/YulBreakStatement.ts b/src/slang-nodes/YulBreakStatement.ts new file mode 100644 index 000000000..8b7ea0dc1 --- /dev/null +++ b/src/slang-nodes/YulBreakStatement.ts @@ -0,0 +1,29 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata } from '../slang-utils/get-offsets.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class YulBreakStatement implements SlangNode { + readonly kind = NonterminalKind.YulBreakStatement; + + comments; + + loc; + + breakKeyword: string; + + constructor(ast: ast.YulBreakStatement, offset: number) { + const metadata = getNodeMetadata(ast, offset); + + this.breakKeyword = ast.breakKeyword.text; + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(): Doc { + return this.breakKeyword; + } +} diff --git a/src/slang-nodes/YulBuiltInFunction.js b/src/slang-nodes/YulBuiltInFunction.js deleted file mode 100644 index f57e8c412..000000000 --- a/src/slang-nodes/YulBuiltInFunction.js +++ /dev/null @@ -1,24 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; - -export class YulBuiltInFunction extends SlangNode { - get kind() { - return NonterminalKind.YulBuiltInFunction; - } - - variant; - - constructor(ast, offset) { - super(); - - const fetch = () => ({ - variant: ast.variant.text - }); - - this.initialize(ast, offset, fetch); - } - - print() { - return this.variant; - } -} diff --git a/src/slang-nodes/YulBuiltInFunction.ts b/src/slang-nodes/YulBuiltInFunction.ts new file mode 100644 index 000000000..c8c154279 --- /dev/null +++ b/src/slang-nodes/YulBuiltInFunction.ts @@ -0,0 +1,29 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata } from '../slang-utils/get-offsets.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class YulBuiltInFunction implements SlangNode { + readonly kind = NonterminalKind.YulBuiltInFunction; + + comments; + + loc; + + variant: string; + + constructor(ast: ast.YulBuiltInFunction, offset: number) { + const metadata = getNodeMetadata(ast, offset); + + this.variant = ast.variant.text; + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(): Doc { + return this.variant; + } +} diff --git a/src/slang-nodes/YulColonEqual.js b/src/slang-nodes/YulColonEqual.js deleted file mode 100644 index b840c82c8..000000000 --- a/src/slang-nodes/YulColonEqual.js +++ /dev/null @@ -1,28 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; - -export class YulColonEqual extends SlangNode { - get kind() { - return NonterminalKind.YulColonEqual; - } - - colon; - - equal; - - constructor(ast, offset) { - super(); - - const fetch = () => ({ - colon: ast.colon.text, - equal: ast.equal.text - }); - - this.initialize(ast, offset, fetch); - } - - // TODO: implement print - print(path, print, options) { - return ['TODO: YulColonEqual']; - } -} diff --git a/src/slang-nodes/YulColonEqual.ts b/src/slang-nodes/YulColonEqual.ts new file mode 100644 index 000000000..608d75397 --- /dev/null +++ b/src/slang-nodes/YulColonEqual.ts @@ -0,0 +1,37 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata } from '../slang-utils/get-offsets.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class YulColonEqual implements SlangNode { + readonly kind = NonterminalKind.YulColonEqual; + + comments; + + loc; + + colon: string; + + equal: string; + + constructor(ast: ast.YulColonEqual, offset: number) { + const metadata = getNodeMetadata(ast, offset); + + this.colon = ast.colon.text; + this.equal = ast.equal.text; + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + // TODO: implement print + print( + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc { + return ['TODO: YulColonEqual']; + } +} diff --git a/src/slang-nodes/YulContinueStatement.js b/src/slang-nodes/YulContinueStatement.js deleted file mode 100644 index 2393319eb..000000000 --- a/src/slang-nodes/YulContinueStatement.js +++ /dev/null @@ -1,24 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; - -export class YulContinueStatement extends SlangNode { - get kind() { - return NonterminalKind.YulContinueStatement; - } - - continueKeyword; - - constructor(ast, offset) { - super(); - - const fetch = () => ({ - continueKeyword: ast.continueKeyword.text - }); - - this.initialize(ast, offset, fetch); - } - - print() { - return this.continueKeyword; - } -} diff --git a/src/slang-nodes/YulContinueStatement.ts b/src/slang-nodes/YulContinueStatement.ts new file mode 100644 index 000000000..8aa997626 --- /dev/null +++ b/src/slang-nodes/YulContinueStatement.ts @@ -0,0 +1,29 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata } from '../slang-utils/get-offsets.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class YulContinueStatement implements SlangNode { + readonly kind = NonterminalKind.YulContinueStatement; + + comments; + + loc; + + continueKeyword: string; + + constructor(ast: ast.YulContinueStatement, offset: number) { + const metadata = getNodeMetadata(ast, offset); + + this.continueKeyword = ast.continueKeyword.text; + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(): Doc { + return this.continueKeyword; + } +} diff --git a/src/slang-nodes/YulDefaultCase.js b/src/slang-nodes/YulDefaultCase.js deleted file mode 100644 index 990631e80..000000000 --- a/src/slang-nodes/YulDefaultCase.js +++ /dev/null @@ -1,28 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { YulBlock } from './YulBlock.js'; - -export class YulDefaultCase extends SlangNode { - get kind() { - return NonterminalKind.YulDefaultCase; - } - - defaultKeyword; - - body; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - defaultKeyword: ast.defaultKeyword.text, - body: new YulBlock(ast.body, offsets[0], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [`${this.defaultKeyword} `, path.call(print, 'body')]; - } -} diff --git a/src/slang-nodes/YulDefaultCase.ts b/src/slang-nodes/YulDefaultCase.ts new file mode 100644 index 000000000..e8d550fbe --- /dev/null +++ b/src/slang-nodes/YulDefaultCase.ts @@ -0,0 +1,36 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { YulBlock } from './YulBlock.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class YulDefaultCase implements SlangNode { + readonly kind = NonterminalKind.YulDefaultCase; + + comments; + + loc; + + defaultKeyword: string; + + body: YulBlock; + + constructor(ast: ast.YulDefaultCase, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.defaultKeyword = ast.defaultKeyword.text; + this.body = new YulBlock(ast.body, offsets[0], options); + + metadata = updateMetadata(metadata, [this.body]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [`${this.defaultKeyword} `, path.call(print, 'body')]; + } +} diff --git a/src/slang-nodes/YulExpression.js b/src/slang-nodes/YulExpression.js deleted file mode 100644 index 1c1d42cc8..000000000 --- a/src/slang-nodes/YulExpression.js +++ /dev/null @@ -1,39 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { YulFunctionCallExpression } from './YulFunctionCallExpression.js'; -import { YulLiteral } from './YulLiteral.js'; -import { YulBuiltInFunction } from './YulBuiltInFunction.js'; -import { YulPath } from './YulPath.js'; - -const variants = { - YulFunctionCallExpression, - YulLiteral, - YulBuiltInFunction, - YulPath -}; - -export class YulExpression extends SlangNode { - get kind() { - return NonterminalKind.YulExpression; - } - - variant; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - variant: new variants[ast.variant.cst.kind]( - ast.variant, - offsets[0], - options - ) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return path.call(print, 'variant'); - } -} diff --git a/src/slang-nodes/YulExpression.ts b/src/slang-nodes/YulExpression.ts new file mode 100644 index 000000000..3ce416432 --- /dev/null +++ b/src/slang-nodes/YulExpression.ts @@ -0,0 +1,66 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { YulFunctionCallExpression } from './YulFunctionCallExpression.js'; +import { YulLiteral } from './YulLiteral.js'; +import { YulBuiltInFunction } from './YulBuiltInFunction.js'; +import { YulPath } from './YulPath.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class YulExpression implements SlangNode { + readonly kind = NonterminalKind.YulExpression; + + comments; + + loc; + + variant: + | YulFunctionCallExpression + | YulLiteral + | YulBuiltInFunction + | YulPath; + + constructor(ast: ast.YulExpression, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + switch (ast.variant.cst.kind) { + case 'YulFunctionCallExpression': + this.variant = new YulFunctionCallExpression( + ast.variant as ast.YulFunctionCallExpression, + offsets[0], + options + ); + break; + case 'YulLiteral': + this.variant = new YulLiteral( + ast.variant as ast.YulLiteral, + offsets[0], + options + ); + break; + case 'YulBuiltInFunction': + this.variant = new YulBuiltInFunction( + ast.variant as ast.YulBuiltInFunction, + offsets[0] + ); + break; + case 'YulPath': + this.variant = new YulPath(ast.variant as ast.YulPath, offsets[0]); + break; + default: + throw new Error(`Unexpected variant: ${ast.variant.cst.kind}`); + } + + metadata = updateMetadata(metadata, [this.variant]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/YulForStatement.js b/src/slang-nodes/YulForStatement.js deleted file mode 100644 index 7dba95860..000000000 --- a/src/slang-nodes/YulForStatement.js +++ /dev/null @@ -1,47 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { YulBlock } from './YulBlock.js'; -import { YulExpression } from './YulExpression.js'; - -export class YulForStatement extends SlangNode { - get kind() { - return NonterminalKind.YulForStatement; - } - - forKeyword; - - initialization; - - condition; - - iterator; - - body; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - forKeyword: ast.forKeyword.text, - initialization: new YulBlock(ast.initialization, offsets[0], options), - condition: new YulExpression(ast.condition, offsets[1], options), - iterator: new YulBlock(ast.iterator, offsets[2], options), - body: new YulBlock(ast.body, offsets[3], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - `${this.forKeyword} `, - path.call(print, 'initialization'), - ' ', - path.call(print, 'condition'), - ' ', - path.call(print, 'iterator'), - ' ', - path.call(print, 'body') - ]; - } -} diff --git a/src/slang-nodes/YulForStatement.ts b/src/slang-nodes/YulForStatement.ts new file mode 100644 index 000000000..8f12833fe --- /dev/null +++ b/src/slang-nodes/YulForStatement.ts @@ -0,0 +1,64 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { YulBlock } from './YulBlock.js'; +import { YulExpression } from './YulExpression.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class YulForStatement implements SlangNode { + readonly kind = NonterminalKind.YulForStatement; + + comments; + + loc; + + forKeyword: string; + + initialization: YulBlock; + + condition: YulExpression; + + iterator: YulBlock; + + body: YulBlock; + + constructor( + ast: ast.YulForStatement, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.forKeyword = ast.forKeyword.text; + this.initialization = new YulBlock(ast.initialization, offsets[0], options); + this.condition = new YulExpression(ast.condition, offsets[1], options); + this.iterator = new YulBlock(ast.iterator, offsets[2], options); + this.body = new YulBlock(ast.body, offsets[3], options); + + metadata = updateMetadata(metadata, [ + this.initialization, + this.condition, + this.iterator, + this.body + ]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + `${this.forKeyword} `, + path.call(print, 'initialization'), + ' ', + path.call(print, 'condition'), + ' ', + path.call(print, 'iterator'), + ' ', + path.call(print, 'body') + ]; + } +} diff --git a/src/slang-nodes/YulFunctionCallExpression.js b/src/slang-nodes/YulFunctionCallExpression.js deleted file mode 100644 index 752bc14bd..000000000 --- a/src/slang-nodes/YulFunctionCallExpression.js +++ /dev/null @@ -1,40 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { YulExpression } from './YulExpression.js'; -import { YulArguments } from './YulArguments.js'; - -export class YulFunctionCallExpression extends SlangNode { - get kind() { - return NonterminalKind.YulFunctionCallExpression; - } - - operand; - - openParen; - - arguments; - - closeParen; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - operand: new YulExpression(ast.operand, offsets[0], options), - openParen: ast.openParen.text, - arguments: new YulArguments(ast.arguments, offsets[1], options), - closeParen: ast.closeParen.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - path.call(print, 'operand'), - this.openParen, - path.call(print, 'arguments'), - this.closeParen - ]; - } -} diff --git a/src/slang-nodes/YulFunctionCallExpression.ts b/src/slang-nodes/YulFunctionCallExpression.ts new file mode 100644 index 000000000..306145e1a --- /dev/null +++ b/src/slang-nodes/YulFunctionCallExpression.ts @@ -0,0 +1,52 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { YulExpression } from './YulExpression.js'; +import { YulArguments } from './YulArguments.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class YulFunctionCallExpression implements SlangNode { + readonly kind = NonterminalKind.YulFunctionCallExpression; + + comments; + + loc; + + operand: YulExpression; + + openParen: string; + + arguments: YulArguments; + + closeParen: string; + + constructor( + ast: ast.YulFunctionCallExpression, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.operand = new YulExpression(ast.operand, offsets[0], options); + this.openParen = ast.openParen.text; + this.arguments = new YulArguments(ast.arguments, offsets[1], options); + this.closeParen = ast.closeParen.text; + + metadata = updateMetadata(metadata, [this.operand, this.arguments]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + path.call(print, 'operand'), + this.openParen, + path.call(print, 'arguments'), + this.closeParen + ]; + } +} diff --git a/src/slang-nodes/YulFunctionDefinition.js b/src/slang-nodes/YulFunctionDefinition.js deleted file mode 100644 index beebaf025..000000000 --- a/src/slang-nodes/YulFunctionDefinition.js +++ /dev/null @@ -1,54 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { YulParametersDeclaration } from './YulParametersDeclaration.js'; -import { YulReturnsDeclaration } from './YulReturnsDeclaration.js'; -import { YulBlock } from './YulBlock.js'; - -export class YulFunctionDefinition extends SlangNode { - get kind() { - return NonterminalKind.YulFunctionDefinition; - } - - functionKeyword; - - name; - - parameters; - - returns; - - body; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => { - let i = 0; - const children = { - functionKeyword: ast.functionKeyword.text, - name: ast.name.text, - parameters: new YulParametersDeclaration( - ast.parameters, - offsets[0], - options - ), - returns: ast.returns - ? new YulReturnsDeclaration(ast.returns, offsets[(i += 1)], options) - : undefined, - body: new YulBlock(ast.body, offsets[(i += 1)], options) - }; - return children; - }; - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - `${this.functionKeyword} ${this.name}`, - path.call(print, 'parameters'), - this.returns ? path.call(print, 'returns') : ' ', - path.call(print, 'body') - ]; - } -} diff --git a/src/slang-nodes/YulFunctionDefinition.ts b/src/slang-nodes/YulFunctionDefinition.ts new file mode 100644 index 000000000..e653bd5b6 --- /dev/null +++ b/src/slang-nodes/YulFunctionDefinition.ts @@ -0,0 +1,64 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { YulParametersDeclaration } from './YulParametersDeclaration.js'; +import { YulReturnsDeclaration } from './YulReturnsDeclaration.js'; +import { YulBlock } from './YulBlock.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class YulFunctionDefinition implements SlangNode { + readonly kind = NonterminalKind.YulFunctionDefinition; + + comments; + + loc; + + functionKeyword; + + name; + + parameters: YulParametersDeclaration; + + returns?: YulReturnsDeclaration; + + body: YulBlock; + + constructor( + ast: ast.YulFunctionDefinition, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.functionKeyword = ast.functionKeyword.text; + this.name = ast.name.text; + this.parameters = new YulParametersDeclaration(ast.parameters, offsets[0]); + let i = 1; + if (ast.returns) { + this.returns = new YulReturnsDeclaration(ast.returns, offsets[i]); + i += 1; + } + this.body = new YulBlock(ast.body, offsets[i], options); + + metadata = updateMetadata(metadata, [ + this.parameters, + this.returns, + this.body + ]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + `${this.functionKeyword} ${this.name}`, + path.call(print, 'parameters'), + this.returns ? path.call(print, 'returns') : ' ', + path.call(print, 'body') + ]; + } +} diff --git a/src/slang-nodes/YulIfStatement.js b/src/slang-nodes/YulIfStatement.js deleted file mode 100644 index 7d475c694..000000000 --- a/src/slang-nodes/YulIfStatement.js +++ /dev/null @@ -1,37 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { YulExpression } from './YulExpression.js'; -import { YulBlock } from './YulBlock.js'; - -export class YulIfStatement extends SlangNode { - get kind() { - return NonterminalKind.YulIfStatement; - } - - ifKeyword; - - condition; - - body; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - ifKeyword: ast.ifKeyword.text, - condition: new YulExpression(ast.condition, offsets[0], options), - body: new YulBlock(ast.body, offsets[1], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - `${this.ifKeyword} `, - path.call(print, 'condition'), - ' ', - path.call(print, 'body') - ]; - } -} diff --git a/src/slang-nodes/YulIfStatement.ts b/src/slang-nodes/YulIfStatement.ts new file mode 100644 index 000000000..f197722f2 --- /dev/null +++ b/src/slang-nodes/YulIfStatement.ts @@ -0,0 +1,45 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { YulExpression } from './YulExpression.js'; +import { YulBlock } from './YulBlock.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class YulIfStatement implements SlangNode { + readonly kind = NonterminalKind.YulIfStatement; + + comments; + + loc; + + ifKeyword: string; + + condition: YulExpression; + + body: YulBlock; + + constructor(ast: ast.YulIfStatement, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.ifKeyword = ast.ifKeyword.text; + this.condition = new YulExpression(ast.condition, offsets[0], options); + this.body = new YulBlock(ast.body, offsets[1], options); + + metadata = updateMetadata(metadata, [this.condition, this.body]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + `${this.ifKeyword} `, + path.call(print, 'condition'), + ' ', + path.call(print, 'body') + ]; + } +} diff --git a/src/slang-nodes/YulLabel.js b/src/slang-nodes/YulLabel.js deleted file mode 100644 index c9d08a0cd..000000000 --- a/src/slang-nodes/YulLabel.js +++ /dev/null @@ -1,30 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; - -const { dedent, line } = doc.builders; - -export class YulLabel extends SlangNode { - get kind() { - return NonterminalKind.YulLabel; - } - - label; - - colon; - - constructor(ast, offset) { - super(); - - const fetch = () => ({ - label: ast.label.text, - colon: ast.colon.text - }); - - this.initialize(ast, offset, fetch); - } - - print() { - return [dedent(line), `${this.label}${this.colon}`]; - } -} diff --git a/src/slang-nodes/YulLabel.ts b/src/slang-nodes/YulLabel.ts new file mode 100644 index 000000000..dffa9e120 --- /dev/null +++ b/src/slang-nodes/YulLabel.ts @@ -0,0 +1,35 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata } from '../slang-utils/get-offsets.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { dedent, line } = doc.builders; + +export class YulLabel implements SlangNode { + readonly kind = NonterminalKind.YulLabel; + + comments; + + loc; + + label: string; + + colon: string; + + constructor(ast: ast.YulLabel, offset: number) { + const metadata = getNodeMetadata(ast, offset); + + this.label = ast.label.text; + this.colon = ast.colon.text; + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(): Doc { + return [dedent(line), `${this.label}${this.colon}`]; + } +} diff --git a/src/slang-nodes/YulLeaveStatement.js b/src/slang-nodes/YulLeaveStatement.js deleted file mode 100644 index f622c28a9..000000000 --- a/src/slang-nodes/YulLeaveStatement.js +++ /dev/null @@ -1,25 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; - -export class YulLeaveStatement extends SlangNode { - get kind() { - return NonterminalKind.YulLeaveStatement; - } - - leaveKeyword; - - constructor(ast, offset) { - super(); - - const fetch = () => ({ - leaveKeyword: ast.leaveKeyword.text - }); - - this.initialize(ast, offset, fetch); - } - - // TODO: implement print - print(path, print, options) { - return ['TODO: YulLeaveStatement']; - } -} diff --git a/src/slang-nodes/YulLeaveStatement.ts b/src/slang-nodes/YulLeaveStatement.ts new file mode 100644 index 000000000..1017b0c4b --- /dev/null +++ b/src/slang-nodes/YulLeaveStatement.ts @@ -0,0 +1,34 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata } from '../slang-utils/get-offsets.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class YulLeaveStatement implements SlangNode { + readonly kind = NonterminalKind.YulLeaveStatement; + + comments; + + loc; + + leaveKeyword: string; + + constructor(ast: ast.YulLeaveStatement, offset: number) { + const metadata = getNodeMetadata(ast, offset); + + this.leaveKeyword = ast.leaveKeyword.text; + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + // TODO: implement print + print( + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc { + return ['TODO: YulLeaveStatement']; + } +} diff --git a/src/slang-nodes/YulLiteral.js b/src/slang-nodes/YulLiteral.js deleted file mode 100644 index c64e543c9..000000000 --- a/src/slang-nodes/YulLiteral.js +++ /dev/null @@ -1,33 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { HexStringLiteral } from './HexStringLiteral.js'; -import { StringLiteral } from './StringLiteral.js'; - -const variants = { HexStringLiteral, StringLiteral }; - -export class YulLiteral extends SlangNode { - get kind() { - return NonterminalKind.YulLiteral; - } - - variant; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - variant: - ast.variant.type === 'Terminal' - ? ast.variant.text - : new variants[ast.variant.cst.kind](ast.variant, offsets[0], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return typeof this.variant === 'string' - ? this.variant - : path.call(print, 'variant'); - } -} diff --git a/src/slang-nodes/YulLiteral.ts b/src/slang-nodes/YulLiteral.ts new file mode 100644 index 000000000..03a490f16 --- /dev/null +++ b/src/slang-nodes/YulLiteral.ts @@ -0,0 +1,61 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { HexStringLiteral } from './HexStringLiteral.js'; +import { StringLiteral } from './StringLiteral.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class YulLiteral implements SlangNode { + readonly kind = NonterminalKind.YulLiteral; + + comments; + + loc; + + variant: HexStringLiteral | StringLiteral | string; + + constructor(ast: ast.YulLiteral, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + if (ast.variant instanceof TerminalNode) { + this.variant = ast.variant.text; + } else { + switch (ast.variant.cst.kind) { + case 'HexStringLiteral': + this.variant = new HexStringLiteral( + ast.variant as ast.HexStringLiteral, + offsets[0], + options + ); + break; + case 'StringLiteral': + this.variant = new StringLiteral( + ast.variant as ast.StringLiteral, + offsets[0], + options + ); + break; + default: + throw new Error(`Unexpected variant: ${ast.variant.cst.kind}`); + } + } + + metadata = updateMetadata( + metadata, + typeof this.variant === 'string' ? [] : [this.variant] + ); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/YulParameters.js b/src/slang-nodes/YulParameters.js deleted file mode 100644 index fd2e86b76..000000000 --- a/src/slang-nodes/YulParameters.js +++ /dev/null @@ -1,28 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printSeparatedList } from '../common/printer-helpers.js'; -import { SlangNode } from './SlangNode.js'; - -export class YulParameters extends SlangNode { - get kind() { - return NonterminalKind.YulParameters; - } - - items; - - separators; - - constructor(ast, offset) { - super(); - - const fetch = () => ({ - items: ast.items.map((item) => item.text), - separators: ast.separators.map((separator) => separator.text) - }); - - this.initialize(ast, offset, fetch); - } - - print() { - return printSeparatedList(this.items); - } -} diff --git a/src/slang-nodes/YulParameters.ts b/src/slang-nodes/YulParameters.ts new file mode 100644 index 000000000..3e2f1020a --- /dev/null +++ b/src/slang-nodes/YulParameters.ts @@ -0,0 +1,33 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printSeparatedList } from '../slang-printers/print-separated-list.js'; +import { getNodeMetadata } from '../slang-utils/get-offsets.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class YulParameters implements SlangNode { + readonly kind = NonterminalKind.YulParameters; + + comments; + + loc; + + items: string[]; + + separators: string[]; + + constructor(ast: ast.YulParameters, offset: number) { + const metadata = getNodeMetadata(ast, offset); + + this.items = ast.items.map((item) => item.text); + this.separators = ast.separators.map((separator) => separator.text); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(): Doc { + return printSeparatedList(this.items); + } +} diff --git a/src/slang-nodes/YulParametersDeclaration.js b/src/slang-nodes/YulParametersDeclaration.js deleted file mode 100644 index 1621cf327..000000000 --- a/src/slang-nodes/YulParametersDeclaration.js +++ /dev/null @@ -1,31 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { YulParameters } from './YulParameters.js'; - -export class YulParametersDeclaration extends SlangNode { - get kind() { - return NonterminalKind.YulParametersDeclaration; - } - - openParen; - - parameters; - - closeParen; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - openParen: ast.openParen.text, - parameters: new YulParameters(ast.parameters, offsets[0], options), - closeParen: ast.closeParen.text - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [this.openParen, path.call(print, 'parameters'), this.closeParen]; - } -} diff --git a/src/slang-nodes/YulParametersDeclaration.ts b/src/slang-nodes/YulParametersDeclaration.ts new file mode 100644 index 000000000..6d6d30dd8 --- /dev/null +++ b/src/slang-nodes/YulParametersDeclaration.ts @@ -0,0 +1,39 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { YulParameters } from './YulParameters.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class YulParametersDeclaration implements SlangNode { + readonly kind = NonterminalKind.YulParametersDeclaration; + + comments; + + loc; + + openParen: string; + + parameters: YulParameters; + + closeParen: string; + + constructor(ast: ast.YulParametersDeclaration, offset: number) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.openParen = ast.openParen.text; + this.parameters = new YulParameters(ast.parameters, offsets[0]); + this.closeParen = ast.closeParen.text; + + metadata = updateMetadata(metadata, [this.parameters]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [this.openParen, path.call(print, 'parameters'), this.closeParen]; + } +} diff --git a/src/slang-nodes/YulPath.js b/src/slang-nodes/YulPath.js deleted file mode 100644 index 425e62110..000000000 --- a/src/slang-nodes/YulPath.js +++ /dev/null @@ -1,34 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { YulPathComponent } from './YulPathComponent.js'; - -export class YulPath extends SlangNode { - get kind() { - return NonterminalKind.YulPath; - } - - items; - - separators; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => new YulPathComponent(item, offsets[index], options) - ), - separators: ast.separators.map((separator) => separator.text) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return path - .map(print, 'items') - .map((item, index) => - index === 0 ? item : [this.separators[index - 1], item] - ); - } -} diff --git a/src/slang-nodes/YulPath.ts b/src/slang-nodes/YulPath.ts new file mode 100644 index 000000000..ea608f27b --- /dev/null +++ b/src/slang-nodes/YulPath.ts @@ -0,0 +1,42 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { YulPathComponent } from './YulPathComponent.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class YulPath implements SlangNode { + readonly kind = NonterminalKind.YulPath; + + comments; + + loc; + + items: YulPathComponent[]; + + separators: string[]; + + constructor(ast: ast.YulPath, offset: number) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => new YulPathComponent(item, offsets[index]) + ); + this.separators = ast.separators.map((separator) => separator.text); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return path + .map(print, 'items') + .map((item, index) => + index === 0 ? item : [this.separators[index - 1], item] + ); + } +} diff --git a/src/slang-nodes/YulPathComponent.js b/src/slang-nodes/YulPathComponent.js deleted file mode 100644 index a55386a20..000000000 --- a/src/slang-nodes/YulPathComponent.js +++ /dev/null @@ -1,24 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; - -export class YulPathComponent extends SlangNode { - get kind() { - return NonterminalKind.YulPathComponent; - } - - variant; - - constructor(ast, offset) { - super(); - - const fetch = () => ({ - variant: ast.variant.text - }); - - this.initialize(ast, offset, fetch); - } - - print() { - return this.variant; - } -} diff --git a/src/slang-nodes/YulPathComponent.ts b/src/slang-nodes/YulPathComponent.ts new file mode 100644 index 000000000..a9ff32ec5 --- /dev/null +++ b/src/slang-nodes/YulPathComponent.ts @@ -0,0 +1,29 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata } from '../slang-utils/get-offsets.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class YulPathComponent implements SlangNode { + readonly kind = NonterminalKind.YulPathComponent; + + comments; + + loc; + + variant: string; + + constructor(ast: ast.YulPathComponent, offset: number) { + const metadata = getNodeMetadata(ast, offset); + + this.variant = ast.variant.text; + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(): Doc { + return this.variant; + } +} diff --git a/src/slang-nodes/YulPaths.js b/src/slang-nodes/YulPaths.js deleted file mode 100644 index 5581fbd29..000000000 --- a/src/slang-nodes/YulPaths.js +++ /dev/null @@ -1,34 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { YulPath } from './YulPath.js'; - -export class YulPaths extends SlangNode { - get kind() { - return NonterminalKind.YulPaths; - } - - items; - - separators; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => new YulPath(item, offsets[index], options) - ), - separators: ast.separators.map((separator) => separator.text) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return path - .map(print, 'items') - .map((item, index) => - index === 0 ? item : [this.separators[index - 1], item] - ); - } -} diff --git a/src/slang-nodes/YulPaths.ts b/src/slang-nodes/YulPaths.ts new file mode 100644 index 000000000..840d079d2 --- /dev/null +++ b/src/slang-nodes/YulPaths.ts @@ -0,0 +1,42 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { YulPath } from './YulPath.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class YulPaths implements SlangNode { + readonly kind = NonterminalKind.YulPaths; + + comments; + + loc; + + items: YulPath[]; + + separators: string[]; + + constructor(ast: ast.YulPaths, offset: number) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => new YulPath(item, offsets[index]) + ); + this.separators = ast.separators.map((separator) => separator.text); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return path + .map(print, 'items') + .map((item, index) => + index === 0 ? item : [this.separators[index - 1], item] + ); + } +} diff --git a/src/slang-nodes/YulReturnVariables.js b/src/slang-nodes/YulReturnVariables.js deleted file mode 100644 index 56366b85d..000000000 --- a/src/slang-nodes/YulReturnVariables.js +++ /dev/null @@ -1,34 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printSeparatedList } from '../common/printer-helpers.js'; -import { SlangNode } from './SlangNode.js'; - -const { line } = doc.builders; - -export class YulReturnVariables extends SlangNode { - get kind() { - return NonterminalKind.YulReturnVariables; - } - - items; - - separators; - - constructor(ast, offset) { - super(); - - const fetch = () => ({ - items: ast.items.map((item) => item.text), - separators: ast.separators.map((separator) => separator.text) - }); - - this.initialize(ast, offset, fetch); - } - - print() { - return printSeparatedList(this.items, { - firstSeparator: line, - lastSeparator: '' - }); - } -} diff --git a/src/slang-nodes/YulReturnVariables.ts b/src/slang-nodes/YulReturnVariables.ts new file mode 100644 index 000000000..3a66f9d7d --- /dev/null +++ b/src/slang-nodes/YulReturnVariables.ts @@ -0,0 +1,39 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printSeparatedList } from '../slang-printers/print-separated-list.js'; +import { getNodeMetadata } from '../slang-utils/get-offsets.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { line } = doc.builders; + +export class YulReturnVariables implements SlangNode { + readonly kind = NonterminalKind.YulReturnVariables; + + comments; + + loc; + + items: string[]; + + separators: string[]; + + constructor(ast: ast.YulReturnVariables, offset: number) { + const metadata = getNodeMetadata(ast, offset); + + this.items = ast.items.map((item) => item.text); + this.separators = ast.separators.map((separator) => separator.text); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(): Doc { + return printSeparatedList(this.items, { + firstSeparator: line, + lastSeparator: '' + }); + } +} diff --git a/src/slang-nodes/YulReturnsDeclaration.js b/src/slang-nodes/YulReturnsDeclaration.js deleted file mode 100644 index 87b77e6e2..000000000 --- a/src/slang-nodes/YulReturnsDeclaration.js +++ /dev/null @@ -1,37 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printSeparatedItem } from '../common/printer-helpers.js'; -import { SlangNode } from './SlangNode.js'; -import { YulReturnVariables } from './YulReturnVariables.js'; - -const { line } = doc.builders; - -export class YulReturnsDeclaration extends SlangNode { - get kind() { - return NonterminalKind.YulReturnsDeclaration; - } - - minusGreaterThan; - - variables; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - minusGreaterThan: ast.minusGreaterThan.text, - variables: new YulReturnVariables(ast.variables, offsets[0], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return printSeparatedItem( - [this.minusGreaterThan, path.call(print, 'variables')], - { - firstSeparator: line - } - ); - } -} diff --git a/src/slang-nodes/YulReturnsDeclaration.ts b/src/slang-nodes/YulReturnsDeclaration.ts new file mode 100644 index 000000000..d8eb98aa2 --- /dev/null +++ b/src/slang-nodes/YulReturnsDeclaration.ts @@ -0,0 +1,45 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printSeparatedItem } from '../slang-printers/print-separated-item.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { YulReturnVariables } from './YulReturnVariables.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { line } = doc.builders; + +export class YulReturnsDeclaration implements SlangNode { + readonly kind = NonterminalKind.YulReturnsDeclaration; + + comments; + + loc; + + minusGreaterThan: string; + + variables: YulReturnVariables; + + constructor(ast: ast.YulReturnsDeclaration, offset: number) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.minusGreaterThan = ast.minusGreaterThan.text; + this.variables = new YulReturnVariables(ast.variables, offsets[0]); + + metadata = updateMetadata(metadata, [this.variables]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return printSeparatedItem( + [this.minusGreaterThan, path.call(print, 'variables')], + { + firstSeparator: line + } + ); + } +} diff --git a/src/slang-nodes/YulStackAssignmentStatement.js b/src/slang-nodes/YulStackAssignmentStatement.js deleted file mode 100644 index a99a0db7e..000000000 --- a/src/slang-nodes/YulStackAssignmentStatement.js +++ /dev/null @@ -1,34 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { YulAssignmentOperator } from './YulAssignmentOperator.js'; -import { YulExpression } from './YulExpression.js'; - -export class YulStackAssignmentStatement extends SlangNode { - get kind() { - return NonterminalKind.YulStackAssignmentStatement; - } - - assignment; - - expression; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - assignment: new YulAssignmentOperator( - ast.assignment, - offsets[0], - options - ), - expression: new YulExpression(ast.expression, offsets[1], options) - }); - - this.initialize(ast, offset, fetch); - } - - // TODO: implement print - print(path, print, options) { - return ['TODO: YulStackAssignmentStatement']; - } -} diff --git a/src/slang-nodes/YulStackAssignmentStatement.ts b/src/slang-nodes/YulStackAssignmentStatement.ts new file mode 100644 index 000000000..c5bacb471 --- /dev/null +++ b/src/slang-nodes/YulStackAssignmentStatement.ts @@ -0,0 +1,46 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { YulAssignmentOperator } from './YulAssignmentOperator.js'; +import { YulExpression } from './YulExpression.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class YulStackAssignmentStatement implements SlangNode { + readonly kind = NonterminalKind.YulStackAssignmentStatement; + + comments; + + loc; + + assignment: YulAssignmentOperator; + + expression: YulExpression; + + constructor( + ast: ast.YulStackAssignmentStatement, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.assignment = new YulAssignmentOperator(ast.assignment, offsets[0]); + this.expression = new YulExpression(ast.expression, offsets[1], options); + + metadata = updateMetadata(metadata, [this.assignment, this.expression]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + // TODO: implement print + print( + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc { + return ['TODO: YulStackAssignmentStatement']; + } +} diff --git a/src/slang-nodes/YulStatement.js b/src/slang-nodes/YulStatement.js deleted file mode 100644 index 3204e58a0..000000000 --- a/src/slang-nodes/YulStatement.js +++ /dev/null @@ -1,57 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { YulBlock } from './YulBlock.js'; -import { YulFunctionDefinition } from './YulFunctionDefinition.js'; -import { YulVariableDeclarationStatement } from './YulVariableDeclarationStatement.js'; -import { YulVariableAssignmentStatement } from './YulVariableAssignmentStatement.js'; -import { YulStackAssignmentStatement } from './YulStackAssignmentStatement.js'; -import { YulIfStatement } from './YulIfStatement.js'; -import { YulForStatement } from './YulForStatement.js'; -import { YulSwitchStatement } from './YulSwitchStatement.js'; -import { YulLeaveStatement } from './YulLeaveStatement.js'; -import { YulBreakStatement } from './YulBreakStatement.js'; -import { YulContinueStatement } from './YulContinueStatement.js'; -import { YulLabel } from './YulLabel.js'; -import { YulExpression } from './YulExpression.js'; - -const variants = { - YulBlock, - YulFunctionDefinition, - YulVariableDeclarationStatement, - YulVariableAssignmentStatement, - YulStackAssignmentStatement, - YulIfStatement, - YulForStatement, - YulSwitchStatement, - YulLeaveStatement, - YulBreakStatement, - YulContinueStatement, - YulLabel, - YulExpression -}; - -export class YulStatement extends SlangNode { - get kind() { - return NonterminalKind.YulStatement; - } - - variant; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - variant: new variants[ast.variant.cst.kind]( - ast.variant, - offsets[0], - options - ) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return path.call(print, 'variant'); - } -} diff --git a/src/slang-nodes/YulStatement.ts b/src/slang-nodes/YulStatement.ts new file mode 100644 index 000000000..96fe2512e --- /dev/null +++ b/src/slang-nodes/YulStatement.ts @@ -0,0 +1,145 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { YulBlock } from './YulBlock.js'; +import { YulFunctionDefinition } from './YulFunctionDefinition.js'; +import { YulVariableDeclarationStatement } from './YulVariableDeclarationStatement.js'; +import { YulVariableAssignmentStatement } from './YulVariableAssignmentStatement.js'; +import { YulStackAssignmentStatement } from './YulStackAssignmentStatement.js'; +import { YulIfStatement } from './YulIfStatement.js'; +import { YulForStatement } from './YulForStatement.js'; +import { YulSwitchStatement } from './YulSwitchStatement.js'; +import { YulLeaveStatement } from './YulLeaveStatement.js'; +import { YulBreakStatement } from './YulBreakStatement.js'; +import { YulContinueStatement } from './YulContinueStatement.js'; +import { YulLabel } from './YulLabel.js'; +import { YulExpression } from './YulExpression.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class YulStatement implements SlangNode { + readonly kind = NonterminalKind.YulStatement; + + comments; + + loc; + + variant: + | YulBlock + | YulFunctionDefinition + | YulVariableDeclarationStatement + | YulVariableAssignmentStatement + | YulStackAssignmentStatement + | YulIfStatement + | YulForStatement + | YulSwitchStatement + | YulLeaveStatement + | YulBreakStatement + | YulContinueStatement + | YulLabel + | YulExpression; + + constructor(ast: ast.YulStatement, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + switch (ast.variant.cst.kind) { + case 'YulBlock': + this.variant = new YulBlock( + ast.variant as ast.YulBlock, + offsets[0], + options + ); + break; + case 'YulFunctionDefinition': + this.variant = new YulFunctionDefinition( + ast.variant as ast.YulFunctionDefinition, + offsets[0], + options + ); + break; + case 'YulVariableDeclarationStatement': + this.variant = new YulVariableDeclarationStatement( + ast.variant as ast.YulVariableDeclarationStatement, + offsets[0], + options + ); + break; + case 'YulVariableAssignmentStatement': + this.variant = new YulVariableAssignmentStatement( + ast.variant as ast.YulVariableAssignmentStatement, + offsets[0], + options + ); + break; + case 'YulStackAssignmentStatement': + this.variant = new YulStackAssignmentStatement( + ast.variant as ast.YulStackAssignmentStatement, + offsets[0], + options + ); + break; + case 'YulIfStatement': + this.variant = new YulIfStatement( + ast.variant as ast.YulIfStatement, + offsets[0], + options + ); + break; + case 'YulForStatement': + this.variant = new YulForStatement( + ast.variant as ast.YulForStatement, + offsets[0], + options + ); + break; + case 'YulSwitchStatement': + this.variant = new YulSwitchStatement( + ast.variant as ast.YulSwitchStatement, + offsets[0], + options + ); + break; + case 'YulLeaveStatement': + this.variant = new YulLeaveStatement( + ast.variant as ast.YulLeaveStatement, + offsets[0] + ); + break; + case 'YulBreakStatement': + this.variant = new YulBreakStatement( + ast.variant as ast.YulBreakStatement, + offsets[0] + ); + break; + case 'YulContinueStatement': + this.variant = new YulContinueStatement( + ast.variant as ast.YulContinueStatement, + offsets[0] + ); + break; + case 'YulLabel': + this.variant = new YulLabel(ast.variant as ast.YulLabel, offsets[0]); + break; + case 'YulExpression': + this.variant = new YulExpression( + ast.variant as ast.YulExpression, + offsets[0], + options + ); + break; + default: + throw new Error(`Unexpected variant: ${ast.variant.cst.kind}`); + } + + metadata = updateMetadata(metadata, [this.variant]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/YulStatements.js b/src/slang-nodes/YulStatements.js deleted file mode 100644 index d41c1ae10..000000000 --- a/src/slang-nodes/YulStatements.js +++ /dev/null @@ -1,45 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { printSeparatedItem } from '../common/printer-helpers.js'; -import { printComments } from '../slang-printers/print-comments.js'; -import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; -import { SlangNode } from './SlangNode.js'; -import { YulStatement } from './YulStatement.js'; - -const { hardline } = doc.builders; - -export class YulStatements extends SlangNode { - get kind() { - return NonterminalKind.YulStatements; - } - - items; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => new YulStatement(item, offsets[index], options) - ) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print, options) { - return this.items.length === 0 && - (!this.comments || this.comments.length === 0) - ? '' - : printSeparatedItem( - [ - printPreservingEmptyLines(path, 'items', options, print), - printComments(this, path, options) - ], - { - firstSeparator: hardline, - grouped: false - } - ); - } -} diff --git a/src/slang-nodes/YulStatements.ts b/src/slang-nodes/YulStatements.ts new file mode 100644 index 000000000..6374f103e --- /dev/null +++ b/src/slang-nodes/YulStatements.ts @@ -0,0 +1,57 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printSeparatedItem } from '../slang-printers/print-separated-item.js'; +import { printComments } from '../slang-printers/print-comments.js'; +import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { YulStatement } from './YulStatement.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { hardline } = doc.builders; + +export class YulStatements implements SlangNode { + readonly kind = NonterminalKind.YulStatements; + + comments; + + loc; + + items: YulStatement[]; + + constructor(ast: ast.YulStatements, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => new YulStatement(item, offsets[index], options) + ); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print( + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc { + return this.items.length === 0 && + (!this.comments || this.comments.length === 0) + ? '' + : printSeparatedItem( + [ + printPreservingEmptyLines(path, 'items', print, options), + printComments(this, path) + ], + { + firstSeparator: hardline, + grouped: false + } + ); + } +} diff --git a/src/slang-nodes/YulSwitchCase.js b/src/slang-nodes/YulSwitchCase.js deleted file mode 100644 index f36bb16c4..000000000 --- a/src/slang-nodes/YulSwitchCase.js +++ /dev/null @@ -1,31 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { YulDefaultCase } from './YulDefaultCase.js'; -import { YulValueCase } from './YulValueCase.js'; - -const variants = { YulDefaultCase, YulValueCase }; -export class YulSwitchCase extends SlangNode { - get kind() { - return NonterminalKind.YulSwitchCase; - } - - variant; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - variant: new variants[ast.variant.cst.kind]( - ast.variant, - offsets[0], - options - ) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return path.call(print, 'variant'); - } -} diff --git a/src/slang-nodes/YulSwitchCase.ts b/src/slang-nodes/YulSwitchCase.ts new file mode 100644 index 000000000..915ba741b --- /dev/null +++ b/src/slang-nodes/YulSwitchCase.ts @@ -0,0 +1,51 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { YulDefaultCase } from './YulDefaultCase.js'; +import { YulValueCase } from './YulValueCase.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class YulSwitchCase implements SlangNode { + readonly kind = NonterminalKind.YulSwitchCase; + + comments; + + loc; + + variant: YulDefaultCase | YulValueCase; + + constructor(ast: ast.YulSwitchCase, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + switch (ast.variant.cst.kind) { + case 'YulDefaultCase': + this.variant = new YulDefaultCase( + ast.variant as ast.YulDefaultCase, + offsets[0], + options + ); + break; + case 'YulValueCase': + this.variant = new YulValueCase( + ast.variant as ast.YulValueCase, + offsets[0], + options + ); + break; + default: + throw new Error(`Unexpected variant: ${ast.variant.cst.kind}`); + } + + metadata = updateMetadata(metadata, [this.variant]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/YulSwitchCases.js b/src/slang-nodes/YulSwitchCases.js deleted file mode 100644 index d064fb7f6..000000000 --- a/src/slang-nodes/YulSwitchCases.js +++ /dev/null @@ -1,30 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { YulSwitchCase } from './YulSwitchCase.js'; - -const { hardline, join } = doc.builders; - -export class YulSwitchCases extends SlangNode { - get kind() { - return NonterminalKind.YulSwitchCases; - } - - items; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - items: ast.items.map( - (item, index) => new YulSwitchCase(item, offsets[index], options) - ) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return join(hardline, path.map(print, 'items')); - } -} diff --git a/src/slang-nodes/YulSwitchCases.ts b/src/slang-nodes/YulSwitchCases.ts new file mode 100644 index 000000000..7bac38a30 --- /dev/null +++ b/src/slang-nodes/YulSwitchCases.ts @@ -0,0 +1,38 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { YulSwitchCase } from './YulSwitchCase.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { hardline, join } = doc.builders; + +export class YulSwitchCases implements SlangNode { + readonly kind = NonterminalKind.YulSwitchCases; + + comments; + + loc; + + items: YulSwitchCase[]; + + constructor(ast: ast.YulSwitchCases, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.items = ast.items.map( + (item, index) => new YulSwitchCase(item, offsets[index], options) + ); + + metadata = updateMetadata(metadata, [this.items]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return join(hardline, path.map(print, 'items')); + } +} diff --git a/src/slang-nodes/YulSwitchStatement.js b/src/slang-nodes/YulSwitchStatement.js deleted file mode 100644 index 4318599e7..000000000 --- a/src/slang-nodes/YulSwitchStatement.js +++ /dev/null @@ -1,40 +0,0 @@ -import { doc } from 'prettier'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { YulExpression } from './YulExpression.js'; -import { YulSwitchCases } from './YulSwitchCases.js'; - -const { hardline } = doc.builders; - -export class YulSwitchStatement extends SlangNode { - get kind() { - return NonterminalKind.YulSwitchStatement; - } - - switchKeyword; - - expression; - - cases; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - switchKeyword: ast.switchKeyword.text, - expression: new YulExpression(ast.expression, offsets[0], options), - cases: new YulSwitchCases(ast.cases, offsets[1], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - `${this.switchKeyword} `, - path.call(print, 'expression'), - hardline, - path.call(print, 'cases') - ]; - } -} diff --git a/src/slang-nodes/YulSwitchStatement.ts b/src/slang-nodes/YulSwitchStatement.ts new file mode 100644 index 000000000..1e0f560ef --- /dev/null +++ b/src/slang-nodes/YulSwitchStatement.ts @@ -0,0 +1,52 @@ +import { doc } from 'prettier'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { YulExpression } from './YulExpression.js'; +import { YulSwitchCases } from './YulSwitchCases.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +const { hardline } = doc.builders; + +export class YulSwitchStatement implements SlangNode { + readonly kind = NonterminalKind.YulSwitchStatement; + + comments; + + loc; + + switchKeyword: string; + + expression: YulExpression; + + cases: YulSwitchCases; + + constructor( + ast: ast.YulSwitchStatement, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.switchKeyword = ast.switchKeyword.text; + this.expression = new YulExpression(ast.expression, offsets[0], options); + this.cases = new YulSwitchCases(ast.cases, offsets[1], options); + + metadata = updateMetadata(metadata, [this.expression, this.cases]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + `${this.switchKeyword} `, + path.call(print, 'expression'), + hardline, + path.call(print, 'cases') + ]; + } +} diff --git a/src/slang-nodes/YulValueCase.js b/src/slang-nodes/YulValueCase.js deleted file mode 100644 index e13d8a7b1..000000000 --- a/src/slang-nodes/YulValueCase.js +++ /dev/null @@ -1,37 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { YulLiteral } from './YulLiteral.js'; -import { YulBlock } from './YulBlock.js'; - -export class YulValueCase extends SlangNode { - get kind() { - return NonterminalKind.YulValueCase; - } - - caseKeyword; - - value; - - body; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - caseKeyword: ast.caseKeyword.text, - value: new YulLiteral(ast.value, offsets[0], options), - body: new YulBlock(ast.body, offsets[1], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - `${this.caseKeyword} `, - path.call(print, 'value'), - ' ', - path.call(print, 'body') - ]; - } -} diff --git a/src/slang-nodes/YulValueCase.ts b/src/slang-nodes/YulValueCase.ts new file mode 100644 index 000000000..be8005f44 --- /dev/null +++ b/src/slang-nodes/YulValueCase.ts @@ -0,0 +1,45 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { YulLiteral } from './YulLiteral.js'; +import { YulBlock } from './YulBlock.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class YulValueCase implements SlangNode { + readonly kind = NonterminalKind.YulValueCase; + + comments; + + loc; + + caseKeyword: string; + + value: YulLiteral; + + body: YulBlock; + + constructor(ast: ast.YulValueCase, offset: number, options: ParserOptions) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.caseKeyword = ast.caseKeyword.text; + this.value = new YulLiteral(ast.value, offsets[0], options); + this.body = new YulBlock(ast.body, offsets[1], options); + + metadata = updateMetadata(metadata, [this.value, this.body]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + `${this.caseKeyword} `, + path.call(print, 'value'), + ' ', + path.call(print, 'body') + ]; + } +} diff --git a/src/slang-nodes/YulVariableAssignmentStatement.js b/src/slang-nodes/YulVariableAssignmentStatement.js deleted file mode 100644 index 38d9dcd75..000000000 --- a/src/slang-nodes/YulVariableAssignmentStatement.js +++ /dev/null @@ -1,43 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { YulPaths } from './YulPaths.js'; -import { YulAssignmentOperator } from './YulAssignmentOperator.js'; -import { YulExpression } from './YulExpression.js'; - -export class YulVariableAssignmentStatement extends SlangNode { - get kind() { - return NonterminalKind.YulVariableAssignmentStatement; - } - - names; - - assignment; - - expression; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - names: new YulPaths(ast.names, offsets[0], options), - assignment: new YulAssignmentOperator( - ast.assignment, - offsets[1], - options - ), - expression: new YulExpression(ast.expression, offsets[2], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - path.call(print, 'names'), - ' ', - path.call(print, 'assignment'), - ' ', - path.call(print, 'expression') - ]; - } -} diff --git a/src/slang-nodes/YulVariableAssignmentStatement.ts b/src/slang-nodes/YulVariableAssignmentStatement.ts new file mode 100644 index 000000000..15d6decc4 --- /dev/null +++ b/src/slang-nodes/YulVariableAssignmentStatement.ts @@ -0,0 +1,55 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { YulPaths } from './YulPaths.js'; +import { YulAssignmentOperator } from './YulAssignmentOperator.js'; +import { YulExpression } from './YulExpression.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class YulVariableAssignmentStatement implements SlangNode { + readonly kind = NonterminalKind.YulVariableAssignmentStatement; + + comments; + + loc; + + names: YulPaths; + + assignment: YulAssignmentOperator; + + expression: YulExpression; + + constructor( + ast: ast.YulVariableAssignmentStatement, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.names = new YulPaths(ast.names, offsets[0]); + this.assignment = new YulAssignmentOperator(ast.assignment, offsets[1]); + this.expression = new YulExpression(ast.expression, offsets[2], options); + + metadata = updateMetadata(metadata, [ + this.names, + this.assignment, + this.expression + ]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + path.call(print, 'names'), + ' ', + path.call(print, 'assignment'), + ' ', + path.call(print, 'expression') + ]; + } +} diff --git a/src/slang-nodes/YulVariableDeclarationStatement.js b/src/slang-nodes/YulVariableDeclarationStatement.js deleted file mode 100644 index 7b83d0b57..000000000 --- a/src/slang-nodes/YulVariableDeclarationStatement.js +++ /dev/null @@ -1,36 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { YulVariableDeclarationValue } from './YulVariableDeclarationValue.js'; - -export class YulVariableDeclarationStatement extends SlangNode { - get kind() { - return NonterminalKind.YulVariableDeclarationStatement; - } - - letKeyword; - - names; - - value; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - letKeyword: ast.letKeyword.text, - names: ast.names.text, - value: ast.value - ? new YulVariableDeclarationValue(ast.value, offsets[0], options) - : undefined - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - `${this.letKeyword} ${this.names} `, - this.value ? path.call(print, 'value') : '' - ]; - } -} diff --git a/src/slang-nodes/YulVariableDeclarationStatement.ts b/src/slang-nodes/YulVariableDeclarationStatement.ts new file mode 100644 index 000000000..93b5bbd05 --- /dev/null +++ b/src/slang-nodes/YulVariableDeclarationStatement.ts @@ -0,0 +1,52 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { YulVariableDeclarationValue } from './YulVariableDeclarationValue.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class YulVariableDeclarationStatement implements SlangNode { + readonly kind = NonterminalKind.YulVariableDeclarationStatement; + + comments; + + loc; + + letKeyword: string; + + names: string; + + value?: YulVariableDeclarationValue; + + constructor( + ast: ast.YulVariableDeclarationStatement, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.letKeyword = ast.letKeyword.text; + this.names = ast.names.text; + if (ast.value) { + this.value = new YulVariableDeclarationValue( + ast.value, + offsets[0], + options + ); + } + + metadata = updateMetadata(metadata, [this.value]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + `${this.letKeyword} ${this.names} `, + this.value ? path.call(print, 'value') : '' + ]; + } +} diff --git a/src/slang-nodes/YulVariableDeclarationValue.js b/src/slang-nodes/YulVariableDeclarationValue.js deleted file mode 100644 index 3276caf03..000000000 --- a/src/slang-nodes/YulVariableDeclarationValue.js +++ /dev/null @@ -1,37 +0,0 @@ -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SlangNode } from './SlangNode.js'; -import { YulAssignmentOperator } from './YulAssignmentOperator.js'; -import { YulExpression } from './YulExpression.js'; - -export class YulVariableDeclarationValue extends SlangNode { - get kind() { - return NonterminalKind.YulVariableDeclarationValue; - } - - assignment; - - expression; - - constructor(ast, offset, options) { - super(); - - const fetch = (offsets) => ({ - assignment: new YulAssignmentOperator( - ast.assignment, - offsets[0], - options - ), - expression: new YulExpression(ast.expression, offsets[1], options) - }); - - this.initialize(ast, offset, fetch); - } - - print(path, print) { - return [ - path.call(print, 'assignment'), - ' ', - path.call(print, 'expression') - ]; - } -} diff --git a/src/slang-nodes/YulVariableDeclarationValue.ts b/src/slang-nodes/YulVariableDeclarationValue.ts new file mode 100644 index 000000000..04824147d --- /dev/null +++ b/src/slang-nodes/YulVariableDeclarationValue.ts @@ -0,0 +1,45 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { YulAssignmentOperator } from './YulAssignmentOperator.js'; +import { YulExpression } from './YulExpression.js'; + +import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { SlangNode } from '../types.js'; + +export class YulVariableDeclarationValue implements SlangNode { + readonly kind = NonterminalKind.YulVariableDeclarationValue; + + comments; + + loc; + + assignment: YulAssignmentOperator; + + expression: YulExpression; + + constructor( + ast: ast.YulVariableDeclarationValue, + offset: number, + options: ParserOptions + ) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.assignment = new YulAssignmentOperator(ast.assignment, offsets[0]); + this.expression = new YulExpression(ast.expression, offsets[1], options); + + metadata = updateMetadata(metadata, [this.assignment, this.expression]); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: (path: AstPath) => Doc): Doc { + return [ + path.call(print, 'assignment'), + ' ', + path.call(print, 'expression') + ]; + } +} diff --git a/src/slang-nodes/index.js b/src/slang-nodes/index.ts similarity index 99% rename from src/slang-nodes/index.js rename to src/slang-nodes/index.ts index f25097c65..1b78ec307 100644 --- a/src/slang-nodes/index.js +++ b/src/slang-nodes/index.ts @@ -1,7 +1,3 @@ -export * from './YulStatement.js'; -export * from './Expression.js'; -export * from './Statement.js'; - export * from './ABICoderPragma.js'; export * from './AdditiveExpression.js'; export * from './AddressType.js'; @@ -53,6 +49,7 @@ export * from './EventParametersDeclaration.js'; export * from './ExperimentalFeature.js'; export * from './ExperimentalPragma.js'; export * from './ExponentiationExpression.js'; +export * from './Expression.js'; export * from './ExpressionStatement.js'; export * from './FallbackFunctionAttribute.js'; export * from './FallbackFunctionAttributes.js'; @@ -131,6 +128,7 @@ export * from './ShiftExpression.js'; export * from './SourceUnit.js'; export * from './SourceUnitMember.js'; export * from './SourceUnitMembers.js'; +export * from './Statement.js'; export * from './Statements.js'; export * from './StateVariableAttribute.js'; export * from './StateVariableAttributes.js'; @@ -206,6 +204,7 @@ export * from './YulPaths.js'; export * from './YulReturnsDeclaration.js'; export * from './YulReturnVariables.js'; export * from './YulStackAssignmentStatement.js'; +export * from './YulStatement.js'; export * from './YulStatements.js'; export * from './YulSwitchCase.js'; export * from './YulSwitchCases.js'; diff --git a/src/slang-printers/create-binary-operation-printer.js b/src/slang-printers/create-binary-operation-printer.ts similarity index 60% rename from src/slang-printers/create-binary-operation-printer.js rename to src/slang-printers/create-binary-operation-printer.ts index 1ac732228..161004438 100644 --- a/src/slang-printers/create-binary-operation-printer.js +++ b/src/slang-printers/create-binary-operation-printer.ts @@ -1,9 +1,16 @@ import { doc } from 'prettier'; import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { BinaryOperation } from '../types.js'; + const { group, line } = doc.builders; -function rightOperandPrint(node, path, print) { +function rightOperandPrint( + node: BinaryOperation, + path: AstPath, + print: (path: AstPath) => Doc +): Doc { const rightOperand = [line, path.call(print, 'rightOperand')]; // If it's a single binary operation, avoid having a small right @@ -16,8 +23,19 @@ function rightOperandPrint(node, path, print) { } export const createBinaryOperationPrinter = - (groupRulesBuilder, indentRulesBuilder) => - ({ node, path, print, options }) => { + ( + groupRulesBuilder: (path: AstPath) => (document: Doc) => Doc, + indentRulesBuilder: ( + path: AstPath, + options: ParserOptions + ) => (document: Doc) => Doc + ) => + ( + node: BinaryOperation, + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc => { const groupRules = groupRulesBuilder(path); const indentRules = indentRulesBuilder(path, options); diff --git a/src/slang-printers/print-binary-operation.js b/src/slang-printers/print-binary-operation.js deleted file mode 100644 index 6aee39f90..000000000 --- a/src/slang-printers/print-binary-operation.js +++ /dev/null @@ -1,45 +0,0 @@ -import { doc } from 'prettier'; -import { createBinaryOperationPrinter } from './create-binary-operation-printer.js'; -import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js'; - -const { group, indent } = doc.builders; - -const isBinaryOperationWithoutComparison = createKindCheckFunction([ - 'AdditiveExpression', - 'MultiplicativeExpression', - 'ExponentiationExpression', - 'AssignmentExpression', - 'BitwiseAndExpression', - 'BitwiseOrExpression', - 'BitwiseXorExpression', - 'AndExpression', - 'OrExpression', - 'ShiftExpression' -]); - -const binaryGroupRulesBuilder = (path) => (document) => { - const grandparentNode = path.getNode(2); - if (isBinaryOperationWithoutComparison(grandparentNode)) { - return document; - } - return group(document); -}; - -const binaryIndentRulesBuilder = (path) => (document) => { - let node = path.getNode(); - for (let i = 2; ; i += 2) { - const grandparentNode = path.getNode(i); - if (grandparentNode.kind === 'ReturnStatement') break; - if (!isBinaryOperationWithoutComparison(grandparentNode)) { - return indent(document); - } - if (node === grandparentNode.rightOperand.variant) break; - node = grandparentNode; - } - return document; -}; - -export const printBinaryOperation = createBinaryOperationPrinter( - binaryGroupRulesBuilder, - binaryIndentRulesBuilder -); diff --git a/src/slang-printers/print-binary-operation.ts b/src/slang-printers/print-binary-operation.ts new file mode 100644 index 000000000..48db2ec72 --- /dev/null +++ b/src/slang-printers/print-binary-operation.ts @@ -0,0 +1,51 @@ +import { doc } from 'prettier'; +import { createBinaryOperationPrinter } from './create-binary-operation-printer.js'; +import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js'; + +import type { AstPath, Doc } from 'prettier'; + +const { group, indent } = doc.builders; + +const isBinaryOperationWithoutComparison = createKindCheckFunction([ + 'AdditiveExpression', + 'MultiplicativeExpression', + 'ExponentiationExpression', + 'AssignmentExpression', + 'BitwiseAndExpression', + 'BitwiseOrExpression', + 'BitwiseXorExpression', + 'AndExpression', + 'OrExpression', + 'ShiftExpression' +]); + +const binaryGroupRulesBuilder = + (path: AstPath) => + (document: Doc): Doc => { + const grandparentNode = path.getNode(2); + if (isBinaryOperationWithoutComparison(grandparentNode)) { + return document; + } + return group(document); + }; + +const binaryIndentRulesBuilder = + (path: AstPath) => + (document: Doc): Doc => { + let node = path.getNode(); + for (let i = 2; ; i += 2) { + const grandparentNode = path.getNode(i); + if (grandparentNode.kind === 'ReturnStatement') break; + if (!isBinaryOperationWithoutComparison(grandparentNode)) { + return indent(document); + } + if (node === grandparentNode.rightOperand.variant) break; + node = grandparentNode; + } + return document; + }; + +export const printBinaryOperation = createBinaryOperationPrinter( + binaryGroupRulesBuilder, + binaryIndentRulesBuilder +); diff --git a/src/slang-printers/print-comments.js b/src/slang-printers/print-comments.ts similarity index 67% rename from src/slang-printers/print-comments.js rename to src/slang-printers/print-comments.ts index 7450a0095..8072b72ca 100644 --- a/src/slang-printers/print-comments.js +++ b/src/slang-printers/print-comments.ts @@ -1,26 +1,28 @@ import { doc } from 'prettier'; +import { printComment } from '../slang-comments/printer.js'; import { isPrettier2 } from '../common/backward-compatibility.js'; +import type { AstPath, Doc } from 'prettier'; +import type { Comment, astNode } from '../types.js'; +import type { DocV2 } from './types.js'; + const { join, line } = doc.builders; -export function printComments(node, path, options, filter = () => true) { +export function printComments(node: astNode, path: AstPath): Doc[] { if (!node.comments) return []; const document = join( line, path .map((commentPath) => { - const comment = commentPath.getValue(); + const comment = commentPath.getValue() as Comment; if (comment.trailing || comment.leading || comment.printed) { return null; } - if (!filter(comment)) { - return null; - } comment.printed = true; // TODO: prettier Prints leading and trailing comments anyway. comment.leading = false; comment.trailing = false; - return options.printer.printComment(commentPath, options); + return printComment(commentPath); }, 'comments') .filter(Boolean) ); @@ -30,7 +32,7 @@ export function printComments(node, path, options, filter = () => true) { // Mocking the behaviour will introduce a lot of maintenance in the tests. /* c8 ignore start */ return isPrettier2 - ? document.parts // Prettier V2 + ? (document as DocV2).parts // Prettier V2 : document; // Prettier V3 /* c8 ignore stop */ } diff --git a/src/slang-printers/print-comparison-operation.js b/src/slang-printers/print-comparison-operation.js deleted file mode 100644 index 09a84c58b..000000000 --- a/src/slang-printers/print-comparison-operation.js +++ /dev/null @@ -1,33 +0,0 @@ -import { doc } from 'prettier'; -import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js'; -import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; -import { createBinaryOperationPrinter } from './create-binary-operation-printer.js'; - -const { group, indent } = doc.builders; - -const isStatementWithoutIndentedOperation = createKindCheckFunction([ - 'ReturnStatement', - 'IfStatement', - 'WhileStatement' -]); - -const comparisonIndentRulesBuilder = (path) => (document) => { - let node = path.getNode(); - for (let i = 2; ; i += 2) { - const grandparentNode = path.getNode(i); - if (grandparentNode.kind === 'ExpressionStatement') { - if (path.getNode(i + 1).kind === 'ForStatementCondition') break; - else return indent(document); - } - if (isStatementWithoutIndentedOperation(grandparentNode)) break; - if (!isBinaryOperation(grandparentNode)) return indent(document); - if (node === grandparentNode.rightOperand.variant) break; - node = grandparentNode; - } - return document; -}; - -export const printComparisonOperation = createBinaryOperationPrinter( - () => (document) => group(document), // always group - comparisonIndentRulesBuilder -); diff --git a/src/slang-printers/print-comparison-operation.ts b/src/slang-printers/print-comparison-operation.ts new file mode 100644 index 000000000..40cf00254 --- /dev/null +++ b/src/slang-printers/print-comparison-operation.ts @@ -0,0 +1,39 @@ +import { doc } from 'prettier'; +import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js'; +import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; +import { createBinaryOperationPrinter } from './create-binary-operation-printer.js'; + +import type { AstPath, Doc } from 'prettier'; + +const { group, indent } = doc.builders; + +const isStatementWithoutIndentedOperation = createKindCheckFunction([ + 'ReturnStatement', + 'IfStatement', + 'WhileStatement' +]); + +const comparisonIndentRulesBuilder = + (path: AstPath) => + (document: Doc): Doc => { + let node = path.getNode(); + for (let i = 2; ; i += 2) { + const grandparentNode = path.getNode(i); + if (grandparentNode.kind === 'ExpressionStatement') { + if (path.getNode(i + 1).kind === 'ForStatementCondition') break; + else return indent(document); + } + if (isStatementWithoutIndentedOperation(grandparentNode)) break; + if (!isBinaryOperation(grandparentNode)) return indent(document); + if (node === grandparentNode.rightOperand.variant) break; + node = grandparentNode; + } + return document; + }; + +export const printComparisonOperation = createBinaryOperationPrinter( + () => + (document: Doc): Doc => + group(document), // always group + comparisonIndentRulesBuilder +); diff --git a/src/slang-printers/print-function.js b/src/slang-printers/print-function.js deleted file mode 100644 index 5f97ecdb6..000000000 --- a/src/slang-printers/print-function.js +++ /dev/null @@ -1,20 +0,0 @@ -import { doc } from 'prettier'; - -const { dedent, group, indent, line } = doc.builders; - -export function printFunction(functionName, node, path, print) { - return [ - group([ - functionName, - path.call(print, 'parameters'), - indent( - group([ - path.call(print, 'attributes'), - node.returns ? [line, path.call(print, 'returns')] : '', - node.body && node.body.variant !== ';' ? dedent(line) : '' - ]) - ) - ]), - node.body ? path.call(print, 'body') : '' - ]; -} diff --git a/src/slang-printers/print-function.ts b/src/slang-printers/print-function.ts new file mode 100644 index 000000000..6727551be --- /dev/null +++ b/src/slang-printers/print-function.ts @@ -0,0 +1,34 @@ +import { doc } from 'prettier'; + +import type { AstPath, Doc } from 'prettier'; +import type { FunctionLike } from '../types.js'; +import type { FunctionDefinition } from '../slang-nodes'; + +const { dedent, group, indent, line } = doc.builders; + +export function printFunction( + functionName: Doc, + node: FunctionLike, + path: AstPath, + print: (path: AstPath) => Doc +): Doc { + return [ + group([ + functionName, + path.call(print, 'parameters'), + indent( + group([ + path.call(print, 'attributes'), + (node as FunctionDefinition).returns + ? [line, path.call(print, 'returns')] + : '', + (node as FunctionDefinition).body && + (node as FunctionDefinition).body.variant !== ';' + ? dedent(line) + : '' + ]) + ) + ]), + (node as FunctionDefinition).body ? path.call(print, 'body') : '' + ]; +} diff --git a/src/slang-printers/print-logical-operation.js b/src/slang-printers/print-logical-operation.js deleted file mode 100644 index 5eb588b01..000000000 --- a/src/slang-printers/print-logical-operation.js +++ /dev/null @@ -1,38 +0,0 @@ -import { doc } from 'prettier'; -import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js'; -import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; -import { createBinaryOperationPrinter } from './create-binary-operation-printer.js'; - -const { group, indent } = doc.builders; - -const isStatementWithoutIndentedOperation = createKindCheckFunction([ - 'ReturnStatement', - 'IfStatement', - 'WhileStatement' -]); - -const logicalGroupRulesBuilder = (path) => (document) => - isBinaryOperation(path.getNode(2)) ? document : group(document); - -const logicalIndentRulesBuilder = (path, options) => (document) => { - let node = path.getNode(); - for (let i = 2; ; i += 2) { - const grandparentNode = path.getNode(i); - if (isStatementWithoutIndentedOperation(grandparentNode)) break; - if ( - options.experimentalTernaries && - grandparentNode.kind === 'ConditionalExpression' && - grandparentNode.operand.variant === node - ) - break; - if (!isBinaryOperation(grandparentNode)) return indent(document); - if (node === grandparentNode.rightOperand.variant) break; - node = grandparentNode; - } - return document; -}; - -export const printLogicalOperation = createBinaryOperationPrinter( - logicalGroupRulesBuilder, - logicalIndentRulesBuilder -); diff --git a/src/slang-printers/print-logical-operation.ts b/src/slang-printers/print-logical-operation.ts new file mode 100644 index 000000000..5c913fc10 --- /dev/null +++ b/src/slang-printers/print-logical-operation.ts @@ -0,0 +1,44 @@ +import { doc } from 'prettier'; +import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js'; +import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; +import { createBinaryOperationPrinter } from './create-binary-operation-printer.js'; + +import type { AstPath, Doc, ParserOptions } from 'prettier'; + +const { group, indent } = doc.builders; + +const isStatementWithoutIndentedOperation = createKindCheckFunction([ + 'ReturnStatement', + 'IfStatement', + 'WhileStatement' +]); + +const logicalGroupRulesBuilder = + (path: AstPath) => + (document: Doc): Doc => + isBinaryOperation(path.getNode(2)) ? document : group(document); + +const logicalIndentRulesBuilder = + (path: AstPath, options: ParserOptions) => + (document: Doc): Doc => { + let node = path.getNode(); + for (let i = 2; ; i += 2) { + const grandparentNode = path.getNode(i); + if (isStatementWithoutIndentedOperation(grandparentNode)) break; + if ( + options.experimentalTernaries && + grandparentNode.kind === 'ConditionalExpression' && + grandparentNode.operand.variant === node + ) + break; + if (!isBinaryOperation(grandparentNode)) return indent(document); + if (node === grandparentNode.rightOperand.variant) break; + node = grandparentNode; + } + return document; + }; + +export const printLogicalOperation = createBinaryOperationPrinter( + logicalGroupRulesBuilder, + logicalIndentRulesBuilder +); diff --git a/src/slang-printers/print-preserving-empty-lines.js b/src/slang-printers/print-preserving-empty-lines.ts similarity index 72% rename from src/slang-printers/print-preserving-empty-lines.js rename to src/slang-printers/print-preserving-empty-lines.ts index 1240d0add..a61122691 100644 --- a/src/slang-printers/print-preserving-empty-lines.js +++ b/src/slang-printers/print-preserving-empty-lines.ts @@ -1,11 +1,19 @@ import { doc } from 'prettier'; import { isLast, isNextLineEmpty } from '../common/backward-compatibility.js'; +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { YulStatement } from '../slang-nodes/YulStatement.js'; + const { hardline } = doc.builders; -export function printPreservingEmptyLines(path, key, options, print) { +export function printPreservingEmptyLines( + path: AstPath, + key: string, + print: (path: AstPath) => Doc, + options: ParserOptions +): Doc { return path.map((childPath, index) => { - const node = childPath.getNode(); + const node = childPath.getNode() as YulStatement; return [ // Only attempt to prepend an empty line if `node` is not the first item diff --git a/src/slang-printers/print-separated-item.ts b/src/slang-printers/print-separated-item.ts new file mode 100644 index 000000000..168554bfb --- /dev/null +++ b/src/slang-printers/print-separated-item.ts @@ -0,0 +1,21 @@ +import { doc } from 'prettier'; + +import type { Doc } from 'prettier'; +import type { PrintSeparatedOptions } from './types'; + +const { group, indent, softline } = doc.builders; + +// This function will add an indentation to the `item` and separate it from the +// rest of the `doc` in most cases by a `softline`. +export function printSeparatedItem( + item: Doc, + { + firstSeparator = softline, + lastSeparator = firstSeparator, + grouped = true + }: PrintSeparatedOptions = {} +): Doc { + return grouped + ? group([indent([firstSeparator, item]), lastSeparator]) + : [indent([firstSeparator, item]), lastSeparator]; +} diff --git a/src/slang-printers/print-separated-list.ts b/src/slang-printers/print-separated-list.ts new file mode 100644 index 000000000..ff5e3fb90 --- /dev/null +++ b/src/slang-printers/print-separated-list.ts @@ -0,0 +1,27 @@ +import { doc } from 'prettier'; +import { printSeparatedItem } from './print-separated-item.js'; + +import type { Doc } from 'prettier'; +import type { PrintSeparatedOptions } from './types'; + +const { join, line } = doc.builders; + +// 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` +export function printSeparatedList( + list: Doc[], + { + firstSeparator, + separator = [',', line], + lastSeparator, + grouped + }: PrintSeparatedOptions = {} +): Doc { + return printSeparatedItem(join(separator, list), { + firstSeparator, + lastSeparator, + grouped + }); +} diff --git a/src/slang-printers/print-string.js b/src/slang-printers/print-string.ts similarity index 81% rename from src/slang-printers/print-string.js rename to src/slang-printers/print-string.ts index 23e327824..5d925d7fd 100644 --- a/src/slang-printers/print-string.js +++ b/src/slang-printers/print-string.ts @@ -1,9 +1,15 @@ import { util } from 'prettier'; -const double = { quote: '"', regex: /"/g }; -const single = { quote: "'", regex: /'/g }; +import type { ParserOptions } from 'prettier'; +import type { QuoteRegex } from './types'; -export function printString(rawContent, options) { +const double: QuoteRegex = { quote: '"', regex: /"/g }; +const single: QuoteRegex = { quote: "'", regex: /'/g }; + +export function printString( + rawContent: string, + options: ParserOptions +): string { const preferred = options.singleQuote ? single : double; const alternate = preferred === single ? double : single; diff --git a/src/slang-printers/types.d.ts b/src/slang-printers/types.d.ts new file mode 100644 index 000000000..ffc22a28f --- /dev/null +++ b/src/slang-printers/types.d.ts @@ -0,0 +1,15 @@ +import type { Doc, util } from 'prettier'; + +interface PrintSeparatedOptions { + firstSeparator?: Doc; + separator?: Doc; + lastSeparator?: Doc; + grouped?: boolean; +} + +type DocV2 = Doc[] & { parts: Doc[] }; + +interface QuoteRegex { + quote: util.Quote; + regex: RegExp; +} diff --git a/src/slang-utils/create-hug-function.js b/src/slang-utils/create-hug-function.ts similarity index 63% rename from src/slang-utils/create-hug-function.js rename to src/slang-utils/create-hug-function.ts index 3c188f21f..a2a7b47df 100644 --- a/src/slang-utils/create-hug-function.js +++ b/src/slang-utils/create-hug-function.ts @@ -1,31 +1,44 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { Expression } from '../slang-nodes/Expression.js'; import { TupleExpression } from '../slang-nodes/TupleExpression.js'; import { TupleValues } from '../slang-nodes/TupleValues.js'; import { TupleValue } from '../slang-nodes/TupleValue.js'; import { isBinaryOperation } from './is-binary-operation.js'; -export function createHugFunction(huggableOperators) { +import type { BinaryOperation } from '../types.js'; + +export function createHugFunction( + huggableOperators: string[] +): (node: Expression) => Expression { const operators = new Set(huggableOperators); - return (node) => { + return (node: Expression): Expression => { if ( isBinaryOperation(node.variant) && - operators.has(node.variant.operator) + operators.has((node.variant as BinaryOperation).operator) ) { const { loc } = node; return Object.create(Expression.prototype, { + kind: { value: NonterminalKind.Expression }, loc: { value: { ...loc } }, + comments: { value: [] }, variant: { value: Object.create(TupleExpression.prototype, { + kind: { value: NonterminalKind.TupleExpression }, loc: { value: { ...loc } }, + comments: { value: [] }, openParen: { value: '(' }, items: { value: Object.create(TupleValues.prototype, { + kind: { value: NonterminalKind.TupleValues }, loc: { value: { ...loc } }, + comments: { value: [] }, items: { value: [ Object.create(TupleValue.prototype, { + kind: { value: NonterminalKind.TupleValue }, loc: { value: { ...loc } }, + comments: { value: [] }, expression: { value: node } }) ] diff --git a/src/slang-utils/get-offsets.js b/src/slang-utils/get-offsets.js deleted file mode 100644 index 416082559..000000000 --- a/src/slang-utils/get-offsets.js +++ /dev/null @@ -1,53 +0,0 @@ -import { isComment } from './is-comment.js'; - -export function getChildrenOffsets(children, initialOffset, comments) { - let offset = initialOffset; - - const offsets = children.reduce((offsetsArray, child) => { - if (child.type === 'Nonterminal') { - offsetsArray.push(offset); - } - if (child.type === 'Terminal' && isComment(child)) { - // Since the fetching the comments and calculating offsets are both done - // as we iterate over the children and the comment also depends on the - // offset, it's hard to separate these responsibilities into different - // functions. - comments.push({ - kind: child.kind, - value: child.text, - loc: { - start: offset, - end: offset + child.textLength.utf8 - } - }); - } - - offset += child.textLength.utf8; - return offsetsArray; - }, []); - return offsets; -} - -export function getLeadingOffset(children) { - let offset = 0; - for (let i = 0; i < children.length; i += 1) { - const child = children[i]; - if (child.type === 'Nonterminal') { - // The node's content starts when we find the first non-terminal, - // non-comment, non-whitespace token. - return offset; - } - if ( - child.type === 'Terminal' && - !isComment(child) && - child.kind !== 'EndOfLine' && - child.kind !== 'Whitespace' - ) { - // The content of the node started if we find a non-comment, - // non-whitespace token. - return offset; - } - offset += child.textLength.utf8; - } - return offset; -} diff --git a/src/slang-utils/get-offsets.ts b/src/slang-utils/get-offsets.ts new file mode 100644 index 000000000..367827514 --- /dev/null +++ b/src/slang-utils/get-offsets.ts @@ -0,0 +1,124 @@ +import { isComment } from './is-comment.js'; + +import type { Node } from '@nomicfoundation/slang/cst/index.js'; +import type { astNode, Comment, Metadata, SlangASTNode } from '../types.js'; + +function getLeadingOffset(children: Node[]): number { + let offset = 0; + for (let i = 0; i < children.length; i += 1) { + const child = children[i]; + if (child.type === 'Nonterminal') { + // The node's content starts when we find the first non-terminal token. + return offset; + } else if ( + !isComment(child) && + child.kind !== 'EndOfLine' && + child.kind !== 'Whitespace' + ) { + // The content of the node started if we find a non-comment, + // non-whitespace token. + return offset; + } + offset += child.textLength.utf8; + } + return offset; +} + +export function getNodeMetadata( + ast: SlangASTNode, + initialOffset: number +): Metadata { + const children = ast.cst.children(); + + let offset = initialOffset; + + const comments: Comment[] = []; + + const offsets = children.reduce((offsetsArray: number[], child) => { + if (child.type === 'Nonterminal') { + offsetsArray.push(offset); + } else if ( + child.kind === 'MultiLineComment' || + child.kind === 'MultiLineNatSpecComment' || + child.kind === 'SingleLineComment' || + child.kind === 'SingleLineNatSpecComment' + ) { + // Since the fetching the comments and calculating offsets are both done + // as we iterate over the children and the comment also depends on the + // offset, it's hard to separate these responsibilities into different + // functions. + comments.push({ + kind: child.kind, + value: child.text, + loc: { + start: offset, + end: offset + child.textLength.utf8 + } + }); + } + + offset += child.textLength.utf8; + return offsetsArray; + }, []); + + const leadingOffset = getLeadingOffset(children); + const trailingOffset = getLeadingOffset(children.reverse()); + const loc = { + start: initialOffset + leadingOffset, + end: initialOffset + ast.cst.textLength.utf8 - trailingOffset, + leadingOffset, + trailingOffset + }; + + return { comments, loc, offsets }; +} + +function collectComments( + comments: Comment[], + node: astNode | astNode[] | undefined +): Comment[] { + if (node) { + if (Array.isArray(node)) { + comments.push(...node.reduce(collectComments, [])); + } else if (node.comments.length > 0) { + comments.push(...node.comments.splice(0)); + } + } + return comments; +} + +export function updateMetadata( + metadata: Metadata, + childNodes: (astNode | astNode[] | undefined)[] +): Metadata { + const { comments, loc } = metadata; + // Collect comments + comments.push(...childNodes.reduce(collectComments, [])); + + // calculate correct loc object + if (loc.leadingOffset === 0 || loc.trailingOffset === 0) { + childNodes.forEach((childNode) => { + if (Array.isArray(childNode)) return; + const childLoc = childNode?.loc; + + if (childLoc) { + if ( + loc.leadingOffset === 0 && + childLoc.start - childLoc.leadingOffset! === loc.start + ) { + loc.leadingOffset = childLoc.leadingOffset; + loc.start += childLoc.leadingOffset!; + } + + if ( + loc.trailingOffset === 0 && + childLoc.end + childLoc.trailingOffset! === loc.end + ) { + loc.trailingOffset = childLoc.trailingOffset; + loc.end -= childLoc.trailingOffset!; + } + } + }); + } + return { comments, loc, offsets: [] }; +} diff --git a/src/slang-utils/is-label.ts b/src/slang-utils/is-label.ts new file mode 100644 index 000000000..8932a2be1 --- /dev/null +++ b/src/slang-utils/is-label.ts @@ -0,0 +1,5 @@ +import type { Doc, doc } from 'prettier'; + +export function isLabel(doc: Doc): doc is doc.builders.Label { + return (doc as doc.builders.DocCommand).type === 'label'; +} diff --git a/src/slang-utils/loc.js b/src/slang-utils/loc.js deleted file mode 100644 index 4d4cdec6b..000000000 --- a/src/slang-utils/loc.js +++ /dev/null @@ -1,7 +0,0 @@ -export function locStart(node) { - return node.loc.start; -} - -export function locEnd(node) { - return node.loc.end; -} diff --git a/src/slang-utils/loc.ts b/src/slang-utils/loc.ts new file mode 100644 index 000000000..93d8e039d --- /dev/null +++ b/src/slang-utils/loc.ts @@ -0,0 +1,9 @@ +import type { astNode, Comment } from '../types'; + +export function locStart(node: astNode | Comment): number { + return node.loc.start; +} + +export function locEnd(node: astNode | Comment): number { + return node.loc.end; +} diff --git a/src/slang-utils/sort-function-attributes.js b/src/slang-utils/sort-function-attributes.js deleted file mode 100644 index 84ee20f51..000000000 --- a/src/slang-utils/sort-function-attributes.js +++ /dev/null @@ -1,45 +0,0 @@ -const visibilityKeyWords = new Set([ - 'external', - 'internal', - 'public', - 'private' -]); - -const mutabilityKeyWords = new Set(['pure', 'constant', 'payable', 'view']); - -function sortFunctionAttributes(a, b) { - const aIsString = typeof a.variant === 'string'; - const bIsString = typeof b.variant === 'string'; - - if (aIsString && !bIsString) return -1; - if (bIsString && !aIsString) return 1; - - // Both are strings - if (aIsString && bIsString) { - // Visibility First - if (visibilityKeyWords.has(a.variant)) return -1; - if (visibilityKeyWords.has(b.variant)) return 1; - // State Mutability Second - if (mutabilityKeyWords.has(a.variant)) return -1; - if (mutabilityKeyWords.has(b.variant)) return 1; - // Virtual keyword last - } else { - // Both are nodes - if ( - a.variant.kind === 'OverrideSpecifier' && - b.variant.kind === 'ModifierInvocation' - ) - return -1; - if ( - b.variant.kind === 'OverrideSpecifier' && - a.variant.kind === 'ModifierInvocation' - ) - return 1; - } - return 0; -} - -export const postProcessFunctionAttributes = (properties) => ({ - ...properties, - items: properties.items.sort(sortFunctionAttributes) -}); diff --git a/src/slang-utils/sort-function-attributes.ts b/src/slang-utils/sort-function-attributes.ts new file mode 100644 index 000000000..34c113f3c --- /dev/null +++ b/src/slang-utils/sort-function-attributes.ts @@ -0,0 +1,46 @@ +import type { SortableAttribute, SortableVariant } from './types'; + +const visibilityKeyWords = new Set([ + 'external', + 'internal', + 'public', + 'private' +]); + +const mutabilityKeyWords = new Set(['pure', 'constant', 'payable', 'view']); + +export function sortFunctionAttributes( + a: SortableAttribute, + b: SortableAttribute +): number { + const aIsString = typeof a.variant === 'string'; + const bIsString = typeof b.variant === 'string'; + + if (aIsString && !bIsString) return -1; + if (bIsString && !aIsString) return 1; + + // Both are strings + if (aIsString) { + // Visibility First + if (visibilityKeyWords.has(a.variant as string)) return -1; + if (visibilityKeyWords.has(b.variant as string)) return 1; + // State Mutability Second + if (mutabilityKeyWords.has(a.variant as string)) return -1; + if (mutabilityKeyWords.has(b.variant as string)) return 1; + // Virtual keyword last + } + // Both are nodes + // OverrideSpecifiers before ModifierInvocation + if ( + (a.variant as SortableVariant).kind === 'OverrideSpecifier' && + (b.variant as SortableVariant).kind === 'ModifierInvocation' + ) + return -1; + if ( + (b.variant as SortableVariant).kind === 'OverrideSpecifier' && + (a.variant as SortableVariant).kind === 'ModifierInvocation' + ) + return 1; + + return 0; +} diff --git a/src/slang-utils/types.d.ts b/src/slang-utils/types.d.ts new file mode 100644 index 000000000..3fe2aa0ab --- /dev/null +++ b/src/slang-utils/types.d.ts @@ -0,0 +1,24 @@ +import type { + ConstructorAttribute, + FallbackFunctionAttribute, + FunctionAttribute, + FunctionTypeAttribute, + ModifierAttribute, + ReceiveFunctionAttribute, + StateVariableAttribute, + UnnamedFunctionAttribute, + OverrideSpecifier, + ModifierInvocation +} from '../slang-nodes'; + +type SortableAttribute = + | ConstructorAttribute + | FallbackFunctionAttribute + | FunctionAttribute + | FunctionTypeAttribute + | ModifierAttribute + | ReceiveFunctionAttribute + | StateVariableAttribute + | UnnamedFunctionAttribute; + +type SortableVariant = OverrideSpecifier | ModifierInvocation; diff --git a/src/slangPrinter.js b/src/slangPrinter.js index ef2ba4dfc..7f10ec4ba 100644 --- a/src/slangPrinter.js +++ b/src/slangPrinter.js @@ -1,4 +1,3 @@ -import * as nodes from './slang-nodes/index.js'; import { prettierVersionSatisfies } from './common/util.js'; import { isBlockComment } from './slang-utils/is-comment.js'; import ignoreComments from './comments/ignore.js'; @@ -31,15 +30,11 @@ function genericPrint(path, options, print) { prettierVersionCheck(); const node = path.getValue(); - const nodeType = node.kind; + if (node === null) { return ''; } - if (!(nodeType in nodes)) { - throw new Error(`Unknown type: ${JSON.stringify(nodeType)}`); - } - if (hasNodeIgnoreComment(node)) { ignoreComments(path); diff --git a/src/types.d.ts b/src/types.d.ts new file mode 100644 index 000000000..036313dbb --- /dev/null +++ b/src/types.d.ts @@ -0,0 +1,518 @@ +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type * as nodes from './slang-nodes/index.js'; +import type * as ast from '@nomicfoundation/slang/ast/index.js'; + +// Adding our own options to prettier's `ParserOptions` interface. +declare module 'prettier' { + interface ParserOptions { + compiler: string; + experimentalTernaries: boolean; + } +} + +interface Location { + start: number; + end: number; + leadingOffset?: number; + trailingOffset?: number; +} + +interface BlockComment { + kind: 'MultiLineComment' | 'MultiLineNatSpecComment'; + value: string; + loc: Location; + leading?: boolean; + trailing?: boolean; + printed?: boolean; + precedingNode?: astNode; + enclosingNode?: astNode; + followingNode?: astNode; +} + +interface LineComment { + kind: 'SingleLineComment' | 'SingleLineNatSpecComment'; + value: string; + loc: Location; + leading?: boolean; + trailing?: boolean; + printed?: boolean; + precedingNode?: astNode; + enclosingNode?: astNode; + followingNode?: astNode; +} + +type Comment = BlockComment | LineComment; + +interface Metadata { + comments: Comment[]; + loc: Location; + offsets: number[]; +} + +interface SlangNode { + get kind(): string; + comments?: Comment[]; + loc: Location; + print?( + path: AstPath, + print: (path: AstPath) => Doc, + options: ParserOptions + ): Doc; +} + +export type BinaryOperation = + | nodes.AdditiveExpression + | nodes.MultiplicativeExpression + | nodes.ExponentiationExpression + | nodes.AssignmentExpression + | nodes.BitwiseAndExpression + | nodes.BitwiseOrExpression + | nodes.BitwiseXorExpression + | nodes.ComparisonExpression + | nodes.EqualityExpression + | nodes.AndExpression + | nodes.OrExpression + | nodes.ShiftExpression; + +export type FunctionLike = + | nodes.ConstructorDefinition + | nodes.FallbackFunctionDefinition + | nodes.FunctionDefinition + | nodes.FunctionType + | nodes.ModifierDefinition + | nodes.ReceiveFunctionDefinition + | nodes.UnnamedFunctionDefinition; + +export type astNode = + | nodes.SourceUnit + | nodes.PragmaDirective + | nodes.ABICoderPragma + | nodes.ExperimentalPragma + | nodes.VersionPragma + | nodes.VersionRange + | nodes.VersionComparator + | nodes.ImportDirective + | nodes.PathImport + | nodes.NamedImport + | nodes.ImportDeconstruction + | nodes.ImportDeconstructionSymbol + | nodes.ImportAlias + | nodes.UsingDirective + | nodes.UsingDeconstruction + | nodes.UsingDeconstructionSymbol + | nodes.UsingAlias + | nodes.ContractDefinition + | nodes.InheritanceSpecifier + | nodes.InheritanceType + | nodes.InterfaceDefinition + | nodes.LibraryDefinition + | nodes.StructDefinition + | nodes.StructMember + | nodes.EnumDefinition + | nodes.ConstantDefinition + | nodes.StateVariableDefinition + | nodes.StateVariableDefinitionValue + | nodes.FunctionDefinition + | nodes.ParametersDeclaration + | nodes.Parameter + | nodes.OverrideSpecifier + | nodes.OverridePathsDeclaration + | nodes.ReturnsDeclaration + | nodes.ConstructorDefinition + | nodes.UnnamedFunctionDefinition + | nodes.FallbackFunctionDefinition + | nodes.ReceiveFunctionDefinition + | nodes.ModifierDefinition + | nodes.ModifierInvocation + | nodes.EventDefinition + | nodes.EventParametersDeclaration + | nodes.EventParameter + | nodes.UserDefinedValueTypeDefinition + | nodes.ErrorDefinition + | nodes.ErrorParametersDeclaration + | nodes.ErrorParameter + | nodes.ArrayTypeName + | nodes.FunctionType + | nodes.MappingType + | nodes.MappingKey + | nodes.MappingValue + | nodes.AddressType + | nodes.Block + | nodes.UncheckedBlock + | nodes.ExpressionStatement + | nodes.AssemblyStatement + | nodes.AssemblyFlagsDeclaration + | nodes.TupleDeconstructionStatement + | nodes.TupleDeconstructionElement + | nodes.TypedTupleMember + | nodes.UntypedTupleMember + | nodes.VariableDeclarationStatement + | nodes.VariableDeclarationValue + | nodes.IfStatement + | nodes.ElseBranch + | nodes.ForStatement + | nodes.WhileStatement + | nodes.DoWhileStatement + | nodes.ContinueStatement + | nodes.BreakStatement + | nodes.ReturnStatement + | nodes.EmitStatement + | nodes.TryStatement + | nodes.CatchClause + | nodes.CatchClauseError + | nodes.RevertStatement + | nodes.ThrowStatement + | nodes.AssignmentExpression + | nodes.ConditionalExpression + | nodes.OrExpression + | nodes.AndExpression + | nodes.EqualityExpression + | nodes.ComparisonExpression + | nodes.BitwiseOrExpression + | nodes.BitwiseXorExpression + | nodes.BitwiseAndExpression + | nodes.ShiftExpression + | nodes.AdditiveExpression + | nodes.MultiplicativeExpression + | nodes.ExponentiationExpression + | nodes.PostfixExpression + | nodes.PrefixExpression + | nodes.FunctionCallExpression + | nodes.CallOptionsExpression + | nodes.MemberAccessExpression + | nodes.IndexAccessExpression + | nodes.IndexAccessEnd + | nodes.PositionalArgumentsDeclaration + | nodes.NamedArgumentsDeclaration + | nodes.NamedArgumentGroup + | nodes.NamedArgument + | nodes.TypeExpression + | nodes.NewExpression + | nodes.TupleExpression + | nodes.TupleValue + | nodes.ArrayExpression + | nodes.HexNumberExpression + | nodes.DecimalNumberExpression + | nodes.YulBlock + | nodes.YulFunctionDefinition + | nodes.YulParametersDeclaration + | nodes.YulReturnsDeclaration + | nodes.YulVariableDeclarationStatement + | nodes.YulVariableDeclarationValue + | nodes.YulVariableAssignmentStatement + | nodes.YulStackAssignmentStatement + | nodes.YulColonEqual + | nodes.YulIfStatement + | nodes.YulForStatement + | nodes.YulSwitchStatement + | nodes.YulDefaultCase + | nodes.YulValueCase + | nodes.YulLeaveStatement + | nodes.YulBreakStatement + | nodes.YulContinueStatement + | nodes.YulLabel + | nodes.YulFunctionCallExpression + | nodes.SourceUnitMember + | nodes.Pragma + | nodes.ExperimentalFeature + | nodes.VersionExpression + | nodes.ImportClause + | nodes.UsingClause + | nodes.UsingOperator + | nodes.UsingTarget + | nodes.ContractMember + | nodes.StateVariableAttribute + | nodes.FunctionName + | nodes.FunctionAttribute + | nodes.FunctionBody + | nodes.ConstructorAttribute + | nodes.UnnamedFunctionAttribute + | nodes.FallbackFunctionAttribute + | nodes.ReceiveFunctionAttribute + | nodes.ModifierAttribute + | nodes.TypeName + | nodes.FunctionTypeAttribute + | nodes.MappingKeyType + | nodes.ElementaryType + | nodes.Statement + | nodes.TupleMember + | nodes.VariableDeclarationType + | nodes.StorageLocation + | nodes.ForStatementInitialization + | nodes.ForStatementCondition + | nodes.Expression + | nodes.MemberAccess + | nodes.ArgumentsDeclaration + | nodes.NumberUnit + | nodes.StringExpression + | nodes.StringLiteral + | nodes.HexStringLiteral + | nodes.UnicodeStringLiteral + | nodes.YulStatement + | nodes.YulAssignmentOperator + | nodes.YulSwitchCase + | nodes.YulExpression + | nodes.YulPathComponent + | nodes.YulBuiltInFunction + | nodes.YulLiteral + | nodes.SourceUnitMembers + | nodes.VersionExpressionSet + | nodes.ContractMembers + | nodes.InterfaceMembers + | nodes.LibraryMembers + | nodes.StructMembers + | nodes.StateVariableAttributes + | nodes.FunctionAttributes + | nodes.ConstructorAttributes + | nodes.UnnamedFunctionAttributes + | nodes.FallbackFunctionAttributes + | nodes.ReceiveFunctionAttributes + | nodes.ModifierAttributes + | nodes.FunctionTypeAttributes + | nodes.Statements + | nodes.CatchClauses + | nodes.StringLiterals + | nodes.HexStringLiterals + | nodes.UnicodeStringLiterals + | nodes.YulStatements + | nodes.YulSwitchCases + | nodes.VersionExpressionSets + | nodes.VersionSpecifiers + | nodes.ImportDeconstructionSymbols + | nodes.UsingDeconstructionSymbols + | nodes.InheritanceTypes + | nodes.EnumMembers + | nodes.Parameters + | nodes.OverridePaths + | nodes.EventParameters + | nodes.ErrorParameters + | nodes.AssemblyFlags + | nodes.TupleDeconstructionElements + | nodes.PositionalArguments + | nodes.NamedArguments + | nodes.CallOptions + | nodes.TupleValues + | nodes.ArrayValues + | nodes.IdentifierPath + | nodes.YulParameters + | nodes.YulReturnVariables + | nodes.YulArguments + | nodes.YulPaths + | nodes.YulPath; + +export type SlangASTNode = + | ast.SourceUnit + | ast.PragmaDirective + | ast.ABICoderPragma + | ast.ExperimentalPragma + | ast.VersionPragma + | ast.VersionRange + | ast.VersionComparator + | ast.ImportDirective + | ast.PathImport + | ast.NamedImport + | ast.ImportDeconstruction + | ast.ImportDeconstructionSymbol + | ast.ImportAlias + | ast.UsingDirective + | ast.UsingDeconstruction + | ast.UsingDeconstructionSymbol + | ast.UsingAlias + | ast.ContractDefinition + | ast.InheritanceSpecifier + | ast.InheritanceType + | ast.InterfaceDefinition + | ast.LibraryDefinition + | ast.StructDefinition + | ast.StructMember + | ast.EnumDefinition + | ast.ConstantDefinition + | ast.StateVariableDefinition + | ast.StateVariableDefinitionValue + | ast.FunctionDefinition + | ast.ParametersDeclaration + | ast.Parameter + | ast.OverrideSpecifier + | ast.OverridePathsDeclaration + | ast.ReturnsDeclaration + | ast.ConstructorDefinition + | ast.UnnamedFunctionDefinition + | ast.FallbackFunctionDefinition + | ast.ReceiveFunctionDefinition + | ast.ModifierDefinition + | ast.ModifierInvocation + | ast.EventDefinition + | ast.EventParametersDeclaration + | ast.EventParameter + | ast.UserDefinedValueTypeDefinition + | ast.ErrorDefinition + | ast.ErrorParametersDeclaration + | ast.ErrorParameter + | ast.ArrayTypeName + | ast.FunctionType + | ast.MappingType + | ast.MappingKey + | ast.MappingValue + | ast.AddressType + | ast.Block + | ast.UncheckedBlock + | ast.ExpressionStatement + | ast.AssemblyStatement + | ast.AssemblyFlagsDeclaration + | ast.TupleDeconstructionStatement + | ast.TupleDeconstructionElement + | ast.TypedTupleMember + | ast.UntypedTupleMember + | ast.VariableDeclarationStatement + | ast.VariableDeclarationValue + | ast.IfStatement + | ast.ElseBranch + | ast.ForStatement + | ast.WhileStatement + | ast.DoWhileStatement + | ast.ContinueStatement + | ast.BreakStatement + | ast.ReturnStatement + | ast.EmitStatement + | ast.TryStatement + | ast.CatchClause + | ast.CatchClauseError + | ast.RevertStatement + | ast.ThrowStatement + | ast.AssignmentExpression + | ast.ConditionalExpression + | ast.OrExpression + | ast.AndExpression + | ast.EqualityExpression + | ast.ComparisonExpression + | ast.BitwiseOrExpression + | ast.BitwiseXorExpression + | ast.BitwiseAndExpression + | ast.ShiftExpression + | ast.AdditiveExpression + | ast.MultiplicativeExpression + | ast.ExponentiationExpression + | ast.PostfixExpression + | ast.PrefixExpression + | ast.FunctionCallExpression + | ast.CallOptionsExpression + | ast.MemberAccessExpression + | ast.IndexAccessExpression + | ast.IndexAccessEnd + | ast.PositionalArgumentsDeclaration + | ast.NamedArgumentsDeclaration + | ast.NamedArgumentGroup + | ast.NamedArgument + | ast.TypeExpression + | ast.NewExpression + | ast.TupleExpression + | ast.TupleValue + | ast.ArrayExpression + | ast.HexNumberExpression + | ast.DecimalNumberExpression + | ast.YulBlock + | ast.YulFunctionDefinition + | ast.YulParametersDeclaration + | ast.YulReturnsDeclaration + | ast.YulVariableDeclarationStatement + | ast.YulVariableDeclarationValue + | ast.YulVariableAssignmentStatement + | ast.YulStackAssignmentStatement + | ast.YulColonEqual + | ast.YulIfStatement + | ast.YulForStatement + | ast.YulSwitchStatement + | ast.YulDefaultCase + | ast.YulValueCase + | ast.YulLeaveStatement + | ast.YulBreakStatement + | ast.YulContinueStatement + | ast.YulLabel + | ast.YulFunctionCallExpression + | ast.SourceUnitMember + | ast.Pragma + | ast.ExperimentalFeature + | ast.VersionExpression + | ast.ImportClause + | ast.UsingClause + | ast.UsingOperator + | ast.UsingTarget + | ast.ContractMember + | ast.StateVariableAttribute + | ast.FunctionName + | ast.FunctionAttribute + | ast.FunctionBody + | ast.ConstructorAttribute + | ast.UnnamedFunctionAttribute + | ast.FallbackFunctionAttribute + | ast.ReceiveFunctionAttribute + | ast.ModifierAttribute + | ast.TypeName + | ast.FunctionTypeAttribute + | ast.MappingKeyType + | ast.ElementaryType + | ast.Statement + | ast.TupleMember + | ast.VariableDeclarationType + | ast.StorageLocation + | ast.ForStatementInitialization + | ast.ForStatementCondition + | ast.Expression + | ast.MemberAccess + | ast.ArgumentsDeclaration + | ast.NumberUnit + | ast.StringExpression + | ast.StringLiteral + | ast.HexStringLiteral + | ast.UnicodeStringLiteral + | ast.YulStatement + | ast.YulAssignmentOperator + | ast.YulSwitchCase + | ast.YulExpression + | ast.YulPathComponent + | ast.YulBuiltInFunction + | ast.YulLiteral + | ast.SourceUnitMembers + | ast.VersionExpressionSet + | ast.ContractMembers + | ast.InterfaceMembers + | ast.LibraryMembers + | ast.StructMembers + | ast.StateVariableAttributes + | ast.FunctionAttributes + | ast.ConstructorAttributes + | ast.UnnamedFunctionAttributes + | ast.FallbackFunctionAttributes + | ast.ReceiveFunctionAttributes + | ast.ModifierAttributes + | ast.FunctionTypeAttributes + | ast.Statements + | ast.CatchClauses + | ast.StringLiterals + | ast.HexStringLiterals + | ast.UnicodeStringLiterals + | ast.YulStatements + | ast.YulSwitchCases + | ast.VersionExpressionSets + | ast.VersionSpecifiers + | ast.ImportDeconstructionSymbols + | ast.UsingDeconstructionSymbols + | ast.InheritanceTypes + | ast.EnumMembers + | ast.Parameters + | ast.OverridePaths + | ast.EventParameters + | ast.ErrorParameters + | ast.AssemblyFlags + | ast.TupleDeconstructionElements + | ast.PositionalArguments + | ast.NamedArguments + | ast.CallOptions + | ast.TupleValues + | ast.ArrayValues + | ast.IdentifierPath + | ast.YulParameters + | ast.YulReturnVariables + | ast.YulArguments + | ast.YulPaths + | ast.YulPath; diff --git a/tests/config/get-prettier.js b/tests/config/get-prettier.js index 5d72040c0..6a7446292 100644 --- a/tests/config/get-prettier.js +++ b/tests/config/get-prettier.js @@ -1,7 +1,7 @@ function getPrettierInternal() { const entry = process.env.TEST_STANDALONE ? new URL("./require-standalone.cjs", import.meta.url) - : new URL("./require-prettier.cjs", import.meta.url); + : "prettier"; return import(entry).then((module) => module.default); } diff --git a/tests/config/require-prettier.cjs b/tests/config/require-prettier.cjs deleted file mode 100644 index f0fa1e6d4..000000000 --- a/tests/config/require-prettier.cjs +++ /dev/null @@ -1,5 +0,0 @@ -"use strict"; - -const prettier = require("prettier"); - -module.exports = prettier; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 000000000..d74332c94 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "allowJs": true, + "outDir": "./dist/", + "noImplicitAny": true, + "sourceMap": true, + "target": "es6", + "module": "es2022", + "moduleResolution": "node", + "strict": true, + "esModuleInterop": true + }, + "ts-node": { + "files": true + }, + "include": ["./src/**/*"] +} diff --git a/webpack.config.js b/webpack.config.js index ab7bcdbd0..b19e28dec 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -27,6 +27,23 @@ export default (webpackEnv) => { bail: isEnvProduction, devtool: 'source-map', + resolve: { + extensions: ['.ts', '.js'], + extensionAlias: { + '.js': ['.js', '.ts'] + } + }, + + module: { + rules: [ + { + test: /\.ts$/, + use: 'ts-loader', + exclude: /node_modules/ + } + ] + }, + optimization: { minimize: isEnvProduction }, From 8194292900fe0fb809bbff9599e80b8df4131531 Mon Sep 17 00:00:00 2001 From: Klaus Date: Tue, 30 Jul 2024 19:01:57 +1200 Subject: [PATCH 100/160] moving 100% to TS and passing all tests --- .c8rc | 1 + src/{clean.js => clean.ts} | 2 +- src/{options.js => options.ts} | 8 +- src/slang-comments/{handler.js => handler.ts} | 55 +++++------ ...lockComments.js => handleBlockComments.ts} | 8 +- ...js => handleContractDefinitionComments.ts} | 17 ++-- ...=> handleParametersDeclarationComments.ts} | 8 +- ...nts.js => handleWhileStatementComments.ts} | 13 +-- ...kComments.js => handleYulBlockComments.ts} | 6 +- .../handlers/{index.js => index.ts} | 0 src/slang-comments/handlers/types.d.ts | 9 ++ src/slang-comments/{index.js => index.ts} | 0 src/slang-comments/{printer.js => printer.ts} | 9 +- src/slang-nodes/AssignmentExpression.ts | 1 + src/slang-nodes/ContractDefinition.ts | 1 - src/slang-nodes/ExponentiationExpression.ts | 89 ++++++++++++------ src/slang-nodes/ModifierDefinition.ts | 34 ++++--- src/slang-nodes/ModifierInvocation.ts | 1 - src/slang-nodes/TupleValues.ts | 1 + .../create-binary-operation-printer.ts | 6 +- src/slang-printers/print-comments.ts | 9 +- .../print-preserving-empty-lines.ts | 8 +- src/slang-utils/backward-compatibility.ts | 44 +++++++++ src/slang-utils/create-hug-function.ts | 51 ++++++---- src/slang-utils/create-kind-check-function.js | 4 - src/slang-utils/create-kind-check-function.ts | 9 ++ ...ry-operation.js => is-binary-operation.ts} | 0 .../{is-comment.js => is-comment.ts} | 0 src/slang-utils/prettier-version-satisfies.ts | 8 ++ src/slang-utils/types.d.ts | 14 +++ src/slangParser.js | 26 ------ src/slangParser.ts | 28 ++++++ src/slangPrinter.js | 50 ---------- src/slangPrinter.ts | 93 +++++++++++++++++++ tests/config/run-format-test.js | 4 +- 35 files changed, 396 insertions(+), 221 deletions(-) rename src/{clean.js => clean.ts} (79%) rename src/{options.js => options.ts} (94%) rename src/slang-comments/{handler.js => handler.ts} (67%) rename src/slang-comments/handlers/{handleBlockComments.js => handleBlockComments.ts} (79%) rename src/slang-comments/handlers/{handleContractDefinitionComments.js => handleContractDefinitionComments.ts} (82%) rename src/slang-comments/handlers/{handleParametersDeclarationComments.js => handleParametersDeclarationComments.ts} (79%) rename src/slang-comments/handlers/{handleWhileStatementComments.js => handleWhileStatementComments.ts} (74%) rename src/slang-comments/handlers/{handleYulBlockComments.js => handleYulBlockComments.ts} (81%) rename src/slang-comments/handlers/{index.js => index.ts} (100%) create mode 100644 src/slang-comments/handlers/types.d.ts rename src/slang-comments/{index.js => index.ts} (100%) rename src/slang-comments/{printer.js => printer.ts} (80%) create mode 100644 src/slang-utils/backward-compatibility.ts delete mode 100644 src/slang-utils/create-kind-check-function.js create mode 100644 src/slang-utils/create-kind-check-function.ts rename src/slang-utils/{is-binary-operation.js => is-binary-operation.ts} (100%) rename src/slang-utils/{is-comment.js => is-comment.ts} (100%) create mode 100644 src/slang-utils/prettier-version-satisfies.ts delete mode 100644 src/slangParser.js create mode 100644 src/slangParser.ts delete mode 100644 src/slangPrinter.js create mode 100644 src/slangPrinter.ts diff --git a/.c8rc b/.c8rc index d1a055fdd..55a27d442 100644 --- a/.c8rc +++ b/.c8rc @@ -7,6 +7,7 @@ "exclude": ["/node_modules/", "/src/prettier-comments/"], "include": [ "src/**/*.js", + "src/**/*.ts", "!src/prettier-comments/**/*.js", "!src/common/backward-compatibility.js" ], diff --git a/src/clean.js b/src/clean.ts similarity index 79% rename from src/clean.js rename to src/clean.ts index 6ce7c3d55..280b14184 100644 --- a/src/clean.js +++ b/src/clean.ts @@ -1,6 +1,6 @@ // Prettier offers a clean way to define ignored properties. const ignoredProperties = new Set(['loc', 'range', 'comments']); -function clean(/* ast, newObj, parent */) {} +function clean(/* ast, newObj, parent */): void {} clean.ignoredProperties = ignoredProperties; export default clean; diff --git a/src/options.js b/src/options.ts similarity index 94% rename from src/options.js rename to src/options.ts index 34fa5a44d..cf8a4e49c 100644 --- a/src/options.js +++ b/src/options.ts @@ -1,11 +1,12 @@ +import type { SupportOptions } from 'prettier'; + const CATEGORY_GLOBAL = 'Global'; const CATEGORY_COMMON = 'Common'; const CATEGORY_JAVASCRIPT = 'JavaScript'; const CATEGORY_SOLIDITY = 'Solidity'; -const options = { +const options: SupportOptions = { printWidth: { - since: '0.0.0', category: CATEGORY_GLOBAL, type: 'int', default: 80, @@ -20,14 +21,12 @@ const options = { range: { start: 0, end: Number.POSITIVE_INFINITY, step: 1 } }, useTabs: { - since: '1.0.0', category: CATEGORY_GLOBAL, type: 'boolean', default: false, description: 'Indent with tabs instead of spaces.' }, bracketSpacing: { - since: '0.0.0', category: CATEGORY_COMMON, type: 'boolean', default: true, @@ -35,7 +34,6 @@ const options = { oppositeDescription: 'Do not print spaces between brackets.' }, singleQuote: { - since: '0.0.0', category: CATEGORY_COMMON, type: 'boolean', default: false, diff --git a/src/slang-comments/handler.js b/src/slang-comments/handler.ts similarity index 67% rename from src/slang-comments/handler.js rename to src/slang-comments/handler.ts index bc095d4ed..15b58e552 100644 --- a/src/slang-comments/handler.js +++ b/src/slang-comments/handler.ts @@ -1,12 +1,15 @@ import handlers from './handlers/index.js'; +import type { AstPath, ParserOptions } from 'prettier'; +import type { Comment } from '../types.js'; + export function slangHandleOwnLineComment( - comment, - text, - options, - ast, - isLastComment -) { + comment: Comment, + text: string, + options: ParserOptions, + ast: AstPath, + isLastComment: boolean +): boolean { const { precedingNode, enclosingNode, followingNode } = comment; const handlerArguments = { text, @@ -22,12 +25,12 @@ export function slangHandleOwnLineComment( } export function slangHandleEndOfLineComment( - comment, - text, - options, - ast, - isLastComment -) { + comment: Comment, + text: string, + options: ParserOptions, + ast: AstPath, + isLastComment: boolean +): boolean { const { precedingNode, enclosingNode, followingNode } = comment; const handlerArguments = { text, @@ -43,12 +46,12 @@ export function slangHandleEndOfLineComment( } export function slangHandleRemainingComment( - comment, - text, - options, - ast, - isLastComment -) { + comment: Comment, + text: string, + options: ParserOptions, + ast: AstPath, + isLastComment: boolean +): boolean { const { precedingNode, enclosingNode, followingNode } = comment; const handlerArguments = { text, @@ -62,19 +65,3 @@ export function slangHandleRemainingComment( return handlers.some((handler) => handler(handlerArguments)); } - -export function isBlockComment(comment) { - return comment.type === 'BlockComment'; -} - -function isNodeOrComment(node) { - return node.type !== undefined; -} - -export function canAttachComment(node) { - return ( - isNodeOrComment(node) && - !isBlockComment(node) && - node.type !== 'LineComment' - ); -} diff --git a/src/slang-comments/handlers/handleBlockComments.js b/src/slang-comments/handlers/handleBlockComments.ts similarity index 79% rename from src/slang-comments/handlers/handleBlockComments.js rename to src/slang-comments/handlers/handleBlockComments.ts index 9122f611f..e570f2316 100644 --- a/src/slang-comments/handlers/handleBlockComments.js +++ b/src/slang-comments/handlers/handleBlockComments.ts @@ -1,5 +1,7 @@ import { util } from 'prettier'; +import type { HandlerParams } from './types'; + const { addDanglingComment, addLeadingComment, addTrailingComment } = util; export default function handleBlockComments({ @@ -7,14 +9,14 @@ export default function handleBlockComments({ enclosingNode, followingNode, comment -}) { +}: HandlerParams): boolean { if (enclosingNode?.kind !== 'Block') { return false; } if (precedingNode?.kind === 'Statements') { if (precedingNode.items.length === 0) { - addDanglingComment(precedingNode, comment); + addDanglingComment(precedingNode, comment, false); } else { addTrailingComment( precedingNode.items[precedingNode.items.length - 1], @@ -26,7 +28,7 @@ export default function handleBlockComments({ if (followingNode?.kind === 'Statements') { if (followingNode.items.length === 0) { - addDanglingComment(followingNode, comment); + addDanglingComment(followingNode, comment, false); } else { addLeadingComment(followingNode.items[0], comment); } diff --git a/src/slang-comments/handlers/handleContractDefinitionComments.js b/src/slang-comments/handlers/handleContractDefinitionComments.ts similarity index 82% rename from src/slang-comments/handlers/handleContractDefinitionComments.js rename to src/slang-comments/handlers/handleContractDefinitionComments.ts index c45eb522a..717486ad9 100644 --- a/src/slang-comments/handlers/handleContractDefinitionComments.js +++ b/src/slang-comments/handlers/handleContractDefinitionComments.ts @@ -1,6 +1,7 @@ import { util } from 'prettier'; -import { getNextNonSpaceNonCommentCharacter } from '../../common/backward-compatibility.js'; -import { locEnd } from '../../slang-utils/loc.js'; +import { getNextNonSpaceNonCommentCharacter } from '../../slang-utils/backward-compatibility.js'; + +import type { HandlerParams } from './types.js'; const { addLeadingComment, addDanglingComment, addTrailingComment } = util; @@ -10,16 +11,12 @@ export default function handleContractDefinitionComments({ enclosingNode, followingNode, comment -}) { +}: HandlerParams): boolean { if (enclosingNode?.kind !== 'ContractDefinition') { return false; } - const nextCharacter = getNextNonSpaceNonCommentCharacter( - text, - comment, - locEnd - ); + const nextCharacter = getNextNonSpaceNonCommentCharacter(text, comment); // Everything before the InheritanceSpecifier is pushed onto the beginning of // the ContractDefinition. @@ -34,7 +31,7 @@ export default function handleContractDefinitionComments({ // The comment is at the end of the body of the ContractDefinition. if (precedingNode?.kind === 'ContractMembers') { if (precedingNode.items.length === 0) { - addDanglingComment(precedingNode, comment); + addDanglingComment(precedingNode, comment, false); } else { addTrailingComment( precedingNode.items[precedingNode.items.length - 1], @@ -65,7 +62,7 @@ export default function handleContractDefinitionComments({ if (followingNode.items.length > 0) { addLeadingComment(followingNode.items[0], comment); } else { - addDanglingComment(followingNode, comment); + addDanglingComment(followingNode, comment, false); } return true; } diff --git a/src/slang-comments/handlers/handleParametersDeclarationComments.js b/src/slang-comments/handlers/handleParametersDeclarationComments.ts similarity index 79% rename from src/slang-comments/handlers/handleParametersDeclarationComments.js rename to src/slang-comments/handlers/handleParametersDeclarationComments.ts index bcf81a61d..0c80083dc 100644 --- a/src/slang-comments/handlers/handleParametersDeclarationComments.js +++ b/src/slang-comments/handlers/handleParametersDeclarationComments.ts @@ -1,5 +1,7 @@ import { util } from 'prettier'; +import type { HandlerParams } from './types'; + const { addDanglingComment, addLeadingComment, addTrailingComment } = util; export default function handleBlockComments({ @@ -7,14 +9,14 @@ export default function handleBlockComments({ enclosingNode, followingNode, comment -}) { +}: HandlerParams): boolean { if (enclosingNode?.kind !== 'ParametersDeclaration') { return false; } if (precedingNode?.kind === 'Parameters') { if (precedingNode.items.length === 0) { - addDanglingComment(precedingNode, comment); + addDanglingComment(precedingNode, comment, false); } else { addTrailingComment( precedingNode.items[precedingNode.items.length - 1], @@ -26,7 +28,7 @@ export default function handleBlockComments({ if (followingNode?.kind === 'Parameters') { if (followingNode.items.length === 0) { - addDanglingComment(followingNode, comment); + addDanglingComment(followingNode, comment, false); } else { addLeadingComment(followingNode.items[0], comment); } diff --git a/src/slang-comments/handlers/handleWhileStatementComments.js b/src/slang-comments/handlers/handleWhileStatementComments.ts similarity index 74% rename from src/slang-comments/handlers/handleWhileStatementComments.js rename to src/slang-comments/handlers/handleWhileStatementComments.ts index 64b604a3f..63d767b09 100644 --- a/src/slang-comments/handlers/handleWhileStatementComments.js +++ b/src/slang-comments/handlers/handleWhileStatementComments.ts @@ -1,6 +1,7 @@ import { util } from 'prettier'; -import { getNextNonSpaceNonCommentCharacter } from '../../common/backward-compatibility.js'; -import { locEnd } from '../../slang-utils/loc.js'; +import { getNextNonSpaceNonCommentCharacter } from '../../slang-utils/backward-compatibility.js'; + +import type { HandlerParams } from './types.js'; const { addTrailingComment } = util; @@ -10,7 +11,7 @@ export default function handleWhileStatementComments({ enclosingNode, followingNode, comment -}) { +}: HandlerParams): boolean { if (enclosingNode?.kind !== 'WhileStatement' || !followingNode) { return false; } @@ -20,11 +21,7 @@ export default function handleWhileStatementComments({ // while (a /* comment */) {} // The only workaround I found is to look at the next character to see if // it is a ). - const nextCharacter = getNextNonSpaceNonCommentCharacter( - text, - comment, - locEnd - ); + const nextCharacter = getNextNonSpaceNonCommentCharacter(text, comment); if (nextCharacter === ')' || enclosingNode.condition === precedingNode) { addTrailingComment(precedingNode, comment); return true; diff --git a/src/slang-comments/handlers/handleYulBlockComments.js b/src/slang-comments/handlers/handleYulBlockComments.ts similarity index 81% rename from src/slang-comments/handlers/handleYulBlockComments.js rename to src/slang-comments/handlers/handleYulBlockComments.ts index 335fa132f..bec362445 100644 --- a/src/slang-comments/handlers/handleYulBlockComments.js +++ b/src/slang-comments/handlers/handleYulBlockComments.ts @@ -1,5 +1,7 @@ import { util } from 'prettier'; +import type { HandlerParams } from './types'; + const { addLeadingComment, addDanglingComment } = util; export default function handleYulBlockComments({ @@ -7,7 +9,7 @@ export default function handleYulBlockComments({ enclosingNode, followingNode, comment -}) { +}: HandlerParams): boolean { if (enclosingNode?.kind !== 'YulBlock') { return false; } @@ -16,7 +18,7 @@ export default function handleYulBlockComments({ precedingNode?.kind === 'YulStatements' && precedingNode.items.length === 0 ) { - addDanglingComment(precedingNode, comment); + addDanglingComment(precedingNode, comment, false); return true; } diff --git a/src/slang-comments/handlers/index.js b/src/slang-comments/handlers/index.ts similarity index 100% rename from src/slang-comments/handlers/index.js rename to src/slang-comments/handlers/index.ts diff --git a/src/slang-comments/handlers/types.d.ts b/src/slang-comments/handlers/types.d.ts new file mode 100644 index 000000000..3d0f15224 --- /dev/null +++ b/src/slang-comments/handlers/types.d.ts @@ -0,0 +1,9 @@ +import type { astNode, Comment } from '../../types'; + +interface HandlerParams { + text: string; + precedingNode?: astNode; + enclosingNode?: astNode; + followingNode?: astNode; + comment: Comment; +} diff --git a/src/slang-comments/index.js b/src/slang-comments/index.ts similarity index 100% rename from src/slang-comments/index.js rename to src/slang-comments/index.ts diff --git a/src/slang-comments/printer.js b/src/slang-comments/printer.ts similarity index 80% rename from src/slang-comments/printer.js rename to src/slang-comments/printer.ts index ce9646e78..37d52121d 100644 --- a/src/slang-comments/printer.js +++ b/src/slang-comments/printer.ts @@ -1,9 +1,12 @@ import { doc } from 'prettier'; import { isBlockComment, isLineComment } from '../slang-utils/is-comment.js'; +import type { AstPath, Doc } from 'prettier'; +import type { Comment } from '../types.js'; + const { hardline, join, literalline } = doc.builders; -function isIndentableBlockComment(comment) { +function isIndentableBlockComment(comment: Comment): boolean { // If the comment has multiple lines and every line starts with a star // we can fix the indentation of each line. The stars in the `/*` and // `*/` delimiters are not included in the comment value, so add them @@ -12,7 +15,7 @@ function isIndentableBlockComment(comment) { return lines.length > 1 && lines.every((line) => line.trimStart()[0] === '*'); } -function printIndentableBlockComment(comment) { +function printIndentableBlockComment(comment: Comment): Doc { const lines = comment.value.split('\n'); return join( @@ -25,7 +28,7 @@ function printIndentableBlockComment(comment) { ); } -export function printComment(commentPath) { +export function printComment(commentPath: AstPath): Doc { const comment = commentPath.node; if (isLineComment(comment)) { diff --git a/src/slang-nodes/AssignmentExpression.ts b/src/slang-nodes/AssignmentExpression.ts index 9f72a9d5e..17fd54104 100644 --- a/src/slang-nodes/AssignmentExpression.ts +++ b/src/slang-nodes/AssignmentExpression.ts @@ -45,6 +45,7 @@ export class AssignmentExpression implements SlangNode { return [ path.call(print, 'leftOperand'), ` ${this.operator}`, + typeof this.rightOperand.variant !== 'string' && isBinaryOperation(this.rightOperand.variant) ? group(indent([line, path.call(print, 'rightOperand')])) : [' ', path.call(print, 'rightOperand')] diff --git a/src/slang-nodes/ContractDefinition.ts b/src/slang-nodes/ContractDefinition.ts index 7fd0dc57a..a2cf73794 100644 --- a/src/slang-nodes/ContractDefinition.ts +++ b/src/slang-nodes/ContractDefinition.ts @@ -5,7 +5,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; import { InheritanceSpecifier } from './InheritanceSpecifier.js'; import { ContractMembers } from './ContractMembers.js'; -import { FunctionDefinition } from './FunctionDefinition.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; diff --git a/src/slang-nodes/ExponentiationExpression.ts b/src/slang-nodes/ExponentiationExpression.ts index 32a333172..1f50ec88e 100644 --- a/src/slang-nodes/ExponentiationExpression.ts +++ b/src/slang-nodes/ExponentiationExpression.ts @@ -27,6 +27,12 @@ const printExponentiationExpression = createBinaryOperationPrinter( indent(document) // always indent ); +const objectConfig = { + writable: true, + enumerable: true, + configurable: true +}; + export class ExponentiationExpression implements SlangNode { readonly kind = NonterminalKind.ExponentiationExpression; @@ -79,60 +85,85 @@ export class ExponentiationExpression implements SlangNode { end: this.rightOperand.variant.leftOperand.loc.end }; this.leftOperand = Object.create(Expression.prototype, { - kind: { value: NonterminalKind.Expression }, - loc: { value: { ...leftLoc } }, - comments: { value: [] }, + kind: { value: NonterminalKind.Expression, ...objectConfig }, + loc: { value: { ...leftLoc }, ...objectConfig }, + comments: { value: [], ...objectConfig }, variant: { value: Object.create(TupleExpression.prototype, { - kind: { value: NonterminalKind.TupleExpression }, - loc: { value: { ...leftLoc } }, - comments: { value: [] }, - openParen: { value: '(' }, + kind: { + value: NonterminalKind.TupleExpression, + ...objectConfig + }, + loc: { value: { ...leftLoc }, ...objectConfig }, + comments: { value: [], ...objectConfig }, + openParen: { value: '(', ...objectConfig }, items: { value: Object.create(TupleValues.prototype, { - kind: { value: NonterminalKind.TupleValues }, - loc: { value: { ...leftLoc } }, - comments: { value: [] }, + kind: { + value: NonterminalKind.TupleValues, + ...objectConfig + }, + loc: { value: { ...leftLoc }, ...objectConfig }, + comments: { value: [], ...objectConfig }, items: { value: [ Object.create(TupleValue.prototype, { - kind: { value: NonterminalKind.TupleValue }, - loc: { value: { ...leftLoc } }, - comments: { value: [] }, + kind: { + value: NonterminalKind.TupleValue, + ...objectConfig + }, + loc: { value: { ...leftLoc }, ...objectConfig }, + comments: { value: [], ...objectConfig }, expression: { value: Object.create(Expression.prototype, { - kind: { value: NonterminalKind.Expression }, - loc: { value: { ...leftLoc } }, - comments: { value: [] }, + kind: { + value: NonterminalKind.Expression, + ...objectConfig + }, + loc: { value: { ...leftLoc }, ...objectConfig }, + comments: { value: [], ...objectConfig }, variant: { value: Object.create( ExponentiationExpression.prototype, { kind: { value: - NonterminalKind.ExponentiationExpression + NonterminalKind.ExponentiationExpression, + ...objectConfig + }, + loc: { + value: { ...leftLoc }, + ...objectConfig + }, + comments: { value: [], ...objectConfig }, + leftOperand: { + value: this.leftOperand, + ...objectConfig }, - loc: { value: { ...leftLoc } }, - comments: { value: [] }, - leftOperand: { value: this.leftOperand }, - operator: { value: '**' }, + operator: { value: '**', ...objectConfig }, rightOperand: { value: - this.rightOperand.variant.leftOperand + this.rightOperand.variant.leftOperand, + ...objectConfig } } - ) + ), + ...objectConfig } - }) + }), + ...objectConfig } }) - ] + ], + ...objectConfig }, - separators: { value: [] } - }) + separators: { value: [], ...objectConfig } + }), + ...objectConfig }, - closeParen: { value: ')' } - }) + closeParen: { value: ')', ...objectConfig } + }), + ...objectConfig } }); this.rightOperand = this.rightOperand.variant.rightOperand; diff --git a/src/slang-nodes/ModifierDefinition.ts b/src/slang-nodes/ModifierDefinition.ts index bb0126fc2..7dcec8d3d 100644 --- a/src/slang-nodes/ModifierDefinition.ts +++ b/src/slang-nodes/ModifierDefinition.ts @@ -10,6 +10,11 @@ import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; import type { SlangNode } from '../types.js'; +const objectConfig = { + writable: true, + enumerable: true, + configurable: true +}; export class ModifierDefinition implements SlangNode { readonly kind = NonterminalKind.ModifierDefinition; @@ -70,20 +75,27 @@ export class ModifierDefinition implements SlangNode { }; this.parameters = Object.create(ParametersDeclaration.prototype, { - kind: { value: NonterminalKind.ParametersDeclaration }, - loc: { value: { ...parametersLoc } }, - comments: { value: [] }, - openParen: { value: '(' }, + kind: { + value: NonterminalKind.ParametersDeclaration, + ...objectConfig + }, + loc: { + value: { ...parametersLoc }, + ...objectConfig + }, + comments: { value: [], ...objectConfig }, + openParen: { value: '(', ...objectConfig }, parameters: { value: Object.create(Parameters.prototype, { - kind: { value: NonterminalKind.Parameters }, - loc: { value: { ...parametersLoc } }, - comments: { value: [] }, - items: { value: [] }, - separators: { value: [] } - }) + kind: { value: NonterminalKind.Parameters, ...objectConfig }, + loc: { value: { ...parametersLoc }, ...objectConfig }, + comments: { value: [], ...objectConfig }, + items: { value: [], ...objectConfig }, + separators: { value: [], ...objectConfig } + }), + ...objectConfig }, - closeParen: { value: ')' } + closeParen: { value: ')', ...objectConfig } }); } } diff --git a/src/slang-nodes/ModifierInvocation.ts b/src/slang-nodes/ModifierInvocation.ts index 04c9d000f..a8b54fc69 100644 --- a/src/slang-nodes/ModifierInvocation.ts +++ b/src/slang-nodes/ModifierInvocation.ts @@ -7,7 +7,6 @@ import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; import type { SlangNode } from '../types.js'; -import type { PositionalArgumentsDeclaration } from './PositionalArgumentsDeclaration.js'; export class ModifierInvocation implements SlangNode { readonly kind = NonterminalKind.ModifierInvocation; diff --git a/src/slang-nodes/TupleValues.ts b/src/slang-nodes/TupleValues.ts index f08fbf41a..e843f678f 100644 --- a/src/slang-nodes/TupleValues.ts +++ b/src/slang-nodes/TupleValues.ts @@ -36,6 +36,7 @@ export class TupleValues implements SlangNode { print(path: AstPath, print: (path: AstPath) => Doc): Doc { return this.items.length === 1 && + typeof this.items[0].expression!.variant !== 'string' && isBinaryOperation(this.items[0].expression!.variant) ? path.map(print, 'items') : printSeparatedList(path.map(print, 'items')); diff --git a/src/slang-printers/create-binary-operation-printer.ts b/src/slang-printers/create-binary-operation-printer.ts index 161004438..89563baa1 100644 --- a/src/slang-printers/create-binary-operation-printer.ts +++ b/src/slang-printers/create-binary-operation-printer.ts @@ -16,8 +16,10 @@ function rightOperandPrint( // If it's a single binary operation, avoid having a small right // operand like - 1 on its own line const shouldGroup = - !isBinaryOperation(node.leftOperand.variant) && - !isBinaryOperation(path.getNode(2)); + !( + typeof node.leftOperand.variant !== 'string' && + isBinaryOperation(node.leftOperand.variant) + ) && !isBinaryOperation(path.getNode(2)); return shouldGroup ? group(rightOperand) : rightOperand; } diff --git a/src/slang-printers/print-comments.ts b/src/slang-printers/print-comments.ts index 8072b72ca..ee3995fbb 100644 --- a/src/slang-printers/print-comments.ts +++ b/src/slang-printers/print-comments.ts @@ -1,6 +1,6 @@ import { doc } from 'prettier'; import { printComment } from '../slang-comments/printer.js'; -import { isPrettier2 } from '../common/backward-compatibility.js'; +import { getNode, isPrettier2 } from '../slang-utils/backward-compatibility.js'; import type { AstPath, Doc } from 'prettier'; import type { Comment, astNode } from '../types.js'; @@ -14,14 +14,11 @@ export function printComments(node: astNode, path: AstPath): Doc[] { line, path .map((commentPath) => { - const comment = commentPath.getValue() as Comment; + const comment = getNode(commentPath) as Comment; if (comment.trailing || comment.leading || comment.printed) { - return null; + return ''; } comment.printed = true; - // TODO: prettier Prints leading and trailing comments anyway. - comment.leading = false; - comment.trailing = false; return printComment(commentPath); }, 'comments') .filter(Boolean) diff --git a/src/slang-printers/print-preserving-empty-lines.ts b/src/slang-printers/print-preserving-empty-lines.ts index a61122691..f8020b3a0 100644 --- a/src/slang-printers/print-preserving-empty-lines.ts +++ b/src/slang-printers/print-preserving-empty-lines.ts @@ -1,5 +1,9 @@ import { doc } from 'prettier'; -import { isLast, isNextLineEmpty } from '../common/backward-compatibility.js'; +import { + isLast, + isNextLineEmpty +} from '../slang-utils/backward-compatibility.js'; +import { locEnd } from '../slang-utils/loc.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; import type { YulStatement } from '../slang-nodes/YulStatement.js'; @@ -27,7 +31,7 @@ export function printPreservingEmptyLines( !isLast(childPath, key, index) && // Append an empty line if the original text already had an one after the // current `node` - isNextLineEmpty(options.originalText, options.locEnd(node)) + isNextLineEmpty(options.originalText, locEnd(node)) ? hardline : '' ]; diff --git a/src/slang-utils/backward-compatibility.ts b/src/slang-utils/backward-compatibility.ts new file mode 100644 index 000000000..8a2f6c14d --- /dev/null +++ b/src/slang-utils/backward-compatibility.ts @@ -0,0 +1,44 @@ +import { util } from 'prettier'; +import { prettierVersionSatisfies } from './prettier-version-satisfies.js'; +import { locEnd } from './loc.js'; + +import type { AstPath } from 'prettier'; +import type { utilV2 } from './types'; +import type { astNode, Comment } from '../types'; + +export const isPrettier2 = prettierVersionSatisfies('^2.3.0'); + +// The functions in this file 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. + +export function isNextLineEmpty(text: string, startIndex: number): boolean { + return isPrettier2 + ? (util as utilV2).isNextLineEmptyAfterIndex(text, startIndex) + : util.isNextLineEmpty(text, startIndex); // V3 deprecated `isNextLineEmptyAfterIndex` +} + +export function getNextNonSpaceNonCommentCharacter( + text: string, + node: astNode | Comment +): string { + if (isPrettier2) { + const index = (util as utilV2).getNextNonSpaceNonCommentCharacterIndex( + text, + node, + locEnd + ); + return index === false ? '' : text.charAt(index); + } + return util.getNextNonSpaceNonCommentCharacter(text, locEnd(node)); // V3 exposes this function directly +} + +// TODO: remove undefined once we stop supporting prettier 2 +export const getNode = (path: AstPath): astNode | Comment | null | undefined => + isPrettier2 ? path.getValue() : path.node; // V3 deprecated `getValue` + +export function isLast(path: AstPath, key: string, index: number): boolean { + return isPrettier2 + ? index === path.getParentNode()[key].length - 1 + : path.isLast; +} diff --git a/src/slang-utils/create-hug-function.ts b/src/slang-utils/create-hug-function.ts index a2a7b47df..e22c3c797 100644 --- a/src/slang-utils/create-hug-function.ts +++ b/src/slang-utils/create-hug-function.ts @@ -7,47 +7,60 @@ import { isBinaryOperation } from './is-binary-operation.js'; import type { BinaryOperation } from '../types.js'; +const objectConfig = { + writable: true, + enumerable: true, + configurable: true +}; + export function createHugFunction( huggableOperators: string[] ): (node: Expression) => Expression { const operators = new Set(huggableOperators); return (node: Expression): Expression => { if ( + typeof node.variant !== 'string' && isBinaryOperation(node.variant) && operators.has((node.variant as BinaryOperation).operator) ) { const { loc } = node; return Object.create(Expression.prototype, { - kind: { value: NonterminalKind.Expression }, - loc: { value: { ...loc } }, - comments: { value: [] }, + kind: { value: NonterminalKind.Expression, ...objectConfig }, + loc: { value: { ...loc }, ...objectConfig }, + comments: { value: [], ...objectConfig }, variant: { value: Object.create(TupleExpression.prototype, { - kind: { value: NonterminalKind.TupleExpression }, - loc: { value: { ...loc } }, - comments: { value: [] }, - openParen: { value: '(' }, + kind: { value: NonterminalKind.TupleExpression, ...objectConfig }, + loc: { value: { ...loc }, ...objectConfig }, + comments: { value: [], ...objectConfig }, + openParen: { value: '(', ...objectConfig }, items: { value: Object.create(TupleValues.prototype, { - kind: { value: NonterminalKind.TupleValues }, - loc: { value: { ...loc } }, - comments: { value: [] }, + kind: { value: NonterminalKind.TupleValues, ...objectConfig }, + loc: { value: { ...loc }, ...objectConfig }, + comments: { value: [], ...objectConfig }, items: { value: [ Object.create(TupleValue.prototype, { - kind: { value: NonterminalKind.TupleValue }, - loc: { value: { ...loc } }, - comments: { value: [] }, - expression: { value: node } + kind: { + value: NonterminalKind.TupleValue, + ...objectConfig + }, + loc: { value: { ...loc }, ...objectConfig }, + comments: { value: [], ...objectConfig }, + expression: { value: node, ...objectConfig } }) - ] + ], + ...objectConfig }, - separators: { value: [] } - }) + separators: { value: [], ...objectConfig } + }), + ...objectConfig }, - closeParen: { value: ')' } - }) + closeParen: { value: ')', ...objectConfig } + }), + ...objectConfig } }); } diff --git a/src/slang-utils/create-kind-check-function.js b/src/slang-utils/create-kind-check-function.js deleted file mode 100644 index 4f3517ed8..000000000 --- a/src/slang-utils/create-kind-check-function.js +++ /dev/null @@ -1,4 +0,0 @@ -export function createKindCheckFunction(kindsArray) { - const kinds = new Set(kindsArray); - return (node) => kinds.has(node?.kind); -} diff --git a/src/slang-utils/create-kind-check-function.ts b/src/slang-utils/create-kind-check-function.ts new file mode 100644 index 000000000..3ed1afb0c --- /dev/null +++ b/src/slang-utils/create-kind-check-function.ts @@ -0,0 +1,9 @@ +import { Node } from '@nomicfoundation/slang/cst'; +import { astNode, Comment } from '../types'; + +export function createKindCheckFunction( + kindsArray: string[] +): (node: astNode | Comment | Node) => boolean { + const kinds = new Set(kindsArray); + return (node: astNode | Comment | Node): boolean => kinds.has(node.kind); +} diff --git a/src/slang-utils/is-binary-operation.js b/src/slang-utils/is-binary-operation.ts similarity index 100% rename from src/slang-utils/is-binary-operation.js rename to src/slang-utils/is-binary-operation.ts diff --git a/src/slang-utils/is-comment.js b/src/slang-utils/is-comment.ts similarity index 100% rename from src/slang-utils/is-comment.js rename to src/slang-utils/is-comment.ts diff --git a/src/slang-utils/prettier-version-satisfies.ts b/src/slang-utils/prettier-version-satisfies.ts new file mode 100644 index 000000000..2258ce819 --- /dev/null +++ b/src/slang-utils/prettier-version-satisfies.ts @@ -0,0 +1,8 @@ +import { version } from 'prettier'; +import satisfies from 'semver/functions/satisfies.js'; + +import type { Range } from 'semver'; + +export function prettierVersionSatisfies(range: string | Range): boolean { + return satisfies(version, range); +} diff --git a/src/slang-utils/types.d.ts b/src/slang-utils/types.d.ts index 3fe2aa0ab..46e4f07d8 100644 --- a/src/slang-utils/types.d.ts +++ b/src/slang-utils/types.d.ts @@ -10,6 +10,8 @@ import type { OverrideSpecifier, ModifierInvocation } from '../slang-nodes'; +import type { util } from 'prettier'; +import type { astNode, Comment } from '../types'; type SortableAttribute = | ConstructorAttribute @@ -22,3 +24,15 @@ type SortableAttribute = | UnnamedFunctionAttribute; type SortableVariant = OverrideSpecifier | ModifierInvocation; + +declare namespace utilV2Functions { + function getNextNonSpaceNonCommentCharacterIndex( + text: string, + node: astNode | Comment, + locEnd: (node: astNode) => number + ): number | false; + + function isNextLineEmptyAfterIndex(text: string, startIndex: number): boolean; +} + +type utilV2 = typeof util & typeof utilV2Functions; diff --git a/src/slangParser.js b/src/slangParser.js deleted file mode 100644 index 55a7cb8c4..000000000 --- a/src/slangParser.js +++ /dev/null @@ -1,26 +0,0 @@ -// https://prettier.io/docs/en/plugins.html#parsers -// import parser from '@solidity-parser/parser'; -import { Language } from '@nomicfoundation/slang/language/index.js'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { SourceUnit } from '@nomicfoundation/slang/ast/index.js'; -import coerce from 'semver/functions/coerce.js'; -import * as parsers from './slang-nodes/index.js'; - -function genericParse(ast, offset, options) { - return new parsers[ast.cst.kind](ast, offset, options); -} - -function parse(text, _parsers, options = _parsers) { - const compiler = coerce(options.compiler); - - const language = new Language(compiler?.version || '0.8.26'); - const ast = new SourceUnit( - language.parse(NonterminalKind.SourceUnit, text).tree() - ); - - const parsed = genericParse(ast, 0, options); - - return parsed; -} - -export default parse; diff --git a/src/slangParser.ts b/src/slangParser.ts new file mode 100644 index 000000000..eee8d089a --- /dev/null +++ b/src/slangParser.ts @@ -0,0 +1,28 @@ +// https://prettier.io/docs/en/plugins.html#parsers +// import parser from '@solidity-parser/parser'; +import { Language } from '@nomicfoundation/slang/language/index.js'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { SourceUnit as SlangSourceUnit } from '@nomicfoundation/slang/ast/index.js'; +import coerce from 'semver/functions/coerce.js'; +import { SourceUnit } from './slang-nodes/SourceUnit.js'; + +import type { NonterminalNode } from '@nomicfoundation/slang/cst/index.js'; +import type { Parser, ParserOptions } from 'prettier'; +import type { astNode } from './types.js'; + +function parse( + text: string, + _parsers: Parser[] | ParserOptions, + options = _parsers as ParserOptions +): astNode { + const compiler = coerce(options.compiler); + + const language = new Language(compiler?.version || '0.8.26'); + const ast = new SlangSourceUnit( + language.parse(NonterminalKind.SourceUnit, text).tree() as NonterminalNode + ); + + return new SourceUnit(ast, 0, options); +} + +export default parse; diff --git a/src/slangPrinter.js b/src/slangPrinter.js deleted file mode 100644 index 7f10ec4ba..000000000 --- a/src/slangPrinter.js +++ /dev/null @@ -1,50 +0,0 @@ -import { prettierVersionSatisfies } from './common/util.js'; -import { isBlockComment } from './slang-utils/is-comment.js'; -import ignoreComments from './comments/ignore.js'; - -let checked = false; - -function prettierVersionCheck() { - if (checked) return; - if (!prettierVersionSatisfies('>=2.3.0')) { - throw new Error( - 'The version of prettier in your node-modules does not satisfy the required ">=2.3.0" constraint. Please update the version of Prettier.' - ); - } - checked = true; -} - -function hasNodeIgnoreComment(node) { - return ( - node?.comments && - node.comments.some( - (comment) => - comment.value - .slice(2, isBlockComment(comment) ? -2 : undefined) - .trim() === 'prettier-ignore' - ) - ); -} - -function genericPrint(path, options, print) { - prettierVersionCheck(); - - const node = path.getValue(); - - if (node === null) { - return ''; - } - - if (hasNodeIgnoreComment(node)) { - ignoreComments(path); - - return options.originalText.slice( - options.locStart(node), - options.locEnd(node) - ); - } - - return node.print(path, print, options); -} - -export default genericPrint; diff --git a/src/slangPrinter.ts b/src/slangPrinter.ts new file mode 100644 index 000000000..acb06ad3a --- /dev/null +++ b/src/slangPrinter.ts @@ -0,0 +1,93 @@ +import { prettierVersionSatisfies } from './slang-utils/prettier-version-satisfies.js'; +import { getNode } from './slang-utils/backward-compatibility.js'; +import { isBlockComment } from './slang-utils/is-comment.js'; + +import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { astNode, Comment } from './types.js'; + +let checked = false; + +function prettierVersionCheck(): void { + if (checked) return; + if (!prettierVersionSatisfies('>=2.3.0')) { + throw new Error( + 'The version of prettier in your node-modules does not satisfy the required ">=2.3.0" constraint. Please update the version of Prettier.' + ); + } + checked = true; +} + +function hasNodeIgnoreComment(node: astNode): boolean { + return ( + node?.comments && + node.comments.some( + (comment) => + comment.value + .slice(2, isBlockComment(comment) ? -2 : undefined) + .trim() === 'prettier-ignore' + ) + ); +} + +function ignoreComments(path: AstPath): void { + // TODO: remove undefined once we stop supporting prettier 2 + const node = getNode(path) as astNode | null | undefined; + // We ignore anything that is not an object + if (node === null || node === undefined || typeof node !== 'object') return; + + const keys = Object.keys(node) as (keyof astNode)[]; + keys.forEach((key) => { + switch (key) { + // We ignore `kind`, `loc`, and comments since these are added by the + // parser + case 'kind': + case 'loc': + case 'print': + break; + // The key `comments` will contain every comment for this node + case 'comments': + path.each((commentPath) => { + const comment = getNode(commentPath) as Comment; + comment.printed = true; + }, 'comments'); + break; + default: + // If the value for that key is an Array or an Object we go deeper. + const childNode = node[key]; + if (typeof childNode === 'object') { + if (Array.isArray(childNode)) { + path.each(ignoreComments, key); + return; + } + path.call(ignoreComments, key); + } + } + }); +} + +function genericPrint( + path: AstPath, + options: ParserOptions, + print: (path: AstPath) => Doc +): Doc { + prettierVersionCheck(); + + const node = getNode(path) as astNode | null | undefined; + + if (node === null || node === undefined) { + return ''; + } + + if (hasNodeIgnoreComment(node)) { + ignoreComments(path); + + return options.originalText.slice( + options.locStart(node), + options.locEnd(node) + ); + } + + return node.print(path, print, options); +} + +export default genericPrint; diff --git a/tests/config/run-format-test.js b/tests/config/run-format-test.js index 8b5164dd3..a7742da44 100644 --- a/tests/config/run-format-test.js +++ b/tests/config/run-format-test.js @@ -363,7 +363,9 @@ async function runTest({ if (isAstUnstableTest) { expect(formattedAst).not.toEqual(originalAst); } else { - expect(formattedAst).toEqual(originalAst); + expect(JSON.parse(JSON.stringify(formattedAst))).toEqual( + JSON.parse(JSON.stringify(originalAst)), + ); } } From 2eed0a33d929cc0108365c0e1835fd9d1262b716 Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 31 Jul 2024 16:09:17 +1200 Subject: [PATCH 101/160] removing unneeded ParserOptions that were not removed due to cyclic dependancy --- .eslintrc | 1 - src/slang-comments/handlers/types.d.ts | 8 +++--- src/slang-nodes/Parameters.ts | 6 +---- src/slang-nodes/Pragma.ts | 3 +-- src/slang-nodes/VersionComparator.ts | 10 +++---- src/slang-nodes/VersionExpression.ts | 14 +++------- src/slang-nodes/VersionExpressionSet.ts | 10 +++---- src/slang-nodes/VersionExpressionSets.ts | 10 +++---- src/slang-nodes/VersionPragma.ts | 6 ++--- src/slang-nodes/VersionRange.ts | 14 +++------- src/slang-printers/print-comments.ts | 4 +-- src/slang-utils/backward-compatibility.ts | 6 ++--- src/slang-utils/create-kind-check-function.ts | 6 ++--- src/slang-utils/get-offsets.ts | 8 +++--- src/slang-utils/loc.ts | 6 ++--- src/slang-utils/types.d.ts | 6 ++--- src/slangParser.ts | 4 +-- src/slangPrinter.ts | 16 +++++------- src/types.d.ts | 26 +++++++------------ 19 files changed, 62 insertions(+), 102 deletions(-) diff --git a/.eslintrc b/.eslintrc index d731dac9f..3122ce9e6 100644 --- a/.eslintrc +++ b/.eslintrc @@ -28,7 +28,6 @@ "rules": { "import/extensions": "off", "import/prefer-default-export": "off", - "import/no-cycle": "off", "class-methods-use-this": "off" } } diff --git a/src/slang-comments/handlers/types.d.ts b/src/slang-comments/handlers/types.d.ts index 3d0f15224..e1f044f43 100644 --- a/src/slang-comments/handlers/types.d.ts +++ b/src/slang-comments/handlers/types.d.ts @@ -1,9 +1,9 @@ -import type { astNode, Comment } from '../../types'; +import type { AstNode, Comment } from '../../types'; interface HandlerParams { text: string; - precedingNode?: astNode; - enclosingNode?: astNode; - followingNode?: astNode; + precedingNode?: AstNode; + enclosingNode?: AstNode; + followingNode?: AstNode; comment: Comment; } diff --git a/src/slang-nodes/Parameters.ts b/src/slang-nodes/Parameters.ts index 0f3b6c424..2681d400f 100644 --- a/src/slang-nodes/Parameters.ts +++ b/src/slang-nodes/Parameters.ts @@ -35,11 +35,7 @@ export class Parameters implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc, - options: ParserOptions - ): Doc { + print(path: AstPath, print: (path: AstPath) => Doc): Doc { if (this.items.length > 0) { return printSeparatedList(path.map(print, 'items'), { grouped: false }); } diff --git a/src/slang-nodes/Pragma.ts b/src/slang-nodes/Pragma.ts index 91dd34c2e..a8d27c9ed 100644 --- a/src/slang-nodes/Pragma.ts +++ b/src/slang-nodes/Pragma.ts @@ -38,8 +38,7 @@ export class Pragma implements SlangNode { case 'VersionPragma': this.variant = new VersionPragma( ast.variant as ast.VersionPragma, - offsets[0], - options + offsets[0] ); break; default: diff --git a/src/slang-nodes/VersionComparator.ts b/src/slang-nodes/VersionComparator.ts index e9742da74..7bfe32899 100644 --- a/src/slang-nodes/VersionComparator.ts +++ b/src/slang-nodes/VersionComparator.ts @@ -3,7 +3,7 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; import { VersionExpression } from './VersionExpression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; -import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { AstPath, Doc } from 'prettier'; import type { SlangNode } from '../types.js'; export class VersionComparator implements SlangNode { @@ -17,16 +17,12 @@ export class VersionComparator implements SlangNode { operand: VersionExpression; - constructor( - ast: ast.VersionComparator, - offset: number, - options: ParserOptions - ) { + constructor(ast: ast.VersionComparator, offset: number) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; this.operator = ast.operator.text; - this.operand = new VersionExpression(ast.operand, offsets[0], options); + this.operand = new VersionExpression(ast.operand, offsets[0]); metadata = updateMetadata(metadata, [this.operand]); diff --git a/src/slang-nodes/VersionExpression.ts b/src/slang-nodes/VersionExpression.ts index 85d21677b..5b89257de 100644 --- a/src/slang-nodes/VersionExpression.ts +++ b/src/slang-nodes/VersionExpression.ts @@ -6,7 +6,7 @@ import { VersionComparator } from './VersionComparator.js'; import { VersionSpecifiers } from './VersionSpecifiers.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; -import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { AstPath, Doc } from 'prettier'; import type { SlangNode } from '../types.js'; export class VersionExpression implements SlangNode { @@ -18,11 +18,7 @@ export class VersionExpression implements SlangNode { variant: VersionRange | VersionComparator | VersionSpecifiers | string; - constructor( - ast: ast.VersionExpression, - offset: number, - options: ParserOptions - ) { + constructor(ast: ast.VersionExpression, offset: number) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; @@ -33,15 +29,13 @@ export class VersionExpression implements SlangNode { case 'VersionRange': this.variant = new VersionRange( ast.variant as ast.VersionRange, - offsets[0], - options + offsets[0] ); break; case 'VersionComparator': this.variant = new VersionComparator( ast.variant as ast.VersionComparator, - offsets[0], - options + offsets[0] ); break; case 'VersionSpecifiers': diff --git a/src/slang-nodes/VersionExpressionSet.ts b/src/slang-nodes/VersionExpressionSet.ts index 821bcd0ef..473ef6e05 100644 --- a/src/slang-nodes/VersionExpressionSet.ts +++ b/src/slang-nodes/VersionExpressionSet.ts @@ -4,7 +4,7 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; import { VersionExpression } from './VersionExpression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; -import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { AstPath, Doc } from 'prettier'; import type { SlangNode } from '../types.js'; const { join } = doc.builders; @@ -18,16 +18,12 @@ export class VersionExpressionSet implements SlangNode { items: VersionExpression[]; - constructor( - ast: ast.VersionExpressionSet, - offset: number, - options: ParserOptions - ) { + constructor(ast: ast.VersionExpressionSet, offset: number) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; this.items = ast.items.map( - (item, index) => new VersionExpression(item, offsets[index], options) + (item, index) => new VersionExpression(item, offsets[index]) ); metadata = updateMetadata(metadata, [this.items]); diff --git a/src/slang-nodes/VersionExpressionSets.ts b/src/slang-nodes/VersionExpressionSets.ts index 9d00704bc..4fe5118ab 100644 --- a/src/slang-nodes/VersionExpressionSets.ts +++ b/src/slang-nodes/VersionExpressionSets.ts @@ -3,7 +3,7 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; import { VersionExpressionSet } from './VersionExpressionSet.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; -import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { AstPath, Doc } from 'prettier'; import type { SlangNode } from '../types.js'; export class VersionExpressionSets implements SlangNode { @@ -17,16 +17,12 @@ export class VersionExpressionSets implements SlangNode { separators: string[]; - constructor( - ast: ast.VersionExpressionSets, - offset: number, - options: ParserOptions - ) { + constructor(ast: ast.VersionExpressionSets, offset: number) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; this.items = ast.items.map( - (item, index) => new VersionExpressionSet(item, offsets[index], options) + (item, index) => new VersionExpressionSet(item, offsets[index]) ); this.separators = ast.separators.map((separator) => separator.text); diff --git a/src/slang-nodes/VersionPragma.ts b/src/slang-nodes/VersionPragma.ts index 2943267ff..f19aa6326 100644 --- a/src/slang-nodes/VersionPragma.ts +++ b/src/slang-nodes/VersionPragma.ts @@ -3,7 +3,7 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; import { VersionExpressionSets } from './VersionExpressionSets.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; -import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { AstPath, Doc } from 'prettier'; import type { SlangNode } from '../types.js'; export class VersionPragma implements SlangNode { @@ -17,12 +17,12 @@ export class VersionPragma implements SlangNode { sets: VersionExpressionSets; - constructor(ast: ast.VersionPragma, offset: number, options: ParserOptions) { + constructor(ast: ast.VersionPragma, offset: number) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; this.solidityKeyword = ast.solidityKeyword.text; - this.sets = new VersionExpressionSets(ast.sets, offsets[0], options); + this.sets = new VersionExpressionSets(ast.sets, offsets[0]); metadata = updateMetadata(metadata, [this.sets]); diff --git a/src/slang-nodes/VersionRange.ts b/src/slang-nodes/VersionRange.ts index 9af6e24b0..a2a012442 100644 --- a/src/slang-nodes/VersionRange.ts +++ b/src/slang-nodes/VersionRange.ts @@ -19,21 +19,13 @@ export class VersionRange implements SlangNode { rightOperand: VersionExpression; - constructor(ast: ast.VersionRange, offset: number, options: ParserOptions) { + constructor(ast: ast.VersionRange, offset: number) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.leftOperand = new VersionExpression( - ast.leftOperand, - offsets[0], - options - ); + this.leftOperand = new VersionExpression(ast.leftOperand, offsets[0]); this.operator = ast.operator.text; - this.rightOperand = new VersionExpression( - ast.rightOperand, - offsets[1], - options - ); + this.rightOperand = new VersionExpression(ast.rightOperand, offsets[1]); metadata = updateMetadata(metadata, [this.leftOperand, this.rightOperand]); diff --git a/src/slang-printers/print-comments.ts b/src/slang-printers/print-comments.ts index ee3995fbb..3d2a83e09 100644 --- a/src/slang-printers/print-comments.ts +++ b/src/slang-printers/print-comments.ts @@ -3,12 +3,12 @@ import { printComment } from '../slang-comments/printer.js'; import { getNode, isPrettier2 } from '../slang-utils/backward-compatibility.js'; import type { AstPath, Doc } from 'prettier'; -import type { Comment, astNode } from '../types.js'; +import type { AstNode, Comment } from '../types.js'; import type { DocV2 } from './types.js'; const { join, line } = doc.builders; -export function printComments(node: astNode, path: AstPath): Doc[] { +export function printComments(node: AstNode, path: AstPath): Doc[] { if (!node.comments) return []; const document = join( line, diff --git a/src/slang-utils/backward-compatibility.ts b/src/slang-utils/backward-compatibility.ts index 8a2f6c14d..1d7565bea 100644 --- a/src/slang-utils/backward-compatibility.ts +++ b/src/slang-utils/backward-compatibility.ts @@ -4,7 +4,7 @@ import { locEnd } from './loc.js'; import type { AstPath } from 'prettier'; import type { utilV2 } from './types'; -import type { astNode, Comment } from '../types'; +import type { AstNode, Comment } from '../types'; export const isPrettier2 = prettierVersionSatisfies('^2.3.0'); @@ -20,7 +20,7 @@ export function isNextLineEmpty(text: string, startIndex: number): boolean { export function getNextNonSpaceNonCommentCharacter( text: string, - node: astNode | Comment + node: AstNode | Comment ): string { if (isPrettier2) { const index = (util as utilV2).getNextNonSpaceNonCommentCharacterIndex( @@ -34,7 +34,7 @@ export function getNextNonSpaceNonCommentCharacter( } // TODO: remove undefined once we stop supporting prettier 2 -export const getNode = (path: AstPath): astNode | Comment | null | undefined => +export const getNode = (path: AstPath): AstNode | Comment | null | undefined => isPrettier2 ? path.getValue() : path.node; // V3 deprecated `getValue` export function isLast(path: AstPath, key: string, index: number): boolean { diff --git a/src/slang-utils/create-kind-check-function.ts b/src/slang-utils/create-kind-check-function.ts index 3ed1afb0c..fdd4e6724 100644 --- a/src/slang-utils/create-kind-check-function.ts +++ b/src/slang-utils/create-kind-check-function.ts @@ -1,9 +1,9 @@ import { Node } from '@nomicfoundation/slang/cst'; -import { astNode, Comment } from '../types'; +import { AstNode, Comment } from '../types'; export function createKindCheckFunction( kindsArray: string[] -): (node: astNode | Comment | Node) => boolean { +): (node: AstNode | Comment | Node) => boolean { const kinds = new Set(kindsArray); - return (node: astNode | Comment | Node): boolean => kinds.has(node.kind); + return (node: AstNode | Comment | Node): boolean => kinds.has(node.kind); } diff --git a/src/slang-utils/get-offsets.ts b/src/slang-utils/get-offsets.ts index 367827514..0506dbccb 100644 --- a/src/slang-utils/get-offsets.ts +++ b/src/slang-utils/get-offsets.ts @@ -1,7 +1,7 @@ import { isComment } from './is-comment.js'; import type { Node } from '@nomicfoundation/slang/cst/index.js'; -import type { astNode, Comment, Metadata, SlangASTNode } from '../types.js'; +import type { AstNode, Comment, Metadata, SlangAstNode } from '../types.js'; function getLeadingOffset(children: Node[]): number { let offset = 0; @@ -25,7 +25,7 @@ function getLeadingOffset(children: Node[]): number { } export function getNodeMetadata( - ast: SlangASTNode, + ast: SlangAstNode, initialOffset: number ): Metadata { const children = ast.cst.children(); @@ -75,7 +75,7 @@ export function getNodeMetadata( function collectComments( comments: Comment[], - node: astNode | astNode[] | undefined + node: AstNode | AstNode[] | undefined ): Comment[] { if (node) { if (Array.isArray(node)) { @@ -89,7 +89,7 @@ function collectComments( export function updateMetadata( metadata: Metadata, - childNodes: (astNode | astNode[] | undefined)[] + childNodes: (AstNode | AstNode[] | undefined)[] ): Metadata { const { comments, loc } = metadata; // Collect comments diff --git a/src/slang-utils/loc.ts b/src/slang-utils/loc.ts index 93d8e039d..fecc681b0 100644 --- a/src/slang-utils/loc.ts +++ b/src/slang-utils/loc.ts @@ -1,9 +1,9 @@ -import type { astNode, Comment } from '../types'; +import type { AstNode, Comment } from '../types'; -export function locStart(node: astNode | Comment): number { +export function locStart(node: AstNode | Comment): number { return node.loc.start; } -export function locEnd(node: astNode | Comment): number { +export function locEnd(node: AstNode | Comment): number { return node.loc.end; } diff --git a/src/slang-utils/types.d.ts b/src/slang-utils/types.d.ts index 46e4f07d8..b283c9457 100644 --- a/src/slang-utils/types.d.ts +++ b/src/slang-utils/types.d.ts @@ -11,7 +11,7 @@ import type { ModifierInvocation } from '../slang-nodes'; import type { util } from 'prettier'; -import type { astNode, Comment } from '../types'; +import type { AstNode, Comment } from '../types'; type SortableAttribute = | ConstructorAttribute @@ -28,8 +28,8 @@ type SortableVariant = OverrideSpecifier | ModifierInvocation; declare namespace utilV2Functions { function getNextNonSpaceNonCommentCharacterIndex( text: string, - node: astNode | Comment, - locEnd: (node: astNode) => number + node: AstNode | Comment, + locEnd: (node: AstNode) => number ): number | false; function isNextLineEmptyAfterIndex(text: string, startIndex: number): boolean; diff --git a/src/slangParser.ts b/src/slangParser.ts index eee8d089a..768421382 100644 --- a/src/slangParser.ts +++ b/src/slangParser.ts @@ -8,13 +8,13 @@ import { SourceUnit } from './slang-nodes/SourceUnit.js'; import type { NonterminalNode } from '@nomicfoundation/slang/cst/index.js'; import type { Parser, ParserOptions } from 'prettier'; -import type { astNode } from './types.js'; +import type { AstNode } from './types.js'; function parse( text: string, _parsers: Parser[] | ParserOptions, options = _parsers as ParserOptions -): astNode { +): AstNode { const compiler = coerce(options.compiler); const language = new Language(compiler?.version || '0.8.26'); diff --git a/src/slangPrinter.ts b/src/slangPrinter.ts index acb06ad3a..49ae9cf13 100644 --- a/src/slangPrinter.ts +++ b/src/slangPrinter.ts @@ -1,9 +1,10 @@ import { prettierVersionSatisfies } from './slang-utils/prettier-version-satisfies.js'; import { getNode } from './slang-utils/backward-compatibility.js'; import { isBlockComment } from './slang-utils/is-comment.js'; +import { locEnd, locStart } from './slang-utils/loc.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { astNode, Comment } from './types.js'; +import type { AstNode, Comment } from './types.js'; let checked = false; @@ -17,7 +18,7 @@ function prettierVersionCheck(): void { checked = true; } -function hasNodeIgnoreComment(node: astNode): boolean { +function hasNodeIgnoreComment(node: AstNode): boolean { return ( node?.comments && node.comments.some( @@ -31,11 +32,11 @@ function hasNodeIgnoreComment(node: astNode): boolean { function ignoreComments(path: AstPath): void { // TODO: remove undefined once we stop supporting prettier 2 - const node = getNode(path) as astNode | null | undefined; + const node = getNode(path) as AstNode | null | undefined; // We ignore anything that is not an object if (node === null || node === undefined || typeof node !== 'object') return; - const keys = Object.keys(node) as (keyof astNode)[]; + const keys = Object.keys(node) as (keyof AstNode)[]; keys.forEach((key) => { switch (key) { // We ignore `kind`, `loc`, and comments since these are added by the @@ -72,7 +73,7 @@ function genericPrint( ): Doc { prettierVersionCheck(); - const node = getNode(path) as astNode | null | undefined; + const node = getNode(path) as AstNode | null | undefined; if (node === null || node === undefined) { return ''; @@ -81,10 +82,7 @@ function genericPrint( if (hasNodeIgnoreComment(node)) { ignoreComments(path); - return options.originalText.slice( - options.locStart(node), - options.locEnd(node) - ); + return options.originalText.slice(locStart(node), locEnd(node)); } return node.print(path, print, options); diff --git a/src/types.d.ts b/src/types.d.ts index 036313dbb..e1f9a6be1 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -17,28 +17,22 @@ interface Location { trailingOffset?: number; } -interface BlockComment { - kind: 'MultiLineComment' | 'MultiLineNatSpecComment'; +interface BaseComment { value: string; loc: Location; leading?: boolean; trailing?: boolean; printed?: boolean; - precedingNode?: astNode; - enclosingNode?: astNode; - followingNode?: astNode; + precedingNode?: AstNode; + enclosingNode?: AstNode; + followingNode?: AstNode; +} +interface BlockComment extends BaseComment { + kind: 'MultiLineComment' | 'MultiLineNatSpecComment'; } -interface LineComment { +interface LineComment extends BaseComment { kind: 'SingleLineComment' | 'SingleLineNatSpecComment'; - value: string; - loc: Location; - leading?: boolean; - trailing?: boolean; - printed?: boolean; - precedingNode?: astNode; - enclosingNode?: astNode; - followingNode?: astNode; } type Comment = BlockComment | LineComment; @@ -83,7 +77,7 @@ export type FunctionLike = | nodes.ReceiveFunctionDefinition | nodes.UnnamedFunctionDefinition; -export type astNode = +export type AstNode = | nodes.SourceUnit | nodes.PragmaDirective | nodes.ABICoderPragma @@ -300,7 +294,7 @@ export type astNode = | nodes.YulPaths | nodes.YulPath; -export type SlangASTNode = +export type SlangAstNode = | ast.SourceUnit | ast.PragmaDirective | ast.ABICoderPragma From f41929ab737512655f8c8d943aca5389c7ec070a Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 31 Jul 2024 17:09:44 +1200 Subject: [PATCH 102/160] removing unnecessary non-null assertions --- src/slang-nodes/ConstantDefinition.ts | 6 +++--- src/slang-nodes/ModifierDefinition.ts | 2 +- src/slang-nodes/OverridePaths.ts | 6 +++--- src/slang-nodes/OverridePathsDeclaration.ts | 6 +++--- src/slang-nodes/TypeExpression.ts | 6 +++--- src/slang-nodes/UntypedTupleMember.ts | 6 +++--- src/slang-nodes/VersionRange.ts | 6 +++--- src/slang-nodes/YulColonEqual.ts | 6 +++--- src/slang-nodes/YulLeaveStatement.ts | 6 +++--- src/slang-nodes/YulStackAssignmentStatement.ts | 6 +++--- src/slang-utils/get-offsets.ts | 8 ++++---- src/types.d.ts | 9 ++++++--- 12 files changed, 38 insertions(+), 35 deletions(-) diff --git a/src/slang-nodes/ConstantDefinition.ts b/src/slang-nodes/ConstantDefinition.ts index ab969c137..411e0551c 100644 --- a/src/slang-nodes/ConstantDefinition.ts +++ b/src/slang-nodes/ConstantDefinition.ts @@ -4,7 +4,7 @@ import { TypeName } from './TypeName.js'; import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; -import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { /*AstPath,*/ Doc, ParserOptions } from 'prettier'; import type { SlangNode } from '../types.js'; export class ConstantDefinition implements SlangNode { @@ -48,11 +48,11 @@ export class ConstantDefinition implements SlangNode { } // TODO: implement print - print( + print(/* path: AstPath, print: (path: AstPath) => Doc, options: ParserOptions - ): Doc { + */): Doc { return ['TODO: ConstantDefinition']; } } diff --git a/src/slang-nodes/ModifierDefinition.ts b/src/slang-nodes/ModifierDefinition.ts index 7dcec8d3d..bb0277633 100644 --- a/src/slang-nodes/ModifierDefinition.ts +++ b/src/slang-nodes/ModifierDefinition.ts @@ -66,7 +66,7 @@ export class ModifierDefinition implements SlangNode { if (!this.parameters) { const parametersOffset = - this.attributes.loc.start - this.attributes.loc.leadingOffset!; + this.attributes.loc.start - this.attributes.loc.leadingOffset; const parametersLoc = { start: parametersOffset, end: parametersOffset, diff --git a/src/slang-nodes/OverridePaths.ts b/src/slang-nodes/OverridePaths.ts index 81f3c4bc6..e73cbdd4e 100644 --- a/src/slang-nodes/OverridePaths.ts +++ b/src/slang-nodes/OverridePaths.ts @@ -3,7 +3,7 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; import { IdentifierPath } from './IdentifierPath.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; -import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { /*AstPath,*/ Doc /*, ParserOptions*/ } from 'prettier'; import type { SlangNode } from '../types.js'; export class OverridePaths implements SlangNode { @@ -33,11 +33,11 @@ export class OverridePaths implements SlangNode { } // TODO: implement print - print( + print(/* path: AstPath, print: (path: AstPath) => Doc, options: ParserOptions - ): Doc { + */): Doc { return ['TODO: OverridePaths']; } } diff --git a/src/slang-nodes/OverridePathsDeclaration.ts b/src/slang-nodes/OverridePathsDeclaration.ts index 341c8c4bf..45194b038 100644 --- a/src/slang-nodes/OverridePathsDeclaration.ts +++ b/src/slang-nodes/OverridePathsDeclaration.ts @@ -3,7 +3,7 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; import { OverridePaths } from './OverridePaths.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; -import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { /*AstPath,*/ Doc /*, ParserOptions*/ } from 'prettier'; import type { SlangNode } from '../types.js'; export class OverridePathsDeclaration implements SlangNode { @@ -34,11 +34,11 @@ export class OverridePathsDeclaration implements SlangNode { } // TODO: implement print - print( + print(/* path: AstPath, print: (path: AstPath) => Doc, options: ParserOptions - ): Doc { + */): Doc { return ['TODO: OverridePathsDeclaration']; } } diff --git a/src/slang-nodes/TypeExpression.ts b/src/slang-nodes/TypeExpression.ts index e92f20c49..609738db2 100644 --- a/src/slang-nodes/TypeExpression.ts +++ b/src/slang-nodes/TypeExpression.ts @@ -3,7 +3,7 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; import { TypeName } from './TypeName.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; -import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { /*AstPath,*/ Doc, ParserOptions } from 'prettier'; import type { SlangNode } from '../types.js'; export class TypeExpression implements SlangNode { @@ -37,11 +37,11 @@ export class TypeExpression implements SlangNode { } // TODO: implement print - print( + print(/* path: AstPath, print: (path: AstPath) => Doc, options: ParserOptions - ): Doc { + */): Doc { return ['TODO: TypeExpression']; } } diff --git a/src/slang-nodes/UntypedTupleMember.ts b/src/slang-nodes/UntypedTupleMember.ts index dba658202..687da9e2b 100644 --- a/src/slang-nodes/UntypedTupleMember.ts +++ b/src/slang-nodes/UntypedTupleMember.ts @@ -3,7 +3,7 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; import { StorageLocation } from './StorageLocation.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; -import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { /*AstPath,*/ Doc /*, ParserOptions*/ } from 'prettier'; import type { SlangNode } from '../types.js'; export class UntypedTupleMember implements SlangNode { @@ -36,11 +36,11 @@ export class UntypedTupleMember implements SlangNode { } // TODO: implement print - print( + print(/* path: AstPath, print: (path: AstPath) => Doc, options: ParserOptions - ): Doc { + */): Doc { return ['TODO: UntypedTupleMemberUntypedTupleMember']; } } diff --git a/src/slang-nodes/VersionRange.ts b/src/slang-nodes/VersionRange.ts index a2a012442..2474773ce 100644 --- a/src/slang-nodes/VersionRange.ts +++ b/src/slang-nodes/VersionRange.ts @@ -3,7 +3,7 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; import { VersionExpression } from './VersionExpression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; -import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { /*AstPath,*/ Doc } from 'prettier'; import type { SlangNode } from '../types.js'; export class VersionRange implements SlangNode { @@ -34,11 +34,11 @@ export class VersionRange implements SlangNode { } // TODO: implement print - print( + print(/* path: AstPath, print: (path: AstPath) => Doc, options: ParserOptions - ): Doc { + */): Doc { return ['TODO: VersionRange']; } } diff --git a/src/slang-nodes/YulColonEqual.ts b/src/slang-nodes/YulColonEqual.ts index 608d75397..70b6ff3bf 100644 --- a/src/slang-nodes/YulColonEqual.ts +++ b/src/slang-nodes/YulColonEqual.ts @@ -2,7 +2,7 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata } from '../slang-utils/get-offsets.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; -import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { /*AstPath,*/ Doc /*, ParserOptions*/ } from 'prettier'; import type { SlangNode } from '../types.js'; export class YulColonEqual implements SlangNode { @@ -27,11 +27,11 @@ export class YulColonEqual implements SlangNode { } // TODO: implement print - print( + print(/* path: AstPath, print: (path: AstPath) => Doc, options: ParserOptions - ): Doc { + */): Doc { return ['TODO: YulColonEqual']; } } diff --git a/src/slang-nodes/YulLeaveStatement.ts b/src/slang-nodes/YulLeaveStatement.ts index 1017b0c4b..3b21c72e1 100644 --- a/src/slang-nodes/YulLeaveStatement.ts +++ b/src/slang-nodes/YulLeaveStatement.ts @@ -2,7 +2,7 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata } from '../slang-utils/get-offsets.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; -import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { /*AstPath,*/ Doc /*, ParserOptions*/ } from 'prettier'; import type { SlangNode } from '../types.js'; export class YulLeaveStatement implements SlangNode { @@ -24,11 +24,11 @@ export class YulLeaveStatement implements SlangNode { } // TODO: implement print - print( + print(/* path: AstPath, print: (path: AstPath) => Doc, options: ParserOptions - ): Doc { + */): Doc { return ['TODO: YulLeaveStatement']; } } diff --git a/src/slang-nodes/YulStackAssignmentStatement.ts b/src/slang-nodes/YulStackAssignmentStatement.ts index c5bacb471..bd57c8f24 100644 --- a/src/slang-nodes/YulStackAssignmentStatement.ts +++ b/src/slang-nodes/YulStackAssignmentStatement.ts @@ -4,7 +4,7 @@ import { YulAssignmentOperator } from './YulAssignmentOperator.js'; import { YulExpression } from './YulExpression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; -import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { /*AstPath,*/ Doc, ParserOptions } from 'prettier'; import type { SlangNode } from '../types.js'; export class YulStackAssignmentStatement implements SlangNode { @@ -36,11 +36,11 @@ export class YulStackAssignmentStatement implements SlangNode { } // TODO: implement print - print( + print(/* path: AstPath, print: (path: AstPath) => Doc, options: ParserOptions - ): Doc { + */): Doc { return ['TODO: YulStackAssignmentStatement']; } } diff --git a/src/slang-utils/get-offsets.ts b/src/slang-utils/get-offsets.ts index 0506dbccb..2dd424814 100644 --- a/src/slang-utils/get-offsets.ts +++ b/src/slang-utils/get-offsets.ts @@ -104,18 +104,18 @@ export function updateMetadata( if (childLoc) { if ( loc.leadingOffset === 0 && - childLoc.start - childLoc.leadingOffset! === loc.start + childLoc.start - childLoc.leadingOffset === loc.start ) { loc.leadingOffset = childLoc.leadingOffset; - loc.start += childLoc.leadingOffset!; + loc.start += childLoc.leadingOffset; } if ( loc.trailingOffset === 0 && - childLoc.end + childLoc.trailingOffset! === loc.end + childLoc.end + childLoc.trailingOffset === loc.end ) { loc.trailingOffset = childLoc.trailingOffset; - loc.end -= childLoc.trailingOffset!; + loc.end -= childLoc.trailingOffset; } } }); diff --git a/src/types.d.ts b/src/types.d.ts index e1f9a6be1..e94c5e1ea 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -13,8 +13,11 @@ declare module 'prettier' { interface Location { start: number; end: number; - leadingOffset?: number; - trailingOffset?: number; +} + +interface AstLocation extends Location { + leadingOffset: number; + trailingOffset: number; } interface BaseComment { @@ -39,7 +42,7 @@ type Comment = BlockComment | LineComment; interface Metadata { comments: Comment[]; - loc: Location; + loc: AstLocation; offsets: number[]; } From ca0b8f2021bffb5e4ca14ffee6fd9a65c552fb9f Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 31 Jul 2024 19:58:43 +1200 Subject: [PATCH 103/160] Safe type checks --- .../handlers/handleBlockComments.ts | 7 +-- .../handleContractDefinitionComments.ts | 14 ++--- .../handleParametersDeclarationComments.ts | 7 +-- .../handlers/handleWhileStatementComments.ts | 6 ++- .../handlers/handleYulBlockComments.ts | 7 +-- src/slang-comments/printer.ts | 2 +- src/slang-nodes/ArgumentsDeclaration.ts | 4 +- src/slang-nodes/ConditionalExpression.ts | 24 +++++---- src/slang-nodes/ContractDefinition.ts | 2 +- src/slang-nodes/ContractMember.ts | 26 ++++----- src/slang-nodes/DoWhileStatement.ts | 2 +- src/slang-nodes/ExponentiationExpression.ts | 15 +++--- src/slang-nodes/Expression.ts | 54 +++++++++---------- src/slang-nodes/FallbackFunctionAttribute.ts | 4 +- src/slang-nodes/FallbackFunctionDefinition.ts | 2 +- src/slang-nodes/ForStatement.ts | 2 +- src/slang-nodes/ForStatementInitialization.ts | 6 +-- src/slang-nodes/FunctionAttribute.ts | 4 +- src/slang-nodes/FunctionDefinition.ts | 2 +- src/slang-nodes/IfStatement.ts | 6 +-- src/slang-nodes/ImportClause.ts | 6 +-- src/slang-nodes/MappingKeyType.ts | 4 +- src/slang-nodes/MemberAccessExpression.ts | 16 +++--- src/slang-nodes/ModifierDefinition.ts | 4 +- src/slang-nodes/ModifierInvocation.ts | 3 +- src/slang-nodes/Parameter.ts | 2 +- src/slang-nodes/Pragma.ts | 6 +-- src/slang-nodes/ReceiveFunctionAttribute.ts | 4 +- src/slang-nodes/ReceiveFunctionDefinition.ts | 2 +- src/slang-nodes/ReturnStatement.ts | 5 +- src/slang-nodes/SourceUnitMember.ts | 26 ++++----- .../StateVariableDefinitionValue.ts | 2 +- src/slang-nodes/Statement.ts | 34 ++++++------ src/slang-nodes/StringExpression.ts | 10 ++-- .../TupleDeconstructionStatement.ts | 2 +- src/slang-nodes/TupleMember.ts | 4 +- src/slang-nodes/TypeName.ts | 10 ++-- src/slang-nodes/UsingClause.ts | 4 +- src/slang-nodes/VersionExpression.ts | 6 +-- src/slang-nodes/WhileStatement.ts | 2 +- src/slang-nodes/YulExpression.ts | 8 +-- src/slang-nodes/YulLiteral.ts | 4 +- src/slang-nodes/YulStatement.ts | 26 ++++----- src/slang-nodes/YulSwitchCase.ts | 4 +- .../create-binary-operation-printer.ts | 4 +- src/slang-printers/print-binary-operation.ts | 13 +++-- .../print-comparison-operation.ts | 17 ++++-- src/slang-printers/print-logical-operation.ts | 13 +++-- .../print-preserving-empty-lines.ts | 8 +-- src/slang-utils/backward-compatibility.ts | 6 ++- src/slang-utils/create-hug-function.ts | 8 +-- src/slang-utils/create-kind-check-function.ts | 3 +- src/slang-utils/get-offsets.ts | 21 ++++---- src/slang-utils/sort-function-attributes.ts | 9 ++-- 54 files changed, 267 insertions(+), 225 deletions(-) diff --git a/src/slang-comments/handlers/handleBlockComments.ts b/src/slang-comments/handlers/handleBlockComments.ts index e570f2316..94e2e2a13 100644 --- a/src/slang-comments/handlers/handleBlockComments.ts +++ b/src/slang-comments/handlers/handleBlockComments.ts @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { util } from 'prettier'; import type { HandlerParams } from './types'; @@ -10,11 +11,11 @@ export default function handleBlockComments({ followingNode, comment }: HandlerParams): boolean { - if (enclosingNode?.kind !== 'Block') { + if (enclosingNode?.kind !== NonterminalKind.Block) { return false; } - if (precedingNode?.kind === 'Statements') { + if (precedingNode?.kind === NonterminalKind.Statements) { if (precedingNode.items.length === 0) { addDanglingComment(precedingNode, comment, false); } else { @@ -26,7 +27,7 @@ export default function handleBlockComments({ return true; } - if (followingNode?.kind === 'Statements') { + if (followingNode?.kind === NonterminalKind.Statements) { if (followingNode.items.length === 0) { addDanglingComment(followingNode, comment, false); } else { diff --git a/src/slang-comments/handlers/handleContractDefinitionComments.ts b/src/slang-comments/handlers/handleContractDefinitionComments.ts index 717486ad9..5893cd4a5 100644 --- a/src/slang-comments/handlers/handleContractDefinitionComments.ts +++ b/src/slang-comments/handlers/handleContractDefinitionComments.ts @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { util } from 'prettier'; import { getNextNonSpaceNonCommentCharacter } from '../../slang-utils/backward-compatibility.js'; @@ -12,7 +13,7 @@ export default function handleContractDefinitionComments({ followingNode, comment }: HandlerParams): boolean { - if (enclosingNode?.kind !== 'ContractDefinition') { + if (enclosingNode?.kind !== NonterminalKind.ContractDefinition) { return false; } @@ -21,15 +22,16 @@ export default function handleContractDefinitionComments({ // Everything before the InheritanceSpecifier is pushed onto the beginning of // the ContractDefinition. if ( - followingNode?.kind === 'InheritanceSpecifier' || - (followingNode?.kind === 'ContractMembers' && nextCharacter !== '{') + followingNode?.kind === NonterminalKind.InheritanceSpecifier || + (followingNode?.kind === NonterminalKind.ContractMembers && + nextCharacter !== '{') ) { addLeadingComment(enclosingNode, comment); return true; } // The comment is at the end of the body of the ContractDefinition. - if (precedingNode?.kind === 'ContractMembers') { + if (precedingNode?.kind === NonterminalKind.ContractMembers) { if (precedingNode.items.length === 0) { addDanglingComment(precedingNode, comment, false); } else { @@ -46,7 +48,7 @@ export default function handleContractDefinitionComments({ // If there's an InheritanceSpecifier, the comment is appended to the last // InheritanceType. if ( - precedingNode?.kind === 'InheritanceSpecifier' && + precedingNode?.kind === NonterminalKind.InheritanceSpecifier && precedingNode.types.items.length > 0 ) { addTrailingComment( @@ -58,7 +60,7 @@ export default function handleContractDefinitionComments({ // If there's no InheritanceSpecifier, the comment before the body is // assumed to be intended at the beginning of the body. - if (followingNode?.kind === 'ContractMembers') { + if (followingNode?.kind === NonterminalKind.ContractMembers) { if (followingNode.items.length > 0) { addLeadingComment(followingNode.items[0], comment); } else { diff --git a/src/slang-comments/handlers/handleParametersDeclarationComments.ts b/src/slang-comments/handlers/handleParametersDeclarationComments.ts index 0c80083dc..3e662de9c 100644 --- a/src/slang-comments/handlers/handleParametersDeclarationComments.ts +++ b/src/slang-comments/handlers/handleParametersDeclarationComments.ts @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { util } from 'prettier'; import type { HandlerParams } from './types'; @@ -10,11 +11,11 @@ export default function handleBlockComments({ followingNode, comment }: HandlerParams): boolean { - if (enclosingNode?.kind !== 'ParametersDeclaration') { + if (enclosingNode?.kind !== NonterminalKind.ParametersDeclaration) { return false; } - if (precedingNode?.kind === 'Parameters') { + if (precedingNode?.kind === NonterminalKind.Parameters) { if (precedingNode.items.length === 0) { addDanglingComment(precedingNode, comment, false); } else { @@ -26,7 +27,7 @@ export default function handleBlockComments({ return true; } - if (followingNode?.kind === 'Parameters') { + if (followingNode?.kind === NonterminalKind.Parameters) { if (followingNode.items.length === 0) { addDanglingComment(followingNode, comment, false); } else { diff --git a/src/slang-comments/handlers/handleWhileStatementComments.ts b/src/slang-comments/handlers/handleWhileStatementComments.ts index 63d767b09..e31cfe507 100644 --- a/src/slang-comments/handlers/handleWhileStatementComments.ts +++ b/src/slang-comments/handlers/handleWhileStatementComments.ts @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { util } from 'prettier'; import { getNextNonSpaceNonCommentCharacter } from '../../slang-utils/backward-compatibility.js'; @@ -12,7 +13,10 @@ export default function handleWhileStatementComments({ followingNode, comment }: HandlerParams): boolean { - if (enclosingNode?.kind !== 'WhileStatement' || !followingNode) { + if ( + enclosingNode?.kind !== NonterminalKind.WhileStatement || + !followingNode + ) { return false; } diff --git a/src/slang-comments/handlers/handleYulBlockComments.ts b/src/slang-comments/handlers/handleYulBlockComments.ts index bec362445..baf6bd16c 100644 --- a/src/slang-comments/handlers/handleYulBlockComments.ts +++ b/src/slang-comments/handlers/handleYulBlockComments.ts @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { util } from 'prettier'; import type { HandlerParams } from './types'; @@ -10,12 +11,12 @@ export default function handleYulBlockComments({ followingNode, comment }: HandlerParams): boolean { - if (enclosingNode?.kind !== 'YulBlock') { + if (enclosingNode?.kind !== NonterminalKind.YulBlock) { return false; } if ( - precedingNode?.kind === 'YulStatements' && + precedingNode?.kind === NonterminalKind.YulStatements && precedingNode.items.length === 0 ) { addDanglingComment(precedingNode, comment, false); @@ -23,7 +24,7 @@ export default function handleYulBlockComments({ } if ( - followingNode?.kind === 'YulStatements' && + followingNode?.kind === NonterminalKind.YulStatements && followingNode.items.length > 0 ) { addLeadingComment(followingNode.items[0], comment); diff --git a/src/slang-comments/printer.ts b/src/slang-comments/printer.ts index 37d52121d..7b65419a4 100644 --- a/src/slang-comments/printer.ts +++ b/src/slang-comments/printer.ts @@ -29,7 +29,7 @@ function printIndentableBlockComment(comment: Comment): Doc { } export function printComment(commentPath: AstPath): Doc { - const comment = commentPath.node; + const comment = commentPath.getNode() as Comment; if (isLineComment(comment)) { return comment.value.trimEnd(); diff --git a/src/slang-nodes/ArgumentsDeclaration.ts b/src/slang-nodes/ArgumentsDeclaration.ts index bd538ac68..1b5df570d 100644 --- a/src/slang-nodes/ArgumentsDeclaration.ts +++ b/src/slang-nodes/ArgumentsDeclaration.ts @@ -25,14 +25,14 @@ export class ArgumentsDeclaration implements SlangNode { const { offsets } = metadata; switch (ast.variant.cst.kind) { - case 'PositionalArgumentsDeclaration': + case NonterminalKind.PositionalArgumentsDeclaration: this.variant = new PositionalArgumentsDeclaration( ast.variant as ast.PositionalArgumentsDeclaration, offsets[0], options ); break; - case 'NamedArgumentsDeclaration': + case NonterminalKind.NamedArgumentsDeclaration: this.variant = new NamedArgumentsDeclaration( ast.variant as ast.NamedArgumentsDeclaration, offsets[0], diff --git a/src/slang-nodes/ConditionalExpression.ts b/src/slang-nodes/ConditionalExpression.ts index ffa80cb9a..9cb227fa5 100644 --- a/src/slang-nodes/ConditionalExpression.ts +++ b/src/slang-nodes/ConditionalExpression.ts @@ -7,7 +7,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { group, hardline, ifBreak, indent, line, softline } = doc.builders; @@ -17,18 +17,19 @@ function experimentalTernaries( print: (path: AstPath) => Doc, options: ParserOptions ): Doc { - const grandparent = path.getNode(2); - const isNested = grandparent.kind === 'ConditionalExpression'; + const grandparent = path.getNode(2) as AstNode; + const isNested = grandparent.kind === NonterminalKind.ConditionalExpression; const isNestedAsTrueExpression = isNested && grandparent.trueExpression.variant === node; let falseExpressionIsTuple = false; let falseExpressionInSameLine = false; if (typeof node.falseExpression.variant !== 'string') { falseExpressionIsTuple = - node.falseExpression.variant.kind === 'TupleExpression'; + node.falseExpression.variant.kind === NonterminalKind.TupleExpression; falseExpressionInSameLine = falseExpressionIsTuple || - node.falseExpression.variant.kind === 'ConditionalExpression'; + node.falseExpression.variant.kind === + NonterminalKind.ConditionalExpression; } // If the `condition` breaks into multiple lines, we add parentheses, @@ -36,7 +37,7 @@ function experimentalTernaries( const operand = path.call(print, 'operand'); const operandDoc = group([ typeof node.operand.variant !== 'string' && - node.operand.variant.kind === 'TupleExpression' + node.operand.variant.kind === NonterminalKind.TupleExpression ? operand : ifBreak(['(', printSeparatedItem(operand), ')'], operand), ` ${node.questionMark}` @@ -79,7 +80,7 @@ function experimentalTernaries( const document = group([conditionAndTrueExpressionGroup, falseExpressionDoc]); - return grandparent.kind === 'VariableDeclarationValue' + return grandparent.kind === NonterminalKind.VariableDeclarationValue ? group(indent([softline, document])) : document; } @@ -94,7 +95,10 @@ function traditionalTernaries( indent([ // Nested trueExpression and falseExpression are always printed in a new // line - path.getNode(2).kind === 'ConditionalExpression' ? hardline : line, + (path.getNode(2) as AstNode).kind === + NonterminalKind.ConditionalExpression + ? hardline + : line, `${node.questionMark} `, path.call(print, 'trueExpression'), line, @@ -158,12 +162,12 @@ export class ConditionalExpression implements SlangNode { const operandLoc = this.operand.loc; while ( typeof this.operand.variant !== 'string' && - this.operand.variant.kind === 'TupleExpression' && + this.operand.variant.kind === NonterminalKind.TupleExpression && this.operand.variant.items.items.length === 1 && (typeof this.operand.variant.items.items[0].expression!.variant === 'string' || this.operand.variant.items.items[0].expression!.variant.kind !== - 'ConditionalExpression') + NonterminalKind.ConditionalExpression) ) { this.operand = this.operand.variant.items.items[0].expression!; } diff --git a/src/slang-nodes/ContractDefinition.ts b/src/slang-nodes/ContractDefinition.ts index a2cf73794..cc6aff506 100644 --- a/src/slang-nodes/ContractDefinition.ts +++ b/src/slang-nodes/ContractDefinition.ts @@ -72,7 +72,7 @@ export class ContractDefinition implements SlangNode { if (compiler && !satisfies(compiler, '>=0.5.0')) { this.members.items.forEach((member) => { if ( - member.variant.kind === 'FunctionDefinition' && + member.variant.kind === NonterminalKind.FunctionDefinition && member.variant.name.variant !== this.name ) { member.variant.cleanModifierInvocationArguments(); diff --git a/src/slang-nodes/ContractMember.ts b/src/slang-nodes/ContractMember.ts index 004ca416b..3c053a608 100644 --- a/src/slang-nodes/ContractMember.ts +++ b/src/slang-nodes/ContractMember.ts @@ -45,90 +45,90 @@ export class ContractMember implements SlangNode { const { offsets } = metadata; switch (ast.variant.cst.kind) { - case 'UsingDirective': + case NonterminalKind.UsingDirective: this.variant = new UsingDirective( ast.variant as ast.UsingDirective, offsets[0], options ); break; - case 'FunctionDefinition': + case NonterminalKind.FunctionDefinition: this.variant = new FunctionDefinition( ast.variant as ast.FunctionDefinition, offsets[0], options ); break; - case 'ConstructorDefinition': + case NonterminalKind.ConstructorDefinition: this.variant = new ConstructorDefinition( ast.variant as ast.ConstructorDefinition, offsets[0], options ); break; - case 'ReceiveFunctionDefinition': + case NonterminalKind.ReceiveFunctionDefinition: this.variant = new ReceiveFunctionDefinition( ast.variant as ast.ReceiveFunctionDefinition, offsets[0], options ); break; - case 'FallbackFunctionDefinition': + case NonterminalKind.FallbackFunctionDefinition: this.variant = new FallbackFunctionDefinition( ast.variant as ast.FallbackFunctionDefinition, offsets[0], options ); break; - case 'UnnamedFunctionDefinition': + case NonterminalKind.UnnamedFunctionDefinition: this.variant = new UnnamedFunctionDefinition( ast.variant as ast.UnnamedFunctionDefinition, offsets[0], options ); break; - case 'ModifierDefinition': + case NonterminalKind.ModifierDefinition: this.variant = new ModifierDefinition( ast.variant as ast.ModifierDefinition, offsets[0], options ); break; - case 'StructDefinition': + case NonterminalKind.StructDefinition: this.variant = new StructDefinition( ast.variant as ast.StructDefinition, offsets[0], options ); break; - case 'EnumDefinition': + case NonterminalKind.EnumDefinition: this.variant = new EnumDefinition( ast.variant as ast.EnumDefinition, offsets[0] ); break; - case 'EventDefinition': + case NonterminalKind.EventDefinition: this.variant = new EventDefinition( ast.variant as ast.EventDefinition, offsets[0], options ); break; - case 'StateVariableDefinition': + case NonterminalKind.StateVariableDefinition: this.variant = new StateVariableDefinition( ast.variant as ast.StateVariableDefinition, offsets[0], options ); break; - case 'ErrorDefinition': + case NonterminalKind.ErrorDefinition: this.variant = new ErrorDefinition( ast.variant as ast.ErrorDefinition, offsets[0], options ); break; - case 'UserDefinedValueTypeDefinition': + case NonterminalKind.UserDefinedValueTypeDefinition: this.variant = new UserDefinedValueTypeDefinition( ast.variant as ast.UserDefinedValueTypeDefinition, offsets[0] diff --git a/src/slang-nodes/DoWhileStatement.ts b/src/slang-nodes/DoWhileStatement.ts index 3be3253b3..28622f92b 100644 --- a/src/slang-nodes/DoWhileStatement.ts +++ b/src/slang-nodes/DoWhileStatement.ts @@ -57,7 +57,7 @@ export class DoWhileStatement implements SlangNode { print(path: AstPath, print: (path: AstPath) => Doc): Doc { return [ this.doKeyword, - this.body.variant.kind === 'Block' + this.body.variant.kind === NonterminalKind.Block ? [' ', path.call(print, 'body'), ' '] : group([indent([line, path.call(print, 'body')]), line]), `${this.whileKeyword} ${this.openParen}`, diff --git a/src/slang-nodes/ExponentiationExpression.ts b/src/slang-nodes/ExponentiationExpression.ts index 1f50ec88e..db3a31640 100644 --- a/src/slang-nodes/ExponentiationExpression.ts +++ b/src/slang-nodes/ExponentiationExpression.ts @@ -75,7 +75,8 @@ export class ExponentiationExpression implements SlangNode { // https://github.com/NomicFoundation/slang/issues/1031 if ( typeof this.rightOperand.variant !== 'string' && - this.rightOperand.variant.kind === 'ExponentiationExpression' + this.rightOperand.variant.kind === + NonterminalKind.ExponentiationExpression ) { const leftLoc = { leadingOffset: this.leftOperand.loc.leadingOffset, @@ -147,25 +148,25 @@ export class ExponentiationExpression implements SlangNode { ...objectConfig } } - ), + ) as ExponentiationExpression, ...objectConfig } - }), + }) as Expression, ...objectConfig } - }) + }) as TupleValue ], ...objectConfig }, separators: { value: [], ...objectConfig } - }), + }) as TupleValues, ...objectConfig }, closeParen: { value: ')', ...objectConfig } - }), + }) as TupleExpression, ...objectConfig } - }); + }) as Expression; this.rightOperand = this.rightOperand.variant.rightOperand; } this.leftOperand = tryToHug(this.leftOperand); diff --git a/src/slang-nodes/Expression.ts b/src/slang-nodes/Expression.ts index cb403802b..b4354b900 100644 --- a/src/slang-nodes/Expression.ts +++ b/src/slang-nodes/Expression.ts @@ -78,187 +78,187 @@ export class Expression implements SlangNode { this.variant = ast.variant.text; } else { switch (ast.variant.cst.kind) { - case 'AssignmentExpression': + case NonterminalKind.AssignmentExpression: this.variant = new AssignmentExpression( ast.variant as ast.AssignmentExpression, offsets[0], options ); break; - case 'ConditionalExpression': + case NonterminalKind.ConditionalExpression: this.variant = new ConditionalExpression( ast.variant as ast.ConditionalExpression, offsets[0], options ); break; - case 'OrExpression': + case NonterminalKind.OrExpression: this.variant = new OrExpression( ast.variant as ast.OrExpression, offsets[0], options ); break; - case 'AndExpression': + case NonterminalKind.AndExpression: this.variant = new AndExpression( ast.variant as ast.AndExpression, offsets[0], options ); break; - case 'EqualityExpression': + case NonterminalKind.EqualityExpression: this.variant = new EqualityExpression( ast.variant as ast.EqualityExpression, offsets[0], options ); break; - case 'ComparisonExpression': + case NonterminalKind.ComparisonExpression: this.variant = new ComparisonExpression( ast.variant as ast.ComparisonExpression, offsets[0], options ); break; - case 'BitwiseOrExpression': + case NonterminalKind.BitwiseOrExpression: this.variant = new BitwiseOrExpression( ast.variant as ast.BitwiseOrExpression, offsets[0], options ); break; - case 'BitwiseXorExpression': + case NonterminalKind.BitwiseXorExpression: this.variant = new BitwiseXorExpression( ast.variant as ast.BitwiseXorExpression, offsets[0], options ); break; - case 'BitwiseAndExpression': + case NonterminalKind.BitwiseAndExpression: this.variant = new BitwiseAndExpression( ast.variant as ast.BitwiseAndExpression, offsets[0], options ); break; - case 'ShiftExpression': + case NonterminalKind.ShiftExpression: this.variant = new ShiftExpression( ast.variant as ast.ShiftExpression, offsets[0], options ); break; - case 'AdditiveExpression': + case NonterminalKind.AdditiveExpression: this.variant = new AdditiveExpression( ast.variant as ast.AdditiveExpression, offsets[0], options ); break; - case 'MultiplicativeExpression': + case NonterminalKind.MultiplicativeExpression: this.variant = new MultiplicativeExpression( ast.variant as ast.MultiplicativeExpression, offsets[0], options ); break; - case 'ExponentiationExpression': + case NonterminalKind.ExponentiationExpression: this.variant = new ExponentiationExpression( ast.variant as ast.ExponentiationExpression, offsets[0], options ); break; - case 'PostfixExpression': + case NonterminalKind.PostfixExpression: this.variant = new PostfixExpression( ast.variant as ast.PostfixExpression, offsets[0], options ); break; - case 'PrefixExpression': + case NonterminalKind.PrefixExpression: this.variant = new PrefixExpression( ast.variant as ast.PrefixExpression, offsets[0], options ); break; - case 'FunctionCallExpression': + case NonterminalKind.FunctionCallExpression: this.variant = new FunctionCallExpression( ast.variant as ast.FunctionCallExpression, offsets[0], options ); break; - case 'CallOptionsExpression': + case NonterminalKind.CallOptionsExpression: this.variant = new CallOptionsExpression( ast.variant as ast.CallOptionsExpression, offsets[0], options ); break; - case 'MemberAccessExpression': + case NonterminalKind.MemberAccessExpression: this.variant = new MemberAccessExpression( ast.variant as ast.MemberAccessExpression, offsets[0], options ); break; - case 'IndexAccessExpression': + case NonterminalKind.IndexAccessExpression: this.variant = new IndexAccessExpression( ast.variant as ast.IndexAccessExpression, offsets[0], options ); break; - case 'NewExpression': + case NonterminalKind.NewExpression: this.variant = new NewExpression( ast.variant as ast.NewExpression, offsets[0], options ); break; - case 'TupleExpression': + case NonterminalKind.TupleExpression: this.variant = new TupleExpression( ast.variant as ast.TupleExpression, offsets[0], options ); break; - case 'TypeExpression': + case NonterminalKind.TypeExpression: this.variant = new TypeExpression( ast.variant as ast.TypeExpression, offsets[0], options ); break; - case 'ArrayExpression': + case NonterminalKind.ArrayExpression: this.variant = new ArrayExpression( ast.variant as ast.ArrayExpression, offsets[0], options ); break; - case 'HexNumberExpression': + case NonterminalKind.HexNumberExpression: this.variant = new HexNumberExpression( ast.variant as ast.HexNumberExpression, offsets[0] ); break; - case 'DecimalNumberExpression': + case NonterminalKind.DecimalNumberExpression: this.variant = new DecimalNumberExpression( ast.variant as ast.DecimalNumberExpression, offsets[0] ); break; - case 'StringExpression': + case NonterminalKind.StringExpression: this.variant = new StringExpression( ast.variant as ast.StringExpression, offsets[0], options ); break; - case 'ElementaryType': + case NonterminalKind.ElementaryType: this.variant = new ElementaryType( ast.variant as ast.ElementaryType, offsets[0] diff --git a/src/slang-nodes/FallbackFunctionAttribute.ts b/src/slang-nodes/FallbackFunctionAttribute.ts index a28fb6ded..1564275fe 100644 --- a/src/slang-nodes/FallbackFunctionAttribute.ts +++ b/src/slang-nodes/FallbackFunctionAttribute.ts @@ -29,14 +29,14 @@ export class FallbackFunctionAttribute implements SlangNode { this.variant = ast.variant.text; } else { switch (ast.variant.cst.kind) { - case 'ModifierInvocation': + case NonterminalKind.ModifierInvocation: this.variant = new ModifierInvocation( ast.variant as ast.ModifierInvocation, offsets[0], options ); break; - case 'OverrideSpecifier': + case NonterminalKind.OverrideSpecifier: this.variant = new OverrideSpecifier( ast.variant as ast.OverrideSpecifier, offsets[0] diff --git a/src/slang-nodes/FallbackFunctionDefinition.ts b/src/slang-nodes/FallbackFunctionDefinition.ts index 2a365df52..76db3ee3d 100644 --- a/src/slang-nodes/FallbackFunctionDefinition.ts +++ b/src/slang-nodes/FallbackFunctionDefinition.ts @@ -70,7 +70,7 @@ export class FallbackFunctionDefinition implements SlangNode { this.attributes.items.forEach((attribute) => { if ( typeof attribute.variant !== 'string' && - attribute.variant.kind === 'ModifierInvocation' + attribute.variant.kind === NonterminalKind.ModifierInvocation ) { attribute.variant.cleanModifierInvocationArguments(); } diff --git a/src/slang-nodes/ForStatement.ts b/src/slang-nodes/ForStatement.ts index c62905566..d9a785a36 100644 --- a/src/slang-nodes/ForStatement.ts +++ b/src/slang-nodes/ForStatement.ts @@ -83,7 +83,7 @@ export class ForStatement implements SlangNode { : '' }), this.closeParen, - this.body.variant.kind === 'Block' + this.body.variant.kind === NonterminalKind.Block ? [' ', path.call(print, 'body')] : group(indent([line, path.call(print, 'body')])) ]; diff --git a/src/slang-nodes/ForStatementInitialization.ts b/src/slang-nodes/ForStatementInitialization.ts index 689b97076..898782a92 100644 --- a/src/slang-nodes/ForStatementInitialization.ts +++ b/src/slang-nodes/ForStatementInitialization.ts @@ -34,21 +34,21 @@ export class ForStatementInitialization implements SlangNode { this.variant = ast.variant.text; } else { switch (ast.variant.cst.kind) { - case 'ExpressionStatement': + case NonterminalKind.ExpressionStatement: this.variant = new ExpressionStatement( ast.variant as ast.ExpressionStatement, offsets[0], options ); break; - case 'VariableDeclarationStatement': + case NonterminalKind.VariableDeclarationStatement: this.variant = new VariableDeclarationStatement( ast.variant as ast.VariableDeclarationStatement, offsets[0], options ); break; - case 'TupleDeconstructionStatement': + case NonterminalKind.TupleDeconstructionStatement: this.variant = new TupleDeconstructionStatement( ast.variant as ast.TupleDeconstructionStatement, offsets[0], diff --git a/src/slang-nodes/FunctionAttribute.ts b/src/slang-nodes/FunctionAttribute.ts index a3c056f59..effd04f68 100644 --- a/src/slang-nodes/FunctionAttribute.ts +++ b/src/slang-nodes/FunctionAttribute.ts @@ -29,14 +29,14 @@ export class FunctionAttribute implements SlangNode { this.variant = ast.variant.text; } else { switch (ast.variant.cst.kind) { - case 'ModifierInvocation': + case NonterminalKind.ModifierInvocation: this.variant = new ModifierInvocation( ast.variant as ast.ModifierInvocation, offsets[0], options ); break; - case 'OverrideSpecifier': + case NonterminalKind.OverrideSpecifier: this.variant = new OverrideSpecifier( ast.variant as ast.OverrideSpecifier, offsets[0] diff --git a/src/slang-nodes/FunctionDefinition.ts b/src/slang-nodes/FunctionDefinition.ts index 73ddba8e9..950f4aa71 100644 --- a/src/slang-nodes/FunctionDefinition.ts +++ b/src/slang-nodes/FunctionDefinition.ts @@ -82,7 +82,7 @@ export class FunctionDefinition implements SlangNode { this.attributes.items.forEach((attribute) => { if ( typeof attribute.variant !== 'string' && - attribute.variant.kind === 'ModifierInvocation' + attribute.variant.kind === NonterminalKind.ModifierInvocation ) { attribute.variant.cleanModifierInvocationArguments(); } diff --git a/src/slang-nodes/IfStatement.ts b/src/slang-nodes/IfStatement.ts index 7b509ca03..5262c8eb5 100644 --- a/src/slang-nodes/IfStatement.ts +++ b/src/slang-nodes/IfStatement.ts @@ -59,14 +59,14 @@ export class IfStatement implements SlangNode { `${this.ifKeyword} ${this.openParen}`, printSeparatedItem(path.call(print, 'condition')), this.closeParen, - this.body.variant.kind === 'Block' + this.body.variant.kind === NonterminalKind.Block ? [' ', path.call(print, 'body')] : group(indent([line, path.call(print, 'body')]), { - shouldBreak: this.body.variant.kind === 'IfStatement' // `if` within `if` + shouldBreak: this.body.variant.kind === NonterminalKind.IfStatement // `if` within `if` }), this.elseBranch ? [ - this.body.variant.kind !== 'Block' + this.body.variant.kind !== NonterminalKind.Block ? hardline // else on a new line if body is not a block : ' ', path.call(print, 'elseBranch') diff --git a/src/slang-nodes/ImportClause.ts b/src/slang-nodes/ImportClause.ts index 3c789b725..5f22dc0c6 100644 --- a/src/slang-nodes/ImportClause.ts +++ b/src/slang-nodes/ImportClause.ts @@ -22,21 +22,21 @@ export class ImportClause implements SlangNode { const { offsets } = metadata; switch (ast.variant.cst.kind) { - case 'PathImport': + case NonterminalKind.PathImport: this.variant = new PathImport( ast.variant as ast.PathImport, offsets[0], options ); break; - case 'NamedImport': + case NonterminalKind.NamedImport: this.variant = new NamedImport( ast.variant as ast.NamedImport, offsets[0], options ); break; - case 'ImportDeconstruction': + case NonterminalKind.ImportDeconstruction: this.variant = new ImportDeconstruction( ast.variant as ast.ImportDeconstruction, offsets[0], diff --git a/src/slang-nodes/MappingKeyType.ts b/src/slang-nodes/MappingKeyType.ts index 29dd9052c..c21378814 100644 --- a/src/slang-nodes/MappingKeyType.ts +++ b/src/slang-nodes/MappingKeyType.ts @@ -21,13 +21,13 @@ export class MappingKeyType implements SlangNode { const { offsets } = metadata; switch (ast.variant.cst.kind) { - case 'ElementaryType': + case NonterminalKind.ElementaryType: this.variant = new ElementaryType( ast.variant as ast.ElementaryType, offsets[0] ); break; - case 'IdentifierPath': + case NonterminalKind.IdentifierPath: this.variant = new IdentifierPath( ast.variant as ast.IdentifierPath, offsets[0] diff --git a/src/slang-nodes/MemberAccessExpression.ts b/src/slang-nodes/MemberAccessExpression.ts index 431438204..597e5bac4 100644 --- a/src/slang-nodes/MemberAccessExpression.ts +++ b/src/slang-nodes/MemberAccessExpression.ts @@ -8,7 +8,7 @@ import { MemberAccess } from './MemberAccess.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { group, indent, label, softline } = doc.builders; @@ -20,24 +20,28 @@ const isChainableExpression = createKindCheckFunction([ function isEndOfChain(node: MemberAccessExpression, path: AstPath): boolean { for ( - let i = 0, currentNode = node, grandparentNode = path.getNode(i + 2); + let i = 0, + currentNode: AstNode = node, + grandparentNode = path.getNode(i + 2) as AstNode; isChainableExpression(grandparentNode); - i += 2, currentNode = grandparentNode, grandparentNode = path.getNode(i + 2) + i += 2, + currentNode = grandparentNode, + grandparentNode = path.getNode(i + 2) as AstNode ) { switch (grandparentNode.kind) { - case 'MemberAccessExpression': + case NonterminalKind.MemberAccessExpression: // If direct ParentNode is a MemberAccess we are not at the end of the // chain. return false; - case 'IndexAccessExpression': + case NonterminalKind.IndexAccessExpression: // If direct ParentNode is an IndexAccess and currentNode is not the // operand then it must be the start or the end in which case it is the // end of the chain. if (currentNode !== grandparentNode.operand.variant) return true; break; - case 'FunctionCallExpression': + case NonterminalKind.FunctionCallExpression: // If direct ParentNode is a FunctionCall and currentNode is not the // operand then it must be and argument in which case it is the end // of the chain. diff --git a/src/slang-nodes/ModifierDefinition.ts b/src/slang-nodes/ModifierDefinition.ts index bb0277633..f20f4d420 100644 --- a/src/slang-nodes/ModifierDefinition.ts +++ b/src/slang-nodes/ModifierDefinition.ts @@ -92,11 +92,11 @@ export class ModifierDefinition implements SlangNode { comments: { value: [], ...objectConfig }, items: { value: [], ...objectConfig }, separators: { value: [], ...objectConfig } - }), + }) as Parameters, ...objectConfig }, closeParen: { value: ')', ...objectConfig } - }); + }) as ParametersDeclaration; } } diff --git a/src/slang-nodes/ModifierInvocation.ts b/src/slang-nodes/ModifierInvocation.ts index a8b54fc69..9c4876cf3 100644 --- a/src/slang-nodes/ModifierInvocation.ts +++ b/src/slang-nodes/ModifierInvocation.ts @@ -42,7 +42,8 @@ export class ModifierInvocation implements SlangNode { this.cleanModifierInvocationArguments = (): void => { if ( this.arguments && - this.arguments.variant.kind === 'PositionalArgumentsDeclaration' && + this.arguments.variant.kind === + NonterminalKind.PositionalArgumentsDeclaration && this.arguments.variant.arguments.items.length === 0 && // no arguments !ast.arguments!.variant.cst.children().some((child) => isComment(child)) // no comments ) { diff --git a/src/slang-nodes/Parameter.ts b/src/slang-nodes/Parameter.ts index ac2c88ced..17064b39d 100644 --- a/src/slang-nodes/Parameter.ts +++ b/src/slang-nodes/Parameter.ts @@ -45,7 +45,7 @@ export class Parameter implements SlangNode { print(path: AstPath, print: (path: AstPath) => Doc): Doc { return group([ path.call(print, 'typeName'), - this.storageLocation ? ` ${path.call(print, 'storageLocation')}` : '', + this.storageLocation ? [' ', path.call(print, 'storageLocation')] : '', this.name ? ` ${this.name}` : '' ]); } diff --git a/src/slang-nodes/Pragma.ts b/src/slang-nodes/Pragma.ts index a8d27c9ed..925320a50 100644 --- a/src/slang-nodes/Pragma.ts +++ b/src/slang-nodes/Pragma.ts @@ -22,20 +22,20 @@ export class Pragma implements SlangNode { const { offsets } = metadata; switch (ast.variant.cst.kind) { - case 'ABICoderPragma': + case NonterminalKind.ABICoderPragma: this.variant = new ABICoderPragma( ast.variant as ast.ABICoderPragma, offsets[0] ); break; - case 'ExperimentalPragma': + case NonterminalKind.ExperimentalPragma: this.variant = new ExperimentalPragma( ast.variant as ast.ExperimentalPragma, offsets[0], options ); break; - case 'VersionPragma': + case NonterminalKind.VersionPragma: this.variant = new VersionPragma( ast.variant as ast.VersionPragma, offsets[0] diff --git a/src/slang-nodes/ReceiveFunctionAttribute.ts b/src/slang-nodes/ReceiveFunctionAttribute.ts index 250739d3d..0f74cbd75 100644 --- a/src/slang-nodes/ReceiveFunctionAttribute.ts +++ b/src/slang-nodes/ReceiveFunctionAttribute.ts @@ -29,14 +29,14 @@ export class ReceiveFunctionAttribute implements SlangNode { this.variant = ast.variant.text; } else { switch (ast.variant.cst.kind) { - case 'ModifierInvocation': + case NonterminalKind.ModifierInvocation: this.variant = new ModifierInvocation( ast.variant as ast.ModifierInvocation, offsets[0], options ); break; - case 'OverrideSpecifier': + case NonterminalKind.OverrideSpecifier: this.variant = new OverrideSpecifier( ast.variant as ast.OverrideSpecifier, offsets[0] diff --git a/src/slang-nodes/ReceiveFunctionDefinition.ts b/src/slang-nodes/ReceiveFunctionDefinition.ts index 5078fb2a6..39350da6b 100644 --- a/src/slang-nodes/ReceiveFunctionDefinition.ts +++ b/src/slang-nodes/ReceiveFunctionDefinition.ts @@ -61,7 +61,7 @@ export class ReceiveFunctionDefinition implements SlangNode { this.attributes.items.forEach((attribute) => { if ( typeof attribute.variant !== 'string' && - attribute.variant.kind === 'ModifierInvocation' + attribute.variant.kind === NonterminalKind.ModifierInvocation ) { attribute.variant.cleanModifierInvocationArguments(); } diff --git a/src/slang-nodes/ReturnStatement.ts b/src/slang-nodes/ReturnStatement.ts index ef2056b7b..2f11223d2 100644 --- a/src/slang-nodes/ReturnStatement.ts +++ b/src/slang-nodes/ReturnStatement.ts @@ -17,9 +17,10 @@ function printExpression( ): Doc { if (node.expression) { return typeof node.expression.variant !== 'string' && - (node.expression.variant.kind === 'TupleExpression' || + (node.expression.variant.kind === NonterminalKind.TupleExpression || (options.experimentalTernaries && - node.expression.variant.kind === 'ConditionalExpression')) + node.expression.variant.kind === + NonterminalKind.ConditionalExpression)) ? [' ', path.call(print, 'expression')] : group(indent([line, path.call(print, 'expression')])); } diff --git a/src/slang-nodes/SourceUnitMember.ts b/src/slang-nodes/SourceUnitMember.ts index bd38b619c..77043bcce 100644 --- a/src/slang-nodes/SourceUnitMember.ts +++ b/src/slang-nodes/SourceUnitMember.ts @@ -49,89 +49,89 @@ export class SourceUnitMember implements SlangNode { const { offsets } = metadata; switch (ast.variant.cst.kind) { - case 'PragmaDirective': + case NonterminalKind.PragmaDirective: this.variant = new PragmaDirective( ast.variant as ast.PragmaDirective, offsets[0], options ); break; - case 'ImportDirective': + case NonterminalKind.ImportDirective: this.variant = new ImportDirective( ast.variant as ast.ImportDirective, offsets[0], options ); break; - case 'ContractDefinition': + case NonterminalKind.ContractDefinition: this.variant = new ContractDefinition( ast.variant as ast.ContractDefinition, offsets[0], options ); break; - case 'InterfaceDefinition': + case NonterminalKind.InterfaceDefinition: this.variant = new InterfaceDefinition( ast.variant as ast.InterfaceDefinition, offsets[0], options ); break; - case 'LibraryDefinition': + case NonterminalKind.LibraryDefinition: this.variant = new LibraryDefinition( ast.variant as ast.LibraryDefinition, offsets[0], options ); break; - case 'StructDefinition': + case NonterminalKind.StructDefinition: this.variant = new StructDefinition( ast.variant as ast.StructDefinition, offsets[0], options ); break; - case 'EnumDefinition': + case NonterminalKind.EnumDefinition: this.variant = new EnumDefinition( ast.variant as ast.EnumDefinition, offsets[0] ); break; - case 'FunctionDefinition': + case NonterminalKind.FunctionDefinition: this.variant = new FunctionDefinition( ast.variant as ast.FunctionDefinition, offsets[0], options ); break; - case 'ConstantDefinition': + case NonterminalKind.ConstantDefinition: this.variant = new ConstantDefinition( ast.variant as ast.ConstantDefinition, offsets[0], options ); break; - case 'ErrorDefinition': + case NonterminalKind.ErrorDefinition: this.variant = new ErrorDefinition( ast.variant as ast.ErrorDefinition, offsets[0], options ); break; - case 'UserDefinedValueTypeDefinition': + case NonterminalKind.UserDefinedValueTypeDefinition: this.variant = new UserDefinedValueTypeDefinition( ast.variant as ast.UserDefinedValueTypeDefinition, offsets[0] ); break; - case 'UsingDirective': + case NonterminalKind.UsingDirective: this.variant = new UsingDirective( ast.variant as ast.UsingDirective, offsets[0], options ); break; - case 'EventDefinition': + case NonterminalKind.EventDefinition: this.variant = new EventDefinition( ast.variant as ast.EventDefinition, offsets[0], diff --git a/src/slang-nodes/StateVariableDefinitionValue.ts b/src/slang-nodes/StateVariableDefinitionValue.ts index 0507ec8ff..b7305aab8 100644 --- a/src/slang-nodes/StateVariableDefinitionValue.ts +++ b/src/slang-nodes/StateVariableDefinitionValue.ts @@ -39,7 +39,7 @@ export class StateVariableDefinitionValue implements SlangNode { print(path: AstPath, print: (path: AstPath) => Doc): Doc { return typeof this.value.variant !== 'string' && - this.value.variant.kind === 'ArrayExpression' + this.value.variant.kind === NonterminalKind.ArrayExpression ? [` ${this.equal} `, path.call(print, 'value')] : group([` ${this.equal}`, indent([line, path.call(print, 'value')])]); } diff --git a/src/slang-nodes/Statement.ts b/src/slang-nodes/Statement.ts index 13d92372f..73aefd3fa 100644 --- a/src/slang-nodes/Statement.ts +++ b/src/slang-nodes/Statement.ts @@ -53,112 +53,112 @@ export class Statement implements SlangNode { const { offsets } = metadata; switch (ast.variant.cst.kind) { - case 'ExpressionStatement': + case NonterminalKind.ExpressionStatement: this.variant = new ExpressionStatement( ast.variant as ast.ExpressionStatement, offsets[0], options ); break; - case 'VariableDeclarationStatement': + case NonterminalKind.VariableDeclarationStatement: this.variant = new VariableDeclarationStatement( ast.variant as ast.VariableDeclarationStatement, offsets[0], options ); break; - case 'TupleDeconstructionStatement': + case NonterminalKind.TupleDeconstructionStatement: this.variant = new TupleDeconstructionStatement( ast.variant as ast.TupleDeconstructionStatement, offsets[0], options ); break; - case 'IfStatement': + case NonterminalKind.IfStatement: this.variant = new IfStatement( ast.variant as ast.IfStatement, offsets[0], options ); break; - case 'ForStatement': + case NonterminalKind.ForStatement: this.variant = new ForStatement( ast.variant as ast.ForStatement, offsets[0], options ); break; - case 'WhileStatement': + case NonterminalKind.WhileStatement: this.variant = new WhileStatement( ast.variant as ast.WhileStatement, offsets[0], options ); break; - case 'DoWhileStatement': + case NonterminalKind.DoWhileStatement: this.variant = new DoWhileStatement( ast.variant as ast.DoWhileStatement, offsets[0], options ); break; - case 'ContinueStatement': + case NonterminalKind.ContinueStatement: this.variant = new ContinueStatement( ast.variant as ast.ContinueStatement, offsets[0] ); break; - case 'BreakStatement': + case NonterminalKind.BreakStatement: this.variant = new BreakStatement( ast.variant as ast.BreakStatement, offsets[0] ); break; - case 'ReturnStatement': + case NonterminalKind.ReturnStatement: this.variant = new ReturnStatement( ast.variant as ast.ReturnStatement, offsets[0], options ); break; - case 'ThrowStatement': + case NonterminalKind.ThrowStatement: this.variant = new ThrowStatement( ast.variant as ast.ThrowStatement, offsets[0] ); break; - case 'EmitStatement': + case NonterminalKind.EmitStatement: this.variant = new EmitStatement( ast.variant as ast.EmitStatement, offsets[0], options ); break; - case 'TryStatement': + case NonterminalKind.TryStatement: this.variant = new TryStatement( ast.variant as ast.TryStatement, offsets[0], options ); break; - case 'RevertStatement': + case NonterminalKind.RevertStatement: this.variant = new RevertStatement( ast.variant as ast.RevertStatement, offsets[0], options ); break; - case 'AssemblyStatement': + case NonterminalKind.AssemblyStatement: this.variant = new AssemblyStatement( ast.variant as ast.AssemblyStatement, offsets[0], options ); break; - case 'Block': + case NonterminalKind.Block: this.variant = new Block(ast.variant as ast.Block, offsets[0], options); break; - case 'UncheckedBlock': + case NonterminalKind.UncheckedBlock: this.variant = new UncheckedBlock( ast.variant as ast.UncheckedBlock, offsets[0], diff --git a/src/slang-nodes/StringExpression.ts b/src/slang-nodes/StringExpression.ts index e8f04e8d0..66c0b858e 100644 --- a/src/slang-nodes/StringExpression.ts +++ b/src/slang-nodes/StringExpression.ts @@ -33,21 +33,21 @@ export class StringExpression implements SlangNode { const { offsets } = metadata; switch (ast.variant.cst.kind) { - case 'StringLiteral': + case NonterminalKind.StringLiteral: this.variant = new StringLiteral( ast.variant as ast.StringLiteral, offsets[0], options ); break; - case 'StringLiterals': + case NonterminalKind.StringLiterals: this.variant = new StringLiterals( ast.variant as ast.StringLiterals, offsets[0], options ); break; - case 'HexStringLiteral': + case NonterminalKind.HexStringLiteral: this.variant = new HexStringLiteral( ast.variant as ast.HexStringLiteral, offsets[0], @@ -55,14 +55,14 @@ export class StringExpression implements SlangNode { ); break; - case 'HexStringLiterals': + case NonterminalKind.HexStringLiterals: this.variant = new HexStringLiterals( ast.variant as ast.HexStringLiterals, offsets[0], options ); break; - case 'UnicodeStringLiterals': + case NonterminalKind.UnicodeStringLiterals: this.variant = new UnicodeStringLiterals( ast.variant as ast.UnicodeStringLiterals, offsets[0], diff --git a/src/slang-nodes/TupleDeconstructionStatement.ts b/src/slang-nodes/TupleDeconstructionStatement.ts index 2f9b5be47..de4bb5053 100644 --- a/src/slang-nodes/TupleDeconstructionStatement.ts +++ b/src/slang-nodes/TupleDeconstructionStatement.ts @@ -63,7 +63,7 @@ export class TupleDeconstructionStatement implements SlangNode { this.openParen, path.call(print, 'elements'), typeof this.expression.variant !== 'string' && - this.expression.variant.kind === 'TupleExpression' + this.expression.variant.kind === NonterminalKind.TupleExpression ? [`${this.closeParen} ${this.equal} `, path.call(print, 'expression')] : group([ `${this.closeParen} ${this.equal}`, diff --git a/src/slang-nodes/TupleMember.ts b/src/slang-nodes/TupleMember.ts index e354d1376..4e24b606f 100644 --- a/src/slang-nodes/TupleMember.ts +++ b/src/slang-nodes/TupleMember.ts @@ -21,14 +21,14 @@ export class TupleMember implements SlangNode { const { offsets } = metadata; switch (ast.variant.cst.kind) { - case 'TypedTupleMember': + case NonterminalKind.TypedTupleMember: this.variant = new TypedTupleMember( ast.variant as ast.TypedTupleMember, offsets[0], options ); break; - case 'UntypedTupleMember': + case NonterminalKind.UntypedTupleMember: this.variant = new UntypedTupleMember( ast.variant as ast.UntypedTupleMember, offsets[0] diff --git a/src/slang-nodes/TypeName.ts b/src/slang-nodes/TypeName.ts index 980277e6b..c3313f186 100644 --- a/src/slang-nodes/TypeName.ts +++ b/src/slang-nodes/TypeName.ts @@ -29,34 +29,34 @@ export class TypeName implements SlangNode { const { offsets } = metadata; switch (ast.variant.cst.kind) { - case 'ArrayTypeName': + case NonterminalKind.ArrayTypeName: this.variant = new ArrayTypeName( ast.variant as ast.ArrayTypeName, offsets[0], options ); break; - case 'FunctionType': + case NonterminalKind.FunctionType: this.variant = new FunctionType( ast.variant as ast.FunctionType, offsets[0], options ); break; - case 'MappingType': + case NonterminalKind.MappingType: this.variant = new MappingType( ast.variant as ast.MappingType, offsets[0], options ); break; - case 'ElementaryType': + case NonterminalKind.ElementaryType: this.variant = new ElementaryType( ast.variant as ast.ElementaryType, offsets[0] ); break; - case 'IdentifierPath': + case NonterminalKind.IdentifierPath: this.variant = new IdentifierPath( ast.variant as ast.IdentifierPath, offsets[0] diff --git a/src/slang-nodes/UsingClause.ts b/src/slang-nodes/UsingClause.ts index 3f929f29d..c829fdb97 100644 --- a/src/slang-nodes/UsingClause.ts +++ b/src/slang-nodes/UsingClause.ts @@ -21,13 +21,13 @@ export class UsingClause implements SlangNode { const { offsets } = metadata; switch (ast.variant.cst.kind) { - case 'IdentifierPath': + case NonterminalKind.IdentifierPath: this.variant = new IdentifierPath( ast.variant as ast.IdentifierPath, offsets[0] ); break; - case 'UsingDeconstruction': + case NonterminalKind.UsingDeconstruction: this.variant = new UsingDeconstruction( ast.variant as ast.UsingDeconstruction, offsets[0] diff --git a/src/slang-nodes/VersionExpression.ts b/src/slang-nodes/VersionExpression.ts index 5b89257de..cbb4f9737 100644 --- a/src/slang-nodes/VersionExpression.ts +++ b/src/slang-nodes/VersionExpression.ts @@ -26,19 +26,19 @@ export class VersionExpression implements SlangNode { this.variant = ast.variant.text; } else { switch (ast.variant.cst.kind) { - case 'VersionRange': + case NonterminalKind.VersionRange: this.variant = new VersionRange( ast.variant as ast.VersionRange, offsets[0] ); break; - case 'VersionComparator': + case NonterminalKind.VersionComparator: this.variant = new VersionComparator( ast.variant as ast.VersionComparator, offsets[0] ); break; - case 'VersionSpecifiers': + case NonterminalKind.VersionSpecifiers: this.variant = new VersionSpecifiers( ast.variant as ast.VersionSpecifiers, offsets[0] diff --git a/src/slang-nodes/WhileStatement.ts b/src/slang-nodes/WhileStatement.ts index fed356c05..7a8c1ae14 100644 --- a/src/slang-nodes/WhileStatement.ts +++ b/src/slang-nodes/WhileStatement.ts @@ -49,7 +49,7 @@ export class WhileStatement implements SlangNode { `${this.whileKeyword} ${this.openParen}`, printSeparatedItem(path.call(print, 'condition')), this.closeParen, - this.body.variant.kind === 'Block' + this.body.variant.kind === NonterminalKind.Block ? [' ', path.call(print, 'body')] : group(indent([line, path.call(print, 'body')])) ]; diff --git a/src/slang-nodes/YulExpression.ts b/src/slang-nodes/YulExpression.ts index 3ce416432..06060a857 100644 --- a/src/slang-nodes/YulExpression.ts +++ b/src/slang-nodes/YulExpression.ts @@ -27,27 +27,27 @@ export class YulExpression implements SlangNode { const { offsets } = metadata; switch (ast.variant.cst.kind) { - case 'YulFunctionCallExpression': + case NonterminalKind.YulFunctionCallExpression: this.variant = new YulFunctionCallExpression( ast.variant as ast.YulFunctionCallExpression, offsets[0], options ); break; - case 'YulLiteral': + case NonterminalKind.YulLiteral: this.variant = new YulLiteral( ast.variant as ast.YulLiteral, offsets[0], options ); break; - case 'YulBuiltInFunction': + case NonterminalKind.YulBuiltInFunction: this.variant = new YulBuiltInFunction( ast.variant as ast.YulBuiltInFunction, offsets[0] ); break; - case 'YulPath': + case NonterminalKind.YulPath: this.variant = new YulPath(ast.variant as ast.YulPath, offsets[0]); break; default: diff --git a/src/slang-nodes/YulLiteral.ts b/src/slang-nodes/YulLiteral.ts index 03a490f16..f4223c6d6 100644 --- a/src/slang-nodes/YulLiteral.ts +++ b/src/slang-nodes/YulLiteral.ts @@ -25,14 +25,14 @@ export class YulLiteral implements SlangNode { this.variant = ast.variant.text; } else { switch (ast.variant.cst.kind) { - case 'HexStringLiteral': + case NonterminalKind.HexStringLiteral: this.variant = new HexStringLiteral( ast.variant as ast.HexStringLiteral, offsets[0], options ); break; - case 'StringLiteral': + case NonterminalKind.StringLiteral: this.variant = new StringLiteral( ast.variant as ast.StringLiteral, offsets[0], diff --git a/src/slang-nodes/YulStatement.ts b/src/slang-nodes/YulStatement.ts index 96fe2512e..1ed394f03 100644 --- a/src/slang-nodes/YulStatement.ts +++ b/src/slang-nodes/YulStatement.ts @@ -45,84 +45,84 @@ export class YulStatement implements SlangNode { const { offsets } = metadata; switch (ast.variant.cst.kind) { - case 'YulBlock': + case NonterminalKind.YulBlock: this.variant = new YulBlock( ast.variant as ast.YulBlock, offsets[0], options ); break; - case 'YulFunctionDefinition': + case NonterminalKind.YulFunctionDefinition: this.variant = new YulFunctionDefinition( ast.variant as ast.YulFunctionDefinition, offsets[0], options ); break; - case 'YulVariableDeclarationStatement': + case NonterminalKind.YulVariableDeclarationStatement: this.variant = new YulVariableDeclarationStatement( ast.variant as ast.YulVariableDeclarationStatement, offsets[0], options ); break; - case 'YulVariableAssignmentStatement': + case NonterminalKind.YulVariableAssignmentStatement: this.variant = new YulVariableAssignmentStatement( ast.variant as ast.YulVariableAssignmentStatement, offsets[0], options ); break; - case 'YulStackAssignmentStatement': + case NonterminalKind.YulStackAssignmentStatement: this.variant = new YulStackAssignmentStatement( ast.variant as ast.YulStackAssignmentStatement, offsets[0], options ); break; - case 'YulIfStatement': + case NonterminalKind.YulIfStatement: this.variant = new YulIfStatement( ast.variant as ast.YulIfStatement, offsets[0], options ); break; - case 'YulForStatement': + case NonterminalKind.YulForStatement: this.variant = new YulForStatement( ast.variant as ast.YulForStatement, offsets[0], options ); break; - case 'YulSwitchStatement': + case NonterminalKind.YulSwitchStatement: this.variant = new YulSwitchStatement( ast.variant as ast.YulSwitchStatement, offsets[0], options ); break; - case 'YulLeaveStatement': + case NonterminalKind.YulLeaveStatement: this.variant = new YulLeaveStatement( ast.variant as ast.YulLeaveStatement, offsets[0] ); break; - case 'YulBreakStatement': + case NonterminalKind.YulBreakStatement: this.variant = new YulBreakStatement( ast.variant as ast.YulBreakStatement, offsets[0] ); break; - case 'YulContinueStatement': + case NonterminalKind.YulContinueStatement: this.variant = new YulContinueStatement( ast.variant as ast.YulContinueStatement, offsets[0] ); break; - case 'YulLabel': + case NonterminalKind.YulLabel: this.variant = new YulLabel(ast.variant as ast.YulLabel, offsets[0]); break; - case 'YulExpression': + case NonterminalKind.YulExpression: this.variant = new YulExpression( ast.variant as ast.YulExpression, offsets[0], diff --git a/src/slang-nodes/YulSwitchCase.ts b/src/slang-nodes/YulSwitchCase.ts index 915ba741b..87b946125 100644 --- a/src/slang-nodes/YulSwitchCase.ts +++ b/src/slang-nodes/YulSwitchCase.ts @@ -21,14 +21,14 @@ export class YulSwitchCase implements SlangNode { const { offsets } = metadata; switch (ast.variant.cst.kind) { - case 'YulDefaultCase': + case NonterminalKind.YulDefaultCase: this.variant = new YulDefaultCase( ast.variant as ast.YulDefaultCase, offsets[0], options ); break; - case 'YulValueCase': + case NonterminalKind.YulValueCase: this.variant = new YulValueCase( ast.variant as ast.YulValueCase, offsets[0], diff --git a/src/slang-printers/create-binary-operation-printer.ts b/src/slang-printers/create-binary-operation-printer.ts index 89563baa1..508bbce9d 100644 --- a/src/slang-printers/create-binary-operation-printer.ts +++ b/src/slang-printers/create-binary-operation-printer.ts @@ -2,7 +2,7 @@ import { doc } from 'prettier'; import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { BinaryOperation } from '../types.js'; +import type { AstNode, BinaryOperation } from '../types.js'; const { group, line } = doc.builders; @@ -19,7 +19,7 @@ function rightOperandPrint( !( typeof node.leftOperand.variant !== 'string' && isBinaryOperation(node.leftOperand.variant) - ) && !isBinaryOperation(path.getNode(2)); + ) && !isBinaryOperation(path.getNode(2) as AstNode); return shouldGroup ? group(rightOperand) : rightOperand; } diff --git a/src/slang-printers/print-binary-operation.ts b/src/slang-printers/print-binary-operation.ts index 48db2ec72..7578597d8 100644 --- a/src/slang-printers/print-binary-operation.ts +++ b/src/slang-printers/print-binary-operation.ts @@ -1,8 +1,10 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { doc } from 'prettier'; import { createBinaryOperationPrinter } from './create-binary-operation-printer.js'; import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js'; import type { AstPath, Doc } from 'prettier'; +import type { AstNode, BinaryOperation } from '../types.js'; const { group, indent } = doc.builders; @@ -22,7 +24,7 @@ const isBinaryOperationWithoutComparison = createKindCheckFunction([ const binaryGroupRulesBuilder = (path: AstPath) => (document: Doc): Doc => { - const grandparentNode = path.getNode(2); + const grandparentNode = path.getNode(2) as AstNode; if (isBinaryOperationWithoutComparison(grandparentNode)) { return document; } @@ -32,14 +34,15 @@ const binaryGroupRulesBuilder = const binaryIndentRulesBuilder = (path: AstPath) => (document: Doc): Doc => { - let node = path.getNode(); + let node = path.getNode() as AstNode; for (let i = 2; ; i += 2) { - const grandparentNode = path.getNode(i); - if (grandparentNode.kind === 'ReturnStatement') break; + const grandparentNode = path.getNode(i) as AstNode; + if (grandparentNode.kind === NonterminalKind.ReturnStatement) break; if (!isBinaryOperationWithoutComparison(grandparentNode)) { return indent(document); } - if (node === grandparentNode.rightOperand.variant) break; + if (node === (grandparentNode as BinaryOperation).rightOperand.variant) + break; node = grandparentNode; } return document; diff --git a/src/slang-printers/print-comparison-operation.ts b/src/slang-printers/print-comparison-operation.ts index 40cf00254..c48e3ddc9 100644 --- a/src/slang-printers/print-comparison-operation.ts +++ b/src/slang-printers/print-comparison-operation.ts @@ -1,9 +1,11 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { doc } from 'prettier'; import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js'; import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; import { createBinaryOperationPrinter } from './create-binary-operation-printer.js'; import type { AstPath, Doc } from 'prettier'; +import type { AstNode, BinaryOperation } from '../types.js'; const { group, indent } = doc.builders; @@ -16,16 +18,21 @@ const isStatementWithoutIndentedOperation = createKindCheckFunction([ const comparisonIndentRulesBuilder = (path: AstPath) => (document: Doc): Doc => { - let node = path.getNode(); + let node = path.getNode() as AstNode; for (let i = 2; ; i += 2) { - const grandparentNode = path.getNode(i); - if (grandparentNode.kind === 'ExpressionStatement') { - if (path.getNode(i + 1).kind === 'ForStatementCondition') break; + const grandparentNode = path.getNode(i) as AstNode; + if (grandparentNode.kind === NonterminalKind.ExpressionStatement) { + if ( + (path.getNode(i + 1) as AstNode).kind === + NonterminalKind.ForStatementCondition + ) + break; else return indent(document); } if (isStatementWithoutIndentedOperation(grandparentNode)) break; if (!isBinaryOperation(grandparentNode)) return indent(document); - if (node === grandparentNode.rightOperand.variant) break; + if (node === (grandparentNode as BinaryOperation).rightOperand.variant) + break; node = grandparentNode; } return document; diff --git a/src/slang-printers/print-logical-operation.ts b/src/slang-printers/print-logical-operation.ts index 5c913fc10..658402c50 100644 --- a/src/slang-printers/print-logical-operation.ts +++ b/src/slang-printers/print-logical-operation.ts @@ -1,9 +1,11 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { doc } from 'prettier'; import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js'; import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; import { createBinaryOperationPrinter } from './create-binary-operation-printer.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; +import type { AstNode, BinaryOperation } from '../types.js'; const { group, indent } = doc.builders; @@ -16,23 +18,24 @@ const isStatementWithoutIndentedOperation = createKindCheckFunction([ const logicalGroupRulesBuilder = (path: AstPath) => (document: Doc): Doc => - isBinaryOperation(path.getNode(2)) ? document : group(document); + isBinaryOperation(path.getNode(2) as AstNode) ? document : group(document); const logicalIndentRulesBuilder = (path: AstPath, options: ParserOptions) => (document: Doc): Doc => { - let node = path.getNode(); + let node = path.getNode() as AstNode; for (let i = 2; ; i += 2) { - const grandparentNode = path.getNode(i); + const grandparentNode = path.getNode(i) as AstNode; if (isStatementWithoutIndentedOperation(grandparentNode)) break; if ( options.experimentalTernaries && - grandparentNode.kind === 'ConditionalExpression' && + grandparentNode.kind === NonterminalKind.ConditionalExpression && grandparentNode.operand.variant === node ) break; if (!isBinaryOperation(grandparentNode)) return indent(document); - if (node === grandparentNode.rightOperand.variant) break; + if (node === (grandparentNode as BinaryOperation).rightOperand.variant) + break; node = grandparentNode; } return document; diff --git a/src/slang-printers/print-preserving-empty-lines.ts b/src/slang-printers/print-preserving-empty-lines.ts index f8020b3a0..d5bece192 100644 --- a/src/slang-printers/print-preserving-empty-lines.ts +++ b/src/slang-printers/print-preserving-empty-lines.ts @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { doc } from 'prettier'; import { isLast, @@ -6,7 +7,7 @@ import { import { locEnd } from '../slang-utils/loc.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { YulStatement } from '../slang-nodes/YulStatement.js'; +import type { AstNode } from '../types.js'; const { hardline } = doc.builders; @@ -17,13 +18,14 @@ export function printPreservingEmptyLines( options: ParserOptions ): Doc { return path.map((childPath, index) => { - const node = childPath.getNode() as YulStatement; + const node = childPath.getNode() as AstNode; return [ // Only attempt to prepend an empty line if `node` is not the first item index > 0 && // YulLabel adds a dedented line so we don't have to prepend a hardline. - (node.kind !== 'YulStatement' || node.variant.kind !== 'YulLabel') + (node.kind !== NonterminalKind.YulStatement || + node.variant.kind !== NonterminalKind.YulLabel) ? hardline : '', print(childPath), diff --git a/src/slang-utils/backward-compatibility.ts b/src/slang-utils/backward-compatibility.ts index 1d7565bea..7639745e0 100644 --- a/src/slang-utils/backward-compatibility.ts +++ b/src/slang-utils/backward-compatibility.ts @@ -35,7 +35,11 @@ export function getNextNonSpaceNonCommentCharacter( // TODO: remove undefined once we stop supporting prettier 2 export const getNode = (path: AstPath): AstNode | Comment | null | undefined => - isPrettier2 ? path.getValue() : path.node; // V3 deprecated `getValue` + (isPrettier2 ? path.getValue() : path.node) as + | AstNode + | Comment + | null + | undefined; // V3 deprecated `getValue` export function isLast(path: AstPath, key: string, index: number): boolean { return isPrettier2 diff --git a/src/slang-utils/create-hug-function.ts b/src/slang-utils/create-hug-function.ts index e22c3c797..ddb976612 100644 --- a/src/slang-utils/create-hug-function.ts +++ b/src/slang-utils/create-hug-function.ts @@ -50,19 +50,19 @@ export function createHugFunction( loc: { value: { ...loc }, ...objectConfig }, comments: { value: [], ...objectConfig }, expression: { value: node, ...objectConfig } - }) + }) as TupleValue ], ...objectConfig }, separators: { value: [], ...objectConfig } - }), + }) as TupleValues, ...objectConfig }, closeParen: { value: ')', ...objectConfig } - }), + }) as TupleExpression, ...objectConfig } - }); + }) as Expression; } return node; diff --git a/src/slang-utils/create-kind-check-function.ts b/src/slang-utils/create-kind-check-function.ts index fdd4e6724..094c0cd38 100644 --- a/src/slang-utils/create-kind-check-function.ts +++ b/src/slang-utils/create-kind-check-function.ts @@ -1,5 +1,6 @@ import { Node } from '@nomicfoundation/slang/cst'; -import { AstNode, Comment } from '../types'; + +import type { AstNode, Comment } from '../types'; export function createKindCheckFunction( kindsArray: string[] diff --git a/src/slang-utils/get-offsets.ts b/src/slang-utils/get-offsets.ts index 2dd424814..492d724a8 100644 --- a/src/slang-utils/get-offsets.ts +++ b/src/slang-utils/get-offsets.ts @@ -1,3 +1,5 @@ +import { TerminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { NodeType } from '@nomicfoundation/slang/cst/index.js'; import { isComment } from './is-comment.js'; import type { Node } from '@nomicfoundation/slang/cst/index.js'; @@ -5,15 +7,14 @@ import type { AstNode, Comment, Metadata, SlangAstNode } from '../types.js'; function getLeadingOffset(children: Node[]): number { let offset = 0; - for (let i = 0; i < children.length; i += 1) { - const child = children[i]; - if (child.type === 'Nonterminal') { + for (const child of children) { + if (child.type === NodeType.Nonterminal) { // The node's content starts when we find the first non-terminal token. return offset; } else if ( !isComment(child) && - child.kind !== 'EndOfLine' && - child.kind !== 'Whitespace' + child.kind !== TerminalKind.EndOfLine && + child.kind !== TerminalKind.Whitespace ) { // The content of the node started if we find a non-comment, // non-whitespace token. @@ -35,13 +36,13 @@ export function getNodeMetadata( const comments: Comment[] = []; const offsets = children.reduce((offsetsArray: number[], child) => { - if (child.type === 'Nonterminal') { + if (child.type === NodeType.Nonterminal) { offsetsArray.push(offset); } else if ( - child.kind === 'MultiLineComment' || - child.kind === 'MultiLineNatSpecComment' || - child.kind === 'SingleLineComment' || - child.kind === 'SingleLineNatSpecComment' + child.kind === TerminalKind.MultiLineComment || + child.kind === TerminalKind.MultiLineNatSpecComment || + child.kind === TerminalKind.SingleLineComment || + child.kind === TerminalKind.SingleLineNatSpecComment ) { // Since the fetching the comments and calculating offsets are both done // as we iterate over the children and the comment also depends on the diff --git a/src/slang-utils/sort-function-attributes.ts b/src/slang-utils/sort-function-attributes.ts index 34c113f3c..6ad5f67c9 100644 --- a/src/slang-utils/sort-function-attributes.ts +++ b/src/slang-utils/sort-function-attributes.ts @@ -1,3 +1,4 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import type { SortableAttribute, SortableVariant } from './types'; const visibilityKeyWords = new Set([ @@ -32,13 +33,13 @@ export function sortFunctionAttributes( // Both are nodes // OverrideSpecifiers before ModifierInvocation if ( - (a.variant as SortableVariant).kind === 'OverrideSpecifier' && - (b.variant as SortableVariant).kind === 'ModifierInvocation' + (a.variant as SortableVariant).kind === NonterminalKind.OverrideSpecifier && + (b.variant as SortableVariant).kind === NonterminalKind.ModifierInvocation ) return -1; if ( - (b.variant as SortableVariant).kind === 'OverrideSpecifier' && - (a.variant as SortableVariant).kind === 'ModifierInvocation' + (b.variant as SortableVariant).kind === NonterminalKind.OverrideSpecifier && + (a.variant as SortableVariant).kind === NonterminalKind.ModifierInvocation ) return 1; From 3cd26e645b616cdaafb51773ce975d79e2f84c1f Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 31 Jul 2024 23:31:17 +1200 Subject: [PATCH 104/160] Improvements on updateMetadata and fully using Slang enum values instead of static strings --- src/slang-nodes/ABICoderPragma.ts | 2 +- src/slang-nodes/AdditiveExpression.ts | 2 +- src/slang-nodes/AddressType.ts | 2 +- src/slang-nodes/AndExpression.ts | 2 +- src/slang-nodes/ArgumentsDeclaration.ts | 2 +- src/slang-nodes/ArrayExpression.ts | 2 +- src/slang-nodes/ArrayTypeName.ts | 2 +- src/slang-nodes/ArrayValues.ts | 2 +- src/slang-nodes/AssemblyFlags.ts | 2 +- src/slang-nodes/AssemblyFlagsDeclaration.ts | 2 +- src/slang-nodes/AssemblyStatement.ts | 2 +- src/slang-nodes/AssignmentExpression.ts | 2 +- src/slang-nodes/BitwiseAndExpression.ts | 2 +- src/slang-nodes/BitwiseOrExpression.ts | 2 +- src/slang-nodes/BitwiseXorExpression.ts | 2 +- src/slang-nodes/Block.ts | 2 +- src/slang-nodes/BreakStatement.ts | 2 +- src/slang-nodes/CallOptions.ts | 2 +- src/slang-nodes/CallOptionsExpression.ts | 2 +- src/slang-nodes/CatchClause.ts | 2 +- src/slang-nodes/CatchClauseError.ts | 2 +- src/slang-nodes/CatchClauses.ts | 2 +- src/slang-nodes/ComparisonExpression.ts | 2 +- src/slang-nodes/ConditionalExpression.ts | 2 +- src/slang-nodes/ConstantDefinition.ts | 2 +- src/slang-nodes/ConstructorAttribute.ts | 2 +- src/slang-nodes/ConstructorAttributes.ts | 2 +- src/slang-nodes/ConstructorDefinition.ts | 2 +- src/slang-nodes/ContinueStatement.ts | 2 +- src/slang-nodes/ContractDefinition.ts | 6 +-- src/slang-nodes/ContractMember.ts | 2 +- src/slang-nodes/ContractMembers.ts | 2 +- src/slang-nodes/DecimalNumberExpression.ts | 2 +- src/slang-nodes/DoWhileStatement.ts | 2 +- src/slang-nodes/ElementaryType.ts | 2 +- src/slang-nodes/ElseBranch.ts | 7 ++- src/slang-nodes/EmitStatement.ts | 2 +- src/slang-nodes/EnumDefinition.ts | 2 +- src/slang-nodes/EnumMembers.ts | 2 +- src/slang-nodes/EqualityExpression.ts | 2 +- src/slang-nodes/ErrorDefinition.ts | 2 +- src/slang-nodes/ErrorParameter.ts | 2 +- src/slang-nodes/ErrorParameters.ts | 2 +- src/slang-nodes/ErrorParametersDeclaration.ts | 2 +- src/slang-nodes/EventDefinition.ts | 2 +- src/slang-nodes/EventParameter.ts | 2 +- src/slang-nodes/EventParameters.ts | 2 +- src/slang-nodes/EventParametersDeclaration.ts | 2 +- src/slang-nodes/ExperimentalFeature.ts | 2 +- src/slang-nodes/ExperimentalPragma.ts | 2 +- src/slang-nodes/ExponentiationExpression.ts | 2 +- src/slang-nodes/Expression.ts | 2 +- src/slang-nodes/ExpressionStatement.ts | 2 +- src/slang-nodes/FallbackFunctionAttribute.ts | 2 +- src/slang-nodes/FallbackFunctionAttributes.ts | 2 +- src/slang-nodes/FallbackFunctionDefinition.ts | 6 +-- src/slang-nodes/ForStatement.ts | 2 +- src/slang-nodes/ForStatementCondition.ts | 2 +- src/slang-nodes/ForStatementInitialization.ts | 2 +- src/slang-nodes/FunctionAttribute.ts | 2 +- src/slang-nodes/FunctionAttributes.ts | 2 +- src/slang-nodes/FunctionBody.ts | 2 +- src/slang-nodes/FunctionCallExpression.ts | 2 +- src/slang-nodes/FunctionDefinition.ts | 6 +-- src/slang-nodes/FunctionName.ts | 2 +- src/slang-nodes/FunctionType.ts | 2 +- src/slang-nodes/FunctionTypeAttribute.ts | 2 +- src/slang-nodes/FunctionTypeAttributes.ts | 2 +- src/slang-nodes/HexNumberExpression.ts | 2 +- src/slang-nodes/HexStringLiteral.ts | 2 +- src/slang-nodes/HexStringLiterals.ts | 2 +- src/slang-nodes/IdentifierPath.ts | 2 +- src/slang-nodes/IfStatement.ts | 2 +- src/slang-nodes/ImportAlias.ts | 2 +- src/slang-nodes/ImportClause.ts | 2 +- src/slang-nodes/ImportDeconstruction.ts | 2 +- src/slang-nodes/ImportDeconstructionSymbol.ts | 2 +- .../ImportDeconstructionSymbols.ts | 2 +- src/slang-nodes/ImportDirective.ts | 2 +- src/slang-nodes/IndexAccessEnd.ts | 2 +- src/slang-nodes/IndexAccessExpression.ts | 2 +- src/slang-nodes/InheritanceSpecifier.ts | 2 +- src/slang-nodes/InheritanceType.ts | 2 +- src/slang-nodes/InheritanceTypes.ts | 2 +- src/slang-nodes/InterfaceDefinition.ts | 2 +- src/slang-nodes/InterfaceMembers.ts | 2 +- src/slang-nodes/LibraryDefinition.ts | 2 +- src/slang-nodes/LibraryMembers.ts | 2 +- src/slang-nodes/MappingKey.ts | 2 +- src/slang-nodes/MappingKeyType.ts | 2 +- src/slang-nodes/MappingType.ts | 2 +- src/slang-nodes/MappingValue.ts | 2 +- src/slang-nodes/MemberAccess.ts | 2 +- src/slang-nodes/MemberAccessExpression.ts | 8 +-- src/slang-nodes/ModifierAttribute.ts | 2 +- src/slang-nodes/ModifierAttributes.ts | 2 +- src/slang-nodes/ModifierDefinition.ts | 2 +- src/slang-nodes/ModifierInvocation.ts | 2 +- src/slang-nodes/MultiplicativeExpression.ts | 2 +- src/slang-nodes/NamedArgument.ts | 2 +- src/slang-nodes/NamedArgumentGroup.ts | 2 +- src/slang-nodes/NamedArguments.ts | 2 +- src/slang-nodes/NamedArgumentsDeclaration.ts | 2 +- src/slang-nodes/NamedImport.ts | 2 +- src/slang-nodes/NewExpression.ts | 2 +- src/slang-nodes/NumberUnit.ts | 2 +- src/slang-nodes/OrExpression.ts | 2 +- src/slang-nodes/OverridePaths.ts | 2 +- src/slang-nodes/OverridePathsDeclaration.ts | 2 +- src/slang-nodes/OverrideSpecifier.ts | 2 +- src/slang-nodes/Parameter.ts | 2 +- src/slang-nodes/Parameters.ts | 2 +- src/slang-nodes/ParametersDeclaration.ts | 2 +- src/slang-nodes/PathImport.ts | 2 +- src/slang-nodes/PositionalArguments.ts | 2 +- .../PositionalArgumentsDeclaration.ts | 2 +- src/slang-nodes/PostfixExpression.ts | 2 +- src/slang-nodes/Pragma.ts | 2 +- src/slang-nodes/PragmaDirective.ts | 2 +- src/slang-nodes/PrefixExpression.ts | 2 +- src/slang-nodes/ReceiveFunctionAttribute.ts | 2 +- src/slang-nodes/ReceiveFunctionAttributes.ts | 2 +- src/slang-nodes/ReceiveFunctionDefinition.ts | 6 +-- src/slang-nodes/ReturnStatement.ts | 2 +- src/slang-nodes/ReturnsDeclaration.ts | 2 +- src/slang-nodes/RevertStatement.ts | 2 +- src/slang-nodes/ShiftExpression.ts | 2 +- src/slang-nodes/SourceUnit.ts | 2 +- src/slang-nodes/SourceUnitMember.ts | 2 +- src/slang-nodes/SourceUnitMembers.ts | 2 +- src/slang-nodes/StateVariableAttribute.ts | 2 +- src/slang-nodes/StateVariableAttributes.ts | 2 +- src/slang-nodes/StateVariableDefinition.ts | 2 +- .../StateVariableDefinitionValue.ts | 2 +- src/slang-nodes/Statement.ts | 2 +- src/slang-nodes/Statements.ts | 2 +- src/slang-nodes/StorageLocation.ts | 2 +- src/slang-nodes/StringExpression.ts | 2 +- src/slang-nodes/StringLiteral.ts | 2 +- src/slang-nodes/StringLiterals.ts | 2 +- src/slang-nodes/StructDefinition.ts | 2 +- src/slang-nodes/StructMember.ts | 2 +- src/slang-nodes/StructMembers.ts | 2 +- src/slang-nodes/ThrowStatement.ts | 2 +- src/slang-nodes/TryStatement.ts | 2 +- src/slang-nodes/TupleDeconstructionElement.ts | 2 +- .../TupleDeconstructionElements.ts | 2 +- .../TupleDeconstructionStatement.ts | 2 +- src/slang-nodes/TupleExpression.ts | 2 +- src/slang-nodes/TupleMember.ts | 2 +- src/slang-nodes/TupleValue.ts | 2 +- src/slang-nodes/TupleValues.ts | 2 +- src/slang-nodes/TypeExpression.ts | 2 +- src/slang-nodes/TypeName.ts | 2 +- src/slang-nodes/TypedTupleMember.ts | 2 +- src/slang-nodes/UncheckedBlock.ts | 2 +- src/slang-nodes/UnicodeStringLiteral.ts | 2 +- src/slang-nodes/UnicodeStringLiterals.ts | 2 +- src/slang-nodes/UnnamedFunctionAttribute.ts | 2 +- src/slang-nodes/UnnamedFunctionAttributes.ts | 2 +- src/slang-nodes/UnnamedFunctionDefinition.ts | 6 +-- src/slang-nodes/UntypedTupleMember.ts | 2 +- .../UserDefinedValueTypeDefinition.ts | 2 +- src/slang-nodes/UsingAlias.ts | 2 +- src/slang-nodes/UsingClause.ts | 2 +- src/slang-nodes/UsingDeconstruction.ts | 2 +- src/slang-nodes/UsingDeconstructionSymbol.ts | 2 +- src/slang-nodes/UsingDeconstructionSymbols.ts | 2 +- src/slang-nodes/UsingDirective.ts | 2 +- src/slang-nodes/UsingOperator.ts | 2 +- src/slang-nodes/UsingTarget.ts | 2 +- .../VariableDeclarationStatement.ts | 2 +- src/slang-nodes/VariableDeclarationType.ts | 2 +- src/slang-nodes/VariableDeclarationValue.ts | 2 +- src/slang-nodes/VersionComparator.ts | 2 +- src/slang-nodes/VersionExpression.ts | 2 +- src/slang-nodes/VersionExpressionSet.ts | 2 +- src/slang-nodes/VersionExpressionSets.ts | 2 +- src/slang-nodes/VersionPragma.ts | 2 +- src/slang-nodes/VersionRange.ts | 4 +- src/slang-nodes/VersionSpecifiers.ts | 2 +- src/slang-nodes/WhileStatement.ts | 2 +- src/slang-nodes/YulArguments.ts | 2 +- src/slang-nodes/YulAssignmentOperator.ts | 2 +- src/slang-nodes/YulBlock.ts | 2 +- src/slang-nodes/YulBreakStatement.ts | 2 +- src/slang-nodes/YulBuiltInFunction.ts | 2 +- src/slang-nodes/YulColonEqual.ts | 2 +- src/slang-nodes/YulContinueStatement.ts | 2 +- src/slang-nodes/YulDefaultCase.ts | 2 +- src/slang-nodes/YulExpression.ts | 2 +- src/slang-nodes/YulForStatement.ts | 2 +- src/slang-nodes/YulFunctionCallExpression.ts | 2 +- src/slang-nodes/YulFunctionDefinition.ts | 2 +- src/slang-nodes/YulIfStatement.ts | 2 +- src/slang-nodes/YulLabel.ts | 2 +- src/slang-nodes/YulLeaveStatement.ts | 2 +- src/slang-nodes/YulLiteral.ts | 2 +- src/slang-nodes/YulParameters.ts | 2 +- src/slang-nodes/YulParametersDeclaration.ts | 2 +- src/slang-nodes/YulPath.ts | 2 +- src/slang-nodes/YulPathComponent.ts | 2 +- src/slang-nodes/YulPaths.ts | 2 +- src/slang-nodes/YulReturnVariables.ts | 2 +- src/slang-nodes/YulReturnsDeclaration.ts | 2 +- .../YulStackAssignmentStatement.ts | 2 +- src/slang-nodes/YulStatement.ts | 2 +- src/slang-nodes/YulStatements.ts | 2 +- src/slang-nodes/YulSwitchCase.ts | 2 +- src/slang-nodes/YulSwitchCases.ts | 2 +- src/slang-nodes/YulSwitchStatement.ts | 2 +- src/slang-nodes/YulValueCase.ts | 2 +- .../YulVariableAssignmentStatement.ts | 2 +- .../YulVariableDeclarationStatement.ts | 2 +- .../YulVariableDeclarationValue.ts | 2 +- src/slang-printers/print-binary-operation.ts | 25 +++++---- src/slang-printers/print-comments.ts | 4 +- .../print-comparison-operation.ts | 11 ++-- src/slang-printers/print-logical-operation.ts | 11 ++-- src/slang-utils/backward-compatibility.ts | 8 --- src/slang-utils/create-hug-function.ts | 4 +- src/slang-utils/create-kind-check-function.ts | 3 +- src/slang-utils/is-binary-operation.ts | 29 ++++++----- src/slang-utils/is-comment.ts | 26 ++++++---- .../{get-offsets.ts => metadata.ts} | 52 ++++++++++--------- src/slangPrinter.ts | 11 ++-- src/types.d.ts | 11 ++-- 227 files changed, 331 insertions(+), 327 deletions(-) rename src/slang-utils/{get-offsets.ts => metadata.ts} (74%) diff --git a/src/slang-nodes/ABICoderPragma.ts b/src/slang-nodes/ABICoderPragma.ts index b2bef6398..5e728294d 100644 --- a/src/slang-nodes/ABICoderPragma.ts +++ b/src/slang-nodes/ABICoderPragma.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata } from '../slang-utils/metadata.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { Doc } from 'prettier'; diff --git a/src/slang-nodes/AdditiveExpression.ts b/src/slang-nodes/AdditiveExpression.ts index 0443f2810..fe52262ce 100644 --- a/src/slang-nodes/AdditiveExpression.ts +++ b/src/slang-nodes/AdditiveExpression.ts @@ -1,7 +1,7 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; import { createHugFunction } from '../slang-utils/create-hug-function.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/AddressType.ts b/src/slang-nodes/AddressType.ts index 5640c5125..7ca005078 100644 --- a/src/slang-nodes/AddressType.ts +++ b/src/slang-nodes/AddressType.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata } from '../slang-utils/metadata.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { Doc } from 'prettier'; diff --git a/src/slang-nodes/AndExpression.ts b/src/slang-nodes/AndExpression.ts index dc9b2ef1e..7f2bd6593 100644 --- a/src/slang-nodes/AndExpression.ts +++ b/src/slang-nodes/AndExpression.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printLogicalOperation } from '../slang-printers/print-logical-operation.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/ArgumentsDeclaration.ts b/src/slang-nodes/ArgumentsDeclaration.ts index 1b5df570d..94743a357 100644 --- a/src/slang-nodes/ArgumentsDeclaration.ts +++ b/src/slang-nodes/ArgumentsDeclaration.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { PositionalArgumentsDeclaration } from './PositionalArgumentsDeclaration.js'; import { NamedArgumentsDeclaration } from './NamedArgumentsDeclaration.js'; diff --git a/src/slang-nodes/ArrayExpression.ts b/src/slang-nodes/ArrayExpression.ts index d86c20528..8c2f901db 100644 --- a/src/slang-nodes/ArrayExpression.ts +++ b/src/slang-nodes/ArrayExpression.ts @@ -1,6 +1,6 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ArrayValues } from './ArrayValues.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/ArrayTypeName.ts b/src/slang-nodes/ArrayTypeName.ts index ab0f61473..69568fc69 100644 --- a/src/slang-nodes/ArrayTypeName.ts +++ b/src/slang-nodes/ArrayTypeName.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TypeName } from './TypeName.js'; import { Expression } from './Expression.js'; diff --git a/src/slang-nodes/ArrayValues.ts b/src/slang-nodes/ArrayValues.ts index 496fec72c..cea5e6561 100644 --- a/src/slang-nodes/ArrayValues.ts +++ b/src/slang-nodes/ArrayValues.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../slang-printers/print-separated-list.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/AssemblyFlags.ts b/src/slang-nodes/AssemblyFlags.ts index 56daa21ba..0445bed74 100644 --- a/src/slang-nodes/AssemblyFlags.ts +++ b/src/slang-nodes/AssemblyFlags.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../slang-printers/print-separated-list.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { StringLiteral } from './StringLiteral.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/AssemblyFlagsDeclaration.ts b/src/slang-nodes/AssemblyFlagsDeclaration.ts index 80359c364..bee431d61 100644 --- a/src/slang-nodes/AssemblyFlagsDeclaration.ts +++ b/src/slang-nodes/AssemblyFlagsDeclaration.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { AssemblyFlags } from './AssemblyFlags.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/AssemblyStatement.ts b/src/slang-nodes/AssemblyStatement.ts index c7644695f..dd8e1f14f 100644 --- a/src/slang-nodes/AssemblyStatement.ts +++ b/src/slang-nodes/AssemblyStatement.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { StringLiteral } from './StringLiteral.js'; import { AssemblyFlagsDeclaration } from './AssemblyFlagsDeclaration.js'; import { YulBlock } from './YulBlock.js'; diff --git a/src/slang-nodes/AssignmentExpression.ts b/src/slang-nodes/AssignmentExpression.ts index 17fd54104..c5827d1e1 100644 --- a/src/slang-nodes/AssignmentExpression.ts +++ b/src/slang-nodes/AssignmentExpression.ts @@ -1,7 +1,7 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/BitwiseAndExpression.ts b/src/slang-nodes/BitwiseAndExpression.ts index 5ccba5bd8..0d0b9296c 100644 --- a/src/slang-nodes/BitwiseAndExpression.ts +++ b/src/slang-nodes/BitwiseAndExpression.ts @@ -1,7 +1,7 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; import { createHugFunction } from '../slang-utils/create-hug-function.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/BitwiseOrExpression.ts b/src/slang-nodes/BitwiseOrExpression.ts index 4faa4cf85..cb4d92bbe 100644 --- a/src/slang-nodes/BitwiseOrExpression.ts +++ b/src/slang-nodes/BitwiseOrExpression.ts @@ -1,7 +1,7 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; import { createHugFunction } from '../slang-utils/create-hug-function.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/BitwiseXorExpression.ts b/src/slang-nodes/BitwiseXorExpression.ts index 34231ee16..a25c48e4e 100644 --- a/src/slang-nodes/BitwiseXorExpression.ts +++ b/src/slang-nodes/BitwiseXorExpression.ts @@ -1,7 +1,7 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; import { createHugFunction } from '../slang-utils/create-hug-function.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/Block.ts b/src/slang-nodes/Block.ts index 48e304e91..c3624dea2 100644 --- a/src/slang-nodes/Block.ts +++ b/src/slang-nodes/Block.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Statements } from './Statements.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/BreakStatement.ts b/src/slang-nodes/BreakStatement.ts index 4d750d7a8..03369297e 100644 --- a/src/slang-nodes/BreakStatement.ts +++ b/src/slang-nodes/BreakStatement.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata } from '../slang-utils/metadata.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { Doc } from 'prettier'; diff --git a/src/slang-nodes/CallOptions.ts b/src/slang-nodes/CallOptions.ts index d2b5a63d9..ede3c57db 100644 --- a/src/slang-nodes/CallOptions.ts +++ b/src/slang-nodes/CallOptions.ts @@ -1,7 +1,7 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../slang-printers/print-separated-list.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { NamedArgument } from './NamedArgument.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/CallOptionsExpression.ts b/src/slang-nodes/CallOptionsExpression.ts index b1a877ba3..ec77d4fa6 100644 --- a/src/slang-nodes/CallOptionsExpression.ts +++ b/src/slang-nodes/CallOptionsExpression.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import { CallOptions } from './CallOptions.js'; diff --git a/src/slang-nodes/CatchClause.ts b/src/slang-nodes/CatchClause.ts index a8c018b6d..38410e6e4 100644 --- a/src/slang-nodes/CatchClause.ts +++ b/src/slang-nodes/CatchClause.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { CatchClauseError } from './CatchClauseError.js'; import { Block } from './Block.js'; diff --git a/src/slang-nodes/CatchClauseError.ts b/src/slang-nodes/CatchClauseError.ts index 844675140..6cfc45656 100644 --- a/src/slang-nodes/CatchClauseError.ts +++ b/src/slang-nodes/CatchClauseError.ts @@ -1,6 +1,6 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ParametersDeclaration } from './ParametersDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/CatchClauses.ts b/src/slang-nodes/CatchClauses.ts index 19e76209f..71c3ae068 100644 --- a/src/slang-nodes/CatchClauses.ts +++ b/src/slang-nodes/CatchClauses.ts @@ -1,6 +1,6 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { CatchClause } from './CatchClause.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/ComparisonExpression.ts b/src/slang-nodes/ComparisonExpression.ts index 86466f039..fb1252cdd 100644 --- a/src/slang-nodes/ComparisonExpression.ts +++ b/src/slang-nodes/ComparisonExpression.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printComparisonOperation } from '../slang-printers/print-comparison-operation.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/ConditionalExpression.ts b/src/slang-nodes/ConditionalExpression.ts index 9cb227fa5..4d1d8e640 100644 --- a/src/slang-nodes/ConditionalExpression.ts +++ b/src/slang-nodes/ConditionalExpression.ts @@ -2,7 +2,7 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedItem } from '../slang-printers/print-separated-item.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/ConstantDefinition.ts b/src/slang-nodes/ConstantDefinition.ts index 411e0551c..0556b9088 100644 --- a/src/slang-nodes/ConstantDefinition.ts +++ b/src/slang-nodes/ConstantDefinition.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TypeName } from './TypeName.js'; import { Expression } from './Expression.js'; diff --git a/src/slang-nodes/ConstructorAttribute.ts b/src/slang-nodes/ConstructorAttribute.ts index 87b349d62..f0dfe7c22 100644 --- a/src/slang-nodes/ConstructorAttribute.ts +++ b/src/slang-nodes/ConstructorAttribute.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ModifierInvocation } from './ModifierInvocation.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/ConstructorAttributes.ts b/src/slang-nodes/ConstructorAttributes.ts index 08e773564..31bde7929 100644 --- a/src/slang-nodes/ConstructorAttributes.ts +++ b/src/slang-nodes/ConstructorAttributes.ts @@ -1,7 +1,7 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ConstructorAttribute } from './ConstructorAttribute.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/ConstructorDefinition.ts b/src/slang-nodes/ConstructorDefinition.ts index 5235e74f9..4d78b4276 100644 --- a/src/slang-nodes/ConstructorDefinition.ts +++ b/src/slang-nodes/ConstructorDefinition.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printFunction } from '../slang-printers/print-function.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ParametersDeclaration } from './ParametersDeclaration.js'; import { ConstructorAttributes } from './ConstructorAttributes.js'; import { Block } from './Block.js'; diff --git a/src/slang-nodes/ContinueStatement.ts b/src/slang-nodes/ContinueStatement.ts index 66b831055..daba6ceba 100644 --- a/src/slang-nodes/ContinueStatement.ts +++ b/src/slang-nodes/ContinueStatement.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata } from '../slang-utils/metadata.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { Doc } from 'prettier'; diff --git a/src/slang-nodes/ContractDefinition.ts b/src/slang-nodes/ContractDefinition.ts index cc6aff506..d4d26b260 100644 --- a/src/slang-nodes/ContractDefinition.ts +++ b/src/slang-nodes/ContractDefinition.ts @@ -2,7 +2,7 @@ import { doc } from 'prettier'; import coerce from 'semver/functions/coerce.js'; import satisfies from 'semver/functions/satisfies.js'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { InheritanceSpecifier } from './InheritanceSpecifier.js'; import { ContractMembers } from './ContractMembers.js'; @@ -70,14 +70,14 @@ export class ContractDefinition implements SlangNode { // the same name as the contract. const compiler = coerce(options.compiler); if (compiler && !satisfies(compiler, '>=0.5.0')) { - this.members.items.forEach((member) => { + for (const member of this.members.items) { if ( member.variant.kind === NonterminalKind.FunctionDefinition && member.variant.name.variant !== this.name ) { member.variant.cleanModifierInvocationArguments(); } - }); + } } } diff --git a/src/slang-nodes/ContractMember.ts b/src/slang-nodes/ContractMember.ts index 3c053a608..5cafdcbcd 100644 --- a/src/slang-nodes/ContractMember.ts +++ b/src/slang-nodes/ContractMember.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { UsingDirective } from './UsingDirective.js'; import { FunctionDefinition } from './FunctionDefinition.js'; import { ConstructorDefinition } from './ConstructorDefinition.js'; diff --git a/src/slang-nodes/ContractMembers.ts b/src/slang-nodes/ContractMembers.ts index c85455a16..6d2f315e9 100644 --- a/src/slang-nodes/ContractMembers.ts +++ b/src/slang-nodes/ContractMembers.ts @@ -3,7 +3,7 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedItem } from '../slang-printers/print-separated-item.js'; import { printComments } from '../slang-printers/print-comments.js'; import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ContractMember } from './ContractMember.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/DecimalNumberExpression.ts b/src/slang-nodes/DecimalNumberExpression.ts index 46d3df7b8..14af61d3e 100644 --- a/src/slang-nodes/DecimalNumberExpression.ts +++ b/src/slang-nodes/DecimalNumberExpression.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { NumberUnit } from './NumberUnit.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/DoWhileStatement.ts b/src/slang-nodes/DoWhileStatement.ts index 28622f92b..72f193489 100644 --- a/src/slang-nodes/DoWhileStatement.ts +++ b/src/slang-nodes/DoWhileStatement.ts @@ -1,7 +1,7 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedItem } from '../slang-printers/print-separated-item.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Statement } from './Statement.js'; import { Expression } from './Expression.js'; diff --git a/src/slang-nodes/ElementaryType.ts b/src/slang-nodes/ElementaryType.ts index 929bcf060..f24b5d84b 100644 --- a/src/slang-nodes/ElementaryType.ts +++ b/src/slang-nodes/ElementaryType.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { AddressType } from './AddressType.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/ElseBranch.ts b/src/slang-nodes/ElseBranch.ts index 68139eba4..57ee23a75 100644 --- a/src/slang-nodes/ElseBranch.ts +++ b/src/slang-nodes/ElseBranch.ts @@ -1,7 +1,7 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Statement } from './Statement.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; @@ -10,7 +10,10 @@ import type { SlangNode } from '../types.js'; const { group, indent, line } = doc.builders; -const isIfStatementOrBlock = createKindCheckFunction(['Block', 'IfStatement']); +const isIfStatementOrBlock = createKindCheckFunction([ + NonterminalKind.Block, + NonterminalKind.IfStatement +]); export class ElseBranch implements SlangNode { readonly kind = NonterminalKind.ElseBranch; diff --git a/src/slang-nodes/EmitStatement.ts b/src/slang-nodes/EmitStatement.ts index ae7c3fac6..4253e3f35 100644 --- a/src/slang-nodes/EmitStatement.ts +++ b/src/slang-nodes/EmitStatement.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { IdentifierPath } from './IdentifierPath.js'; import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; diff --git a/src/slang-nodes/EnumDefinition.ts b/src/slang-nodes/EnumDefinition.ts index 390833fd3..a9adc21ed 100644 --- a/src/slang-nodes/EnumDefinition.ts +++ b/src/slang-nodes/EnumDefinition.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { EnumMembers } from './EnumMembers.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/EnumMembers.ts b/src/slang-nodes/EnumMembers.ts index bbbb96b91..59c59175b 100644 --- a/src/slang-nodes/EnumMembers.ts +++ b/src/slang-nodes/EnumMembers.ts @@ -1,7 +1,7 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../slang-printers/print-separated-list.js'; -import { getNodeMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata } from '../slang-utils/metadata.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { Doc } from 'prettier'; diff --git a/src/slang-nodes/EqualityExpression.ts b/src/slang-nodes/EqualityExpression.ts index 6d05a3a4d..0ebb5433e 100644 --- a/src/slang-nodes/EqualityExpression.ts +++ b/src/slang-nodes/EqualityExpression.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printComparisonOperation } from '../slang-printers/print-comparison-operation.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/ErrorDefinition.ts b/src/slang-nodes/ErrorDefinition.ts index 0c6a625ce..92e6bff2c 100644 --- a/src/slang-nodes/ErrorDefinition.ts +++ b/src/slang-nodes/ErrorDefinition.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ErrorParametersDeclaration } from './ErrorParametersDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/ErrorParameter.ts b/src/slang-nodes/ErrorParameter.ts index 49bf46ab4..089c98133 100644 --- a/src/slang-nodes/ErrorParameter.ts +++ b/src/slang-nodes/ErrorParameter.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TypeName } from './TypeName.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/ErrorParameters.ts b/src/slang-nodes/ErrorParameters.ts index 47a206e33..1c8666e97 100644 --- a/src/slang-nodes/ErrorParameters.ts +++ b/src/slang-nodes/ErrorParameters.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../slang-printers/print-separated-list.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ErrorParameter } from './ErrorParameter.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/ErrorParametersDeclaration.ts b/src/slang-nodes/ErrorParametersDeclaration.ts index 085f05a96..248ab8dd1 100644 --- a/src/slang-nodes/ErrorParametersDeclaration.ts +++ b/src/slang-nodes/ErrorParametersDeclaration.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ErrorParameters } from './ErrorParameters.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/EventDefinition.ts b/src/slang-nodes/EventDefinition.ts index 439d1cb13..77ee8e962 100644 --- a/src/slang-nodes/EventDefinition.ts +++ b/src/slang-nodes/EventDefinition.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { EventParametersDeclaration } from './EventParametersDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/EventParameter.ts b/src/slang-nodes/EventParameter.ts index 4096aeef7..1a1f40ebf 100644 --- a/src/slang-nodes/EventParameter.ts +++ b/src/slang-nodes/EventParameter.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TypeName } from './TypeName.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/EventParameters.ts b/src/slang-nodes/EventParameters.ts index 105193e84..67455fb8b 100644 --- a/src/slang-nodes/EventParameters.ts +++ b/src/slang-nodes/EventParameters.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../slang-printers/print-separated-list.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { EventParameter } from './EventParameter.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/EventParametersDeclaration.ts b/src/slang-nodes/EventParametersDeclaration.ts index 9d5f148b4..e3cf1782d 100644 --- a/src/slang-nodes/EventParametersDeclaration.ts +++ b/src/slang-nodes/EventParametersDeclaration.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { EventParameters } from './EventParameters.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/ExperimentalFeature.ts b/src/slang-nodes/ExperimentalFeature.ts index d0031d85f..fe3394a96 100644 --- a/src/slang-nodes/ExperimentalFeature.ts +++ b/src/slang-nodes/ExperimentalFeature.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { StringLiteral } from './StringLiteral.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/ExperimentalPragma.ts b/src/slang-nodes/ExperimentalPragma.ts index 72019f939..9e920c234 100644 --- a/src/slang-nodes/ExperimentalPragma.ts +++ b/src/slang-nodes/ExperimentalPragma.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ExperimentalFeature } from './ExperimentalFeature.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/ExponentiationExpression.ts b/src/slang-nodes/ExponentiationExpression.ts index db3a31640..949c39fa0 100644 --- a/src/slang-nodes/ExponentiationExpression.ts +++ b/src/slang-nodes/ExponentiationExpression.ts @@ -4,7 +4,7 @@ import satisfies from 'semver/functions/satisfies.js'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { createBinaryOperationPrinter } from '../slang-printers/create-binary-operation-printer.js'; import { createHugFunction } from '../slang-utils/create-hug-function.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import { TupleExpression } from './TupleExpression.js'; import { TupleValues } from './TupleValues.js'; diff --git a/src/slang-nodes/Expression.ts b/src/slang-nodes/Expression.ts index b4354b900..d6398a645 100644 --- a/src/slang-nodes/Expression.ts +++ b/src/slang-nodes/Expression.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { AssignmentExpression } from './AssignmentExpression.js'; import { ConditionalExpression } from './ConditionalExpression.js'; import { OrExpression } from './OrExpression.js'; diff --git a/src/slang-nodes/ExpressionStatement.ts b/src/slang-nodes/ExpressionStatement.ts index 4cc452810..1c252cfa1 100644 --- a/src/slang-nodes/ExpressionStatement.ts +++ b/src/slang-nodes/ExpressionStatement.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/FallbackFunctionAttribute.ts b/src/slang-nodes/FallbackFunctionAttribute.ts index 1564275fe..6c38d1576 100644 --- a/src/slang-nodes/FallbackFunctionAttribute.ts +++ b/src/slang-nodes/FallbackFunctionAttribute.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ModifierInvocation } from './ModifierInvocation.js'; import { OverrideSpecifier } from './OverrideSpecifier.js'; diff --git a/src/slang-nodes/FallbackFunctionAttributes.ts b/src/slang-nodes/FallbackFunctionAttributes.ts index 76c9f4268..f6b80bb00 100644 --- a/src/slang-nodes/FallbackFunctionAttributes.ts +++ b/src/slang-nodes/FallbackFunctionAttributes.ts @@ -1,7 +1,7 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { FallbackFunctionAttribute } from './FallbackFunctionAttribute.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/FallbackFunctionDefinition.ts b/src/slang-nodes/FallbackFunctionDefinition.ts index 76db3ee3d..742b2dbfb 100644 --- a/src/slang-nodes/FallbackFunctionDefinition.ts +++ b/src/slang-nodes/FallbackFunctionDefinition.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printFunction } from '../slang-printers/print-function.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ParametersDeclaration } from './ParametersDeclaration.js'; import { FallbackFunctionAttributes } from './FallbackFunctionAttributes.js'; import { ReturnsDeclaration } from './ReturnsDeclaration.js'; @@ -67,14 +67,14 @@ export class FallbackFunctionDefinition implements SlangNode { } cleanModifierInvocationArguments(): void { - this.attributes.items.forEach((attribute) => { + for (const attribute of this.attributes.items) { if ( typeof attribute.variant !== 'string' && attribute.variant.kind === NonterminalKind.ModifierInvocation ) { attribute.variant.cleanModifierInvocationArguments(); } - }); + } } print(path: AstPath, print: (path: AstPath) => Doc): Doc { diff --git a/src/slang-nodes/ForStatement.ts b/src/slang-nodes/ForStatement.ts index d9a785a36..5591359f5 100644 --- a/src/slang-nodes/ForStatement.ts +++ b/src/slang-nodes/ForStatement.ts @@ -1,7 +1,7 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../slang-printers/print-separated-list.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ForStatementInitialization } from './ForStatementInitialization.js'; import { ForStatementCondition } from './ForStatementCondition.js'; import { Expression } from './Expression.js'; diff --git a/src/slang-nodes/ForStatementCondition.ts b/src/slang-nodes/ForStatementCondition.ts index 8e35c6710..d783cc4c5 100644 --- a/src/slang-nodes/ForStatementCondition.ts +++ b/src/slang-nodes/ForStatementCondition.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ExpressionStatement } from './ExpressionStatement.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/ForStatementInitialization.ts b/src/slang-nodes/ForStatementInitialization.ts index 898782a92..996b5b71b 100644 --- a/src/slang-nodes/ForStatementInitialization.ts +++ b/src/slang-nodes/ForStatementInitialization.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ExpressionStatement } from './ExpressionStatement.js'; import { VariableDeclarationStatement } from './VariableDeclarationStatement.js'; import { TupleDeconstructionStatement } from './TupleDeconstructionStatement.js'; diff --git a/src/slang-nodes/FunctionAttribute.ts b/src/slang-nodes/FunctionAttribute.ts index effd04f68..f0a0ada00 100644 --- a/src/slang-nodes/FunctionAttribute.ts +++ b/src/slang-nodes/FunctionAttribute.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ModifierInvocation } from './ModifierInvocation.js'; import { OverrideSpecifier } from './OverrideSpecifier.js'; diff --git a/src/slang-nodes/FunctionAttributes.ts b/src/slang-nodes/FunctionAttributes.ts index 3dc786602..8beecf94c 100644 --- a/src/slang-nodes/FunctionAttributes.ts +++ b/src/slang-nodes/FunctionAttributes.ts @@ -1,7 +1,7 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { FunctionAttribute } from './FunctionAttribute.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/FunctionBody.ts b/src/slang-nodes/FunctionBody.ts index a678bf15e..606a9a472 100644 --- a/src/slang-nodes/FunctionBody.ts +++ b/src/slang-nodes/FunctionBody.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Block } from './Block.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/FunctionCallExpression.ts b/src/slang-nodes/FunctionCallExpression.ts index f2698a2d7..3ce450d7d 100644 --- a/src/slang-nodes/FunctionCallExpression.ts +++ b/src/slang-nodes/FunctionCallExpression.ts @@ -1,7 +1,7 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { isLabel } from '../slang-utils/is-label.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; diff --git a/src/slang-nodes/FunctionDefinition.ts b/src/slang-nodes/FunctionDefinition.ts index 950f4aa71..d36e757bc 100644 --- a/src/slang-nodes/FunctionDefinition.ts +++ b/src/slang-nodes/FunctionDefinition.ts @@ -2,7 +2,7 @@ import coerce from 'semver/functions/coerce.js'; import satisfies from 'semver/functions/satisfies.js'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printFunction } from '../slang-printers/print-function.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { FunctionName } from './FunctionName.js'; import { ParametersDeclaration } from './ParametersDeclaration.js'; import { FunctionAttributes } from './FunctionAttributes.js'; @@ -79,14 +79,14 @@ export class FunctionDefinition implements SlangNode { } cleanModifierInvocationArguments(): void { - this.attributes.items.forEach((attribute) => { + for (const attribute of this.attributes.items) { if ( typeof attribute.variant !== 'string' && attribute.variant.kind === NonterminalKind.ModifierInvocation ) { attribute.variant.cleanModifierInvocationArguments(); } - }); + } } print(path: AstPath, print: (path: AstPath) => Doc): Doc { diff --git a/src/slang-nodes/FunctionName.ts b/src/slang-nodes/FunctionName.ts index 4f2712287..e7b82da40 100644 --- a/src/slang-nodes/FunctionName.ts +++ b/src/slang-nodes/FunctionName.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata } from '../slang-utils/metadata.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { Doc } from 'prettier'; diff --git a/src/slang-nodes/FunctionType.ts b/src/slang-nodes/FunctionType.ts index 18caeeab3..cac1ef941 100644 --- a/src/slang-nodes/FunctionType.ts +++ b/src/slang-nodes/FunctionType.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printFunction } from '../slang-printers/print-function.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ParametersDeclaration } from './ParametersDeclaration.js'; import { FunctionTypeAttributes } from './FunctionTypeAttributes.js'; import { ReturnsDeclaration } from './ReturnsDeclaration.js'; diff --git a/src/slang-nodes/FunctionTypeAttribute.ts b/src/slang-nodes/FunctionTypeAttribute.ts index 3daf8190e..0b57ce7dc 100644 --- a/src/slang-nodes/FunctionTypeAttribute.ts +++ b/src/slang-nodes/FunctionTypeAttribute.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata } from '../slang-utils/metadata.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { Doc } from 'prettier'; diff --git a/src/slang-nodes/FunctionTypeAttributes.ts b/src/slang-nodes/FunctionTypeAttributes.ts index 0148b2c76..04978010a 100644 --- a/src/slang-nodes/FunctionTypeAttributes.ts +++ b/src/slang-nodes/FunctionTypeAttributes.ts @@ -1,7 +1,7 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { FunctionTypeAttribute } from './FunctionTypeAttribute.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/HexNumberExpression.ts b/src/slang-nodes/HexNumberExpression.ts index 5a2edc8ed..3ec9f36bc 100644 --- a/src/slang-nodes/HexNumberExpression.ts +++ b/src/slang-nodes/HexNumberExpression.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { NumberUnit } from './NumberUnit.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/HexStringLiteral.ts b/src/slang-nodes/HexStringLiteral.ts index a3baa7a7a..d59234ffe 100644 --- a/src/slang-nodes/HexStringLiteral.ts +++ b/src/slang-nodes/HexStringLiteral.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printString } from '../slang-printers/print-string.js'; -import { getNodeMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata } from '../slang-utils/metadata.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { Doc, ParserOptions } from 'prettier'; diff --git a/src/slang-nodes/HexStringLiterals.ts b/src/slang-nodes/HexStringLiterals.ts index d908ed385..561c7649f 100644 --- a/src/slang-nodes/HexStringLiterals.ts +++ b/src/slang-nodes/HexStringLiterals.ts @@ -1,6 +1,6 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { HexStringLiteral } from './HexStringLiteral.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/IdentifierPath.ts b/src/slang-nodes/IdentifierPath.ts index a971d2565..45cc18544 100644 --- a/src/slang-nodes/IdentifierPath.ts +++ b/src/slang-nodes/IdentifierPath.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata } from '../slang-utils/metadata.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { Doc } from 'prettier'; diff --git a/src/slang-nodes/IfStatement.ts b/src/slang-nodes/IfStatement.ts index 5262c8eb5..0cc55f33b 100644 --- a/src/slang-nodes/IfStatement.ts +++ b/src/slang-nodes/IfStatement.ts @@ -1,7 +1,7 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedItem } from '../slang-printers/print-separated-item.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import { Statement } from './Statement.js'; import { ElseBranch } from './ElseBranch.js'; diff --git a/src/slang-nodes/ImportAlias.ts b/src/slang-nodes/ImportAlias.ts index ff74c9b0f..43ae375af 100644 --- a/src/slang-nodes/ImportAlias.ts +++ b/src/slang-nodes/ImportAlias.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata } from '../slang-utils/metadata.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { Doc } from 'prettier'; diff --git a/src/slang-nodes/ImportClause.ts b/src/slang-nodes/ImportClause.ts index 5f22dc0c6..b697524c5 100644 --- a/src/slang-nodes/ImportClause.ts +++ b/src/slang-nodes/ImportClause.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { PathImport } from './PathImport.js'; import { NamedImport } from './NamedImport.js'; import { ImportDeconstruction } from './ImportDeconstruction.js'; diff --git a/src/slang-nodes/ImportDeconstruction.ts b/src/slang-nodes/ImportDeconstruction.ts index 5ab9e482f..0ecef95fe 100644 --- a/src/slang-nodes/ImportDeconstruction.ts +++ b/src/slang-nodes/ImportDeconstruction.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ImportDeconstructionSymbols } from './ImportDeconstructionSymbols.js'; import { StringLiteral } from './StringLiteral.js'; diff --git a/src/slang-nodes/ImportDeconstructionSymbol.ts b/src/slang-nodes/ImportDeconstructionSymbol.ts index 8ffae8131..9f88426f4 100644 --- a/src/slang-nodes/ImportDeconstructionSymbol.ts +++ b/src/slang-nodes/ImportDeconstructionSymbol.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ImportAlias } from './ImportAlias.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/ImportDeconstructionSymbols.ts b/src/slang-nodes/ImportDeconstructionSymbols.ts index 85d12b4cf..82ecd1951 100644 --- a/src/slang-nodes/ImportDeconstructionSymbols.ts +++ b/src/slang-nodes/ImportDeconstructionSymbols.ts @@ -3,7 +3,7 @@ import coerce from 'semver/functions/coerce.js'; import satisfies from 'semver/functions/satisfies.js'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../slang-printers/print-separated-list.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ImportDeconstructionSymbol } from './ImportDeconstructionSymbol.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/ImportDirective.ts b/src/slang-nodes/ImportDirective.ts index d2c7c2538..7c16df598 100644 --- a/src/slang-nodes/ImportDirective.ts +++ b/src/slang-nodes/ImportDirective.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ImportClause } from './ImportClause.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/IndexAccessEnd.ts b/src/slang-nodes/IndexAccessEnd.ts index 9ac9bcea0..a94f49f62 100644 --- a/src/slang-nodes/IndexAccessEnd.ts +++ b/src/slang-nodes/IndexAccessEnd.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/IndexAccessExpression.ts b/src/slang-nodes/IndexAccessExpression.ts index 0463d88d0..b59f41df6 100644 --- a/src/slang-nodes/IndexAccessExpression.ts +++ b/src/slang-nodes/IndexAccessExpression.ts @@ -1,7 +1,7 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { isLabel } from '../slang-utils/is-label.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import { IndexAccessEnd } from './IndexAccessEnd.js'; diff --git a/src/slang-nodes/InheritanceSpecifier.ts b/src/slang-nodes/InheritanceSpecifier.ts index 61f7fb3a0..241c06840 100644 --- a/src/slang-nodes/InheritanceSpecifier.ts +++ b/src/slang-nodes/InheritanceSpecifier.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { InheritanceTypes } from './InheritanceTypes.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/InheritanceType.ts b/src/slang-nodes/InheritanceType.ts index c1ba52b0e..e32280425 100644 --- a/src/slang-nodes/InheritanceType.ts +++ b/src/slang-nodes/InheritanceType.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { IdentifierPath } from './IdentifierPath.js'; import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; diff --git a/src/slang-nodes/InheritanceTypes.ts b/src/slang-nodes/InheritanceTypes.ts index 3b811af29..a02389703 100644 --- a/src/slang-nodes/InheritanceTypes.ts +++ b/src/slang-nodes/InheritanceTypes.ts @@ -1,7 +1,7 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../slang-printers/print-separated-list.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { InheritanceType } from './InheritanceType.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/InterfaceDefinition.ts b/src/slang-nodes/InterfaceDefinition.ts index c86b48542..feba04c5e 100644 --- a/src/slang-nodes/InterfaceDefinition.ts +++ b/src/slang-nodes/InterfaceDefinition.ts @@ -1,6 +1,6 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { InheritanceSpecifier } from './InheritanceSpecifier.js'; import { InterfaceMembers } from './InterfaceMembers.js'; diff --git a/src/slang-nodes/InterfaceMembers.ts b/src/slang-nodes/InterfaceMembers.ts index 9c42c7608..6ac73d2a0 100644 --- a/src/slang-nodes/InterfaceMembers.ts +++ b/src/slang-nodes/InterfaceMembers.ts @@ -2,7 +2,7 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedItem } from '../slang-printers/print-separated-item.js'; import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ContractMember } from './ContractMember.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/LibraryDefinition.ts b/src/slang-nodes/LibraryDefinition.ts index 24cca7d1a..6f8716492 100644 --- a/src/slang-nodes/LibraryDefinition.ts +++ b/src/slang-nodes/LibraryDefinition.ts @@ -1,6 +1,6 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { LibraryMembers } from './LibraryMembers.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/LibraryMembers.ts b/src/slang-nodes/LibraryMembers.ts index 3168dd4e3..f1c7aa171 100644 --- a/src/slang-nodes/LibraryMembers.ts +++ b/src/slang-nodes/LibraryMembers.ts @@ -2,7 +2,7 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedItem } from '../slang-printers/print-separated-item.js'; import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ContractMember } from './ContractMember.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/MappingKey.ts b/src/slang-nodes/MappingKey.ts index ba5a76182..5df8261e4 100644 --- a/src/slang-nodes/MappingKey.ts +++ b/src/slang-nodes/MappingKey.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { MappingKeyType } from './MappingKeyType.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/MappingKeyType.ts b/src/slang-nodes/MappingKeyType.ts index c21378814..ae502fbe1 100644 --- a/src/slang-nodes/MappingKeyType.ts +++ b/src/slang-nodes/MappingKeyType.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ElementaryType } from './ElementaryType.js'; import { IdentifierPath } from './IdentifierPath.js'; diff --git a/src/slang-nodes/MappingType.ts b/src/slang-nodes/MappingType.ts index ee7403d27..1aaf07138 100644 --- a/src/slang-nodes/MappingType.ts +++ b/src/slang-nodes/MappingType.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { MappingKey } from './MappingKey.js'; import { MappingValue } from './MappingValue.js'; diff --git a/src/slang-nodes/MappingValue.ts b/src/slang-nodes/MappingValue.ts index 342853e42..2d7d04ea7 100644 --- a/src/slang-nodes/MappingValue.ts +++ b/src/slang-nodes/MappingValue.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TypeName } from './TypeName.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/MemberAccess.ts b/src/slang-nodes/MemberAccess.ts index ae2534336..4023b6ff1 100644 --- a/src/slang-nodes/MemberAccess.ts +++ b/src/slang-nodes/MemberAccess.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata } from '../slang-utils/metadata.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { Doc } from 'prettier'; diff --git a/src/slang-nodes/MemberAccessExpression.ts b/src/slang-nodes/MemberAccessExpression.ts index 597e5bac4..0591d4898 100644 --- a/src/slang-nodes/MemberAccessExpression.ts +++ b/src/slang-nodes/MemberAccessExpression.ts @@ -2,7 +2,7 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { isLabel } from '../slang-utils/is-label.js'; import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import { MemberAccess } from './MemberAccess.js'; @@ -13,9 +13,9 @@ import type { AstNode, SlangNode } from '../types.js'; const { group, indent, label, softline } = doc.builders; const isChainableExpression = createKindCheckFunction([ - 'FunctionCallExpression', - 'IndexAccessExpression', - 'MemberAccessExpression' + NonterminalKind.FunctionCallExpression, + NonterminalKind.IndexAccessExpression, + NonterminalKind.MemberAccessExpression ]); function isEndOfChain(node: MemberAccessExpression, path: AstPath): boolean { diff --git a/src/slang-nodes/ModifierAttribute.ts b/src/slang-nodes/ModifierAttribute.ts index a5e46b080..fee6c7504 100644 --- a/src/slang-nodes/ModifierAttribute.ts +++ b/src/slang-nodes/ModifierAttribute.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { OverrideSpecifier } from './OverrideSpecifier.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/ModifierAttributes.ts b/src/slang-nodes/ModifierAttributes.ts index d77174e2b..86efcc59b 100644 --- a/src/slang-nodes/ModifierAttributes.ts +++ b/src/slang-nodes/ModifierAttributes.ts @@ -1,7 +1,7 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ModifierAttribute } from './ModifierAttribute.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/ModifierDefinition.ts b/src/slang-nodes/ModifierDefinition.ts index f20f4d420..a523ef137 100644 --- a/src/slang-nodes/ModifierDefinition.ts +++ b/src/slang-nodes/ModifierDefinition.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printFunction } from '../slang-printers/print-function.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ParametersDeclaration } from './ParametersDeclaration.js'; import { Parameters } from './Parameters.js'; import { ModifierAttributes } from './ModifierAttributes.js'; diff --git a/src/slang-nodes/ModifierInvocation.ts b/src/slang-nodes/ModifierInvocation.ts index 9c4876cf3..c29c3d3d4 100644 --- a/src/slang-nodes/ModifierInvocation.ts +++ b/src/slang-nodes/ModifierInvocation.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { isComment } from '../slang-utils/is-comment.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { IdentifierPath } from './IdentifierPath.js'; import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; diff --git a/src/slang-nodes/MultiplicativeExpression.ts b/src/slang-nodes/MultiplicativeExpression.ts index 8a5a332a3..a8a8e1321 100644 --- a/src/slang-nodes/MultiplicativeExpression.ts +++ b/src/slang-nodes/MultiplicativeExpression.ts @@ -1,7 +1,7 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; import { createHugFunction } from '../slang-utils/create-hug-function.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/NamedArgument.ts b/src/slang-nodes/NamedArgument.ts index f64e34db1..7fe28e2e0 100644 --- a/src/slang-nodes/NamedArgument.ts +++ b/src/slang-nodes/NamedArgument.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/NamedArgumentGroup.ts b/src/slang-nodes/NamedArgumentGroup.ts index d9cd21eb9..ec1dfe139 100644 --- a/src/slang-nodes/NamedArgumentGroup.ts +++ b/src/slang-nodes/NamedArgumentGroup.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { NamedArguments } from './NamedArguments.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/NamedArguments.ts b/src/slang-nodes/NamedArguments.ts index 903f18805..9c2bf75e0 100644 --- a/src/slang-nodes/NamedArguments.ts +++ b/src/slang-nodes/NamedArguments.ts @@ -1,7 +1,7 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../slang-printers/print-separated-list.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { NamedArgument } from './NamedArgument.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/NamedArgumentsDeclaration.ts b/src/slang-nodes/NamedArgumentsDeclaration.ts index 62ccbf265..0e2934fc8 100644 --- a/src/slang-nodes/NamedArgumentsDeclaration.ts +++ b/src/slang-nodes/NamedArgumentsDeclaration.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { NamedArgumentGroup } from './NamedArgumentGroup.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/NamedImport.ts b/src/slang-nodes/NamedImport.ts index dad172e6c..b01236cdf 100644 --- a/src/slang-nodes/NamedImport.ts +++ b/src/slang-nodes/NamedImport.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ImportAlias } from './ImportAlias.js'; import { StringLiteral } from './StringLiteral.js'; diff --git a/src/slang-nodes/NewExpression.ts b/src/slang-nodes/NewExpression.ts index 0590b6067..2a1ff26e0 100644 --- a/src/slang-nodes/NewExpression.ts +++ b/src/slang-nodes/NewExpression.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TypeName } from './TypeName.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/NumberUnit.ts b/src/slang-nodes/NumberUnit.ts index 14a3e4bf5..25ce93878 100644 --- a/src/slang-nodes/NumberUnit.ts +++ b/src/slang-nodes/NumberUnit.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata } from '../slang-utils/metadata.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { Doc } from 'prettier'; diff --git a/src/slang-nodes/OrExpression.ts b/src/slang-nodes/OrExpression.ts index d4feabde3..8c8470c1b 100644 --- a/src/slang-nodes/OrExpression.ts +++ b/src/slang-nodes/OrExpression.ts @@ -1,7 +1,7 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printLogicalOperation } from '../slang-printers/print-logical-operation.js'; import { createHugFunction } from '../slang-utils/create-hug-function.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/OverridePaths.ts b/src/slang-nodes/OverridePaths.ts index e73cbdd4e..0a77b7c77 100644 --- a/src/slang-nodes/OverridePaths.ts +++ b/src/slang-nodes/OverridePaths.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { IdentifierPath } from './IdentifierPath.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/OverridePathsDeclaration.ts b/src/slang-nodes/OverridePathsDeclaration.ts index 45194b038..08cbac2f9 100644 --- a/src/slang-nodes/OverridePathsDeclaration.ts +++ b/src/slang-nodes/OverridePathsDeclaration.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { OverridePaths } from './OverridePaths.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/OverrideSpecifier.ts b/src/slang-nodes/OverrideSpecifier.ts index 67e202172..97b2d3ddb 100644 --- a/src/slang-nodes/OverrideSpecifier.ts +++ b/src/slang-nodes/OverrideSpecifier.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { OverridePathsDeclaration } from './OverridePathsDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/Parameter.ts b/src/slang-nodes/Parameter.ts index 17064b39d..94e86a56c 100644 --- a/src/slang-nodes/Parameter.ts +++ b/src/slang-nodes/Parameter.ts @@ -1,6 +1,6 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TypeName } from './TypeName.js'; import { StorageLocation } from './StorageLocation.js'; diff --git a/src/slang-nodes/Parameters.ts b/src/slang-nodes/Parameters.ts index 2681d400f..0477b4887 100644 --- a/src/slang-nodes/Parameters.ts +++ b/src/slang-nodes/Parameters.ts @@ -2,7 +2,7 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../slang-printers/print-separated-list.js'; import { printSeparatedItem } from '../slang-printers/print-separated-item.js'; import { printComments } from '../slang-printers/print-comments.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Parameter } from './Parameter.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/ParametersDeclaration.ts b/src/slang-nodes/ParametersDeclaration.ts index 3b165b7ea..17b02ada0 100644 --- a/src/slang-nodes/ParametersDeclaration.ts +++ b/src/slang-nodes/ParametersDeclaration.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Parameters } from './Parameters.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/PathImport.ts b/src/slang-nodes/PathImport.ts index 99cb695ca..6609d98a5 100644 --- a/src/slang-nodes/PathImport.ts +++ b/src/slang-nodes/PathImport.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { StringLiteral } from './StringLiteral.js'; import { ImportAlias } from './ImportAlias.js'; diff --git a/src/slang-nodes/PositionalArguments.ts b/src/slang-nodes/PositionalArguments.ts index bdee513bc..b87743403 100644 --- a/src/slang-nodes/PositionalArguments.ts +++ b/src/slang-nodes/PositionalArguments.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../slang-printers/print-separated-list.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/PositionalArgumentsDeclaration.ts b/src/slang-nodes/PositionalArgumentsDeclaration.ts index 91565e3ca..04d309913 100644 --- a/src/slang-nodes/PositionalArgumentsDeclaration.ts +++ b/src/slang-nodes/PositionalArgumentsDeclaration.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { PositionalArguments } from './PositionalArguments.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/PostfixExpression.ts b/src/slang-nodes/PostfixExpression.ts index 4d75aa8cf..4a841129f 100644 --- a/src/slang-nodes/PostfixExpression.ts +++ b/src/slang-nodes/PostfixExpression.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/Pragma.ts b/src/slang-nodes/Pragma.ts index 925320a50..aa6c0ec29 100644 --- a/src/slang-nodes/Pragma.ts +++ b/src/slang-nodes/Pragma.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ABICoderPragma } from './ABICoderPragma.js'; import { ExperimentalPragma } from './ExperimentalPragma.js'; import { VersionPragma } from './VersionPragma.js'; diff --git a/src/slang-nodes/PragmaDirective.ts b/src/slang-nodes/PragmaDirective.ts index 11030d009..33549c047 100644 --- a/src/slang-nodes/PragmaDirective.ts +++ b/src/slang-nodes/PragmaDirective.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Pragma } from './Pragma.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/PrefixExpression.ts b/src/slang-nodes/PrefixExpression.ts index dabf4152d..59594ffa7 100644 --- a/src/slang-nodes/PrefixExpression.ts +++ b/src/slang-nodes/PrefixExpression.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/ReceiveFunctionAttribute.ts b/src/slang-nodes/ReceiveFunctionAttribute.ts index 0f74cbd75..123ad645a 100644 --- a/src/slang-nodes/ReceiveFunctionAttribute.ts +++ b/src/slang-nodes/ReceiveFunctionAttribute.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ModifierInvocation } from './ModifierInvocation.js'; import { OverrideSpecifier } from './OverrideSpecifier.js'; diff --git a/src/slang-nodes/ReceiveFunctionAttributes.ts b/src/slang-nodes/ReceiveFunctionAttributes.ts index 512ac7544..0a02a2332 100644 --- a/src/slang-nodes/ReceiveFunctionAttributes.ts +++ b/src/slang-nodes/ReceiveFunctionAttributes.ts @@ -1,7 +1,7 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ReceiveFunctionAttribute } from './ReceiveFunctionAttribute.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/ReceiveFunctionDefinition.ts b/src/slang-nodes/ReceiveFunctionDefinition.ts index 39350da6b..9ff424e08 100644 --- a/src/slang-nodes/ReceiveFunctionDefinition.ts +++ b/src/slang-nodes/ReceiveFunctionDefinition.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printFunction } from '../slang-printers/print-function.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ParametersDeclaration } from './ParametersDeclaration.js'; import { ReceiveFunctionAttributes } from './ReceiveFunctionAttributes.js'; import { FunctionBody } from './FunctionBody.js'; @@ -58,14 +58,14 @@ export class ReceiveFunctionDefinition implements SlangNode { } cleanModifierInvocationArguments(): void { - this.attributes.items.forEach((attribute) => { + for (const attribute of this.attributes.items) { if ( typeof attribute.variant !== 'string' && attribute.variant.kind === NonterminalKind.ModifierInvocation ) { attribute.variant.cleanModifierInvocationArguments(); } - }); + } } print(path: AstPath, print: (path: AstPath) => Doc): Doc { diff --git a/src/slang-nodes/ReturnStatement.ts b/src/slang-nodes/ReturnStatement.ts index 2f11223d2..e9318923b 100644 --- a/src/slang-nodes/ReturnStatement.ts +++ b/src/slang-nodes/ReturnStatement.ts @@ -1,6 +1,6 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/ReturnsDeclaration.ts b/src/slang-nodes/ReturnsDeclaration.ts index eaf0c5016..9cdc61b7e 100644 --- a/src/slang-nodes/ReturnsDeclaration.ts +++ b/src/slang-nodes/ReturnsDeclaration.ts @@ -1,6 +1,6 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ParametersDeclaration } from './ParametersDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/RevertStatement.ts b/src/slang-nodes/RevertStatement.ts index 453b1151e..7147e300a 100644 --- a/src/slang-nodes/RevertStatement.ts +++ b/src/slang-nodes/RevertStatement.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { IdentifierPath } from './IdentifierPath.js'; import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; diff --git a/src/slang-nodes/ShiftExpression.ts b/src/slang-nodes/ShiftExpression.ts index 4c5ba7b59..2fbb1a656 100644 --- a/src/slang-nodes/ShiftExpression.ts +++ b/src/slang-nodes/ShiftExpression.ts @@ -1,7 +1,7 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printBinaryOperation } from '../slang-printers/print-binary-operation.js'; import { createHugFunction } from '../slang-utils/create-hug-function.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/SourceUnit.ts b/src/slang-nodes/SourceUnit.ts index 772db108a..325702844 100644 --- a/src/slang-nodes/SourceUnit.ts +++ b/src/slang-nodes/SourceUnit.ts @@ -1,6 +1,6 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { SourceUnitMembers } from './SourceUnitMembers.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/SourceUnitMember.ts b/src/slang-nodes/SourceUnitMember.ts index 77043bcce..782035214 100644 --- a/src/slang-nodes/SourceUnitMember.ts +++ b/src/slang-nodes/SourceUnitMember.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { PragmaDirective } from './PragmaDirective.js'; import { ImportDirective } from './ImportDirective.js'; import { ContractDefinition } from './ContractDefinition.js'; diff --git a/src/slang-nodes/SourceUnitMembers.ts b/src/slang-nodes/SourceUnitMembers.ts index 68c6b78cd..6100e9386 100644 --- a/src/slang-nodes/SourceUnitMembers.ts +++ b/src/slang-nodes/SourceUnitMembers.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { SourceUnitMember } from './SourceUnitMember.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/StateVariableAttribute.ts b/src/slang-nodes/StateVariableAttribute.ts index e0d453e33..7f805a5af 100644 --- a/src/slang-nodes/StateVariableAttribute.ts +++ b/src/slang-nodes/StateVariableAttribute.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { OverrideSpecifier } from './OverrideSpecifier.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/StateVariableAttributes.ts b/src/slang-nodes/StateVariableAttributes.ts index 6a3029fe1..4a6d97871 100644 --- a/src/slang-nodes/StateVariableAttributes.ts +++ b/src/slang-nodes/StateVariableAttributes.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { StateVariableAttribute } from './StateVariableAttribute.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/StateVariableDefinition.ts b/src/slang-nodes/StateVariableDefinition.ts index d2f661813..721197c57 100644 --- a/src/slang-nodes/StateVariableDefinition.ts +++ b/src/slang-nodes/StateVariableDefinition.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TypeName } from './TypeName.js'; import { StateVariableAttributes } from './StateVariableAttributes.js'; import { StateVariableDefinitionValue } from './StateVariableDefinitionValue.js'; diff --git a/src/slang-nodes/StateVariableDefinitionValue.ts b/src/slang-nodes/StateVariableDefinitionValue.ts index b7305aab8..f36df9d0a 100644 --- a/src/slang-nodes/StateVariableDefinitionValue.ts +++ b/src/slang-nodes/StateVariableDefinitionValue.ts @@ -1,6 +1,6 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/Statement.ts b/src/slang-nodes/Statement.ts index 73aefd3fa..6c5096033 100644 --- a/src/slang-nodes/Statement.ts +++ b/src/slang-nodes/Statement.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ExpressionStatement } from './ExpressionStatement.js'; import { VariableDeclarationStatement } from './VariableDeclarationStatement.js'; import { TupleDeconstructionStatement } from './TupleDeconstructionStatement.js'; diff --git a/src/slang-nodes/Statements.ts b/src/slang-nodes/Statements.ts index 2d0394d29..99dd0162d 100644 --- a/src/slang-nodes/Statements.ts +++ b/src/slang-nodes/Statements.ts @@ -3,7 +3,7 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedItem } from '../slang-printers/print-separated-item.js'; import { printComments } from '../slang-printers/print-comments.js'; import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Statement } from './Statement.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/StorageLocation.ts b/src/slang-nodes/StorageLocation.ts index b3596855d..15c26db74 100644 --- a/src/slang-nodes/StorageLocation.ts +++ b/src/slang-nodes/StorageLocation.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata } from '../slang-utils/metadata.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { Doc } from 'prettier'; diff --git a/src/slang-nodes/StringExpression.ts b/src/slang-nodes/StringExpression.ts index 66c0b858e..25b310bc4 100644 --- a/src/slang-nodes/StringExpression.ts +++ b/src/slang-nodes/StringExpression.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { StringLiteral } from './StringLiteral.js'; import { StringLiterals } from './StringLiterals.js'; import { HexStringLiteral } from './HexStringLiteral.js'; diff --git a/src/slang-nodes/StringLiteral.ts b/src/slang-nodes/StringLiteral.ts index 738c703d6..8139e101c 100644 --- a/src/slang-nodes/StringLiteral.ts +++ b/src/slang-nodes/StringLiteral.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printString } from '../slang-printers/print-string.js'; -import { getNodeMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata } from '../slang-utils/metadata.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { Doc, ParserOptions } from 'prettier'; diff --git a/src/slang-nodes/StringLiterals.ts b/src/slang-nodes/StringLiterals.ts index 791be0115..8e7d14fc0 100644 --- a/src/slang-nodes/StringLiterals.ts +++ b/src/slang-nodes/StringLiterals.ts @@ -1,6 +1,6 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { StringLiteral } from './StringLiteral.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/StructDefinition.ts b/src/slang-nodes/StructDefinition.ts index 38badeb00..564151b4b 100644 --- a/src/slang-nodes/StructDefinition.ts +++ b/src/slang-nodes/StructDefinition.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { StructMembers } from './StructMembers.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/StructMember.ts b/src/slang-nodes/StructMember.ts index ea5ec43c0..6e09f320e 100644 --- a/src/slang-nodes/StructMember.ts +++ b/src/slang-nodes/StructMember.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TypeName } from './TypeName.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/StructMembers.ts b/src/slang-nodes/StructMembers.ts index d0f905223..06325a6bb 100644 --- a/src/slang-nodes/StructMembers.ts +++ b/src/slang-nodes/StructMembers.ts @@ -1,7 +1,7 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../slang-printers/print-separated-list.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { StructMember } from './StructMember.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/ThrowStatement.ts b/src/slang-nodes/ThrowStatement.ts index 9c0fd861f..9ee5c94ce 100644 --- a/src/slang-nodes/ThrowStatement.ts +++ b/src/slang-nodes/ThrowStatement.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata } from '../slang-utils/metadata.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { Doc } from 'prettier'; diff --git a/src/slang-nodes/TryStatement.ts b/src/slang-nodes/TryStatement.ts index c6705b12d..f9b492335 100644 --- a/src/slang-nodes/TryStatement.ts +++ b/src/slang-nodes/TryStatement.ts @@ -1,7 +1,7 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedItem } from '../slang-printers/print-separated-item.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import { ReturnsDeclaration } from './ReturnsDeclaration.js'; import { Block } from './Block.js'; diff --git a/src/slang-nodes/TupleDeconstructionElement.ts b/src/slang-nodes/TupleDeconstructionElement.ts index 97217466d..b629b0acc 100644 --- a/src/slang-nodes/TupleDeconstructionElement.ts +++ b/src/slang-nodes/TupleDeconstructionElement.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TupleMember } from './TupleMember.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/TupleDeconstructionElements.ts b/src/slang-nodes/TupleDeconstructionElements.ts index 88b28fa77..1933cc551 100644 --- a/src/slang-nodes/TupleDeconstructionElements.ts +++ b/src/slang-nodes/TupleDeconstructionElements.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../slang-printers/print-separated-list.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TupleDeconstructionElement } from './TupleDeconstructionElement.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/TupleDeconstructionStatement.ts b/src/slang-nodes/TupleDeconstructionStatement.ts index de4bb5053..6af563d9f 100644 --- a/src/slang-nodes/TupleDeconstructionStatement.ts +++ b/src/slang-nodes/TupleDeconstructionStatement.ts @@ -1,6 +1,6 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TupleDeconstructionElements } from './TupleDeconstructionElements.js'; import { Expression } from './Expression.js'; diff --git a/src/slang-nodes/TupleExpression.ts b/src/slang-nodes/TupleExpression.ts index 7ae3502c4..337f79e62 100644 --- a/src/slang-nodes/TupleExpression.ts +++ b/src/slang-nodes/TupleExpression.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TupleValues } from './TupleValues.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/TupleMember.ts b/src/slang-nodes/TupleMember.ts index 4e24b606f..5792687c3 100644 --- a/src/slang-nodes/TupleMember.ts +++ b/src/slang-nodes/TupleMember.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TypedTupleMember } from './TypedTupleMember.js'; import { UntypedTupleMember } from './UntypedTupleMember.js'; diff --git a/src/slang-nodes/TupleValue.ts b/src/slang-nodes/TupleValue.ts index c1c23acf9..6eb94e711 100644 --- a/src/slang-nodes/TupleValue.ts +++ b/src/slang-nodes/TupleValue.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/TupleValues.ts b/src/slang-nodes/TupleValues.ts index e843f678f..ebb672717 100644 --- a/src/slang-nodes/TupleValues.ts +++ b/src/slang-nodes/TupleValues.ts @@ -1,7 +1,7 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../slang-printers/print-separated-list.js'; import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TupleValue } from './TupleValue.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/TypeExpression.ts b/src/slang-nodes/TypeExpression.ts index 609738db2..3238bfa6f 100644 --- a/src/slang-nodes/TypeExpression.ts +++ b/src/slang-nodes/TypeExpression.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TypeName } from './TypeName.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/TypeName.ts b/src/slang-nodes/TypeName.ts index c3313f186..a57198c86 100644 --- a/src/slang-nodes/TypeName.ts +++ b/src/slang-nodes/TypeName.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ArrayTypeName } from './ArrayTypeName.js'; import { FunctionType } from './FunctionType.js'; import { MappingType } from './MappingType.js'; diff --git a/src/slang-nodes/TypedTupleMember.ts b/src/slang-nodes/TypedTupleMember.ts index 61d080d83..a23739d8c 100644 --- a/src/slang-nodes/TypedTupleMember.ts +++ b/src/slang-nodes/TypedTupleMember.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TypeName } from './TypeName.js'; import { StorageLocation } from './StorageLocation.js'; diff --git a/src/slang-nodes/UncheckedBlock.ts b/src/slang-nodes/UncheckedBlock.ts index 82d636c06..81167e978 100644 --- a/src/slang-nodes/UncheckedBlock.ts +++ b/src/slang-nodes/UncheckedBlock.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Block } from './Block.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/UnicodeStringLiteral.ts b/src/slang-nodes/UnicodeStringLiteral.ts index 99c4400d9..e50acedcb 100644 --- a/src/slang-nodes/UnicodeStringLiteral.ts +++ b/src/slang-nodes/UnicodeStringLiteral.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printString } from '../slang-printers/print-string.js'; -import { getNodeMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata } from '../slang-utils/metadata.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { Doc, ParserOptions } from 'prettier'; diff --git a/src/slang-nodes/UnicodeStringLiterals.ts b/src/slang-nodes/UnicodeStringLiterals.ts index b1f84e536..7050fc51d 100644 --- a/src/slang-nodes/UnicodeStringLiterals.ts +++ b/src/slang-nodes/UnicodeStringLiterals.ts @@ -1,6 +1,6 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { UnicodeStringLiteral } from './UnicodeStringLiteral.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/UnnamedFunctionAttribute.ts b/src/slang-nodes/UnnamedFunctionAttribute.ts index 4e19a4899..92e709a1d 100644 --- a/src/slang-nodes/UnnamedFunctionAttribute.ts +++ b/src/slang-nodes/UnnamedFunctionAttribute.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ModifierInvocation } from './ModifierInvocation.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/UnnamedFunctionAttributes.ts b/src/slang-nodes/UnnamedFunctionAttributes.ts index 68a85ad6b..30748711a 100644 --- a/src/slang-nodes/UnnamedFunctionAttributes.ts +++ b/src/slang-nodes/UnnamedFunctionAttributes.ts @@ -1,7 +1,7 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { UnnamedFunctionAttribute } from './UnnamedFunctionAttribute.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/UnnamedFunctionDefinition.ts b/src/slang-nodes/UnnamedFunctionDefinition.ts index 5c40ce47a..579bac4f1 100644 --- a/src/slang-nodes/UnnamedFunctionDefinition.ts +++ b/src/slang-nodes/UnnamedFunctionDefinition.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printFunction } from '../slang-printers/print-function.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ParametersDeclaration } from './ParametersDeclaration.js'; import { UnnamedFunctionAttributes } from './UnnamedFunctionAttributes.js'; import { FunctionBody } from './FunctionBody.js'; @@ -58,11 +58,11 @@ export class UnnamedFunctionDefinition implements SlangNode { } cleanModifierInvocationArguments(): void { - this.attributes.items.forEach((attribute) => { + for (const attribute of this.attributes.items) { if (typeof attribute.variant !== 'string') { attribute.variant.cleanModifierInvocationArguments(); } - }); + } } print(path: AstPath, print: (path: AstPath) => Doc): Doc { diff --git a/src/slang-nodes/UntypedTupleMember.ts b/src/slang-nodes/UntypedTupleMember.ts index 687da9e2b..2c0ddd412 100644 --- a/src/slang-nodes/UntypedTupleMember.ts +++ b/src/slang-nodes/UntypedTupleMember.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { StorageLocation } from './StorageLocation.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/UserDefinedValueTypeDefinition.ts b/src/slang-nodes/UserDefinedValueTypeDefinition.ts index 810a4cd80..4098fda5f 100644 --- a/src/slang-nodes/UserDefinedValueTypeDefinition.ts +++ b/src/slang-nodes/UserDefinedValueTypeDefinition.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ElementaryType } from './ElementaryType.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/UsingAlias.ts b/src/slang-nodes/UsingAlias.ts index 18f47a0a3..1b49b7e33 100644 --- a/src/slang-nodes/UsingAlias.ts +++ b/src/slang-nodes/UsingAlias.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { UsingOperator } from './UsingOperator.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/UsingClause.ts b/src/slang-nodes/UsingClause.ts index c829fdb97..140c77dc5 100644 --- a/src/slang-nodes/UsingClause.ts +++ b/src/slang-nodes/UsingClause.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { IdentifierPath } from './IdentifierPath.js'; import { UsingDeconstruction } from './UsingDeconstruction.js'; diff --git a/src/slang-nodes/UsingDeconstruction.ts b/src/slang-nodes/UsingDeconstruction.ts index acfca21f7..8d15f8dee 100644 --- a/src/slang-nodes/UsingDeconstruction.ts +++ b/src/slang-nodes/UsingDeconstruction.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { UsingDeconstructionSymbols } from './UsingDeconstructionSymbols.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/UsingDeconstructionSymbol.ts b/src/slang-nodes/UsingDeconstructionSymbol.ts index b77c77cb8..35ee72ef0 100644 --- a/src/slang-nodes/UsingDeconstructionSymbol.ts +++ b/src/slang-nodes/UsingDeconstructionSymbol.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { IdentifierPath } from './IdentifierPath.js'; import { UsingAlias } from './UsingAlias.js'; diff --git a/src/slang-nodes/UsingDeconstructionSymbols.ts b/src/slang-nodes/UsingDeconstructionSymbols.ts index a89dfa577..f5435d054 100644 --- a/src/slang-nodes/UsingDeconstructionSymbols.ts +++ b/src/slang-nodes/UsingDeconstructionSymbols.ts @@ -1,7 +1,7 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../slang-printers/print-separated-list.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { UsingDeconstructionSymbol } from './UsingDeconstructionSymbol.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/UsingDirective.ts b/src/slang-nodes/UsingDirective.ts index 88ea96ea1..33845f4ad 100644 --- a/src/slang-nodes/UsingDirective.ts +++ b/src/slang-nodes/UsingDirective.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { UsingClause } from './UsingClause.js'; import { UsingTarget } from './UsingTarget.js'; diff --git a/src/slang-nodes/UsingOperator.ts b/src/slang-nodes/UsingOperator.ts index c50c1733a..d5c03b58b 100644 --- a/src/slang-nodes/UsingOperator.ts +++ b/src/slang-nodes/UsingOperator.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata } from '../slang-utils/metadata.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { Doc } from 'prettier'; diff --git a/src/slang-nodes/UsingTarget.ts b/src/slang-nodes/UsingTarget.ts index 565f1c33a..3e6fe009e 100644 --- a/src/slang-nodes/UsingTarget.ts +++ b/src/slang-nodes/UsingTarget.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TypeName } from './TypeName.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/VariableDeclarationStatement.ts b/src/slang-nodes/VariableDeclarationStatement.ts index 38d937660..30b196cb1 100644 --- a/src/slang-nodes/VariableDeclarationStatement.ts +++ b/src/slang-nodes/VariableDeclarationStatement.ts @@ -1,6 +1,6 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { VariableDeclarationType } from './VariableDeclarationType.js'; import { StorageLocation } from './StorageLocation.js'; import { VariableDeclarationValue } from './VariableDeclarationValue.js'; diff --git a/src/slang-nodes/VariableDeclarationType.ts b/src/slang-nodes/VariableDeclarationType.ts index c586565ee..d0efc795b 100644 --- a/src/slang-nodes/VariableDeclarationType.ts +++ b/src/slang-nodes/VariableDeclarationType.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TypeName } from './TypeName.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/VariableDeclarationValue.ts b/src/slang-nodes/VariableDeclarationValue.ts index 9b7adc36f..d2fe13503 100644 --- a/src/slang-nodes/VariableDeclarationValue.ts +++ b/src/slang-nodes/VariableDeclarationValue.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/VersionComparator.ts b/src/slang-nodes/VersionComparator.ts index 7bfe32899..916e84466 100644 --- a/src/slang-nodes/VersionComparator.ts +++ b/src/slang-nodes/VersionComparator.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { VersionExpression } from './VersionExpression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/VersionExpression.ts b/src/slang-nodes/VersionExpression.ts index cbb4f9737..4e0bf8e28 100644 --- a/src/slang-nodes/VersionExpression.ts +++ b/src/slang-nodes/VersionExpression.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { VersionRange } from './VersionRange.js'; import { VersionComparator } from './VersionComparator.js'; import { VersionSpecifiers } from './VersionSpecifiers.js'; diff --git a/src/slang-nodes/VersionExpressionSet.ts b/src/slang-nodes/VersionExpressionSet.ts index 473ef6e05..6f58aae27 100644 --- a/src/slang-nodes/VersionExpressionSet.ts +++ b/src/slang-nodes/VersionExpressionSet.ts @@ -1,6 +1,6 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { VersionExpression } from './VersionExpression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/VersionExpressionSets.ts b/src/slang-nodes/VersionExpressionSets.ts index 4fe5118ab..44ed38290 100644 --- a/src/slang-nodes/VersionExpressionSets.ts +++ b/src/slang-nodes/VersionExpressionSets.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { VersionExpressionSet } from './VersionExpressionSet.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/VersionPragma.ts b/src/slang-nodes/VersionPragma.ts index f19aa6326..904346b6e 100644 --- a/src/slang-nodes/VersionPragma.ts +++ b/src/slang-nodes/VersionPragma.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { VersionExpressionSets } from './VersionExpressionSets.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/VersionRange.ts b/src/slang-nodes/VersionRange.ts index 2474773ce..979be3605 100644 --- a/src/slang-nodes/VersionRange.ts +++ b/src/slang-nodes/VersionRange.ts @@ -1,9 +1,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { VersionExpression } from './VersionExpression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; -import type { /*AstPath,*/ Doc } from 'prettier'; +import type { /*AstPath,*/ Doc /*, ParserOptions*/ } from 'prettier'; import type { SlangNode } from '../types.js'; export class VersionRange implements SlangNode { diff --git a/src/slang-nodes/VersionSpecifiers.ts b/src/slang-nodes/VersionSpecifiers.ts index ffc93f7ed..13eb76704 100644 --- a/src/slang-nodes/VersionSpecifiers.ts +++ b/src/slang-nodes/VersionSpecifiers.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata } from '../slang-utils/metadata.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { Doc } from 'prettier'; diff --git a/src/slang-nodes/WhileStatement.ts b/src/slang-nodes/WhileStatement.ts index 7a8c1ae14..f7c6439c3 100644 --- a/src/slang-nodes/WhileStatement.ts +++ b/src/slang-nodes/WhileStatement.ts @@ -1,7 +1,7 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedItem } from '../slang-printers/print-separated-item.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import { Statement } from './Statement.js'; diff --git a/src/slang-nodes/YulArguments.ts b/src/slang-nodes/YulArguments.ts index 622eec350..5796f5405 100644 --- a/src/slang-nodes/YulArguments.ts +++ b/src/slang-nodes/YulArguments.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../slang-printers/print-separated-list.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulExpression } from './YulExpression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/YulAssignmentOperator.ts b/src/slang-nodes/YulAssignmentOperator.ts index b80307a7c..0904ac97b 100644 --- a/src/slang-nodes/YulAssignmentOperator.ts +++ b/src/slang-nodes/YulAssignmentOperator.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulColonEqual } from './YulColonEqual.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/YulBlock.ts b/src/slang-nodes/YulBlock.ts index 396a1f610..a3478c1cf 100644 --- a/src/slang-nodes/YulBlock.ts +++ b/src/slang-nodes/YulBlock.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulStatements } from './YulStatements.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/YulBreakStatement.ts b/src/slang-nodes/YulBreakStatement.ts index 8b7ea0dc1..fedf22198 100644 --- a/src/slang-nodes/YulBreakStatement.ts +++ b/src/slang-nodes/YulBreakStatement.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata } from '../slang-utils/metadata.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { Doc } from 'prettier'; diff --git a/src/slang-nodes/YulBuiltInFunction.ts b/src/slang-nodes/YulBuiltInFunction.ts index c8c154279..0bb02e80b 100644 --- a/src/slang-nodes/YulBuiltInFunction.ts +++ b/src/slang-nodes/YulBuiltInFunction.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata } from '../slang-utils/metadata.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { Doc } from 'prettier'; diff --git a/src/slang-nodes/YulColonEqual.ts b/src/slang-nodes/YulColonEqual.ts index 70b6ff3bf..68d10b275 100644 --- a/src/slang-nodes/YulColonEqual.ts +++ b/src/slang-nodes/YulColonEqual.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata } from '../slang-utils/metadata.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { /*AstPath,*/ Doc /*, ParserOptions*/ } from 'prettier'; diff --git a/src/slang-nodes/YulContinueStatement.ts b/src/slang-nodes/YulContinueStatement.ts index 8aa997626..10ac4768c 100644 --- a/src/slang-nodes/YulContinueStatement.ts +++ b/src/slang-nodes/YulContinueStatement.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata } from '../slang-utils/metadata.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { Doc } from 'prettier'; diff --git a/src/slang-nodes/YulDefaultCase.ts b/src/slang-nodes/YulDefaultCase.ts index e8d550fbe..e3a269c0e 100644 --- a/src/slang-nodes/YulDefaultCase.ts +++ b/src/slang-nodes/YulDefaultCase.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulBlock } from './YulBlock.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/YulExpression.ts b/src/slang-nodes/YulExpression.ts index 06060a857..75c7fde06 100644 --- a/src/slang-nodes/YulExpression.ts +++ b/src/slang-nodes/YulExpression.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulFunctionCallExpression } from './YulFunctionCallExpression.js'; import { YulLiteral } from './YulLiteral.js'; import { YulBuiltInFunction } from './YulBuiltInFunction.js'; diff --git a/src/slang-nodes/YulForStatement.ts b/src/slang-nodes/YulForStatement.ts index 8f12833fe..c25c0468d 100644 --- a/src/slang-nodes/YulForStatement.ts +++ b/src/slang-nodes/YulForStatement.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulBlock } from './YulBlock.js'; import { YulExpression } from './YulExpression.js'; diff --git a/src/slang-nodes/YulFunctionCallExpression.ts b/src/slang-nodes/YulFunctionCallExpression.ts index 306145e1a..05bc01c4e 100644 --- a/src/slang-nodes/YulFunctionCallExpression.ts +++ b/src/slang-nodes/YulFunctionCallExpression.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulExpression } from './YulExpression.js'; import { YulArguments } from './YulArguments.js'; diff --git a/src/slang-nodes/YulFunctionDefinition.ts b/src/slang-nodes/YulFunctionDefinition.ts index e653bd5b6..1c0de61dc 100644 --- a/src/slang-nodes/YulFunctionDefinition.ts +++ b/src/slang-nodes/YulFunctionDefinition.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulParametersDeclaration } from './YulParametersDeclaration.js'; import { YulReturnsDeclaration } from './YulReturnsDeclaration.js'; import { YulBlock } from './YulBlock.js'; diff --git a/src/slang-nodes/YulIfStatement.ts b/src/slang-nodes/YulIfStatement.ts index f197722f2..f0e9e5c5a 100644 --- a/src/slang-nodes/YulIfStatement.ts +++ b/src/slang-nodes/YulIfStatement.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulExpression } from './YulExpression.js'; import { YulBlock } from './YulBlock.js'; diff --git a/src/slang-nodes/YulLabel.ts b/src/slang-nodes/YulLabel.ts index dffa9e120..36dd658c4 100644 --- a/src/slang-nodes/YulLabel.ts +++ b/src/slang-nodes/YulLabel.ts @@ -1,6 +1,6 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata } from '../slang-utils/metadata.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { Doc } from 'prettier'; diff --git a/src/slang-nodes/YulLeaveStatement.ts b/src/slang-nodes/YulLeaveStatement.ts index 3b21c72e1..c1da016d2 100644 --- a/src/slang-nodes/YulLeaveStatement.ts +++ b/src/slang-nodes/YulLeaveStatement.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata } from '../slang-utils/metadata.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { /*AstPath,*/ Doc /*, ParserOptions*/ } from 'prettier'; diff --git a/src/slang-nodes/YulLiteral.ts b/src/slang-nodes/YulLiteral.ts index f4223c6d6..e70d2c41a 100644 --- a/src/slang-nodes/YulLiteral.ts +++ b/src/slang-nodes/YulLiteral.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { HexStringLiteral } from './HexStringLiteral.js'; import { StringLiteral } from './StringLiteral.js'; diff --git a/src/slang-nodes/YulParameters.ts b/src/slang-nodes/YulParameters.ts index 3e2f1020a..5e654f9f5 100644 --- a/src/slang-nodes/YulParameters.ts +++ b/src/slang-nodes/YulParameters.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../slang-printers/print-separated-list.js'; -import { getNodeMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata } from '../slang-utils/metadata.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { Doc } from 'prettier'; diff --git a/src/slang-nodes/YulParametersDeclaration.ts b/src/slang-nodes/YulParametersDeclaration.ts index 6d6d30dd8..0fe0e9ce1 100644 --- a/src/slang-nodes/YulParametersDeclaration.ts +++ b/src/slang-nodes/YulParametersDeclaration.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulParameters } from './YulParameters.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/YulPath.ts b/src/slang-nodes/YulPath.ts index ea608f27b..4ead1ad26 100644 --- a/src/slang-nodes/YulPath.ts +++ b/src/slang-nodes/YulPath.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulPathComponent } from './YulPathComponent.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/YulPathComponent.ts b/src/slang-nodes/YulPathComponent.ts index a9ff32ec5..e9b6e573d 100644 --- a/src/slang-nodes/YulPathComponent.ts +++ b/src/slang-nodes/YulPathComponent.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata } from '../slang-utils/metadata.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { Doc } from 'prettier'; diff --git a/src/slang-nodes/YulPaths.ts b/src/slang-nodes/YulPaths.ts index 840d079d2..af149a6bf 100644 --- a/src/slang-nodes/YulPaths.ts +++ b/src/slang-nodes/YulPaths.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulPath } from './YulPath.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/YulReturnVariables.ts b/src/slang-nodes/YulReturnVariables.ts index 3a66f9d7d..8bb8e0c48 100644 --- a/src/slang-nodes/YulReturnVariables.ts +++ b/src/slang-nodes/YulReturnVariables.ts @@ -1,7 +1,7 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../slang-printers/print-separated-list.js'; -import { getNodeMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata } from '../slang-utils/metadata.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { Doc } from 'prettier'; diff --git a/src/slang-nodes/YulReturnsDeclaration.ts b/src/slang-nodes/YulReturnsDeclaration.ts index d8eb98aa2..01b52f8e4 100644 --- a/src/slang-nodes/YulReturnsDeclaration.ts +++ b/src/slang-nodes/YulReturnsDeclaration.ts @@ -1,7 +1,7 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedItem } from '../slang-printers/print-separated-item.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulReturnVariables } from './YulReturnVariables.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/YulStackAssignmentStatement.ts b/src/slang-nodes/YulStackAssignmentStatement.ts index bd57c8f24..038048747 100644 --- a/src/slang-nodes/YulStackAssignmentStatement.ts +++ b/src/slang-nodes/YulStackAssignmentStatement.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulAssignmentOperator } from './YulAssignmentOperator.js'; import { YulExpression } from './YulExpression.js'; diff --git a/src/slang-nodes/YulStatement.ts b/src/slang-nodes/YulStatement.ts index 1ed394f03..a4055b27a 100644 --- a/src/slang-nodes/YulStatement.ts +++ b/src/slang-nodes/YulStatement.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulBlock } from './YulBlock.js'; import { YulFunctionDefinition } from './YulFunctionDefinition.js'; import { YulVariableDeclarationStatement } from './YulVariableDeclarationStatement.js'; diff --git a/src/slang-nodes/YulStatements.ts b/src/slang-nodes/YulStatements.ts index 6374f103e..702254a4b 100644 --- a/src/slang-nodes/YulStatements.ts +++ b/src/slang-nodes/YulStatements.ts @@ -3,7 +3,7 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedItem } from '../slang-printers/print-separated-item.js'; import { printComments } from '../slang-printers/print-comments.js'; import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulStatement } from './YulStatement.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/YulSwitchCase.ts b/src/slang-nodes/YulSwitchCase.ts index 87b946125..aea232792 100644 --- a/src/slang-nodes/YulSwitchCase.ts +++ b/src/slang-nodes/YulSwitchCase.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulDefaultCase } from './YulDefaultCase.js'; import { YulValueCase } from './YulValueCase.js'; diff --git a/src/slang-nodes/YulSwitchCases.ts b/src/slang-nodes/YulSwitchCases.ts index 7bac38a30..4c561c5ac 100644 --- a/src/slang-nodes/YulSwitchCases.ts +++ b/src/slang-nodes/YulSwitchCases.ts @@ -1,6 +1,6 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulSwitchCase } from './YulSwitchCase.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/YulSwitchStatement.ts b/src/slang-nodes/YulSwitchStatement.ts index 1e0f560ef..92f184317 100644 --- a/src/slang-nodes/YulSwitchStatement.ts +++ b/src/slang-nodes/YulSwitchStatement.ts @@ -1,6 +1,6 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulExpression } from './YulExpression.js'; import { YulSwitchCases } from './YulSwitchCases.js'; diff --git a/src/slang-nodes/YulValueCase.ts b/src/slang-nodes/YulValueCase.ts index be8005f44..177948e70 100644 --- a/src/slang-nodes/YulValueCase.ts +++ b/src/slang-nodes/YulValueCase.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulLiteral } from './YulLiteral.js'; import { YulBlock } from './YulBlock.js'; diff --git a/src/slang-nodes/YulVariableAssignmentStatement.ts b/src/slang-nodes/YulVariableAssignmentStatement.ts index 15d6decc4..b55869841 100644 --- a/src/slang-nodes/YulVariableAssignmentStatement.ts +++ b/src/slang-nodes/YulVariableAssignmentStatement.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulPaths } from './YulPaths.js'; import { YulAssignmentOperator } from './YulAssignmentOperator.js'; import { YulExpression } from './YulExpression.js'; diff --git a/src/slang-nodes/YulVariableDeclarationStatement.ts b/src/slang-nodes/YulVariableDeclarationStatement.ts index 93b5bbd05..f97aaa815 100644 --- a/src/slang-nodes/YulVariableDeclarationStatement.ts +++ b/src/slang-nodes/YulVariableDeclarationStatement.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulVariableDeclarationValue } from './YulVariableDeclarationValue.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; diff --git a/src/slang-nodes/YulVariableDeclarationValue.ts b/src/slang-nodes/YulVariableDeclarationValue.ts index 04824147d..c3df5762f 100644 --- a/src/slang-nodes/YulVariableDeclarationValue.ts +++ b/src/slang-nodes/YulVariableDeclarationValue.ts @@ -1,5 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { getNodeMetadata, updateMetadata } from '../slang-utils/get-offsets.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulAssignmentOperator } from './YulAssignmentOperator.js'; import { YulExpression } from './YulExpression.js'; diff --git a/src/slang-printers/print-binary-operation.ts b/src/slang-printers/print-binary-operation.ts index 7578597d8..abd4a83d5 100644 --- a/src/slang-printers/print-binary-operation.ts +++ b/src/slang-printers/print-binary-operation.ts @@ -9,17 +9,17 @@ import type { AstNode, BinaryOperation } from '../types.js'; const { group, indent } = doc.builders; const isBinaryOperationWithoutComparison = createKindCheckFunction([ - 'AdditiveExpression', - 'MultiplicativeExpression', - 'ExponentiationExpression', - 'AssignmentExpression', - 'BitwiseAndExpression', - 'BitwiseOrExpression', - 'BitwiseXorExpression', - 'AndExpression', - 'OrExpression', - 'ShiftExpression' -]); + NonterminalKind.AdditiveExpression, + NonterminalKind.MultiplicativeExpression, + NonterminalKind.ExponentiationExpression, + NonterminalKind.AssignmentExpression, + NonterminalKind.BitwiseAndExpression, + NonterminalKind.BitwiseOrExpression, + NonterminalKind.BitwiseXorExpression, + NonterminalKind.AndExpression, + NonterminalKind.OrExpression, + NonterminalKind.ShiftExpression +]) as (node: AstNode | Comment | Node) => node is BinaryOperation; const binaryGroupRulesBuilder = (path: AstPath) => @@ -41,8 +41,7 @@ const binaryIndentRulesBuilder = if (!isBinaryOperationWithoutComparison(grandparentNode)) { return indent(document); } - if (node === (grandparentNode as BinaryOperation).rightOperand.variant) - break; + if (node === grandparentNode.rightOperand.variant) break; node = grandparentNode; } return document; diff --git a/src/slang-printers/print-comments.ts b/src/slang-printers/print-comments.ts index 3d2a83e09..c0c58e500 100644 --- a/src/slang-printers/print-comments.ts +++ b/src/slang-printers/print-comments.ts @@ -1,6 +1,6 @@ import { doc } from 'prettier'; import { printComment } from '../slang-comments/printer.js'; -import { getNode, isPrettier2 } from '../slang-utils/backward-compatibility.js'; +import { isPrettier2 } from '../slang-utils/backward-compatibility.js'; import type { AstPath, Doc } from 'prettier'; import type { AstNode, Comment } from '../types.js'; @@ -14,7 +14,7 @@ export function printComments(node: AstNode, path: AstPath): Doc[] { line, path .map((commentPath) => { - const comment = getNode(commentPath) as Comment; + const comment = commentPath.getNode() as Comment; if (comment.trailing || comment.leading || comment.printed) { return ''; } diff --git a/src/slang-printers/print-comparison-operation.ts b/src/slang-printers/print-comparison-operation.ts index c48e3ddc9..e8cd44b80 100644 --- a/src/slang-printers/print-comparison-operation.ts +++ b/src/slang-printers/print-comparison-operation.ts @@ -5,14 +5,14 @@ import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; import { createBinaryOperationPrinter } from './create-binary-operation-printer.js'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, BinaryOperation } from '../types.js'; +import type { AstNode } from '../types.js'; const { group, indent } = doc.builders; const isStatementWithoutIndentedOperation = createKindCheckFunction([ - 'ReturnStatement', - 'IfStatement', - 'WhileStatement' + NonterminalKind.ReturnStatement, + NonterminalKind.IfStatement, + NonterminalKind.WhileStatement ]); const comparisonIndentRulesBuilder = @@ -31,8 +31,7 @@ const comparisonIndentRulesBuilder = } if (isStatementWithoutIndentedOperation(grandparentNode)) break; if (!isBinaryOperation(grandparentNode)) return indent(document); - if (node === (grandparentNode as BinaryOperation).rightOperand.variant) - break; + if (node === grandparentNode.rightOperand.variant) break; node = grandparentNode; } return document; diff --git a/src/slang-printers/print-logical-operation.ts b/src/slang-printers/print-logical-operation.ts index 658402c50..9e16b6506 100644 --- a/src/slang-printers/print-logical-operation.ts +++ b/src/slang-printers/print-logical-operation.ts @@ -5,14 +5,14 @@ import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; import { createBinaryOperationPrinter } from './create-binary-operation-printer.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, BinaryOperation } from '../types.js'; +import type { AstNode } from '../types.js'; const { group, indent } = doc.builders; const isStatementWithoutIndentedOperation = createKindCheckFunction([ - 'ReturnStatement', - 'IfStatement', - 'WhileStatement' + NonterminalKind.ReturnStatement, + NonterminalKind.IfStatement, + NonterminalKind.WhileStatement ]); const logicalGroupRulesBuilder = @@ -34,8 +34,7 @@ const logicalIndentRulesBuilder = ) break; if (!isBinaryOperation(grandparentNode)) return indent(document); - if (node === (grandparentNode as BinaryOperation).rightOperand.variant) - break; + if (node === grandparentNode.rightOperand.variant) break; node = grandparentNode; } return document; diff --git a/src/slang-utils/backward-compatibility.ts b/src/slang-utils/backward-compatibility.ts index 7639745e0..4e8da5c0e 100644 --- a/src/slang-utils/backward-compatibility.ts +++ b/src/slang-utils/backward-compatibility.ts @@ -33,14 +33,6 @@ export function getNextNonSpaceNonCommentCharacter( return util.getNextNonSpaceNonCommentCharacter(text, locEnd(node)); // V3 exposes this function directly } -// TODO: remove undefined once we stop supporting prettier 2 -export const getNode = (path: AstPath): AstNode | Comment | null | undefined => - (isPrettier2 ? path.getValue() : path.node) as - | AstNode - | Comment - | null - | undefined; // V3 deprecated `getValue` - export function isLast(path: AstPath, key: string, index: number): boolean { return isPrettier2 ? index === path.getParentNode()[key].length - 1 diff --git a/src/slang-utils/create-hug-function.ts b/src/slang-utils/create-hug-function.ts index ddb976612..bd7ef9eea 100644 --- a/src/slang-utils/create-hug-function.ts +++ b/src/slang-utils/create-hug-function.ts @@ -5,8 +5,6 @@ import { TupleValues } from '../slang-nodes/TupleValues.js'; import { TupleValue } from '../slang-nodes/TupleValue.js'; import { isBinaryOperation } from './is-binary-operation.js'; -import type { BinaryOperation } from '../types.js'; - const objectConfig = { writable: true, enumerable: true, @@ -21,7 +19,7 @@ export function createHugFunction( if ( typeof node.variant !== 'string' && isBinaryOperation(node.variant) && - operators.has((node.variant as BinaryOperation).operator) + operators.has(node.variant.operator) ) { const { loc } = node; diff --git a/src/slang-utils/create-kind-check-function.ts b/src/slang-utils/create-kind-check-function.ts index 094c0cd38..5077d55f4 100644 --- a/src/slang-utils/create-kind-check-function.ts +++ b/src/slang-utils/create-kind-check-function.ts @@ -1,5 +1,4 @@ -import { Node } from '@nomicfoundation/slang/cst'; - +import type { Node } from '@nomicfoundation/slang/cst'; import type { AstNode, Comment } from '../types'; export function createKindCheckFunction( diff --git a/src/slang-utils/is-binary-operation.ts b/src/slang-utils/is-binary-operation.ts index be3e669b2..9e3af39ea 100644 --- a/src/slang-utils/is-binary-operation.ts +++ b/src/slang-utils/is-binary-operation.ts @@ -1,16 +1,19 @@ import { createKindCheckFunction } from './create-kind-check-function.js'; +import type { AstNode, BinaryOperation } from '../types.js'; +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; + export const isBinaryOperation = createKindCheckFunction([ - 'AdditiveExpression', - 'MultiplicativeExpression', - 'ExponentiationExpression', - 'AssignmentExpression', - 'BitwiseAndExpression', - 'BitwiseOrExpression', - 'BitwiseXorExpression', - 'ComparisonExpression', - 'EqualityExpression', - 'AndExpression', - 'OrExpression', - 'ShiftExpression' -]); + NonterminalKind.AdditiveExpression, + NonterminalKind.MultiplicativeExpression, + NonterminalKind.ExponentiationExpression, + NonterminalKind.AssignmentExpression, + NonterminalKind.BitwiseAndExpression, + NonterminalKind.BitwiseOrExpression, + NonterminalKind.BitwiseXorExpression, + NonterminalKind.ComparisonExpression, + NonterminalKind.EqualityExpression, + NonterminalKind.AndExpression, + NonterminalKind.OrExpression, + NonterminalKind.ShiftExpression +]) as (node: AstNode | Comment | Node) => node is BinaryOperation; diff --git a/src/slang-utils/is-comment.ts b/src/slang-utils/is-comment.ts index 24ef85e9d..dd43bd162 100644 --- a/src/slang-utils/is-comment.ts +++ b/src/slang-utils/is-comment.ts @@ -1,18 +1,22 @@ +import { TerminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { createKindCheckFunction } from './create-kind-check-function.js'; +import type { Node } from '@nomicfoundation/slang/cst'; +import type { AstNode, BlockComment, Comment, LineComment } from '../types.js'; + export const isBlockComment = createKindCheckFunction([ - 'MultiLineComment', - 'MultiLineNatSpecComment' -]); + TerminalKind.MultiLineComment, + TerminalKind.MultiLineNatSpecComment +]) as (node: AstNode | Comment | Node) => node is BlockComment; export const isLineComment = createKindCheckFunction([ - 'SingleLineComment', - 'SingleLineNatSpecComment' -]); + TerminalKind.SingleLineComment, + TerminalKind.SingleLineNatSpecComment +]) as (node: AstNode | Comment | Node) => node is LineComment; export const isComment = createKindCheckFunction([ - 'MultiLineComment', - 'MultiLineNatSpecComment', - 'SingleLineComment', - 'SingleLineNatSpecComment' -]); + TerminalKind.MultiLineComment, + TerminalKind.MultiLineNatSpecComment, + TerminalKind.SingleLineComment, + TerminalKind.SingleLineNatSpecComment +]) as (node: AstNode | Comment | Node) => node is Comment; diff --git a/src/slang-utils/get-offsets.ts b/src/slang-utils/metadata.ts similarity index 74% rename from src/slang-utils/get-offsets.ts rename to src/slang-utils/metadata.ts index 492d724a8..9ac2ee612 100644 --- a/src/slang-utils/get-offsets.ts +++ b/src/slang-utils/metadata.ts @@ -80,7 +80,7 @@ function collectComments( ): Comment[] { if (node) { if (Array.isArray(node)) { - comments.push(...node.reduce(collectComments, [])); + return node.reduce(collectComments, comments); } else if (node.comments.length > 0) { comments.push(...node.comments.splice(0)); } @@ -92,34 +92,38 @@ export function updateMetadata( metadata: Metadata, childNodes: (AstNode | AstNode[] | undefined)[] ): Metadata { - const { comments, loc } = metadata; // Collect comments - comments.push(...childNodes.reduce(collectComments, [])); + const comments = childNodes.reduce(collectComments, metadata.comments); // calculate correct loc object - if (loc.leadingOffset === 0 || loc.trailingOffset === 0) { - childNodes.forEach((childNode) => { - if (Array.isArray(childNode)) return; - const childLoc = childNode?.loc; - - if (childLoc) { - if ( - loc.leadingOffset === 0 && - childLoc.start - childLoc.leadingOffset === loc.start - ) { - loc.leadingOffset = childLoc.leadingOffset; - loc.start += childLoc.leadingOffset; - } + const { loc } = metadata; + if (loc.leadingOffset === 0) { + for (const childNode of childNodes) { + if (typeof childNode === 'undefined' || Array.isArray(childNode)) + continue; + const childLoc = childNode.loc; - if ( - loc.trailingOffset === 0 && - childLoc.end + childLoc.trailingOffset === loc.end - ) { - loc.trailingOffset = childLoc.trailingOffset; - loc.end -= childLoc.trailingOffset; - } + if (childLoc.start - childLoc.leadingOffset === loc.start) { + loc.leadingOffset = childLoc.leadingOffset; + loc.start += childLoc.leadingOffset; + break; } - }); + } } + + if (loc.trailingOffset === 0) { + for (const childNode of childNodes.reverse()) { + if (typeof childNode === 'undefined' || Array.isArray(childNode)) + continue; + const childLoc = childNode.loc; + + if (childLoc.end + childLoc.trailingOffset === loc.end) { + loc.trailingOffset = childLoc.trailingOffset; + loc.end -= childLoc.trailingOffset; + break; + } + } + } + return { comments, loc, offsets: [] }; } diff --git a/src/slangPrinter.ts b/src/slangPrinter.ts index 49ae9cf13..2c3bdc17f 100644 --- a/src/slangPrinter.ts +++ b/src/slangPrinter.ts @@ -1,5 +1,4 @@ import { prettierVersionSatisfies } from './slang-utils/prettier-version-satisfies.js'; -import { getNode } from './slang-utils/backward-compatibility.js'; import { isBlockComment } from './slang-utils/is-comment.js'; import { locEnd, locStart } from './slang-utils/loc.js'; @@ -32,12 +31,12 @@ function hasNodeIgnoreComment(node: AstNode): boolean { function ignoreComments(path: AstPath): void { // TODO: remove undefined once we stop supporting prettier 2 - const node = getNode(path) as AstNode | null | undefined; + const node = path.getNode() as AstNode | null | undefined; // We ignore anything that is not an object if (node === null || node === undefined || typeof node !== 'object') return; const keys = Object.keys(node) as (keyof AstNode)[]; - keys.forEach((key) => { + for (const key of keys) { switch (key) { // We ignore `kind`, `loc`, and comments since these are added by the // parser @@ -48,7 +47,7 @@ function ignoreComments(path: AstPath): void { // The key `comments` will contain every comment for this node case 'comments': path.each((commentPath) => { - const comment = getNode(commentPath) as Comment; + const comment = commentPath.getNode() as Comment; comment.printed = true; }, 'comments'); break; @@ -63,7 +62,7 @@ function ignoreComments(path: AstPath): void { path.call(ignoreComments, key); } } - }); + } } function genericPrint( @@ -73,7 +72,7 @@ function genericPrint( ): Doc { prettierVersionCheck(); - const node = getNode(path) as AstNode | null | undefined; + const node = path.getNode() as AstNode | null | undefined; if (node === null || node === undefined) { return ''; diff --git a/src/types.d.ts b/src/types.d.ts index e94c5e1ea..aa4483ca0 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -1,6 +1,7 @@ +import type { kinds } from '@nomicfoundation/slang/napi-bindings/generated/index.js'; +import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; import type * as nodes from './slang-nodes/index.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; // Adding our own options to prettier's `ParserOptions` interface. declare module 'prettier' { @@ -31,11 +32,15 @@ interface BaseComment { followingNode?: AstNode; } interface BlockComment extends BaseComment { - kind: 'MultiLineComment' | 'MultiLineNatSpecComment'; + kind: + | kinds.TerminalKind.MultiLineComment + | kinds.TerminalKind.MultiLineNatSpecComment; } interface LineComment extends BaseComment { - kind: 'SingleLineComment' | 'SingleLineNatSpecComment'; + kind: + | kinds.TerminalKind.SingleLineComment + | kinds.TerminalKind.SingleLineNatSpecComment; } type Comment = BlockComment | LineComment; From d6cf7953f9043f5be3dc4a62c99f73138319d907 Mon Sep 17 00:00:00 2001 From: Klaus Date: Thu, 1 Aug 2024 02:42:54 +1200 Subject: [PATCH 105/160] Providing AstNode to ParserOptions --- src/{index.js => index.ts} | 78 +++++++++++-------- src/slang-comments/handler.ts | 16 ++-- src/slang-nodes/AdditiveExpression.ts | 6 +- src/slang-nodes/AndExpression.ts | 10 ++- src/slang-nodes/ArgumentsDeclaration.ts | 4 +- src/slang-nodes/ArrayExpression.ts | 4 +- src/slang-nodes/ArrayTypeName.ts | 8 +- src/slang-nodes/ArrayValues.ts | 8 +- src/slang-nodes/AssemblyFlags.ts | 8 +- src/slang-nodes/AssemblyFlagsDeclaration.ts | 4 +- src/slang-nodes/AssemblyStatement.ts | 4 +- src/slang-nodes/AssignmentExpression.ts | 4 +- src/slang-nodes/BitwiseAndExpression.ts | 6 +- src/slang-nodes/BitwiseOrExpression.ts | 6 +- src/slang-nodes/BitwiseXorExpression.ts | 6 +- src/slang-nodes/Block.ts | 4 +- src/slang-nodes/CallOptions.ts | 10 ++- src/slang-nodes/CallOptionsExpression.ts | 4 +- src/slang-nodes/CatchClause.ts | 8 +- src/slang-nodes/CatchClauseError.ts | 4 +- src/slang-nodes/CatchClauses.ts | 8 +- src/slang-nodes/ComparisonExpression.ts | 6 +- src/slang-nodes/ConditionalExpression.ts | 6 +- src/slang-nodes/ConstantDefinition.ts | 6 +- src/slang-nodes/ConstructorAttribute.ts | 4 +- src/slang-nodes/ConstructorAttributes.ts | 4 +- src/slang-nodes/ConstructorDefinition.ts | 4 +- src/slang-nodes/ContractDefinition.ts | 6 +- src/slang-nodes/ContractMember.ts | 8 +- src/slang-nodes/ContractMembers.ts | 6 +- src/slang-nodes/DoWhileStatement.ts | 4 +- src/slang-nodes/ElseBranch.ts | 8 +- src/slang-nodes/EmitStatement.ts | 8 +- src/slang-nodes/EqualityExpression.ts | 6 +- src/slang-nodes/ErrorDefinition.ts | 4 +- src/slang-nodes/ErrorParameter.ts | 8 +- src/slang-nodes/ErrorParameters.ts | 4 +- src/slang-nodes/ErrorParametersDeclaration.ts | 4 +- src/slang-nodes/EventDefinition.ts | 4 +- src/slang-nodes/EventParameter.ts | 8 +- src/slang-nodes/EventParameters.ts | 4 +- src/slang-nodes/EventParametersDeclaration.ts | 4 +- src/slang-nodes/ExperimentalFeature.ts | 4 +- src/slang-nodes/ExperimentalPragma.ts | 4 +- src/slang-nodes/ExponentiationExpression.ts | 6 +- src/slang-nodes/Expression.ts | 8 +- src/slang-nodes/ExpressionStatement.ts | 4 +- src/slang-nodes/FallbackFunctionAttribute.ts | 4 +- src/slang-nodes/FallbackFunctionAttributes.ts | 4 +- src/slang-nodes/FallbackFunctionDefinition.ts | 4 +- src/slang-nodes/ForStatement.ts | 8 +- src/slang-nodes/ForStatementCondition.ts | 4 +- src/slang-nodes/ForStatementInitialization.ts | 4 +- src/slang-nodes/FunctionAttribute.ts | 4 +- src/slang-nodes/FunctionAttributes.ts | 4 +- src/slang-nodes/FunctionBody.ts | 8 +- src/slang-nodes/FunctionCallExpression.ts | 4 +- src/slang-nodes/FunctionDefinition.ts | 4 +- src/slang-nodes/FunctionType.ts | 8 +- src/slang-nodes/HexStringLiteral.ts | 4 +- src/slang-nodes/HexStringLiterals.ts | 4 +- src/slang-nodes/IfStatement.ts | 8 +- src/slang-nodes/ImportClause.ts | 8 +- src/slang-nodes/ImportDeconstruction.ts | 4 +- .../ImportDeconstructionSymbols.ts | 4 +- src/slang-nodes/ImportDirective.ts | 4 +- src/slang-nodes/IndexAccessEnd.ts | 8 +- src/slang-nodes/IndexAccessExpression.ts | 4 +- src/slang-nodes/InheritanceSpecifier.ts | 4 +- src/slang-nodes/InheritanceType.ts | 4 +- src/slang-nodes/InheritanceTypes.ts | 4 +- src/slang-nodes/InterfaceDefinition.ts | 4 +- src/slang-nodes/InterfaceMembers.ts | 6 +- src/slang-nodes/LibraryDefinition.ts | 4 +- src/slang-nodes/LibraryMembers.ts | 10 ++- src/slang-nodes/MappingType.ts | 8 +- src/slang-nodes/MappingValue.ts | 8 +- src/slang-nodes/MemberAccessExpression.ts | 2 +- src/slang-nodes/ModifierDefinition.ts | 4 +- src/slang-nodes/ModifierInvocation.ts | 4 +- src/slang-nodes/MultiplicativeExpression.ts | 6 +- src/slang-nodes/NamedArgument.ts | 8 +- src/slang-nodes/NamedArgumentGroup.ts | 4 +- src/slang-nodes/NamedArguments.ts | 10 ++- src/slang-nodes/NamedArgumentsDeclaration.ts | 4 +- src/slang-nodes/NamedImport.ts | 8 +- src/slang-nodes/NewExpression.ts | 8 +- src/slang-nodes/OrExpression.ts | 10 ++- src/slang-nodes/OverridePaths.ts | 2 +- src/slang-nodes/OverridePathsDeclaration.ts | 2 +- src/slang-nodes/Parameter.ts | 8 +- src/slang-nodes/Parameters.ts | 8 +- src/slang-nodes/ParametersDeclaration.ts | 4 +- src/slang-nodes/PathImport.ts | 8 +- src/slang-nodes/PositionalArguments.ts | 4 +- .../PositionalArgumentsDeclaration.ts | 4 +- src/slang-nodes/PostfixExpression.ts | 4 +- src/slang-nodes/Pragma.ts | 8 +- src/slang-nodes/PragmaDirective.ts | 4 +- src/slang-nodes/PrefixExpression.ts | 4 +- src/slang-nodes/ReceiveFunctionAttribute.ts | 4 +- src/slang-nodes/ReceiveFunctionAttributes.ts | 4 +- src/slang-nodes/ReceiveFunctionDefinition.ts | 4 +- src/slang-nodes/ReturnStatement.ts | 8 +- src/slang-nodes/ReturnsDeclaration.ts | 4 +- src/slang-nodes/RevertStatement.ts | 4 +- src/slang-nodes/ShiftExpression.ts | 6 +- src/slang-nodes/SourceUnit.ts | 10 ++- src/slang-nodes/SourceUnitMember.ts | 4 +- src/slang-nodes/SourceUnitMembers.ts | 6 +- src/slang-nodes/StateVariableDefinition.ts | 4 +- .../StateVariableDefinitionValue.ts | 4 +- src/slang-nodes/Statement.ts | 8 +- src/slang-nodes/Statements.ts | 10 ++- src/slang-nodes/StringExpression.ts | 4 +- src/slang-nodes/StringLiteral.ts | 8 +- src/slang-nodes/StringLiterals.ts | 8 +- src/slang-nodes/StructDefinition.ts | 4 +- src/slang-nodes/StructMember.ts | 8 +- src/slang-nodes/StructMembers.ts | 8 +- src/slang-nodes/TryStatement.ts | 8 +- src/slang-nodes/TupleDeconstructionElement.ts | 4 +- .../TupleDeconstructionElements.ts | 4 +- .../TupleDeconstructionStatement.ts | 4 +- src/slang-nodes/TupleExpression.ts | 4 +- src/slang-nodes/TupleMember.ts | 8 +- src/slang-nodes/TupleValue.ts | 8 +- src/slang-nodes/TupleValues.ts | 8 +- src/slang-nodes/TypeExpression.ts | 10 ++- src/slang-nodes/TypeName.ts | 8 +- src/slang-nodes/TypedTupleMember.ts | 4 +- src/slang-nodes/UncheckedBlock.ts | 8 +- src/slang-nodes/UnicodeStringLiteral.ts | 4 +- src/slang-nodes/UnicodeStringLiterals.ts | 4 +- src/slang-nodes/UnnamedFunctionAttribute.ts | 4 +- src/slang-nodes/UnnamedFunctionAttributes.ts | 4 +- src/slang-nodes/UnnamedFunctionDefinition.ts | 4 +- src/slang-nodes/UntypedTupleMember.ts | 2 +- src/slang-nodes/UsingDeconstructionSymbols.ts | 4 +- src/slang-nodes/UsingDirective.ts | 8 +- src/slang-nodes/UsingTarget.ts | 8 +- .../VariableDeclarationStatement.ts | 4 +- src/slang-nodes/VariableDeclarationType.ts | 4 +- src/slang-nodes/VariableDeclarationValue.ts | 4 +- src/slang-nodes/VersionRange.ts | 2 +- src/slang-nodes/WhileStatement.ts | 8 +- src/slang-nodes/YulArguments.ts | 8 +- src/slang-nodes/YulBlock.ts | 8 +- src/slang-nodes/YulColonEqual.ts | 2 +- src/slang-nodes/YulDefaultCase.ts | 8 +- src/slang-nodes/YulExpression.ts | 8 +- src/slang-nodes/YulForStatement.ts | 4 +- src/slang-nodes/YulFunctionCallExpression.ts | 4 +- src/slang-nodes/YulFunctionDefinition.ts | 4 +- src/slang-nodes/YulIfStatement.ts | 8 +- src/slang-nodes/YulLeaveStatement.ts | 2 +- src/slang-nodes/YulLiteral.ts | 8 +- .../YulStackAssignmentStatement.ts | 6 +- src/slang-nodes/YulStatement.ts | 8 +- src/slang-nodes/YulStatements.ts | 10 ++- src/slang-nodes/YulSwitchCase.ts | 8 +- src/slang-nodes/YulSwitchCases.ts | 8 +- src/slang-nodes/YulSwitchStatement.ts | 4 +- src/slang-nodes/YulValueCase.ts | 8 +- .../YulVariableAssignmentStatement.ts | 4 +- .../YulVariableDeclarationStatement.ts | 4 +- .../YulVariableDeclarationValue.ts | 4 +- .../create-binary-operation-printer.ts | 4 +- src/slang-printers/print-logical-operation.ts | 2 +- .../print-preserving-empty-lines.ts | 2 +- src/slang-printers/print-string.ts | 3 +- src/slangParser.ts | 4 +- src/slangPrinter.ts | 2 +- tests/unit/prettier-version/esmock-plugin.js | 2 +- 174 files changed, 649 insertions(+), 400 deletions(-) rename src/{index.js => index.ts} (52%) diff --git a/src/index.js b/src/index.ts similarity index 52% rename from src/index.js rename to src/index.ts index 96b7bbe4a..cc7f1b363 100644 --- a/src/index.js +++ b/src/index.ts @@ -10,17 +10,23 @@ import slangPrint from './slangPrinter.js'; import { isComment, isBlockComment } from './slang-utils/is-comment.js'; import { locEnd, locStart } from './slang-utils/loc.js'; +import type { + Parser, + Printer, + RequiredOptions, + SupportLanguage +} from 'prettier'; +import type { AstNode, Comment } from './types.js'; + const parserName = 'slang'; const astFormat = 'slang-ast'; // https://prettier.io/docs/en/plugins.html#languages // https://github.com/ikatyang/linguist-languages/blob/master/data/Solidity.json -const languages = [ +const languages: SupportLanguage[] = [ { linguistLanguageId: 237469032, name: 'Solidity', - type: 'programming', - color: '#AA6746', aceMode: 'text', tmScope: 'source.solidity', extensions: ['.sol'], @@ -31,52 +37,58 @@ const languages = [ // https://prettier.io/docs/en/plugins.html#parsers const parser = { astFormat: 'solidity-ast', parse, ...loc }; -const slangParser = { +const slangParser: Parser = { astFormat, parse: slangParse, locStart, locEnd }; + const parsers = { 'solidity-parse': parser, [parserName]: slangParser }; -const canAttachComment = (node) => - node.type && node.type !== 'BlockComment' && node.type !== 'LineComment'; - -const slangCanAttachComment = (node) => node.kind && !isComment(node); +const canAttachComment = (node: { type: string }): boolean => + typeof node.type === 'string' && + node.type !== 'BlockComment' && + node.type !== 'LineComment'; +const slangCanAttachComment = (node: AstNode | Comment): boolean => + node.kind && !isComment(node); // https://prettier.io/docs/en/plugins.html#printers -const printers = { - 'solidity-ast': { - canAttachComment, - handleComments: { - ownLine: comments.solidityHandleOwnLineComment, - endOfLine: comments.solidityHandleEndOfLineComment, - remaining: comments.solidityHandleRemainingComment - }, - isBlockComment: comments.isBlockComment, - massageAstNode, - print, - printComment: comments.printComment +const printer = { + canAttachComment, + handleComments: { + ownLine: comments.solidityHandleOwnLineComment, + endOfLine: comments.solidityHandleEndOfLineComment, + remaining: comments.solidityHandleRemainingComment }, - [astFormat]: { - canAttachComment: slangCanAttachComment, - handleComments: { - ownLine: slangComments.slangHandleOwnLineComment, - endOfLine: slangComments.slangHandleEndOfLineComment, - remaining: slangComments.slangHandleRemainingComment - }, - isBlockComment, - massageAstNode, - print: slangPrint, - printComment: slangComments.printComment - } + isBlockComment: comments.isBlockComment, + massageAstNode, + print, + printComment: comments.printComment +}; +const slangPrinter: Printer = { + canAttachComment: slangCanAttachComment, + handleComments: { + ownLine: slangComments.slangHandleOwnLineComment, + endOfLine: slangComments.slangHandleEndOfLineComment, + remaining: slangComments.slangHandleRemainingComment + }, + isBlockComment, + massageAstNode, + print: slangPrint, + printComment: slangComments.printComment +}; + +const printers = { + 'solidity-ast': printer, + [astFormat]: slangPrinter }; // https://prettier.io/docs/en/plugins.html#defaultoptions -const defaultOptions = { +const defaultOptions: Partial = { bracketSpacing: false, tabWidth: 4 }; diff --git a/src/slang-comments/handler.ts b/src/slang-comments/handler.ts index 15b58e552..de7666a95 100644 --- a/src/slang-comments/handler.ts +++ b/src/slang-comments/handler.ts @@ -1,13 +1,13 @@ import handlers from './handlers/index.js'; -import type { AstPath, ParserOptions } from 'prettier'; -import type { Comment } from '../types.js'; +import type { ParserOptions } from 'prettier'; +import type { AstNode, Comment } from '../types.js'; export function slangHandleOwnLineComment( comment: Comment, text: string, - options: ParserOptions, - ast: AstPath, + options: ParserOptions, + ast: AstNode, isLastComment: boolean ): boolean { const { precedingNode, enclosingNode, followingNode } = comment; @@ -27,8 +27,8 @@ export function slangHandleOwnLineComment( export function slangHandleEndOfLineComment( comment: Comment, text: string, - options: ParserOptions, - ast: AstPath, + options: ParserOptions, + ast: AstNode, isLastComment: boolean ): boolean { const { precedingNode, enclosingNode, followingNode } = comment; @@ -48,8 +48,8 @@ export function slangHandleEndOfLineComment( export function slangHandleRemainingComment( comment: Comment, text: string, - options: ParserOptions, - ast: AstPath, + options: ParserOptions, + ast: AstNode, isLastComment: boolean ): boolean { const { precedingNode, enclosingNode, followingNode } = comment; diff --git a/src/slang-nodes/AdditiveExpression.ts b/src/slang-nodes/AdditiveExpression.ts index fe52262ce..0db8e6715 100644 --- a/src/slang-nodes/AdditiveExpression.ts +++ b/src/slang-nodes/AdditiveExpression.ts @@ -6,7 +6,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const tryToHug = createHugFunction(['%']); @@ -26,7 +26,7 @@ export class AdditiveExpression implements SlangNode { constructor( ast: ast.AdditiveExpression, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; @@ -47,7 +47,7 @@ export class AdditiveExpression implements SlangNode { print( path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions ): Doc { return printBinaryOperation(this, path, print, options); } diff --git a/src/slang-nodes/AndExpression.ts b/src/slang-nodes/AndExpression.ts index 7f2bd6593..b7eac5664 100644 --- a/src/slang-nodes/AndExpression.ts +++ b/src/slang-nodes/AndExpression.ts @@ -5,7 +5,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class AndExpression implements SlangNode { readonly kind = NonterminalKind.AndExpression; @@ -20,7 +20,11 @@ export class AndExpression implements SlangNode { rightOperand: Expression; - constructor(ast: ast.AndExpression, offset: number, options: ParserOptions) { + constructor( + ast: ast.AndExpression, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; @@ -37,7 +41,7 @@ export class AndExpression implements SlangNode { print( path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions ): Doc { return printLogicalOperation(this, path, print, options); } diff --git a/src/slang-nodes/ArgumentsDeclaration.ts b/src/slang-nodes/ArgumentsDeclaration.ts index 94743a357..b665b1411 100644 --- a/src/slang-nodes/ArgumentsDeclaration.ts +++ b/src/slang-nodes/ArgumentsDeclaration.ts @@ -5,7 +5,7 @@ import { NamedArgumentsDeclaration } from './NamedArgumentsDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class ArgumentsDeclaration implements SlangNode { readonly kind = NonterminalKind.ArgumentsDeclaration; @@ -19,7 +19,7 @@ export class ArgumentsDeclaration implements SlangNode { constructor( ast: ast.ArgumentsDeclaration, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/ArrayExpression.ts b/src/slang-nodes/ArrayExpression.ts index 8c2f901db..8768565d1 100644 --- a/src/slang-nodes/ArrayExpression.ts +++ b/src/slang-nodes/ArrayExpression.ts @@ -5,7 +5,7 @@ import { ArrayValues } from './ArrayValues.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { group } = doc.builders; @@ -25,7 +25,7 @@ export class ArrayExpression implements SlangNode { constructor( ast: ast.ArrayExpression, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/ArrayTypeName.ts b/src/slang-nodes/ArrayTypeName.ts index 69568fc69..00b9004b8 100644 --- a/src/slang-nodes/ArrayTypeName.ts +++ b/src/slang-nodes/ArrayTypeName.ts @@ -5,7 +5,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class ArrayTypeName implements SlangNode { readonly kind = NonterminalKind.ArrayTypeName; @@ -22,7 +22,11 @@ export class ArrayTypeName implements SlangNode { closeBracket: string; - constructor(ast: ast.ArrayTypeName, offset: number, options: ParserOptions) { + constructor( + ast: ast.ArrayTypeName, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/ArrayValues.ts b/src/slang-nodes/ArrayValues.ts index cea5e6561..b62c15903 100644 --- a/src/slang-nodes/ArrayValues.ts +++ b/src/slang-nodes/ArrayValues.ts @@ -5,7 +5,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class ArrayValues implements SlangNode { readonly kind = NonterminalKind.ArrayValues; @@ -18,7 +18,11 @@ export class ArrayValues implements SlangNode { separators: string[]; - constructor(ast: ast.ArrayValues, offset: number, options: ParserOptions) { + constructor( + ast: ast.ArrayValues, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/AssemblyFlags.ts b/src/slang-nodes/AssemblyFlags.ts index 0445bed74..73d1bfef6 100644 --- a/src/slang-nodes/AssemblyFlags.ts +++ b/src/slang-nodes/AssemblyFlags.ts @@ -5,7 +5,7 @@ import { StringLiteral } from './StringLiteral.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class AssemblyFlags implements SlangNode { readonly kind = NonterminalKind.AssemblyFlags; @@ -18,7 +18,11 @@ export class AssemblyFlags implements SlangNode { separators: string[]; - constructor(ast: ast.AssemblyFlags, offset: number, options: ParserOptions) { + constructor( + ast: ast.AssemblyFlags, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/AssemblyFlagsDeclaration.ts b/src/slang-nodes/AssemblyFlagsDeclaration.ts index bee431d61..887ab2b4c 100644 --- a/src/slang-nodes/AssemblyFlagsDeclaration.ts +++ b/src/slang-nodes/AssemblyFlagsDeclaration.ts @@ -4,7 +4,7 @@ import { AssemblyFlags } from './AssemblyFlags.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class AssemblyFlagsDeclaration implements SlangNode { readonly kind = NonterminalKind.AssemblyFlagsDeclaration; @@ -22,7 +22,7 @@ export class AssemblyFlagsDeclaration implements SlangNode { constructor( ast: ast.AssemblyFlagsDeclaration, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/AssemblyStatement.ts b/src/slang-nodes/AssemblyStatement.ts index dd8e1f14f..6a0785dc5 100644 --- a/src/slang-nodes/AssemblyStatement.ts +++ b/src/slang-nodes/AssemblyStatement.ts @@ -6,7 +6,7 @@ import { YulBlock } from './YulBlock.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class AssemblyStatement implements SlangNode { readonly kind = NonterminalKind.AssemblyStatement; @@ -26,7 +26,7 @@ export class AssemblyStatement implements SlangNode { constructor( ast: ast.AssemblyStatement, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/AssignmentExpression.ts b/src/slang-nodes/AssignmentExpression.ts index c5827d1e1..6d564f9cf 100644 --- a/src/slang-nodes/AssignmentExpression.ts +++ b/src/slang-nodes/AssignmentExpression.ts @@ -6,7 +6,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { group, indent, line } = doc.builders; @@ -26,7 +26,7 @@ export class AssignmentExpression implements SlangNode { constructor( ast: ast.AssignmentExpression, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/BitwiseAndExpression.ts b/src/slang-nodes/BitwiseAndExpression.ts index 0d0b9296c..2f06355f1 100644 --- a/src/slang-nodes/BitwiseAndExpression.ts +++ b/src/slang-nodes/BitwiseAndExpression.ts @@ -6,7 +6,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const tryToHug = createHugFunction(['+', '-', '*', '/', '**', '<<', '>>']); @@ -26,7 +26,7 @@ export class BitwiseAndExpression implements SlangNode { constructor( ast: ast.BitwiseAndExpression, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; @@ -47,7 +47,7 @@ export class BitwiseAndExpression implements SlangNode { print( path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions ): Doc { return printBinaryOperation(this, path, print, options); } diff --git a/src/slang-nodes/BitwiseOrExpression.ts b/src/slang-nodes/BitwiseOrExpression.ts index cb4d92bbe..a1e96aa43 100644 --- a/src/slang-nodes/BitwiseOrExpression.ts +++ b/src/slang-nodes/BitwiseOrExpression.ts @@ -6,7 +6,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const tryToHug = createHugFunction([ '+', @@ -36,7 +36,7 @@ export class BitwiseOrExpression implements SlangNode { constructor( ast: ast.BitwiseOrExpression, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; @@ -57,7 +57,7 @@ export class BitwiseOrExpression implements SlangNode { print( path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions ): Doc { return printBinaryOperation(this, path, print, options); } diff --git a/src/slang-nodes/BitwiseXorExpression.ts b/src/slang-nodes/BitwiseXorExpression.ts index a25c48e4e..eca9020a4 100644 --- a/src/slang-nodes/BitwiseXorExpression.ts +++ b/src/slang-nodes/BitwiseXorExpression.ts @@ -6,7 +6,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const tryToHug = createHugFunction(['+', '-', '*', '/', '**', '<<', '>>', '&']); @@ -26,7 +26,7 @@ export class BitwiseXorExpression implements SlangNode { constructor( ast: ast.BitwiseXorExpression, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; @@ -47,7 +47,7 @@ export class BitwiseXorExpression implements SlangNode { print( path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions ): Doc { return printBinaryOperation(this, path, print, options); } diff --git a/src/slang-nodes/Block.ts b/src/slang-nodes/Block.ts index c3624dea2..cd8ac0b6d 100644 --- a/src/slang-nodes/Block.ts +++ b/src/slang-nodes/Block.ts @@ -4,7 +4,7 @@ import { Statements } from './Statements.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class Block implements SlangNode { readonly kind = NonterminalKind.Block; @@ -19,7 +19,7 @@ export class Block implements SlangNode { closeBrace: string; - constructor(ast: ast.Block, offset: number, options: ParserOptions) { + constructor(ast: ast.Block, offset: number, options: ParserOptions) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/CallOptions.ts b/src/slang-nodes/CallOptions.ts index ede3c57db..f6e39fc9d 100644 --- a/src/slang-nodes/CallOptions.ts +++ b/src/slang-nodes/CallOptions.ts @@ -6,7 +6,7 @@ import { NamedArgument } from './NamedArgument.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { line, softline } = doc.builders; @@ -21,7 +21,11 @@ export class CallOptions implements SlangNode { separators: string[]; - constructor(ast: ast.CallOptions, offset: number, options: ParserOptions) { + constructor( + ast: ast.CallOptions, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; @@ -39,7 +43,7 @@ export class CallOptions implements SlangNode { print( path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions ): Doc { return printSeparatedList(path.map(print, 'items'), { firstSeparator: options.bracketSpacing ? line : softline diff --git a/src/slang-nodes/CallOptionsExpression.ts b/src/slang-nodes/CallOptionsExpression.ts index ec77d4fa6..d9b12732f 100644 --- a/src/slang-nodes/CallOptionsExpression.ts +++ b/src/slang-nodes/CallOptionsExpression.ts @@ -5,7 +5,7 @@ import { CallOptions } from './CallOptions.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class CallOptionsExpression implements SlangNode { readonly kind = NonterminalKind.CallOptionsExpression; @@ -25,7 +25,7 @@ export class CallOptionsExpression implements SlangNode { constructor( ast: ast.CallOptionsExpression, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/CatchClause.ts b/src/slang-nodes/CatchClause.ts index 38410e6e4..24bb281b7 100644 --- a/src/slang-nodes/CatchClause.ts +++ b/src/slang-nodes/CatchClause.ts @@ -5,7 +5,7 @@ import { Block } from './Block.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class CatchClause implements SlangNode { readonly kind = NonterminalKind.CatchClause; @@ -20,7 +20,11 @@ export class CatchClause implements SlangNode { body: Block; - constructor(ast: ast.CatchClause, offset: number, options: ParserOptions) { + constructor( + ast: ast.CatchClause, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/CatchClauseError.ts b/src/slang-nodes/CatchClauseError.ts index 6cfc45656..aa2fad0cb 100644 --- a/src/slang-nodes/CatchClauseError.ts +++ b/src/slang-nodes/CatchClauseError.ts @@ -5,7 +5,7 @@ import { ParametersDeclaration } from './ParametersDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { group } = doc.builders; @@ -23,7 +23,7 @@ export class CatchClauseError implements SlangNode { constructor( ast: ast.CatchClauseError, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/CatchClauses.ts b/src/slang-nodes/CatchClauses.ts index 71c3ae068..b1bf0e2c1 100644 --- a/src/slang-nodes/CatchClauses.ts +++ b/src/slang-nodes/CatchClauses.ts @@ -5,7 +5,7 @@ import { CatchClause } from './CatchClause.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { join } = doc.builders; @@ -18,7 +18,11 @@ export class CatchClauses implements SlangNode { items: CatchClause[]; - constructor(ast: ast.CatchClauses, offset: number, options: ParserOptions) { + constructor( + ast: ast.CatchClauses, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/ComparisonExpression.ts b/src/slang-nodes/ComparisonExpression.ts index fb1252cdd..ed0ad2320 100644 --- a/src/slang-nodes/ComparisonExpression.ts +++ b/src/slang-nodes/ComparisonExpression.ts @@ -5,7 +5,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class ComparisonExpression implements SlangNode { readonly kind = NonterminalKind.ComparisonExpression; @@ -23,7 +23,7 @@ export class ComparisonExpression implements SlangNode { constructor( ast: ast.ComparisonExpression, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; @@ -41,7 +41,7 @@ export class ComparisonExpression implements SlangNode { print( path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions ): Doc { return printComparisonOperation(this, path, print, options); } diff --git a/src/slang-nodes/ConditionalExpression.ts b/src/slang-nodes/ConditionalExpression.ts index 4d1d8e640..eaaf8d3f8 100644 --- a/src/slang-nodes/ConditionalExpression.ts +++ b/src/slang-nodes/ConditionalExpression.ts @@ -15,7 +15,7 @@ function experimentalTernaries( node: ConditionalExpression, path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions ): Doc { const grandparent = path.getNode(2) as AstNode; const isNested = grandparent.kind === NonterminalKind.ConditionalExpression; @@ -128,7 +128,7 @@ export class ConditionalExpression implements SlangNode { constructor( ast: ast.ConditionalExpression, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; @@ -178,7 +178,7 @@ export class ConditionalExpression implements SlangNode { print( path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions ): Doc { return options.experimentalTernaries ? experimentalTernaries(this, path, print, options) diff --git a/src/slang-nodes/ConstantDefinition.ts b/src/slang-nodes/ConstantDefinition.ts index 0556b9088..36fd5f325 100644 --- a/src/slang-nodes/ConstantDefinition.ts +++ b/src/slang-nodes/ConstantDefinition.ts @@ -5,7 +5,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { /*AstPath,*/ Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class ConstantDefinition implements SlangNode { readonly kind = NonterminalKind.ConstantDefinition; @@ -29,7 +29,7 @@ export class ConstantDefinition implements SlangNode { constructor( ast: ast.ConstantDefinition, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; @@ -51,7 +51,7 @@ export class ConstantDefinition implements SlangNode { print(/* path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions */): Doc { return ['TODO: ConstantDefinition']; } diff --git a/src/slang-nodes/ConstructorAttribute.ts b/src/slang-nodes/ConstructorAttribute.ts index f0dfe7c22..f0c724af3 100644 --- a/src/slang-nodes/ConstructorAttribute.ts +++ b/src/slang-nodes/ConstructorAttribute.ts @@ -5,7 +5,7 @@ import { ModifierInvocation } from './ModifierInvocation.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class ConstructorAttribute implements SlangNode { readonly kind = NonterminalKind.ConstructorAttribute; @@ -19,7 +19,7 @@ export class ConstructorAttribute implements SlangNode { constructor( ast: ast.ConstructorAttribute, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/ConstructorAttributes.ts b/src/slang-nodes/ConstructorAttributes.ts index 31bde7929..a81c04a27 100644 --- a/src/slang-nodes/ConstructorAttributes.ts +++ b/src/slang-nodes/ConstructorAttributes.ts @@ -6,7 +6,7 @@ import { ConstructorAttribute } from './ConstructorAttribute.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { line } = doc.builders; @@ -22,7 +22,7 @@ export class ConstructorAttributes implements SlangNode { constructor( ast: ast.ConstructorAttributes, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/ConstructorDefinition.ts b/src/slang-nodes/ConstructorDefinition.ts index 4d78b4276..e9ced9528 100644 --- a/src/slang-nodes/ConstructorDefinition.ts +++ b/src/slang-nodes/ConstructorDefinition.ts @@ -7,7 +7,7 @@ import { Block } from './Block.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class ConstructorDefinition implements SlangNode { readonly kind = NonterminalKind.ConstructorDefinition; @@ -27,7 +27,7 @@ export class ConstructorDefinition implements SlangNode { constructor( ast: ast.ConstructorDefinition, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/ContractDefinition.ts b/src/slang-nodes/ContractDefinition.ts index d4d26b260..41171a6ab 100644 --- a/src/slang-nodes/ContractDefinition.ts +++ b/src/slang-nodes/ContractDefinition.ts @@ -8,7 +8,7 @@ import { ContractMembers } from './ContractMembers.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { group, line } = doc.builders; @@ -36,7 +36,7 @@ export class ContractDefinition implements SlangNode { constructor( ast: ast.ContractDefinition, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; @@ -65,7 +65,7 @@ export class ContractDefinition implements SlangNode { this.cleanModifierInvocationArguments(options); } - cleanModifierInvocationArguments(options: ParserOptions): void { + cleanModifierInvocationArguments(options: ParserOptions): void { // Older versions of Solidity defined a constructor as a function having // the same name as the contract. const compiler = coerce(options.compiler); diff --git a/src/slang-nodes/ContractMember.ts b/src/slang-nodes/ContractMember.ts index 5cafdcbcd..4eeb04a19 100644 --- a/src/slang-nodes/ContractMember.ts +++ b/src/slang-nodes/ContractMember.ts @@ -16,7 +16,7 @@ import { UserDefinedValueTypeDefinition } from './UserDefinedValueTypeDefinition import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class ContractMember implements SlangNode { readonly kind = NonterminalKind.ContractMember; @@ -40,7 +40,11 @@ export class ContractMember implements SlangNode { | ErrorDefinition | UserDefinedValueTypeDefinition; - constructor(ast: ast.ContractMember, offset: number, options: ParserOptions) { + constructor( + ast: ast.ContractMember, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/ContractMembers.ts b/src/slang-nodes/ContractMembers.ts index 6d2f315e9..722b36786 100644 --- a/src/slang-nodes/ContractMembers.ts +++ b/src/slang-nodes/ContractMembers.ts @@ -8,7 +8,7 @@ import { ContractMember } from './ContractMember.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { hardline } = doc.builders; @@ -24,7 +24,7 @@ export class ContractMembers implements SlangNode { constructor( ast: ast.ContractMembers, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; @@ -42,7 +42,7 @@ export class ContractMembers implements SlangNode { print( path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions ): Doc { return this.items.length === 0 && (!this.comments || this.comments.length === 0) diff --git a/src/slang-nodes/DoWhileStatement.ts b/src/slang-nodes/DoWhileStatement.ts index 72f193489..15c7e5ba7 100644 --- a/src/slang-nodes/DoWhileStatement.ts +++ b/src/slang-nodes/DoWhileStatement.ts @@ -7,7 +7,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { group, indent, line } = doc.builders; @@ -35,7 +35,7 @@ export class DoWhileStatement implements SlangNode { constructor( ast: ast.DoWhileStatement, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/ElseBranch.ts b/src/slang-nodes/ElseBranch.ts index 57ee23a75..bcfce5421 100644 --- a/src/slang-nodes/ElseBranch.ts +++ b/src/slang-nodes/ElseBranch.ts @@ -6,7 +6,7 @@ import { Statement } from './Statement.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { group, indent, line } = doc.builders; @@ -26,7 +26,11 @@ export class ElseBranch implements SlangNode { body: Statement; - constructor(ast: ast.ElseBranch, offset: number, options: ParserOptions) { + constructor( + ast: ast.ElseBranch, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/EmitStatement.ts b/src/slang-nodes/EmitStatement.ts index 4253e3f35..2af41983c 100644 --- a/src/slang-nodes/EmitStatement.ts +++ b/src/slang-nodes/EmitStatement.ts @@ -5,7 +5,7 @@ import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class EmitStatement implements SlangNode { readonly kind = NonterminalKind.EmitStatement; @@ -22,7 +22,11 @@ export class EmitStatement implements SlangNode { semicolon: string; - constructor(ast: ast.EmitStatement, offset: number, options: ParserOptions) { + constructor( + ast: ast.EmitStatement, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/EqualityExpression.ts b/src/slang-nodes/EqualityExpression.ts index 0ebb5433e..9b9907f25 100644 --- a/src/slang-nodes/EqualityExpression.ts +++ b/src/slang-nodes/EqualityExpression.ts @@ -5,7 +5,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class EqualityExpression implements SlangNode { readonly kind = NonterminalKind.EqualityExpression; @@ -23,7 +23,7 @@ export class EqualityExpression implements SlangNode { constructor( ast: ast.EqualityExpression, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; @@ -41,7 +41,7 @@ export class EqualityExpression implements SlangNode { print( path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions ): Doc { return printComparisonOperation(this, path, print, options); } diff --git a/src/slang-nodes/ErrorDefinition.ts b/src/slang-nodes/ErrorDefinition.ts index 92e6bff2c..90d5350b6 100644 --- a/src/slang-nodes/ErrorDefinition.ts +++ b/src/slang-nodes/ErrorDefinition.ts @@ -4,7 +4,7 @@ import { ErrorParametersDeclaration } from './ErrorParametersDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class ErrorDefinition implements SlangNode { readonly kind = NonterminalKind.ErrorDefinition; @@ -24,7 +24,7 @@ export class ErrorDefinition implements SlangNode { constructor( ast: ast.ErrorDefinition, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/ErrorParameter.ts b/src/slang-nodes/ErrorParameter.ts index 089c98133..0984d537b 100644 --- a/src/slang-nodes/ErrorParameter.ts +++ b/src/slang-nodes/ErrorParameter.ts @@ -4,7 +4,7 @@ import { TypeName } from './TypeName.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class ErrorParameter implements SlangNode { readonly kind = NonterminalKind.ErrorParameter; @@ -17,7 +17,11 @@ export class ErrorParameter implements SlangNode { name?: string; - constructor(ast: ast.ErrorParameter, offset: number, options: ParserOptions) { + constructor( + ast: ast.ErrorParameter, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/ErrorParameters.ts b/src/slang-nodes/ErrorParameters.ts index 1c8666e97..c359285b4 100644 --- a/src/slang-nodes/ErrorParameters.ts +++ b/src/slang-nodes/ErrorParameters.ts @@ -5,7 +5,7 @@ import { ErrorParameter } from './ErrorParameter.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class ErrorParameters implements SlangNode { readonly kind = NonterminalKind.ErrorParameters; @@ -21,7 +21,7 @@ export class ErrorParameters implements SlangNode { constructor( ast: ast.ErrorParameters, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/ErrorParametersDeclaration.ts b/src/slang-nodes/ErrorParametersDeclaration.ts index 248ab8dd1..2c9176d23 100644 --- a/src/slang-nodes/ErrorParametersDeclaration.ts +++ b/src/slang-nodes/ErrorParametersDeclaration.ts @@ -4,7 +4,7 @@ import { ErrorParameters } from './ErrorParameters.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class ErrorParametersDeclaration implements SlangNode { readonly kind = NonterminalKind.ErrorParametersDeclaration; @@ -22,7 +22,7 @@ export class ErrorParametersDeclaration implements SlangNode { constructor( ast: ast.ErrorParametersDeclaration, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/EventDefinition.ts b/src/slang-nodes/EventDefinition.ts index 77ee8e962..8086b63c6 100644 --- a/src/slang-nodes/EventDefinition.ts +++ b/src/slang-nodes/EventDefinition.ts @@ -4,7 +4,7 @@ import { EventParametersDeclaration } from './EventParametersDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class EventDefinition implements SlangNode { readonly kind = NonterminalKind.EventDefinition; @@ -26,7 +26,7 @@ export class EventDefinition implements SlangNode { constructor( ast: ast.EventDefinition, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/EventParameter.ts b/src/slang-nodes/EventParameter.ts index 1a1f40ebf..13e9891ae 100644 --- a/src/slang-nodes/EventParameter.ts +++ b/src/slang-nodes/EventParameter.ts @@ -4,7 +4,7 @@ import { TypeName } from './TypeName.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class EventParameter implements SlangNode { readonly kind = NonterminalKind.EventParameter; @@ -19,7 +19,11 @@ export class EventParameter implements SlangNode { name?: string; - constructor(ast: ast.EventParameter, offset: number, options: ParserOptions) { + constructor( + ast: ast.EventParameter, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/EventParameters.ts b/src/slang-nodes/EventParameters.ts index 67455fb8b..d2f150d61 100644 --- a/src/slang-nodes/EventParameters.ts +++ b/src/slang-nodes/EventParameters.ts @@ -5,7 +5,7 @@ import { EventParameter } from './EventParameter.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class EventParameters implements SlangNode { readonly kind = NonterminalKind.EventParameters; @@ -21,7 +21,7 @@ export class EventParameters implements SlangNode { constructor( ast: ast.EventParameters, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/EventParametersDeclaration.ts b/src/slang-nodes/EventParametersDeclaration.ts index e3cf1782d..a79fe8115 100644 --- a/src/slang-nodes/EventParametersDeclaration.ts +++ b/src/slang-nodes/EventParametersDeclaration.ts @@ -4,7 +4,7 @@ import { EventParameters } from './EventParameters.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class EventParametersDeclaration implements SlangNode { readonly kind = NonterminalKind.EventParametersDeclaration; @@ -22,7 +22,7 @@ export class EventParametersDeclaration implements SlangNode { constructor( ast: ast.EventParametersDeclaration, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/ExperimentalFeature.ts b/src/slang-nodes/ExperimentalFeature.ts index fe3394a96..67b789e1b 100644 --- a/src/slang-nodes/ExperimentalFeature.ts +++ b/src/slang-nodes/ExperimentalFeature.ts @@ -5,7 +5,7 @@ import { StringLiteral } from './StringLiteral.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class ExperimentalFeature implements SlangNode { readonly kind = NonterminalKind.ExperimentalFeature; @@ -19,7 +19,7 @@ export class ExperimentalFeature implements SlangNode { constructor( ast: ast.ExperimentalFeature, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/ExperimentalPragma.ts b/src/slang-nodes/ExperimentalPragma.ts index 9e920c234..b70e0c2b2 100644 --- a/src/slang-nodes/ExperimentalPragma.ts +++ b/src/slang-nodes/ExperimentalPragma.ts @@ -4,7 +4,7 @@ import { ExperimentalFeature } from './ExperimentalFeature.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class ExperimentalPragma implements SlangNode { readonly kind = NonterminalKind.ExperimentalPragma; @@ -20,7 +20,7 @@ export class ExperimentalPragma implements SlangNode { constructor( ast: ast.ExperimentalPragma, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/ExponentiationExpression.ts b/src/slang-nodes/ExponentiationExpression.ts index 949c39fa0..1a24e9c2e 100644 --- a/src/slang-nodes/ExponentiationExpression.ts +++ b/src/slang-nodes/ExponentiationExpression.ts @@ -12,7 +12,7 @@ import { TupleValue } from './TupleValue.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { group, indent } = doc.builders; @@ -49,7 +49,7 @@ export class ExponentiationExpression implements SlangNode { constructor( ast: ast.ExponentiationExpression, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; @@ -177,7 +177,7 @@ export class ExponentiationExpression implements SlangNode { print( path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions ): Doc { return printExponentiationExpression(this, path, print, options); } diff --git a/src/slang-nodes/Expression.ts b/src/slang-nodes/Expression.ts index d6398a645..b0e18348f 100644 --- a/src/slang-nodes/Expression.ts +++ b/src/slang-nodes/Expression.ts @@ -31,7 +31,7 @@ import { ElementaryType } from './ElementaryType.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class Expression implements SlangNode { readonly kind = NonterminalKind.Expression; @@ -70,7 +70,11 @@ export class Expression implements SlangNode { | ElementaryType | string; - constructor(ast: ast.Expression, offset: number, options: ParserOptions) { + constructor( + ast: ast.Expression, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/ExpressionStatement.ts b/src/slang-nodes/ExpressionStatement.ts index 1c252cfa1..70205558b 100644 --- a/src/slang-nodes/ExpressionStatement.ts +++ b/src/slang-nodes/ExpressionStatement.ts @@ -4,7 +4,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class ExpressionStatement implements SlangNode { readonly kind = NonterminalKind.ExpressionStatement; @@ -20,7 +20,7 @@ export class ExpressionStatement implements SlangNode { constructor( ast: ast.ExpressionStatement, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/FallbackFunctionAttribute.ts b/src/slang-nodes/FallbackFunctionAttribute.ts index 6c38d1576..c9cb80670 100644 --- a/src/slang-nodes/FallbackFunctionAttribute.ts +++ b/src/slang-nodes/FallbackFunctionAttribute.ts @@ -6,7 +6,7 @@ import { OverrideSpecifier } from './OverrideSpecifier.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class FallbackFunctionAttribute implements SlangNode { readonly kind = NonterminalKind.FallbackFunctionAttribute; @@ -20,7 +20,7 @@ export class FallbackFunctionAttribute implements SlangNode { constructor( ast: ast.FallbackFunctionAttribute, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/FallbackFunctionAttributes.ts b/src/slang-nodes/FallbackFunctionAttributes.ts index f6b80bb00..307d677d1 100644 --- a/src/slang-nodes/FallbackFunctionAttributes.ts +++ b/src/slang-nodes/FallbackFunctionAttributes.ts @@ -6,7 +6,7 @@ import { FallbackFunctionAttribute } from './FallbackFunctionAttribute.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { line } = doc.builders; @@ -22,7 +22,7 @@ export class FallbackFunctionAttributes implements SlangNode { constructor( ast: ast.FallbackFunctionAttributes, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/FallbackFunctionDefinition.ts b/src/slang-nodes/FallbackFunctionDefinition.ts index 742b2dbfb..95ad376e4 100644 --- a/src/slang-nodes/FallbackFunctionDefinition.ts +++ b/src/slang-nodes/FallbackFunctionDefinition.ts @@ -8,7 +8,7 @@ import { FunctionBody } from './FunctionBody.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class FallbackFunctionDefinition implements SlangNode { readonly kind = NonterminalKind.FallbackFunctionDefinition; @@ -30,7 +30,7 @@ export class FallbackFunctionDefinition implements SlangNode { constructor( ast: ast.FallbackFunctionDefinition, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/ForStatement.ts b/src/slang-nodes/ForStatement.ts index 5591359f5..ec1c93c08 100644 --- a/src/slang-nodes/ForStatement.ts +++ b/src/slang-nodes/ForStatement.ts @@ -9,7 +9,7 @@ import { Statement } from './Statement.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { group, indent, line } = doc.builders; @@ -34,7 +34,11 @@ export class ForStatement implements SlangNode { body: Statement; - constructor(ast: ast.ForStatement, offset: number, options: ParserOptions) { + constructor( + ast: ast.ForStatement, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/ForStatementCondition.ts b/src/slang-nodes/ForStatementCondition.ts index d783cc4c5..51aa111ad 100644 --- a/src/slang-nodes/ForStatementCondition.ts +++ b/src/slang-nodes/ForStatementCondition.ts @@ -5,7 +5,7 @@ import { ExpressionStatement } from './ExpressionStatement.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class ForStatementCondition implements SlangNode { readonly kind = NonterminalKind.ForStatementCondition; @@ -19,7 +19,7 @@ export class ForStatementCondition implements SlangNode { constructor( ast: ast.ForStatementCondition, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/ForStatementInitialization.ts b/src/slang-nodes/ForStatementInitialization.ts index 996b5b71b..e23954c9e 100644 --- a/src/slang-nodes/ForStatementInitialization.ts +++ b/src/slang-nodes/ForStatementInitialization.ts @@ -7,7 +7,7 @@ import { TupleDeconstructionStatement } from './TupleDeconstructionStatement.js' import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class ForStatementInitialization implements SlangNode { readonly kind = NonterminalKind.ForStatementInitialization; @@ -25,7 +25,7 @@ export class ForStatementInitialization implements SlangNode { constructor( ast: ast.ForStatementInitialization, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/FunctionAttribute.ts b/src/slang-nodes/FunctionAttribute.ts index f0a0ada00..ce3c36756 100644 --- a/src/slang-nodes/FunctionAttribute.ts +++ b/src/slang-nodes/FunctionAttribute.ts @@ -6,7 +6,7 @@ import { OverrideSpecifier } from './OverrideSpecifier.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class FunctionAttribute implements SlangNode { readonly kind = NonterminalKind.FunctionAttribute; @@ -20,7 +20,7 @@ export class FunctionAttribute implements SlangNode { constructor( ast: ast.FunctionAttribute, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/FunctionAttributes.ts b/src/slang-nodes/FunctionAttributes.ts index 8beecf94c..cfae7e547 100644 --- a/src/slang-nodes/FunctionAttributes.ts +++ b/src/slang-nodes/FunctionAttributes.ts @@ -6,7 +6,7 @@ import { FunctionAttribute } from './FunctionAttribute.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { line } = doc.builders; @@ -22,7 +22,7 @@ export class FunctionAttributes implements SlangNode { constructor( ast: ast.FunctionAttributes, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/FunctionBody.ts b/src/slang-nodes/FunctionBody.ts index 606a9a472..4bc48d4c2 100644 --- a/src/slang-nodes/FunctionBody.ts +++ b/src/slang-nodes/FunctionBody.ts @@ -5,7 +5,7 @@ import { Block } from './Block.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class FunctionBody implements SlangNode { readonly kind = NonterminalKind.FunctionBody; @@ -16,7 +16,11 @@ export class FunctionBody implements SlangNode { variant: Block | string; - constructor(ast: ast.FunctionBody, offset: number, options: ParserOptions) { + constructor( + ast: ast.FunctionBody, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/FunctionCallExpression.ts b/src/slang-nodes/FunctionCallExpression.ts index 3ce450d7d..78d6149ee 100644 --- a/src/slang-nodes/FunctionCallExpression.ts +++ b/src/slang-nodes/FunctionCallExpression.ts @@ -7,7 +7,7 @@ import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { group, indentIfBreak, label } = doc.builders; @@ -25,7 +25,7 @@ export class FunctionCallExpression implements SlangNode { constructor( ast: ast.FunctionCallExpression, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/FunctionDefinition.ts b/src/slang-nodes/FunctionDefinition.ts index d36e757bc..d5428e7e0 100644 --- a/src/slang-nodes/FunctionDefinition.ts +++ b/src/slang-nodes/FunctionDefinition.ts @@ -11,7 +11,7 @@ import { FunctionBody } from './FunctionBody.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class FunctionDefinition implements SlangNode { readonly kind = NonterminalKind.FunctionDefinition; @@ -35,7 +35,7 @@ export class FunctionDefinition implements SlangNode { constructor( ast: ast.FunctionDefinition, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/FunctionType.ts b/src/slang-nodes/FunctionType.ts index cac1ef941..9ea4d826b 100644 --- a/src/slang-nodes/FunctionType.ts +++ b/src/slang-nodes/FunctionType.ts @@ -7,7 +7,7 @@ import { ReturnsDeclaration } from './ReturnsDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class FunctionType implements SlangNode { readonly kind = NonterminalKind.FunctionType; @@ -24,7 +24,11 @@ export class FunctionType implements SlangNode { returns?: ReturnsDeclaration; - constructor(ast: ast.FunctionType, offset: number, options: ParserOptions) { + constructor( + ast: ast.FunctionType, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/HexStringLiteral.ts b/src/slang-nodes/HexStringLiteral.ts index d59234ffe..460955253 100644 --- a/src/slang-nodes/HexStringLiteral.ts +++ b/src/slang-nodes/HexStringLiteral.ts @@ -4,7 +4,7 @@ import { getNodeMetadata } from '../slang-utils/metadata.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class HexStringLiteral implements SlangNode { readonly kind = NonterminalKind.HexStringLiteral; @@ -18,7 +18,7 @@ export class HexStringLiteral implements SlangNode { constructor( ast: ast.HexStringLiteral, offset: number, - options: ParserOptions + options: ParserOptions ) { const metadata = getNodeMetadata(ast, offset); diff --git a/src/slang-nodes/HexStringLiterals.ts b/src/slang-nodes/HexStringLiterals.ts index 561c7649f..8bceec27b 100644 --- a/src/slang-nodes/HexStringLiterals.ts +++ b/src/slang-nodes/HexStringLiterals.ts @@ -5,7 +5,7 @@ import { HexStringLiteral } from './HexStringLiteral.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { join, hardline } = doc.builders; @@ -21,7 +21,7 @@ export class HexStringLiterals implements SlangNode { constructor( ast: ast.HexStringLiterals, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/IfStatement.ts b/src/slang-nodes/IfStatement.ts index 0cc55f33b..026959243 100644 --- a/src/slang-nodes/IfStatement.ts +++ b/src/slang-nodes/IfStatement.ts @@ -8,7 +8,7 @@ import { ElseBranch } from './ElseBranch.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { group, hardline, indent, line } = doc.builders; @@ -31,7 +31,11 @@ export class IfStatement implements SlangNode { elseBranch?: ElseBranch; - constructor(ast: ast.IfStatement, offset: number, options: ParserOptions) { + constructor( + ast: ast.IfStatement, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/ImportClause.ts b/src/slang-nodes/ImportClause.ts index b697524c5..5f9a9e9ce 100644 --- a/src/slang-nodes/ImportClause.ts +++ b/src/slang-nodes/ImportClause.ts @@ -6,7 +6,7 @@ import { ImportDeconstruction } from './ImportDeconstruction.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class ImportClause implements SlangNode { readonly kind = NonterminalKind.ImportClause; @@ -17,7 +17,11 @@ export class ImportClause implements SlangNode { variant: PathImport | NamedImport | ImportDeconstruction; - constructor(ast: ast.ImportClause, offset: number, options: ParserOptions) { + constructor( + ast: ast.ImportClause, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/ImportDeconstruction.ts b/src/slang-nodes/ImportDeconstruction.ts index 0ecef95fe..c91e0f751 100644 --- a/src/slang-nodes/ImportDeconstruction.ts +++ b/src/slang-nodes/ImportDeconstruction.ts @@ -5,7 +5,7 @@ import { StringLiteral } from './StringLiteral.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class ImportDeconstruction implements SlangNode { readonly kind = NonterminalKind.ImportDeconstruction; @@ -27,7 +27,7 @@ export class ImportDeconstruction implements SlangNode { constructor( ast: ast.ImportDeconstruction, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/ImportDeconstructionSymbols.ts b/src/slang-nodes/ImportDeconstructionSymbols.ts index 82ecd1951..7a6eae692 100644 --- a/src/slang-nodes/ImportDeconstructionSymbols.ts +++ b/src/slang-nodes/ImportDeconstructionSymbols.ts @@ -8,7 +8,7 @@ import { ImportDeconstructionSymbol } from './ImportDeconstructionSymbol.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { line, softline } = doc.builders; @@ -41,7 +41,7 @@ export class ImportDeconstructionSymbols implements SlangNode { print( path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions ): Doc { const compiler = coerce(options.compiler); let firstSeparator; diff --git a/src/slang-nodes/ImportDirective.ts b/src/slang-nodes/ImportDirective.ts index 7c16df598..8c2dedc5b 100644 --- a/src/slang-nodes/ImportDirective.ts +++ b/src/slang-nodes/ImportDirective.ts @@ -4,7 +4,7 @@ import { ImportClause } from './ImportClause.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class ImportDirective implements SlangNode { readonly kind = NonterminalKind.ImportDirective; @@ -22,7 +22,7 @@ export class ImportDirective implements SlangNode { constructor( ast: ast.ImportDirective, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/IndexAccessEnd.ts b/src/slang-nodes/IndexAccessEnd.ts index a94f49f62..1f488a311 100644 --- a/src/slang-nodes/IndexAccessEnd.ts +++ b/src/slang-nodes/IndexAccessEnd.ts @@ -4,7 +4,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class IndexAccessEnd implements SlangNode { readonly kind = NonterminalKind.IndexAccessEnd; @@ -17,7 +17,11 @@ export class IndexAccessEnd implements SlangNode { end?: Expression; - constructor(ast: ast.IndexAccessEnd, offset: number, options: ParserOptions) { + constructor( + ast: ast.IndexAccessEnd, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/IndexAccessExpression.ts b/src/slang-nodes/IndexAccessExpression.ts index b59f41df6..f66073f19 100644 --- a/src/slang-nodes/IndexAccessExpression.ts +++ b/src/slang-nodes/IndexAccessExpression.ts @@ -7,7 +7,7 @@ import { IndexAccessEnd } from './IndexAccessEnd.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { group, indent, indentIfBreak, label, softline } = doc.builders; @@ -31,7 +31,7 @@ export class IndexAccessExpression implements SlangNode { constructor( ast: ast.IndexAccessExpression, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/InheritanceSpecifier.ts b/src/slang-nodes/InheritanceSpecifier.ts index 241c06840..4452f4ac2 100644 --- a/src/slang-nodes/InheritanceSpecifier.ts +++ b/src/slang-nodes/InheritanceSpecifier.ts @@ -4,7 +4,7 @@ import { InheritanceTypes } from './InheritanceTypes.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class InheritanceSpecifier implements SlangNode { readonly kind = NonterminalKind.InheritanceSpecifier; @@ -20,7 +20,7 @@ export class InheritanceSpecifier implements SlangNode { constructor( ast: ast.InheritanceSpecifier, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/InheritanceType.ts b/src/slang-nodes/InheritanceType.ts index e32280425..2b2f39f41 100644 --- a/src/slang-nodes/InheritanceType.ts +++ b/src/slang-nodes/InheritanceType.ts @@ -5,7 +5,7 @@ import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class InheritanceType implements SlangNode { readonly kind = NonterminalKind.InheritanceType; @@ -21,7 +21,7 @@ export class InheritanceType implements SlangNode { constructor( ast: ast.InheritanceType, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/InheritanceTypes.ts b/src/slang-nodes/InheritanceTypes.ts index a02389703..0e4198709 100644 --- a/src/slang-nodes/InheritanceTypes.ts +++ b/src/slang-nodes/InheritanceTypes.ts @@ -6,7 +6,7 @@ import { InheritanceType } from './InheritanceType.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { line } = doc.builders; @@ -24,7 +24,7 @@ export class InheritanceTypes implements SlangNode { constructor( ast: ast.InheritanceTypes, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/InterfaceDefinition.ts b/src/slang-nodes/InterfaceDefinition.ts index feba04c5e..d91d6a941 100644 --- a/src/slang-nodes/InterfaceDefinition.ts +++ b/src/slang-nodes/InterfaceDefinition.ts @@ -6,7 +6,7 @@ import { InterfaceMembers } from './InterfaceMembers.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { group, line } = doc.builders; @@ -32,7 +32,7 @@ export class InterfaceDefinition implements SlangNode { constructor( ast: ast.InterfaceDefinition, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/InterfaceMembers.ts b/src/slang-nodes/InterfaceMembers.ts index 6ac73d2a0..859e2219e 100644 --- a/src/slang-nodes/InterfaceMembers.ts +++ b/src/slang-nodes/InterfaceMembers.ts @@ -7,7 +7,7 @@ import { ContractMember } from './ContractMember.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { hardline } = doc.builders; @@ -23,7 +23,7 @@ export class InterfaceMembers implements SlangNode { constructor( ast: ast.InterfaceMembers, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; @@ -41,7 +41,7 @@ export class InterfaceMembers implements SlangNode { print( path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions ): Doc { return this.items.length > 0 ? printSeparatedItem( diff --git a/src/slang-nodes/LibraryDefinition.ts b/src/slang-nodes/LibraryDefinition.ts index 6f8716492..cba4d12d9 100644 --- a/src/slang-nodes/LibraryDefinition.ts +++ b/src/slang-nodes/LibraryDefinition.ts @@ -5,7 +5,7 @@ import { LibraryMembers } from './LibraryMembers.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { group, line } = doc.builders; @@ -29,7 +29,7 @@ export class LibraryDefinition implements SlangNode { constructor( ast: ast.LibraryDefinition, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/LibraryMembers.ts b/src/slang-nodes/LibraryMembers.ts index f1c7aa171..280785a93 100644 --- a/src/slang-nodes/LibraryMembers.ts +++ b/src/slang-nodes/LibraryMembers.ts @@ -7,7 +7,7 @@ import { ContractMember } from './ContractMember.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { hardline } = doc.builders; @@ -20,7 +20,11 @@ export class LibraryMembers implements SlangNode { items: ContractMember[]; - constructor(ast: ast.LibraryMembers, offset: number, options: ParserOptions) { + constructor( + ast: ast.LibraryMembers, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; @@ -37,7 +41,7 @@ export class LibraryMembers implements SlangNode { print( path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions ): Doc { return this.items.length > 0 ? printSeparatedItem( diff --git a/src/slang-nodes/MappingType.ts b/src/slang-nodes/MappingType.ts index 1aaf07138..53d6fb8a9 100644 --- a/src/slang-nodes/MappingType.ts +++ b/src/slang-nodes/MappingType.ts @@ -5,7 +5,7 @@ import { MappingValue } from './MappingValue.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class MappingType implements SlangNode { readonly kind = NonterminalKind.MappingType; @@ -26,7 +26,11 @@ export class MappingType implements SlangNode { closeParen: string; - constructor(ast: ast.MappingType, offset: number, options: ParserOptions) { + constructor( + ast: ast.MappingType, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/MappingValue.ts b/src/slang-nodes/MappingValue.ts index 2d7d04ea7..9f096b7de 100644 --- a/src/slang-nodes/MappingValue.ts +++ b/src/slang-nodes/MappingValue.ts @@ -4,7 +4,7 @@ import { TypeName } from './TypeName.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class MappingValue implements SlangNode { readonly kind = NonterminalKind.MappingValue; @@ -17,7 +17,11 @@ export class MappingValue implements SlangNode { name?: string; - constructor(ast: ast.MappingValue, offset: number, options: ParserOptions) { + constructor( + ast: ast.MappingValue, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/MemberAccessExpression.ts b/src/slang-nodes/MemberAccessExpression.ts index 0591d4898..8480557ed 100644 --- a/src/slang-nodes/MemberAccessExpression.ts +++ b/src/slang-nodes/MemberAccessExpression.ts @@ -132,7 +132,7 @@ export class MemberAccessExpression implements SlangNode { constructor( ast: ast.MemberAccessExpression, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/ModifierDefinition.ts b/src/slang-nodes/ModifierDefinition.ts index a523ef137..e69cae52d 100644 --- a/src/slang-nodes/ModifierDefinition.ts +++ b/src/slang-nodes/ModifierDefinition.ts @@ -8,7 +8,7 @@ import { FunctionBody } from './FunctionBody.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const objectConfig = { writable: true, @@ -35,7 +35,7 @@ export class ModifierDefinition implements SlangNode { constructor( ast: ast.ModifierDefinition, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/ModifierInvocation.ts b/src/slang-nodes/ModifierInvocation.ts index c29c3d3d4..f77ea0213 100644 --- a/src/slang-nodes/ModifierInvocation.ts +++ b/src/slang-nodes/ModifierInvocation.ts @@ -6,7 +6,7 @@ import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class ModifierInvocation implements SlangNode { readonly kind = NonterminalKind.ModifierInvocation; @@ -24,7 +24,7 @@ export class ModifierInvocation implements SlangNode { constructor( ast: ast.ModifierInvocation, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/MultiplicativeExpression.ts b/src/slang-nodes/MultiplicativeExpression.ts index a8a8e1321..31053f06b 100644 --- a/src/slang-nodes/MultiplicativeExpression.ts +++ b/src/slang-nodes/MultiplicativeExpression.ts @@ -6,7 +6,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const multiplicationTryToHug = createHugFunction(['/', '%']); const divisionTryToHug = createHugFunction(['*', '%']); @@ -28,7 +28,7 @@ export class MultiplicativeExpression implements SlangNode { constructor( ast: ast.MultiplicativeExpression, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; @@ -60,7 +60,7 @@ export class MultiplicativeExpression implements SlangNode { print( path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions ): Doc { return printBinaryOperation(this, path, print, options); } diff --git a/src/slang-nodes/NamedArgument.ts b/src/slang-nodes/NamedArgument.ts index 7fe28e2e0..95dd95042 100644 --- a/src/slang-nodes/NamedArgument.ts +++ b/src/slang-nodes/NamedArgument.ts @@ -4,7 +4,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class NamedArgument implements SlangNode { readonly kind = NonterminalKind.NamedArgument; @@ -19,7 +19,11 @@ export class NamedArgument implements SlangNode { value: Expression; - constructor(ast: ast.NamedArgument, offset: number, options: ParserOptions) { + constructor( + ast: ast.NamedArgument, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/NamedArgumentGroup.ts b/src/slang-nodes/NamedArgumentGroup.ts index ec1dfe139..b67e066e4 100644 --- a/src/slang-nodes/NamedArgumentGroup.ts +++ b/src/slang-nodes/NamedArgumentGroup.ts @@ -4,7 +4,7 @@ import { NamedArguments } from './NamedArguments.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class NamedArgumentGroup implements SlangNode { readonly kind = NonterminalKind.NamedArgumentGroup; @@ -22,7 +22,7 @@ export class NamedArgumentGroup implements SlangNode { constructor( ast: ast.NamedArgumentGroup, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/NamedArguments.ts b/src/slang-nodes/NamedArguments.ts index 9c2bf75e0..51ecb6817 100644 --- a/src/slang-nodes/NamedArguments.ts +++ b/src/slang-nodes/NamedArguments.ts @@ -6,7 +6,7 @@ import { NamedArgument } from './NamedArgument.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { line, softline } = doc.builders; @@ -21,7 +21,11 @@ export class NamedArguments implements SlangNode { separators: string[]; - constructor(ast: ast.NamedArguments, offset: number, options: ParserOptions) { + constructor( + ast: ast.NamedArguments, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; @@ -39,7 +43,7 @@ export class NamedArguments implements SlangNode { print( path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions ): Doc { return printSeparatedList(path.map(print, 'items'), { firstSeparator: options.bracketSpacing ? line : softline diff --git a/src/slang-nodes/NamedArgumentsDeclaration.ts b/src/slang-nodes/NamedArgumentsDeclaration.ts index 0e2934fc8..3efa1e745 100644 --- a/src/slang-nodes/NamedArgumentsDeclaration.ts +++ b/src/slang-nodes/NamedArgumentsDeclaration.ts @@ -4,7 +4,7 @@ import { NamedArgumentGroup } from './NamedArgumentGroup.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class NamedArgumentsDeclaration implements SlangNode { readonly kind = NonterminalKind.NamedArgumentsDeclaration; @@ -22,7 +22,7 @@ export class NamedArgumentsDeclaration implements SlangNode { constructor( ast: ast.NamedArgumentsDeclaration, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/NamedImport.ts b/src/slang-nodes/NamedImport.ts index b01236cdf..f3735aad4 100644 --- a/src/slang-nodes/NamedImport.ts +++ b/src/slang-nodes/NamedImport.ts @@ -5,7 +5,7 @@ import { StringLiteral } from './StringLiteral.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class NamedImport implements SlangNode { readonly kind = NonterminalKind.NamedImport; @@ -22,7 +22,11 @@ export class NamedImport implements SlangNode { path: StringLiteral; - constructor(ast: ast.NamedImport, offset: number, options: ParserOptions) { + constructor( + ast: ast.NamedImport, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/NewExpression.ts b/src/slang-nodes/NewExpression.ts index 2a1ff26e0..568ed5ac5 100644 --- a/src/slang-nodes/NewExpression.ts +++ b/src/slang-nodes/NewExpression.ts @@ -4,7 +4,7 @@ import { TypeName } from './TypeName.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class NewExpression implements SlangNode { readonly kind = NonterminalKind.NewExpression; @@ -17,7 +17,11 @@ export class NewExpression implements SlangNode { typeName: TypeName; - constructor(ast: ast.NewExpression, offset: number, options: ParserOptions) { + constructor( + ast: ast.NewExpression, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/OrExpression.ts b/src/slang-nodes/OrExpression.ts index 8c8470c1b..422818f03 100644 --- a/src/slang-nodes/OrExpression.ts +++ b/src/slang-nodes/OrExpression.ts @@ -6,7 +6,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const tryToHug = createHugFunction(['&&']); @@ -23,7 +23,11 @@ export class OrExpression implements SlangNode { rightOperand: Expression; - constructor(ast: ast.OrExpression, offset: number, options: ParserOptions) { + constructor( + ast: ast.OrExpression, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; @@ -43,7 +47,7 @@ export class OrExpression implements SlangNode { print( path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions ): Doc { return printLogicalOperation(this, path, print, options); } diff --git a/src/slang-nodes/OverridePaths.ts b/src/slang-nodes/OverridePaths.ts index 0a77b7c77..a6c26366e 100644 --- a/src/slang-nodes/OverridePaths.ts +++ b/src/slang-nodes/OverridePaths.ts @@ -36,7 +36,7 @@ export class OverridePaths implements SlangNode { print(/* path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions */): Doc { return ['TODO: OverridePaths']; } diff --git a/src/slang-nodes/OverridePathsDeclaration.ts b/src/slang-nodes/OverridePathsDeclaration.ts index 08cbac2f9..49496df96 100644 --- a/src/slang-nodes/OverridePathsDeclaration.ts +++ b/src/slang-nodes/OverridePathsDeclaration.ts @@ -37,7 +37,7 @@ export class OverridePathsDeclaration implements SlangNode { print(/* path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions */): Doc { return ['TODO: OverridePathsDeclaration']; } diff --git a/src/slang-nodes/Parameter.ts b/src/slang-nodes/Parameter.ts index 94e86a56c..f69d99445 100644 --- a/src/slang-nodes/Parameter.ts +++ b/src/slang-nodes/Parameter.ts @@ -6,7 +6,7 @@ import { StorageLocation } from './StorageLocation.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { group } = doc.builders; @@ -23,7 +23,11 @@ export class Parameter implements SlangNode { name?: string; - constructor(ast: ast.Parameter, offset: number, options: ParserOptions) { + constructor( + ast: ast.Parameter, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/Parameters.ts b/src/slang-nodes/Parameters.ts index 0477b4887..367ddaa2f 100644 --- a/src/slang-nodes/Parameters.ts +++ b/src/slang-nodes/Parameters.ts @@ -7,7 +7,7 @@ import { Parameter } from './Parameter.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class Parameters implements SlangNode { readonly kind = NonterminalKind.Parameters; @@ -20,7 +20,11 @@ export class Parameters implements SlangNode { separators: string[]; - constructor(ast: ast.Parameters, offset: number, options: ParserOptions) { + constructor( + ast: ast.Parameters, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/ParametersDeclaration.ts b/src/slang-nodes/ParametersDeclaration.ts index 17b02ada0..298b78a25 100644 --- a/src/slang-nodes/ParametersDeclaration.ts +++ b/src/slang-nodes/ParametersDeclaration.ts @@ -4,7 +4,7 @@ import { Parameters } from './Parameters.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class ParametersDeclaration implements SlangNode { readonly kind = NonterminalKind.ParametersDeclaration; @@ -22,7 +22,7 @@ export class ParametersDeclaration implements SlangNode { constructor( ast: ast.ParametersDeclaration, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/PathImport.ts b/src/slang-nodes/PathImport.ts index 6609d98a5..2bc8cf283 100644 --- a/src/slang-nodes/PathImport.ts +++ b/src/slang-nodes/PathImport.ts @@ -5,7 +5,7 @@ import { ImportAlias } from './ImportAlias.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class PathImport implements SlangNode { readonly kind = NonterminalKind.PathImport; @@ -18,7 +18,11 @@ export class PathImport implements SlangNode { alias?: ImportAlias; - constructor(ast: ast.PathImport, offset: number, options: ParserOptions) { + constructor( + ast: ast.PathImport, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/PositionalArguments.ts b/src/slang-nodes/PositionalArguments.ts index b87743403..b0684ff57 100644 --- a/src/slang-nodes/PositionalArguments.ts +++ b/src/slang-nodes/PositionalArguments.ts @@ -5,7 +5,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class PositionalArguments implements SlangNode { readonly kind = NonterminalKind.PositionalArguments; @@ -21,7 +21,7 @@ export class PositionalArguments implements SlangNode { constructor( ast: ast.PositionalArguments, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/PositionalArgumentsDeclaration.ts b/src/slang-nodes/PositionalArgumentsDeclaration.ts index 04d309913..5d9ef2ee2 100644 --- a/src/slang-nodes/PositionalArgumentsDeclaration.ts +++ b/src/slang-nodes/PositionalArgumentsDeclaration.ts @@ -4,7 +4,7 @@ import { PositionalArguments } from './PositionalArguments.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class PositionalArgumentsDeclaration implements SlangNode { readonly kind = NonterminalKind.PositionalArgumentsDeclaration; @@ -22,7 +22,7 @@ export class PositionalArgumentsDeclaration implements SlangNode { constructor( ast: ast.PositionalArgumentsDeclaration, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/PostfixExpression.ts b/src/slang-nodes/PostfixExpression.ts index 4a841129f..9ab783050 100644 --- a/src/slang-nodes/PostfixExpression.ts +++ b/src/slang-nodes/PostfixExpression.ts @@ -4,7 +4,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class PostfixExpression implements SlangNode { readonly kind = NonterminalKind.PostfixExpression; @@ -20,7 +20,7 @@ export class PostfixExpression implements SlangNode { constructor( ast: ast.PostfixExpression, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/Pragma.ts b/src/slang-nodes/Pragma.ts index aa6c0ec29..b660baf4f 100644 --- a/src/slang-nodes/Pragma.ts +++ b/src/slang-nodes/Pragma.ts @@ -6,7 +6,7 @@ import { VersionPragma } from './VersionPragma.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class Pragma implements SlangNode { readonly kind = NonterminalKind.Pragma; @@ -17,7 +17,11 @@ export class Pragma implements SlangNode { variant: ABICoderPragma | ExperimentalPragma | VersionPragma; - constructor(ast: ast.Pragma, offset: number, options: ParserOptions) { + constructor( + ast: ast.Pragma, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/PragmaDirective.ts b/src/slang-nodes/PragmaDirective.ts index 33549c047..d18e9f7fe 100644 --- a/src/slang-nodes/PragmaDirective.ts +++ b/src/slang-nodes/PragmaDirective.ts @@ -4,7 +4,7 @@ import { Pragma } from './Pragma.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class PragmaDirective implements SlangNode { readonly kind = NonterminalKind.PragmaDirective; @@ -22,7 +22,7 @@ export class PragmaDirective implements SlangNode { constructor( ast: ast.PragmaDirective, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/PrefixExpression.ts b/src/slang-nodes/PrefixExpression.ts index 59594ffa7..4242ac1af 100644 --- a/src/slang-nodes/PrefixExpression.ts +++ b/src/slang-nodes/PrefixExpression.ts @@ -4,7 +4,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class PrefixExpression implements SlangNode { readonly kind = NonterminalKind.PrefixExpression; @@ -20,7 +20,7 @@ export class PrefixExpression implements SlangNode { constructor( ast: ast.PrefixExpression, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/ReceiveFunctionAttribute.ts b/src/slang-nodes/ReceiveFunctionAttribute.ts index 123ad645a..71b6ff0da 100644 --- a/src/slang-nodes/ReceiveFunctionAttribute.ts +++ b/src/slang-nodes/ReceiveFunctionAttribute.ts @@ -6,7 +6,7 @@ import { OverrideSpecifier } from './OverrideSpecifier.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class ReceiveFunctionAttribute implements SlangNode { readonly kind = NonterminalKind.ReceiveFunctionAttribute; @@ -20,7 +20,7 @@ export class ReceiveFunctionAttribute implements SlangNode { constructor( ast: ast.ReceiveFunctionAttribute, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/ReceiveFunctionAttributes.ts b/src/slang-nodes/ReceiveFunctionAttributes.ts index 0a02a2332..9b3bd33fa 100644 --- a/src/slang-nodes/ReceiveFunctionAttributes.ts +++ b/src/slang-nodes/ReceiveFunctionAttributes.ts @@ -6,7 +6,7 @@ import { ReceiveFunctionAttribute } from './ReceiveFunctionAttribute.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { line } = doc.builders; @@ -22,7 +22,7 @@ export class ReceiveFunctionAttributes implements SlangNode { constructor( ast: ast.ReceiveFunctionAttributes, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/ReceiveFunctionDefinition.ts b/src/slang-nodes/ReceiveFunctionDefinition.ts index 9ff424e08..7bdfeb00f 100644 --- a/src/slang-nodes/ReceiveFunctionDefinition.ts +++ b/src/slang-nodes/ReceiveFunctionDefinition.ts @@ -7,7 +7,7 @@ import { FunctionBody } from './FunctionBody.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class ReceiveFunctionDefinition implements SlangNode { readonly kind = NonterminalKind.ReceiveFunctionDefinition; @@ -27,7 +27,7 @@ export class ReceiveFunctionDefinition implements SlangNode { constructor( ast: ast.ReceiveFunctionDefinition, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/ReturnStatement.ts b/src/slang-nodes/ReturnStatement.ts index e9318923b..037987705 100644 --- a/src/slang-nodes/ReturnStatement.ts +++ b/src/slang-nodes/ReturnStatement.ts @@ -5,7 +5,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { group, indent, line } = doc.builders; @@ -13,7 +13,7 @@ function printExpression( node: ReturnStatement, path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions ): Doc { if (node.expression) { return typeof node.expression.variant !== 'string' && @@ -43,7 +43,7 @@ export class ReturnStatement implements SlangNode { constructor( ast: ast.ReturnStatement, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; @@ -63,7 +63,7 @@ export class ReturnStatement implements SlangNode { print( path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions ): Doc { return [ this.returnKeyword, diff --git a/src/slang-nodes/ReturnsDeclaration.ts b/src/slang-nodes/ReturnsDeclaration.ts index 9cdc61b7e..10c7c48da 100644 --- a/src/slang-nodes/ReturnsDeclaration.ts +++ b/src/slang-nodes/ReturnsDeclaration.ts @@ -5,7 +5,7 @@ import { ParametersDeclaration } from './ParametersDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { group } = doc.builders; @@ -23,7 +23,7 @@ export class ReturnsDeclaration implements SlangNode { constructor( ast: ast.ReturnsDeclaration, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/RevertStatement.ts b/src/slang-nodes/RevertStatement.ts index 7147e300a..23a4fe53c 100644 --- a/src/slang-nodes/RevertStatement.ts +++ b/src/slang-nodes/RevertStatement.ts @@ -5,7 +5,7 @@ import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class RevertStatement implements SlangNode { readonly kind = NonterminalKind.RevertStatement; @@ -25,7 +25,7 @@ export class RevertStatement implements SlangNode { constructor( ast: ast.RevertStatement, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/ShiftExpression.ts b/src/slang-nodes/ShiftExpression.ts index 2fbb1a656..98023e427 100644 --- a/src/slang-nodes/ShiftExpression.ts +++ b/src/slang-nodes/ShiftExpression.ts @@ -6,7 +6,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const tryToHugLeftOperand = createHugFunction([ '+', @@ -35,7 +35,7 @@ export class ShiftExpression implements SlangNode { constructor( ast: ast.ShiftExpression, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; @@ -56,7 +56,7 @@ export class ShiftExpression implements SlangNode { print( path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions ): Doc { return printBinaryOperation(this, path, print, options); } diff --git a/src/slang-nodes/SourceUnit.ts b/src/slang-nodes/SourceUnit.ts index 325702844..33bdedb6d 100644 --- a/src/slang-nodes/SourceUnit.ts +++ b/src/slang-nodes/SourceUnit.ts @@ -5,7 +5,7 @@ import { SourceUnitMembers } from './SourceUnitMembers.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { line } = doc.builders; @@ -18,7 +18,11 @@ export class SourceUnit implements SlangNode { members: SourceUnitMembers; - constructor(ast: ast.SourceUnit, offset: number, options: ParserOptions) { + constructor( + ast: ast.SourceUnit, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; @@ -33,7 +37,7 @@ export class SourceUnit implements SlangNode { print( path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions ): Doc { return [path.call(print, 'members'), options.parentParser ? '' : line]; } diff --git a/src/slang-nodes/SourceUnitMember.ts b/src/slang-nodes/SourceUnitMember.ts index 782035214..94b5ae20d 100644 --- a/src/slang-nodes/SourceUnitMember.ts +++ b/src/slang-nodes/SourceUnitMember.ts @@ -16,7 +16,7 @@ import { EventDefinition } from './EventDefinition.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class SourceUnitMember implements SlangNode { readonly kind = NonterminalKind.SourceUnitMember; @@ -43,7 +43,7 @@ export class SourceUnitMember implements SlangNode { constructor( ast: ast.SourceUnitMember, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/SourceUnitMembers.ts b/src/slang-nodes/SourceUnitMembers.ts index 6100e9386..69e3572b8 100644 --- a/src/slang-nodes/SourceUnitMembers.ts +++ b/src/slang-nodes/SourceUnitMembers.ts @@ -5,7 +5,7 @@ import { SourceUnitMember } from './SourceUnitMember.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class SourceUnitMembers implements SlangNode { readonly kind = NonterminalKind.SourceUnitMembers; @@ -19,7 +19,7 @@ export class SourceUnitMembers implements SlangNode { constructor( ast: ast.SourceUnitMembers, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; @@ -37,7 +37,7 @@ export class SourceUnitMembers implements SlangNode { print( path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions ): Doc { return printPreservingEmptyLines(path, 'items', print, options); } diff --git a/src/slang-nodes/StateVariableDefinition.ts b/src/slang-nodes/StateVariableDefinition.ts index 721197c57..fa9f0131e 100644 --- a/src/slang-nodes/StateVariableDefinition.ts +++ b/src/slang-nodes/StateVariableDefinition.ts @@ -6,7 +6,7 @@ import { StateVariableDefinitionValue } from './StateVariableDefinitionValue.js' import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class StateVariableDefinition implements SlangNode { readonly kind = NonterminalKind.StateVariableDefinition; @@ -28,7 +28,7 @@ export class StateVariableDefinition implements SlangNode { constructor( ast: ast.StateVariableDefinition, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/StateVariableDefinitionValue.ts b/src/slang-nodes/StateVariableDefinitionValue.ts index f36df9d0a..4dab16408 100644 --- a/src/slang-nodes/StateVariableDefinitionValue.ts +++ b/src/slang-nodes/StateVariableDefinitionValue.ts @@ -5,7 +5,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { group, indent, line } = doc.builders; @@ -23,7 +23,7 @@ export class StateVariableDefinitionValue implements SlangNode { constructor( ast: ast.StateVariableDefinitionValue, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/Statement.ts b/src/slang-nodes/Statement.ts index 6c5096033..5a7bfec6e 100644 --- a/src/slang-nodes/Statement.ts +++ b/src/slang-nodes/Statement.ts @@ -20,7 +20,7 @@ import { UncheckedBlock } from './UncheckedBlock.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class Statement implements SlangNode { readonly kind = NonterminalKind.Statement; @@ -48,7 +48,11 @@ export class Statement implements SlangNode { | Block | UncheckedBlock; - constructor(ast: ast.Statement, offset: number, options: ParserOptions) { + constructor( + ast: ast.Statement, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/Statements.ts b/src/slang-nodes/Statements.ts index 99dd0162d..331f795e2 100644 --- a/src/slang-nodes/Statements.ts +++ b/src/slang-nodes/Statements.ts @@ -8,7 +8,7 @@ import { Statement } from './Statement.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { hardline } = doc.builders; @@ -21,7 +21,11 @@ export class Statements implements SlangNode { items: Statement[]; - constructor(ast: ast.Statements, offset: number, options: ParserOptions) { + constructor( + ast: ast.Statements, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; @@ -38,7 +42,7 @@ export class Statements implements SlangNode { print( path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions ): Doc { return this.items.length === 0 && (!this.comments || this.comments.length === 0) diff --git a/src/slang-nodes/StringExpression.ts b/src/slang-nodes/StringExpression.ts index 25b310bc4..61431919c 100644 --- a/src/slang-nodes/StringExpression.ts +++ b/src/slang-nodes/StringExpression.ts @@ -8,7 +8,7 @@ import { UnicodeStringLiterals } from './UnicodeStringLiterals.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class StringExpression implements SlangNode { readonly kind = NonterminalKind.StringExpression; @@ -27,7 +27,7 @@ export class StringExpression implements SlangNode { constructor( ast: ast.StringExpression, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/StringLiteral.ts b/src/slang-nodes/StringLiteral.ts index 8139e101c..3df4f32ba 100644 --- a/src/slang-nodes/StringLiteral.ts +++ b/src/slang-nodes/StringLiteral.ts @@ -4,7 +4,7 @@ import { getNodeMetadata } from '../slang-utils/metadata.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class StringLiteral implements SlangNode { readonly kind = NonterminalKind.StringLiteral; @@ -15,7 +15,11 @@ export class StringLiteral implements SlangNode { variant; - constructor(ast: ast.StringLiteral, offset: number, options: ParserOptions) { + constructor( + ast: ast.StringLiteral, + offset: number, + options: ParserOptions + ) { const metadata = getNodeMetadata(ast, offset); this.variant = ast.variant.text; diff --git a/src/slang-nodes/StringLiterals.ts b/src/slang-nodes/StringLiterals.ts index 8e7d14fc0..18a8c676f 100644 --- a/src/slang-nodes/StringLiterals.ts +++ b/src/slang-nodes/StringLiterals.ts @@ -5,7 +5,7 @@ import { StringLiteral } from './StringLiteral.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { join, hardline } = doc.builders; @@ -18,7 +18,11 @@ export class StringLiterals implements SlangNode { items: StringLiteral[]; - constructor(ast: ast.StringLiterals, offset: number, options: ParserOptions) { + constructor( + ast: ast.StringLiterals, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/StructDefinition.ts b/src/slang-nodes/StructDefinition.ts index 564151b4b..dd10be13f 100644 --- a/src/slang-nodes/StructDefinition.ts +++ b/src/slang-nodes/StructDefinition.ts @@ -4,7 +4,7 @@ import { StructMembers } from './StructMembers.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class StructDefinition implements SlangNode { readonly kind = NonterminalKind.StructDefinition; @@ -26,7 +26,7 @@ export class StructDefinition implements SlangNode { constructor( ast: ast.StructDefinition, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/StructMember.ts b/src/slang-nodes/StructMember.ts index 6e09f320e..407e0ada2 100644 --- a/src/slang-nodes/StructMember.ts +++ b/src/slang-nodes/StructMember.ts @@ -4,7 +4,7 @@ import { TypeName } from './TypeName.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class StructMember implements SlangNode { readonly kind = NonterminalKind.StructMember; @@ -19,7 +19,11 @@ export class StructMember implements SlangNode { semicolon: string; - constructor(ast: ast.StructMember, offset: number, options: ParserOptions) { + constructor( + ast: ast.StructMember, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/StructMembers.ts b/src/slang-nodes/StructMembers.ts index 06325a6bb..edeb8ddb6 100644 --- a/src/slang-nodes/StructMembers.ts +++ b/src/slang-nodes/StructMembers.ts @@ -6,7 +6,7 @@ import { StructMember } from './StructMember.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { hardline } = doc.builders; @@ -19,7 +19,11 @@ export class StructMembers implements SlangNode { items: StructMember[]; - constructor(ast: ast.StructMembers, offset: number, options: ParserOptions) { + constructor( + ast: ast.StructMembers, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/TryStatement.ts b/src/slang-nodes/TryStatement.ts index f9b492335..5946d1678 100644 --- a/src/slang-nodes/TryStatement.ts +++ b/src/slang-nodes/TryStatement.ts @@ -9,7 +9,7 @@ import { CatchClauses } from './CatchClauses.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { line } = doc.builders; @@ -30,7 +30,11 @@ export class TryStatement implements SlangNode { catchClauses: CatchClauses; - constructor(ast: ast.TryStatement, offset: number, options: ParserOptions) { + constructor( + ast: ast.TryStatement, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/TupleDeconstructionElement.ts b/src/slang-nodes/TupleDeconstructionElement.ts index b629b0acc..0ce174e9b 100644 --- a/src/slang-nodes/TupleDeconstructionElement.ts +++ b/src/slang-nodes/TupleDeconstructionElement.ts @@ -4,7 +4,7 @@ import { TupleMember } from './TupleMember.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class TupleDeconstructionElement implements SlangNode { readonly kind = NonterminalKind.TupleDeconstructionElement; @@ -18,7 +18,7 @@ export class TupleDeconstructionElement implements SlangNode { constructor( ast: ast.TupleDeconstructionElement, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/TupleDeconstructionElements.ts b/src/slang-nodes/TupleDeconstructionElements.ts index 1933cc551..1582eab13 100644 --- a/src/slang-nodes/TupleDeconstructionElements.ts +++ b/src/slang-nodes/TupleDeconstructionElements.ts @@ -5,7 +5,7 @@ import { TupleDeconstructionElement } from './TupleDeconstructionElement.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class TupleDeconstructionElements implements SlangNode { readonly kind = NonterminalKind.TupleDeconstructionElements; @@ -21,7 +21,7 @@ export class TupleDeconstructionElements implements SlangNode { constructor( ast: ast.TupleDeconstructionElements, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/TupleDeconstructionStatement.ts b/src/slang-nodes/TupleDeconstructionStatement.ts index 6af563d9f..e62ab93d2 100644 --- a/src/slang-nodes/TupleDeconstructionStatement.ts +++ b/src/slang-nodes/TupleDeconstructionStatement.ts @@ -6,7 +6,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { group, indent, line } = doc.builders; @@ -34,7 +34,7 @@ export class TupleDeconstructionStatement implements SlangNode { constructor( ast: ast.TupleDeconstructionStatement, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/TupleExpression.ts b/src/slang-nodes/TupleExpression.ts index 337f79e62..26c7908b7 100644 --- a/src/slang-nodes/TupleExpression.ts +++ b/src/slang-nodes/TupleExpression.ts @@ -4,7 +4,7 @@ import { TupleValues } from './TupleValues.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class TupleExpression implements SlangNode { readonly kind = NonterminalKind.TupleExpression; @@ -22,7 +22,7 @@ export class TupleExpression implements SlangNode { constructor( ast: ast.TupleExpression, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/TupleMember.ts b/src/slang-nodes/TupleMember.ts index 5792687c3..49127393e 100644 --- a/src/slang-nodes/TupleMember.ts +++ b/src/slang-nodes/TupleMember.ts @@ -5,7 +5,7 @@ import { UntypedTupleMember } from './UntypedTupleMember.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class TupleMember implements SlangNode { readonly kind = NonterminalKind.TupleMember; @@ -16,7 +16,11 @@ export class TupleMember implements SlangNode { variant: TypedTupleMember | UntypedTupleMember; - constructor(ast: ast.TupleMember, offset: number, options: ParserOptions) { + constructor( + ast: ast.TupleMember, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/TupleValue.ts b/src/slang-nodes/TupleValue.ts index 6eb94e711..b36a9f593 100644 --- a/src/slang-nodes/TupleValue.ts +++ b/src/slang-nodes/TupleValue.ts @@ -4,7 +4,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class TupleValue implements SlangNode { readonly kind = NonterminalKind.TupleValue; @@ -15,7 +15,11 @@ export class TupleValue implements SlangNode { expression?: Expression; - constructor(ast: ast.TupleValue, offset: number, options: ParserOptions) { + constructor( + ast: ast.TupleValue, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/TupleValues.ts b/src/slang-nodes/TupleValues.ts index ebb672717..c6f12e1b3 100644 --- a/src/slang-nodes/TupleValues.ts +++ b/src/slang-nodes/TupleValues.ts @@ -6,7 +6,7 @@ import { TupleValue } from './TupleValue.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class TupleValues implements SlangNode { readonly kind = NonterminalKind.TupleValues; @@ -19,7 +19,11 @@ export class TupleValues implements SlangNode { separators: string[]; - constructor(ast: ast.TupleValues, offset: number, options: ParserOptions) { + constructor( + ast: ast.TupleValues, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/TypeExpression.ts b/src/slang-nodes/TypeExpression.ts index 3238bfa6f..75889c031 100644 --- a/src/slang-nodes/TypeExpression.ts +++ b/src/slang-nodes/TypeExpression.ts @@ -4,7 +4,7 @@ import { TypeName } from './TypeName.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { /*AstPath,*/ Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class TypeExpression implements SlangNode { readonly kind = NonterminalKind.TypeExpression; @@ -21,7 +21,11 @@ export class TypeExpression implements SlangNode { closeParen: string; - constructor(ast: ast.TypeExpression, offset: number, options: ParserOptions) { + constructor( + ast: ast.TypeExpression, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; @@ -40,7 +44,7 @@ export class TypeExpression implements SlangNode { print(/* path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions */): Doc { return ['TODO: TypeExpression']; } diff --git a/src/slang-nodes/TypeName.ts b/src/slang-nodes/TypeName.ts index a57198c86..164a38d56 100644 --- a/src/slang-nodes/TypeName.ts +++ b/src/slang-nodes/TypeName.ts @@ -8,7 +8,7 @@ import { IdentifierPath } from './IdentifierPath.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class TypeName implements SlangNode { readonly kind = NonterminalKind.TypeName; @@ -24,7 +24,11 @@ export class TypeName implements SlangNode { | ElementaryType | IdentifierPath; - constructor(ast: ast.TypeName, offset: number, options: ParserOptions) { + constructor( + ast: ast.TypeName, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/TypedTupleMember.ts b/src/slang-nodes/TypedTupleMember.ts index a23739d8c..0e03d6cb5 100644 --- a/src/slang-nodes/TypedTupleMember.ts +++ b/src/slang-nodes/TypedTupleMember.ts @@ -5,7 +5,7 @@ import { StorageLocation } from './StorageLocation.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class TypedTupleMember implements SlangNode { readonly kind = NonterminalKind.TypedTupleMember; @@ -23,7 +23,7 @@ export class TypedTupleMember implements SlangNode { constructor( ast: ast.TypedTupleMember, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/UncheckedBlock.ts b/src/slang-nodes/UncheckedBlock.ts index 81167e978..5a40db489 100644 --- a/src/slang-nodes/UncheckedBlock.ts +++ b/src/slang-nodes/UncheckedBlock.ts @@ -4,7 +4,7 @@ import { Block } from './Block.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class UncheckedBlock implements SlangNode { readonly kind = NonterminalKind.UncheckedBlock; @@ -17,7 +17,11 @@ export class UncheckedBlock implements SlangNode { block: Block; - constructor(ast: ast.UncheckedBlock, offset: number, options: ParserOptions) { + constructor( + ast: ast.UncheckedBlock, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/UnicodeStringLiteral.ts b/src/slang-nodes/UnicodeStringLiteral.ts index e50acedcb..579645dc1 100644 --- a/src/slang-nodes/UnicodeStringLiteral.ts +++ b/src/slang-nodes/UnicodeStringLiteral.ts @@ -4,7 +4,7 @@ import { getNodeMetadata } from '../slang-utils/metadata.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class UnicodeStringLiteral implements SlangNode { readonly kind = NonterminalKind.UnicodeStringLiteral; @@ -18,7 +18,7 @@ export class UnicodeStringLiteral implements SlangNode { constructor( ast: ast.UnicodeStringLiteral, offset: number, - options: ParserOptions + options: ParserOptions ) { const metadata = getNodeMetadata(ast, offset); diff --git a/src/slang-nodes/UnicodeStringLiterals.ts b/src/slang-nodes/UnicodeStringLiterals.ts index 7050fc51d..5cfe9af33 100644 --- a/src/slang-nodes/UnicodeStringLiterals.ts +++ b/src/slang-nodes/UnicodeStringLiterals.ts @@ -5,7 +5,7 @@ import { UnicodeStringLiteral } from './UnicodeStringLiteral.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { join, hardline } = doc.builders; @@ -21,7 +21,7 @@ export class UnicodeStringLiterals implements SlangNode { constructor( ast: ast.UnicodeStringLiterals, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/UnnamedFunctionAttribute.ts b/src/slang-nodes/UnnamedFunctionAttribute.ts index 92e709a1d..fbdce4499 100644 --- a/src/slang-nodes/UnnamedFunctionAttribute.ts +++ b/src/slang-nodes/UnnamedFunctionAttribute.ts @@ -5,7 +5,7 @@ import { ModifierInvocation } from './ModifierInvocation.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class UnnamedFunctionAttribute implements SlangNode { readonly kind = NonterminalKind.UnnamedFunctionAttribute; @@ -19,7 +19,7 @@ export class UnnamedFunctionAttribute implements SlangNode { constructor( ast: ast.UnnamedFunctionAttribute, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/UnnamedFunctionAttributes.ts b/src/slang-nodes/UnnamedFunctionAttributes.ts index 30748711a..5df978b03 100644 --- a/src/slang-nodes/UnnamedFunctionAttributes.ts +++ b/src/slang-nodes/UnnamedFunctionAttributes.ts @@ -6,7 +6,7 @@ import { UnnamedFunctionAttribute } from './UnnamedFunctionAttribute.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { line } = doc.builders; @@ -22,7 +22,7 @@ export class UnnamedFunctionAttributes implements SlangNode { constructor( ast: ast.UnnamedFunctionAttributes, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/UnnamedFunctionDefinition.ts b/src/slang-nodes/UnnamedFunctionDefinition.ts index 579bac4f1..e15ab05af 100644 --- a/src/slang-nodes/UnnamedFunctionDefinition.ts +++ b/src/slang-nodes/UnnamedFunctionDefinition.ts @@ -7,7 +7,7 @@ import { FunctionBody } from './FunctionBody.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class UnnamedFunctionDefinition implements SlangNode { readonly kind = NonterminalKind.UnnamedFunctionDefinition; @@ -27,7 +27,7 @@ export class UnnamedFunctionDefinition implements SlangNode { constructor( ast: ast.UnnamedFunctionDefinition, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/UntypedTupleMember.ts b/src/slang-nodes/UntypedTupleMember.ts index 2c0ddd412..5f24566c0 100644 --- a/src/slang-nodes/UntypedTupleMember.ts +++ b/src/slang-nodes/UntypedTupleMember.ts @@ -39,7 +39,7 @@ export class UntypedTupleMember implements SlangNode { print(/* path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions */): Doc { return ['TODO: UntypedTupleMemberUntypedTupleMember']; } diff --git a/src/slang-nodes/UsingDeconstructionSymbols.ts b/src/slang-nodes/UsingDeconstructionSymbols.ts index f5435d054..783783fd1 100644 --- a/src/slang-nodes/UsingDeconstructionSymbols.ts +++ b/src/slang-nodes/UsingDeconstructionSymbols.ts @@ -6,7 +6,7 @@ import { UsingDeconstructionSymbol } from './UsingDeconstructionSymbol.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { line, softline } = doc.builders; @@ -39,7 +39,7 @@ export class UsingDeconstructionSymbols implements SlangNode { print( path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions ): Doc { return printSeparatedList(path.map(print, 'items'), { firstSeparator: options.bracketSpacing ? line : softline diff --git a/src/slang-nodes/UsingDirective.ts b/src/slang-nodes/UsingDirective.ts index 33845f4ad..788d98acd 100644 --- a/src/slang-nodes/UsingDirective.ts +++ b/src/slang-nodes/UsingDirective.ts @@ -5,7 +5,7 @@ import { UsingTarget } from './UsingTarget.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class UsingDirective implements SlangNode { readonly kind = NonterminalKind.UsingDirective; @@ -26,7 +26,11 @@ export class UsingDirective implements SlangNode { semicolon: string; - constructor(ast: ast.UsingDirective, offset: number, options: ParserOptions) { + constructor( + ast: ast.UsingDirective, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/UsingTarget.ts b/src/slang-nodes/UsingTarget.ts index 3e6fe009e..b8e840979 100644 --- a/src/slang-nodes/UsingTarget.ts +++ b/src/slang-nodes/UsingTarget.ts @@ -5,7 +5,7 @@ import { TypeName } from './TypeName.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class UsingTarget implements SlangNode { readonly kind = NonterminalKind.UsingTarget; @@ -16,7 +16,11 @@ export class UsingTarget implements SlangNode { variant: TypeName | string; - constructor(ast: ast.UsingTarget, offset: number, options: ParserOptions) { + constructor( + ast: ast.UsingTarget, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/VariableDeclarationStatement.ts b/src/slang-nodes/VariableDeclarationStatement.ts index 30b196cb1..3f76644f5 100644 --- a/src/slang-nodes/VariableDeclarationStatement.ts +++ b/src/slang-nodes/VariableDeclarationStatement.ts @@ -7,7 +7,7 @@ import { VariableDeclarationValue } from './VariableDeclarationValue.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { group, indent, indentIfBreak, line } = doc.builders; @@ -31,7 +31,7 @@ export class VariableDeclarationStatement implements SlangNode { constructor( ast: ast.VariableDeclarationStatement, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/VariableDeclarationType.ts b/src/slang-nodes/VariableDeclarationType.ts index d0efc795b..1c5353ca4 100644 --- a/src/slang-nodes/VariableDeclarationType.ts +++ b/src/slang-nodes/VariableDeclarationType.ts @@ -5,7 +5,7 @@ import { TypeName } from './TypeName.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class VariableDeclarationType implements SlangNode { readonly kind = NonterminalKind.VariableDeclarationType; @@ -19,7 +19,7 @@ export class VariableDeclarationType implements SlangNode { constructor( ast: ast.VariableDeclarationType, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/VariableDeclarationValue.ts b/src/slang-nodes/VariableDeclarationValue.ts index d2fe13503..2eb61a8cf 100644 --- a/src/slang-nodes/VariableDeclarationValue.ts +++ b/src/slang-nodes/VariableDeclarationValue.ts @@ -4,7 +4,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class VariableDeclarationValue implements SlangNode { readonly kind = NonterminalKind.VariableDeclarationValue; @@ -20,7 +20,7 @@ export class VariableDeclarationValue implements SlangNode { constructor( ast: ast.VariableDeclarationValue, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/VersionRange.ts b/src/slang-nodes/VersionRange.ts index 979be3605..e8011cc44 100644 --- a/src/slang-nodes/VersionRange.ts +++ b/src/slang-nodes/VersionRange.ts @@ -37,7 +37,7 @@ export class VersionRange implements SlangNode { print(/* path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions */): Doc { return ['TODO: VersionRange']; } diff --git a/src/slang-nodes/WhileStatement.ts b/src/slang-nodes/WhileStatement.ts index f7c6439c3..3bcbc77e4 100644 --- a/src/slang-nodes/WhileStatement.ts +++ b/src/slang-nodes/WhileStatement.ts @@ -7,7 +7,7 @@ import { Statement } from './Statement.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { group, indent, line } = doc.builders; @@ -28,7 +28,11 @@ export class WhileStatement implements SlangNode { body: Statement; - constructor(ast: ast.WhileStatement, offset: number, options: ParserOptions) { + constructor( + ast: ast.WhileStatement, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/YulArguments.ts b/src/slang-nodes/YulArguments.ts index 5796f5405..f0bef0f35 100644 --- a/src/slang-nodes/YulArguments.ts +++ b/src/slang-nodes/YulArguments.ts @@ -5,7 +5,7 @@ import { YulExpression } from './YulExpression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class YulArguments implements SlangNode { readonly kind = NonterminalKind.YulArguments; @@ -18,7 +18,11 @@ export class YulArguments implements SlangNode { separators: string[]; - constructor(ast: ast.YulArguments, offset: number, options: ParserOptions) { + constructor( + ast: ast.YulArguments, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/YulBlock.ts b/src/slang-nodes/YulBlock.ts index a3478c1cf..7057079b0 100644 --- a/src/slang-nodes/YulBlock.ts +++ b/src/slang-nodes/YulBlock.ts @@ -4,7 +4,7 @@ import { YulStatements } from './YulStatements.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class YulBlock implements SlangNode { readonly kind = NonterminalKind.YulBlock; @@ -19,7 +19,11 @@ export class YulBlock implements SlangNode { closeBrace: string; - constructor(ast: ast.YulBlock, offset: number, options: ParserOptions) { + constructor( + ast: ast.YulBlock, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/YulColonEqual.ts b/src/slang-nodes/YulColonEqual.ts index 68d10b275..da5448281 100644 --- a/src/slang-nodes/YulColonEqual.ts +++ b/src/slang-nodes/YulColonEqual.ts @@ -30,7 +30,7 @@ export class YulColonEqual implements SlangNode { print(/* path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions */): Doc { return ['TODO: YulColonEqual']; } diff --git a/src/slang-nodes/YulDefaultCase.ts b/src/slang-nodes/YulDefaultCase.ts index e3a269c0e..dc6d3dd87 100644 --- a/src/slang-nodes/YulDefaultCase.ts +++ b/src/slang-nodes/YulDefaultCase.ts @@ -4,7 +4,7 @@ import { YulBlock } from './YulBlock.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class YulDefaultCase implements SlangNode { readonly kind = NonterminalKind.YulDefaultCase; @@ -17,7 +17,11 @@ export class YulDefaultCase implements SlangNode { body: YulBlock; - constructor(ast: ast.YulDefaultCase, offset: number, options: ParserOptions) { + constructor( + ast: ast.YulDefaultCase, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/YulExpression.ts b/src/slang-nodes/YulExpression.ts index 75c7fde06..8419346bb 100644 --- a/src/slang-nodes/YulExpression.ts +++ b/src/slang-nodes/YulExpression.ts @@ -7,7 +7,7 @@ import { YulPath } from './YulPath.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class YulExpression implements SlangNode { readonly kind = NonterminalKind.YulExpression; @@ -22,7 +22,11 @@ export class YulExpression implements SlangNode { | YulBuiltInFunction | YulPath; - constructor(ast: ast.YulExpression, offset: number, options: ParserOptions) { + constructor( + ast: ast.YulExpression, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/YulForStatement.ts b/src/slang-nodes/YulForStatement.ts index c25c0468d..4dcc0a813 100644 --- a/src/slang-nodes/YulForStatement.ts +++ b/src/slang-nodes/YulForStatement.ts @@ -5,7 +5,7 @@ import { YulExpression } from './YulExpression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class YulForStatement implements SlangNode { readonly kind = NonterminalKind.YulForStatement; @@ -27,7 +27,7 @@ export class YulForStatement implements SlangNode { constructor( ast: ast.YulForStatement, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/YulFunctionCallExpression.ts b/src/slang-nodes/YulFunctionCallExpression.ts index 05bc01c4e..6d6413a7c 100644 --- a/src/slang-nodes/YulFunctionCallExpression.ts +++ b/src/slang-nodes/YulFunctionCallExpression.ts @@ -5,7 +5,7 @@ import { YulArguments } from './YulArguments.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class YulFunctionCallExpression implements SlangNode { readonly kind = NonterminalKind.YulFunctionCallExpression; @@ -25,7 +25,7 @@ export class YulFunctionCallExpression implements SlangNode { constructor( ast: ast.YulFunctionCallExpression, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/YulFunctionDefinition.ts b/src/slang-nodes/YulFunctionDefinition.ts index 1c0de61dc..2969839e8 100644 --- a/src/slang-nodes/YulFunctionDefinition.ts +++ b/src/slang-nodes/YulFunctionDefinition.ts @@ -6,7 +6,7 @@ import { YulBlock } from './YulBlock.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class YulFunctionDefinition implements SlangNode { readonly kind = NonterminalKind.YulFunctionDefinition; @@ -28,7 +28,7 @@ export class YulFunctionDefinition implements SlangNode { constructor( ast: ast.YulFunctionDefinition, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/YulIfStatement.ts b/src/slang-nodes/YulIfStatement.ts index f0e9e5c5a..c811d929e 100644 --- a/src/slang-nodes/YulIfStatement.ts +++ b/src/slang-nodes/YulIfStatement.ts @@ -5,7 +5,7 @@ import { YulBlock } from './YulBlock.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class YulIfStatement implements SlangNode { readonly kind = NonterminalKind.YulIfStatement; @@ -20,7 +20,11 @@ export class YulIfStatement implements SlangNode { body: YulBlock; - constructor(ast: ast.YulIfStatement, offset: number, options: ParserOptions) { + constructor( + ast: ast.YulIfStatement, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/YulLeaveStatement.ts b/src/slang-nodes/YulLeaveStatement.ts index c1da016d2..ce62a5f18 100644 --- a/src/slang-nodes/YulLeaveStatement.ts +++ b/src/slang-nodes/YulLeaveStatement.ts @@ -27,7 +27,7 @@ export class YulLeaveStatement implements SlangNode { print(/* path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions */): Doc { return ['TODO: YulLeaveStatement']; } diff --git a/src/slang-nodes/YulLiteral.ts b/src/slang-nodes/YulLiteral.ts index e70d2c41a..850c06887 100644 --- a/src/slang-nodes/YulLiteral.ts +++ b/src/slang-nodes/YulLiteral.ts @@ -6,7 +6,7 @@ import { StringLiteral } from './StringLiteral.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class YulLiteral implements SlangNode { readonly kind = NonterminalKind.YulLiteral; @@ -17,7 +17,11 @@ export class YulLiteral implements SlangNode { variant: HexStringLiteral | StringLiteral | string; - constructor(ast: ast.YulLiteral, offset: number, options: ParserOptions) { + constructor( + ast: ast.YulLiteral, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/YulStackAssignmentStatement.ts b/src/slang-nodes/YulStackAssignmentStatement.ts index 038048747..4a2f3e7de 100644 --- a/src/slang-nodes/YulStackAssignmentStatement.ts +++ b/src/slang-nodes/YulStackAssignmentStatement.ts @@ -5,7 +5,7 @@ import { YulExpression } from './YulExpression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { /*AstPath,*/ Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class YulStackAssignmentStatement implements SlangNode { readonly kind = NonterminalKind.YulStackAssignmentStatement; @@ -21,7 +21,7 @@ export class YulStackAssignmentStatement implements SlangNode { constructor( ast: ast.YulStackAssignmentStatement, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; @@ -39,7 +39,7 @@ export class YulStackAssignmentStatement implements SlangNode { print(/* path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions */): Doc { return ['TODO: YulStackAssignmentStatement']; } diff --git a/src/slang-nodes/YulStatement.ts b/src/slang-nodes/YulStatement.ts index a4055b27a..3bd0f8f39 100644 --- a/src/slang-nodes/YulStatement.ts +++ b/src/slang-nodes/YulStatement.ts @@ -16,7 +16,7 @@ import { YulExpression } from './YulExpression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class YulStatement implements SlangNode { readonly kind = NonterminalKind.YulStatement; @@ -40,7 +40,11 @@ export class YulStatement implements SlangNode { | YulLabel | YulExpression; - constructor(ast: ast.YulStatement, offset: number, options: ParserOptions) { + constructor( + ast: ast.YulStatement, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/YulStatements.ts b/src/slang-nodes/YulStatements.ts index 702254a4b..bb89c367b 100644 --- a/src/slang-nodes/YulStatements.ts +++ b/src/slang-nodes/YulStatements.ts @@ -8,7 +8,7 @@ import { YulStatement } from './YulStatement.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { hardline } = doc.builders; @@ -21,7 +21,11 @@ export class YulStatements implements SlangNode { items: YulStatement[]; - constructor(ast: ast.YulStatements, offset: number, options: ParserOptions) { + constructor( + ast: ast.YulStatements, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; @@ -38,7 +42,7 @@ export class YulStatements implements SlangNode { print( path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions ): Doc { return this.items.length === 0 && (!this.comments || this.comments.length === 0) diff --git a/src/slang-nodes/YulSwitchCase.ts b/src/slang-nodes/YulSwitchCase.ts index aea232792..3457d1eff 100644 --- a/src/slang-nodes/YulSwitchCase.ts +++ b/src/slang-nodes/YulSwitchCase.ts @@ -5,7 +5,7 @@ import { YulValueCase } from './YulValueCase.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class YulSwitchCase implements SlangNode { readonly kind = NonterminalKind.YulSwitchCase; @@ -16,7 +16,11 @@ export class YulSwitchCase implements SlangNode { variant: YulDefaultCase | YulValueCase; - constructor(ast: ast.YulSwitchCase, offset: number, options: ParserOptions) { + constructor( + ast: ast.YulSwitchCase, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/YulSwitchCases.ts b/src/slang-nodes/YulSwitchCases.ts index 4c561c5ac..d611ef9f4 100644 --- a/src/slang-nodes/YulSwitchCases.ts +++ b/src/slang-nodes/YulSwitchCases.ts @@ -5,7 +5,7 @@ import { YulSwitchCase } from './YulSwitchCase.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { hardline, join } = doc.builders; @@ -18,7 +18,11 @@ export class YulSwitchCases implements SlangNode { items: YulSwitchCase[]; - constructor(ast: ast.YulSwitchCases, offset: number, options: ParserOptions) { + constructor( + ast: ast.YulSwitchCases, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/YulSwitchStatement.ts b/src/slang-nodes/YulSwitchStatement.ts index 92f184317..30cae6d2d 100644 --- a/src/slang-nodes/YulSwitchStatement.ts +++ b/src/slang-nodes/YulSwitchStatement.ts @@ -6,7 +6,7 @@ import { YulSwitchCases } from './YulSwitchCases.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { hardline } = doc.builders; @@ -26,7 +26,7 @@ export class YulSwitchStatement implements SlangNode { constructor( ast: ast.YulSwitchStatement, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/YulValueCase.ts b/src/slang-nodes/YulValueCase.ts index 177948e70..ef94d8346 100644 --- a/src/slang-nodes/YulValueCase.ts +++ b/src/slang-nodes/YulValueCase.ts @@ -5,7 +5,7 @@ import { YulBlock } from './YulBlock.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class YulValueCase implements SlangNode { readonly kind = NonterminalKind.YulValueCase; @@ -20,7 +20,11 @@ export class YulValueCase implements SlangNode { body: YulBlock; - constructor(ast: ast.YulValueCase, offset: number, options: ParserOptions) { + constructor( + ast: ast.YulValueCase, + offset: number, + options: ParserOptions + ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/YulVariableAssignmentStatement.ts b/src/slang-nodes/YulVariableAssignmentStatement.ts index b55869841..d8e57c459 100644 --- a/src/slang-nodes/YulVariableAssignmentStatement.ts +++ b/src/slang-nodes/YulVariableAssignmentStatement.ts @@ -6,7 +6,7 @@ import { YulExpression } from './YulExpression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class YulVariableAssignmentStatement implements SlangNode { readonly kind = NonterminalKind.YulVariableAssignmentStatement; @@ -24,7 +24,7 @@ export class YulVariableAssignmentStatement implements SlangNode { constructor( ast: ast.YulVariableAssignmentStatement, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/YulVariableDeclarationStatement.ts b/src/slang-nodes/YulVariableDeclarationStatement.ts index f97aaa815..1c71aa44b 100644 --- a/src/slang-nodes/YulVariableDeclarationStatement.ts +++ b/src/slang-nodes/YulVariableDeclarationStatement.ts @@ -4,7 +4,7 @@ import { YulVariableDeclarationValue } from './YulVariableDeclarationValue.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class YulVariableDeclarationStatement implements SlangNode { readonly kind = NonterminalKind.YulVariableDeclarationStatement; @@ -22,7 +22,7 @@ export class YulVariableDeclarationStatement implements SlangNode { constructor( ast: ast.YulVariableDeclarationStatement, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-nodes/YulVariableDeclarationValue.ts b/src/slang-nodes/YulVariableDeclarationValue.ts index c3df5762f..9e020861e 100644 --- a/src/slang-nodes/YulVariableDeclarationValue.ts +++ b/src/slang-nodes/YulVariableDeclarationValue.ts @@ -5,7 +5,7 @@ import { YulExpression } from './YulExpression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class YulVariableDeclarationValue implements SlangNode { readonly kind = NonterminalKind.YulVariableDeclarationValue; @@ -21,7 +21,7 @@ export class YulVariableDeclarationValue implements SlangNode { constructor( ast: ast.YulVariableDeclarationValue, offset: number, - options: ParserOptions + options: ParserOptions ) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; diff --git a/src/slang-printers/create-binary-operation-printer.ts b/src/slang-printers/create-binary-operation-printer.ts index 508bbce9d..218ccec2b 100644 --- a/src/slang-printers/create-binary-operation-printer.ts +++ b/src/slang-printers/create-binary-operation-printer.ts @@ -29,14 +29,14 @@ export const createBinaryOperationPrinter = groupRulesBuilder: (path: AstPath) => (document: Doc) => Doc, indentRulesBuilder: ( path: AstPath, - options: ParserOptions + options: ParserOptions ) => (document: Doc) => Doc ) => ( node: BinaryOperation, path: AstPath, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions ): Doc => { const groupRules = groupRulesBuilder(path); const indentRules = indentRulesBuilder(path, options); diff --git a/src/slang-printers/print-logical-operation.ts b/src/slang-printers/print-logical-operation.ts index 9e16b6506..3eea0fd1e 100644 --- a/src/slang-printers/print-logical-operation.ts +++ b/src/slang-printers/print-logical-operation.ts @@ -21,7 +21,7 @@ const logicalGroupRulesBuilder = isBinaryOperation(path.getNode(2) as AstNode) ? document : group(document); const logicalIndentRulesBuilder = - (path: AstPath, options: ParserOptions) => + (path: AstPath, options: ParserOptions) => (document: Doc): Doc => { let node = path.getNode() as AstNode; for (let i = 2; ; i += 2) { diff --git a/src/slang-printers/print-preserving-empty-lines.ts b/src/slang-printers/print-preserving-empty-lines.ts index d5bece192..b0e87bcfe 100644 --- a/src/slang-printers/print-preserving-empty-lines.ts +++ b/src/slang-printers/print-preserving-empty-lines.ts @@ -15,7 +15,7 @@ export function printPreservingEmptyLines( path: AstPath, key: string, print: (path: AstPath) => Doc, - options: ParserOptions + options: ParserOptions ): Doc { return path.map((childPath, index) => { const node = childPath.getNode() as AstNode; diff --git a/src/slang-printers/print-string.ts b/src/slang-printers/print-string.ts index 5d925d7fd..7f77aa68c 100644 --- a/src/slang-printers/print-string.ts +++ b/src/slang-printers/print-string.ts @@ -2,13 +2,14 @@ import { util } from 'prettier'; import type { ParserOptions } from 'prettier'; import type { QuoteRegex } from './types'; +import type { AstNode } from '../types'; const double: QuoteRegex = { quote: '"', regex: /"/g }; const single: QuoteRegex = { quote: "'", regex: /'/g }; export function printString( rawContent: string, - options: ParserOptions + options: ParserOptions ): string { const preferred = options.singleQuote ? single : double; const alternate = preferred === single ? double : single; diff --git a/src/slangParser.ts b/src/slangParser.ts index 768421382..d761be39f 100644 --- a/src/slangParser.ts +++ b/src/slangParser.ts @@ -12,8 +12,8 @@ import type { AstNode } from './types.js'; function parse( text: string, - _parsers: Parser[] | ParserOptions, - options = _parsers as ParserOptions + _parsers: Parser[] | ParserOptions, + options = _parsers as ParserOptions ): AstNode { const compiler = coerce(options.compiler); diff --git a/src/slangPrinter.ts b/src/slangPrinter.ts index 2c3bdc17f..7cb7a06e2 100644 --- a/src/slangPrinter.ts +++ b/src/slangPrinter.ts @@ -67,7 +67,7 @@ function ignoreComments(path: AstPath): void { function genericPrint( path: AstPath, - options: ParserOptions, + options: ParserOptions, print: (path: AstPath) => Doc ): Doc { prettierVersionCheck(); diff --git a/tests/unit/prettier-version/esmock-plugin.js b/tests/unit/prettier-version/esmock-plugin.js index 20a129d95..65df6ca67 100644 --- a/tests/unit/prettier-version/esmock-plugin.js +++ b/tests/unit/prettier-version/esmock-plugin.js @@ -5,7 +5,7 @@ const esmockPlugin = async () => { const prettierMock = { ...prettier, version: '2.2.1' }; const plugin = await esmock( - '../../../src/index.js', + '../../../src/index.ts', {}, { prettier: prettierMock From 4cc09fe0bd02440924d568d62d5dbb4ae99484f5 Mon Sep 17 00:00:00 2001 From: Klaus Date: Thu, 1 Aug 2024 18:12:56 +1200 Subject: [PATCH 106/160] using specific versions of AstPath --- src/slang-nodes/AdditiveExpression.ts | 4 +- src/slang-nodes/AndExpression.ts | 4 +- src/slang-nodes/ArgumentsDeclaration.ts | 5 +- src/slang-nodes/ArrayExpression.ts | 5 +- src/slang-nodes/ArrayTypeName.ts | 5 +- src/slang-nodes/ArrayValues.ts | 5 +- src/slang-nodes/AssemblyFlags.ts | 5 +- src/slang-nodes/AssemblyFlagsDeclaration.ts | 5 +- src/slang-nodes/AssemblyStatement.ts | 5 +- src/slang-nodes/AssignmentExpression.ts | 5 +- src/slang-nodes/BitwiseAndExpression.ts | 4 +- src/slang-nodes/BitwiseOrExpression.ts | 4 +- src/slang-nodes/BitwiseXorExpression.ts | 4 +- src/slang-nodes/Block.ts | 2 +- src/slang-nodes/CallOptions.ts | 4 +- src/slang-nodes/CallOptionsExpression.ts | 5 +- src/slang-nodes/CatchClause.ts | 5 +- src/slang-nodes/CatchClauseError.ts | 5 +- src/slang-nodes/CatchClauses.ts | 5 +- src/slang-nodes/ComparisonExpression.ts | 4 +- src/slang-nodes/ConditionalExpression.ts | 12 ++--- src/slang-nodes/ConstantDefinition.ts | 4 +- src/slang-nodes/ConstructorAttribute.ts | 5 +- src/slang-nodes/ConstructorAttributes.ts | 5 +- src/slang-nodes/ConstructorDefinition.ts | 5 +- src/slang-nodes/ContractDefinition.ts | 5 +- src/slang-nodes/ContractMember.ts | 5 +- src/slang-nodes/ContractMembers.ts | 6 +-- src/slang-nodes/DecimalNumberExpression.ts | 7 ++- src/slang-nodes/DoWhileStatement.ts | 5 +- src/slang-nodes/ElementaryType.ts | 7 ++- src/slang-nodes/ElseBranch.ts | 5 +- src/slang-nodes/EmitStatement.ts | 5 +- src/slang-nodes/EnumDefinition.ts | 7 ++- src/slang-nodes/EqualityExpression.ts | 4 +- src/slang-nodes/ErrorDefinition.ts | 5 +- src/slang-nodes/ErrorParameter.ts | 5 +- src/slang-nodes/ErrorParameters.ts | 5 +- src/slang-nodes/ErrorParametersDeclaration.ts | 5 +- src/slang-nodes/EventDefinition.ts | 5 +- src/slang-nodes/EventParameter.ts | 5 +- src/slang-nodes/EventParameters.ts | 5 +- src/slang-nodes/EventParametersDeclaration.ts | 5 +- src/slang-nodes/ExperimentalFeature.ts | 5 +- src/slang-nodes/ExperimentalPragma.ts | 5 +- src/slang-nodes/ExponentiationExpression.ts | 4 +- src/slang-nodes/Expression.ts | 5 +- src/slang-nodes/ExpressionStatement.ts | 5 +- src/slang-nodes/FallbackFunctionAttribute.ts | 5 +- src/slang-nodes/FallbackFunctionAttributes.ts | 5 +- src/slang-nodes/FallbackFunctionDefinition.ts | 5 +- src/slang-nodes/ForStatement.ts | 5 +- src/slang-nodes/ForStatementCondition.ts | 5 +- src/slang-nodes/ForStatementInitialization.ts | 5 +- src/slang-nodes/FunctionAttribute.ts | 5 +- src/slang-nodes/FunctionAttributes.ts | 5 +- src/slang-nodes/FunctionBody.ts | 5 +- src/slang-nodes/FunctionCallExpression.ts | 5 +- src/slang-nodes/FunctionDefinition.ts | 5 +- src/slang-nodes/FunctionType.ts | 5 +- src/slang-nodes/FunctionTypeAttributes.ts | 7 ++- src/slang-nodes/HexNumberExpression.ts | 7 ++- src/slang-nodes/HexStringLiterals.ts | 5 +- src/slang-nodes/IfStatement.ts | 5 +- src/slang-nodes/ImportClause.ts | 5 +- src/slang-nodes/ImportDeconstruction.ts | 5 +- src/slang-nodes/ImportDeconstructionSymbol.ts | 7 ++- .../ImportDeconstructionSymbols.ts | 4 +- src/slang-nodes/ImportDirective.ts | 5 +- src/slang-nodes/IndexAccessEnd.ts | 5 +- src/slang-nodes/IndexAccessExpression.ts | 5 +- src/slang-nodes/InheritanceSpecifier.ts | 5 +- src/slang-nodes/InheritanceType.ts | 5 +- src/slang-nodes/InheritanceTypes.ts | 5 +- src/slang-nodes/InterfaceDefinition.ts | 5 +- src/slang-nodes/InterfaceMembers.ts | 12 ++--- src/slang-nodes/LibraryDefinition.ts | 5 +- src/slang-nodes/LibraryMembers.ts | 12 ++--- src/slang-nodes/MappingKey.ts | 7 ++- src/slang-nodes/MappingKeyType.ts | 7 ++- src/slang-nodes/MappingType.ts | 5 +- src/slang-nodes/MappingValue.ts | 5 +- src/slang-nodes/MemberAccessExpression.ts | 10 +++- src/slang-nodes/ModifierAttribute.ts | 7 ++- src/slang-nodes/ModifierAttributes.ts | 7 ++- src/slang-nodes/ModifierDefinition.ts | 5 +- src/slang-nodes/ModifierInvocation.ts | 5 +- src/slang-nodes/MultiplicativeExpression.ts | 4 +- src/slang-nodes/NamedArgument.ts | 5 +- src/slang-nodes/NamedArgumentGroup.ts | 5 +- src/slang-nodes/NamedArguments.ts | 4 +- src/slang-nodes/NamedArgumentsDeclaration.ts | 5 +- src/slang-nodes/NamedImport.ts | 5 +- src/slang-nodes/NewExpression.ts | 5 +- src/slang-nodes/OrExpression.ts | 4 +- src/slang-nodes/OverridePaths.ts | 4 +- src/slang-nodes/OverridePathsDeclaration.ts | 4 +- src/slang-nodes/OverrideSpecifier.ts | 7 ++- src/slang-nodes/Parameter.ts | 5 +- src/slang-nodes/Parameters.ts | 5 +- src/slang-nodes/ParametersDeclaration.ts | 5 +- src/slang-nodes/PathImport.ts | 5 +- src/slang-nodes/PositionalArguments.ts | 5 +- .../PositionalArgumentsDeclaration.ts | 5 +- src/slang-nodes/PostfixExpression.ts | 5 +- src/slang-nodes/Pragma.ts | 2 +- src/slang-nodes/PragmaDirective.ts | 5 +- src/slang-nodes/PrefixExpression.ts | 5 +- src/slang-nodes/ReceiveFunctionAttribute.ts | 5 +- src/slang-nodes/ReceiveFunctionAttributes.ts | 5 +- src/slang-nodes/ReceiveFunctionDefinition.ts | 5 +- src/slang-nodes/ReturnStatement.ts | 8 +-- src/slang-nodes/ReturnsDeclaration.ts | 5 +- src/slang-nodes/RevertStatement.ts | 5 +- src/slang-nodes/ShiftExpression.ts | 4 +- src/slang-nodes/SourceUnit.ts | 4 +- src/slang-nodes/SourceUnitMember.ts | 5 +- src/slang-nodes/SourceUnitMembers.ts | 6 +-- src/slang-nodes/StateVariableAttribute.ts | 7 ++- src/slang-nodes/StateVariableAttributes.ts | 7 ++- src/slang-nodes/StateVariableDefinition.ts | 5 +- .../StateVariableDefinitionValue.ts | 5 +- src/slang-nodes/Statement.ts | 2 +- src/slang-nodes/Statements.ts | 6 +-- src/slang-nodes/StringExpression.ts | 5 +- src/slang-nodes/StringLiterals.ts | 5 +- src/slang-nodes/StructDefinition.ts | 5 +- src/slang-nodes/StructMember.ts | 5 +- src/slang-nodes/StructMembers.ts | 5 +- src/slang-nodes/TryStatement.ts | 5 +- src/slang-nodes/TupleDeconstructionElement.ts | 5 +- .../TupleDeconstructionElements.ts | 5 +- .../TupleDeconstructionStatement.ts | 5 +- src/slang-nodes/TupleExpression.ts | 5 +- src/slang-nodes/TupleMember.ts | 5 +- src/slang-nodes/TupleValue.ts | 5 +- src/slang-nodes/TupleValues.ts | 5 +- src/slang-nodes/TypeExpression.ts | 4 +- src/slang-nodes/TypeName.ts | 2 +- src/slang-nodes/TypedTupleMember.ts | 5 +- src/slang-nodes/UncheckedBlock.ts | 5 +- src/slang-nodes/UnicodeStringLiterals.ts | 5 +- src/slang-nodes/UnnamedFunctionAttribute.ts | 5 +- src/slang-nodes/UnnamedFunctionAttributes.ts | 5 +- src/slang-nodes/UnnamedFunctionDefinition.ts | 5 +- src/slang-nodes/UntypedTupleMember.ts | 4 +- .../UserDefinedValueTypeDefinition.ts | 7 ++- src/slang-nodes/UsingAlias.ts | 7 ++- src/slang-nodes/UsingClause.ts | 7 ++- src/slang-nodes/UsingDeconstruction.ts | 7 ++- src/slang-nodes/UsingDeconstructionSymbol.ts | 7 ++- src/slang-nodes/UsingDeconstructionSymbols.ts | 4 +- src/slang-nodes/UsingDirective.ts | 5 +- src/slang-nodes/UsingTarget.ts | 5 +- .../VariableDeclarationStatement.ts | 5 +- src/slang-nodes/VariableDeclarationType.ts | 5 +- src/slang-nodes/VariableDeclarationValue.ts | 5 +- src/slang-nodes/VersionComparator.ts | 7 ++- src/slang-nodes/VersionExpression.ts | 7 ++- src/slang-nodes/VersionExpressionSet.ts | 7 ++- src/slang-nodes/VersionExpressionSets.ts | 7 ++- src/slang-nodes/VersionPragma.ts | 7 ++- src/slang-nodes/VersionRange.ts | 4 +- src/slang-nodes/WhileStatement.ts | 5 +- src/slang-nodes/YulArguments.ts | 5 +- src/slang-nodes/YulAssignmentOperator.ts | 7 ++- src/slang-nodes/YulBlock.ts | 2 +- src/slang-nodes/YulColonEqual.ts | 4 +- src/slang-nodes/YulDefaultCase.ts | 5 +- src/slang-nodes/YulExpression.ts | 5 +- src/slang-nodes/YulForStatement.ts | 5 +- src/slang-nodes/YulFunctionCallExpression.ts | 5 +- src/slang-nodes/YulFunctionDefinition.ts | 5 +- src/slang-nodes/YulIfStatement.ts | 5 +- src/slang-nodes/YulLeaveStatement.ts | 4 +- src/slang-nodes/YulLiteral.ts | 5 +- src/slang-nodes/YulParametersDeclaration.ts | 7 ++- src/slang-nodes/YulPath.ts | 4 +- src/slang-nodes/YulPaths.ts | 4 +- src/slang-nodes/YulReturnsDeclaration.ts | 7 ++- .../YulStackAssignmentStatement.ts | 4 +- src/slang-nodes/YulStatement.ts | 5 +- src/slang-nodes/YulStatements.ts | 6 +-- src/slang-nodes/YulSwitchCase.ts | 5 +- src/slang-nodes/YulSwitchCases.ts | 5 +- src/slang-nodes/YulSwitchStatement.ts | 5 +- src/slang-nodes/YulValueCase.ts | 5 +- .../YulVariableAssignmentStatement.ts | 5 +- .../YulVariableDeclarationStatement.ts | 5 +- .../YulVariableDeclarationValue.ts | 5 +- .../create-binary-operation-printer.ts | 14 +++--- src/slang-printers/print-binary-operation.ts | 4 +- src/slang-printers/print-comments.ts | 2 +- .../print-comparison-operation.ts | 4 +- src/slang-printers/print-function.ts | 6 +-- src/slang-printers/print-logical-operation.ts | 6 +-- .../print-preserving-empty-lines.ts | 11 ++--- src/slang-utils/backward-compatibility.ts | 9 ++-- src/slangPrinter.ts | 14 ++++-- src/types.d.ts | 49 ++++++++++++++++++- 200 files changed, 809 insertions(+), 303 deletions(-) diff --git a/src/slang-nodes/AdditiveExpression.ts b/src/slang-nodes/AdditiveExpression.ts index 0db8e6715..b7a3a8acf 100644 --- a/src/slang-nodes/AdditiveExpression.ts +++ b/src/slang-nodes/AdditiveExpression.ts @@ -45,8 +45,8 @@ export class AdditiveExpression implements SlangNode { } print( - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions ): Doc { return printBinaryOperation(this, path, print, options); diff --git a/src/slang-nodes/AndExpression.ts b/src/slang-nodes/AndExpression.ts index b7eac5664..8b4440ed1 100644 --- a/src/slang-nodes/AndExpression.ts +++ b/src/slang-nodes/AndExpression.ts @@ -39,8 +39,8 @@ export class AndExpression implements SlangNode { } print( - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions ): Doc { return printLogicalOperation(this, path, print, options); diff --git a/src/slang-nodes/ArgumentsDeclaration.ts b/src/slang-nodes/ArgumentsDeclaration.ts index b665b1411..ce9411897 100644 --- a/src/slang-nodes/ArgumentsDeclaration.ts +++ b/src/slang-nodes/ArgumentsDeclaration.ts @@ -49,7 +49,10 @@ export class ArgumentsDeclaration implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/ArrayExpression.ts b/src/slang-nodes/ArrayExpression.ts index 8768565d1..cef9d35bc 100644 --- a/src/slang-nodes/ArrayExpression.ts +++ b/src/slang-nodes/ArrayExpression.ts @@ -40,7 +40,10 @@ export class ArrayExpression implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return group([ this.openBracket, path.call(print, 'items'), diff --git a/src/slang-nodes/ArrayTypeName.ts b/src/slang-nodes/ArrayTypeName.ts index 00b9004b8..049eb8506 100644 --- a/src/slang-nodes/ArrayTypeName.ts +++ b/src/slang-nodes/ArrayTypeName.ts @@ -43,7 +43,10 @@ export class ArrayTypeName implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ path.call(print, 'operand'), this.openBracket, diff --git a/src/slang-nodes/ArrayValues.ts b/src/slang-nodes/ArrayValues.ts index b62c15903..530749ac0 100644 --- a/src/slang-nodes/ArrayValues.ts +++ b/src/slang-nodes/ArrayValues.ts @@ -37,7 +37,10 @@ export class ArrayValues implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return printSeparatedList(path.map(print, 'items')); } } diff --git a/src/slang-nodes/AssemblyFlags.ts b/src/slang-nodes/AssemblyFlags.ts index 73d1bfef6..b7aec3347 100644 --- a/src/slang-nodes/AssemblyFlags.ts +++ b/src/slang-nodes/AssemblyFlags.ts @@ -37,7 +37,10 @@ export class AssemblyFlags implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return printSeparatedList(path.map(print, 'items')); } } diff --git a/src/slang-nodes/AssemblyFlagsDeclaration.ts b/src/slang-nodes/AssemblyFlagsDeclaration.ts index 887ab2b4c..73e38229d 100644 --- a/src/slang-nodes/AssemblyFlagsDeclaration.ts +++ b/src/slang-nodes/AssemblyFlagsDeclaration.ts @@ -37,7 +37,10 @@ export class AssemblyFlagsDeclaration implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [this.openParen, path.call(print, 'flags'), this.closeParen]; } } diff --git a/src/slang-nodes/AssemblyStatement.ts b/src/slang-nodes/AssemblyStatement.ts index 6a0785dc5..9a669c3ec 100644 --- a/src/slang-nodes/AssemblyStatement.ts +++ b/src/slang-nodes/AssemblyStatement.ts @@ -49,7 +49,10 @@ export class AssemblyStatement implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ `${this.assemblyKeyword} `, this.label ? [path.call(print, 'label'), ' '] : '', diff --git a/src/slang-nodes/AssignmentExpression.ts b/src/slang-nodes/AssignmentExpression.ts index 6d564f9cf..65ba4d332 100644 --- a/src/slang-nodes/AssignmentExpression.ts +++ b/src/slang-nodes/AssignmentExpression.ts @@ -41,7 +41,10 @@ export class AssignmentExpression implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ path.call(print, 'leftOperand'), ` ${this.operator}`, diff --git a/src/slang-nodes/BitwiseAndExpression.ts b/src/slang-nodes/BitwiseAndExpression.ts index 2f06355f1..95e0d58ba 100644 --- a/src/slang-nodes/BitwiseAndExpression.ts +++ b/src/slang-nodes/BitwiseAndExpression.ts @@ -45,8 +45,8 @@ export class BitwiseAndExpression implements SlangNode { } print( - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions ): Doc { return printBinaryOperation(this, path, print, options); diff --git a/src/slang-nodes/BitwiseOrExpression.ts b/src/slang-nodes/BitwiseOrExpression.ts index a1e96aa43..dd5746826 100644 --- a/src/slang-nodes/BitwiseOrExpression.ts +++ b/src/slang-nodes/BitwiseOrExpression.ts @@ -55,8 +55,8 @@ export class BitwiseOrExpression implements SlangNode { } print( - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions ): Doc { return printBinaryOperation(this, path, print, options); diff --git a/src/slang-nodes/BitwiseXorExpression.ts b/src/slang-nodes/BitwiseXorExpression.ts index eca9020a4..dd8d78d6c 100644 --- a/src/slang-nodes/BitwiseXorExpression.ts +++ b/src/slang-nodes/BitwiseXorExpression.ts @@ -45,8 +45,8 @@ export class BitwiseXorExpression implements SlangNode { } print( - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions ): Doc { return printBinaryOperation(this, path, print, options); diff --git a/src/slang-nodes/Block.ts b/src/slang-nodes/Block.ts index cd8ac0b6d..034452c88 100644 --- a/src/slang-nodes/Block.ts +++ b/src/slang-nodes/Block.ts @@ -33,7 +33,7 @@ export class Block implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print(path: AstPath, print: (path: AstPath) => Doc): Doc { return [this.openBrace, path.call(print, 'statements'), this.closeBrace]; } } diff --git a/src/slang-nodes/CallOptions.ts b/src/slang-nodes/CallOptions.ts index f6e39fc9d..592b57ccb 100644 --- a/src/slang-nodes/CallOptions.ts +++ b/src/slang-nodes/CallOptions.ts @@ -41,8 +41,8 @@ export class CallOptions implements SlangNode { } print( - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions ): Doc { return printSeparatedList(path.map(print, 'items'), { diff --git a/src/slang-nodes/CallOptionsExpression.ts b/src/slang-nodes/CallOptionsExpression.ts index d9b12732f..4a0e6884b 100644 --- a/src/slang-nodes/CallOptionsExpression.ts +++ b/src/slang-nodes/CallOptionsExpression.ts @@ -41,7 +41,10 @@ export class CallOptionsExpression implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ path.call(print, 'operand'), this.openBrace, diff --git a/src/slang-nodes/CatchClause.ts b/src/slang-nodes/CatchClause.ts index 24bb281b7..7a0527d53 100644 --- a/src/slang-nodes/CatchClause.ts +++ b/src/slang-nodes/CatchClause.ts @@ -42,7 +42,10 @@ export class CatchClause implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ `${this.catchKeyword} `, this.error ? path.call(print, 'error') : '', diff --git a/src/slang-nodes/CatchClauseError.ts b/src/slang-nodes/CatchClauseError.ts index aa2fad0cb..67b364816 100644 --- a/src/slang-nodes/CatchClauseError.ts +++ b/src/slang-nodes/CatchClauseError.ts @@ -41,7 +41,10 @@ export class CatchClauseError implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [`${this.name ?? ''}`, group(path.call(print, 'parameters')), ' ']; } } diff --git a/src/slang-nodes/CatchClauses.ts b/src/slang-nodes/CatchClauses.ts index b1bf0e2c1..e76af0b98 100644 --- a/src/slang-nodes/CatchClauses.ts +++ b/src/slang-nodes/CatchClauses.ts @@ -36,7 +36,10 @@ export class CatchClauses implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return join(' ', path.map(print, 'items')); } } diff --git a/src/slang-nodes/ComparisonExpression.ts b/src/slang-nodes/ComparisonExpression.ts index ed0ad2320..885f7b195 100644 --- a/src/slang-nodes/ComparisonExpression.ts +++ b/src/slang-nodes/ComparisonExpression.ts @@ -39,8 +39,8 @@ export class ComparisonExpression implements SlangNode { } print( - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions ): Doc { return printComparisonOperation(this, path, print, options); diff --git a/src/slang-nodes/ConditionalExpression.ts b/src/slang-nodes/ConditionalExpression.ts index eaaf8d3f8..0c69e9235 100644 --- a/src/slang-nodes/ConditionalExpression.ts +++ b/src/slang-nodes/ConditionalExpression.ts @@ -13,8 +13,8 @@ const { group, hardline, ifBreak, indent, line, softline } = doc.builders; function experimentalTernaries( node: ConditionalExpression, - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions ): Doc { const grandparent = path.getNode(2) as AstNode; @@ -87,8 +87,8 @@ function experimentalTernaries( function traditionalTernaries( node: ConditionalExpression, - path: AstPath, - print: (path: AstPath) => Doc + path: AstPath, + print: (path: AstPath) => Doc ): Doc { return group([ path.call(print, 'operand'), @@ -176,8 +176,8 @@ export class ConditionalExpression implements SlangNode { } print( - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions ): Doc { return options.experimentalTernaries diff --git a/src/slang-nodes/ConstantDefinition.ts b/src/slang-nodes/ConstantDefinition.ts index 36fd5f325..1ef88be55 100644 --- a/src/slang-nodes/ConstantDefinition.ts +++ b/src/slang-nodes/ConstantDefinition.ts @@ -49,8 +49,8 @@ export class ConstantDefinition implements SlangNode { // TODO: implement print print(/* - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions */): Doc { return ['TODO: ConstantDefinition']; diff --git a/src/slang-nodes/ConstructorAttribute.ts b/src/slang-nodes/ConstructorAttribute.ts index f0c724af3..8248d6b07 100644 --- a/src/slang-nodes/ConstructorAttribute.ts +++ b/src/slang-nodes/ConstructorAttribute.ts @@ -38,7 +38,10 @@ export class ConstructorAttribute implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/ConstructorAttributes.ts b/src/slang-nodes/ConstructorAttributes.ts index a81c04a27..d08f7d555 100644 --- a/src/slang-nodes/ConstructorAttributes.ts +++ b/src/slang-nodes/ConstructorAttributes.ts @@ -39,7 +39,10 @@ export class ConstructorAttributes implements SlangNode { this.items = this.items.sort(sortFunctionAttributes); } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return path.map(print, 'items').map((item) => [line, item]); } } diff --git a/src/slang-nodes/ConstructorDefinition.ts b/src/slang-nodes/ConstructorDefinition.ts index e9ced9528..26754d2f6 100644 --- a/src/slang-nodes/ConstructorDefinition.ts +++ b/src/slang-nodes/ConstructorDefinition.ts @@ -55,7 +55,10 @@ export class ConstructorDefinition implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return printFunction(this.constructorKeyword, this, path, print); } } diff --git a/src/slang-nodes/ContractDefinition.ts b/src/slang-nodes/ContractDefinition.ts index 41171a6ab..702d4fe78 100644 --- a/src/slang-nodes/ContractDefinition.ts +++ b/src/slang-nodes/ContractDefinition.ts @@ -81,7 +81,10 @@ export class ContractDefinition implements SlangNode { } } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ group([ `${this.abstractKeyword ? `${this.abstractKeyword} ` : ''}${this.contractKeyword} ${this.name}`, diff --git a/src/slang-nodes/ContractMember.ts b/src/slang-nodes/ContractMember.ts index 4eeb04a19..36199e1b2 100644 --- a/src/slang-nodes/ContractMember.ts +++ b/src/slang-nodes/ContractMember.ts @@ -148,7 +148,10 @@ export class ContractMember implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/ContractMembers.ts b/src/slang-nodes/ContractMembers.ts index 722b36786..1fd8e22bf 100644 --- a/src/slang-nodes/ContractMembers.ts +++ b/src/slang-nodes/ContractMembers.ts @@ -40,8 +40,8 @@ export class ContractMembers implements SlangNode { } print( - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions ): Doc { return this.items.length === 0 && @@ -49,7 +49,7 @@ export class ContractMembers implements SlangNode { ? '' : printSeparatedItem( [ - printPreservingEmptyLines(path, 'items', print, options), + printPreservingEmptyLines(path, print, options), printComments(this, path) ], { firstSeparator: hardline, grouped: false } diff --git a/src/slang-nodes/DecimalNumberExpression.ts b/src/slang-nodes/DecimalNumberExpression.ts index 14af61d3e..a808acc04 100644 --- a/src/slang-nodes/DecimalNumberExpression.ts +++ b/src/slang-nodes/DecimalNumberExpression.ts @@ -4,7 +4,7 @@ import { NumberUnit } from './NumberUnit.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class DecimalNumberExpression implements SlangNode { readonly kind = NonterminalKind.DecimalNumberExpression; @@ -32,7 +32,10 @@ export class DecimalNumberExpression implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [this.literal, this.unit ? [' ', path.call(print, 'unit')] : '']; } } diff --git a/src/slang-nodes/DoWhileStatement.ts b/src/slang-nodes/DoWhileStatement.ts index 15c7e5ba7..0fb38fe15 100644 --- a/src/slang-nodes/DoWhileStatement.ts +++ b/src/slang-nodes/DoWhileStatement.ts @@ -54,7 +54,10 @@ export class DoWhileStatement implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ this.doKeyword, this.body.variant.kind === NonterminalKind.Block diff --git a/src/slang-nodes/ElementaryType.ts b/src/slang-nodes/ElementaryType.ts index f24b5d84b..9c9e7cc5e 100644 --- a/src/slang-nodes/ElementaryType.ts +++ b/src/slang-nodes/ElementaryType.ts @@ -5,7 +5,7 @@ import { AddressType } from './AddressType.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class ElementaryType implements SlangNode { readonly kind = NonterminalKind.ElementaryType; @@ -34,7 +34,10 @@ export class ElementaryType implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/ElseBranch.ts b/src/slang-nodes/ElseBranch.ts index bcfce5421..c8443d355 100644 --- a/src/slang-nodes/ElseBranch.ts +++ b/src/slang-nodes/ElseBranch.ts @@ -43,7 +43,10 @@ export class ElseBranch implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ this.elseKeyword, isIfStatementOrBlock(this.body.variant) diff --git a/src/slang-nodes/EmitStatement.ts b/src/slang-nodes/EmitStatement.ts index 2af41983c..24fb19d27 100644 --- a/src/slang-nodes/EmitStatement.ts +++ b/src/slang-nodes/EmitStatement.ts @@ -45,7 +45,10 @@ export class EmitStatement implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ `${this.emitKeyword} `, path.call(print, 'event'), diff --git a/src/slang-nodes/EnumDefinition.ts b/src/slang-nodes/EnumDefinition.ts index a9adc21ed..3999679c4 100644 --- a/src/slang-nodes/EnumDefinition.ts +++ b/src/slang-nodes/EnumDefinition.ts @@ -4,7 +4,7 @@ import { EnumMembers } from './EnumMembers.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class EnumDefinition implements SlangNode { readonly kind = NonterminalKind.EnumDefinition; @@ -39,7 +39,10 @@ export class EnumDefinition implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ `${this.enumKeyword} ${this.name} ${this.openBrace}`, path.call(print, 'members'), diff --git a/src/slang-nodes/EqualityExpression.ts b/src/slang-nodes/EqualityExpression.ts index 9b9907f25..fc12cc135 100644 --- a/src/slang-nodes/EqualityExpression.ts +++ b/src/slang-nodes/EqualityExpression.ts @@ -39,8 +39,8 @@ export class EqualityExpression implements SlangNode { } print( - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions ): Doc { return printComparisonOperation(this, path, print, options); diff --git a/src/slang-nodes/ErrorDefinition.ts b/src/slang-nodes/ErrorDefinition.ts index 90d5350b6..7b8ce7515 100644 --- a/src/slang-nodes/ErrorDefinition.ts +++ b/src/slang-nodes/ErrorDefinition.ts @@ -44,7 +44,10 @@ export class ErrorDefinition implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ `${this.errorKeyword} ${this.name}`, path.call(print, 'members'), diff --git a/src/slang-nodes/ErrorParameter.ts b/src/slang-nodes/ErrorParameter.ts index 0984d537b..70c1abe41 100644 --- a/src/slang-nodes/ErrorParameter.ts +++ b/src/slang-nodes/ErrorParameter.ts @@ -34,7 +34,10 @@ export class ErrorParameter implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [path.call(print, 'typeName'), this.name ? ` ${this.name}` : '']; } } diff --git a/src/slang-nodes/ErrorParameters.ts b/src/slang-nodes/ErrorParameters.ts index c359285b4..0a010901d 100644 --- a/src/slang-nodes/ErrorParameters.ts +++ b/src/slang-nodes/ErrorParameters.ts @@ -37,7 +37,10 @@ export class ErrorParameters implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return this.items.length > 0 ? printSeparatedList(path.map(print, 'items')) : ''; diff --git a/src/slang-nodes/ErrorParametersDeclaration.ts b/src/slang-nodes/ErrorParametersDeclaration.ts index 2c9176d23..9e2c2aa39 100644 --- a/src/slang-nodes/ErrorParametersDeclaration.ts +++ b/src/slang-nodes/ErrorParametersDeclaration.ts @@ -37,7 +37,10 @@ export class ErrorParametersDeclaration implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [this.openParen, path.call(print, 'parameters'), this.closeParen]; } } diff --git a/src/slang-nodes/EventDefinition.ts b/src/slang-nodes/EventDefinition.ts index 8086b63c6..36d9119e7 100644 --- a/src/slang-nodes/EventDefinition.ts +++ b/src/slang-nodes/EventDefinition.ts @@ -47,7 +47,10 @@ export class EventDefinition implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ `${this.eventKeyword} ${this.name}`, path.call(print, 'parameters'), diff --git a/src/slang-nodes/EventParameter.ts b/src/slang-nodes/EventParameter.ts index 13e9891ae..7a05bb15f 100644 --- a/src/slang-nodes/EventParameter.ts +++ b/src/slang-nodes/EventParameter.ts @@ -37,7 +37,10 @@ export class EventParameter implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ path.call(print, 'typeName'), this.indexedKeyword ? ` ${this.indexedKeyword}` : '', diff --git a/src/slang-nodes/EventParameters.ts b/src/slang-nodes/EventParameters.ts index d2f150d61..8fbdbdcf6 100644 --- a/src/slang-nodes/EventParameters.ts +++ b/src/slang-nodes/EventParameters.ts @@ -37,7 +37,10 @@ export class EventParameters implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return this.items.length > 0 ? printSeparatedList(path.map(print, 'items')) : ''; diff --git a/src/slang-nodes/EventParametersDeclaration.ts b/src/slang-nodes/EventParametersDeclaration.ts index a79fe8115..88892048c 100644 --- a/src/slang-nodes/EventParametersDeclaration.ts +++ b/src/slang-nodes/EventParametersDeclaration.ts @@ -37,7 +37,10 @@ export class EventParametersDeclaration implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [this.openParen, path.call(print, 'parameters'), this.closeParen]; } } diff --git a/src/slang-nodes/ExperimentalFeature.ts b/src/slang-nodes/ExperimentalFeature.ts index 67b789e1b..0167f3d35 100644 --- a/src/slang-nodes/ExperimentalFeature.ts +++ b/src/slang-nodes/ExperimentalFeature.ts @@ -38,7 +38,10 @@ export class ExperimentalFeature implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/ExperimentalPragma.ts b/src/slang-nodes/ExperimentalPragma.ts index b70e0c2b2..1ca6ffdf1 100644 --- a/src/slang-nodes/ExperimentalPragma.ts +++ b/src/slang-nodes/ExperimentalPragma.ts @@ -34,7 +34,10 @@ export class ExperimentalPragma implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [`${this.experimentalKeyword} `, path.call(print, 'feature')]; } } diff --git a/src/slang-nodes/ExponentiationExpression.ts b/src/slang-nodes/ExponentiationExpression.ts index 1a24e9c2e..601049894 100644 --- a/src/slang-nodes/ExponentiationExpression.ts +++ b/src/slang-nodes/ExponentiationExpression.ts @@ -175,8 +175,8 @@ export class ExponentiationExpression implements SlangNode { } print( - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions ): Doc { return printExponentiationExpression(this, path, print, options); diff --git a/src/slang-nodes/Expression.ts b/src/slang-nodes/Expression.ts index b0e18348f..d632c5bfa 100644 --- a/src/slang-nodes/Expression.ts +++ b/src/slang-nodes/Expression.ts @@ -282,7 +282,10 @@ export class Expression implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/ExpressionStatement.ts b/src/slang-nodes/ExpressionStatement.ts index 70205558b..50aaa5e01 100644 --- a/src/slang-nodes/ExpressionStatement.ts +++ b/src/slang-nodes/ExpressionStatement.ts @@ -34,7 +34,10 @@ export class ExpressionStatement implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [path.call(print, 'expression'), this.semicolon]; } } diff --git a/src/slang-nodes/FallbackFunctionAttribute.ts b/src/slang-nodes/FallbackFunctionAttribute.ts index c9cb80670..3e62dcaa2 100644 --- a/src/slang-nodes/FallbackFunctionAttribute.ts +++ b/src/slang-nodes/FallbackFunctionAttribute.ts @@ -56,7 +56,10 @@ export class FallbackFunctionAttribute implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/FallbackFunctionAttributes.ts b/src/slang-nodes/FallbackFunctionAttributes.ts index 307d677d1..148529fca 100644 --- a/src/slang-nodes/FallbackFunctionAttributes.ts +++ b/src/slang-nodes/FallbackFunctionAttributes.ts @@ -40,7 +40,10 @@ export class FallbackFunctionAttributes implements SlangNode { this.items = this.items.sort(sortFunctionAttributes); } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return path.map(print, 'items').map((item) => [line, item]); } } diff --git a/src/slang-nodes/FallbackFunctionDefinition.ts b/src/slang-nodes/FallbackFunctionDefinition.ts index 95ad376e4..2624c3926 100644 --- a/src/slang-nodes/FallbackFunctionDefinition.ts +++ b/src/slang-nodes/FallbackFunctionDefinition.ts @@ -77,7 +77,10 @@ export class FallbackFunctionDefinition implements SlangNode { } } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return printFunction(this.fallbackKeyword, this, path, print); } } diff --git a/src/slang-nodes/ForStatement.ts b/src/slang-nodes/ForStatement.ts index ec1c93c08..ff3e32483 100644 --- a/src/slang-nodes/ForStatement.ts +++ b/src/slang-nodes/ForStatement.ts @@ -73,7 +73,10 @@ export class ForStatement implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { const initialization = path.call(print, 'initialization'); const condition = path.call(print, 'condition'); const iterator = this.iterator ? path.call(print, 'iterator') : ''; diff --git a/src/slang-nodes/ForStatementCondition.ts b/src/slang-nodes/ForStatementCondition.ts index 51aa111ad..0b31ff47e 100644 --- a/src/slang-nodes/ForStatementCondition.ts +++ b/src/slang-nodes/ForStatementCondition.ts @@ -38,7 +38,10 @@ export class ForStatementCondition implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/ForStatementInitialization.ts b/src/slang-nodes/ForStatementInitialization.ts index e23954c9e..76f7e72e3 100644 --- a/src/slang-nodes/ForStatementInitialization.ts +++ b/src/slang-nodes/ForStatementInitialization.ts @@ -69,7 +69,10 @@ export class ForStatementInitialization implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/FunctionAttribute.ts b/src/slang-nodes/FunctionAttribute.ts index ce3c36756..879e8f5cd 100644 --- a/src/slang-nodes/FunctionAttribute.ts +++ b/src/slang-nodes/FunctionAttribute.ts @@ -56,7 +56,10 @@ export class FunctionAttribute implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/FunctionAttributes.ts b/src/slang-nodes/FunctionAttributes.ts index cfae7e547..1365dd1a6 100644 --- a/src/slang-nodes/FunctionAttributes.ts +++ b/src/slang-nodes/FunctionAttributes.ts @@ -39,7 +39,10 @@ export class FunctionAttributes implements SlangNode { this.items = this.items.sort(sortFunctionAttributes); } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return path.map(print, 'items').map((item) => [line, item]); } } diff --git a/src/slang-nodes/FunctionBody.ts b/src/slang-nodes/FunctionBody.ts index 4bc48d4c2..5f0cf86f6 100644 --- a/src/slang-nodes/FunctionBody.ts +++ b/src/slang-nodes/FunctionBody.ts @@ -38,7 +38,10 @@ export class FunctionBody implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/FunctionCallExpression.ts b/src/slang-nodes/FunctionCallExpression.ts index 78d6149ee..b87abf617 100644 --- a/src/slang-nodes/FunctionCallExpression.ts +++ b/src/slang-nodes/FunctionCallExpression.ts @@ -43,7 +43,10 @@ export class FunctionCallExpression implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { let operandDoc = path.call(print, 'operand'); let argumentsDoc = path.call(print, 'arguments'); diff --git a/src/slang-nodes/FunctionDefinition.ts b/src/slang-nodes/FunctionDefinition.ts index d5428e7e0..9770fdb6d 100644 --- a/src/slang-nodes/FunctionDefinition.ts +++ b/src/slang-nodes/FunctionDefinition.ts @@ -89,7 +89,10 @@ export class FunctionDefinition implements SlangNode { } } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return printFunction( [`${this.functionKeyword} `, path.call(print, 'name')], this, diff --git a/src/slang-nodes/FunctionType.ts b/src/slang-nodes/FunctionType.ts index 9ea4d826b..ac9b04813 100644 --- a/src/slang-nodes/FunctionType.ts +++ b/src/slang-nodes/FunctionType.ts @@ -53,7 +53,10 @@ export class FunctionType implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return printFunction(this.functionKeyword, this, path, print); } } diff --git a/src/slang-nodes/FunctionTypeAttributes.ts b/src/slang-nodes/FunctionTypeAttributes.ts index 04978010a..ca46df461 100644 --- a/src/slang-nodes/FunctionTypeAttributes.ts +++ b/src/slang-nodes/FunctionTypeAttributes.ts @@ -6,7 +6,7 @@ import { FunctionTypeAttribute } from './FunctionTypeAttribute.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { line } = doc.builders; @@ -35,7 +35,10 @@ export class FunctionTypeAttributes implements SlangNode { this.items = this.items.sort(sortFunctionAttributes); } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return path.map(print, 'items').map((item) => [line, item]); } } diff --git a/src/slang-nodes/HexNumberExpression.ts b/src/slang-nodes/HexNumberExpression.ts index 3ec9f36bc..870fa5c99 100644 --- a/src/slang-nodes/HexNumberExpression.ts +++ b/src/slang-nodes/HexNumberExpression.ts @@ -4,7 +4,7 @@ import { NumberUnit } from './NumberUnit.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class HexNumberExpression implements SlangNode { readonly kind = NonterminalKind.HexNumberExpression; @@ -32,7 +32,10 @@ export class HexNumberExpression implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [this.literal, this.unit ? [' ', path.call(print, 'unit')] : '']; } } diff --git a/src/slang-nodes/HexStringLiterals.ts b/src/slang-nodes/HexStringLiterals.ts index 8bceec27b..af7949ca5 100644 --- a/src/slang-nodes/HexStringLiterals.ts +++ b/src/slang-nodes/HexStringLiterals.ts @@ -36,7 +36,10 @@ export class HexStringLiterals implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return join(hardline, path.map(print, 'items')); } } diff --git a/src/slang-nodes/IfStatement.ts b/src/slang-nodes/IfStatement.ts index 026959243..7353cc05c 100644 --- a/src/slang-nodes/IfStatement.ts +++ b/src/slang-nodes/IfStatement.ts @@ -58,7 +58,10 @@ export class IfStatement implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ `${this.ifKeyword} ${this.openParen}`, printSeparatedItem(path.call(print, 'condition')), diff --git a/src/slang-nodes/ImportClause.ts b/src/slang-nodes/ImportClause.ts index 5f9a9e9ce..38b60a538 100644 --- a/src/slang-nodes/ImportClause.ts +++ b/src/slang-nodes/ImportClause.ts @@ -58,7 +58,10 @@ export class ImportClause implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/ImportDeconstruction.ts b/src/slang-nodes/ImportDeconstruction.ts index c91e0f751..eb747547a 100644 --- a/src/slang-nodes/ImportDeconstruction.ts +++ b/src/slang-nodes/ImportDeconstruction.ts @@ -44,7 +44,10 @@ export class ImportDeconstruction implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ this.openBrace, path.call(print, 'symbols'), diff --git a/src/slang-nodes/ImportDeconstructionSymbol.ts b/src/slang-nodes/ImportDeconstructionSymbol.ts index 9f88426f4..dfb33aebf 100644 --- a/src/slang-nodes/ImportDeconstructionSymbol.ts +++ b/src/slang-nodes/ImportDeconstructionSymbol.ts @@ -4,7 +4,7 @@ import { ImportAlias } from './ImportAlias.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class ImportDeconstructionSymbol implements SlangNode { readonly kind = NonterminalKind.ImportDeconstructionSymbol; @@ -32,7 +32,10 @@ export class ImportDeconstructionSymbol implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [this.name, this.alias ? path.call(print, 'alias') : '']; } } diff --git a/src/slang-nodes/ImportDeconstructionSymbols.ts b/src/slang-nodes/ImportDeconstructionSymbols.ts index 7a6eae692..1f48a8f25 100644 --- a/src/slang-nodes/ImportDeconstructionSymbols.ts +++ b/src/slang-nodes/ImportDeconstructionSymbols.ts @@ -39,8 +39,8 @@ export class ImportDeconstructionSymbols implements SlangNode { } print( - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions ): Doc { const compiler = coerce(options.compiler); diff --git a/src/slang-nodes/ImportDirective.ts b/src/slang-nodes/ImportDirective.ts index 8c2dedc5b..e79957b00 100644 --- a/src/slang-nodes/ImportDirective.ts +++ b/src/slang-nodes/ImportDirective.ts @@ -37,7 +37,10 @@ export class ImportDirective implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ `${this.importKeyword} `, path.call(print, 'clause'), diff --git a/src/slang-nodes/IndexAccessEnd.ts b/src/slang-nodes/IndexAccessEnd.ts index 1f488a311..7200249ca 100644 --- a/src/slang-nodes/IndexAccessEnd.ts +++ b/src/slang-nodes/IndexAccessEnd.ts @@ -36,7 +36,10 @@ export class IndexAccessEnd implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [this.colon, this.end ? path.call(print, 'end') : '']; } } diff --git a/src/slang-nodes/IndexAccessExpression.ts b/src/slang-nodes/IndexAccessExpression.ts index f66073f19..ba6c08724 100644 --- a/src/slang-nodes/IndexAccessExpression.ts +++ b/src/slang-nodes/IndexAccessExpression.ts @@ -54,7 +54,10 @@ export class IndexAccessExpression implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { let operandDoc: Doc = path.call(print, 'operand'); let indexDoc: Doc = group([ this.openBracket, diff --git a/src/slang-nodes/InheritanceSpecifier.ts b/src/slang-nodes/InheritanceSpecifier.ts index 4452f4ac2..9cc627d74 100644 --- a/src/slang-nodes/InheritanceSpecifier.ts +++ b/src/slang-nodes/InheritanceSpecifier.ts @@ -34,7 +34,10 @@ export class InheritanceSpecifier implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [this.isKeyword, path.call(print, 'types')]; } } diff --git a/src/slang-nodes/InheritanceType.ts b/src/slang-nodes/InheritanceType.ts index 2b2f39f41..2252807f6 100644 --- a/src/slang-nodes/InheritanceType.ts +++ b/src/slang-nodes/InheritanceType.ts @@ -41,7 +41,10 @@ export class InheritanceType implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ path.call(print, 'typeName'), this.arguments ? path.call(print, 'arguments') : '' diff --git a/src/slang-nodes/InheritanceTypes.ts b/src/slang-nodes/InheritanceTypes.ts index 0e4198709..ad22e8cc0 100644 --- a/src/slang-nodes/InheritanceTypes.ts +++ b/src/slang-nodes/InheritanceTypes.ts @@ -40,7 +40,10 @@ export class InheritanceTypes implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return printSeparatedList(path.map(print, 'items'), { firstSeparator: line }); diff --git a/src/slang-nodes/InterfaceDefinition.ts b/src/slang-nodes/InterfaceDefinition.ts index d91d6a941..d46d53bf4 100644 --- a/src/slang-nodes/InterfaceDefinition.ts +++ b/src/slang-nodes/InterfaceDefinition.ts @@ -58,7 +58,10 @@ export class InterfaceDefinition implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ group([ `${this.interfaceKeyword} ${this.name}`, diff --git a/src/slang-nodes/InterfaceMembers.ts b/src/slang-nodes/InterfaceMembers.ts index 859e2219e..8515591b2 100644 --- a/src/slang-nodes/InterfaceMembers.ts +++ b/src/slang-nodes/InterfaceMembers.ts @@ -39,15 +39,15 @@ export class InterfaceMembers implements SlangNode { } print( - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions ): Doc { return this.items.length > 0 - ? printSeparatedItem( - printPreservingEmptyLines(path, 'items', print, options), - { firstSeparator: hardline, grouped: false } - ) + ? printSeparatedItem(printPreservingEmptyLines(path, print, options), { + firstSeparator: hardline, + grouped: false + }) : ''; } } diff --git a/src/slang-nodes/LibraryDefinition.ts b/src/slang-nodes/LibraryDefinition.ts index cba4d12d9..7efd0c681 100644 --- a/src/slang-nodes/LibraryDefinition.ts +++ b/src/slang-nodes/LibraryDefinition.ts @@ -46,7 +46,10 @@ export class LibraryDefinition implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ group([`${this.libraryKeyword} ${this.name}`, line, this.openBrace]), path.call(print, 'members'), diff --git a/src/slang-nodes/LibraryMembers.ts b/src/slang-nodes/LibraryMembers.ts index 280785a93..4e46b4d4a 100644 --- a/src/slang-nodes/LibraryMembers.ts +++ b/src/slang-nodes/LibraryMembers.ts @@ -39,15 +39,15 @@ export class LibraryMembers implements SlangNode { } print( - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions ): Doc { return this.items.length > 0 - ? printSeparatedItem( - printPreservingEmptyLines(path, 'items', print, options), - { firstSeparator: hardline, grouped: false } - ) + ? printSeparatedItem(printPreservingEmptyLines(path, print, options), { + firstSeparator: hardline, + grouped: false + }) : ''; } } diff --git a/src/slang-nodes/MappingKey.ts b/src/slang-nodes/MappingKey.ts index 5df8261e4..d5b658907 100644 --- a/src/slang-nodes/MappingKey.ts +++ b/src/slang-nodes/MappingKey.ts @@ -4,7 +4,7 @@ import { MappingKeyType } from './MappingKeyType.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class MappingKey implements SlangNode { readonly kind = NonterminalKind.MappingKey; @@ -30,7 +30,10 @@ export class MappingKey implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [path.call(print, 'keyType'), this.name ? ` ${this.name}` : '']; } } diff --git a/src/slang-nodes/MappingKeyType.ts b/src/slang-nodes/MappingKeyType.ts index ae502fbe1..ac0b1a7a7 100644 --- a/src/slang-nodes/MappingKeyType.ts +++ b/src/slang-nodes/MappingKeyType.ts @@ -5,7 +5,7 @@ import { IdentifierPath } from './IdentifierPath.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class MappingKeyType implements SlangNode { readonly kind = NonterminalKind.MappingKeyType; @@ -43,7 +43,10 @@ export class MappingKeyType implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/MappingType.ts b/src/slang-nodes/MappingType.ts index 53d6fb8a9..7e453880d 100644 --- a/src/slang-nodes/MappingType.ts +++ b/src/slang-nodes/MappingType.ts @@ -47,7 +47,10 @@ export class MappingType implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ `${this.mappingKeyword}${this.openParen}`, path.call(print, 'keyType'), diff --git a/src/slang-nodes/MappingValue.ts b/src/slang-nodes/MappingValue.ts index 9f096b7de..bae55d364 100644 --- a/src/slang-nodes/MappingValue.ts +++ b/src/slang-nodes/MappingValue.ts @@ -34,7 +34,10 @@ export class MappingValue implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [path.call(print, 'typeName'), this.name ? ` ${this.name}` : '']; } } diff --git a/src/slang-nodes/MemberAccessExpression.ts b/src/slang-nodes/MemberAccessExpression.ts index 8480557ed..3e0ce37aa 100644 --- a/src/slang-nodes/MemberAccessExpression.ts +++ b/src/slang-nodes/MemberAccessExpression.ts @@ -18,7 +18,10 @@ const isChainableExpression = createKindCheckFunction([ NonterminalKind.MemberAccessExpression ]); -function isEndOfChain(node: MemberAccessExpression, path: AstPath): boolean { +function isEndOfChain( + node: MemberAccessExpression, + path: AstPath +): boolean { for ( let i = 0, currentNode: AstNode = node, @@ -147,7 +150,10 @@ export class MemberAccessExpression implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { let operandDoc = path.call(print, 'operand'); if (Array.isArray(operandDoc)) { operandDoc = operandDoc.flat(); diff --git a/src/slang-nodes/ModifierAttribute.ts b/src/slang-nodes/ModifierAttribute.ts index fee6c7504..a2dbf15b3 100644 --- a/src/slang-nodes/ModifierAttribute.ts +++ b/src/slang-nodes/ModifierAttribute.ts @@ -5,7 +5,7 @@ import { OverrideSpecifier } from './OverrideSpecifier.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class ModifierAttribute implements SlangNode { readonly kind = NonterminalKind.ModifierAttribute; @@ -34,7 +34,10 @@ export class ModifierAttribute implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/ModifierAttributes.ts b/src/slang-nodes/ModifierAttributes.ts index 86efcc59b..99af50f95 100644 --- a/src/slang-nodes/ModifierAttributes.ts +++ b/src/slang-nodes/ModifierAttributes.ts @@ -6,7 +6,7 @@ import { ModifierAttribute } from './ModifierAttribute.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { line } = doc.builders; @@ -35,7 +35,10 @@ export class ModifierAttributes implements SlangNode { this.items = this.items.sort(sortFunctionAttributes); } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return path.map(print, 'items').map((item) => [line, item]); } } diff --git a/src/slang-nodes/ModifierDefinition.ts b/src/slang-nodes/ModifierDefinition.ts index e69cae52d..d6019136b 100644 --- a/src/slang-nodes/ModifierDefinition.ts +++ b/src/slang-nodes/ModifierDefinition.ts @@ -100,7 +100,10 @@ export class ModifierDefinition implements SlangNode { } } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return printFunction( `${this.modifierKeyword} ${this.name}`, this, diff --git a/src/slang-nodes/ModifierInvocation.ts b/src/slang-nodes/ModifierInvocation.ts index f77ea0213..0ab5905ed 100644 --- a/src/slang-nodes/ModifierInvocation.ts +++ b/src/slang-nodes/ModifierInvocation.ts @@ -52,7 +52,10 @@ export class ModifierInvocation implements SlangNode { }; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ path.call(print, 'name'), this.arguments ? path.call(print, 'arguments') : '' diff --git a/src/slang-nodes/MultiplicativeExpression.ts b/src/slang-nodes/MultiplicativeExpression.ts index 31053f06b..73349770d 100644 --- a/src/slang-nodes/MultiplicativeExpression.ts +++ b/src/slang-nodes/MultiplicativeExpression.ts @@ -58,8 +58,8 @@ export class MultiplicativeExpression implements SlangNode { } print( - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions ): Doc { return printBinaryOperation(this, path, print, options); diff --git a/src/slang-nodes/NamedArgument.ts b/src/slang-nodes/NamedArgument.ts index 95dd95042..44157d4c3 100644 --- a/src/slang-nodes/NamedArgument.ts +++ b/src/slang-nodes/NamedArgument.ts @@ -37,7 +37,10 @@ export class NamedArgument implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [`${this.name}${this.colon} `, path.call(print, 'value')]; } } diff --git a/src/slang-nodes/NamedArgumentGroup.ts b/src/slang-nodes/NamedArgumentGroup.ts index b67e066e4..1d16dc316 100644 --- a/src/slang-nodes/NamedArgumentGroup.ts +++ b/src/slang-nodes/NamedArgumentGroup.ts @@ -37,7 +37,10 @@ export class NamedArgumentGroup implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [this.openBrace, path.call(print, 'arguments'), this.closeBrace]; } } diff --git a/src/slang-nodes/NamedArguments.ts b/src/slang-nodes/NamedArguments.ts index 51ecb6817..9a374d425 100644 --- a/src/slang-nodes/NamedArguments.ts +++ b/src/slang-nodes/NamedArguments.ts @@ -41,8 +41,8 @@ export class NamedArguments implements SlangNode { } print( - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions ): Doc { return printSeparatedList(path.map(print, 'items'), { diff --git a/src/slang-nodes/NamedArgumentsDeclaration.ts b/src/slang-nodes/NamedArgumentsDeclaration.ts index 3efa1e745..32e8e13c8 100644 --- a/src/slang-nodes/NamedArgumentsDeclaration.ts +++ b/src/slang-nodes/NamedArgumentsDeclaration.ts @@ -43,7 +43,10 @@ export class NamedArgumentsDeclaration implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ this.openParen, this.arguments ? path.call(print, 'arguments') : '', diff --git a/src/slang-nodes/NamedImport.ts b/src/slang-nodes/NamedImport.ts index f3735aad4..d5fd0754b 100644 --- a/src/slang-nodes/NamedImport.ts +++ b/src/slang-nodes/NamedImport.ts @@ -41,7 +41,10 @@ export class NamedImport implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ this.asterisk, path.call(print, 'alias'), diff --git a/src/slang-nodes/NewExpression.ts b/src/slang-nodes/NewExpression.ts index 568ed5ac5..d8e928b2f 100644 --- a/src/slang-nodes/NewExpression.ts +++ b/src/slang-nodes/NewExpression.ts @@ -34,7 +34,10 @@ export class NewExpression implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [`${this.newKeyword} `, path.call(print, 'typeName')]; } } diff --git a/src/slang-nodes/OrExpression.ts b/src/slang-nodes/OrExpression.ts index 422818f03..79ae17f17 100644 --- a/src/slang-nodes/OrExpression.ts +++ b/src/slang-nodes/OrExpression.ts @@ -45,8 +45,8 @@ export class OrExpression implements SlangNode { } print( - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions ): Doc { return printLogicalOperation(this, path, print, options); diff --git a/src/slang-nodes/OverridePaths.ts b/src/slang-nodes/OverridePaths.ts index a6c26366e..a195017dc 100644 --- a/src/slang-nodes/OverridePaths.ts +++ b/src/slang-nodes/OverridePaths.ts @@ -34,8 +34,8 @@ export class OverridePaths implements SlangNode { // TODO: implement print print(/* - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions */): Doc { return ['TODO: OverridePaths']; diff --git a/src/slang-nodes/OverridePathsDeclaration.ts b/src/slang-nodes/OverridePathsDeclaration.ts index 49496df96..cfbf150a0 100644 --- a/src/slang-nodes/OverridePathsDeclaration.ts +++ b/src/slang-nodes/OverridePathsDeclaration.ts @@ -35,8 +35,8 @@ export class OverridePathsDeclaration implements SlangNode { // TODO: implement print print(/* - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions */): Doc { return ['TODO: OverridePathsDeclaration']; diff --git a/src/slang-nodes/OverrideSpecifier.ts b/src/slang-nodes/OverrideSpecifier.ts index 97b2d3ddb..141faab5e 100644 --- a/src/slang-nodes/OverrideSpecifier.ts +++ b/src/slang-nodes/OverrideSpecifier.ts @@ -4,7 +4,7 @@ import { OverridePathsDeclaration } from './OverridePathsDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class OverrideSpecifier implements SlangNode { readonly kind = NonterminalKind.OverrideSpecifier; @@ -35,7 +35,10 @@ export class OverrideSpecifier implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ this.overrideKeyword, this.overridden ? path.call(print, 'overridden') : '' diff --git a/src/slang-nodes/Parameter.ts b/src/slang-nodes/Parameter.ts index f69d99445..fd650175f 100644 --- a/src/slang-nodes/Parameter.ts +++ b/src/slang-nodes/Parameter.ts @@ -46,7 +46,10 @@ export class Parameter implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return group([ path.call(print, 'typeName'), this.storageLocation ? [' ', path.call(print, 'storageLocation')] : '', diff --git a/src/slang-nodes/Parameters.ts b/src/slang-nodes/Parameters.ts index 367ddaa2f..a1eab4ca2 100644 --- a/src/slang-nodes/Parameters.ts +++ b/src/slang-nodes/Parameters.ts @@ -39,7 +39,10 @@ export class Parameters implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { if (this.items.length > 0) { return printSeparatedList(path.map(print, 'items'), { grouped: false }); } diff --git a/src/slang-nodes/ParametersDeclaration.ts b/src/slang-nodes/ParametersDeclaration.ts index 298b78a25..66463670e 100644 --- a/src/slang-nodes/ParametersDeclaration.ts +++ b/src/slang-nodes/ParametersDeclaration.ts @@ -37,7 +37,10 @@ export class ParametersDeclaration implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [this.openParen, path.call(print, 'parameters'), this.closeParen]; } } diff --git a/src/slang-nodes/PathImport.ts b/src/slang-nodes/PathImport.ts index 2bc8cf283..2b61a8c1b 100644 --- a/src/slang-nodes/PathImport.ts +++ b/src/slang-nodes/PathImport.ts @@ -37,7 +37,10 @@ export class PathImport implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ path.call(print, 'path'), this.alias ? path.call(print, 'alias') : '' diff --git a/src/slang-nodes/PositionalArguments.ts b/src/slang-nodes/PositionalArguments.ts index b0684ff57..a62e0b31e 100644 --- a/src/slang-nodes/PositionalArguments.ts +++ b/src/slang-nodes/PositionalArguments.ts @@ -37,7 +37,10 @@ export class PositionalArguments implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return this.items.length > 0 ? printSeparatedList(path.map(print, 'items')) : ''; diff --git a/src/slang-nodes/PositionalArgumentsDeclaration.ts b/src/slang-nodes/PositionalArgumentsDeclaration.ts index 5d9ef2ee2..54e8c83e2 100644 --- a/src/slang-nodes/PositionalArgumentsDeclaration.ts +++ b/src/slang-nodes/PositionalArgumentsDeclaration.ts @@ -41,7 +41,10 @@ export class PositionalArgumentsDeclaration implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [this.openParen, path.call(print, 'arguments'), this.closeParen]; } } diff --git a/src/slang-nodes/PostfixExpression.ts b/src/slang-nodes/PostfixExpression.ts index 9ab783050..781ea5417 100644 --- a/src/slang-nodes/PostfixExpression.ts +++ b/src/slang-nodes/PostfixExpression.ts @@ -34,7 +34,10 @@ export class PostfixExpression implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [path.call(print, 'operand'), this.operator]; } } diff --git a/src/slang-nodes/Pragma.ts b/src/slang-nodes/Pragma.ts index b660baf4f..1905338e8 100644 --- a/src/slang-nodes/Pragma.ts +++ b/src/slang-nodes/Pragma.ts @@ -55,7 +55,7 @@ export class Pragma implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print(path: AstPath, print: (path: AstPath) => Doc): Doc { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/PragmaDirective.ts b/src/slang-nodes/PragmaDirective.ts index d18e9f7fe..aa9a9478f 100644 --- a/src/slang-nodes/PragmaDirective.ts +++ b/src/slang-nodes/PragmaDirective.ts @@ -37,7 +37,10 @@ export class PragmaDirective implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ `${this.pragmaKeyword} `, path.call(print, 'pragma'), diff --git a/src/slang-nodes/PrefixExpression.ts b/src/slang-nodes/PrefixExpression.ts index 4242ac1af..375423ffd 100644 --- a/src/slang-nodes/PrefixExpression.ts +++ b/src/slang-nodes/PrefixExpression.ts @@ -34,7 +34,10 @@ export class PrefixExpression implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [this.operator, path.call(print, 'operand')]; } } diff --git a/src/slang-nodes/ReceiveFunctionAttribute.ts b/src/slang-nodes/ReceiveFunctionAttribute.ts index 71b6ff0da..59befcb14 100644 --- a/src/slang-nodes/ReceiveFunctionAttribute.ts +++ b/src/slang-nodes/ReceiveFunctionAttribute.ts @@ -56,7 +56,10 @@ export class ReceiveFunctionAttribute implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/ReceiveFunctionAttributes.ts b/src/slang-nodes/ReceiveFunctionAttributes.ts index 9b3bd33fa..bfcea0429 100644 --- a/src/slang-nodes/ReceiveFunctionAttributes.ts +++ b/src/slang-nodes/ReceiveFunctionAttributes.ts @@ -40,7 +40,10 @@ export class ReceiveFunctionAttributes implements SlangNode { this.items = this.items.sort(sortFunctionAttributes); } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return path.map(print, 'items').map((item) => [line, item]); } } diff --git a/src/slang-nodes/ReceiveFunctionDefinition.ts b/src/slang-nodes/ReceiveFunctionDefinition.ts index 7bdfeb00f..d6fca1bfa 100644 --- a/src/slang-nodes/ReceiveFunctionDefinition.ts +++ b/src/slang-nodes/ReceiveFunctionDefinition.ts @@ -68,7 +68,10 @@ export class ReceiveFunctionDefinition implements SlangNode { } } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return printFunction(this.receiveKeyword, this, path, print); } } diff --git a/src/slang-nodes/ReturnStatement.ts b/src/slang-nodes/ReturnStatement.ts index 037987705..2789c1127 100644 --- a/src/slang-nodes/ReturnStatement.ts +++ b/src/slang-nodes/ReturnStatement.ts @@ -11,8 +11,8 @@ const { group, indent, line } = doc.builders; function printExpression( node: ReturnStatement, - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions ): Doc { if (node.expression) { @@ -61,8 +61,8 @@ export class ReturnStatement implements SlangNode { } print( - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions ): Doc { return [ diff --git a/src/slang-nodes/ReturnsDeclaration.ts b/src/slang-nodes/ReturnsDeclaration.ts index 10c7c48da..6f5321cc9 100644 --- a/src/slang-nodes/ReturnsDeclaration.ts +++ b/src/slang-nodes/ReturnsDeclaration.ts @@ -41,7 +41,10 @@ export class ReturnsDeclaration implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [`${this.returnsKeyword} `, group(path.call(print, 'variables'))]; } } diff --git a/src/slang-nodes/RevertStatement.ts b/src/slang-nodes/RevertStatement.ts index 23a4fe53c..e80ac1726 100644 --- a/src/slang-nodes/RevertStatement.ts +++ b/src/slang-nodes/RevertStatement.ts @@ -49,7 +49,10 @@ export class RevertStatement implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ `${this.revertKeyword} `, this.error ? path.call(print, 'error') : '', diff --git a/src/slang-nodes/ShiftExpression.ts b/src/slang-nodes/ShiftExpression.ts index 98023e427..2c076b639 100644 --- a/src/slang-nodes/ShiftExpression.ts +++ b/src/slang-nodes/ShiftExpression.ts @@ -54,8 +54,8 @@ export class ShiftExpression implements SlangNode { } print( - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions ): Doc { return printBinaryOperation(this, path, print, options); diff --git a/src/slang-nodes/SourceUnit.ts b/src/slang-nodes/SourceUnit.ts index 33bdedb6d..db0e66a67 100644 --- a/src/slang-nodes/SourceUnit.ts +++ b/src/slang-nodes/SourceUnit.ts @@ -35,8 +35,8 @@ export class SourceUnit implements SlangNode { } print( - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions ): Doc { return [path.call(print, 'members'), options.parentParser ? '' : line]; diff --git a/src/slang-nodes/SourceUnitMember.ts b/src/slang-nodes/SourceUnitMember.ts index 94b5ae20d..8b2054c60 100644 --- a/src/slang-nodes/SourceUnitMember.ts +++ b/src/slang-nodes/SourceUnitMember.ts @@ -148,7 +148,10 @@ export class SourceUnitMember implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/SourceUnitMembers.ts b/src/slang-nodes/SourceUnitMembers.ts index 69e3572b8..750ac58b2 100644 --- a/src/slang-nodes/SourceUnitMembers.ts +++ b/src/slang-nodes/SourceUnitMembers.ts @@ -35,10 +35,10 @@ export class SourceUnitMembers implements SlangNode { } print( - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions ): Doc { - return printPreservingEmptyLines(path, 'items', print, options); + return printPreservingEmptyLines(path, print, options); } } diff --git a/src/slang-nodes/StateVariableAttribute.ts b/src/slang-nodes/StateVariableAttribute.ts index 7f805a5af..1c4a4e477 100644 --- a/src/slang-nodes/StateVariableAttribute.ts +++ b/src/slang-nodes/StateVariableAttribute.ts @@ -5,7 +5,7 @@ import { OverrideSpecifier } from './OverrideSpecifier.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class StateVariableAttribute implements SlangNode { readonly kind = NonterminalKind.StateVariableAttribute; @@ -34,7 +34,10 @@ export class StateVariableAttribute implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/StateVariableAttributes.ts b/src/slang-nodes/StateVariableAttributes.ts index 4a6d97871..4544b5bc0 100644 --- a/src/slang-nodes/StateVariableAttributes.ts +++ b/src/slang-nodes/StateVariableAttributes.ts @@ -4,7 +4,7 @@ import { StateVariableAttribute } from './StateVariableAttribute.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class StateVariableAttributes implements SlangNode { readonly kind = NonterminalKind.StateVariableAttributes; @@ -29,7 +29,10 @@ export class StateVariableAttributes implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return this.items.length ? path.map(print, 'items').map((item) => [' ', item]) : ''; diff --git a/src/slang-nodes/StateVariableDefinition.ts b/src/slang-nodes/StateVariableDefinition.ts index fa9f0131e..47a2d369b 100644 --- a/src/slang-nodes/StateVariableDefinition.ts +++ b/src/slang-nodes/StateVariableDefinition.ts @@ -51,7 +51,10 @@ export class StateVariableDefinition implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ path.call(print, 'typeName'), path.call(print, 'attributes'), diff --git a/src/slang-nodes/StateVariableDefinitionValue.ts b/src/slang-nodes/StateVariableDefinitionValue.ts index 4dab16408..c3dbf17b3 100644 --- a/src/slang-nodes/StateVariableDefinitionValue.ts +++ b/src/slang-nodes/StateVariableDefinitionValue.ts @@ -37,7 +37,10 @@ export class StateVariableDefinitionValue implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return typeof this.value.variant !== 'string' && this.value.variant.kind === NonterminalKind.ArrayExpression ? [` ${this.equal} `, path.call(print, 'value')] diff --git a/src/slang-nodes/Statement.ts b/src/slang-nodes/Statement.ts index 5a7bfec6e..32716722b 100644 --- a/src/slang-nodes/Statement.ts +++ b/src/slang-nodes/Statement.ts @@ -179,7 +179,7 @@ export class Statement implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print(path: AstPath, print: (path: AstPath) => Doc): Doc { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/Statements.ts b/src/slang-nodes/Statements.ts index 331f795e2..a771f6f27 100644 --- a/src/slang-nodes/Statements.ts +++ b/src/slang-nodes/Statements.ts @@ -40,8 +40,8 @@ export class Statements implements SlangNode { } print( - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions ): Doc { return this.items.length === 0 && @@ -49,7 +49,7 @@ export class Statements implements SlangNode { ? '' : printSeparatedItem( [ - printPreservingEmptyLines(path, 'items', print, options), + printPreservingEmptyLines(path, print, options), printComments(this, path) ], { diff --git a/src/slang-nodes/StringExpression.ts b/src/slang-nodes/StringExpression.ts index 61431919c..00ed510a8 100644 --- a/src/slang-nodes/StringExpression.ts +++ b/src/slang-nodes/StringExpression.ts @@ -79,7 +79,10 @@ export class StringExpression implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/StringLiterals.ts b/src/slang-nodes/StringLiterals.ts index 18a8c676f..449b2808d 100644 --- a/src/slang-nodes/StringLiterals.ts +++ b/src/slang-nodes/StringLiterals.ts @@ -36,7 +36,10 @@ export class StringLiterals implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return join(hardline, path.map(print, 'items')); } } diff --git a/src/slang-nodes/StructDefinition.ts b/src/slang-nodes/StructDefinition.ts index dd10be13f..64457602d 100644 --- a/src/slang-nodes/StructDefinition.ts +++ b/src/slang-nodes/StructDefinition.ts @@ -43,7 +43,10 @@ export class StructDefinition implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ `${this.structKeyword} ${this.name} ${this.openBrace}`, path.call(print, 'members'), diff --git a/src/slang-nodes/StructMember.ts b/src/slang-nodes/StructMember.ts index 407e0ada2..660108ad3 100644 --- a/src/slang-nodes/StructMember.ts +++ b/src/slang-nodes/StructMember.ts @@ -37,7 +37,10 @@ export class StructMember implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [path.call(print, 'typeName'), ` ${this.name}${this.semicolon}`]; } } diff --git a/src/slang-nodes/StructMembers.ts b/src/slang-nodes/StructMembers.ts index edeb8ddb6..b32b8dfe2 100644 --- a/src/slang-nodes/StructMembers.ts +++ b/src/slang-nodes/StructMembers.ts @@ -37,7 +37,10 @@ export class StructMembers implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return this.items.length > 0 ? printSeparatedList(path.map(print, 'items'), { firstSeparator: hardline, diff --git a/src/slang-nodes/TryStatement.ts b/src/slang-nodes/TryStatement.ts index 5946d1678..20fd3de98 100644 --- a/src/slang-nodes/TryStatement.ts +++ b/src/slang-nodes/TryStatement.ts @@ -60,7 +60,10 @@ export class TryStatement implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ this.tryKeyword, printSeparatedItem(path.call(print, 'expression'), { diff --git a/src/slang-nodes/TupleDeconstructionElement.ts b/src/slang-nodes/TupleDeconstructionElement.ts index 0ce174e9b..d9dae7b32 100644 --- a/src/slang-nodes/TupleDeconstructionElement.ts +++ b/src/slang-nodes/TupleDeconstructionElement.ts @@ -33,7 +33,10 @@ export class TupleDeconstructionElement implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return this.member ? path.call(print, 'member') : ''; } } diff --git a/src/slang-nodes/TupleDeconstructionElements.ts b/src/slang-nodes/TupleDeconstructionElements.ts index 1582eab13..ac2a0e3af 100644 --- a/src/slang-nodes/TupleDeconstructionElements.ts +++ b/src/slang-nodes/TupleDeconstructionElements.ts @@ -38,7 +38,10 @@ export class TupleDeconstructionElements implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return printSeparatedList(path.map(print, 'items')); } } diff --git a/src/slang-nodes/TupleDeconstructionStatement.ts b/src/slang-nodes/TupleDeconstructionStatement.ts index e62ab93d2..0ce1a1a77 100644 --- a/src/slang-nodes/TupleDeconstructionStatement.ts +++ b/src/slang-nodes/TupleDeconstructionStatement.ts @@ -57,7 +57,10 @@ export class TupleDeconstructionStatement implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ this.varKeyword ? this.varKeyword : '', this.openParen, diff --git a/src/slang-nodes/TupleExpression.ts b/src/slang-nodes/TupleExpression.ts index 26c7908b7..c3fb59f8b 100644 --- a/src/slang-nodes/TupleExpression.ts +++ b/src/slang-nodes/TupleExpression.ts @@ -37,7 +37,10 @@ export class TupleExpression implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [this.openParen, path.call(print, 'items'), this.closeParen]; } } diff --git a/src/slang-nodes/TupleMember.ts b/src/slang-nodes/TupleMember.ts index 49127393e..477999f81 100644 --- a/src/slang-nodes/TupleMember.ts +++ b/src/slang-nodes/TupleMember.ts @@ -48,7 +48,10 @@ export class TupleMember implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/TupleValue.ts b/src/slang-nodes/TupleValue.ts index b36a9f593..2cc94c763 100644 --- a/src/slang-nodes/TupleValue.ts +++ b/src/slang-nodes/TupleValue.ts @@ -33,7 +33,10 @@ export class TupleValue implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return this.expression ? path.call(print, 'expression') : ''; } } diff --git a/src/slang-nodes/TupleValues.ts b/src/slang-nodes/TupleValues.ts index c6f12e1b3..98c7ca4d3 100644 --- a/src/slang-nodes/TupleValues.ts +++ b/src/slang-nodes/TupleValues.ts @@ -38,7 +38,10 @@ export class TupleValues implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return this.items.length === 1 && typeof this.items[0].expression!.variant !== 'string' && isBinaryOperation(this.items[0].expression!.variant) diff --git a/src/slang-nodes/TypeExpression.ts b/src/slang-nodes/TypeExpression.ts index 75889c031..5230d6d81 100644 --- a/src/slang-nodes/TypeExpression.ts +++ b/src/slang-nodes/TypeExpression.ts @@ -42,8 +42,8 @@ export class TypeExpression implements SlangNode { // TODO: implement print print(/* - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions */): Doc { return ['TODO: TypeExpression']; diff --git a/src/slang-nodes/TypeName.ts b/src/slang-nodes/TypeName.ts index 164a38d56..acc1f0d3d 100644 --- a/src/slang-nodes/TypeName.ts +++ b/src/slang-nodes/TypeName.ts @@ -79,7 +79,7 @@ export class TypeName implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print(path: AstPath, print: (path: AstPath) => Doc): Doc { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/TypedTupleMember.ts b/src/slang-nodes/TypedTupleMember.ts index 0e03d6cb5..9d718de08 100644 --- a/src/slang-nodes/TypedTupleMember.ts +++ b/src/slang-nodes/TypedTupleMember.ts @@ -43,7 +43,10 @@ export class TypedTupleMember implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ path.call(print, 'typeName'), this.storageLocation ? [' ', path.call(print, 'storageLocation')] : '', diff --git a/src/slang-nodes/UncheckedBlock.ts b/src/slang-nodes/UncheckedBlock.ts index 5a40db489..c9bc7a6dd 100644 --- a/src/slang-nodes/UncheckedBlock.ts +++ b/src/slang-nodes/UncheckedBlock.ts @@ -34,7 +34,10 @@ export class UncheckedBlock implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [`${this.uncheckedKeyword} `, path.call(print, 'block')]; } } diff --git a/src/slang-nodes/UnicodeStringLiterals.ts b/src/slang-nodes/UnicodeStringLiterals.ts index 5cfe9af33..1009498d6 100644 --- a/src/slang-nodes/UnicodeStringLiterals.ts +++ b/src/slang-nodes/UnicodeStringLiterals.ts @@ -36,7 +36,10 @@ export class UnicodeStringLiterals implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return join(hardline, path.map(print, 'items')); } } diff --git a/src/slang-nodes/UnnamedFunctionAttribute.ts b/src/slang-nodes/UnnamedFunctionAttribute.ts index fbdce4499..52d364752 100644 --- a/src/slang-nodes/UnnamedFunctionAttribute.ts +++ b/src/slang-nodes/UnnamedFunctionAttribute.ts @@ -38,7 +38,10 @@ export class UnnamedFunctionAttribute implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/UnnamedFunctionAttributes.ts b/src/slang-nodes/UnnamedFunctionAttributes.ts index 5df978b03..fa015983e 100644 --- a/src/slang-nodes/UnnamedFunctionAttributes.ts +++ b/src/slang-nodes/UnnamedFunctionAttributes.ts @@ -40,7 +40,10 @@ export class UnnamedFunctionAttributes implements SlangNode { this.items = this.items.sort(sortFunctionAttributes); } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return path.map(print, 'items').map((item) => [line, item]); } } diff --git a/src/slang-nodes/UnnamedFunctionDefinition.ts b/src/slang-nodes/UnnamedFunctionDefinition.ts index e15ab05af..0650ee497 100644 --- a/src/slang-nodes/UnnamedFunctionDefinition.ts +++ b/src/slang-nodes/UnnamedFunctionDefinition.ts @@ -65,7 +65,10 @@ export class UnnamedFunctionDefinition implements SlangNode { } } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return printFunction(this.functionKeyword, this, path, print); } } diff --git a/src/slang-nodes/UntypedTupleMember.ts b/src/slang-nodes/UntypedTupleMember.ts index 5f24566c0..c0d923951 100644 --- a/src/slang-nodes/UntypedTupleMember.ts +++ b/src/slang-nodes/UntypedTupleMember.ts @@ -37,8 +37,8 @@ export class UntypedTupleMember implements SlangNode { // TODO: implement print print(/* - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions */): Doc { return ['TODO: UntypedTupleMemberUntypedTupleMember']; diff --git a/src/slang-nodes/UserDefinedValueTypeDefinition.ts b/src/slang-nodes/UserDefinedValueTypeDefinition.ts index 4098fda5f..b604f23db 100644 --- a/src/slang-nodes/UserDefinedValueTypeDefinition.ts +++ b/src/slang-nodes/UserDefinedValueTypeDefinition.ts @@ -4,7 +4,7 @@ import { ElementaryType } from './ElementaryType.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class UserDefinedValueTypeDefinition implements SlangNode { readonly kind = NonterminalKind.UserDefinedValueTypeDefinition; @@ -39,7 +39,10 @@ export class UserDefinedValueTypeDefinition implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ `${this.typeKeyword} ${this.name} ${this.isKeyword} `, path.call(print, 'valueType'), diff --git a/src/slang-nodes/UsingAlias.ts b/src/slang-nodes/UsingAlias.ts index 1b49b7e33..ad9a04e77 100644 --- a/src/slang-nodes/UsingAlias.ts +++ b/src/slang-nodes/UsingAlias.ts @@ -4,7 +4,7 @@ import { UsingOperator } from './UsingOperator.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class UsingAlias implements SlangNode { readonly kind = NonterminalKind.UsingAlias; @@ -30,7 +30,10 @@ export class UsingAlias implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [` ${this.asKeyword} `, path.call(print, 'operator')]; } } diff --git a/src/slang-nodes/UsingClause.ts b/src/slang-nodes/UsingClause.ts index 140c77dc5..1a5f01056 100644 --- a/src/slang-nodes/UsingClause.ts +++ b/src/slang-nodes/UsingClause.ts @@ -5,7 +5,7 @@ import { UsingDeconstruction } from './UsingDeconstruction.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class UsingClause implements SlangNode { readonly kind = NonterminalKind.UsingClause; @@ -46,7 +46,10 @@ export class UsingClause implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/UsingDeconstruction.ts b/src/slang-nodes/UsingDeconstruction.ts index 8d15f8dee..a017b2f77 100644 --- a/src/slang-nodes/UsingDeconstruction.ts +++ b/src/slang-nodes/UsingDeconstruction.ts @@ -4,7 +4,7 @@ import { UsingDeconstructionSymbols } from './UsingDeconstructionSymbols.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class UsingDeconstruction implements SlangNode { readonly kind = NonterminalKind.UsingDeconstruction; @@ -33,7 +33,10 @@ export class UsingDeconstruction implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [this.openBrace, path.call(print, 'symbols'), this.closeBrace]; } } diff --git a/src/slang-nodes/UsingDeconstructionSymbol.ts b/src/slang-nodes/UsingDeconstructionSymbol.ts index 35ee72ef0..a2c5cf198 100644 --- a/src/slang-nodes/UsingDeconstructionSymbol.ts +++ b/src/slang-nodes/UsingDeconstructionSymbol.ts @@ -5,7 +5,7 @@ import { UsingAlias } from './UsingAlias.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class UsingDeconstructionSymbol implements SlangNode { readonly kind = NonterminalKind.UsingDeconstructionSymbol; @@ -33,7 +33,10 @@ export class UsingDeconstructionSymbol implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ path.call(print, 'name'), this.alias ? path.call(print, 'alias') : '' diff --git a/src/slang-nodes/UsingDeconstructionSymbols.ts b/src/slang-nodes/UsingDeconstructionSymbols.ts index 783783fd1..5c74db160 100644 --- a/src/slang-nodes/UsingDeconstructionSymbols.ts +++ b/src/slang-nodes/UsingDeconstructionSymbols.ts @@ -37,8 +37,8 @@ export class UsingDeconstructionSymbols implements SlangNode { } print( - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions ): Doc { return printSeparatedList(path.map(print, 'items'), { diff --git a/src/slang-nodes/UsingDirective.ts b/src/slang-nodes/UsingDirective.ts index 788d98acd..3ceab3f51 100644 --- a/src/slang-nodes/UsingDirective.ts +++ b/src/slang-nodes/UsingDirective.ts @@ -47,7 +47,10 @@ export class UsingDirective implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ `${this.usingKeyword} `, path.call(print, 'clause'), diff --git a/src/slang-nodes/UsingTarget.ts b/src/slang-nodes/UsingTarget.ts index b8e840979..ce13833a5 100644 --- a/src/slang-nodes/UsingTarget.ts +++ b/src/slang-nodes/UsingTarget.ts @@ -38,7 +38,10 @@ export class UsingTarget implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/VariableDeclarationStatement.ts b/src/slang-nodes/VariableDeclarationStatement.ts index 3f76644f5..60bd5a701 100644 --- a/src/slang-nodes/VariableDeclarationStatement.ts +++ b/src/slang-nodes/VariableDeclarationStatement.ts @@ -64,7 +64,10 @@ export class VariableDeclarationStatement implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { const declarationDoc = group( [ path.call(print, 'variableType'), diff --git a/src/slang-nodes/VariableDeclarationType.ts b/src/slang-nodes/VariableDeclarationType.ts index 1c5353ca4..31653ce17 100644 --- a/src/slang-nodes/VariableDeclarationType.ts +++ b/src/slang-nodes/VariableDeclarationType.ts @@ -38,7 +38,10 @@ export class VariableDeclarationType implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/VariableDeclarationValue.ts b/src/slang-nodes/VariableDeclarationValue.ts index 2eb61a8cf..30b86759e 100644 --- a/src/slang-nodes/VariableDeclarationValue.ts +++ b/src/slang-nodes/VariableDeclarationValue.ts @@ -34,7 +34,10 @@ export class VariableDeclarationValue implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [` ${this.equal} `, path.call(print, 'expression')]; } } diff --git a/src/slang-nodes/VersionComparator.ts b/src/slang-nodes/VersionComparator.ts index 916e84466..5a5981a26 100644 --- a/src/slang-nodes/VersionComparator.ts +++ b/src/slang-nodes/VersionComparator.ts @@ -4,7 +4,7 @@ import { VersionExpression } from './VersionExpression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class VersionComparator implements SlangNode { readonly kind = NonterminalKind.VersionComparator; @@ -30,7 +30,10 @@ export class VersionComparator implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [this.operator, path.call(print, 'operand')]; } } diff --git a/src/slang-nodes/VersionExpression.ts b/src/slang-nodes/VersionExpression.ts index 4e0bf8e28..d9733ffe8 100644 --- a/src/slang-nodes/VersionExpression.ts +++ b/src/slang-nodes/VersionExpression.ts @@ -7,7 +7,7 @@ import { VersionSpecifiers } from './VersionSpecifiers.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class VersionExpression implements SlangNode { readonly kind = NonterminalKind.VersionExpression; @@ -58,7 +58,10 @@ export class VersionExpression implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/VersionExpressionSet.ts b/src/slang-nodes/VersionExpressionSet.ts index 6f58aae27..cb9e62280 100644 --- a/src/slang-nodes/VersionExpressionSet.ts +++ b/src/slang-nodes/VersionExpressionSet.ts @@ -5,7 +5,7 @@ import { VersionExpression } from './VersionExpression.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { join } = doc.builders; @@ -32,7 +32,10 @@ export class VersionExpressionSet implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return join(' ', path.map(print, 'items')); } } diff --git a/src/slang-nodes/VersionExpressionSets.ts b/src/slang-nodes/VersionExpressionSets.ts index 44ed38290..f73113117 100644 --- a/src/slang-nodes/VersionExpressionSets.ts +++ b/src/slang-nodes/VersionExpressionSets.ts @@ -4,7 +4,7 @@ import { VersionExpressionSet } from './VersionExpressionSet.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class VersionExpressionSets implements SlangNode { readonly kind = NonterminalKind.VersionExpressionSets; @@ -32,7 +32,10 @@ export class VersionExpressionSets implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return path .map(print, 'items') .map((item, index) => diff --git a/src/slang-nodes/VersionPragma.ts b/src/slang-nodes/VersionPragma.ts index 904346b6e..d04d6d2e3 100644 --- a/src/slang-nodes/VersionPragma.ts +++ b/src/slang-nodes/VersionPragma.ts @@ -4,7 +4,7 @@ import { VersionExpressionSets } from './VersionExpressionSets.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class VersionPragma implements SlangNode { readonly kind = NonterminalKind.VersionPragma; @@ -30,7 +30,10 @@ export class VersionPragma implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [`${this.solidityKeyword} `, path.call(print, 'sets')]; } } diff --git a/src/slang-nodes/VersionRange.ts b/src/slang-nodes/VersionRange.ts index e8011cc44..dc2091cfc 100644 --- a/src/slang-nodes/VersionRange.ts +++ b/src/slang-nodes/VersionRange.ts @@ -35,8 +35,8 @@ export class VersionRange implements SlangNode { // TODO: implement print print(/* - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions */): Doc { return ['TODO: VersionRange']; diff --git a/src/slang-nodes/WhileStatement.ts b/src/slang-nodes/WhileStatement.ts index 3bcbc77e4..066f587ad 100644 --- a/src/slang-nodes/WhileStatement.ts +++ b/src/slang-nodes/WhileStatement.ts @@ -48,7 +48,10 @@ export class WhileStatement implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ `${this.whileKeyword} ${this.openParen}`, printSeparatedItem(path.call(print, 'condition')), diff --git a/src/slang-nodes/YulArguments.ts b/src/slang-nodes/YulArguments.ts index f0bef0f35..684a2f04f 100644 --- a/src/slang-nodes/YulArguments.ts +++ b/src/slang-nodes/YulArguments.ts @@ -37,7 +37,10 @@ export class YulArguments implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return printSeparatedList(path.map(print, 'items')); } } diff --git a/src/slang-nodes/YulAssignmentOperator.ts b/src/slang-nodes/YulAssignmentOperator.ts index 0904ac97b..3628266dd 100644 --- a/src/slang-nodes/YulAssignmentOperator.ts +++ b/src/slang-nodes/YulAssignmentOperator.ts @@ -5,7 +5,7 @@ import { YulColonEqual } from './YulColonEqual.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class YulAssignmentOperator implements SlangNode { readonly kind = NonterminalKind.YulAssignmentOperator; @@ -34,7 +34,10 @@ export class YulAssignmentOperator implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/YulBlock.ts b/src/slang-nodes/YulBlock.ts index 7057079b0..6bda9de35 100644 --- a/src/slang-nodes/YulBlock.ts +++ b/src/slang-nodes/YulBlock.ts @@ -37,7 +37,7 @@ export class YulBlock implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print(path: AstPath, print: (path: AstPath) => Doc): Doc { return [this.openBrace, path.call(print, 'statements'), this.closeBrace]; } } diff --git a/src/slang-nodes/YulColonEqual.ts b/src/slang-nodes/YulColonEqual.ts index da5448281..06b8f9afe 100644 --- a/src/slang-nodes/YulColonEqual.ts +++ b/src/slang-nodes/YulColonEqual.ts @@ -28,8 +28,8 @@ export class YulColonEqual implements SlangNode { // TODO: implement print print(/* - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions */): Doc { return ['TODO: YulColonEqual']; diff --git a/src/slang-nodes/YulDefaultCase.ts b/src/slang-nodes/YulDefaultCase.ts index dc6d3dd87..3700b0cdf 100644 --- a/src/slang-nodes/YulDefaultCase.ts +++ b/src/slang-nodes/YulDefaultCase.ts @@ -34,7 +34,10 @@ export class YulDefaultCase implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [`${this.defaultKeyword} `, path.call(print, 'body')]; } } diff --git a/src/slang-nodes/YulExpression.ts b/src/slang-nodes/YulExpression.ts index 8419346bb..03e299a15 100644 --- a/src/slang-nodes/YulExpression.ts +++ b/src/slang-nodes/YulExpression.ts @@ -64,7 +64,10 @@ export class YulExpression implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/YulForStatement.ts b/src/slang-nodes/YulForStatement.ts index 4dcc0a813..e62ef5b9b 100644 --- a/src/slang-nodes/YulForStatement.ts +++ b/src/slang-nodes/YulForStatement.ts @@ -49,7 +49,10 @@ export class YulForStatement implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ `${this.forKeyword} `, path.call(print, 'initialization'), diff --git a/src/slang-nodes/YulFunctionCallExpression.ts b/src/slang-nodes/YulFunctionCallExpression.ts index 6d6413a7c..d9ae1ef12 100644 --- a/src/slang-nodes/YulFunctionCallExpression.ts +++ b/src/slang-nodes/YulFunctionCallExpression.ts @@ -41,7 +41,10 @@ export class YulFunctionCallExpression implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ path.call(print, 'operand'), this.openParen, diff --git a/src/slang-nodes/YulFunctionDefinition.ts b/src/slang-nodes/YulFunctionDefinition.ts index 2969839e8..b14e32c32 100644 --- a/src/slang-nodes/YulFunctionDefinition.ts +++ b/src/slang-nodes/YulFunctionDefinition.ts @@ -53,7 +53,10 @@ export class YulFunctionDefinition implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ `${this.functionKeyword} ${this.name}`, path.call(print, 'parameters'), diff --git a/src/slang-nodes/YulIfStatement.ts b/src/slang-nodes/YulIfStatement.ts index c811d929e..50247ba4e 100644 --- a/src/slang-nodes/YulIfStatement.ts +++ b/src/slang-nodes/YulIfStatement.ts @@ -38,7 +38,10 @@ export class YulIfStatement implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ `${this.ifKeyword} `, path.call(print, 'condition'), diff --git a/src/slang-nodes/YulLeaveStatement.ts b/src/slang-nodes/YulLeaveStatement.ts index ce62a5f18..8bb1d7a7b 100644 --- a/src/slang-nodes/YulLeaveStatement.ts +++ b/src/slang-nodes/YulLeaveStatement.ts @@ -25,8 +25,8 @@ export class YulLeaveStatement implements SlangNode { // TODO: implement print print(/* - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions */): Doc { return ['TODO: YulLeaveStatement']; diff --git a/src/slang-nodes/YulLiteral.ts b/src/slang-nodes/YulLiteral.ts index 850c06887..9546c3f54 100644 --- a/src/slang-nodes/YulLiteral.ts +++ b/src/slang-nodes/YulLiteral.ts @@ -57,7 +57,10 @@ export class YulLiteral implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/YulParametersDeclaration.ts b/src/slang-nodes/YulParametersDeclaration.ts index 0fe0e9ce1..2454fb34d 100644 --- a/src/slang-nodes/YulParametersDeclaration.ts +++ b/src/slang-nodes/YulParametersDeclaration.ts @@ -4,7 +4,7 @@ import { YulParameters } from './YulParameters.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class YulParametersDeclaration implements SlangNode { readonly kind = NonterminalKind.YulParametersDeclaration; @@ -33,7 +33,10 @@ export class YulParametersDeclaration implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [this.openParen, path.call(print, 'parameters'), this.closeParen]; } } diff --git a/src/slang-nodes/YulPath.ts b/src/slang-nodes/YulPath.ts index 4ead1ad26..56d7d14a8 100644 --- a/src/slang-nodes/YulPath.ts +++ b/src/slang-nodes/YulPath.ts @@ -4,7 +4,7 @@ import { YulPathComponent } from './YulPathComponent.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class YulPath implements SlangNode { readonly kind = NonterminalKind.YulPath; @@ -32,7 +32,7 @@ export class YulPath implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print(path: AstPath, print: (path: AstPath) => Doc): Doc { return path .map(print, 'items') .map((item, index) => diff --git a/src/slang-nodes/YulPaths.ts b/src/slang-nodes/YulPaths.ts index af149a6bf..34244780e 100644 --- a/src/slang-nodes/YulPaths.ts +++ b/src/slang-nodes/YulPaths.ts @@ -4,7 +4,7 @@ import { YulPath } from './YulPath.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; export class YulPaths implements SlangNode { readonly kind = NonterminalKind.YulPaths; @@ -32,7 +32,7 @@ export class YulPaths implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print(path: AstPath, print: (path: AstPath) => Doc): Doc { return path .map(print, 'items') .map((item, index) => diff --git a/src/slang-nodes/YulReturnsDeclaration.ts b/src/slang-nodes/YulReturnsDeclaration.ts index 01b52f8e4..02fbbd9f4 100644 --- a/src/slang-nodes/YulReturnsDeclaration.ts +++ b/src/slang-nodes/YulReturnsDeclaration.ts @@ -6,7 +6,7 @@ import { YulReturnVariables } from './YulReturnVariables.js'; import type * as ast from '@nomicfoundation/slang/ast/index.js'; import type { AstPath, Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types.js'; const { line } = doc.builders; @@ -34,7 +34,10 @@ export class YulReturnsDeclaration implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return printSeparatedItem( [this.minusGreaterThan, path.call(print, 'variables')], { diff --git a/src/slang-nodes/YulStackAssignmentStatement.ts b/src/slang-nodes/YulStackAssignmentStatement.ts index 4a2f3e7de..0f28a1230 100644 --- a/src/slang-nodes/YulStackAssignmentStatement.ts +++ b/src/slang-nodes/YulStackAssignmentStatement.ts @@ -37,8 +37,8 @@ export class YulStackAssignmentStatement implements SlangNode { // TODO: implement print print(/* - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions */): Doc { return ['TODO: YulStackAssignmentStatement']; diff --git a/src/slang-nodes/YulStatement.ts b/src/slang-nodes/YulStatement.ts index 3bd0f8f39..7b49516ab 100644 --- a/src/slang-nodes/YulStatement.ts +++ b/src/slang-nodes/YulStatement.ts @@ -143,7 +143,10 @@ export class YulStatement implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/YulStatements.ts b/src/slang-nodes/YulStatements.ts index bb89c367b..4b67e605e 100644 --- a/src/slang-nodes/YulStatements.ts +++ b/src/slang-nodes/YulStatements.ts @@ -40,8 +40,8 @@ export class YulStatements implements SlangNode { } print( - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions ): Doc { return this.items.length === 0 && @@ -49,7 +49,7 @@ export class YulStatements implements SlangNode { ? '' : printSeparatedItem( [ - printPreservingEmptyLines(path, 'items', print, options), + printPreservingEmptyLines(path, print, options), printComments(this, path) ], { diff --git a/src/slang-nodes/YulSwitchCase.ts b/src/slang-nodes/YulSwitchCase.ts index 3457d1eff..0bd9d01ed 100644 --- a/src/slang-nodes/YulSwitchCase.ts +++ b/src/slang-nodes/YulSwitchCase.ts @@ -49,7 +49,10 @@ export class YulSwitchCase implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/YulSwitchCases.ts b/src/slang-nodes/YulSwitchCases.ts index d611ef9f4..cffeca92d 100644 --- a/src/slang-nodes/YulSwitchCases.ts +++ b/src/slang-nodes/YulSwitchCases.ts @@ -36,7 +36,10 @@ export class YulSwitchCases implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return join(hardline, path.map(print, 'items')); } } diff --git a/src/slang-nodes/YulSwitchStatement.ts b/src/slang-nodes/YulSwitchStatement.ts index 30cae6d2d..b4975c3bf 100644 --- a/src/slang-nodes/YulSwitchStatement.ts +++ b/src/slang-nodes/YulSwitchStatement.ts @@ -41,7 +41,10 @@ export class YulSwitchStatement implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ `${this.switchKeyword} `, path.call(print, 'expression'), diff --git a/src/slang-nodes/YulValueCase.ts b/src/slang-nodes/YulValueCase.ts index ef94d8346..5b711d217 100644 --- a/src/slang-nodes/YulValueCase.ts +++ b/src/slang-nodes/YulValueCase.ts @@ -38,7 +38,10 @@ export class YulValueCase implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ `${this.caseKeyword} `, path.call(print, 'value'), diff --git a/src/slang-nodes/YulVariableAssignmentStatement.ts b/src/slang-nodes/YulVariableAssignmentStatement.ts index d8e57c459..5f2a33fee 100644 --- a/src/slang-nodes/YulVariableAssignmentStatement.ts +++ b/src/slang-nodes/YulVariableAssignmentStatement.ts @@ -43,7 +43,10 @@ export class YulVariableAssignmentStatement implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ path.call(print, 'names'), ' ', diff --git a/src/slang-nodes/YulVariableDeclarationStatement.ts b/src/slang-nodes/YulVariableDeclarationStatement.ts index 1c71aa44b..795258af4 100644 --- a/src/slang-nodes/YulVariableDeclarationStatement.ts +++ b/src/slang-nodes/YulVariableDeclarationStatement.ts @@ -43,7 +43,10 @@ export class YulVariableDeclarationStatement implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ `${this.letKeyword} ${this.names} `, this.value ? path.call(print, 'value') : '' diff --git a/src/slang-nodes/YulVariableDeclarationValue.ts b/src/slang-nodes/YulVariableDeclarationValue.ts index 9e020861e..cba8ba17e 100644 --- a/src/slang-nodes/YulVariableDeclarationValue.ts +++ b/src/slang-nodes/YulVariableDeclarationValue.ts @@ -35,7 +35,10 @@ export class YulVariableDeclarationValue implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print( + path: AstPath, + print: (path: AstPath) => Doc + ): Doc { return [ path.call(print, 'assignment'), ' ', diff --git a/src/slang-printers/create-binary-operation-printer.ts b/src/slang-printers/create-binary-operation-printer.ts index 218ccec2b..19d0b4433 100644 --- a/src/slang-printers/create-binary-operation-printer.ts +++ b/src/slang-printers/create-binary-operation-printer.ts @@ -8,8 +8,8 @@ const { group, line } = doc.builders; function rightOperandPrint( node: BinaryOperation, - path: AstPath, - print: (path: AstPath) => Doc + path: AstPath, + print: (path: AstPath) => Doc ): Doc { const rightOperand = [line, path.call(print, 'rightOperand')]; @@ -26,16 +26,18 @@ function rightOperandPrint( export const createBinaryOperationPrinter = ( - groupRulesBuilder: (path: AstPath) => (document: Doc) => Doc, + groupRulesBuilder: ( + path: AstPath + ) => (document: Doc) => Doc, indentRulesBuilder: ( - path: AstPath, + path: AstPath, options: ParserOptions ) => (document: Doc) => Doc ) => ( node: BinaryOperation, - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions ): Doc => { const groupRules = groupRulesBuilder(path); diff --git a/src/slang-printers/print-binary-operation.ts b/src/slang-printers/print-binary-operation.ts index abd4a83d5..89833fbce 100644 --- a/src/slang-printers/print-binary-operation.ts +++ b/src/slang-printers/print-binary-operation.ts @@ -22,7 +22,7 @@ const isBinaryOperationWithoutComparison = createKindCheckFunction([ ]) as (node: AstNode | Comment | Node) => node is BinaryOperation; const binaryGroupRulesBuilder = - (path: AstPath) => + (path: AstPath) => (document: Doc): Doc => { const grandparentNode = path.getNode(2) as AstNode; if (isBinaryOperationWithoutComparison(grandparentNode)) { @@ -32,7 +32,7 @@ const binaryGroupRulesBuilder = }; const binaryIndentRulesBuilder = - (path: AstPath) => + (path: AstPath) => (document: Doc): Doc => { let node = path.getNode() as AstNode; for (let i = 2; ; i += 2) { diff --git a/src/slang-printers/print-comments.ts b/src/slang-printers/print-comments.ts index c0c58e500..33a14aca2 100644 --- a/src/slang-printers/print-comments.ts +++ b/src/slang-printers/print-comments.ts @@ -8,7 +8,7 @@ import type { DocV2 } from './types.js'; const { join, line } = doc.builders; -export function printComments(node: AstNode, path: AstPath): Doc[] { +export function printComments(node: AstNode, path: AstPath): Doc[] { if (!node.comments) return []; const document = join( line, diff --git a/src/slang-printers/print-comparison-operation.ts b/src/slang-printers/print-comparison-operation.ts index e8cd44b80..2bfce07df 100644 --- a/src/slang-printers/print-comparison-operation.ts +++ b/src/slang-printers/print-comparison-operation.ts @@ -5,7 +5,7 @@ import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; import { createBinaryOperationPrinter } from './create-binary-operation-printer.js'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode } from '../types.js'; +import type { AstNode, BinaryOperation } from '../types.js'; const { group, indent } = doc.builders; @@ -16,7 +16,7 @@ const isStatementWithoutIndentedOperation = createKindCheckFunction([ ]); const comparisonIndentRulesBuilder = - (path: AstPath) => + (path: AstPath) => (document: Doc): Doc => { let node = path.getNode() as AstNode; for (let i = 2; ; i += 2) { diff --git a/src/slang-printers/print-function.ts b/src/slang-printers/print-function.ts index 6727551be..a9b9e1ebb 100644 --- a/src/slang-printers/print-function.ts +++ b/src/slang-printers/print-function.ts @@ -1,7 +1,7 @@ import { doc } from 'prettier'; import type { AstPath, Doc } from 'prettier'; -import type { FunctionLike } from '../types.js'; +import type { AstNode, FunctionLike } from '../types.js'; import type { FunctionDefinition } from '../slang-nodes'; const { dedent, group, indent, line } = doc.builders; @@ -9,8 +9,8 @@ const { dedent, group, indent, line } = doc.builders; export function printFunction( functionName: Doc, node: FunctionLike, - path: AstPath, - print: (path: AstPath) => Doc + path: AstPath, + print: (path: AstPath) => Doc ): Doc { return [ group([ diff --git a/src/slang-printers/print-logical-operation.ts b/src/slang-printers/print-logical-operation.ts index 3eea0fd1e..a1e855e25 100644 --- a/src/slang-printers/print-logical-operation.ts +++ b/src/slang-printers/print-logical-operation.ts @@ -5,7 +5,7 @@ import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; import { createBinaryOperationPrinter } from './create-binary-operation-printer.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode } from '../types.js'; +import type { AstNode, BinaryOperation } from '../types.js'; const { group, indent } = doc.builders; @@ -16,12 +16,12 @@ const isStatementWithoutIndentedOperation = createKindCheckFunction([ ]); const logicalGroupRulesBuilder = - (path: AstPath) => + (path: AstPath) => (document: Doc): Doc => isBinaryOperation(path.getNode(2) as AstNode) ? document : group(document); const logicalIndentRulesBuilder = - (path: AstPath, options: ParserOptions) => + (path: AstPath, options: ParserOptions) => (document: Doc): Doc => { let node = path.getNode() as AstNode; for (let i = 2; ; i += 2) { diff --git a/src/slang-printers/print-preserving-empty-lines.ts b/src/slang-printers/print-preserving-empty-lines.ts index b0e87bcfe..b4c94a568 100644 --- a/src/slang-printers/print-preserving-empty-lines.ts +++ b/src/slang-printers/print-preserving-empty-lines.ts @@ -12,13 +12,12 @@ import type { AstNode } from '../types.js'; const { hardline } = doc.builders; export function printPreservingEmptyLines( - path: AstPath, - key: string, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions ): Doc { return path.map((childPath, index) => { - const node = childPath.getNode() as AstNode; + const node = childPath.getNode()! as AstNode; return [ // Only attempt to prepend an empty line if `node` is not the first item @@ -30,12 +29,12 @@ export function printPreservingEmptyLines( : '', print(childPath), // Only attempt to append an empty line if `node` is not the last item - !isLast(childPath, key, index) && + !isLast(childPath, index) && // Append an empty line if the original text already had an one after the // current `node` isNextLineEmpty(options.originalText, locEnd(node)) ? hardline : '' ]; - }, key); + }, 'items'); } diff --git a/src/slang-utils/backward-compatibility.ts b/src/slang-utils/backward-compatibility.ts index 4e8da5c0e..c9896a279 100644 --- a/src/slang-utils/backward-compatibility.ts +++ b/src/slang-utils/backward-compatibility.ts @@ -4,7 +4,7 @@ import { locEnd } from './loc.js'; import type { AstPath } from 'prettier'; import type { utilV2 } from './types'; -import type { AstNode, Comment } from '../types'; +import type { AstNode, Comment, HubNode } from '../types'; export const isPrettier2 = prettierVersionSatisfies('^2.3.0'); @@ -33,8 +33,11 @@ export function getNextNonSpaceNonCommentCharacter( return util.getNextNonSpaceNonCommentCharacter(text, locEnd(node)); // V3 exposes this function directly } -export function isLast(path: AstPath, key: string, index: number): boolean { +export function isLast( + path: AstPath, + index: number +): boolean { return isPrettier2 - ? index === path.getParentNode()[key].length - 1 + ? index === (path.getParentNode() as HubNode).items.length - 1 : path.isLast; } diff --git a/src/slangPrinter.ts b/src/slangPrinter.ts index 7cb7a06e2..23258b8e8 100644 --- a/src/slangPrinter.ts +++ b/src/slangPrinter.ts @@ -29,7 +29,7 @@ function hasNodeIgnoreComment(node: AstNode): boolean { ); } -function ignoreComments(path: AstPath): void { +function ignoreComments(path: AstPath): void { // TODO: remove undefined once we stop supporting prettier 2 const node = path.getNode() as AstNode | null | undefined; // We ignore anything that is not an object @@ -66,13 +66,13 @@ function ignoreComments(path: AstPath): void { } function genericPrint( - path: AstPath, + path: AstPath, options: ParserOptions, - print: (path: AstPath) => Doc + print: (path: AstPath) => Doc ): Doc { prettierVersionCheck(); - const node = path.getNode() as AstNode | null | undefined; + const node = path.getNode(); if (node === null || node === undefined) { return ''; @@ -84,7 +84,11 @@ function genericPrint( return options.originalText.slice(locStart(node), locEnd(node)); } - return node.print(path, print, options); + return node.print( + path as AstPath, + print as (path: AstPath) => Doc, + options + ); } export default genericPrint; diff --git a/src/types.d.ts b/src/types.d.ts index aa4483ca0..bd925c8ba 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -56,8 +56,8 @@ interface SlangNode { comments?: Comment[]; loc: Location; print?( - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: (path: AstPath) => Doc, options: ParserOptions ): Doc; } @@ -85,6 +85,51 @@ export type FunctionLike = | nodes.ReceiveFunctionDefinition | nodes.UnnamedFunctionDefinition; +export type HubNode = + | nodes.ArrayValues + | nodes.AssemblyFlags + | nodes.CallOptions + | nodes.CatchClauses + | nodes.ConstructorAttributes + | nodes.ContractMembers + | nodes.EnumMembers + | nodes.ErrorParameters + | nodes.EventParameters + | nodes.FallbackFunctionAttributes + | nodes.FunctionAttributes + | nodes.FunctionTypeAttributes + | nodes.HexStringLiterals + | nodes.IdentifierPath + | nodes.ImportDeconstructionSymbols + | nodes.InheritanceTypes + | nodes.InterfaceMembers + | nodes.LibraryMembers + | nodes.ModifierAttributes + | nodes.NamedArguments + | nodes.OverridePaths + | nodes.Parameters + | nodes.ReceiveFunctionAttributes + | nodes.SourceUnitMembers + | nodes.Statements + | nodes.StateVariableAttributes + | nodes.StringLiterals + | nodes.StructMembers + | nodes.TupleDeconstructionElements + | nodes.TupleValues + | nodes.UnicodeStringLiterals + | nodes.UnnamedFunctionAttributes + | nodes.UsingDeconstructionSymbols + | nodes.VersionExpressionSet + | nodes.VersionExpressionSets + | nodes.VersionSpecifiers + | nodes.YulArguments + | nodes.YulParameters + | nodes.YulPath + | nodes.YulPaths + | nodes.YulReturnVariables + | nodes.YulStatements + | nodes.YulSwitchCases; + export type AstNode = | nodes.SourceUnit | nodes.PragmaDirective From 1026ecc9153a061a20de117419a258555ee2805c Mon Sep 17 00:00:00 2001 From: Klaus Date: Fri, 2 Aug 2024 11:51:07 +1200 Subject: [PATCH 107/160] using supported languages instead of magic constant '0..8.26' --- .c8rc | 9 ++------- src/clean.ts | 1 + src/slangParser.ts | 8 +++++++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.c8rc b/.c8rc index 55a27d442..5ef7bcaa5 100644 --- a/.c8rc +++ b/.c8rc @@ -4,13 +4,8 @@ "lines": 100, "functions": 100, "statements": 100, - "exclude": ["/node_modules/", "/src/prettier-comments/"], - "include": [ - "src/**/*.js", - "src/**/*.ts", - "!src/prettier-comments/**/*.js", - "!src/common/backward-compatibility.js" - ], + "exclude": ["/node_modules/"], + "include": ["src/**/*.ts", "!src/slang-utils/backward-compatibility.ts"], "reporter": ["lcov", "text"], "temp-dir": "./coverage/" } diff --git a/src/clean.ts b/src/clean.ts index 280b14184..2205dea7e 100644 --- a/src/clean.ts +++ b/src/clean.ts @@ -1,5 +1,6 @@ // Prettier offers a clean way to define ignored properties. const ignoredProperties = new Set(['loc', 'range', 'comments']); +// eslint-disable-next-line @typescript-eslint/no-empty-function function clean(/* ast, newObj, parent */): void {} clean.ignoredProperties = ignoredProperties; diff --git a/src/slangParser.ts b/src/slangParser.ts index d761be39f..4b5232da8 100644 --- a/src/slangParser.ts +++ b/src/slangParser.ts @@ -16,8 +16,14 @@ function parse( options = _parsers as ParserOptions ): AstNode { const compiler = coerce(options.compiler); + const supportedVersions = Language.supportedVersions(); + + const language = new Language( + compiler && supportedVersions.includes(compiler.version) + ? compiler.version + : supportedVersions[supportedVersions.length - 1] + ); - const language = new Language(compiler?.version || '0.8.26'); const ast = new SlangSourceUnit( language.parse(NonterminalKind.SourceUnit, text).tree() as NonterminalNode ); From 527c6953bf45bca0cf63b0338072db2ae82e6cce Mon Sep 17 00:00:00 2001 From: Klaus Date: Fri, 2 Aug 2024 12:45:14 +1200 Subject: [PATCH 108/160] Handling IfStatements --- .../handlers/add-hub-node-first-comment.ts | 16 ++++++ .../handlers/add-hub-node-last-comment.ts | 16 ++++++ .../handlers/handleBlockComments.ts | 11 ++--- .../handleContractDefinitionComments.ts | 19 ++----- .../handlers/handleIfStatementComments.ts | 49 +++++++++++++++++++ .../handleParametersDeclarationComments.ts | 22 ++------- .../handlers/handleYulBlockComments.ts | 2 +- src/slang-comments/handlers/index.ts | 2 + tests/config/run-format-test.js | 1 - tests/format/AssemblyV0.4.26/Assembly.sol | 2 +- .../__snapshots__/format.test.js.snap | 4 +- .../Etc/__snapshots__/format.test.js.snap | 2 +- tests/format/Etc/format.test.js | 2 +- 13 files changed, 103 insertions(+), 45 deletions(-) create mode 100644 src/slang-comments/handlers/add-hub-node-first-comment.ts create mode 100644 src/slang-comments/handlers/add-hub-node-last-comment.ts create mode 100644 src/slang-comments/handlers/handleIfStatementComments.ts diff --git a/src/slang-comments/handlers/add-hub-node-first-comment.ts b/src/slang-comments/handlers/add-hub-node-first-comment.ts new file mode 100644 index 000000000..1a133d0d9 --- /dev/null +++ b/src/slang-comments/handlers/add-hub-node-first-comment.ts @@ -0,0 +1,16 @@ +import { util } from 'prettier'; + +import type { Comment, HubNode } from '../../types'; + +const { addDanglingComment, addLeadingComment } = util; + +export default function addHubNodeFirstComment( + node: HubNode, + comment: Comment +): void { + if (node.items.length === 0) { + addDanglingComment(node, comment, false); + } else { + addLeadingComment(node.items[0], comment); + } +} diff --git a/src/slang-comments/handlers/add-hub-node-last-comment.ts b/src/slang-comments/handlers/add-hub-node-last-comment.ts new file mode 100644 index 000000000..0f34e74af --- /dev/null +++ b/src/slang-comments/handlers/add-hub-node-last-comment.ts @@ -0,0 +1,16 @@ +import { util } from 'prettier'; + +import type { Comment, HubNode } from '../../types'; + +const { addDanglingComment, addTrailingComment } = util; + +export default function addHubNodeLastComment( + node: HubNode, + comment: Comment +): void { + if (node.items.length === 0) { + addDanglingComment(node, comment, false); + } else { + addTrailingComment(node.items[node.items.length - 1], comment); + } +} diff --git a/src/slang-comments/handlers/handleBlockComments.ts b/src/slang-comments/handlers/handleBlockComments.ts index 94e2e2a13..37d59d8f2 100644 --- a/src/slang-comments/handlers/handleBlockComments.ts +++ b/src/slang-comments/handlers/handleBlockComments.ts @@ -1,9 +1,10 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { util } from 'prettier'; +import addHubNodeFirstComment from './add-hub-node-first-comment.js'; -import type { HandlerParams } from './types'; +import type { HandlerParams } from './types.js'; -const { addDanglingComment, addLeadingComment, addTrailingComment } = util; +const { addDanglingComment, addTrailingComment } = util; export default function handleBlockComments({ precedingNode, @@ -28,11 +29,7 @@ export default function handleBlockComments({ } if (followingNode?.kind === NonterminalKind.Statements) { - if (followingNode.items.length === 0) { - addDanglingComment(followingNode, comment, false); - } else { - addLeadingComment(followingNode.items[0], comment); - } + addHubNodeFirstComment(followingNode, comment); return true; } diff --git a/src/slang-comments/handlers/handleContractDefinitionComments.ts b/src/slang-comments/handlers/handleContractDefinitionComments.ts index 5893cd4a5..2c508ac08 100644 --- a/src/slang-comments/handlers/handleContractDefinitionComments.ts +++ b/src/slang-comments/handlers/handleContractDefinitionComments.ts @@ -1,10 +1,12 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { util } from 'prettier'; import { getNextNonSpaceNonCommentCharacter } from '../../slang-utils/backward-compatibility.js'; +import addHubNodeFirstComment from './add-hub-node-first-comment.js'; +import addHubNodeLastComment from './add-hub-node-last-comment.js'; import type { HandlerParams } from './types.js'; -const { addLeadingComment, addDanglingComment, addTrailingComment } = util; +const { addLeadingComment, addTrailingComment } = util; export default function handleContractDefinitionComments({ text, @@ -32,14 +34,7 @@ export default function handleContractDefinitionComments({ // The comment is at the end of the body of the ContractDefinition. if (precedingNode?.kind === NonterminalKind.ContractMembers) { - if (precedingNode.items.length === 0) { - addDanglingComment(precedingNode, comment, false); - } else { - addTrailingComment( - precedingNode.items[precedingNode.items.length - 1], - comment - ); - } + addHubNodeLastComment(precedingNode, comment); return true; } @@ -61,11 +56,7 @@ export default function handleContractDefinitionComments({ // If there's no InheritanceSpecifier, the comment before the body is // assumed to be intended at the beginning of the body. if (followingNode?.kind === NonterminalKind.ContractMembers) { - if (followingNode.items.length > 0) { - addLeadingComment(followingNode.items[0], comment); - } else { - addDanglingComment(followingNode, comment, false); - } + addHubNodeFirstComment(followingNode, comment); return true; } } diff --git a/src/slang-comments/handlers/handleIfStatementComments.ts b/src/slang-comments/handlers/handleIfStatementComments.ts new file mode 100644 index 000000000..5f78be151 --- /dev/null +++ b/src/slang-comments/handlers/handleIfStatementComments.ts @@ -0,0 +1,49 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { util } from 'prettier'; +import { getNextNonSpaceNonCommentCharacter } from '../../slang-utils/backward-compatibility.js'; +import addHubNodeLastComment from './add-hub-node-last-comment.js'; + +import type { HandlerParams } from './types.js'; + +const { addTrailingComment } = util; + +export default function handleIfStatementComments({ + text, + precedingNode, + enclosingNode, + followingNode, + comment +}: HandlerParams): boolean { + // console.log(comment); + if (enclosingNode?.kind !== NonterminalKind.IfStatement || !followingNode) { + return false; + } + + // We unfortunately have no way using the AST or location of nodes to know + // if the comment is positioned before the condition parenthesis: + // if (a /* comment */) {} + // The only workaround I found is to look at the next character to see if + // it is a ). + const nextCharacter = getNextNonSpaceNonCommentCharacter(text, comment); + if (nextCharacter === ')') { + addTrailingComment(precedingNode, comment); + return true; + } + + // Comments before `else`: + // - treat as trailing comments of the consequent, if it's a BlockStatement + // - treat as a dangling comment otherwise + if ( + precedingNode === enclosingNode.body && + followingNode === enclosingNode.elseBranch + ) { + if (precedingNode.variant.kind === NonterminalKind.Block) { + addHubNodeLastComment(precedingNode.variant.statements, comment); + } else { + addTrailingComment(precedingNode, comment); + } + return true; + } + + return false; +} diff --git a/src/slang-comments/handlers/handleParametersDeclarationComments.ts b/src/slang-comments/handlers/handleParametersDeclarationComments.ts index 3e662de9c..f9ec482e1 100644 --- a/src/slang-comments/handlers/handleParametersDeclarationComments.ts +++ b/src/slang-comments/handlers/handleParametersDeclarationComments.ts @@ -1,9 +1,8 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import { util } from 'prettier'; +import addHubNodeFirstComment from './add-hub-node-first-comment.js'; +import addHubNodeLastComment from './add-hub-node-last-comment.js'; -import type { HandlerParams } from './types'; - -const { addDanglingComment, addLeadingComment, addTrailingComment } = util; +import type { HandlerParams } from './types.js'; export default function handleBlockComments({ precedingNode, @@ -16,23 +15,12 @@ export default function handleBlockComments({ } if (precedingNode?.kind === NonterminalKind.Parameters) { - if (precedingNode.items.length === 0) { - addDanglingComment(precedingNode, comment, false); - } else { - addTrailingComment( - precedingNode.items[precedingNode.items.length - 1], - comment - ); - } + addHubNodeLastComment(precedingNode, comment); return true; } if (followingNode?.kind === NonterminalKind.Parameters) { - if (followingNode.items.length === 0) { - addDanglingComment(followingNode, comment, false); - } else { - addLeadingComment(followingNode.items[0], comment); - } + addHubNodeFirstComment(followingNode, comment); return true; } diff --git a/src/slang-comments/handlers/handleYulBlockComments.ts b/src/slang-comments/handlers/handleYulBlockComments.ts index baf6bd16c..151eba657 100644 --- a/src/slang-comments/handlers/handleYulBlockComments.ts +++ b/src/slang-comments/handlers/handleYulBlockComments.ts @@ -1,7 +1,7 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { util } from 'prettier'; -import type { HandlerParams } from './types'; +import type { HandlerParams } from './types.js'; const { addLeadingComment, addDanglingComment } = util; diff --git a/src/slang-comments/handlers/index.ts b/src/slang-comments/handlers/index.ts index 09d543df9..ca0c013a3 100644 --- a/src/slang-comments/handlers/index.ts +++ b/src/slang-comments/handlers/index.ts @@ -1,5 +1,6 @@ import handleBlockComments from './handleBlockComments.js'; import handleContractDefinitionComments from './handleContractDefinitionComments.js'; +import handleIfStatementComments from './handleIfStatementComments.js'; import handleParametersDeclarationComments from './handleParametersDeclarationComments.js'; import handleWhileStatementComments from './handleWhileStatementComments.js'; import handleYulBlockComments from './handleYulBlockComments.js'; @@ -7,6 +8,7 @@ import handleYulBlockComments from './handleYulBlockComments.js'; export default [ handleBlockComments, handleContractDefinitionComments, + handleIfStatementComments, handleParametersDeclarationComments, handleWhileStatementComments, handleYulBlockComments diff --git a/tests/config/run-format-test.js b/tests/config/run-format-test.js index a7742da44..023b71fa8 100644 --- a/tests/config/run-format-test.js +++ b/tests/config/run-format-test.js @@ -46,7 +46,6 @@ const testsWithSlang = new Map( // "AssemblyV0.4.26/Assembly.sol", // TODO: Report to Nomic Foundation? // "BasicIterator/BasicIterator.sol", // TODO: Fix solidity-parser comments // "Comments/Comments.sol", // TODO: finish Comments - // "Etc/Etc.sol", // TODO: Comments for if Statements // "IndexOf/IndexOf.sol", // TODO: Finish comments and file level functions ].map((fixture) => { const [file, testSlang = () => true] = Array.isArray(fixture) diff --git a/tests/format/AssemblyV0.4.26/Assembly.sol b/tests/format/AssemblyV0.4.26/Assembly.sol index cbe6b873e..dddccb54c 100644 --- a/tests/format/AssemblyV0.4.26/Assembly.sol +++ b/tests/format/AssemblyV0.4.26/Assembly.sol @@ -35,7 +35,7 @@ assembly{ } } -contract MultipleAssemblyAssignement { +contract MultipleAssemblyAssignment { function foo() public pure { assembly { function bar() -> a, b { diff --git a/tests/format/AssemblyV0.4.26/__snapshots__/format.test.js.snap b/tests/format/AssemblyV0.4.26/__snapshots__/format.test.js.snap index 35ca25460..d249ad2e4 100644 --- a/tests/format/AssemblyV0.4.26/__snapshots__/format.test.js.snap +++ b/tests/format/AssemblyV0.4.26/__snapshots__/format.test.js.snap @@ -44,7 +44,7 @@ assembly{ } } -contract MultipleAssemblyAssignement { +contract MultipleAssemblyAssignment { function foo() public pure { assembly { function bar() -> a, b { @@ -105,7 +105,7 @@ contract Assembly { } } -contract MultipleAssemblyAssignement { +contract MultipleAssemblyAssignment { function foo() public pure { assembly { function bar() -> a, b { diff --git a/tests/format/Etc/__snapshots__/format.test.js.snap b/tests/format/Etc/__snapshots__/format.test.js.snap index eee66d87d..49763d7c9 100644 --- a/tests/format/Etc/__snapshots__/format.test.js.snap +++ b/tests/format/Etc/__snapshots__/format.test.js.snap @@ -2,7 +2,7 @@ exports[`Etc.sol format 1`] = ` ====================================options===================================== -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/format/Etc/format.test.js b/tests/format/Etc/format.test.js index 2ae629864..6021bbb0d 100644 --- a/tests/format/Etc/format.test.js +++ b/tests/format/Etc/format.test.js @@ -1 +1 @@ -runFormatTest(import.meta, ['solidity-parse']); +runFormatTest(import.meta, ['slang']); From e9876cc61ed88569ef566e8a1c72451f02119e06 Mon Sep 17 00:00:00 2001 From: Klaus Date: Fri, 2 Aug 2024 15:24:56 +1200 Subject: [PATCH 109/160] more if statement comment cases --- .../handlers/handleIfStatementComments.ts | 23 ++++++++++++++++++- tests/config/run-format-test.js | 2 +- .../IndexOf/__snapshots__/format.test.js.snap | 3 ++- tests/format/IndexOf/format.test.js | 2 +- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/slang-comments/handlers/handleIfStatementComments.ts b/src/slang-comments/handlers/handleIfStatementComments.ts index 5f78be151..ebafe0284 100644 --- a/src/slang-comments/handlers/handleIfStatementComments.ts +++ b/src/slang-comments/handlers/handleIfStatementComments.ts @@ -1,11 +1,12 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { util } from 'prettier'; import { getNextNonSpaceNonCommentCharacter } from '../../slang-utils/backward-compatibility.js'; +import addHubNodeFirstComment from './add-hub-node-first-comment.js'; import addHubNodeLastComment from './add-hub-node-last-comment.js'; import type { HandlerParams } from './types.js'; -const { addTrailingComment } = util; +const { addLeadingComment, addTrailingComment } = util; export default function handleIfStatementComments({ text, @@ -45,5 +46,25 @@ export default function handleIfStatementComments({ return true; } + if (followingNode.kind === NonterminalKind.IfStatement) { + if (followingNode.body.variant.kind === NonterminalKind.Block) { + addHubNodeFirstComment(followingNode.body.variant.statements, comment); + } else { + addLeadingComment(followingNode.body.variant, comment); + } + return true; + } + + // For comments positioned after the condition parenthesis in an if statement + // before the consequent without brackets on, such as + // if (a) /* comment */ true + if (enclosingNode.body === followingNode) { + if (followingNode.variant.kind === NonterminalKind.Block) { + addHubNodeFirstComment(followingNode.variant.statements, comment); + } else { + addLeadingComment(followingNode, comment); + } + return true; + } return false; } diff --git a/tests/config/run-format-test.js b/tests/config/run-format-test.js index 023b71fa8..65afde5d1 100644 --- a/tests/config/run-format-test.js +++ b/tests/config/run-format-test.js @@ -46,7 +46,7 @@ const testsWithSlang = new Map( // "AssemblyV0.4.26/Assembly.sol", // TODO: Report to Nomic Foundation? // "BasicIterator/BasicIterator.sol", // TODO: Fix solidity-parser comments // "Comments/Comments.sol", // TODO: finish Comments - // "IndexOf/IndexOf.sol", // TODO: Finish comments and file level functions + "IndexOf/IndexOf.sol", // TODO: Finish comments and file level functions ].map((fixture) => { const [file, testSlang = () => true] = Array.isArray(fixture) ? fixture diff --git a/tests/format/IndexOf/__snapshots__/format.test.js.snap b/tests/format/IndexOf/__snapshots__/format.test.js.snap index ed75f25aa..8704a8bb6 100644 --- a/tests/format/IndexOf/__snapshots__/format.test.js.snap +++ b/tests/format/IndexOf/__snapshots__/format.test.js.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`IndexOf.sol format 1`] = ` +exports[`IndexOf.sol - {"compiler":"0.4.26"} format 1`] = ` ====================================options===================================== +compiler: "0.4.26" parsers: ["solidity-parse"] printWidth: 80 | printWidth diff --git a/tests/format/IndexOf/format.test.js b/tests/format/IndexOf/format.test.js index 2ae629864..94898ac13 100644 --- a/tests/format/IndexOf/format.test.js +++ b/tests/format/IndexOf/format.test.js @@ -1 +1 @@ -runFormatTest(import.meta, ['solidity-parse']); +runFormatTest(import.meta, ['solidity-parse'], { compiler: '0.4.26' }); From e45eb4ee233554687dff2c0a1df0aff02657aa93 Mon Sep 17 00:00:00 2001 From: Klaus Date: Fri, 2 Aug 2024 15:55:02 +1200 Subject: [PATCH 110/160] cleaning up imports --- src/index.ts | 2 +- src/slang-comments/handler.ts | 2 +- .../handlers/handleBlockComments.ts | 2 +- .../handleContractDefinitionComments.ts | 2 +- .../handlers/handleIfStatementComments.ts | 2 +- .../handleParametersDeclarationComments.ts | 2 +- .../handlers/handleWhileStatementComments.ts | 2 +- .../handlers/handleYulBlockComments.ts | 2 +- src/slang-comments/printer.ts | 2 +- src/slang-nodes/ABICoderPragma.ts | 4 +- src/slang-nodes/AdditiveExpression.ts | 4 +- src/slang-nodes/AddressType.ts | 4 +- src/slang-nodes/AndExpression.ts | 4 +- src/slang-nodes/ArgumentsDeclaration.ts | 4 +- src/slang-nodes/ArrayExpression.ts | 4 +- src/slang-nodes/ArrayTypeName.ts | 4 +- src/slang-nodes/ArrayValues.ts | 4 +- src/slang-nodes/AssemblyFlags.ts | 4 +- src/slang-nodes/AssemblyFlagsDeclaration.ts | 4 +- src/slang-nodes/AssemblyStatement.ts | 4 +- src/slang-nodes/AssignmentExpression.ts | 4 +- src/slang-nodes/BitwiseAndExpression.ts | 4 +- src/slang-nodes/BitwiseOrExpression.ts | 4 +- src/slang-nodes/BitwiseXorExpression.ts | 4 +- src/slang-nodes/Block.ts | 4 +- src/slang-nodes/BreakStatement.ts | 4 +- src/slang-nodes/CallOptions.ts | 4 +- src/slang-nodes/CallOptionsExpression.ts | 4 +- src/slang-nodes/CatchClause.ts | 4 +- src/slang-nodes/CatchClauseError.ts | 4 +- src/slang-nodes/CatchClauses.ts | 4 +- src/slang-nodes/ComparisonExpression.ts | 4 +- src/slang-nodes/ConditionalExpression.ts | 4 +- src/slang-nodes/ConstantDefinition.ts | 4 +- src/slang-nodes/ConstructorAttribute.ts | 4 +- src/slang-nodes/ConstructorAttributes.ts | 4 +- src/slang-nodes/ConstructorDefinition.ts | 4 +- src/slang-nodes/ContinueStatement.ts | 4 +- src/slang-nodes/ContractDefinition.ts | 4 +- src/slang-nodes/ContractMember.ts | 4 +- src/slang-nodes/ContractMembers.ts | 4 +- src/slang-nodes/DecimalNumberExpression.ts | 4 +- src/slang-nodes/DoWhileStatement.ts | 4 +- src/slang-nodes/ElementaryType.ts | 4 +- src/slang-nodes/ElseBranch.ts | 4 +- src/slang-nodes/EmitStatement.ts | 4 +- src/slang-nodes/EnumDefinition.ts | 4 +- src/slang-nodes/EnumMembers.ts | 4 +- src/slang-nodes/EqualityExpression.ts | 4 +- src/slang-nodes/ErrorDefinition.ts | 4 +- src/slang-nodes/ErrorParameter.ts | 4 +- src/slang-nodes/ErrorParameters.ts | 4 +- src/slang-nodes/ErrorParametersDeclaration.ts | 4 +- src/slang-nodes/EventDefinition.ts | 4 +- src/slang-nodes/EventParameter.ts | 4 +- src/slang-nodes/EventParameters.ts | 4 +- src/slang-nodes/EventParametersDeclaration.ts | 4 +- src/slang-nodes/ExperimentalFeature.ts | 4 +- src/slang-nodes/ExperimentalPragma.ts | 4 +- src/slang-nodes/ExponentiationExpression.ts | 4 +- src/slang-nodes/Expression.ts | 4 +- src/slang-nodes/ExpressionStatement.ts | 4 +- src/slang-nodes/FallbackFunctionAttribute.ts | 4 +- src/slang-nodes/FallbackFunctionAttributes.ts | 4 +- src/slang-nodes/FallbackFunctionDefinition.ts | 4 +- src/slang-nodes/ForStatement.ts | 4 +- src/slang-nodes/ForStatementCondition.ts | 4 +- src/slang-nodes/ForStatementInitialization.ts | 4 +- src/slang-nodes/FunctionAttribute.ts | 4 +- src/slang-nodes/FunctionAttributes.ts | 4 +- src/slang-nodes/FunctionBody.ts | 4 +- src/slang-nodes/FunctionCallExpression.ts | 4 +- src/slang-nodes/FunctionDefinition.ts | 4 +- src/slang-nodes/FunctionName.ts | 4 +- src/slang-nodes/FunctionType.ts | 4 +- src/slang-nodes/FunctionTypeAttribute.ts | 4 +- src/slang-nodes/FunctionTypeAttributes.ts | 4 +- src/slang-nodes/HexNumberExpression.ts | 4 +- src/slang-nodes/HexStringLiteral.ts | 4 +- src/slang-nodes/HexStringLiterals.ts | 4 +- src/slang-nodes/IdentifierPath.ts | 4 +- src/slang-nodes/IfStatement.ts | 4 +- src/slang-nodes/ImportAlias.ts | 4 +- src/slang-nodes/ImportClause.ts | 4 +- src/slang-nodes/ImportDeconstruction.ts | 4 +- src/slang-nodes/ImportDeconstructionSymbol.ts | 4 +- .../ImportDeconstructionSymbols.ts | 4 +- src/slang-nodes/ImportDirective.ts | 4 +- src/slang-nodes/IndexAccessEnd.ts | 4 +- src/slang-nodes/IndexAccessExpression.ts | 4 +- src/slang-nodes/InheritanceSpecifier.ts | 4 +- src/slang-nodes/InheritanceType.ts | 4 +- src/slang-nodes/InheritanceTypes.ts | 4 +- src/slang-nodes/InterfaceDefinition.ts | 4 +- src/slang-nodes/InterfaceMembers.ts | 4 +- src/slang-nodes/LibraryDefinition.ts | 4 +- src/slang-nodes/LibraryMembers.ts | 4 +- src/slang-nodes/MappingKey.ts | 4 +- src/slang-nodes/MappingKeyType.ts | 4 +- src/slang-nodes/MappingType.ts | 4 +- src/slang-nodes/MappingValue.ts | 4 +- src/slang-nodes/MemberAccess.ts | 4 +- src/slang-nodes/MemberAccessExpression.ts | 4 +- src/slang-nodes/ModifierAttribute.ts | 4 +- src/slang-nodes/ModifierAttributes.ts | 4 +- src/slang-nodes/ModifierDefinition.ts | 4 +- src/slang-nodes/ModifierInvocation.ts | 4 +- src/slang-nodes/MultiplicativeExpression.ts | 4 +- src/slang-nodes/NamedArgument.ts | 4 +- src/slang-nodes/NamedArgumentGroup.ts | 4 +- src/slang-nodes/NamedArguments.ts | 4 +- src/slang-nodes/NamedArgumentsDeclaration.ts | 4 +- src/slang-nodes/NamedImport.ts | 4 +- src/slang-nodes/NewExpression.ts | 4 +- src/slang-nodes/NumberUnit.ts | 4 +- src/slang-nodes/OrExpression.ts | 4 +- src/slang-nodes/OverridePaths.ts | 4 +- src/slang-nodes/OverridePathsDeclaration.ts | 4 +- src/slang-nodes/OverrideSpecifier.ts | 4 +- src/slang-nodes/Parameter.ts | 4 +- src/slang-nodes/Parameters.ts | 4 +- src/slang-nodes/ParametersDeclaration.ts | 4 +- src/slang-nodes/PathImport.ts | 4 +- src/slang-nodes/PositionalArguments.ts | 4 +- .../PositionalArgumentsDeclaration.ts | 4 +- src/slang-nodes/PostfixExpression.ts | 4 +- src/slang-nodes/Pragma.ts | 4 +- src/slang-nodes/PragmaDirective.ts | 4 +- src/slang-nodes/PrefixExpression.ts | 4 +- src/slang-nodes/ReceiveFunctionAttribute.ts | 4 +- src/slang-nodes/ReceiveFunctionAttributes.ts | 4 +- src/slang-nodes/ReceiveFunctionDefinition.ts | 4 +- src/slang-nodes/ReturnStatement.ts | 4 +- src/slang-nodes/ReturnsDeclaration.ts | 4 +- src/slang-nodes/RevertStatement.ts | 4 +- src/slang-nodes/ShiftExpression.ts | 4 +- src/slang-nodes/SourceUnit.ts | 4 +- src/slang-nodes/SourceUnitMember.ts | 4 +- src/slang-nodes/SourceUnitMembers.ts | 4 +- src/slang-nodes/StateVariableAttribute.ts | 4 +- src/slang-nodes/StateVariableAttributes.ts | 4 +- src/slang-nodes/StateVariableDefinition.ts | 4 +- .../StateVariableDefinitionValue.ts | 4 +- src/slang-nodes/Statement.ts | 4 +- src/slang-nodes/Statements.ts | 4 +- src/slang-nodes/StorageLocation.ts | 4 +- src/slang-nodes/StringExpression.ts | 4 +- src/slang-nodes/StringLiteral.ts | 4 +- src/slang-nodes/StringLiterals.ts | 4 +- src/slang-nodes/StructDefinition.ts | 4 +- src/slang-nodes/StructMember.ts | 4 +- src/slang-nodes/StructMembers.ts | 4 +- src/slang-nodes/ThrowStatement.ts | 4 +- src/slang-nodes/TryStatement.ts | 4 +- src/slang-nodes/TupleDeconstructionElement.ts | 4 +- .../TupleDeconstructionElements.ts | 4 +- .../TupleDeconstructionStatement.ts | 4 +- src/slang-nodes/TupleExpression.ts | 4 +- src/slang-nodes/TupleMember.ts | 4 +- src/slang-nodes/TupleValue.ts | 4 +- src/slang-nodes/TupleValues.ts | 4 +- src/slang-nodes/TypeExpression.ts | 4 +- src/slang-nodes/TypeName.ts | 4 +- src/slang-nodes/TypedTupleMember.ts | 4 +- src/slang-nodes/UncheckedBlock.ts | 4 +- src/slang-nodes/UnicodeStringLiteral.ts | 4 +- src/slang-nodes/UnicodeStringLiterals.ts | 4 +- src/slang-nodes/UnnamedFunctionAttribute.ts | 4 +- src/slang-nodes/UnnamedFunctionAttributes.ts | 4 +- src/slang-nodes/UnnamedFunctionDefinition.ts | 4 +- src/slang-nodes/UntypedTupleMember.ts | 4 +- .../UserDefinedValueTypeDefinition.ts | 4 +- src/slang-nodes/UsingAlias.ts | 4 +- src/slang-nodes/UsingClause.ts | 4 +- src/slang-nodes/UsingDeconstruction.ts | 4 +- src/slang-nodes/UsingDeconstructionSymbol.ts | 4 +- src/slang-nodes/UsingDeconstructionSymbols.ts | 4 +- src/slang-nodes/UsingDirective.ts | 4 +- src/slang-nodes/UsingOperator.ts | 4 +- src/slang-nodes/UsingTarget.ts | 4 +- .../VariableDeclarationStatement.ts | 4 +- src/slang-nodes/VariableDeclarationType.ts | 4 +- src/slang-nodes/VariableDeclarationValue.ts | 4 +- src/slang-nodes/VersionComparator.ts | 4 +- src/slang-nodes/VersionExpression.ts | 4 +- src/slang-nodes/VersionExpressionSet.ts | 4 +- src/slang-nodes/VersionExpressionSets.ts | 4 +- src/slang-nodes/VersionPragma.ts | 4 +- src/slang-nodes/VersionRange.ts | 4 +- src/slang-nodes/VersionSpecifiers.ts | 4 +- src/slang-nodes/WhileStatement.ts | 4 +- src/slang-nodes/YulArguments.ts | 4 +- src/slang-nodes/YulAssignmentOperator.ts | 4 +- src/slang-nodes/YulBlock.ts | 4 +- src/slang-nodes/YulBreakStatement.ts | 4 +- src/slang-nodes/YulBuiltInFunction.ts | 4 +- src/slang-nodes/YulColonEqual.ts | 4 +- src/slang-nodes/YulContinueStatement.ts | 4 +- src/slang-nodes/YulDefaultCase.ts | 4 +- src/slang-nodes/YulExpression.ts | 4 +- src/slang-nodes/YulForStatement.ts | 4 +- src/slang-nodes/YulFunctionCallExpression.ts | 4 +- src/slang-nodes/YulFunctionDefinition.ts | 4 +- src/slang-nodes/YulIfStatement.ts | 4 +- src/slang-nodes/YulLabel.ts | 4 +- src/slang-nodes/YulLeaveStatement.ts | 4 +- src/slang-nodes/YulLiteral.ts | 4 +- src/slang-nodes/YulParameters.ts | 4 +- src/slang-nodes/YulParametersDeclaration.ts | 4 +- src/slang-nodes/YulPath.ts | 4 +- src/slang-nodes/YulPathComponent.ts | 4 +- src/slang-nodes/YulPaths.ts | 4 +- src/slang-nodes/YulReturnVariables.ts | 4 +- src/slang-nodes/YulReturnsDeclaration.ts | 4 +- .../YulStackAssignmentStatement.ts | 4 +- src/slang-nodes/YulStatement.ts | 4 +- src/slang-nodes/YulStatements.ts | 4 +- src/slang-nodes/YulSwitchCase.ts | 4 +- src/slang-nodes/YulSwitchCases.ts | 4 +- src/slang-nodes/YulSwitchStatement.ts | 4 +- src/slang-nodes/YulValueCase.ts | 4 +- .../YulVariableAssignmentStatement.ts | 4 +- .../YulVariableDeclarationStatement.ts | 4 +- .../YulVariableDeclarationValue.ts | 4 +- src/slang-nodes/index.d.ts | 215 ++++++++++++++++++ src/slang-nodes/index.ts | 215 ------------------ .../create-binary-operation-printer.ts | 2 +- src/slang-printers/print-binary-operation.ts | 2 +- src/slang-printers/print-comments.ts | 4 +- .../print-comparison-operation.ts | 2 +- src/slang-printers/print-function.ts | 2 +- src/slang-printers/print-logical-operation.ts | 2 +- .../print-preserving-empty-lines.ts | 2 +- src/slang-utils/is-binary-operation.ts | 4 +- src/slang-utils/is-comment.ts | 2 +- src/slang-utils/metadata.ts | 4 +- src/slang-utils/sort-function-attributes.ts | 1 + src/slang-utils/types.d.ts | 2 +- src/slangParser.ts | 4 +- src/slangPrinter.ts | 2 +- src/types.d.ts | 6 +- 241 files changed, 675 insertions(+), 674 deletions(-) create mode 100644 src/slang-nodes/index.d.ts delete mode 100644 src/slang-nodes/index.ts diff --git a/src/index.ts b/src/index.ts index cc7f1b363..6218e63e6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,7 +16,7 @@ import type { RequiredOptions, SupportLanguage } from 'prettier'; -import type { AstNode, Comment } from './types.js'; +import type { AstNode, Comment } from './types'; const parserName = 'slang'; const astFormat = 'slang-ast'; diff --git a/src/slang-comments/handler.ts b/src/slang-comments/handler.ts index de7666a95..a4727f88b 100644 --- a/src/slang-comments/handler.ts +++ b/src/slang-comments/handler.ts @@ -1,7 +1,7 @@ import handlers from './handlers/index.js'; import type { ParserOptions } from 'prettier'; -import type { AstNode, Comment } from '../types.js'; +import type { AstNode, Comment } from '../types'; export function slangHandleOwnLineComment( comment: Comment, diff --git a/src/slang-comments/handlers/handleBlockComments.ts b/src/slang-comments/handlers/handleBlockComments.ts index 37d59d8f2..e4d12ef1e 100644 --- a/src/slang-comments/handlers/handleBlockComments.ts +++ b/src/slang-comments/handlers/handleBlockComments.ts @@ -2,7 +2,7 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { util } from 'prettier'; import addHubNodeFirstComment from './add-hub-node-first-comment.js'; -import type { HandlerParams } from './types.js'; +import type { HandlerParams } from './types'; const { addDanglingComment, addTrailingComment } = util; diff --git a/src/slang-comments/handlers/handleContractDefinitionComments.ts b/src/slang-comments/handlers/handleContractDefinitionComments.ts index 2c508ac08..ba986bf55 100644 --- a/src/slang-comments/handlers/handleContractDefinitionComments.ts +++ b/src/slang-comments/handlers/handleContractDefinitionComments.ts @@ -4,7 +4,7 @@ import { getNextNonSpaceNonCommentCharacter } from '../../slang-utils/backward-c import addHubNodeFirstComment from './add-hub-node-first-comment.js'; import addHubNodeLastComment from './add-hub-node-last-comment.js'; -import type { HandlerParams } from './types.js'; +import type { HandlerParams } from './types'; const { addLeadingComment, addTrailingComment } = util; diff --git a/src/slang-comments/handlers/handleIfStatementComments.ts b/src/slang-comments/handlers/handleIfStatementComments.ts index ebafe0284..1d96a7f6a 100644 --- a/src/slang-comments/handlers/handleIfStatementComments.ts +++ b/src/slang-comments/handlers/handleIfStatementComments.ts @@ -4,7 +4,7 @@ import { getNextNonSpaceNonCommentCharacter } from '../../slang-utils/backward-c import addHubNodeFirstComment from './add-hub-node-first-comment.js'; import addHubNodeLastComment from './add-hub-node-last-comment.js'; -import type { HandlerParams } from './types.js'; +import type { HandlerParams } from './types'; const { addLeadingComment, addTrailingComment } = util; diff --git a/src/slang-comments/handlers/handleParametersDeclarationComments.ts b/src/slang-comments/handlers/handleParametersDeclarationComments.ts index f9ec482e1..896d908d4 100644 --- a/src/slang-comments/handlers/handleParametersDeclarationComments.ts +++ b/src/slang-comments/handlers/handleParametersDeclarationComments.ts @@ -2,7 +2,7 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import addHubNodeFirstComment from './add-hub-node-first-comment.js'; import addHubNodeLastComment from './add-hub-node-last-comment.js'; -import type { HandlerParams } from './types.js'; +import type { HandlerParams } from './types'; export default function handleBlockComments({ precedingNode, diff --git a/src/slang-comments/handlers/handleWhileStatementComments.ts b/src/slang-comments/handlers/handleWhileStatementComments.ts index e31cfe507..7ca332ea4 100644 --- a/src/slang-comments/handlers/handleWhileStatementComments.ts +++ b/src/slang-comments/handlers/handleWhileStatementComments.ts @@ -2,7 +2,7 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { util } from 'prettier'; import { getNextNonSpaceNonCommentCharacter } from '../../slang-utils/backward-compatibility.js'; -import type { HandlerParams } from './types.js'; +import type { HandlerParams } from './types'; const { addTrailingComment } = util; diff --git a/src/slang-comments/handlers/handleYulBlockComments.ts b/src/slang-comments/handlers/handleYulBlockComments.ts index 151eba657..baf6bd16c 100644 --- a/src/slang-comments/handlers/handleYulBlockComments.ts +++ b/src/slang-comments/handlers/handleYulBlockComments.ts @@ -1,7 +1,7 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { util } from 'prettier'; -import type { HandlerParams } from './types.js'; +import type { HandlerParams } from './types'; const { addLeadingComment, addDanglingComment } = util; diff --git a/src/slang-comments/printer.ts b/src/slang-comments/printer.ts index 7b65419a4..82d5f38de 100644 --- a/src/slang-comments/printer.ts +++ b/src/slang-comments/printer.ts @@ -2,7 +2,7 @@ import { doc } from 'prettier'; import { isBlockComment, isLineComment } from '../slang-utils/is-comment.js'; import type { AstPath, Doc } from 'prettier'; -import type { Comment } from '../types.js'; +import type { Comment } from '../types'; const { hardline, join, literalline } = doc.builders; diff --git a/src/slang-nodes/ABICoderPragma.ts b/src/slang-nodes/ABICoderPragma.ts index 5e728294d..8c8f5e050 100644 --- a/src/slang-nodes/ABICoderPragma.ts +++ b/src/slang-nodes/ABICoderPragma.ts @@ -1,9 +1,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata } from '../slang-utils/metadata.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { SlangNode } from '../types'; export class ABICoderPragma implements SlangNode { readonly kind = NonterminalKind.ABICoderPragma; diff --git a/src/slang-nodes/AdditiveExpression.ts b/src/slang-nodes/AdditiveExpression.ts index b7a3a8acf..d6c8ae5bb 100644 --- a/src/slang-nodes/AdditiveExpression.ts +++ b/src/slang-nodes/AdditiveExpression.ts @@ -4,9 +4,9 @@ import { createHugFunction } from '../slang-utils/create-hug-function.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const tryToHug = createHugFunction(['%']); diff --git a/src/slang-nodes/AddressType.ts b/src/slang-nodes/AddressType.ts index 7ca005078..14588d1dd 100644 --- a/src/slang-nodes/AddressType.ts +++ b/src/slang-nodes/AddressType.ts @@ -1,9 +1,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata } from '../slang-utils/metadata.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { SlangNode } from '../types'; export class AddressType implements SlangNode { readonly kind = NonterminalKind.AddressType; diff --git a/src/slang-nodes/AndExpression.ts b/src/slang-nodes/AndExpression.ts index 8b4440ed1..e2c8da4eb 100644 --- a/src/slang-nodes/AndExpression.ts +++ b/src/slang-nodes/AndExpression.ts @@ -3,9 +3,9 @@ import { printLogicalOperation } from '../slang-printers/print-logical-operation import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class AndExpression implements SlangNode { readonly kind = NonterminalKind.AndExpression; diff --git a/src/slang-nodes/ArgumentsDeclaration.ts b/src/slang-nodes/ArgumentsDeclaration.ts index ce9411897..31555090f 100644 --- a/src/slang-nodes/ArgumentsDeclaration.ts +++ b/src/slang-nodes/ArgumentsDeclaration.ts @@ -3,9 +3,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { PositionalArgumentsDeclaration } from './PositionalArgumentsDeclaration.js'; import { NamedArgumentsDeclaration } from './NamedArgumentsDeclaration.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class ArgumentsDeclaration implements SlangNode { readonly kind = NonterminalKind.ArgumentsDeclaration; diff --git a/src/slang-nodes/ArrayExpression.ts b/src/slang-nodes/ArrayExpression.ts index cef9d35bc..306abf0de 100644 --- a/src/slang-nodes/ArrayExpression.ts +++ b/src/slang-nodes/ArrayExpression.ts @@ -3,9 +3,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ArrayValues } from './ArrayValues.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { group } = doc.builders; diff --git a/src/slang-nodes/ArrayTypeName.ts b/src/slang-nodes/ArrayTypeName.ts index 049eb8506..c903929c6 100644 --- a/src/slang-nodes/ArrayTypeName.ts +++ b/src/slang-nodes/ArrayTypeName.ts @@ -3,9 +3,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TypeName } from './TypeName.js'; import { Expression } from './Expression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class ArrayTypeName implements SlangNode { readonly kind = NonterminalKind.ArrayTypeName; diff --git a/src/slang-nodes/ArrayValues.ts b/src/slang-nodes/ArrayValues.ts index 530749ac0..0925d36e1 100644 --- a/src/slang-nodes/ArrayValues.ts +++ b/src/slang-nodes/ArrayValues.ts @@ -3,9 +3,9 @@ import { printSeparatedList } from '../slang-printers/print-separated-list.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class ArrayValues implements SlangNode { readonly kind = NonterminalKind.ArrayValues; diff --git a/src/slang-nodes/AssemblyFlags.ts b/src/slang-nodes/AssemblyFlags.ts index b7aec3347..4c948dbc1 100644 --- a/src/slang-nodes/AssemblyFlags.ts +++ b/src/slang-nodes/AssemblyFlags.ts @@ -3,9 +3,9 @@ import { printSeparatedList } from '../slang-printers/print-separated-list.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { StringLiteral } from './StringLiteral.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class AssemblyFlags implements SlangNode { readonly kind = NonterminalKind.AssemblyFlags; diff --git a/src/slang-nodes/AssemblyFlagsDeclaration.ts b/src/slang-nodes/AssemblyFlagsDeclaration.ts index 73e38229d..792a39ef5 100644 --- a/src/slang-nodes/AssemblyFlagsDeclaration.ts +++ b/src/slang-nodes/AssemblyFlagsDeclaration.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { AssemblyFlags } from './AssemblyFlags.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class AssemblyFlagsDeclaration implements SlangNode { readonly kind = NonterminalKind.AssemblyFlagsDeclaration; diff --git a/src/slang-nodes/AssemblyStatement.ts b/src/slang-nodes/AssemblyStatement.ts index 9a669c3ec..1ef0e0825 100644 --- a/src/slang-nodes/AssemblyStatement.ts +++ b/src/slang-nodes/AssemblyStatement.ts @@ -4,9 +4,9 @@ import { StringLiteral } from './StringLiteral.js'; import { AssemblyFlagsDeclaration } from './AssemblyFlagsDeclaration.js'; import { YulBlock } from './YulBlock.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class AssemblyStatement implements SlangNode { readonly kind = NonterminalKind.AssemblyStatement; diff --git a/src/slang-nodes/AssignmentExpression.ts b/src/slang-nodes/AssignmentExpression.ts index 65ba4d332..6dd355119 100644 --- a/src/slang-nodes/AssignmentExpression.ts +++ b/src/slang-nodes/AssignmentExpression.ts @@ -4,9 +4,9 @@ import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { group, indent, line } = doc.builders; diff --git a/src/slang-nodes/BitwiseAndExpression.ts b/src/slang-nodes/BitwiseAndExpression.ts index 95e0d58ba..a84fdfd9b 100644 --- a/src/slang-nodes/BitwiseAndExpression.ts +++ b/src/slang-nodes/BitwiseAndExpression.ts @@ -4,9 +4,9 @@ import { createHugFunction } from '../slang-utils/create-hug-function.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const tryToHug = createHugFunction(['+', '-', '*', '/', '**', '<<', '>>']); diff --git a/src/slang-nodes/BitwiseOrExpression.ts b/src/slang-nodes/BitwiseOrExpression.ts index dd5746826..1149e9c68 100644 --- a/src/slang-nodes/BitwiseOrExpression.ts +++ b/src/slang-nodes/BitwiseOrExpression.ts @@ -4,9 +4,9 @@ import { createHugFunction } from '../slang-utils/create-hug-function.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const tryToHug = createHugFunction([ '+', diff --git a/src/slang-nodes/BitwiseXorExpression.ts b/src/slang-nodes/BitwiseXorExpression.ts index dd8d78d6c..a8f9846d9 100644 --- a/src/slang-nodes/BitwiseXorExpression.ts +++ b/src/slang-nodes/BitwiseXorExpression.ts @@ -4,9 +4,9 @@ import { createHugFunction } from '../slang-utils/create-hug-function.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const tryToHug = createHugFunction(['+', '-', '*', '/', '**', '<<', '>>', '&']); diff --git a/src/slang-nodes/Block.ts b/src/slang-nodes/Block.ts index 034452c88..99d8af64b 100644 --- a/src/slang-nodes/Block.ts +++ b/src/slang-nodes/Block.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Statements } from './Statements.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class Block implements SlangNode { readonly kind = NonterminalKind.Block; diff --git a/src/slang-nodes/BreakStatement.ts b/src/slang-nodes/BreakStatement.ts index 03369297e..1a8a7006a 100644 --- a/src/slang-nodes/BreakStatement.ts +++ b/src/slang-nodes/BreakStatement.ts @@ -1,9 +1,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata } from '../slang-utils/metadata.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { SlangNode } from '../types'; export class BreakStatement implements SlangNode { readonly kind = NonterminalKind.BreakStatement; diff --git a/src/slang-nodes/CallOptions.ts b/src/slang-nodes/CallOptions.ts index 592b57ccb..fd779d790 100644 --- a/src/slang-nodes/CallOptions.ts +++ b/src/slang-nodes/CallOptions.ts @@ -4,9 +4,9 @@ import { printSeparatedList } from '../slang-printers/print-separated-list.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { NamedArgument } from './NamedArgument.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { line, softline } = doc.builders; diff --git a/src/slang-nodes/CallOptionsExpression.ts b/src/slang-nodes/CallOptionsExpression.ts index 4a0e6884b..57caf225a 100644 --- a/src/slang-nodes/CallOptionsExpression.ts +++ b/src/slang-nodes/CallOptionsExpression.ts @@ -3,9 +3,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import { CallOptions } from './CallOptions.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class CallOptionsExpression implements SlangNode { readonly kind = NonterminalKind.CallOptionsExpression; diff --git a/src/slang-nodes/CatchClause.ts b/src/slang-nodes/CatchClause.ts index 7a0527d53..b867c2624 100644 --- a/src/slang-nodes/CatchClause.ts +++ b/src/slang-nodes/CatchClause.ts @@ -3,9 +3,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { CatchClauseError } from './CatchClauseError.js'; import { Block } from './Block.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class CatchClause implements SlangNode { readonly kind = NonterminalKind.CatchClause; diff --git a/src/slang-nodes/CatchClauseError.ts b/src/slang-nodes/CatchClauseError.ts index 67b364816..9ad2856ad 100644 --- a/src/slang-nodes/CatchClauseError.ts +++ b/src/slang-nodes/CatchClauseError.ts @@ -3,9 +3,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ParametersDeclaration } from './ParametersDeclaration.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { group } = doc.builders; diff --git a/src/slang-nodes/CatchClauses.ts b/src/slang-nodes/CatchClauses.ts index e76af0b98..d191ca538 100644 --- a/src/slang-nodes/CatchClauses.ts +++ b/src/slang-nodes/CatchClauses.ts @@ -3,9 +3,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { CatchClause } from './CatchClause.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { join } = doc.builders; diff --git a/src/slang-nodes/ComparisonExpression.ts b/src/slang-nodes/ComparisonExpression.ts index 885f7b195..98462acc3 100644 --- a/src/slang-nodes/ComparisonExpression.ts +++ b/src/slang-nodes/ComparisonExpression.ts @@ -3,9 +3,9 @@ import { printComparisonOperation } from '../slang-printers/print-comparison-ope import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class ComparisonExpression implements SlangNode { readonly kind = NonterminalKind.ComparisonExpression; diff --git a/src/slang-nodes/ConditionalExpression.ts b/src/slang-nodes/ConditionalExpression.ts index 0c69e9235..42173d03c 100644 --- a/src/slang-nodes/ConditionalExpression.ts +++ b/src/slang-nodes/ConditionalExpression.ts @@ -5,9 +5,9 @@ import { printSeparatedItem } from '../slang-printers/print-separated-item.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { group, hardline, ifBreak, indent, line, softline } = doc.builders; diff --git a/src/slang-nodes/ConstantDefinition.ts b/src/slang-nodes/ConstantDefinition.ts index 1ef88be55..db50fc169 100644 --- a/src/slang-nodes/ConstantDefinition.ts +++ b/src/slang-nodes/ConstantDefinition.ts @@ -3,9 +3,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TypeName } from './TypeName.js'; import { Expression } from './Expression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { /*AstPath,*/ Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class ConstantDefinition implements SlangNode { readonly kind = NonterminalKind.ConstantDefinition; diff --git a/src/slang-nodes/ConstructorAttribute.ts b/src/slang-nodes/ConstructorAttribute.ts index 8248d6b07..c14bbb95a 100644 --- a/src/slang-nodes/ConstructorAttribute.ts +++ b/src/slang-nodes/ConstructorAttribute.ts @@ -3,9 +3,9 @@ import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ModifierInvocation } from './ModifierInvocation.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class ConstructorAttribute implements SlangNode { readonly kind = NonterminalKind.ConstructorAttribute; diff --git a/src/slang-nodes/ConstructorAttributes.ts b/src/slang-nodes/ConstructorAttributes.ts index d08f7d555..6a205ebba 100644 --- a/src/slang-nodes/ConstructorAttributes.ts +++ b/src/slang-nodes/ConstructorAttributes.ts @@ -4,9 +4,9 @@ import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes. import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ConstructorAttribute } from './ConstructorAttribute.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { line } = doc.builders; diff --git a/src/slang-nodes/ConstructorDefinition.ts b/src/slang-nodes/ConstructorDefinition.ts index 26754d2f6..b9bbf80ac 100644 --- a/src/slang-nodes/ConstructorDefinition.ts +++ b/src/slang-nodes/ConstructorDefinition.ts @@ -5,9 +5,9 @@ import { ParametersDeclaration } from './ParametersDeclaration.js'; import { ConstructorAttributes } from './ConstructorAttributes.js'; import { Block } from './Block.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class ConstructorDefinition implements SlangNode { readonly kind = NonterminalKind.ConstructorDefinition; diff --git a/src/slang-nodes/ContinueStatement.ts b/src/slang-nodes/ContinueStatement.ts index daba6ceba..071a80bf9 100644 --- a/src/slang-nodes/ContinueStatement.ts +++ b/src/slang-nodes/ContinueStatement.ts @@ -1,9 +1,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata } from '../slang-utils/metadata.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { SlangNode } from '../types'; export class ContinueStatement implements SlangNode { readonly kind = NonterminalKind.ContinueStatement; diff --git a/src/slang-nodes/ContractDefinition.ts b/src/slang-nodes/ContractDefinition.ts index 702d4fe78..ed3c31729 100644 --- a/src/slang-nodes/ContractDefinition.ts +++ b/src/slang-nodes/ContractDefinition.ts @@ -6,9 +6,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { InheritanceSpecifier } from './InheritanceSpecifier.js'; import { ContractMembers } from './ContractMembers.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { group, line } = doc.builders; diff --git a/src/slang-nodes/ContractMember.ts b/src/slang-nodes/ContractMember.ts index 36199e1b2..6ca2df214 100644 --- a/src/slang-nodes/ContractMember.ts +++ b/src/slang-nodes/ContractMember.ts @@ -14,9 +14,9 @@ import { StateVariableDefinition } from './StateVariableDefinition.js'; import { ErrorDefinition } from './ErrorDefinition.js'; import { UserDefinedValueTypeDefinition } from './UserDefinedValueTypeDefinition.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class ContractMember implements SlangNode { readonly kind = NonterminalKind.ContractMember; diff --git a/src/slang-nodes/ContractMembers.ts b/src/slang-nodes/ContractMembers.ts index 1fd8e22bf..27ca03559 100644 --- a/src/slang-nodes/ContractMembers.ts +++ b/src/slang-nodes/ContractMembers.ts @@ -6,9 +6,9 @@ import { printPreservingEmptyLines } from '../slang-printers/print-preserving-em import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ContractMember } from './ContractMember.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { hardline } = doc.builders; diff --git a/src/slang-nodes/DecimalNumberExpression.ts b/src/slang-nodes/DecimalNumberExpression.ts index a808acc04..12385a0f6 100644 --- a/src/slang-nodes/DecimalNumberExpression.ts +++ b/src/slang-nodes/DecimalNumberExpression.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { NumberUnit } from './NumberUnit.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class DecimalNumberExpression implements SlangNode { readonly kind = NonterminalKind.DecimalNumberExpression; diff --git a/src/slang-nodes/DoWhileStatement.ts b/src/slang-nodes/DoWhileStatement.ts index 0fb38fe15..0e280b773 100644 --- a/src/slang-nodes/DoWhileStatement.ts +++ b/src/slang-nodes/DoWhileStatement.ts @@ -5,9 +5,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Statement } from './Statement.js'; import { Expression } from './Expression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { group, indent, line } = doc.builders; diff --git a/src/slang-nodes/ElementaryType.ts b/src/slang-nodes/ElementaryType.ts index 9c9e7cc5e..92c187f32 100644 --- a/src/slang-nodes/ElementaryType.ts +++ b/src/slang-nodes/ElementaryType.ts @@ -3,9 +3,9 @@ import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { AddressType } from './AddressType.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class ElementaryType implements SlangNode { readonly kind = NonterminalKind.ElementaryType; diff --git a/src/slang-nodes/ElseBranch.ts b/src/slang-nodes/ElseBranch.ts index c8443d355..bf63d74e0 100644 --- a/src/slang-nodes/ElseBranch.ts +++ b/src/slang-nodes/ElseBranch.ts @@ -4,9 +4,9 @@ import { createKindCheckFunction } from '../slang-utils/create-kind-check-functi import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Statement } from './Statement.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { group, indent, line } = doc.builders; diff --git a/src/slang-nodes/EmitStatement.ts b/src/slang-nodes/EmitStatement.ts index 24fb19d27..7fcca5606 100644 --- a/src/slang-nodes/EmitStatement.ts +++ b/src/slang-nodes/EmitStatement.ts @@ -3,9 +3,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { IdentifierPath } from './IdentifierPath.js'; import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class EmitStatement implements SlangNode { readonly kind = NonterminalKind.EmitStatement; diff --git a/src/slang-nodes/EnumDefinition.ts b/src/slang-nodes/EnumDefinition.ts index 3999679c4..a1d72a413 100644 --- a/src/slang-nodes/EnumDefinition.ts +++ b/src/slang-nodes/EnumDefinition.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { EnumMembers } from './EnumMembers.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class EnumDefinition implements SlangNode { readonly kind = NonterminalKind.EnumDefinition; diff --git a/src/slang-nodes/EnumMembers.ts b/src/slang-nodes/EnumMembers.ts index 59c59175b..878f6c55c 100644 --- a/src/slang-nodes/EnumMembers.ts +++ b/src/slang-nodes/EnumMembers.ts @@ -3,9 +3,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../slang-printers/print-separated-list.js'; import { getNodeMetadata } from '../slang-utils/metadata.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { SlangNode } from '../types'; const { hardline } = doc.builders; diff --git a/src/slang-nodes/EqualityExpression.ts b/src/slang-nodes/EqualityExpression.ts index fc12cc135..a958e12ec 100644 --- a/src/slang-nodes/EqualityExpression.ts +++ b/src/slang-nodes/EqualityExpression.ts @@ -3,9 +3,9 @@ import { printComparisonOperation } from '../slang-printers/print-comparison-ope import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class EqualityExpression implements SlangNode { readonly kind = NonterminalKind.EqualityExpression; diff --git a/src/slang-nodes/ErrorDefinition.ts b/src/slang-nodes/ErrorDefinition.ts index 7b8ce7515..aff39438b 100644 --- a/src/slang-nodes/ErrorDefinition.ts +++ b/src/slang-nodes/ErrorDefinition.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ErrorParametersDeclaration } from './ErrorParametersDeclaration.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class ErrorDefinition implements SlangNode { readonly kind = NonterminalKind.ErrorDefinition; diff --git a/src/slang-nodes/ErrorParameter.ts b/src/slang-nodes/ErrorParameter.ts index 70c1abe41..1c702b947 100644 --- a/src/slang-nodes/ErrorParameter.ts +++ b/src/slang-nodes/ErrorParameter.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TypeName } from './TypeName.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class ErrorParameter implements SlangNode { readonly kind = NonterminalKind.ErrorParameter; diff --git a/src/slang-nodes/ErrorParameters.ts b/src/slang-nodes/ErrorParameters.ts index 0a010901d..5535f2219 100644 --- a/src/slang-nodes/ErrorParameters.ts +++ b/src/slang-nodes/ErrorParameters.ts @@ -3,9 +3,9 @@ import { printSeparatedList } from '../slang-printers/print-separated-list.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ErrorParameter } from './ErrorParameter.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class ErrorParameters implements SlangNode { readonly kind = NonterminalKind.ErrorParameters; diff --git a/src/slang-nodes/ErrorParametersDeclaration.ts b/src/slang-nodes/ErrorParametersDeclaration.ts index 9e2c2aa39..6f0a51991 100644 --- a/src/slang-nodes/ErrorParametersDeclaration.ts +++ b/src/slang-nodes/ErrorParametersDeclaration.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ErrorParameters } from './ErrorParameters.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class ErrorParametersDeclaration implements SlangNode { readonly kind = NonterminalKind.ErrorParametersDeclaration; diff --git a/src/slang-nodes/EventDefinition.ts b/src/slang-nodes/EventDefinition.ts index 36d9119e7..9ce882c6e 100644 --- a/src/slang-nodes/EventDefinition.ts +++ b/src/slang-nodes/EventDefinition.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { EventParametersDeclaration } from './EventParametersDeclaration.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class EventDefinition implements SlangNode { readonly kind = NonterminalKind.EventDefinition; diff --git a/src/slang-nodes/EventParameter.ts b/src/slang-nodes/EventParameter.ts index 7a05bb15f..c24b28202 100644 --- a/src/slang-nodes/EventParameter.ts +++ b/src/slang-nodes/EventParameter.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TypeName } from './TypeName.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class EventParameter implements SlangNode { readonly kind = NonterminalKind.EventParameter; diff --git a/src/slang-nodes/EventParameters.ts b/src/slang-nodes/EventParameters.ts index 8fbdbdcf6..cc80d2379 100644 --- a/src/slang-nodes/EventParameters.ts +++ b/src/slang-nodes/EventParameters.ts @@ -3,9 +3,9 @@ import { printSeparatedList } from '../slang-printers/print-separated-list.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { EventParameter } from './EventParameter.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class EventParameters implements SlangNode { readonly kind = NonterminalKind.EventParameters; diff --git a/src/slang-nodes/EventParametersDeclaration.ts b/src/slang-nodes/EventParametersDeclaration.ts index 88892048c..b3c8b3e1c 100644 --- a/src/slang-nodes/EventParametersDeclaration.ts +++ b/src/slang-nodes/EventParametersDeclaration.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { EventParameters } from './EventParameters.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class EventParametersDeclaration implements SlangNode { readonly kind = NonterminalKind.EventParametersDeclaration; diff --git a/src/slang-nodes/ExperimentalFeature.ts b/src/slang-nodes/ExperimentalFeature.ts index 0167f3d35..59cbd3708 100644 --- a/src/slang-nodes/ExperimentalFeature.ts +++ b/src/slang-nodes/ExperimentalFeature.ts @@ -3,9 +3,9 @@ import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { StringLiteral } from './StringLiteral.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class ExperimentalFeature implements SlangNode { readonly kind = NonterminalKind.ExperimentalFeature; diff --git a/src/slang-nodes/ExperimentalPragma.ts b/src/slang-nodes/ExperimentalPragma.ts index 1ca6ffdf1..ce12580cf 100644 --- a/src/slang-nodes/ExperimentalPragma.ts +++ b/src/slang-nodes/ExperimentalPragma.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ExperimentalFeature } from './ExperimentalFeature.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class ExperimentalPragma implements SlangNode { readonly kind = NonterminalKind.ExperimentalPragma; diff --git a/src/slang-nodes/ExponentiationExpression.ts b/src/slang-nodes/ExponentiationExpression.ts index 601049894..93793793c 100644 --- a/src/slang-nodes/ExponentiationExpression.ts +++ b/src/slang-nodes/ExponentiationExpression.ts @@ -10,9 +10,9 @@ import { TupleExpression } from './TupleExpression.js'; import { TupleValues } from './TupleValues.js'; import { TupleValue } from './TupleValue.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { group, indent } = doc.builders; diff --git a/src/slang-nodes/Expression.ts b/src/slang-nodes/Expression.ts index d632c5bfa..57c04afc8 100644 --- a/src/slang-nodes/Expression.ts +++ b/src/slang-nodes/Expression.ts @@ -29,9 +29,9 @@ import { DecimalNumberExpression } from './DecimalNumberExpression.js'; import { StringExpression } from './StringExpression.js'; import { ElementaryType } from './ElementaryType.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class Expression implements SlangNode { readonly kind = NonterminalKind.Expression; diff --git a/src/slang-nodes/ExpressionStatement.ts b/src/slang-nodes/ExpressionStatement.ts index 50aaa5e01..cf7911dd8 100644 --- a/src/slang-nodes/ExpressionStatement.ts +++ b/src/slang-nodes/ExpressionStatement.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class ExpressionStatement implements SlangNode { readonly kind = NonterminalKind.ExpressionStatement; diff --git a/src/slang-nodes/FallbackFunctionAttribute.ts b/src/slang-nodes/FallbackFunctionAttribute.ts index 3e62dcaa2..cadb5faae 100644 --- a/src/slang-nodes/FallbackFunctionAttribute.ts +++ b/src/slang-nodes/FallbackFunctionAttribute.ts @@ -4,9 +4,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ModifierInvocation } from './ModifierInvocation.js'; import { OverrideSpecifier } from './OverrideSpecifier.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class FallbackFunctionAttribute implements SlangNode { readonly kind = NonterminalKind.FallbackFunctionAttribute; diff --git a/src/slang-nodes/FallbackFunctionAttributes.ts b/src/slang-nodes/FallbackFunctionAttributes.ts index 148529fca..f0cf852d5 100644 --- a/src/slang-nodes/FallbackFunctionAttributes.ts +++ b/src/slang-nodes/FallbackFunctionAttributes.ts @@ -4,9 +4,9 @@ import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes. import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { FallbackFunctionAttribute } from './FallbackFunctionAttribute.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { line } = doc.builders; diff --git a/src/slang-nodes/FallbackFunctionDefinition.ts b/src/slang-nodes/FallbackFunctionDefinition.ts index 2624c3926..99ca112e9 100644 --- a/src/slang-nodes/FallbackFunctionDefinition.ts +++ b/src/slang-nodes/FallbackFunctionDefinition.ts @@ -6,9 +6,9 @@ import { FallbackFunctionAttributes } from './FallbackFunctionAttributes.js'; import { ReturnsDeclaration } from './ReturnsDeclaration.js'; import { FunctionBody } from './FunctionBody.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class FallbackFunctionDefinition implements SlangNode { readonly kind = NonterminalKind.FallbackFunctionDefinition; diff --git a/src/slang-nodes/ForStatement.ts b/src/slang-nodes/ForStatement.ts index ff3e32483..c1a2709e8 100644 --- a/src/slang-nodes/ForStatement.ts +++ b/src/slang-nodes/ForStatement.ts @@ -7,9 +7,9 @@ import { ForStatementCondition } from './ForStatementCondition.js'; import { Expression } from './Expression.js'; import { Statement } from './Statement.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { group, indent, line } = doc.builders; diff --git a/src/slang-nodes/ForStatementCondition.ts b/src/slang-nodes/ForStatementCondition.ts index 0b31ff47e..768e685f9 100644 --- a/src/slang-nodes/ForStatementCondition.ts +++ b/src/slang-nodes/ForStatementCondition.ts @@ -3,9 +3,9 @@ import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ExpressionStatement } from './ExpressionStatement.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class ForStatementCondition implements SlangNode { readonly kind = NonterminalKind.ForStatementCondition; diff --git a/src/slang-nodes/ForStatementInitialization.ts b/src/slang-nodes/ForStatementInitialization.ts index 76f7e72e3..4e160325b 100644 --- a/src/slang-nodes/ForStatementInitialization.ts +++ b/src/slang-nodes/ForStatementInitialization.ts @@ -5,9 +5,9 @@ import { ExpressionStatement } from './ExpressionStatement.js'; import { VariableDeclarationStatement } from './VariableDeclarationStatement.js'; import { TupleDeconstructionStatement } from './TupleDeconstructionStatement.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class ForStatementInitialization implements SlangNode { readonly kind = NonterminalKind.ForStatementInitialization; diff --git a/src/slang-nodes/FunctionAttribute.ts b/src/slang-nodes/FunctionAttribute.ts index 879e8f5cd..83d6559dc 100644 --- a/src/slang-nodes/FunctionAttribute.ts +++ b/src/slang-nodes/FunctionAttribute.ts @@ -4,9 +4,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ModifierInvocation } from './ModifierInvocation.js'; import { OverrideSpecifier } from './OverrideSpecifier.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class FunctionAttribute implements SlangNode { readonly kind = NonterminalKind.FunctionAttribute; diff --git a/src/slang-nodes/FunctionAttributes.ts b/src/slang-nodes/FunctionAttributes.ts index 1365dd1a6..0b7572f45 100644 --- a/src/slang-nodes/FunctionAttributes.ts +++ b/src/slang-nodes/FunctionAttributes.ts @@ -4,9 +4,9 @@ import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes. import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { FunctionAttribute } from './FunctionAttribute.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { line } = doc.builders; diff --git a/src/slang-nodes/FunctionBody.ts b/src/slang-nodes/FunctionBody.ts index 5f0cf86f6..1f0f2f8fe 100644 --- a/src/slang-nodes/FunctionBody.ts +++ b/src/slang-nodes/FunctionBody.ts @@ -3,9 +3,9 @@ import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Block } from './Block.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class FunctionBody implements SlangNode { readonly kind = NonterminalKind.FunctionBody; diff --git a/src/slang-nodes/FunctionCallExpression.ts b/src/slang-nodes/FunctionCallExpression.ts index b87abf617..67fd58916 100644 --- a/src/slang-nodes/FunctionCallExpression.ts +++ b/src/slang-nodes/FunctionCallExpression.ts @@ -5,9 +5,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { group, indentIfBreak, label } = doc.builders; diff --git a/src/slang-nodes/FunctionDefinition.ts b/src/slang-nodes/FunctionDefinition.ts index 9770fdb6d..b240b5080 100644 --- a/src/slang-nodes/FunctionDefinition.ts +++ b/src/slang-nodes/FunctionDefinition.ts @@ -9,9 +9,9 @@ import { FunctionAttributes } from './FunctionAttributes.js'; import { ReturnsDeclaration } from './ReturnsDeclaration.js'; import { FunctionBody } from './FunctionBody.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class FunctionDefinition implements SlangNode { readonly kind = NonterminalKind.FunctionDefinition; diff --git a/src/slang-nodes/FunctionName.ts b/src/slang-nodes/FunctionName.ts index e7b82da40..a7d0a1937 100644 --- a/src/slang-nodes/FunctionName.ts +++ b/src/slang-nodes/FunctionName.ts @@ -1,9 +1,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata } from '../slang-utils/metadata.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { SlangNode } from '../types'; export class FunctionName implements SlangNode { readonly kind = NonterminalKind.FunctionName; diff --git a/src/slang-nodes/FunctionType.ts b/src/slang-nodes/FunctionType.ts index ac9b04813..4b465722f 100644 --- a/src/slang-nodes/FunctionType.ts +++ b/src/slang-nodes/FunctionType.ts @@ -5,9 +5,9 @@ import { ParametersDeclaration } from './ParametersDeclaration.js'; import { FunctionTypeAttributes } from './FunctionTypeAttributes.js'; import { ReturnsDeclaration } from './ReturnsDeclaration.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class FunctionType implements SlangNode { readonly kind = NonterminalKind.FunctionType; diff --git a/src/slang-nodes/FunctionTypeAttribute.ts b/src/slang-nodes/FunctionTypeAttribute.ts index 0b57ce7dc..ccd5eaee0 100644 --- a/src/slang-nodes/FunctionTypeAttribute.ts +++ b/src/slang-nodes/FunctionTypeAttribute.ts @@ -1,9 +1,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata } from '../slang-utils/metadata.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { SlangNode } from '../types'; export class FunctionTypeAttribute implements SlangNode { readonly kind = NonterminalKind.FunctionTypeAttribute; diff --git a/src/slang-nodes/FunctionTypeAttributes.ts b/src/slang-nodes/FunctionTypeAttributes.ts index ca46df461..4647f2e42 100644 --- a/src/slang-nodes/FunctionTypeAttributes.ts +++ b/src/slang-nodes/FunctionTypeAttributes.ts @@ -4,9 +4,9 @@ import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes. import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { FunctionTypeAttribute } from './FunctionTypeAttribute.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { line } = doc.builders; diff --git a/src/slang-nodes/HexNumberExpression.ts b/src/slang-nodes/HexNumberExpression.ts index 870fa5c99..62e1d0c12 100644 --- a/src/slang-nodes/HexNumberExpression.ts +++ b/src/slang-nodes/HexNumberExpression.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { NumberUnit } from './NumberUnit.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class HexNumberExpression implements SlangNode { readonly kind = NonterminalKind.HexNumberExpression; diff --git a/src/slang-nodes/HexStringLiteral.ts b/src/slang-nodes/HexStringLiteral.ts index 460955253..29001ea32 100644 --- a/src/slang-nodes/HexStringLiteral.ts +++ b/src/slang-nodes/HexStringLiteral.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printString } from '../slang-printers/print-string.js'; import { getNodeMetadata } from '../slang-utils/metadata.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class HexStringLiteral implements SlangNode { readonly kind = NonterminalKind.HexStringLiteral; diff --git a/src/slang-nodes/HexStringLiterals.ts b/src/slang-nodes/HexStringLiterals.ts index af7949ca5..6851d9e95 100644 --- a/src/slang-nodes/HexStringLiterals.ts +++ b/src/slang-nodes/HexStringLiterals.ts @@ -3,9 +3,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { HexStringLiteral } from './HexStringLiteral.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { join, hardline } = doc.builders; diff --git a/src/slang-nodes/IdentifierPath.ts b/src/slang-nodes/IdentifierPath.ts index 45cc18544..d7198169e 100644 --- a/src/slang-nodes/IdentifierPath.ts +++ b/src/slang-nodes/IdentifierPath.ts @@ -1,9 +1,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata } from '../slang-utils/metadata.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { SlangNode } from '../types'; export class IdentifierPath implements SlangNode { readonly kind = NonterminalKind.IdentifierPath; diff --git a/src/slang-nodes/IfStatement.ts b/src/slang-nodes/IfStatement.ts index 7353cc05c..62ebb8969 100644 --- a/src/slang-nodes/IfStatement.ts +++ b/src/slang-nodes/IfStatement.ts @@ -6,9 +6,9 @@ import { Expression } from './Expression.js'; import { Statement } from './Statement.js'; import { ElseBranch } from './ElseBranch.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { group, hardline, indent, line } = doc.builders; diff --git a/src/slang-nodes/ImportAlias.ts b/src/slang-nodes/ImportAlias.ts index 43ae375af..2f951c408 100644 --- a/src/slang-nodes/ImportAlias.ts +++ b/src/slang-nodes/ImportAlias.ts @@ -1,9 +1,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata } from '../slang-utils/metadata.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { SlangNode } from '../types'; export class ImportAlias implements SlangNode { readonly kind = NonterminalKind.ImportAlias; diff --git a/src/slang-nodes/ImportClause.ts b/src/slang-nodes/ImportClause.ts index 38b60a538..7a17f24db 100644 --- a/src/slang-nodes/ImportClause.ts +++ b/src/slang-nodes/ImportClause.ts @@ -4,9 +4,9 @@ import { PathImport } from './PathImport.js'; import { NamedImport } from './NamedImport.js'; import { ImportDeconstruction } from './ImportDeconstruction.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class ImportClause implements SlangNode { readonly kind = NonterminalKind.ImportClause; diff --git a/src/slang-nodes/ImportDeconstruction.ts b/src/slang-nodes/ImportDeconstruction.ts index eb747547a..d085761bc 100644 --- a/src/slang-nodes/ImportDeconstruction.ts +++ b/src/slang-nodes/ImportDeconstruction.ts @@ -3,9 +3,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ImportDeconstructionSymbols } from './ImportDeconstructionSymbols.js'; import { StringLiteral } from './StringLiteral.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class ImportDeconstruction implements SlangNode { readonly kind = NonterminalKind.ImportDeconstruction; diff --git a/src/slang-nodes/ImportDeconstructionSymbol.ts b/src/slang-nodes/ImportDeconstructionSymbol.ts index dfb33aebf..81b98667f 100644 --- a/src/slang-nodes/ImportDeconstructionSymbol.ts +++ b/src/slang-nodes/ImportDeconstructionSymbol.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ImportAlias } from './ImportAlias.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class ImportDeconstructionSymbol implements SlangNode { readonly kind = NonterminalKind.ImportDeconstructionSymbol; diff --git a/src/slang-nodes/ImportDeconstructionSymbols.ts b/src/slang-nodes/ImportDeconstructionSymbols.ts index 1f48a8f25..e2b4bfc5a 100644 --- a/src/slang-nodes/ImportDeconstructionSymbols.ts +++ b/src/slang-nodes/ImportDeconstructionSymbols.ts @@ -6,9 +6,9 @@ import { printSeparatedList } from '../slang-printers/print-separated-list.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ImportDeconstructionSymbol } from './ImportDeconstructionSymbol.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { line, softline } = doc.builders; diff --git a/src/slang-nodes/ImportDirective.ts b/src/slang-nodes/ImportDirective.ts index e79957b00..163b120db 100644 --- a/src/slang-nodes/ImportDirective.ts +++ b/src/slang-nodes/ImportDirective.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ImportClause } from './ImportClause.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class ImportDirective implements SlangNode { readonly kind = NonterminalKind.ImportDirective; diff --git a/src/slang-nodes/IndexAccessEnd.ts b/src/slang-nodes/IndexAccessEnd.ts index 7200249ca..55c0d7e50 100644 --- a/src/slang-nodes/IndexAccessEnd.ts +++ b/src/slang-nodes/IndexAccessEnd.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class IndexAccessEnd implements SlangNode { readonly kind = NonterminalKind.IndexAccessEnd; diff --git a/src/slang-nodes/IndexAccessExpression.ts b/src/slang-nodes/IndexAccessExpression.ts index ba6c08724..be07dca0f 100644 --- a/src/slang-nodes/IndexAccessExpression.ts +++ b/src/slang-nodes/IndexAccessExpression.ts @@ -5,9 +5,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import { IndexAccessEnd } from './IndexAccessEnd.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { group, indent, indentIfBreak, label, softline } = doc.builders; diff --git a/src/slang-nodes/InheritanceSpecifier.ts b/src/slang-nodes/InheritanceSpecifier.ts index 9cc627d74..8501dd393 100644 --- a/src/slang-nodes/InheritanceSpecifier.ts +++ b/src/slang-nodes/InheritanceSpecifier.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { InheritanceTypes } from './InheritanceTypes.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class InheritanceSpecifier implements SlangNode { readonly kind = NonterminalKind.InheritanceSpecifier; diff --git a/src/slang-nodes/InheritanceType.ts b/src/slang-nodes/InheritanceType.ts index 2252807f6..59b554c9a 100644 --- a/src/slang-nodes/InheritanceType.ts +++ b/src/slang-nodes/InheritanceType.ts @@ -3,9 +3,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { IdentifierPath } from './IdentifierPath.js'; import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class InheritanceType implements SlangNode { readonly kind = NonterminalKind.InheritanceType; diff --git a/src/slang-nodes/InheritanceTypes.ts b/src/slang-nodes/InheritanceTypes.ts index ad22e8cc0..3b33179f4 100644 --- a/src/slang-nodes/InheritanceTypes.ts +++ b/src/slang-nodes/InheritanceTypes.ts @@ -4,9 +4,9 @@ import { printSeparatedList } from '../slang-printers/print-separated-list.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { InheritanceType } from './InheritanceType.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { line } = doc.builders; diff --git a/src/slang-nodes/InterfaceDefinition.ts b/src/slang-nodes/InterfaceDefinition.ts index d46d53bf4..2cb78fbb5 100644 --- a/src/slang-nodes/InterfaceDefinition.ts +++ b/src/slang-nodes/InterfaceDefinition.ts @@ -4,9 +4,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { InheritanceSpecifier } from './InheritanceSpecifier.js'; import { InterfaceMembers } from './InterfaceMembers.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { group, line } = doc.builders; diff --git a/src/slang-nodes/InterfaceMembers.ts b/src/slang-nodes/InterfaceMembers.ts index 8515591b2..3445adbdf 100644 --- a/src/slang-nodes/InterfaceMembers.ts +++ b/src/slang-nodes/InterfaceMembers.ts @@ -5,9 +5,9 @@ import { printPreservingEmptyLines } from '../slang-printers/print-preserving-em import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ContractMember } from './ContractMember.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { hardline } = doc.builders; diff --git a/src/slang-nodes/LibraryDefinition.ts b/src/slang-nodes/LibraryDefinition.ts index 7efd0c681..2fd0ec594 100644 --- a/src/slang-nodes/LibraryDefinition.ts +++ b/src/slang-nodes/LibraryDefinition.ts @@ -3,9 +3,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { LibraryMembers } from './LibraryMembers.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { group, line } = doc.builders; diff --git a/src/slang-nodes/LibraryMembers.ts b/src/slang-nodes/LibraryMembers.ts index 4e46b4d4a..59d1ec6a7 100644 --- a/src/slang-nodes/LibraryMembers.ts +++ b/src/slang-nodes/LibraryMembers.ts @@ -5,9 +5,9 @@ import { printPreservingEmptyLines } from '../slang-printers/print-preserving-em import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ContractMember } from './ContractMember.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { hardline } = doc.builders; diff --git a/src/slang-nodes/MappingKey.ts b/src/slang-nodes/MappingKey.ts index d5b658907..f21e28620 100644 --- a/src/slang-nodes/MappingKey.ts +++ b/src/slang-nodes/MappingKey.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { MappingKeyType } from './MappingKeyType.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class MappingKey implements SlangNode { readonly kind = NonterminalKind.MappingKey; diff --git a/src/slang-nodes/MappingKeyType.ts b/src/slang-nodes/MappingKeyType.ts index ac0b1a7a7..ac68207b5 100644 --- a/src/slang-nodes/MappingKeyType.ts +++ b/src/slang-nodes/MappingKeyType.ts @@ -3,9 +3,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ElementaryType } from './ElementaryType.js'; import { IdentifierPath } from './IdentifierPath.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class MappingKeyType implements SlangNode { readonly kind = NonterminalKind.MappingKeyType; diff --git a/src/slang-nodes/MappingType.ts b/src/slang-nodes/MappingType.ts index 7e453880d..3c11bbb77 100644 --- a/src/slang-nodes/MappingType.ts +++ b/src/slang-nodes/MappingType.ts @@ -3,9 +3,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { MappingKey } from './MappingKey.js'; import { MappingValue } from './MappingValue.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class MappingType implements SlangNode { readonly kind = NonterminalKind.MappingType; diff --git a/src/slang-nodes/MappingValue.ts b/src/slang-nodes/MappingValue.ts index bae55d364..63c105484 100644 --- a/src/slang-nodes/MappingValue.ts +++ b/src/slang-nodes/MappingValue.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TypeName } from './TypeName.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class MappingValue implements SlangNode { readonly kind = NonterminalKind.MappingValue; diff --git a/src/slang-nodes/MemberAccess.ts b/src/slang-nodes/MemberAccess.ts index 4023b6ff1..c89f8aa6a 100644 --- a/src/slang-nodes/MemberAccess.ts +++ b/src/slang-nodes/MemberAccess.ts @@ -1,9 +1,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata } from '../slang-utils/metadata.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { SlangNode } from '../types'; export class MemberAccess implements SlangNode { readonly kind = NonterminalKind.MemberAccess; diff --git a/src/slang-nodes/MemberAccessExpression.ts b/src/slang-nodes/MemberAccessExpression.ts index 3e0ce37aa..067ca6a71 100644 --- a/src/slang-nodes/MemberAccessExpression.ts +++ b/src/slang-nodes/MemberAccessExpression.ts @@ -6,9 +6,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import { MemberAccess } from './MemberAccess.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { group, indent, label, softline } = doc.builders; diff --git a/src/slang-nodes/ModifierAttribute.ts b/src/slang-nodes/ModifierAttribute.ts index a2dbf15b3..9953d1920 100644 --- a/src/slang-nodes/ModifierAttribute.ts +++ b/src/slang-nodes/ModifierAttribute.ts @@ -3,9 +3,9 @@ import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { OverrideSpecifier } from './OverrideSpecifier.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class ModifierAttribute implements SlangNode { readonly kind = NonterminalKind.ModifierAttribute; diff --git a/src/slang-nodes/ModifierAttributes.ts b/src/slang-nodes/ModifierAttributes.ts index 99af50f95..2d440c5b7 100644 --- a/src/slang-nodes/ModifierAttributes.ts +++ b/src/slang-nodes/ModifierAttributes.ts @@ -4,9 +4,9 @@ import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes. import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ModifierAttribute } from './ModifierAttribute.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { line } = doc.builders; diff --git a/src/slang-nodes/ModifierDefinition.ts b/src/slang-nodes/ModifierDefinition.ts index d6019136b..6b5d414ee 100644 --- a/src/slang-nodes/ModifierDefinition.ts +++ b/src/slang-nodes/ModifierDefinition.ts @@ -6,9 +6,9 @@ import { Parameters } from './Parameters.js'; import { ModifierAttributes } from './ModifierAttributes.js'; import { FunctionBody } from './FunctionBody.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const objectConfig = { writable: true, diff --git a/src/slang-nodes/ModifierInvocation.ts b/src/slang-nodes/ModifierInvocation.ts index 0ab5905ed..b16ce1d04 100644 --- a/src/slang-nodes/ModifierInvocation.ts +++ b/src/slang-nodes/ModifierInvocation.ts @@ -4,9 +4,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { IdentifierPath } from './IdentifierPath.js'; import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class ModifierInvocation implements SlangNode { readonly kind = NonterminalKind.ModifierInvocation; diff --git a/src/slang-nodes/MultiplicativeExpression.ts b/src/slang-nodes/MultiplicativeExpression.ts index 73349770d..4db8d9a96 100644 --- a/src/slang-nodes/MultiplicativeExpression.ts +++ b/src/slang-nodes/MultiplicativeExpression.ts @@ -4,9 +4,9 @@ import { createHugFunction } from '../slang-utils/create-hug-function.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const multiplicationTryToHug = createHugFunction(['/', '%']); const divisionTryToHug = createHugFunction(['*', '%']); diff --git a/src/slang-nodes/NamedArgument.ts b/src/slang-nodes/NamedArgument.ts index 44157d4c3..f80ec4fc5 100644 --- a/src/slang-nodes/NamedArgument.ts +++ b/src/slang-nodes/NamedArgument.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class NamedArgument implements SlangNode { readonly kind = NonterminalKind.NamedArgument; diff --git a/src/slang-nodes/NamedArgumentGroup.ts b/src/slang-nodes/NamedArgumentGroup.ts index 1d16dc316..1dd0019f9 100644 --- a/src/slang-nodes/NamedArgumentGroup.ts +++ b/src/slang-nodes/NamedArgumentGroup.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { NamedArguments } from './NamedArguments.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class NamedArgumentGroup implements SlangNode { readonly kind = NonterminalKind.NamedArgumentGroup; diff --git a/src/slang-nodes/NamedArguments.ts b/src/slang-nodes/NamedArguments.ts index 9a374d425..369584585 100644 --- a/src/slang-nodes/NamedArguments.ts +++ b/src/slang-nodes/NamedArguments.ts @@ -4,9 +4,9 @@ import { printSeparatedList } from '../slang-printers/print-separated-list.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { NamedArgument } from './NamedArgument.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { line, softline } = doc.builders; diff --git a/src/slang-nodes/NamedArgumentsDeclaration.ts b/src/slang-nodes/NamedArgumentsDeclaration.ts index 32e8e13c8..50c07d5f3 100644 --- a/src/slang-nodes/NamedArgumentsDeclaration.ts +++ b/src/slang-nodes/NamedArgumentsDeclaration.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { NamedArgumentGroup } from './NamedArgumentGroup.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class NamedArgumentsDeclaration implements SlangNode { readonly kind = NonterminalKind.NamedArgumentsDeclaration; diff --git a/src/slang-nodes/NamedImport.ts b/src/slang-nodes/NamedImport.ts index d5fd0754b..ff44b0c95 100644 --- a/src/slang-nodes/NamedImport.ts +++ b/src/slang-nodes/NamedImport.ts @@ -3,9 +3,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ImportAlias } from './ImportAlias.js'; import { StringLiteral } from './StringLiteral.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class NamedImport implements SlangNode { readonly kind = NonterminalKind.NamedImport; diff --git a/src/slang-nodes/NewExpression.ts b/src/slang-nodes/NewExpression.ts index d8e928b2f..24c672ca6 100644 --- a/src/slang-nodes/NewExpression.ts +++ b/src/slang-nodes/NewExpression.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TypeName } from './TypeName.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class NewExpression implements SlangNode { readonly kind = NonterminalKind.NewExpression; diff --git a/src/slang-nodes/NumberUnit.ts b/src/slang-nodes/NumberUnit.ts index 25ce93878..c007871c0 100644 --- a/src/slang-nodes/NumberUnit.ts +++ b/src/slang-nodes/NumberUnit.ts @@ -1,9 +1,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata } from '../slang-utils/metadata.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { SlangNode } from '../types'; export class NumberUnit implements SlangNode { readonly kind = NonterminalKind.NumberUnit; diff --git a/src/slang-nodes/OrExpression.ts b/src/slang-nodes/OrExpression.ts index 79ae17f17..0923d979f 100644 --- a/src/slang-nodes/OrExpression.ts +++ b/src/slang-nodes/OrExpression.ts @@ -4,9 +4,9 @@ import { createHugFunction } from '../slang-utils/create-hug-function.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const tryToHug = createHugFunction(['&&']); diff --git a/src/slang-nodes/OverridePaths.ts b/src/slang-nodes/OverridePaths.ts index a195017dc..0988dbc76 100644 --- a/src/slang-nodes/OverridePaths.ts +++ b/src/slang-nodes/OverridePaths.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { IdentifierPath } from './IdentifierPath.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { /*AstPath,*/ Doc /*, ParserOptions*/ } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { SlangNode } from '../types'; export class OverridePaths implements SlangNode { readonly kind = NonterminalKind.OverridePaths; diff --git a/src/slang-nodes/OverridePathsDeclaration.ts b/src/slang-nodes/OverridePathsDeclaration.ts index cfbf150a0..8834024ad 100644 --- a/src/slang-nodes/OverridePathsDeclaration.ts +++ b/src/slang-nodes/OverridePathsDeclaration.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { OverridePaths } from './OverridePaths.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { /*AstPath,*/ Doc /*, ParserOptions*/ } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { SlangNode } from '../types'; export class OverridePathsDeclaration implements SlangNode { readonly kind = NonterminalKind.OverridePathsDeclaration; diff --git a/src/slang-nodes/OverrideSpecifier.ts b/src/slang-nodes/OverrideSpecifier.ts index 141faab5e..1bcf05602 100644 --- a/src/slang-nodes/OverrideSpecifier.ts +++ b/src/slang-nodes/OverrideSpecifier.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { OverridePathsDeclaration } from './OverridePathsDeclaration.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class OverrideSpecifier implements SlangNode { readonly kind = NonterminalKind.OverrideSpecifier; diff --git a/src/slang-nodes/Parameter.ts b/src/slang-nodes/Parameter.ts index fd650175f..8e9cf7ab7 100644 --- a/src/slang-nodes/Parameter.ts +++ b/src/slang-nodes/Parameter.ts @@ -4,9 +4,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TypeName } from './TypeName.js'; import { StorageLocation } from './StorageLocation.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { group } = doc.builders; diff --git a/src/slang-nodes/Parameters.ts b/src/slang-nodes/Parameters.ts index a1eab4ca2..6ee76591c 100644 --- a/src/slang-nodes/Parameters.ts +++ b/src/slang-nodes/Parameters.ts @@ -5,9 +5,9 @@ import { printComments } from '../slang-printers/print-comments.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Parameter } from './Parameter.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class Parameters implements SlangNode { readonly kind = NonterminalKind.Parameters; diff --git a/src/slang-nodes/ParametersDeclaration.ts b/src/slang-nodes/ParametersDeclaration.ts index 66463670e..fed30a428 100644 --- a/src/slang-nodes/ParametersDeclaration.ts +++ b/src/slang-nodes/ParametersDeclaration.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Parameters } from './Parameters.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class ParametersDeclaration implements SlangNode { readonly kind = NonterminalKind.ParametersDeclaration; diff --git a/src/slang-nodes/PathImport.ts b/src/slang-nodes/PathImport.ts index 2b61a8c1b..cd092c707 100644 --- a/src/slang-nodes/PathImport.ts +++ b/src/slang-nodes/PathImport.ts @@ -3,9 +3,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { StringLiteral } from './StringLiteral.js'; import { ImportAlias } from './ImportAlias.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class PathImport implements SlangNode { readonly kind = NonterminalKind.PathImport; diff --git a/src/slang-nodes/PositionalArguments.ts b/src/slang-nodes/PositionalArguments.ts index a62e0b31e..219e47e9b 100644 --- a/src/slang-nodes/PositionalArguments.ts +++ b/src/slang-nodes/PositionalArguments.ts @@ -3,9 +3,9 @@ import { printSeparatedList } from '../slang-printers/print-separated-list.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class PositionalArguments implements SlangNode { readonly kind = NonterminalKind.PositionalArguments; diff --git a/src/slang-nodes/PositionalArgumentsDeclaration.ts b/src/slang-nodes/PositionalArgumentsDeclaration.ts index 54e8c83e2..0d17122ad 100644 --- a/src/slang-nodes/PositionalArgumentsDeclaration.ts +++ b/src/slang-nodes/PositionalArgumentsDeclaration.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { PositionalArguments } from './PositionalArguments.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class PositionalArgumentsDeclaration implements SlangNode { readonly kind = NonterminalKind.PositionalArgumentsDeclaration; diff --git a/src/slang-nodes/PostfixExpression.ts b/src/slang-nodes/PostfixExpression.ts index 781ea5417..94eb016f0 100644 --- a/src/slang-nodes/PostfixExpression.ts +++ b/src/slang-nodes/PostfixExpression.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class PostfixExpression implements SlangNode { readonly kind = NonterminalKind.PostfixExpression; diff --git a/src/slang-nodes/Pragma.ts b/src/slang-nodes/Pragma.ts index 1905338e8..55c7eb19e 100644 --- a/src/slang-nodes/Pragma.ts +++ b/src/slang-nodes/Pragma.ts @@ -4,9 +4,9 @@ import { ABICoderPragma } from './ABICoderPragma.js'; import { ExperimentalPragma } from './ExperimentalPragma.js'; import { VersionPragma } from './VersionPragma.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class Pragma implements SlangNode { readonly kind = NonterminalKind.Pragma; diff --git a/src/slang-nodes/PragmaDirective.ts b/src/slang-nodes/PragmaDirective.ts index aa9a9478f..7a5c13806 100644 --- a/src/slang-nodes/PragmaDirective.ts +++ b/src/slang-nodes/PragmaDirective.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Pragma } from './Pragma.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class PragmaDirective implements SlangNode { readonly kind = NonterminalKind.PragmaDirective; diff --git a/src/slang-nodes/PrefixExpression.ts b/src/slang-nodes/PrefixExpression.ts index 375423ffd..2c82d54ea 100644 --- a/src/slang-nodes/PrefixExpression.ts +++ b/src/slang-nodes/PrefixExpression.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class PrefixExpression implements SlangNode { readonly kind = NonterminalKind.PrefixExpression; diff --git a/src/slang-nodes/ReceiveFunctionAttribute.ts b/src/slang-nodes/ReceiveFunctionAttribute.ts index 59befcb14..8b86eaa2e 100644 --- a/src/slang-nodes/ReceiveFunctionAttribute.ts +++ b/src/slang-nodes/ReceiveFunctionAttribute.ts @@ -4,9 +4,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ModifierInvocation } from './ModifierInvocation.js'; import { OverrideSpecifier } from './OverrideSpecifier.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class ReceiveFunctionAttribute implements SlangNode { readonly kind = NonterminalKind.ReceiveFunctionAttribute; diff --git a/src/slang-nodes/ReceiveFunctionAttributes.ts b/src/slang-nodes/ReceiveFunctionAttributes.ts index bfcea0429..f1a011e6e 100644 --- a/src/slang-nodes/ReceiveFunctionAttributes.ts +++ b/src/slang-nodes/ReceiveFunctionAttributes.ts @@ -4,9 +4,9 @@ import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes. import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ReceiveFunctionAttribute } from './ReceiveFunctionAttribute.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { line } = doc.builders; diff --git a/src/slang-nodes/ReceiveFunctionDefinition.ts b/src/slang-nodes/ReceiveFunctionDefinition.ts index d6fca1bfa..20f5da776 100644 --- a/src/slang-nodes/ReceiveFunctionDefinition.ts +++ b/src/slang-nodes/ReceiveFunctionDefinition.ts @@ -5,9 +5,9 @@ import { ParametersDeclaration } from './ParametersDeclaration.js'; import { ReceiveFunctionAttributes } from './ReceiveFunctionAttributes.js'; import { FunctionBody } from './FunctionBody.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class ReceiveFunctionDefinition implements SlangNode { readonly kind = NonterminalKind.ReceiveFunctionDefinition; diff --git a/src/slang-nodes/ReturnStatement.ts b/src/slang-nodes/ReturnStatement.ts index 2789c1127..b96f395fb 100644 --- a/src/slang-nodes/ReturnStatement.ts +++ b/src/slang-nodes/ReturnStatement.ts @@ -3,9 +3,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { group, indent, line } = doc.builders; diff --git a/src/slang-nodes/ReturnsDeclaration.ts b/src/slang-nodes/ReturnsDeclaration.ts index 6f5321cc9..053ea2f81 100644 --- a/src/slang-nodes/ReturnsDeclaration.ts +++ b/src/slang-nodes/ReturnsDeclaration.ts @@ -3,9 +3,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ParametersDeclaration } from './ParametersDeclaration.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { group } = doc.builders; diff --git a/src/slang-nodes/RevertStatement.ts b/src/slang-nodes/RevertStatement.ts index e80ac1726..fdb15755a 100644 --- a/src/slang-nodes/RevertStatement.ts +++ b/src/slang-nodes/RevertStatement.ts @@ -3,9 +3,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { IdentifierPath } from './IdentifierPath.js'; import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class RevertStatement implements SlangNode { readonly kind = NonterminalKind.RevertStatement; diff --git a/src/slang-nodes/ShiftExpression.ts b/src/slang-nodes/ShiftExpression.ts index 2c076b639..1515ba639 100644 --- a/src/slang-nodes/ShiftExpression.ts +++ b/src/slang-nodes/ShiftExpression.ts @@ -4,9 +4,9 @@ import { createHugFunction } from '../slang-utils/create-hug-function.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const tryToHugLeftOperand = createHugFunction([ '+', diff --git a/src/slang-nodes/SourceUnit.ts b/src/slang-nodes/SourceUnit.ts index db0e66a67..bac4eb7b6 100644 --- a/src/slang-nodes/SourceUnit.ts +++ b/src/slang-nodes/SourceUnit.ts @@ -3,9 +3,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { SourceUnitMembers } from './SourceUnitMembers.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { line } = doc.builders; diff --git a/src/slang-nodes/SourceUnitMember.ts b/src/slang-nodes/SourceUnitMember.ts index 8b2054c60..8b42767cf 100644 --- a/src/slang-nodes/SourceUnitMember.ts +++ b/src/slang-nodes/SourceUnitMember.ts @@ -14,9 +14,9 @@ import { UserDefinedValueTypeDefinition } from './UserDefinedValueTypeDefinition import { UsingDirective } from './UsingDirective.js'; import { EventDefinition } from './EventDefinition.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class SourceUnitMember implements SlangNode { readonly kind = NonterminalKind.SourceUnitMember; diff --git a/src/slang-nodes/SourceUnitMembers.ts b/src/slang-nodes/SourceUnitMembers.ts index 750ac58b2..0870af416 100644 --- a/src/slang-nodes/SourceUnitMembers.ts +++ b/src/slang-nodes/SourceUnitMembers.ts @@ -3,9 +3,9 @@ import { printPreservingEmptyLines } from '../slang-printers/print-preserving-em import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { SourceUnitMember } from './SourceUnitMember.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class SourceUnitMembers implements SlangNode { readonly kind = NonterminalKind.SourceUnitMembers; diff --git a/src/slang-nodes/StateVariableAttribute.ts b/src/slang-nodes/StateVariableAttribute.ts index 1c4a4e477..7558e294c 100644 --- a/src/slang-nodes/StateVariableAttribute.ts +++ b/src/slang-nodes/StateVariableAttribute.ts @@ -3,9 +3,9 @@ import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { OverrideSpecifier } from './OverrideSpecifier.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class StateVariableAttribute implements SlangNode { readonly kind = NonterminalKind.StateVariableAttribute; diff --git a/src/slang-nodes/StateVariableAttributes.ts b/src/slang-nodes/StateVariableAttributes.ts index 4544b5bc0..a8fde4ad6 100644 --- a/src/slang-nodes/StateVariableAttributes.ts +++ b/src/slang-nodes/StateVariableAttributes.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { StateVariableAttribute } from './StateVariableAttribute.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class StateVariableAttributes implements SlangNode { readonly kind = NonterminalKind.StateVariableAttributes; diff --git a/src/slang-nodes/StateVariableDefinition.ts b/src/slang-nodes/StateVariableDefinition.ts index 47a2d369b..b5e06c308 100644 --- a/src/slang-nodes/StateVariableDefinition.ts +++ b/src/slang-nodes/StateVariableDefinition.ts @@ -4,9 +4,9 @@ import { TypeName } from './TypeName.js'; import { StateVariableAttributes } from './StateVariableAttributes.js'; import { StateVariableDefinitionValue } from './StateVariableDefinitionValue.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class StateVariableDefinition implements SlangNode { readonly kind = NonterminalKind.StateVariableDefinition; diff --git a/src/slang-nodes/StateVariableDefinitionValue.ts b/src/slang-nodes/StateVariableDefinitionValue.ts index c3dbf17b3..280b7a754 100644 --- a/src/slang-nodes/StateVariableDefinitionValue.ts +++ b/src/slang-nodes/StateVariableDefinitionValue.ts @@ -3,9 +3,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { group, indent, line } = doc.builders; diff --git a/src/slang-nodes/Statement.ts b/src/slang-nodes/Statement.ts index 32716722b..13aeaec30 100644 --- a/src/slang-nodes/Statement.ts +++ b/src/slang-nodes/Statement.ts @@ -18,9 +18,9 @@ import { AssemblyStatement } from './AssemblyStatement.js'; import { Block } from './Block.js'; import { UncheckedBlock } from './UncheckedBlock.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class Statement implements SlangNode { readonly kind = NonterminalKind.Statement; diff --git a/src/slang-nodes/Statements.ts b/src/slang-nodes/Statements.ts index a771f6f27..ac752636d 100644 --- a/src/slang-nodes/Statements.ts +++ b/src/slang-nodes/Statements.ts @@ -6,9 +6,9 @@ import { printPreservingEmptyLines } from '../slang-printers/print-preserving-em import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Statement } from './Statement.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { hardline } = doc.builders; diff --git a/src/slang-nodes/StorageLocation.ts b/src/slang-nodes/StorageLocation.ts index 15c26db74..b7155f961 100644 --- a/src/slang-nodes/StorageLocation.ts +++ b/src/slang-nodes/StorageLocation.ts @@ -1,9 +1,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata } from '../slang-utils/metadata.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { SlangNode } from '../types'; export class StorageLocation implements SlangNode { readonly kind = NonterminalKind.StorageLocation; diff --git a/src/slang-nodes/StringExpression.ts b/src/slang-nodes/StringExpression.ts index 00ed510a8..50778d4e5 100644 --- a/src/slang-nodes/StringExpression.ts +++ b/src/slang-nodes/StringExpression.ts @@ -6,9 +6,9 @@ import { HexStringLiteral } from './HexStringLiteral.js'; import { HexStringLiterals } from './HexStringLiterals.js'; import { UnicodeStringLiterals } from './UnicodeStringLiterals.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class StringExpression implements SlangNode { readonly kind = NonterminalKind.StringExpression; diff --git a/src/slang-nodes/StringLiteral.ts b/src/slang-nodes/StringLiteral.ts index 3df4f32ba..2a5eb0993 100644 --- a/src/slang-nodes/StringLiteral.ts +++ b/src/slang-nodes/StringLiteral.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printString } from '../slang-printers/print-string.js'; import { getNodeMetadata } from '../slang-utils/metadata.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class StringLiteral implements SlangNode { readonly kind = NonterminalKind.StringLiteral; diff --git a/src/slang-nodes/StringLiterals.ts b/src/slang-nodes/StringLiterals.ts index 449b2808d..4a2849fba 100644 --- a/src/slang-nodes/StringLiterals.ts +++ b/src/slang-nodes/StringLiterals.ts @@ -3,9 +3,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { StringLiteral } from './StringLiteral.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { join, hardline } = doc.builders; diff --git a/src/slang-nodes/StructDefinition.ts b/src/slang-nodes/StructDefinition.ts index 64457602d..33ea86380 100644 --- a/src/slang-nodes/StructDefinition.ts +++ b/src/slang-nodes/StructDefinition.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { StructMembers } from './StructMembers.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class StructDefinition implements SlangNode { readonly kind = NonterminalKind.StructDefinition; diff --git a/src/slang-nodes/StructMember.ts b/src/slang-nodes/StructMember.ts index 660108ad3..c562bc0d6 100644 --- a/src/slang-nodes/StructMember.ts +++ b/src/slang-nodes/StructMember.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TypeName } from './TypeName.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class StructMember implements SlangNode { readonly kind = NonterminalKind.StructMember; diff --git a/src/slang-nodes/StructMembers.ts b/src/slang-nodes/StructMembers.ts index b32b8dfe2..43663eaba 100644 --- a/src/slang-nodes/StructMembers.ts +++ b/src/slang-nodes/StructMembers.ts @@ -4,9 +4,9 @@ import { printSeparatedList } from '../slang-printers/print-separated-list.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { StructMember } from './StructMember.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { hardline } = doc.builders; diff --git a/src/slang-nodes/ThrowStatement.ts b/src/slang-nodes/ThrowStatement.ts index 9ee5c94ce..60d4c2d0a 100644 --- a/src/slang-nodes/ThrowStatement.ts +++ b/src/slang-nodes/ThrowStatement.ts @@ -1,9 +1,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata } from '../slang-utils/metadata.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { SlangNode } from '../types'; export class ThrowStatement implements SlangNode { readonly kind = NonterminalKind.ThrowStatement; diff --git a/src/slang-nodes/TryStatement.ts b/src/slang-nodes/TryStatement.ts index 20fd3de98..3925beca8 100644 --- a/src/slang-nodes/TryStatement.ts +++ b/src/slang-nodes/TryStatement.ts @@ -7,9 +7,9 @@ import { ReturnsDeclaration } from './ReturnsDeclaration.js'; import { Block } from './Block.js'; import { CatchClauses } from './CatchClauses.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { line } = doc.builders; diff --git a/src/slang-nodes/TupleDeconstructionElement.ts b/src/slang-nodes/TupleDeconstructionElement.ts index d9dae7b32..59c85e101 100644 --- a/src/slang-nodes/TupleDeconstructionElement.ts +++ b/src/slang-nodes/TupleDeconstructionElement.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TupleMember } from './TupleMember.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class TupleDeconstructionElement implements SlangNode { readonly kind = NonterminalKind.TupleDeconstructionElement; diff --git a/src/slang-nodes/TupleDeconstructionElements.ts b/src/slang-nodes/TupleDeconstructionElements.ts index ac2a0e3af..9466e30e8 100644 --- a/src/slang-nodes/TupleDeconstructionElements.ts +++ b/src/slang-nodes/TupleDeconstructionElements.ts @@ -3,9 +3,9 @@ import { printSeparatedList } from '../slang-printers/print-separated-list.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TupleDeconstructionElement } from './TupleDeconstructionElement.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class TupleDeconstructionElements implements SlangNode { readonly kind = NonterminalKind.TupleDeconstructionElements; diff --git a/src/slang-nodes/TupleDeconstructionStatement.ts b/src/slang-nodes/TupleDeconstructionStatement.ts index 0ce1a1a77..f3df87140 100644 --- a/src/slang-nodes/TupleDeconstructionStatement.ts +++ b/src/slang-nodes/TupleDeconstructionStatement.ts @@ -4,9 +4,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TupleDeconstructionElements } from './TupleDeconstructionElements.js'; import { Expression } from './Expression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { group, indent, line } = doc.builders; diff --git a/src/slang-nodes/TupleExpression.ts b/src/slang-nodes/TupleExpression.ts index c3fb59f8b..0efcb80b8 100644 --- a/src/slang-nodes/TupleExpression.ts +++ b/src/slang-nodes/TupleExpression.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TupleValues } from './TupleValues.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class TupleExpression implements SlangNode { readonly kind = NonterminalKind.TupleExpression; diff --git a/src/slang-nodes/TupleMember.ts b/src/slang-nodes/TupleMember.ts index 477999f81..7a82c70b1 100644 --- a/src/slang-nodes/TupleMember.ts +++ b/src/slang-nodes/TupleMember.ts @@ -3,9 +3,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TypedTupleMember } from './TypedTupleMember.js'; import { UntypedTupleMember } from './UntypedTupleMember.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class TupleMember implements SlangNode { readonly kind = NonterminalKind.TupleMember; diff --git a/src/slang-nodes/TupleValue.ts b/src/slang-nodes/TupleValue.ts index 2cc94c763..817a911e6 100644 --- a/src/slang-nodes/TupleValue.ts +++ b/src/slang-nodes/TupleValue.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class TupleValue implements SlangNode { readonly kind = NonterminalKind.TupleValue; diff --git a/src/slang-nodes/TupleValues.ts b/src/slang-nodes/TupleValues.ts index 98c7ca4d3..bfd026496 100644 --- a/src/slang-nodes/TupleValues.ts +++ b/src/slang-nodes/TupleValues.ts @@ -4,9 +4,9 @@ import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TupleValue } from './TupleValue.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class TupleValues implements SlangNode { readonly kind = NonterminalKind.TupleValues; diff --git a/src/slang-nodes/TypeExpression.ts b/src/slang-nodes/TypeExpression.ts index 5230d6d81..251fabc06 100644 --- a/src/slang-nodes/TypeExpression.ts +++ b/src/slang-nodes/TypeExpression.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TypeName } from './TypeName.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { /*AstPath,*/ Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class TypeExpression implements SlangNode { readonly kind = NonterminalKind.TypeExpression; diff --git a/src/slang-nodes/TypeName.ts b/src/slang-nodes/TypeName.ts index acc1f0d3d..b3c93d9cb 100644 --- a/src/slang-nodes/TypeName.ts +++ b/src/slang-nodes/TypeName.ts @@ -6,9 +6,9 @@ import { MappingType } from './MappingType.js'; import { ElementaryType } from './ElementaryType.js'; import { IdentifierPath } from './IdentifierPath.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class TypeName implements SlangNode { readonly kind = NonterminalKind.TypeName; diff --git a/src/slang-nodes/TypedTupleMember.ts b/src/slang-nodes/TypedTupleMember.ts index 9d718de08..0ec0cbc7f 100644 --- a/src/slang-nodes/TypedTupleMember.ts +++ b/src/slang-nodes/TypedTupleMember.ts @@ -3,9 +3,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TypeName } from './TypeName.js'; import { StorageLocation } from './StorageLocation.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class TypedTupleMember implements SlangNode { readonly kind = NonterminalKind.TypedTupleMember; diff --git a/src/slang-nodes/UncheckedBlock.ts b/src/slang-nodes/UncheckedBlock.ts index c9bc7a6dd..7e3ecaaf9 100644 --- a/src/slang-nodes/UncheckedBlock.ts +++ b/src/slang-nodes/UncheckedBlock.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Block } from './Block.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class UncheckedBlock implements SlangNode { readonly kind = NonterminalKind.UncheckedBlock; diff --git a/src/slang-nodes/UnicodeStringLiteral.ts b/src/slang-nodes/UnicodeStringLiteral.ts index 579645dc1..1e8a1cfd3 100644 --- a/src/slang-nodes/UnicodeStringLiteral.ts +++ b/src/slang-nodes/UnicodeStringLiteral.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printString } from '../slang-printers/print-string.js'; import { getNodeMetadata } from '../slang-utils/metadata.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class UnicodeStringLiteral implements SlangNode { readonly kind = NonterminalKind.UnicodeStringLiteral; diff --git a/src/slang-nodes/UnicodeStringLiterals.ts b/src/slang-nodes/UnicodeStringLiterals.ts index 1009498d6..a45fa04d6 100644 --- a/src/slang-nodes/UnicodeStringLiterals.ts +++ b/src/slang-nodes/UnicodeStringLiterals.ts @@ -3,9 +3,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { UnicodeStringLiteral } from './UnicodeStringLiteral.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { join, hardline } = doc.builders; diff --git a/src/slang-nodes/UnnamedFunctionAttribute.ts b/src/slang-nodes/UnnamedFunctionAttribute.ts index 52d364752..881566ab6 100644 --- a/src/slang-nodes/UnnamedFunctionAttribute.ts +++ b/src/slang-nodes/UnnamedFunctionAttribute.ts @@ -3,9 +3,9 @@ import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ModifierInvocation } from './ModifierInvocation.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class UnnamedFunctionAttribute implements SlangNode { readonly kind = NonterminalKind.UnnamedFunctionAttribute; diff --git a/src/slang-nodes/UnnamedFunctionAttributes.ts b/src/slang-nodes/UnnamedFunctionAttributes.ts index fa015983e..289a1c030 100644 --- a/src/slang-nodes/UnnamedFunctionAttributes.ts +++ b/src/slang-nodes/UnnamedFunctionAttributes.ts @@ -4,9 +4,9 @@ import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes. import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { UnnamedFunctionAttribute } from './UnnamedFunctionAttribute.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { line } = doc.builders; diff --git a/src/slang-nodes/UnnamedFunctionDefinition.ts b/src/slang-nodes/UnnamedFunctionDefinition.ts index 0650ee497..3317b55e5 100644 --- a/src/slang-nodes/UnnamedFunctionDefinition.ts +++ b/src/slang-nodes/UnnamedFunctionDefinition.ts @@ -5,9 +5,9 @@ import { ParametersDeclaration } from './ParametersDeclaration.js'; import { UnnamedFunctionAttributes } from './UnnamedFunctionAttributes.js'; import { FunctionBody } from './FunctionBody.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class UnnamedFunctionDefinition implements SlangNode { readonly kind = NonterminalKind.UnnamedFunctionDefinition; diff --git a/src/slang-nodes/UntypedTupleMember.ts b/src/slang-nodes/UntypedTupleMember.ts index c0d923951..b82016bbf 100644 --- a/src/slang-nodes/UntypedTupleMember.ts +++ b/src/slang-nodes/UntypedTupleMember.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { StorageLocation } from './StorageLocation.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { /*AstPath,*/ Doc /*, ParserOptions*/ } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { SlangNode } from '../types'; export class UntypedTupleMember implements SlangNode { readonly kind = NonterminalKind.UntypedTupleMember; diff --git a/src/slang-nodes/UserDefinedValueTypeDefinition.ts b/src/slang-nodes/UserDefinedValueTypeDefinition.ts index b604f23db..65137297c 100644 --- a/src/slang-nodes/UserDefinedValueTypeDefinition.ts +++ b/src/slang-nodes/UserDefinedValueTypeDefinition.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { ElementaryType } from './ElementaryType.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class UserDefinedValueTypeDefinition implements SlangNode { readonly kind = NonterminalKind.UserDefinedValueTypeDefinition; diff --git a/src/slang-nodes/UsingAlias.ts b/src/slang-nodes/UsingAlias.ts index ad9a04e77..1baee70ad 100644 --- a/src/slang-nodes/UsingAlias.ts +++ b/src/slang-nodes/UsingAlias.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { UsingOperator } from './UsingOperator.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class UsingAlias implements SlangNode { readonly kind = NonterminalKind.UsingAlias; diff --git a/src/slang-nodes/UsingClause.ts b/src/slang-nodes/UsingClause.ts index 1a5f01056..ce8e561f2 100644 --- a/src/slang-nodes/UsingClause.ts +++ b/src/slang-nodes/UsingClause.ts @@ -3,9 +3,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { IdentifierPath } from './IdentifierPath.js'; import { UsingDeconstruction } from './UsingDeconstruction.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class UsingClause implements SlangNode { readonly kind = NonterminalKind.UsingClause; diff --git a/src/slang-nodes/UsingDeconstruction.ts b/src/slang-nodes/UsingDeconstruction.ts index a017b2f77..a84452a9d 100644 --- a/src/slang-nodes/UsingDeconstruction.ts +++ b/src/slang-nodes/UsingDeconstruction.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { UsingDeconstructionSymbols } from './UsingDeconstructionSymbols.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class UsingDeconstruction implements SlangNode { readonly kind = NonterminalKind.UsingDeconstruction; diff --git a/src/slang-nodes/UsingDeconstructionSymbol.ts b/src/slang-nodes/UsingDeconstructionSymbol.ts index a2c5cf198..dc7f1ccff 100644 --- a/src/slang-nodes/UsingDeconstructionSymbol.ts +++ b/src/slang-nodes/UsingDeconstructionSymbol.ts @@ -3,9 +3,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { IdentifierPath } from './IdentifierPath.js'; import { UsingAlias } from './UsingAlias.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class UsingDeconstructionSymbol implements SlangNode { readonly kind = NonterminalKind.UsingDeconstructionSymbol; diff --git a/src/slang-nodes/UsingDeconstructionSymbols.ts b/src/slang-nodes/UsingDeconstructionSymbols.ts index 5c74db160..2588b312b 100644 --- a/src/slang-nodes/UsingDeconstructionSymbols.ts +++ b/src/slang-nodes/UsingDeconstructionSymbols.ts @@ -4,9 +4,9 @@ import { printSeparatedList } from '../slang-printers/print-separated-list.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { UsingDeconstructionSymbol } from './UsingDeconstructionSymbol.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { line, softline } = doc.builders; diff --git a/src/slang-nodes/UsingDirective.ts b/src/slang-nodes/UsingDirective.ts index 3ceab3f51..efd5dbb40 100644 --- a/src/slang-nodes/UsingDirective.ts +++ b/src/slang-nodes/UsingDirective.ts @@ -3,9 +3,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { UsingClause } from './UsingClause.js'; import { UsingTarget } from './UsingTarget.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class UsingDirective implements SlangNode { readonly kind = NonterminalKind.UsingDirective; diff --git a/src/slang-nodes/UsingOperator.ts b/src/slang-nodes/UsingOperator.ts index d5c03b58b..e0e36081c 100644 --- a/src/slang-nodes/UsingOperator.ts +++ b/src/slang-nodes/UsingOperator.ts @@ -1,9 +1,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata } from '../slang-utils/metadata.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { SlangNode } from '../types'; export class UsingOperator implements SlangNode { readonly kind = NonterminalKind.UsingOperator; diff --git a/src/slang-nodes/UsingTarget.ts b/src/slang-nodes/UsingTarget.ts index ce13833a5..adf0c9d6b 100644 --- a/src/slang-nodes/UsingTarget.ts +++ b/src/slang-nodes/UsingTarget.ts @@ -3,9 +3,9 @@ import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TypeName } from './TypeName.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class UsingTarget implements SlangNode { readonly kind = NonterminalKind.UsingTarget; diff --git a/src/slang-nodes/VariableDeclarationStatement.ts b/src/slang-nodes/VariableDeclarationStatement.ts index 60bd5a701..dc498a0dc 100644 --- a/src/slang-nodes/VariableDeclarationStatement.ts +++ b/src/slang-nodes/VariableDeclarationStatement.ts @@ -5,9 +5,9 @@ import { VariableDeclarationType } from './VariableDeclarationType.js'; import { StorageLocation } from './StorageLocation.js'; import { VariableDeclarationValue } from './VariableDeclarationValue.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { group, indent, indentIfBreak, line } = doc.builders; diff --git a/src/slang-nodes/VariableDeclarationType.ts b/src/slang-nodes/VariableDeclarationType.ts index 31653ce17..09db0dc27 100644 --- a/src/slang-nodes/VariableDeclarationType.ts +++ b/src/slang-nodes/VariableDeclarationType.ts @@ -3,9 +3,9 @@ import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { TypeName } from './TypeName.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class VariableDeclarationType implements SlangNode { readonly kind = NonterminalKind.VariableDeclarationType; diff --git a/src/slang-nodes/VariableDeclarationValue.ts b/src/slang-nodes/VariableDeclarationValue.ts index 30b86759e..cc8496a88 100644 --- a/src/slang-nodes/VariableDeclarationValue.ts +++ b/src/slang-nodes/VariableDeclarationValue.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class VariableDeclarationValue implements SlangNode { readonly kind = NonterminalKind.VariableDeclarationValue; diff --git a/src/slang-nodes/VersionComparator.ts b/src/slang-nodes/VersionComparator.ts index 5a5981a26..4579b9503 100644 --- a/src/slang-nodes/VersionComparator.ts +++ b/src/slang-nodes/VersionComparator.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { VersionExpression } from './VersionExpression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class VersionComparator implements SlangNode { readonly kind = NonterminalKind.VersionComparator; diff --git a/src/slang-nodes/VersionExpression.ts b/src/slang-nodes/VersionExpression.ts index d9733ffe8..c6894b59b 100644 --- a/src/slang-nodes/VersionExpression.ts +++ b/src/slang-nodes/VersionExpression.ts @@ -5,9 +5,9 @@ import { VersionRange } from './VersionRange.js'; import { VersionComparator } from './VersionComparator.js'; import { VersionSpecifiers } from './VersionSpecifiers.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class VersionExpression implements SlangNode { readonly kind = NonterminalKind.VersionExpression; diff --git a/src/slang-nodes/VersionExpressionSet.ts b/src/slang-nodes/VersionExpressionSet.ts index cb9e62280..511232298 100644 --- a/src/slang-nodes/VersionExpressionSet.ts +++ b/src/slang-nodes/VersionExpressionSet.ts @@ -3,9 +3,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { VersionExpression } from './VersionExpression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { join } = doc.builders; diff --git a/src/slang-nodes/VersionExpressionSets.ts b/src/slang-nodes/VersionExpressionSets.ts index f73113117..33b66c138 100644 --- a/src/slang-nodes/VersionExpressionSets.ts +++ b/src/slang-nodes/VersionExpressionSets.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { VersionExpressionSet } from './VersionExpressionSet.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class VersionExpressionSets implements SlangNode { readonly kind = NonterminalKind.VersionExpressionSets; diff --git a/src/slang-nodes/VersionPragma.ts b/src/slang-nodes/VersionPragma.ts index d04d6d2e3..0f9efbcd1 100644 --- a/src/slang-nodes/VersionPragma.ts +++ b/src/slang-nodes/VersionPragma.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { VersionExpressionSets } from './VersionExpressionSets.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class VersionPragma implements SlangNode { readonly kind = NonterminalKind.VersionPragma; diff --git a/src/slang-nodes/VersionRange.ts b/src/slang-nodes/VersionRange.ts index dc2091cfc..72110ee29 100644 --- a/src/slang-nodes/VersionRange.ts +++ b/src/slang-nodes/VersionRange.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { VersionExpression } from './VersionExpression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { /*AstPath,*/ Doc /*, ParserOptions*/ } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { SlangNode } from '../types'; export class VersionRange implements SlangNode { readonly kind = NonterminalKind.VersionRange; diff --git a/src/slang-nodes/VersionSpecifiers.ts b/src/slang-nodes/VersionSpecifiers.ts index 13eb76704..d3c9f6b62 100644 --- a/src/slang-nodes/VersionSpecifiers.ts +++ b/src/slang-nodes/VersionSpecifiers.ts @@ -1,9 +1,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata } from '../slang-utils/metadata.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { SlangNode } from '../types'; export class VersionSpecifiers implements SlangNode { readonly kind = NonterminalKind.VersionSpecifiers; diff --git a/src/slang-nodes/WhileStatement.ts b/src/slang-nodes/WhileStatement.ts index 066f587ad..e16148a63 100644 --- a/src/slang-nodes/WhileStatement.ts +++ b/src/slang-nodes/WhileStatement.ts @@ -5,9 +5,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import { Statement } from './Statement.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { group, indent, line } = doc.builders; diff --git a/src/slang-nodes/YulArguments.ts b/src/slang-nodes/YulArguments.ts index 684a2f04f..8cca490f9 100644 --- a/src/slang-nodes/YulArguments.ts +++ b/src/slang-nodes/YulArguments.ts @@ -3,9 +3,9 @@ import { printSeparatedList } from '../slang-printers/print-separated-list.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulExpression } from './YulExpression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class YulArguments implements SlangNode { readonly kind = NonterminalKind.YulArguments; diff --git a/src/slang-nodes/YulAssignmentOperator.ts b/src/slang-nodes/YulAssignmentOperator.ts index 3628266dd..b08c19c24 100644 --- a/src/slang-nodes/YulAssignmentOperator.ts +++ b/src/slang-nodes/YulAssignmentOperator.ts @@ -3,9 +3,9 @@ import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulColonEqual } from './YulColonEqual.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class YulAssignmentOperator implements SlangNode { readonly kind = NonterminalKind.YulAssignmentOperator; diff --git a/src/slang-nodes/YulBlock.ts b/src/slang-nodes/YulBlock.ts index 6bda9de35..6b823a9c8 100644 --- a/src/slang-nodes/YulBlock.ts +++ b/src/slang-nodes/YulBlock.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulStatements } from './YulStatements.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class YulBlock implements SlangNode { readonly kind = NonterminalKind.YulBlock; diff --git a/src/slang-nodes/YulBreakStatement.ts b/src/slang-nodes/YulBreakStatement.ts index fedf22198..4c0f9df49 100644 --- a/src/slang-nodes/YulBreakStatement.ts +++ b/src/slang-nodes/YulBreakStatement.ts @@ -1,9 +1,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata } from '../slang-utils/metadata.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { SlangNode } from '../types'; export class YulBreakStatement implements SlangNode { readonly kind = NonterminalKind.YulBreakStatement; diff --git a/src/slang-nodes/YulBuiltInFunction.ts b/src/slang-nodes/YulBuiltInFunction.ts index 0bb02e80b..4df02fb54 100644 --- a/src/slang-nodes/YulBuiltInFunction.ts +++ b/src/slang-nodes/YulBuiltInFunction.ts @@ -1,9 +1,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata } from '../slang-utils/metadata.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { SlangNode } from '../types'; export class YulBuiltInFunction implements SlangNode { readonly kind = NonterminalKind.YulBuiltInFunction; diff --git a/src/slang-nodes/YulColonEqual.ts b/src/slang-nodes/YulColonEqual.ts index 06b8f9afe..806cad10e 100644 --- a/src/slang-nodes/YulColonEqual.ts +++ b/src/slang-nodes/YulColonEqual.ts @@ -1,9 +1,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata } from '../slang-utils/metadata.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { /*AstPath,*/ Doc /*, ParserOptions*/ } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { SlangNode } from '../types'; export class YulColonEqual implements SlangNode { readonly kind = NonterminalKind.YulColonEqual; diff --git a/src/slang-nodes/YulContinueStatement.ts b/src/slang-nodes/YulContinueStatement.ts index 10ac4768c..1c64d7e23 100644 --- a/src/slang-nodes/YulContinueStatement.ts +++ b/src/slang-nodes/YulContinueStatement.ts @@ -1,9 +1,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata } from '../slang-utils/metadata.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { SlangNode } from '../types'; export class YulContinueStatement implements SlangNode { readonly kind = NonterminalKind.YulContinueStatement; diff --git a/src/slang-nodes/YulDefaultCase.ts b/src/slang-nodes/YulDefaultCase.ts index 3700b0cdf..d8aeda6cb 100644 --- a/src/slang-nodes/YulDefaultCase.ts +++ b/src/slang-nodes/YulDefaultCase.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulBlock } from './YulBlock.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class YulDefaultCase implements SlangNode { readonly kind = NonterminalKind.YulDefaultCase; diff --git a/src/slang-nodes/YulExpression.ts b/src/slang-nodes/YulExpression.ts index 03e299a15..d3b8db596 100644 --- a/src/slang-nodes/YulExpression.ts +++ b/src/slang-nodes/YulExpression.ts @@ -5,9 +5,9 @@ import { YulLiteral } from './YulLiteral.js'; import { YulBuiltInFunction } from './YulBuiltInFunction.js'; import { YulPath } from './YulPath.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class YulExpression implements SlangNode { readonly kind = NonterminalKind.YulExpression; diff --git a/src/slang-nodes/YulForStatement.ts b/src/slang-nodes/YulForStatement.ts index e62ef5b9b..20f580bf6 100644 --- a/src/slang-nodes/YulForStatement.ts +++ b/src/slang-nodes/YulForStatement.ts @@ -3,9 +3,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulBlock } from './YulBlock.js'; import { YulExpression } from './YulExpression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class YulForStatement implements SlangNode { readonly kind = NonterminalKind.YulForStatement; diff --git a/src/slang-nodes/YulFunctionCallExpression.ts b/src/slang-nodes/YulFunctionCallExpression.ts index d9ae1ef12..87e50ca0b 100644 --- a/src/slang-nodes/YulFunctionCallExpression.ts +++ b/src/slang-nodes/YulFunctionCallExpression.ts @@ -3,9 +3,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulExpression } from './YulExpression.js'; import { YulArguments } from './YulArguments.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class YulFunctionCallExpression implements SlangNode { readonly kind = NonterminalKind.YulFunctionCallExpression; diff --git a/src/slang-nodes/YulFunctionDefinition.ts b/src/slang-nodes/YulFunctionDefinition.ts index b14e32c32..62f07d26d 100644 --- a/src/slang-nodes/YulFunctionDefinition.ts +++ b/src/slang-nodes/YulFunctionDefinition.ts @@ -4,9 +4,9 @@ import { YulParametersDeclaration } from './YulParametersDeclaration.js'; import { YulReturnsDeclaration } from './YulReturnsDeclaration.js'; import { YulBlock } from './YulBlock.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class YulFunctionDefinition implements SlangNode { readonly kind = NonterminalKind.YulFunctionDefinition; diff --git a/src/slang-nodes/YulIfStatement.ts b/src/slang-nodes/YulIfStatement.ts index 50247ba4e..b03a45fe1 100644 --- a/src/slang-nodes/YulIfStatement.ts +++ b/src/slang-nodes/YulIfStatement.ts @@ -3,9 +3,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulExpression } from './YulExpression.js'; import { YulBlock } from './YulBlock.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class YulIfStatement implements SlangNode { readonly kind = NonterminalKind.YulIfStatement; diff --git a/src/slang-nodes/YulLabel.ts b/src/slang-nodes/YulLabel.ts index 36dd658c4..d5012be6b 100644 --- a/src/slang-nodes/YulLabel.ts +++ b/src/slang-nodes/YulLabel.ts @@ -2,9 +2,9 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata } from '../slang-utils/metadata.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { SlangNode } from '../types'; const { dedent, line } = doc.builders; diff --git a/src/slang-nodes/YulLeaveStatement.ts b/src/slang-nodes/YulLeaveStatement.ts index 8bb1d7a7b..55a93ff27 100644 --- a/src/slang-nodes/YulLeaveStatement.ts +++ b/src/slang-nodes/YulLeaveStatement.ts @@ -1,9 +1,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata } from '../slang-utils/metadata.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { /*AstPath,*/ Doc /*, ParserOptions*/ } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { SlangNode } from '../types'; export class YulLeaveStatement implements SlangNode { readonly kind = NonterminalKind.YulLeaveStatement; diff --git a/src/slang-nodes/YulLiteral.ts b/src/slang-nodes/YulLiteral.ts index 9546c3f54..0a260b121 100644 --- a/src/slang-nodes/YulLiteral.ts +++ b/src/slang-nodes/YulLiteral.ts @@ -4,9 +4,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { HexStringLiteral } from './HexStringLiteral.js'; import { StringLiteral } from './StringLiteral.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class YulLiteral implements SlangNode { readonly kind = NonterminalKind.YulLiteral; diff --git a/src/slang-nodes/YulParameters.ts b/src/slang-nodes/YulParameters.ts index 5e654f9f5..8161f8852 100644 --- a/src/slang-nodes/YulParameters.ts +++ b/src/slang-nodes/YulParameters.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../slang-printers/print-separated-list.js'; import { getNodeMetadata } from '../slang-utils/metadata.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { SlangNode } from '../types'; export class YulParameters implements SlangNode { readonly kind = NonterminalKind.YulParameters; diff --git a/src/slang-nodes/YulParametersDeclaration.ts b/src/slang-nodes/YulParametersDeclaration.ts index 2454fb34d..d63adaf5a 100644 --- a/src/slang-nodes/YulParametersDeclaration.ts +++ b/src/slang-nodes/YulParametersDeclaration.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulParameters } from './YulParameters.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class YulParametersDeclaration implements SlangNode { readonly kind = NonterminalKind.YulParametersDeclaration; diff --git a/src/slang-nodes/YulPath.ts b/src/slang-nodes/YulPath.ts index 56d7d14a8..2c6575cdb 100644 --- a/src/slang-nodes/YulPath.ts +++ b/src/slang-nodes/YulPath.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulPathComponent } from './YulPathComponent.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class YulPath implements SlangNode { readonly kind = NonterminalKind.YulPath; diff --git a/src/slang-nodes/YulPathComponent.ts b/src/slang-nodes/YulPathComponent.ts index e9b6e573d..da616526c 100644 --- a/src/slang-nodes/YulPathComponent.ts +++ b/src/slang-nodes/YulPathComponent.ts @@ -1,9 +1,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata } from '../slang-utils/metadata.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { SlangNode } from '../types'; export class YulPathComponent implements SlangNode { readonly kind = NonterminalKind.YulPathComponent; diff --git a/src/slang-nodes/YulPaths.ts b/src/slang-nodes/YulPaths.ts index 34244780e..ee4de9e8a 100644 --- a/src/slang-nodes/YulPaths.ts +++ b/src/slang-nodes/YulPaths.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulPath } from './YulPath.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class YulPaths implements SlangNode { readonly kind = NonterminalKind.YulPaths; diff --git a/src/slang-nodes/YulReturnVariables.ts b/src/slang-nodes/YulReturnVariables.ts index 8bb8e0c48..166d2c7da 100644 --- a/src/slang-nodes/YulReturnVariables.ts +++ b/src/slang-nodes/YulReturnVariables.ts @@ -3,9 +3,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedList } from '../slang-printers/print-separated-list.js'; import { getNodeMetadata } from '../slang-utils/metadata.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { Doc } from 'prettier'; -import type { SlangNode } from '../types.js'; +import type { SlangNode } from '../types'; const { line } = doc.builders; diff --git a/src/slang-nodes/YulReturnsDeclaration.ts b/src/slang-nodes/YulReturnsDeclaration.ts index 02fbbd9f4..4939a452e 100644 --- a/src/slang-nodes/YulReturnsDeclaration.ts +++ b/src/slang-nodes/YulReturnsDeclaration.ts @@ -4,9 +4,9 @@ import { printSeparatedItem } from '../slang-printers/print-separated-item.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulReturnVariables } from './YulReturnVariables.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { line } = doc.builders; diff --git a/src/slang-nodes/YulStackAssignmentStatement.ts b/src/slang-nodes/YulStackAssignmentStatement.ts index 0f28a1230..da32895d5 100644 --- a/src/slang-nodes/YulStackAssignmentStatement.ts +++ b/src/slang-nodes/YulStackAssignmentStatement.ts @@ -3,9 +3,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulAssignmentOperator } from './YulAssignmentOperator.js'; import { YulExpression } from './YulExpression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { /*AstPath,*/ Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class YulStackAssignmentStatement implements SlangNode { readonly kind = NonterminalKind.YulStackAssignmentStatement; diff --git a/src/slang-nodes/YulStatement.ts b/src/slang-nodes/YulStatement.ts index 7b49516ab..ec590d7b1 100644 --- a/src/slang-nodes/YulStatement.ts +++ b/src/slang-nodes/YulStatement.ts @@ -14,9 +14,9 @@ import { YulContinueStatement } from './YulContinueStatement.js'; import { YulLabel } from './YulLabel.js'; import { YulExpression } from './YulExpression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class YulStatement implements SlangNode { readonly kind = NonterminalKind.YulStatement; diff --git a/src/slang-nodes/YulStatements.ts b/src/slang-nodes/YulStatements.ts index 4b67e605e..44009687d 100644 --- a/src/slang-nodes/YulStatements.ts +++ b/src/slang-nodes/YulStatements.ts @@ -6,9 +6,9 @@ import { printPreservingEmptyLines } from '../slang-printers/print-preserving-em import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulStatement } from './YulStatement.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { hardline } = doc.builders; diff --git a/src/slang-nodes/YulSwitchCase.ts b/src/slang-nodes/YulSwitchCase.ts index 0bd9d01ed..8f70a4a7d 100644 --- a/src/slang-nodes/YulSwitchCase.ts +++ b/src/slang-nodes/YulSwitchCase.ts @@ -3,9 +3,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulDefaultCase } from './YulDefaultCase.js'; import { YulValueCase } from './YulValueCase.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class YulSwitchCase implements SlangNode { readonly kind = NonterminalKind.YulSwitchCase; diff --git a/src/slang-nodes/YulSwitchCases.ts b/src/slang-nodes/YulSwitchCases.ts index cffeca92d..70f173047 100644 --- a/src/slang-nodes/YulSwitchCases.ts +++ b/src/slang-nodes/YulSwitchCases.ts @@ -3,9 +3,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulSwitchCase } from './YulSwitchCase.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { hardline, join } = doc.builders; diff --git a/src/slang-nodes/YulSwitchStatement.ts b/src/slang-nodes/YulSwitchStatement.ts index b4975c3bf..52cd1bb1c 100644 --- a/src/slang-nodes/YulSwitchStatement.ts +++ b/src/slang-nodes/YulSwitchStatement.ts @@ -4,9 +4,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulExpression } from './YulExpression.js'; import { YulSwitchCases } from './YulSwitchCases.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; const { hardline } = doc.builders; diff --git a/src/slang-nodes/YulValueCase.ts b/src/slang-nodes/YulValueCase.ts index 5b711d217..aa220954b 100644 --- a/src/slang-nodes/YulValueCase.ts +++ b/src/slang-nodes/YulValueCase.ts @@ -3,9 +3,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulLiteral } from './YulLiteral.js'; import { YulBlock } from './YulBlock.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class YulValueCase implements SlangNode { readonly kind = NonterminalKind.YulValueCase; diff --git a/src/slang-nodes/YulVariableAssignmentStatement.ts b/src/slang-nodes/YulVariableAssignmentStatement.ts index 5f2a33fee..96b34f822 100644 --- a/src/slang-nodes/YulVariableAssignmentStatement.ts +++ b/src/slang-nodes/YulVariableAssignmentStatement.ts @@ -4,9 +4,9 @@ import { YulPaths } from './YulPaths.js'; import { YulAssignmentOperator } from './YulAssignmentOperator.js'; import { YulExpression } from './YulExpression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class YulVariableAssignmentStatement implements SlangNode { readonly kind = NonterminalKind.YulVariableAssignmentStatement; diff --git a/src/slang-nodes/YulVariableDeclarationStatement.ts b/src/slang-nodes/YulVariableDeclarationStatement.ts index 795258af4..1fc186e44 100644 --- a/src/slang-nodes/YulVariableDeclarationStatement.ts +++ b/src/slang-nodes/YulVariableDeclarationStatement.ts @@ -2,9 +2,9 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulVariableDeclarationValue } from './YulVariableDeclarationValue.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class YulVariableDeclarationStatement implements SlangNode { readonly kind = NonterminalKind.YulVariableDeclarationStatement; diff --git a/src/slang-nodes/YulVariableDeclarationValue.ts b/src/slang-nodes/YulVariableDeclarationValue.ts index cba8ba17e..6bcf5a5f3 100644 --- a/src/slang-nodes/YulVariableDeclarationValue.ts +++ b/src/slang-nodes/YulVariableDeclarationValue.ts @@ -3,9 +3,9 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulAssignmentOperator } from './YulAssignmentOperator.js'; import { YulExpression } from './YulExpression.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types.js'; +import type { AstNode, SlangNode } from '../types'; export class YulVariableDeclarationValue implements SlangNode { readonly kind = NonterminalKind.YulVariableDeclarationValue; diff --git a/src/slang-nodes/index.d.ts b/src/slang-nodes/index.d.ts new file mode 100644 index 000000000..cdb1b15e0 --- /dev/null +++ b/src/slang-nodes/index.d.ts @@ -0,0 +1,215 @@ +export type * from './ABICoderPragma.js'; +export type * from './AdditiveExpression.js'; +export type * from './AddressType.js'; +export type * from './AndExpression.js'; +export type * from './ArgumentsDeclaration.js'; +export type * from './ArrayExpression.js'; +export type * from './ArrayTypeName.js'; +export type * from './ArrayValues.js'; +export type * from './AssemblyFlags.js'; +export type * from './AssemblyFlagsDeclaration.js'; +export type * from './AssemblyStatement.js'; +export type * from './AssignmentExpression.js'; +export type * from './BitwiseAndExpression.js'; +export type * from './BitwiseOrExpression.js'; +export type * from './BitwiseXorExpression.js'; +export type * from './Block.js'; +export type * from './BreakStatement.js'; +export type * from './CallOptions.js'; +export type * from './CallOptionsExpression.js'; +export type * from './CatchClause.js'; +export type * from './CatchClauseError.js'; +export type * from './CatchClauses.js'; +export type * from './ComparisonExpression.js'; +export type * from './ConditionalExpression.js'; +export type * from './ConstantDefinition.js'; +export type * from './ConstructorAttribute.js'; +export type * from './ConstructorAttributes.js'; +export type * from './ConstructorDefinition.js'; +export type * from './ContinueStatement.js'; +export type * from './ContractDefinition.js'; +export type * from './ContractMember.js'; +export type * from './ContractMembers.js'; +export type * from './DecimalNumberExpression.js'; +export type * from './DoWhileStatement.js'; +export type * from './ElementaryType.js'; +export type * from './ElseBranch.js'; +export type * from './EmitStatement.js'; +export type * from './EnumDefinition.js'; +export type * from './EnumMembers.js'; +export type * from './EqualityExpression.js'; +export type * from './ErrorDefinition.js'; +export type * from './ErrorParameter.js'; +export type * from './ErrorParameters.js'; +export type * from './ErrorParametersDeclaration.js'; +export type * from './EventDefinition.js'; +export type * from './EventParameter.js'; +export type * from './EventParameters.js'; +export type * from './EventParametersDeclaration.js'; +export type * from './ExperimentalFeature.js'; +export type * from './ExperimentalPragma.js'; +export type * from './ExponentiationExpression.js'; +export type * from './Expression.js'; +export type * from './ExpressionStatement.js'; +export type * from './FallbackFunctionAttribute.js'; +export type * from './FallbackFunctionAttributes.js'; +export type * from './FallbackFunctionDefinition.js'; +export type * from './ForStatement.js'; +export type * from './ForStatementCondition.js'; +export type * from './ForStatementInitialization.js'; +export type * from './FunctionAttribute.js'; +export type * from './FunctionAttributes.js'; +export type * from './FunctionBody.js'; +export type * from './FunctionCallExpression.js'; +export type * from './FunctionDefinition.js'; +export type * from './FunctionName.js'; +export type * from './FunctionType.js'; +export type * from './FunctionTypeAttribute.js'; +export type * from './FunctionTypeAttributes.js'; +export type * from './HexNumberExpression.js'; +export type * from './HexStringLiteral.js'; +export type * from './HexStringLiterals.js'; +export type * from './IdentifierPath.js'; +export type * from './IfStatement.js'; +export type * from './ImportAlias.js'; +export type * from './ImportClause.js'; +export type * from './ImportDeconstruction.js'; +export type * from './ImportDeconstructionSymbol.js'; +export type * from './ImportDeconstructionSymbols.js'; +export type * from './ImportDirective.js'; +export type * from './IndexAccessEnd.js'; +export type * from './IndexAccessExpression.js'; +export type * from './InheritanceSpecifier.js'; +export type * from './InheritanceType.js'; +export type * from './InheritanceTypes.js'; +export type * from './InterfaceDefinition.js'; +export type * from './InterfaceMembers.js'; +export type * from './LibraryDefinition.js'; +export type * from './LibraryMembers.js'; +export type * from './MappingKey.js'; +export type * from './MappingKeyType.js'; +export type * from './MappingType.js'; +export type * from './MappingValue.js'; +export type * from './MemberAccess.js'; +export type * from './MemberAccessExpression.js'; +export type * from './ModifierAttribute.js'; +export type * from './ModifierAttributes.js'; +export type * from './ModifierDefinition.js'; +export type * from './ModifierInvocation.js'; +export type * from './MultiplicativeExpression.js'; +export type * from './NamedArgument.js'; +export type * from './NamedArgumentGroup.js'; +export type * from './NamedArguments.js'; +export type * from './NamedArgumentsDeclaration.js'; +export type * from './NamedImport.js'; +export type * from './NewExpression.js'; +export type * from './NumberUnit.js'; +export type * from './OrExpression.js'; +export type * from './OverridePaths.js'; +export type * from './OverridePathsDeclaration.js'; +export type * from './OverrideSpecifier.js'; +export type * from './Parameter.js'; +export type * from './Parameters.js'; +export type * from './ParametersDeclaration.js'; +export type * from './PathImport.js'; +export type * from './PositionalArguments.js'; +export type * from './PositionalArgumentsDeclaration.js'; +export type * from './PostfixExpression.js'; +export type * from './Pragma.js'; +export type * from './PragmaDirective.js'; +export type * from './PrefixExpression.js'; +export type * from './ReceiveFunctionAttribute.js'; +export type * from './ReceiveFunctionAttributes.js'; +export type * from './ReceiveFunctionDefinition.js'; +export type * from './ReturnsDeclaration.js'; +export type * from './ReturnStatement.js'; +export type * from './RevertStatement.js'; +export type * from './ShiftExpression.js'; +export type * from './SourceUnit.js'; +export type * from './SourceUnitMember.js'; +export type * from './SourceUnitMembers.js'; +export type * from './Statement.js'; +export type * from './Statements.js'; +export type * from './StateVariableAttribute.js'; +export type * from './StateVariableAttributes.js'; +export type * from './StateVariableDefinition.js'; +export type * from './StateVariableDefinitionValue.js'; +export type * from './StorageLocation.js'; +export type * from './StringExpression.js'; +export type * from './StringLiteral.js'; +export type * from './StringLiterals.js'; +export type * from './StructDefinition.js'; +export type * from './StructMember.js'; +export type * from './StructMembers.js'; +export type * from './ThrowStatement.js'; +export type * from './TryStatement.js'; +export type * from './TupleDeconstructionElement.js'; +export type * from './TupleDeconstructionElements.js'; +export type * from './TupleDeconstructionStatement.js'; +export type * from './TupleExpression.js'; +export type * from './TupleMember.js'; +export type * from './TupleValue.js'; +export type * from './TupleValues.js'; +export type * from './TypedTupleMember.js'; +export type * from './TypeExpression.js'; +export type * from './TypeName.js'; +export type * from './UncheckedBlock.js'; +export type * from './UnicodeStringLiteral.js'; +export type * from './UnicodeStringLiterals.js'; +export type * from './UnnamedFunctionAttribute.js'; +export type * from './UnnamedFunctionAttributes.js'; +export type * from './UnnamedFunctionDefinition.js'; +export type * from './UntypedTupleMember.js'; +export type * from './UserDefinedValueTypeDefinition.js'; +export type * from './UsingAlias.js'; +export type * from './UsingClause.js'; +export type * from './UsingDeconstruction.js'; +export type * from './UsingDeconstructionSymbol.js'; +export type * from './UsingDeconstructionSymbols.js'; +export type * from './UsingDirective.js'; +export type * from './UsingOperator.js'; +export type * from './UsingTarget.js'; +export type * from './VariableDeclarationStatement.js'; +export type * from './VariableDeclarationType.js'; +export type * from './VariableDeclarationValue.js'; +export type * from './VersionComparator.js'; +export type * from './VersionExpression.js'; +export type * from './VersionExpressionSet.js'; +export type * from './VersionExpressionSets.js'; +export type * from './VersionPragma.js'; +export type * from './VersionRange.js'; +export type * from './VersionSpecifiers.js'; +export type * from './WhileStatement.js'; +export type * from './YulArguments.js'; +export type * from './YulAssignmentOperator.js'; +export type * from './YulBlock.js'; +export type * from './YulBreakStatement.js'; +export type * from './YulBuiltInFunction.js'; +export type * from './YulColonEqual.js'; +export type * from './YulContinueStatement.js'; +export type * from './YulDefaultCase.js'; +export type * from './YulExpression.js'; +export type * from './YulForStatement.js'; +export type * from './YulFunctionCallExpression.js'; +export type * from './YulFunctionDefinition.js'; +export type * from './YulIfStatement.js'; +export type * from './YulLabel.js'; +export type * from './YulLeaveStatement.js'; +export type * from './YulLiteral.js'; +export type * from './YulParameters.js'; +export type * from './YulParametersDeclaration.js'; +export type * from './YulPath.js'; +export type * from './YulPathComponent.js'; +export type * from './YulPaths.js'; +export type * from './YulReturnsDeclaration.js'; +export type * from './YulReturnVariables.js'; +export type * from './YulStackAssignmentStatement.js'; +export type * from './YulStatement.js'; +export type * from './YulStatements.js'; +export type * from './YulSwitchCase.js'; +export type * from './YulSwitchCases.js'; +export type * from './YulSwitchStatement.js'; +export type * from './YulValueCase.js'; +export type * from './YulVariableAssignmentStatement.js'; +export type * from './YulVariableDeclarationStatement.js'; +export type * from './YulVariableDeclarationValue.js'; diff --git a/src/slang-nodes/index.ts b/src/slang-nodes/index.ts deleted file mode 100644 index 1b78ec307..000000000 --- a/src/slang-nodes/index.ts +++ /dev/null @@ -1,215 +0,0 @@ -export * from './ABICoderPragma.js'; -export * from './AdditiveExpression.js'; -export * from './AddressType.js'; -export * from './AndExpression.js'; -export * from './ArgumentsDeclaration.js'; -export * from './ArrayExpression.js'; -export * from './ArrayTypeName.js'; -export * from './ArrayValues.js'; -export * from './AssemblyFlags.js'; -export * from './AssemblyFlagsDeclaration.js'; -export * from './AssemblyStatement.js'; -export * from './AssignmentExpression.js'; -export * from './BitwiseAndExpression.js'; -export * from './BitwiseOrExpression.js'; -export * from './BitwiseXorExpression.js'; -export * from './Block.js'; -export * from './BreakStatement.js'; -export * from './CallOptions.js'; -export * from './CallOptionsExpression.js'; -export * from './CatchClause.js'; -export * from './CatchClauseError.js'; -export * from './CatchClauses.js'; -export * from './ComparisonExpression.js'; -export * from './ConditionalExpression.js'; -export * from './ConstantDefinition.js'; -export * from './ConstructorAttribute.js'; -export * from './ConstructorAttributes.js'; -export * from './ConstructorDefinition.js'; -export * from './ContinueStatement.js'; -export * from './ContractDefinition.js'; -export * from './ContractMember.js'; -export * from './ContractMembers.js'; -export * from './DecimalNumberExpression.js'; -export * from './DoWhileStatement.js'; -export * from './ElementaryType.js'; -export * from './ElseBranch.js'; -export * from './EmitStatement.js'; -export * from './EnumDefinition.js'; -export * from './EnumMembers.js'; -export * from './EqualityExpression.js'; -export * from './ErrorDefinition.js'; -export * from './ErrorParameter.js'; -export * from './ErrorParameters.js'; -export * from './ErrorParametersDeclaration.js'; -export * from './EventDefinition.js'; -export * from './EventParameter.js'; -export * from './EventParameters.js'; -export * from './EventParametersDeclaration.js'; -export * from './ExperimentalFeature.js'; -export * from './ExperimentalPragma.js'; -export * from './ExponentiationExpression.js'; -export * from './Expression.js'; -export * from './ExpressionStatement.js'; -export * from './FallbackFunctionAttribute.js'; -export * from './FallbackFunctionAttributes.js'; -export * from './FallbackFunctionDefinition.js'; -export * from './ForStatement.js'; -export * from './ForStatementCondition.js'; -export * from './ForStatementInitialization.js'; -export * from './FunctionAttribute.js'; -export * from './FunctionAttributes.js'; -export * from './FunctionBody.js'; -export * from './FunctionCallExpression.js'; -export * from './FunctionDefinition.js'; -export * from './FunctionName.js'; -export * from './FunctionType.js'; -export * from './FunctionTypeAttribute.js'; -export * from './FunctionTypeAttributes.js'; -export * from './HexNumberExpression.js'; -export * from './HexStringLiteral.js'; -export * from './HexStringLiterals.js'; -export * from './IdentifierPath.js'; -export * from './IfStatement.js'; -export * from './ImportAlias.js'; -export * from './ImportClause.js'; -export * from './ImportDeconstruction.js'; -export * from './ImportDeconstructionSymbol.js'; -export * from './ImportDeconstructionSymbols.js'; -export * from './ImportDirective.js'; -export * from './IndexAccessEnd.js'; -export * from './IndexAccessExpression.js'; -export * from './InheritanceSpecifier.js'; -export * from './InheritanceType.js'; -export * from './InheritanceTypes.js'; -export * from './InterfaceDefinition.js'; -export * from './InterfaceMembers.js'; -export * from './LibraryDefinition.js'; -export * from './LibraryMembers.js'; -export * from './MappingKey.js'; -export * from './MappingKeyType.js'; -export * from './MappingType.js'; -export * from './MappingValue.js'; -export * from './MemberAccess.js'; -export * from './MemberAccessExpression.js'; -export * from './ModifierAttribute.js'; -export * from './ModifierAttributes.js'; -export * from './ModifierDefinition.js'; -export * from './ModifierInvocation.js'; -export * from './MultiplicativeExpression.js'; -export * from './NamedArgument.js'; -export * from './NamedArgumentGroup.js'; -export * from './NamedArguments.js'; -export * from './NamedArgumentsDeclaration.js'; -export * from './NamedImport.js'; -export * from './NewExpression.js'; -export * from './NumberUnit.js'; -export * from './OrExpression.js'; -export * from './OverridePaths.js'; -export * from './OverridePathsDeclaration.js'; -export * from './OverrideSpecifier.js'; -export * from './Parameter.js'; -export * from './Parameters.js'; -export * from './ParametersDeclaration.js'; -export * from './PathImport.js'; -export * from './PositionalArguments.js'; -export * from './PositionalArgumentsDeclaration.js'; -export * from './PostfixExpression.js'; -export * from './Pragma.js'; -export * from './PragmaDirective.js'; -export * from './PrefixExpression.js'; -export * from './ReceiveFunctionAttribute.js'; -export * from './ReceiveFunctionAttributes.js'; -export * from './ReceiveFunctionDefinition.js'; -export * from './ReturnsDeclaration.js'; -export * from './ReturnStatement.js'; -export * from './RevertStatement.js'; -export * from './ShiftExpression.js'; -export * from './SourceUnit.js'; -export * from './SourceUnitMember.js'; -export * from './SourceUnitMembers.js'; -export * from './Statement.js'; -export * from './Statements.js'; -export * from './StateVariableAttribute.js'; -export * from './StateVariableAttributes.js'; -export * from './StateVariableDefinition.js'; -export * from './StateVariableDefinitionValue.js'; -export * from './StorageLocation.js'; -export * from './StringExpression.js'; -export * from './StringLiteral.js'; -export * from './StringLiterals.js'; -export * from './StructDefinition.js'; -export * from './StructMember.js'; -export * from './StructMembers.js'; -export * from './ThrowStatement.js'; -export * from './TryStatement.js'; -export * from './TupleDeconstructionElement.js'; -export * from './TupleDeconstructionElements.js'; -export * from './TupleDeconstructionStatement.js'; -export * from './TupleExpression.js'; -export * from './TupleMember.js'; -export * from './TupleValue.js'; -export * from './TupleValues.js'; -export * from './TypedTupleMember.js'; -export * from './TypeExpression.js'; -export * from './TypeName.js'; -export * from './UncheckedBlock.js'; -export * from './UnicodeStringLiteral.js'; -export * from './UnicodeStringLiterals.js'; -export * from './UnnamedFunctionAttribute.js'; -export * from './UnnamedFunctionAttributes.js'; -export * from './UnnamedFunctionDefinition.js'; -export * from './UntypedTupleMember.js'; -export * from './UserDefinedValueTypeDefinition.js'; -export * from './UsingAlias.js'; -export * from './UsingClause.js'; -export * from './UsingDeconstruction.js'; -export * from './UsingDeconstructionSymbol.js'; -export * from './UsingDeconstructionSymbols.js'; -export * from './UsingDirective.js'; -export * from './UsingOperator.js'; -export * from './UsingTarget.js'; -export * from './VariableDeclarationStatement.js'; -export * from './VariableDeclarationType.js'; -export * from './VariableDeclarationValue.js'; -export * from './VersionComparator.js'; -export * from './VersionExpression.js'; -export * from './VersionExpressionSet.js'; -export * from './VersionExpressionSets.js'; -export * from './VersionPragma.js'; -export * from './VersionRange.js'; -export * from './VersionSpecifiers.js'; -export * from './WhileStatement.js'; -export * from './YulArguments.js'; -export * from './YulAssignmentOperator.js'; -export * from './YulBlock.js'; -export * from './YulBreakStatement.js'; -export * from './YulBuiltInFunction.js'; -export * from './YulColonEqual.js'; -export * from './YulContinueStatement.js'; -export * from './YulDefaultCase.js'; -export * from './YulExpression.js'; -export * from './YulForStatement.js'; -export * from './YulFunctionCallExpression.js'; -export * from './YulFunctionDefinition.js'; -export * from './YulIfStatement.js'; -export * from './YulLabel.js'; -export * from './YulLeaveStatement.js'; -export * from './YulLiteral.js'; -export * from './YulParameters.js'; -export * from './YulParametersDeclaration.js'; -export * from './YulPath.js'; -export * from './YulPathComponent.js'; -export * from './YulPaths.js'; -export * from './YulReturnsDeclaration.js'; -export * from './YulReturnVariables.js'; -export * from './YulStackAssignmentStatement.js'; -export * from './YulStatement.js'; -export * from './YulStatements.js'; -export * from './YulSwitchCase.js'; -export * from './YulSwitchCases.js'; -export * from './YulSwitchStatement.js'; -export * from './YulValueCase.js'; -export * from './YulVariableAssignmentStatement.js'; -export * from './YulVariableDeclarationStatement.js'; -export * from './YulVariableDeclarationValue.js'; diff --git a/src/slang-printers/create-binary-operation-printer.ts b/src/slang-printers/create-binary-operation-printer.ts index 19d0b4433..e6c7213f0 100644 --- a/src/slang-printers/create-binary-operation-printer.ts +++ b/src/slang-printers/create-binary-operation-printer.ts @@ -2,7 +2,7 @@ import { doc } from 'prettier'; import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, BinaryOperation } from '../types.js'; +import type { AstNode, BinaryOperation } from '../types'; const { group, line } = doc.builders; diff --git a/src/slang-printers/print-binary-operation.ts b/src/slang-printers/print-binary-operation.ts index 89833fbce..6a8903454 100644 --- a/src/slang-printers/print-binary-operation.ts +++ b/src/slang-printers/print-binary-operation.ts @@ -4,7 +4,7 @@ import { createBinaryOperationPrinter } from './create-binary-operation-printer. import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, BinaryOperation } from '../types.js'; +import type { AstNode, BinaryOperation } from '../types'; const { group, indent } = doc.builders; diff --git a/src/slang-printers/print-comments.ts b/src/slang-printers/print-comments.ts index 33a14aca2..4e26ca68e 100644 --- a/src/slang-printers/print-comments.ts +++ b/src/slang-printers/print-comments.ts @@ -3,8 +3,8 @@ import { printComment } from '../slang-comments/printer.js'; import { isPrettier2 } from '../slang-utils/backward-compatibility.js'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, Comment } from '../types.js'; -import type { DocV2 } from './types.js'; +import type { AstNode, Comment } from '../types'; +import type { DocV2 } from './types'; const { join, line } = doc.builders; diff --git a/src/slang-printers/print-comparison-operation.ts b/src/slang-printers/print-comparison-operation.ts index 2bfce07df..c6b7eef4c 100644 --- a/src/slang-printers/print-comparison-operation.ts +++ b/src/slang-printers/print-comparison-operation.ts @@ -5,7 +5,7 @@ import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; import { createBinaryOperationPrinter } from './create-binary-operation-printer.js'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, BinaryOperation } from '../types.js'; +import type { AstNode, BinaryOperation } from '../types'; const { group, indent } = doc.builders; diff --git a/src/slang-printers/print-function.ts b/src/slang-printers/print-function.ts index a9b9e1ebb..f820bd833 100644 --- a/src/slang-printers/print-function.ts +++ b/src/slang-printers/print-function.ts @@ -1,7 +1,7 @@ import { doc } from 'prettier'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, FunctionLike } from '../types.js'; +import type { AstNode, FunctionLike } from '../types'; import type { FunctionDefinition } from '../slang-nodes'; const { dedent, group, indent, line } = doc.builders; diff --git a/src/slang-printers/print-logical-operation.ts b/src/slang-printers/print-logical-operation.ts index a1e855e25..ff19f9ec3 100644 --- a/src/slang-printers/print-logical-operation.ts +++ b/src/slang-printers/print-logical-operation.ts @@ -5,7 +5,7 @@ import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; import { createBinaryOperationPrinter } from './create-binary-operation-printer.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, BinaryOperation } from '../types.js'; +import type { AstNode, BinaryOperation } from '../types'; const { group, indent } = doc.builders; diff --git a/src/slang-printers/print-preserving-empty-lines.ts b/src/slang-printers/print-preserving-empty-lines.ts index b4c94a568..a0e5bcd11 100644 --- a/src/slang-printers/print-preserving-empty-lines.ts +++ b/src/slang-printers/print-preserving-empty-lines.ts @@ -7,7 +7,7 @@ import { import { locEnd } from '../slang-utils/loc.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode } from '../types.js'; +import type { AstNode } from '../types'; const { hardline } = doc.builders; diff --git a/src/slang-utils/is-binary-operation.ts b/src/slang-utils/is-binary-operation.ts index 9e3af39ea..81bfe2a65 100644 --- a/src/slang-utils/is-binary-operation.ts +++ b/src/slang-utils/is-binary-operation.ts @@ -1,7 +1,7 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { createKindCheckFunction } from './create-kind-check-function.js'; -import type { AstNode, BinaryOperation } from '../types.js'; -import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import type { AstNode, BinaryOperation } from '../types'; export const isBinaryOperation = createKindCheckFunction([ NonterminalKind.AdditiveExpression, diff --git a/src/slang-utils/is-comment.ts b/src/slang-utils/is-comment.ts index dd43bd162..05a51abf6 100644 --- a/src/slang-utils/is-comment.ts +++ b/src/slang-utils/is-comment.ts @@ -2,7 +2,7 @@ import { TerminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { createKindCheckFunction } from './create-kind-check-function.js'; import type { Node } from '@nomicfoundation/slang/cst'; -import type { AstNode, BlockComment, Comment, LineComment } from '../types.js'; +import type { AstNode, BlockComment, Comment, LineComment } from '../types'; export const isBlockComment = createKindCheckFunction([ TerminalKind.MultiLineComment, diff --git a/src/slang-utils/metadata.ts b/src/slang-utils/metadata.ts index 9ac2ee612..9c52e9437 100644 --- a/src/slang-utils/metadata.ts +++ b/src/slang-utils/metadata.ts @@ -2,8 +2,8 @@ import { TerminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { NodeType } from '@nomicfoundation/slang/cst/index.js'; import { isComment } from './is-comment.js'; -import type { Node } from '@nomicfoundation/slang/cst/index.js'; -import type { AstNode, Comment, Metadata, SlangAstNode } from '../types.js'; +import type { Node } from '@nomicfoundation/slang/cst'; +import type { AstNode, Comment, Metadata, SlangAstNode } from '../types'; function getLeadingOffset(children: Node[]): number { let offset = 0; diff --git a/src/slang-utils/sort-function-attributes.ts b/src/slang-utils/sort-function-attributes.ts index 6ad5f67c9..62ab11f3a 100644 --- a/src/slang-utils/sort-function-attributes.ts +++ b/src/slang-utils/sort-function-attributes.ts @@ -1,4 +1,5 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; + import type { SortableAttribute, SortableVariant } from './types'; const visibilityKeyWords = new Set([ diff --git a/src/slang-utils/types.d.ts b/src/slang-utils/types.d.ts index b283c9457..0da419d7f 100644 --- a/src/slang-utils/types.d.ts +++ b/src/slang-utils/types.d.ts @@ -1,3 +1,4 @@ +import type { util } from 'prettier'; import type { ConstructorAttribute, FallbackFunctionAttribute, @@ -10,7 +11,6 @@ import type { OverrideSpecifier, ModifierInvocation } from '../slang-nodes'; -import type { util } from 'prettier'; import type { AstNode, Comment } from '../types'; type SortableAttribute = diff --git a/src/slangParser.ts b/src/slangParser.ts index 4b5232da8..0800a812a 100644 --- a/src/slangParser.ts +++ b/src/slangParser.ts @@ -6,9 +6,9 @@ import { SourceUnit as SlangSourceUnit } from '@nomicfoundation/slang/ast/index. import coerce from 'semver/functions/coerce.js'; import { SourceUnit } from './slang-nodes/SourceUnit.js'; -import type { NonterminalNode } from '@nomicfoundation/slang/cst/index.js'; +import type { NonterminalNode } from '@nomicfoundation/slang/cst'; import type { Parser, ParserOptions } from 'prettier'; -import type { AstNode } from './types.js'; +import type { AstNode } from './types'; function parse( text: string, diff --git a/src/slangPrinter.ts b/src/slangPrinter.ts index 23258b8e8..43f1cf92a 100644 --- a/src/slangPrinter.ts +++ b/src/slangPrinter.ts @@ -3,7 +3,7 @@ import { isBlockComment } from './slang-utils/is-comment.js'; import { locEnd, locStart } from './slang-utils/loc.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, Comment } from './types.js'; +import type { AstNode, Comment } from './types'; let checked = false; diff --git a/src/types.d.ts b/src/types.d.ts index bd925c8ba..913619aa4 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -1,7 +1,7 @@ -import type { kinds } from '@nomicfoundation/slang/napi-bindings/generated/index.js'; -import type * as ast from '@nomicfoundation/slang/ast/index.js'; +import type { kinds } from '@nomicfoundation/slang/napi-bindings/generated'; +import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type * as nodes from './slang-nodes/index.js'; +import type * as nodes from './slang-nodes'; // Adding our own options to prettier's `ParserOptions` interface. declare module 'prettier' { From 737256e443b768267bf2d73e1b98908bf9268d55 Mon Sep 17 00:00:00 2001 From: Klaus Date: Fri, 2 Aug 2024 19:40:10 +1200 Subject: [PATCH 111/160] while statement comments --- .../handlers/handleIfStatementComments.ts | 1 + .../handlers/handleWhileStatementComments.ts | 12 +++++++++++- .../handlers/handleYulBlockComments.ts | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/slang-comments/handlers/handleIfStatementComments.ts b/src/slang-comments/handlers/handleIfStatementComments.ts index 1d96a7f6a..0f87aaefa 100644 --- a/src/slang-comments/handlers/handleIfStatementComments.ts +++ b/src/slang-comments/handlers/handleIfStatementComments.ts @@ -66,5 +66,6 @@ export default function handleIfStatementComments({ } return true; } + return false; } diff --git a/src/slang-comments/handlers/handleWhileStatementComments.ts b/src/slang-comments/handlers/handleWhileStatementComments.ts index 7ca332ea4..90437cd7c 100644 --- a/src/slang-comments/handlers/handleWhileStatementComments.ts +++ b/src/slang-comments/handlers/handleWhileStatementComments.ts @@ -1,10 +1,11 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { util } from 'prettier'; import { getNextNonSpaceNonCommentCharacter } from '../../slang-utils/backward-compatibility.js'; +import addHubNodeFirstComment from './add-hub-node-first-comment.js'; import type { HandlerParams } from './types'; -const { addTrailingComment } = util; +const { addLeadingComment, addTrailingComment } = util; export default function handleWhileStatementComments({ text, @@ -31,5 +32,14 @@ export default function handleWhileStatementComments({ return true; } + if (enclosingNode.body === followingNode) { + if (followingNode.variant.kind === NonterminalKind.Block) { + addHubNodeFirstComment(followingNode.variant.statements, comment); + } else { + addLeadingComment(followingNode, comment); + } + return true; + } + return false; } diff --git a/src/slang-comments/handlers/handleYulBlockComments.ts b/src/slang-comments/handlers/handleYulBlockComments.ts index baf6bd16c..5a6786791 100644 --- a/src/slang-comments/handlers/handleYulBlockComments.ts +++ b/src/slang-comments/handlers/handleYulBlockComments.ts @@ -30,5 +30,6 @@ export default function handleYulBlockComments({ addLeadingComment(followingNode.items[0], comment); return true; } + return false; } From c1cf6f6f4a8c1181bb362eff98b520db8339c050 Mon Sep 17 00:00:00 2001 From: Klaus Date: Sat, 3 Aug 2024 11:33:06 +1200 Subject: [PATCH 112/160] old comment resolution for if statements matches new comment resolution for if statements --- src/prettier-comments/language-js/comments.js | 12 ++++++++++-- .../format/IndexOf/__snapshots__/format.test.js.snap | 10 ++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/prettier-comments/language-js/comments.js b/src/prettier-comments/language-js/comments.js index 7b0003828..f2dfe5dcf 100644 --- a/src/prettier-comments/language-js/comments.js +++ b/src/prettier-comments/language-js/comments.js @@ -265,8 +265,16 @@ function handleIfStatementComments( return true; } - if (followingNode.type === "ExpressionStatement") { - addBlockStatementFirstComment(followingNode, comment); + if (enclosingNode.trueBody === followingNode) { + if (followingNode.type === "Block") { + if(followingNode.statements.length === 0) { + addDanglingComment(followingNode, comment); + } else { + addLeadingComment(followingNode.statements[0], comment); + } + } else { + addLeadingComment(followingNode, comment); + } return true; } diff --git a/tests/format/IndexOf/__snapshots__/format.test.js.snap b/tests/format/IndexOf/__snapshots__/format.test.js.snap index 8704a8bb6..cb8ef152b 100644 --- a/tests/format/IndexOf/__snapshots__/format.test.js.snap +++ b/tests/format/IndexOf/__snapshots__/format.test.js.snap @@ -99,17 +99,15 @@ contract IndexOf { if (a.length < 1 || b.length < 1 || (b.length > a.length)) { whatwastheval = -1; return -1; - } else if ( - a.length > (2 ** 128 - 1) - ) // since we have to be able to return -1 (if the char isn't found or input error), this function must return an "int" type with a max length of (2^128 - 1) - { + } else if (a.length > (2 ** 128 - 1)) { + // since we have to be able to return -1 (if the char isn't found or input error), this function must return an "int" type with a max length of (2^128 - 1) whatwastheval = -1; return -1; } else { uint subindex = 0; for (uint i = 0; i < a.length; i++) { - if (a[i] == b[0]) // found the first char of b - { + if (a[i] == b[0]) { + // found the first char of b subindex = 1; while ( subindex < b.length && From 811f69defb805e7409df48c51e871abff1ec8723 Mon Sep 17 00:00:00 2001 From: Klaus Date: Sat, 3 Aug 2024 17:39:32 +1200 Subject: [PATCH 113/160] adding missing printers --- src/slang-nodes/VersionRange.ts | 17 ++++++++++------- src/slang-nodes/YulColonEqual.ts | 11 +++-------- src/slang-nodes/YulLeaveStatement.ts | 11 +++-------- tests/format/AssemblyV0.4.26/Assembly.sol | 2 +- .../__snapshots__/format.test.js.snap | 8 ++++---- tests/format/AssemblyV0.4.26/format.test.js | 2 +- tests/format/Pragma/Pragma.sol | 1 + .../Pragma/__snapshots__/format.test.js.snap | 2 ++ 8 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/slang-nodes/VersionRange.ts b/src/slang-nodes/VersionRange.ts index 72110ee29..4b55c113d 100644 --- a/src/slang-nodes/VersionRange.ts +++ b/src/slang-nodes/VersionRange.ts @@ -3,8 +3,8 @@ import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { VersionExpression } from './VersionExpression.js'; import type * as ast from '@nomicfoundation/slang/ast'; -import type { /*AstPath,*/ Doc /*, ParserOptions*/ } from 'prettier'; -import type { SlangNode } from '../types'; +import type { AstPath, Doc } from 'prettier'; +import type { AstNode, SlangNode } from '../types'; export class VersionRange implements SlangNode { readonly kind = NonterminalKind.VersionRange; @@ -34,11 +34,14 @@ export class VersionRange implements SlangNode { } // TODO: implement print - print(/* + print( path: AstPath, - print: (path: AstPath) => Doc, - options: ParserOptions - */): Doc { - return ['TODO: VersionRange']; + print: (path: AstPath) => Doc + ): Doc { + return [ + path.call(print, 'leftOperand'), + ` ${this.operator} `, + path.call(print, 'rightOperand') + ]; } } diff --git a/src/slang-nodes/YulColonEqual.ts b/src/slang-nodes/YulColonEqual.ts index 806cad10e..0b7468f64 100644 --- a/src/slang-nodes/YulColonEqual.ts +++ b/src/slang-nodes/YulColonEqual.ts @@ -2,7 +2,7 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata } from '../slang-utils/metadata.js'; import type * as ast from '@nomicfoundation/slang/ast'; -import type { /*AstPath,*/ Doc /*, ParserOptions*/ } from 'prettier'; +import type { Doc } from 'prettier'; import type { SlangNode } from '../types'; export class YulColonEqual implements SlangNode { @@ -26,12 +26,7 @@ export class YulColonEqual implements SlangNode { this.loc = metadata.loc; } - // TODO: implement print - print(/* - path: AstPath, - print: (path: AstPath) => Doc, - options: ParserOptions - */): Doc { - return ['TODO: YulColonEqual']; + print(): Doc { + return `${this.colon}${this.equal}`; } } diff --git a/src/slang-nodes/YulLeaveStatement.ts b/src/slang-nodes/YulLeaveStatement.ts index 55a93ff27..c2a1c3653 100644 --- a/src/slang-nodes/YulLeaveStatement.ts +++ b/src/slang-nodes/YulLeaveStatement.ts @@ -2,7 +2,7 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata } from '../slang-utils/metadata.js'; import type * as ast from '@nomicfoundation/slang/ast'; -import type { /*AstPath,*/ Doc /*, ParserOptions*/ } from 'prettier'; +import type { Doc } from 'prettier'; import type { SlangNode } from '../types'; export class YulLeaveStatement implements SlangNode { @@ -23,12 +23,7 @@ export class YulLeaveStatement implements SlangNode { this.loc = metadata.loc; } - // TODO: implement print - print(/* - path: AstPath, - print: (path: AstPath) => Doc, - options: ParserOptions - */): Doc { - return ['TODO: YulLeaveStatement']; + print(): Doc { + return this.leaveKeyword; } } diff --git a/tests/format/AssemblyV0.4.26/Assembly.sol b/tests/format/AssemblyV0.4.26/Assembly.sol index dddccb54c..a417cad4c 100644 --- a/tests/format/AssemblyV0.4.26/Assembly.sol +++ b/tests/format/AssemblyV0.4.26/Assembly.sol @@ -25,7 +25,7 @@ assembly{ // but the assembler thinks it is 1 because it reads // from top to bottom. // Accessing the stack variable x here will lead to errors. - x := 9 + x : = 9 jump(three) two: 7 // push something onto the stack diff --git a/tests/format/AssemblyV0.4.26/__snapshots__/format.test.js.snap b/tests/format/AssemblyV0.4.26/__snapshots__/format.test.js.snap index d249ad2e4..4055715a0 100644 --- a/tests/format/AssemblyV0.4.26/__snapshots__/format.test.js.snap +++ b/tests/format/AssemblyV0.4.26/__snapshots__/format.test.js.snap @@ -3,7 +3,7 @@ exports[`Assembly.sol - {"compiler":"0.4.26"} format 1`] = ` ====================================options===================================== compiler: "0.4.26" -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -34,7 +34,7 @@ assembly{ // but the assembler thinks it is 1 because it reads // from top to bottom. // Accessing the stack variable x here will lead to errors. - x := 9 + x : = 9 jump(three) two: 7 // push something onto the stack @@ -113,7 +113,7 @@ contract MultipleAssemblyAssignment { b := 2 } - let i, j := bar() + let i } } } @@ -121,7 +121,7 @@ contract MultipleAssemblyAssignment { contract AssemblyStackAssignment { function f() public { assembly { - 4 =: y + 4 } } } diff --git a/tests/format/AssemblyV0.4.26/format.test.js b/tests/format/AssemblyV0.4.26/format.test.js index 94898ac13..85c6f9a33 100644 --- a/tests/format/AssemblyV0.4.26/format.test.js +++ b/tests/format/AssemblyV0.4.26/format.test.js @@ -1 +1 @@ -runFormatTest(import.meta, ['solidity-parse'], { compiler: '0.4.26' }); +runFormatTest(import.meta, ['slang'], { compiler: '0.4.26' }); diff --git a/tests/format/Pragma/Pragma.sol b/tests/format/Pragma/Pragma.sol index 9ba96701f..83f9315d5 100644 --- a/tests/format/Pragma/Pragma.sol +++ b/tests/format/Pragma/Pragma.sol @@ -6,5 +6,6 @@ pragma solidity >=0.4.21<0.6.0; pragma solidity ^ 0.4.21 ; pragma solidity ~ 0.4.21 ; pragma solidity ^0.5.0 || ^0.6.0 || ^0.7.0 ; +pragma solidity 0.5.0 - 0.6.0 ; pragma experimental ABIEncoderV2; pragma abicoder v2; diff --git a/tests/format/Pragma/__snapshots__/format.test.js.snap b/tests/format/Pragma/__snapshots__/format.test.js.snap index 69e0101b1..99a4c4664 100644 --- a/tests/format/Pragma/__snapshots__/format.test.js.snap +++ b/tests/format/Pragma/__snapshots__/format.test.js.snap @@ -14,6 +14,7 @@ pragma solidity >=0.4.21<0.6.0; pragma solidity ^ 0.4.21 ; pragma solidity ~ 0.4.21 ; pragma solidity ^0.5.0 || ^0.6.0 || ^0.7.0 ; +pragma solidity 0.5.0 - 0.6.0 ; pragma experimental ABIEncoderV2; pragma abicoder v2; @@ -26,6 +27,7 @@ pragma solidity >=0.4.21 <0.6.0; pragma solidity ^0.4.21; pragma solidity ~0.4.21; pragma solidity ^0.5.0 || ^0.6.0 || ^0.7.0; +pragma solidity 0.5.0 - 0.6.0; pragma experimental ABIEncoderV2; pragma abicoder v2; From 793074eca969bab58f2cb0deef66760ee3a7fada Mon Sep 17 00:00:00 2001 From: Klaus Date: Sat, 3 Aug 2024 17:42:12 +1200 Subject: [PATCH 114/160] simplifying printString based on prettier's changes to the same function --- src/slang-printers/print-string.ts | 39 ++++++++++++------------------ src/slang-printers/types.d.ts | 7 +----- 2 files changed, 16 insertions(+), 30 deletions(-) diff --git a/src/slang-printers/print-string.ts b/src/slang-printers/print-string.ts index 7f77aa68c..eed964eb8 100644 --- a/src/slang-printers/print-string.ts +++ b/src/slang-printers/print-string.ts @@ -1,39 +1,30 @@ import { util } from 'prettier'; import type { ParserOptions } from 'prettier'; -import type { QuoteRegex } from './types'; import type { AstNode } from '../types'; -const double: QuoteRegex = { quote: '"', regex: /"/g }; -const single: QuoteRegex = { quote: "'", regex: /'/g }; +const SINGLE_QUOTE: util.Quote = "'"; +const DOUBLE_QUOTE: util.Quote = '"'; export function printString( rawContent: string, options: ParserOptions ): string { - const preferred = options.singleQuote ? single : double; - const alternate = preferred === single ? double : single; - - let shouldUseAlternateQuote = false; - - // If `rawContent` contains at least one of the quote preferred for enclosing - // the string, we might want to enclose with the alternate quote instead, to - // minimize the number of escaped quotes. - // Also check for the alternate quote, to determine if we're allowed to swap - // the quotes on a DirectiveLiteral. - if ( - rawContent.includes(preferred.quote) || - rawContent.includes(alternate.quote) - ) { - const numPreferredQuotes = (rawContent.match(preferred.regex) || []).length; - const numAlternateQuotes = (rawContent.match(alternate.regex) || []).length; - - shouldUseAlternateQuote = numPreferredQuotes > numAlternateQuotes; + const preferred = options.singleQuote ? SINGLE_QUOTE : DOUBLE_QUOTE; + const alternate = preferred === SINGLE_QUOTE ? DOUBLE_QUOTE : SINGLE_QUOTE; + + let preferredQuoteCount = 0; + let alternateQuoteCount = 0; + for (const character of rawContent) { + if (character === preferred) { + preferredQuoteCount++; + } else if (character === alternate) { + alternateQuoteCount++; + } } - const enclosingQuote = shouldUseAlternateQuote - ? alternate.quote - : preferred.quote; + const enclosingQuote = + preferredQuoteCount > alternateQuoteCount ? alternate : preferred; // It might sound unnecessary to use `makeString` even if the string already // is enclosed with `enclosingQuote`, but it isn't. The string could contain diff --git a/src/slang-printers/types.d.ts b/src/slang-printers/types.d.ts index ffc22a28f..65ef7ee4f 100644 --- a/src/slang-printers/types.d.ts +++ b/src/slang-printers/types.d.ts @@ -1,4 +1,4 @@ -import type { Doc, util } from 'prettier'; +import type { Doc } from 'prettier'; interface PrintSeparatedOptions { firstSeparator?: Doc; @@ -8,8 +8,3 @@ interface PrintSeparatedOptions { } type DocV2 = Doc[] & { parts: Doc[] }; - -interface QuoteRegex { - quote: util.Quote; - regex: RegExp; -} From 8999b7a5cda76fce936daee3882566ddd78c6290 Mon Sep 17 00:00:00 2001 From: Klaus Date: Sat, 3 Aug 2024 18:42:47 +1200 Subject: [PATCH 115/160] rename lower camel case files --- ...ndleBlockComments.ts => handle-block-comments.ts} | 2 +- ...nts.ts => handle-contract-definition-comments.ts} | 2 +- ...ntComments.ts => handle-if-statement-comments.ts} | 2 +- ....ts => handle-parameters-declaration-comments.ts} | 2 +- ...omments.ts => handle-while-statement-comments.ts} | 2 +- ...BlockComments.ts => handle-yul-block-comments.ts} | 0 src/slang-comments/handlers/index.ts | 12 ++++++------ 7 files changed, 11 insertions(+), 11 deletions(-) rename src/slang-comments/handlers/{handleBlockComments.ts => handle-block-comments.ts} (94%) rename src/slang-comments/handlers/{handleContractDefinitionComments.ts => handle-contract-definition-comments.ts} (97%) rename src/slang-comments/handlers/{handleIfStatementComments.ts => handle-if-statement-comments.ts} (97%) rename src/slang-comments/handlers/{handleParametersDeclarationComments.ts => handle-parameters-declaration-comments.ts} (93%) rename src/slang-comments/handlers/{handleWhileStatementComments.ts => handle-while-statement-comments.ts} (96%) rename src/slang-comments/handlers/{handleYulBlockComments.ts => handle-yul-block-comments.ts} (100%) diff --git a/src/slang-comments/handlers/handleBlockComments.ts b/src/slang-comments/handlers/handle-block-comments.ts similarity index 94% rename from src/slang-comments/handlers/handleBlockComments.ts rename to src/slang-comments/handlers/handle-block-comments.ts index e4d12ef1e..37d59d8f2 100644 --- a/src/slang-comments/handlers/handleBlockComments.ts +++ b/src/slang-comments/handlers/handle-block-comments.ts @@ -2,7 +2,7 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { util } from 'prettier'; import addHubNodeFirstComment from './add-hub-node-first-comment.js'; -import type { HandlerParams } from './types'; +import type { HandlerParams } from './types.js'; const { addDanglingComment, addTrailingComment } = util; diff --git a/src/slang-comments/handlers/handleContractDefinitionComments.ts b/src/slang-comments/handlers/handle-contract-definition-comments.ts similarity index 97% rename from src/slang-comments/handlers/handleContractDefinitionComments.ts rename to src/slang-comments/handlers/handle-contract-definition-comments.ts index ba986bf55..2c508ac08 100644 --- a/src/slang-comments/handlers/handleContractDefinitionComments.ts +++ b/src/slang-comments/handlers/handle-contract-definition-comments.ts @@ -4,7 +4,7 @@ import { getNextNonSpaceNonCommentCharacter } from '../../slang-utils/backward-c import addHubNodeFirstComment from './add-hub-node-first-comment.js'; import addHubNodeLastComment from './add-hub-node-last-comment.js'; -import type { HandlerParams } from './types'; +import type { HandlerParams } from './types.js'; const { addLeadingComment, addTrailingComment } = util; diff --git a/src/slang-comments/handlers/handleIfStatementComments.ts b/src/slang-comments/handlers/handle-if-statement-comments.ts similarity index 97% rename from src/slang-comments/handlers/handleIfStatementComments.ts rename to src/slang-comments/handlers/handle-if-statement-comments.ts index 0f87aaefa..e76a3c370 100644 --- a/src/slang-comments/handlers/handleIfStatementComments.ts +++ b/src/slang-comments/handlers/handle-if-statement-comments.ts @@ -4,7 +4,7 @@ import { getNextNonSpaceNonCommentCharacter } from '../../slang-utils/backward-c import addHubNodeFirstComment from './add-hub-node-first-comment.js'; import addHubNodeLastComment from './add-hub-node-last-comment.js'; -import type { HandlerParams } from './types'; +import type { HandlerParams } from './types.js'; const { addLeadingComment, addTrailingComment } = util; diff --git a/src/slang-comments/handlers/handleParametersDeclarationComments.ts b/src/slang-comments/handlers/handle-parameters-declaration-comments.ts similarity index 93% rename from src/slang-comments/handlers/handleParametersDeclarationComments.ts rename to src/slang-comments/handlers/handle-parameters-declaration-comments.ts index 896d908d4..f9ec482e1 100644 --- a/src/slang-comments/handlers/handleParametersDeclarationComments.ts +++ b/src/slang-comments/handlers/handle-parameters-declaration-comments.ts @@ -2,7 +2,7 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import addHubNodeFirstComment from './add-hub-node-first-comment.js'; import addHubNodeLastComment from './add-hub-node-last-comment.js'; -import type { HandlerParams } from './types'; +import type { HandlerParams } from './types.js'; export default function handleBlockComments({ precedingNode, diff --git a/src/slang-comments/handlers/handleWhileStatementComments.ts b/src/slang-comments/handlers/handle-while-statement-comments.ts similarity index 96% rename from src/slang-comments/handlers/handleWhileStatementComments.ts rename to src/slang-comments/handlers/handle-while-statement-comments.ts index 90437cd7c..3ee56d574 100644 --- a/src/slang-comments/handlers/handleWhileStatementComments.ts +++ b/src/slang-comments/handlers/handle-while-statement-comments.ts @@ -3,7 +3,7 @@ import { util } from 'prettier'; import { getNextNonSpaceNonCommentCharacter } from '../../slang-utils/backward-compatibility.js'; import addHubNodeFirstComment from './add-hub-node-first-comment.js'; -import type { HandlerParams } from './types'; +import type { HandlerParams } from './types.js'; const { addLeadingComment, addTrailingComment } = util; diff --git a/src/slang-comments/handlers/handleYulBlockComments.ts b/src/slang-comments/handlers/handle-yul-block-comments.ts similarity index 100% rename from src/slang-comments/handlers/handleYulBlockComments.ts rename to src/slang-comments/handlers/handle-yul-block-comments.ts diff --git a/src/slang-comments/handlers/index.ts b/src/slang-comments/handlers/index.ts index ca0c013a3..0488a93af 100644 --- a/src/slang-comments/handlers/index.ts +++ b/src/slang-comments/handlers/index.ts @@ -1,9 +1,9 @@ -import handleBlockComments from './handleBlockComments.js'; -import handleContractDefinitionComments from './handleContractDefinitionComments.js'; -import handleIfStatementComments from './handleIfStatementComments.js'; -import handleParametersDeclarationComments from './handleParametersDeclarationComments.js'; -import handleWhileStatementComments from './handleWhileStatementComments.js'; -import handleYulBlockComments from './handleYulBlockComments.js'; +import handleBlockComments from './handle-block-comments.js'; +import handleContractDefinitionComments from './handle-contract-definition-comments.js'; +import handleIfStatementComments from './handle-if-statement-comments.js'; +import handleParametersDeclarationComments from './handle-parameters-declaration-comments.js'; +import handleWhileStatementComments from './handle-while-statement-comments.js'; +import handleYulBlockComments from './handle-yul-block-comments.js'; export default [ handleBlockComments, From d52ec2e08dace64ebf1ad6f8a02acba0242f2954 Mon Sep 17 00:00:00 2001 From: Klaus Date: Sun, 4 Aug 2024 17:33:08 +1200 Subject: [PATCH 116/160] comments after returns declaration belong outside the parentheses and it's too difficult to do it with the old parser --- tests/config/run-format-test.js | 4 +--- .../format/BasicIterator/__snapshots__/format.test.js.snap | 6 ++---- tests/format/BasicIterator/format.test.js | 2 +- tests/format/IndexOf/__snapshots__/format.test.js.snap | 6 ++---- tests/format/IndexOf/format.test.js | 2 +- 5 files changed, 7 insertions(+), 13 deletions(-) diff --git a/tests/config/run-format-test.js b/tests/config/run-format-test.js index 65afde5d1..75a7fe709 100644 --- a/tests/config/run-format-test.js +++ b/tests/config/run-format-test.js @@ -43,10 +43,8 @@ const unstableAstTests = new Map( const testsWithSlang = new Map( [ // "AllSolidityFeatures/AllSolidityFeatures.sol", - // "AssemblyV0.4.26/Assembly.sol", // TODO: Report to Nomic Foundation? - // "BasicIterator/BasicIterator.sol", // TODO: Fix solidity-parser comments + // "AssemblyV0.4.26/Assembly.sol", // TODO: Wait for Nomic Foundation's response // "Comments/Comments.sol", // TODO: finish Comments - "IndexOf/IndexOf.sol", // TODO: Finish comments and file level functions ].map((fixture) => { const [file, testSlang = () => true] = Array.isArray(fixture) ? fixture diff --git a/tests/format/BasicIterator/__snapshots__/format.test.js.snap b/tests/format/BasicIterator/__snapshots__/format.test.js.snap index 091266f11..7375872cd 100644 --- a/tests/format/BasicIterator/__snapshots__/format.test.js.snap +++ b/tests/format/BasicIterator/__snapshots__/format.test.js.snap @@ -3,7 +3,7 @@ exports[`BasicIterator.sol - {"compiler":"0.4.26"} format 1`] = ` ====================================options===================================== compiler: "0.4.26" -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -74,9 +74,7 @@ contract BasicIterator { function getSum() constant - returns ( - uint // "constant" just means this function returns something to the caller - ) + returns (uint) // "constant" just means this function returns something to the caller { // which is immediately followed by what type gets returned, in this case a full uint256 uint8 sum = 0; diff --git a/tests/format/BasicIterator/format.test.js b/tests/format/BasicIterator/format.test.js index 94898ac13..85c6f9a33 100644 --- a/tests/format/BasicIterator/format.test.js +++ b/tests/format/BasicIterator/format.test.js @@ -1 +1 @@ -runFormatTest(import.meta, ['solidity-parse'], { compiler: '0.4.26' }); +runFormatTest(import.meta, ['slang'], { compiler: '0.4.26' }); diff --git a/tests/format/IndexOf/__snapshots__/format.test.js.snap b/tests/format/IndexOf/__snapshots__/format.test.js.snap index cb8ef152b..3895e494a 100644 --- a/tests/format/IndexOf/__snapshots__/format.test.js.snap +++ b/tests/format/IndexOf/__snapshots__/format.test.js.snap @@ -3,7 +3,7 @@ exports[`IndexOf.sol - {"compiler":"0.4.26"} format 1`] = ` ====================================options===================================== compiler: "0.4.26" -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -89,9 +89,7 @@ contract IndexOf { string _a, string _b ) - returns ( - int // _a = string to search, _b = string we want to find - ) + returns (int) // _a = string to search, _b = string we want to find { bytes memory a = bytes(_a); bytes memory b = bytes(_b); diff --git a/tests/format/IndexOf/format.test.js b/tests/format/IndexOf/format.test.js index 94898ac13..85c6f9a33 100644 --- a/tests/format/IndexOf/format.test.js +++ b/tests/format/IndexOf/format.test.js @@ -1 +1 @@ -runFormatTest(import.meta, ['solidity-parse'], { compiler: '0.4.26' }); +runFormatTest(import.meta, ['slang'], { compiler: '0.4.26' }); From 817ca7aa728a7eeab216eb76f3345c40725e5dd6 Mon Sep 17 00:00:00 2001 From: Klaus Date: Mon, 5 Aug 2024 11:41:46 +1200 Subject: [PATCH 117/160] Throwing Slang Errors and only parsing valid code --- src/slang-comments/printer.ts | 6 +++--- src/slang-printers/print-comments.ts | 4 ++-- src/slangParser.ts | 17 ++++++++++------- src/slangPrinter.ts | 6 +++--- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/slang-comments/printer.ts b/src/slang-comments/printer.ts index 82d5f38de..c25cb2547 100644 --- a/src/slang-comments/printer.ts +++ b/src/slang-comments/printer.ts @@ -2,7 +2,7 @@ import { doc } from 'prettier'; import { isBlockComment, isLineComment } from '../slang-utils/is-comment.js'; import type { AstPath, Doc } from 'prettier'; -import type { Comment } from '../types'; +import type { AstNode, Comment } from '../types'; const { hardline, join, literalline } = doc.builders; @@ -28,8 +28,8 @@ function printIndentableBlockComment(comment: Comment): Doc { ); } -export function printComment(commentPath: AstPath): Doc { - const comment = commentPath.getNode() as Comment; +export function printComment(commentPath: AstPath): Doc { + const comment = commentPath.getNode()!; if (isLineComment(comment)) { return comment.value.trimEnd(); diff --git a/src/slang-printers/print-comments.ts b/src/slang-printers/print-comments.ts index 4e26ca68e..e931d4c6f 100644 --- a/src/slang-printers/print-comments.ts +++ b/src/slang-printers/print-comments.ts @@ -3,7 +3,7 @@ import { printComment } from '../slang-comments/printer.js'; import { isPrettier2 } from '../slang-utils/backward-compatibility.js'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, Comment } from '../types'; +import type { AstNode } from '../types'; import type { DocV2 } from './types'; const { join, line } = doc.builders; @@ -14,7 +14,7 @@ export function printComments(node: AstNode, path: AstPath): Doc[] { line, path .map((commentPath) => { - const comment = commentPath.getNode() as Comment; + const comment = commentPath.getNode()!; if (comment.trailing || comment.leading || comment.printed) { return ''; } diff --git a/src/slangParser.ts b/src/slangParser.ts index 0800a812a..6eaee643a 100644 --- a/src/slangParser.ts +++ b/src/slangParser.ts @@ -10,7 +10,7 @@ import type { NonterminalNode } from '@nomicfoundation/slang/cst'; import type { Parser, ParserOptions } from 'prettier'; import type { AstNode } from './types'; -function parse( +export default function parse( text: string, _parsers: Parser[] | ParserOptions, options = _parsers as ParserOptions @@ -24,11 +24,14 @@ function parse( : supportedVersions[supportedVersions.length - 1] ); - const ast = new SlangSourceUnit( - language.parse(NonterminalKind.SourceUnit, text).tree() as NonterminalNode - ); + const parseOutput = language.parse(NonterminalKind.SourceUnit, text); - return new SourceUnit(ast, 0, options); + if (parseOutput.isValid) { + return new SourceUnit( + new SlangSourceUnit(parseOutput.tree() as NonterminalNode), + 0, + options + ); + } + throw new Error(parseOutput.errors()[0].message()); } - -export default parse; diff --git a/src/slangPrinter.ts b/src/slangPrinter.ts index 43f1cf92a..d0f91f5c1 100644 --- a/src/slangPrinter.ts +++ b/src/slangPrinter.ts @@ -3,7 +3,7 @@ import { isBlockComment } from './slang-utils/is-comment.js'; import { locEnd, locStart } from './slang-utils/loc.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, Comment } from './types'; +import type { AstNode } from './types'; let checked = false; @@ -31,7 +31,7 @@ function hasNodeIgnoreComment(node: AstNode): boolean { function ignoreComments(path: AstPath): void { // TODO: remove undefined once we stop supporting prettier 2 - const node = path.getNode() as AstNode | null | undefined; + const node = path.getNode(); // We ignore anything that is not an object if (node === null || node === undefined || typeof node !== 'object') return; @@ -47,7 +47,7 @@ function ignoreComments(path: AstPath): void { // The key `comments` will contain every comment for this node case 'comments': path.each((commentPath) => { - const comment = commentPath.getNode() as Comment; + const comment = commentPath.getNode()!; comment.printed = true; }, 'comments'); break; From 88c5b1b494b3a611f431eb3826ba2fdf9962cfe9 Mon Sep 17 00:00:00 2001 From: Klaus Date: Tue, 6 Aug 2024 13:08:36 +1200 Subject: [PATCH 118/160] all constant strings are printed directly --- .eslintignore | 1 + .eslintrc | 7 +++- src/slang-nodes/ABICoderPragma.ts | 5 +-- src/slang-nodes/AddressType.ts | 5 +-- src/slang-nodes/ArrayExpression.ts | 12 +------ src/slang-nodes/ArrayTypeName.ts | 10 ++---- src/slang-nodes/AssemblyFlagsDeclaration.ts | 8 +---- src/slang-nodes/AssemblyStatement.ts | 5 +-- src/slang-nodes/Block.ts | 8 +---- src/slang-nodes/BreakStatement.ts | 9 +---- src/slang-nodes/CallOptionsExpression.ts | 13 +------ src/slang-nodes/CatchClause.ts | 5 +-- src/slang-nodes/CatchClauseError.ts | 6 +++- src/slang-nodes/ConditionalExpression.ts | 14 +++----- src/slang-nodes/ConstantDefinition.ts | 9 ----- src/slang-nodes/ConstructorDefinition.ts | 5 +-- src/slang-nodes/ContinueStatement.ts | 9 +---- src/slang-nodes/ContractDefinition.ts | 16 +++------ src/slang-nodes/ContractMembers.ts | 3 +- src/slang-nodes/DoWhileStatement.ts | 21 ++---------- src/slang-nodes/ElseBranch.ts | 5 +-- src/slang-nodes/EmitStatement.ts | 10 ++---- src/slang-nodes/EnumDefinition.ts | 15 +------- src/slang-nodes/ErrorDefinition.ts | 12 +------ src/slang-nodes/ErrorParametersDeclaration.ts | 8 +---- src/slang-nodes/EventDefinition.ts | 12 ++----- src/slang-nodes/EventParameter.ts | 2 +- src/slang-nodes/EventParametersDeclaration.ts | 8 +---- src/slang-nodes/ExperimentalPragma.ts | 5 +-- src/slang-nodes/ExponentiationExpression.ts | 4 +-- src/slang-nodes/ExpressionStatement.ts | 5 +-- src/slang-nodes/FallbackFunctionDefinition.ts | 5 +-- src/slang-nodes/ForStatement.ts | 13 ++----- src/slang-nodes/FunctionDefinition.ts | 5 +-- src/slang-nodes/FunctionType.ts | 5 +-- src/slang-nodes/IfStatement.ts | 13 ++----- src/slang-nodes/ImportAlias.ts | 5 +-- src/slang-nodes/ImportDeconstruction.ts | 13 ++----- .../ImportDeconstructionSymbols.ts | 34 +++++++++---------- src/slang-nodes/ImportDirective.ts | 12 +------ src/slang-nodes/IndexAccessEnd.ts | 5 +-- src/slang-nodes/IndexAccessExpression.ts | 10 ++---- src/slang-nodes/InheritanceSpecifier.ts | 5 +-- src/slang-nodes/InterfaceDefinition.ts | 15 ++------ src/slang-nodes/LibraryDefinition.ts | 13 ++----- src/slang-nodes/MappingType.ts | 13 ++----- src/slang-nodes/ModifierDefinition.ts | 16 ++------- src/slang-nodes/NamedArgument.ts | 5 +-- src/slang-nodes/NamedArgumentGroup.ts | 8 +---- src/slang-nodes/NamedArgumentsDeclaration.ts | 12 +------ src/slang-nodes/NamedImport.ts | 5 +-- src/slang-nodes/NewExpression.ts | 5 +-- src/slang-nodes/OverridePathsDeclaration.ts | 6 ---- src/slang-nodes/OverrideSpecifier.ts | 8 +---- src/slang-nodes/ParametersDeclaration.ts | 8 +---- .../PositionalArgumentsDeclaration.ts | 8 +---- src/slang-nodes/PragmaDirective.ts | 12 +------ src/slang-nodes/ReceiveFunctionDefinition.ts | 5 +-- src/slang-nodes/ReturnStatement.ts | 12 +------ src/slang-nodes/ReturnsDeclaration.ts | 5 +-- src/slang-nodes/RevertStatement.ts | 10 ++---- src/slang-nodes/StateVariableDefinition.ts | 5 +-- .../StateVariableDefinitionValue.ts | 7 ++-- src/slang-nodes/Statements.ts | 3 +- src/slang-nodes/StructDefinition.ts | 15 +------- src/slang-nodes/StructMember.ts | 5 +-- src/slang-nodes/ThrowStatement.ts | 9 +---- src/slang-nodes/TryStatement.ts | 5 +-- .../TupleDeconstructionStatement.ts | 21 ++---------- src/slang-nodes/TupleExpression.ts | 8 +---- src/slang-nodes/TypeExpression.ts | 9 ----- src/slang-nodes/UncheckedBlock.ts | 5 +-- src/slang-nodes/UnnamedFunctionDefinition.ts | 5 +-- .../UserDefinedValueTypeDefinition.ts | 15 +------- src/slang-nodes/UsingAlias.ts | 5 +-- src/slang-nodes/UsingDeconstruction.ts | 8 +---- src/slang-nodes/UsingDirective.ts | 16 +++------ .../VariableDeclarationStatement.ts | 5 +-- src/slang-nodes/VariableDeclarationValue.ts | 5 +-- src/slang-nodes/VersionPragma.ts | 5 +-- src/slang-nodes/WhileStatement.ts | 13 ++----- src/slang-nodes/YulBlock.ts | 8 +---- src/slang-nodes/YulBreakStatement.ts | 6 +--- src/slang-nodes/YulColonEqual.ts | 9 +---- src/slang-nodes/YulContinueStatement.ts | 6 +--- src/slang-nodes/YulDefaultCase.ts | 5 +-- src/slang-nodes/YulForStatement.ts | 5 +-- src/slang-nodes/YulFunctionCallExpression.ts | 10 ++---- src/slang-nodes/YulFunctionDefinition.ts | 7 ++-- src/slang-nodes/YulIfStatement.ts | 5 +-- src/slang-nodes/YulLabel.ts | 5 +-- src/slang-nodes/YulLeaveStatement.ts | 6 +--- src/slang-nodes/YulParametersDeclaration.ts | 8 +---- src/slang-nodes/YulStatements.ts | 3 +- src/slang-nodes/YulSwitchStatement.ts | 5 +-- src/slang-nodes/YulValueCase.ts | 10 +----- .../YulVariableDeclarationStatement.ts | 8 +---- src/slang-printers/print-comments.ts | 1 - src/slang-utils/create-hug-function.ts | 4 +-- src/types.d.ts | 6 ++-- tsconfig.json | 1 + 101 files changed, 155 insertions(+), 680 deletions(-) diff --git a/.eslintignore b/.eslintignore index d42818524..adae9ec7f 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,5 +1,6 @@ coverage/**/*.js dist/**/*.cjs +dist/**/*.js tests/**/*.snap tests/format/**/*.sol tests/format/Markdown/Markdown.md diff --git a/.eslintrc b/.eslintrc index 3122ce9e6..80ca5af98 100644 --- a/.eslintrc +++ b/.eslintrc @@ -8,7 +8,12 @@ "overrides": [ { "files": ["**/*.ts"], - "extends": ["prettier", "plugin:@typescript-eslint/recommended"], + "extends": [ + "prettier", + "plugin:@typescript-eslint/recommended", + "plugin:@typescript-eslint/stylistic", + "plugin:@typescript-eslint/recommended-type-checked" + ], "parser": "@typescript-eslint/parser", "plugins": ["@typescript-eslint"], "parserOptions": { diff --git a/src/slang-nodes/ABICoderPragma.ts b/src/slang-nodes/ABICoderPragma.ts index 8c8f5e050..32cdd4b51 100644 --- a/src/slang-nodes/ABICoderPragma.ts +++ b/src/slang-nodes/ABICoderPragma.ts @@ -12,14 +12,11 @@ export class ABICoderPragma implements SlangNode { loc; - abicoderKeyword: string; - version: string; constructor(ast: ast.ABICoderPragma, offset: number) { const metadata = getNodeMetadata(ast, offset); - this.abicoderKeyword = ast.abicoderKeyword.text; this.version = ast.version.text; this.comments = metadata.comments; @@ -27,6 +24,6 @@ export class ABICoderPragma implements SlangNode { } print(): Doc { - return `${this.abicoderKeyword} ${this.version}`; + return `abicoder ${this.version}`; } } diff --git a/src/slang-nodes/AddressType.ts b/src/slang-nodes/AddressType.ts index 14588d1dd..3bf7b369d 100644 --- a/src/slang-nodes/AddressType.ts +++ b/src/slang-nodes/AddressType.ts @@ -12,14 +12,11 @@ export class AddressType implements SlangNode { loc; - addressKeyword: string; - payableKeyword?: string; constructor(ast: ast.AddressType, offset: number) { const metadata = getNodeMetadata(ast, offset); - this.addressKeyword = ast.addressKeyword.text; this.payableKeyword = ast.payableKeyword?.text; this.comments = metadata.comments; @@ -27,6 +24,6 @@ export class AddressType implements SlangNode { } print(): Doc { - return `${this.addressKeyword}${this.payableKeyword ? ` ${this.payableKeyword}` : ''}`; + return ['address', this.payableKeyword ? ' payable' : '']; } } diff --git a/src/slang-nodes/ArrayExpression.ts b/src/slang-nodes/ArrayExpression.ts index 306abf0de..4679e4837 100644 --- a/src/slang-nodes/ArrayExpression.ts +++ b/src/slang-nodes/ArrayExpression.ts @@ -16,12 +16,8 @@ export class ArrayExpression implements SlangNode { loc; - openBracket: string; - items: ArrayValues; - closeBracket: string; - constructor( ast: ast.ArrayExpression, offset: number, @@ -30,9 +26,7 @@ export class ArrayExpression implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.openBracket = ast.openBracket.text; this.items = new ArrayValues(ast.items, offsets[0], options); - this.closeBracket = ast.closeBracket.text; metadata = updateMetadata(metadata, [this.items]); @@ -44,10 +38,6 @@ export class ArrayExpression implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return group([ - this.openBracket, - path.call(print, 'items'), - this.closeBracket - ]); + return group(['[', path.call(print, 'items'), ']']); } } diff --git a/src/slang-nodes/ArrayTypeName.ts b/src/slang-nodes/ArrayTypeName.ts index c903929c6..4773a574f 100644 --- a/src/slang-nodes/ArrayTypeName.ts +++ b/src/slang-nodes/ArrayTypeName.ts @@ -16,12 +16,8 @@ export class ArrayTypeName implements SlangNode { operand: TypeName; - openBracket: string; - index?: Expression; - closeBracket: string; - constructor( ast: ast.ArrayTypeName, offset: number, @@ -31,11 +27,9 @@ export class ArrayTypeName implements SlangNode { const { offsets } = metadata; this.operand = new TypeName(ast.operand, offsets[0], options); - this.openBracket = ast.openBracket.text; if (ast.index) { this.index = new Expression(ast.index, offsets[1], options); } - this.closeBracket = ast.closeBracket.text; metadata = updateMetadata(metadata, [this.operand, this.index]); @@ -49,9 +43,9 @@ export class ArrayTypeName implements SlangNode { ): Doc { return [ path.call(print, 'operand'), - this.openBracket, + '[', this.index ? path.call(print, 'index') : '', - this.closeBracket + ']' ]; } } diff --git a/src/slang-nodes/AssemblyFlagsDeclaration.ts b/src/slang-nodes/AssemblyFlagsDeclaration.ts index 792a39ef5..f66b0765f 100644 --- a/src/slang-nodes/AssemblyFlagsDeclaration.ts +++ b/src/slang-nodes/AssemblyFlagsDeclaration.ts @@ -13,12 +13,8 @@ export class AssemblyFlagsDeclaration implements SlangNode { loc; - openParen: string; - flags: AssemblyFlags; - closeParen: string; - constructor( ast: ast.AssemblyFlagsDeclaration, offset: number, @@ -27,9 +23,7 @@ export class AssemblyFlagsDeclaration implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.openParen = ast.openParen.text; this.flags = new AssemblyFlags(ast.flags, offsets[0], options); - this.closeParen = ast.closeParen.text; metadata = updateMetadata(metadata, [this.flags]); @@ -41,6 +35,6 @@ export class AssemblyFlagsDeclaration implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return [this.openParen, path.call(print, 'flags'), this.closeParen]; + return ['(', path.call(print, 'flags'), ')']; } } diff --git a/src/slang-nodes/AssemblyStatement.ts b/src/slang-nodes/AssemblyStatement.ts index 1ef0e0825..b5b6aa351 100644 --- a/src/slang-nodes/AssemblyStatement.ts +++ b/src/slang-nodes/AssemblyStatement.ts @@ -15,8 +15,6 @@ export class AssemblyStatement implements SlangNode { loc; - assemblyKeyword: string; - label?: StringLiteral; flags?: AssemblyFlagsDeclaration; @@ -31,7 +29,6 @@ export class AssemblyStatement implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.assemblyKeyword = ast.assemblyKeyword.text; let i = 0; if (ast.label) { this.label = new StringLiteral(ast.label, offsets[i], options); @@ -54,7 +51,7 @@ export class AssemblyStatement implements SlangNode { print: (path: AstPath) => Doc ): Doc { return [ - `${this.assemblyKeyword} `, + 'assembly ', this.label ? [path.call(print, 'label'), ' '] : '', this.flags ? [path.call(print, 'flags'), ' '] : '', path.call(print, 'body') diff --git a/src/slang-nodes/Block.ts b/src/slang-nodes/Block.ts index 99d8af64b..4b07724b9 100644 --- a/src/slang-nodes/Block.ts +++ b/src/slang-nodes/Block.ts @@ -13,19 +13,13 @@ export class Block implements SlangNode { loc; - openBrace: string; - statements: Statements; - closeBrace: string; - constructor(ast: ast.Block, offset: number, options: ParserOptions) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.openBrace = ast.openBrace.text; this.statements = new Statements(ast.statements, offsets[0], options); - this.closeBrace = ast.closeBrace.text; metadata = updateMetadata(metadata, [this.statements]); @@ -34,6 +28,6 @@ export class Block implements SlangNode { } print(path: AstPath, print: (path: AstPath) => Doc): Doc { - return [this.openBrace, path.call(print, 'statements'), this.closeBrace]; + return ['{', path.call(print, 'statements'), '}']; } } diff --git a/src/slang-nodes/BreakStatement.ts b/src/slang-nodes/BreakStatement.ts index 1a8a7006a..b65ef522c 100644 --- a/src/slang-nodes/BreakStatement.ts +++ b/src/slang-nodes/BreakStatement.ts @@ -12,21 +12,14 @@ export class BreakStatement implements SlangNode { loc; - breakKeyword: string; - - semicolon: string; - constructor(ast: ast.BreakStatement, offset: number) { const metadata = getNodeMetadata(ast, offset); - this.breakKeyword = ast.breakKeyword.text; - this.semicolon = ast.semicolon.text; - this.comments = metadata.comments; this.loc = metadata.loc; } print(): Doc { - return `${this.breakKeyword}${this.semicolon}`; + return 'break;'; } } diff --git a/src/slang-nodes/CallOptionsExpression.ts b/src/slang-nodes/CallOptionsExpression.ts index 57caf225a..44a1ee6ad 100644 --- a/src/slang-nodes/CallOptionsExpression.ts +++ b/src/slang-nodes/CallOptionsExpression.ts @@ -16,12 +16,8 @@ export class CallOptionsExpression implements SlangNode { operand: Expression; - openBrace: string; - options: CallOptions; - closeBrace: string; - constructor( ast: ast.CallOptionsExpression, offset: number, @@ -31,9 +27,7 @@ export class CallOptionsExpression implements SlangNode { const { offsets } = metadata; this.operand = new Expression(ast.operand, offsets[0], options); - this.openBrace = ast.openBrace.text; this.options = new CallOptions(ast.options, offsets[1], options); - this.closeBrace = ast.closeBrace.text; metadata = updateMetadata(metadata, [this.operand, this.options]); @@ -45,11 +39,6 @@ export class CallOptionsExpression implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return [ - path.call(print, 'operand'), - this.openBrace, - path.call(print, 'options'), - this.closeBrace - ]; + return [path.call(print, 'operand'), '{', path.call(print, 'options'), '}']; } } diff --git a/src/slang-nodes/CatchClause.ts b/src/slang-nodes/CatchClause.ts index b867c2624..472386680 100644 --- a/src/slang-nodes/CatchClause.ts +++ b/src/slang-nodes/CatchClause.ts @@ -14,8 +14,6 @@ export class CatchClause implements SlangNode { loc; - catchKeyword: string; - error?: CatchClauseError; body: Block; @@ -28,7 +26,6 @@ export class CatchClause implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.catchKeyword = ast.catchKeyword.text; let i = 0; if (ast.error) { this.error = new CatchClauseError(ast.error, offsets[i], options); @@ -47,7 +44,7 @@ export class CatchClause implements SlangNode { print: (path: AstPath) => Doc ): Doc { return [ - `${this.catchKeyword} `, + 'catch ', this.error ? path.call(print, 'error') : '', path.call(print, 'body') ]; diff --git a/src/slang-nodes/CatchClauseError.ts b/src/slang-nodes/CatchClauseError.ts index 9ad2856ad..52b660274 100644 --- a/src/slang-nodes/CatchClauseError.ts +++ b/src/slang-nodes/CatchClauseError.ts @@ -45,6 +45,10 @@ export class CatchClauseError implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return [`${this.name ?? ''}`, group(path.call(print, 'parameters')), ' ']; + return [ + this.name ? this.name : '', + group(path.call(print, 'parameters')), + ' ' + ]; } } diff --git a/src/slang-nodes/ConditionalExpression.ts b/src/slang-nodes/ConditionalExpression.ts index 42173d03c..64c9e3452 100644 --- a/src/slang-nodes/ConditionalExpression.ts +++ b/src/slang-nodes/ConditionalExpression.ts @@ -40,7 +40,7 @@ function experimentalTernaries( node.operand.variant.kind === NonterminalKind.TupleExpression ? operand : ifBreak(['(', printSeparatedItem(operand), ')'], operand), - ` ${node.questionMark}` + ' ?' ]); // To switch between "case-style" and "curious" ternaries we force a new line @@ -69,7 +69,7 @@ function experimentalTernaries( const falseExpression = path.call(print, 'falseExpression'); const falseExpressionDoc = [ isNested ? hardline : line, - node.colon, + ':', falseExpressionInSameLine ? [' ', falseExpression] : ifBreak([fillTab, indent(falseExpression)], [' ', falseExpression], { @@ -99,10 +99,10 @@ function traditionalTernaries( NonterminalKind.ConditionalExpression ? hardline : line, - `${node.questionMark} `, + '? ', path.call(print, 'trueExpression'), line, - `${node.colon} `, + ': ', path.call(print, 'falseExpression') ]) ]); @@ -117,12 +117,8 @@ export class ConditionalExpression implements SlangNode { operand: Expression; - questionMark: string; - trueExpression: Expression; - colon: string; - falseExpression: Expression; constructor( @@ -134,13 +130,11 @@ export class ConditionalExpression implements SlangNode { const { offsets } = metadata; this.operand = new Expression(ast.operand, offsets[0], options); - this.questionMark = ast.questionMark.text; this.trueExpression = new Expression( ast.trueExpression, offsets[1], options ); - this.colon = ast.colon.text; this.falseExpression = new Expression( ast.falseExpression, offsets[2], diff --git a/src/slang-nodes/ConstantDefinition.ts b/src/slang-nodes/ConstantDefinition.ts index db50fc169..14343c084 100644 --- a/src/slang-nodes/ConstantDefinition.ts +++ b/src/slang-nodes/ConstantDefinition.ts @@ -16,16 +16,10 @@ export class ConstantDefinition implements SlangNode { typeName: TypeName; - constantKeyword: string; - name: string; - equal: string; - value: Expression; - semicolon: string; - constructor( ast: ast.ConstantDefinition, offset: number, @@ -35,11 +29,8 @@ export class ConstantDefinition implements SlangNode { const { offsets } = metadata; this.typeName = new TypeName(ast.typeName, offsets[0], options); - this.constantKeyword = ast.constantKeyword.text; this.name = ast.name.text; - this.equal = ast.equal.text; this.value = new Expression(ast.value, offsets[1], options); - this.semicolon = ast.semicolon.text; metadata = updateMetadata(metadata, [this.typeName, this.value]); diff --git a/src/slang-nodes/ConstructorDefinition.ts b/src/slang-nodes/ConstructorDefinition.ts index b9bbf80ac..a9d6af288 100644 --- a/src/slang-nodes/ConstructorDefinition.ts +++ b/src/slang-nodes/ConstructorDefinition.ts @@ -16,8 +16,6 @@ export class ConstructorDefinition implements SlangNode { loc; - constructorKeyword: string; - parameters: ParametersDeclaration; attributes: ConstructorAttributes; @@ -32,7 +30,6 @@ export class ConstructorDefinition implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.constructorKeyword = ast.constructorKeyword.text; this.parameters = new ParametersDeclaration( ast.parameters, offsets[0], @@ -59,6 +56,6 @@ export class ConstructorDefinition implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return printFunction(this.constructorKeyword, this, path, print); + return printFunction('constructor', this, path, print); } } diff --git a/src/slang-nodes/ContinueStatement.ts b/src/slang-nodes/ContinueStatement.ts index 071a80bf9..0b3b2f91b 100644 --- a/src/slang-nodes/ContinueStatement.ts +++ b/src/slang-nodes/ContinueStatement.ts @@ -12,21 +12,14 @@ export class ContinueStatement implements SlangNode { loc; - continueKeyword: string; - - semicolon: string; - constructor(ast: ast.ContinueStatement, offset: number) { const metadata = getNodeMetadata(ast, offset); - this.continueKeyword = ast.continueKeyword.text; - this.semicolon = ast.semicolon.text; - this.comments = metadata.comments; this.loc = metadata.loc; } print(): Doc { - return `${this.continueKeyword}${this.semicolon}`; + return 'continue;'; } } diff --git a/src/slang-nodes/ContractDefinition.ts b/src/slang-nodes/ContractDefinition.ts index ed3c31729..21a316169 100644 --- a/src/slang-nodes/ContractDefinition.ts +++ b/src/slang-nodes/ContractDefinition.ts @@ -21,18 +21,12 @@ export class ContractDefinition implements SlangNode { abstractKeyword?: string; - contractKeyword: string; - name: string; inheritance?: InheritanceSpecifier; - openBrace: string; - members: ContractMembers; - closeBrace: string; - constructor( ast: ast.ContractDefinition, offset: number, @@ -42,7 +36,6 @@ export class ContractDefinition implements SlangNode { const { offsets } = metadata; this.abstractKeyword = ast.abstractKeyword?.text; - this.contractKeyword = ast.contractKeyword.text; this.name = ast.name.text; let i = 0; if (ast.inheritance) { @@ -53,9 +46,7 @@ export class ContractDefinition implements SlangNode { ); i += 1; } - this.openBrace = ast.openBrace.text; this.members = new ContractMembers(ast.members, offsets[i], options); - this.closeBrace = ast.closeBrace.text; metadata = updateMetadata(metadata, [this.inheritance, this.members]); @@ -87,12 +78,13 @@ export class ContractDefinition implements SlangNode { ): Doc { return [ group([ - `${this.abstractKeyword ? `${this.abstractKeyword} ` : ''}${this.contractKeyword} ${this.name}`, + this.abstractKeyword ? 'abstract ' : '', + `contract ${this.name}`, this.inheritance ? [' ', path.call(print, 'inheritance')] : line, - this.openBrace + '{' ]), path.call(print, 'members'), - this.closeBrace + '}' ]; } } diff --git a/src/slang-nodes/ContractMembers.ts b/src/slang-nodes/ContractMembers.ts index 27ca03559..b56f8668d 100644 --- a/src/slang-nodes/ContractMembers.ts +++ b/src/slang-nodes/ContractMembers.ts @@ -44,8 +44,7 @@ export class ContractMembers implements SlangNode { print: (path: AstPath) => Doc, options: ParserOptions ): Doc { - return this.items.length === 0 && - (!this.comments || this.comments.length === 0) + return this.items.length === 0 && this.comments.length === 0 ? '' : printSeparatedItem( [ diff --git a/src/slang-nodes/DoWhileStatement.ts b/src/slang-nodes/DoWhileStatement.ts index 0e280b773..65bd62175 100644 --- a/src/slang-nodes/DoWhileStatement.ts +++ b/src/slang-nodes/DoWhileStatement.ts @@ -18,20 +18,10 @@ export class DoWhileStatement implements SlangNode { loc; - doKeyword: string; - body: Statement; - whileKeyword: string; - - openParen: string; - condition: Expression; - closeParen: string; - - semicolon: string; - constructor( ast: ast.DoWhileStatement, offset: number, @@ -40,13 +30,8 @@ export class DoWhileStatement implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.doKeyword = ast.doKeyword.text; this.body = new Statement(ast.body, offsets[0], options); - this.whileKeyword = ast.whileKeyword.text; - this.openParen = ast.openParen.text; this.condition = new Expression(ast.condition, offsets[1], options); - this.closeParen = ast.closeParen.text; - this.semicolon = ast.semicolon.text; metadata = updateMetadata(metadata, [this.body, this.condition]); @@ -59,13 +44,13 @@ export class DoWhileStatement implements SlangNode { print: (path: AstPath) => Doc ): Doc { return [ - this.doKeyword, + 'do', this.body.variant.kind === NonterminalKind.Block ? [' ', path.call(print, 'body'), ' '] : group([indent([line, path.call(print, 'body')]), line]), - `${this.whileKeyword} ${this.openParen}`, + 'while (', printSeparatedItem(path.call(print, 'condition')), - `${this.closeParen}${this.semicolon}` + ');' ]; } } diff --git a/src/slang-nodes/ElseBranch.ts b/src/slang-nodes/ElseBranch.ts index bf63d74e0..8e30c4685 100644 --- a/src/slang-nodes/ElseBranch.ts +++ b/src/slang-nodes/ElseBranch.ts @@ -22,8 +22,6 @@ export class ElseBranch implements SlangNode { loc; - elseKeyword: string; - body: Statement; constructor( @@ -34,7 +32,6 @@ export class ElseBranch implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.elseKeyword = ast.elseKeyword.text; this.body = new Statement(ast.body, offsets[0], options); metadata = updateMetadata(metadata, [this.body]); @@ -48,7 +45,7 @@ export class ElseBranch implements SlangNode { print: (path: AstPath) => Doc ): Doc { return [ - this.elseKeyword, + 'else', isIfStatementOrBlock(this.body.variant) ? [' ', path.call(print, 'body')] : group(indent([line, path.call(print, 'body')])) diff --git a/src/slang-nodes/EmitStatement.ts b/src/slang-nodes/EmitStatement.ts index 7fcca5606..f060fe5f8 100644 --- a/src/slang-nodes/EmitStatement.ts +++ b/src/slang-nodes/EmitStatement.ts @@ -14,14 +14,10 @@ export class EmitStatement implements SlangNode { loc; - emitKeyword: string; - event: IdentifierPath; arguments: ArgumentsDeclaration; - semicolon: string; - constructor( ast: ast.EmitStatement, offset: number, @@ -30,14 +26,12 @@ export class EmitStatement implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.emitKeyword = ast.emitKeyword.text; this.event = new IdentifierPath(ast.event, offsets[0]); this.arguments = new ArgumentsDeclaration( ast.arguments, offsets[1], options ); - this.semicolon = ast.semicolon.text; metadata = updateMetadata(metadata, [this.event, this.arguments]); @@ -50,10 +44,10 @@ export class EmitStatement implements SlangNode { print: (path: AstPath) => Doc ): Doc { return [ - `${this.emitKeyword} `, + 'emit ', path.call(print, 'event'), path.call(print, 'arguments'), - this.semicolon + ';' ]; } } diff --git a/src/slang-nodes/EnumDefinition.ts b/src/slang-nodes/EnumDefinition.ts index a1d72a413..761d8d1bb 100644 --- a/src/slang-nodes/EnumDefinition.ts +++ b/src/slang-nodes/EnumDefinition.ts @@ -13,25 +13,16 @@ export class EnumDefinition implements SlangNode { loc; - enumKeyword: string; - name: string; - openBrace: string; - members: EnumMembers; - closeBrace: string; - constructor(ast: ast.EnumDefinition, offset: number) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.enumKeyword = ast.enumKeyword.text; this.name = ast.name.text; - this.openBrace = ast.openBrace.text; this.members = new EnumMembers(ast.members, offsets[0]); - this.closeBrace = ast.closeBrace.text; metadata = updateMetadata(metadata, [this.members]); @@ -43,10 +34,6 @@ export class EnumDefinition implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return [ - `${this.enumKeyword} ${this.name} ${this.openBrace}`, - path.call(print, 'members'), - this.closeBrace - ]; + return [`enum ${this.name} {`, path.call(print, 'members'), '}']; } } diff --git a/src/slang-nodes/ErrorDefinition.ts b/src/slang-nodes/ErrorDefinition.ts index aff39438b..874a57d93 100644 --- a/src/slang-nodes/ErrorDefinition.ts +++ b/src/slang-nodes/ErrorDefinition.ts @@ -13,14 +13,10 @@ export class ErrorDefinition implements SlangNode { loc; - errorKeyword: string; - name: string; members: ErrorParametersDeclaration; - semicolon: string; - constructor( ast: ast.ErrorDefinition, offset: number, @@ -29,14 +25,12 @@ export class ErrorDefinition implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.errorKeyword = ast.errorKeyword.text; this.name = ast.name.text; this.members = new ErrorParametersDeclaration( ast.members, offsets[0], options ); - this.semicolon = ast.semicolon.text; metadata = updateMetadata(metadata, [this.members]); @@ -48,10 +42,6 @@ export class ErrorDefinition implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return [ - `${this.errorKeyword} ${this.name}`, - path.call(print, 'members'), - this.semicolon - ]; + return [`error ${this.name}`, path.call(print, 'members'), ';']; } } diff --git a/src/slang-nodes/ErrorParametersDeclaration.ts b/src/slang-nodes/ErrorParametersDeclaration.ts index 6f0a51991..3a2256343 100644 --- a/src/slang-nodes/ErrorParametersDeclaration.ts +++ b/src/slang-nodes/ErrorParametersDeclaration.ts @@ -13,12 +13,8 @@ export class ErrorParametersDeclaration implements SlangNode { loc; - openParen: string; - parameters: ErrorParameters; - closeParen: string; - constructor( ast: ast.ErrorParametersDeclaration, offset: number, @@ -27,9 +23,7 @@ export class ErrorParametersDeclaration implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.openParen = ast.openParen.text; this.parameters = new ErrorParameters(ast.parameters, offsets[0], options); - this.closeParen = ast.closeParen.text; metadata = updateMetadata(metadata, [this.parameters]); @@ -41,6 +35,6 @@ export class ErrorParametersDeclaration implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return [this.openParen, path.call(print, 'parameters'), this.closeParen]; + return ['(', path.call(print, 'parameters'), ')']; } } diff --git a/src/slang-nodes/EventDefinition.ts b/src/slang-nodes/EventDefinition.ts index 9ce882c6e..32d5a3381 100644 --- a/src/slang-nodes/EventDefinition.ts +++ b/src/slang-nodes/EventDefinition.ts @@ -13,16 +13,12 @@ export class EventDefinition implements SlangNode { loc; - eventKeyword: string; - name: string; parameters: EventParametersDeclaration; anonymousKeyword?: string; - semicolon: string; - constructor( ast: ast.EventDefinition, offset: number, @@ -31,7 +27,6 @@ export class EventDefinition implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.eventKeyword = ast.eventKeyword.text; this.name = ast.name.text; this.parameters = new EventParametersDeclaration( ast.parameters, @@ -39,7 +34,6 @@ export class EventDefinition implements SlangNode { options ); this.anonymousKeyword = ast.anonymousKeyword?.text; - this.semicolon = ast.semicolon.text; metadata = updateMetadata(metadata, [this.parameters]); @@ -52,10 +46,10 @@ export class EventDefinition implements SlangNode { print: (path: AstPath) => Doc ): Doc { return [ - `${this.eventKeyword} ${this.name}`, + `event ${this.name}`, path.call(print, 'parameters'), - this.anonymousKeyword ? ` ${this.anonymousKeyword}` : '', - this.semicolon + this.anonymousKeyword ? ' anonymous' : '', + ';' ]; } } diff --git a/src/slang-nodes/EventParameter.ts b/src/slang-nodes/EventParameter.ts index c24b28202..dd56cfb93 100644 --- a/src/slang-nodes/EventParameter.ts +++ b/src/slang-nodes/EventParameter.ts @@ -43,7 +43,7 @@ export class EventParameter implements SlangNode { ): Doc { return [ path.call(print, 'typeName'), - this.indexedKeyword ? ` ${this.indexedKeyword}` : '', + this.indexedKeyword ? ' indexed' : '', this.name ? ` ${this.name}` : '' ]; } diff --git a/src/slang-nodes/EventParametersDeclaration.ts b/src/slang-nodes/EventParametersDeclaration.ts index b3c8b3e1c..f36677094 100644 --- a/src/slang-nodes/EventParametersDeclaration.ts +++ b/src/slang-nodes/EventParametersDeclaration.ts @@ -13,12 +13,8 @@ export class EventParametersDeclaration implements SlangNode { loc; - openParen: string; - parameters: EventParameters; - closeParen: string; - constructor( ast: ast.EventParametersDeclaration, offset: number, @@ -27,9 +23,7 @@ export class EventParametersDeclaration implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.openParen = ast.openParen.text; this.parameters = new EventParameters(ast.parameters, offsets[0], options); - this.closeParen = ast.closeParen.text; metadata = updateMetadata(metadata, [this.parameters]); @@ -41,6 +35,6 @@ export class EventParametersDeclaration implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return [this.openParen, path.call(print, 'parameters'), this.closeParen]; + return ['(', path.call(print, 'parameters'), ')']; } } diff --git a/src/slang-nodes/ExperimentalPragma.ts b/src/slang-nodes/ExperimentalPragma.ts index ce12580cf..d7309ac43 100644 --- a/src/slang-nodes/ExperimentalPragma.ts +++ b/src/slang-nodes/ExperimentalPragma.ts @@ -13,8 +13,6 @@ export class ExperimentalPragma implements SlangNode { loc; - experimentalKeyword: string; - feature: ExperimentalFeature; constructor( @@ -25,7 +23,6 @@ export class ExperimentalPragma implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.experimentalKeyword = ast.experimentalKeyword.text; this.feature = new ExperimentalFeature(ast.feature, offsets[0], options); metadata = updateMetadata(metadata, [this.feature]); @@ -38,6 +35,6 @@ export class ExperimentalPragma implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return [`${this.experimentalKeyword} `, path.call(print, 'feature')]; + return ['experimental ', path.call(print, 'feature')]; } } diff --git a/src/slang-nodes/ExponentiationExpression.ts b/src/slang-nodes/ExponentiationExpression.ts index 93793793c..db51702ef 100644 --- a/src/slang-nodes/ExponentiationExpression.ts +++ b/src/slang-nodes/ExponentiationExpression.ts @@ -97,7 +97,6 @@ export class ExponentiationExpression implements SlangNode { }, loc: { value: { ...leftLoc }, ...objectConfig }, comments: { value: [], ...objectConfig }, - openParen: { value: '(', ...objectConfig }, items: { value: Object.create(TupleValues.prototype, { kind: { @@ -161,8 +160,7 @@ export class ExponentiationExpression implements SlangNode { separators: { value: [], ...objectConfig } }) as TupleValues, ...objectConfig - }, - closeParen: { value: ')', ...objectConfig } + } }) as TupleExpression, ...objectConfig } diff --git a/src/slang-nodes/ExpressionStatement.ts b/src/slang-nodes/ExpressionStatement.ts index cf7911dd8..02c867934 100644 --- a/src/slang-nodes/ExpressionStatement.ts +++ b/src/slang-nodes/ExpressionStatement.ts @@ -15,8 +15,6 @@ export class ExpressionStatement implements SlangNode { expression: Expression; - semicolon: string; - constructor( ast: ast.ExpressionStatement, offset: number, @@ -26,7 +24,6 @@ export class ExpressionStatement implements SlangNode { const { offsets } = metadata; this.expression = new Expression(ast.expression, offsets[0], options); - this.semicolon = ast.semicolon.text; metadata = updateMetadata(metadata, [this.expression]); @@ -38,6 +35,6 @@ export class ExpressionStatement implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return [path.call(print, 'expression'), this.semicolon]; + return [path.call(print, 'expression'), ';']; } } diff --git a/src/slang-nodes/FallbackFunctionDefinition.ts b/src/slang-nodes/FallbackFunctionDefinition.ts index 99ca112e9..2bb902aba 100644 --- a/src/slang-nodes/FallbackFunctionDefinition.ts +++ b/src/slang-nodes/FallbackFunctionDefinition.ts @@ -17,8 +17,6 @@ export class FallbackFunctionDefinition implements SlangNode { loc; - fallbackKeyword: string; - parameters: ParametersDeclaration; attributes: FallbackFunctionAttributes; @@ -35,7 +33,6 @@ export class FallbackFunctionDefinition implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.fallbackKeyword = ast.fallbackKeyword.text; this.parameters = new ParametersDeclaration( ast.parameters, offsets[0], @@ -81,6 +78,6 @@ export class FallbackFunctionDefinition implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return printFunction(this.fallbackKeyword, this, path, print); + return printFunction('fallback', this, path, print); } } diff --git a/src/slang-nodes/ForStatement.ts b/src/slang-nodes/ForStatement.ts index c1a2709e8..9eae87041 100644 --- a/src/slang-nodes/ForStatement.ts +++ b/src/slang-nodes/ForStatement.ts @@ -20,18 +20,12 @@ export class ForStatement implements SlangNode { loc; - forKeyword: string; - - openParen: string; - initialization: ForStatementInitialization; condition: ForStatementCondition; iterator?: Expression; - closeParen: string; - body: Statement; constructor( @@ -42,8 +36,6 @@ export class ForStatement implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.forKeyword = ast.forKeyword.text; - this.openParen = ast.openParen.text; this.initialization = new ForStatementInitialization( ast.initialization, offsets[0], @@ -59,7 +51,6 @@ export class ForStatement implements SlangNode { this.iterator = new Expression(ast.iterator, offsets[i], options); i += 1; } - this.closeParen = ast.closeParen.text; this.body = new Statement(ast.body, offsets[i], options); metadata = updateMetadata(metadata, [ @@ -82,14 +73,14 @@ export class ForStatement implements SlangNode { const iterator = this.iterator ? path.call(print, 'iterator') : ''; return [ - `${this.forKeyword} ${this.openParen}`, + 'for (', printSeparatedList([initialization, condition, iterator], { separator: initialization !== ';' || condition !== ';' || iterator !== '' ? line : '' }), - this.closeParen, + ')', this.body.variant.kind === NonterminalKind.Block ? [' ', path.call(print, 'body')] : group(indent([line, path.call(print, 'body')])) diff --git a/src/slang-nodes/FunctionDefinition.ts b/src/slang-nodes/FunctionDefinition.ts index b240b5080..7e7ede141 100644 --- a/src/slang-nodes/FunctionDefinition.ts +++ b/src/slang-nodes/FunctionDefinition.ts @@ -20,8 +20,6 @@ export class FunctionDefinition implements SlangNode { loc; - functionKeyword: string; - name: FunctionName; parameters: ParametersDeclaration; @@ -40,7 +38,6 @@ export class FunctionDefinition implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.functionKeyword = ast.functionKeyword.text; this.name = new FunctionName(ast.name, offsets[0]); this.parameters = new ParametersDeclaration( ast.parameters, @@ -94,7 +91,7 @@ export class FunctionDefinition implements SlangNode { print: (path: AstPath) => Doc ): Doc { return printFunction( - [`${this.functionKeyword} `, path.call(print, 'name')], + ['function ', path.call(print, 'name')], this, path, print diff --git a/src/slang-nodes/FunctionType.ts b/src/slang-nodes/FunctionType.ts index 4b465722f..f6e562d41 100644 --- a/src/slang-nodes/FunctionType.ts +++ b/src/slang-nodes/FunctionType.ts @@ -16,8 +16,6 @@ export class FunctionType implements SlangNode { loc; - functionKeyword: string; - parameters: ParametersDeclaration; attributes: FunctionTypeAttributes; @@ -32,7 +30,6 @@ export class FunctionType implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.functionKeyword = ast.functionKeyword.text; this.parameters = new ParametersDeclaration( ast.parameters, offsets[0], @@ -57,6 +54,6 @@ export class FunctionType implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return printFunction(this.functionKeyword, this, path, print); + return printFunction('function', this, path, print); } } diff --git a/src/slang-nodes/IfStatement.ts b/src/slang-nodes/IfStatement.ts index 62ebb8969..1df6dd8f3 100644 --- a/src/slang-nodes/IfStatement.ts +++ b/src/slang-nodes/IfStatement.ts @@ -19,14 +19,8 @@ export class IfStatement implements SlangNode { loc; - ifKeyword: string; - - openParen: string; - condition: Expression; - closeParen: string; - body: Statement; elseBranch?: ElseBranch; @@ -39,10 +33,7 @@ export class IfStatement implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.ifKeyword = ast.ifKeyword.text; - this.openParen = ast.openParen.text; this.condition = new Expression(ast.condition, offsets[0], options); - this.closeParen = ast.closeParen.text; this.body = new Statement(ast.body, offsets[1], options); if (ast.elseBranch) { this.elseBranch = new ElseBranch(ast.elseBranch, offsets[2], options); @@ -63,9 +54,9 @@ export class IfStatement implements SlangNode { print: (path: AstPath) => Doc ): Doc { return [ - `${this.ifKeyword} ${this.openParen}`, + 'if (', printSeparatedItem(path.call(print, 'condition')), - this.closeParen, + ')', this.body.variant.kind === NonterminalKind.Block ? [' ', path.call(print, 'body')] : group(indent([line, path.call(print, 'body')]), { diff --git a/src/slang-nodes/ImportAlias.ts b/src/slang-nodes/ImportAlias.ts index 2f951c408..2bffa5084 100644 --- a/src/slang-nodes/ImportAlias.ts +++ b/src/slang-nodes/ImportAlias.ts @@ -12,14 +12,11 @@ export class ImportAlias implements SlangNode { loc; - asKeyword: string; - identifier: string; constructor(ast: ast.ImportAlias, offset: number) { const metadata = getNodeMetadata(ast, offset); - this.asKeyword = ast.asKeyword.text; this.identifier = ast.identifier.text; this.comments = metadata.comments; @@ -27,6 +24,6 @@ export class ImportAlias implements SlangNode { } print(): Doc { - return ` ${this.asKeyword} ${this.identifier}`; + return ` as ${this.identifier}`; } } diff --git a/src/slang-nodes/ImportDeconstruction.ts b/src/slang-nodes/ImportDeconstruction.ts index d085761bc..5b36a0ad9 100644 --- a/src/slang-nodes/ImportDeconstruction.ts +++ b/src/slang-nodes/ImportDeconstruction.ts @@ -14,14 +14,8 @@ export class ImportDeconstruction implements SlangNode { loc; - openBrace: string; - symbols: ImportDeconstructionSymbols; - closeBrace: string; - - fromKeyword: string; - path: StringLiteral; constructor( @@ -32,10 +26,7 @@ export class ImportDeconstruction implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.openBrace = ast.openBrace.text; this.symbols = new ImportDeconstructionSymbols(ast.symbols, offsets[0]); - this.closeBrace = ast.closeBrace.text; - this.fromKeyword = ast.fromKeyword.text; this.path = new StringLiteral(ast.path, offsets[1], options); metadata = updateMetadata(metadata, [this.symbols, this.path]); @@ -49,9 +40,9 @@ export class ImportDeconstruction implements SlangNode { print: (path: AstPath) => Doc ): Doc { return [ - this.openBrace, + '{', path.call(print, 'symbols'), - `${this.closeBrace} ${this.fromKeyword} `, + '} from ', path.call(print, 'path') ]; } diff --git a/src/slang-nodes/ImportDeconstructionSymbols.ts b/src/slang-nodes/ImportDeconstructionSymbols.ts index e2b4bfc5a..d4ee715bf 100644 --- a/src/slang-nodes/ImportDeconstructionSymbols.ts +++ b/src/slang-nodes/ImportDeconstructionSymbols.ts @@ -44,23 +44,21 @@ export class ImportDeconstructionSymbols implements SlangNode { options: ParserOptions ): Doc { const compiler = coerce(options.compiler); - let firstSeparator; - let separator; - - if (compiler && satisfies(compiler, '>=0.7.4')) { - // if the compiler exists and is greater than or equal to 0.7.4 we will - // split the ImportDirective. - firstSeparator = options.bracketSpacing ? line : softline; - separator = [',', line]; - } else { - // if the compiler is not given or is lower than 0.7.4 we will not - // split the ImportDirective. - firstSeparator = options.bracketSpacing ? ' ' : ''; - separator = ', '; - } - return printSeparatedList(path.map(print, 'items'), { - firstSeparator, - separator - }); + return printSeparatedList( + path.map(print, 'items'), + compiler && satisfies(compiler, '>=0.7.4') + ? { + // if the compiler exists and is greater than or equal to 0.7.4 we will + // split the ImportDirective. + firstSeparator: options.bracketSpacing ? line : softline, + separator: [',', line] + } + : { + // if the compiler is not given or is lower than 0.7.4 we will not + // split the ImportDirective. + firstSeparator: options.bracketSpacing ? ' ' : '', + separator: ', ' + } + ); } } diff --git a/src/slang-nodes/ImportDirective.ts b/src/slang-nodes/ImportDirective.ts index 163b120db..e19f084fd 100644 --- a/src/slang-nodes/ImportDirective.ts +++ b/src/slang-nodes/ImportDirective.ts @@ -13,12 +13,8 @@ export class ImportDirective implements SlangNode { loc; - importKeyword: string; - clause: ImportClause; - semicolon: string; - constructor( ast: ast.ImportDirective, offset: number, @@ -27,9 +23,7 @@ export class ImportDirective implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.importKeyword = ast.importKeyword.text; this.clause = new ImportClause(ast.clause, offsets[0], options); - this.semicolon = ast.semicolon.text; metadata = updateMetadata(metadata, [this.clause]); @@ -41,10 +35,6 @@ export class ImportDirective implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return [ - `${this.importKeyword} `, - path.call(print, 'clause'), - this.semicolon - ]; + return ['import ', path.call(print, 'clause'), ';']; } } diff --git a/src/slang-nodes/IndexAccessEnd.ts b/src/slang-nodes/IndexAccessEnd.ts index 55c0d7e50..7fe563850 100644 --- a/src/slang-nodes/IndexAccessEnd.ts +++ b/src/slang-nodes/IndexAccessEnd.ts @@ -13,8 +13,6 @@ export class IndexAccessEnd implements SlangNode { loc; - colon: string; - end?: Expression; constructor( @@ -25,7 +23,6 @@ export class IndexAccessEnd implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.colon = ast.colon.text; if (ast.end) { this.end = new Expression(ast.end, offsets[0], options); } @@ -40,6 +37,6 @@ export class IndexAccessEnd implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return [this.colon, this.end ? path.call(print, 'end') : '']; + return [':', this.end ? path.call(print, 'end') : '']; } } diff --git a/src/slang-nodes/IndexAccessExpression.ts b/src/slang-nodes/IndexAccessExpression.ts index be07dca0f..64f61111a 100644 --- a/src/slang-nodes/IndexAccessExpression.ts +++ b/src/slang-nodes/IndexAccessExpression.ts @@ -20,14 +20,10 @@ export class IndexAccessExpression implements SlangNode { operand: Expression; - openBracket: string; - start?: Expression; end?: IndexAccessEnd; - closeBracket: string; - constructor( ast: ast.IndexAccessExpression, offset: number, @@ -37,7 +33,6 @@ export class IndexAccessExpression implements SlangNode { const { offsets } = metadata; this.operand = new Expression(ast.operand, offsets[0], options); - this.openBracket = ast.openBracket.text; let i = 1; if (ast.start) { this.start = new Expression(ast.start, offsets[i], options); @@ -46,7 +41,6 @@ export class IndexAccessExpression implements SlangNode { if (ast.end) { this.end = new IndexAccessEnd(ast.end, offsets[i], options); } - this.closeBracket = ast.closeBracket.text; metadata = updateMetadata(metadata, [this.operand, this.start, this.end]); @@ -60,14 +54,14 @@ export class IndexAccessExpression implements SlangNode { ): Doc { let operandDoc: Doc = path.call(print, 'operand'); let indexDoc: Doc = group([ - this.openBracket, + '[', indent([ softline, this.start ? path.call(print, 'start') : '', this.end ? path.call(print, 'end') : '' ]), softline, - this.closeBracket + ']' ]); // If we are at the end of a MemberAccessChain we should indent the diff --git a/src/slang-nodes/InheritanceSpecifier.ts b/src/slang-nodes/InheritanceSpecifier.ts index 8501dd393..1ea92d222 100644 --- a/src/slang-nodes/InheritanceSpecifier.ts +++ b/src/slang-nodes/InheritanceSpecifier.ts @@ -13,8 +13,6 @@ export class InheritanceSpecifier implements SlangNode { loc; - isKeyword: string; - types: InheritanceTypes; constructor( @@ -25,7 +23,6 @@ export class InheritanceSpecifier implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.isKeyword = ast.isKeyword?.text; this.types = new InheritanceTypes(ast.types, offsets[0], options); metadata = updateMetadata(metadata, [this.types]); @@ -38,6 +35,6 @@ export class InheritanceSpecifier implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return [this.isKeyword, path.call(print, 'types')]; + return ['is', path.call(print, 'types')]; } } diff --git a/src/slang-nodes/InterfaceDefinition.ts b/src/slang-nodes/InterfaceDefinition.ts index 2cb78fbb5..415d3e0f8 100644 --- a/src/slang-nodes/InterfaceDefinition.ts +++ b/src/slang-nodes/InterfaceDefinition.ts @@ -17,18 +17,12 @@ export class InterfaceDefinition implements SlangNode { loc; - interfaceKeyword: string; - name: string; inheritance?: InheritanceSpecifier; - openBrace: string; - members: InterfaceMembers; - closeBrace: string; - constructor( ast: ast.InterfaceDefinition, offset: number, @@ -37,7 +31,6 @@ export class InterfaceDefinition implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.interfaceKeyword = ast.interfaceKeyword.text; this.name = ast.name.text; let i = 0; if (ast.inheritance) { @@ -48,9 +41,7 @@ export class InterfaceDefinition implements SlangNode { ); i += 1; } - this.openBrace = ast.openBrace.text; this.members = new InterfaceMembers(ast.members, offsets[i], options); - this.closeBrace = ast.closeBrace.text; metadata = updateMetadata(metadata, [this.inheritance, this.members]); @@ -64,12 +55,12 @@ export class InterfaceDefinition implements SlangNode { ): Doc { return [ group([ - `${this.interfaceKeyword} ${this.name}`, + `interface ${this.name}`, this.inheritance ? path.call(print, 'inheritance') : line, - this.openBrace + '{' ]), path.call(print, 'members'), - this.closeBrace + '}' ]; } } diff --git a/src/slang-nodes/LibraryDefinition.ts b/src/slang-nodes/LibraryDefinition.ts index 2fd0ec594..6728c3191 100644 --- a/src/slang-nodes/LibraryDefinition.ts +++ b/src/slang-nodes/LibraryDefinition.ts @@ -16,16 +16,10 @@ export class LibraryDefinition implements SlangNode { loc; - libraryKeyword: string; - name: string; - openBrace: string; - members: LibraryMembers; - closeBrace: string; - constructor( ast: ast.LibraryDefinition, offset: number, @@ -34,11 +28,8 @@ export class LibraryDefinition implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.libraryKeyword = ast.libraryKeyword.text; this.name = ast.name.text; - this.openBrace = ast.openBrace.text; this.members = new LibraryMembers(ast.members, offsets[0], options); - this.closeBrace = ast.closeBrace.text; metadata = updateMetadata(metadata, [this.members]); @@ -51,9 +42,9 @@ export class LibraryDefinition implements SlangNode { print: (path: AstPath) => Doc ): Doc { return [ - group([`${this.libraryKeyword} ${this.name}`, line, this.openBrace]), + group([`library ${this.name}`, line, '{']), path.call(print, 'members'), - this.closeBrace + '}' ]; } } diff --git a/src/slang-nodes/MappingType.ts b/src/slang-nodes/MappingType.ts index 3c11bbb77..6e5095a79 100644 --- a/src/slang-nodes/MappingType.ts +++ b/src/slang-nodes/MappingType.ts @@ -14,18 +14,12 @@ export class MappingType implements SlangNode { loc; - mappingKeyword: string; - - openParen: string; - keyType: MappingKey; equalGreaterThan: string; valueType: MappingValue; - closeParen: string; - constructor( ast: ast.MappingType, offset: number, @@ -34,12 +28,9 @@ export class MappingType implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.mappingKeyword = ast.mappingKeyword.text; - this.openParen = ast.openParen.text; this.keyType = new MappingKey(ast.keyType, offsets[0]); this.equalGreaterThan = ast.equalGreaterThan.text; this.valueType = new MappingValue(ast.valueType, offsets[1], options); - this.closeParen = ast.closeParen.text; metadata = updateMetadata(metadata, [this.keyType, this.valueType]); @@ -52,11 +43,11 @@ export class MappingType implements SlangNode { print: (path: AstPath) => Doc ): Doc { return [ - `${this.mappingKeyword}${this.openParen}`, + 'mapping(', path.call(print, 'keyType'), ` ${this.equalGreaterThan} `, path.call(print, 'valueType'), - this.closeParen + ')' ]; } } diff --git a/src/slang-nodes/ModifierDefinition.ts b/src/slang-nodes/ModifierDefinition.ts index 6b5d414ee..226b37f71 100644 --- a/src/slang-nodes/ModifierDefinition.ts +++ b/src/slang-nodes/ModifierDefinition.ts @@ -22,9 +22,7 @@ export class ModifierDefinition implements SlangNode { loc; - modifierKeyword; - - name; + name: string; parameters?: ParametersDeclaration; @@ -40,7 +38,6 @@ export class ModifierDefinition implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.modifierKeyword = ast.modifierKeyword.text; this.name = ast.name.text; let i = 0; if (ast.parameters) { @@ -84,7 +81,6 @@ export class ModifierDefinition implements SlangNode { ...objectConfig }, comments: { value: [], ...objectConfig }, - openParen: { value: '(', ...objectConfig }, parameters: { value: Object.create(Parameters.prototype, { kind: { value: NonterminalKind.Parameters, ...objectConfig }, @@ -94,8 +90,7 @@ export class ModifierDefinition implements SlangNode { separators: { value: [], ...objectConfig } }) as Parameters, ...objectConfig - }, - closeParen: { value: ')', ...objectConfig } + } }) as ParametersDeclaration; } } @@ -104,11 +99,6 @@ export class ModifierDefinition implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return printFunction( - `${this.modifierKeyword} ${this.name}`, - this, - path, - print - ); + return printFunction(`modifier ${this.name}`, this, path, print); } } diff --git a/src/slang-nodes/NamedArgument.ts b/src/slang-nodes/NamedArgument.ts index f80ec4fc5..1c0b5892e 100644 --- a/src/slang-nodes/NamedArgument.ts +++ b/src/slang-nodes/NamedArgument.ts @@ -15,8 +15,6 @@ export class NamedArgument implements SlangNode { name: string; - colon: string; - value: Expression; constructor( @@ -28,7 +26,6 @@ export class NamedArgument implements SlangNode { const { offsets } = metadata; this.name = ast.name.text; - this.colon = ast.colon.text; this.value = new Expression(ast.value, offsets[0], options); metadata = updateMetadata(metadata, [this.value]); @@ -41,6 +38,6 @@ export class NamedArgument implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return [`${this.name}${this.colon} `, path.call(print, 'value')]; + return [`${this.name}: `, path.call(print, 'value')]; } } diff --git a/src/slang-nodes/NamedArgumentGroup.ts b/src/slang-nodes/NamedArgumentGroup.ts index 1dd0019f9..aa7743af9 100644 --- a/src/slang-nodes/NamedArgumentGroup.ts +++ b/src/slang-nodes/NamedArgumentGroup.ts @@ -13,12 +13,8 @@ export class NamedArgumentGroup implements SlangNode { loc; - openBrace: string; - arguments: NamedArguments; - closeBrace: string; - constructor( ast: ast.NamedArgumentGroup, offset: number, @@ -27,9 +23,7 @@ export class NamedArgumentGroup implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.openBrace = ast.openBrace.text; this.arguments = new NamedArguments(ast.arguments, offsets[0], options); - this.closeBrace = ast.closeBrace.text; metadata = updateMetadata(metadata, [this.arguments]); @@ -41,6 +35,6 @@ export class NamedArgumentGroup implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return [this.openBrace, path.call(print, 'arguments'), this.closeBrace]; + return ['{', path.call(print, 'arguments'), '}']; } } diff --git a/src/slang-nodes/NamedArgumentsDeclaration.ts b/src/slang-nodes/NamedArgumentsDeclaration.ts index 50c07d5f3..b679e8fde 100644 --- a/src/slang-nodes/NamedArgumentsDeclaration.ts +++ b/src/slang-nodes/NamedArgumentsDeclaration.ts @@ -13,12 +13,8 @@ export class NamedArgumentsDeclaration implements SlangNode { loc; - openParen: string; - arguments?: NamedArgumentGroup; - closeParen: string; - constructor( ast: ast.NamedArgumentsDeclaration, offset: number, @@ -27,7 +23,6 @@ export class NamedArgumentsDeclaration implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.openParen = ast.openParen.text; if (ast.arguments) { this.arguments = new NamedArgumentGroup( ast.arguments, @@ -35,7 +30,6 @@ export class NamedArgumentsDeclaration implements SlangNode { options ); } - this.closeParen = ast.closeParen.text; metadata = updateMetadata(metadata, [this.arguments]); @@ -47,10 +41,6 @@ export class NamedArgumentsDeclaration implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return [ - this.openParen, - this.arguments ? path.call(print, 'arguments') : '', - this.closeParen - ]; + return ['(', this.arguments ? path.call(print, 'arguments') : '', ')']; } } diff --git a/src/slang-nodes/NamedImport.ts b/src/slang-nodes/NamedImport.ts index ff44b0c95..94bb87fd2 100644 --- a/src/slang-nodes/NamedImport.ts +++ b/src/slang-nodes/NamedImport.ts @@ -18,8 +18,6 @@ export class NamedImport implements SlangNode { alias: ImportAlias; - fromKeyword: string; - path: StringLiteral; constructor( @@ -32,7 +30,6 @@ export class NamedImport implements SlangNode { this.asterisk = ast.asterisk.text; this.alias = new ImportAlias(ast.alias, offsets[0]); - this.fromKeyword = ast.fromKeyword.text; this.path = new StringLiteral(ast.path, offsets[1], options); metadata = updateMetadata(metadata, [this.alias, this.path]); @@ -48,7 +45,7 @@ export class NamedImport implements SlangNode { return [ this.asterisk, path.call(print, 'alias'), - ` ${this.fromKeyword} `, + ' from ', path.call(print, 'path') ]; } diff --git a/src/slang-nodes/NewExpression.ts b/src/slang-nodes/NewExpression.ts index 24c672ca6..730a9f05f 100644 --- a/src/slang-nodes/NewExpression.ts +++ b/src/slang-nodes/NewExpression.ts @@ -13,8 +13,6 @@ export class NewExpression implements SlangNode { loc; - newKeyword: string; - typeName: TypeName; constructor( @@ -25,7 +23,6 @@ export class NewExpression implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.newKeyword = ast.newKeyword.text; this.typeName = new TypeName(ast.typeName, offsets[0], options); metadata = updateMetadata(metadata, [this.typeName]); @@ -38,6 +35,6 @@ export class NewExpression implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return [`${this.newKeyword} `, path.call(print, 'typeName')]; + return ['new ', path.call(print, 'typeName')]; } } diff --git a/src/slang-nodes/OverridePathsDeclaration.ts b/src/slang-nodes/OverridePathsDeclaration.ts index 8834024ad..e535102c3 100644 --- a/src/slang-nodes/OverridePathsDeclaration.ts +++ b/src/slang-nodes/OverridePathsDeclaration.ts @@ -13,19 +13,13 @@ export class OverridePathsDeclaration implements SlangNode { loc; - openParen: string; - paths: OverridePaths; - closeParen: string; - constructor(ast: ast.OverridePathsDeclaration, offset: number) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.openParen = ast.openParen.text; this.paths = new OverridePaths(ast.paths, offsets[0]); - this.closeParen = ast.closeParen.text; metadata = updateMetadata(metadata, [this.paths]); diff --git a/src/slang-nodes/OverrideSpecifier.ts b/src/slang-nodes/OverrideSpecifier.ts index 1bcf05602..6a401644e 100644 --- a/src/slang-nodes/OverrideSpecifier.ts +++ b/src/slang-nodes/OverrideSpecifier.ts @@ -13,15 +13,12 @@ export class OverrideSpecifier implements SlangNode { loc; - overrideKeyword: string; - overridden?: OverridePathsDeclaration; constructor(ast: ast.OverrideSpecifier, offset: number) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.overrideKeyword = ast.overrideKeyword.text; if (ast.overridden) { this.overridden = new OverridePathsDeclaration( ast.overridden, @@ -39,9 +36,6 @@ export class OverrideSpecifier implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return [ - this.overrideKeyword, - this.overridden ? path.call(print, 'overridden') : '' - ]; + return ['override', this.overridden ? path.call(print, 'overridden') : '']; } } diff --git a/src/slang-nodes/ParametersDeclaration.ts b/src/slang-nodes/ParametersDeclaration.ts index fed30a428..e837fbe40 100644 --- a/src/slang-nodes/ParametersDeclaration.ts +++ b/src/slang-nodes/ParametersDeclaration.ts @@ -13,12 +13,8 @@ export class ParametersDeclaration implements SlangNode { loc; - openParen: string; - parameters: Parameters; - closeParen: string; - constructor( ast: ast.ParametersDeclaration, offset: number, @@ -27,9 +23,7 @@ export class ParametersDeclaration implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.openParen = ast.openParen.text; this.parameters = new Parameters(ast.parameters, offsets[0], options); - this.closeParen = ast.closeParen.text; metadata = updateMetadata(metadata, [this.parameters]); @@ -41,6 +35,6 @@ export class ParametersDeclaration implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return [this.openParen, path.call(print, 'parameters'), this.closeParen]; + return ['(', path.call(print, 'parameters'), ')']; } } diff --git a/src/slang-nodes/PositionalArgumentsDeclaration.ts b/src/slang-nodes/PositionalArgumentsDeclaration.ts index 0d17122ad..a818bfd9d 100644 --- a/src/slang-nodes/PositionalArgumentsDeclaration.ts +++ b/src/slang-nodes/PositionalArgumentsDeclaration.ts @@ -13,12 +13,8 @@ export class PositionalArgumentsDeclaration implements SlangNode { loc; - openParen: string; - arguments: PositionalArguments; - closeParen: string; - constructor( ast: ast.PositionalArgumentsDeclaration, offset: number, @@ -27,13 +23,11 @@ export class PositionalArgumentsDeclaration implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.openParen = ast.openParen.text; this.arguments = new PositionalArguments( ast.arguments, offsets[0], options ); - this.closeParen = ast.closeParen.text; metadata = updateMetadata(metadata, [this.arguments]); @@ -45,6 +39,6 @@ export class PositionalArgumentsDeclaration implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return [this.openParen, path.call(print, 'arguments'), this.closeParen]; + return ['(', path.call(print, 'arguments'), ')']; } } diff --git a/src/slang-nodes/PragmaDirective.ts b/src/slang-nodes/PragmaDirective.ts index 7a5c13806..d9a4267c2 100644 --- a/src/slang-nodes/PragmaDirective.ts +++ b/src/slang-nodes/PragmaDirective.ts @@ -13,12 +13,8 @@ export class PragmaDirective implements SlangNode { loc; - pragmaKeyword: string; - pragma: Pragma; - semicolon: string; - constructor( ast: ast.PragmaDirective, offset: number, @@ -27,9 +23,7 @@ export class PragmaDirective implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.pragmaKeyword = ast.pragmaKeyword.text; this.pragma = new Pragma(ast.pragma, offsets[0], options); - this.semicolon = ast.semicolon.text; metadata = updateMetadata(metadata, [this.pragma]); @@ -41,10 +35,6 @@ export class PragmaDirective implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return [ - `${this.pragmaKeyword} `, - path.call(print, 'pragma'), - this.semicolon - ]; + return ['pragma ', path.call(print, 'pragma'), ';']; } } diff --git a/src/slang-nodes/ReceiveFunctionDefinition.ts b/src/slang-nodes/ReceiveFunctionDefinition.ts index 20f5da776..877ec2e89 100644 --- a/src/slang-nodes/ReceiveFunctionDefinition.ts +++ b/src/slang-nodes/ReceiveFunctionDefinition.ts @@ -16,8 +16,6 @@ export class ReceiveFunctionDefinition implements SlangNode { loc; - receiveKeyword: string; - parameters: ParametersDeclaration; attributes: ReceiveFunctionAttributes; @@ -32,7 +30,6 @@ export class ReceiveFunctionDefinition implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.receiveKeyword = ast.receiveKeyword.text; this.parameters = new ParametersDeclaration( ast.parameters, offsets[0], @@ -72,6 +69,6 @@ export class ReceiveFunctionDefinition implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return printFunction(this.receiveKeyword, this, path, print); + return printFunction('receive', this, path, print); } } diff --git a/src/slang-nodes/ReturnStatement.ts b/src/slang-nodes/ReturnStatement.ts index b96f395fb..276995025 100644 --- a/src/slang-nodes/ReturnStatement.ts +++ b/src/slang-nodes/ReturnStatement.ts @@ -34,12 +34,8 @@ export class ReturnStatement implements SlangNode { loc; - returnKeyword: string; - expression?: Expression; - semicolon: string; - constructor( ast: ast.ReturnStatement, offset: number, @@ -48,11 +44,9 @@ export class ReturnStatement implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.returnKeyword = ast.returnKeyword.text; if (ast.expression) { this.expression = new Expression(ast.expression, offsets[0], options); } - this.semicolon = ast.semicolon.text; metadata = updateMetadata(metadata, [this.expression]); @@ -65,10 +59,6 @@ export class ReturnStatement implements SlangNode { print: (path: AstPath) => Doc, options: ParserOptions ): Doc { - return [ - this.returnKeyword, - printExpression(this, path, print, options), - this.semicolon - ]; + return ['return', printExpression(this, path, print, options), ';']; } } diff --git a/src/slang-nodes/ReturnsDeclaration.ts b/src/slang-nodes/ReturnsDeclaration.ts index 053ea2f81..59b617001 100644 --- a/src/slang-nodes/ReturnsDeclaration.ts +++ b/src/slang-nodes/ReturnsDeclaration.ts @@ -16,8 +16,6 @@ export class ReturnsDeclaration implements SlangNode { loc; - returnsKeyword: string; - variables: ParametersDeclaration; constructor( @@ -28,7 +26,6 @@ export class ReturnsDeclaration implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.returnsKeyword = ast.returnsKeyword.text; this.variables = new ParametersDeclaration( ast.variables, offsets[0], @@ -45,6 +42,6 @@ export class ReturnsDeclaration implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return [`${this.returnsKeyword} `, group(path.call(print, 'variables'))]; + return ['returns ', group(path.call(print, 'variables'))]; } } diff --git a/src/slang-nodes/RevertStatement.ts b/src/slang-nodes/RevertStatement.ts index fdb15755a..2e03a0f69 100644 --- a/src/slang-nodes/RevertStatement.ts +++ b/src/slang-nodes/RevertStatement.ts @@ -14,14 +14,10 @@ export class RevertStatement implements SlangNode { loc; - revertKeyword: string; - error?: IdentifierPath; arguments: ArgumentsDeclaration; - semicolon: string; - constructor( ast: ast.RevertStatement, offset: number, @@ -30,7 +26,6 @@ export class RevertStatement implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.revertKeyword = ast.revertKeyword.text; let i = 0; if (ast.error) { this.error = new IdentifierPath(ast.error, offsets[i]); @@ -41,7 +36,6 @@ export class RevertStatement implements SlangNode { offsets[i], options ); - this.semicolon = ast.semicolon.text; metadata = updateMetadata(metadata, [this.error, this.arguments]); @@ -54,10 +48,10 @@ export class RevertStatement implements SlangNode { print: (path: AstPath) => Doc ): Doc { return [ - `${this.revertKeyword} `, + 'revert ', this.error ? path.call(print, 'error') : '', path.call(print, 'arguments'), - this.semicolon + ';' ]; } } diff --git a/src/slang-nodes/StateVariableDefinition.ts b/src/slang-nodes/StateVariableDefinition.ts index b5e06c308..c6b89004b 100644 --- a/src/slang-nodes/StateVariableDefinition.ts +++ b/src/slang-nodes/StateVariableDefinition.ts @@ -23,8 +23,6 @@ export class StateVariableDefinition implements SlangNode { value?: StateVariableDefinitionValue; - semicolon: string; - constructor( ast: ast.StateVariableDefinition, offset: number, @@ -39,7 +37,6 @@ export class StateVariableDefinition implements SlangNode { this.value = ast.value ? new StateVariableDefinitionValue(ast.value, offsets[2], options) : undefined; - this.semicolon = ast.semicolon.text; metadata = updateMetadata(metadata, [ this.typeName, @@ -60,7 +57,7 @@ export class StateVariableDefinition implements SlangNode { path.call(print, 'attributes'), ` ${this.name}`, this.value ? path.call(print, 'value') : '', - this.semicolon + ';' ]; } } diff --git a/src/slang-nodes/StateVariableDefinitionValue.ts b/src/slang-nodes/StateVariableDefinitionValue.ts index 280b7a754..36e4670a7 100644 --- a/src/slang-nodes/StateVariableDefinitionValue.ts +++ b/src/slang-nodes/StateVariableDefinitionValue.ts @@ -16,8 +16,6 @@ export class StateVariableDefinitionValue implements SlangNode { loc; - equal: string; - value: Expression; constructor( @@ -28,7 +26,6 @@ export class StateVariableDefinitionValue implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.equal = ast.equal.text; this.value = new Expression(ast.value, offsets[0], options); metadata = updateMetadata(metadata, [this.value]); @@ -43,7 +40,7 @@ export class StateVariableDefinitionValue implements SlangNode { ): Doc { return typeof this.value.variant !== 'string' && this.value.variant.kind === NonterminalKind.ArrayExpression - ? [` ${this.equal} `, path.call(print, 'value')] - : group([` ${this.equal}`, indent([line, path.call(print, 'value')])]); + ? [' = ', path.call(print, 'value')] + : group([' =', indent([line, path.call(print, 'value')])]); } } diff --git a/src/slang-nodes/Statements.ts b/src/slang-nodes/Statements.ts index ac752636d..e69f98e04 100644 --- a/src/slang-nodes/Statements.ts +++ b/src/slang-nodes/Statements.ts @@ -44,8 +44,7 @@ export class Statements implements SlangNode { print: (path: AstPath) => Doc, options: ParserOptions ): Doc { - return this.items.length === 0 && - (!this.comments || this.comments.length === 0) + return this.items.length === 0 && this.comments.length === 0 ? '' : printSeparatedItem( [ diff --git a/src/slang-nodes/StructDefinition.ts b/src/slang-nodes/StructDefinition.ts index 33ea86380..405d82f7e 100644 --- a/src/slang-nodes/StructDefinition.ts +++ b/src/slang-nodes/StructDefinition.ts @@ -13,16 +13,10 @@ export class StructDefinition implements SlangNode { loc; - structKeyword: string; - name: string; - openBrace: string; - members: StructMembers; - closeBrace: string; - constructor( ast: ast.StructDefinition, offset: number, @@ -31,11 +25,8 @@ export class StructDefinition implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.structKeyword = ast.structKeyword.text; this.name = ast.name.text; - this.openBrace = ast.openBrace.text; this.members = new StructMembers(ast.members, offsets[0], options); - this.closeBrace = ast.closeBrace.text; metadata = updateMetadata(metadata, [this.members]); @@ -47,10 +38,6 @@ export class StructDefinition implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return [ - `${this.structKeyword} ${this.name} ${this.openBrace}`, - path.call(print, 'members'), - this.closeBrace - ]; + return [`struct ${this.name} {`, path.call(print, 'members'), '}']; } } diff --git a/src/slang-nodes/StructMember.ts b/src/slang-nodes/StructMember.ts index c562bc0d6..13c2ded53 100644 --- a/src/slang-nodes/StructMember.ts +++ b/src/slang-nodes/StructMember.ts @@ -17,8 +17,6 @@ export class StructMember implements SlangNode { name: string; - semicolon: string; - constructor( ast: ast.StructMember, offset: number, @@ -29,7 +27,6 @@ export class StructMember implements SlangNode { this.typeName = new TypeName(ast.typeName, offsets[0], options); this.name = ast.name.text; - this.semicolon = ast.semicolon.text; metadata = updateMetadata(metadata, [this.typeName]); @@ -41,6 +38,6 @@ export class StructMember implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return [path.call(print, 'typeName'), ` ${this.name}${this.semicolon}`]; + return [path.call(print, 'typeName'), ` ${this.name};`]; } } diff --git a/src/slang-nodes/ThrowStatement.ts b/src/slang-nodes/ThrowStatement.ts index 60d4c2d0a..d17b4794e 100644 --- a/src/slang-nodes/ThrowStatement.ts +++ b/src/slang-nodes/ThrowStatement.ts @@ -12,21 +12,14 @@ export class ThrowStatement implements SlangNode { loc; - throwKeyword: string; - - semicolon: string; - constructor(ast: ast.ThrowStatement, offset: number) { const metadata = getNodeMetadata(ast, offset); - this.throwKeyword = ast.throwKeyword.text; - this.semicolon = ast.semicolon.text; - this.comments = metadata.comments; this.loc = metadata.loc; } print(): Doc { - return `${this.throwKeyword}${this.semicolon}`; + return 'throw;'; } } diff --git a/src/slang-nodes/TryStatement.ts b/src/slang-nodes/TryStatement.ts index 3925beca8..fddb532c4 100644 --- a/src/slang-nodes/TryStatement.ts +++ b/src/slang-nodes/TryStatement.ts @@ -20,8 +20,6 @@ export class TryStatement implements SlangNode { loc; - tryKeyword; - expression: Expression; returns?: ReturnsDeclaration; @@ -38,7 +36,6 @@ export class TryStatement implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.tryKeyword = ast.tryKeyword.text; this.expression = new Expression(ast.expression, offsets[0], options); let i = 1; if (ast.returns) { @@ -65,7 +62,7 @@ export class TryStatement implements SlangNode { print: (path: AstPath) => Doc ): Doc { return [ - this.tryKeyword, + 'try', printSeparatedItem(path.call(print, 'expression'), { firstSeparator: line }), diff --git a/src/slang-nodes/TupleDeconstructionStatement.ts b/src/slang-nodes/TupleDeconstructionStatement.ts index f3df87140..2f4592642 100644 --- a/src/slang-nodes/TupleDeconstructionStatement.ts +++ b/src/slang-nodes/TupleDeconstructionStatement.ts @@ -19,18 +19,10 @@ export class TupleDeconstructionStatement implements SlangNode { varKeyword?: string; - openParen: string; - elements: TupleDeconstructionElements; - closeParen: string; - - equal: string; - expression: Expression; - semicolon: string; - constructor( ast: ast.TupleDeconstructionStatement, offset: number, @@ -40,16 +32,12 @@ export class TupleDeconstructionStatement implements SlangNode { const { offsets } = metadata; this.varKeyword = ast.varKeyword?.text; - this.openParen = ast.openParen.text; this.elements = new TupleDeconstructionElements( ast.elements, offsets[0], options ); - this.closeParen = ast.closeParen.text; - this.equal = ast.equal.text; this.expression = new Expression(ast.expression, offsets[1], options); - this.semicolon = ast.semicolon.text; metadata = updateMetadata(metadata, [this.elements, this.expression]); @@ -63,15 +51,12 @@ export class TupleDeconstructionStatement implements SlangNode { ): Doc { return [ this.varKeyword ? this.varKeyword : '', - this.openParen, + '(', path.call(print, 'elements'), typeof this.expression.variant !== 'string' && this.expression.variant.kind === NonterminalKind.TupleExpression - ? [`${this.closeParen} ${this.equal} `, path.call(print, 'expression')] - : group([ - `${this.closeParen} ${this.equal}`, - indent([line, path.call(print, 'expression'), this.semicolon]) - ]) + ? [') = ', path.call(print, 'expression')] + : group([') =', indent([line, path.call(print, 'expression'), ';'])]) ]; } } diff --git a/src/slang-nodes/TupleExpression.ts b/src/slang-nodes/TupleExpression.ts index 0efcb80b8..0f5e350ea 100644 --- a/src/slang-nodes/TupleExpression.ts +++ b/src/slang-nodes/TupleExpression.ts @@ -13,12 +13,8 @@ export class TupleExpression implements SlangNode { loc; - openParen: string; - items: TupleValues; - closeParen: string; - constructor( ast: ast.TupleExpression, offset: number, @@ -27,9 +23,7 @@ export class TupleExpression implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.openParen = ast.openParen.text; this.items = new TupleValues(ast.items, offsets[0], options); - this.closeParen = ast.closeParen.text; metadata = updateMetadata(metadata, [this.items]); @@ -41,6 +35,6 @@ export class TupleExpression implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return [this.openParen, path.call(print, 'items'), this.closeParen]; + return ['(', path.call(print, 'items'), ')']; } } diff --git a/src/slang-nodes/TypeExpression.ts b/src/slang-nodes/TypeExpression.ts index 251fabc06..ea8a984f4 100644 --- a/src/slang-nodes/TypeExpression.ts +++ b/src/slang-nodes/TypeExpression.ts @@ -13,14 +13,8 @@ export class TypeExpression implements SlangNode { loc; - typeKeyword: string; - - openParen: string; - typeName: TypeName; - closeParen: string; - constructor( ast: ast.TypeExpression, offset: number, @@ -29,10 +23,7 @@ export class TypeExpression implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.typeKeyword = ast.typeKeyword.text; - this.openParen = ast.openParen.text; this.typeName = new TypeName(ast.typeName, offsets[0], options); - this.closeParen = ast.closeParen.text; metadata = updateMetadata(metadata, [this.typeName]); diff --git a/src/slang-nodes/UncheckedBlock.ts b/src/slang-nodes/UncheckedBlock.ts index 7e3ecaaf9..c3b9889a2 100644 --- a/src/slang-nodes/UncheckedBlock.ts +++ b/src/slang-nodes/UncheckedBlock.ts @@ -13,8 +13,6 @@ export class UncheckedBlock implements SlangNode { loc; - uncheckedKeyword: string; - block: Block; constructor( @@ -25,7 +23,6 @@ export class UncheckedBlock implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.uncheckedKeyword = ast.uncheckedKeyword.text; this.block = new Block(ast.block, offsets[0], options); metadata = updateMetadata(metadata, [this.block]); @@ -38,6 +35,6 @@ export class UncheckedBlock implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return [`${this.uncheckedKeyword} `, path.call(print, 'block')]; + return ['unchecked ', path.call(print, 'block')]; } } diff --git a/src/slang-nodes/UnnamedFunctionDefinition.ts b/src/slang-nodes/UnnamedFunctionDefinition.ts index 3317b55e5..2d4689501 100644 --- a/src/slang-nodes/UnnamedFunctionDefinition.ts +++ b/src/slang-nodes/UnnamedFunctionDefinition.ts @@ -16,8 +16,6 @@ export class UnnamedFunctionDefinition implements SlangNode { loc; - functionKeyword: string; - parameters: ParametersDeclaration; attributes: UnnamedFunctionAttributes; @@ -32,7 +30,6 @@ export class UnnamedFunctionDefinition implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.functionKeyword = ast.functionKeyword.text; this.parameters = new ParametersDeclaration( ast.parameters, offsets[0], @@ -69,6 +66,6 @@ export class UnnamedFunctionDefinition implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return printFunction(this.functionKeyword, this, path, print); + return printFunction('function', this, path, print); } } diff --git a/src/slang-nodes/UserDefinedValueTypeDefinition.ts b/src/slang-nodes/UserDefinedValueTypeDefinition.ts index 65137297c..82201c550 100644 --- a/src/slang-nodes/UserDefinedValueTypeDefinition.ts +++ b/src/slang-nodes/UserDefinedValueTypeDefinition.ts @@ -13,25 +13,16 @@ export class UserDefinedValueTypeDefinition implements SlangNode { loc; - typeKeyword: string; - name: string; - isKeyword: string; - valueType: ElementaryType; - semicolon: string; - constructor(ast: ast.UserDefinedValueTypeDefinition, offset: number) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.typeKeyword = ast.typeKeyword.text; this.name = ast.name.text; - this.isKeyword = ast.isKeyword.text; this.valueType = new ElementaryType(ast.valueType, offsets[0]); - this.semicolon = ast.semicolon.text; metadata = updateMetadata(metadata, [this.valueType]); @@ -43,10 +34,6 @@ export class UserDefinedValueTypeDefinition implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return [ - `${this.typeKeyword} ${this.name} ${this.isKeyword} `, - path.call(print, 'valueType'), - this.semicolon - ]; + return [`type ${this.name} is `, path.call(print, 'valueType'), ';']; } } diff --git a/src/slang-nodes/UsingAlias.ts b/src/slang-nodes/UsingAlias.ts index 1baee70ad..300567b3a 100644 --- a/src/slang-nodes/UsingAlias.ts +++ b/src/slang-nodes/UsingAlias.ts @@ -13,15 +13,12 @@ export class UsingAlias implements SlangNode { loc; - asKeyword: string; - operator: UsingOperator; constructor(ast: ast.UsingAlias, offset: number) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.asKeyword = ast.asKeyword.text; this.operator = new UsingOperator(ast.operator, offsets[0]); metadata = updateMetadata(metadata, [this.operator]); @@ -34,6 +31,6 @@ export class UsingAlias implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return [` ${this.asKeyword} `, path.call(print, 'operator')]; + return [' as ', path.call(print, 'operator')]; } } diff --git a/src/slang-nodes/UsingDeconstruction.ts b/src/slang-nodes/UsingDeconstruction.ts index a84452a9d..a11a2feb8 100644 --- a/src/slang-nodes/UsingDeconstruction.ts +++ b/src/slang-nodes/UsingDeconstruction.ts @@ -13,19 +13,13 @@ export class UsingDeconstruction implements SlangNode { loc; - openBrace: string; - symbols: UsingDeconstructionSymbols; - closeBrace: string; - constructor(ast: ast.UsingDeconstruction, offset: number) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.openBrace = ast.openBrace.text; this.symbols = new UsingDeconstructionSymbols(ast.symbols, offsets[0]); - this.closeBrace = ast.closeBrace.text; metadata = updateMetadata(metadata, [this.symbols]); @@ -37,6 +31,6 @@ export class UsingDeconstruction implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return [this.openBrace, path.call(print, 'symbols'), this.closeBrace]; + return ['{', path.call(print, 'symbols'), '}']; } } diff --git a/src/slang-nodes/UsingDirective.ts b/src/slang-nodes/UsingDirective.ts index efd5dbb40..978d5e446 100644 --- a/src/slang-nodes/UsingDirective.ts +++ b/src/slang-nodes/UsingDirective.ts @@ -14,18 +14,12 @@ export class UsingDirective implements SlangNode { loc; - usingKeyword: string; - clause: UsingClause; - forKeyword: string; - target: UsingTarget; globalKeyword?: string; - semicolon: string; - constructor( ast: ast.UsingDirective, offset: number, @@ -34,12 +28,9 @@ export class UsingDirective implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.usingKeyword = ast.usingKeyword.text; this.clause = new UsingClause(ast.clause, offsets[0]); - this.forKeyword = ast.forKeyword.text; this.target = new UsingTarget(ast.target, offsets[1], options); this.globalKeyword = ast.globalKeyword?.text; - this.semicolon = ast.semicolon.text; metadata = updateMetadata(metadata, [this.clause, this.target]); @@ -52,11 +43,12 @@ export class UsingDirective implements SlangNode { print: (path: AstPath) => Doc ): Doc { return [ - `${this.usingKeyword} `, + 'using ', path.call(print, 'clause'), - ` ${this.forKeyword} `, + ' for ', path.call(print, 'target'), - `${this.globalKeyword ? ` ${this.globalKeyword}` : ''}${this.semicolon}` + this.globalKeyword ? ' global' : '', + ';' ]; } } diff --git a/src/slang-nodes/VariableDeclarationStatement.ts b/src/slang-nodes/VariableDeclarationStatement.ts index dc498a0dc..729050c2b 100644 --- a/src/slang-nodes/VariableDeclarationStatement.ts +++ b/src/slang-nodes/VariableDeclarationStatement.ts @@ -26,8 +26,6 @@ export class VariableDeclarationStatement implements SlangNode { value?: VariableDeclarationValue; - semicolon: string; - constructor( ast: ast.VariableDeclarationStatement, offset: number, @@ -52,7 +50,6 @@ export class VariableDeclarationStatement implements SlangNode { if (ast.value) { this.value = new VariableDeclarationValue(ast.value, offsets[i], options); } - this.semicolon = ast.semicolon.text; metadata = updateMetadata(metadata, [ this.variableType, @@ -86,7 +83,7 @@ export class VariableDeclarationStatement implements SlangNode { indentIfBreak(this.value ? path.call(print, 'value') : '', { groupId: declarationDoc.id! }), - this.semicolon + ';' ]; } } diff --git a/src/slang-nodes/VariableDeclarationValue.ts b/src/slang-nodes/VariableDeclarationValue.ts index cc8496a88..237853fd5 100644 --- a/src/slang-nodes/VariableDeclarationValue.ts +++ b/src/slang-nodes/VariableDeclarationValue.ts @@ -13,8 +13,6 @@ export class VariableDeclarationValue implements SlangNode { loc; - equal: string; - expression: Expression; constructor( @@ -25,7 +23,6 @@ export class VariableDeclarationValue implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.equal = ast.equal.text; this.expression = new Expression(ast.expression, offsets[0], options); metadata = updateMetadata(metadata, [this.expression]); @@ -38,6 +35,6 @@ export class VariableDeclarationValue implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return [` ${this.equal} `, path.call(print, 'expression')]; + return [' = ', path.call(print, 'expression')]; } } diff --git a/src/slang-nodes/VersionPragma.ts b/src/slang-nodes/VersionPragma.ts index 0f9efbcd1..3e9fcfae5 100644 --- a/src/slang-nodes/VersionPragma.ts +++ b/src/slang-nodes/VersionPragma.ts @@ -13,15 +13,12 @@ export class VersionPragma implements SlangNode { loc; - solidityKeyword: string; - sets: VersionExpressionSets; constructor(ast: ast.VersionPragma, offset: number) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.solidityKeyword = ast.solidityKeyword.text; this.sets = new VersionExpressionSets(ast.sets, offsets[0]); metadata = updateMetadata(metadata, [this.sets]); @@ -34,6 +31,6 @@ export class VersionPragma implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return [`${this.solidityKeyword} `, path.call(print, 'sets')]; + return ['solidity ', path.call(print, 'sets')]; } } diff --git a/src/slang-nodes/WhileStatement.ts b/src/slang-nodes/WhileStatement.ts index e16148a63..77154068b 100644 --- a/src/slang-nodes/WhileStatement.ts +++ b/src/slang-nodes/WhileStatement.ts @@ -18,14 +18,8 @@ export class WhileStatement implements SlangNode { loc; - whileKeyword: string; - - openParen: string; - condition: Expression; - closeParen: string; - body: Statement; constructor( @@ -36,10 +30,7 @@ export class WhileStatement implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.whileKeyword = ast.whileKeyword.text; - this.openParen = ast.openParen.text; this.condition = new Expression(ast.condition, offsets[0], options); - this.closeParen = ast.closeParen.text; this.body = new Statement(ast.body, offsets[1], options); metadata = updateMetadata(metadata, [this.condition, this.body]); @@ -53,9 +44,9 @@ export class WhileStatement implements SlangNode { print: (path: AstPath) => Doc ): Doc { return [ - `${this.whileKeyword} ${this.openParen}`, + 'while (', printSeparatedItem(path.call(print, 'condition')), - this.closeParen, + ')', this.body.variant.kind === NonterminalKind.Block ? [' ', path.call(print, 'body')] : group(indent([line, path.call(print, 'body')])) diff --git a/src/slang-nodes/YulBlock.ts b/src/slang-nodes/YulBlock.ts index 6b823a9c8..cbfb607de 100644 --- a/src/slang-nodes/YulBlock.ts +++ b/src/slang-nodes/YulBlock.ts @@ -13,12 +13,8 @@ export class YulBlock implements SlangNode { loc; - openBrace: string; - statements: YulStatements; - closeBrace: string; - constructor( ast: ast.YulBlock, offset: number, @@ -27,9 +23,7 @@ export class YulBlock implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.openBrace = ast.openBrace.text; this.statements = new YulStatements(ast.statements, offsets[0], options); - this.closeBrace = ast.closeBrace.text; metadata = updateMetadata(metadata, [this.statements]); @@ -38,6 +32,6 @@ export class YulBlock implements SlangNode { } print(path: AstPath, print: (path: AstPath) => Doc): Doc { - return [this.openBrace, path.call(print, 'statements'), this.closeBrace]; + return ['{', path.call(print, 'statements'), '}']; } } diff --git a/src/slang-nodes/YulBreakStatement.ts b/src/slang-nodes/YulBreakStatement.ts index 4c0f9df49..efe3cb52a 100644 --- a/src/slang-nodes/YulBreakStatement.ts +++ b/src/slang-nodes/YulBreakStatement.ts @@ -12,18 +12,14 @@ export class YulBreakStatement implements SlangNode { loc; - breakKeyword: string; - constructor(ast: ast.YulBreakStatement, offset: number) { const metadata = getNodeMetadata(ast, offset); - this.breakKeyword = ast.breakKeyword.text; - this.comments = metadata.comments; this.loc = metadata.loc; } print(): Doc { - return this.breakKeyword; + return 'break'; } } diff --git a/src/slang-nodes/YulColonEqual.ts b/src/slang-nodes/YulColonEqual.ts index 0b7468f64..b3eb3cc0c 100644 --- a/src/slang-nodes/YulColonEqual.ts +++ b/src/slang-nodes/YulColonEqual.ts @@ -12,21 +12,14 @@ export class YulColonEqual implements SlangNode { loc; - colon: string; - - equal: string; - constructor(ast: ast.YulColonEqual, offset: number) { const metadata = getNodeMetadata(ast, offset); - this.colon = ast.colon.text; - this.equal = ast.equal.text; - this.comments = metadata.comments; this.loc = metadata.loc; } print(): Doc { - return `${this.colon}${this.equal}`; + return ':='; } } diff --git a/src/slang-nodes/YulContinueStatement.ts b/src/slang-nodes/YulContinueStatement.ts index 1c64d7e23..aecfa89c7 100644 --- a/src/slang-nodes/YulContinueStatement.ts +++ b/src/slang-nodes/YulContinueStatement.ts @@ -12,18 +12,14 @@ export class YulContinueStatement implements SlangNode { loc; - continueKeyword: string; - constructor(ast: ast.YulContinueStatement, offset: number) { const metadata = getNodeMetadata(ast, offset); - this.continueKeyword = ast.continueKeyword.text; - this.comments = metadata.comments; this.loc = metadata.loc; } print(): Doc { - return this.continueKeyword; + return 'continue'; } } diff --git a/src/slang-nodes/YulDefaultCase.ts b/src/slang-nodes/YulDefaultCase.ts index d8aeda6cb..7d32fbf31 100644 --- a/src/slang-nodes/YulDefaultCase.ts +++ b/src/slang-nodes/YulDefaultCase.ts @@ -13,8 +13,6 @@ export class YulDefaultCase implements SlangNode { loc; - defaultKeyword: string; - body: YulBlock; constructor( @@ -25,7 +23,6 @@ export class YulDefaultCase implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.defaultKeyword = ast.defaultKeyword.text; this.body = new YulBlock(ast.body, offsets[0], options); metadata = updateMetadata(metadata, [this.body]); @@ -38,6 +35,6 @@ export class YulDefaultCase implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return [`${this.defaultKeyword} `, path.call(print, 'body')]; + return ['default ', path.call(print, 'body')]; } } diff --git a/src/slang-nodes/YulForStatement.ts b/src/slang-nodes/YulForStatement.ts index 20f580bf6..5d375fd28 100644 --- a/src/slang-nodes/YulForStatement.ts +++ b/src/slang-nodes/YulForStatement.ts @@ -14,8 +14,6 @@ export class YulForStatement implements SlangNode { loc; - forKeyword: string; - initialization: YulBlock; condition: YulExpression; @@ -32,7 +30,6 @@ export class YulForStatement implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.forKeyword = ast.forKeyword.text; this.initialization = new YulBlock(ast.initialization, offsets[0], options); this.condition = new YulExpression(ast.condition, offsets[1], options); this.iterator = new YulBlock(ast.iterator, offsets[2], options); @@ -54,7 +51,7 @@ export class YulForStatement implements SlangNode { print: (path: AstPath) => Doc ): Doc { return [ - `${this.forKeyword} `, + 'for ', path.call(print, 'initialization'), ' ', path.call(print, 'condition'), diff --git a/src/slang-nodes/YulFunctionCallExpression.ts b/src/slang-nodes/YulFunctionCallExpression.ts index 87e50ca0b..fc43092f8 100644 --- a/src/slang-nodes/YulFunctionCallExpression.ts +++ b/src/slang-nodes/YulFunctionCallExpression.ts @@ -16,12 +16,8 @@ export class YulFunctionCallExpression implements SlangNode { operand: YulExpression; - openParen: string; - arguments: YulArguments; - closeParen: string; - constructor( ast: ast.YulFunctionCallExpression, offset: number, @@ -31,9 +27,7 @@ export class YulFunctionCallExpression implements SlangNode { const { offsets } = metadata; this.operand = new YulExpression(ast.operand, offsets[0], options); - this.openParen = ast.openParen.text; this.arguments = new YulArguments(ast.arguments, offsets[1], options); - this.closeParen = ast.closeParen.text; metadata = updateMetadata(metadata, [this.operand, this.arguments]); @@ -47,9 +41,9 @@ export class YulFunctionCallExpression implements SlangNode { ): Doc { return [ path.call(print, 'operand'), - this.openParen, + '(', path.call(print, 'arguments'), - this.closeParen + ')' ]; } } diff --git a/src/slang-nodes/YulFunctionDefinition.ts b/src/slang-nodes/YulFunctionDefinition.ts index 62f07d26d..a197966d9 100644 --- a/src/slang-nodes/YulFunctionDefinition.ts +++ b/src/slang-nodes/YulFunctionDefinition.ts @@ -15,9 +15,7 @@ export class YulFunctionDefinition implements SlangNode { loc; - functionKeyword; - - name; + name: string; parameters: YulParametersDeclaration; @@ -33,7 +31,6 @@ export class YulFunctionDefinition implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.functionKeyword = ast.functionKeyword.text; this.name = ast.name.text; this.parameters = new YulParametersDeclaration(ast.parameters, offsets[0]); let i = 1; @@ -58,7 +55,7 @@ export class YulFunctionDefinition implements SlangNode { print: (path: AstPath) => Doc ): Doc { return [ - `${this.functionKeyword} ${this.name}`, + `function ${this.name}`, path.call(print, 'parameters'), this.returns ? path.call(print, 'returns') : ' ', path.call(print, 'body') diff --git a/src/slang-nodes/YulIfStatement.ts b/src/slang-nodes/YulIfStatement.ts index b03a45fe1..49d4f9ff3 100644 --- a/src/slang-nodes/YulIfStatement.ts +++ b/src/slang-nodes/YulIfStatement.ts @@ -14,8 +14,6 @@ export class YulIfStatement implements SlangNode { loc; - ifKeyword: string; - condition: YulExpression; body: YulBlock; @@ -28,7 +26,6 @@ export class YulIfStatement implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.ifKeyword = ast.ifKeyword.text; this.condition = new YulExpression(ast.condition, offsets[0], options); this.body = new YulBlock(ast.body, offsets[1], options); @@ -43,7 +40,7 @@ export class YulIfStatement implements SlangNode { print: (path: AstPath) => Doc ): Doc { return [ - `${this.ifKeyword} `, + 'if ', path.call(print, 'condition'), ' ', path.call(print, 'body') diff --git a/src/slang-nodes/YulLabel.ts b/src/slang-nodes/YulLabel.ts index d5012be6b..4c8311009 100644 --- a/src/slang-nodes/YulLabel.ts +++ b/src/slang-nodes/YulLabel.ts @@ -17,19 +17,16 @@ export class YulLabel implements SlangNode { label: string; - colon: string; - constructor(ast: ast.YulLabel, offset: number) { const metadata = getNodeMetadata(ast, offset); this.label = ast.label.text; - this.colon = ast.colon.text; this.comments = metadata.comments; this.loc = metadata.loc; } print(): Doc { - return [dedent(line), `${this.label}${this.colon}`]; + return [dedent(line), `${this.label}:`]; } } diff --git a/src/slang-nodes/YulLeaveStatement.ts b/src/slang-nodes/YulLeaveStatement.ts index c2a1c3653..de493c5e1 100644 --- a/src/slang-nodes/YulLeaveStatement.ts +++ b/src/slang-nodes/YulLeaveStatement.ts @@ -12,18 +12,14 @@ export class YulLeaveStatement implements SlangNode { loc; - leaveKeyword: string; - constructor(ast: ast.YulLeaveStatement, offset: number) { const metadata = getNodeMetadata(ast, offset); - this.leaveKeyword = ast.leaveKeyword.text; - this.comments = metadata.comments; this.loc = metadata.loc; } print(): Doc { - return this.leaveKeyword; + return 'leave'; } } diff --git a/src/slang-nodes/YulParametersDeclaration.ts b/src/slang-nodes/YulParametersDeclaration.ts index d63adaf5a..b382c0166 100644 --- a/src/slang-nodes/YulParametersDeclaration.ts +++ b/src/slang-nodes/YulParametersDeclaration.ts @@ -13,19 +13,13 @@ export class YulParametersDeclaration implements SlangNode { loc; - openParen: string; - parameters: YulParameters; - closeParen: string; - constructor(ast: ast.YulParametersDeclaration, offset: number) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.openParen = ast.openParen.text; this.parameters = new YulParameters(ast.parameters, offsets[0]); - this.closeParen = ast.closeParen.text; metadata = updateMetadata(metadata, [this.parameters]); @@ -37,6 +31,6 @@ export class YulParametersDeclaration implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return [this.openParen, path.call(print, 'parameters'), this.closeParen]; + return ['(', path.call(print, 'parameters'), ')']; } } diff --git a/src/slang-nodes/YulStatements.ts b/src/slang-nodes/YulStatements.ts index 44009687d..f5a0b1df1 100644 --- a/src/slang-nodes/YulStatements.ts +++ b/src/slang-nodes/YulStatements.ts @@ -44,8 +44,7 @@ export class YulStatements implements SlangNode { print: (path: AstPath) => Doc, options: ParserOptions ): Doc { - return this.items.length === 0 && - (!this.comments || this.comments.length === 0) + return this.items.length === 0 && this.comments.length === 0 ? '' : printSeparatedItem( [ diff --git a/src/slang-nodes/YulSwitchStatement.ts b/src/slang-nodes/YulSwitchStatement.ts index 52cd1bb1c..352fe6470 100644 --- a/src/slang-nodes/YulSwitchStatement.ts +++ b/src/slang-nodes/YulSwitchStatement.ts @@ -17,8 +17,6 @@ export class YulSwitchStatement implements SlangNode { loc; - switchKeyword: string; - expression: YulExpression; cases: YulSwitchCases; @@ -31,7 +29,6 @@ export class YulSwitchStatement implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.switchKeyword = ast.switchKeyword.text; this.expression = new YulExpression(ast.expression, offsets[0], options); this.cases = new YulSwitchCases(ast.cases, offsets[1], options); @@ -46,7 +43,7 @@ export class YulSwitchStatement implements SlangNode { print: (path: AstPath) => Doc ): Doc { return [ - `${this.switchKeyword} `, + 'switch ', path.call(print, 'expression'), hardline, path.call(print, 'cases') diff --git a/src/slang-nodes/YulValueCase.ts b/src/slang-nodes/YulValueCase.ts index aa220954b..15ddfb639 100644 --- a/src/slang-nodes/YulValueCase.ts +++ b/src/slang-nodes/YulValueCase.ts @@ -14,8 +14,6 @@ export class YulValueCase implements SlangNode { loc; - caseKeyword: string; - value: YulLiteral; body: YulBlock; @@ -28,7 +26,6 @@ export class YulValueCase implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.caseKeyword = ast.caseKeyword.text; this.value = new YulLiteral(ast.value, offsets[0], options); this.body = new YulBlock(ast.body, offsets[1], options); @@ -42,11 +39,6 @@ export class YulValueCase implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return [ - `${this.caseKeyword} `, - path.call(print, 'value'), - ' ', - path.call(print, 'body') - ]; + return ['case ', path.call(print, 'value'), ' ', path.call(print, 'body')]; } } diff --git a/src/slang-nodes/YulVariableDeclarationStatement.ts b/src/slang-nodes/YulVariableDeclarationStatement.ts index 1fc186e44..98e6d5ef6 100644 --- a/src/slang-nodes/YulVariableDeclarationStatement.ts +++ b/src/slang-nodes/YulVariableDeclarationStatement.ts @@ -13,8 +13,6 @@ export class YulVariableDeclarationStatement implements SlangNode { loc; - letKeyword: string; - names: string; value?: YulVariableDeclarationValue; @@ -27,7 +25,6 @@ export class YulVariableDeclarationStatement implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.letKeyword = ast.letKeyword.text; this.names = ast.names.text; if (ast.value) { this.value = new YulVariableDeclarationValue( @@ -47,9 +44,6 @@ export class YulVariableDeclarationStatement implements SlangNode { path: AstPath, print: (path: AstPath) => Doc ): Doc { - return [ - `${this.letKeyword} ${this.names} `, - this.value ? path.call(print, 'value') : '' - ]; + return [`let ${this.names} `, this.value ? path.call(print, 'value') : '']; } } diff --git a/src/slang-printers/print-comments.ts b/src/slang-printers/print-comments.ts index e931d4c6f..39927a3a9 100644 --- a/src/slang-printers/print-comments.ts +++ b/src/slang-printers/print-comments.ts @@ -9,7 +9,6 @@ import type { DocV2 } from './types'; const { join, line } = doc.builders; export function printComments(node: AstNode, path: AstPath): Doc[] { - if (!node.comments) return []; const document = join( line, path diff --git a/src/slang-utils/create-hug-function.ts b/src/slang-utils/create-hug-function.ts index bd7ef9eea..d8cc1b21e 100644 --- a/src/slang-utils/create-hug-function.ts +++ b/src/slang-utils/create-hug-function.ts @@ -32,7 +32,6 @@ export function createHugFunction( kind: { value: NonterminalKind.TupleExpression, ...objectConfig }, loc: { value: { ...loc }, ...objectConfig }, comments: { value: [], ...objectConfig }, - openParen: { value: '(', ...objectConfig }, items: { value: Object.create(TupleValues.prototype, { kind: { value: NonterminalKind.TupleValues, ...objectConfig }, @@ -55,8 +54,7 @@ export function createHugFunction( separators: { value: [], ...objectConfig } }) as TupleValues, ...objectConfig - }, - closeParen: { value: ')', ...objectConfig } + } }) as TupleExpression, ...objectConfig } diff --git a/src/types.d.ts b/src/types.d.ts index 913619aa4..46864ec16 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -52,10 +52,10 @@ interface Metadata { } interface SlangNode { - get kind(): string; - comments?: Comment[]; + kind: string; + comments: Comment[]; loc: Location; - print?( + print( path: AstPath, print: (path: AstPath) => Doc, options: ParserOptions diff --git a/tsconfig.json b/tsconfig.json index d74332c94..cec75c6de 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,6 +3,7 @@ "allowJs": true, "outDir": "./dist/", "noImplicitAny": true, + "strictPropertyInitialization": true, "sourceMap": true, "target": "es6", "module": "es2022", From ad2e2c98c4a3cd7072c676c0389e36d0f074e631 Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 7 Aug 2024 00:49:42 +1200 Subject: [PATCH 119/160] introducing StrictAstNode to standardise PrintFunction across the codebase --- src/index.ts | 5 ++- src/slang-comments/handlers/types.d.ts | 8 ++-- src/slang-nodes/AdditiveExpression.ts | 4 +- src/slang-nodes/AndExpression.ts | 4 +- src/slang-nodes/ArgumentsDeclaration.ts | 7 +-- src/slang-nodes/ArrayExpression.ts | 7 +-- src/slang-nodes/ArrayTypeName.ts | 7 +-- src/slang-nodes/ArrayValues.ts | 7 +-- src/slang-nodes/AssemblyFlags.ts | 7 +-- src/slang-nodes/AssemblyFlagsDeclaration.ts | 7 +-- src/slang-nodes/AssemblyStatement.ts | 7 +-- src/slang-nodes/AssignmentExpression.ts | 7 +-- src/slang-nodes/BitwiseAndExpression.ts | 4 +- src/slang-nodes/BitwiseOrExpression.ts | 4 +- src/slang-nodes/BitwiseXorExpression.ts | 4 +- src/slang-nodes/Block.ts | 4 +- src/slang-nodes/CallOptions.ts | 4 +- src/slang-nodes/CallOptionsExpression.ts | 7 +-- src/slang-nodes/CatchClause.ts | 7 +-- src/slang-nodes/CatchClauseError.ts | 7 +-- src/slang-nodes/CatchClauses.ts | 7 +-- src/slang-nodes/ComparisonExpression.ts | 4 +- src/slang-nodes/ConditionalExpression.ts | 17 +++++--- src/slang-nodes/ConstantDefinition.ts | 2 +- src/slang-nodes/ConstructorAttribute.ts | 7 +-- src/slang-nodes/ConstructorAttributes.ts | 7 +-- src/slang-nodes/ConstructorDefinition.ts | 7 +-- src/slang-nodes/ContractDefinition.ts | 7 +-- src/slang-nodes/ContractMember.ts | 7 +-- src/slang-nodes/ContractMembers.ts | 4 +- src/slang-nodes/DecimalNumberExpression.ts | 7 +-- src/slang-nodes/DoWhileStatement.ts | 7 +-- src/slang-nodes/ElementaryType.ts | 7 +-- src/slang-nodes/ElseBranch.ts | 7 +-- src/slang-nodes/EmitStatement.ts | 7 +-- src/slang-nodes/EnumDefinition.ts | 7 +-- src/slang-nodes/EqualityExpression.ts | 4 +- src/slang-nodes/ErrorDefinition.ts | 7 +-- src/slang-nodes/ErrorParameter.ts | 7 +-- src/slang-nodes/ErrorParameters.ts | 7 +-- src/slang-nodes/ErrorParametersDeclaration.ts | 7 +-- src/slang-nodes/EventDefinition.ts | 7 +-- src/slang-nodes/EventParameter.ts | 7 +-- src/slang-nodes/EventParameters.ts | 7 +-- src/slang-nodes/EventParametersDeclaration.ts | 7 +-- src/slang-nodes/ExperimentalFeature.ts | 7 +-- src/slang-nodes/ExperimentalPragma.ts | 7 +-- src/slang-nodes/ExponentiationExpression.ts | 4 +- src/slang-nodes/Expression.ts | 7 +-- src/slang-nodes/ExpressionStatement.ts | 7 +-- src/slang-nodes/FallbackFunctionAttribute.ts | 7 +-- src/slang-nodes/FallbackFunctionAttributes.ts | 7 +-- src/slang-nodes/FallbackFunctionDefinition.ts | 7 +-- src/slang-nodes/ForStatement.ts | 7 +-- src/slang-nodes/ForStatementCondition.ts | 7 +-- src/slang-nodes/ForStatementInitialization.ts | 7 +-- src/slang-nodes/FunctionAttribute.ts | 7 +-- src/slang-nodes/FunctionAttributes.ts | 7 +-- src/slang-nodes/FunctionBody.ts | 7 +-- src/slang-nodes/FunctionCallExpression.ts | 7 +-- src/slang-nodes/FunctionDefinition.ts | 7 +-- src/slang-nodes/FunctionType.ts | 7 +-- src/slang-nodes/FunctionTypeAttributes.ts | 7 +-- src/slang-nodes/HexNumberExpression.ts | 7 +-- src/slang-nodes/HexStringLiterals.ts | 7 +-- src/slang-nodes/IfStatement.ts | 7 +-- src/slang-nodes/ImportClause.ts | 7 +-- src/slang-nodes/ImportDeconstruction.ts | 7 +-- src/slang-nodes/ImportDeconstructionSymbol.ts | 7 +-- .../ImportDeconstructionSymbols.ts | 4 +- src/slang-nodes/ImportDirective.ts | 7 +-- src/slang-nodes/IndexAccessEnd.ts | 7 +-- src/slang-nodes/IndexAccessExpression.ts | 7 +-- src/slang-nodes/InheritanceSpecifier.ts | 7 +-- src/slang-nodes/InheritanceType.ts | 7 +-- src/slang-nodes/InheritanceTypes.ts | 7 +-- src/slang-nodes/InterfaceDefinition.ts | 7 +-- src/slang-nodes/InterfaceMembers.ts | 4 +- src/slang-nodes/LibraryDefinition.ts | 7 +-- src/slang-nodes/LibraryMembers.ts | 4 +- src/slang-nodes/MappingKey.ts | 7 +-- src/slang-nodes/MappingKeyType.ts | 7 +-- src/slang-nodes/MappingType.ts | 7 +-- src/slang-nodes/MappingValue.ts | 7 +-- src/slang-nodes/MemberAccessExpression.ts | 16 ++++--- src/slang-nodes/ModifierAttribute.ts | 7 +-- src/slang-nodes/ModifierAttributes.ts | 7 +-- src/slang-nodes/ModifierDefinition.ts | 7 +-- src/slang-nodes/ModifierInvocation.ts | 7 +-- src/slang-nodes/MultiplicativeExpression.ts | 4 +- src/slang-nodes/NamedArgument.ts | 7 +-- src/slang-nodes/NamedArgumentGroup.ts | 7 +-- src/slang-nodes/NamedArguments.ts | 4 +- src/slang-nodes/NamedArgumentsDeclaration.ts | 7 +-- src/slang-nodes/NamedImport.ts | 7 +-- src/slang-nodes/NewExpression.ts | 7 +-- src/slang-nodes/OrExpression.ts | 4 +- src/slang-nodes/OverridePaths.ts | 2 +- src/slang-nodes/OverridePathsDeclaration.ts | 2 +- src/slang-nodes/OverrideSpecifier.ts | 7 +-- src/slang-nodes/Parameter.ts | 7 +-- src/slang-nodes/Parameters.ts | 7 +-- src/slang-nodes/ParametersDeclaration.ts | 7 +-- src/slang-nodes/PathImport.ts | 7 +-- src/slang-nodes/PositionalArguments.ts | 7 +-- .../PositionalArgumentsDeclaration.ts | 4 +- src/slang-nodes/PostfixExpression.ts | 7 +-- src/slang-nodes/Pragma.ts | 4 +- src/slang-nodes/PragmaDirective.ts | 7 +-- src/slang-nodes/PrefixExpression.ts | 7 +-- src/slang-nodes/ReceiveFunctionAttribute.ts | 7 +-- src/slang-nodes/ReceiveFunctionAttributes.ts | 7 +-- src/slang-nodes/ReceiveFunctionDefinition.ts | 7 +-- src/slang-nodes/ReturnStatement.ts | 6 +-- src/slang-nodes/ReturnsDeclaration.ts | 7 +-- src/slang-nodes/RevertStatement.ts | 7 +-- src/slang-nodes/ShiftExpression.ts | 4 +- src/slang-nodes/SourceUnit.ts | 4 +- src/slang-nodes/SourceUnitMember.ts | 7 +-- src/slang-nodes/SourceUnitMembers.ts | 4 +- src/slang-nodes/StateVariableAttribute.ts | 7 +-- src/slang-nodes/StateVariableAttributes.ts | 7 +-- src/slang-nodes/StateVariableDefinition.ts | 7 +-- .../StateVariableDefinitionValue.ts | 4 +- src/slang-nodes/Statement.ts | 4 +- src/slang-nodes/Statements.ts | 4 +- src/slang-nodes/StringExpression.ts | 7 +-- src/slang-nodes/StringLiterals.ts | 7 +-- src/slang-nodes/StructDefinition.ts | 7 +-- src/slang-nodes/StructMember.ts | 7 +-- src/slang-nodes/StructMembers.ts | 7 +-- src/slang-nodes/TryStatement.ts | 7 +-- src/slang-nodes/TupleDeconstructionElement.ts | 7 +-- .../TupleDeconstructionElements.ts | 7 +-- .../TupleDeconstructionStatement.ts | 6 +-- src/slang-nodes/TupleExpression.ts | 7 +-- src/slang-nodes/TupleMember.ts | 7 +-- src/slang-nodes/TupleValue.ts | 7 +-- src/slang-nodes/TupleValues.ts | 7 +-- src/slang-nodes/TypeExpression.ts | 2 +- src/slang-nodes/TypeName.ts | 4 +- src/slang-nodes/TypedTupleMember.ts | 7 +-- src/slang-nodes/UncheckedBlock.ts | 7 +-- src/slang-nodes/UnicodeStringLiterals.ts | 7 +-- src/slang-nodes/UnnamedFunctionAttribute.ts | 7 +-- src/slang-nodes/UnnamedFunctionAttributes.ts | 7 +-- src/slang-nodes/UnnamedFunctionDefinition.ts | 7 +-- src/slang-nodes/UntypedTupleMember.ts | 2 +- .../UserDefinedValueTypeDefinition.ts | 4 +- src/slang-nodes/UsingAlias.ts | 7 +-- src/slang-nodes/UsingClause.ts | 7 +-- src/slang-nodes/UsingDeconstruction.ts | 7 +-- src/slang-nodes/UsingDeconstructionSymbol.ts | 7 +-- src/slang-nodes/UsingDeconstructionSymbols.ts | 4 +- src/slang-nodes/UsingDirective.ts | 7 +-- src/slang-nodes/UsingTarget.ts | 7 +-- .../VariableDeclarationStatement.ts | 4 +- src/slang-nodes/VariableDeclarationType.ts | 7 +-- src/slang-nodes/VariableDeclarationValue.ts | 7 +-- src/slang-nodes/VersionComparator.ts | 7 +-- src/slang-nodes/VersionExpression.ts | 7 +-- src/slang-nodes/VersionExpressionSet.ts | 7 +-- src/slang-nodes/VersionExpressionSets.ts | 7 +-- src/slang-nodes/VersionPragma.ts | 7 +-- src/slang-nodes/VersionRange.ts | 8 +--- src/slang-nodes/WhileStatement.ts | 7 +-- src/slang-nodes/YulArguments.ts | 7 +-- src/slang-nodes/YulAssignmentOperator.ts | 7 +-- src/slang-nodes/YulBlock.ts | 4 +- src/slang-nodes/YulDefaultCase.ts | 7 +-- src/slang-nodes/YulExpression.ts | 7 +-- src/slang-nodes/YulForStatement.ts | 7 +-- src/slang-nodes/YulFunctionCallExpression.ts | 7 +-- src/slang-nodes/YulFunctionDefinition.ts | 7 +-- src/slang-nodes/YulIfStatement.ts | 7 +-- src/slang-nodes/YulLiteral.ts | 7 +-- src/slang-nodes/YulParametersDeclaration.ts | 7 +-- src/slang-nodes/YulPath.ts | 4 +- src/slang-nodes/YulPaths.ts | 4 +- src/slang-nodes/YulReturnsDeclaration.ts | 7 +-- .../YulStackAssignmentStatement.ts | 2 +- src/slang-nodes/YulStatement.ts | 7 +-- src/slang-nodes/YulStatements.ts | 4 +- src/slang-nodes/YulSwitchCase.ts | 7 +-- src/slang-nodes/YulSwitchCases.ts | 7 +-- src/slang-nodes/YulSwitchStatement.ts | 7 +-- src/slang-nodes/YulValueCase.ts | 7 +-- .../YulVariableAssignmentStatement.ts | 4 +- .../YulVariableDeclarationStatement.ts | 4 +- .../YulVariableDeclarationValue.ts | 7 +-- .../create-binary-operation-printer.ts | 13 ++++-- src/slang-printers/print-binary-operation.ts | 8 ++-- .../print-comparison-operation.ts | 8 ++-- src/slang-printers/print-function.ts | 4 +- src/slang-printers/print-logical-operation.ts | 10 +++-- .../print-preserving-empty-lines.ts | 8 ++-- src/slang-utils/backward-compatibility.ts | 5 +-- src/slang-utils/create-kind-check-function.ts | 7 +-- src/slang-utils/is-binary-operation.ts | 4 +- src/slang-utils/loc.ts | 2 + src/slang-utils/metadata.ts | 6 +-- src/slang-utils/sort-function-attributes.ts | 43 +++++++++++-------- src/slang-utils/types.d.ts | 6 +-- src/slangPrinter.ts | 31 +++++++------ src/types.d.ts | 12 ++++-- 205 files changed, 486 insertions(+), 893 deletions(-) diff --git a/src/index.ts b/src/index.ts index 6218e63e6..33956f2e9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -54,7 +54,10 @@ const canAttachComment = (node: { type: string }): boolean => node.type !== 'BlockComment' && node.type !== 'LineComment'; const slangCanAttachComment = (node: AstNode | Comment): boolean => - node.kind && !isComment(node); + typeof node !== 'string' && + typeof node !== 'undefined' && + node.kind && + !isComment(node); // https://prettier.io/docs/en/plugins.html#printers const printer = { diff --git a/src/slang-comments/handlers/types.d.ts b/src/slang-comments/handlers/types.d.ts index e1f044f43..79d60de5e 100644 --- a/src/slang-comments/handlers/types.d.ts +++ b/src/slang-comments/handlers/types.d.ts @@ -1,9 +1,9 @@ -import type { AstNode, Comment } from '../../types'; +import type { Comment, StrictAstNode } from '../../types'; interface HandlerParams { text: string; - precedingNode?: AstNode; - enclosingNode?: AstNode; - followingNode?: AstNode; + precedingNode?: StrictAstNode; + enclosingNode?: StrictAstNode; + followingNode?: StrictAstNode; comment: Comment; } diff --git a/src/slang-nodes/AdditiveExpression.ts b/src/slang-nodes/AdditiveExpression.ts index d6c8ae5bb..73038680b 100644 --- a/src/slang-nodes/AdditiveExpression.ts +++ b/src/slang-nodes/AdditiveExpression.ts @@ -6,7 +6,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const tryToHug = createHugFunction(['%']); @@ -46,7 +46,7 @@ export class AdditiveExpression implements SlangNode { print( path: AstPath, - print: (path: AstPath) => Doc, + print: PrintFunction, options: ParserOptions ): Doc { return printBinaryOperation(this, path, print, options); diff --git a/src/slang-nodes/AndExpression.ts b/src/slang-nodes/AndExpression.ts index e2c8da4eb..2f90afd70 100644 --- a/src/slang-nodes/AndExpression.ts +++ b/src/slang-nodes/AndExpression.ts @@ -5,7 +5,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class AndExpression implements SlangNode { readonly kind = NonterminalKind.AndExpression; @@ -40,7 +40,7 @@ export class AndExpression implements SlangNode { print( path: AstPath, - print: (path: AstPath) => Doc, + print: PrintFunction, options: ParserOptions ): Doc { return printLogicalOperation(this, path, print, options); diff --git a/src/slang-nodes/ArgumentsDeclaration.ts b/src/slang-nodes/ArgumentsDeclaration.ts index 31555090f..9706b8b1e 100644 --- a/src/slang-nodes/ArgumentsDeclaration.ts +++ b/src/slang-nodes/ArgumentsDeclaration.ts @@ -5,7 +5,7 @@ import { NamedArgumentsDeclaration } from './NamedArgumentsDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class ArgumentsDeclaration implements SlangNode { readonly kind = NonterminalKind.ArgumentsDeclaration; @@ -49,10 +49,7 @@ export class ArgumentsDeclaration implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/ArrayExpression.ts b/src/slang-nodes/ArrayExpression.ts index 4679e4837..166ba3ac2 100644 --- a/src/slang-nodes/ArrayExpression.ts +++ b/src/slang-nodes/ArrayExpression.ts @@ -5,7 +5,7 @@ import { ArrayValues } from './ArrayValues.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { group } = doc.builders; @@ -34,10 +34,7 @@ export class ArrayExpression implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return group(['[', path.call(print, 'items'), ']']); } } diff --git a/src/slang-nodes/ArrayTypeName.ts b/src/slang-nodes/ArrayTypeName.ts index 4773a574f..e04fc9664 100644 --- a/src/slang-nodes/ArrayTypeName.ts +++ b/src/slang-nodes/ArrayTypeName.ts @@ -5,7 +5,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class ArrayTypeName implements SlangNode { readonly kind = NonterminalKind.ArrayTypeName; @@ -37,10 +37,7 @@ export class ArrayTypeName implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [ path.call(print, 'operand'), '[', diff --git a/src/slang-nodes/ArrayValues.ts b/src/slang-nodes/ArrayValues.ts index 0925d36e1..683e46161 100644 --- a/src/slang-nodes/ArrayValues.ts +++ b/src/slang-nodes/ArrayValues.ts @@ -5,7 +5,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class ArrayValues implements SlangNode { readonly kind = NonterminalKind.ArrayValues; @@ -37,10 +37,7 @@ export class ArrayValues implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return printSeparatedList(path.map(print, 'items')); } } diff --git a/src/slang-nodes/AssemblyFlags.ts b/src/slang-nodes/AssemblyFlags.ts index 4c948dbc1..18a409d15 100644 --- a/src/slang-nodes/AssemblyFlags.ts +++ b/src/slang-nodes/AssemblyFlags.ts @@ -5,7 +5,7 @@ import { StringLiteral } from './StringLiteral.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class AssemblyFlags implements SlangNode { readonly kind = NonterminalKind.AssemblyFlags; @@ -37,10 +37,7 @@ export class AssemblyFlags implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return printSeparatedList(path.map(print, 'items')); } } diff --git a/src/slang-nodes/AssemblyFlagsDeclaration.ts b/src/slang-nodes/AssemblyFlagsDeclaration.ts index f66b0765f..d143a6c3c 100644 --- a/src/slang-nodes/AssemblyFlagsDeclaration.ts +++ b/src/slang-nodes/AssemblyFlagsDeclaration.ts @@ -4,7 +4,7 @@ import { AssemblyFlags } from './AssemblyFlags.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class AssemblyFlagsDeclaration implements SlangNode { readonly kind = NonterminalKind.AssemblyFlagsDeclaration; @@ -31,10 +31,7 @@ export class AssemblyFlagsDeclaration implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return ['(', path.call(print, 'flags'), ')']; } } diff --git a/src/slang-nodes/AssemblyStatement.ts b/src/slang-nodes/AssemblyStatement.ts index b5b6aa351..827beb758 100644 --- a/src/slang-nodes/AssemblyStatement.ts +++ b/src/slang-nodes/AssemblyStatement.ts @@ -6,7 +6,7 @@ import { YulBlock } from './YulBlock.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class AssemblyStatement implements SlangNode { readonly kind = NonterminalKind.AssemblyStatement; @@ -46,10 +46,7 @@ export class AssemblyStatement implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [ 'assembly ', this.label ? [path.call(print, 'label'), ' '] : '', diff --git a/src/slang-nodes/AssignmentExpression.ts b/src/slang-nodes/AssignmentExpression.ts index 6dd355119..72e2afba8 100644 --- a/src/slang-nodes/AssignmentExpression.ts +++ b/src/slang-nodes/AssignmentExpression.ts @@ -6,7 +6,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { group, indent, line } = doc.builders; @@ -41,10 +41,7 @@ export class AssignmentExpression implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [ path.call(print, 'leftOperand'), ` ${this.operator}`, diff --git a/src/slang-nodes/BitwiseAndExpression.ts b/src/slang-nodes/BitwiseAndExpression.ts index a84fdfd9b..69ca5cfe7 100644 --- a/src/slang-nodes/BitwiseAndExpression.ts +++ b/src/slang-nodes/BitwiseAndExpression.ts @@ -6,7 +6,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const tryToHug = createHugFunction(['+', '-', '*', '/', '**', '<<', '>>']); @@ -46,7 +46,7 @@ export class BitwiseAndExpression implements SlangNode { print( path: AstPath, - print: (path: AstPath) => Doc, + print: PrintFunction, options: ParserOptions ): Doc { return printBinaryOperation(this, path, print, options); diff --git a/src/slang-nodes/BitwiseOrExpression.ts b/src/slang-nodes/BitwiseOrExpression.ts index 1149e9c68..f8186451f 100644 --- a/src/slang-nodes/BitwiseOrExpression.ts +++ b/src/slang-nodes/BitwiseOrExpression.ts @@ -6,7 +6,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const tryToHug = createHugFunction([ '+', @@ -56,7 +56,7 @@ export class BitwiseOrExpression implements SlangNode { print( path: AstPath, - print: (path: AstPath) => Doc, + print: PrintFunction, options: ParserOptions ): Doc { return printBinaryOperation(this, path, print, options); diff --git a/src/slang-nodes/BitwiseXorExpression.ts b/src/slang-nodes/BitwiseXorExpression.ts index a8f9846d9..a8dfd5040 100644 --- a/src/slang-nodes/BitwiseXorExpression.ts +++ b/src/slang-nodes/BitwiseXorExpression.ts @@ -6,7 +6,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const tryToHug = createHugFunction(['+', '-', '*', '/', '**', '<<', '>>', '&']); @@ -46,7 +46,7 @@ export class BitwiseXorExpression implements SlangNode { print( path: AstPath, - print: (path: AstPath) => Doc, + print: PrintFunction, options: ParserOptions ): Doc { return printBinaryOperation(this, path, print, options); diff --git a/src/slang-nodes/Block.ts b/src/slang-nodes/Block.ts index 4b07724b9..2c0c2aac0 100644 --- a/src/slang-nodes/Block.ts +++ b/src/slang-nodes/Block.ts @@ -4,7 +4,7 @@ import { Statements } from './Statements.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class Block implements SlangNode { readonly kind = NonterminalKind.Block; @@ -27,7 +27,7 @@ export class Block implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print(path: AstPath, print: PrintFunction): Doc { return ['{', path.call(print, 'statements'), '}']; } } diff --git a/src/slang-nodes/CallOptions.ts b/src/slang-nodes/CallOptions.ts index fd779d790..b927af17a 100644 --- a/src/slang-nodes/CallOptions.ts +++ b/src/slang-nodes/CallOptions.ts @@ -6,7 +6,7 @@ import { NamedArgument } from './NamedArgument.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { line, softline } = doc.builders; @@ -42,7 +42,7 @@ export class CallOptions implements SlangNode { print( path: AstPath, - print: (path: AstPath) => Doc, + print: PrintFunction, options: ParserOptions ): Doc { return printSeparatedList(path.map(print, 'items'), { diff --git a/src/slang-nodes/CallOptionsExpression.ts b/src/slang-nodes/CallOptionsExpression.ts index 44a1ee6ad..5e3157345 100644 --- a/src/slang-nodes/CallOptionsExpression.ts +++ b/src/slang-nodes/CallOptionsExpression.ts @@ -5,7 +5,7 @@ import { CallOptions } from './CallOptions.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class CallOptionsExpression implements SlangNode { readonly kind = NonterminalKind.CallOptionsExpression; @@ -35,10 +35,7 @@ export class CallOptionsExpression implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [path.call(print, 'operand'), '{', path.call(print, 'options'), '}']; } } diff --git a/src/slang-nodes/CatchClause.ts b/src/slang-nodes/CatchClause.ts index 472386680..4914c9479 100644 --- a/src/slang-nodes/CatchClause.ts +++ b/src/slang-nodes/CatchClause.ts @@ -5,7 +5,7 @@ import { Block } from './Block.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class CatchClause implements SlangNode { readonly kind = NonterminalKind.CatchClause; @@ -39,10 +39,7 @@ export class CatchClause implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [ 'catch ', this.error ? path.call(print, 'error') : '', diff --git a/src/slang-nodes/CatchClauseError.ts b/src/slang-nodes/CatchClauseError.ts index 52b660274..772e6b529 100644 --- a/src/slang-nodes/CatchClauseError.ts +++ b/src/slang-nodes/CatchClauseError.ts @@ -5,7 +5,7 @@ import { ParametersDeclaration } from './ParametersDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { group } = doc.builders; @@ -41,10 +41,7 @@ export class CatchClauseError implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [ this.name ? this.name : '', group(path.call(print, 'parameters')), diff --git a/src/slang-nodes/CatchClauses.ts b/src/slang-nodes/CatchClauses.ts index d191ca538..fc0996c12 100644 --- a/src/slang-nodes/CatchClauses.ts +++ b/src/slang-nodes/CatchClauses.ts @@ -5,7 +5,7 @@ import { CatchClause } from './CatchClause.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { join } = doc.builders; @@ -36,10 +36,7 @@ export class CatchClauses implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return join(' ', path.map(print, 'items')); } } diff --git a/src/slang-nodes/ComparisonExpression.ts b/src/slang-nodes/ComparisonExpression.ts index 98462acc3..733e6b9b7 100644 --- a/src/slang-nodes/ComparisonExpression.ts +++ b/src/slang-nodes/ComparisonExpression.ts @@ -5,7 +5,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class ComparisonExpression implements SlangNode { readonly kind = NonterminalKind.ComparisonExpression; @@ -40,7 +40,7 @@ export class ComparisonExpression implements SlangNode { print( path: AstPath, - print: (path: AstPath) => Doc, + print: PrintFunction, options: ParserOptions ): Doc { return printComparisonOperation(this, path, print, options); diff --git a/src/slang-nodes/ConditionalExpression.ts b/src/slang-nodes/ConditionalExpression.ts index 64c9e3452..e94558929 100644 --- a/src/slang-nodes/ConditionalExpression.ts +++ b/src/slang-nodes/ConditionalExpression.ts @@ -7,17 +7,22 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { + AstNode, + PrintFunction, + SlangNode, + StrictAstNode +} from '../types'; const { group, hardline, ifBreak, indent, line, softline } = doc.builders; function experimentalTernaries( node: ConditionalExpression, path: AstPath, - print: (path: AstPath) => Doc, + print: PrintFunction, options: ParserOptions ): Doc { - const grandparent = path.getNode(2) as AstNode; + const grandparent = path.getNode(2) as StrictAstNode; const isNested = grandparent.kind === NonterminalKind.ConditionalExpression; const isNestedAsTrueExpression = isNested && grandparent.trueExpression.variant === node; @@ -88,14 +93,14 @@ function experimentalTernaries( function traditionalTernaries( node: ConditionalExpression, path: AstPath, - print: (path: AstPath) => Doc + print: PrintFunction ): Doc { return group([ path.call(print, 'operand'), indent([ // Nested trueExpression and falseExpression are always printed in a new // line - (path.getNode(2) as AstNode).kind === + (path.getNode(2) as StrictAstNode).kind === NonterminalKind.ConditionalExpression ? hardline : line, @@ -171,7 +176,7 @@ export class ConditionalExpression implements SlangNode { print( path: AstPath, - print: (path: AstPath) => Doc, + print: PrintFunction, options: ParserOptions ): Doc { return options.experimentalTernaries diff --git a/src/slang-nodes/ConstantDefinition.ts b/src/slang-nodes/ConstantDefinition.ts index 14343c084..86e9d1742 100644 --- a/src/slang-nodes/ConstantDefinition.ts +++ b/src/slang-nodes/ConstantDefinition.ts @@ -41,7 +41,7 @@ export class ConstantDefinition implements SlangNode { // TODO: implement print print(/* path: AstPath, - print: (path: AstPath) => Doc, + print: PrintFunction, options: ParserOptions */): Doc { return ['TODO: ConstantDefinition']; diff --git a/src/slang-nodes/ConstructorAttribute.ts b/src/slang-nodes/ConstructorAttribute.ts index c14bbb95a..027730efd 100644 --- a/src/slang-nodes/ConstructorAttribute.ts +++ b/src/slang-nodes/ConstructorAttribute.ts @@ -5,7 +5,7 @@ import { ModifierInvocation } from './ModifierInvocation.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class ConstructorAttribute implements SlangNode { readonly kind = NonterminalKind.ConstructorAttribute; @@ -38,10 +38,7 @@ export class ConstructorAttribute implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/ConstructorAttributes.ts b/src/slang-nodes/ConstructorAttributes.ts index 6a205ebba..268aaa014 100644 --- a/src/slang-nodes/ConstructorAttributes.ts +++ b/src/slang-nodes/ConstructorAttributes.ts @@ -6,7 +6,7 @@ import { ConstructorAttribute } from './ConstructorAttribute.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { line } = doc.builders; @@ -39,10 +39,7 @@ export class ConstructorAttributes implements SlangNode { this.items = this.items.sort(sortFunctionAttributes); } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return path.map(print, 'items').map((item) => [line, item]); } } diff --git a/src/slang-nodes/ConstructorDefinition.ts b/src/slang-nodes/ConstructorDefinition.ts index a9d6af288..9545d108f 100644 --- a/src/slang-nodes/ConstructorDefinition.ts +++ b/src/slang-nodes/ConstructorDefinition.ts @@ -7,7 +7,7 @@ import { Block } from './Block.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class ConstructorDefinition implements SlangNode { readonly kind = NonterminalKind.ConstructorDefinition; @@ -52,10 +52,7 @@ export class ConstructorDefinition implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return printFunction('constructor', this, path, print); } } diff --git a/src/slang-nodes/ContractDefinition.ts b/src/slang-nodes/ContractDefinition.ts index 21a316169..416b6ccb0 100644 --- a/src/slang-nodes/ContractDefinition.ts +++ b/src/slang-nodes/ContractDefinition.ts @@ -8,7 +8,7 @@ import { ContractMembers } from './ContractMembers.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { group, line } = doc.builders; @@ -72,10 +72,7 @@ export class ContractDefinition implements SlangNode { } } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [ group([ this.abstractKeyword ? 'abstract ' : '', diff --git a/src/slang-nodes/ContractMember.ts b/src/slang-nodes/ContractMember.ts index 6ca2df214..08ac4940c 100644 --- a/src/slang-nodes/ContractMember.ts +++ b/src/slang-nodes/ContractMember.ts @@ -16,7 +16,7 @@ import { UserDefinedValueTypeDefinition } from './UserDefinedValueTypeDefinition import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class ContractMember implements SlangNode { readonly kind = NonterminalKind.ContractMember; @@ -148,10 +148,7 @@ export class ContractMember implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/ContractMembers.ts b/src/slang-nodes/ContractMembers.ts index b56f8668d..e5cd1f44b 100644 --- a/src/slang-nodes/ContractMembers.ts +++ b/src/slang-nodes/ContractMembers.ts @@ -8,7 +8,7 @@ import { ContractMember } from './ContractMember.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { hardline } = doc.builders; @@ -41,7 +41,7 @@ export class ContractMembers implements SlangNode { print( path: AstPath, - print: (path: AstPath) => Doc, + print: PrintFunction, options: ParserOptions ): Doc { return this.items.length === 0 && this.comments.length === 0 diff --git a/src/slang-nodes/DecimalNumberExpression.ts b/src/slang-nodes/DecimalNumberExpression.ts index 12385a0f6..130103ff6 100644 --- a/src/slang-nodes/DecimalNumberExpression.ts +++ b/src/slang-nodes/DecimalNumberExpression.ts @@ -4,7 +4,7 @@ import { NumberUnit } from './NumberUnit.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { PrintFunction, SlangNode } from '../types'; export class DecimalNumberExpression implements SlangNode { readonly kind = NonterminalKind.DecimalNumberExpression; @@ -32,10 +32,7 @@ export class DecimalNumberExpression implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [this.literal, this.unit ? [' ', path.call(print, 'unit')] : '']; } } diff --git a/src/slang-nodes/DoWhileStatement.ts b/src/slang-nodes/DoWhileStatement.ts index 65bd62175..818dadebb 100644 --- a/src/slang-nodes/DoWhileStatement.ts +++ b/src/slang-nodes/DoWhileStatement.ts @@ -7,7 +7,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { group, indent, line } = doc.builders; @@ -39,10 +39,7 @@ export class DoWhileStatement implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [ 'do', this.body.variant.kind === NonterminalKind.Block diff --git a/src/slang-nodes/ElementaryType.ts b/src/slang-nodes/ElementaryType.ts index 92c187f32..26a968520 100644 --- a/src/slang-nodes/ElementaryType.ts +++ b/src/slang-nodes/ElementaryType.ts @@ -5,7 +5,7 @@ import { AddressType } from './AddressType.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { PrintFunction, SlangNode } from '../types'; export class ElementaryType implements SlangNode { readonly kind = NonterminalKind.ElementaryType; @@ -34,10 +34,7 @@ export class ElementaryType implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/ElseBranch.ts b/src/slang-nodes/ElseBranch.ts index 8e30c4685..934c74c91 100644 --- a/src/slang-nodes/ElseBranch.ts +++ b/src/slang-nodes/ElseBranch.ts @@ -6,7 +6,7 @@ import { Statement } from './Statement.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { group, indent, line } = doc.builders; @@ -40,10 +40,7 @@ export class ElseBranch implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [ 'else', isIfStatementOrBlock(this.body.variant) diff --git a/src/slang-nodes/EmitStatement.ts b/src/slang-nodes/EmitStatement.ts index f060fe5f8..2182106ee 100644 --- a/src/slang-nodes/EmitStatement.ts +++ b/src/slang-nodes/EmitStatement.ts @@ -5,7 +5,7 @@ import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class EmitStatement implements SlangNode { readonly kind = NonterminalKind.EmitStatement; @@ -39,10 +39,7 @@ export class EmitStatement implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [ 'emit ', path.call(print, 'event'), diff --git a/src/slang-nodes/EnumDefinition.ts b/src/slang-nodes/EnumDefinition.ts index 761d8d1bb..0a4e6ab75 100644 --- a/src/slang-nodes/EnumDefinition.ts +++ b/src/slang-nodes/EnumDefinition.ts @@ -4,7 +4,7 @@ import { EnumMembers } from './EnumMembers.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { PrintFunction, SlangNode } from '../types'; export class EnumDefinition implements SlangNode { readonly kind = NonterminalKind.EnumDefinition; @@ -30,10 +30,7 @@ export class EnumDefinition implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [`enum ${this.name} {`, path.call(print, 'members'), '}']; } } diff --git a/src/slang-nodes/EqualityExpression.ts b/src/slang-nodes/EqualityExpression.ts index a958e12ec..99f15a43a 100644 --- a/src/slang-nodes/EqualityExpression.ts +++ b/src/slang-nodes/EqualityExpression.ts @@ -5,7 +5,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class EqualityExpression implements SlangNode { readonly kind = NonterminalKind.EqualityExpression; @@ -40,7 +40,7 @@ export class EqualityExpression implements SlangNode { print( path: AstPath, - print: (path: AstPath) => Doc, + print: PrintFunction, options: ParserOptions ): Doc { return printComparisonOperation(this, path, print, options); diff --git a/src/slang-nodes/ErrorDefinition.ts b/src/slang-nodes/ErrorDefinition.ts index 874a57d93..0e0e03993 100644 --- a/src/slang-nodes/ErrorDefinition.ts +++ b/src/slang-nodes/ErrorDefinition.ts @@ -4,7 +4,7 @@ import { ErrorParametersDeclaration } from './ErrorParametersDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class ErrorDefinition implements SlangNode { readonly kind = NonterminalKind.ErrorDefinition; @@ -38,10 +38,7 @@ export class ErrorDefinition implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [`error ${this.name}`, path.call(print, 'members'), ';']; } } diff --git a/src/slang-nodes/ErrorParameter.ts b/src/slang-nodes/ErrorParameter.ts index 1c702b947..a30da22e6 100644 --- a/src/slang-nodes/ErrorParameter.ts +++ b/src/slang-nodes/ErrorParameter.ts @@ -4,7 +4,7 @@ import { TypeName } from './TypeName.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class ErrorParameter implements SlangNode { readonly kind = NonterminalKind.ErrorParameter; @@ -34,10 +34,7 @@ export class ErrorParameter implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [path.call(print, 'typeName'), this.name ? ` ${this.name}` : '']; } } diff --git a/src/slang-nodes/ErrorParameters.ts b/src/slang-nodes/ErrorParameters.ts index 5535f2219..4e5918f91 100644 --- a/src/slang-nodes/ErrorParameters.ts +++ b/src/slang-nodes/ErrorParameters.ts @@ -5,7 +5,7 @@ import { ErrorParameter } from './ErrorParameter.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class ErrorParameters implements SlangNode { readonly kind = NonterminalKind.ErrorParameters; @@ -37,10 +37,7 @@ export class ErrorParameters implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return this.items.length > 0 ? printSeparatedList(path.map(print, 'items')) : ''; diff --git a/src/slang-nodes/ErrorParametersDeclaration.ts b/src/slang-nodes/ErrorParametersDeclaration.ts index 3a2256343..6d0472f63 100644 --- a/src/slang-nodes/ErrorParametersDeclaration.ts +++ b/src/slang-nodes/ErrorParametersDeclaration.ts @@ -4,7 +4,7 @@ import { ErrorParameters } from './ErrorParameters.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class ErrorParametersDeclaration implements SlangNode { readonly kind = NonterminalKind.ErrorParametersDeclaration; @@ -31,10 +31,7 @@ export class ErrorParametersDeclaration implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return ['(', path.call(print, 'parameters'), ')']; } } diff --git a/src/slang-nodes/EventDefinition.ts b/src/slang-nodes/EventDefinition.ts index 32d5a3381..aad2d002e 100644 --- a/src/slang-nodes/EventDefinition.ts +++ b/src/slang-nodes/EventDefinition.ts @@ -4,7 +4,7 @@ import { EventParametersDeclaration } from './EventParametersDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class EventDefinition implements SlangNode { readonly kind = NonterminalKind.EventDefinition; @@ -41,10 +41,7 @@ export class EventDefinition implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [ `event ${this.name}`, path.call(print, 'parameters'), diff --git a/src/slang-nodes/EventParameter.ts b/src/slang-nodes/EventParameter.ts index dd56cfb93..ea8399b51 100644 --- a/src/slang-nodes/EventParameter.ts +++ b/src/slang-nodes/EventParameter.ts @@ -4,7 +4,7 @@ import { TypeName } from './TypeName.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class EventParameter implements SlangNode { readonly kind = NonterminalKind.EventParameter; @@ -37,10 +37,7 @@ export class EventParameter implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [ path.call(print, 'typeName'), this.indexedKeyword ? ' indexed' : '', diff --git a/src/slang-nodes/EventParameters.ts b/src/slang-nodes/EventParameters.ts index cc80d2379..d82ad61f6 100644 --- a/src/slang-nodes/EventParameters.ts +++ b/src/slang-nodes/EventParameters.ts @@ -5,7 +5,7 @@ import { EventParameter } from './EventParameter.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class EventParameters implements SlangNode { readonly kind = NonterminalKind.EventParameters; @@ -37,10 +37,7 @@ export class EventParameters implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return this.items.length > 0 ? printSeparatedList(path.map(print, 'items')) : ''; diff --git a/src/slang-nodes/EventParametersDeclaration.ts b/src/slang-nodes/EventParametersDeclaration.ts index f36677094..94b62ff2b 100644 --- a/src/slang-nodes/EventParametersDeclaration.ts +++ b/src/slang-nodes/EventParametersDeclaration.ts @@ -4,7 +4,7 @@ import { EventParameters } from './EventParameters.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class EventParametersDeclaration implements SlangNode { readonly kind = NonterminalKind.EventParametersDeclaration; @@ -31,10 +31,7 @@ export class EventParametersDeclaration implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return ['(', path.call(print, 'parameters'), ')']; } } diff --git a/src/slang-nodes/ExperimentalFeature.ts b/src/slang-nodes/ExperimentalFeature.ts index 59cbd3708..4de012c99 100644 --- a/src/slang-nodes/ExperimentalFeature.ts +++ b/src/slang-nodes/ExperimentalFeature.ts @@ -5,7 +5,7 @@ import { StringLiteral } from './StringLiteral.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class ExperimentalFeature implements SlangNode { readonly kind = NonterminalKind.ExperimentalFeature; @@ -38,10 +38,7 @@ export class ExperimentalFeature implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/ExperimentalPragma.ts b/src/slang-nodes/ExperimentalPragma.ts index d7309ac43..5f3962ba6 100644 --- a/src/slang-nodes/ExperimentalPragma.ts +++ b/src/slang-nodes/ExperimentalPragma.ts @@ -4,7 +4,7 @@ import { ExperimentalFeature } from './ExperimentalFeature.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class ExperimentalPragma implements SlangNode { readonly kind = NonterminalKind.ExperimentalPragma; @@ -31,10 +31,7 @@ export class ExperimentalPragma implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return ['experimental ', path.call(print, 'feature')]; } } diff --git a/src/slang-nodes/ExponentiationExpression.ts b/src/slang-nodes/ExponentiationExpression.ts index db51702ef..44b2c64c5 100644 --- a/src/slang-nodes/ExponentiationExpression.ts +++ b/src/slang-nodes/ExponentiationExpression.ts @@ -12,7 +12,7 @@ import { TupleValue } from './TupleValue.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { group, indent } = doc.builders; @@ -174,7 +174,7 @@ export class ExponentiationExpression implements SlangNode { print( path: AstPath, - print: (path: AstPath) => Doc, + print: PrintFunction, options: ParserOptions ): Doc { return printExponentiationExpression(this, path, print, options); diff --git a/src/slang-nodes/Expression.ts b/src/slang-nodes/Expression.ts index 57c04afc8..f96a6dac2 100644 --- a/src/slang-nodes/Expression.ts +++ b/src/slang-nodes/Expression.ts @@ -31,7 +31,7 @@ import { ElementaryType } from './ElementaryType.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class Expression implements SlangNode { readonly kind = NonterminalKind.Expression; @@ -282,10 +282,7 @@ export class Expression implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/ExpressionStatement.ts b/src/slang-nodes/ExpressionStatement.ts index 02c867934..f25941d79 100644 --- a/src/slang-nodes/ExpressionStatement.ts +++ b/src/slang-nodes/ExpressionStatement.ts @@ -4,7 +4,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class ExpressionStatement implements SlangNode { readonly kind = NonterminalKind.ExpressionStatement; @@ -31,10 +31,7 @@ export class ExpressionStatement implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [path.call(print, 'expression'), ';']; } } diff --git a/src/slang-nodes/FallbackFunctionAttribute.ts b/src/slang-nodes/FallbackFunctionAttribute.ts index cadb5faae..44ba1a7ea 100644 --- a/src/slang-nodes/FallbackFunctionAttribute.ts +++ b/src/slang-nodes/FallbackFunctionAttribute.ts @@ -6,7 +6,7 @@ import { OverrideSpecifier } from './OverrideSpecifier.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class FallbackFunctionAttribute implements SlangNode { readonly kind = NonterminalKind.FallbackFunctionAttribute; @@ -56,10 +56,7 @@ export class FallbackFunctionAttribute implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/FallbackFunctionAttributes.ts b/src/slang-nodes/FallbackFunctionAttributes.ts index f0cf852d5..5f6c8e4c7 100644 --- a/src/slang-nodes/FallbackFunctionAttributes.ts +++ b/src/slang-nodes/FallbackFunctionAttributes.ts @@ -6,7 +6,7 @@ import { FallbackFunctionAttribute } from './FallbackFunctionAttribute.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { line } = doc.builders; @@ -40,10 +40,7 @@ export class FallbackFunctionAttributes implements SlangNode { this.items = this.items.sort(sortFunctionAttributes); } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return path.map(print, 'items').map((item) => [line, item]); } } diff --git a/src/slang-nodes/FallbackFunctionDefinition.ts b/src/slang-nodes/FallbackFunctionDefinition.ts index 2bb902aba..65af63762 100644 --- a/src/slang-nodes/FallbackFunctionDefinition.ts +++ b/src/slang-nodes/FallbackFunctionDefinition.ts @@ -8,7 +8,7 @@ import { FunctionBody } from './FunctionBody.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class FallbackFunctionDefinition implements SlangNode { readonly kind = NonterminalKind.FallbackFunctionDefinition; @@ -74,10 +74,7 @@ export class FallbackFunctionDefinition implements SlangNode { } } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return printFunction('fallback', this, path, print); } } diff --git a/src/slang-nodes/ForStatement.ts b/src/slang-nodes/ForStatement.ts index 9eae87041..9bad7ce6c 100644 --- a/src/slang-nodes/ForStatement.ts +++ b/src/slang-nodes/ForStatement.ts @@ -9,7 +9,7 @@ import { Statement } from './Statement.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { group, indent, line } = doc.builders; @@ -64,10 +64,7 @@ export class ForStatement implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { const initialization = path.call(print, 'initialization'); const condition = path.call(print, 'condition'); const iterator = this.iterator ? path.call(print, 'iterator') : ''; diff --git a/src/slang-nodes/ForStatementCondition.ts b/src/slang-nodes/ForStatementCondition.ts index 768e685f9..839924799 100644 --- a/src/slang-nodes/ForStatementCondition.ts +++ b/src/slang-nodes/ForStatementCondition.ts @@ -5,7 +5,7 @@ import { ExpressionStatement } from './ExpressionStatement.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class ForStatementCondition implements SlangNode { readonly kind = NonterminalKind.ForStatementCondition; @@ -38,10 +38,7 @@ export class ForStatementCondition implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/ForStatementInitialization.ts b/src/slang-nodes/ForStatementInitialization.ts index 4e160325b..3cee0c370 100644 --- a/src/slang-nodes/ForStatementInitialization.ts +++ b/src/slang-nodes/ForStatementInitialization.ts @@ -7,7 +7,7 @@ import { TupleDeconstructionStatement } from './TupleDeconstructionStatement.js' import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class ForStatementInitialization implements SlangNode { readonly kind = NonterminalKind.ForStatementInitialization; @@ -69,10 +69,7 @@ export class ForStatementInitialization implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/FunctionAttribute.ts b/src/slang-nodes/FunctionAttribute.ts index 83d6559dc..4b4b44f1f 100644 --- a/src/slang-nodes/FunctionAttribute.ts +++ b/src/slang-nodes/FunctionAttribute.ts @@ -6,7 +6,7 @@ import { OverrideSpecifier } from './OverrideSpecifier.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class FunctionAttribute implements SlangNode { readonly kind = NonterminalKind.FunctionAttribute; @@ -56,10 +56,7 @@ export class FunctionAttribute implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/FunctionAttributes.ts b/src/slang-nodes/FunctionAttributes.ts index 0b7572f45..1fa7d0b38 100644 --- a/src/slang-nodes/FunctionAttributes.ts +++ b/src/slang-nodes/FunctionAttributes.ts @@ -6,7 +6,7 @@ import { FunctionAttribute } from './FunctionAttribute.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { line } = doc.builders; @@ -39,10 +39,7 @@ export class FunctionAttributes implements SlangNode { this.items = this.items.sort(sortFunctionAttributes); } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return path.map(print, 'items').map((item) => [line, item]); } } diff --git a/src/slang-nodes/FunctionBody.ts b/src/slang-nodes/FunctionBody.ts index 1f0f2f8fe..5153da2d0 100644 --- a/src/slang-nodes/FunctionBody.ts +++ b/src/slang-nodes/FunctionBody.ts @@ -5,7 +5,7 @@ import { Block } from './Block.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class FunctionBody implements SlangNode { readonly kind = NonterminalKind.FunctionBody; @@ -38,10 +38,7 @@ export class FunctionBody implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/FunctionCallExpression.ts b/src/slang-nodes/FunctionCallExpression.ts index 67fd58916..f30186fef 100644 --- a/src/slang-nodes/FunctionCallExpression.ts +++ b/src/slang-nodes/FunctionCallExpression.ts @@ -7,7 +7,7 @@ import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { group, indentIfBreak, label } = doc.builders; @@ -43,10 +43,7 @@ export class FunctionCallExpression implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { let operandDoc = path.call(print, 'operand'); let argumentsDoc = path.call(print, 'arguments'); diff --git a/src/slang-nodes/FunctionDefinition.ts b/src/slang-nodes/FunctionDefinition.ts index 7e7ede141..a4d1d0f83 100644 --- a/src/slang-nodes/FunctionDefinition.ts +++ b/src/slang-nodes/FunctionDefinition.ts @@ -11,7 +11,7 @@ import { FunctionBody } from './FunctionBody.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class FunctionDefinition implements SlangNode { readonly kind = NonterminalKind.FunctionDefinition; @@ -86,10 +86,7 @@ export class FunctionDefinition implements SlangNode { } } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return printFunction( ['function ', path.call(print, 'name')], this, diff --git a/src/slang-nodes/FunctionType.ts b/src/slang-nodes/FunctionType.ts index f6e562d41..a3ed0e0e6 100644 --- a/src/slang-nodes/FunctionType.ts +++ b/src/slang-nodes/FunctionType.ts @@ -7,7 +7,7 @@ import { ReturnsDeclaration } from './ReturnsDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class FunctionType implements SlangNode { readonly kind = NonterminalKind.FunctionType; @@ -50,10 +50,7 @@ export class FunctionType implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return printFunction('function', this, path, print); } } diff --git a/src/slang-nodes/FunctionTypeAttributes.ts b/src/slang-nodes/FunctionTypeAttributes.ts index 4647f2e42..85205aed5 100644 --- a/src/slang-nodes/FunctionTypeAttributes.ts +++ b/src/slang-nodes/FunctionTypeAttributes.ts @@ -6,7 +6,7 @@ import { FunctionTypeAttribute } from './FunctionTypeAttribute.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { PrintFunction, SlangNode } from '../types'; const { line } = doc.builders; @@ -35,10 +35,7 @@ export class FunctionTypeAttributes implements SlangNode { this.items = this.items.sort(sortFunctionAttributes); } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return path.map(print, 'items').map((item) => [line, item]); } } diff --git a/src/slang-nodes/HexNumberExpression.ts b/src/slang-nodes/HexNumberExpression.ts index 62e1d0c12..6a6da4fdb 100644 --- a/src/slang-nodes/HexNumberExpression.ts +++ b/src/slang-nodes/HexNumberExpression.ts @@ -4,7 +4,7 @@ import { NumberUnit } from './NumberUnit.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { PrintFunction, SlangNode } from '../types'; export class HexNumberExpression implements SlangNode { readonly kind = NonterminalKind.HexNumberExpression; @@ -32,10 +32,7 @@ export class HexNumberExpression implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [this.literal, this.unit ? [' ', path.call(print, 'unit')] : '']; } } diff --git a/src/slang-nodes/HexStringLiterals.ts b/src/slang-nodes/HexStringLiterals.ts index 6851d9e95..ab927d5cd 100644 --- a/src/slang-nodes/HexStringLiterals.ts +++ b/src/slang-nodes/HexStringLiterals.ts @@ -5,7 +5,7 @@ import { HexStringLiteral } from './HexStringLiteral.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { join, hardline } = doc.builders; @@ -36,10 +36,7 @@ export class HexStringLiterals implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return join(hardline, path.map(print, 'items')); } } diff --git a/src/slang-nodes/IfStatement.ts b/src/slang-nodes/IfStatement.ts index 1df6dd8f3..978e3dc25 100644 --- a/src/slang-nodes/IfStatement.ts +++ b/src/slang-nodes/IfStatement.ts @@ -8,7 +8,7 @@ import { ElseBranch } from './ElseBranch.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { group, hardline, indent, line } = doc.builders; @@ -49,10 +49,7 @@ export class IfStatement implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [ 'if (', printSeparatedItem(path.call(print, 'condition')), diff --git a/src/slang-nodes/ImportClause.ts b/src/slang-nodes/ImportClause.ts index 7a17f24db..c331fc391 100644 --- a/src/slang-nodes/ImportClause.ts +++ b/src/slang-nodes/ImportClause.ts @@ -6,7 +6,7 @@ import { ImportDeconstruction } from './ImportDeconstruction.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class ImportClause implements SlangNode { readonly kind = NonterminalKind.ImportClause; @@ -58,10 +58,7 @@ export class ImportClause implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/ImportDeconstruction.ts b/src/slang-nodes/ImportDeconstruction.ts index 5b36a0ad9..e5195fd34 100644 --- a/src/slang-nodes/ImportDeconstruction.ts +++ b/src/slang-nodes/ImportDeconstruction.ts @@ -5,7 +5,7 @@ import { StringLiteral } from './StringLiteral.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class ImportDeconstruction implements SlangNode { readonly kind = NonterminalKind.ImportDeconstruction; @@ -35,10 +35,7 @@ export class ImportDeconstruction implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [ '{', path.call(print, 'symbols'), diff --git a/src/slang-nodes/ImportDeconstructionSymbol.ts b/src/slang-nodes/ImportDeconstructionSymbol.ts index 81b98667f..53fc3ed38 100644 --- a/src/slang-nodes/ImportDeconstructionSymbol.ts +++ b/src/slang-nodes/ImportDeconstructionSymbol.ts @@ -4,7 +4,7 @@ import { ImportAlias } from './ImportAlias.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { PrintFunction, SlangNode } from '../types'; export class ImportDeconstructionSymbol implements SlangNode { readonly kind = NonterminalKind.ImportDeconstructionSymbol; @@ -32,10 +32,7 @@ export class ImportDeconstructionSymbol implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [this.name, this.alias ? path.call(print, 'alias') : '']; } } diff --git a/src/slang-nodes/ImportDeconstructionSymbols.ts b/src/slang-nodes/ImportDeconstructionSymbols.ts index d4ee715bf..e1f5ec8ac 100644 --- a/src/slang-nodes/ImportDeconstructionSymbols.ts +++ b/src/slang-nodes/ImportDeconstructionSymbols.ts @@ -8,7 +8,7 @@ import { ImportDeconstructionSymbol } from './ImportDeconstructionSymbol.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { line, softline } = doc.builders; @@ -40,7 +40,7 @@ export class ImportDeconstructionSymbols implements SlangNode { print( path: AstPath, - print: (path: AstPath) => Doc, + print: PrintFunction, options: ParserOptions ): Doc { const compiler = coerce(options.compiler); diff --git a/src/slang-nodes/ImportDirective.ts b/src/slang-nodes/ImportDirective.ts index e19f084fd..874c07f79 100644 --- a/src/slang-nodes/ImportDirective.ts +++ b/src/slang-nodes/ImportDirective.ts @@ -4,7 +4,7 @@ import { ImportClause } from './ImportClause.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class ImportDirective implements SlangNode { readonly kind = NonterminalKind.ImportDirective; @@ -31,10 +31,7 @@ export class ImportDirective implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return ['import ', path.call(print, 'clause'), ';']; } } diff --git a/src/slang-nodes/IndexAccessEnd.ts b/src/slang-nodes/IndexAccessEnd.ts index 7fe563850..3713680c7 100644 --- a/src/slang-nodes/IndexAccessEnd.ts +++ b/src/slang-nodes/IndexAccessEnd.ts @@ -4,7 +4,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class IndexAccessEnd implements SlangNode { readonly kind = NonterminalKind.IndexAccessEnd; @@ -33,10 +33,7 @@ export class IndexAccessEnd implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [':', this.end ? path.call(print, 'end') : '']; } } diff --git a/src/slang-nodes/IndexAccessExpression.ts b/src/slang-nodes/IndexAccessExpression.ts index 64f61111a..3aefccdf6 100644 --- a/src/slang-nodes/IndexAccessExpression.ts +++ b/src/slang-nodes/IndexAccessExpression.ts @@ -7,7 +7,7 @@ import { IndexAccessEnd } from './IndexAccessEnd.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { group, indent, indentIfBreak, label, softline } = doc.builders; @@ -48,10 +48,7 @@ export class IndexAccessExpression implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { let operandDoc: Doc = path.call(print, 'operand'); let indexDoc: Doc = group([ '[', diff --git a/src/slang-nodes/InheritanceSpecifier.ts b/src/slang-nodes/InheritanceSpecifier.ts index 1ea92d222..2079cab4e 100644 --- a/src/slang-nodes/InheritanceSpecifier.ts +++ b/src/slang-nodes/InheritanceSpecifier.ts @@ -4,7 +4,7 @@ import { InheritanceTypes } from './InheritanceTypes.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class InheritanceSpecifier implements SlangNode { readonly kind = NonterminalKind.InheritanceSpecifier; @@ -31,10 +31,7 @@ export class InheritanceSpecifier implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return ['is', path.call(print, 'types')]; } } diff --git a/src/slang-nodes/InheritanceType.ts b/src/slang-nodes/InheritanceType.ts index 59b554c9a..601ad5711 100644 --- a/src/slang-nodes/InheritanceType.ts +++ b/src/slang-nodes/InheritanceType.ts @@ -5,7 +5,7 @@ import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class InheritanceType implements SlangNode { readonly kind = NonterminalKind.InheritanceType; @@ -41,10 +41,7 @@ export class InheritanceType implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [ path.call(print, 'typeName'), this.arguments ? path.call(print, 'arguments') : '' diff --git a/src/slang-nodes/InheritanceTypes.ts b/src/slang-nodes/InheritanceTypes.ts index 3b33179f4..27c366970 100644 --- a/src/slang-nodes/InheritanceTypes.ts +++ b/src/slang-nodes/InheritanceTypes.ts @@ -6,7 +6,7 @@ import { InheritanceType } from './InheritanceType.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { line } = doc.builders; @@ -40,10 +40,7 @@ export class InheritanceTypes implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return printSeparatedList(path.map(print, 'items'), { firstSeparator: line }); diff --git a/src/slang-nodes/InterfaceDefinition.ts b/src/slang-nodes/InterfaceDefinition.ts index 415d3e0f8..163e91538 100644 --- a/src/slang-nodes/InterfaceDefinition.ts +++ b/src/slang-nodes/InterfaceDefinition.ts @@ -6,7 +6,7 @@ import { InterfaceMembers } from './InterfaceMembers.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { group, line } = doc.builders; @@ -49,10 +49,7 @@ export class InterfaceDefinition implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [ group([ `interface ${this.name}`, diff --git a/src/slang-nodes/InterfaceMembers.ts b/src/slang-nodes/InterfaceMembers.ts index 3445adbdf..ccb716578 100644 --- a/src/slang-nodes/InterfaceMembers.ts +++ b/src/slang-nodes/InterfaceMembers.ts @@ -7,7 +7,7 @@ import { ContractMember } from './ContractMember.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { hardline } = doc.builders; @@ -40,7 +40,7 @@ export class InterfaceMembers implements SlangNode { print( path: AstPath, - print: (path: AstPath) => Doc, + print: PrintFunction, options: ParserOptions ): Doc { return this.items.length > 0 diff --git a/src/slang-nodes/LibraryDefinition.ts b/src/slang-nodes/LibraryDefinition.ts index 6728c3191..f9da35a02 100644 --- a/src/slang-nodes/LibraryDefinition.ts +++ b/src/slang-nodes/LibraryDefinition.ts @@ -5,7 +5,7 @@ import { LibraryMembers } from './LibraryMembers.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { group, line } = doc.builders; @@ -37,10 +37,7 @@ export class LibraryDefinition implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [ group([`library ${this.name}`, line, '{']), path.call(print, 'members'), diff --git a/src/slang-nodes/LibraryMembers.ts b/src/slang-nodes/LibraryMembers.ts index 59d1ec6a7..869cd1848 100644 --- a/src/slang-nodes/LibraryMembers.ts +++ b/src/slang-nodes/LibraryMembers.ts @@ -7,7 +7,7 @@ import { ContractMember } from './ContractMember.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { hardline } = doc.builders; @@ -40,7 +40,7 @@ export class LibraryMembers implements SlangNode { print( path: AstPath, - print: (path: AstPath) => Doc, + print: PrintFunction, options: ParserOptions ): Doc { return this.items.length > 0 diff --git a/src/slang-nodes/MappingKey.ts b/src/slang-nodes/MappingKey.ts index f21e28620..de38a59f1 100644 --- a/src/slang-nodes/MappingKey.ts +++ b/src/slang-nodes/MappingKey.ts @@ -4,7 +4,7 @@ import { MappingKeyType } from './MappingKeyType.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { PrintFunction, SlangNode } from '../types'; export class MappingKey implements SlangNode { readonly kind = NonterminalKind.MappingKey; @@ -30,10 +30,7 @@ export class MappingKey implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [path.call(print, 'keyType'), this.name ? ` ${this.name}` : '']; } } diff --git a/src/slang-nodes/MappingKeyType.ts b/src/slang-nodes/MappingKeyType.ts index ac68207b5..e7c4995c4 100644 --- a/src/slang-nodes/MappingKeyType.ts +++ b/src/slang-nodes/MappingKeyType.ts @@ -5,7 +5,7 @@ import { IdentifierPath } from './IdentifierPath.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { PrintFunction, SlangNode } from '../types'; export class MappingKeyType implements SlangNode { readonly kind = NonterminalKind.MappingKeyType; @@ -43,10 +43,7 @@ export class MappingKeyType implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/MappingType.ts b/src/slang-nodes/MappingType.ts index 6e5095a79..1d7bee9a7 100644 --- a/src/slang-nodes/MappingType.ts +++ b/src/slang-nodes/MappingType.ts @@ -5,7 +5,7 @@ import { MappingValue } from './MappingValue.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class MappingType implements SlangNode { readonly kind = NonterminalKind.MappingType; @@ -38,10 +38,7 @@ export class MappingType implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [ 'mapping(', path.call(print, 'keyType'), diff --git a/src/slang-nodes/MappingValue.ts b/src/slang-nodes/MappingValue.ts index 63c105484..2c91357e7 100644 --- a/src/slang-nodes/MappingValue.ts +++ b/src/slang-nodes/MappingValue.ts @@ -4,7 +4,7 @@ import { TypeName } from './TypeName.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class MappingValue implements SlangNode { readonly kind = NonterminalKind.MappingValue; @@ -34,10 +34,7 @@ export class MappingValue implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [path.call(print, 'typeName'), this.name ? ` ${this.name}` : '']; } } diff --git a/src/slang-nodes/MemberAccessExpression.ts b/src/slang-nodes/MemberAccessExpression.ts index 067ca6a71..0114c9998 100644 --- a/src/slang-nodes/MemberAccessExpression.ts +++ b/src/slang-nodes/MemberAccessExpression.ts @@ -8,7 +8,12 @@ import { MemberAccess } from './MemberAccess.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { + AstNode, + PrintFunction, + SlangNode, + StrictAstNode +} from '../types'; const { group, indent, label, softline } = doc.builders; @@ -25,11 +30,11 @@ function isEndOfChain( for ( let i = 0, currentNode: AstNode = node, - grandparentNode = path.getNode(i + 2) as AstNode; + grandparentNode = path.getNode(i + 2) as StrictAstNode; isChainableExpression(grandparentNode); i += 2, currentNode = grandparentNode, - grandparentNode = path.getNode(i + 2) as AstNode + grandparentNode = path.getNode(i + 2) as StrictAstNode ) { switch (grandparentNode.kind) { case NonterminalKind.MemberAccessExpression: @@ -150,10 +155,7 @@ export class MemberAccessExpression implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { let operandDoc = path.call(print, 'operand'); if (Array.isArray(operandDoc)) { operandDoc = operandDoc.flat(); diff --git a/src/slang-nodes/ModifierAttribute.ts b/src/slang-nodes/ModifierAttribute.ts index 9953d1920..9ef709945 100644 --- a/src/slang-nodes/ModifierAttribute.ts +++ b/src/slang-nodes/ModifierAttribute.ts @@ -5,7 +5,7 @@ import { OverrideSpecifier } from './OverrideSpecifier.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { PrintFunction, SlangNode } from '../types'; export class ModifierAttribute implements SlangNode { readonly kind = NonterminalKind.ModifierAttribute; @@ -34,10 +34,7 @@ export class ModifierAttribute implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/ModifierAttributes.ts b/src/slang-nodes/ModifierAttributes.ts index 2d440c5b7..c8e67a703 100644 --- a/src/slang-nodes/ModifierAttributes.ts +++ b/src/slang-nodes/ModifierAttributes.ts @@ -6,7 +6,7 @@ import { ModifierAttribute } from './ModifierAttribute.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { PrintFunction, SlangNode } from '../types'; const { line } = doc.builders; @@ -35,10 +35,7 @@ export class ModifierAttributes implements SlangNode { this.items = this.items.sort(sortFunctionAttributes); } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return path.map(print, 'items').map((item) => [line, item]); } } diff --git a/src/slang-nodes/ModifierDefinition.ts b/src/slang-nodes/ModifierDefinition.ts index 226b37f71..29a882c8c 100644 --- a/src/slang-nodes/ModifierDefinition.ts +++ b/src/slang-nodes/ModifierDefinition.ts @@ -8,7 +8,7 @@ import { FunctionBody } from './FunctionBody.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const objectConfig = { writable: true, @@ -95,10 +95,7 @@ export class ModifierDefinition implements SlangNode { } } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return printFunction(`modifier ${this.name}`, this, path, print); } } diff --git a/src/slang-nodes/ModifierInvocation.ts b/src/slang-nodes/ModifierInvocation.ts index b16ce1d04..cb56d137d 100644 --- a/src/slang-nodes/ModifierInvocation.ts +++ b/src/slang-nodes/ModifierInvocation.ts @@ -6,7 +6,7 @@ import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class ModifierInvocation implements SlangNode { readonly kind = NonterminalKind.ModifierInvocation; @@ -52,10 +52,7 @@ export class ModifierInvocation implements SlangNode { }; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [ path.call(print, 'name'), this.arguments ? path.call(print, 'arguments') : '' diff --git a/src/slang-nodes/MultiplicativeExpression.ts b/src/slang-nodes/MultiplicativeExpression.ts index 4db8d9a96..f54e768f1 100644 --- a/src/slang-nodes/MultiplicativeExpression.ts +++ b/src/slang-nodes/MultiplicativeExpression.ts @@ -6,7 +6,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const multiplicationTryToHug = createHugFunction(['/', '%']); const divisionTryToHug = createHugFunction(['*', '%']); @@ -59,7 +59,7 @@ export class MultiplicativeExpression implements SlangNode { print( path: AstPath, - print: (path: AstPath) => Doc, + print: PrintFunction, options: ParserOptions ): Doc { return printBinaryOperation(this, path, print, options); diff --git a/src/slang-nodes/NamedArgument.ts b/src/slang-nodes/NamedArgument.ts index 1c0b5892e..67b48312c 100644 --- a/src/slang-nodes/NamedArgument.ts +++ b/src/slang-nodes/NamedArgument.ts @@ -4,7 +4,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class NamedArgument implements SlangNode { readonly kind = NonterminalKind.NamedArgument; @@ -34,10 +34,7 @@ export class NamedArgument implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [`${this.name}: `, path.call(print, 'value')]; } } diff --git a/src/slang-nodes/NamedArgumentGroup.ts b/src/slang-nodes/NamedArgumentGroup.ts index aa7743af9..0648293ea 100644 --- a/src/slang-nodes/NamedArgumentGroup.ts +++ b/src/slang-nodes/NamedArgumentGroup.ts @@ -4,7 +4,7 @@ import { NamedArguments } from './NamedArguments.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class NamedArgumentGroup implements SlangNode { readonly kind = NonterminalKind.NamedArgumentGroup; @@ -31,10 +31,7 @@ export class NamedArgumentGroup implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return ['{', path.call(print, 'arguments'), '}']; } } diff --git a/src/slang-nodes/NamedArguments.ts b/src/slang-nodes/NamedArguments.ts index 369584585..6257bdc84 100644 --- a/src/slang-nodes/NamedArguments.ts +++ b/src/slang-nodes/NamedArguments.ts @@ -6,7 +6,7 @@ import { NamedArgument } from './NamedArgument.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { line, softline } = doc.builders; @@ -42,7 +42,7 @@ export class NamedArguments implements SlangNode { print( path: AstPath, - print: (path: AstPath) => Doc, + print: PrintFunction, options: ParserOptions ): Doc { return printSeparatedList(path.map(print, 'items'), { diff --git a/src/slang-nodes/NamedArgumentsDeclaration.ts b/src/slang-nodes/NamedArgumentsDeclaration.ts index b679e8fde..1b64ee67c 100644 --- a/src/slang-nodes/NamedArgumentsDeclaration.ts +++ b/src/slang-nodes/NamedArgumentsDeclaration.ts @@ -4,7 +4,7 @@ import { NamedArgumentGroup } from './NamedArgumentGroup.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class NamedArgumentsDeclaration implements SlangNode { readonly kind = NonterminalKind.NamedArgumentsDeclaration; @@ -37,10 +37,7 @@ export class NamedArgumentsDeclaration implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return ['(', this.arguments ? path.call(print, 'arguments') : '', ')']; } } diff --git a/src/slang-nodes/NamedImport.ts b/src/slang-nodes/NamedImport.ts index 94bb87fd2..0faa5d435 100644 --- a/src/slang-nodes/NamedImport.ts +++ b/src/slang-nodes/NamedImport.ts @@ -5,7 +5,7 @@ import { StringLiteral } from './StringLiteral.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class NamedImport implements SlangNode { readonly kind = NonterminalKind.NamedImport; @@ -38,10 +38,7 @@ export class NamedImport implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [ this.asterisk, path.call(print, 'alias'), diff --git a/src/slang-nodes/NewExpression.ts b/src/slang-nodes/NewExpression.ts index 730a9f05f..79a9ad888 100644 --- a/src/slang-nodes/NewExpression.ts +++ b/src/slang-nodes/NewExpression.ts @@ -4,7 +4,7 @@ import { TypeName } from './TypeName.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class NewExpression implements SlangNode { readonly kind = NonterminalKind.NewExpression; @@ -31,10 +31,7 @@ export class NewExpression implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return ['new ', path.call(print, 'typeName')]; } } diff --git a/src/slang-nodes/OrExpression.ts b/src/slang-nodes/OrExpression.ts index 0923d979f..1fb9d2ce9 100644 --- a/src/slang-nodes/OrExpression.ts +++ b/src/slang-nodes/OrExpression.ts @@ -6,7 +6,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const tryToHug = createHugFunction(['&&']); @@ -46,7 +46,7 @@ export class OrExpression implements SlangNode { print( path: AstPath, - print: (path: AstPath) => Doc, + print: PrintFunction, options: ParserOptions ): Doc { return printLogicalOperation(this, path, print, options); diff --git a/src/slang-nodes/OverridePaths.ts b/src/slang-nodes/OverridePaths.ts index 0988dbc76..6d6182c69 100644 --- a/src/slang-nodes/OverridePaths.ts +++ b/src/slang-nodes/OverridePaths.ts @@ -35,7 +35,7 @@ export class OverridePaths implements SlangNode { // TODO: implement print print(/* path: AstPath, - print: (path: AstPath) => Doc, + print: PrintFunction, options: ParserOptions */): Doc { return ['TODO: OverridePaths']; diff --git a/src/slang-nodes/OverridePathsDeclaration.ts b/src/slang-nodes/OverridePathsDeclaration.ts index e535102c3..711ee78e2 100644 --- a/src/slang-nodes/OverridePathsDeclaration.ts +++ b/src/slang-nodes/OverridePathsDeclaration.ts @@ -30,7 +30,7 @@ export class OverridePathsDeclaration implements SlangNode { // TODO: implement print print(/* path: AstPath, - print: (path: AstPath) => Doc, + print: PrintFunction, options: ParserOptions */): Doc { return ['TODO: OverridePathsDeclaration']; diff --git a/src/slang-nodes/OverrideSpecifier.ts b/src/slang-nodes/OverrideSpecifier.ts index 6a401644e..7e424f6c1 100644 --- a/src/slang-nodes/OverrideSpecifier.ts +++ b/src/slang-nodes/OverrideSpecifier.ts @@ -4,7 +4,7 @@ import { OverridePathsDeclaration } from './OverridePathsDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { PrintFunction, SlangNode } from '../types'; export class OverrideSpecifier implements SlangNode { readonly kind = NonterminalKind.OverrideSpecifier; @@ -32,10 +32,7 @@ export class OverrideSpecifier implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return ['override', this.overridden ? path.call(print, 'overridden') : '']; } } diff --git a/src/slang-nodes/Parameter.ts b/src/slang-nodes/Parameter.ts index 8e9cf7ab7..5ed2be6b6 100644 --- a/src/slang-nodes/Parameter.ts +++ b/src/slang-nodes/Parameter.ts @@ -6,7 +6,7 @@ import { StorageLocation } from './StorageLocation.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { group } = doc.builders; @@ -46,10 +46,7 @@ export class Parameter implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return group([ path.call(print, 'typeName'), this.storageLocation ? [' ', path.call(print, 'storageLocation')] : '', diff --git a/src/slang-nodes/Parameters.ts b/src/slang-nodes/Parameters.ts index 6ee76591c..f3c19fe62 100644 --- a/src/slang-nodes/Parameters.ts +++ b/src/slang-nodes/Parameters.ts @@ -7,7 +7,7 @@ import { Parameter } from './Parameter.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class Parameters implements SlangNode { readonly kind = NonterminalKind.Parameters; @@ -39,10 +39,7 @@ export class Parameters implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { if (this.items.length > 0) { return printSeparatedList(path.map(print, 'items'), { grouped: false }); } diff --git a/src/slang-nodes/ParametersDeclaration.ts b/src/slang-nodes/ParametersDeclaration.ts index e837fbe40..de7de6233 100644 --- a/src/slang-nodes/ParametersDeclaration.ts +++ b/src/slang-nodes/ParametersDeclaration.ts @@ -4,7 +4,7 @@ import { Parameters } from './Parameters.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class ParametersDeclaration implements SlangNode { readonly kind = NonterminalKind.ParametersDeclaration; @@ -31,10 +31,7 @@ export class ParametersDeclaration implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return ['(', path.call(print, 'parameters'), ')']; } } diff --git a/src/slang-nodes/PathImport.ts b/src/slang-nodes/PathImport.ts index cd092c707..7950d17a6 100644 --- a/src/slang-nodes/PathImport.ts +++ b/src/slang-nodes/PathImport.ts @@ -5,7 +5,7 @@ import { ImportAlias } from './ImportAlias.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class PathImport implements SlangNode { readonly kind = NonterminalKind.PathImport; @@ -37,10 +37,7 @@ export class PathImport implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [ path.call(print, 'path'), this.alias ? path.call(print, 'alias') : '' diff --git a/src/slang-nodes/PositionalArguments.ts b/src/slang-nodes/PositionalArguments.ts index 219e47e9b..c6cd2fe1d 100644 --- a/src/slang-nodes/PositionalArguments.ts +++ b/src/slang-nodes/PositionalArguments.ts @@ -5,7 +5,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class PositionalArguments implements SlangNode { readonly kind = NonterminalKind.PositionalArguments; @@ -37,10 +37,7 @@ export class PositionalArguments implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return this.items.length > 0 ? printSeparatedList(path.map(print, 'items')) : ''; diff --git a/src/slang-nodes/PositionalArgumentsDeclaration.ts b/src/slang-nodes/PositionalArgumentsDeclaration.ts index a818bfd9d..5a8169e0d 100644 --- a/src/slang-nodes/PositionalArgumentsDeclaration.ts +++ b/src/slang-nodes/PositionalArgumentsDeclaration.ts @@ -4,7 +4,7 @@ import { PositionalArguments } from './PositionalArguments.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class PositionalArgumentsDeclaration implements SlangNode { readonly kind = NonterminalKind.PositionalArgumentsDeclaration; @@ -37,7 +37,7 @@ export class PositionalArgumentsDeclaration implements SlangNode { print( path: AstPath, - print: (path: AstPath) => Doc + print: PrintFunction ): Doc { return ['(', path.call(print, 'arguments'), ')']; } diff --git a/src/slang-nodes/PostfixExpression.ts b/src/slang-nodes/PostfixExpression.ts index 94eb016f0..33d7b38ce 100644 --- a/src/slang-nodes/PostfixExpression.ts +++ b/src/slang-nodes/PostfixExpression.ts @@ -4,7 +4,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class PostfixExpression implements SlangNode { readonly kind = NonterminalKind.PostfixExpression; @@ -34,10 +34,7 @@ export class PostfixExpression implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [path.call(print, 'operand'), this.operator]; } } diff --git a/src/slang-nodes/Pragma.ts b/src/slang-nodes/Pragma.ts index 55c7eb19e..7c2a96128 100644 --- a/src/slang-nodes/Pragma.ts +++ b/src/slang-nodes/Pragma.ts @@ -6,7 +6,7 @@ import { VersionPragma } from './VersionPragma.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class Pragma implements SlangNode { readonly kind = NonterminalKind.Pragma; @@ -55,7 +55,7 @@ export class Pragma implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print(path: AstPath, print: PrintFunction): Doc { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/PragmaDirective.ts b/src/slang-nodes/PragmaDirective.ts index d9a4267c2..a24470cf5 100644 --- a/src/slang-nodes/PragmaDirective.ts +++ b/src/slang-nodes/PragmaDirective.ts @@ -4,7 +4,7 @@ import { Pragma } from './Pragma.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class PragmaDirective implements SlangNode { readonly kind = NonterminalKind.PragmaDirective; @@ -31,10 +31,7 @@ export class PragmaDirective implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return ['pragma ', path.call(print, 'pragma'), ';']; } } diff --git a/src/slang-nodes/PrefixExpression.ts b/src/slang-nodes/PrefixExpression.ts index 2c82d54ea..c0191d242 100644 --- a/src/slang-nodes/PrefixExpression.ts +++ b/src/slang-nodes/PrefixExpression.ts @@ -4,7 +4,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class PrefixExpression implements SlangNode { readonly kind = NonterminalKind.PrefixExpression; @@ -34,10 +34,7 @@ export class PrefixExpression implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [this.operator, path.call(print, 'operand')]; } } diff --git a/src/slang-nodes/ReceiveFunctionAttribute.ts b/src/slang-nodes/ReceiveFunctionAttribute.ts index 8b86eaa2e..e333a2394 100644 --- a/src/slang-nodes/ReceiveFunctionAttribute.ts +++ b/src/slang-nodes/ReceiveFunctionAttribute.ts @@ -6,7 +6,7 @@ import { OverrideSpecifier } from './OverrideSpecifier.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class ReceiveFunctionAttribute implements SlangNode { readonly kind = NonterminalKind.ReceiveFunctionAttribute; @@ -56,10 +56,7 @@ export class ReceiveFunctionAttribute implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/ReceiveFunctionAttributes.ts b/src/slang-nodes/ReceiveFunctionAttributes.ts index f1a011e6e..98b9c36b6 100644 --- a/src/slang-nodes/ReceiveFunctionAttributes.ts +++ b/src/slang-nodes/ReceiveFunctionAttributes.ts @@ -6,7 +6,7 @@ import { ReceiveFunctionAttribute } from './ReceiveFunctionAttribute.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { line } = doc.builders; @@ -40,10 +40,7 @@ export class ReceiveFunctionAttributes implements SlangNode { this.items = this.items.sort(sortFunctionAttributes); } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return path.map(print, 'items').map((item) => [line, item]); } } diff --git a/src/slang-nodes/ReceiveFunctionDefinition.ts b/src/slang-nodes/ReceiveFunctionDefinition.ts index 877ec2e89..111261f23 100644 --- a/src/slang-nodes/ReceiveFunctionDefinition.ts +++ b/src/slang-nodes/ReceiveFunctionDefinition.ts @@ -7,7 +7,7 @@ import { FunctionBody } from './FunctionBody.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class ReceiveFunctionDefinition implements SlangNode { readonly kind = NonterminalKind.ReceiveFunctionDefinition; @@ -65,10 +65,7 @@ export class ReceiveFunctionDefinition implements SlangNode { } } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return printFunction('receive', this, path, print); } } diff --git a/src/slang-nodes/ReturnStatement.ts b/src/slang-nodes/ReturnStatement.ts index 276995025..e880834d3 100644 --- a/src/slang-nodes/ReturnStatement.ts +++ b/src/slang-nodes/ReturnStatement.ts @@ -5,14 +5,14 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { group, indent, line } = doc.builders; function printExpression( node: ReturnStatement, path: AstPath, - print: (path: AstPath) => Doc, + print: PrintFunction, options: ParserOptions ): Doc { if (node.expression) { @@ -56,7 +56,7 @@ export class ReturnStatement implements SlangNode { print( path: AstPath, - print: (path: AstPath) => Doc, + print: PrintFunction, options: ParserOptions ): Doc { return ['return', printExpression(this, path, print, options), ';']; diff --git a/src/slang-nodes/ReturnsDeclaration.ts b/src/slang-nodes/ReturnsDeclaration.ts index 59b617001..5c21ca546 100644 --- a/src/slang-nodes/ReturnsDeclaration.ts +++ b/src/slang-nodes/ReturnsDeclaration.ts @@ -5,7 +5,7 @@ import { ParametersDeclaration } from './ParametersDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { group } = doc.builders; @@ -38,10 +38,7 @@ export class ReturnsDeclaration implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return ['returns ', group(path.call(print, 'variables'))]; } } diff --git a/src/slang-nodes/RevertStatement.ts b/src/slang-nodes/RevertStatement.ts index 2e03a0f69..738a14a3c 100644 --- a/src/slang-nodes/RevertStatement.ts +++ b/src/slang-nodes/RevertStatement.ts @@ -5,7 +5,7 @@ import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class RevertStatement implements SlangNode { readonly kind = NonterminalKind.RevertStatement; @@ -43,10 +43,7 @@ export class RevertStatement implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [ 'revert ', this.error ? path.call(print, 'error') : '', diff --git a/src/slang-nodes/ShiftExpression.ts b/src/slang-nodes/ShiftExpression.ts index 1515ba639..61fcb3591 100644 --- a/src/slang-nodes/ShiftExpression.ts +++ b/src/slang-nodes/ShiftExpression.ts @@ -6,7 +6,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const tryToHugLeftOperand = createHugFunction([ '+', @@ -55,7 +55,7 @@ export class ShiftExpression implements SlangNode { print( path: AstPath, - print: (path: AstPath) => Doc, + print: PrintFunction, options: ParserOptions ): Doc { return printBinaryOperation(this, path, print, options); diff --git a/src/slang-nodes/SourceUnit.ts b/src/slang-nodes/SourceUnit.ts index bac4eb7b6..1e1b5b71b 100644 --- a/src/slang-nodes/SourceUnit.ts +++ b/src/slang-nodes/SourceUnit.ts @@ -5,7 +5,7 @@ import { SourceUnitMembers } from './SourceUnitMembers.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { line } = doc.builders; @@ -36,7 +36,7 @@ export class SourceUnit implements SlangNode { print( path: AstPath, - print: (path: AstPath) => Doc, + print: PrintFunction, options: ParserOptions ): Doc { return [path.call(print, 'members'), options.parentParser ? '' : line]; diff --git a/src/slang-nodes/SourceUnitMember.ts b/src/slang-nodes/SourceUnitMember.ts index 8b42767cf..65ca24d44 100644 --- a/src/slang-nodes/SourceUnitMember.ts +++ b/src/slang-nodes/SourceUnitMember.ts @@ -16,7 +16,7 @@ import { EventDefinition } from './EventDefinition.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class SourceUnitMember implements SlangNode { readonly kind = NonterminalKind.SourceUnitMember; @@ -148,10 +148,7 @@ export class SourceUnitMember implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/SourceUnitMembers.ts b/src/slang-nodes/SourceUnitMembers.ts index 0870af416..48cd7626e 100644 --- a/src/slang-nodes/SourceUnitMembers.ts +++ b/src/slang-nodes/SourceUnitMembers.ts @@ -5,7 +5,7 @@ import { SourceUnitMember } from './SourceUnitMember.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class SourceUnitMembers implements SlangNode { readonly kind = NonterminalKind.SourceUnitMembers; @@ -36,7 +36,7 @@ export class SourceUnitMembers implements SlangNode { print( path: AstPath, - print: (path: AstPath) => Doc, + print: PrintFunction, options: ParserOptions ): Doc { return printPreservingEmptyLines(path, print, options); diff --git a/src/slang-nodes/StateVariableAttribute.ts b/src/slang-nodes/StateVariableAttribute.ts index 7558e294c..52d4da220 100644 --- a/src/slang-nodes/StateVariableAttribute.ts +++ b/src/slang-nodes/StateVariableAttribute.ts @@ -5,7 +5,7 @@ import { OverrideSpecifier } from './OverrideSpecifier.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { PrintFunction, SlangNode } from '../types'; export class StateVariableAttribute implements SlangNode { readonly kind = NonterminalKind.StateVariableAttribute; @@ -34,10 +34,7 @@ export class StateVariableAttribute implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/StateVariableAttributes.ts b/src/slang-nodes/StateVariableAttributes.ts index a8fde4ad6..8ce97fc5d 100644 --- a/src/slang-nodes/StateVariableAttributes.ts +++ b/src/slang-nodes/StateVariableAttributes.ts @@ -4,7 +4,7 @@ import { StateVariableAttribute } from './StateVariableAttribute.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { PrintFunction, SlangNode } from '../types'; export class StateVariableAttributes implements SlangNode { readonly kind = NonterminalKind.StateVariableAttributes; @@ -29,10 +29,7 @@ export class StateVariableAttributes implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return this.items.length ? path.map(print, 'items').map((item) => [' ', item]) : ''; diff --git a/src/slang-nodes/StateVariableDefinition.ts b/src/slang-nodes/StateVariableDefinition.ts index c6b89004b..b4998e42f 100644 --- a/src/slang-nodes/StateVariableDefinition.ts +++ b/src/slang-nodes/StateVariableDefinition.ts @@ -6,7 +6,7 @@ import { StateVariableDefinitionValue } from './StateVariableDefinitionValue.js' import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class StateVariableDefinition implements SlangNode { readonly kind = NonterminalKind.StateVariableDefinition; @@ -48,10 +48,7 @@ export class StateVariableDefinition implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [ path.call(print, 'typeName'), path.call(print, 'attributes'), diff --git a/src/slang-nodes/StateVariableDefinitionValue.ts b/src/slang-nodes/StateVariableDefinitionValue.ts index 36e4670a7..6d5cf5b43 100644 --- a/src/slang-nodes/StateVariableDefinitionValue.ts +++ b/src/slang-nodes/StateVariableDefinitionValue.ts @@ -5,7 +5,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { group, indent, line } = doc.builders; @@ -36,7 +36,7 @@ export class StateVariableDefinitionValue implements SlangNode { print( path: AstPath, - print: (path: AstPath) => Doc + print: PrintFunction ): Doc { return typeof this.value.variant !== 'string' && this.value.variant.kind === NonterminalKind.ArrayExpression diff --git a/src/slang-nodes/Statement.ts b/src/slang-nodes/Statement.ts index 13aeaec30..eda9204dd 100644 --- a/src/slang-nodes/Statement.ts +++ b/src/slang-nodes/Statement.ts @@ -20,7 +20,7 @@ import { UncheckedBlock } from './UncheckedBlock.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class Statement implements SlangNode { readonly kind = NonterminalKind.Statement; @@ -179,7 +179,7 @@ export class Statement implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print(path: AstPath, print: PrintFunction): Doc { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/Statements.ts b/src/slang-nodes/Statements.ts index e69f98e04..9073d3be7 100644 --- a/src/slang-nodes/Statements.ts +++ b/src/slang-nodes/Statements.ts @@ -8,7 +8,7 @@ import { Statement } from './Statement.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { hardline } = doc.builders; @@ -41,7 +41,7 @@ export class Statements implements SlangNode { print( path: AstPath, - print: (path: AstPath) => Doc, + print: PrintFunction, options: ParserOptions ): Doc { return this.items.length === 0 && this.comments.length === 0 diff --git a/src/slang-nodes/StringExpression.ts b/src/slang-nodes/StringExpression.ts index 50778d4e5..6c3c12151 100644 --- a/src/slang-nodes/StringExpression.ts +++ b/src/slang-nodes/StringExpression.ts @@ -8,7 +8,7 @@ import { UnicodeStringLiterals } from './UnicodeStringLiterals.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class StringExpression implements SlangNode { readonly kind = NonterminalKind.StringExpression; @@ -79,10 +79,7 @@ export class StringExpression implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/StringLiterals.ts b/src/slang-nodes/StringLiterals.ts index 4a2849fba..3a71b17b3 100644 --- a/src/slang-nodes/StringLiterals.ts +++ b/src/slang-nodes/StringLiterals.ts @@ -5,7 +5,7 @@ import { StringLiteral } from './StringLiteral.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { join, hardline } = doc.builders; @@ -36,10 +36,7 @@ export class StringLiterals implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return join(hardline, path.map(print, 'items')); } } diff --git a/src/slang-nodes/StructDefinition.ts b/src/slang-nodes/StructDefinition.ts index 405d82f7e..9bf6f943c 100644 --- a/src/slang-nodes/StructDefinition.ts +++ b/src/slang-nodes/StructDefinition.ts @@ -4,7 +4,7 @@ import { StructMembers } from './StructMembers.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class StructDefinition implements SlangNode { readonly kind = NonterminalKind.StructDefinition; @@ -34,10 +34,7 @@ export class StructDefinition implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [`struct ${this.name} {`, path.call(print, 'members'), '}']; } } diff --git a/src/slang-nodes/StructMember.ts b/src/slang-nodes/StructMember.ts index 13c2ded53..795c1426a 100644 --- a/src/slang-nodes/StructMember.ts +++ b/src/slang-nodes/StructMember.ts @@ -4,7 +4,7 @@ import { TypeName } from './TypeName.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class StructMember implements SlangNode { readonly kind = NonterminalKind.StructMember; @@ -34,10 +34,7 @@ export class StructMember implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [path.call(print, 'typeName'), ` ${this.name};`]; } } diff --git a/src/slang-nodes/StructMembers.ts b/src/slang-nodes/StructMembers.ts index 43663eaba..9f3cf110b 100644 --- a/src/slang-nodes/StructMembers.ts +++ b/src/slang-nodes/StructMembers.ts @@ -6,7 +6,7 @@ import { StructMember } from './StructMember.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { hardline } = doc.builders; @@ -37,10 +37,7 @@ export class StructMembers implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return this.items.length > 0 ? printSeparatedList(path.map(print, 'items'), { firstSeparator: hardline, diff --git a/src/slang-nodes/TryStatement.ts b/src/slang-nodes/TryStatement.ts index fddb532c4..02be9c69c 100644 --- a/src/slang-nodes/TryStatement.ts +++ b/src/slang-nodes/TryStatement.ts @@ -9,7 +9,7 @@ import { CatchClauses } from './CatchClauses.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { line } = doc.builders; @@ -57,10 +57,7 @@ export class TryStatement implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [ 'try', printSeparatedItem(path.call(print, 'expression'), { diff --git a/src/slang-nodes/TupleDeconstructionElement.ts b/src/slang-nodes/TupleDeconstructionElement.ts index 59c85e101..93d30c33b 100644 --- a/src/slang-nodes/TupleDeconstructionElement.ts +++ b/src/slang-nodes/TupleDeconstructionElement.ts @@ -4,7 +4,7 @@ import { TupleMember } from './TupleMember.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class TupleDeconstructionElement implements SlangNode { readonly kind = NonterminalKind.TupleDeconstructionElement; @@ -33,10 +33,7 @@ export class TupleDeconstructionElement implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return this.member ? path.call(print, 'member') : ''; } } diff --git a/src/slang-nodes/TupleDeconstructionElements.ts b/src/slang-nodes/TupleDeconstructionElements.ts index 9466e30e8..cfbd1eb8c 100644 --- a/src/slang-nodes/TupleDeconstructionElements.ts +++ b/src/slang-nodes/TupleDeconstructionElements.ts @@ -5,7 +5,7 @@ import { TupleDeconstructionElement } from './TupleDeconstructionElement.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class TupleDeconstructionElements implements SlangNode { readonly kind = NonterminalKind.TupleDeconstructionElements; @@ -38,10 +38,7 @@ export class TupleDeconstructionElements implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return printSeparatedList(path.map(print, 'items')); } } diff --git a/src/slang-nodes/TupleDeconstructionStatement.ts b/src/slang-nodes/TupleDeconstructionStatement.ts index 2f4592642..f2818bc3f 100644 --- a/src/slang-nodes/TupleDeconstructionStatement.ts +++ b/src/slang-nodes/TupleDeconstructionStatement.ts @@ -6,7 +6,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { group, indent, line } = doc.builders; @@ -47,10 +47,10 @@ export class TupleDeconstructionStatement implements SlangNode { print( path: AstPath, - print: (path: AstPath) => Doc + print: PrintFunction ): Doc { return [ - this.varKeyword ? this.varKeyword : '', + this.varKeyword ? 'var ' : '', '(', path.call(print, 'elements'), typeof this.expression.variant !== 'string' && diff --git a/src/slang-nodes/TupleExpression.ts b/src/slang-nodes/TupleExpression.ts index 0f5e350ea..517c4a8db 100644 --- a/src/slang-nodes/TupleExpression.ts +++ b/src/slang-nodes/TupleExpression.ts @@ -4,7 +4,7 @@ import { TupleValues } from './TupleValues.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class TupleExpression implements SlangNode { readonly kind = NonterminalKind.TupleExpression; @@ -31,10 +31,7 @@ export class TupleExpression implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return ['(', path.call(print, 'items'), ')']; } } diff --git a/src/slang-nodes/TupleMember.ts b/src/slang-nodes/TupleMember.ts index 7a82c70b1..a656fc3a8 100644 --- a/src/slang-nodes/TupleMember.ts +++ b/src/slang-nodes/TupleMember.ts @@ -5,7 +5,7 @@ import { UntypedTupleMember } from './UntypedTupleMember.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class TupleMember implements SlangNode { readonly kind = NonterminalKind.TupleMember; @@ -48,10 +48,7 @@ export class TupleMember implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/TupleValue.ts b/src/slang-nodes/TupleValue.ts index 817a911e6..42c5f3ba3 100644 --- a/src/slang-nodes/TupleValue.ts +++ b/src/slang-nodes/TupleValue.ts @@ -4,7 +4,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class TupleValue implements SlangNode { readonly kind = NonterminalKind.TupleValue; @@ -33,10 +33,7 @@ export class TupleValue implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return this.expression ? path.call(print, 'expression') : ''; } } diff --git a/src/slang-nodes/TupleValues.ts b/src/slang-nodes/TupleValues.ts index bfd026496..180dd50ab 100644 --- a/src/slang-nodes/TupleValues.ts +++ b/src/slang-nodes/TupleValues.ts @@ -6,7 +6,7 @@ import { TupleValue } from './TupleValue.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class TupleValues implements SlangNode { readonly kind = NonterminalKind.TupleValues; @@ -38,10 +38,7 @@ export class TupleValues implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return this.items.length === 1 && typeof this.items[0].expression!.variant !== 'string' && isBinaryOperation(this.items[0].expression!.variant) diff --git a/src/slang-nodes/TypeExpression.ts b/src/slang-nodes/TypeExpression.ts index ea8a984f4..26d8004f5 100644 --- a/src/slang-nodes/TypeExpression.ts +++ b/src/slang-nodes/TypeExpression.ts @@ -34,7 +34,7 @@ export class TypeExpression implements SlangNode { // TODO: implement print print(/* path: AstPath, - print: (path: AstPath) => Doc, + print: PrintFunction, options: ParserOptions */): Doc { return ['TODO: TypeExpression']; diff --git a/src/slang-nodes/TypeName.ts b/src/slang-nodes/TypeName.ts index b3c93d9cb..3d75f1056 100644 --- a/src/slang-nodes/TypeName.ts +++ b/src/slang-nodes/TypeName.ts @@ -8,7 +8,7 @@ import { IdentifierPath } from './IdentifierPath.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class TypeName implements SlangNode { readonly kind = NonterminalKind.TypeName; @@ -79,7 +79,7 @@ export class TypeName implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print(path: AstPath, print: PrintFunction): Doc { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/TypedTupleMember.ts b/src/slang-nodes/TypedTupleMember.ts index 0ec0cbc7f..38654c0c7 100644 --- a/src/slang-nodes/TypedTupleMember.ts +++ b/src/slang-nodes/TypedTupleMember.ts @@ -5,7 +5,7 @@ import { StorageLocation } from './StorageLocation.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class TypedTupleMember implements SlangNode { readonly kind = NonterminalKind.TypedTupleMember; @@ -43,10 +43,7 @@ export class TypedTupleMember implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [ path.call(print, 'typeName'), this.storageLocation ? [' ', path.call(print, 'storageLocation')] : '', diff --git a/src/slang-nodes/UncheckedBlock.ts b/src/slang-nodes/UncheckedBlock.ts index c3b9889a2..c902a76af 100644 --- a/src/slang-nodes/UncheckedBlock.ts +++ b/src/slang-nodes/UncheckedBlock.ts @@ -4,7 +4,7 @@ import { Block } from './Block.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class UncheckedBlock implements SlangNode { readonly kind = NonterminalKind.UncheckedBlock; @@ -31,10 +31,7 @@ export class UncheckedBlock implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return ['unchecked ', path.call(print, 'block')]; } } diff --git a/src/slang-nodes/UnicodeStringLiterals.ts b/src/slang-nodes/UnicodeStringLiterals.ts index a45fa04d6..6b1fa3421 100644 --- a/src/slang-nodes/UnicodeStringLiterals.ts +++ b/src/slang-nodes/UnicodeStringLiterals.ts @@ -5,7 +5,7 @@ import { UnicodeStringLiteral } from './UnicodeStringLiteral.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { join, hardline } = doc.builders; @@ -36,10 +36,7 @@ export class UnicodeStringLiterals implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return join(hardline, path.map(print, 'items')); } } diff --git a/src/slang-nodes/UnnamedFunctionAttribute.ts b/src/slang-nodes/UnnamedFunctionAttribute.ts index 881566ab6..cb2f69887 100644 --- a/src/slang-nodes/UnnamedFunctionAttribute.ts +++ b/src/slang-nodes/UnnamedFunctionAttribute.ts @@ -5,7 +5,7 @@ import { ModifierInvocation } from './ModifierInvocation.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class UnnamedFunctionAttribute implements SlangNode { readonly kind = NonterminalKind.UnnamedFunctionAttribute; @@ -38,10 +38,7 @@ export class UnnamedFunctionAttribute implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/UnnamedFunctionAttributes.ts b/src/slang-nodes/UnnamedFunctionAttributes.ts index 289a1c030..73b6b0651 100644 --- a/src/slang-nodes/UnnamedFunctionAttributes.ts +++ b/src/slang-nodes/UnnamedFunctionAttributes.ts @@ -6,7 +6,7 @@ import { UnnamedFunctionAttribute } from './UnnamedFunctionAttribute.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { line } = doc.builders; @@ -40,10 +40,7 @@ export class UnnamedFunctionAttributes implements SlangNode { this.items = this.items.sort(sortFunctionAttributes); } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return path.map(print, 'items').map((item) => [line, item]); } } diff --git a/src/slang-nodes/UnnamedFunctionDefinition.ts b/src/slang-nodes/UnnamedFunctionDefinition.ts index 2d4689501..501f8d916 100644 --- a/src/slang-nodes/UnnamedFunctionDefinition.ts +++ b/src/slang-nodes/UnnamedFunctionDefinition.ts @@ -7,7 +7,7 @@ import { FunctionBody } from './FunctionBody.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class UnnamedFunctionDefinition implements SlangNode { readonly kind = NonterminalKind.UnnamedFunctionDefinition; @@ -62,10 +62,7 @@ export class UnnamedFunctionDefinition implements SlangNode { } } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return printFunction('function', this, path, print); } } diff --git a/src/slang-nodes/UntypedTupleMember.ts b/src/slang-nodes/UntypedTupleMember.ts index b82016bbf..2b55c94fc 100644 --- a/src/slang-nodes/UntypedTupleMember.ts +++ b/src/slang-nodes/UntypedTupleMember.ts @@ -38,7 +38,7 @@ export class UntypedTupleMember implements SlangNode { // TODO: implement print print(/* path: AstPath, - print: (path: AstPath) => Doc, + print: PrintFunction, options: ParserOptions */): Doc { return ['TODO: UntypedTupleMemberUntypedTupleMember']; diff --git a/src/slang-nodes/UserDefinedValueTypeDefinition.ts b/src/slang-nodes/UserDefinedValueTypeDefinition.ts index 82201c550..451e9dccd 100644 --- a/src/slang-nodes/UserDefinedValueTypeDefinition.ts +++ b/src/slang-nodes/UserDefinedValueTypeDefinition.ts @@ -4,7 +4,7 @@ import { ElementaryType } from './ElementaryType.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { PrintFunction, SlangNode } from '../types'; export class UserDefinedValueTypeDefinition implements SlangNode { readonly kind = NonterminalKind.UserDefinedValueTypeDefinition; @@ -32,7 +32,7 @@ export class UserDefinedValueTypeDefinition implements SlangNode { print( path: AstPath, - print: (path: AstPath) => Doc + print: PrintFunction ): Doc { return [`type ${this.name} is `, path.call(print, 'valueType'), ';']; } diff --git a/src/slang-nodes/UsingAlias.ts b/src/slang-nodes/UsingAlias.ts index 300567b3a..3396719af 100644 --- a/src/slang-nodes/UsingAlias.ts +++ b/src/slang-nodes/UsingAlias.ts @@ -4,7 +4,7 @@ import { UsingOperator } from './UsingOperator.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { PrintFunction, SlangNode } from '../types'; export class UsingAlias implements SlangNode { readonly kind = NonterminalKind.UsingAlias; @@ -27,10 +27,7 @@ export class UsingAlias implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [' as ', path.call(print, 'operator')]; } } diff --git a/src/slang-nodes/UsingClause.ts b/src/slang-nodes/UsingClause.ts index ce8e561f2..55bbcaa8e 100644 --- a/src/slang-nodes/UsingClause.ts +++ b/src/slang-nodes/UsingClause.ts @@ -5,7 +5,7 @@ import { UsingDeconstruction } from './UsingDeconstruction.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { PrintFunction, SlangNode } from '../types'; export class UsingClause implements SlangNode { readonly kind = NonterminalKind.UsingClause; @@ -46,10 +46,7 @@ export class UsingClause implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/UsingDeconstruction.ts b/src/slang-nodes/UsingDeconstruction.ts index a11a2feb8..1a75b255f 100644 --- a/src/slang-nodes/UsingDeconstruction.ts +++ b/src/slang-nodes/UsingDeconstruction.ts @@ -4,7 +4,7 @@ import { UsingDeconstructionSymbols } from './UsingDeconstructionSymbols.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { PrintFunction, SlangNode } from '../types'; export class UsingDeconstruction implements SlangNode { readonly kind = NonterminalKind.UsingDeconstruction; @@ -27,10 +27,7 @@ export class UsingDeconstruction implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return ['{', path.call(print, 'symbols'), '}']; } } diff --git a/src/slang-nodes/UsingDeconstructionSymbol.ts b/src/slang-nodes/UsingDeconstructionSymbol.ts index dc7f1ccff..8197e7976 100644 --- a/src/slang-nodes/UsingDeconstructionSymbol.ts +++ b/src/slang-nodes/UsingDeconstructionSymbol.ts @@ -5,7 +5,7 @@ import { UsingAlias } from './UsingAlias.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { PrintFunction, SlangNode } from '../types'; export class UsingDeconstructionSymbol implements SlangNode { readonly kind = NonterminalKind.UsingDeconstructionSymbol; @@ -33,10 +33,7 @@ export class UsingDeconstructionSymbol implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [ path.call(print, 'name'), this.alias ? path.call(print, 'alias') : '' diff --git a/src/slang-nodes/UsingDeconstructionSymbols.ts b/src/slang-nodes/UsingDeconstructionSymbols.ts index 2588b312b..38d69b43c 100644 --- a/src/slang-nodes/UsingDeconstructionSymbols.ts +++ b/src/slang-nodes/UsingDeconstructionSymbols.ts @@ -6,7 +6,7 @@ import { UsingDeconstructionSymbol } from './UsingDeconstructionSymbol.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { line, softline } = doc.builders; @@ -38,7 +38,7 @@ export class UsingDeconstructionSymbols implements SlangNode { print( path: AstPath, - print: (path: AstPath) => Doc, + print: PrintFunction, options: ParserOptions ): Doc { return printSeparatedList(path.map(print, 'items'), { diff --git a/src/slang-nodes/UsingDirective.ts b/src/slang-nodes/UsingDirective.ts index 978d5e446..1e96bb2b2 100644 --- a/src/slang-nodes/UsingDirective.ts +++ b/src/slang-nodes/UsingDirective.ts @@ -5,7 +5,7 @@ import { UsingTarget } from './UsingTarget.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class UsingDirective implements SlangNode { readonly kind = NonterminalKind.UsingDirective; @@ -38,10 +38,7 @@ export class UsingDirective implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [ 'using ', path.call(print, 'clause'), diff --git a/src/slang-nodes/UsingTarget.ts b/src/slang-nodes/UsingTarget.ts index adf0c9d6b..ed3c32923 100644 --- a/src/slang-nodes/UsingTarget.ts +++ b/src/slang-nodes/UsingTarget.ts @@ -5,7 +5,7 @@ import { TypeName } from './TypeName.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class UsingTarget implements SlangNode { readonly kind = NonterminalKind.UsingTarget; @@ -38,10 +38,7 @@ export class UsingTarget implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/VariableDeclarationStatement.ts b/src/slang-nodes/VariableDeclarationStatement.ts index 729050c2b..d94aa1a80 100644 --- a/src/slang-nodes/VariableDeclarationStatement.ts +++ b/src/slang-nodes/VariableDeclarationStatement.ts @@ -7,7 +7,7 @@ import { VariableDeclarationValue } from './VariableDeclarationValue.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { group, indent, indentIfBreak, line } = doc.builders; @@ -63,7 +63,7 @@ export class VariableDeclarationStatement implements SlangNode { print( path: AstPath, - print: (path: AstPath) => Doc + print: PrintFunction ): Doc { const declarationDoc = group( [ diff --git a/src/slang-nodes/VariableDeclarationType.ts b/src/slang-nodes/VariableDeclarationType.ts index 09db0dc27..1963f9747 100644 --- a/src/slang-nodes/VariableDeclarationType.ts +++ b/src/slang-nodes/VariableDeclarationType.ts @@ -5,7 +5,7 @@ import { TypeName } from './TypeName.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class VariableDeclarationType implements SlangNode { readonly kind = NonterminalKind.VariableDeclarationType; @@ -38,10 +38,7 @@ export class VariableDeclarationType implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/VariableDeclarationValue.ts b/src/slang-nodes/VariableDeclarationValue.ts index 237853fd5..d810b8df5 100644 --- a/src/slang-nodes/VariableDeclarationValue.ts +++ b/src/slang-nodes/VariableDeclarationValue.ts @@ -4,7 +4,7 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class VariableDeclarationValue implements SlangNode { readonly kind = NonterminalKind.VariableDeclarationValue; @@ -31,10 +31,7 @@ export class VariableDeclarationValue implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [' = ', path.call(print, 'expression')]; } } diff --git a/src/slang-nodes/VersionComparator.ts b/src/slang-nodes/VersionComparator.ts index 4579b9503..589916749 100644 --- a/src/slang-nodes/VersionComparator.ts +++ b/src/slang-nodes/VersionComparator.ts @@ -4,7 +4,7 @@ import { VersionExpression } from './VersionExpression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { PrintFunction, SlangNode } from '../types'; export class VersionComparator implements SlangNode { readonly kind = NonterminalKind.VersionComparator; @@ -30,10 +30,7 @@ export class VersionComparator implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [this.operator, path.call(print, 'operand')]; } } diff --git a/src/slang-nodes/VersionExpression.ts b/src/slang-nodes/VersionExpression.ts index c6894b59b..f00c058ba 100644 --- a/src/slang-nodes/VersionExpression.ts +++ b/src/slang-nodes/VersionExpression.ts @@ -7,7 +7,7 @@ import { VersionSpecifiers } from './VersionSpecifiers.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { PrintFunction, SlangNode } from '../types'; export class VersionExpression implements SlangNode { readonly kind = NonterminalKind.VersionExpression; @@ -58,10 +58,7 @@ export class VersionExpression implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/VersionExpressionSet.ts b/src/slang-nodes/VersionExpressionSet.ts index 511232298..cc3f67ab2 100644 --- a/src/slang-nodes/VersionExpressionSet.ts +++ b/src/slang-nodes/VersionExpressionSet.ts @@ -5,7 +5,7 @@ import { VersionExpression } from './VersionExpression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { PrintFunction, SlangNode } from '../types'; const { join } = doc.builders; @@ -32,10 +32,7 @@ export class VersionExpressionSet implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return join(' ', path.map(print, 'items')); } } diff --git a/src/slang-nodes/VersionExpressionSets.ts b/src/slang-nodes/VersionExpressionSets.ts index 33b66c138..20c95d7fe 100644 --- a/src/slang-nodes/VersionExpressionSets.ts +++ b/src/slang-nodes/VersionExpressionSets.ts @@ -4,7 +4,7 @@ import { VersionExpressionSet } from './VersionExpressionSet.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { PrintFunction, SlangNode } from '../types'; export class VersionExpressionSets implements SlangNode { readonly kind = NonterminalKind.VersionExpressionSets; @@ -32,10 +32,7 @@ export class VersionExpressionSets implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return path .map(print, 'items') .map((item, index) => diff --git a/src/slang-nodes/VersionPragma.ts b/src/slang-nodes/VersionPragma.ts index 3e9fcfae5..fdd2f812e 100644 --- a/src/slang-nodes/VersionPragma.ts +++ b/src/slang-nodes/VersionPragma.ts @@ -4,7 +4,7 @@ import { VersionExpressionSets } from './VersionExpressionSets.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { PrintFunction, SlangNode } from '../types'; export class VersionPragma implements SlangNode { readonly kind = NonterminalKind.VersionPragma; @@ -27,10 +27,7 @@ export class VersionPragma implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return ['solidity ', path.call(print, 'sets')]; } } diff --git a/src/slang-nodes/VersionRange.ts b/src/slang-nodes/VersionRange.ts index 4b55c113d..71fbe5a14 100644 --- a/src/slang-nodes/VersionRange.ts +++ b/src/slang-nodes/VersionRange.ts @@ -4,7 +4,7 @@ import { VersionExpression } from './VersionExpression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { PrintFunction, SlangNode } from '../types'; export class VersionRange implements SlangNode { readonly kind = NonterminalKind.VersionRange; @@ -33,11 +33,7 @@ export class VersionRange implements SlangNode { this.loc = metadata.loc; } - // TODO: implement print - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [ path.call(print, 'leftOperand'), ` ${this.operator} `, diff --git a/src/slang-nodes/WhileStatement.ts b/src/slang-nodes/WhileStatement.ts index 77154068b..db46ab691 100644 --- a/src/slang-nodes/WhileStatement.ts +++ b/src/slang-nodes/WhileStatement.ts @@ -7,7 +7,7 @@ import { Statement } from './Statement.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { group, indent, line } = doc.builders; @@ -39,10 +39,7 @@ export class WhileStatement implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [ 'while (', printSeparatedItem(path.call(print, 'condition')), diff --git a/src/slang-nodes/YulArguments.ts b/src/slang-nodes/YulArguments.ts index 8cca490f9..99241e23b 100644 --- a/src/slang-nodes/YulArguments.ts +++ b/src/slang-nodes/YulArguments.ts @@ -5,7 +5,7 @@ import { YulExpression } from './YulExpression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class YulArguments implements SlangNode { readonly kind = NonterminalKind.YulArguments; @@ -37,10 +37,7 @@ export class YulArguments implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return printSeparatedList(path.map(print, 'items')); } } diff --git a/src/slang-nodes/YulAssignmentOperator.ts b/src/slang-nodes/YulAssignmentOperator.ts index b08c19c24..ffeb05768 100644 --- a/src/slang-nodes/YulAssignmentOperator.ts +++ b/src/slang-nodes/YulAssignmentOperator.ts @@ -5,7 +5,7 @@ import { YulColonEqual } from './YulColonEqual.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { PrintFunction, SlangNode } from '../types'; export class YulAssignmentOperator implements SlangNode { readonly kind = NonterminalKind.YulAssignmentOperator; @@ -34,10 +34,7 @@ export class YulAssignmentOperator implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/YulBlock.ts b/src/slang-nodes/YulBlock.ts index cbfb607de..f6ddd8cbb 100644 --- a/src/slang-nodes/YulBlock.ts +++ b/src/slang-nodes/YulBlock.ts @@ -4,7 +4,7 @@ import { YulStatements } from './YulStatements.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class YulBlock implements SlangNode { readonly kind = NonterminalKind.YulBlock; @@ -31,7 +31,7 @@ export class YulBlock implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print(path: AstPath, print: PrintFunction): Doc { return ['{', path.call(print, 'statements'), '}']; } } diff --git a/src/slang-nodes/YulDefaultCase.ts b/src/slang-nodes/YulDefaultCase.ts index 7d32fbf31..d070bf8a6 100644 --- a/src/slang-nodes/YulDefaultCase.ts +++ b/src/slang-nodes/YulDefaultCase.ts @@ -4,7 +4,7 @@ import { YulBlock } from './YulBlock.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class YulDefaultCase implements SlangNode { readonly kind = NonterminalKind.YulDefaultCase; @@ -31,10 +31,7 @@ export class YulDefaultCase implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return ['default ', path.call(print, 'body')]; } } diff --git a/src/slang-nodes/YulExpression.ts b/src/slang-nodes/YulExpression.ts index d3b8db596..df1ddcf72 100644 --- a/src/slang-nodes/YulExpression.ts +++ b/src/slang-nodes/YulExpression.ts @@ -7,7 +7,7 @@ import { YulPath } from './YulPath.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class YulExpression implements SlangNode { readonly kind = NonterminalKind.YulExpression; @@ -64,10 +64,7 @@ export class YulExpression implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/YulForStatement.ts b/src/slang-nodes/YulForStatement.ts index 5d375fd28..cef1366a3 100644 --- a/src/slang-nodes/YulForStatement.ts +++ b/src/slang-nodes/YulForStatement.ts @@ -5,7 +5,7 @@ import { YulExpression } from './YulExpression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class YulForStatement implements SlangNode { readonly kind = NonterminalKind.YulForStatement; @@ -46,10 +46,7 @@ export class YulForStatement implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [ 'for ', path.call(print, 'initialization'), diff --git a/src/slang-nodes/YulFunctionCallExpression.ts b/src/slang-nodes/YulFunctionCallExpression.ts index fc43092f8..0daf8d368 100644 --- a/src/slang-nodes/YulFunctionCallExpression.ts +++ b/src/slang-nodes/YulFunctionCallExpression.ts @@ -5,7 +5,7 @@ import { YulArguments } from './YulArguments.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class YulFunctionCallExpression implements SlangNode { readonly kind = NonterminalKind.YulFunctionCallExpression; @@ -35,10 +35,7 @@ export class YulFunctionCallExpression implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [ path.call(print, 'operand'), '(', diff --git a/src/slang-nodes/YulFunctionDefinition.ts b/src/slang-nodes/YulFunctionDefinition.ts index a197966d9..ef454a679 100644 --- a/src/slang-nodes/YulFunctionDefinition.ts +++ b/src/slang-nodes/YulFunctionDefinition.ts @@ -6,7 +6,7 @@ import { YulBlock } from './YulBlock.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class YulFunctionDefinition implements SlangNode { readonly kind = NonterminalKind.YulFunctionDefinition; @@ -50,10 +50,7 @@ export class YulFunctionDefinition implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [ `function ${this.name}`, path.call(print, 'parameters'), diff --git a/src/slang-nodes/YulIfStatement.ts b/src/slang-nodes/YulIfStatement.ts index 49d4f9ff3..35b0282f1 100644 --- a/src/slang-nodes/YulIfStatement.ts +++ b/src/slang-nodes/YulIfStatement.ts @@ -5,7 +5,7 @@ import { YulBlock } from './YulBlock.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class YulIfStatement implements SlangNode { readonly kind = NonterminalKind.YulIfStatement; @@ -35,10 +35,7 @@ export class YulIfStatement implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [ 'if ', path.call(print, 'condition'), diff --git a/src/slang-nodes/YulLiteral.ts b/src/slang-nodes/YulLiteral.ts index 0a260b121..dec44ff49 100644 --- a/src/slang-nodes/YulLiteral.ts +++ b/src/slang-nodes/YulLiteral.ts @@ -6,7 +6,7 @@ import { StringLiteral } from './StringLiteral.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class YulLiteral implements SlangNode { readonly kind = NonterminalKind.YulLiteral; @@ -57,10 +57,7 @@ export class YulLiteral implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return typeof this.variant === 'string' ? this.variant : path.call(print, 'variant'); diff --git a/src/slang-nodes/YulParametersDeclaration.ts b/src/slang-nodes/YulParametersDeclaration.ts index b382c0166..5988031af 100644 --- a/src/slang-nodes/YulParametersDeclaration.ts +++ b/src/slang-nodes/YulParametersDeclaration.ts @@ -4,7 +4,7 @@ import { YulParameters } from './YulParameters.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { PrintFunction, SlangNode } from '../types'; export class YulParametersDeclaration implements SlangNode { readonly kind = NonterminalKind.YulParametersDeclaration; @@ -27,10 +27,7 @@ export class YulParametersDeclaration implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return ['(', path.call(print, 'parameters'), ')']; } } diff --git a/src/slang-nodes/YulPath.ts b/src/slang-nodes/YulPath.ts index 2c6575cdb..f1c7785ca 100644 --- a/src/slang-nodes/YulPath.ts +++ b/src/slang-nodes/YulPath.ts @@ -4,7 +4,7 @@ import { YulPathComponent } from './YulPathComponent.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { PrintFunction, SlangNode } from '../types'; export class YulPath implements SlangNode { readonly kind = NonterminalKind.YulPath; @@ -32,7 +32,7 @@ export class YulPath implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print(path: AstPath, print: PrintFunction): Doc { return path .map(print, 'items') .map((item, index) => diff --git a/src/slang-nodes/YulPaths.ts b/src/slang-nodes/YulPaths.ts index ee4de9e8a..d69a6b2c9 100644 --- a/src/slang-nodes/YulPaths.ts +++ b/src/slang-nodes/YulPaths.ts @@ -4,7 +4,7 @@ import { YulPath } from './YulPath.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { PrintFunction, SlangNode } from '../types'; export class YulPaths implements SlangNode { readonly kind = NonterminalKind.YulPaths; @@ -32,7 +32,7 @@ export class YulPaths implements SlangNode { this.loc = metadata.loc; } - print(path: AstPath, print: (path: AstPath) => Doc): Doc { + print(path: AstPath, print: PrintFunction): Doc { return path .map(print, 'items') .map((item, index) => diff --git a/src/slang-nodes/YulReturnsDeclaration.ts b/src/slang-nodes/YulReturnsDeclaration.ts index 4939a452e..becc0cc11 100644 --- a/src/slang-nodes/YulReturnsDeclaration.ts +++ b/src/slang-nodes/YulReturnsDeclaration.ts @@ -6,7 +6,7 @@ import { YulReturnVariables } from './YulReturnVariables.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { PrintFunction, SlangNode } from '../types'; const { line } = doc.builders; @@ -34,10 +34,7 @@ export class YulReturnsDeclaration implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return printSeparatedItem( [this.minusGreaterThan, path.call(print, 'variables')], { diff --git a/src/slang-nodes/YulStackAssignmentStatement.ts b/src/slang-nodes/YulStackAssignmentStatement.ts index da32895d5..e58602f00 100644 --- a/src/slang-nodes/YulStackAssignmentStatement.ts +++ b/src/slang-nodes/YulStackAssignmentStatement.ts @@ -38,7 +38,7 @@ export class YulStackAssignmentStatement implements SlangNode { // TODO: implement print print(/* path: AstPath, - print: (path: AstPath) => Doc, + print: PrintFunction, options: ParserOptions */): Doc { return ['TODO: YulStackAssignmentStatement']; diff --git a/src/slang-nodes/YulStatement.ts b/src/slang-nodes/YulStatement.ts index ec590d7b1..311d305ed 100644 --- a/src/slang-nodes/YulStatement.ts +++ b/src/slang-nodes/YulStatement.ts @@ -16,7 +16,7 @@ import { YulExpression } from './YulExpression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class YulStatement implements SlangNode { readonly kind = NonterminalKind.YulStatement; @@ -143,10 +143,7 @@ export class YulStatement implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/YulStatements.ts b/src/slang-nodes/YulStatements.ts index f5a0b1df1..997853360 100644 --- a/src/slang-nodes/YulStatements.ts +++ b/src/slang-nodes/YulStatements.ts @@ -8,7 +8,7 @@ import { YulStatement } from './YulStatement.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { hardline } = doc.builders; @@ -41,7 +41,7 @@ export class YulStatements implements SlangNode { print( path: AstPath, - print: (path: AstPath) => Doc, + print: PrintFunction, options: ParserOptions ): Doc { return this.items.length === 0 && this.comments.length === 0 diff --git a/src/slang-nodes/YulSwitchCase.ts b/src/slang-nodes/YulSwitchCase.ts index 8f70a4a7d..6d6bcc259 100644 --- a/src/slang-nodes/YulSwitchCase.ts +++ b/src/slang-nodes/YulSwitchCase.ts @@ -5,7 +5,7 @@ import { YulValueCase } from './YulValueCase.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class YulSwitchCase implements SlangNode { readonly kind = NonterminalKind.YulSwitchCase; @@ -49,10 +49,7 @@ export class YulSwitchCase implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return path.call(print, 'variant'); } } diff --git a/src/slang-nodes/YulSwitchCases.ts b/src/slang-nodes/YulSwitchCases.ts index 70f173047..1fd814c61 100644 --- a/src/slang-nodes/YulSwitchCases.ts +++ b/src/slang-nodes/YulSwitchCases.ts @@ -5,7 +5,7 @@ import { YulSwitchCase } from './YulSwitchCase.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { hardline, join } = doc.builders; @@ -36,10 +36,7 @@ export class YulSwitchCases implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return join(hardline, path.map(print, 'items')); } } diff --git a/src/slang-nodes/YulSwitchStatement.ts b/src/slang-nodes/YulSwitchStatement.ts index 352fe6470..cbdfe00e3 100644 --- a/src/slang-nodes/YulSwitchStatement.ts +++ b/src/slang-nodes/YulSwitchStatement.ts @@ -6,7 +6,7 @@ import { YulSwitchCases } from './YulSwitchCases.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; const { hardline } = doc.builders; @@ -38,10 +38,7 @@ export class YulSwitchStatement implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [ 'switch ', path.call(print, 'expression'), diff --git a/src/slang-nodes/YulValueCase.ts b/src/slang-nodes/YulValueCase.ts index 15ddfb639..b321a0077 100644 --- a/src/slang-nodes/YulValueCase.ts +++ b/src/slang-nodes/YulValueCase.ts @@ -5,7 +5,7 @@ import { YulBlock } from './YulBlock.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class YulValueCase implements SlangNode { readonly kind = NonterminalKind.YulValueCase; @@ -35,10 +35,7 @@ export class YulValueCase implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return ['case ', path.call(print, 'value'), ' ', path.call(print, 'body')]; } } diff --git a/src/slang-nodes/YulVariableAssignmentStatement.ts b/src/slang-nodes/YulVariableAssignmentStatement.ts index 96b34f822..2e308ac1a 100644 --- a/src/slang-nodes/YulVariableAssignmentStatement.ts +++ b/src/slang-nodes/YulVariableAssignmentStatement.ts @@ -6,7 +6,7 @@ import { YulExpression } from './YulExpression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class YulVariableAssignmentStatement implements SlangNode { readonly kind = NonterminalKind.YulVariableAssignmentStatement; @@ -45,7 +45,7 @@ export class YulVariableAssignmentStatement implements SlangNode { print( path: AstPath, - print: (path: AstPath) => Doc + print: PrintFunction ): Doc { return [ path.call(print, 'names'), diff --git a/src/slang-nodes/YulVariableDeclarationStatement.ts b/src/slang-nodes/YulVariableDeclarationStatement.ts index 98e6d5ef6..3213fa59a 100644 --- a/src/slang-nodes/YulVariableDeclarationStatement.ts +++ b/src/slang-nodes/YulVariableDeclarationStatement.ts @@ -4,7 +4,7 @@ import { YulVariableDeclarationValue } from './YulVariableDeclarationValue.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class YulVariableDeclarationStatement implements SlangNode { readonly kind = NonterminalKind.YulVariableDeclarationStatement; @@ -42,7 +42,7 @@ export class YulVariableDeclarationStatement implements SlangNode { print( path: AstPath, - print: (path: AstPath) => Doc + print: PrintFunction ): Doc { return [`let ${this.names} `, this.value ? path.call(print, 'value') : '']; } diff --git a/src/slang-nodes/YulVariableDeclarationValue.ts b/src/slang-nodes/YulVariableDeclarationValue.ts index 6bcf5a5f3..1b750c3cf 100644 --- a/src/slang-nodes/YulVariableDeclarationValue.ts +++ b/src/slang-nodes/YulVariableDeclarationValue.ts @@ -5,7 +5,7 @@ import { YulExpression } from './YulExpression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode, PrintFunction, SlangNode } from '../types'; export class YulVariableDeclarationValue implements SlangNode { readonly kind = NonterminalKind.YulVariableDeclarationValue; @@ -35,10 +35,7 @@ export class YulVariableDeclarationValue implements SlangNode { this.loc = metadata.loc; } - print( - path: AstPath, - print: (path: AstPath) => Doc - ): Doc { + print(path: AstPath, print: PrintFunction): Doc { return [ path.call(print, 'assignment'), ' ', diff --git a/src/slang-printers/create-binary-operation-printer.ts b/src/slang-printers/create-binary-operation-printer.ts index e6c7213f0..f9bb47a40 100644 --- a/src/slang-printers/create-binary-operation-printer.ts +++ b/src/slang-printers/create-binary-operation-printer.ts @@ -2,14 +2,19 @@ import { doc } from 'prettier'; import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, BinaryOperation } from '../types'; +import type { + AstNode, + BinaryOperation, + PrintFunction, + StrictAstNode +} from '../types'; const { group, line } = doc.builders; function rightOperandPrint( node: BinaryOperation, path: AstPath, - print: (path: AstPath) => Doc + print: PrintFunction ): Doc { const rightOperand = [line, path.call(print, 'rightOperand')]; @@ -19,7 +24,7 @@ function rightOperandPrint( !( typeof node.leftOperand.variant !== 'string' && isBinaryOperation(node.leftOperand.variant) - ) && !isBinaryOperation(path.getNode(2) as AstNode); + ) && !isBinaryOperation(path.getNode(2) as StrictAstNode); return shouldGroup ? group(rightOperand) : rightOperand; } @@ -37,7 +42,7 @@ export const createBinaryOperationPrinter = ( node: BinaryOperation, path: AstPath, - print: (path: AstPath) => Doc, + print: PrintFunction, options: ParserOptions ): Doc => { const groupRules = groupRulesBuilder(path); diff --git a/src/slang-printers/print-binary-operation.ts b/src/slang-printers/print-binary-operation.ts index 6a8903454..4042e1722 100644 --- a/src/slang-printers/print-binary-operation.ts +++ b/src/slang-printers/print-binary-operation.ts @@ -4,7 +4,7 @@ import { createBinaryOperationPrinter } from './create-binary-operation-printer. import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, BinaryOperation } from '../types'; +import type { AstNode, BinaryOperation, StrictAstNode } from '../types'; const { group, indent } = doc.builders; @@ -19,12 +19,12 @@ const isBinaryOperationWithoutComparison = createKindCheckFunction([ NonterminalKind.AndExpression, NonterminalKind.OrExpression, NonterminalKind.ShiftExpression -]) as (node: AstNode | Comment | Node) => node is BinaryOperation; +]) as (node: StrictAstNode | Comment | Node) => node is BinaryOperation; const binaryGroupRulesBuilder = (path: AstPath) => (document: Doc): Doc => { - const grandparentNode = path.getNode(2) as AstNode; + const grandparentNode = path.getNode(2) as StrictAstNode; if (isBinaryOperationWithoutComparison(grandparentNode)) { return document; } @@ -36,7 +36,7 @@ const binaryIndentRulesBuilder = (document: Doc): Doc => { let node = path.getNode() as AstNode; for (let i = 2; ; i += 2) { - const grandparentNode = path.getNode(i) as AstNode; + const grandparentNode = path.getNode(i) as StrictAstNode; if (grandparentNode.kind === NonterminalKind.ReturnStatement) break; if (!isBinaryOperationWithoutComparison(grandparentNode)) { return indent(document); diff --git a/src/slang-printers/print-comparison-operation.ts b/src/slang-printers/print-comparison-operation.ts index c6b7eef4c..f5d192d3d 100644 --- a/src/slang-printers/print-comparison-operation.ts +++ b/src/slang-printers/print-comparison-operation.ts @@ -5,7 +5,7 @@ import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; import { createBinaryOperationPrinter } from './create-binary-operation-printer.js'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, BinaryOperation } from '../types'; +import type { BinaryOperation, StrictAstNode } from '../types'; const { group, indent } = doc.builders; @@ -18,12 +18,12 @@ const isStatementWithoutIndentedOperation = createKindCheckFunction([ const comparisonIndentRulesBuilder = (path: AstPath) => (document: Doc): Doc => { - let node = path.getNode() as AstNode; + let node = path.getNode() as StrictAstNode; for (let i = 2; ; i += 2) { - const grandparentNode = path.getNode(i) as AstNode; + const grandparentNode = path.getNode(i) as StrictAstNode; if (grandparentNode.kind === NonterminalKind.ExpressionStatement) { if ( - (path.getNode(i + 1) as AstNode).kind === + (path.getNode(i + 1) as StrictAstNode).kind === NonterminalKind.ForStatementCondition ) break; diff --git a/src/slang-printers/print-function.ts b/src/slang-printers/print-function.ts index f820bd833..3cdb604f3 100644 --- a/src/slang-printers/print-function.ts +++ b/src/slang-printers/print-function.ts @@ -1,7 +1,7 @@ import { doc } from 'prettier'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, FunctionLike } from '../types'; +import type { FunctionLike, PrintFunction } from '../types'; import type { FunctionDefinition } from '../slang-nodes'; const { dedent, group, indent, line } = doc.builders; @@ -10,7 +10,7 @@ export function printFunction( functionName: Doc, node: FunctionLike, path: AstPath, - print: (path: AstPath) => Doc + print: PrintFunction ): Doc { return [ group([ diff --git a/src/slang-printers/print-logical-operation.ts b/src/slang-printers/print-logical-operation.ts index ff19f9ec3..31f43c116 100644 --- a/src/slang-printers/print-logical-operation.ts +++ b/src/slang-printers/print-logical-operation.ts @@ -5,7 +5,7 @@ import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; import { createBinaryOperationPrinter } from './create-binary-operation-printer.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, BinaryOperation } from '../types'; +import type { AstNode, BinaryOperation, StrictAstNode } from '../types'; const { group, indent } = doc.builders; @@ -18,14 +18,16 @@ const isStatementWithoutIndentedOperation = createKindCheckFunction([ const logicalGroupRulesBuilder = (path: AstPath) => (document: Doc): Doc => - isBinaryOperation(path.getNode(2) as AstNode) ? document : group(document); + isBinaryOperation(path.getNode(2) as StrictAstNode) + ? document + : group(document); const logicalIndentRulesBuilder = (path: AstPath, options: ParserOptions) => (document: Doc): Doc => { - let node = path.getNode() as AstNode; + let node = path.getNode() as StrictAstNode; for (let i = 2; ; i += 2) { - const grandparentNode = path.getNode(i) as AstNode; + const grandparentNode = path.getNode(i) as StrictAstNode; if (isStatementWithoutIndentedOperation(grandparentNode)) break; if ( options.experimentalTernaries && diff --git a/src/slang-printers/print-preserving-empty-lines.ts b/src/slang-printers/print-preserving-empty-lines.ts index a0e5bcd11..bbc46297f 100644 --- a/src/slang-printers/print-preserving-empty-lines.ts +++ b/src/slang-printers/print-preserving-empty-lines.ts @@ -7,17 +7,17 @@ import { import { locEnd } from '../slang-utils/loc.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode } from '../types'; +import type { AstNode, HubNode, PrintFunction, StrictAstNode } from '../types'; const { hardline } = doc.builders; export function printPreservingEmptyLines( - path: AstPath, - print: (path: AstPath) => Doc, + path: AstPath, + print: PrintFunction, options: ParserOptions ): Doc { return path.map((childPath, index) => { - const node = childPath.getNode()! as AstNode; + const node = childPath.getNode() as StrictAstNode; return [ // Only attempt to prepend an empty line if `node` is not the first item diff --git a/src/slang-utils/backward-compatibility.ts b/src/slang-utils/backward-compatibility.ts index c9896a279..6c7a52564 100644 --- a/src/slang-utils/backward-compatibility.ts +++ b/src/slang-utils/backward-compatibility.ts @@ -33,10 +33,7 @@ export function getNextNonSpaceNonCommentCharacter( return util.getNextNonSpaceNonCommentCharacter(text, locEnd(node)); // V3 exposes this function directly } -export function isLast( - path: AstPath, - index: number -): boolean { +export function isLast(path: AstPath, index: number): boolean { return isPrettier2 ? index === (path.getParentNode() as HubNode).items.length - 1 : path.isLast; diff --git a/src/slang-utils/create-kind-check-function.ts b/src/slang-utils/create-kind-check-function.ts index 5077d55f4..39aa40102 100644 --- a/src/slang-utils/create-kind-check-function.ts +++ b/src/slang-utils/create-kind-check-function.ts @@ -1,9 +1,10 @@ import type { Node } from '@nomicfoundation/slang/cst'; -import type { AstNode, Comment } from '../types'; +import type { Comment, StrictAstNode } from '../types'; export function createKindCheckFunction( kindsArray: string[] -): (node: AstNode | Comment | Node) => boolean { +): (node: StrictAstNode | Comment | Node) => boolean { const kinds = new Set(kindsArray); - return (node: AstNode | Comment | Node): boolean => kinds.has(node.kind); + return (node: StrictAstNode | Comment | Node): boolean => + kinds.has(node.kind); } diff --git a/src/slang-utils/is-binary-operation.ts b/src/slang-utils/is-binary-operation.ts index 81bfe2a65..bbe9a95d7 100644 --- a/src/slang-utils/is-binary-operation.ts +++ b/src/slang-utils/is-binary-operation.ts @@ -1,7 +1,7 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { createKindCheckFunction } from './create-kind-check-function.js'; -import type { AstNode, BinaryOperation } from '../types'; +import type { BinaryOperation, StrictAstNode } from '../types'; export const isBinaryOperation = createKindCheckFunction([ NonterminalKind.AdditiveExpression, @@ -16,4 +16,4 @@ export const isBinaryOperation = createKindCheckFunction([ NonterminalKind.AndExpression, NonterminalKind.OrExpression, NonterminalKind.ShiftExpression -]) as (node: AstNode | Comment | Node) => node is BinaryOperation; +]) as (node: StrictAstNode | Comment | Node) => node is BinaryOperation; diff --git a/src/slang-utils/loc.ts b/src/slang-utils/loc.ts index fecc681b0..b0f107c1b 100644 --- a/src/slang-utils/loc.ts +++ b/src/slang-utils/loc.ts @@ -1,9 +1,11 @@ import type { AstNode, Comment } from '../types'; export function locStart(node: AstNode | Comment): number { + if (typeof node === 'string' || typeof node === 'undefined') return -1; return node.loc.start; } export function locEnd(node: AstNode | Comment): number { + if (typeof node === 'string' || typeof node === 'undefined') return -1; return node.loc.end; } diff --git a/src/slang-utils/metadata.ts b/src/slang-utils/metadata.ts index 9c52e9437..94446fe01 100644 --- a/src/slang-utils/metadata.ts +++ b/src/slang-utils/metadata.ts @@ -3,7 +3,7 @@ import { NodeType } from '@nomicfoundation/slang/cst/index.js'; import { isComment } from './is-comment.js'; import type { Node } from '@nomicfoundation/slang/cst'; -import type { AstNode, Comment, Metadata, SlangAstNode } from '../types'; +import type { Comment, Metadata, SlangAstNode, StrictAstNode } from '../types'; function getLeadingOffset(children: Node[]): number { let offset = 0; @@ -76,7 +76,7 @@ export function getNodeMetadata( function collectComments( comments: Comment[], - node: AstNode | AstNode[] | undefined + node: StrictAstNode | StrictAstNode[] | undefined ): Comment[] { if (node) { if (Array.isArray(node)) { @@ -90,7 +90,7 @@ function collectComments( export function updateMetadata( metadata: Metadata, - childNodes: (AstNode | AstNode[] | undefined)[] + childNodes: (StrictAstNode | StrictAstNode[] | undefined)[] ): Metadata { // Collect comments const comments = childNodes.reduce(collectComments, metadata.comments); diff --git a/src/slang-utils/sort-function-attributes.ts b/src/slang-utils/sort-function-attributes.ts index 62ab11f3a..7385e228c 100644 --- a/src/slang-utils/sort-function-attributes.ts +++ b/src/slang-utils/sort-function-attributes.ts @@ -1,6 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; -import type { SortableAttribute, SortableVariant } from './types'; +import type { SortableAttribute } from './types'; const visibilityKeyWords = new Set([ 'external', @@ -15,34 +15,39 @@ export function sortFunctionAttributes( a: SortableAttribute, b: SortableAttribute ): number { - const aIsString = typeof a.variant === 'string'; - const bIsString = typeof b.variant === 'string'; + const aVariant = a.variant; + const bVariant = b.variant; + + const aIsString = typeof aVariant === 'string'; + const bIsString = typeof bVariant === 'string'; if (aIsString && !bIsString) return -1; if (bIsString && !aIsString) return 1; // Both are strings - if (aIsString) { + if (aIsString && bIsString) { // Visibility First - if (visibilityKeyWords.has(a.variant as string)) return -1; - if (visibilityKeyWords.has(b.variant as string)) return 1; + if (visibilityKeyWords.has(aVariant)) return -1; + if (visibilityKeyWords.has(bVariant)) return 1; // State Mutability Second - if (mutabilityKeyWords.has(a.variant as string)) return -1; - if (mutabilityKeyWords.has(b.variant as string)) return 1; + if (mutabilityKeyWords.has(aVariant)) return -1; + if (mutabilityKeyWords.has(bVariant)) return 1; // Virtual keyword last } // Both are nodes - // OverrideSpecifiers before ModifierInvocation - if ( - (a.variant as SortableVariant).kind === NonterminalKind.OverrideSpecifier && - (b.variant as SortableVariant).kind === NonterminalKind.ModifierInvocation - ) - return -1; - if ( - (b.variant as SortableVariant).kind === NonterminalKind.OverrideSpecifier && - (a.variant as SortableVariant).kind === NonterminalKind.ModifierInvocation - ) - return 1; + if (!aIsString && !bIsString) { + // OverrideSpecifiers before ModifierInvocation + if ( + aVariant.kind === NonterminalKind.OverrideSpecifier && + bVariant.kind === NonterminalKind.ModifierInvocation + ) + return -1; + if ( + bVariant.kind === NonterminalKind.OverrideSpecifier && + aVariant.kind === NonterminalKind.ModifierInvocation + ) + return 1; + } return 0; } diff --git a/src/slang-utils/types.d.ts b/src/slang-utils/types.d.ts index 0da419d7f..a6496d865 100644 --- a/src/slang-utils/types.d.ts +++ b/src/slang-utils/types.d.ts @@ -7,9 +7,7 @@ import type { ModifierAttribute, ReceiveFunctionAttribute, StateVariableAttribute, - UnnamedFunctionAttribute, - OverrideSpecifier, - ModifierInvocation + UnnamedFunctionAttribute } from '../slang-nodes'; import type { AstNode, Comment } from '../types'; @@ -23,8 +21,6 @@ type SortableAttribute = | StateVariableAttribute | UnnamedFunctionAttribute; -type SortableVariant = OverrideSpecifier | ModifierInvocation; - declare namespace utilV2Functions { function getNextNonSpaceNonCommentCharacterIndex( text: string, diff --git a/src/slangPrinter.ts b/src/slangPrinter.ts index d0f91f5c1..f7b791fc2 100644 --- a/src/slangPrinter.ts +++ b/src/slangPrinter.ts @@ -3,7 +3,7 @@ import { isBlockComment } from './slang-utils/is-comment.js'; import { locEnd, locStart } from './slang-utils/loc.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode } from './types'; +import type { AstNode, PrintFunction, StrictAstNode } from './types'; let checked = false; @@ -17,9 +17,11 @@ function prettierVersionCheck(): void { checked = true; } -function hasNodeIgnoreComment(node: AstNode): boolean { +function hasNodeIgnoreComment(node: StrictAstNode): boolean { + // Prettier sets SourceUnit's comments to undefined after assigning comments + // to each node. return ( - node?.comments && + node.comments && node.comments.some( (comment) => comment.value @@ -35,7 +37,7 @@ function ignoreComments(path: AstPath): void { // We ignore anything that is not an object if (node === null || node === undefined || typeof node !== 'object') return; - const keys = Object.keys(node) as (keyof AstNode)[]; + const keys = Object.keys(node) as (keyof StrictAstNode)[]; for (const key of keys) { switch (key) { // We ignore `kind`, `loc`, and comments since these are added by the @@ -65,18 +67,16 @@ function ignoreComments(path: AstPath): void { } } +// Nodes take care of undefined and string properties so we can restrict path +// to AstPath function genericPrint( - path: AstPath, + path: AstPath, options: ParserOptions, - print: (path: AstPath) => Doc + print: PrintFunction ): Doc { prettierVersionCheck(); - const node = path.getNode(); - - if (node === null || node === undefined) { - return ''; - } + const node = path.getNode()!; if (hasNodeIgnoreComment(node)) { ignoreComments(path); @@ -84,11 +84,10 @@ function genericPrint( return options.originalText.slice(locStart(node), locEnd(node)); } - return node.print( - path as AstPath, - print as (path: AstPath) => Doc, - options - ); + // Since each node has a print function with a specific AstPath, the union of + // all nodes into AstNode creates a print function with an AstPath of the + // intersection of all nodes. This forces us to cast this with a never type. + return node.print(path as AstPath, print, options); } export default genericPrint; diff --git a/src/types.d.ts b/src/types.d.ts index 46864ec16..6d816a522 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -27,9 +27,9 @@ interface BaseComment { leading?: boolean; trailing?: boolean; printed?: boolean; - precedingNode?: AstNode; - enclosingNode?: AstNode; - followingNode?: AstNode; + precedingNode?: StrictAstNode; + enclosingNode?: StrictAstNode; + followingNode?: StrictAstNode; } interface BlockComment extends BaseComment { kind: @@ -131,6 +131,8 @@ export type HubNode = | nodes.YulSwitchCases; export type AstNode = + | string + | undefined | nodes.SourceUnit | nodes.PragmaDirective | nodes.ABICoderPragma @@ -347,6 +349,10 @@ export type AstNode = | nodes.YulPaths | nodes.YulPath; +type StrictAstNode = Exclude; + +type PrintFunction = (path: AstPath) => Doc; + export type SlangAstNode = | ast.SourceUnit | ast.PragmaDirective From e16a8c73c49e0a29220274304c7115ef2e997a27 Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 7 Aug 2024 11:06:09 +1200 Subject: [PATCH 120/160] IfStatements Comments are now assigned in a similar way --- src/index.ts | 34 ++++++++----------- src/prettier-comments/language-js/comments.js | 10 ++++-- src/slang-comments/handler.ts | 12 +++++-- .../handlers/handle-else-branch-comments.ts | 34 +++++++++++++++++++ .../handlers/handle-if-statement-comments.ts | 1 - src/slang-comments/handlers/index.ts | 2 ++ src/slang-utils/is-label.ts | 4 +-- .../__snapshots__/format.test.js.snap | 14 ++++---- 8 files changed, 76 insertions(+), 35 deletions(-) create mode 100644 src/slang-comments/handlers/handle-else-branch-comments.ts diff --git a/src/index.ts b/src/index.ts index 33956f2e9..a33caecae 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,12 +1,12 @@ import * as comments from './comments/index.js'; -import * as slangComments from './slang-comments/index.js'; +import { handleComments, printComment } from './slang-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'; -import slangParse from './slangParser.js'; -import slangPrint from './slangPrinter.js'; +import solidityParse from './parser.js'; +import solidityPrint from './printer.js'; +import parse from './slangParser.js'; +import print from './slangPrinter.js'; import { isComment, isBlockComment } from './slang-utils/is-comment.js'; import { locEnd, locStart } from './slang-utils/loc.js'; @@ -36,10 +36,10 @@ const languages: SupportLanguage[] = [ ]; // https://prettier.io/docs/en/plugins.html#parsers -const parser = { astFormat: 'solidity-ast', parse, ...loc }; +const parser = { astFormat: 'solidity-ast', parse: solidityParse, ...loc }; const slangParser: Parser = { astFormat, - parse: slangParse, + parse, locStart, locEnd }; @@ -49,11 +49,11 @@ const parsers = { [parserName]: slangParser }; -const canAttachComment = (node: { type: string }): boolean => +const solidityCanAttachComment = (node: { type: string }): boolean => typeof node.type === 'string' && node.type !== 'BlockComment' && node.type !== 'LineComment'; -const slangCanAttachComment = (node: AstNode | Comment): boolean => +const canAttachComment = (node: AstNode | Comment): boolean => typeof node !== 'string' && typeof node !== 'undefined' && node.kind && @@ -61,7 +61,7 @@ const slangCanAttachComment = (node: AstNode | Comment): boolean => // https://prettier.io/docs/en/plugins.html#printers const printer = { - canAttachComment, + canAttachComment: solidityCanAttachComment, handleComments: { ownLine: comments.solidityHandleOwnLineComment, endOfLine: comments.solidityHandleEndOfLineComment, @@ -69,20 +69,16 @@ const printer = { }, isBlockComment: comments.isBlockComment, massageAstNode, - print, + print: solidityPrint, printComment: comments.printComment }; const slangPrinter: Printer = { - canAttachComment: slangCanAttachComment, - handleComments: { - ownLine: slangComments.slangHandleOwnLineComment, - endOfLine: slangComments.slangHandleEndOfLineComment, - remaining: slangComments.slangHandleRemainingComment - }, + canAttachComment, + handleComments, isBlockComment, massageAstNode, - print: slangPrint, - printComment: slangComments.printComment + print, + printComment }; const printers = { diff --git a/src/prettier-comments/language-js/comments.js b/src/prettier-comments/language-js/comments.js index f2dfe5dcf..269f68420 100644 --- a/src/prettier-comments/language-js/comments.js +++ b/src/prettier-comments/language-js/comments.js @@ -257,10 +257,14 @@ function handleIfStatementComments( precedingNode === enclosingNode.trueBody && followingNode === enclosingNode.falseBody ) { - if (precedingNode.type === "ExpressionStatement") { - addTrailingComment(precedingNode, comment); + if (precedingNode.type === "Block") { + if(precedingNode.statements.length === 0) { + addDanglingComment(precedingNode, comment); + } else { + addTrailingComment(precedingNode.statements[precedingNode.statements.length - 1], comment); + } } else { - addDanglingComment(enclosingNode, comment); + addTrailingComment(precedingNode, comment); } return true; } diff --git a/src/slang-comments/handler.ts b/src/slang-comments/handler.ts index a4727f88b..efaecb8cd 100644 --- a/src/slang-comments/handler.ts +++ b/src/slang-comments/handler.ts @@ -3,7 +3,7 @@ import handlers from './handlers/index.js'; import type { ParserOptions } from 'prettier'; import type { AstNode, Comment } from '../types'; -export function slangHandleOwnLineComment( +function ownLine( comment: Comment, text: string, options: ParserOptions, @@ -24,7 +24,7 @@ export function slangHandleOwnLineComment( return handlers.some((handler) => handler(handlerArguments)); } -export function slangHandleEndOfLineComment( +function endOfLine( comment: Comment, text: string, options: ParserOptions, @@ -45,7 +45,7 @@ export function slangHandleEndOfLineComment( return handlers.some((handler) => handler(handlerArguments)); } -export function slangHandleRemainingComment( +function remaining( comment: Comment, text: string, options: ParserOptions, @@ -65,3 +65,9 @@ export function slangHandleRemainingComment( return handlers.some((handler) => handler(handlerArguments)); } + +export const handleComments = { + ownLine, + endOfLine, + remaining +}; diff --git a/src/slang-comments/handlers/handle-else-branch-comments.ts b/src/slang-comments/handlers/handle-else-branch-comments.ts new file mode 100644 index 000000000..21670bb0d --- /dev/null +++ b/src/slang-comments/handlers/handle-else-branch-comments.ts @@ -0,0 +1,34 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { util } from 'prettier'; +import addHubNodeFirstComment from './add-hub-node-first-comment.js'; + +import type { HandlerParams } from './types.js'; + +const { addLeadingComment } = util; + +export default function handleElseBranchComments({ + enclosingNode, + followingNode, + comment +}: HandlerParams): boolean { + if (enclosingNode?.kind !== NonterminalKind.ElseBranch || !followingNode) { + return false; + } + + if ( + followingNode === enclosingNode.body && + followingNode.variant.kind === NonterminalKind.IfStatement + ) { + if (followingNode.variant.body.variant.kind === NonterminalKind.Block) { + addHubNodeFirstComment( + followingNode.variant.body.variant.statements, + comment + ); + } else { + addLeadingComment(followingNode.variant.body.variant, comment); + } + return true; + } + + return false; +} diff --git a/src/slang-comments/handlers/handle-if-statement-comments.ts b/src/slang-comments/handlers/handle-if-statement-comments.ts index e76a3c370..b43504cce 100644 --- a/src/slang-comments/handlers/handle-if-statement-comments.ts +++ b/src/slang-comments/handlers/handle-if-statement-comments.ts @@ -15,7 +15,6 @@ export default function handleIfStatementComments({ followingNode, comment }: HandlerParams): boolean { - // console.log(comment); if (enclosingNode?.kind !== NonterminalKind.IfStatement || !followingNode) { return false; } diff --git a/src/slang-comments/handlers/index.ts b/src/slang-comments/handlers/index.ts index 0488a93af..01551ade7 100644 --- a/src/slang-comments/handlers/index.ts +++ b/src/slang-comments/handlers/index.ts @@ -1,5 +1,6 @@ import handleBlockComments from './handle-block-comments.js'; import handleContractDefinitionComments from './handle-contract-definition-comments.js'; +import handleElseBranchComments from './handle-else-branch-comments.js'; import handleIfStatementComments from './handle-if-statement-comments.js'; import handleParametersDeclarationComments from './handle-parameters-declaration-comments.js'; import handleWhileStatementComments from './handle-while-statement-comments.js'; @@ -8,6 +9,7 @@ import handleYulBlockComments from './handle-yul-block-comments.js'; export default [ handleBlockComments, handleContractDefinitionComments, + handleElseBranchComments, handleIfStatementComments, handleParametersDeclarationComments, handleWhileStatementComments, diff --git a/src/slang-utils/is-label.ts b/src/slang-utils/is-label.ts index 8932a2be1..4116b52b4 100644 --- a/src/slang-utils/is-label.ts +++ b/src/slang-utils/is-label.ts @@ -1,5 +1,5 @@ import type { Doc, doc } from 'prettier'; -export function isLabel(doc: Doc): doc is doc.builders.Label { - return (doc as doc.builders.DocCommand).type === 'label'; +export function isLabel(document: Doc): document is doc.builders.Label { + return (document as doc.builders.DocCommand).type === 'label'; } diff --git a/tests/format/Comments/__snapshots__/format.test.js.snap b/tests/format/Comments/__snapshots__/format.test.js.snap index 097b2df9e..6a14f5883 100644 --- a/tests/format/Comments/__snapshots__/format.test.js.snap +++ b/tests/format/Comments/__snapshots__/format.test.js.snap @@ -260,18 +260,18 @@ contract Comments7 { contract Comments8 { function someFunction() { - if (something) {} - // comment - else {} + if (something) { + // comment + } else {} } } contract Comments8 { function someFunction() { - if (something) {} - /* comment - * comment */ - else {} + if (something) { + /* comment + * comment */ + } else {} } } From 7788f613997cb2b39b99d7b914e1d100c8d9e21a Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 7 Aug 2024 12:03:43 +1200 Subject: [PATCH 121/160] Rearranging the placement of the definition of the AstNode type --- src/index.ts | 3 +- src/slang-comments/handler.ts | 3 +- .../handlers/add-hub-node-first-comment.ts | 3 +- .../handlers/add-hub-node-last-comment.ts | 3 +- src/slang-comments/handlers/types.d.ts | 3 +- src/slang-comments/printer.ts | 3 +- src/slang-nodes/AdditiveExpression.ts | 3 +- src/slang-nodes/AndExpression.ts | 3 +- src/slang-nodes/ArgumentsDeclaration.ts | 3 +- src/slang-nodes/ArrayExpression.ts | 3 +- src/slang-nodes/ArrayTypeName.ts | 3 +- src/slang-nodes/ArrayValues.ts | 3 +- src/slang-nodes/AssemblyFlags.ts | 3 +- src/slang-nodes/AssemblyFlagsDeclaration.ts | 3 +- src/slang-nodes/AssemblyStatement.ts | 3 +- src/slang-nodes/AssignmentExpression.ts | 3 +- src/slang-nodes/BitwiseAndExpression.ts | 3 +- src/slang-nodes/BitwiseOrExpression.ts | 3 +- src/slang-nodes/BitwiseXorExpression.ts | 3 +- src/slang-nodes/Block.ts | 3 +- src/slang-nodes/CallOptions.ts | 3 +- src/slang-nodes/CallOptionsExpression.ts | 3 +- src/slang-nodes/CatchClause.ts | 3 +- src/slang-nodes/CatchClauseError.ts | 3 +- src/slang-nodes/CatchClauses.ts | 3 +- src/slang-nodes/ComparisonExpression.ts | 3 +- src/slang-nodes/ConditionalExpression.ts | 8 +- src/slang-nodes/ConstantDefinition.ts | 3 +- src/slang-nodes/ConstructorAttribute.ts | 3 +- src/slang-nodes/ConstructorAttributes.ts | 3 +- src/slang-nodes/ConstructorDefinition.ts | 3 +- src/slang-nodes/ContractDefinition.ts | 3 +- src/slang-nodes/ContractMember.ts | 3 +- src/slang-nodes/ContractMembers.ts | 3 +- src/slang-nodes/DoWhileStatement.ts | 3 +- src/slang-nodes/ElseBranch.ts | 3 +- src/slang-nodes/EmitStatement.ts | 3 +- src/slang-nodes/EqualityExpression.ts | 3 +- src/slang-nodes/ErrorDefinition.ts | 3 +- src/slang-nodes/ErrorParameter.ts | 3 +- src/slang-nodes/ErrorParameters.ts | 3 +- src/slang-nodes/ErrorParametersDeclaration.ts | 3 +- src/slang-nodes/EventDefinition.ts | 3 +- src/slang-nodes/EventParameter.ts | 3 +- src/slang-nodes/EventParameters.ts | 3 +- src/slang-nodes/EventParametersDeclaration.ts | 3 +- src/slang-nodes/ExperimentalFeature.ts | 3 +- src/slang-nodes/ExperimentalPragma.ts | 3 +- src/slang-nodes/ExponentiationExpression.ts | 3 +- src/slang-nodes/Expression.ts | 3 +- src/slang-nodes/ExpressionStatement.ts | 3 +- src/slang-nodes/FallbackFunctionAttribute.ts | 3 +- src/slang-nodes/FallbackFunctionAttributes.ts | 3 +- src/slang-nodes/FallbackFunctionDefinition.ts | 3 +- src/slang-nodes/ForStatement.ts | 3 +- src/slang-nodes/ForStatementCondition.ts | 3 +- src/slang-nodes/ForStatementInitialization.ts | 3 +- src/slang-nodes/FunctionAttribute.ts | 3 +- src/slang-nodes/FunctionAttributes.ts | 3 +- src/slang-nodes/FunctionBody.ts | 3 +- src/slang-nodes/FunctionCallExpression.ts | 3 +- src/slang-nodes/FunctionDefinition.ts | 3 +- src/slang-nodes/FunctionType.ts | 3 +- src/slang-nodes/HexStringLiteral.ts | 3 +- src/slang-nodes/HexStringLiterals.ts | 3 +- src/slang-nodes/IfStatement.ts | 3 +- src/slang-nodes/ImportClause.ts | 3 +- src/slang-nodes/ImportDeconstruction.ts | 3 +- .../ImportDeconstructionSymbols.ts | 3 +- src/slang-nodes/ImportDirective.ts | 3 +- src/slang-nodes/IndexAccessEnd.ts | 3 +- src/slang-nodes/IndexAccessExpression.ts | 3 +- src/slang-nodes/InheritanceSpecifier.ts | 3 +- src/slang-nodes/InheritanceType.ts | 3 +- src/slang-nodes/InheritanceTypes.ts | 3 +- src/slang-nodes/InterfaceDefinition.ts | 3 +- src/slang-nodes/InterfaceMembers.ts | 3 +- src/slang-nodes/LibraryDefinition.ts | 3 +- src/slang-nodes/LibraryMembers.ts | 3 +- src/slang-nodes/MappingType.ts | 3 +- src/slang-nodes/MappingValue.ts | 3 +- src/slang-nodes/MemberAccessExpression.ts | 8 +- src/slang-nodes/ModifierDefinition.ts | 3 +- src/slang-nodes/ModifierInvocation.ts | 3 +- src/slang-nodes/MultiplicativeExpression.ts | 3 +- src/slang-nodes/NamedArgument.ts | 3 +- src/slang-nodes/NamedArgumentGroup.ts | 3 +- src/slang-nodes/NamedArguments.ts | 3 +- src/slang-nodes/NamedArgumentsDeclaration.ts | 3 +- src/slang-nodes/NamedImport.ts | 3 +- src/slang-nodes/NewExpression.ts | 3 +- src/slang-nodes/OrExpression.ts | 3 +- src/slang-nodes/Parameter.ts | 3 +- src/slang-nodes/Parameters.ts | 3 +- src/slang-nodes/ParametersDeclaration.ts | 3 +- src/slang-nodes/PathImport.ts | 3 +- src/slang-nodes/PositionalArguments.ts | 3 +- .../PositionalArgumentsDeclaration.ts | 3 +- src/slang-nodes/PostfixExpression.ts | 3 +- src/slang-nodes/Pragma.ts | 3 +- src/slang-nodes/PragmaDirective.ts | 3 +- src/slang-nodes/PrefixExpression.ts | 3 +- src/slang-nodes/ReceiveFunctionAttribute.ts | 3 +- src/slang-nodes/ReceiveFunctionAttributes.ts | 3 +- src/slang-nodes/ReceiveFunctionDefinition.ts | 3 +- src/slang-nodes/ReturnStatement.ts | 3 +- src/slang-nodes/ReturnsDeclaration.ts | 3 +- src/slang-nodes/RevertStatement.ts | 3 +- src/slang-nodes/ShiftExpression.ts | 3 +- src/slang-nodes/SourceUnit.ts | 3 +- src/slang-nodes/SourceUnitMember.ts | 3 +- src/slang-nodes/SourceUnitMembers.ts | 3 +- src/slang-nodes/StateVariableDefinition.ts | 3 +- .../StateVariableDefinitionValue.ts | 3 +- src/slang-nodes/Statement.ts | 3 +- src/slang-nodes/Statements.ts | 3 +- src/slang-nodes/StringExpression.ts | 3 +- src/slang-nodes/StringLiteral.ts | 3 +- src/slang-nodes/StringLiterals.ts | 3 +- src/slang-nodes/StructDefinition.ts | 3 +- src/slang-nodes/StructMember.ts | 3 +- src/slang-nodes/StructMembers.ts | 3 +- src/slang-nodes/TryStatement.ts | 3 +- src/slang-nodes/TupleDeconstructionElement.ts | 3 +- .../TupleDeconstructionElements.ts | 3 +- .../TupleDeconstructionStatement.ts | 3 +- src/slang-nodes/TupleExpression.ts | 3 +- src/slang-nodes/TupleMember.ts | 3 +- src/slang-nodes/TupleValue.ts | 3 +- src/slang-nodes/TupleValues.ts | 3 +- src/slang-nodes/TypeExpression.ts | 3 +- src/slang-nodes/TypeName.ts | 3 +- src/slang-nodes/TypedTupleMember.ts | 3 +- src/slang-nodes/UncheckedBlock.ts | 3 +- src/slang-nodes/UnicodeStringLiteral.ts | 3 +- src/slang-nodes/UnicodeStringLiterals.ts | 3 +- src/slang-nodes/UnnamedFunctionAttribute.ts | 3 +- src/slang-nodes/UnnamedFunctionAttributes.ts | 3 +- src/slang-nodes/UnnamedFunctionDefinition.ts | 3 +- src/slang-nodes/UsingDeconstructionSymbols.ts | 3 +- src/slang-nodes/UsingDirective.ts | 3 +- src/slang-nodes/UsingTarget.ts | 3 +- .../VariableDeclarationStatement.ts | 3 +- src/slang-nodes/VariableDeclarationType.ts | 3 +- src/slang-nodes/VariableDeclarationValue.ts | 3 +- src/slang-nodes/WhileStatement.ts | 3 +- src/slang-nodes/YulArguments.ts | 3 +- src/slang-nodes/YulBlock.ts | 3 +- src/slang-nodes/YulDefaultCase.ts | 3 +- src/slang-nodes/YulExpression.ts | 3 +- src/slang-nodes/YulForStatement.ts | 3 +- src/slang-nodes/YulFunctionCallExpression.ts | 3 +- src/slang-nodes/YulFunctionDefinition.ts | 3 +- src/slang-nodes/YulIfStatement.ts | 3 +- src/slang-nodes/YulLiteral.ts | 3 +- .../YulStackAssignmentStatement.ts | 3 +- src/slang-nodes/YulStatement.ts | 3 +- src/slang-nodes/YulStatements.ts | 3 +- src/slang-nodes/YulSwitchCase.ts | 3 +- src/slang-nodes/YulSwitchCases.ts | 3 +- src/slang-nodes/YulSwitchStatement.ts | 3 +- src/slang-nodes/YulValueCase.ts | 3 +- .../YulVariableAssignmentStatement.ts | 3 +- .../YulVariableDeclarationStatement.ts | 3 +- .../YulVariableDeclarationValue.ts | 3 +- src/slang-nodes/index.d.ts | 719 ++++++++++++------ .../create-binary-operation-printer.ts | 8 +- src/slang-printers/print-binary-operation.ts | 2 +- src/slang-printers/print-comments.ts | 2 +- .../print-comparison-operation.ts | 2 +- src/slang-printers/print-function.ts | 5 +- src/slang-printers/print-logical-operation.ts | 2 +- .../print-preserving-empty-lines.ts | 3 +- src/slang-printers/print-string.ts | 2 +- src/slang-utils/backward-compatibility.ts | 3 +- src/slang-utils/create-kind-check-function.ts | 3 +- src/slang-utils/is-binary-operation.ts | 2 +- src/slang-utils/is-comment.ts | 3 +- src/slang-utils/loc.ts | 3 +- src/slang-utils/metadata.ts | 3 +- src/slang-utils/types.d.ts | 21 +- src/slangParser.ts | 2 +- src/slangPrinter.ts | 3 +- src/types.d.ts | 291 +------ tests/config/run-format-test.js | 2 +- tests/format/AssemblyV0.4.26/Assembly.sol | 2 +- .../__snapshots__/format.test.js.snap | 8 +- tests/format/AssemblyV0.4.26/format.test.js | 2 +- 188 files changed, 878 insertions(+), 720 deletions(-) diff --git a/src/index.ts b/src/index.ts index a33caecae..d060762c2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,7 +16,8 @@ import type { RequiredOptions, SupportLanguage } from 'prettier'; -import type { AstNode, Comment } from './types'; +import type { AstNode } from './slang-nodes'; +import type { Comment } from './types'; const parserName = 'slang'; const astFormat = 'slang-ast'; diff --git a/src/slang-comments/handler.ts b/src/slang-comments/handler.ts index efaecb8cd..bb66c7685 100644 --- a/src/slang-comments/handler.ts +++ b/src/slang-comments/handler.ts @@ -1,7 +1,8 @@ import handlers from './handlers/index.js'; import type { ParserOptions } from 'prettier'; -import type { AstNode, Comment } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { Comment } from '../types'; function ownLine( comment: Comment, diff --git a/src/slang-comments/handlers/add-hub-node-first-comment.ts b/src/slang-comments/handlers/add-hub-node-first-comment.ts index 1a133d0d9..e6f34ffe2 100644 --- a/src/slang-comments/handlers/add-hub-node-first-comment.ts +++ b/src/slang-comments/handlers/add-hub-node-first-comment.ts @@ -1,6 +1,7 @@ import { util } from 'prettier'; -import type { Comment, HubNode } from '../../types'; +import type { HubNode } from '../../slang-nodes'; +import type { Comment } from '../../types'; const { addDanglingComment, addLeadingComment } = util; diff --git a/src/slang-comments/handlers/add-hub-node-last-comment.ts b/src/slang-comments/handlers/add-hub-node-last-comment.ts index 0f34e74af..45f3f11c3 100644 --- a/src/slang-comments/handlers/add-hub-node-last-comment.ts +++ b/src/slang-comments/handlers/add-hub-node-last-comment.ts @@ -1,6 +1,7 @@ import { util } from 'prettier'; -import type { Comment, HubNode } from '../../types'; +import type { HubNode } from '../../slang-nodes'; +import type { Comment } from '../../types'; const { addDanglingComment, addTrailingComment } = util; diff --git a/src/slang-comments/handlers/types.d.ts b/src/slang-comments/handlers/types.d.ts index 79d60de5e..7edcdb2c4 100644 --- a/src/slang-comments/handlers/types.d.ts +++ b/src/slang-comments/handlers/types.d.ts @@ -1,4 +1,5 @@ -import type { Comment, StrictAstNode } from '../../types'; +import type { StrictAstNode } from '../../slang-nodes'; +import type { Comment } from '../../types'; interface HandlerParams { text: string; diff --git a/src/slang-comments/printer.ts b/src/slang-comments/printer.ts index c25cb2547..dca423de2 100644 --- a/src/slang-comments/printer.ts +++ b/src/slang-comments/printer.ts @@ -2,7 +2,8 @@ import { doc } from 'prettier'; import { isBlockComment, isLineComment } from '../slang-utils/is-comment.js'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, Comment } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { Comment } from '../types'; const { hardline, join, literalline } = doc.builders; diff --git a/src/slang-nodes/AdditiveExpression.ts b/src/slang-nodes/AdditiveExpression.ts index 73038680b..b25376ab5 100644 --- a/src/slang-nodes/AdditiveExpression.ts +++ b/src/slang-nodes/AdditiveExpression.ts @@ -6,7 +6,8 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const tryToHug = createHugFunction(['%']); diff --git a/src/slang-nodes/AndExpression.ts b/src/slang-nodes/AndExpression.ts index 2f90afd70..5b7cd6004 100644 --- a/src/slang-nodes/AndExpression.ts +++ b/src/slang-nodes/AndExpression.ts @@ -5,7 +5,8 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class AndExpression implements SlangNode { readonly kind = NonterminalKind.AndExpression; diff --git a/src/slang-nodes/ArgumentsDeclaration.ts b/src/slang-nodes/ArgumentsDeclaration.ts index 9706b8b1e..1f4afad0b 100644 --- a/src/slang-nodes/ArgumentsDeclaration.ts +++ b/src/slang-nodes/ArgumentsDeclaration.ts @@ -5,7 +5,8 @@ import { NamedArgumentsDeclaration } from './NamedArgumentsDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class ArgumentsDeclaration implements SlangNode { readonly kind = NonterminalKind.ArgumentsDeclaration; diff --git a/src/slang-nodes/ArrayExpression.ts b/src/slang-nodes/ArrayExpression.ts index 166ba3ac2..f7d8d584a 100644 --- a/src/slang-nodes/ArrayExpression.ts +++ b/src/slang-nodes/ArrayExpression.ts @@ -5,7 +5,8 @@ import { ArrayValues } from './ArrayValues.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { group } = doc.builders; diff --git a/src/slang-nodes/ArrayTypeName.ts b/src/slang-nodes/ArrayTypeName.ts index e04fc9664..88e71f9f2 100644 --- a/src/slang-nodes/ArrayTypeName.ts +++ b/src/slang-nodes/ArrayTypeName.ts @@ -5,7 +5,8 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class ArrayTypeName implements SlangNode { readonly kind = NonterminalKind.ArrayTypeName; diff --git a/src/slang-nodes/ArrayValues.ts b/src/slang-nodes/ArrayValues.ts index 683e46161..052efe8e8 100644 --- a/src/slang-nodes/ArrayValues.ts +++ b/src/slang-nodes/ArrayValues.ts @@ -5,7 +5,8 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class ArrayValues implements SlangNode { readonly kind = NonterminalKind.ArrayValues; diff --git a/src/slang-nodes/AssemblyFlags.ts b/src/slang-nodes/AssemblyFlags.ts index 18a409d15..caed68184 100644 --- a/src/slang-nodes/AssemblyFlags.ts +++ b/src/slang-nodes/AssemblyFlags.ts @@ -5,7 +5,8 @@ import { StringLiteral } from './StringLiteral.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class AssemblyFlags implements SlangNode { readonly kind = NonterminalKind.AssemblyFlags; diff --git a/src/slang-nodes/AssemblyFlagsDeclaration.ts b/src/slang-nodes/AssemblyFlagsDeclaration.ts index d143a6c3c..46dc52823 100644 --- a/src/slang-nodes/AssemblyFlagsDeclaration.ts +++ b/src/slang-nodes/AssemblyFlagsDeclaration.ts @@ -4,7 +4,8 @@ import { AssemblyFlags } from './AssemblyFlags.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class AssemblyFlagsDeclaration implements SlangNode { readonly kind = NonterminalKind.AssemblyFlagsDeclaration; diff --git a/src/slang-nodes/AssemblyStatement.ts b/src/slang-nodes/AssemblyStatement.ts index 827beb758..d162f60c6 100644 --- a/src/slang-nodes/AssemblyStatement.ts +++ b/src/slang-nodes/AssemblyStatement.ts @@ -6,7 +6,8 @@ import { YulBlock } from './YulBlock.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class AssemblyStatement implements SlangNode { readonly kind = NonterminalKind.AssemblyStatement; diff --git a/src/slang-nodes/AssignmentExpression.ts b/src/slang-nodes/AssignmentExpression.ts index 72e2afba8..6245f0234 100644 --- a/src/slang-nodes/AssignmentExpression.ts +++ b/src/slang-nodes/AssignmentExpression.ts @@ -6,7 +6,8 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { group, indent, line } = doc.builders; diff --git a/src/slang-nodes/BitwiseAndExpression.ts b/src/slang-nodes/BitwiseAndExpression.ts index 69ca5cfe7..f5e8d2ecb 100644 --- a/src/slang-nodes/BitwiseAndExpression.ts +++ b/src/slang-nodes/BitwiseAndExpression.ts @@ -6,7 +6,8 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const tryToHug = createHugFunction(['+', '-', '*', '/', '**', '<<', '>>']); diff --git a/src/slang-nodes/BitwiseOrExpression.ts b/src/slang-nodes/BitwiseOrExpression.ts index f8186451f..4bb639c19 100644 --- a/src/slang-nodes/BitwiseOrExpression.ts +++ b/src/slang-nodes/BitwiseOrExpression.ts @@ -6,7 +6,8 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const tryToHug = createHugFunction([ '+', diff --git a/src/slang-nodes/BitwiseXorExpression.ts b/src/slang-nodes/BitwiseXorExpression.ts index a8dfd5040..024eeb701 100644 --- a/src/slang-nodes/BitwiseXorExpression.ts +++ b/src/slang-nodes/BitwiseXorExpression.ts @@ -6,7 +6,8 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const tryToHug = createHugFunction(['+', '-', '*', '/', '**', '<<', '>>', '&']); diff --git a/src/slang-nodes/Block.ts b/src/slang-nodes/Block.ts index 2c0c2aac0..0af6065e7 100644 --- a/src/slang-nodes/Block.ts +++ b/src/slang-nodes/Block.ts @@ -4,7 +4,8 @@ import { Statements } from './Statements.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class Block implements SlangNode { readonly kind = NonterminalKind.Block; diff --git a/src/slang-nodes/CallOptions.ts b/src/slang-nodes/CallOptions.ts index b927af17a..bfca3e7ed 100644 --- a/src/slang-nodes/CallOptions.ts +++ b/src/slang-nodes/CallOptions.ts @@ -6,7 +6,8 @@ import { NamedArgument } from './NamedArgument.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { line, softline } = doc.builders; diff --git a/src/slang-nodes/CallOptionsExpression.ts b/src/slang-nodes/CallOptionsExpression.ts index 5e3157345..3fa5d005b 100644 --- a/src/slang-nodes/CallOptionsExpression.ts +++ b/src/slang-nodes/CallOptionsExpression.ts @@ -5,7 +5,8 @@ import { CallOptions } from './CallOptions.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class CallOptionsExpression implements SlangNode { readonly kind = NonterminalKind.CallOptionsExpression; diff --git a/src/slang-nodes/CatchClause.ts b/src/slang-nodes/CatchClause.ts index 4914c9479..0cc558c4d 100644 --- a/src/slang-nodes/CatchClause.ts +++ b/src/slang-nodes/CatchClause.ts @@ -5,7 +5,8 @@ import { Block } from './Block.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class CatchClause implements SlangNode { readonly kind = NonterminalKind.CatchClause; diff --git a/src/slang-nodes/CatchClauseError.ts b/src/slang-nodes/CatchClauseError.ts index 772e6b529..c3c2ce48e 100644 --- a/src/slang-nodes/CatchClauseError.ts +++ b/src/slang-nodes/CatchClauseError.ts @@ -5,7 +5,8 @@ import { ParametersDeclaration } from './ParametersDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { group } = doc.builders; diff --git a/src/slang-nodes/CatchClauses.ts b/src/slang-nodes/CatchClauses.ts index fc0996c12..5178712dc 100644 --- a/src/slang-nodes/CatchClauses.ts +++ b/src/slang-nodes/CatchClauses.ts @@ -5,7 +5,8 @@ import { CatchClause } from './CatchClause.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { join } = doc.builders; diff --git a/src/slang-nodes/ComparisonExpression.ts b/src/slang-nodes/ComparisonExpression.ts index 733e6b9b7..b6d893aee 100644 --- a/src/slang-nodes/ComparisonExpression.ts +++ b/src/slang-nodes/ComparisonExpression.ts @@ -5,7 +5,8 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class ComparisonExpression implements SlangNode { readonly kind = NonterminalKind.ComparisonExpression; diff --git a/src/slang-nodes/ConditionalExpression.ts b/src/slang-nodes/ConditionalExpression.ts index e94558929..64c1b9960 100644 --- a/src/slang-nodes/ConditionalExpression.ts +++ b/src/slang-nodes/ConditionalExpression.ts @@ -7,12 +7,8 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { - AstNode, - PrintFunction, - SlangNode, - StrictAstNode -} from '../types'; +import type { AstNode, StrictAstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { group, hardline, ifBreak, indent, line, softline } = doc.builders; diff --git a/src/slang-nodes/ConstantDefinition.ts b/src/slang-nodes/ConstantDefinition.ts index 86e9d1742..d730717ed 100644 --- a/src/slang-nodes/ConstantDefinition.ts +++ b/src/slang-nodes/ConstantDefinition.ts @@ -5,7 +5,8 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { /*AstPath,*/ Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { SlangNode } from '../types'; export class ConstantDefinition implements SlangNode { readonly kind = NonterminalKind.ConstantDefinition; diff --git a/src/slang-nodes/ConstructorAttribute.ts b/src/slang-nodes/ConstructorAttribute.ts index 027730efd..61ecfdcae 100644 --- a/src/slang-nodes/ConstructorAttribute.ts +++ b/src/slang-nodes/ConstructorAttribute.ts @@ -5,7 +5,8 @@ import { ModifierInvocation } from './ModifierInvocation.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class ConstructorAttribute implements SlangNode { readonly kind = NonterminalKind.ConstructorAttribute; diff --git a/src/slang-nodes/ConstructorAttributes.ts b/src/slang-nodes/ConstructorAttributes.ts index 268aaa014..a17eb1184 100644 --- a/src/slang-nodes/ConstructorAttributes.ts +++ b/src/slang-nodes/ConstructorAttributes.ts @@ -6,7 +6,8 @@ import { ConstructorAttribute } from './ConstructorAttribute.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { line } = doc.builders; diff --git a/src/slang-nodes/ConstructorDefinition.ts b/src/slang-nodes/ConstructorDefinition.ts index 9545d108f..1e0c674fa 100644 --- a/src/slang-nodes/ConstructorDefinition.ts +++ b/src/slang-nodes/ConstructorDefinition.ts @@ -7,7 +7,8 @@ import { Block } from './Block.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class ConstructorDefinition implements SlangNode { readonly kind = NonterminalKind.ConstructorDefinition; diff --git a/src/slang-nodes/ContractDefinition.ts b/src/slang-nodes/ContractDefinition.ts index 416b6ccb0..2587c3b26 100644 --- a/src/slang-nodes/ContractDefinition.ts +++ b/src/slang-nodes/ContractDefinition.ts @@ -8,7 +8,8 @@ import { ContractMembers } from './ContractMembers.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { group, line } = doc.builders; diff --git a/src/slang-nodes/ContractMember.ts b/src/slang-nodes/ContractMember.ts index 08ac4940c..fcd76624b 100644 --- a/src/slang-nodes/ContractMember.ts +++ b/src/slang-nodes/ContractMember.ts @@ -16,7 +16,8 @@ import { UserDefinedValueTypeDefinition } from './UserDefinedValueTypeDefinition import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class ContractMember implements SlangNode { readonly kind = NonterminalKind.ContractMember; diff --git a/src/slang-nodes/ContractMembers.ts b/src/slang-nodes/ContractMembers.ts index e5cd1f44b..2ea431de0 100644 --- a/src/slang-nodes/ContractMembers.ts +++ b/src/slang-nodes/ContractMembers.ts @@ -8,7 +8,8 @@ import { ContractMember } from './ContractMember.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { hardline } = doc.builders; diff --git a/src/slang-nodes/DoWhileStatement.ts b/src/slang-nodes/DoWhileStatement.ts index 818dadebb..5b5781bff 100644 --- a/src/slang-nodes/DoWhileStatement.ts +++ b/src/slang-nodes/DoWhileStatement.ts @@ -7,7 +7,8 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { group, indent, line } = doc.builders; diff --git a/src/slang-nodes/ElseBranch.ts b/src/slang-nodes/ElseBranch.ts index 934c74c91..b621a083c 100644 --- a/src/slang-nodes/ElseBranch.ts +++ b/src/slang-nodes/ElseBranch.ts @@ -6,7 +6,8 @@ import { Statement } from './Statement.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { group, indent, line } = doc.builders; diff --git a/src/slang-nodes/EmitStatement.ts b/src/slang-nodes/EmitStatement.ts index 2182106ee..48f8dfc77 100644 --- a/src/slang-nodes/EmitStatement.ts +++ b/src/slang-nodes/EmitStatement.ts @@ -5,7 +5,8 @@ import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class EmitStatement implements SlangNode { readonly kind = NonterminalKind.EmitStatement; diff --git a/src/slang-nodes/EqualityExpression.ts b/src/slang-nodes/EqualityExpression.ts index 99f15a43a..f08d4471b 100644 --- a/src/slang-nodes/EqualityExpression.ts +++ b/src/slang-nodes/EqualityExpression.ts @@ -5,7 +5,8 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class EqualityExpression implements SlangNode { readonly kind = NonterminalKind.EqualityExpression; diff --git a/src/slang-nodes/ErrorDefinition.ts b/src/slang-nodes/ErrorDefinition.ts index 0e0e03993..86a5a32a0 100644 --- a/src/slang-nodes/ErrorDefinition.ts +++ b/src/slang-nodes/ErrorDefinition.ts @@ -4,7 +4,8 @@ import { ErrorParametersDeclaration } from './ErrorParametersDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class ErrorDefinition implements SlangNode { readonly kind = NonterminalKind.ErrorDefinition; diff --git a/src/slang-nodes/ErrorParameter.ts b/src/slang-nodes/ErrorParameter.ts index a30da22e6..05d7f448c 100644 --- a/src/slang-nodes/ErrorParameter.ts +++ b/src/slang-nodes/ErrorParameter.ts @@ -4,7 +4,8 @@ import { TypeName } from './TypeName.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class ErrorParameter implements SlangNode { readonly kind = NonterminalKind.ErrorParameter; diff --git a/src/slang-nodes/ErrorParameters.ts b/src/slang-nodes/ErrorParameters.ts index 4e5918f91..2e3613756 100644 --- a/src/slang-nodes/ErrorParameters.ts +++ b/src/slang-nodes/ErrorParameters.ts @@ -5,7 +5,8 @@ import { ErrorParameter } from './ErrorParameter.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class ErrorParameters implements SlangNode { readonly kind = NonterminalKind.ErrorParameters; diff --git a/src/slang-nodes/ErrorParametersDeclaration.ts b/src/slang-nodes/ErrorParametersDeclaration.ts index 6d0472f63..c82b2cefe 100644 --- a/src/slang-nodes/ErrorParametersDeclaration.ts +++ b/src/slang-nodes/ErrorParametersDeclaration.ts @@ -4,7 +4,8 @@ import { ErrorParameters } from './ErrorParameters.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class ErrorParametersDeclaration implements SlangNode { readonly kind = NonterminalKind.ErrorParametersDeclaration; diff --git a/src/slang-nodes/EventDefinition.ts b/src/slang-nodes/EventDefinition.ts index aad2d002e..de808af1b 100644 --- a/src/slang-nodes/EventDefinition.ts +++ b/src/slang-nodes/EventDefinition.ts @@ -4,7 +4,8 @@ import { EventParametersDeclaration } from './EventParametersDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class EventDefinition implements SlangNode { readonly kind = NonterminalKind.EventDefinition; diff --git a/src/slang-nodes/EventParameter.ts b/src/slang-nodes/EventParameter.ts index ea8399b51..90ab00a9a 100644 --- a/src/slang-nodes/EventParameter.ts +++ b/src/slang-nodes/EventParameter.ts @@ -4,7 +4,8 @@ import { TypeName } from './TypeName.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class EventParameter implements SlangNode { readonly kind = NonterminalKind.EventParameter; diff --git a/src/slang-nodes/EventParameters.ts b/src/slang-nodes/EventParameters.ts index d82ad61f6..9ae3f36b7 100644 --- a/src/slang-nodes/EventParameters.ts +++ b/src/slang-nodes/EventParameters.ts @@ -5,7 +5,8 @@ import { EventParameter } from './EventParameter.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class EventParameters implements SlangNode { readonly kind = NonterminalKind.EventParameters; diff --git a/src/slang-nodes/EventParametersDeclaration.ts b/src/slang-nodes/EventParametersDeclaration.ts index 94b62ff2b..3cba0a19d 100644 --- a/src/slang-nodes/EventParametersDeclaration.ts +++ b/src/slang-nodes/EventParametersDeclaration.ts @@ -4,7 +4,8 @@ import { EventParameters } from './EventParameters.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class EventParametersDeclaration implements SlangNode { readonly kind = NonterminalKind.EventParametersDeclaration; diff --git a/src/slang-nodes/ExperimentalFeature.ts b/src/slang-nodes/ExperimentalFeature.ts index 4de012c99..b2945f64f 100644 --- a/src/slang-nodes/ExperimentalFeature.ts +++ b/src/slang-nodes/ExperimentalFeature.ts @@ -5,7 +5,8 @@ import { StringLiteral } from './StringLiteral.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class ExperimentalFeature implements SlangNode { readonly kind = NonterminalKind.ExperimentalFeature; diff --git a/src/slang-nodes/ExperimentalPragma.ts b/src/slang-nodes/ExperimentalPragma.ts index 5f3962ba6..1bcf2a42d 100644 --- a/src/slang-nodes/ExperimentalPragma.ts +++ b/src/slang-nodes/ExperimentalPragma.ts @@ -4,7 +4,8 @@ import { ExperimentalFeature } from './ExperimentalFeature.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class ExperimentalPragma implements SlangNode { readonly kind = NonterminalKind.ExperimentalPragma; diff --git a/src/slang-nodes/ExponentiationExpression.ts b/src/slang-nodes/ExponentiationExpression.ts index 44b2c64c5..659fc0ecd 100644 --- a/src/slang-nodes/ExponentiationExpression.ts +++ b/src/slang-nodes/ExponentiationExpression.ts @@ -12,7 +12,8 @@ import { TupleValue } from './TupleValue.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { group, indent } = doc.builders; diff --git a/src/slang-nodes/Expression.ts b/src/slang-nodes/Expression.ts index f96a6dac2..d08892c61 100644 --- a/src/slang-nodes/Expression.ts +++ b/src/slang-nodes/Expression.ts @@ -31,7 +31,8 @@ import { ElementaryType } from './ElementaryType.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class Expression implements SlangNode { readonly kind = NonterminalKind.Expression; diff --git a/src/slang-nodes/ExpressionStatement.ts b/src/slang-nodes/ExpressionStatement.ts index f25941d79..5393edc38 100644 --- a/src/slang-nodes/ExpressionStatement.ts +++ b/src/slang-nodes/ExpressionStatement.ts @@ -4,7 +4,8 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class ExpressionStatement implements SlangNode { readonly kind = NonterminalKind.ExpressionStatement; diff --git a/src/slang-nodes/FallbackFunctionAttribute.ts b/src/slang-nodes/FallbackFunctionAttribute.ts index 44ba1a7ea..3b7ca0b39 100644 --- a/src/slang-nodes/FallbackFunctionAttribute.ts +++ b/src/slang-nodes/FallbackFunctionAttribute.ts @@ -6,7 +6,8 @@ import { OverrideSpecifier } from './OverrideSpecifier.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class FallbackFunctionAttribute implements SlangNode { readonly kind = NonterminalKind.FallbackFunctionAttribute; diff --git a/src/slang-nodes/FallbackFunctionAttributes.ts b/src/slang-nodes/FallbackFunctionAttributes.ts index 5f6c8e4c7..9e4cb5c2c 100644 --- a/src/slang-nodes/FallbackFunctionAttributes.ts +++ b/src/slang-nodes/FallbackFunctionAttributes.ts @@ -6,7 +6,8 @@ import { FallbackFunctionAttribute } from './FallbackFunctionAttribute.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { line } = doc.builders; diff --git a/src/slang-nodes/FallbackFunctionDefinition.ts b/src/slang-nodes/FallbackFunctionDefinition.ts index 65af63762..ec69f3985 100644 --- a/src/slang-nodes/FallbackFunctionDefinition.ts +++ b/src/slang-nodes/FallbackFunctionDefinition.ts @@ -8,7 +8,8 @@ import { FunctionBody } from './FunctionBody.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class FallbackFunctionDefinition implements SlangNode { readonly kind = NonterminalKind.FallbackFunctionDefinition; diff --git a/src/slang-nodes/ForStatement.ts b/src/slang-nodes/ForStatement.ts index 9bad7ce6c..baaae3e4a 100644 --- a/src/slang-nodes/ForStatement.ts +++ b/src/slang-nodes/ForStatement.ts @@ -9,7 +9,8 @@ import { Statement } from './Statement.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { group, indent, line } = doc.builders; diff --git a/src/slang-nodes/ForStatementCondition.ts b/src/slang-nodes/ForStatementCondition.ts index 839924799..ec5608a0b 100644 --- a/src/slang-nodes/ForStatementCondition.ts +++ b/src/slang-nodes/ForStatementCondition.ts @@ -5,7 +5,8 @@ import { ExpressionStatement } from './ExpressionStatement.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class ForStatementCondition implements SlangNode { readonly kind = NonterminalKind.ForStatementCondition; diff --git a/src/slang-nodes/ForStatementInitialization.ts b/src/slang-nodes/ForStatementInitialization.ts index 3cee0c370..63f1b111f 100644 --- a/src/slang-nodes/ForStatementInitialization.ts +++ b/src/slang-nodes/ForStatementInitialization.ts @@ -7,7 +7,8 @@ import { TupleDeconstructionStatement } from './TupleDeconstructionStatement.js' import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class ForStatementInitialization implements SlangNode { readonly kind = NonterminalKind.ForStatementInitialization; diff --git a/src/slang-nodes/FunctionAttribute.ts b/src/slang-nodes/FunctionAttribute.ts index 4b4b44f1f..ff81dbf34 100644 --- a/src/slang-nodes/FunctionAttribute.ts +++ b/src/slang-nodes/FunctionAttribute.ts @@ -6,7 +6,8 @@ import { OverrideSpecifier } from './OverrideSpecifier.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class FunctionAttribute implements SlangNode { readonly kind = NonterminalKind.FunctionAttribute; diff --git a/src/slang-nodes/FunctionAttributes.ts b/src/slang-nodes/FunctionAttributes.ts index 1fa7d0b38..4096901b9 100644 --- a/src/slang-nodes/FunctionAttributes.ts +++ b/src/slang-nodes/FunctionAttributes.ts @@ -6,7 +6,8 @@ import { FunctionAttribute } from './FunctionAttribute.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { line } = doc.builders; diff --git a/src/slang-nodes/FunctionBody.ts b/src/slang-nodes/FunctionBody.ts index 5153da2d0..21a73fa3a 100644 --- a/src/slang-nodes/FunctionBody.ts +++ b/src/slang-nodes/FunctionBody.ts @@ -5,7 +5,8 @@ import { Block } from './Block.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class FunctionBody implements SlangNode { readonly kind = NonterminalKind.FunctionBody; diff --git a/src/slang-nodes/FunctionCallExpression.ts b/src/slang-nodes/FunctionCallExpression.ts index f30186fef..62c7dd539 100644 --- a/src/slang-nodes/FunctionCallExpression.ts +++ b/src/slang-nodes/FunctionCallExpression.ts @@ -7,7 +7,8 @@ import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { group, indentIfBreak, label } = doc.builders; diff --git a/src/slang-nodes/FunctionDefinition.ts b/src/slang-nodes/FunctionDefinition.ts index a4d1d0f83..d792dcd64 100644 --- a/src/slang-nodes/FunctionDefinition.ts +++ b/src/slang-nodes/FunctionDefinition.ts @@ -11,7 +11,8 @@ import { FunctionBody } from './FunctionBody.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class FunctionDefinition implements SlangNode { readonly kind = NonterminalKind.FunctionDefinition; diff --git a/src/slang-nodes/FunctionType.ts b/src/slang-nodes/FunctionType.ts index a3ed0e0e6..38bcb8d4d 100644 --- a/src/slang-nodes/FunctionType.ts +++ b/src/slang-nodes/FunctionType.ts @@ -7,7 +7,8 @@ import { ReturnsDeclaration } from './ReturnsDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class FunctionType implements SlangNode { readonly kind = NonterminalKind.FunctionType; diff --git a/src/slang-nodes/HexStringLiteral.ts b/src/slang-nodes/HexStringLiteral.ts index 29001ea32..ade0856b8 100644 --- a/src/slang-nodes/HexStringLiteral.ts +++ b/src/slang-nodes/HexStringLiteral.ts @@ -4,7 +4,8 @@ import { getNodeMetadata } from '../slang-utils/metadata.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { SlangNode } from '../types'; export class HexStringLiteral implements SlangNode { readonly kind = NonterminalKind.HexStringLiteral; diff --git a/src/slang-nodes/HexStringLiterals.ts b/src/slang-nodes/HexStringLiterals.ts index ab927d5cd..63e85dc13 100644 --- a/src/slang-nodes/HexStringLiterals.ts +++ b/src/slang-nodes/HexStringLiterals.ts @@ -5,7 +5,8 @@ import { HexStringLiteral } from './HexStringLiteral.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { join, hardline } = doc.builders; diff --git a/src/slang-nodes/IfStatement.ts b/src/slang-nodes/IfStatement.ts index 978e3dc25..0ac5ad73e 100644 --- a/src/slang-nodes/IfStatement.ts +++ b/src/slang-nodes/IfStatement.ts @@ -8,7 +8,8 @@ import { ElseBranch } from './ElseBranch.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { group, hardline, indent, line } = doc.builders; diff --git a/src/slang-nodes/ImportClause.ts b/src/slang-nodes/ImportClause.ts index c331fc391..c35ad307e 100644 --- a/src/slang-nodes/ImportClause.ts +++ b/src/slang-nodes/ImportClause.ts @@ -6,7 +6,8 @@ import { ImportDeconstruction } from './ImportDeconstruction.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class ImportClause implements SlangNode { readonly kind = NonterminalKind.ImportClause; diff --git a/src/slang-nodes/ImportDeconstruction.ts b/src/slang-nodes/ImportDeconstruction.ts index e5195fd34..44cd553b9 100644 --- a/src/slang-nodes/ImportDeconstruction.ts +++ b/src/slang-nodes/ImportDeconstruction.ts @@ -5,7 +5,8 @@ import { StringLiteral } from './StringLiteral.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class ImportDeconstruction implements SlangNode { readonly kind = NonterminalKind.ImportDeconstruction; diff --git a/src/slang-nodes/ImportDeconstructionSymbols.ts b/src/slang-nodes/ImportDeconstructionSymbols.ts index e1f5ec8ac..687c78517 100644 --- a/src/slang-nodes/ImportDeconstructionSymbols.ts +++ b/src/slang-nodes/ImportDeconstructionSymbols.ts @@ -8,7 +8,8 @@ import { ImportDeconstructionSymbol } from './ImportDeconstructionSymbol.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { line, softline } = doc.builders; diff --git a/src/slang-nodes/ImportDirective.ts b/src/slang-nodes/ImportDirective.ts index 874c07f79..5422a6d1d 100644 --- a/src/slang-nodes/ImportDirective.ts +++ b/src/slang-nodes/ImportDirective.ts @@ -4,7 +4,8 @@ import { ImportClause } from './ImportClause.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class ImportDirective implements SlangNode { readonly kind = NonterminalKind.ImportDirective; diff --git a/src/slang-nodes/IndexAccessEnd.ts b/src/slang-nodes/IndexAccessEnd.ts index 3713680c7..e09f39a84 100644 --- a/src/slang-nodes/IndexAccessEnd.ts +++ b/src/slang-nodes/IndexAccessEnd.ts @@ -4,7 +4,8 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class IndexAccessEnd implements SlangNode { readonly kind = NonterminalKind.IndexAccessEnd; diff --git a/src/slang-nodes/IndexAccessExpression.ts b/src/slang-nodes/IndexAccessExpression.ts index 3aefccdf6..3359b660e 100644 --- a/src/slang-nodes/IndexAccessExpression.ts +++ b/src/slang-nodes/IndexAccessExpression.ts @@ -7,7 +7,8 @@ import { IndexAccessEnd } from './IndexAccessEnd.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { group, indent, indentIfBreak, label, softline } = doc.builders; diff --git a/src/slang-nodes/InheritanceSpecifier.ts b/src/slang-nodes/InheritanceSpecifier.ts index 2079cab4e..3aecffa56 100644 --- a/src/slang-nodes/InheritanceSpecifier.ts +++ b/src/slang-nodes/InheritanceSpecifier.ts @@ -4,7 +4,8 @@ import { InheritanceTypes } from './InheritanceTypes.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class InheritanceSpecifier implements SlangNode { readonly kind = NonterminalKind.InheritanceSpecifier; diff --git a/src/slang-nodes/InheritanceType.ts b/src/slang-nodes/InheritanceType.ts index 601ad5711..a0fb448e4 100644 --- a/src/slang-nodes/InheritanceType.ts +++ b/src/slang-nodes/InheritanceType.ts @@ -5,7 +5,8 @@ import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class InheritanceType implements SlangNode { readonly kind = NonterminalKind.InheritanceType; diff --git a/src/slang-nodes/InheritanceTypes.ts b/src/slang-nodes/InheritanceTypes.ts index 27c366970..ff4176921 100644 --- a/src/slang-nodes/InheritanceTypes.ts +++ b/src/slang-nodes/InheritanceTypes.ts @@ -6,7 +6,8 @@ import { InheritanceType } from './InheritanceType.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { line } = doc.builders; diff --git a/src/slang-nodes/InterfaceDefinition.ts b/src/slang-nodes/InterfaceDefinition.ts index 163e91538..be147d4b4 100644 --- a/src/slang-nodes/InterfaceDefinition.ts +++ b/src/slang-nodes/InterfaceDefinition.ts @@ -6,7 +6,8 @@ import { InterfaceMembers } from './InterfaceMembers.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { group, line } = doc.builders; diff --git a/src/slang-nodes/InterfaceMembers.ts b/src/slang-nodes/InterfaceMembers.ts index ccb716578..04647a41a 100644 --- a/src/slang-nodes/InterfaceMembers.ts +++ b/src/slang-nodes/InterfaceMembers.ts @@ -7,7 +7,8 @@ import { ContractMember } from './ContractMember.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { hardline } = doc.builders; diff --git a/src/slang-nodes/LibraryDefinition.ts b/src/slang-nodes/LibraryDefinition.ts index f9da35a02..2647feaed 100644 --- a/src/slang-nodes/LibraryDefinition.ts +++ b/src/slang-nodes/LibraryDefinition.ts @@ -5,7 +5,8 @@ import { LibraryMembers } from './LibraryMembers.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { group, line } = doc.builders; diff --git a/src/slang-nodes/LibraryMembers.ts b/src/slang-nodes/LibraryMembers.ts index 869cd1848..0a758bb95 100644 --- a/src/slang-nodes/LibraryMembers.ts +++ b/src/slang-nodes/LibraryMembers.ts @@ -7,7 +7,8 @@ import { ContractMember } from './ContractMember.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { hardline } = doc.builders; diff --git a/src/slang-nodes/MappingType.ts b/src/slang-nodes/MappingType.ts index 1d7bee9a7..b1a8649d9 100644 --- a/src/slang-nodes/MappingType.ts +++ b/src/slang-nodes/MappingType.ts @@ -5,7 +5,8 @@ import { MappingValue } from './MappingValue.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class MappingType implements SlangNode { readonly kind = NonterminalKind.MappingType; diff --git a/src/slang-nodes/MappingValue.ts b/src/slang-nodes/MappingValue.ts index 2c91357e7..cfeed5355 100644 --- a/src/slang-nodes/MappingValue.ts +++ b/src/slang-nodes/MappingValue.ts @@ -4,7 +4,8 @@ import { TypeName } from './TypeName.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class MappingValue implements SlangNode { readonly kind = NonterminalKind.MappingValue; diff --git a/src/slang-nodes/MemberAccessExpression.ts b/src/slang-nodes/MemberAccessExpression.ts index 0114c9998..67412517b 100644 --- a/src/slang-nodes/MemberAccessExpression.ts +++ b/src/slang-nodes/MemberAccessExpression.ts @@ -8,12 +8,8 @@ import { MemberAccess } from './MemberAccess.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { - AstNode, - PrintFunction, - SlangNode, - StrictAstNode -} from '../types'; +import type { AstNode, StrictAstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { group, indent, label, softline } = doc.builders; diff --git a/src/slang-nodes/ModifierDefinition.ts b/src/slang-nodes/ModifierDefinition.ts index 29a882c8c..545483825 100644 --- a/src/slang-nodes/ModifierDefinition.ts +++ b/src/slang-nodes/ModifierDefinition.ts @@ -8,7 +8,8 @@ import { FunctionBody } from './FunctionBody.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const objectConfig = { writable: true, diff --git a/src/slang-nodes/ModifierInvocation.ts b/src/slang-nodes/ModifierInvocation.ts index cb56d137d..fdde50908 100644 --- a/src/slang-nodes/ModifierInvocation.ts +++ b/src/slang-nodes/ModifierInvocation.ts @@ -6,7 +6,8 @@ import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class ModifierInvocation implements SlangNode { readonly kind = NonterminalKind.ModifierInvocation; diff --git a/src/slang-nodes/MultiplicativeExpression.ts b/src/slang-nodes/MultiplicativeExpression.ts index f54e768f1..ee6a10bf1 100644 --- a/src/slang-nodes/MultiplicativeExpression.ts +++ b/src/slang-nodes/MultiplicativeExpression.ts @@ -6,7 +6,8 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const multiplicationTryToHug = createHugFunction(['/', '%']); const divisionTryToHug = createHugFunction(['*', '%']); diff --git a/src/slang-nodes/NamedArgument.ts b/src/slang-nodes/NamedArgument.ts index 67b48312c..a226dc0e3 100644 --- a/src/slang-nodes/NamedArgument.ts +++ b/src/slang-nodes/NamedArgument.ts @@ -4,7 +4,8 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class NamedArgument implements SlangNode { readonly kind = NonterminalKind.NamedArgument; diff --git a/src/slang-nodes/NamedArgumentGroup.ts b/src/slang-nodes/NamedArgumentGroup.ts index 0648293ea..0354f45b8 100644 --- a/src/slang-nodes/NamedArgumentGroup.ts +++ b/src/slang-nodes/NamedArgumentGroup.ts @@ -4,7 +4,8 @@ import { NamedArguments } from './NamedArguments.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class NamedArgumentGroup implements SlangNode { readonly kind = NonterminalKind.NamedArgumentGroup; diff --git a/src/slang-nodes/NamedArguments.ts b/src/slang-nodes/NamedArguments.ts index 6257bdc84..091433b37 100644 --- a/src/slang-nodes/NamedArguments.ts +++ b/src/slang-nodes/NamedArguments.ts @@ -6,7 +6,8 @@ import { NamedArgument } from './NamedArgument.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { line, softline } = doc.builders; diff --git a/src/slang-nodes/NamedArgumentsDeclaration.ts b/src/slang-nodes/NamedArgumentsDeclaration.ts index 1b64ee67c..5b1c9b9e1 100644 --- a/src/slang-nodes/NamedArgumentsDeclaration.ts +++ b/src/slang-nodes/NamedArgumentsDeclaration.ts @@ -4,7 +4,8 @@ import { NamedArgumentGroup } from './NamedArgumentGroup.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class NamedArgumentsDeclaration implements SlangNode { readonly kind = NonterminalKind.NamedArgumentsDeclaration; diff --git a/src/slang-nodes/NamedImport.ts b/src/slang-nodes/NamedImport.ts index 0faa5d435..121cbd717 100644 --- a/src/slang-nodes/NamedImport.ts +++ b/src/slang-nodes/NamedImport.ts @@ -5,7 +5,8 @@ import { StringLiteral } from './StringLiteral.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class NamedImport implements SlangNode { readonly kind = NonterminalKind.NamedImport; diff --git a/src/slang-nodes/NewExpression.ts b/src/slang-nodes/NewExpression.ts index 79a9ad888..c588bff56 100644 --- a/src/slang-nodes/NewExpression.ts +++ b/src/slang-nodes/NewExpression.ts @@ -4,7 +4,8 @@ import { TypeName } from './TypeName.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class NewExpression implements SlangNode { readonly kind = NonterminalKind.NewExpression; diff --git a/src/slang-nodes/OrExpression.ts b/src/slang-nodes/OrExpression.ts index 1fb9d2ce9..9dd7f7844 100644 --- a/src/slang-nodes/OrExpression.ts +++ b/src/slang-nodes/OrExpression.ts @@ -6,7 +6,8 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const tryToHug = createHugFunction(['&&']); diff --git a/src/slang-nodes/Parameter.ts b/src/slang-nodes/Parameter.ts index 5ed2be6b6..68993e7f5 100644 --- a/src/slang-nodes/Parameter.ts +++ b/src/slang-nodes/Parameter.ts @@ -6,7 +6,8 @@ import { StorageLocation } from './StorageLocation.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { group } = doc.builders; diff --git a/src/slang-nodes/Parameters.ts b/src/slang-nodes/Parameters.ts index f3c19fe62..ed3265c2e 100644 --- a/src/slang-nodes/Parameters.ts +++ b/src/slang-nodes/Parameters.ts @@ -7,7 +7,8 @@ import { Parameter } from './Parameter.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class Parameters implements SlangNode { readonly kind = NonterminalKind.Parameters; diff --git a/src/slang-nodes/ParametersDeclaration.ts b/src/slang-nodes/ParametersDeclaration.ts index de7de6233..7bf92f860 100644 --- a/src/slang-nodes/ParametersDeclaration.ts +++ b/src/slang-nodes/ParametersDeclaration.ts @@ -4,7 +4,8 @@ import { Parameters } from './Parameters.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class ParametersDeclaration implements SlangNode { readonly kind = NonterminalKind.ParametersDeclaration; diff --git a/src/slang-nodes/PathImport.ts b/src/slang-nodes/PathImport.ts index 7950d17a6..69f2b7c47 100644 --- a/src/slang-nodes/PathImport.ts +++ b/src/slang-nodes/PathImport.ts @@ -5,7 +5,8 @@ import { ImportAlias } from './ImportAlias.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class PathImport implements SlangNode { readonly kind = NonterminalKind.PathImport; diff --git a/src/slang-nodes/PositionalArguments.ts b/src/slang-nodes/PositionalArguments.ts index c6cd2fe1d..023a75073 100644 --- a/src/slang-nodes/PositionalArguments.ts +++ b/src/slang-nodes/PositionalArguments.ts @@ -5,7 +5,8 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class PositionalArguments implements SlangNode { readonly kind = NonterminalKind.PositionalArguments; diff --git a/src/slang-nodes/PositionalArgumentsDeclaration.ts b/src/slang-nodes/PositionalArgumentsDeclaration.ts index 5a8169e0d..37a1ec3d3 100644 --- a/src/slang-nodes/PositionalArgumentsDeclaration.ts +++ b/src/slang-nodes/PositionalArgumentsDeclaration.ts @@ -4,7 +4,8 @@ import { PositionalArguments } from './PositionalArguments.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class PositionalArgumentsDeclaration implements SlangNode { readonly kind = NonterminalKind.PositionalArgumentsDeclaration; diff --git a/src/slang-nodes/PostfixExpression.ts b/src/slang-nodes/PostfixExpression.ts index 33d7b38ce..1617613b1 100644 --- a/src/slang-nodes/PostfixExpression.ts +++ b/src/slang-nodes/PostfixExpression.ts @@ -4,7 +4,8 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class PostfixExpression implements SlangNode { readonly kind = NonterminalKind.PostfixExpression; diff --git a/src/slang-nodes/Pragma.ts b/src/slang-nodes/Pragma.ts index 7c2a96128..62504caaf 100644 --- a/src/slang-nodes/Pragma.ts +++ b/src/slang-nodes/Pragma.ts @@ -6,7 +6,8 @@ import { VersionPragma } from './VersionPragma.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class Pragma implements SlangNode { readonly kind = NonterminalKind.Pragma; diff --git a/src/slang-nodes/PragmaDirective.ts b/src/slang-nodes/PragmaDirective.ts index a24470cf5..5b5ee0d15 100644 --- a/src/slang-nodes/PragmaDirective.ts +++ b/src/slang-nodes/PragmaDirective.ts @@ -4,7 +4,8 @@ import { Pragma } from './Pragma.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class PragmaDirective implements SlangNode { readonly kind = NonterminalKind.PragmaDirective; diff --git a/src/slang-nodes/PrefixExpression.ts b/src/slang-nodes/PrefixExpression.ts index c0191d242..235b06476 100644 --- a/src/slang-nodes/PrefixExpression.ts +++ b/src/slang-nodes/PrefixExpression.ts @@ -4,7 +4,8 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class PrefixExpression implements SlangNode { readonly kind = NonterminalKind.PrefixExpression; diff --git a/src/slang-nodes/ReceiveFunctionAttribute.ts b/src/slang-nodes/ReceiveFunctionAttribute.ts index e333a2394..d529fac22 100644 --- a/src/slang-nodes/ReceiveFunctionAttribute.ts +++ b/src/slang-nodes/ReceiveFunctionAttribute.ts @@ -6,7 +6,8 @@ import { OverrideSpecifier } from './OverrideSpecifier.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class ReceiveFunctionAttribute implements SlangNode { readonly kind = NonterminalKind.ReceiveFunctionAttribute; diff --git a/src/slang-nodes/ReceiveFunctionAttributes.ts b/src/slang-nodes/ReceiveFunctionAttributes.ts index 98b9c36b6..831bcf9fe 100644 --- a/src/slang-nodes/ReceiveFunctionAttributes.ts +++ b/src/slang-nodes/ReceiveFunctionAttributes.ts @@ -6,7 +6,8 @@ import { ReceiveFunctionAttribute } from './ReceiveFunctionAttribute.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { line } = doc.builders; diff --git a/src/slang-nodes/ReceiveFunctionDefinition.ts b/src/slang-nodes/ReceiveFunctionDefinition.ts index 111261f23..d71461bbf 100644 --- a/src/slang-nodes/ReceiveFunctionDefinition.ts +++ b/src/slang-nodes/ReceiveFunctionDefinition.ts @@ -7,7 +7,8 @@ import { FunctionBody } from './FunctionBody.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class ReceiveFunctionDefinition implements SlangNode { readonly kind = NonterminalKind.ReceiveFunctionDefinition; diff --git a/src/slang-nodes/ReturnStatement.ts b/src/slang-nodes/ReturnStatement.ts index e880834d3..0050402bf 100644 --- a/src/slang-nodes/ReturnStatement.ts +++ b/src/slang-nodes/ReturnStatement.ts @@ -5,7 +5,8 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { group, indent, line } = doc.builders; diff --git a/src/slang-nodes/ReturnsDeclaration.ts b/src/slang-nodes/ReturnsDeclaration.ts index 5c21ca546..b9c555902 100644 --- a/src/slang-nodes/ReturnsDeclaration.ts +++ b/src/slang-nodes/ReturnsDeclaration.ts @@ -5,7 +5,8 @@ import { ParametersDeclaration } from './ParametersDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { group } = doc.builders; diff --git a/src/slang-nodes/RevertStatement.ts b/src/slang-nodes/RevertStatement.ts index 738a14a3c..97ed970a0 100644 --- a/src/slang-nodes/RevertStatement.ts +++ b/src/slang-nodes/RevertStatement.ts @@ -5,7 +5,8 @@ import { ArgumentsDeclaration } from './ArgumentsDeclaration.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class RevertStatement implements SlangNode { readonly kind = NonterminalKind.RevertStatement; diff --git a/src/slang-nodes/ShiftExpression.ts b/src/slang-nodes/ShiftExpression.ts index 61fcb3591..fe04a3617 100644 --- a/src/slang-nodes/ShiftExpression.ts +++ b/src/slang-nodes/ShiftExpression.ts @@ -6,7 +6,8 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const tryToHugLeftOperand = createHugFunction([ '+', diff --git a/src/slang-nodes/SourceUnit.ts b/src/slang-nodes/SourceUnit.ts index 1e1b5b71b..4d83326ce 100644 --- a/src/slang-nodes/SourceUnit.ts +++ b/src/slang-nodes/SourceUnit.ts @@ -5,7 +5,8 @@ import { SourceUnitMembers } from './SourceUnitMembers.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { line } = doc.builders; diff --git a/src/slang-nodes/SourceUnitMember.ts b/src/slang-nodes/SourceUnitMember.ts index 65ca24d44..7deb86638 100644 --- a/src/slang-nodes/SourceUnitMember.ts +++ b/src/slang-nodes/SourceUnitMember.ts @@ -16,7 +16,8 @@ import { EventDefinition } from './EventDefinition.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class SourceUnitMember implements SlangNode { readonly kind = NonterminalKind.SourceUnitMember; diff --git a/src/slang-nodes/SourceUnitMembers.ts b/src/slang-nodes/SourceUnitMembers.ts index 48cd7626e..40c83c212 100644 --- a/src/slang-nodes/SourceUnitMembers.ts +++ b/src/slang-nodes/SourceUnitMembers.ts @@ -5,7 +5,8 @@ import { SourceUnitMember } from './SourceUnitMember.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class SourceUnitMembers implements SlangNode { readonly kind = NonterminalKind.SourceUnitMembers; diff --git a/src/slang-nodes/StateVariableDefinition.ts b/src/slang-nodes/StateVariableDefinition.ts index b4998e42f..fb4b014f7 100644 --- a/src/slang-nodes/StateVariableDefinition.ts +++ b/src/slang-nodes/StateVariableDefinition.ts @@ -6,7 +6,8 @@ import { StateVariableDefinitionValue } from './StateVariableDefinitionValue.js' import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class StateVariableDefinition implements SlangNode { readonly kind = NonterminalKind.StateVariableDefinition; diff --git a/src/slang-nodes/StateVariableDefinitionValue.ts b/src/slang-nodes/StateVariableDefinitionValue.ts index 6d5cf5b43..d882b418a 100644 --- a/src/slang-nodes/StateVariableDefinitionValue.ts +++ b/src/slang-nodes/StateVariableDefinitionValue.ts @@ -5,7 +5,8 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { group, indent, line } = doc.builders; diff --git a/src/slang-nodes/Statement.ts b/src/slang-nodes/Statement.ts index eda9204dd..01fb2a085 100644 --- a/src/slang-nodes/Statement.ts +++ b/src/slang-nodes/Statement.ts @@ -20,7 +20,8 @@ import { UncheckedBlock } from './UncheckedBlock.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class Statement implements SlangNode { readonly kind = NonterminalKind.Statement; diff --git a/src/slang-nodes/Statements.ts b/src/slang-nodes/Statements.ts index 9073d3be7..6cb8ee665 100644 --- a/src/slang-nodes/Statements.ts +++ b/src/slang-nodes/Statements.ts @@ -8,7 +8,8 @@ import { Statement } from './Statement.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { hardline } = doc.builders; diff --git a/src/slang-nodes/StringExpression.ts b/src/slang-nodes/StringExpression.ts index 6c3c12151..1509d634d 100644 --- a/src/slang-nodes/StringExpression.ts +++ b/src/slang-nodes/StringExpression.ts @@ -8,7 +8,8 @@ import { UnicodeStringLiterals } from './UnicodeStringLiterals.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class StringExpression implements SlangNode { readonly kind = NonterminalKind.StringExpression; diff --git a/src/slang-nodes/StringLiteral.ts b/src/slang-nodes/StringLiteral.ts index 2a5eb0993..ef8a2357b 100644 --- a/src/slang-nodes/StringLiteral.ts +++ b/src/slang-nodes/StringLiteral.ts @@ -4,7 +4,8 @@ import { getNodeMetadata } from '../slang-utils/metadata.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { SlangNode } from '../types'; export class StringLiteral implements SlangNode { readonly kind = NonterminalKind.StringLiteral; diff --git a/src/slang-nodes/StringLiterals.ts b/src/slang-nodes/StringLiterals.ts index 3a71b17b3..415153d57 100644 --- a/src/slang-nodes/StringLiterals.ts +++ b/src/slang-nodes/StringLiterals.ts @@ -5,7 +5,8 @@ import { StringLiteral } from './StringLiteral.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { join, hardline } = doc.builders; diff --git a/src/slang-nodes/StructDefinition.ts b/src/slang-nodes/StructDefinition.ts index 9bf6f943c..a5c13349b 100644 --- a/src/slang-nodes/StructDefinition.ts +++ b/src/slang-nodes/StructDefinition.ts @@ -4,7 +4,8 @@ import { StructMembers } from './StructMembers.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class StructDefinition implements SlangNode { readonly kind = NonterminalKind.StructDefinition; diff --git a/src/slang-nodes/StructMember.ts b/src/slang-nodes/StructMember.ts index 795c1426a..41855adcc 100644 --- a/src/slang-nodes/StructMember.ts +++ b/src/slang-nodes/StructMember.ts @@ -4,7 +4,8 @@ import { TypeName } from './TypeName.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class StructMember implements SlangNode { readonly kind = NonterminalKind.StructMember; diff --git a/src/slang-nodes/StructMembers.ts b/src/slang-nodes/StructMembers.ts index 9f3cf110b..cb0976f13 100644 --- a/src/slang-nodes/StructMembers.ts +++ b/src/slang-nodes/StructMembers.ts @@ -6,7 +6,8 @@ import { StructMember } from './StructMember.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { hardline } = doc.builders; diff --git a/src/slang-nodes/TryStatement.ts b/src/slang-nodes/TryStatement.ts index 02be9c69c..eb390c569 100644 --- a/src/slang-nodes/TryStatement.ts +++ b/src/slang-nodes/TryStatement.ts @@ -9,7 +9,8 @@ import { CatchClauses } from './CatchClauses.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { line } = doc.builders; diff --git a/src/slang-nodes/TupleDeconstructionElement.ts b/src/slang-nodes/TupleDeconstructionElement.ts index 93d30c33b..791a367a0 100644 --- a/src/slang-nodes/TupleDeconstructionElement.ts +++ b/src/slang-nodes/TupleDeconstructionElement.ts @@ -4,7 +4,8 @@ import { TupleMember } from './TupleMember.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class TupleDeconstructionElement implements SlangNode { readonly kind = NonterminalKind.TupleDeconstructionElement; diff --git a/src/slang-nodes/TupleDeconstructionElements.ts b/src/slang-nodes/TupleDeconstructionElements.ts index cfbd1eb8c..feebbd096 100644 --- a/src/slang-nodes/TupleDeconstructionElements.ts +++ b/src/slang-nodes/TupleDeconstructionElements.ts @@ -5,7 +5,8 @@ import { TupleDeconstructionElement } from './TupleDeconstructionElement.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class TupleDeconstructionElements implements SlangNode { readonly kind = NonterminalKind.TupleDeconstructionElements; diff --git a/src/slang-nodes/TupleDeconstructionStatement.ts b/src/slang-nodes/TupleDeconstructionStatement.ts index f2818bc3f..475e9076b 100644 --- a/src/slang-nodes/TupleDeconstructionStatement.ts +++ b/src/slang-nodes/TupleDeconstructionStatement.ts @@ -6,7 +6,8 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { group, indent, line } = doc.builders; diff --git a/src/slang-nodes/TupleExpression.ts b/src/slang-nodes/TupleExpression.ts index 517c4a8db..1cb523f97 100644 --- a/src/slang-nodes/TupleExpression.ts +++ b/src/slang-nodes/TupleExpression.ts @@ -4,7 +4,8 @@ import { TupleValues } from './TupleValues.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class TupleExpression implements SlangNode { readonly kind = NonterminalKind.TupleExpression; diff --git a/src/slang-nodes/TupleMember.ts b/src/slang-nodes/TupleMember.ts index a656fc3a8..e117f7763 100644 --- a/src/slang-nodes/TupleMember.ts +++ b/src/slang-nodes/TupleMember.ts @@ -5,7 +5,8 @@ import { UntypedTupleMember } from './UntypedTupleMember.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class TupleMember implements SlangNode { readonly kind = NonterminalKind.TupleMember; diff --git a/src/slang-nodes/TupleValue.ts b/src/slang-nodes/TupleValue.ts index 42c5f3ba3..2608d1539 100644 --- a/src/slang-nodes/TupleValue.ts +++ b/src/slang-nodes/TupleValue.ts @@ -4,7 +4,8 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class TupleValue implements SlangNode { readonly kind = NonterminalKind.TupleValue; diff --git a/src/slang-nodes/TupleValues.ts b/src/slang-nodes/TupleValues.ts index 180dd50ab..e068ff61a 100644 --- a/src/slang-nodes/TupleValues.ts +++ b/src/slang-nodes/TupleValues.ts @@ -6,7 +6,8 @@ import { TupleValue } from './TupleValue.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class TupleValues implements SlangNode { readonly kind = NonterminalKind.TupleValues; diff --git a/src/slang-nodes/TypeExpression.ts b/src/slang-nodes/TypeExpression.ts index 26d8004f5..4d62ae928 100644 --- a/src/slang-nodes/TypeExpression.ts +++ b/src/slang-nodes/TypeExpression.ts @@ -4,7 +4,8 @@ import { TypeName } from './TypeName.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { /*AstPath,*/ Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { SlangNode } from '../types'; export class TypeExpression implements SlangNode { readonly kind = NonterminalKind.TypeExpression; diff --git a/src/slang-nodes/TypeName.ts b/src/slang-nodes/TypeName.ts index 3d75f1056..03e19f11f 100644 --- a/src/slang-nodes/TypeName.ts +++ b/src/slang-nodes/TypeName.ts @@ -8,7 +8,8 @@ import { IdentifierPath } from './IdentifierPath.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class TypeName implements SlangNode { readonly kind = NonterminalKind.TypeName; diff --git a/src/slang-nodes/TypedTupleMember.ts b/src/slang-nodes/TypedTupleMember.ts index 38654c0c7..b0d8014b0 100644 --- a/src/slang-nodes/TypedTupleMember.ts +++ b/src/slang-nodes/TypedTupleMember.ts @@ -5,7 +5,8 @@ import { StorageLocation } from './StorageLocation.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class TypedTupleMember implements SlangNode { readonly kind = NonterminalKind.TypedTupleMember; diff --git a/src/slang-nodes/UncheckedBlock.ts b/src/slang-nodes/UncheckedBlock.ts index c902a76af..ab24ec20a 100644 --- a/src/slang-nodes/UncheckedBlock.ts +++ b/src/slang-nodes/UncheckedBlock.ts @@ -4,7 +4,8 @@ import { Block } from './Block.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class UncheckedBlock implements SlangNode { readonly kind = NonterminalKind.UncheckedBlock; diff --git a/src/slang-nodes/UnicodeStringLiteral.ts b/src/slang-nodes/UnicodeStringLiteral.ts index 1e8a1cfd3..e36d2f09a 100644 --- a/src/slang-nodes/UnicodeStringLiteral.ts +++ b/src/slang-nodes/UnicodeStringLiteral.ts @@ -4,7 +4,8 @@ import { getNodeMetadata } from '../slang-utils/metadata.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { SlangNode } from '../types'; export class UnicodeStringLiteral implements SlangNode { readonly kind = NonterminalKind.UnicodeStringLiteral; diff --git a/src/slang-nodes/UnicodeStringLiterals.ts b/src/slang-nodes/UnicodeStringLiterals.ts index 6b1fa3421..4f73b7a97 100644 --- a/src/slang-nodes/UnicodeStringLiterals.ts +++ b/src/slang-nodes/UnicodeStringLiterals.ts @@ -5,7 +5,8 @@ import { UnicodeStringLiteral } from './UnicodeStringLiteral.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { join, hardline } = doc.builders; diff --git a/src/slang-nodes/UnnamedFunctionAttribute.ts b/src/slang-nodes/UnnamedFunctionAttribute.ts index cb2f69887..a4786c412 100644 --- a/src/slang-nodes/UnnamedFunctionAttribute.ts +++ b/src/slang-nodes/UnnamedFunctionAttribute.ts @@ -5,7 +5,8 @@ import { ModifierInvocation } from './ModifierInvocation.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class UnnamedFunctionAttribute implements SlangNode { readonly kind = NonterminalKind.UnnamedFunctionAttribute; diff --git a/src/slang-nodes/UnnamedFunctionAttributes.ts b/src/slang-nodes/UnnamedFunctionAttributes.ts index 73b6b0651..a015fa660 100644 --- a/src/slang-nodes/UnnamedFunctionAttributes.ts +++ b/src/slang-nodes/UnnamedFunctionAttributes.ts @@ -6,7 +6,8 @@ import { UnnamedFunctionAttribute } from './UnnamedFunctionAttribute.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { line } = doc.builders; diff --git a/src/slang-nodes/UnnamedFunctionDefinition.ts b/src/slang-nodes/UnnamedFunctionDefinition.ts index 501f8d916..c83af05fb 100644 --- a/src/slang-nodes/UnnamedFunctionDefinition.ts +++ b/src/slang-nodes/UnnamedFunctionDefinition.ts @@ -7,7 +7,8 @@ import { FunctionBody } from './FunctionBody.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class UnnamedFunctionDefinition implements SlangNode { readonly kind = NonterminalKind.UnnamedFunctionDefinition; diff --git a/src/slang-nodes/UsingDeconstructionSymbols.ts b/src/slang-nodes/UsingDeconstructionSymbols.ts index 38d69b43c..48116cd21 100644 --- a/src/slang-nodes/UsingDeconstructionSymbols.ts +++ b/src/slang-nodes/UsingDeconstructionSymbols.ts @@ -6,7 +6,8 @@ import { UsingDeconstructionSymbol } from './UsingDeconstructionSymbol.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { line, softline } = doc.builders; diff --git a/src/slang-nodes/UsingDirective.ts b/src/slang-nodes/UsingDirective.ts index 1e96bb2b2..d60dceae8 100644 --- a/src/slang-nodes/UsingDirective.ts +++ b/src/slang-nodes/UsingDirective.ts @@ -5,7 +5,8 @@ import { UsingTarget } from './UsingTarget.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class UsingDirective implements SlangNode { readonly kind = NonterminalKind.UsingDirective; diff --git a/src/slang-nodes/UsingTarget.ts b/src/slang-nodes/UsingTarget.ts index ed3c32923..d33b82699 100644 --- a/src/slang-nodes/UsingTarget.ts +++ b/src/slang-nodes/UsingTarget.ts @@ -5,7 +5,8 @@ import { TypeName } from './TypeName.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class UsingTarget implements SlangNode { readonly kind = NonterminalKind.UsingTarget; diff --git a/src/slang-nodes/VariableDeclarationStatement.ts b/src/slang-nodes/VariableDeclarationStatement.ts index d94aa1a80..25f741ea7 100644 --- a/src/slang-nodes/VariableDeclarationStatement.ts +++ b/src/slang-nodes/VariableDeclarationStatement.ts @@ -7,7 +7,8 @@ import { VariableDeclarationValue } from './VariableDeclarationValue.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { group, indent, indentIfBreak, line } = doc.builders; diff --git a/src/slang-nodes/VariableDeclarationType.ts b/src/slang-nodes/VariableDeclarationType.ts index 1963f9747..294c3f4be 100644 --- a/src/slang-nodes/VariableDeclarationType.ts +++ b/src/slang-nodes/VariableDeclarationType.ts @@ -5,7 +5,8 @@ import { TypeName } from './TypeName.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class VariableDeclarationType implements SlangNode { readonly kind = NonterminalKind.VariableDeclarationType; diff --git a/src/slang-nodes/VariableDeclarationValue.ts b/src/slang-nodes/VariableDeclarationValue.ts index d810b8df5..240e89d1a 100644 --- a/src/slang-nodes/VariableDeclarationValue.ts +++ b/src/slang-nodes/VariableDeclarationValue.ts @@ -4,7 +4,8 @@ import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class VariableDeclarationValue implements SlangNode { readonly kind = NonterminalKind.VariableDeclarationValue; diff --git a/src/slang-nodes/WhileStatement.ts b/src/slang-nodes/WhileStatement.ts index db46ab691..95111fd92 100644 --- a/src/slang-nodes/WhileStatement.ts +++ b/src/slang-nodes/WhileStatement.ts @@ -7,7 +7,8 @@ import { Statement } from './Statement.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { group, indent, line } = doc.builders; diff --git a/src/slang-nodes/YulArguments.ts b/src/slang-nodes/YulArguments.ts index 99241e23b..02e528913 100644 --- a/src/slang-nodes/YulArguments.ts +++ b/src/slang-nodes/YulArguments.ts @@ -5,7 +5,8 @@ import { YulExpression } from './YulExpression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class YulArguments implements SlangNode { readonly kind = NonterminalKind.YulArguments; diff --git a/src/slang-nodes/YulBlock.ts b/src/slang-nodes/YulBlock.ts index f6ddd8cbb..2e38c4de8 100644 --- a/src/slang-nodes/YulBlock.ts +++ b/src/slang-nodes/YulBlock.ts @@ -4,7 +4,8 @@ import { YulStatements } from './YulStatements.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class YulBlock implements SlangNode { readonly kind = NonterminalKind.YulBlock; diff --git a/src/slang-nodes/YulDefaultCase.ts b/src/slang-nodes/YulDefaultCase.ts index d070bf8a6..db189a62e 100644 --- a/src/slang-nodes/YulDefaultCase.ts +++ b/src/slang-nodes/YulDefaultCase.ts @@ -4,7 +4,8 @@ import { YulBlock } from './YulBlock.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class YulDefaultCase implements SlangNode { readonly kind = NonterminalKind.YulDefaultCase; diff --git a/src/slang-nodes/YulExpression.ts b/src/slang-nodes/YulExpression.ts index df1ddcf72..662eda547 100644 --- a/src/slang-nodes/YulExpression.ts +++ b/src/slang-nodes/YulExpression.ts @@ -7,7 +7,8 @@ import { YulPath } from './YulPath.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class YulExpression implements SlangNode { readonly kind = NonterminalKind.YulExpression; diff --git a/src/slang-nodes/YulForStatement.ts b/src/slang-nodes/YulForStatement.ts index cef1366a3..f1ca210ab 100644 --- a/src/slang-nodes/YulForStatement.ts +++ b/src/slang-nodes/YulForStatement.ts @@ -5,7 +5,8 @@ import { YulExpression } from './YulExpression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class YulForStatement implements SlangNode { readonly kind = NonterminalKind.YulForStatement; diff --git a/src/slang-nodes/YulFunctionCallExpression.ts b/src/slang-nodes/YulFunctionCallExpression.ts index 0daf8d368..8302acfe4 100644 --- a/src/slang-nodes/YulFunctionCallExpression.ts +++ b/src/slang-nodes/YulFunctionCallExpression.ts @@ -5,7 +5,8 @@ import { YulArguments } from './YulArguments.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class YulFunctionCallExpression implements SlangNode { readonly kind = NonterminalKind.YulFunctionCallExpression; diff --git a/src/slang-nodes/YulFunctionDefinition.ts b/src/slang-nodes/YulFunctionDefinition.ts index ef454a679..0ac264ae9 100644 --- a/src/slang-nodes/YulFunctionDefinition.ts +++ b/src/slang-nodes/YulFunctionDefinition.ts @@ -6,7 +6,8 @@ import { YulBlock } from './YulBlock.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class YulFunctionDefinition implements SlangNode { readonly kind = NonterminalKind.YulFunctionDefinition; diff --git a/src/slang-nodes/YulIfStatement.ts b/src/slang-nodes/YulIfStatement.ts index 35b0282f1..a5d86d1d1 100644 --- a/src/slang-nodes/YulIfStatement.ts +++ b/src/slang-nodes/YulIfStatement.ts @@ -5,7 +5,8 @@ import { YulBlock } from './YulBlock.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class YulIfStatement implements SlangNode { readonly kind = NonterminalKind.YulIfStatement; diff --git a/src/slang-nodes/YulLiteral.ts b/src/slang-nodes/YulLiteral.ts index dec44ff49..a88f1281c 100644 --- a/src/slang-nodes/YulLiteral.ts +++ b/src/slang-nodes/YulLiteral.ts @@ -6,7 +6,8 @@ import { StringLiteral } from './StringLiteral.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class YulLiteral implements SlangNode { readonly kind = NonterminalKind.YulLiteral; diff --git a/src/slang-nodes/YulStackAssignmentStatement.ts b/src/slang-nodes/YulStackAssignmentStatement.ts index e58602f00..f59e42e73 100644 --- a/src/slang-nodes/YulStackAssignmentStatement.ts +++ b/src/slang-nodes/YulStackAssignmentStatement.ts @@ -5,7 +5,8 @@ import { YulExpression } from './YulExpression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { /*AstPath,*/ Doc, ParserOptions } from 'prettier'; -import type { AstNode, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { SlangNode } from '../types'; export class YulStackAssignmentStatement implements SlangNode { readonly kind = NonterminalKind.YulStackAssignmentStatement; diff --git a/src/slang-nodes/YulStatement.ts b/src/slang-nodes/YulStatement.ts index 311d305ed..823612d65 100644 --- a/src/slang-nodes/YulStatement.ts +++ b/src/slang-nodes/YulStatement.ts @@ -16,7 +16,8 @@ import { YulExpression } from './YulExpression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class YulStatement implements SlangNode { readonly kind = NonterminalKind.YulStatement; diff --git a/src/slang-nodes/YulStatements.ts b/src/slang-nodes/YulStatements.ts index 997853360..a345e71f5 100644 --- a/src/slang-nodes/YulStatements.ts +++ b/src/slang-nodes/YulStatements.ts @@ -8,7 +8,8 @@ import { YulStatement } from './YulStatement.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { hardline } = doc.builders; diff --git a/src/slang-nodes/YulSwitchCase.ts b/src/slang-nodes/YulSwitchCase.ts index 6d6bcc259..2d47fd6d1 100644 --- a/src/slang-nodes/YulSwitchCase.ts +++ b/src/slang-nodes/YulSwitchCase.ts @@ -5,7 +5,8 @@ import { YulValueCase } from './YulValueCase.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class YulSwitchCase implements SlangNode { readonly kind = NonterminalKind.YulSwitchCase; diff --git a/src/slang-nodes/YulSwitchCases.ts b/src/slang-nodes/YulSwitchCases.ts index 1fd814c61..8f26535ed 100644 --- a/src/slang-nodes/YulSwitchCases.ts +++ b/src/slang-nodes/YulSwitchCases.ts @@ -5,7 +5,8 @@ import { YulSwitchCase } from './YulSwitchCase.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { hardline, join } = doc.builders; diff --git a/src/slang-nodes/YulSwitchStatement.ts b/src/slang-nodes/YulSwitchStatement.ts index cbdfe00e3..ae95cf658 100644 --- a/src/slang-nodes/YulSwitchStatement.ts +++ b/src/slang-nodes/YulSwitchStatement.ts @@ -6,7 +6,8 @@ import { YulSwitchCases } from './YulSwitchCases.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; const { hardline } = doc.builders; diff --git a/src/slang-nodes/YulValueCase.ts b/src/slang-nodes/YulValueCase.ts index b321a0077..9b5d58047 100644 --- a/src/slang-nodes/YulValueCase.ts +++ b/src/slang-nodes/YulValueCase.ts @@ -5,7 +5,8 @@ import { YulBlock } from './YulBlock.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class YulValueCase implements SlangNode { readonly kind = NonterminalKind.YulValueCase; diff --git a/src/slang-nodes/YulVariableAssignmentStatement.ts b/src/slang-nodes/YulVariableAssignmentStatement.ts index 2e308ac1a..4a1b10cc3 100644 --- a/src/slang-nodes/YulVariableAssignmentStatement.ts +++ b/src/slang-nodes/YulVariableAssignmentStatement.ts @@ -6,7 +6,8 @@ import { YulExpression } from './YulExpression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class YulVariableAssignmentStatement implements SlangNode { readonly kind = NonterminalKind.YulVariableAssignmentStatement; diff --git a/src/slang-nodes/YulVariableDeclarationStatement.ts b/src/slang-nodes/YulVariableDeclarationStatement.ts index 3213fa59a..0d6a0156a 100644 --- a/src/slang-nodes/YulVariableDeclarationStatement.ts +++ b/src/slang-nodes/YulVariableDeclarationStatement.ts @@ -4,7 +4,8 @@ import { YulVariableDeclarationValue } from './YulVariableDeclarationValue.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class YulVariableDeclarationStatement implements SlangNode { readonly kind = NonterminalKind.YulVariableDeclarationStatement; diff --git a/src/slang-nodes/YulVariableDeclarationValue.ts b/src/slang-nodes/YulVariableDeclarationValue.ts index 1b750c3cf..aef660882 100644 --- a/src/slang-nodes/YulVariableDeclarationValue.ts +++ b/src/slang-nodes/YulVariableDeclarationValue.ts @@ -5,7 +5,8 @@ import { YulExpression } from './YulExpression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, SlangNode } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { PrintFunction, SlangNode } from '../types'; export class YulVariableDeclarationValue implements SlangNode { readonly kind = NonterminalKind.YulVariableDeclarationValue; diff --git a/src/slang-nodes/index.d.ts b/src/slang-nodes/index.d.ts index cdb1b15e0..1b174e6d6 100644 --- a/src/slang-nodes/index.d.ts +++ b/src/slang-nodes/index.d.ts @@ -1,215 +1,504 @@ -export type * from './ABICoderPragma.js'; -export type * from './AdditiveExpression.js'; -export type * from './AddressType.js'; -export type * from './AndExpression.js'; -export type * from './ArgumentsDeclaration.js'; -export type * from './ArrayExpression.js'; -export type * from './ArrayTypeName.js'; -export type * from './ArrayValues.js'; -export type * from './AssemblyFlags.js'; -export type * from './AssemblyFlagsDeclaration.js'; -export type * from './AssemblyStatement.js'; -export type * from './AssignmentExpression.js'; -export type * from './BitwiseAndExpression.js'; -export type * from './BitwiseOrExpression.js'; -export type * from './BitwiseXorExpression.js'; -export type * from './Block.js'; -export type * from './BreakStatement.js'; -export type * from './CallOptions.js'; -export type * from './CallOptionsExpression.js'; -export type * from './CatchClause.js'; -export type * from './CatchClauseError.js'; -export type * from './CatchClauses.js'; -export type * from './ComparisonExpression.js'; -export type * from './ConditionalExpression.js'; -export type * from './ConstantDefinition.js'; -export type * from './ConstructorAttribute.js'; -export type * from './ConstructorAttributes.js'; -export type * from './ConstructorDefinition.js'; -export type * from './ContinueStatement.js'; -export type * from './ContractDefinition.js'; -export type * from './ContractMember.js'; -export type * from './ContractMembers.js'; -export type * from './DecimalNumberExpression.js'; -export type * from './DoWhileStatement.js'; -export type * from './ElementaryType.js'; -export type * from './ElseBranch.js'; -export type * from './EmitStatement.js'; -export type * from './EnumDefinition.js'; -export type * from './EnumMembers.js'; -export type * from './EqualityExpression.js'; -export type * from './ErrorDefinition.js'; -export type * from './ErrorParameter.js'; -export type * from './ErrorParameters.js'; -export type * from './ErrorParametersDeclaration.js'; -export type * from './EventDefinition.js'; -export type * from './EventParameter.js'; -export type * from './EventParameters.js'; -export type * from './EventParametersDeclaration.js'; -export type * from './ExperimentalFeature.js'; -export type * from './ExperimentalPragma.js'; -export type * from './ExponentiationExpression.js'; -export type * from './Expression.js'; -export type * from './ExpressionStatement.js'; -export type * from './FallbackFunctionAttribute.js'; -export type * from './FallbackFunctionAttributes.js'; -export type * from './FallbackFunctionDefinition.js'; -export type * from './ForStatement.js'; -export type * from './ForStatementCondition.js'; -export type * from './ForStatementInitialization.js'; -export type * from './FunctionAttribute.js'; -export type * from './FunctionAttributes.js'; -export type * from './FunctionBody.js'; -export type * from './FunctionCallExpression.js'; -export type * from './FunctionDefinition.js'; -export type * from './FunctionName.js'; -export type * from './FunctionType.js'; -export type * from './FunctionTypeAttribute.js'; -export type * from './FunctionTypeAttributes.js'; -export type * from './HexNumberExpression.js'; -export type * from './HexStringLiteral.js'; -export type * from './HexStringLiterals.js'; -export type * from './IdentifierPath.js'; -export type * from './IfStatement.js'; -export type * from './ImportAlias.js'; -export type * from './ImportClause.js'; -export type * from './ImportDeconstruction.js'; -export type * from './ImportDeconstructionSymbol.js'; -export type * from './ImportDeconstructionSymbols.js'; -export type * from './ImportDirective.js'; -export type * from './IndexAccessEnd.js'; -export type * from './IndexAccessExpression.js'; -export type * from './InheritanceSpecifier.js'; -export type * from './InheritanceType.js'; -export type * from './InheritanceTypes.js'; -export type * from './InterfaceDefinition.js'; -export type * from './InterfaceMembers.js'; -export type * from './LibraryDefinition.js'; -export type * from './LibraryMembers.js'; -export type * from './MappingKey.js'; -export type * from './MappingKeyType.js'; -export type * from './MappingType.js'; -export type * from './MappingValue.js'; -export type * from './MemberAccess.js'; -export type * from './MemberAccessExpression.js'; -export type * from './ModifierAttribute.js'; -export type * from './ModifierAttributes.js'; -export type * from './ModifierDefinition.js'; -export type * from './ModifierInvocation.js'; -export type * from './MultiplicativeExpression.js'; -export type * from './NamedArgument.js'; -export type * from './NamedArgumentGroup.js'; -export type * from './NamedArguments.js'; -export type * from './NamedArgumentsDeclaration.js'; -export type * from './NamedImport.js'; -export type * from './NewExpression.js'; -export type * from './NumberUnit.js'; -export type * from './OrExpression.js'; -export type * from './OverridePaths.js'; -export type * from './OverridePathsDeclaration.js'; -export type * from './OverrideSpecifier.js'; -export type * from './Parameter.js'; -export type * from './Parameters.js'; -export type * from './ParametersDeclaration.js'; -export type * from './PathImport.js'; -export type * from './PositionalArguments.js'; -export type * from './PositionalArgumentsDeclaration.js'; -export type * from './PostfixExpression.js'; -export type * from './Pragma.js'; -export type * from './PragmaDirective.js'; -export type * from './PrefixExpression.js'; -export type * from './ReceiveFunctionAttribute.js'; -export type * from './ReceiveFunctionAttributes.js'; -export type * from './ReceiveFunctionDefinition.js'; -export type * from './ReturnsDeclaration.js'; -export type * from './ReturnStatement.js'; -export type * from './RevertStatement.js'; -export type * from './ShiftExpression.js'; -export type * from './SourceUnit.js'; -export type * from './SourceUnitMember.js'; -export type * from './SourceUnitMembers.js'; -export type * from './Statement.js'; -export type * from './Statements.js'; -export type * from './StateVariableAttribute.js'; -export type * from './StateVariableAttributes.js'; -export type * from './StateVariableDefinition.js'; -export type * from './StateVariableDefinitionValue.js'; -export type * from './StorageLocation.js'; -export type * from './StringExpression.js'; -export type * from './StringLiteral.js'; -export type * from './StringLiterals.js'; -export type * from './StructDefinition.js'; -export type * from './StructMember.js'; -export type * from './StructMembers.js'; -export type * from './ThrowStatement.js'; -export type * from './TryStatement.js'; -export type * from './TupleDeconstructionElement.js'; -export type * from './TupleDeconstructionElements.js'; -export type * from './TupleDeconstructionStatement.js'; -export type * from './TupleExpression.js'; -export type * from './TupleMember.js'; -export type * from './TupleValue.js'; -export type * from './TupleValues.js'; -export type * from './TypedTupleMember.js'; -export type * from './TypeExpression.js'; -export type * from './TypeName.js'; -export type * from './UncheckedBlock.js'; -export type * from './UnicodeStringLiteral.js'; -export type * from './UnicodeStringLiterals.js'; -export type * from './UnnamedFunctionAttribute.js'; -export type * from './UnnamedFunctionAttributes.js'; -export type * from './UnnamedFunctionDefinition.js'; -export type * from './UntypedTupleMember.js'; -export type * from './UserDefinedValueTypeDefinition.js'; -export type * from './UsingAlias.js'; -export type * from './UsingClause.js'; -export type * from './UsingDeconstruction.js'; -export type * from './UsingDeconstructionSymbol.js'; -export type * from './UsingDeconstructionSymbols.js'; -export type * from './UsingDirective.js'; -export type * from './UsingOperator.js'; -export type * from './UsingTarget.js'; -export type * from './VariableDeclarationStatement.js'; -export type * from './VariableDeclarationType.js'; -export type * from './VariableDeclarationValue.js'; -export type * from './VersionComparator.js'; -export type * from './VersionExpression.js'; -export type * from './VersionExpressionSet.js'; -export type * from './VersionExpressionSets.js'; -export type * from './VersionPragma.js'; -export type * from './VersionRange.js'; -export type * from './VersionSpecifiers.js'; -export type * from './WhileStatement.js'; -export type * from './YulArguments.js'; -export type * from './YulAssignmentOperator.js'; -export type * from './YulBlock.js'; -export type * from './YulBreakStatement.js'; -export type * from './YulBuiltInFunction.js'; -export type * from './YulColonEqual.js'; -export type * from './YulContinueStatement.js'; -export type * from './YulDefaultCase.js'; -export type * from './YulExpression.js'; -export type * from './YulForStatement.js'; -export type * from './YulFunctionCallExpression.js'; -export type * from './YulFunctionDefinition.js'; -export type * from './YulIfStatement.js'; -export type * from './YulLabel.js'; -export type * from './YulLeaveStatement.js'; -export type * from './YulLiteral.js'; -export type * from './YulParameters.js'; -export type * from './YulParametersDeclaration.js'; -export type * from './YulPath.js'; -export type * from './YulPathComponent.js'; -export type * from './YulPaths.js'; -export type * from './YulReturnsDeclaration.js'; -export type * from './YulReturnVariables.js'; -export type * from './YulStackAssignmentStatement.js'; -export type * from './YulStatement.js'; -export type * from './YulStatements.js'; -export type * from './YulSwitchCase.js'; -export type * from './YulSwitchCases.js'; -export type * from './YulSwitchStatement.js'; -export type * from './YulValueCase.js'; -export type * from './YulVariableAssignmentStatement.js'; -export type * from './YulVariableDeclarationStatement.js'; -export type * from './YulVariableDeclarationValue.js'; +import type { ABICoderPragma } from './ABICoderPragma'; +import type { AdditiveExpression } from './AdditiveExpression'; +import type { AddressType } from './AddressType'; +import type { AndExpression } from './AndExpression'; +import type { ArgumentsDeclaration } from './ArgumentsDeclaration'; +import type { ArrayExpression } from './ArrayExpression'; +import type { ArrayTypeName } from './ArrayTypeName'; +import type { ArrayValues } from './ArrayValues'; +import type { AssemblyFlags } from './AssemblyFlags'; +import type { AssemblyFlagsDeclaration } from './AssemblyFlagsDeclaration'; +import type { AssemblyStatement } from './AssemblyStatement'; +import type { AssignmentExpression } from './AssignmentExpression'; +import type { BitwiseAndExpression } from './BitwiseAndExpression'; +import type { BitwiseOrExpression } from './BitwiseOrExpression'; +import type { BitwiseXorExpression } from './BitwiseXorExpression'; +import type { Block } from './Block'; +import type { BreakStatement } from './BreakStatement'; +import type { CallOptions } from './CallOptions'; +import type { CallOptionsExpression } from './CallOptionsExpression'; +import type { CatchClause } from './CatchClause'; +import type { CatchClauseError } from './CatchClauseError'; +import type { CatchClauses } from './CatchClauses'; +import type { ComparisonExpression } from './ComparisonExpression'; +import type { ConditionalExpression } from './ConditionalExpression'; +import type { ConstantDefinition } from './ConstantDefinition'; +import type { ConstructorAttribute } from './ConstructorAttribute'; +import type { ConstructorAttributes } from './ConstructorAttributes'; +import type { ConstructorDefinition } from './ConstructorDefinition'; +import type { ContinueStatement } from './ContinueStatement'; +import type { ContractDefinition } from './ContractDefinition'; +import type { ContractMember } from './ContractMember'; +import type { ContractMembers } from './ContractMembers'; +import type { DecimalNumberExpression } from './DecimalNumberExpression'; +import type { DoWhileStatement } from './DoWhileStatement'; +import type { ElementaryType } from './ElementaryType'; +import type { ElseBranch } from './ElseBranch'; +import type { EmitStatement } from './EmitStatement'; +import type { EnumDefinition } from './EnumDefinition'; +import type { EnumMembers } from './EnumMembers'; +import type { EqualityExpression } from './EqualityExpression'; +import type { ErrorDefinition } from './ErrorDefinition'; +import type { ErrorParameter } from './ErrorParameter'; +import type { ErrorParameters } from './ErrorParameters'; +import type { ErrorParametersDeclaration } from './ErrorParametersDeclaration'; +import type { EventDefinition } from './EventDefinition'; +import type { EventParameter } from './EventParameter'; +import type { EventParameters } from './EventParameters'; +import type { EventParametersDeclaration } from './EventParametersDeclaration'; +import type { ExperimentalFeature } from './ExperimentalFeature'; +import type { ExperimentalPragma } from './ExperimentalPragma'; +import type { ExponentiationExpression } from './ExponentiationExpression'; +import type { Expression } from './Expression'; +import type { ExpressionStatement } from './ExpressionStatement'; +import type { FallbackFunctionAttribute } from './FallbackFunctionAttribute'; +import type { FallbackFunctionAttributes } from './FallbackFunctionAttributes'; +import type { FallbackFunctionDefinition } from './FallbackFunctionDefinition'; +import type { ForStatement } from './ForStatement'; +import type { ForStatementCondition } from './ForStatementCondition'; +import type { ForStatementInitialization } from './ForStatementInitialization'; +import type { FunctionAttribute } from './FunctionAttribute'; +import type { FunctionAttributes } from './FunctionAttributes'; +import type { FunctionBody } from './FunctionBody'; +import type { FunctionCallExpression } from './FunctionCallExpression'; +import type { FunctionDefinition } from './FunctionDefinition'; +import type { FunctionName } from './FunctionName'; +import type { FunctionType } from './FunctionType'; +import type { FunctionTypeAttribute } from './FunctionTypeAttribute'; +import type { FunctionTypeAttributes } from './FunctionTypeAttributes'; +import type { HexNumberExpression } from './HexNumberExpression'; +import type { HexStringLiteral } from './HexStringLiteral'; +import type { HexStringLiterals } from './HexStringLiterals'; +import type { IdentifierPath } from './IdentifierPath'; +import type { IfStatement } from './IfStatement'; +import type { ImportAlias } from './ImportAlias'; +import type { ImportClause } from './ImportClause'; +import type { ImportDeconstruction } from './ImportDeconstruction'; +import type { ImportDeconstructionSymbol } from './ImportDeconstructionSymbol'; +import type { ImportDeconstructionSymbols } from './ImportDeconstructionSymbols'; +import type { ImportDirective } from './ImportDirective'; +import type { IndexAccessEnd } from './IndexAccessEnd'; +import type { IndexAccessExpression } from './IndexAccessExpression'; +import type { InheritanceSpecifier } from './InheritanceSpecifier'; +import type { InheritanceType } from './InheritanceType'; +import type { InheritanceTypes } from './InheritanceTypes'; +import type { InterfaceDefinition } from './InterfaceDefinition'; +import type { InterfaceMembers } from './InterfaceMembers'; +import type { LibraryDefinition } from './LibraryDefinition'; +import type { LibraryMembers } from './LibraryMembers'; +import type { MappingKey } from './MappingKey'; +import type { MappingKeyType } from './MappingKeyType'; +import type { MappingType } from './MappingType'; +import type { MappingValue } from './MappingValue'; +import type { MemberAccess } from './MemberAccess'; +import type { MemberAccessExpression } from './MemberAccessExpression'; +import type { ModifierAttribute } from './ModifierAttribute'; +import type { ModifierAttributes } from './ModifierAttributes'; +import type { ModifierDefinition } from './ModifierDefinition'; +import type { ModifierInvocation } from './ModifierInvocation'; +import type { MultiplicativeExpression } from './MultiplicativeExpression'; +import type { NamedArgument } from './NamedArgument'; +import type { NamedArgumentGroup } from './NamedArgumentGroup'; +import type { NamedArguments } from './NamedArguments'; +import type { NamedArgumentsDeclaration } from './NamedArgumentsDeclaration'; +import type { NamedImport } from './NamedImport'; +import type { NewExpression } from './NewExpression'; +import type { NumberUnit } from './NumberUnit'; +import type { OrExpression } from './OrExpression'; +import type { OverridePaths } from './OverridePaths'; +import type { OverridePathsDeclaration } from './OverridePathsDeclaration'; +import type { OverrideSpecifier } from './OverrideSpecifier'; +import type { Parameter } from './Parameter'; +import type { Parameters } from './Parameters'; +import type { ParametersDeclaration } from './ParametersDeclaration'; +import type { PathImport } from './PathImport'; +import type { PositionalArguments } from './PositionalArguments'; +import type { PositionalArgumentsDeclaration } from './PositionalArgumentsDeclaration'; +import type { PostfixExpression } from './PostfixExpression'; +import type { Pragma } from './Pragma'; +import type { PragmaDirective } from './PragmaDirective'; +import type { PrefixExpression } from './PrefixExpression'; +import type { ReceiveFunctionAttribute } from './ReceiveFunctionAttribute'; +import type { ReceiveFunctionAttributes } from './ReceiveFunctionAttributes'; +import type { ReceiveFunctionDefinition } from './ReceiveFunctionDefinition'; +import type { ReturnsDeclaration } from './ReturnsDeclaration'; +import type { ReturnStatement } from './ReturnStatement'; +import type { RevertStatement } from './RevertStatement'; +import type { ShiftExpression } from './ShiftExpression'; +import type { SourceUnit } from './SourceUnit'; +import type { SourceUnitMember } from './SourceUnitMember'; +import type { SourceUnitMembers } from './SourceUnitMembers'; +import type { Statement } from './Statement'; +import type { Statements } from './Statements'; +import type { StateVariableAttribute } from './StateVariableAttribute'; +import type { StateVariableAttributes } from './StateVariableAttributes'; +import type { StateVariableDefinition } from './StateVariableDefinition'; +import type { StateVariableDefinitionValue } from './StateVariableDefinitionValue'; +import type { StorageLocation } from './StorageLocation'; +import type { StringExpression } from './StringExpression'; +import type { StringLiteral } from './StringLiteral'; +import type { StringLiterals } from './StringLiterals'; +import type { StructDefinition } from './StructDefinition'; +import type { StructMember } from './StructMember'; +import type { StructMembers } from './StructMembers'; +import type { ThrowStatement } from './ThrowStatement'; +import type { TryStatement } from './TryStatement'; +import type { TupleDeconstructionElement } from './TupleDeconstructionElement'; +import type { TupleDeconstructionElements } from './TupleDeconstructionElements'; +import type { TupleDeconstructionStatement } from './TupleDeconstructionStatement'; +import type { TupleExpression } from './TupleExpression'; +import type { TupleMember } from './TupleMember'; +import type { TupleValue } from './TupleValue'; +import type { TupleValues } from './TupleValues'; +import type { TypedTupleMember } from './TypedTupleMember'; +import type { TypeExpression } from './TypeExpression'; +import type { TypeName } from './TypeName'; +import type { UncheckedBlock } from './UncheckedBlock'; +import type { UnicodeStringLiteral } from './UnicodeStringLiteral'; +import type { UnicodeStringLiterals } from './UnicodeStringLiterals'; +import type { UnnamedFunctionAttribute } from './UnnamedFunctionAttribute'; +import type { UnnamedFunctionAttributes } from './UnnamedFunctionAttributes'; +import type { UnnamedFunctionDefinition } from './UnnamedFunctionDefinition'; +import type { UntypedTupleMember } from './UntypedTupleMember'; +import type { UserDefinedValueTypeDefinition } from './UserDefinedValueTypeDefinition'; +import type { UsingAlias } from './UsingAlias'; +import type { UsingClause } from './UsingClause'; +import type { UsingDeconstruction } from './UsingDeconstruction'; +import type { UsingDeconstructionSymbol } from './UsingDeconstructionSymbol'; +import type { UsingDeconstructionSymbols } from './UsingDeconstructionSymbols'; +import type { UsingDirective } from './UsingDirective'; +import type { UsingOperator } from './UsingOperator'; +import type { UsingTarget } from './UsingTarget'; +import type { VariableDeclarationStatement } from './VariableDeclarationStatement'; +import type { VariableDeclarationType } from './VariableDeclarationType'; +import type { VariableDeclarationValue } from './VariableDeclarationValue'; +import type { VersionComparator } from './VersionComparator'; +import type { VersionExpression } from './VersionExpression'; +import type { VersionExpressionSet } from './VersionExpressionSet'; +import type { VersionExpressionSets } from './VersionExpressionSets'; +import type { VersionPragma } from './VersionPragma'; +import type { VersionRange } from './VersionRange'; +import type { VersionSpecifiers } from './VersionSpecifiers'; +import type { WhileStatement } from './WhileStatement'; +import type { YulArguments } from './YulArguments'; +import type { YulAssignmentOperator } from './YulAssignmentOperator'; +import type { YulBlock } from './YulBlock'; +import type { YulBreakStatement } from './YulBreakStatement'; +import type { YulBuiltInFunction } from './YulBuiltInFunction'; +import type { YulColonEqual } from './YulColonEqual'; +import type { YulContinueStatement } from './YulContinueStatement'; +import type { YulDefaultCase } from './YulDefaultCase'; +import type { YulExpression } from './YulExpression'; +import type { YulForStatement } from './YulForStatement'; +import type { YulFunctionCallExpression } from './YulFunctionCallExpression'; +import type { YulFunctionDefinition } from './YulFunctionDefinition'; +import type { YulIfStatement } from './YulIfStatement'; +import type { YulLabel } from './YulLabel'; +import type { YulLeaveStatement } from './YulLeaveStatement'; +import type { YulLiteral } from './YulLiteral'; +import type { YulParameters } from './YulParameters'; +import type { YulParametersDeclaration } from './YulParametersDeclaration'; +import type { YulPath } from './YulPath'; +import type { YulPathComponent } from './YulPathComponent'; +import type { YulPaths } from './YulPaths'; +import type { YulReturnsDeclaration } from './YulReturnsDeclaration'; +import type { YulReturnVariables } from './YulReturnVariables'; +import type { YulStackAssignmentStatement } from './YulStackAssignmentStatement'; +import type { YulStatement } from './YulStatement'; +import type { YulStatements } from './YulStatements'; +import type { YulSwitchCase } from './YulSwitchCase'; +import type { YulSwitchCases } from './YulSwitchCases'; +import type { YulSwitchStatement } from './YulSwitchStatement'; +import type { YulValueCase } from './YulValueCase'; +import type { YulVariableAssignmentStatement } from './YulVariableAssignmentStatement'; +import type { YulVariableDeclarationStatement } from './YulVariableDeclarationStatement'; +import type { YulVariableDeclarationValue } from './YulVariableDeclarationValue'; + +export type BinaryOperation = + | AdditiveExpression + | MultiplicativeExpression + | ExponentiationExpression + | AssignmentExpression + | BitwiseAndExpression + | BitwiseOrExpression + | BitwiseXorExpression + | ComparisonExpression + | EqualityExpression + | AndExpression + | OrExpression + | ShiftExpression; + +export type FunctionLike = + | ConstructorDefinition + | FallbackFunctionDefinition + | FunctionDefinition + | FunctionType + | ModifierDefinition + | ReceiveFunctionDefinition + | UnnamedFunctionDefinition; + +export type HubNode = + | ArrayValues + | AssemblyFlags + | CallOptions + | CatchClauses + | ConstructorAttributes + | ContractMembers + | EnumMembers + | ErrorParameters + | EventParameters + | FallbackFunctionAttributes + | FunctionAttributes + | FunctionTypeAttributes + | HexStringLiterals + | IdentifierPath + | ImportDeconstructionSymbols + | InheritanceTypes + | InterfaceMembers + | LibraryMembers + | ModifierAttributes + | NamedArguments + | OverridePaths + | Parameters + | ReceiveFunctionAttributes + | SourceUnitMembers + | Statements + | StateVariableAttributes + | StringLiterals + | StructMembers + | TupleDeconstructionElements + | TupleValues + | UnicodeStringLiterals + | UnnamedFunctionAttributes + | UsingDeconstructionSymbols + | VersionExpressionSet + | VersionExpressionSets + | VersionSpecifiers + | YulArguments + | YulParameters + | YulPath + | YulPaths + | YulReturnVariables + | YulStatements + | YulSwitchCases; + +export type AstNode = + | string + | undefined + | SourceUnit + | PragmaDirective + | ABICoderPragma + | ExperimentalPragma + | VersionPragma + | VersionRange + | VersionComparator + | ImportDirective + | PathImport + | NamedImport + | ImportDeconstruction + | ImportDeconstructionSymbol + | ImportAlias + | UsingDirective + | UsingDeconstruction + | UsingDeconstructionSymbol + | UsingAlias + | ContractDefinition + | InheritanceSpecifier + | InheritanceType + | InterfaceDefinition + | LibraryDefinition + | StructDefinition + | StructMember + | EnumDefinition + | ConstantDefinition + | StateVariableDefinition + | StateVariableDefinitionValue + | FunctionDefinition + | ParametersDeclaration + | Parameter + | OverrideSpecifier + | OverridePathsDeclaration + | ReturnsDeclaration + | ConstructorDefinition + | UnnamedFunctionDefinition + | FallbackFunctionDefinition + | ReceiveFunctionDefinition + | ModifierDefinition + | ModifierInvocation + | EventDefinition + | EventParametersDeclaration + | EventParameter + | UserDefinedValueTypeDefinition + | ErrorDefinition + | ErrorParametersDeclaration + | ErrorParameter + | ArrayTypeName + | FunctionType + | MappingType + | MappingKey + | MappingValue + | AddressType + | Block + | UncheckedBlock + | ExpressionStatement + | AssemblyStatement + | AssemblyFlagsDeclaration + | TupleDeconstructionStatement + | TupleDeconstructionElement + | TypedTupleMember + | UntypedTupleMember + | VariableDeclarationStatement + | VariableDeclarationValue + | IfStatement + | ElseBranch + | ForStatement + | WhileStatement + | DoWhileStatement + | ContinueStatement + | BreakStatement + | ReturnStatement + | EmitStatement + | TryStatement + | CatchClause + | CatchClauseError + | RevertStatement + | ThrowStatement + | AssignmentExpression + | ConditionalExpression + | OrExpression + | AndExpression + | EqualityExpression + | ComparisonExpression + | BitwiseOrExpression + | BitwiseXorExpression + | BitwiseAndExpression + | ShiftExpression + | AdditiveExpression + | MultiplicativeExpression + | ExponentiationExpression + | PostfixExpression + | PrefixExpression + | FunctionCallExpression + | CallOptionsExpression + | MemberAccessExpression + | IndexAccessExpression + | IndexAccessEnd + | PositionalArgumentsDeclaration + | NamedArgumentsDeclaration + | NamedArgumentGroup + | NamedArgument + | TypeExpression + | NewExpression + | TupleExpression + | TupleValue + | ArrayExpression + | HexNumberExpression + | DecimalNumberExpression + | YulBlock + | YulFunctionDefinition + | YulParametersDeclaration + | YulReturnsDeclaration + | YulVariableDeclarationStatement + | YulVariableDeclarationValue + | YulVariableAssignmentStatement + | YulStackAssignmentStatement + | YulColonEqual + | YulIfStatement + | YulForStatement + | YulSwitchStatement + | YulDefaultCase + | YulValueCase + | YulLeaveStatement + | YulBreakStatement + | YulContinueStatement + | YulLabel + | YulFunctionCallExpression + | SourceUnitMember + | Pragma + | ExperimentalFeature + | VersionExpression + | ImportClause + | UsingClause + | UsingOperator + | UsingTarget + | ContractMember + | StateVariableAttribute + | FunctionName + | FunctionAttribute + | FunctionBody + | ConstructorAttribute + | UnnamedFunctionAttribute + | FallbackFunctionAttribute + | ReceiveFunctionAttribute + | ModifierAttribute + | TypeName + | FunctionTypeAttribute + | MappingKeyType + | ElementaryType + | Statement + | TupleMember + | VariableDeclarationType + | StorageLocation + | ForStatementInitialization + | ForStatementCondition + | Expression + | MemberAccess + | ArgumentsDeclaration + | NumberUnit + | StringExpression + | StringLiteral + | HexStringLiteral + | UnicodeStringLiteral + | YulStatement + | YulAssignmentOperator + | YulSwitchCase + | YulExpression + | YulPathComponent + | YulBuiltInFunction + | YulLiteral + | SourceUnitMembers + | VersionExpressionSet + | ContractMembers + | InterfaceMembers + | LibraryMembers + | StructMembers + | StateVariableAttributes + | FunctionAttributes + | ConstructorAttributes + | UnnamedFunctionAttributes + | FallbackFunctionAttributes + | ReceiveFunctionAttributes + | ModifierAttributes + | FunctionTypeAttributes + | Statements + | CatchClauses + | StringLiterals + | HexStringLiterals + | UnicodeStringLiterals + | YulStatements + | YulSwitchCases + | VersionExpressionSets + | VersionSpecifiers + | ImportDeconstructionSymbols + | UsingDeconstructionSymbols + | InheritanceTypes + | EnumMembers + | Parameters + | OverridePaths + | EventParameters + | ErrorParameters + | AssemblyFlags + | TupleDeconstructionElements + | PositionalArguments + | NamedArguments + | CallOptions + | TupleValues + | ArrayValues + | IdentifierPath + | YulParameters + | YulReturnVariables + | YulArguments + | YulPaths + | YulPath; + +export type StrictAstNode = Exclude; diff --git a/src/slang-printers/create-binary-operation-printer.ts b/src/slang-printers/create-binary-operation-printer.ts index f9bb47a40..aa01eb45f 100644 --- a/src/slang-printers/create-binary-operation-printer.ts +++ b/src/slang-printers/create-binary-operation-printer.ts @@ -2,12 +2,8 @@ import { doc } from 'prettier'; import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { - AstNode, - BinaryOperation, - PrintFunction, - StrictAstNode -} from '../types'; +import type { AstNode, BinaryOperation, StrictAstNode } from '../slang-nodes'; +import type { PrintFunction } from '../types'; const { group, line } = doc.builders; diff --git a/src/slang-printers/print-binary-operation.ts b/src/slang-printers/print-binary-operation.ts index 4042e1722..ec8d510b8 100644 --- a/src/slang-printers/print-binary-operation.ts +++ b/src/slang-printers/print-binary-operation.ts @@ -4,7 +4,7 @@ import { createBinaryOperationPrinter } from './create-binary-operation-printer. import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode, BinaryOperation, StrictAstNode } from '../types'; +import type { AstNode, BinaryOperation, StrictAstNode } from '../slang-nodes'; const { group, indent } = doc.builders; diff --git a/src/slang-printers/print-comments.ts b/src/slang-printers/print-comments.ts index 39927a3a9..f8d5c72a5 100644 --- a/src/slang-printers/print-comments.ts +++ b/src/slang-printers/print-comments.ts @@ -3,7 +3,7 @@ import { printComment } from '../slang-comments/printer.js'; import { isPrettier2 } from '../slang-utils/backward-compatibility.js'; import type { AstPath, Doc } from 'prettier'; -import type { AstNode } from '../types'; +import type { AstNode } from '../slang-nodes'; import type { DocV2 } from './types'; const { join, line } = doc.builders; diff --git a/src/slang-printers/print-comparison-operation.ts b/src/slang-printers/print-comparison-operation.ts index f5d192d3d..c25182434 100644 --- a/src/slang-printers/print-comparison-operation.ts +++ b/src/slang-printers/print-comparison-operation.ts @@ -5,7 +5,7 @@ import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; import { createBinaryOperationPrinter } from './create-binary-operation-printer.js'; import type { AstPath, Doc } from 'prettier'; -import type { BinaryOperation, StrictAstNode } from '../types'; +import type { BinaryOperation, StrictAstNode } from '../slang-nodes'; const { group, indent } = doc.builders; diff --git a/src/slang-printers/print-function.ts b/src/slang-printers/print-function.ts index 3cdb604f3..e7a55ea50 100644 --- a/src/slang-printers/print-function.ts +++ b/src/slang-printers/print-function.ts @@ -1,8 +1,9 @@ import { doc } from 'prettier'; import type { AstPath, Doc } from 'prettier'; -import type { FunctionLike, PrintFunction } from '../types'; -import type { FunctionDefinition } from '../slang-nodes'; +import type { FunctionLike } from '../slang-nodes'; +import type { PrintFunction } from '../types'; +import type { FunctionDefinition } from '../slang-nodes/FunctionDefinition'; const { dedent, group, indent, line } = doc.builders; diff --git a/src/slang-printers/print-logical-operation.ts b/src/slang-printers/print-logical-operation.ts index 31f43c116..6207f2d38 100644 --- a/src/slang-printers/print-logical-operation.ts +++ b/src/slang-printers/print-logical-operation.ts @@ -5,7 +5,7 @@ import { isBinaryOperation } from '../slang-utils/is-binary-operation.js'; import { createBinaryOperationPrinter } from './create-binary-operation-printer.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, BinaryOperation, StrictAstNode } from '../types'; +import type { AstNode, BinaryOperation, StrictAstNode } from '../slang-nodes'; const { group, indent } = doc.builders; diff --git a/src/slang-printers/print-preserving-empty-lines.ts b/src/slang-printers/print-preserving-empty-lines.ts index bbc46297f..0fd77c953 100644 --- a/src/slang-printers/print-preserving-empty-lines.ts +++ b/src/slang-printers/print-preserving-empty-lines.ts @@ -7,7 +7,8 @@ import { import { locEnd } from '../slang-utils/loc.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, HubNode, PrintFunction, StrictAstNode } from '../types'; +import type { AstNode, HubNode, StrictAstNode } from '../slang-nodes'; +import type { PrintFunction } from '../types'; const { hardline } = doc.builders; diff --git a/src/slang-printers/print-string.ts b/src/slang-printers/print-string.ts index eed964eb8..beef30a12 100644 --- a/src/slang-printers/print-string.ts +++ b/src/slang-printers/print-string.ts @@ -1,7 +1,7 @@ import { util } from 'prettier'; import type { ParserOptions } from 'prettier'; -import type { AstNode } from '../types'; +import type { AstNode } from '../slang-nodes'; const SINGLE_QUOTE: util.Quote = "'"; const DOUBLE_QUOTE: util.Quote = '"'; diff --git a/src/slang-utils/backward-compatibility.ts b/src/slang-utils/backward-compatibility.ts index 6c7a52564..d2548f6c3 100644 --- a/src/slang-utils/backward-compatibility.ts +++ b/src/slang-utils/backward-compatibility.ts @@ -4,7 +4,8 @@ import { locEnd } from './loc.js'; import type { AstPath } from 'prettier'; import type { utilV2 } from './types'; -import type { AstNode, Comment, HubNode } from '../types'; +import type { AstNode, HubNode } from '../slang-nodes'; +import type { Comment } from '../types'; export const isPrettier2 = prettierVersionSatisfies('^2.3.0'); diff --git a/src/slang-utils/create-kind-check-function.ts b/src/slang-utils/create-kind-check-function.ts index 39aa40102..f6f5bb511 100644 --- a/src/slang-utils/create-kind-check-function.ts +++ b/src/slang-utils/create-kind-check-function.ts @@ -1,5 +1,6 @@ import type { Node } from '@nomicfoundation/slang/cst'; -import type { Comment, StrictAstNode } from '../types'; +import type { StrictAstNode } from '../slang-nodes'; +import type { Comment } from '../types'; export function createKindCheckFunction( kindsArray: string[] diff --git a/src/slang-utils/is-binary-operation.ts b/src/slang-utils/is-binary-operation.ts index bbe9a95d7..362b4bc34 100644 --- a/src/slang-utils/is-binary-operation.ts +++ b/src/slang-utils/is-binary-operation.ts @@ -1,7 +1,7 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { createKindCheckFunction } from './create-kind-check-function.js'; -import type { BinaryOperation, StrictAstNode } from '../types'; +import type { BinaryOperation, StrictAstNode } from '../slang-nodes'; export const isBinaryOperation = createKindCheckFunction([ NonterminalKind.AdditiveExpression, diff --git a/src/slang-utils/is-comment.ts b/src/slang-utils/is-comment.ts index 05a51abf6..6560fbc19 100644 --- a/src/slang-utils/is-comment.ts +++ b/src/slang-utils/is-comment.ts @@ -2,7 +2,8 @@ import { TerminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { createKindCheckFunction } from './create-kind-check-function.js'; import type { Node } from '@nomicfoundation/slang/cst'; -import type { AstNode, BlockComment, Comment, LineComment } from '../types'; +import type { AstNode } from '../slang-nodes'; +import type { BlockComment, Comment, LineComment } from '../types'; export const isBlockComment = createKindCheckFunction([ TerminalKind.MultiLineComment, diff --git a/src/slang-utils/loc.ts b/src/slang-utils/loc.ts index b0f107c1b..56dc9f5aa 100644 --- a/src/slang-utils/loc.ts +++ b/src/slang-utils/loc.ts @@ -1,4 +1,5 @@ -import type { AstNode, Comment } from '../types'; +import type { AstNode, StrictAstNode } from '../slang-nodes'; +import type { Comment } from '../types'; export function locStart(node: AstNode | Comment): number { if (typeof node === 'string' || typeof node === 'undefined') return -1; diff --git a/src/slang-utils/metadata.ts b/src/slang-utils/metadata.ts index 94446fe01..f3199ee73 100644 --- a/src/slang-utils/metadata.ts +++ b/src/slang-utils/metadata.ts @@ -3,7 +3,8 @@ import { NodeType } from '@nomicfoundation/slang/cst/index.js'; import { isComment } from './is-comment.js'; import type { Node } from '@nomicfoundation/slang/cst'; -import type { Comment, Metadata, SlangAstNode, StrictAstNode } from '../types'; +import type { StrictAstNode } from '../slang-nodes'; +import type { Comment, Metadata, SlangAstNode } from '../types'; function getLeadingOffset(children: Node[]): number { let offset = 0; diff --git a/src/slang-utils/types.d.ts b/src/slang-utils/types.d.ts index a6496d865..0e9dfdc3f 100644 --- a/src/slang-utils/types.d.ts +++ b/src/slang-utils/types.d.ts @@ -1,15 +1,14 @@ import type { util } from 'prettier'; -import type { - ConstructorAttribute, - FallbackFunctionAttribute, - FunctionAttribute, - FunctionTypeAttribute, - ModifierAttribute, - ReceiveFunctionAttribute, - StateVariableAttribute, - UnnamedFunctionAttribute -} from '../slang-nodes'; -import type { AstNode, Comment } from '../types'; +import type { ConstructorAttribute } from '../slang-nodes/ConstructorAttribute'; +import type { FallbackFunctionAttribute } from '../slang-nodes/FallbackFunctionAttribute'; +import type { FunctionAttribute } from '../slang-nodes/FunctionAttribute'; +import type { FunctionTypeAttribute } from '../slang-nodes/FunctionTypeAttribute'; +import type { ModifierAttribute } from '../slang-nodes/ModifierAttribute'; +import type { ReceiveFunctionAttribute } from '../slang-nodes/ReceiveFunctionAttribute'; +import type { StateVariableAttribute } from '../slang-nodes/StateVariableAttribute'; +import type { UnnamedFunctionAttribute } from '../slang-nodes/UnnamedFunctionAttribute'; +import type { AstNode } from '../slang-nodes'; +import type { Comment } from '../types'; type SortableAttribute = | ConstructorAttribute diff --git a/src/slangParser.ts b/src/slangParser.ts index 6eaee643a..160ccc4c4 100644 --- a/src/slangParser.ts +++ b/src/slangParser.ts @@ -8,7 +8,7 @@ import { SourceUnit } from './slang-nodes/SourceUnit.js'; import type { NonterminalNode } from '@nomicfoundation/slang/cst'; import type { Parser, ParserOptions } from 'prettier'; -import type { AstNode } from './types'; +import type { AstNode } from './slang-nodes'; export default function parse( text: string, diff --git a/src/slangPrinter.ts b/src/slangPrinter.ts index f7b791fc2..2f2f7faf0 100644 --- a/src/slangPrinter.ts +++ b/src/slangPrinter.ts @@ -3,7 +3,8 @@ import { isBlockComment } from './slang-utils/is-comment.js'; import { locEnd, locStart } from './slang-utils/loc.js'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type { AstNode, PrintFunction, StrictAstNode } from './types'; +import type { AstNode, StrictAstNode } from './slang-nodes'; +import type { PrintFunction } from './types'; let checked = false; diff --git a/src/types.d.ts b/src/types.d.ts index 6d816a522..00f1a6687 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -1,7 +1,7 @@ import type { kinds } from '@nomicfoundation/slang/napi-bindings/generated'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; -import type * as nodes from './slang-nodes'; +import type { AstNode, StrictAstNode } from './slang-nodes'; // Adding our own options to prettier's `ParserOptions` interface. declare module 'prettier' { @@ -62,295 +62,6 @@ interface SlangNode { ): Doc; } -export type BinaryOperation = - | nodes.AdditiveExpression - | nodes.MultiplicativeExpression - | nodes.ExponentiationExpression - | nodes.AssignmentExpression - | nodes.BitwiseAndExpression - | nodes.BitwiseOrExpression - | nodes.BitwiseXorExpression - | nodes.ComparisonExpression - | nodes.EqualityExpression - | nodes.AndExpression - | nodes.OrExpression - | nodes.ShiftExpression; - -export type FunctionLike = - | nodes.ConstructorDefinition - | nodes.FallbackFunctionDefinition - | nodes.FunctionDefinition - | nodes.FunctionType - | nodes.ModifierDefinition - | nodes.ReceiveFunctionDefinition - | nodes.UnnamedFunctionDefinition; - -export type HubNode = - | nodes.ArrayValues - | nodes.AssemblyFlags - | nodes.CallOptions - | nodes.CatchClauses - | nodes.ConstructorAttributes - | nodes.ContractMembers - | nodes.EnumMembers - | nodes.ErrorParameters - | nodes.EventParameters - | nodes.FallbackFunctionAttributes - | nodes.FunctionAttributes - | nodes.FunctionTypeAttributes - | nodes.HexStringLiterals - | nodes.IdentifierPath - | nodes.ImportDeconstructionSymbols - | nodes.InheritanceTypes - | nodes.InterfaceMembers - | nodes.LibraryMembers - | nodes.ModifierAttributes - | nodes.NamedArguments - | nodes.OverridePaths - | nodes.Parameters - | nodes.ReceiveFunctionAttributes - | nodes.SourceUnitMembers - | nodes.Statements - | nodes.StateVariableAttributes - | nodes.StringLiterals - | nodes.StructMembers - | nodes.TupleDeconstructionElements - | nodes.TupleValues - | nodes.UnicodeStringLiterals - | nodes.UnnamedFunctionAttributes - | nodes.UsingDeconstructionSymbols - | nodes.VersionExpressionSet - | nodes.VersionExpressionSets - | nodes.VersionSpecifiers - | nodes.YulArguments - | nodes.YulParameters - | nodes.YulPath - | nodes.YulPaths - | nodes.YulReturnVariables - | nodes.YulStatements - | nodes.YulSwitchCases; - -export type AstNode = - | string - | undefined - | nodes.SourceUnit - | nodes.PragmaDirective - | nodes.ABICoderPragma - | nodes.ExperimentalPragma - | nodes.VersionPragma - | nodes.VersionRange - | nodes.VersionComparator - | nodes.ImportDirective - | nodes.PathImport - | nodes.NamedImport - | nodes.ImportDeconstruction - | nodes.ImportDeconstructionSymbol - | nodes.ImportAlias - | nodes.UsingDirective - | nodes.UsingDeconstruction - | nodes.UsingDeconstructionSymbol - | nodes.UsingAlias - | nodes.ContractDefinition - | nodes.InheritanceSpecifier - | nodes.InheritanceType - | nodes.InterfaceDefinition - | nodes.LibraryDefinition - | nodes.StructDefinition - | nodes.StructMember - | nodes.EnumDefinition - | nodes.ConstantDefinition - | nodes.StateVariableDefinition - | nodes.StateVariableDefinitionValue - | nodes.FunctionDefinition - | nodes.ParametersDeclaration - | nodes.Parameter - | nodes.OverrideSpecifier - | nodes.OverridePathsDeclaration - | nodes.ReturnsDeclaration - | nodes.ConstructorDefinition - | nodes.UnnamedFunctionDefinition - | nodes.FallbackFunctionDefinition - | nodes.ReceiveFunctionDefinition - | nodes.ModifierDefinition - | nodes.ModifierInvocation - | nodes.EventDefinition - | nodes.EventParametersDeclaration - | nodes.EventParameter - | nodes.UserDefinedValueTypeDefinition - | nodes.ErrorDefinition - | nodes.ErrorParametersDeclaration - | nodes.ErrorParameter - | nodes.ArrayTypeName - | nodes.FunctionType - | nodes.MappingType - | nodes.MappingKey - | nodes.MappingValue - | nodes.AddressType - | nodes.Block - | nodes.UncheckedBlock - | nodes.ExpressionStatement - | nodes.AssemblyStatement - | nodes.AssemblyFlagsDeclaration - | nodes.TupleDeconstructionStatement - | nodes.TupleDeconstructionElement - | nodes.TypedTupleMember - | nodes.UntypedTupleMember - | nodes.VariableDeclarationStatement - | nodes.VariableDeclarationValue - | nodes.IfStatement - | nodes.ElseBranch - | nodes.ForStatement - | nodes.WhileStatement - | nodes.DoWhileStatement - | nodes.ContinueStatement - | nodes.BreakStatement - | nodes.ReturnStatement - | nodes.EmitStatement - | nodes.TryStatement - | nodes.CatchClause - | nodes.CatchClauseError - | nodes.RevertStatement - | nodes.ThrowStatement - | nodes.AssignmentExpression - | nodes.ConditionalExpression - | nodes.OrExpression - | nodes.AndExpression - | nodes.EqualityExpression - | nodes.ComparisonExpression - | nodes.BitwiseOrExpression - | nodes.BitwiseXorExpression - | nodes.BitwiseAndExpression - | nodes.ShiftExpression - | nodes.AdditiveExpression - | nodes.MultiplicativeExpression - | nodes.ExponentiationExpression - | nodes.PostfixExpression - | nodes.PrefixExpression - | nodes.FunctionCallExpression - | nodes.CallOptionsExpression - | nodes.MemberAccessExpression - | nodes.IndexAccessExpression - | nodes.IndexAccessEnd - | nodes.PositionalArgumentsDeclaration - | nodes.NamedArgumentsDeclaration - | nodes.NamedArgumentGroup - | nodes.NamedArgument - | nodes.TypeExpression - | nodes.NewExpression - | nodes.TupleExpression - | nodes.TupleValue - | nodes.ArrayExpression - | nodes.HexNumberExpression - | nodes.DecimalNumberExpression - | nodes.YulBlock - | nodes.YulFunctionDefinition - | nodes.YulParametersDeclaration - | nodes.YulReturnsDeclaration - | nodes.YulVariableDeclarationStatement - | nodes.YulVariableDeclarationValue - | nodes.YulVariableAssignmentStatement - | nodes.YulStackAssignmentStatement - | nodes.YulColonEqual - | nodes.YulIfStatement - | nodes.YulForStatement - | nodes.YulSwitchStatement - | nodes.YulDefaultCase - | nodes.YulValueCase - | nodes.YulLeaveStatement - | nodes.YulBreakStatement - | nodes.YulContinueStatement - | nodes.YulLabel - | nodes.YulFunctionCallExpression - | nodes.SourceUnitMember - | nodes.Pragma - | nodes.ExperimentalFeature - | nodes.VersionExpression - | nodes.ImportClause - | nodes.UsingClause - | nodes.UsingOperator - | nodes.UsingTarget - | nodes.ContractMember - | nodes.StateVariableAttribute - | nodes.FunctionName - | nodes.FunctionAttribute - | nodes.FunctionBody - | nodes.ConstructorAttribute - | nodes.UnnamedFunctionAttribute - | nodes.FallbackFunctionAttribute - | nodes.ReceiveFunctionAttribute - | nodes.ModifierAttribute - | nodes.TypeName - | nodes.FunctionTypeAttribute - | nodes.MappingKeyType - | nodes.ElementaryType - | nodes.Statement - | nodes.TupleMember - | nodes.VariableDeclarationType - | nodes.StorageLocation - | nodes.ForStatementInitialization - | nodes.ForStatementCondition - | nodes.Expression - | nodes.MemberAccess - | nodes.ArgumentsDeclaration - | nodes.NumberUnit - | nodes.StringExpression - | nodes.StringLiteral - | nodes.HexStringLiteral - | nodes.UnicodeStringLiteral - | nodes.YulStatement - | nodes.YulAssignmentOperator - | nodes.YulSwitchCase - | nodes.YulExpression - | nodes.YulPathComponent - | nodes.YulBuiltInFunction - | nodes.YulLiteral - | nodes.SourceUnitMembers - | nodes.VersionExpressionSet - | nodes.ContractMembers - | nodes.InterfaceMembers - | nodes.LibraryMembers - | nodes.StructMembers - | nodes.StateVariableAttributes - | nodes.FunctionAttributes - | nodes.ConstructorAttributes - | nodes.UnnamedFunctionAttributes - | nodes.FallbackFunctionAttributes - | nodes.ReceiveFunctionAttributes - | nodes.ModifierAttributes - | nodes.FunctionTypeAttributes - | nodes.Statements - | nodes.CatchClauses - | nodes.StringLiterals - | nodes.HexStringLiterals - | nodes.UnicodeStringLiterals - | nodes.YulStatements - | nodes.YulSwitchCases - | nodes.VersionExpressionSets - | nodes.VersionSpecifiers - | nodes.ImportDeconstructionSymbols - | nodes.UsingDeconstructionSymbols - | nodes.InheritanceTypes - | nodes.EnumMembers - | nodes.Parameters - | nodes.OverridePaths - | nodes.EventParameters - | nodes.ErrorParameters - | nodes.AssemblyFlags - | nodes.TupleDeconstructionElements - | nodes.PositionalArguments - | nodes.NamedArguments - | nodes.CallOptions - | nodes.TupleValues - | nodes.ArrayValues - | nodes.IdentifierPath - | nodes.YulParameters - | nodes.YulReturnVariables - | nodes.YulArguments - | nodes.YulPaths - | nodes.YulPath; - -type StrictAstNode = Exclude; - type PrintFunction = (path: AstPath) => Doc; export type SlangAstNode = diff --git a/tests/config/run-format-test.js b/tests/config/run-format-test.js index 75a7fe709..e7e1046c4 100644 --- a/tests/config/run-format-test.js +++ b/tests/config/run-format-test.js @@ -44,7 +44,7 @@ const testsWithSlang = new Map( [ // "AllSolidityFeatures/AllSolidityFeatures.sol", // "AssemblyV0.4.26/Assembly.sol", // TODO: Wait for Nomic Foundation's response - // "Comments/Comments.sol", // TODO: finish Comments + "Comments/Comments.sol", // TODO: finish Comments ].map((fixture) => { const [file, testSlang = () => true] = Array.isArray(fixture) ? fixture diff --git a/tests/format/AssemblyV0.4.26/Assembly.sol b/tests/format/AssemblyV0.4.26/Assembly.sol index a417cad4c..dddccb54c 100644 --- a/tests/format/AssemblyV0.4.26/Assembly.sol +++ b/tests/format/AssemblyV0.4.26/Assembly.sol @@ -25,7 +25,7 @@ assembly{ // but the assembler thinks it is 1 because it reads // from top to bottom. // Accessing the stack variable x here will lead to errors. - x : = 9 + x := 9 jump(three) two: 7 // push something onto the stack diff --git a/tests/format/AssemblyV0.4.26/__snapshots__/format.test.js.snap b/tests/format/AssemblyV0.4.26/__snapshots__/format.test.js.snap index 4055715a0..d249ad2e4 100644 --- a/tests/format/AssemblyV0.4.26/__snapshots__/format.test.js.snap +++ b/tests/format/AssemblyV0.4.26/__snapshots__/format.test.js.snap @@ -3,7 +3,7 @@ exports[`Assembly.sol - {"compiler":"0.4.26"} format 1`] = ` ====================================options===================================== compiler: "0.4.26" -parsers: ["slang"] +parsers: ["solidity-parse"] printWidth: 80 | printWidth =====================================input====================================== @@ -34,7 +34,7 @@ assembly{ // but the assembler thinks it is 1 because it reads // from top to bottom. // Accessing the stack variable x here will lead to errors. - x : = 9 + x := 9 jump(three) two: 7 // push something onto the stack @@ -113,7 +113,7 @@ contract MultipleAssemblyAssignment { b := 2 } - let i + let i, j := bar() } } } @@ -121,7 +121,7 @@ contract MultipleAssemblyAssignment { contract AssemblyStackAssignment { function f() public { assembly { - 4 + 4 =: y } } } diff --git a/tests/format/AssemblyV0.4.26/format.test.js b/tests/format/AssemblyV0.4.26/format.test.js index 85c6f9a33..94898ac13 100644 --- a/tests/format/AssemblyV0.4.26/format.test.js +++ b/tests/format/AssemblyV0.4.26/format.test.js @@ -1 +1 @@ -runFormatTest(import.meta, ['slang'], { compiler: '0.4.26' }); +runFormatTest(import.meta, ['solidity-parse'], { compiler: '0.4.26' }); From 7bca7601d6359d48357ca5730da992f0f50c78dd Mon Sep 17 00:00:00 2001 From: Klaus Date: Thu, 8 Aug 2024 13:22:17 +1200 Subject: [PATCH 122/160] updating to the last version of slang and fixing the grammar changes --- src/slang-nodes/ContractMembers.ts | 2 +- src/slang-nodes/MemberAccessExpression.ts | 9 ++-- src/slang-nodes/Parameters.ts | 2 +- src/slang-nodes/PositionalArguments.ts | 11 ++++- src/slang-nodes/Statements.ts | 2 +- src/slang-nodes/YulAssignmentOperator.ts | 6 +-- .../{YulColonEqual.ts => YulColonAndEqual.ts} | 6 +-- .../{MemberAccess.ts => YulEqualAndColon.ts} | 12 ++--- src/slang-nodes/YulReturnsDeclaration.ts | 6 +-- src/slang-nodes/YulStackAssignmentOperator.ts | 42 +++++++++++++++++ .../YulStackAssignmentStatement.ts | 46 ++++++++++--------- src/slang-nodes/YulStatement.ts | 3 +- src/slang-nodes/YulStatements.ts | 2 +- .../YulVariableAssignmentStatement.ts | 8 ++-- .../YulVariableDeclarationStatement.ts | 14 ++++-- ...ReturnVariables.ts => YulVariableNames.ts} | 8 ++-- src/slang-nodes/index.d.ts | 19 ++++---- src/slang-printers/print-comments.ts | 2 +- src/types.d.ts | 10 ++-- tests/config/run-format-test.js | 3 +- .../__snapshots__/format.test.js.snap | 5 +- tests/format/AssemblyV0.4.26/format.test.js | 2 +- 22 files changed, 138 insertions(+), 82 deletions(-) rename src/slang-nodes/{YulColonEqual.ts => YulColonAndEqual.ts} (73%) rename src/slang-nodes/{MemberAccess.ts => YulEqualAndColon.ts} (65%) create mode 100644 src/slang-nodes/YulStackAssignmentOperator.ts rename src/slang-nodes/{YulReturnVariables.ts => YulVariableNames.ts} (83%) diff --git a/src/slang-nodes/ContractMembers.ts b/src/slang-nodes/ContractMembers.ts index 2ea431de0..70fe2078e 100644 --- a/src/slang-nodes/ContractMembers.ts +++ b/src/slang-nodes/ContractMembers.ts @@ -50,7 +50,7 @@ export class ContractMembers implements SlangNode { : printSeparatedItem( [ printPreservingEmptyLines(path, print, options), - printComments(this, path) + printComments(path) ], { firstSeparator: hardline, grouped: false } ); diff --git a/src/slang-nodes/MemberAccessExpression.ts b/src/slang-nodes/MemberAccessExpression.ts index 67412517b..17c4a9cec 100644 --- a/src/slang-nodes/MemberAccessExpression.ts +++ b/src/slang-nodes/MemberAccessExpression.ts @@ -4,7 +4,6 @@ import { isLabel } from '../slang-utils/is-label.js'; import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; -import { MemberAccess } from './MemberAccess.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; @@ -131,7 +130,7 @@ export class MemberAccessExpression implements SlangNode { period: string; - member: MemberAccess; + member: string; constructor( ast: ast.MemberAccessExpression, @@ -143,9 +142,9 @@ export class MemberAccessExpression implements SlangNode { this.operand = new Expression(ast.operand, offsets[0], options); this.period = ast.period.text; - this.member = new MemberAccess(ast.member, offsets[1]); + this.member = ast.member.text; - metadata = updateMetadata(metadata, [this.operand, this.member]); + metadata = updateMetadata(metadata, [this.operand]); this.comments = metadata.comments; this.loc = metadata.loc; @@ -160,7 +159,7 @@ export class MemberAccessExpression implements SlangNode { const document = [ operandDoc, label('separator', [softline, this.period]), - path.call(print, 'member') + this.member ].flat(); return isEndOfChain(this, path) ? processChain(document) : document; diff --git a/src/slang-nodes/Parameters.ts b/src/slang-nodes/Parameters.ts index ed3265c2e..0a4953789 100644 --- a/src/slang-nodes/Parameters.ts +++ b/src/slang-nodes/Parameters.ts @@ -45,7 +45,7 @@ export class Parameters implements SlangNode { return printSeparatedList(path.map(print, 'items'), { grouped: false }); } - const parameterComments = printComments(this, path); + const parameterComments = printComments(path); return parameterComments.length > 0 ? printSeparatedItem(parameterComments) diff --git a/src/slang-nodes/PositionalArguments.ts b/src/slang-nodes/PositionalArguments.ts index 023a75073..bdb38c5f5 100644 --- a/src/slang-nodes/PositionalArguments.ts +++ b/src/slang-nodes/PositionalArguments.ts @@ -1,4 +1,6 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { printComments } from '../slang-printers/print-comments.js'; +import { printSeparatedItem } from '../slang-printers/print-separated-item.js'; import { printSeparatedList } from '../slang-printers/print-separated-list.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; @@ -39,8 +41,13 @@ export class PositionalArguments implements SlangNode { } print(path: AstPath, print: PrintFunction): Doc { - return this.items.length > 0 - ? printSeparatedList(path.map(print, 'items')) + if (this.items.length > 0) { + return printSeparatedList(path.map(print, 'items')); + } + const argumentComments = printComments(path); + + return argumentComments.length > 0 + ? printSeparatedItem(argumentComments) : ''; } } diff --git a/src/slang-nodes/Statements.ts b/src/slang-nodes/Statements.ts index 6cb8ee665..c261236d6 100644 --- a/src/slang-nodes/Statements.ts +++ b/src/slang-nodes/Statements.ts @@ -50,7 +50,7 @@ export class Statements implements SlangNode { : printSeparatedItem( [ printPreservingEmptyLines(path, print, options), - printComments(this, path) + printComments(path) ], { firstSeparator: hardline, diff --git a/src/slang-nodes/YulAssignmentOperator.ts b/src/slang-nodes/YulAssignmentOperator.ts index ffeb05768..eb7efcbb2 100644 --- a/src/slang-nodes/YulAssignmentOperator.ts +++ b/src/slang-nodes/YulAssignmentOperator.ts @@ -1,7 +1,7 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; -import { YulColonEqual } from './YulColonEqual.js'; +import { YulColonAndEqual } from './YulColonAndEqual.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; @@ -14,7 +14,7 @@ export class YulAssignmentOperator implements SlangNode { loc; - variant: YulColonEqual | string; + variant: YulColonAndEqual | string; constructor(ast: ast.YulAssignmentOperator, offset: number) { let metadata = getNodeMetadata(ast, offset); @@ -23,7 +23,7 @@ export class YulAssignmentOperator implements SlangNode { this.variant = ast.variant instanceof TerminalNode ? ast.variant.text - : new YulColonEqual(ast.variant, offsets[0]); + : new YulColonAndEqual(ast.variant, offsets[0]); metadata = updateMetadata( metadata, diff --git a/src/slang-nodes/YulColonEqual.ts b/src/slang-nodes/YulColonAndEqual.ts similarity index 73% rename from src/slang-nodes/YulColonEqual.ts rename to src/slang-nodes/YulColonAndEqual.ts index b3eb3cc0c..ed7fe8bc0 100644 --- a/src/slang-nodes/YulColonEqual.ts +++ b/src/slang-nodes/YulColonAndEqual.ts @@ -5,14 +5,14 @@ import type * as ast from '@nomicfoundation/slang/ast'; import type { Doc } from 'prettier'; import type { SlangNode } from '../types'; -export class YulColonEqual implements SlangNode { - readonly kind = NonterminalKind.YulColonEqual; +export class YulColonAndEqual implements SlangNode { + readonly kind = NonterminalKind.YulColonAndEqual; comments; loc; - constructor(ast: ast.YulColonEqual, offset: number) { + constructor(ast: ast.YulColonAndEqual, offset: number) { const metadata = getNodeMetadata(ast, offset); this.comments = metadata.comments; diff --git a/src/slang-nodes/MemberAccess.ts b/src/slang-nodes/YulEqualAndColon.ts similarity index 65% rename from src/slang-nodes/MemberAccess.ts rename to src/slang-nodes/YulEqualAndColon.ts index c89f8aa6a..ab138530f 100644 --- a/src/slang-nodes/MemberAccess.ts +++ b/src/slang-nodes/YulEqualAndColon.ts @@ -5,25 +5,21 @@ import type * as ast from '@nomicfoundation/slang/ast'; import type { Doc } from 'prettier'; import type { SlangNode } from '../types'; -export class MemberAccess implements SlangNode { - readonly kind = NonterminalKind.MemberAccess; +export class YulEqualAndColon implements SlangNode { + readonly kind = NonterminalKind.YulEqualAndColon; comments; loc; - variant: string; - - constructor(ast: ast.MemberAccess, offset: number) { + constructor(ast: ast.YulEqualAndColon, offset: number) { const metadata = getNodeMetadata(ast, offset); - this.variant = ast.variant.text; - this.comments = metadata.comments; this.loc = metadata.loc; } print(): Doc { - return this.variant; + return '=:'; } } diff --git a/src/slang-nodes/YulReturnsDeclaration.ts b/src/slang-nodes/YulReturnsDeclaration.ts index becc0cc11..3c01f1a11 100644 --- a/src/slang-nodes/YulReturnsDeclaration.ts +++ b/src/slang-nodes/YulReturnsDeclaration.ts @@ -2,7 +2,7 @@ import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { printSeparatedItem } from '../slang-printers/print-separated-item.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; -import { YulReturnVariables } from './YulReturnVariables.js'; +import { YulVariableNames } from './YulVariableNames.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; @@ -19,14 +19,14 @@ export class YulReturnsDeclaration implements SlangNode { minusGreaterThan: string; - variables: YulReturnVariables; + variables: YulVariableNames; constructor(ast: ast.YulReturnsDeclaration, offset: number) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; this.minusGreaterThan = ast.minusGreaterThan.text; - this.variables = new YulReturnVariables(ast.variables, offsets[0]); + this.variables = new YulVariableNames(ast.variables, offsets[0]); metadata = updateMetadata(metadata, [this.variables]); diff --git a/src/slang-nodes/YulStackAssignmentOperator.ts b/src/slang-nodes/YulStackAssignmentOperator.ts new file mode 100644 index 000000000..7f0e5d113 --- /dev/null +++ b/src/slang-nodes/YulStackAssignmentOperator.ts @@ -0,0 +1,42 @@ +import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { TerminalNode } from '@nomicfoundation/slang/cst/index.js'; +import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; +import { YulEqualAndColon } from './YulEqualAndColon.js'; + +import type * as ast from '@nomicfoundation/slang/ast'; +import type { AstPath, Doc } from 'prettier'; +import type { PrintFunction, SlangNode } from '../types'; + +export class YulStackAssignmentOperator implements SlangNode { + readonly kind = NonterminalKind.YulStackAssignmentOperator; + + comments; + + loc; + + variant: YulEqualAndColon | string; + + constructor(ast: ast.YulStackAssignmentOperator, offset: number) { + let metadata = getNodeMetadata(ast, offset); + const { offsets } = metadata; + + this.variant = + ast.variant instanceof TerminalNode + ? ast.variant.text + : new YulEqualAndColon(ast.variant, offsets[0]); + + metadata = updateMetadata( + metadata, + typeof this.variant === 'string' ? [] : [this.variant] + ); + + this.comments = metadata.comments; + this.loc = metadata.loc; + } + + print(path: AstPath, print: PrintFunction): Doc { + return typeof this.variant === 'string' + ? this.variant + : path.call(print, 'variant'); + } +} diff --git a/src/slang-nodes/YulStackAssignmentStatement.ts b/src/slang-nodes/YulStackAssignmentStatement.ts index f59e42e73..1d772b0dd 100644 --- a/src/slang-nodes/YulStackAssignmentStatement.ts +++ b/src/slang-nodes/YulStackAssignmentStatement.ts @@ -1,12 +1,14 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { doc } from 'prettier'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; -import { YulAssignmentOperator } from './YulAssignmentOperator.js'; -import { YulExpression } from './YulExpression.js'; +import { YulStackAssignmentOperator } from './YulStackAssignmentOperator.js'; import type * as ast from '@nomicfoundation/slang/ast'; -import type { /*AstPath,*/ Doc, ParserOptions } from 'prettier'; -import type { AstNode } from '../slang-nodes'; -import type { SlangNode } from '../types'; +import type { AstPath, Doc } from 'prettier'; +import type { PrintFunction, SlangNode } from '../types'; +import { printSeparatedItem } from '../slang-printers/print-separated-item.js'; + +const { line } = doc.builders; export class YulStackAssignmentStatement implements SlangNode { readonly kind = NonterminalKind.YulStackAssignmentStatement; @@ -15,33 +17,33 @@ export class YulStackAssignmentStatement implements SlangNode { loc; - assignment: YulAssignmentOperator; + assignment: YulStackAssignmentOperator; - expression: YulExpression; + variable: string; - constructor( - ast: ast.YulStackAssignmentStatement, - offset: number, - options: ParserOptions - ) { + constructor(ast: ast.YulStackAssignmentStatement, offset: number) { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.assignment = new YulAssignmentOperator(ast.assignment, offsets[0]); - this.expression = new YulExpression(ast.expression, offsets[1], options); + this.assignment = new YulStackAssignmentOperator( + ast.assignment, + offsets[0] + ); + this.variable = ast.variable.text; - metadata = updateMetadata(metadata, [this.assignment, this.expression]); + metadata = updateMetadata(metadata, [this.assignment]); this.comments = metadata.comments; this.loc = metadata.loc; } - // TODO: implement print - print(/* - path: AstPath, - print: PrintFunction, - options: ParserOptions - */): Doc { - return ['TODO: YulStackAssignmentStatement']; + print(path: AstPath, print: PrintFunction): Doc { + return [ + path.call(print, 'assignment'), + printSeparatedItem(this.variable, { + firstSeparator: line, + lastSeparator: '' + }) + ]; } } diff --git a/src/slang-nodes/YulStatement.ts b/src/slang-nodes/YulStatement.ts index 823612d65..3f44d45c9 100644 --- a/src/slang-nodes/YulStatement.ts +++ b/src/slang-nodes/YulStatement.ts @@ -81,8 +81,7 @@ export class YulStatement implements SlangNode { case NonterminalKind.YulStackAssignmentStatement: this.variant = new YulStackAssignmentStatement( ast.variant as ast.YulStackAssignmentStatement, - offsets[0], - options + offsets[0] ); break; case NonterminalKind.YulIfStatement: diff --git a/src/slang-nodes/YulStatements.ts b/src/slang-nodes/YulStatements.ts index a345e71f5..b6a848499 100644 --- a/src/slang-nodes/YulStatements.ts +++ b/src/slang-nodes/YulStatements.ts @@ -50,7 +50,7 @@ export class YulStatements implements SlangNode { : printSeparatedItem( [ printPreservingEmptyLines(path, print, options), - printComments(this, path) + printComments(path) ], { firstSeparator: hardline, diff --git a/src/slang-nodes/YulVariableAssignmentStatement.ts b/src/slang-nodes/YulVariableAssignmentStatement.ts index 4a1b10cc3..79a102bd0 100644 --- a/src/slang-nodes/YulVariableAssignmentStatement.ts +++ b/src/slang-nodes/YulVariableAssignmentStatement.ts @@ -16,7 +16,7 @@ export class YulVariableAssignmentStatement implements SlangNode { loc; - names: YulPaths; + variables: YulPaths; assignment: YulAssignmentOperator; @@ -30,12 +30,12 @@ export class YulVariableAssignmentStatement implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.names = new YulPaths(ast.names, offsets[0]); + this.variables = new YulPaths(ast.variables, offsets[0]); this.assignment = new YulAssignmentOperator(ast.assignment, offsets[1]); this.expression = new YulExpression(ast.expression, offsets[2], options); metadata = updateMetadata(metadata, [ - this.names, + this.variables, this.assignment, this.expression ]); @@ -49,7 +49,7 @@ export class YulVariableAssignmentStatement implements SlangNode { print: PrintFunction ): Doc { return [ - path.call(print, 'names'), + path.call(print, 'variables'), ' ', path.call(print, 'assignment'), ' ', diff --git a/src/slang-nodes/YulVariableDeclarationStatement.ts b/src/slang-nodes/YulVariableDeclarationStatement.ts index 0d6a0156a..a2dc806ce 100644 --- a/src/slang-nodes/YulVariableDeclarationStatement.ts +++ b/src/slang-nodes/YulVariableDeclarationStatement.ts @@ -1,6 +1,7 @@ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { YulVariableDeclarationValue } from './YulVariableDeclarationValue.js'; +import { YulVariableNames } from './YulVariableNames.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; @@ -14,7 +15,7 @@ export class YulVariableDeclarationStatement implements SlangNode { loc; - names: string; + variables: YulVariableNames; value?: YulVariableDeclarationValue; @@ -26,11 +27,11 @@ export class YulVariableDeclarationStatement implements SlangNode { let metadata = getNodeMetadata(ast, offset); const { offsets } = metadata; - this.names = ast.names.text; + this.variables = new YulVariableNames(ast.variables, offsets[0]); if (ast.value) { this.value = new YulVariableDeclarationValue( ast.value, - offsets[0], + offsets[1], options ); } @@ -45,6 +46,11 @@ export class YulVariableDeclarationStatement implements SlangNode { path: AstPath, print: PrintFunction ): Doc { - return [`let ${this.names} `, this.value ? path.call(print, 'value') : '']; + return [ + 'let', + path.call(print, 'variables'), + ' ', + this.value ? path.call(print, 'value') : '' + ]; } } diff --git a/src/slang-nodes/YulReturnVariables.ts b/src/slang-nodes/YulVariableNames.ts similarity index 83% rename from src/slang-nodes/YulReturnVariables.ts rename to src/slang-nodes/YulVariableNames.ts index 166d2c7da..f09826a00 100644 --- a/src/slang-nodes/YulReturnVariables.ts +++ b/src/slang-nodes/YulVariableNames.ts @@ -1,5 +1,5 @@ -import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js'; +import { doc } from 'prettier'; import { printSeparatedList } from '../slang-printers/print-separated-list.js'; import { getNodeMetadata } from '../slang-utils/metadata.js'; @@ -9,8 +9,8 @@ import type { SlangNode } from '../types'; const { line } = doc.builders; -export class YulReturnVariables implements SlangNode { - readonly kind = NonterminalKind.YulReturnVariables; +export class YulVariableNames implements SlangNode { + readonly kind = NonterminalKind.YulVariableNames; comments; @@ -20,7 +20,7 @@ export class YulReturnVariables implements SlangNode { separators: string[]; - constructor(ast: ast.YulReturnVariables, offset: number) { + constructor(ast: ast.YulVariableNames, offset: number) { const metadata = getNodeMetadata(ast, offset); this.items = ast.items.map((item) => item.text); diff --git a/src/slang-nodes/index.d.ts b/src/slang-nodes/index.d.ts index 1b174e6d6..8af2afa03 100644 --- a/src/slang-nodes/index.d.ts +++ b/src/slang-nodes/index.d.ts @@ -90,7 +90,6 @@ import type { MappingKey } from './MappingKey'; import type { MappingKeyType } from './MappingKeyType'; import type { MappingType } from './MappingType'; import type { MappingValue } from './MappingValue'; -import type { MemberAccess } from './MemberAccess'; import type { MemberAccessExpression } from './MemberAccessExpression'; import type { ModifierAttribute } from './ModifierAttribute'; import type { ModifierAttributes } from './ModifierAttributes'; @@ -185,9 +184,10 @@ import type { YulAssignmentOperator } from './YulAssignmentOperator'; import type { YulBlock } from './YulBlock'; import type { YulBreakStatement } from './YulBreakStatement'; import type { YulBuiltInFunction } from './YulBuiltInFunction'; -import type { YulColonEqual } from './YulColonEqual'; +import type { YulColonAndEqual } from './YulColonAndEqual'; import type { YulContinueStatement } from './YulContinueStatement'; import type { YulDefaultCase } from './YulDefaultCase'; +import type { YulEqualAndColon } from './YulEqualAndColon'; import type { YulExpression } from './YulExpression'; import type { YulForStatement } from './YulForStatement'; import type { YulFunctionCallExpression } from './YulFunctionCallExpression'; @@ -202,7 +202,7 @@ import type { YulPath } from './YulPath'; import type { YulPathComponent } from './YulPathComponent'; import type { YulPaths } from './YulPaths'; import type { YulReturnsDeclaration } from './YulReturnsDeclaration'; -import type { YulReturnVariables } from './YulReturnVariables'; +import type { YulStackAssignmentOperator } from './YulStackAssignmentOperator'; import type { YulStackAssignmentStatement } from './YulStackAssignmentStatement'; import type { YulStatement } from './YulStatement'; import type { YulStatements } from './YulStatements'; @@ -213,6 +213,7 @@ import type { YulValueCase } from './YulValueCase'; import type { YulVariableAssignmentStatement } from './YulVariableAssignmentStatement'; import type { YulVariableDeclarationStatement } from './YulVariableDeclarationStatement'; import type { YulVariableDeclarationValue } from './YulVariableDeclarationValue'; +import type { YulVariableNames } from './YulVariableNames'; export type BinaryOperation = | AdditiveExpression @@ -260,6 +261,7 @@ export type HubNode = | NamedArguments | OverridePaths | Parameters + | PositionalArguments | ReceiveFunctionAttributes | SourceUnitMembers | Statements @@ -278,9 +280,9 @@ export type HubNode = | YulParameters | YulPath | YulPaths - | YulReturnVariables | YulStatements - | YulSwitchCases; + | YulSwitchCases + | YulVariableNames; export type AstNode = | string @@ -402,7 +404,9 @@ export type AstNode = | YulVariableDeclarationValue | YulVariableAssignmentStatement | YulStackAssignmentStatement - | YulColonEqual + | YulStackAssignmentOperator + | YulColonAndEqual + | YulEqualAndColon | YulIfStatement | YulForStatement | YulSwitchStatement @@ -442,7 +446,6 @@ export type AstNode = | ForStatementInitialization | ForStatementCondition | Expression - | MemberAccess | ArgumentsDeclaration | NumberUnit | StringExpression @@ -496,7 +499,7 @@ export type AstNode = | ArrayValues | IdentifierPath | YulParameters - | YulReturnVariables + | YulVariableNames | YulArguments | YulPaths | YulPath; diff --git a/src/slang-printers/print-comments.ts b/src/slang-printers/print-comments.ts index f8d5c72a5..603cbc1c9 100644 --- a/src/slang-printers/print-comments.ts +++ b/src/slang-printers/print-comments.ts @@ -8,7 +8,7 @@ import type { DocV2 } from './types'; const { join, line } = doc.builders; -export function printComments(node: AstNode, path: AstPath): Doc[] { +export function printComments(path: AstPath): Doc[] { const document = join( line, path diff --git a/src/types.d.ts b/src/types.d.ts index 00f1a6687..02e8a0a92 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -1,3 +1,4 @@ +import type { NonterminalKind } from '@nomicfoundation/slang/kinds'; import type { kinds } from '@nomicfoundation/slang/napi-bindings/generated'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; @@ -52,7 +53,7 @@ interface Metadata { } interface SlangNode { - kind: string; + kind: keyof typeof NonterminalKind; comments: Comment[]; loc: Location; print( @@ -182,7 +183,9 @@ export type SlangAstNode = | ast.YulVariableDeclarationValue | ast.YulVariableAssignmentStatement | ast.YulStackAssignmentStatement - | ast.YulColonEqual + | ast.YulStackAssignmentOperator + | ast.YulColonAndEqual + | ast.YulEqualAndColon | ast.YulIfStatement | ast.YulForStatement | ast.YulSwitchStatement @@ -222,7 +225,6 @@ export type SlangAstNode = | ast.ForStatementInitialization | ast.ForStatementCondition | ast.Expression - | ast.MemberAccess | ast.ArgumentsDeclaration | ast.NumberUnit | ast.StringExpression @@ -276,7 +278,7 @@ export type SlangAstNode = | ast.ArrayValues | ast.IdentifierPath | ast.YulParameters - | ast.YulReturnVariables + | ast.YulVariableNames | ast.YulArguments | ast.YulPaths | ast.YulPath; diff --git a/tests/config/run-format-test.js b/tests/config/run-format-test.js index e7e1046c4..7e4afd298 100644 --- a/tests/config/run-format-test.js +++ b/tests/config/run-format-test.js @@ -43,8 +43,7 @@ const unstableAstTests = new Map( const testsWithSlang = new Map( [ // "AllSolidityFeatures/AllSolidityFeatures.sol", - // "AssemblyV0.4.26/Assembly.sol", // TODO: Wait for Nomic Foundation's response - "Comments/Comments.sol", // TODO: finish Comments + // "Comments/Comments.sol", // TODO: finish Comments ].map((fixture) => { const [file, testSlang = () => true] = Array.isArray(fixture) ? fixture diff --git a/tests/format/AssemblyV0.4.26/__snapshots__/format.test.js.snap b/tests/format/AssemblyV0.4.26/__snapshots__/format.test.js.snap index d249ad2e4..cf1500e11 100644 --- a/tests/format/AssemblyV0.4.26/__snapshots__/format.test.js.snap +++ b/tests/format/AssemblyV0.4.26/__snapshots__/format.test.js.snap @@ -3,7 +3,7 @@ exports[`Assembly.sol - {"compiler":"0.4.26"} format 1`] = ` ====================================options===================================== compiler: "0.4.26" -parsers: ["solidity-parse"] +parsers: ["slang"] printWidth: 80 | printWidth =====================================input====================================== @@ -121,7 +121,8 @@ contract MultipleAssemblyAssignment { contract AssemblyStackAssignment { function f() public { assembly { - 4 =: y + 4 + =: y } } } diff --git a/tests/format/AssemblyV0.4.26/format.test.js b/tests/format/AssemblyV0.4.26/format.test.js index 94898ac13..85c6f9a33 100644 --- a/tests/format/AssemblyV0.4.26/format.test.js +++ b/tests/format/AssemblyV0.4.26/format.test.js @@ -1 +1 @@ -runFormatTest(import.meta, ['solidity-parse'], { compiler: '0.4.26' }); +runFormatTest(import.meta, ['slang'], { compiler: '0.4.26' }); From c8cc1a58bbe8460c0ff29b9f62254523b6756afe Mon Sep 17 00:00:00 2001 From: Klaus Date: Thu, 8 Aug 2024 13:30:56 +1200 Subject: [PATCH 123/160] using 'slang' instead of 'solidity-parse' --- README.md | 2 +- tests/integration/test-app.js | 2 +- tests/unit/prettier-version/index.test.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e6c435886..70cffe327 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ We follow Prettier's strategy for populating their plugins in the object `pretti