solidity-docgen
Advanced tools
Comparing version 0.5.15 to 0.5.16
# Changelog | ||
## 0.5.16 | ||
- Change handling of circular dependencies to an incomplete but correct approach, fixing a potential issue with bad caching. | ||
## 0.5.15 | ||
@@ -4,0 +8,0 @@ |
@@ -72,10 +72,17 @@ "use strict"; | ||
], SourceFile.prototype, "contracts", null); | ||
const scopeCache = new WeakMap(); | ||
function contractsInScope(file) { | ||
__decorate([ | ||
memoize_1.memoize | ||
], SourceFile.prototype, "contractsInScope", null); | ||
function contractsInScope(file, stack = new Set(), aliasedImport = false) { | ||
var _a; | ||
if (scopeCache.has(file)) { | ||
return scopeCache.get(file); | ||
if (stack.has(file)) { | ||
if (aliasedImport) { | ||
throw new Error('Circular dependency detected: aliased imports not supported'); | ||
} | ||
else { | ||
return {}; | ||
} | ||
} | ||
stack.add(file); | ||
const scope = {}; | ||
scopeCache.set(file, scope); | ||
for (const c of file.contracts) { | ||
@@ -87,8 +94,9 @@ scope[c.name] = c; | ||
const importedFile = file.source.fileById(i.sourceUnit); | ||
const importedScope = contractsInScope(importedFile, stack, aliasedImport || i.symbolAliases.length > 0); | ||
if (i.symbolAliases.length === 0) { | ||
Object.assign(scope, importedFile.contractsInScope); | ||
Object.assign(scope, importedScope); | ||
} | ||
else { | ||
for (const a of i.symbolAliases) { | ||
scope[(_a = a.local) !== null && _a !== void 0 ? _a : a.foreign.name] = importedFile.contractsInScope[a.foreign.name]; | ||
scope[(_a = a.local) !== null && _a !== void 0 ? _a : a.foreign.name] = importedScope[a.foreign.name]; | ||
} | ||
@@ -98,2 +106,3 @@ } | ||
; | ||
stack.delete(file); | ||
return scope; | ||
@@ -100,0 +109,0 @@ } |
{ | ||
"name": "solidity-docgen", | ||
"version": "0.5.15", | ||
"version": "0.5.16", | ||
"description": "Solidity API documentation automatic generator.", | ||
@@ -5,0 +5,0 @@ "repository": "github:OpenZeppelin/solidity-docgen", |
@@ -72,2 +72,3 @@ import { flatten, uniqBy, groupBy, defaults } from 'lodash'; | ||
@memoize | ||
get contractsInScope(): Record<string, SourceContract> { | ||
@@ -82,13 +83,19 @@ return contractsInScope(this); | ||
const scopeCache = new WeakMap<SourceFile, Record<string, SourceContract>>(); | ||
function contractsInScope(file: SourceFile): Record<string, SourceContract> { | ||
if (scopeCache.has(file)) { | ||
return scopeCache.get(file)!; | ||
function contractsInScope( | ||
file: SourceFile, | ||
stack = new Set<SourceFile>(), | ||
aliasedImport = false, | ||
): Record<string, SourceContract> { | ||
if (stack.has(file)) { | ||
if (aliasedImport) { | ||
throw new Error('Circular dependency detected: aliased imports not supported'); | ||
} else { | ||
return {}; | ||
} | ||
} | ||
stack.add(file); | ||
const scope: Record<string, SourceContract> = {}; | ||
scopeCache.set(file, scope); | ||
for (const c of file.contracts) { | ||
@@ -101,7 +108,8 @@ scope[c.name] = c; | ||
const importedFile = file.source.fileById(i.sourceUnit); | ||
const importedScope = contractsInScope(importedFile, stack, aliasedImport || i.symbolAliases.length > 0); | ||
if (i.symbolAliases.length === 0) { | ||
Object.assign(scope, importedFile.contractsInScope); | ||
Object.assign(scope, importedScope); | ||
} else { | ||
for (const a of i.symbolAliases) { | ||
scope[a.local ?? a.foreign.name] = importedFile.contractsInScope[a.foreign.name]; | ||
scope[a.local ?? a.foreign.name] = importedScope[a.foreign.name]; | ||
} | ||
@@ -111,2 +119,4 @@ } | ||
stack.delete(file); | ||
return scope; | ||
@@ -113,0 +123,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
229197
4108