Skip to content

Commit

Permalink
Fix SyntaxError due to function declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
christofferqa committed Sep 14, 2016
1 parent 1950f5e commit 70de912
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/js/instrument/esnstrument.js
Original file line number Diff line number Diff line change
Expand Up @@ -1819,9 +1819,19 @@ if (typeof J$ === 'undefined') {
}
}
for (var i = startIndex; i < ast.body.length; i++) {

if (ast.body[i].type === 'FunctionDeclaration') {
newBody.push(ast.body[i]);
var name = ast.body[i].id.name;
var params = ast.body[i].params.map(function (param) { return param.name; }).join(', ');
var assignStmt;
if (ast.body[i].body === null) {
assignStmt = acorn.parse(
"var " + name + " = function " + name + "(" + params + ") {}").body;
} else {
assignStmt = replaceInStatement(
"var " + name + " = function " + name + "(" + params + ") { " + RP + "1 }",
ast.body[i].body.body);
}
newBody.push(assignStmt[0]);
if (newBody.length !== i + 1) {
hoisteredFunctions.push(ast.body[i].id.name);
}
Expand All @@ -1835,9 +1845,7 @@ if (typeof J$ === 'undefined') {
while (ast.body.length > 0) {
ast.body.pop();
}
for (var i = 0; i < newBody.length; i++) {
ast.body.push(newBody[i]);
}
Array.prototype.push.apply(ast.body, newBody);
} else {
//console.log(typeof ast.body);
}
Expand Down

0 comments on commit 70de912

Please sign in to comment.