prettier-plugin-solidity
Version:
A Prettier Plugin for automatically formatting your Solidity code.
42 lines • 1.68 kB
JavaScript
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { doc } from 'prettier';
import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js';
import { TypeName } from './TypeName.js';
import { StateVariableAttributes } from './StateVariableAttributes.js';
import { Identifier } from './Identifier.js';
import { StateVariableDefinitionValue } from './StateVariableDefinitionValue.js';
const { group, indent, indentIfBreak } = doc.builders;
export class StateVariableDefinition {
constructor(ast, options) {
this.kind = NonterminalKind.StateVariableDefinition;
let metadata = getNodeMetadata(ast);
this.typeName = new TypeName(ast.typeName, options);
this.attributes = new StateVariableAttributes(ast.attributes);
this.name = new Identifier(ast.name);
if (ast.value) {
this.value = new StateVariableDefinitionValue(ast.value, options);
}
metadata = updateMetadata(metadata, [
this.typeName,
this.attributes,
this.value
]);
this.comments = metadata.comments;
this.loc = metadata.loc;
}
print(path, print) {
const groupId = Symbol('Slang.StateVariableDefinition.attributes');
const attributesDoc = group(indent(path.call(print, 'attributes')), {
id: groupId
});
return [
path.call(print, 'typeName'),
attributesDoc,
' ',
path.call(print, 'name'),
this.value ? indentIfBreak(path.call(print, 'value'), { groupId }) : '',
';'
];
}
}
//# sourceMappingURL=StateVariableDefinition.js.map