Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
cd1m0 committed Sep 21, 2021
2 parents 63b831b + 14a3704 commit 8dafdf7
Show file tree
Hide file tree
Showing 159 changed files with 7,641 additions and 4,694 deletions.
929 changes: 334 additions & 595 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"fs-extra": "^10.0.0",
"logplease": "^1.2.15",
"semver": "^7.3.5",
"solc-typed-ast": "^5.0.3",
"solc-typed-ast": "^6.1.2",
"src-location": "^1.1.0"
},
"scripts": {
Expand Down
32 changes: 22 additions & 10 deletions src/ast_to_source_printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,28 @@ function findImport(

// Check if `from` re-exports `name`
for (const importDir of from.vImportDirectives) {
if (importDir.vSymbolAliases.length === 0) {
if (importDir.vSymbolAliases.length === 0 && importDir.unitAlias === "") {
// Simple import - e.g 'import "abc.sol"'. All top-level definition from "abc.sol" are imported.
const importee = findImport(name, importDir.vSourceUnit, sources, factory);

if (importee !== undefined) {
return importee;
}
} else if (importDir.unitAlias !== "") {
// Unit alias import - 'import "abc.sol" as abc'. `abc` is the only identifier defined.
if (importDir.unitAlias === name) return importDir;
} else {
// Individual symbols imported - 'import {A, B as C} from "abc.sol"'. Only listed definitions imported.
for (const [origin, alias] of importDir.vSymbolAliases) {
const originName =
origin instanceof ImportDirective ? origin.unitAlias : origin.name;
let impName: string;

if ((alias !== undefined && alias === name) || originName === name) {
if (alias != undefined) {
impName = alias;
} else {
impName = origin instanceof ImportDirective ? origin.unitAlias : origin.name;
}

if (impName === name) {
return origin;
}
}
Expand Down Expand Up @@ -107,11 +117,17 @@ export function rewriteImports(
`Sym ${symDesc.name} not found in exports of ${importedUnit.sourceEntryKey}`
);

const id = factory.makeIdentifierFor(sym);
const id = factory.makeIdentifier("<missing>", symDesc.name, sym.id);

id.parent = importDir;

newSymbolAliases.push({ foreign: id, local: symDesc.alias });

const symName = symDesc.alias !== null ? symDesc.alias : id.name;

if (!sourceUnit.exportedSymbols.has(symName)) {
sourceUnit.exportedSymbols.set(symName, id.referencedDeclaration);
}
}

importDir.symbolAliases = newSymbolAliases;
Expand All @@ -129,17 +145,13 @@ function getWriter(targetCompilerVersion: string): ASTWriter {

const formatter = new PrettyFormatter(4);
const writer = new ASTWriter(DefaultASTWriterMapping, formatter, targetCompilerVersion);

writerCache.set(targetCompilerVersion, writer);

return writer;
}
/**
* Print a list of SourceUnits, with potentially different versions and ASTContext's
*
* @param sourceUnits
* @param factoryMap
* @param targetCompilerVersion
* @param skipImportRewriting
*/
export function print(
sourceUnits: SourceUnit[],
Expand Down
Loading

0 comments on commit 8dafdf7

Please sign in to comment.