Skip to content

Commit

Permalink
Fix some styles.
Browse files Browse the repository at this point in the history
  • Loading branch information
BYVoid committed Jun 29, 2013
1 parent 19cb905 commit b958717
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 27 deletions.
4 changes: 2 additions & 2 deletions continuation.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ exports.compile = function (code, options) {
indent: {
style: indent,
base: 0
},
}
},
comment: true
};
Expand All @@ -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;
Expand Down
11 changes: 6 additions & 5 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions lib/syntax/CallExpression.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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'
));

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/syntax/ConditionalExpression.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ ConditionalExpression.prototype.transform = function (place) {
place = this.consequent.transform(place);
place = this.alternate.transform(place);
return place;
}
};
2 changes: 1 addition & 1 deletion lib/syntax/ForInStatement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion lib/syntax/ForStatement.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ ForStatement.prototype.normalize = function () {
result.push(whileStatement);

return result;
}
};
7 changes: 4 additions & 3 deletions lib/syntax/IfStatement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -83,4 +84,4 @@ IfStatement.prototype.transform = function (place) {
place.push(this);
return place;
}
}
};
2 changes: 1 addition & 1 deletion lib/syntax/SwitchStatement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
];
});

Expand Down
17 changes: 10 additions & 7 deletions lib/syntax/TryStatement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/traverse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b958717

Please sign in to comment.