UNPKG

prettier-plugin-solidity

Version:

A Prettier Plugin for automatically formatting your Solidity code.

48 lines 1.91 kB
import { NonterminalKind } from '@nomicfoundation/slang/cst'; import { doc } from 'prettier'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { VariableDeclarationType } from './VariableDeclarationType.js'; import { StorageLocation } from './StorageLocation.js'; import { Identifier } from './Identifier.js'; import { VariableDeclarationValue } from './VariableDeclarationValue.js'; const { group, indent, indentIfBreak, line } = doc.builders; export class VariableDeclarationStatement { constructor(ast, options) { this.kind = NonterminalKind.VariableDeclarationStatement; let metadata = getNodeMetadata(ast); this.variableType = new VariableDeclarationType(ast.variableType, options); if (ast.storageLocation) { this.storageLocation = new StorageLocation(ast.storageLocation); } this.name = new Identifier(ast.name); if (ast.value) { this.value = new VariableDeclarationValue(ast.value, options); } metadata = updateMetadata(metadata, [ this.variableType, this.storageLocation, this.value ]); this.comments = metadata.comments; this.loc = metadata.loc; } print(path, print) { const groupId = Symbol('Slang.VariableDeclarationStatement.variables'); const declarationDoc = group([ path.call(print, 'variableType'), indent([ this.storageLocation ? [line, path.call(print, 'storageLocation')] : '', ' ', path.call(print, 'name') ]) ], { id: groupId }); return [ declarationDoc, indentIfBreak(path.call(print, 'value'), { groupId }), ';' ]; } } //# sourceMappingURL=VariableDeclarationStatement.js.map