Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

api: process function expressions too

  • Loading branch information...
commit c6193dc74cd783f3c849069b0a5598ec067b0efb 1 parent d34b14a
@indutny authored
Showing with 12 additions and 5 deletions.
  1. +12 −5 lib/spoon/api.js
View
17 lib/spoon/api.js
@@ -18,7 +18,7 @@ api.render = function render(cfg) {
};
function patch(ast, decl, callback) {
- var fn = null,
+ var fn = {},
body = null,
stack = [];
@@ -30,7 +30,7 @@ function patch(ast, decl, callback) {
}
return;
} else if (ast.type === 'FunctionDeclaration' ||
- ast.type ===' FunctionExpression') {
+ ast.type === 'FunctionExpression') {
stack.push({
fn: fn,
body: body
@@ -40,7 +40,7 @@ function patch(ast, decl, callback) {
},
leave: function(ast) {
if (ast === fn) {
- if (body !== null) ast.body = body;
+ if (body) ast.body = body;
// Restore previous position
var onstack = stack.pop();
@@ -69,8 +69,15 @@ api.preprocess = function preprocess(code, options, callback) {
ast = api.spoon.render(cfg);
// A big fat hack here, but I need to get Esprima AST to replace it.
- return esprima.parse(uglify.uglify.gen_code(ast, options.uglify),
- options.esprima).body[0];
+ ast = esprima.parse(uglify.uglify.gen_code(ast, options.uglify),
+ options.esprima).body[0];
+
+ // Get function out of expression
+ if (ast.type === 'ExpressionStatement') {
+ ast = ast.expression;
+ }
+
+ return ast;
});
// And this is a hack too
Please sign in to comment.
Something went wrong with that request. Please try again.