Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for documentation of global variables #340

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/solc-output-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export class SolcOutputBuilder implements SolcOutput {
nodeType: 'VariableDeclaration',
visibility: 'public',
name: variableName,
documentation: null,
constant: false,
typeName: {
nodeType: 'ElementaryTypeName',
Expand Down
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
18 changes: 11 additions & 7 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 @@ -452,7 +456,7 @@ class SourceStruct extends SourceContractItem {
}

get natspec(): {} {
warnStateVariableNatspec();
warnNatSpecIsNotAvailable();
return {}
}
}
Expand All @@ -471,7 +475,7 @@ class SourceEnum extends SourceContractItem {
}

get natspec(): {} {
warnStateVariableNatspec();
warnNatSpecIsNotAvailable();
return {}
}
}
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 Expand Up @@ -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.');