prettier-plugin-solidity
Version:
A Prettier Plugin for automatically formatting your Solidity code.
42 lines (32 loc) • 1.28 kB
text/typescript
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { joinExisting } from '../slang-utils/join-existing.js';
import { extractVariant } from '../slang-utils/extract-variant.js';
import { SlangNode } from './SlangNode.js';
import { TypeName } from './TypeName.js';
import { TerminalNode } from './TerminalNode.js';
import type * as ast from '@nomicfoundation/slang/ast';
import type { AstPath, Doc, ParserOptions } from 'prettier';
import type { PrintFunction } from '../types.d.ts';
import type { AstNode } from './types.d.ts';
export class EventParameter extends SlangNode {
readonly kind = NonterminalKind.EventParameter;
typeName: TypeName['variant'];
indexedKeyword?: string;
name?: TerminalNode;
constructor(ast: ast.EventParameter, options: ParserOptions<AstNode>) {
super(ast);
this.typeName = extractVariant(new TypeName(ast.typeName, options));
this.indexedKeyword = ast.indexedKeyword?.unparse();
if (ast.name) {
this.name = new TerminalNode(ast.name);
}
this.updateMetadata(this.typeName);
}
print(path: AstPath<EventParameter>, print: PrintFunction): Doc {
return joinExisting(' ', [
path.call(print, 'typeName'),
this.indexedKeyword,
path.call(print, 'name')
]);
}
}