diff --git a/src/solc-output-builder.ts b/src/solc-output-builder.ts index 8d52efd0..e47378b2 100644 --- a/src/solc-output-builder.ts +++ b/src/solc-output-builder.ts @@ -121,6 +121,7 @@ export class SolcOutputBuilder implements SolcOutput { nodeType: 'VariableDeclaration', visibility: 'public', name: variableName, + documentation: null, constant: false, typeName: { nodeType: 'ElementaryTypeName', diff --git a/src/solc.ts b/src/solc.ts index e6e0040e..6578a3d7 100644 --- a/src/solc.ts +++ b/src/solc.ts @@ -52,6 +52,7 @@ export namespace ast { nodeType: 'VariableDeclaration'; visibility: 'internal' | 'public' | 'private'; name: string; + documentation: string | null; constant: boolean; typeName: TypeName; } diff --git a/src/source.ts b/src/source.ts index 4c667020..24738fa9 100644 --- a/src/source.ts +++ b/src/source.ts @@ -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); } } @@ -452,7 +456,7 @@ class SourceStruct extends SourceContractItem { } get natspec(): {} { - warnStateVariableNatspec(); + warnNatSpecIsNotAvailable(); return {} } } @@ -471,7 +475,7 @@ class SourceEnum extends SourceContractItem { } get natspec(): {} { - warnStateVariableNatspec(); + warnNatSpecIsNotAvailable(); return {} } } @@ -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); @@ -675,4 +679,4 @@ function oneTimeLogger(msg: string): () => void { }; } -const warnStateVariableNatspec = oneTimeLogger('Warning: NatSpec is currently not available for state variables, structs, or enums.'); +const warnNatSpecIsNotAvailable = oneTimeLogger('Warning: NatSpec is currently not available for structs and enums.');