Permalink
Browse files

renderer: use escodegen for render, remove uglify

  • Loading branch information...
1 parent 8b9072a commit dc1ed5c96301c726bb7193dc0f18f8c30ac16cca @indutny committed Jan 15, 2013
Showing with 307 additions and 98 deletions.
  1. +2 −10 lib/spoon/api.js
  2. +8 −4 lib/spoon/cfg.js
  3. +292 −78 lib/spoon/renderer.js
  4. +0 −1 package.json
  5. +3 −3 test/asyncify-test.js
  6. +2 −2 test/cfg-test.js
View
@@ -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();
@@ -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) {
View
@@ -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') {
@@ -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) {
Oops, something went wrong.

0 comments on commit dc1ed5c

Please sign in to comment.