Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

api: fix

  • Loading branch information...
commit 39569224d8b192fc1f107def7a62daf2516c0451 1 parent 144fe8e
@indutny authored
Showing with 26 additions and 2 deletions.
  1. +2 −2 lib/spoon/api.js
  2. +24 −0 test/api-test.js
View
4 lib/spoon/api.js
@@ -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
24 test/api-test.js
@@ -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);
+ }
+ });
+ });
+ });
+});
Please sign in to comment.
Something went wrong with that request. Please try again.