Skip to content

Commit f0acefb

Browse files
committed
use more efficient ast deref implementation
1 parent 00207ef commit f0acefb

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"lodash": "^4.17.20",
4343
"minimatch": "^6.0.0",
4444
"minimist": "^1.2.5",
45-
"solidity-ast": "^0.4.13"
45+
"solidity-ast": "^0.4.48"
4646
},
4747
"devDependencies": {
4848
"@types/lodash": "^4.14.165",

src/ast-resolver.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import { ContractDefinition } from 'solidity-ast';
2-
import { findAll } from 'solidity-ast/utils';
2+
import { findAll, astDereferencer, ASTDereferencer } from 'solidity-ast/utils';
33
import { NodeType, NodeTypeMap } from 'solidity-ast/node';
44

55
import { SolcOutput } from './solc/input-output';
66

77
export class ASTResolver {
8-
constructor(readonly output: SolcOutput, readonly exclude?: (source: string) => boolean) {}
8+
private deref: ASTDereferencer;
9+
10+
constructor(readonly output: SolcOutput, readonly exclude?: (source: string) => boolean) {
11+
this.deref = astDereferencer(output);
12+
}
913

1014
resolveContract(id: number): ContractDefinition | undefined {
1115
try {
@@ -28,16 +32,12 @@ export class ASTResolver {
2832
}
2933

3034
tryResolveNode<T extends NodeType>(nodeType: T, id: number): NodeTypeMap[T] | undefined {
31-
for (const source in this.output.sources) {
32-
for (const c of findAll(nodeType, this.output.sources[source].ast)) {
33-
if (c.id === id) {
34-
if (this.exclude?.(source)) {
35-
throw new Error(`Symbol #${id} was imported from an excluded file (${source})`);
36-
} else {
37-
return c;
38-
}
39-
}
40-
}
35+
const { node, sourceUnit } = this.deref.withSourceUnit(nodeType, id);
36+
const source = sourceUnit.absolutePath;
37+
if (this.exclude?.(source)) {
38+
throw new Error(`Symbol #${id} was imported from an excluded file (${source})`);
39+
} else {
40+
return node;
4141
}
4242
}
4343
}

0 commit comments

Comments
 (0)