aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-cov
diff options
context:
space:
mode:
Diffstat (limited to 'packages/sol-cov')
-rw-r--r--packages/sol-cov/src/ast_visitor.ts5
-rw-r--r--packages/sol-cov/src/get_source_range_snippet.ts15
2 files changed, 11 insertions, 9 deletions
diff --git a/packages/sol-cov/src/ast_visitor.ts b/packages/sol-cov/src/ast_visitor.ts
index 16984b5ec..564f0f7d2 100644
--- a/packages/sol-cov/src/ast_visitor.ts
+++ b/packages/sol-cov/src/ast_visitor.ts
@@ -116,8 +116,9 @@ export class ASTVisitor {
this._statementMap[this._entryId++] = this._getExpressionRange(ast);
}
private _getExpressionRange(ast: Parser.ASTNode): SingleFileSourceRange {
- const start = this._locationByOffset[ast.range[0]];
- const end = this._locationByOffset[ast.range[1] + 1];
+ const astRange = ast.range as [number, number];
+ const start = this._locationByOffset[astRange[0]];
+ const end = this._locationByOffset[astRange[1] + 1];
const range = {
start,
end,
diff --git a/packages/sol-cov/src/get_source_range_snippet.ts b/packages/sol-cov/src/get_source_range_snippet.ts
index 48c74dd27..30d6ec802 100644
--- a/packages/sol-cov/src/get_source_range_snippet.ts
+++ b/packages/sol-cov/src/get_source_range_snippet.ts
@@ -9,7 +9,7 @@ interface ASTInfo {
type: string;
node: Parser.ASTNode;
name: string | null;
- range: SingleFileSourceRange;
+ range?: SingleFileSourceRange;
}
// Parsing source code for each transaction/code is slow and therefore we cache it
@@ -30,13 +30,13 @@ export function getSourceRangeSnippet(sourceRange: SourceRange, sourceCode: stri
const sourceCodeInRange = utils.getRange(sourceCode, sourceRange.location);
return {
...astInfo,
+ range: astInfo.range as SingleFileSourceRange,
source: sourceCodeInRange,
fileName: sourceRange.fileName,
};
}
-// A visitor which collects ASTInfo for contract definitions, function
-// definitions, and other types of statements.
+// A visitor which collects ASTInfo for most nodes in the AST.
class ASTInfoVisitor {
private _astInfos: ASTInfo[] = [];
public getASTInfoForRange(sourceRange: SourceRange): ASTInfo | null {
@@ -165,11 +165,12 @@ class ASTInfoVisitor {
},
};
for (const astInfo of this._astInfos) {
+ const astInfoRange = astInfo.range as SingleFileSourceRange;
if (
- astInfo.range.start.column === offsetSourceRange.location.start.column &&
- astInfo.range.start.line === offsetSourceRange.location.start.line &&
- astInfo.range.end.column === offsetSourceRange.location.end.column &&
- astInfo.range.end.line === offsetSourceRange.location.end.line
+ astInfoRange.start.column === offsetSourceRange.location.start.column &&
+ astInfoRange.start.line === offsetSourceRange.location.start.line &&
+ astInfoRange.end.column === offsetSourceRange.location.end.column &&
+ astInfoRange.end.line === offsetSourceRange.location.end.line
) {
return astInfo;
}