Permalink
Browse files

api: fix

  • Loading branch information...
1 parent 144fe8e commit 39569224d8b192fc1f107def7a62daf2516c0451 @indutny committed Jan 17, 2013
Showing with 26 additions and 2 deletions.
  1. +2 −2 lib/spoon/api.js
  2. +24 −0 test/api-test.js
View
@@ -27,7 +27,7 @@ function patch(ast, decl, callback) {
if (ast.value === decl && fn) {
body = {
type: 'BlockStatement',
- body: callback(fn).body
+ body: callback(fn.body)
};
}
return;
@@ -68,7 +68,7 @@ api.preprocess = function preprocess(code, options, callback) {
if (callback) callback(cfg);
- ast = api.spoon.render(cfg);
+ ast = api.spoon.render(cfg).body;
// Get function out of expression
if (ast.type === 'ExpressionStatement') {
View
@@ -0,0 +1,24 @@
+var spoon = require('..'),
+ assert = require('assert'),
+ vm = require('vm'),
+ esprima = require('esprima'),
+ escodegen = require('escodegen');
+
+describe('Spoon', function() {
+ describe('spoon() API function', function() {
+ it('should work properly', function() {
+ var code = spoon(function a(__$callback) {
+ "enable spoon";
+ return 1;
+ }.toString(), ['async'], {
+ declaration: 'enable spoon'
+ });
+
+ vm.runInNewContext(code + ';a(callback);', {
+ callback: function(err, value) {
+ assert.equal(value, 1);
+ }
+ });
+ });
+ });
+});

0 comments on commit 3956922

Please sign in to comment.