Skip to content

Commit

Permalink
Initial fixes/impl for method-debug-messages.
Browse files Browse the repository at this point in the history
lib/blocks/core: updated to commit ff19ee08e3107367f5584b745bd2a7a3aa8ce281

build/taks/debug: Re-added code generation for debug-messages.
	Inserting statement to enable blocks.debug after the rest of the
	framework initialized (jsdeug requires functions that aren't
	initialized when jsdebug is first called.)
	Added statement to not insert jsdebug argument checks in functions
	that don't have parameter docs.

lib/blocks/jsdebug:
	Fixed type of observables (in @param jsdoc observables are called
	"blocks.observable" not "blocks.observable()" as the code
	expected).
	Changed "enabled" to default to false (will be set to true after
	framework initialization).
  • Loading branch information
Joscha Rohmann committed Aug 16, 2016
1 parent f0e77b8 commit 7f337f7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 31 deletions.
43 changes: 22 additions & 21 deletions build/tasks/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ module.exports = function (grunt) {
});
}

if (data.memberof && data.memberof.indexOf('blocks.queries') == 0) {
if (data.memberof && data.memberof.indexOf('blocks.queries') === 0) {
queries[data.name] = data;
return;
}

if (!node) {
if (!node || data.params.length === 0) {
return;
}

var func;
if (node.expression && node.expression.right && node.expression.right.type == 'FunctionExpression') {
func = node.expression.right;
Expand All @@ -60,42 +61,42 @@ module.exports = function (grunt) {
if (func) {
// FunctionExpression.BlockStatement.body(Array)
var funcBody = func.body.body;

esprima.parse('blocks.debug.checkArgs && blocks.debug.checkArgs(' + toValueString(data) + ', Array.prototype.slice.call(arguments))').body.forEach(function (chunk) {
esprima.parse('blocks.debug && blocks.debug.checkArgs(' + toValueString(data) + ', Array.prototype.slice.call(arguments), {})').body.forEach(function (chunk) {
funcBody.unshift(chunk);
});
}
}
});
//var code = escodegen.generate(parsed.parseTree(), {
// format: {
// indent: {
// style: ' ',
// base: 0,
// adjustMultilineComment: true
// }
// },
// comment: true
//});

code = insertSourceCode(code, grunt.file.read('lib/blocks/jsdebug.js'));
code = insertSourceCode(code, 'blocks.debug.queries = ' + toValueString(queries));
var targetCode = escodegen.generate(parsed.parseTree(), {
format: {
indent: {
style: ' ',
base: 0,
adjustMultilineComment: true
}
},
comment: true
});

grunt.file.write('dist/blocks.js', code);
targetCode = insertSourceCode(targetCode, grunt.file.read('lib/blocks/jsdebug.js'));
targetCode = insertSourceCode(targetCode, 'blocks.debug.queries = ' + toValueString(queries));
// enable blocks.debug after the framework initialized completly (jsdebug uses some functions that aren't initialized when they are needed the first time)
targetCode = insertSourceCode(targetCode, 'blocks.debug.enabled = true;', true);
grunt.file.write('dist/blocks.js', targetCode);
});

function insertSourceCode(baseCode, insertCode) {
function insertSourceCode(baseCode, insertCode, source) {
var sourceCodeLocation;
var result = baseCode;

sourceCodeLocation = result.indexOf('// @debug-code');
sourceCodeLocation = result.indexOf(source ? '// @source-code' : '// @debug-code');
result = result.substring(0, sourceCodeLocation) + '\n' + getSourceCodeWrap(insertCode) + result.substring(sourceCodeLocation);

return result;
}

function getSourceCodeWrap(code) {
return '(function () {\n' + code + '\n})();'
return '(function () {\n' + code + '\n})();';
}

function toValueString(value, options) {
Expand Down
10 changes: 4 additions & 6 deletions lib/blocks/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1062,13 +1062,11 @@
return callback;
}

(function () {
// @debug-code
})();

(function () {
// @source-code
})();
// @debug-code

// @source-code


/* @if DEBUG */
(function() {
Expand Down
8 changes: 4 additions & 4 deletions lib/blocks/jsdebug.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var customTypes = {};

blocks.debug = {
enabled: true,
enabled: false,

enable: function () {
blocks.debug.enabled = true;
Expand Down Expand Up @@ -390,7 +390,7 @@ function checkArgsTypes(method, args) {
var params = method.params;
var maxOptionals = params.length - (params.length - getOptionalParamsCount(method.params));
var paramIndex = 0;
var passDetailValues = blocks.queries[method.name] && blocks.queries[method.name].passDetailValues;
var passDetailValues = blocks.queries && blocks.queries[method.name] && blocks.queries[method.name].passDetailValues;
var currentErrors;
var param;
var value;
Expand Down Expand Up @@ -467,15 +467,15 @@ function checkType(param, value) {
continue;
}
} else if (blocks.isObservable(value)) {
valueType = 'blocks.observable()';
valueType = 'blocks.observable';
} else {
valueType = blocks.type(value).toLowerCase();
}

if (type === valueType) {
satisfied = true;
break;
} else if (valueType == 'blocks.observable()') {
} else if (valueType == 'blocks.observable') {
valueType = blocks.type(blocks.unwrapObservable(value));
if (type === valueType) {
satisfied = true;
Expand Down

0 comments on commit 7f337f7

Please sign in to comment.