prettier-plugin-solidity
Version:
A Prettier Plugin for automatically formatting your Solidity code.
30 lines • 1.41 kB
JavaScript
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { doc } from 'prettier';
import { satisfies } from 'semver';
import { printSeparatedList } from '../slang-printers/print-separated-list.js';
import { SlangNode } from './SlangNode.js';
import { ImportDeconstructionSymbol } from './ImportDeconstructionSymbol.js';
const { line, softline } = doc.builders;
export class ImportDeconstructionSymbols extends SlangNode {
constructor(ast, collected) {
super(ast, collected, true);
this.kind = NonterminalKind.ImportDeconstructionSymbols;
this.items = ast.items.map((item) => new ImportDeconstructionSymbol(item, collected));
}
print(path, print, { compiler, bracketSpacing }) {
const items = path.map(print, 'items');
return printSeparatedList(items, items.length > 1 && 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: bracketSpacing ? line : softline
}
: {
// if the compiler is not given or is lower than 0.7.4 we will not
// split the ImportDirective.
firstSeparator: bracketSpacing ? ' ' : '',
separator: ', '
});
}
}
//# sourceMappingURL=ImportDeconstructionSymbols.js.map