prettier-plugin-solidity
Version:
A Prettier Plugin for automatically formatting your Solidity code.
36 lines • 1.66 kB
JavaScript
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { doc } from 'prettier';
import { printGroupAndIndentIfBreakPair } from '../slang-printers/print-group-and-indent-if-break-pair.js';
import { extractVariant } from '../slang-utils/extract-variant.js';
import { SlangNode } from './SlangNode.js';
import { VariableDeclarationType } from './VariableDeclarationType.js';
import { StorageLocation } from './StorageLocation.js';
import { TerminalNode } from './TerminalNode.js';
import { VariableDeclarationValue } from './VariableDeclarationValue.js';
const { indent, line } = doc.builders;
export class VariableDeclarationStatement extends SlangNode {
constructor(ast, options) {
super(ast);
this.kind = NonterminalKind.VariableDeclarationStatement;
this.variableType = extractVariant(new VariableDeclarationType(ast.variableType, options));
if (ast.storageLocation) {
this.storageLocation = new StorageLocation(ast.storageLocation);
}
this.name = new TerminalNode(ast.name);
if (ast.value) {
this.value = new VariableDeclarationValue(ast.value, options);
}
this.updateMetadata(this.variableType, this.storageLocation, this.value);
}
print(path, print) {
return printGroupAndIndentIfBreakPair([
path.call(print, 'variableType'),
this.storageLocation
? indent([line, path.call(print, 'storageLocation')])
: '',
' ',
path.call(print, 'name')
], [path.call(print, 'value'), ';']);
}
}
//# sourceMappingURL=VariableDeclarationStatement.js.map