prettier-plugin-solidity
Version:
A Prettier Plugin for automatically formatting your Solidity code.
52 lines • 2.24 kB
JavaScript
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { printFunction } from '../slang-printers/print-function.js';
import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js';
import { Identifier } from './Identifier.js';
import { ParametersDeclaration } from './ParametersDeclaration.js';
import { Parameters } from './Parameters.js';
import { ModifierAttributes } from './ModifierAttributes.js';
import { FunctionBody } from './FunctionBody.js';
export class ModifierDefinition {
constructor(ast, options) {
this.kind = NonterminalKind.ModifierDefinition;
let metadata = getNodeMetadata(ast);
this.name = new Identifier(ast.name);
if (ast.parameters) {
this.parameters = new ParametersDeclaration(ast.parameters, options);
}
this.attributes = new ModifierAttributes(ast.attributes);
this.body = new FunctionBody(ast.body, options);
metadata = updateMetadata(metadata, [
this.parameters,
this.attributes,
this.body
]);
this.comments = metadata.comments;
this.loc = metadata.loc;
if (!this.parameters) {
const parametersOffset = this.attributes.loc.start - this.attributes.loc.leadingOffset;
const parametersLoc = {
start: parametersOffset,
end: parametersOffset,
leadingOffset: 0,
trailingOffset: 0
};
this.parameters = Object.assign(Object.create(ParametersDeclaration.prototype), {
kind: NonterminalKind.ParametersDeclaration,
loc: Object.assign({}, parametersLoc),
comments: [],
parameters: Object.assign(Object.create(Parameters.prototype), {
kind: NonterminalKind.Parameters,
loc: Object.assign({}, parametersLoc),
comments: [],
items: [],
separators: []
})
});
}
}
print(path, print) {
return printFunction(['modifier ', path.call(print, 'name')], this, path, print);
}
}
//# sourceMappingURL=ModifierDefinition.js.map