diff --git a/CHANGELOG.md b/CHANGELOG.md index c76d89f..c328f91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.3.14 + +- Fix missing types when project uses aliased imports. + ## 0.3.13 - Interfaces are not longer exposed. diff --git a/src/core.test.ts.md b/src/core.test.ts.md index 25c95db..6784d97 100644 --- a/src/core.test.ts.md +++ b/src/core.test.ts.md @@ -377,6 +377,7 @@ Generated by [AVA](https://avajs.dev). import "../contracts/Test.sol";␊ import "../contracts/Imported.sol";␊ import "../contracts/Imported2.sol";␊ + import "@openzeppelin/contracts/proxy/Clones.sol";␊ ␊ contract $Foo is Foo {␊ bytes32 public constant __hh_exposed_bytecode_marker = "hardhat-exposed";␊ diff --git a/src/core.test.ts.snap b/src/core.test.ts.snap index a4e1cc8..62e03a2 100644 Binary files a/src/core.test.ts.snap and b/src/core.test.ts.snap differ diff --git a/src/core.ts b/src/core.ts index a6f8039..3702f40 100644 --- a/src/core.ts +++ b/src/core.ts @@ -121,19 +121,7 @@ function getExposedContent(ast: SourceUnit, relativizePath: (p: string) => strin const contractPrefix = prefix.replace(/^./, c => c.toUpperCase()); - const neededAbsoluteImports = [ast.absolutePath].concat( - [...findAll('ImportDirective', ast)] - .filter(i => i.symbolAliases.length > 0) - .map(i => i.absolutePath), - [...findAll('ContractDefinition', ast)] - .flatMap(c => c.linearizedBaseContracts.map(p => { - const sourceId = deref('ContractDefinition', p).scope; - return deref('SourceUnit', sourceId).absolutePath; - })), - ); - - // remove duplicates and relativize - const imports = Array.from(new Set(neededAbsoluteImports), relativizePath); + const imports = Array.from(getNeededImports(ast, deref), u => relativizePath(u.absolutePath)); const contracts = [...findAll('ContractDefinition', ast)].filter(c => filter?.(c) !== false && c.contractKind !== 'interface'); @@ -575,6 +563,26 @@ function getFunctions(contract: ContractDefinition, deref: ASTDereferencer, subs return res; } +function* getNeededImports(ast: SourceUnit, deref: ASTDereferencer): Iterable { + const needed = new Set([ast].concat( + [...findAll('ContractDefinition', ast)] + .flatMap(c => c.linearizedBaseContracts.map(p => { + const { sourceUnit } = deref.withSourceUnit('ContractDefinition', p) + return sourceUnit; + })), + )); + + for (const n of needed) { + yield n; + + for (const imp of findAll('ImportDirective', n)) { + if (imp.symbolAliases.length > 0) { + needed.add(deref('SourceUnit', imp.sourceUnit)); + } + } + } +} + function mustGet(map: Map, key: K): V { const value = map.get(key); if (value === undefined) {