Skip to content

Commit

Permalink
trying to fix debugger
Browse files Browse the repository at this point in the history
  • Loading branch information
yazz committed Jul 22, 2023
1 parent 744848b commit 48fc865
Showing 1 changed file with 43 additions and 63 deletions.
106 changes: 43 additions & 63 deletions public/go.html
Original file line number Diff line number Diff line change
Expand Up @@ -3342,29 +3342,17 @@
return trcode2
}

let debugFromHere = false
if (trcode2.indexOf("let debug_from_here = true;") != -1) {
debugFromHere = true
}

let _b = esprima.parse(trcode2,{tolerant: true , loc:true, range: true, attachComment: false})
let line = -1
let varsToAdd = {}
let skipFirstAndLastLine = false
let numLinesToSkip = 0
let debugLineNumber = 0
if (isValidObject(args)) {
if (args.skipFirstAndLastLine){
skipFirstAndLastLine=true
numLinesToSkip = 1
}
}
if (debugFromHere) {
var index = trcode2.indexOf("let debug_from_here = true;");
var tempString = trcode2.substring(0, index);
var lineNumber = tempString.split('\n').length;
debugLineNumber = lineNumber
}

estraverse.traverse(_b, {
enter: function (node, parent) {
Expand Down Expand Up @@ -3404,30 +3392,26 @@
if (node.declarations[0].init) {
//alert(`let ${node.declarations[0].id.name} = ${node.declarations[0].init.value}`)
let varNameToUse = node.declarations[0].id.name
if ((!isValidObject(varNameToUse)) || varNameToUse.indexOf("undefined" != -1)) {
} else {

if (node.kind == "var") {
let newLine = "logVarBefore('" + blockName + "', " + node.loc.start.line + ",'" +
varNameToUse + "', " + varNameToUse + ");"
let newNode = esprima.parse(newLine)
}
varsToAdd[varNameToUse] = {}
if (node.kind == "var") {
let newLine = "logVarBefore('" + blockName + "', " + node.loc.start.line + ",'" +
varNameToUse + "', " + varNameToUse + ");"
let newNode = esprima.parse(newLine)
}
varsToAdd[varNameToUse] = {}

let newLineAfter = "logVarAfter('" + blockName + "', " + node.loc.start.line + ",'" +
varNameToUse + "'," + varNameToUse + ");"
let newNodeAfter = esprima.parse(newLineAfter)
let newLineAfter = "logVarAfter('" + blockName + "', " + node.loc.start.line + ",'" +
varNameToUse + "'," + varNameToUse + ");"
let newNodeAfter = esprima.parse(newLineAfter)

let logWatchVarsCode = `for (let _uu=0; _uu<Object.keys(globalWatchList).length; _uu++){try { let _vName = Object.keys(globalWatchList)[_uu];if (isValidObject(_vName)){ addWatchPoint(_vName, eval(_vName) ) }} catch(_err){}}`
let logWatchVarsNode = esprima.parse(logWatchVarsCode)
let logWatchVarsCode = `for (let _uu=0; _uu<Object.keys(globalWatchList).length; _uu++){try { let _vName = Object.keys(globalWatchList)[_uu];if (isValidObject(_vName)){ addWatchPoint(_vName, eval(_vName) ) }} catch(_err){}}`
let logWatchVarsNode = esprima.parse(logWatchVarsCode)

for (let rr = 0; rr < parent.body.length; rr++) {
if (parent.body[rr] == node) {
parent.body.splice(rr + 1, 0, logWatchVarsNode);
parent.body.splice(rr + 1, 0, newNodeAfter);
parent.body.splice(rr, 0, newNode);
break;
}
for (let rr = 0; rr < parent.body.length; rr++) {
if (parent.body[rr] == node) {
parent.body.splice(rr + 1, 0, logWatchVarsNode);
parent.body.splice(rr + 1, 0, newNodeAfter);
parent.body.splice(rr, 0, newNode);
break;
}
}
}
Expand All @@ -3454,44 +3438,40 @@
if ((node.expression.type == "AssignmentExpression") &&
(node.expression.operator == "=")) {
let varName = node.expression.left.name
if ((!isValidObject(varName)) || varName.indexOf("undefined" != -1)) {
} else {
if (!isValidObject(varName)) {
if (node.expression.left.object.type == "ThisExpression") {
varName = "this." + node.expression.left.property.name
} else if (node.expression.left.type == "MemberExpression") {
varName = node.expression.left.object.name
if (node.expression.left.property.type == "Identifier") {
varName += "." + node.expression.left.property.name
}
if (!isValidObject(varName)) {
if (node.expression.left.object.type == "ThisExpression") {
varName = "this." + node.expression.left.property.name
} else if (node.expression.left.type == "MemberExpression") {
varName = node.expression.left.object.name
if (node.expression.left.property.type == "Identifier") {
varName += "." + node.expression.left.property.name
}
}
varsToAdd[varName] = {}
}
varsToAdd[varName] = {}

let newLine = "logVarBefore('" + blockName + "', " + node.loc.start.line + ",'" +
varName + "', " + varName + ");"
let newNode = esprima.parse(newLine)
let newLine = "logVarBefore('" + blockName + "', " + node.loc.start.line + ",'" +
varName + "', " + varName + ");"
let newNode = esprima.parse(newLine)

let newLineAfter = "logVarAfter('" + blockName + "', " + node.loc.start.line + ",'" +
varName + "', " + varName + ");"
let newNodeAfter = esprima.parse(newLineAfter)
let newLineAfter = "logVarAfter('" + blockName + "', " + node.loc.start.line + ",'" +
varName + "', " + varName + ");"
let newNodeAfter = esprima.parse(newLineAfter)

let logWatchVarsCode = `for (let _uu=0; _uu<Object.keys(globalWatchList).length; _uu++){try { let _vName = Object.keys(globalWatchList)[_uu];if (isValidObject(_vName)){ addWatchPoint(_vName, eval(_vName) ) }} catch(_err){}}`
let logWatchVarsNode = esprima.parse(logWatchVarsCode)
let logWatchVarsCode = `for (let _uu=0; _uu<Object.keys(globalWatchList).length; _uu++){try { let _vName = Object.keys(globalWatchList)[_uu];if (isValidObject(_vName)){ addWatchPoint(_vName, eval(_vName) ) }} catch(_err){}}`
let logWatchVarsNode = esprima.parse(logWatchVarsCode)

for (let rr = 0; rr < parent.body.length; rr++) {
if (parent.body[rr] == node) {
if (logWatchVarsNode) {
parent.body.splice(rr + 1, 0, logWatchVarsNode);
}
if (newNodeAfter) {
parent.body.splice(rr + 1, 0, newNodeAfter);
}
parent.body.splice(rr, 0, newNode);
break;
for (let rr = 0; rr < parent.body.length; rr++) {
if (parent.body[rr] == node) {
if (logWatchVarsNode) {
parent.body.splice(rr + 1, 0, logWatchVarsNode);
}
if (newNodeAfter) {
parent.body.splice(rr + 1, 0, newNodeAfter);
}
parent.body.splice(rr, 0, newNode);
break;
}

}
}
}
Expand Down

0 comments on commit 48fc865

Please sign in to comment.