diff --git a/continuation.js b/continuation.js index 1d1aecc..62c3cca 100644 --- a/continuation.js +++ b/continuation.js @@ -58,7 +58,7 @@ exports.compile = function (code, options) { indent: { style: indent, base: 0 - }, + } }, comment: true }; @@ -76,7 +76,7 @@ exports.getSourceMap = function (file, sources) { sourceMap.file = file; sourceMap.sources = sources; return JSON.stringify(sourceMap); -} +}; var findExplicitMark = function (ast) { var found = false; diff --git a/lib/parser.js b/lib/parser.js index 425d54a..47ef22f 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -8,18 +8,19 @@ exports.parse = function parse(code) { loc: true, range: true, token: true, - comment: true, + comment: true }; - + + var ast; try { - var ast = esprima.parse(code, options); + ast = esprima.parse(code, options); } catch (err) { throw new Error(err.message + ' in ' + global.currentFilename); } - + //console.log(util.inspect(ast, false, null, true)); ast = new syntax.Program(ast.body, ast.comments, ast.loc, ast.range); - + traverse(ast, syntax.factory); //console.log(util.inspect(ast, false, null, true)); return ast; diff --git a/lib/syntax/CallExpression.js b/lib/syntax/CallExpression.js index 6773008..bb8da04 100644 --- a/lib/syntax/CallExpression.js +++ b/lib/syntax/CallExpression.js @@ -127,7 +127,7 @@ CallExpression.prototype.transformParallel = function (place) { expPlaces.push(expPlace); }); - var numParallels = this.arguments.length + var numParallels = this.arguments.length; var innerPlace = []; var nextPlace = []; @@ -144,7 +144,7 @@ CallExpression.prototype.transformParallel = function (place) { //Define var _$errors = [] place.push(new VariableDeclaration( - new VariableDeclarator(errArray, new ArrayExpression), + new VariableDeclarator(errArray, new ArrayExpression()), 'var' )); @@ -181,7 +181,7 @@ CallExpression.prototype.transformParallel = function (place) { //Add if (_$parallel_done !== ...) return nextPlace.push(new IfStatement( new BinaryExpression('!==', parallelCounter, new Literal(numParallels)), - new ReturnStatement + new ReturnStatement() )); //Add if (_$errors.length > 0) throw $_errors diff --git a/lib/syntax/ConditionalExpression.js b/lib/syntax/ConditionalExpression.js index 12df707..4b3cad4 100644 --- a/lib/syntax/ConditionalExpression.js +++ b/lib/syntax/ConditionalExpression.js @@ -12,4 +12,4 @@ ConditionalExpression.prototype.transform = function (place) { place = this.consequent.transform(place); place = this.alternate.transform(place); return place; -} +}; diff --git a/lib/syntax/ForInStatement.js b/lib/syntax/ForInStatement.js index df937f6..0b31af2 100644 --- a/lib/syntax/ForInStatement.js +++ b/lib/syntax/ForInStatement.js @@ -39,7 +39,7 @@ ForInStatement.prototype.normalize = function () { var iter = new Identifier(helpers.forInIter); var iterArray = new Identifier(helpers.forInArray); var iterDef = new VariableDeclaration(new VariableDeclarator(iter, new Literal(0))); - var iterArrayDef = new VariableDeclaration(new VariableDeclarator(iterArray, new ArrayExpression)); + var iterArrayDef = new VariableDeclaration(new VariableDeclarator(iterArray, new ArrayExpression())); //Move actual iteration into a while loop var cond = new BinaryExpression('<', iter, new MemberExpression(iterArray, new Identifier('length'), false)); diff --git a/lib/syntax/ForStatement.js b/lib/syntax/ForStatement.js index 18168f8..c196a5b 100644 --- a/lib/syntax/ForStatement.js +++ b/lib/syntax/ForStatement.js @@ -41,4 +41,4 @@ ForStatement.prototype.normalize = function () { result.push(whileStatement); return result; -} +}; diff --git a/lib/syntax/IfStatement.js b/lib/syntax/IfStatement.js index 8e1d589..b7637f1 100644 --- a/lib/syntax/IfStatement.js +++ b/lib/syntax/IfStatement.js @@ -38,10 +38,11 @@ IfStatement.prototype.transform = function (place) { var consequentPlace = this.consequent.transform(); var async = (consequentPlace != this.consequent.body); - + + var alternatePlace; if (this.alternate !== null) { assert(this.alternate.type === 'BlockStatement'); - var alternatePlace = this.alternate.transform(); + alternatePlace = this.alternate.transform(); async = async || (alternatePlace != this.alternate.body); } @@ -83,4 +84,4 @@ IfStatement.prototype.transform = function (place) { place.push(this); return place; } -} +}; diff --git a/lib/syntax/SwitchStatement.js b/lib/syntax/SwitchStatement.js index 64d2942..fd69170 100644 --- a/lib/syntax/SwitchStatement.js +++ b/lib/syntax/SwitchStatement.js @@ -52,7 +52,7 @@ SwitchStatement.prototype.transform = function (place) { var name = 'case_' + index; var continuationExpression = new CallExpression(new Identifier(name), callbackId); sCase.consequent = [ - new ReturnStatement(continuationExpression), + new ReturnStatement(continuationExpression) ]; }); diff --git a/lib/syntax/TryStatement.js b/lib/syntax/TryStatement.js index 8f878bb..079a74e 100644 --- a/lib/syntax/TryStatement.js +++ b/lib/syntax/TryStatement.js @@ -33,8 +33,9 @@ TryStatement.prototype.transform = function (place) { //TODO multiple handlers (but multiple handles seems not supported by V8) var handler = this.handlers[0]; var handlerAsync = false; + var handlerPlace; if (handler) { - var handlerPlace = handler.transform(); + handlerPlace = handler.transform(); handlerAsync = (handlerPlace != handler.body.body); } //Not transform if not async calls inside @@ -46,6 +47,7 @@ TryStatement.prototype.transform = function (place) { var errId = new Identifier(helpers.errName); var callbackStmt = new ExpressionStatement(new CallExpression(callbackId)); var breakCont = new ExpressionStatement(new CallExpression(callbackId, errId)); + var tryCatch, judgeIfException, handlerFunction; if (blockAsync) { //Push explicit continuation statement innerPlace.push(callbackStmt); @@ -64,22 +66,23 @@ TryStatement.prototype.transform = function (place) { return node; }); //Generate try handler function - var judgeIfException = new IfStatement( + judgeIfException = new IfStatement( new BinaryExpression('!==', handler.param, new Identifier('undefined')), handler.body, null ); - var handlerFunction = new FunctionExpression( + handlerFunction = new FunctionExpression( null, [handler.param], new BlockStatement(judgeIfException) ); - var tryCatch = new ExpressionStatement( + tryCatch = new ExpressionStatement( new CallExpression(tryFunction, handlerFunction) ); } else { - var tryCatch = this; + tryCatch = this; } + var continuationPlace; if (handler) { if (handlerAsync) { //If there's async call in catch clause, do CPS transformation on catch function @@ -104,11 +107,11 @@ TryStatement.prototype.transform = function (place) { //Add continuation call for non-exception condition catchFunction.body.body.push(callbackStmt); } - var continuationPlace = continuationFunction.body.body; + continuationPlace = continuationFunction.body.body; } else { //Or else directly add catch function place.push(tryCatch); - var continuationPlace = handlerFunction.body.body; + continuationPlace = handlerFunction.body.body; } } //If finally clause found, push it into continuation place diff --git a/lib/traverse.js b/lib/traverse.js index 55a7241..7db8f54 100644 --- a/lib/traverse.js +++ b/lib/traverse.js @@ -4,9 +4,9 @@ var assert = require('assert'); var traverse = module.exports = function (node, options, func) { if (!func) func = options; function go(node) { - if (node === null || typeof(node) === 'string' || typeof(node) === 'number' - || typeof(node) === 'boolean' || typeof(node) === 'undefined' - || util.isRegExp(node)) { + if (node === null || typeof(node) === 'string' || typeof(node) === 'number' || + typeof(node) === 'boolean' || typeof(node) === 'undefined' || + util.isRegExp(node)) { return node; } assert(node.type);