diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-03-09 22:58:25 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-03-12 10:37:29 +0800 |
commit | 21aac75533620545b9982cd73a2f0753930db021 (patch) | |
tree | 8f5c24b7a9f892c1213a1788f07bfed696e24e78 | |
parent | 95b02a3197d1a54658fb0e7c82f48bfd1d579d53 (diff) | |
download | dexon-sol-tools-21aac75533620545b9982cd73a2f0753930db021.tar.gz dexon-sol-tools-21aac75533620545b9982cd73a2f0753930db021.tar.zst dexon-sol-tools-21aac75533620545b9982cd73a2f0753930db021.zip |
Use string enum for branch types
-rw-r--r-- | packages/sol-cov/src/ast_visitor.ts | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/packages/sol-cov/src/ast_visitor.ts b/packages/sol-cov/src/ast_visitor.ts index f450dadbb..588d179d4 100644 --- a/packages/sol-cov/src/ast_visitor.ts +++ b/packages/sol-cov/src/ast_visitor.ts @@ -9,6 +9,12 @@ export interface CoverageEntriesDescription { statementMap: StatementMap; } +enum BranchType { + If = 'if', + ConditionalExpression = 'cond-expr', + BinaryExpression = 'binary-expr', +} + export class ASTVisitor { private _entryId = 0; private _fnMap: FnMap = {}; @@ -47,7 +53,7 @@ export class ASTVisitor { return coverageEntriesDescription; } private _visitConditionalExpression(ast: SolidityParser.AST): void { - this._visitBinaryBranch(ast, ast.consequent, ast.alternate, 'cond-expr'); + this._visitBinaryBranch(ast, ast.consequent, ast.alternate, BranchType.ConditionalExpression); } private _visitFunctionDeclaration(ast: SolidityParser.AST): void { const loc = this._getExpressionRange(ast); @@ -58,11 +64,11 @@ export class ASTVisitor { }; } private _visitBinaryExpression(ast: SolidityParser.AST): void { - this._visitBinaryBranch(ast, ast.left, ast.right, 'binary-expr'); + this._visitBinaryBranch(ast, ast.left, ast.right, BranchType.BinaryExpression); } private _visitIfStatement(ast: SolidityParser.AST): void { this._visitStatement(ast); - this._visitBinaryBranch(ast, ast.consequent, ast.alternate || ast, 'if'); + this._visitBinaryBranch(ast, ast.consequent, ast.alternate || ast, BranchType.If); } private _visitBreakStatement(ast: SolidityParser.AST): void { this._visitStatement(ast); @@ -92,7 +98,7 @@ export class ASTVisitor { ast: SolidityParser.AST, left: SolidityParser.AST, right: SolidityParser.AST, - type: 'if' | 'cond-expr' | 'binary-expr', + type: BranchType, ): void { this._branchMap[this._entryId++] = { line: this._getExpressionRange(ast).start.line, |