|
|
|
@ -182,29 +182,50 @@ class Registrar { |
|
|
|
|
* @param {Object} expression AST node |
|
|
|
|
*/ |
|
|
|
|
addNewLogicalORBranch(contract, expression) { |
|
|
|
|
const startContract = contract.instrumented.slice(0, expression.range[0]); |
|
|
|
|
const startline = ( startContract.match(/\n/g) || [] ).length + 1; |
|
|
|
|
let start; |
|
|
|
|
|
|
|
|
|
// Instabul HTML highlighting location data...
|
|
|
|
|
const leftZero = expression.left.range[0]; |
|
|
|
|
const leftOne = expression.left.range[1]; |
|
|
|
|
const rightZero = expression.right.range[0]; |
|
|
|
|
const rightOne = expression.right.range[1]; |
|
|
|
|
|
|
|
|
|
start = contract.instrumented.slice(0, leftZero); |
|
|
|
|
const leftStartLine = ( start.match(/\n/g) || [] ).length + 1; |
|
|
|
|
const leftStartCol = leftZero - start.lastIndexOf('\n') - 1; |
|
|
|
|
|
|
|
|
|
start = contract.instrumented.slice(0, leftOne); |
|
|
|
|
const leftEndLine = ( start.match(/\n/g) || [] ).length + 1; |
|
|
|
|
const leftEndCol = leftOne - start.lastIndexOf('\n') - 1; |
|
|
|
|
|
|
|
|
|
start = contract.instrumented.slice(0, rightZero); |
|
|
|
|
const rightStartLine = ( start.match(/\n/g) || [] ).length + 1; |
|
|
|
|
const rightStartCol = rightZero - start.lastIndexOf('\n') - 1; |
|
|
|
|
|
|
|
|
|
start = contract.instrumented.slice(0, rightOne); |
|
|
|
|
const rightEndLine = ( start.match(/\n/g) || [] ).length + 1; |
|
|
|
|
const rightEndCol = rightOne - start.lastIndexOf('\n') - 1; |
|
|
|
|
|
|
|
|
|
contract.branchId += 1; |
|
|
|
|
|
|
|
|
|
// NB locations for if branches in istanbul are zero
|
|
|
|
|
// length and associated with the start of the if.
|
|
|
|
|
contract.branchMap[contract.branchId] = { |
|
|
|
|
line: startline, |
|
|
|
|
line: leftStartLine, |
|
|
|
|
type: 'cond-expr', |
|
|
|
|
locations: [{ |
|
|
|
|
start: { |
|
|
|
|
line: startline, column: expression.left.range[0], |
|
|
|
|
line: leftStartLine, column: leftStartCol, |
|
|
|
|
}, |
|
|
|
|
end: { |
|
|
|
|
line: startline, column: expression.left.range[1], |
|
|
|
|
line: leftEndLine, column: leftEndCol, |
|
|
|
|
}, |
|
|
|
|
}, { |
|
|
|
|
start: { |
|
|
|
|
line: startline, column: expression.right.range[0], |
|
|
|
|
line: rightStartLine, column: rightStartCol, |
|
|
|
|
}, |
|
|
|
|
end: { |
|
|
|
|
line: startline, column: expression.right.range[1], |
|
|
|
|
line: rightEndLine, column: rightEndCol, |
|
|
|
|
}, |
|
|
|
|
}], |
|
|
|
|
}; |
|
|
|
|