Skip to content

Commit

Permalink
clean up & minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
llafuente committed May 6, 2014
1 parent 52b61c7 commit 185943c
Show file tree
Hide file tree
Showing 19 changed files with 7,337 additions and 82 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/node_modules
/doc
/dist
/debug
/debug/*
75 changes: 48 additions & 27 deletions dist.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ var methods,
src,
mod_required;

function isAssertCall(node){
return node.type === 'CallExpression' &&
node.callee.type === 'Identifier' &&
node.callee.name === 'assert';
function isAssertCall(node) {
return node.type === "CallExpression" &&
node.callee.type === "Identifier" &&
node.callee.name === "assert";
}

function isComment(node) {
Expand Down Expand Up @@ -87,6 +87,37 @@ function parse_comments(list) {
return comments.join("\n\n");
}

function create_number_validator(post_str) {
post_str = post_str || "";
return "if (%var%" + post_str + " == undefined) { console.log(%var%); throw new Error('%var%" + post_str + " is undefined/null'); }\n" +
"if (Number.isNaN(%var%" + post_str + ")) { console.log(%var%); throw new Error('%var%" + post_str + " is nan'); }\n";
}


var validators = {
"Number": create_number_validator()
};

validators.Vec2 = [0, 1].map(function (i) {return create_number_validator("[" + i + "]"); }).join("\n");

validators.Matrix23 = [0, 1, 2, 3, 4, 5].map(function (i) {return create_number_validator("[" + i + "]"); }).join("\n");

validators.Matrix22 = [0, 1, 2, 3].map(function (i) {return create_number_validator("[" + i + "]"); }).join("\n");

validators.AABB2 = validators.Segment2 = validators.Matrix22;

validators.Rectangle = [0, 1].map(function (i) {
return [0, 1].map(function (j) {
return create_number_validator("[" + i + "][" + j + "]");
}).join("\n");
}).join("\n");

validators.Triangle = [0, 1, 2].map(function (i) {
return [0, 1].map(function (j) {
return create_number_validator("[" + i + "][" + j + "]");
}).join("\n");
}).join("\n");


var cls_list = [],
cls,
Expand Down Expand Up @@ -126,7 +157,7 @@ function getNearestFunction(node) {

for (cls in files) {

console.log("* ["+cls+"](https://github.com/llafuente/js-2dmath/blob/master/" + files[cls].doc_file.replace("./", "") +")");
console.log("* [" + cls + "](https://github.com/llafuente/js-2dmath/blob/master/" + files[cls].doc_file.replace("./", "") + ")");
console.log("");

description = null;
Expand Down Expand Up @@ -158,39 +189,28 @@ for (cls in files) {

if (isComment(node)) {
if (isFileDesccription(node)) {
description = node.value.split("\n")
description = node.value.split("\n");
} else {

var fn = getNearestFunction(node);

if (fn) {
methods[fn.id.name].comments = node.value.split("\n");

} }
}
}
}
});

var validators = {
"Number":
"if (%var% == undefined) { console.log(%var%); throw new Error('%var% is undefined/null'); }\n" +
"if (Number.isNaN(%var%)) { console.log(%var%); throw new Error('%var% is nan'); }\n"
, "Vec2":
"if (%var%[0] == undefined) { console.log(%var%); throw new Error('%var%[0] is undefined/null'); }\n" +
"if (%var%[1] == undefined) { console.log(%var%); throw new Error('%var%[1] is undefined/null'); }\n" +
"if (Number.isNaN(%var%[0])) { console.log(%var%); throw new Error('%var%[0] is nan'); }\n" +
"if (Number.isNaN(%var%[1])) { console.log(%var%); throw new Error('%var%[1] is nan'); }\n"
}

//
// - debug
//
output = falafel(src, function (node) {
var output = falafel(src, function (node) {
// anti-nan
if (isFunction(node)) {
var args = getArguments(node, valid_arguments);

var fn_txt = node.body.source().trim().substring(1);
var validations = [];
var args = getArguments(node, valid_arguments),
fn_txt = node.body.source().trim().substring(1),
validations = [],
i;

for (i in args) {
if (validators[args[i].type] && args[i].name.indexOf("out") !== 0) {
Expand Down Expand Up @@ -220,7 +240,7 @@ for (cls in files) {

isFunction(node);
});
} catch(e) {
} catch (e) {
methods[i] = {
arguments: [],
comments: [],
Expand All @@ -232,7 +252,8 @@ for (cls in files) {
}
}

var contents = [];
var contents = [],
i;
contents.push("<a name=\"" + cls + "\"></a>");
contents.push("## " + cls);

Expand Down Expand Up @@ -264,7 +285,7 @@ for (cls in files) {
process.exit();
}

var args_str = methods[i].arguments.map(function(a) {
var args_str = methods[i].arguments.map(function (a) {
return "*" + a.name + "*: " + a.type;
}).join(", ");

Expand Down
Loading

0 comments on commit 185943c

Please sign in to comment.