mirror of
https://github.com/embarklabs/embark.git
synced 2025-02-19 17:14:40 +00:00
feat: handle missing directive
WhileStatement UsingForDirective EnumDefinition
This commit is contained in:
parent
154a4f0284
commit
bae31165dd
@ -98,6 +98,7 @@ class ContractSource {
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
const node = nodesRequiringVisiting.pop();
|
const node = nodesRequiringVisiting.pop();
|
||||||
|
|
||||||
if(!node) continue;
|
if(!node) continue;
|
||||||
|
|
||||||
let children = [];
|
let children = [];
|
||||||
@ -112,6 +113,8 @@ class ContractSource {
|
|||||||
case 'PragmaDirective':
|
case 'PragmaDirective':
|
||||||
case 'StructDefinition':
|
case 'StructDefinition':
|
||||||
case 'VariableDeclaration':
|
case 'VariableDeclaration':
|
||||||
|
case 'UsingForDirective':
|
||||||
|
case 'EnumDefinition':
|
||||||
// We don't need to do anything with these. Just carry on.
|
// We don't need to do anything with these. Just carry on.
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -216,6 +219,7 @@ class ContractSource {
|
|||||||
markLocations = [location];
|
markLocations = [location];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 'WhileStatement':
|
||||||
case 'ForStatement': {
|
case 'ForStatement': {
|
||||||
// For statements will be a bit of a special case. We want to count the body
|
// For statements will be a bit of a special case. We want to count the body
|
||||||
// iterations but we only want to count the for loop being hit once. Because
|
// iterations but we only want to count the for loop being hit once. Because
|
||||||
@ -226,7 +230,7 @@ class ContractSource {
|
|||||||
|
|
||||||
location = this.sourceMapToLocations(forLoopDeclaration);
|
location = this.sourceMapToLocations(forLoopDeclaration);
|
||||||
|
|
||||||
const markExpression = node.initializationExpression || node.loopExpression;
|
const markExpression = node.initializationExpression || node.loopExpression || node.condition;
|
||||||
const expressionLocation = this.sourceMapToLocations(markExpression.src);
|
const expressionLocation = this.sourceMapToLocations(markExpression.src);
|
||||||
|
|
||||||
if(!sourceMapToNodeType[markExpression.src]) sourceMapToNodeType[markExpression.src] = [];
|
if(!sourceMapToNodeType[markExpression.src]) sourceMapToNodeType[markExpression.src] = [];
|
||||||
@ -282,23 +286,17 @@ class ContractSource {
|
|||||||
// then we bail.
|
// then we bail.
|
||||||
|
|
||||||
contractMatches = trace.structLogs.filter((step) => bytecode[step.pc]);
|
contractMatches = trace.structLogs.filter((step) => bytecode[step.pc]);
|
||||||
if(!contractMatches) continue;
|
|
||||||
|
|
||||||
|
if(!contractMatches) continue;
|
||||||
contractMatches.forEach((step) => {
|
contractMatches.forEach((step) => {
|
||||||
step = bytecode[step.pc];
|
step = bytecode[step.pc];
|
||||||
|
|
||||||
if(!step.sourceMap || step.sourceMap === '' || step.sourceMap === SourceMap.empty()) return;
|
if(!step.sourceMap || step.sourceMap === '' || step.sourceMap === SourceMap.empty()) return;
|
||||||
|
|
||||||
const sourceMapString = step.sourceMap.toString(this.id);
|
const sourceMapString = step.sourceMap.toString(this.id);
|
||||||
|
|
||||||
const [offsetToFind, _length, _] = sourceMapString.split(":");
|
const [offsetToFind, lengthToFind, _] = sourceMapString.split(":");
|
||||||
let nodes;
|
const nodes = this._findNodes(offsetToFind, lengthToFind, sourceMapToNodeType);
|
||||||
Object.keys(sourceMapToNodeType).some(sourceMap => {
|
|
||||||
const [offset, _length, _] = sourceMap.split(":");
|
|
||||||
if (offsetToFind === offset) {
|
|
||||||
nodes = sourceMapToNodeType[sourceMap];
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if(!nodes) return;
|
if(!nodes) return;
|
||||||
|
|
||||||
@ -329,6 +327,18 @@ class ContractSource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_findNodes(offsetToFind, _lengthToFind, sourceMapToNodeType) {
|
||||||
|
let nodes;
|
||||||
|
Object.keys(sourceMapToNodeType).some(sourceMap => {
|
||||||
|
const [offset, _length, _] = sourceMap.split(":");
|
||||||
|
if (offsetToFind === offset) {
|
||||||
|
nodes = sourceMapToNodeType[sourceMap];
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return nodes;
|
||||||
|
}
|
||||||
|
|
||||||
_buildContractBytecode(contractName, contractBytecode, opcodes, sourceMaps) {
|
_buildContractBytecode(contractName, contractBytecode, opcodes, sourceMaps) {
|
||||||
const bytecodeMapping = contractBytecode[contractName];
|
const bytecodeMapping = contractBytecode[contractName];
|
||||||
let bytecodeIdx = 0;
|
let bytecodeIdx = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user