Skip to content

Commit

Permalink
add support for documentation of global variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Vsevo1od committed Dec 2, 2021
1 parent ef47ca5 commit c3b7d8d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/solc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export namespace ast {
nodeType: 'VariableDeclaration';
visibility: 'internal' | 'public' | 'private';
name: string;
documentation: string | null;
constant: boolean;
typeName: TypeName;
}
Expand Down
12 changes: 8 additions & 4 deletions src/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,13 @@ class SourceStateVariable implements Linkable {
return `${this.type} ${this.name}`;
}

get natspec(): {} {
warnStateVariableNatspec();
return {}
@memoize
get natspec(): NatSpec {
if (this.astNode.documentation === null || this.astNode.documentation === undefined) {
return {};
}

return parseNatSpec(this.astNode.documentation, this);
}
}

Expand Down Expand Up @@ -554,7 +558,7 @@ interface NatSpec {
};
}

function parseNatSpec(doc: string, context: SourceFunctionLike | SourceContract): NatSpec {
function parseNatSpec(doc: string, context: SourceFunctionLike | SourceContract | SourceStateVariable): NatSpec {
const res: NatSpec = {};

const tagMatches = execall(/^(?:@(\w+|custom:[a-z][a-z-]*) )?((?:(?!^@(?:\w+|custom:[a-z][a-z-]*) )[^])*)/m, doc);
Expand Down

0 comments on commit c3b7d8d

Please sign in to comment.