Socket
Socket
Sign inDemoInstall

prettier-plugin-solidity

Package Overview
Dependencies
Maintainers
3
Versions
95
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prettier-plugin-solidity - npm Package Compare versions

Comparing version 1.1.3 to 1.2.0

dist/standalone.cjs

75

package.json
{
"name": "prettier-plugin-solidity",
"version": "1.1.3",
"version": "1.2.0",
"description": "A Prettier Plugin for automatically formatting your Solidity code.",
"type": "module",
"main": "./src/index.js",
"browser": "./dist/standalone.js",
"unpkg": "./dist/standalone.js",
"browser": "./dist/standalone.cjs",
"unpkg": "./dist/standalone.cjs",
"exports": {
".": {
"import": "./src/index.js",
"require": "./dist/standalone.cjs"
},
"./standalone": {
"default": "./dist/standalone.cjs"
}
},
"scripts": {
"build": "webpack --env production",
"build:dev": "webpack --env development",
"eslint": "eslint 'scripts/**' 'src/**' 'tests/**'",
"generateindexes": "cross-env SCRIPT=true node scripts/generateIndexes.js",
"build:test": "webpack --config test.config.js",
"eslint": "eslint 'src/**' 'tests/**'",
"lint": "npm run eslint && npm run prettier -- --list-different",
"lint:fix": "npm run eslint -- --fix && npm run prettier -- --write",
"prepublishOnly": "npm run build",
"prettier": "prettier './*.{js,json,md,yml}' '{scripts,src,tests}/**/*.js'",
"test": "jest",
"test:all": "cross-env FULL_TEST=1 c8 jest",
"prettier": "prettier './*.{js,json,md,yml}' '{src,tests}/**/*.js'",
"test": "NODE_OPTIONS=--loader=esmock jest",
"test:all": "cross-env FULL_TEST=1 NODE_OPTIONS=--loader=esmock c8 jest",
"test:standalone": "cross-env TEST_STANDALONE=1 FULL_TEST=1 jest"

@@ -23,5 +33,3 @@ },

"src",
"dist/standalone.js",
"dist/standalone.js.LICENSE.txt",
"dist/standalone.js.map",
"dist/**/*",
"LICENSE",

@@ -80,39 +88,40 @@ "README.md"

"engines": {
"node": ">=12"
"node": ">=16"
},
"devDependencies": {
"@babel/code-frame": "^7.18.6",
"c8": "^7.12.0",
"@babel/code-frame": "^7.22.10",
"c8": "^8.0.1",
"cross-env": "^7.0.3",
"dir-to-object": "^2.0.0",
"eslint": "^8.31.0",
"eslint": "^8.47.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.28.1",
"esm-utils": "^4.1.2",
"esmock": "^2.3.8",
"exports-loader": "^4.0.0",
"jest": "^29.3.1",
"jest-light-runner": "^0.4.1",
"jest-mock-now": "^1.3.0",
"jest-snapshot-serializer-ansi": "^1.0.0",
"jest-snapshot-serializer-raw": "^1.2.0",
"jest-watch-typeahead": "^2.2.1",
"jest": "^29.6.3",
"jest-light-runner": "^0.5.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": "^2.8.1",
"prettier": "^3.0.2",
"proxyquire": "^2.1.3",
"solc": "^0.8.17",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.1"
"solc": "^0.8.21",
"webpack": "^5.88.2",
"webpack-cli": "^5.1.4"
},
"dependencies": {
"@solidity-parser/parser": "^0.16.0",
"semver": "^7.3.8",
"@solidity-parser/parser": "^0.16.2",
"semver": "^7.5.4",
"solidity-comments-extractor": "^0.0.7"
},
"peerDependencies": {
"prettier": ">=2.3.0 || >=3.0.0-alpha.0"
"prettier": ">=2.3.0"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
">0.5%",
"not ie 11",
"not safari 5.1",
"not op_mini all"

@@ -119,0 +128,0 @@ ],

@@ -13,4 +13,2 @@ # prettier-plugin-solidity

If you like this project, please consider contributing to our [Gitcoin grant](https://gitcoin.co/grants/1534/prettier-solidity)!
## Installation and usage

@@ -29,3 +27,3 @@

```Bash
npx prettier --write 'contracts/**/*.sol'
npx prettier --write --plugin=prettier-plugin-solidity 'contracts/**/*.sol'
```

@@ -36,3 +34,3 @@

```
"prettier": "prettier --write 'contracts/**/*.sol'"
"prettier": "prettier --write --plugin=prettier-plugin-solidity 'contracts/**/*.sol'"
```

@@ -43,3 +41,3 @@

```
"lint": "prettier --list-different 'contracts/**/*.sol'"
"lint": "prettier --list-different --plugin=prettier-plugin-solidity 'contracts/**/*.sol'"
```

@@ -68,7 +66,11 @@

<script>
async function format(code) {
return await prettier.format(code, {
parser: 'solidity-parse',
plugins: [solidityPlugin]
});
}
const originalCode = 'contract Foo {}';
const formattedCode = prettier.format(originalCode, {
parser: 'solidity-parse',
plugins: prettierPlugins
});
const formattedCode = format(originalCode);
</script>

@@ -79,2 +81,23 @@ ```

### Creating a package for the Browser
_Added in v1.2.0_
If you are creating your own package to be run in a browser, you might want to import the standalone files directly.
```Javascript
import prettier from 'prettier/standalone';
import solidityPlugin from 'prettier-plugin-solidity/standalone';
async function format(code) {
return await prettier.format(code, {
parser: "solidity-parse",
plugins: [solidityPlugin],
});
}
const originalCode = 'contract Foo {}';
const formattedCode = format(originalCode);
```
## Configuration File

@@ -87,2 +110,3 @@

{
"plugins": ["prettier-plugin-solidity"],
"overrides": [

@@ -92,2 +116,3 @@ {

"options": {
"parser": "solidity-parse",
"printWidth": 80,

@@ -106,2 +131,4 @@ "tabWidth": 4,

Since Prettier v3.0.0, the plugin search feature has been removed so we encourage adding our plugin to the configuration file.
Most options are described in Prettier's [documentation](https://prettier.io/docs/en/options.html).

@@ -309,2 +336,14 @@

### Pnpm
To make Prettier Solidity work in your project, you have to add a `.prettierrc` file as shown [here](#configuration-file).
Then, if you are using VSCode, you also need to add this to your VSCode settings:
```json
{
"prettier.documentSelectors": ["**/*.sol"]
}
```
## Edge cases

@@ -311,0 +350,0 @@

@@ -1,9 +0,7 @@

const {
doc: {
builders: { group, line, indent }
}
} = require('prettier');
const comparison = require('./comparison');
import { doc } from 'prettier';
import { comparison } from './comparison.js';
const groupIfNecessaryBuilder = (path) => (doc) => {
const { group, line, indent } = doc.builders;
const groupIfNecessaryBuilder = (path) => (document) => {
const parentNode = path.getParentNode();

@@ -14,12 +12,12 @@ if (

) {
return doc;
return document;
}
return group(doc);
return group(document);
};
const indentIfNecessaryBuilder = (path) => (doc) => {
const indentIfNecessaryBuilder = (path) => (document) => {
let node = path.getNode();
for (let i = 0; ; i += 1) {
const parentNode = path.getParentNode(i);
if (parentNode.type === 'ReturnStatement') return doc;
if (parentNode.type === 'ReturnStatement') return document;
if (

@@ -29,5 +27,5 @@ parentNode.type !== 'BinaryOperation' ||

) {
return indent(doc);
return indent(document);
}
if (node === parentNode.right) return doc;
if (node === parentNode.right) return document;
node = parentNode;

@@ -37,3 +35,3 @@ }

module.exports = {
export const arithmetic = {
match: (op) => ['+', '-', '*', '/', '%'].includes(op),

@@ -40,0 +38,0 @@ print: (node, path, print) => {

@@ -1,8 +0,6 @@

const {
doc: {
builders: { group, line, indent }
}
} = require('prettier');
import { doc } from 'prettier';
module.exports = {
const { group, line, indent } = doc.builders;
export const assignment = {
match: (op) =>

@@ -9,0 +7,0 @@ [

@@ -1,6 +0,6 @@

const arithmetic = require('./arithmetic');
import { arithmetic } from './arithmetic.js';
module.exports = {
export const bit = {
match: (op) => ['&', '|', '^'].includes(op),
print: arithmetic.print
};

@@ -1,17 +0,15 @@

const {
doc: {
builders: { group, line, indent }
}
} = require('prettier');
import { doc } from 'prettier';
const indentIfNecessaryBuilder = (path) => (doc) => {
const { group, indent, line } = doc.builders;
const indentIfNecessaryBuilder = (path) => (document) => {
let node = path.getNode();
for (let i = 0; ; i += 1) {
const parentNode = path.getParentNode(i);
if (parentNode.type === 'ReturnStatement') return doc;
if (parentNode.type === 'IfStatement') return doc;
if (parentNode.type === 'ForStatement') return doc;
if (parentNode.type === 'WhileStatement') return doc;
if (parentNode.type !== 'BinaryOperation') return indent(doc);
if (node === parentNode.right) return doc;
if (parentNode.type === 'ReturnStatement') return document;
if (parentNode.type === 'IfStatement') return document;
if (parentNode.type === 'ForStatement') return document;
if (parentNode.type === 'WhileStatement') return document;
if (parentNode.type !== 'BinaryOperation') return indent(document);
if (node === parentNode.right) return document;
node = parentNode;

@@ -21,3 +19,3 @@ }

module.exports = {
export const comparison = {
match: (op) => ['<', '>', '<=', '>=', '==', '!='].includes(op),

@@ -24,0 +22,0 @@ print: (node, path, print) => {

@@ -1,8 +0,6 @@

const {
doc: {
builders: { group, indent, line }
}
} = require('prettier');
import { doc } from 'prettier';
module.exports = {
const { group, indent, line } = doc.builders;
export const exponentiation = {
match: (op) => op === '**',

@@ -9,0 +7,0 @@ print: (node, path, print) => {

@@ -1,13 +0,7 @@

/* This file was automatically generated on 1666691919.933 */
/* eslint-disable global-require */
module.exports = {
arithmetic: require('./arithmetic'),
assignment: require('./assignment'),
bit: require('./bit'),
comparison: require('./comparison'),
exponentiation: require('./exponentiation'),
logical: require('./logical'),
shift: require('./shift')
};
export * from './arithmetic.js';
export * from './assignment.js';
export * from './bit.js';
export * from './comparison.js';
export * from './exponentiation.js';
export * from './logical.js';
export * from './shift.js';

@@ -1,19 +0,17 @@

const {
doc: {
builders: { group, line, indent }
}
} = require('prettier');
import { doc } from 'prettier';
const groupIfNecessaryBuilder = (path) => (doc) =>
path.getParentNode().type === 'BinaryOperation' ? doc : group(doc);
const { group, line, indent } = doc.builders;
const indentIfNecessaryBuilder = (path) => (doc) => {
const groupIfNecessaryBuilder = (path) => (document) =>
path.getParentNode().type === 'BinaryOperation' ? document : group(document);
const indentIfNecessaryBuilder = (path) => (document) => {
let node = path.getNode();
for (let i = 0; ; i += 1) {
const parentNode = path.getParentNode(i);
if (parentNode.type === 'ReturnStatement') return doc;
if (parentNode.type === 'IfStatement') return doc;
if (parentNode.type === 'WhileStatement') return doc;
if (parentNode.type !== 'BinaryOperation') return indent(doc);
if (node === parentNode.right) return doc;
if (parentNode.type === 'ReturnStatement') return document;
if (parentNode.type === 'IfStatement') return document;
if (parentNode.type === 'WhileStatement') return document;
if (parentNode.type !== 'BinaryOperation') return indent(document);
if (node === parentNode.right) return document;
node = parentNode;

@@ -23,3 +21,3 @@ }

module.exports = {
export const logical = {
match: (op) => ['&&', '||'].includes(op),

@@ -26,0 +24,0 @@ print: (node, path, print) => {

@@ -1,6 +0,6 @@

const arithmetic = require('./arithmetic');
import { arithmetic } from './arithmetic.js';
module.exports = {
export const shift = {
match: (op) => ['<<', '>>'].includes(op),
print: arithmetic.print
};

@@ -6,2 +6,2 @@ // Prettier offers a clean way to define ignored properties.

module.exports = clean;
export default clean;

@@ -1,10 +0,9 @@

const {
import {
handleOwnLineComment,
handleEndOfLineComment,
handleRemainingComment
} = require('../prettier-comments/language-js/comments');
} from '../prettier-comments/language-js/comments.js';
import handlers from './handlers/index.js';
const handlers = require('./handlers');
function solidityHandleOwnLineComment(
export function solidityHandleOwnLineComment(
comment,

@@ -35,3 +34,3 @@ text,

function solidityHandleEndOfLineComment(
export function solidityHandleEndOfLineComment(
comment,

@@ -62,3 +61,3 @@ text,

function solidityHandleRemainingComment(
export function solidityHandleRemainingComment(
comment,

@@ -89,11 +88,4 @@ text,

function isBlockComment(comment) {
export function isBlockComment(comment) {
return comment.type === 'BlockComment';
}
module.exports = {
handleOwnLineComment: solidityHandleOwnLineComment,
handleEndOfLineComment: solidityHandleEndOfLineComment,
handleRemainingComment: solidityHandleRemainingComment,
isBlockComment
};

@@ -1,10 +0,6 @@

const {
util: {
addLeadingComment,
addTrailingComment,
addDanglingComment,
getNextNonSpaceNonCommentCharacterIndex
}
} = require('prettier');
import { util } from 'prettier';
import { getNextNonSpaceNonCommentCharacter } from '../../common/backward-compatibility.js';
const { addLeadingComment, addTrailingComment, addDanglingComment } = util;
function handleContractDefinitionComments({

@@ -27,4 +23,6 @@ text,

// it is a {}.
const nextCharacter = text.charAt(
getNextNonSpaceNonCommentCharacterIndex(text, comment, options.locEnd)
const nextCharacter = getNextNonSpaceNonCommentCharacter(
text,
comment,
options.locEnd
);

@@ -61,2 +59,2 @@

module.exports = handleContractDefinitionComments;
export default handleContractDefinitionComments;

@@ -1,10 +0,6 @@

const {
util: {
addLeadingComment,
addTrailingComment,
addDanglingComment,
getNextNonSpaceNonCommentCharacterIndex
}
} = require('prettier');
import { util } from 'prettier';
import { getNextNonSpaceNonCommentCharacter } from '../../common/backward-compatibility.js';
const { addLeadingComment, addTrailingComment, addDanglingComment } = util;
function handleModifierInvocationComments({

@@ -26,4 +22,6 @@ text,

// it is a ().
const nextCharacter = text.charAt(
getNextNonSpaceNonCommentCharacterIndex(text, comment, options.locEnd)
const nextCharacter = getNextNonSpaceNonCommentCharacter(
text,
comment,
options.locEnd
);

@@ -70,2 +68,2 @@

module.exports = handleModifierInvocationComments;
export default handleModifierInvocationComments;
/* eslint-disable global-require */
import handleContractDefinitionComments from './handleContractDefinitionComments.js';
import handleModifierInvocationComments from './handleModifierInvocationComments.js';
module.exports = [
require('./handleContractDefinitionComments'),
require('./handleModifierInvocationComments')
export default [
handleContractDefinitionComments,
handleModifierInvocationComments
];

@@ -33,2 +33,2 @@ function ignoreComments(path) {

module.exports = ignoreComments;
export default ignoreComments;

@@ -1,4 +0,2 @@

const handler = require('./handler');
const printer = require('./printer');
module.exports = { handleComments: handler, printComment: printer };
export * from './handler.js';
export * from './printer.js';

@@ -1,8 +0,5 @@

const {
doc: {
builders: { hardline, join }
},
util: { hasNewline }
} = require('prettier');
import { doc, util } from 'prettier';
const { hardline, join } = doc.builders;
function isIndentableBlockComment(comment) {

@@ -34,3 +31,3 @@ // If the comment has multiple lines and every line starts with a star

function printComment(commentPath, options) {
export function printComment(commentPath, options) {
const comment = commentPath.getValue();

@@ -47,3 +44,3 @@

comment.trailing &&
!hasNewline(options.originalText, options.locStart(comment), {
!util.hasNewline(options.originalText, options.locStart(comment), {
backwards: true

@@ -65,3 +62,1 @@ })

}
module.exports = printComment;

@@ -1,12 +0,16 @@

const {
doc: {
builders: { group, indent, join, line, softline, hardline }
},
util: { isNextLineEmptyAfterIndex }
} = require('prettier');
const { prettierVersionSatisfies } = require('./util');
import { doc } from 'prettier';
import {
isFirst,
isLast,
isNextLineEmpty,
isPrettier2,
next,
previous
} from './backward-compatibility.js';
const printComments = (node, path, options, filter = () => true) => {
const { group, indent, join, line, softline, hardline } = doc.builders;
export const printComments = (node, path, options, filter = () => true) => {
if (!node.comments) return '';
const doc = join(
const document = join(
line,

@@ -32,9 +36,25 @@ path

/* c8 ignore start */
return prettierVersionSatisfies('^2.3.0')
? doc.parts // Prettier V2
: doc; // Prettier V3
return isPrettier2
? document.parts // Prettier V2
: document; // Prettier V3
/* c8 ignore stop */
};
function printPreservingEmptyLines(path, key, options, print) {
const shouldHaveEmptyLine = (node, checkForLeading) =>
Boolean(
// if node is not FunctionDefinition, it should have an empty line
node.type !== 'FunctionDefinition' ||
// if FunctionDefinition is not abstract, it should have an empty line
node.body ||
// if FunctionDefinition has the comment we are looking for (trailing or
// leading), it should have an empty line
node.comments?.some((comment) => checkForLeading && comment.leading)
);
const separatingLine = (firstNode, secondNode) =>
shouldHaveEmptyLine(firstNode, false) || shouldHaveEmptyLine(secondNode, true)
? hardline
: '';
export function printPreservingEmptyLines(path, key, options, print) {
const parts = [];

@@ -55,7 +75,14 @@ path.each((childPath, index) => {

if (index > 0) {
if (
['ContractDefinition', 'FunctionDefinition'].includes(nodeType) &&
parts[parts.length - 2] !== hardline
) {
// Only attempt to prepend an empty line if `node` is not the first item
// and an empty line hasn't already been appended after the previous `node`
if (
!isFirst(childPath, key, index) &&
parts[parts.length - 2] !== hardline
) {
if (nodeType === 'FunctionDefinition') {
// Prepend FunctionDefinition with an empty line if there should be a
// separation with the previous `node`
parts.push(separatingLine(previous(childPath, key, index), node));
} else if (nodeType === 'ContractDefinition') {
// Prepend ContractDefinition with an empty line
parts.push(hardline);

@@ -67,17 +94,19 @@ }

if (
isNextLineEmptyAfterIndex(
options.originalText,
options.locEnd(node) + 1
) ||
nodeType === 'FunctionDefinition'
) {
parts.push(hardline);
// Only attempt to append an empty line if `node` is not the last item
if (!isLast(childPath, key, index)) {
if (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);
} else if (nodeType === 'FunctionDefinition') {
// Append FunctionDefinition with an empty line if there should be a
// separation with the next `node`
parts.push(separatingLine(node, next(childPath, key, index)));
} else if (nodeType === 'ContractDefinition') {
// Append ContractDefinition with an empty line
parts.push(hardline);
}
}
}, key);
if (parts.length > 1 && parts[parts.length - 1] === hardline) {
parts.pop();
}
return parts;

@@ -88,3 +117,3 @@ }

// rest of the `doc` in most cases by a `softline`.
const printSeparatedItem = (
export const printSeparatedItem = (
item,

@@ -97,4 +126,4 @@ {

) => {
const doc = [indent([firstSeparator, item]), lastSeparator];
return grouped ? group(doc) : doc;
const document = [indent([firstSeparator, item]), lastSeparator];
return grouped ? group(document) : document;
};

@@ -106,3 +135,3 @@

// comma (,) and a `line`
const printSeparatedList = (
export const printSeparatedList = (
list,

@@ -116,8 +145,1 @@ { firstSeparator, separator = [',', line], lastSeparator, grouped } = {}

});
module.exports = {
printComments,
printPreservingEmptyLines,
printSeparatedList,
printSeparatedItem
};

@@ -1,16 +0,7 @@

const {
util: { getNextNonSpaceNonCommentCharacterIndex, makeString },
version
} = require('prettier');
const satisfies = require('semver/functions/satisfies');
import { util, version } from 'prettier';
import satisfies from 'semver/functions/satisfies.js';
const prettierVersionSatisfies = (range) => satisfies(version, range);
export const prettierVersionSatisfies = (range) => satisfies(version, range);
function getNextNonSpaceNonCommentCharacter(text, node, locEnd) {
return text.charAt(
getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd)
);
}
function printString(rawContent, options) {
export function printString(rawContent, options) {
const double = { quote: '"', regex: /"/g };

@@ -47,6 +38,6 @@ const single = { quote: "'", regex: /'/g };

// sure that we consistently output the minimum amount of escaped quotes.
return makeString(rawContent, enclosingQuote);
return util.makeString(rawContent, enclosingQuote);
}
function hasNodeIgnoreComment(node) {
export function hasNodeIgnoreComment(node) {
return (

@@ -59,8 +50,1 @@ node &&

}
module.exports = {
getNextNonSpaceNonCommentCharacter,
printString,
prettierVersionSatisfies,
hasNodeIgnoreComment
};

@@ -1,7 +0,7 @@

const { handleComments, printComment } = require('./comments');
const massageAstNode = require('./clean');
const loc = require('./loc');
const options = require('./options');
const parse = require('./parser');
const print = require('./printer');
import * as comments from './comments/index.js';
import massageAstNode from './clean.js';
import loc from './loc.js';
import options from './options.js';
import parse from './parser.js';
import print from './printer.js';

@@ -38,10 +38,10 @@ // https://prettier.io/docs/en/plugins.html#languages

handleComments: {
ownLine: handleComments.handleOwnLineComment,
endOfLine: handleComments.handleEndOfLineComment,
remaining: handleComments.handleRemainingComment
ownLine: comments.solidityHandleOwnLineComment,
endOfLine: comments.solidityHandleEndOfLineComment,
remaining: comments.solidityHandleRemainingComment
},
isBlockComment: handleComments.isBlockComment,
isBlockComment: comments.isBlockComment,
massageAstNode,
print,
printComment
printComment: comments.printComment
}

@@ -56,3 +56,3 @@ };

module.exports = {
const plugin = {
languages,

@@ -64,1 +64,3 @@ parsers,

};
export default plugin;

@@ -13,5 +13,5 @@ // see: https://github.com/prettier/prettier/blob/main/src/language-js/loc.js

module.exports = {
export default {
locEnd: (node) => getRange(1, node),
locStart: (node) => getRange(0, node)
};

@@ -1,2 +0,2 @@

const ArrayTypeName = {
export const ArrayTypeName = {
print: ({ node, path, print }) => [

@@ -9,3 +9,1 @@ path.call(print, 'baseTypeName'),

};
module.exports = ArrayTypeName;

@@ -1,8 +0,6 @@

const {
doc: {
builders: { join }
}
} = require('prettier');
import { doc } from 'prettier';
const AssemblyAssignment = {
const { join } = doc.builders;
export const AssemblyAssignment = {
print: ({ path, print }) => [

@@ -14,3 +12,1 @@ join(', ', path.map(print, 'names')),

};
module.exports = AssemblyAssignment;

@@ -1,14 +0,11 @@

const {
doc: {
builders: { hardline }
}
} = require('prettier');
const {
import { doc } from 'prettier';
import {
printComments,
printPreservingEmptyLines,
printSeparatedItem
} = require('../common/printer-helpers');
} from '../common/printer-helpers.js';
const AssemblyBlock = {
const { hardline } = doc.builders;
export const AssemblyBlock = {
print: ({ node, options, path, print }) => [

@@ -26,3 +23,1 @@ '{',

};
module.exports = AssemblyBlock;

@@ -1,4 +0,4 @@

const { printSeparatedList } = require('../common/printer-helpers');
import { printSeparatedList } from '../common/printer-helpers.js';
const AssemblyCall = {
export const AssemblyCall = {
print: ({ node, path, print, options }) =>

@@ -15,3 +15,1 @@ node.arguments.length === 0 &&

};
module.exports = AssemblyCall;

@@ -1,2 +0,2 @@

const AssemblyCase = {
export const AssemblyCase = {
print: ({ node, path, print }) => [

@@ -8,3 +8,1 @@ node.default ? 'default' : ['case ', path.call(print, 'value')],

};
module.exports = AssemblyCase;

@@ -1,8 +0,6 @@

const {
doc: {
builders: { join }
}
} = require('prettier');
import { doc } from 'prettier';
const AssemblyFor = {
const { join } = doc.builders;
export const AssemblyFor = {
print: ({ path, print }) =>

@@ -17,3 +15,1 @@ join(' ', [

};
module.exports = AssemblyFor;

@@ -1,13 +0,10 @@

const {
doc: {
builders: { line }
}
} = require('prettier');
const {
import { doc } from 'prettier';
import {
printSeparatedItem,
printSeparatedList
} = require('../common/printer-helpers');
} from '../common/printer-helpers.js';
const AssemblyFunctionDefinition = {
const { line } = doc.builders;
export const AssemblyFunctionDefinition = {
print: ({ node, path, print }) => [

@@ -34,3 +31,1 @@ 'function ',

};
module.exports = AssemblyFunctionDefinition;

@@ -1,2 +0,2 @@

const AssemblyIf = {
export const AssemblyIf = {
print: ({ path, print }) => [

@@ -9,3 +9,1 @@ 'if ',

};
module.exports = AssemblyIf;

@@ -1,10 +0,7 @@

const {
doc: {
builders: { line }
}
} = require('prettier');
import { doc } from 'prettier';
import { printSeparatedList } from '../common/printer-helpers.js';
const { printSeparatedList } = require('../common/printer-helpers');
const { line } = doc.builders;
const AssemblyLocalDefinition = {
export const AssemblyLocalDefinition = {
print: ({ node, path, print }) => {

@@ -24,3 +21,1 @@ const parts = [

};
module.exports = AssemblyLocalDefinition;

@@ -1,2 +0,2 @@

const AssemblyMemberAccess = {
export const AssemblyMemberAccess = {
print: ({ path, print }) => [

@@ -8,3 +8,1 @@ path.call(print, 'expression'),

};
module.exports = AssemblyMemberAccess;

@@ -1,2 +0,2 @@

const AssemblyStackAssignment = {
export const AssemblyStackAssignment = {
print: ({ node, path, print }) => [

@@ -8,3 +8,1 @@ path.call(print, 'expression'),

};
module.exports = AssemblyStackAssignment;

@@ -1,8 +0,6 @@

const {
doc: {
builders: { hardline, join }
}
} = require('prettier');
import { doc } from 'prettier';
const AssemblySwitch = {
const { hardline, join } = doc.builders;
export const AssemblySwitch = {
print: ({ path, print }) => [

@@ -15,3 +13,1 @@ 'switch ',

};
module.exports = AssemblySwitch;

@@ -1,5 +0,4 @@

/* eslint-disable consistent-return */
const printers = require('../binary-operator-printers');
import * as printers from '../binary-operator-printers/index.js';
const BinaryOperation = {
export const BinaryOperation = {
print: ({ node, path, print, options }) => {

@@ -19,3 +18,1 @@ const binaryOperationPrinter = Object.values(printers).find((printer) =>

};
module.exports = BinaryOperation;

@@ -1,13 +0,10 @@

const {
doc: {
builders: { hardline, indent }
}
} = require('prettier');
const {
import { doc } from 'prettier';
import {
printComments,
printPreservingEmptyLines
} = require('../common/printer-helpers');
} from '../common/printer-helpers.js';
const Block = {
const { hardline, indent } = doc.builders;
export const Block = {
print: ({ node, options, path, print }) =>

@@ -28,3 +25,1 @@ // if block is empty, just return the pair of braces

};
module.exports = Block;

@@ -1,5 +0,3 @@

const BooleanLiteral = {
export const BooleanLiteral = {
print: ({ node }) => (node.value ? 'true' : 'false')
};
module.exports = BooleanLiteral;

@@ -1,5 +0,3 @@

const Break = {
export const Break = {
print: () => 'break'
};
module.exports = Break;

@@ -1,5 +0,3 @@

const BreakStatement = {
export const BreakStatement = {
print: () => 'break;'
};
module.exports = BreakStatement;

@@ -1,2 +0,2 @@

const { printSeparatedList } = require('../common/printer-helpers');
import { printSeparatedList } from '../common/printer-helpers.js';

@@ -13,3 +13,3 @@ const parameters = (node, path, print) =>

const CatchClause = {
export const CatchClause = {
print: ({ node, path, print }) => [

@@ -21,3 +21,1 @@ 'catch ',

};
module.exports = CatchClause;

@@ -1,8 +0,6 @@

const {
doc: {
builders: { group, indent, line }
}
} = require('prettier');
import { doc } from 'prettier';
const Conditional = {
const { group, indent, line } = doc.builders;
export const Conditional = {
print: ({ path, print }) =>

@@ -21,3 +19,1 @@ group([

};
module.exports = Conditional;

@@ -1,5 +0,3 @@

const Continue = {
export const Continue = {
print: () => 'continue'
};
module.exports = Continue;

@@ -1,5 +0,3 @@

const ContinueStatement = {
export const ContinueStatement = {
print: () => 'continue;'
};
module.exports = ContinueStatement;

@@ -1,8 +0,3 @@

const {
doc: {
builders: { group, line, hardline }
}
} = require('prettier');
const {
import { doc } from 'prettier';
import {
printComments,

@@ -12,4 +7,6 @@ printPreservingEmptyLines,

printSeparatedList
} = require('../common/printer-helpers');
} from '../common/printer-helpers.js';
const { group, line, hardline } = doc.builders;
const inheritance = (node, path, print) =>

@@ -25,14 +22,13 @@ node.baseContracts.length > 0

const body = (node, path, options, print) =>
node.subNodes.length > 0 || node.comments
const body = (node, path, options, print) => {
const comments = printComments(node, path, options);
return node.subNodes.length > 0 || (comments && comments.length)
? printSeparatedItem(
[
printPreservingEmptyLines(path, 'subNodes', options, print),
printComments(node, path, options)
],
[printPreservingEmptyLines(path, 'subNodes', options, print), comments],
{ firstSeparator: hardline, grouped: false }
)
: '';
};
const ContractDefinition = {
export const ContractDefinition = {
print: ({ node, options, path, print }) => [

@@ -50,3 +46,1 @@ group([

};
module.exports = ContractDefinition;

@@ -1,2 +0,2 @@

const { printSeparatedList } = require('../common/printer-helpers');
import { printSeparatedList } from '../common/printer-helpers.js';

@@ -8,3 +8,3 @@ const parameters = (node, path, print) =>

const CustomErrorDefinition = {
export const CustomErrorDefinition = {
print: ({ node, path, print }) => [

@@ -18,3 +18,1 @@ 'error ',

};
module.exports = CustomErrorDefinition;

@@ -1,5 +0,3 @@

const DecimalNumber = {
export const DecimalNumber = {
print: ({ node }) => node.value
};
module.exports = DecimalNumber;

@@ -1,8 +0,5 @@

const {
doc: {
builders: { group, indent, line }
}
} = require('prettier');
import { doc } from 'prettier';
import { printSeparatedItem } from '../common/printer-helpers.js';
const { printSeparatedItem } = require('../common/printer-helpers');
const { group, indent, line } = doc.builders;

@@ -14,3 +11,3 @@ const printBody = (node, path, print) =>

const DoWhileStatement = {
export const DoWhileStatement = {
print: ({ node, path, print }) => [

@@ -24,3 +21,1 @@ 'do',

};
module.exports = DoWhileStatement;

@@ -6,6 +6,4 @@ const stateMutability = (node) =>

const ElementaryTypeName = {
export const ElementaryTypeName = {
print: ({ node }) => [node.name, stateMutability(node)]
};
module.exports = ElementaryTypeName;

@@ -1,5 +0,3 @@

const EmitStatement = {
export const EmitStatement = {
print: ({ path, print }) => ['emit ', path.call(print, 'eventCall'), ';']
};
module.exports = EmitStatement;

@@ -1,10 +0,7 @@

const {
doc: {
builders: { group, hardline }
}
} = require('prettier');
import { doc } from 'prettier';
import { printSeparatedList } from '../common/printer-helpers.js';
const { printSeparatedList } = require('../common/printer-helpers');
const { group, hardline } = doc.builders;
const EnumDefinition = {
export const EnumDefinition = {
print: ({ node, path, print }) =>

@@ -21,3 +18,1 @@ group([

};
module.exports = EnumDefinition;

@@ -1,5 +0,3 @@

const EnumValue = {
export const EnumValue = {
print: ({ node }) => node.name
};
module.exports = EnumValue;

@@ -1,2 +0,2 @@

const { printSeparatedList } = require('../common/printer-helpers');
import { printSeparatedList } from '../common/printer-helpers.js';

@@ -8,3 +8,3 @@ const parameters = (node, path, print) =>

const EventDefinition = {
export const EventDefinition = {
print: ({ node, path, print }) => [

@@ -20,3 +20,1 @@ 'event ',

};
module.exports = EventDefinition;

@@ -1,10 +0,7 @@

const {
doc: {
builders: { hardline }
}
} = require('prettier');
import { doc } from 'prettier';
import { printComments } from '../common/printer-helpers.js';
const { printComments } = require('../common/printer-helpers');
const { hardline } = doc.builders;
const ExpressionStatement = {
export const ExpressionStatement = {
print: ({ node, options, path, print }) => {

@@ -31,3 +28,1 @@ const parts = [];

};
module.exports = ExpressionStatement;

@@ -1,2 +0,2 @@

const FileLevelConstant = {
export const FileLevelConstant = {
print: ({ node, path, print }) => [

@@ -11,3 +11,1 @@ path.call(print, 'typeName'),

};
module.exports = FileLevelConstant;

@@ -1,8 +0,5 @@

const {
doc: {
builders: { group, indent, line }
}
} = require('prettier');
import { doc } from 'prettier';
import { printSeparatedList } from '../common/printer-helpers.js';
const { printSeparatedList } = require('../common/printer-helpers');
const { group, indent, line } = doc.builders;

@@ -23,3 +20,3 @@ const initExpression = (node, path, print) =>

const ForStatement = {
export const ForStatement = {
print: ({ node, path, print }) => [

@@ -46,3 +43,1 @@ 'for (',

};
module.exports = ForStatement;

@@ -1,8 +0,5 @@

const {
doc: {
builders: { group, indentIfBreak, label, line, softline }
}
} = require('prettier');
import { doc } from 'prettier';
import { printSeparatedList } from '../common/printer-helpers.js';
const { printSeparatedList } = require('../common/printer-helpers');
const { group, indentIfBreak, label, line, softline } = doc.builders;

@@ -31,3 +28,3 @@ const printObject = (path, print, options) => {

let groupIndex = 0;
const FunctionCall = {
export const FunctionCall = {
print: ({ node, path, print, options }) => {

@@ -65,3 +62,1 @@ let expressionDoc = path.call(print, 'expression');

};
module.exports = FunctionCall;

@@ -1,14 +0,11 @@

const {
doc: {
builders: { dedent, group, indent, join, line }
},
util: { getNextNonSpaceNonCommentCharacterIndex }
} = require('prettier');
const {
import { doc } from 'prettier';
import { getNextNonSpaceNonCommentCharacter } from '../common/backward-compatibility.js';
import {
printComments,
printSeparatedItem,
printSeparatedList
} = require('../common/printer-helpers');
} from '../common/printer-helpers.js';
const { dedent, group, indent, join, line } = doc.builders;
const functionName = (node, options) => {

@@ -44,8 +41,6 @@ if (node.isConstructor && !node.name) return 'constructor';

(comment) =>
options.originalText.charAt(
getNextNonSpaceNonCommentCharacterIndex(
options.originalText,
comment,
options.locEnd
)
getNextNonSpaceNonCommentCharacter(
options.originalText,
comment,
options.locEnd
) === ')'

@@ -100,3 +95,3 @@ );

const FunctionDefinition = {
export const FunctionDefinition = {
print: ({ node, path, print, options }) => [

@@ -125,3 +120,1 @@ group([

};
module.exports = FunctionDefinition;

@@ -1,8 +0,5 @@

const {
doc: {
builders: { group, indent, line }
}
} = require('prettier');
import { doc } from 'prettier';
import { printSeparatedList } from '../common/printer-helpers.js';
const { printSeparatedList } = require('../common/printer-helpers');
const { group, indent, line } = doc.builders;

@@ -29,3 +26,3 @@ const returnTypes = (node, path, print) =>

const FunctionTypeName = {
export const FunctionTypeName = {
print: ({ node, path, print }) => [

@@ -44,3 +41,1 @@ 'function(',

};
module.exports = FunctionTypeName;

@@ -1,10 +0,7 @@

const {
doc: {
builders: { join, line }
}
} = require('prettier');
import { doc } from 'prettier';
import { printString } from '../common/util.js';
const { printString } = require('../common/util');
const { join, line } = doc.builders;
const HexLiteral = {
export const HexLiteral = {
print: ({ node, options }) => {

@@ -15,3 +12,1 @@ const list = node.parts.map((part) => `hex${printString(part, options)}`);

};
module.exports = HexLiteral;

@@ -1,5 +0,3 @@

const HexNumber = {
export const HexNumber = {
print: ({ node }) => node.value
};
module.exports = HexNumber;

@@ -1,5 +0,3 @@

const Identifier = {
export const Identifier = {
print: ({ node }) => node.name
};
module.exports = Identifier;

@@ -1,12 +0,9 @@

const {
doc: {
builders: { group, hardline, indent, line }
}
} = require('prettier');
const {
import { doc } from 'prettier';
import {
printComments,
printSeparatedItem
} = require('../common/printer-helpers');
} from '../common/printer-helpers.js';
const { group, hardline, indent, line } = doc.builders;
const printTrueBody = (node, path, print) => {

@@ -41,3 +38,3 @@ if (node.trueBody.type === 'Block') {

const IfStatement = {
export const IfStatement = {
print: ({ node, options, path, print }) => {

@@ -62,3 +59,1 @@ const comments = node.comments || [];

};
module.exports = IfStatement;

@@ -1,20 +0,17 @@

const {
doc: {
builders: { group, line, softline }
}
} = require('prettier');
const coerce = require('semver/functions/coerce');
const satisfies = require('semver/functions/satisfies');
import { doc } from 'prettier';
import coerce from 'semver/functions/coerce.js';
import satisfies from 'semver/functions/satisfies.js';
import { printSeparatedList } from '../common/printer-helpers.js';
import { printString } from '../common/util.js';
const { printSeparatedList } = require('../common/printer-helpers');
const { printString } = require('../common/util');
const { group, line, softline } = doc.builders;
const ImportDirective = {
export const ImportDirective = {
print: ({ node, options }) => {
const importPath = printString(node.path, options);
let doc;
let document;
if (node.unitAlias) {
// import "./Foo.sol" as Foo;
doc = [importPath, ' as ', node.unitAlias];
document = [importPath, ' as ', node.unitAlias];
} else if (node.symbolAliases) {

@@ -41,3 +38,3 @@ // import { Foo, Bar as Qux } from "./Foo.sol";

doc = [
document = [
'{',

@@ -50,8 +47,6 @@ printSeparatedList(symbolAliases, { firstSeparator, separator }),

// import "./Foo.sol";
doc = importPath;
document = importPath;
}
return group(['import ', doc, ';']);
return group(['import ', document, ';']);
}
};
module.exports = ImportDirective;

@@ -1,78 +0,72 @@

/* This file was automatically generated on 1666691919.885 */
/* eslint-disable global-require */
module.exports = {
ArrayTypeName: require('./ArrayTypeName'),
AssemblyAssignment: require('./AssemblyAssignment'),
AssemblyBlock: require('./AssemblyBlock'),
AssemblyCall: require('./AssemblyCall'),
AssemblyCase: require('./AssemblyCase'),
AssemblyFor: require('./AssemblyFor'),
AssemblyFunctionDefinition: require('./AssemblyFunctionDefinition'),
AssemblyIf: require('./AssemblyIf'),
AssemblyLocalDefinition: require('./AssemblyLocalDefinition'),
AssemblyMemberAccess: require('./AssemblyMemberAccess'),
AssemblyStackAssignment: require('./AssemblyStackAssignment'),
AssemblySwitch: require('./AssemblySwitch'),
BinaryOperation: require('./BinaryOperation'),
Block: require('./Block'),
BooleanLiteral: require('./BooleanLiteral'),
Break: require('./Break'),
BreakStatement: require('./BreakStatement'),
CatchClause: require('./CatchClause'),
Conditional: require('./Conditional'),
Continue: require('./Continue'),
ContinueStatement: require('./ContinueStatement'),
ContractDefinition: require('./ContractDefinition'),
CustomErrorDefinition: require('./CustomErrorDefinition'),
DecimalNumber: require('./DecimalNumber'),
DoWhileStatement: require('./DoWhileStatement'),
ElementaryTypeName: require('./ElementaryTypeName'),
EmitStatement: require('./EmitStatement'),
EnumDefinition: require('./EnumDefinition'),
EnumValue: require('./EnumValue'),
EventDefinition: require('./EventDefinition'),
ExpressionStatement: require('./ExpressionStatement'),
FileLevelConstant: require('./FileLevelConstant'),
ForStatement: require('./ForStatement'),
FunctionCall: require('./FunctionCall'),
FunctionDefinition: require('./FunctionDefinition'),
FunctionTypeName: require('./FunctionTypeName'),
HexLiteral: require('./HexLiteral'),
HexNumber: require('./HexNumber'),
Identifier: require('./Identifier'),
IfStatement: require('./IfStatement'),
ImportDirective: require('./ImportDirective'),
IndexAccess: require('./IndexAccess'),
IndexRangeAccess: require('./IndexRangeAccess'),
InheritanceSpecifier: require('./InheritanceSpecifier'),
InlineAssemblyStatement: require('./InlineAssemblyStatement'),
LabelDefinition: require('./LabelDefinition'),
Mapping: require('./Mapping'),
MemberAccess: require('./MemberAccess'),
ModifierDefinition: require('./ModifierDefinition'),
ModifierInvocation: require('./ModifierInvocation'),
NameValueExpression: require('./NameValueExpression'),
NameValueList: require('./NameValueList'),
NewExpression: require('./NewExpression'),
NumberLiteral: require('./NumberLiteral'),
PragmaDirective: require('./PragmaDirective'),
ReturnStatement: require('./ReturnStatement'),
RevertStatement: require('./RevertStatement'),
SourceUnit: require('./SourceUnit'),
StateVariableDeclaration: require('./StateVariableDeclaration'),
StringLiteral: require('./StringLiteral'),
StructDefinition: require('./StructDefinition'),
ThrowStatement: require('./ThrowStatement'),
TryStatement: require('./TryStatement'),
TupleExpression: require('./TupleExpression'),
TypeDefinition: require('./TypeDefinition'),
UnaryOperation: require('./UnaryOperation'),
UncheckedStatement: require('./UncheckedStatement'),
UserDefinedTypeName: require('./UserDefinedTypeName'),
UsingForDeclaration: require('./UsingForDeclaration'),
VariableDeclaration: require('./VariableDeclaration'),
VariableDeclarationStatement: require('./VariableDeclarationStatement'),
WhileStatement: require('./WhileStatement')
};
export * from './ArrayTypeName.js';
export * from './AssemblyAssignment.js';
export * from './AssemblyBlock.js';
export * from './AssemblyCall.js';
export * from './AssemblyCase.js';
export * from './AssemblyFor.js';
export * from './AssemblyFunctionDefinition.js';
export * from './AssemblyIf.js';
export * from './AssemblyLocalDefinition.js';
export * from './AssemblyMemberAccess.js';
export * from './AssemblyStackAssignment.js';
export * from './AssemblySwitch.js';
export * from './BinaryOperation.js';
export * from './Block.js';
export * from './BooleanLiteral.js';
export * from './Break.js';
export * from './BreakStatement.js';
export * from './CatchClause.js';
export * from './Conditional.js';
export * from './Continue.js';
export * from './ContinueStatement.js';
export * from './ContractDefinition.js';
export * from './CustomErrorDefinition.js';
export * from './DecimalNumber.js';
export * from './DoWhileStatement.js';
export * from './ElementaryTypeName.js';
export * from './EmitStatement.js';
export * from './EnumDefinition.js';
export * from './EnumValue.js';
export * from './EventDefinition.js';
export * from './ExpressionStatement.js';
export * from './FileLevelConstant.js';
export * from './ForStatement.js';
export * from './FunctionCall.js';
export * from './FunctionDefinition.js';
export * from './FunctionTypeName.js';
export * from './HexLiteral.js';
export * from './HexNumber.js';
export * from './Identifier.js';
export * from './IfStatement.js';
export * from './ImportDirective.js';
export * from './IndexAccess.js';
export * from './IndexRangeAccess.js';
export * from './InheritanceSpecifier.js';
export * from './InlineAssemblyStatement.js';
export * from './LabelDefinition.js';
export * from './Mapping.js';
export * from './MemberAccess.js';
export * from './ModifierDefinition.js';
export * from './ModifierInvocation.js';
export * from './NameValueExpression.js';
export * from './NameValueList.js';
export * from './NewExpression.js';
export * from './NumberLiteral.js';
export * from './PragmaDirective.js';
export * from './ReturnStatement.js';
export * from './RevertStatement.js';
export * from './SourceUnit.js';
export * from './StateVariableDeclaration.js';
export * from './StringLiteral.js';
export * from './StructDefinition.js';
export * from './ThrowStatement.js';
export * from './TryStatement.js';
export * from './TupleExpression.js';
export * from './TypeDefinition.js';
export * from './UnaryOperation.js';
export * from './UncheckedStatement.js';
export * from './UserDefinedTypeName.js';
export * from './UsingForDeclaration.js';
export * from './VariableDeclaration.js';
export * from './VariableDeclarationStatement.js';
export * from './WhileStatement.js';

@@ -1,9 +0,7 @@

const {
doc: {
builders: { group, indent, indentIfBreak, label, softline }
}
} = require('prettier');
import { doc } from 'prettier';
const { group, indent, indentIfBreak, label, softline } = doc.builders;
let groupIndex = 0;
const IndexAccess = {
export const IndexAccess = {
print: ({ path, print }) => {

@@ -37,3 +35,1 @@ let baseDoc = path.call(print, 'base');

};
module.exports = IndexAccess;

@@ -1,2 +0,2 @@

const IndexRangeAccess = {
export const IndexRangeAccess = {
print: ({ node, path, print }) => [

@@ -11,3 +11,1 @@ path.call(print, 'base'),

};
module.exports = IndexRangeAccess;

@@ -1,2 +0,2 @@

const { printSeparatedList } = require('../common/printer-helpers');
import { printSeparatedList } from '../common/printer-helpers.js';

@@ -8,3 +8,3 @@ const printArguments = (node, path, print) =>

const InheritanceSpecifier = {
export const InheritanceSpecifier = {
print: ({ node, path, print }) => [

@@ -15,3 +15,1 @@ path.call(print, 'baseName'),

};
module.exports = InheritanceSpecifier;
// @TODO: add support for assembly language specifier
const { printString } = require('../common/util');
const { printSeparatedList } = require('../common/printer-helpers');
import { printString } from '../common/util.js';
import { printSeparatedList } from '../common/printer-helpers.js';
const InlineAssemblyStatement = {
export const InlineAssemblyStatement = {
print: ({ node, path, print, options }) => [

@@ -21,2 +21,1 @@ 'assembly ',

};
module.exports = InlineAssemblyStatement;

@@ -1,11 +0,7 @@

const {
doc: {
builders: { dedent, line }
}
} = require('prettier');
import { doc } from 'prettier';
const LabelDefinition = {
const { dedent, line } = doc.builders;
export const LabelDefinition = {
print: ({ node }) => [dedent(line), node.name, ':']
};
module.exports = LabelDefinition;

@@ -1,19 +0,18 @@

const Mapping = {
print: ({ path, print }) => {
const keyType = path.call(print, 'keyType');
const keyName = path.call(print, 'keyName');
const valueType = path.call(print, 'valueType');
const valueName = path.call(print, 'valueName');
return [
'mapping(',
keyType,
keyName ? ` ${keyName}` : '',
' => ',
valueType,
valueName ? ` ${valueName}` : '',
')'
];
}
const namedParameter = (prefix, node, path, print) =>
node[`${prefix}Name`]
? [
path.call(print, `${prefix}Type`),
' ',
path.call(print, `${prefix}Name`)
]
: path.call(print, `${prefix}Type`);
export const Mapping = {
print: ({ node, path, print }) => [
'mapping(',
namedParameter('key', node, path, print),
' => ',
namedParameter('value', node, path, print),
')'
]
};
module.exports = Mapping;

@@ -1,7 +0,5 @@

const {
doc: {
builders: { group, indent, label, softline }
}
} = require('prettier');
import { doc } from 'prettier';
const { group, indent, label, softline } = doc.builders;
const isEndOfChain = (node, path) => {

@@ -110,3 +108,3 @@ let i = 0;

const MemberAccess = {
export const MemberAccess = {
print: ({ node, path, print }) => {

@@ -118,3 +116,3 @@ let expressionDoc = path.call(print, 'expression');

const doc = [
const document = [
expressionDoc,

@@ -125,6 +123,4 @@ label('separator', [softline, '.']),

return isEndOfChain(node, path) ? processChain(doc) : doc;
return isEndOfChain(node, path) ? processChain(document) : document;
}
};
module.exports = MemberAccess;

@@ -1,8 +0,5 @@

const {
doc: {
builders: { group, hardline, indent, line }
}
} = require('prettier');
import { doc } from 'prettier';
import { printSeparatedList } from '../common/printer-helpers.js';
const { printSeparatedList } = require('../common/printer-helpers');
const { group, hardline, indent, line } = doc.builders;

@@ -48,3 +45,3 @@ const modifierParameters = (node, path, print) => {

const ModifierDefinition = {
export const ModifierDefinition = {
print: ({ node, path, print }) => [

@@ -58,3 +55,1 @@ 'modifier ',

};
module.exports = ModifierDefinition;

@@ -1,5 +0,5 @@

const {
import {
printComments,
printSeparatedList
} = require('../common/printer-helpers');
} from '../common/printer-helpers.js';

@@ -30,3 +30,3 @@ const modifierArguments = (node, path, print, options) => {

const ModifierInvocation = {
export const ModifierInvocation = {
print: ({ node, path, print, options }) => [

@@ -37,3 +37,1 @@ node.name,

};
module.exports = ModifierInvocation;

@@ -1,2 +0,2 @@

const NameValueExpression = {
export const NameValueExpression = {
print: ({ path, print }) => [

@@ -9,3 +9,1 @@ path.call(print, 'expression'),

};
module.exports = NameValueExpression;

@@ -1,10 +0,7 @@

const {
doc: {
builders: { line, softline }
}
} = require('prettier');
import { doc } from 'prettier';
import { printSeparatedList } from '../common/printer-helpers.js';
const { printSeparatedList } = require('../common/printer-helpers');
const { line, softline } = doc.builders;
const NameValueList = {
export const NameValueList = {
print: ({ node, path, print, options }) =>

@@ -20,3 +17,1 @@ printSeparatedList(

};
module.exports = NameValueList;

@@ -1,5 +0,3 @@

const NewExpression = {
export const NewExpression = {
print: ({ path, print }) => ['new ', path.call(print, 'typeName')]
};
module.exports = NewExpression;

@@ -1,2 +0,2 @@

const NumberLiteral = {
export const NumberLiteral = {
print: ({ node }) =>

@@ -7,3 +7,1 @@ node.subdenomination

};
module.exports = NumberLiteral;

@@ -1,5 +0,3 @@

const PragmaDirective = {
export const PragmaDirective = {
print: ({ node }) => ['pragma ', node.name, ' ', node.value, ';']
};
module.exports = PragmaDirective;

@@ -1,7 +0,5 @@

const {
doc: {
builders: { group, indent, line }
}
} = require('prettier');
import { doc } from 'prettier';
const { group, indent, line } = doc.builders;
const expression = (node, path, print) => {

@@ -16,3 +14,3 @@ if (node.expression) {

const ReturnStatement = {
export const ReturnStatement = {
print: ({ node, path, print }) => [

@@ -24,3 +22,1 @@ 'return',

};
module.exports = ReturnStatement;

@@ -1,5 +0,3 @@

const RevertStatement = {
export const RevertStatement = {
print: ({ path, print }) => ['revert ', path.call(print, 'revertCall'), ';']
};
module.exports = RevertStatement;

@@ -1,10 +0,7 @@

const {
doc: {
builders: { line }
}
} = require('prettier');
import { doc } from 'prettier';
import { printPreservingEmptyLines } from '../common/printer-helpers.js';
const { printPreservingEmptyLines } = require('../common/printer-helpers');
const { line } = doc.builders;
const SourceUnit = {
export const SourceUnit = {
print: ({ options, path, print }) => [

@@ -15,3 +12,1 @@ printPreservingEmptyLines(path, 'children', options, print),

};
module.exports = SourceUnit;

@@ -1,7 +0,5 @@

const {
doc: {
builders: { group, indent, line }
}
} = require('prettier');
import { doc } from 'prettier';
const { group, indent, line } = doc.builders;
const initialValue = (node, path, print) => {

@@ -19,3 +17,3 @@ if (!node.initialValue) {

const StateVariableDeclaration = {
export const StateVariableDeclaration = {
print: ({ node, path, print }) => [

@@ -27,3 +25,1 @@ ...path.map(print, 'variables'),

};
module.exports = StateVariableDeclaration;

@@ -1,9 +0,7 @@

const {
doc: {
builders: { join, hardline }
}
} = require('prettier');
const { printString } = require('../common/util');
import { doc } from 'prettier';
import { printString } from '../common/util.js';
const StringLiteral = {
const { join, hardline } = doc.builders;
export const StringLiteral = {
print: ({ node, options }) => {

@@ -20,3 +18,1 @@ const list = node.parts.map(

};
module.exports = StringLiteral;

@@ -1,16 +0,13 @@

const {
doc: {
builders: { hardline }
}
} = require('prettier');
import { doc } from 'prettier';
import { printSeparatedList } from '../common/printer-helpers.js';
const { printSeparatedList } = require('../common/printer-helpers');
const { hardline } = doc.builders;
const StructDefinition = {
print: ({ node, path, print }) => {
const parts = ['struct ', node.name, ' {'];
if (node.members.length > 0) {
parts.push(
printSeparatedList(path.map(print, 'members'), {
export const StructDefinition = {
print: ({ node, path, print }) => [
'struct ',
node.name,
' {',
node.members.length > 0
? printSeparatedList(path.map(print, 'members'), {
firstSeparator: hardline,

@@ -20,11 +17,5 @@ separator: [';', hardline],

})
);
}
parts.push('}');
return parts;
}
: '',
'}'
]
};
module.exports = StructDefinition;

@@ -1,5 +0,3 @@

const ThrowStatement = {
export const ThrowStatement = {
print: () => 'throw;'
};
module.exports = ThrowStatement;

@@ -1,12 +0,9 @@

const {
doc: {
builders: { join, line }
}
} = require('prettier');
const {
import { doc } from 'prettier';
import {
printSeparatedItem,
printSeparatedList
} = require('../common/printer-helpers');
} from '../common/printer-helpers.js';
const { join, line } = doc.builders;
const returnParameters = (node, path, print) =>

@@ -21,3 +18,3 @@ node.returnParameters

const TryStatement = {
export const TryStatement = {
print: ({ node, path, print }) => {

@@ -45,3 +42,1 @@ let parts = [

};
module.exports = TryStatement;

@@ -1,8 +0,5 @@

const {
doc: {
builders: { group }
}
} = require('prettier');
import { doc } from 'prettier';
import { printSeparatedList } from '../common/printer-helpers.js';
const { printSeparatedList } = require('../common/printer-helpers');
const { group } = doc.builders;

@@ -16,3 +13,3 @@ const contents = (node, path, print) =>

const TupleExpression = {
export const TupleExpression = {
print: ({ node, path, print }) =>

@@ -25,3 +22,1 @@ group([

};
module.exports = TupleExpression;

@@ -1,5 +0,3 @@

const TypeDefinition = {
export const TypeDefinition = {
print: ({ node }) => ['type ', node.name, ' is ', node.definition.name, ';']
};
module.exports = TypeDefinition;

@@ -1,2 +0,2 @@

const UnaryOperation = {
export const UnaryOperation = {
print: ({ node, path, print }) =>

@@ -11,3 +11,1 @@ node.isPrefix

};
module.exports = UnaryOperation;

@@ -1,11 +0,7 @@

const {
doc: {
builders: { group }
}
} = require('prettier');
import { doc } from 'prettier';
const UncheckedStatement = {
const { group } = doc.builders;
export const UncheckedStatement = {
print: ({ path, print }) => group(['unchecked ', path.call(print, 'block')])
};
module.exports = UncheckedStatement;

@@ -1,5 +0,3 @@

const UserDefinedTypeName = {
export const UserDefinedTypeName = {
print: ({ node }) => node.namePath
};
module.exports = UserDefinedTypeName;

@@ -1,45 +0,29 @@

const {
doc: {
builders: { line, softline }
}
} = require('prettier');
import { doc } from 'prettier';
import { printSeparatedList } from '../common/printer-helpers.js';
const { printSeparatedList } = require('../common/printer-helpers');
const { line, softline } = doc.builders;
const UsingForDeclaration = {
print: ({ node, path, print, options }) => {
const parts = ['using '];
if (node.functions && node.functions.length) {
const importedFunctions = [];
for (let i = 0; i < node.functions.length; i += 1) {
const fun = node.functions[i];
const operator = node.operators[i];
if (operator) {
importedFunctions.push(`${fun} as ${operator}`);
} else {
importedFunctions.push(fun);
}
}
parts.push('{');
parts.push(
printSeparatedList(importedFunctions, {
firstSeparator: options.bracketSpacing ? line : softline
})
);
parts.push('}');
} else {
parts.push(node.libraryName);
}
parts.push(' for ');
parts.push(node.typeName ? path.call(print, 'typeName') : '*');
parts.push(node.isGlobal ? ' global;' : ';');
return parts;
}
export const UsingForDeclaration = {
print: ({ node, path, print, options }) => [
'using ',
node.functions && node.functions.length
? [
'{',
printSeparatedList(
node.functions.map((functionName, i) =>
node.operators[i]
? [functionName, ' as ', node.operators[i]]
: functionName
),
{
firstSeparator: options.bracketSpacing ? line : softline
}
),
'}'
]
: node.libraryName,
' for ',
node.typeName ? path.call(print, 'typeName') : '*',
node.isGlobal ? ' global;' : ';'
]
};
module.exports = UsingForDeclaration;

@@ -1,8 +0,5 @@

const {
doc: {
builders: { group, indent, line }
}
} = require('prettier');
import { doc } from 'prettier';
import { printSeparatedList } from '../common/printer-helpers.js';
const { printSeparatedList } = require('../common/printer-helpers');
const { group, indent, line } = doc.builders;

@@ -38,3 +35,3 @@ const indexed = (node) => (node.isIndexed ? ' indexed' : '');

const VariableDeclaration = {
export const VariableDeclaration = {
print: ({ node, path, print }) =>

@@ -56,3 +53,1 @@ node.typeName

};
module.exports = VariableDeclaration;

@@ -1,11 +0,8 @@

const {
doc: {
builders: { group, indentIfBreak }
}
} = require('prettier');
import { doc } from 'prettier';
import { printSeparatedList } from '../common/printer-helpers.js';
const { printSeparatedList } = require('../common/printer-helpers');
const { group, indentIfBreak } = doc.builders;
const embraceVariables = (doc, embrace) =>
embrace ? ['(', printSeparatedList(doc), ')'] : doc;
const embraceVariables = (document, embrace) =>
embrace ? ['(', printSeparatedList(document), ')'] : document;

@@ -16,3 +13,3 @@ const initialValue = (node, path, print) =>

let groupIndex = 0;
const VariableDeclarationStatement = {
export const VariableDeclarationStatement = {
print: ({ node, path, print }) => {

@@ -44,3 +41,1 @@ const startsWithVar =

};
module.exports = VariableDeclarationStatement;

@@ -1,8 +0,5 @@

const {
doc: {
builders: { group, indent, line }
}
} = require('prettier');
import { doc } from 'prettier';
import { printSeparatedItem } from '../common/printer-helpers.js';
const { printSeparatedItem } = require('../common/printer-helpers');
const { group, indent, line } = doc.builders;

@@ -14,3 +11,3 @@ const printBody = (node, path, print) =>

const WhileStatement = {
export const WhileStatement = {
print: ({ node, path, print }) => [

@@ -23,3 +20,1 @@ 'while (',

};
module.exports = WhileStatement;

@@ -51,2 +51,2 @@ const CATEGORY_GLOBAL = 'Global';

module.exports = options;
export default options;

@@ -1,6 +0,6 @@

const extractComments = require('solidity-comments-extractor');
import extractComments from 'solidity-comments-extractor';
// https://prettier.io/docs/en/plugins.html#parsers
const parser = require('@solidity-parser/parser');
const coerce = require('semver/functions/coerce');
const satisfies = require('semver/functions/satisfies');
import parser from '@solidity-parser/parser';
import coerce from 'semver/functions/coerce.js';
import satisfies from 'semver/functions/satisfies.js';

@@ -64,9 +64,2 @@ const tryHug = (node, operators) => {

},
ElementaryTypeName(ctx) {
// if the compiler is below 0.8.0 we will recognize the type 'byte' as an
// alias of 'bytes1'. Otherwise we will ignore this and enforce always
// 'bytes1'.
const pre080 = compiler && satisfies(compiler, '<0.8.0');
if (!pre080 && ctx.name === 'byte') ctx.name = 'bytes1';
},
BinaryOperation(ctx) {

@@ -188,2 +181,2 @@ switch (ctx.operator) {

module.exports = parse;
export default parse;

@@ -1,16 +0,13 @@

"use strict";
import { util } from "prettier";
import { getNextNonSpaceNonCommentCharacter } from "../../common/backward-compatibility.js";
const {
util: {
addLeadingComment,
addTrailingComment,
addDanglingComment,
getNextNonSpaceNonCommentCharacterIndex,
hasNewline,
hasNewlineInRange
}
} = require('prettier');
const { getNextNonSpaceNonCommentCharacter } = require("../../common/util");
addLeadingComment,
addTrailingComment,
addDanglingComment,
hasNewline,
hasNewlineInRange
} = util
function handleOwnLineComment(comment, text, options, ast, isLastComment) {
export function handleOwnLineComment(comment, text, options, ast, isLastComment) {
const { precedingNode, enclosingNode, followingNode } = comment;

@@ -80,3 +77,3 @@ if (

function handleEndOfLineComment(comment, text, options, ast, isLastComment) {
export function handleEndOfLineComment(comment, text, options, ast, isLastComment) {
const { precedingNode, enclosingNode, followingNode } = comment;

@@ -136,3 +133,3 @@ if (

function handleRemainingComment(comment, text, options, ast, isLastComment) {
export function handleRemainingComment(comment, text, options, ast, isLastComment) {
const { precedingNode, enclosingNode, followingNode } = comment;

@@ -839,11 +836,4 @@

function isBlockComment(comment) {
export function isBlockComment(comment) {
return comment.type === "Block" || comment.type === "CommentBlock";
}
module.exports = {
handleOwnLineComment,
handleEndOfLineComment,
handleRemainingComment,
isBlockComment
};

@@ -1,7 +0,7 @@

const nodes = require('./nodes');
const {
import * as nodes from './nodes/index.js';
import {
hasNodeIgnoreComment,
prettierVersionSatisfies
} = require('./common/util');
const ignoreComments = require('./comments/ignore');
} from './common/util.js';
import ignoreComments from './comments/ignore.js';

@@ -12,3 +12,3 @@ let checked = false;

if (checked) return;
if (!prettierVersionSatisfies('>=2.3.0 || >=3.0.0-alpha.0')) {
if (!prettierVersionSatisfies('>=2.3.0')) {
throw new Error(

@@ -45,2 +45,2 @@ 'The version of prettier in your node-modules does not satisfy the required ">=2.3.0" constraint. Please update the version of Prettier.'

module.exports = genericPrint;
export default genericPrint;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc