Skip to content

Commit

Permalink
Added custom debug methods, kinda.
Browse files Browse the repository at this point in the history
- Debug Build step now adds the method definition to a
  function-local-variable '__DEBUG_METHOD'.
- Added __DEBUG_METHOD to the .jshintrc.
- Added blocks.debug.throwMessage(Message: String, method: (e.g.
  __DEBUG_METHOD, level: [Notice, Warning, Error])
   Level currently only prints an other message and changes the color.
It's not perfect for example I don't like the __DEBUG_METHOD "global" in
the jshintrc but it's the best and cleanest way I could come up with for
now.
Other approches involved scary Estree-Magic and wold fail in case of
errors e.g. in user inserted function (callbacks).
For now it should be enough.
  • Loading branch information
Joscha Rohmann authored and Kanaye committed Sep 10, 2016
1 parent 8fe09d4 commit bdcd089
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build/tasks/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module.exports = function (grunt) {
if (func) {
// FunctionExpression.BlockStatement.body(Array)
var funcBody = func.body.body;
esprima.parse('blocks.debug && blocks.debug.checkArgs(' + toValueString(data) + ', Array.prototype.slice.call(arguments), {})').body.forEach(function (chunk) {
esprima.parse('blocks.debug && blocks.debug.checkArgs(__DEBUG_METHOD, Array.prototype.slice.call(arguments), {}); var __DEBUG_METHOD = ' + toValueString(data) + ';').body.forEach(function (chunk) {
funcBody.unshift(chunk);
});
}
Expand Down
3 changes: 2 additions & 1 deletion src/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

"globals": {
"blocks": true,
"define": true
"define": true,
"__DEBUG_METHOD": true
}
}

0 comments on commit bdcd089

Please sign in to comment.