From b7084b3bb67782cdd0e683f27bbcd0f512d4084a Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Sat, 30 Sep 2023 02:17:47 -0300 Subject: [PATCH] Fix missing types due to aliased imports --- CHANGELOG.md | 4 ++++ src/core.test.ts.md | 1 + src/core.test.ts.snap | Bin 2431 -> 2425 bytes src/core.ts | 34 +++++++++++++++++++++------------- 4 files changed, 26 insertions(+), 13 deletions(-) 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 a4e1cc83ff696a9f68d8b6344944bf6b7b8035c8..62e03a23d55114641f1386e8e172d2c346e88598 100644 GIT binary patch literal 2425 zcmV-<35NDTRzVgSH9{jLs0Wzm{Gd9kyEsN1cPGtE-j`&UGL;riN66N76UD zTaCw!ttYFiNViNIOZOX%O~o{@4HWEb9t;(2phC4lD%>YT{vBz}zat?>3a)=zmB^k01)>W`Zo?slwgI#;-TT$|tITREcSBaItxU*jZCV&u zEtN)&5PfS}(71$_1vO-F^p!3oj0q2xQ2NQ+>bM`pxuboB-Bsx36XgzaxpP-Ois?gSUw2_Mtga}fgz_N zSdKtgUL*|5Jcwtf`J4gl_J2bF`_Ju30nF$_8xh+oFb=Wjz$QYrT?hG>6L-%58CZVw zSQ@VTGV8;9F7wH=+!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8GXKq9%SMVPkRNkpW*!m zUIP%u4b8xKV4;@_uqO7-t8u!A3+4bs=MW#e$>TaZq7GH6*_mmkX7YD3H{b%sE-Mkb z2+^sR|7yhYYbAxAMpJLawzX_vkBEEN#CG!2Ibxl9RBWSd7=!~qXDZ~>v&gP_bQeM( zFKg(FRXZDRsz*l-_f~wQ%W?&K!O*~euaJbeqm<*f4gHlpE_>&{p~q$aeWyCmSqk>k zJJ87;(cxShX@L95J^)l5{hXhppWIooEVpKzM5_*o-aH^q?~rJDAbN!v$2qGbrd8NB1iw?wD9%ao!WCgyP2R^pOx5jIHy5#1T z_kUx{`&<7BmiHglR%G(ML;n6r{ywRFaIf~kv)*5zf@`(l^6uTcOSO-dYRgNtJA`KW z54Dx0+O2!F--8}mwGS|S4shQu+zrDDCHGVLANxz|3;tI zN=t>sg!757apA7SjO@vY@J~*GG176X#EJ_H5|Xmvd(Z(IzV;@CHHb*25>px(shrVb z%Z4gaaH!Irr*odBZ}>DSv@~<%o?a59jD12T5UL?daHWAM(o{>Z$wr{UWSS}*+$P?# xQg1I<`BzeZ{p~gN*Pq7wYyLF_*&TBATJ 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) {