solidity-docgen
Version:
Solidity API documentation automatic generator.
84 lines • 2.66 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// fake solc output builder for tests
class SolcOutputBuilder {
constructor() {
this.errors = [];
this.sources = {};
this._nextId = 0;
this._contractIds = {};
}
file(fileName) {
this._currentFile = fileName;
this.sources[fileName] = {
ast: {
nodeType: 'SourceUnit',
nodes: [],
},
};
return this;
}
contract(contractName, ...baseContracts) {
const fileName = this._currentFile;
if (fileName === undefined)
throw new Error('No file defined');
const id = this._getContractId(contractName);
const astNode = {
nodeType: 'ContractDefinition',
name: contractName,
documentation: null,
id,
linearizedBaseContracts: [id].concat(
// this isn't really linearizing, but it'll do
baseContracts.map(name => this._getContractId(name))),
nodes: [],
};
this._currentContract = { astNode };
this.sources[fileName].ast.nodes.push(astNode);
return this;
}
_getContractId(contractName) {
if (contractName in this._contractIds) {
return this._contractIds[contractName];
}
else {
const id = this._nextId;
this._nextId += 1;
this._contractIds[contractName] = id;
return id;
}
}
function(functionName, ...argTypes) {
const contract = this._currentContract;
if (contract === undefined)
throw new Error('No contract defined');
const kind = functionName === 'fallback' || functionName === 'constructor'
? functionName
: 'function';
const astNode = {
nodeType: 'FunctionDefinition',
kind,
visibility: 'public',
name: functionName,
documentation: null,
parameters: {
parameters: argTypes.map(t => ({
name: '',
typeName: {
nodeType: 'ElementaryTypeName',
typeDescriptions: {
typeString: t,
},
},
})),
},
returnParameters: {
parameters: [],
},
};
contract.astNode.nodes.push(astNode);
return this;
}
}
exports.SolcOutputBuilder = SolcOutputBuilder;
//# sourceMappingURL=solc.js.map