Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
renderer: use escodegen for render, remove uglify
  • Loading branch information
indutny committed Jan 15, 2013
1 parent 8b9072a commit dc1ed5c
Show file tree
Hide file tree
Showing 6 changed files with 307 additions and 98 deletions.
12 changes: 2 additions & 10 deletions lib/spoon/api.js
@@ -1,7 +1,6 @@
var api = exports,
esprima = require('esprima'),
escodegen = require('escodegen'),
uglify = require('uglify-js');
escodegen = require('escodegen');

api.construct = function construct(ast) {
var cfg = api.spoon.cfg.create();
Expand Down Expand Up @@ -68,28 +67,21 @@ 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.
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
ast = uglify.parser.parse(escodegen.generate(ast));
} else {
var cfg = api.spoon.construct(ast);

if (callback) callback(cfg);

ast = api.spoon.render(cfg);
}
return uglify.uglify.gen_code(ast, options.uglify);
return escodegen.generate(ast);
};

api.spoon = function spoon(code, fns, options) {
Expand Down
12 changes: 8 additions & 4 deletions lib/spoon/cfg.js
Expand Up @@ -612,7 +612,7 @@ Cfg.prototype.visit = function visit(ast) {
} else if (t === 'UnaryExpression') {
return this.visitUnop(ast);
} else if (t === 'UpdateExpression') {
return this.visitUnop(ast);
return this.visitUpdate(ast);
} else if (t === 'Literal') {
return this.visitLiteral(ast);
} else if (t === 'Identifier') {
Expand Down Expand Up @@ -788,9 +788,13 @@ Cfg.prototype.visitLogical = function visitLogical(ast) {
};

Cfg.prototype.visitUnop = function visitUnop(ast) {
return this.add('unop', [ast.operator,
ast.prefix === undefined ? true : ast.prefix,
this.visit(ast.argument)]);
return this.add('unop', [ast.operator, this.visit(ast.argument)]);
};

Cfg.prototype.visitUpdate = function visitUpdate(ast) {
return this.add('update', [ast.operator,
ast.prefix,
this.visit(ast.argument)]);
};

Cfg.prototype.visitLiteral = function visitLiteral(ast) {
Expand Down

0 comments on commit dc1ed5c

Please sign in to comment.