Last active
December 23, 2015 13:29
-
-
Save paulfryzel/6642935 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var parse = require('esprima').parse; | |
var generate = require('escodegen').generate; | |
function foo() { | |
var a = 1; | |
(function () { | |
var b = 2; | |
console.log(a); | |
})(); | |
console.log(a); | |
console.log(b); | |
} | |
function body(fn) { | |
var ast = parse(foo).body[0].body; | |
var gen = generate(ast, { format: { compact: true } }); | |
return gen.substring(1, gen.length - 1); | |
} | |
console.log(body(foo)); | |
//=> var a=1;(function(){var b=2;console.log(a);}());console.log(a);console.log(b); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment